WIP: Aureplop/kpsul js refactor #501
2 changed files with 34 additions and 15 deletions
|
@ -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;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue