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

127 lines
3.8 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: prpr
2016-02-05 22:08:06 +08:00
* @Last Modified time: 2016-02-05 22:01:44
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();
}
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=delete&uname="+uname,
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` 哦');
}
});
}