From c9f2a86be5955a3a76702c0a1047d2a6332ba59c Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Mon, 4 Feb 2013 13:43:48 +0100 Subject: [PATCH] [FIX] Calendar popup form view_id is not honored. Default form view is used instead. Added instance.web.ViewManager#get_view_id(view_type) Fetch the title of the popup from the parent if it's a ViewManagerAction, otherwise, use the current's view title. bzr revid: fme@openerp.com-20130204124348-p79drjm72vt2j2ty --- addons/web/static/src/js/view_form.js | 3 ++- addons/web/static/src/js/views.js | 6 +++++ addons/web_calendar/static/src/js/calendar.js | 24 +++++++++++++++++-- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 4880b3882ff..8ff70e1010b 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -4450,6 +4450,7 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({ * options: * -readonly: only applicable when not in creation mode, default to false * - alternative_form_view + * - view_id * - write_function * - read_function * - create_function @@ -4516,7 +4517,7 @@ instance.web.form.AbstractFormPopup = instance.web.Widget.extend({ _.extend(options, { $buttons: this.$buttonpane, }); - this.view_form = new instance.web.FormView(this, this.dataset, false, options); + this.view_form = new instance.web.FormView(this, this.dataset, this.options.view_id || false, options); if (this.options.alternative_form_view) { this.view_form.set_embedded_view(this.options.alternative_form_view); } diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 9fd49367171..075312e639d 100644 --- a/addons/web/static/src/js/views.js +++ b/addons/web/static/src/js/views.js @@ -597,6 +597,12 @@ instance.web.ViewManager = instance.web.Widget.extend({ self.trigger("controller_inited",view_type,controller); }); }, + /** + * @returns {Number|Boolean} the view id of the given type, false if not found + */ + get_view_id: function(view_type) { + return this.views[view_type] && this.views[view_type].view_id || false; + }, set_title: function(title) { this.$el.find('.oe_view_title_text:first').text(title); }, diff --git a/addons/web_calendar/static/src/js/calendar.js b/addons/web_calendar/static/src/js/calendar.js index 9cac4db09d5..e42ec2ba1c8 100644 --- a/addons/web_calendar/static/src/js/calendar.js +++ b/addons/web_calendar/static/src/js/calendar.js @@ -416,6 +416,15 @@ instance.web_calendar.CalendarView = instance.web.View.extend({ }, slow_create: function(event_id, event_obj) { var self = this; + var view_id = false; + var title = this.name; + var parent = this.getParent(); + if (parent instanceof instance.web.ViewManager) { + view_id = parent.get_view_id('form'); + if (parent instanceof instance.web.ViewManagerAction) { + title = parent.get_action_manager().get_title(); + } + } if (this.current_mode() === 'month') { event_obj['start_date'].addHours(8); if (event_obj._length === 1) { @@ -432,8 +441,9 @@ instance.web_calendar.CalendarView = instance.web.View.extend({ var something_saved = false; var pop = new instance.web.form.FormOpenPopup(this); pop.show_element(this.dataset.model, null, this.dataset.get_context(defaults), { - title: _t("Create: ") + ' ' + this.name, + title: _t("Create: ") + ' ' + title, disable_multiple_selection: true, + view_id: view_id, }); pop.on('closed', self, function() { if (!something_saved) { @@ -450,6 +460,15 @@ instance.web_calendar.CalendarView = instance.web.View.extend({ open_event: function(event_id) { var self = this; var index = this.dataset.get_id_index(event_id); + var view_id = false; + var title = this.name; + var parent = this.getParent(); + if (parent instanceof instance.web.ViewManager) { + view_id = parent.get_view_id('form'); + if (parent instanceof instance.web.ViewManagerAction) { + title = parent.get_action_manager().get_title(); + } + } if (index === null) { // Some weird behaviour in dhtmlx scheduler could lead to this case // eg: making multiple days event in week view, dhtmlx doesn't trigger eventAdded !!?? @@ -467,7 +486,8 @@ instance.web_calendar.CalendarView = instance.web.View.extend({ var pop = new instance.web.form.FormOpenPopup(this); var id_from_dataset = this.dataset.ids[index]; // dhtmlx scheduler loses id's type pop.show_element(this.dataset.model, id_from_dataset, this.dataset.get_context(), { - title: _t("Edit: ") + this.name + title: _t("Edit: ") + title, + view_id: view_id, }); pop.on('write_completed', self, function(){ self.reload_event(id_from_dataset);