diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index cfd01b7fbdd..eda2a0861d2 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -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}); }, diff --git a/addons/web_kanban/static/src/js/kanban.js b/addons/web_kanban/static/src/js/kanban.js index 6c70ecfb8ec..dc06eb14444 100644 --- a/addons/web_kanban/static/src/js/kanban.js +++ b/addons/web_kanban/static/src/js/kanban.js @@ -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); }