/* * @Author: printempw * @Date: 2016-07-22 14:02:44 * @Last Modified by: printempw * @Last Modified time: 2017-01-08 16:07:24 */ 'use strict'; $(document).ready(function() { $('input').iCheck({ checkboxClass: 'icheckbox_square-blue' }); }); $('#layout-skins-list [data-skin]').click(function(e) { e.preventDefault(); var skin_name = $(this).data('skin'); $('body').removeClass(current_skin).addClass(skin_name); current_skin = skin_name; }); $('#color-submit').click(function() { $.ajax({ type: "POST", url: "./customize?action=color", dataType: "json", data: { "color_scheme": current_skin }, success: function(json) { if (json.errno == 0) toastr.success(json.msg); else toastr.warning(json.msg); }, error: showAjaxError }); }); function changeUserEmail(uid) { var email = prompt(trans('admin.newUserEmail')); if (!email) return; $.ajax({ type: "POST", url: "./users?action=email", dataType: "json", data: { 'uid': uid, 'email': email }, success: function(json) { if (json.errno == 0) { $($('tr#'+uid+' > td')[1]).html(email); toastr.success(json.msg); } else { toastr.warning(json.msg); } }, error: showAjaxError }); } function changeUserNickName(uid) { var nickname = prompt(trans('admin.newUserNickname')); if (!nickname) return; $.ajax({ type: "POST", url: "./users?action=nickname", dataType: "json", data: { 'uid': uid, 'nickname': nickname }, success: function(json) { if (json.errno == 0) { $($('tr#'+uid+' > td')[2]).html(nickname); toastr.success(json.msg); } else { toastr.warning(json.msg); } }, error: showAjaxError }); } function changeUserPwd(uid) { var password = prompt(trans('admin.newUserPassword')); if (!password) return; $.ajax({ type: "POST", url: "./users?action=password", dataType: "json", data: { 'uid': uid, 'password': password }, success: function(json) { if (json.errno == 0) toastr.success(json.msg); else toastr.warning(json.msg); }, error: showAjaxError }); } function changeUserScore(uid, score) { $.ajax({ type: "POST", url: "./users?action=score", dataType: "json", data: { 'uid': uid, 'score': score }, success: function(json) { if (json.errno == 0) { $('tr#'+uid+' > td > .score').val(score); toastr.success(json.msg); } else { toastr.warning(json.msg); } }, error: showAjaxError }); } function changeBanStatus(uid) { $.ajax({ type: "POST", url: "./users?action=ban", dataType: "json", data: { 'uid': uid }, success: function(json) { if (json.errno == 0) { var object = $('#'+uid).find('a#ban'); var dom = '' + (object.text() == trans('admin.ban') ? trans('admin.unban') : trans('admin.ban')) + ''; object.html(dom); $('#'+uid).find('#permission').text(json.permission == '-1' ? trans('admin.banned') : trans('admin.normal')); toastr.success(json.msg); } else { toastr.warning(json.msg); } }, error: showAjaxError }); } function changeAdminStatus(uid) { $.ajax({ type: "POST", url: "./users?action=admin", dataType: "json", data: { 'uid': uid }, success: function(json) { if (json.errno == 0) { var object = $('#'+uid).find('a#admin'); var dom = '' + (object.text() == trans('admin.setAdmin') ? trans('admin.unsetAdmin') : trans('admin.setAdmin')) + ''; object.html(dom); $('#'+uid).find('#permission').text(json.permission == '1' ? trans('admin.admin') : trans('admin.normal')); toastr.success(json.msg); } else { toastr.warning(json.msg); } }, error: showAjaxError }); } function deleteUserAccount(uid) { if (!window.confirm(trans('admin.deleteUserNotice'))) return; $.ajax({ type: "POST", url: "./users?action=delete", dataType: "json", data: { 'uid': uid }, success: function(json) { if (json.errno == 0) { $('tr#'+uid).remove(); toastr.success(json.msg); } else { toastr.warning(json.msg); } }, error: showAjaxError }); } $('body').on('keypress', '.score', function(event){ if (event.which == 13) { changeUserScore($(this).parent().parent().attr('id'), $(this).val()); } }); $('body').on('change', '#preference', function() { $.ajax({ type: "POST", url: "./players?action=preference", dataType: "json", data: { 'pid': $(this).parent().parent().attr('id'), 'preference': $(this).val() }, success: function(json) { if (json.errno == 0) { toastr.success(json.msg); } else { toastr.warning(json.msg); } }, error: showAjaxError }); }); function changeTexture(pid) { var dom = '
'+trans('admin.downloadCompleted')+'
') console.log("Start extracting"); $.ajax({ url: './update/download?action=extract', type: 'POST', dataType: 'json' }) .done(function(json) { console.log("Package extracted and files are covered"); $('#modal-start-download').modal('toggle'); swal({ type: 'success', html: json.msg }).then(function() { window.location = "../"; }, function(dismiss) { window.location = "../"; }); }) .fail(showAjaxError); } else { $.ajax({ url: './update/download?action=get-file-size', type: 'GET' }) .done(function(json) { progress = (json.size / file_size * 100).toFixed(2); console.log("Progress: "+progress); }) .fail(showAjaxError); } }, 300); }) .fail(showAjaxError); }