Added possibility to choose the mode at each call to do_show. do_show now also switch to initial_mode if no mode is specified.

bzr revid: nicolas.vanhoren@openerp.com-20120816093818-m1dykz5rywujg78j
This commit is contained in:
niv-openerp 2012-08-16 11:38:18 +02:00
parent 1e1936b59a
commit ceed9015d1
2 changed files with 13 additions and 6 deletions

View File

@ -255,7 +255,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
/**
*
* @param {Object} [options]
* @param {Boolean} [editable=false] whether the form should be switched to edition mode. A value of ``false`` will keep the current mode.
* @param {Boolean} [mode=undefined] If specified, switch the form to specified mode. Can be "edit" or "view".
* @param {Boolean} [reload=true] whether the form should reload its content on show, or use the currently loaded record
* @return {$.Deferred}
*/
@ -292,9 +292,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
});
}
return shown.pipe(function() {
if (options.editable) {
self.to_edit_mode();
}
self._actualize_mode(options.mode || self.options.initial_mode);
self.$element.css({
opacity: '1',
filter: 'alpha(opacity = 100)'
@ -634,12 +632,21 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
this._actualize_mode("edit");
},
/**
* Reactualize actual_mode.
* Ask the view to switch to a precise mode if possible. The view is free to
* not respect this command if the state of the dataset is not compatible with
* the new mode. For example, it is not possible to switch to edit mode if
* the current record is not yet saved in database.
*
* @param {string} [new_mode] Can be "edit", "view", "create" or undefined. If
* undefined the view will test the actual mode to check if it is still consistent
* with the dataset state.
*/
_actualize_mode: function(switch_to) {
var mode = switch_to || this.get("actual_mode");
if (! this.datarecord.id) {
mode = "create";
} else if (mode === "create") {
mode = "edit";
}
this.set({actual_mode: mode});
},

View File

@ -321,7 +321,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
},
open_record: function(id, editable) {
if (this.dataset.select_id(id)) {
this.do_switch_view('form', null, { editable: editable });
this.do_switch_view('form', null, { mode: editable ? "edit" : undefined });
} else {
this.do_warn("Kanban: could not find id#" + id);
}