From 236dcb4644ac1b619f85f9b21c73889e88cc456b Mon Sep 17 00:00:00 2001 From: Ludovic Stephan Date: Fri, 31 Mar 2017 18:10:06 -0300 Subject: [PATCH] Tweaks to UserDialog --- kfet/static/kfet/js/kfet.js | 26 ++++++++++++++++---------- kfet/templates/kfet/kpsul.html | 23 ++++++++++++++++++----- 2 files changed, 34 insertions(+), 15 deletions(-) diff --git a/kfet/static/kfet/js/kfet.js b/kfet/static/kfet/js/kfet.js index 5e49065d..0fa6e06a 100644 --- a/kfet/static/kfet/js/kfet.js +++ b/kfet/static/kfet/js/kfet.js @@ -185,11 +185,16 @@ class UserDialog { $.extend(this, this.constructor.defaults, data); } - open(callback, errors, next_focus) { + 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: errors + this.content, + content: pre_content + this.content + post_content, backgroundDismiss: true, animation:'top', closeAnimation:'bottom', @@ -213,7 +218,7 @@ class UserDialog { } }); }, - onClose: function() { if (next_focus) { this._lastFocused = next_focus; } } + onClose: function() { if (settings.next_focus) { this._lastFocused = settings.next_focus; } } }); } } @@ -287,24 +292,25 @@ function api_with_auth(settings, password) { }) .done(function(data) { on_success(data); - window.lock = 0 ; }) .fail(function($xhr) { var response = $xhr.responseJSON; switch ($xhr.status) { case 403: - authDialog.open( - function(password) { + authDialog.open({ + callback: function(password) { api_with_auth(settings, password) }, - getErrorsHtml(response), - settings.next_focus - ); + pre_content: getErrorsHtml(response), + next_focus: settings.next_focus, + }); break; case 400: on_400(response); break; } - window.lock = 0 ; + }) + .always(function() { + window.lock = 0; }); } diff --git a/kfet/templates/kfet/kpsul.html b/kfet/templates/kfet/kpsul.html index 61a17ecd..6eeb9e39 100644 --- a/kfet/templates/kfet/kpsul.html +++ b/kfet/templates/kfet/kpsul.html @@ -200,7 +200,10 @@ $(document).ready(function() { callback(); } - commentDialog.open(confirm_callback, '', articleSelect); + commentDialog.open({ + callback: confirm_callback, + next_focus: articleSelect + }); } function resetComment() { @@ -655,7 +658,10 @@ $(document).ready(function() { } var next_focus = articleSelect.val() ? articleNb : articleSelect ; - depositDialog.open(callback, '', next_focus); + depositDialog.open({ + callback: callback, + next_focus: next_focus, + }); } function askWithdraw() { @@ -667,11 +673,14 @@ $(document).ready(function() { function callback(amount) { if (!$.isNumeric(amount) || amount <= 0) return false; - addWithdraw(amount, is_checkout); + addWithdraw(amount); } - withdrawDialog.open(callback, '', articleSelect); + withdrawDialog.open({ + callback: callback, + next_focus: articleSelect + }); } // Event @@ -814,7 +823,11 @@ $(document).ready(function() { }); } - addcostDialog.open(callback, errors, kpsul.account_manager); + addcostDialog.open({ + callback: callback, + pre_content: errors, + next_focus: kpsul.account_manager, + }); }