Fire callback also on pure closing of prompt dialog

Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
Morris Jobke 2016-12-09 10:47:40 +01:00
parent 88d90066ba
commit ec52286a0f
No known key found for this signature in database
GPG Key ID: 9CE5ED29E7FCD38A
1 changed files with 15 additions and 1 deletions

View File

@ -124,6 +124,14 @@ var OCdialogs = {
modal = false;
}
$('body').append($dlg);
// wrap callback in _.once():
// only call callback once and not twice (button handler and close
// event) but call it for the close event, if ESC or the x is hit
if (callback !== undefined) {
callback = _.once(callback);
}
var buttonlist = [{
text : t('core', 'No'),
click: function () {
@ -147,7 +155,13 @@ var OCdialogs = {
$(dialogId).ocdialog({
closeOnEscape: true,
modal : modal,
buttons : buttonlist
buttons : buttonlist,
close : function() {
// callback is already fired if Yes/No is clicked directly
if (callback !== undefined) {
callback(false, input.val());
}
}
});
input.focus();
OCdialogs.dialogsCounter++;