[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);
},
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({

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}
*/
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);
}

View File

@ -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