Use ES6 destructuring assignment syntax

This commit is contained in:
printempw 2017-07-14 09:34:09 +08:00
parent 3a74329548
commit 52a18195cd
4 changed files with 68 additions and 68 deletions

View File

@ -25,7 +25,7 @@ function addToCloset(tid) {
inputValidator: value => (new Promise((resolve, reject) => { inputValidator: value => (new Promise((resolve, reject) => {
value ? resolve() : reject(trans('skinlib.emptyItemName')); value ? resolve() : reject(trans('skinlib.emptyItemName'));
})) }))
}).then((result) => ajaxAddToCloset(tid, result)); }).then(result => ajaxAddToCloset(tid, result));
}); });
} }

View File

@ -6,6 +6,10 @@
var selectedTextures = []; var selectedTextures = [];
$(document).ready(function () { $(document).ready(function () {
$('input[type=radio]').iCheck({
radioClass: 'iradio_square-blue'
});
if (! window.location.pathname.includes('/user/closet')) if (! window.location.pathname.includes('/user/closet'))
return; return;
@ -13,11 +17,11 @@ $(document).ready(function () {
type: 'GET', type: 'GET',
url: url('/user/closet-data'), url: url('/user/closet-data'),
dataType: 'json' dataType: 'json'
}).then(result => { }).then(({ items, category, total_pages }) => {
renderCloset(result.items, result.category); renderCloset(items, category);
$('#closet-paginator').jqPaginator($.extend({}, $.defaultPaginatorConfig, { $('#closet-paginator').jqPaginator($.extend({}, $.defaultPaginatorConfig, {
totalPages: result.total_pages, totalPages: total_pages,
onPageChange: page => reloadCloset( onPageChange: page => reloadCloset(
$('#skin-category').hasClass('active') ? 'skin' : 'cape', $('#skin-category').hasClass('active') ? 'skin' : 'cape',
page, $('input[name=q]').val() page, $('input[name=q]').val()
@ -43,12 +47,12 @@ $('body').on('click', '.item-body', function () {
type: 'POST', type: 'POST',
url: url(`skinlib/info/${tid}`), url: url(`skinlib/info/${tid}`),
dataType: 'json' dataType: 'json'
}).then(result => { }).then(({ type, hash }) => {
if (result.type == 'cape') { if (type == 'cape') {
MSP.changeCape(url(`textures/${result.hash}`)); MSP.changeCape(url(`textures/${hash}`));
selectedTextures['cape'] = tid; selectedTextures['cape'] = tid;
} else { } else {
MSP.changeSkin(url(`textures/${result.hash}`)); MSP.changeSkin(url(`textures/${hash}`));
selectedTextures['skin'] = tid; selectedTextures['skin'] = tid;
} }
@ -145,15 +149,15 @@ function reloadCloset(category, page, search) {
page: page, page: page,
q: search q: search
} }
}).then(result => { }).then(({ items, category, total_pages }) => {
renderCloset(result.items, result.category); renderCloset(items, category);
let paginator = $('#closet-paginator'); let paginator = $('#closet-paginator');
paginator.attr(`last-${result.category}-page`, page); paginator.attr(`last-${category}-page`, page);
paginator.jqPaginator('option', { paginator.jqPaginator('option', {
currentPage: page, currentPage: page,
totalPages: result.total_pages totalPages: total_pages
}); });
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -174,12 +178,12 @@ function renameClosetItem(tid, oldName) {
url: url('closet/rename'), url: url('closet/rename'),
dataType: 'json', dataType: 'json',
data: { tid: tid, new_name: name } data: { tid: tid, new_name: name }
})).then(result => { })).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
$(`[tid=${tid}]>.item-footer>.texture-name>span`).html(newTextureName); $(`[tid=${tid}]>.item-footer>.texture-name>span`).html(newTextureName);
toastr.success(result.msg); toastr.success(msg);
} else { } else {
toastr.warning(result.msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -194,9 +198,9 @@ function removeFromCloset(tid) {
url: url('closet/remove'), url: url('closet/remove'),
dataType: 'json', dataType: 'json',
data: { tid: tid } data: { tid: tid }
})).then(result => { })).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
swal({ type: 'success', html: result.msg }); swal({ type: 'success', html: msg });
$(`div[tid=${tid}]`).remove(); $(`div[tid=${tid}]`).remove();
@ -209,7 +213,7 @@ function removeFromCloset(tid) {
} }
}); });
} else { } else {
toastr.warning(result.msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -225,16 +229,16 @@ function setAsAvatar(tid) {
url: url('user/profile/avatar'), url: url('user/profile/avatar'),
dataType: 'json', dataType: 'json',
data: { tid: tid } data: { tid: tid }
})).then(result => { })).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
toastr.success(result.msg); toastr.success(msg);
// Refersh avatars // Refersh avatars
$('[alt="User Image"]').each(function () { $('[alt="User Image"]').each(function () {
$(this).prop('src', $(this).attr('src') + '?' + new Date().getTime()); $(this).prop('src', $(this).attr('src') + '?' + new Date().getTime());
}); });
} else { } else {
toastr.warning(result.msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }

View File

@ -51,12 +51,8 @@ $('body').on('change', '#preference', function () {
url: url('user/player/preference'), url: url('user/player/preference'),
dataType: 'json', dataType: 'json',
data: { pid: $(this).attr('pid'), preference: $(this).val() } data: { pid: $(this).attr('pid'), preference: $(this).val() }
}).then(result => { }).then(({ errno, msg }) => {
if (result.errno == 0) { (errno == 0) ? toastr.success(msg) : toastr.warning(msg);
toastr.success(result.msg);
} else {
toastr.warning(result.msg);
}
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
}); });
@ -77,13 +73,13 @@ function changePlayerName(pid, currentPlayerName) {
url: url('user/player/rename'), url: url('user/player/rename'),
dataType: 'json', dataType: 'json',
data: { pid: pid, new_player_name: name } data: { pid: pid, new_player_name: name }
})).then(result => { })).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
swal({ type: 'success', html: result.msg }); swal({ type: 'success', html: msg });
$(`td:contains("${pid}")`).next().html(newPlayerName); $(`td:contains("${pid}")`).next().html(newPlayerName);
} else { } else {
swal({ type: 'error', html: result.msg }); swal({ type: 'error', html: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -127,8 +123,8 @@ function ajaxClearTexture(pid) {
url: url('user/player/texture/clear'), url: url('user/player/texture/clear'),
dataType: 'json', dataType: 'json',
data: data data: data
}).then(result => { }).then(({ errno, msg }) => {
swal({ type: result.errno == 0 ? 'success' : 'error', html: result.msg }); swal({ type: errno == 0 ? 'success' : 'error', html: msg });
$('.modal').modal('hide'); $('.modal').modal('hide');
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -146,14 +142,14 @@ function deletePlayer(pid) {
url: url('user/player/delete'), url: url('user/player/delete'),
dataType: 'json', dataType: 'json',
data: { pid: pid } data: { pid: pid }
})).then(result => { })).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
swal({ swal({
type: 'success', type: 'success',
html: result.msg html: msg
}).then(() => $(`tr#${pid}`).remove()); }).then(() => $(`tr#${pid}`).remove());
} else { } else {
swal({ type: 'error', html: result.msg }); swal({ type: 'error', html: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -164,16 +160,16 @@ function addNewPlayer() {
url: url('user/player/add'), url: url('user/player/add'),
dataType: 'json', dataType: 'json',
data: { player_name: $('#player_name').val() } data: { player_name: $('#player_name').val() }
}).then(result => { }).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
swal({ swal({
type: 'success', type: 'success',
html: result.msg html: msg
}).then(() => location.reload()); }).then(() => location.reload());
$('#modal-add-player').modal('hide'); $('#modal-add-player').modal('hide');
} else { } else {
toastr.warning(result.msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -201,12 +197,12 @@ function setTexture() {
'tid[skin]': skin, 'tid[skin]': skin,
'tid[cape]': cape 'tid[cape]': cape
} }
}).then(result => { }).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
swal({ type: 'success', html: result.msg }); swal({ type: 'success', html: msg });
$('#modal-use-as').modal('hide'); $('#modal-use-as').modal('hide');
} else { } else {
toastr.warning(result.msg); toastr.warning(msg);
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }

View File

@ -18,16 +18,16 @@ function changeNickName() {
url: url('user/profile?action=nickname'), url: url('user/profile?action=nickname'),
dataType: 'json', dataType: 'json',
data: { new_nickname: name } data: { new_nickname: name }
})).then(result => { })).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
$('.nickname').each(function () { $('.nickname').each(function () {
$(this).html(name); $(this).html(name);
}); });
return swal({ type: 'success', html: result.msg }); return swal({ type: 'success', html: msg });
} else { } else {
return swal({ type: 'warning', html: result.msg }); return swal({ type: 'warning', html: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -58,20 +58,20 @@ function changePassword() {
url: url('user/profile?action=password'), url: url('user/profile?action=password'),
dataType: 'json', dataType: 'json',
data: { 'current_password': password, 'new_password': newPasswd } data: { 'current_password': password, 'new_password': newPasswd }
}).then(result => { }).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
return swal({ return swal({
type: 'success', type: 'success',
text: result.msg } text: msg }
).then(() => { ).then(() => {
return logout(); return logout();
}).then(result => { }).then(({ errno }) => {
if (result.errno == 0) { if (errno == 0) {
window.location = url('auth/login'); window.location = url('auth/login');
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} else { } else {
return swal({ type: 'warning', text: result.msg }); return swal({ type: 'warning', text: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -108,20 +108,20 @@ function changeEmail() {
url: url('user/profile?action=email'), url: url('user/profile?action=email'),
dataType: 'json', dataType: 'json',
data: { new_email: newEmail, password: $('#current-password').val() } data: { new_email: newEmail, password: $('#current-password').val() }
})).then(result => { })).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
return swal({ return swal({
type: 'success', type: 'success',
text: result.msg text: msg
}).then(() => { }).then(() => {
return logout(); return logout();
}).then(result => { }).then(({ errno }) => {
if (result.errno == 0) { if (errno == 0) {
window.location = url('auth/login'); window.location = url('auth/login');
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} else { } else {
return swal({ type: 'warning', text: result.msg }); return swal({ type: 'warning', text: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }
@ -138,16 +138,16 @@ function deleteAccount() {
url: url('user/profile?action=delete'), url: url('user/profile?action=delete'),
dataType: 'json', dataType: 'json',
data: { password: password } data: { password: password }
}).then(result => { }).then(({ errno, msg }) => {
if (result.errno == 0) { if (errno == 0) {
return swal({ return swal({
type: 'success', type: 'success',
html: result.msg html: msg
}).then(() => { }).then(() => {
window.location = url('auth/login'); window.location = url('auth/login');
}); });
} else { } else {
return swal({ type: 'warning', html: result.msg }); return swal({ type: 'warning', html: msg });
} }
}).catch(err => showAjaxError(err)); }).catch(err => showAjaxError(err));
} }