From 6be2f086df4cb9a9d602e19dc23c720b3e12c047 Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Sun, 26 Mar 2017 00:20:28 -0300 Subject: [PATCH 01/13] Add generic functions for confirm dialogs --- kfet/static/kfet/js/kfet.js | 134 ++++++++++++++++++++++++++++-------- 1 file changed, 106 insertions(+), 28 deletions(-) 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 += '