Better callback management

This commit is contained in:
Ludovic Stephan 2017-03-31 17:49:22 -03:00
parent 08c752f1b3
commit 582cdebaa1
2 changed files with 11 additions and 15 deletions

View file

@ -177,12 +177,12 @@ function isValidTrigramme(trigramme) {
class UserDialog {
static get default_data() {
return {'title': '', 'content': '', 'callback_as_dict': false};
static get defaults() {
return {'title': '', 'content': ''};
}
constructor(data) {
$.extend(this, this.constructor.default_data, data);
$.extend(this, this.constructor.defaults, data);
}
open(callback, errors, next_focus) {
@ -195,18 +195,14 @@ class UserDialog {
closeAnimation:'bottom',
keyboardEnabled: true,
confirm: function() {
if (that.callback_as_dict) {
var inputs = {};
this.$content.find('input').each(function () {
inputs[$(this).attr('name')] = $(this).val();
});
var inputs = {};
this.$content.find('input').each(function () {
inputs[$(this).attr('name')] = $(this).val();
});
if (Object.keys(inputs).length > 1)
return callback(inputs);
} else {
var input_values = this.$content.find('input').map(function () {
return $(this).val();
}).get();
return callback.apply(null, input_values);
}
else
return callback(inputs[Object.keys(inputs)[0]]);
},
onOpen: function() {
var that = this

View file

@ -243,7 +243,7 @@ $(document).ready(function() {
if ('need_comment' in data['errors'])
askComment(performOperations);
else
displayErrors(data);
displayErrors(getErrorsHtml(data));
},
next_focus: articleSelect,
});