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

View file

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