From 27869cac8b76baea212575cf95c351a3cf5aa7d2 Mon Sep 17 00:00:00 2001 From: Christophe Simonis Date: Mon, 10 Oct 2011 14:34:32 +0200 Subject: [PATCH] [IMP] change the way the sections and items are added to the sidebar bzr revid: chs@openerp.com-20111010123432-619o61elz09jm9sy --- addons/web/static/src/js/view_form.js | 12 +- addons/web/static/src/js/views.js | 139 +++++++++++------- addons/web/static/src/xml/base.xml | 11 +- addons/web_calendar/static/src/js/calendar.js | 18 ++- 4 files changed, 111 insertions(+), 69 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 = $('
'); + $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 = $(' - +