changeset 98a0d96e411e in sao:5.2
details: https://hg.tryton.org/sao?cmd=changeset;node=98a0d96e411e
description:
Disable button until handler promise is finished
This ensure that all the widgets have the value of the current record
before
changing the record.
issue8923
review266571003
(grafted from 362d17cf7f042af2cdad3fa18943972c6d69f35a)
diffstat:
src/screen.js | 4 ++--
src/tab.js | 10 ++++++----
src/view/form.js | 43 +++++++++++++++++++++++++++----------------
src/window.js | 36 +++++++++++++++++++++++++-----------
4 files changed, 60 insertions(+), 33 deletions(-)
diffs (309 lines):
diff -r 4c6e13be353d -r 98a0d96e411e src/screen.js
--- a/src/screen.js Sat Dec 28 17:52:30 2019 +0100
+++ b/src/screen.js Sat Dec 28 17:55:47 2019 +0100
@@ -1284,7 +1284,7 @@
this.current_record = this.group[0];
}
this.set_cursor(false, false);
- view.display();
+ return view.display();
},
display_previous: function() {
var view = this.current_view;
@@ -1313,7 +1313,7 @@
this.current_record = this.group[0];
}
this.set_cursor(false, false);
- view.display();
+ return view.display();
},
clear: function() {
this.current_record = null;
diff -r 4c6e13be353d -r 98a0d96e411e src/tab.js
--- a/src/tab.js Sat Dec 28 17:52:30 2019 +0100
+++ b/src/tab.js Sat Dec 28 17:55:47 2019 +0100
@@ -762,8 +762,8 @@
}.bind(this));
},
switch_: function() {
- return this.modified_save().done(function() {
- this.screen.switch_view();
+ return this.modified_save().then(function() {
+ return this.screen.switch_view();
}.bind(this));
},
reload: function(test_modified) {
@@ -847,16 +847,18 @@
},
previous: function() {
return this.modified_save().then(function() {
- this.screen.display_previous();
+ var prm = this.screen.display_previous();
this.info_bar.message();
// TODO activate_save
+ return prm;
}.bind(this));
},
next: function() {
return this.modified_save().then(function() {
- this.screen.display_next();
+ var prm = this.screen.display_next();
this.info_bar.message();
// TODO activate_save
+ return prm;
}.bind(this));
},
search: function() {
diff -r 4c6e13be353d -r 98a0d96e411e src/view/form.js
--- a/src/view/form.js Sat Dec 28 17:52:30 2019 +0100
+++ b/src/view/form.js Sat Dec 28 17:55:47 2019 +0100
@@ -2655,6 +2655,17 @@
'class': 'input-group-btn'
}).appendTo(group);
+ var disable_during = function(callback) {
+ return function(evt) {
+ var button = jQuery(evt.target);
+ button.prop('disabled', true);
+ (callback(evt) || jQuery.when())
+ .always(function() {
+ button.prop('disabled', false);
+ });
+ };
+ };
+
this.but_switch = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
'type': 'button',
@@ -2663,7 +2674,7 @@
'title': Sao.i18n.gettext("Switch"),
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-switch')
).appendTo(buttons);
- this.but_switch.click(this.switch_.bind(this));
+ this.but_switch.click(disable_during(this.switch_.bind(this)));
this.but_previous = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
@@ -2673,7 +2684,7 @@
'title': Sao.i18n.gettext("Previous"),
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-back')
).appendTo(buttons);
- this.but_previous.click(this.previous.bind(this));
+ this.but_previous.click(disable_during(this.previous.bind(this)));
this.label = jQuery('<span/>', {
'class': 'badge',
@@ -2689,7 +2700,7 @@
'title': Sao.i18n.gettext("Next"),
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-forward')
).appendTo(buttons);
- this.but_next.click(this.next.bind(this));
+ this.but_next.click(disable_during(this.next.bind(this)));
if (attributes.add_remove) {
this.wid_text = jQuery('<input/>', {
@@ -2711,7 +2722,7 @@
'title': Sao.i18n.gettext("Add"),
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-add')
).appendTo(buttons);
- this.but_add.click(this.add.bind(this));
+ this.but_add.click(disable_during(this.add.bind(this)));
this.but_remove = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
@@ -2721,7 +2732,7 @@
'title': Sao.i18n.gettext("Remove"),
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-remove')
).appendTo(buttons);
- this.but_remove.click(this.remove.bind(this));
+ this.but_remove.click(disable_during(this.remove.bind(this)));
}
this.but_new = jQuery('<button/>', {
@@ -2732,7 +2743,7 @@
'title': Sao.i18n.gettext("New"),
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-create')
).appendTo(buttons);
- this.but_new.click(this.new_.bind(this));
+ this.but_new.click(disable_during(this.new_.bind(this)));
this.but_open = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
@@ -2742,7 +2753,7 @@
'title': Sao.i18n.gettext("Open"),
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-open')
).appendTo(buttons);
- this.but_open.click(this.open.bind(this));
+ this.but_open.click(disable_during(this.open.bind(this)));
this.but_del = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
@@ -2752,7 +2763,7 @@
'title': Sao.i18n.gettext("Delete"),
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-delete')
).appendTo(buttons);
- this.but_del.click(this.delete_.bind(this));
+ this.but_del.click(disable_during(this.delete_.bind(this)));
this.but_undel = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
@@ -2762,7 +2773,7 @@
'title': Sao.i18n.gettext("Undelete"),
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-undo')
).appendTo(buttons);
- this.but_undel.click(this.undelete.bind(this));
+ this.but_undel.click(disable_during(this.undelete.bind(this)));
this.content = jQuery('<div/>', {
'class': this.class_ + '-content panel-body'
@@ -3055,7 +3066,7 @@
}.bind(this));
},
open: function(event_) {
- this.edit();
+ return this.edit();
},
delete_: function(event_) {
if (!Sao.common.MODELACCESS.get(this.screen.model_name)['delete'])
{
@@ -3067,23 +3078,23 @@
this.screen.unremove();
},
previous: function(event_) {
- this.validate().done(function() {
- this.screen.display_previous();
+ return this.validate().then(function() {
+ return this.screen.display_previous();
}.bind(this));
},
next: function(event_) {
- this.validate().done(function() {
- this.screen.display_next();
+ return this.validate().then(function() {
+ return this.screen.display_next();
}.bind(this));
},
switch_: function(event_) {
- this.screen.switch_view();
+ return this.screen.switch_view();
},
edit: function() {
if (!Sao.common.MODELACCESS.get(this.screen.model_name).read) {
return;
}
- this.validate().done(function() {
+ return this.validate().then(function() {
var record = this.screen.current_record;
if (record) {
var win = new Sao.Window.Form(this.screen, function() {},
diff -r 4c6e13be353d -r 98a0d96e411e src/window.js
--- a/src/window.js Sat Dec 28 17:52:30 2019 +0100
+++ b/src/window.js Sat Dec 28 17:55:47 2019 +0100
@@ -135,13 +135,25 @@
}).appendTo(group);
var access =
Sao.common.MODELACCESS.get(this.screen.model_name);
+ var disable_during = function(callback) {
+ return function(evt) {
+ var button = jQuery(evt.target);
+ button.prop('disabled', true);
+ (callback(evt) || jQuery.when())
+ .always(function() {
+ button.prop('disabled', false);
+ });
+ };
+ };
+
this.but_switch = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
'type': 'button',
'aria-label': Sao.i18n.gettext('Switch')
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-switch')
).appendTo(buttons);
- this.but_switch.click(this.switch_.bind(this));
+ this.but_switch.click(
+ disable_during(this.switch_.bind(this)));
this.but_previous = jQuery('<button/>', {
'class': 'btn btn-default btn-sm',
@@ -149,7 +161,8 @@
'aria-label': Sao.i18n.gettext('Previous')
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-back')
).appendTo(buttons);
- this.but_previous.click(this.previous.bind(this));
+ this.but_previous.click(
+ disable_during(this.previous.bind(this)));
this.label = jQuery('<span/>', {
'class': 'badge'
@@ -163,7 +176,7 @@
'aria-label': Sao.i18n.gettext('Next')
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-forward')
).appendTo(buttons);
- this.but_next.click(this.next.bind(this));
+ this.but_next.click(disable_during(this.next.bind(this)));
if (this.domain) {
this.wid_text.show();
@@ -174,7 +187,7 @@
'aria-label': Sao.i18n.gettext('Add')
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-add')
).appendTo(buttons);
- this.but_add.click(this.add.bind(this));
+ this.but_add.click(disable_during(this.add.bind(this)));
this.but_add.prop('disabled', !access.read || readonly);
this.but_remove = jQuery('<button/>', {
@@ -183,7 +196,8 @@
'aria-label': Sao.i18n.gettext('Remove')
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-remove')
).appendTo(buttons);
- this.but_remove.click(this.remove.bind(this));
+ this.but_remove.click(
+ disable_during(this.remove.bind(this)));
this.but_remove.prop('disabled', !access.read || readonly);
}
@@ -193,7 +207,7 @@
'aria-label': Sao.i18n.gettext('New')
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-create')
).appendTo(buttons);
- this.but_new.click(this.new_.bind(this));
+ this.but_new.click(disable_during(this.new_.bind(this)));
this.but_new.prop('disabled', !access.create || readonly);
this.but_del = jQuery('<button/>', {
@@ -202,7 +216,7 @@
'aria-label': Sao.i18n.gettext('Delete')
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-delete')
).appendTo(buttons);
- this.but_del.click(this.delete_.bind(this));
+ this.but_del.click(disable_during(this.delete_.bind(this)));
this.but_del.prop('disabled', !access['delete'] || readonly);
this.but_undel = jQuery('<button/>', {
@@ -211,7 +225,7 @@
'aria-label': Sao.i18n.gettext('Undelete')
}).append(Sao.common.ICONFACTORY.get_icon_img('tryton-undo')
).appendTo(buttons);
- this.but_undel.click(this.undelete.bind(this));
+ this.but_undel.click(disable_during(this.undelete.bind(this)));
this.but_undel.prop('disabled', !access['delete'] || readonly);
this.screen.message_callback = this.record_label.bind(this);
@@ -308,13 +322,13 @@
this.screen.unremove();
},
previous: function() {
- this.screen.display_previous();
+ return this.screen.display_previous();
},
next: function() {
- this.screen.display_next();
+ return this.screen.display_next();
},
switch_: function() {
- this.screen.switch_view();
+ return this.screen.switch_view();
},
response: function(response_id) {
var result;