From d8e2bec1580f8a4635f9cfa52be5001a777cd35b Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 6 Aug 2012 17:00:02 +0200 Subject: [PATCH] [FIX] state of editor after cancelled cancel() (haha), handling of a record being edited during o2m deletion bzr revid: xmo@openerp.com-20120806150002-45c8mjq9dk5hck7y --- addons/web/static/src/js/view_form.js | 26 ++++++++++++++----- .../web/static/src/js/view_list_editable.js | 13 +++++----- doc/list-view.rst | 10 +++++-- 3 files changed, 34 insertions(+), 15 deletions(-) diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js index 1f22529ba2a..cc92244ce81 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -3483,14 +3483,26 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({ this._super.apply(this, arguments); }, do_delete: function (ids) { - // wheeee - var confirm = window.confirm; - window.confirm = function () { return true; }; - try { - return this._super(ids); - } finally { - window.confirm = confirm; + var self = this; + var next = $.when(); + var _super = this._super; + // handle deletion of an item which does not exist + // TODO: better handle that in the editable list? + var false_id_index = _(ids).indexOf(false); + if (false_id_index !== -1) { + ids.splice(false_id_index, 1); + next = this.cancel_edition(true); } + return next.pipe(function () { + // wheeee + var confirm = window.confirm; + window.confirm = function () { return true; }; + try { + return _super.call(self, ids); + } finally { + window.confirm = confirm; + } + }); } }); instance.web.form.One2ManyList = instance.web.ListView.List.extend({ diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 038593c54c3..3a574c30e56 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -281,16 +281,17 @@ openerp.web.list_editable = function (instance) { }); }, /** + * @param {Boolean} [force=false] discards the data even if the form has been edited * @return {jQuery.Deferred} */ - cancel_edition: function () { + cancel_edition: function (force) { var self = this; return this.with_event('cancel', { editor: this.editor, form: this.editor.form, cancel: false }, function () { - return this.editor.cancel().pipe(function (attrs) { + return this.editor.cancel(force).pipe(function (attrs) { if (attrs.id) { var record = self.records.get(attrs.id); if (!record) { @@ -717,13 +718,13 @@ openerp.web.list_editable = function (instance) { return self.cancel(); }); }, - cancel: function () { - var record = this.record; - this.record = null; - if (!this.form.can_be_discarded()) { + cancel: function (force) { + if (!(force || this.form.can_be_discarded())) { return $.Deferred().reject({ message: "The form's data can not be discarded"}).promise(); } + var record = this.record; + this.record = null; this.form.do_hide(); return $.when(record); } diff --git a/doc/list-view.rst b/doc/list-view.rst index 83925d82f46..24c7bb3beb4 100644 --- a/doc/list-view.rst +++ b/doc/list-view.rst @@ -160,11 +160,14 @@ Interaction Methods updated) and ``record`` the reloaded record having been edited. -.. js:function:: openerp.web.ListView.cancel_edition +.. js:function:: openerp.web.ListView.cancel_edition([force=false]) Cancels pending edition, cleans up the list view in case of creation (removes the empty record being created). + :param Boolean force: doesn't check if the user has added any + data, discards the edition unconditionally + Utility Methods +++++++++++++++ @@ -345,11 +348,14 @@ formview, delegating instead to its from when it was passed in, aside from the ``id`` attribute. - .. js:function:: openerp.web.list.Editor.cancel + .. js:function:: openerp.web.list.Editor.cancel([force=false]) Attemps to cancel the edition of the internal form, then hide the form + :param Boolean force: unconditionally cancels the edition of + the internal form, even if the user has + already entered data in it. :returns: delegate to the record under edition .. js:class:: EditorOptions