[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
This commit is contained in:
Fabien Meghazi 2013-02-04 13:43:48 +01:00
parent 9ac5a60972
commit c9f2a86be5
3 changed files with 30 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

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