[FIX] state of editor after cancelled cancel() (haha), handling of a record being edited during o2m deletion

bzr revid: xmo@openerp.com-20120806150002-45c8mjq9dk5hck7y
This commit is contained in:
Xavier Morel 2012-08-06 17:00:02 +02:00
parent 3f955f0525
commit d8e2bec158
3 changed files with 34 additions and 15 deletions

View File

@ -3483,14 +3483,26 @@ instance.web.form.One2ManyListView = instance.web.ListView.extend({
this._super.apply(this, arguments); this._super.apply(this, arguments);
}, },
do_delete: function (ids) { do_delete: function (ids) {
// wheeee var self = this;
var confirm = window.confirm; var next = $.when();
window.confirm = function () { return true; }; var _super = this._super;
try { // handle deletion of an item which does not exist
return this._super(ids); // TODO: better handle that in the editable list?
} finally { var false_id_index = _(ids).indexOf(false);
window.confirm = confirm; 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({ instance.web.form.One2ManyList = instance.web.ListView.List.extend({

View File

@ -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} * @return {jQuery.Deferred}
*/ */
cancel_edition: function () { cancel_edition: function (force) {
var self = this; var self = this;
return this.with_event('cancel', { return this.with_event('cancel', {
editor: this.editor, editor: this.editor,
form: this.editor.form, form: this.editor.form,
cancel: false cancel: false
}, function () { }, function () {
return this.editor.cancel().pipe(function (attrs) { return this.editor.cancel(force).pipe(function (attrs) {
if (attrs.id) { if (attrs.id) {
var record = self.records.get(attrs.id); var record = self.records.get(attrs.id);
if (!record) { if (!record) {
@ -717,13 +718,13 @@ openerp.web.list_editable = function (instance) {
return self.cancel(); return self.cancel();
}); });
}, },
cancel: function () { cancel: function (force) {
var record = this.record; if (!(force || this.form.can_be_discarded())) {
this.record = null;
if (!this.form.can_be_discarded()) {
return $.Deferred().reject({ return $.Deferred().reject({
message: "The form's data can not be discarded"}).promise(); message: "The form's data can not be discarded"}).promise();
} }
var record = this.record;
this.record = null;
this.form.do_hide(); this.form.do_hide();
return $.when(record); return $.when(record);
} }

View File

@ -160,11 +160,14 @@ Interaction Methods
updated) and ``record`` the reloaded record having been updated) and ``record`` the reloaded record having been
edited. 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 Cancels pending edition, cleans up the list view in case of
creation (removes the empty record being created). 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 Utility Methods
+++++++++++++++ +++++++++++++++
@ -345,11 +348,14 @@ formview, delegating instead to its
from when it was passed in, aside from the ``id`` from when it was passed in, aside from the ``id``
attribute. 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 Attemps to cancel the edition of the internal form, then hide
the form 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 :returns: delegate to the record under edition
.. js:class:: EditorOptions .. js:class:: EditorOptions