Disable buttons when clicked

and enable them after the callback is complete.

issue7148
review37131002
This commit is contained in:
Cédric Krier committed 2018-03-27 10:49:21 +02:00
1 parent 0abda1bfd1
commit 9f80bb9b4f
4 files changed
+35 -30

No files matched your search

+5 -5
View File
@@ -1614,7 +1614,7 @@
(attributes.states || {})).pre_validate || [];
prms.push(record.validate(fields, false, domain));
}
jQuery.when.apply(jQuery, prms).then(function() {
return jQuery.when.apply(jQuery, prms).then(function() {
var record;
for (var i = 0; i < selected_records.length; i++) {
record = selected_records[i];
@@ -1632,12 +1632,12 @@
if (attributes.confirm) {
prm = Sao.common.sur.run(attributes.confirm);
}
prm.then(function() {
return prm.then(function() {
var record = this.current_record;
if (attributes.type === 'instance') {
var args = record.expr_eval(attributes.change || []);
var values = record._get_on_change_args(args);
record.model.execute(attributes.name, [values],
return record.model.execute(attributes.name, [values],
this.context()).then(function(changes) {
record.set_on_change(changes);
record.group.root_group().screens.forEach(
@@ -1646,7 +1646,7 @@
});
});
} else {
record.save(false).done(function() {
return record.save(false).then(function() {
var context = this.context();
context._timestamp = {};
ids = [];
@@ -1656,7 +1656,7 @@
record.get_timestamp());
ids.push(record.id);
}
record.model.execute(attributes.name,
return record.model.execute(attributes.name,
[ids], context).then(process_action.bind(this));
}.bind(this));
}
+26 -17
View File
@@ -218,7 +218,15 @@
'aria-hidden': 'true'
}))
.appendTo(group);
this.buttons[item.id].click(this[item.id].bind(this));
this.buttons[item.id].click(item, function(event) {
var item = event.data;
var button = this.buttons[item.id];
button.prop('disabled', true);
(this[item.id](this) || jQuery.when())
.always(function() {
button.prop('disabled', false);
});
}.bind(this));
};
this.menu_def().forEach(add_button.bind(this));
this.status_label = jQuery('<span/>', {
@@ -588,10 +596,10 @@
},
new_: function() {
if (!Sao.common.MODELACCESS.get(this.screen.model_name).create) {
return;
return jQuery.when();
}
this.modified_save().done(function() {
this.screen.new_().then(function() {
return this.modified_save().then(function() {
return this.screen.new_().then(function() {
this.info_bar.message();
}.bind(this));
// TODO activate_save
@@ -614,7 +622,7 @@
}.bind(this));
},
switch_: function() {
this.modified_save().done(function() {
return this.modified_save().done(function() {
this.screen.switch_view();
}.bind(this));
},
@@ -645,10 +653,10 @@
},
copy: function() {
if (!Sao.common.MODELACCESS.get(this.screen.model_name).create) {
return;
return jQuery.when();
}
this.modified_save().done(function() {
this.screen.copy().then(function() {
return this.modified_save().then(function() {
return this.screen.copy().then(function() {
this.info_bar.message(
Sao.i18n.gettext(
'Working now on the duplicated record(s).'),
@@ -659,7 +667,7 @@
},
delete_: function() {
if (!Sao.common.MODELACCESS.get(this.screen.model_name)['delete']) {
return;
return jQuery.when();
}
var msg;
if (this.screen.current_view.view_type == 'form') {
@@ -667,8 +675,8 @@
} else {
msg = Sao.i18n.gettext('Are you sure to remove those records?');
}
Sao.common.sur.run(msg).done(function() {
this.screen.remove(true, false, true).then(
return Sao.common.sur.run(msg).then(function() {
return this.screen.remove(true, false, true).then(
function() {
this.info_bar.message(
Sao.i18n.gettext('Records removed.'),
@@ -682,14 +690,14 @@
}.bind(this));
},
previous: function() {
this.modified_save().done(function() {
return this.modified_save().then(function() {
this.screen.display_previous();
this.info_bar.message();
// TODO activate_save
}.bind(this));
},
next: function() {
this.modified_save().done(function() {
return this.modified_save().then(function() {
this.screen.display_next();
this.info_bar.message();
// TODO activate_save
@@ -702,6 +710,7 @@
search_entry.focus();
}, 0);
}
return jQuery.when();
},
logs: function() {
var record = this.screen.current_record;
@@ -709,7 +718,7 @@
this.info_bar.message(
Sao.i18n.gettext('You have to select one record.'),
'info');
return;
return jQuery.when();
}
var fields = [
['id', Sao.i18n.gettext('ID:')],
@@ -721,7 +730,7 @@
['write_date', Sao.i18n.gettext('Latest Modification Date:')]
];
this.screen.model.execute('read', [[record.id],
return this.screen.model.execute('read', [[record.id],
fields.map(function(field) {
return field[0];
})], this.screen.context())
@@ -778,12 +787,12 @@
}
}.bind(this);
}.bind(this);
this.modified_save().done(function() {
return this.modified_save().then(function() {
var ids = this.screen.current_view.selected_records().map(
function(record) {
return record.id;
});
this.screen.model.execute('history_revisions',
return this.screen.model.execute('history_revisions',
[ids], this.screen.context())
.then(function(revisions) {
new Sao.Window.Revision(revisions, set_revision(revisions));
+2 -4
View File
@@ -382,11 +382,9 @@ function eval_pyson(value){
button_clicked: function(event) {
var button = event.data;
button.el.prop('disabled', true);
try {
this.screen.button(button.attributes);
} finally {
this.screen.button(button.attributes).always(function() {
button.el.prop('disabled', false);
}
});
},
selected_records: function() {
if (this.screen.current_record) {
+2 -4
View File
@@ -1952,11 +1952,9 @@
return;
}
button.el.prop('disabled', true);
try {
this.screen.button(this.attributes);
} finally {
this.screen.button(this.attributes).always(function() {
button.el.prop('disabled', false);
}
});
}
});