diff --git a/kfet/static/kfet/css/jconfirm-kfet.css b/kfet/static/kfet/css/jconfirm-kfet.css index 0bd53ab7..6c27f77c 100644 --- a/kfet/static/kfet/css/jconfirm-kfet.css +++ b/kfet/static/kfet/css/jconfirm-kfet.css @@ -71,14 +71,19 @@ .jconfirm .capslock .glyphicon { position: absolute; + display:none; padding: 10px; right: 0px; top: 15px; font-size: 30px; - display: none ; margin-left: 60px !important; } +.capslock_on .capslock .glyphicon{ + display: inline-block !important; +} + + .jconfirm .capslock input { padding-right: 50px; padding-left: 50px; diff --git a/kfet/static/kfet/js/kfet.js b/kfet/static/kfet/js/kfet.js index cf120fd4..b30772a9 100644 --- a/kfet/static/kfet/js/kfet.js +++ b/kfet/static/kfet/js/kfet.js @@ -124,8 +124,33 @@ $(document).ready(function() { } }); } + }); +/* + * Capslock management + */ + +window.capslock = -1; +$(document).on('keypress', function(e) { + var s = String.fromCharCode(e.which); + if ((s.toUpperCase() === s && s.toLowerCase() !== s && !e.shiftKey)|| //caps on, shift off + (s.toUpperCase() !== s && s.toLowerCase() === s && e.shiftKey)) { //caps on, shift on + $('body').addClass('capslock_on') + } else if ((s.toLowerCase() === s && s.toUpperCase() !== s && !e.shiftKey)|| //caps off, shift off + (s.toLowerCase() !== s && s.toUpperCase() === s && e.shiftKey)) { //caps off, shift on + $('body').removeClass('capslock_on') + } +}); + +$(document).on('keydown', function(e) { + if (e.which == 20) { + $('body').toggleClass('capslock_on') + } +}); + + + function dateUTCToParis(date) { return moment.tz(date, 'UTC').tz('Europe/Paris'); } @@ -146,6 +171,58 @@ function isValidTrigramme(trigramme) { return trigramme.match(pattern); } +/** + * Dialogs with user via jconfirm + */ + +class UserDialog { + + static get defaults() { + return {'title': '', 'content': ''}; + } + + constructor(data) { + $.extend(this, this.constructor.defaults, data); + } + + open(settings) { + // Arg management + var pre_content = settings.pre_content || ''; + var post_content = settings.post_content || ''; + var callback = settings.callback || $.noop; + + var that = this; + $.confirm({ + title: this.title, + content: pre_content + this.content + post_content, + backgroundDismiss: true, + animation:'top', + closeAnimation:'bottom', + keyboardEnabled: true, + confirm: function() { + var inputs = {}; + this.$content.find('input').each(function () { + inputs[$(this).attr('name')] = $(this).val(); + }); + if (Object.keys(inputs).length > 1) + return callback(inputs); + else + return callback(inputs[Object.keys(inputs)[0]]); + }, + 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 (settings.next_focus) { this._lastFocused = settings.next_focus; } } + }); + } +} + function getErrorsHtml(data) { var content = ''; if ('operation_group' in data['errors']) { @@ -185,55 +262,55 @@ function getErrorsHtml(data) { return content; } -function requestAuth(data, callback, focus_next = null) { - var content = getErrorsHtml(data); - content += '