Tweaks to UserDialog

This commit is contained in:
Ludovic Stephan 2017-03-31 18:10:06 -03:00
parent 582cdebaa1
commit 236dcb4644
2 changed files with 34 additions and 15 deletions

View file

@ -185,11 +185,16 @@ class UserDialog {
$.extend(this, this.constructor.defaults, data); $.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; var that = this;
$.confirm({ $.confirm({
title: this.title, title: this.title,
content: errors + this.content, content: pre_content + this.content + post_content,
backgroundDismiss: true, backgroundDismiss: true,
animation:'top', animation:'top',
closeAnimation:'bottom', 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) { .done(function(data) {
on_success(data); on_success(data);
window.lock = 0 ;
}) })
.fail(function($xhr) { .fail(function($xhr) {
var response = $xhr.responseJSON; var response = $xhr.responseJSON;
switch ($xhr.status) { switch ($xhr.status) {
case 403: case 403:
authDialog.open( authDialog.open({
function(password) { callback: function(password) {
api_with_auth(settings, password) api_with_auth(settings, password)
}, },
getErrorsHtml(response), pre_content: getErrorsHtml(response),
settings.next_focus next_focus: settings.next_focus,
); });
break; break;
case 400: case 400:
on_400(response); on_400(response);
break; break;
} }
window.lock = 0 ; })
.always(function() {
window.lock = 0;
}); });
} }

View file

@ -200,7 +200,10 @@ $(document).ready(function() {
callback(); callback();
} }
commentDialog.open(confirm_callback, '', articleSelect); commentDialog.open({
callback: confirm_callback,
next_focus: articleSelect
});
} }
function resetComment() { function resetComment() {
@ -655,7 +658,10 @@ $(document).ready(function() {
} }
var next_focus = articleSelect.val() ? articleNb : articleSelect ; var next_focus = articleSelect.val() ? articleNb : articleSelect ;
depositDialog.open(callback, '', next_focus); depositDialog.open({
callback: callback,
next_focus: next_focus,
});
} }
function askWithdraw() { function askWithdraw() {
@ -667,11 +673,14 @@ $(document).ready(function() {
function callback(amount) { function callback(amount) {
if (!$.isNumeric(amount) || amount <= 0) if (!$.isNumeric(amount) || amount <= 0)
return false; return false;
addWithdraw(amount, is_checkout); addWithdraw(amount);
} }
withdrawDialog.open(callback, '', articleSelect); withdrawDialog.open({
callback: callback,
next_focus: articleSelect
});
} }
// Event // 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,
});
} }