Use sweetalert2 instead of built-in function

This commit is contained in:
gplane 2017-04-23 11:46:51 +08:00
parent 80f82b4b87
commit 7607beebaf

View File

@ -54,67 +54,75 @@ $('#color-submit').click(function() {
}); });
function changeUserEmail(uid) { function changeUserEmail(uid) {
var email = prompt(trans('admin.newUserEmail')); let dom = $(`tr#${uid} > td:nth-child(2)`);
swal({
if (!email) return; text: trans('admin.newUserEmail'),
showCancelButton: true,
$.ajax({ input: 'text',
type: "POST", inputValue: dom.text()
url: "./users?action=email", }).then(email => {
dataType: "json", $.ajax({
data: { 'uid': uid, 'email': email }, type: "POST",
success: function(json) { url: "./users?action=email",
if (json.errno == 0) { dataType: "json",
$($('tr#'+uid+' > td')[1]).html(email); data: { 'uid': uid, 'email': email },
toastr.success(json.msg); success: json => {
} else { if (json.errno == 0) {
toastr.warning(json.msg); dom.text(email);
} toastr.success(json.msg);
}, } else {
error: showAjaxError toastr.warning(json.msg);
}
},
error: showAjaxError
});
}); });
} }
function changeUserNickName(uid) { function changeUserNickName(uid) {
var nickname = prompt(trans('admin.newUserNickname')); let dom = $(`tr#${uid} > td:nth-child(3)`);
swal({
if (!nickname) return; text: trans('admin.newUserNickname'),
showCancelButton: true,
$.ajax({ input: 'text',
type: "POST", inputValue: dom.text()
url: "./users?action=nickname", }).then(nickname => {
dataType: "json", $.ajax({
data: { 'uid': uid, 'nickname': nickname }, type: "POST",
success: function(json) { url: "./users?action=nickname",
if (json.errno == 0) { dataType: "json",
$($('tr#'+uid+' > td')[2]).html(nickname); data: { 'uid': uid, 'nickname': nickname },
toastr.success(json.msg); success: json => {
} else { if (json.errno == 0) {
toastr.warning(json.msg); dom.text(nickname);
} toastr.success(json.msg);
}, } else {
error: showAjaxError toastr.warning(json.msg);
}
},
error: showAjaxError
});
}); });
} }
function changeUserPwd(uid) { function changeUserPwd(uid) {
var password = prompt(trans('admin.newUserPassword')); swal({
text: trans('admin.newUserPassword'),
if (!password) return; showCancelButton: true,
input: 'password',
$.ajax({ }).then(password => {
type: "POST", return Promise.resolve($.ajax({
url: "./users?action=password", type: "POST",
dataType: "json", url: "./users?action=password",
data: { 'uid': uid, 'password': password }, dataType: "json",
success: function(json) { data: { 'uid': uid, 'password': password }
if (json.errno == 0) }));
toastr.success(json.msg); }).then(json => {
else if (json.errno == 0)
toastr.warning(json.msg); toastr.success(json.msg);
}, else
error: showAjaxError toastr.warning(json.msg);
}); }).catch(error => showAjaxError);
} }
function changeUserScore(uid, score) { function changeUserScore(uid, score) {
@ -182,23 +190,25 @@ function changeAdminStatus(uid) {
} }
function deleteUserAccount(uid) { function deleteUserAccount(uid) {
if (!window.confirm(trans('admin.deleteUserNotice'))) return; swal({
text: trans('admin.deleteUserNotice'),
$.ajax({ type: 'warning',
type: "POST", showCancelButton: true
url: "./users?action=delete", }).then(() => {
dataType: "json", return Promise.resolve($.ajax({
data: { 'uid': uid }, type: "POST",
success: function(json) { url: "./users?action=delete",
if (json.errno == 0) { dataType: "json",
$('tr#'+uid).remove(); data: { 'uid': uid }
toastr.success(json.msg); }))
} else { }).then(json => {
toastr.warning(json.msg); if (json.errno == 0) {
} $('tr#' + uid).remove();
}, toastr.success(json.msg);
error: showAjaxError } else {
}); toastr.warning(json.msg);
}
}).catch(error => showAjaxError);
} }
$('body').on('keypress', '.score', function(event){ $('body').on('keypress', '.score', function(event){
@ -275,45 +285,55 @@ function ajaxChangeTexture(pid) {
} }
function changeOwner(pid) { function changeOwner(pid) {
var uid = prompt(trans('admin.changePlayerOwner')); let dom = $(`#${pid} > td:nth-child(2)`);
swal({
if (!uid) return; text: trans('admin.changePlayerOwner'),
input: 'number',
$.ajax({ inputValue: dom.text(),
type: "POST", showCancelButton: true
url: "./players?action=owner", }).then(uid => {
dataType: "json", $.ajax({
data: { 'pid': pid, 'uid': uid }, type: "POST",
success: function(json) { url: "./players?action=owner",
if (json.errno == 0) { dataType: "json",
$($('#'+pid).children()[1]).text(uid); data: { 'pid': pid, 'uid': uid },
toastr.success(json.msg); success: function (json) {
} else { if (json.errno == 0) {
toastr.warning(json.msg); $($('#' + pid).children()[1]).text(uid);
} toastr.success(json.msg);
}, } else {
error: showAjaxError toastr.warning(json.msg);
}
},
error: showAjaxError
});
}); });
} }
function deletePlayer(pid) { function deletePlayer(pid) {
if (!window.confirm(trans('admin.deletePlayerNotice'))) return; swal({
text: trans('admin.deletePlayerNotice'),
type: 'warning',
showCancelButton: true
}).then(() => {
return Promise.resolve($.ajax({
type: "POST",
url: "./players?action=delete",
dataType: "json",
data: { 'pid': pid },
success: function (json) {
$.ajax({ },
type: "POST", error: showAjaxError
url: "./players?action=delete", }))
dataType: "json", }).then(json => {
data: { 'pid': pid }, if (json.errno == 0) {
success: function(json) { $('tr#' + pid).remove();
if (json.errno == 0) { toastr.success(json.msg);
$('tr#'+pid).remove(); } else {
toastr.success(json.msg); toastr.warning(json.msg);
} else { }
toastr.warning(json.msg); }).catch(error => showAjaxError);
}
},
error: showAjaxError
});
} }
function enablePlugin(name) { function enablePlugin(name) {