diff --git a/kfet/static/kfet/js/kfet.js b/kfet/static/kfet/js/kfet.js index 0fb5c0e1..7a32ce15 100644 --- a/kfet/static/kfet/js/kfet.js +++ b/kfet/static/kfet/js/kfet.js @@ -89,8 +89,60 @@ function isValidTrigramme(trigramme) { return trigramme.match(pattern); } +/** + * Dialogs with user via jconfirm + */ + +class UserDialog { + + static get default_data() { + return {'title': '', 'content': '', 'callback_as_dict': false}; + } + + constructor(data) { + $.extend(this, this.constructor.default_data, data); + } + + open(callback, errors, next_focus) { + var that = this; + $.confirm({ + title: this.title, + content: errors + this.content, + backgroundDismiss: true, + animation:'top', + 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(); + }); + return callback(inputs); + } else { + var input_values = this.$content.find('input').map(function () { + return $(this).val(); + }).get(); + return callback.apply(null, input_values); + } + }, + onOpen: function() { + var that = this + this.$content.find('input').on('keydown', function(e) { + if (e.keyCode == 13) { + e.preventDefault(); + that.$confirmButton.click(); + } + }); + }, + onClose: function() { if (next_focus) { this._lastFocused = next_focus; } } + }); + } +} + function getErrorsHtml(data) { var content = ''; + console.log(data); if ('operation_group' in data['errors']) { content += 'Général'; content += '