changeset 8290b7b36a69 in sao:5.0
details: https://hg.tryton.org/sao?cmd=changeset;node=8290b7b36a69
description:
Return rejected promise when creation fails
issue8168
review51631002
(grafted from cfc42be09a25768dacb1242c530b62c6d5e62368)
diffstat:
src/model.js | 7 ++++++-
src/screen.js | 10 ++--------
2 files changed, 8 insertions(+), 9 deletions(-)
diffs (44 lines):
diff -r 26522e741d48 -r 8290b7b36a69 src/model.js
--- a/src/model.js Thu May 16 17:46:05 2019 +0200
+++ b/src/model.js Wed May 01 21:58:01 2019 +0200
@@ -506,7 +506,12 @@
if ((this.id < 0) || !jQuery.isEmptyObject(values)) {
if (this.id < 0) {
// synchronous call to avoid multiple creation
- this.id = this.model.execute('create', [[values]],
context, false)[0];
+ try {
+ this.id = this.model.execute(
+ 'create', [[values]], context, false)[0];
+ } catch (e) {
+ return jQuery.Deferred().reject(e);
+ }
} else {
if (!jQuery.isEmptyObject(values)) {
context._timestamp = this.get_timestamp();
diff -r 26522e741d48 -r 8290b7b36a69 src/screen.js
--- a/src/screen.js Thu May 16 17:46:05 2019 +0200
+++ b/src/screen.js Wed May 01 21:58:01 2019 +0200
@@ -1355,8 +1355,7 @@
}
}.bind(this));
}
- var dfd = jQuery.Deferred();
- prm.then(function(current_record) {
+ return prm.then(function(current_record) {
if (path && current_record && current_record.id) {
path.splice(-1, 1,
[path[path.length - 1][0], current_record.id]);
@@ -1364,12 +1363,7 @@
return this.group.get_by_path(path).then(function(record) {
this.set_current_record(record);
}.bind(this));
- }.bind(this)).then(function() {
- this.display().always(dfd.resolve);
- }.bind(this), function() {
- this.display().always(dfd.reject);
- }.bind(this));
- return dfd.promise();
+ }.bind(this)).always(this.display.bind(this));
},
set_cursor: function(new_, reset_view) {
if (!this.current_view) {