summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorChristophe Simonis <chs@openerp.com>2011-10-10 14:34:32 +0200
committerChristophe Simonis <chs@openerp.com>2011-10-10 14:34:32 +0200
commit27869cac8b76baea212575cf95c351a3cf5aa7d2 (patch)
tree4422289dd5de8c27c897165f5d3f8d31c9a44282 /addons/web/static/src
parentca224b647cefbd752aff8f6cfacd27593ec874a8 (diff)
[IMP] change the way the sections and items are added to the sidebar
bzr revid: chs@openerp.com-20111010123432-619o61elz09jm9sy
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/view_form.js12
-rw-r--r--addons/web/static/src/js/views.js139
-rw-r--r--addons/web/static/src/xml/base.xml11
3 files changed, 100 insertions, 62 deletions
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index f1fab7702c3..af0a9370933 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -119,7 +119,7 @@ openerp.web.FormView = openerp.web.View.extend( /** @lends openerp.web.FormView#
this.sidebar = new openerp.web.Sidebar(this, this.options.sidebar_id);
this.sidebar.start();
this.sidebar.do_unfold();
- this.sidebar.attachments = new openerp.web.form.SidebarAttachments(this.sidebar, this.sidebar.add_section('attachments', "Attachments"), this);
+ this.sidebar.attachments = new openerp.web.form.SidebarAttachments(this.sidebar, this);
this.sidebar.add_toolbar(this.fields_view.toolbar);
this.set_common_sidebar_sections(this.sidebar);
}
@@ -541,8 +541,12 @@ openerp.web.FormDialog = openerp.web.Dialog.extend({
openerp.web.form = {};
openerp.web.form.SidebarAttachments = openerp.web.Widget.extend({
- init: function(parent, element_id, form_view) {
- this._super(parent, element_id);
+ init: function(parent, form_view) {
+ var $section = parent.add_section('Attachments');
+ this.$div = $('<div class="oe-sidebar-attachments"></div>');
+ $section.append(this.$div);
+
+ this._super(parent, $section.attr('id'));
this.view = form_view;
},
do_update: function() {
@@ -560,7 +564,7 @@ openerp.web.form.SidebarAttachments = openerp.web.Widget.extend({
},
on_attachments_loaded: function(attachments) {
this.attachments = attachments;
- this.$element.html(QWeb.render('FormView.sidebar.attachments', this));
+ this.$div.html(QWeb.render('FormView.sidebar.attachments', this));
this.$element.find('.oe-binary-file').change(this.on_attachment_changed);
this.$element.find('.oe-sidebar-attachment-delete').click(this.on_attachment_delete);
},
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index aeedee706d8..50ffb4bbbc5 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -512,6 +512,52 @@ db.web.Sidebar = db.web.Widget.extend({
self.do_toggle();
});
},
+
+ call_default_on_sidebar: function(item) {
+ var func_name = 'on_sidebar_' + _.underscored(item.label);
+ var fn = this.widget_parent[func_name];
+ if(typeof fn === 'function') {
+ fn(item);
+ }
+ },
+
+ add_default_sections: function() {
+ this.add_items('Customize', [
+ {
+ label: "Manage Views",
+ callback: this.call_default_on_sidebar,
+ title: "Manage views of the current object"
+ }, {
+ label: "Edit Workflow",
+ callback: this.call_default_on_sidebar,
+ title: "Manage views of the current object",
+ classname: 'oe_hide oe_sidebar_edit_workflow'
+ }, {
+ label: "Customize Object",
+ callback: this.call_default_on_sidebar,
+ title: "Manage views of the current object"
+ }
+ ]);
+
+ this.add_items('Other Options', [
+ {
+ label: "Import",
+ callback: this.call_default_on_sidebar,
+ }, {
+ label: "Export",
+ callback: this.call_default_on_sidebar,
+ }, {
+ label: "Translate",
+ callback: this.call_default_on_sidebar,
+ classname: 'oe_sidebar_translate oe_hide'
+ }, {
+ label: "View Log",
+ callback: this.call_default_on_sidebar,
+ classname: 'oe_hide oe_sidebar_view_log'
+ }
+ ]);
+ },
+
add_toolbar: function(toolbar) {
var self = this;
_.each([['print', "Reports"], ['action', "Actions"], ['relate', "Links"]], function(type) {
@@ -524,15 +570,29 @@ db.web.Sidebar = db.web.Widget.extend({
classname: 'oe_sidebar_' + type[0]
}
}
- self.add_section(type[0], type[1], items);
+ self.add_items(type[1], items);
}
});
},
- add_section: function(code, name, items) {
- // For each section, we pass a name/label and optionally an array of items.
- // If no items are passed, then the section will be created as a custom section
- // returning back an element_id to be used by a custom controller.
- // Else, the section is a standard section with items displayed as links.
+
+ add_section: function(name) {
+ var code = _.underscored(name),
+ $section = this.sections[code];
+
+ if(!$section) {
+ section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
+ var $section = $(db.web.qweb.render("Sidebar.section", {
+ section_id: section_id,
+ name: name,
+ classname: 'oe_sidebar_' + code,
+ }));
+ $section.appendTo(this.$element.find('div.sidebar-actions'));
+ this.sections[code] = $section;
+ }
+ return $section;
+ },
+
+ add_items: function(section_name, items) {
// An item is a dictonary : {
// label: label to be displayed for the link,
// action: action to be launch when the link is clicked,
@@ -541,25 +601,24 @@ db.web.Sidebar = db.web.Widget.extend({
// title: optional title for the link
// }
// Note: The item should have one action or/and a callback
+ //
+
var self = this,
- section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
+ $section = this.add_section(section_name),
+ section_id = $section.attr('id');
+
if (items) {
for (var i = 0; i < items.length; i++) {
items[i].element_id = _.uniqueId(section_id + '_item_');
this.items[items[i].element_id] = items[i];
}
- }
- var $section = $(db.web.qweb.render("Sidebar.section", {
- section_id: section_id,
- name: name,
- classname: 'oe_sidebar_' + code,
- items: items
- }));
- if (items) {
- $section.find('a.oe_sidebar_action_a').click(function() {
+
+ var $items = $(db.web.qweb.render("Sidebar.section.items", {items: items}));
+
+ $items.find('a.oe_sidebar_action_a').click(function() {
var item = self.items[$(this).attr('id')];
if (item.callback) {
- item.callback();
+ item.callback.apply(self, [item]);
}
if (item.action) {
var ids = self.widget_parent.get_selected_ids();
@@ -589,10 +648,13 @@ db.web.Sidebar = db.web.Widget.extend({
}
return false;
});
+
+ var $ul = $section.find('ul');
+ if(!$ul.length) {
+ $ul = $('<ul/>').appendTo($section);
+ }
+ $items.appendTo($ul);
}
- $section.appendTo(this.$element.find('div.sidebar-actions'));
- this.sections[code] = $section;
- return section_id;
},
do_fold: function() {
this.$element.addClass('closed-sidebar').removeClass('open-sidebar');
@@ -821,42 +883,11 @@ db.web.View = db.web.Widget.extend(/** @lends db.web.View# */{
},
do_search: function(view) {
},
+
set_common_sidebar_sections: function(sidebar) {
- sidebar.add_section('customize', "Customize", [
- {
- label: "Manage Views",
- callback: this.on_sidebar_manage_view,
- title: "Manage views of the current object"
- }, {
- label: "Edit Workflow",
- callback: this.on_sidebar_edit_workflow,
- title: "Manage views of the current object",
- classname: 'oe_hide oe_sidebar_edit_workflow'
- }, {
- label: "Customize Object",
- callback: this.on_sidebar_customize_object,
- title: "Manage views of the current object"
- }
- ]);
- sidebar.add_section('other', "Other Options", [
- {
- label: "Import",
- callback: this.on_sidebar_import
- }, {
- label: "Export",
- callback: this.on_sidebar_export
- }, {
- label: "Translate",
- callback: this.on_sidebar_translate,
- classname: 'oe_sidebar_translate oe_hide'
- }, {
- label: "View Log",
- callback: this.on_sidebar_view_log,
- classname: 'oe_hide oe_sidebar_view_log'
- }
- ]);
+ sidebar.add_default_sections();
},
- on_sidebar_manage_view: function() {
+ on_sidebar_manage_views: function() {
if (this.fields_view && this.fields_view.arch) {
$('<xmp>' + db.web.json_node_to_xml(this.fields_view.arch, true) + '</xmp>').dialog({ width: '95%', height: 600});
} else {
diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml
index 0e5c97c4707..fb645296d0e 100644
--- a/addons/web/static/src/xml/base.xml
+++ b/addons/web/static/src/xml/base.xml
@@ -467,17 +467,20 @@
</div>
</t>
<t t-name="Sidebar.section">
- <h2><t t-esc="name"/></h2>
<div t-att-id="section_id" t-att-class="classname">
- <ul t-if="items">
+ <h2><t t-esc="name"/></h2>
+ </div>
+</t>
+
+
+<t t-name="Sidebar.section.items">
<li t-foreach="items" t-as="item" t-att-class="item.classname">
<a class="oe_sidebar_action_a" t-att-id="item.element_id" t-att-title="item.title" href="#">
<t t-esc="item.label"/>
</a>
</li>
- </ul>
- </div>
</t>
+
<t t-name="TranslateDialog">
<ul class="oe_translate_tabs">
<li><a t-attf-href="##{widget.element_id}_fields">Fields</a></li>