diff --git a/CHANGELOG b/CHANGELOG index f9f6ebbc8b..815f56ab7c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Reset record to its original state when discarding the popup window * Add support of expand attribute on group tag * Add the context model name in the screen context * Add sum of records on list view diff --git a/src/model.js b/src/model.js index af50fd78cd..a3c1e610dd 100644 --- a/src/model.js +++ b/src/model.js @@ -1095,6 +1095,19 @@ this.autocompletion[fieldname] = result; }.bind(this)); }, + reset: function(value) { + this.cancel(); + return this.set(value, true).then(function() { + var promises = []; + if (this.group.parent) { + promises.push(this.group.parent.on_change( + [this.group.child_name])); + promises.push(this.group.parent.on_change_with( + [this.group.child_name])); + } + return jQuery.when.apply(jQuery, promises); + }.bind(this)); + }, expr_eval: function(expr) { if (typeof(expr) != 'string') return expr; var ctx = this.get_eval(); diff --git a/src/screen.js b/src/screen.js index fd0c6d2011..2bbc9c9f50 100644 --- a/src/screen.js +++ b/src/screen.js @@ -1147,13 +1147,19 @@ } } }, - cancel_current: function() { + cancel_current: function(initial_value) { var prms = []; if (this.current_record) { this.current_record.cancel(); if (this.current_record.id < 0) { - prms.push(this.remove( - false, false, false, [this.current_record])); + if (initial_value) { + prms.push( + this.current_record.reset(initial_value).then( + this.display.bind(this))); + } else { + prms.push(this.remove( + false, false, false, [this.current_record])); + } } } return jQuery.when.apply(jQuery, prms); diff --git a/src/window.js b/src/window.js index cf7ef9b536..fc3544112a 100644 --- a/src/window.js +++ b/src/window.js @@ -78,15 +78,19 @@ var readonly = (this.screen.attributes.readonly || this.screen.group.get_readonly()); + this._initial_value = null; if (view_type == 'form') { + var button_text = Sao.i18n.gettext('Cancel'); + if (kwargs.new_) { + button_text = Sao.i18n.gettext('Delete'); + } + dialog.footer.append(jQuery('