163 lines
5.9 KiB
JavaScript
163 lines
5.9 KiB
JavaScript
/*
|
|
* @Author: printempw
|
|
* @Date: 2016-02-04 16:48:42
|
|
* @Last Modified by: printempw
|
|
* @Last Modified time: 2016-04-03 11:42:38
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
function uploadTexture(uname, type) {
|
|
var ply = new Ply({
|
|
el: '<h2>为该用户上传新的 ' + type + ' 材质:</h2>'+
|
|
'<input type="file" id="file" accept="image/png">'+
|
|
'<button id="upload" class="btn btn-primary fw">上传</button>',
|
|
effect: "fade",
|
|
onaction: function(){
|
|
var form_data = new FormData();
|
|
var file = $('#file').get(0).files[0];
|
|
if (file) {
|
|
form_data.append('file', file);
|
|
$.ajax({
|
|
type: 'POST',
|
|
contentType: false,
|
|
url: 'admin_ajax.php?action=upload&type='+type+'&uname='+uname,
|
|
dataType: "json",
|
|
data: form_data,
|
|
processData: false,
|
|
success: function(json) {
|
|
if (json.errno == 0) {
|
|
showAlert("上传成功。");
|
|
// refresh image
|
|
if (type == "steve") $('#'+uname+'-steve').prop('src',
|
|
'../skin/'+uname+'-steve.png?'+Math.round(Math.random() * 1000000));
|
|
if (type == "alex") $('#'+uname+'-alex').prop('src',
|
|
'../skin/'+uname+'-alex.png?'+Math.round(Math.random() * 1000000));
|
|
if (type == "cape") $('#'+uname+'-cape').prop('src',
|
|
'../cape/'+uname+'-.png?'+Math.round(Math.random() * 1000000));
|
|
} else {
|
|
showAlert("上传材质的时候出错啦:\n" + json.msg);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
});
|
|
ply.open();
|
|
}
|
|
|
|
function deleteTexture(uname) {
|
|
var ply = new Ply({
|
|
el: '<h2>选择要删除的 '+uname+' 的当前材质:</h2>'+
|
|
'<label><input id="steve" type="checkbox" checked="">Steve 模型</label>'+
|
|
'<label><input id="alex" type="checkbox" checked="">Alex 模型</label>'+
|
|
'<label><input id="cape" type="checkbox" checked="">披风</label>'+
|
|
'<label style="margin: 6px 0 12px;"><input id="all" type="checkbox" checked="">全部</label>'+
|
|
'<button id="confirm" class="btn btn-primary fw">确定</button>',
|
|
effect: "fade",
|
|
onaction: function(ui) {
|
|
if (ui.state == true) {
|
|
var steve = $('#steve').prop('checked');
|
|
var alex = $('#alex').prop('checked');
|
|
var cape = $('#cape').prop('checked');
|
|
if ($('#all').prop('checked')) {
|
|
steve = alex = cape = true;
|
|
}
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "admin_ajax.php?action=deleteTexture&uname="+uname,
|
|
dataType: "json",
|
|
data: {
|
|
"steve" : steve,
|
|
"alex" : alex,
|
|
"cape" : cape
|
|
},
|
|
success: function(json) {
|
|
if (json.errno == 0) {
|
|
showAlert(json.msg);
|
|
// remove DOM
|
|
if (steve) $('#' + uname + '-steve').remove();
|
|
if (alex) $('#' + uname + '-alex ').remove();
|
|
if (cape) $('#' + uname + '-cape ').remove();
|
|
} else {
|
|
showAlert(json.msg);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
},
|
|
});
|
|
ply.open();
|
|
}
|
|
|
|
function changePasswd(uname) {
|
|
Ply.dialog("prompt", {
|
|
title: "修改 "+uname+" 的登录密码:",
|
|
form: { passwd: "新的密码" }
|
|
}).done(function(ui){
|
|
var passwd = ui.data.passwd;
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "admin_ajax.php?action=change&uname="+uname,
|
|
dataType: "json",
|
|
data: { "passwd": passwd },
|
|
success: function(json) {
|
|
if (json.errno == 0) {
|
|
showAlert(json.msg);
|
|
} else {
|
|
showAlert(json.msg);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function deleteAccount(uname) {
|
|
Ply.dialog("prompt", {
|
|
title: "确定要删除 "+uname+"?此操作不可恢复。",
|
|
}).done(function(ui){
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "admin_ajax.php?action=deleteAccount&uname="+uname,
|
|
dataType: "json",
|
|
success: function(json) {
|
|
if (json.errno == 0) {
|
|
showAlert(json.msg, function(){
|
|
location.reload();
|
|
});
|
|
} else {
|
|
showAlert(json.msg);
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
|
|
function changeModel(uname) {
|
|
Ply.dialog("prompt", {
|
|
title: "修改 "+uname+" 的优先皮肤模型:",
|
|
form: { text: "输入 `slim` 或者 `default`" }
|
|
}).done(function(ui){
|
|
var model = ui.data.text;
|
|
if (model == 'slim'| model == 'default') {
|
|
$.ajax({
|
|
type: "POST",
|
|
url: "admin_ajax.php?action=model&uname="+uname,
|
|
data: { "model": ui.data.text },
|
|
dataType: "json",
|
|
success: function(json) {
|
|
if (json.errno == 0) {
|
|
showAlert(json.msg, function(){
|
|
location.reload();
|
|
});
|
|
} else {
|
|
showAlert(json.msg);
|
|
}
|
|
}
|
|
});
|
|
} else {
|
|
showAlert('只能输入 `slim` 或者 `default` 哦');
|
|
}
|
|
});
|
|
}
|