blessing-skin-server/assets/js/admin.utils.js

164 lines
5.3 KiB
JavaScript
Raw Normal View History

2016-02-04 17:21:05 +08:00
/*
* @Author: prpr
* @Date: 2016-02-04 16:48:42
* @Last Modified by: printempw
* @Last Modified time: 2016-03-06 15:23:40
2016-02-04 17:21:05 +08:00
*/
'use strict';
function uploadSkin(uname) {
Ply.dialog("confirm", {
2016-02-05 22:08:06 +08:00
text: "更改该用户对应哪个模型的皮肤?",
ok: "Steve",
cancel: "Alex"
}).done(function(){
uploadTexture(uname, 'steve');
}).fail(function(){
uploadTexture(uname, 'alex');
});
}
2016-02-04 18:35:14 +08:00
function uploadTexture(uname, type) {
2016-02-04 17:21:05 +08:00
var ply = new Ply({
2016-02-05 22:08:06 +08:00
el: '<h2>为该用户上传新的 '+type+':</h2>'+
2016-02-04 18:35:14 +08:00
'<input type="file" id="file" accept="image/png">'+
2016-02-05 22:08:06 +08:00
'<button id="upload" class="pure-button pure-button-primary fw">上传</button>',
2016-02-04 17:21:05 +08:00
effect: "fade",
2016-02-04 18:35:14 +08:00
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) {
2016-02-05 22:08:06 +08:00
showAlert("上传成功。", function(){
2016-02-04 18:35:14 +08:00
location.reload();
});
} else {
2016-02-05 22:08:06 +08:00
showAlert("上传材质的时候出错啦:\n" + json.msg);
2016-02-04 18:35:14 +08:00
}
}
});
}
},
2016-02-04 17:21:05 +08:00
});
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="pure-button pure-button-primary fw">确定</button>',
effect: "fade",
onaction: function() {
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);
} else {
showAlert(json.msg);
}
}
});
},
});
ply.open();
}
2016-02-04 17:21:05 +08:00
2016-02-04 18:35:14 +08:00
function changePasswd(uname) {
2016-02-04 17:21:05 +08:00
Ply.dialog("prompt", {
2016-02-05 22:08:06 +08:00
title: "修改 "+uname+" 的登录密码:",
form: { passwd: "新的密码" }
2016-02-04 17:21:05 +08:00
}).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);
}
}
});
});
}
2016-02-04 18:35:14 +08:00
function deleteAccount(uname) {
2016-02-04 17:21:05 +08:00
Ply.dialog("prompt", {
2016-02-05 22:08:06 +08:00
title: "确定要删除 "+uname+"?此操作不可恢复。",
2016-02-04 17:21:05 +08:00
}).done(function(ui){
$.ajax({
type: "POST",
url: "admin_ajax.php?action=deleteAccount&uname="+uname,
2016-02-04 17:21:05 +08:00
dataType: "json",
success: function(json) {
if (json.errno == 0) {
showAlert(json.msg, function(){
location.reload();
});
2016-02-04 17:21:05 +08:00
} else {
showAlert(json.msg);
}
}
});
});
}
2016-02-04 18:35:14 +08:00
function changeModel(uname) {
Ply.dialog("prompt", {
2016-02-05 22:08:06 +08:00
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 {
2016-02-05 22:08:06 +08:00
showAlert('只能输入 `slim` 或者 `default` 哦');
}
});
}