Reset record to its original state when discarding the popup window

issue3325
review41921002
This commit is contained in:
Nicolas Évrard
2018-03-23 16:39:21 +01:00
parent ea7c53e830
commit c633ac1a53
4 changed files with 44 additions and 16 deletions
+1
View File
@@ -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
+13
View File
@@ -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();
+9 -3
View File
@@ -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);
+21 -13
View File
@@ -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('<button/>', {
'class': 'btn btn-link',
'type': 'button'
}).append(!kwargs.new_ && this.screen.current_record.id < 0 ?
Sao.i18n.gettext('Delete') : Sao.i18n.gettext('Cancel'))
.click(function() {
this.response('RESPONSE_CANCEL');
}.bind(this)));
}).append(button_text).click(function() {
this.response('RESPONSE_CANCEL');
}.bind(this)));
}
if (kwargs.new_ && this.many) {
@@ -236,6 +240,9 @@
jQuery(this).remove();
});
if (!kwargs.new_) {
this._initial_value = this.screen.current_record.get_eval();
}
},
add: function() {
var domain = jQuery.extend([], this.domain);
@@ -270,6 +277,7 @@
},
new_: function() {
this.screen.new_();
this._initial_value = null;
},
delete_: function() {
this.screen.remove(false, false, false);
@@ -355,25 +363,25 @@
return;
}
var cancel_prm = null;
if (response_id == 'RESPONSE_CANCEL' &&
!readonly &&
this.screen.current_record) {
result = false;
if ((this.screen.current_record.id < 0) || this.save_current) {
this.screen.cancel_current();
cancel_prm = this.screen.cancel_current(
this._initial_value);
} else if (this.screen.current_record.has_changed()) {
this.screen.current_record.cancel();
this.screen.current_record.reload().always(function() {
this.callback(result);
this.destroy();
}.bind(this));
return;
cancel_prm = this.screen.current_record.reload();
}
} else {
result = response_id != 'RESPONSE_CANCEL';
}
this.callback(result);
this.destroy();
(cancel_prm || jQuery.when()).done(function() {
this.callback(result);
this.destroy();
}.bind(this));
},
destroy: function() {
this.screen.screen_container.alternate_view = false;