[IMP] In form view, 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-20120816094612-5lxnc7xpg8atr28b
This commit is contained in:
niv-openerp 2012-08-16 11:46:12 +02:00
commit c26032e594
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 {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 * @param {Boolean} [reload=true] whether the form should reload its content on show, or use the currently loaded record
* @return {$.Deferred} * @return {$.Deferred}
*/ */
@ -292,9 +292,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
}); });
} }
return shown.pipe(function() { return shown.pipe(function() {
if (options.editable) { self._actualize_mode(options.mode || self.options.initial_mode);
self.to_edit_mode();
}
self.$element.css({ self.$element.css({
opacity: '1', opacity: '1',
filter: 'alpha(opacity = 100)' filter: 'alpha(opacity = 100)'
@ -634,12 +632,21 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
this._actualize_mode("edit"); 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) { _actualize_mode: function(switch_to) {
var mode = switch_to || this.get("actual_mode"); var mode = switch_to || this.get("actual_mode");
if (! this.datarecord.id) { if (! this.datarecord.id) {
mode = "create"; mode = "create";
} else if (mode === "create") {
mode = "edit";
} }
this.set({actual_mode: mode}); this.set({actual_mode: mode});
}, },

View File

@ -321,7 +321,7 @@ instance.web_kanban.KanbanView = instance.web.View.extend({
}, },
open_record: function(id, editable) { open_record: function(id, editable) {
if (this.dataset.select_id(id)) { 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 { } else {
this.do_warn("Kanban: could not find id#" + id); this.do_warn("Kanban: could not find id#" + id);
} }