[FIX] Calendar popup form view should be the same as the action if defined.

- 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-20130204150437-xyg7ol0cu7525sc4
This commit is contained in:
Fabien Meghazi 2013-02-04 16:04:37 +01:00
commit f63c3caaf2
3 changed files with 28 additions and 3 deletions

View File

@ -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);
}

View File

@ -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);
},

View File

@ -414,6 +414,20 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
self.slow_create(event_id, event_obj);
});
},
get_form_popup_infos: function() {
var parent = this.getParent();
var infos = {
view_id: false,
title: this.name,
};
if (parent instanceof instance.web.ViewManager) {
infos.view_id = parent.get_view_id('form');
if (parent instanceof instance.web.ViewManagerAction && parent.action && parent.action.name) {
infos.title = parent.action.name;
}
}
return infos;
},
slow_create: function(event_id, event_obj) {
var self = this;
if (this.current_mode() === 'month') {
@ -431,9 +445,11 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
});
var something_saved = false;
var pop = new instance.web.form.FormOpenPopup(this);
var pop_infos = this.get_form_popup_infos();
pop.show_element(this.dataset.model, null, this.dataset.get_context(defaults), {
title: _t("Create: ") + ' ' + this.name,
title: _.str.sprintf(_t("Create: %s"), pop_infos.title),
disable_multiple_selection: true,
view_id: pop_infos.view_id,
});
pop.on('closed', self, function() {
if (!something_saved) {
@ -465,9 +481,11 @@ instance.web_calendar.CalendarView = instance.web.View.extend({
});
} else {
var pop = new instance.web.form.FormOpenPopup(this);
var pop_infos = this.get_form_popup_infos();
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: _.str.sprintf(_t("Edit: %s"), pop_infos.title),
view_id: pop_infos.view_id,
});
pop.on('write_completed', self, function(){
self.reload_event(id_from_dataset);