Refactor: rewrite most script in admin page

1. Using ES6 & Arrow function
2. Make the shit-liked code in google js standard
nimaqu_dev
SukkaW 8 years ago
parent c8c75c2592
commit d7e0edb9e4

@ -1,17 +1,5 @@
{include file='admin/main.tpl'}
<main class="content">
<div class="content-header ui-content-header">
<div class="container">
@ -110,30 +98,17 @@
</main>
{include file='admin/footer.tpl'}
<script>
function randomWord() {
return Math.random().toString(36).substr(2);
}
var $$ = document;
let randomWord = () => Math.random().toString(36).substr(2);
{include file='table/js_1.tpl'}
function submitCoupon(code) {
let submitCoupon = code => {
$.ajax({
type: "POST",
url: "/admin/coupon",
@ -141,40 +116,40 @@ function submitCoupon(code) {
data: {
// prefix: $("#prefix").val(),
prefix: code,
credit: $("#credit").val(),
shop: $("#shop").val(),
onetime: $("#count").val(),
expire: $("#expire").val()
credit: $$.getElementById('credit').value,
shop: $$.getElementById('shop').value,
onetime: $$.getElementById('count').value,
expire: $$.getElementById('expire').value,
},
success: function (data) {
success: data => {
if (data.ret) {
$("#result").modal();
$("#msg").html(data.msg);
$$.getElementById('msg').innerHTML = data.msg;
window.setTimeout("location.href='/admin/coupon'", {$config['jump_delay']});
}
// window.location.reload();
},
error: function (jqXHR) {
error: jqXHR => {
alert("发生错误:" + jqXHR.status);
}
})
}
$(document).ready(function () {
window.addEventListener('load', () => {
{include file='table/js_2.tpl'}
$("#coupon").click(function () {
var couponCode = $("#prefix").val();
$$.getElementById('coupon').addEventListener('click', () => {
let couponCode = $$.getElementById('prefix').value;
submitCoupon(couponCode);
})
})
$("#coupon-random").click(function () {
var couponCode = randomWord();
$$.getElementById('coupon-random').addEventListener('click', () => {
let couponCode = randomWord();
submitCoupon(couponCode);
})
$("#coupon-prefix-random").click(function () {
var couponCode = $("#prefix").val().concat(randomWord());
$$.getElementById('coupon-random').addEventListener('click', () => {
let couponCode = $$.getElementById('prefix').value.concat(randomWord());
submitCoupon(couponCode);
})

@ -1,11 +1,5 @@
{include file='admin/main.tpl'}
<main class="content">
<div class="content-header ui-content-header">
<div class="container">
@ -38,7 +32,7 @@
<div id="check_chart" style="height: 300px; width: 100%;"></div>
<script src="//cdn.jsdelivr.net/gh/YihanH/canvasjs.js@v2.2/canvasjs.min.js"></script>
<script type="text/javascript">
<script>
var chart = new CanvasJS.Chart("check_chart",
{
title:{
@ -79,29 +73,28 @@
chart.render();
function chartRender(chart){
chart.render();
chart.ctx.shadowBlur = 8;
chart.ctx.shadowOffsetX = 4;
chart.ctx.shadowColor = "black";
chart.render();
chart.ctx.shadowBlur = 8;
chart.ctx.shadowOffsetX = 4;
chart.ctx.shadowColor = "black";
for (var i = 0; i < chart.plotInfo.plotTypes.length; i++) {
var plotType = chart.plotInfo.plotTypes[i];
for (var j = 0; j < plotType.plotUnits.length; j++) {
var plotUnit = plotType.plotUnits[j];
//For Column Chart
if (plotUnit.type === "doughnut"){
chart.renderDoughnut(plotUnit);
}
//For Bar Chart
else if (plotUnit.type === "bar"){
chart.renderBar(plotUnit);
}
}
}
chart.ctx.shadowBlur = 0;
chart.ctx.shadowOffsetX = 0;
chart.ctx.shadowColor = "transparent";
}
for (let i in chart.plotInfo.plotTypes) {
let plotType = chart.plotInfo.plotTypes[i];
for (let j in plotType.plotUnits) {
let plotUnit = plotType.plotUnits[j];
if (plotUnit.type === "doughnut") {
// For Column Chart
chart.renderDoughnut(plotUnit);
} else if (plotUnit.type === "bar") {
// For Bar Chart
chart.renderBar(plotUnit);
}
}
}
chart.ctx.shadowBlur = 0;
chart.ctx.shadowOffsetX = 0;
chart.ctx.shadowColor = "transparent";
}
</script>
</div>
@ -295,15 +288,4 @@
{include file='admin/footer.tpl'}

@ -1,10 +1,4 @@
{include file='admin/main.tpl'}
{include file='admin/main.tpl'}
<main class="content">
<div class="content-header ui-content-header">
@ -76,50 +70,42 @@
</main>
{include file='admin/footer.tpl'}
<script>
var document = $$;
{include file='table/js_1.tpl'}
$("#invite").click(function () {
$$.getElementById('invite').addEventListener('click', () => {
$.ajax({
type: "POST",
url: "/admin/invite",
dataType: "json",
data: {
prefix: $("#prefix").val(),
uid: $("#uid").val(),
num: $("#num").val()
prefix: $$.getElementById('invite').value,
uid: $$.getElementById('uid').value,
num: $$.getElementById('num').value,
},
success: function (data) {
success: data => {
if (data.ret) {
$("#result").modal();
$("#msg").html(data.msg);
window.setTimeout("location.href='/admin/invite'", {$config['jump_delay']});
}
else
{
$("#result").modal();
$("#msg").html(data.msg+"。");
}
$$.getElementById('msg').innerHTML = data.msg;
window.setTimeout("location.href='/admin/invite'", {$config['jump_delay']} );
} else {
$("#result").modal();
$$.getElementById('msg').innerHTML = data.msg;
}
// window.location.reload();
},
error: function (jqXHR) {
error: jqXHR => {
alert("发生错误:" + jqXHR.status);
}
})
});
})
$(document).ready(function(){
window.addEventListener('load', () => {
{include file='table/js_2.tpl'}
});
</script>

@ -113,53 +113,60 @@
<script>
$(document).ready(function () {
function submit() {
if (document.getElementById('AliPay_Status').checked) var AliPay_Status = 1;
else var AliPay_Status = 0;
if (document.getElementById('WxPay_Status').checked) var WxPay_Status = 1;
else var WxPay_Status = 0;
$.ajax({
type: "POST",
url: "/admin/saveConfig",
dataType: "json",
data: {
AliPay_Status: AliPay_Status,
WxPay_Status: WxPay_Status,
Notice_EMail: $("#Notice_EMail").val(),
AliPay_QRcode: $("#AliPay_QRcode").val(),
AliPay_Cookie: $("#AliPay_Cookie").val(),
WxPay_Url: $("#WxPay_Url").val(),
WxPay_QRcode: $("#WxPay_QRcode").val(),
WxPay_Cookie: $("#WxPay_Cookie").val(),
Pay_Price: $("#Pay_Price").val()
},
success: function (data) {
if (data.ret) {
$("#result").modal();
$("#msg").html(data.msg);
window.setTimeout("location.reload()", {$config['jump_delay']});
} else {
$("#msg-error").hide(10);
$("#msg-error").show(100);
$("#msg-error-p").html(data.msg);
}
},
error: function (jqXHR) {
var $$ = document;
window.addEventListener('load', () => {
function submit() {
if ($$.getElementById('AliPay_Status').checked) {
var AliPay_Status = 1;
} else {
var AliPay_Status = 0;
}
if ($$.getElementById('WxPay_Status').checked) {
var WxPay_Status = 1
} else {
var WxPay_Status = 0
};
$.ajax({
type: "POST",
url: "/admin/saveConfig",
dataType: "json",
data: {
AliPay_Status,
WxPay_Status,
Notice_EMail: $$.getElementById('Notice_EMail').value,
AliPay_QRcode: $$.getElementById('AliPay_QRcode').value,
AliPay_Cookie: $$.getElementById('AliPay_Cookie').value,
WxPay_Url: $$.getElementById('WxPay_Url').value,
WxPay_QRcode: $$.getElementById('WxPay_QRcode').value,
WxPay_Cookie: $$.getElementById('WxPay_Cookie').value,
Pay_Price: $$.getElementById('Pay_Price').value,
},
success: data => {
if (data.ret) {
$("#result").modal();
$("#msg").html(data.msg + " 发生错误了。");
$$.getElementById('msg').innerHTML = data.msg;
window.setTimeout("location.reload()", {$config['jump_delay']});
} else {
$("#msg-error").hide(10);
$("#msg-error").show(100);
$$.getElementById('msg-error-p').innerHTML = data.msg;
}
});
}
$("html").keydown(function (event) {
if (event.keyCode == 13) {
login();
},
error: jqXHR => {
$("#result").modal();
$$.getElementById('msg').innerHTML = `${data.msg}发生错误了。`;
}
});
$("#submit").click(function () {
submit();
});
}
$("html").keydown(event => {
if (event.keyCode == 13) {
login();
}
});
$$.getElementById('submit').addEventListener('click', submit);
})
})
</script>

@ -1,10 +1,4 @@
{include file='admin/main.tpl'}
{include file='admin/main.tpl'}
<main class="content">
<div class="content-header ui-content-header">
@ -41,14 +35,6 @@
</main>
{include file='admin/footer.tpl'}
<script>
@ -56,7 +42,7 @@
{include file='table/js_1.tpl'}
$(document).ready(function(){
window.addEventListener('load', () => {
{include file='table/js_2.tpl'}
});
</script>

@ -259,108 +259,90 @@
</main>
{include file='admin/footer.tpl'}
<script>
var $$ = document;
//document.getElementById("class_expire").value="{$edit_user->class_expire}";
$(document).ready(function () {
function submit() {
if(document.getElementById('is_admin').checked)
{
var is_admin=1;
}
else
{
var is_admin=0;
}
if(document.getElementById('enable').checked)
{
var enable=1;
}
else
{
var enable=0;
}
if(document.getElementById('ga_enable').checked)
{
var ga_enable=1;
}
else
{
var ga_enable=0;
}
$.ajax({
type: "PUT",
url: "/admin/user/{$edit_user->id}",
dataType: "json",
data: {
email: $("#email").val(),
pass: $("#pass").val(),
auto_reset_day: $("#auto_reset_day").val(),
auto_reset_bandwidth: $("#auto_reset_bandwidth").val(),
is_multi_user: $("#is_multi_user").val(),
port: $("#port").val(),
group: $("#group").val(),
passwd: $("#passwd").val(),
transfer_enable: $("#transfer_enable").val(),
invite_num: $("#invite_num").val(),
node_speedlimit: $("#node_speedlimit").val(),
method: $("#method").val(),
remark: $("#remark").val(),
money: $("#money").val(),
enable: enable,
is_admin: is_admin,
ga_enable: ga_enable,
ref_by: $("#ref_by").val(),
forbidden_ip: $("#forbidden_ip").val(),
forbidden_port: $("#forbidden_port").val(),
class: $("#class").val(),
class_expire: $("#class_expire").val(),
expire_in: $("#expire_in").val(),
node_connector: $("#node_connector").val(),
protocol: $("#protocol").val(),
protocol_param: $("#protocol_param").val(),
obfs: $("#obfs").val(),
obfs_param: $("#obfs_param").val(),
},
success: function (data) {
if (data.ret) {
$("#result").modal();
$("#msg").html(data.msg);
window.setTimeout("location.href=top.document.referrer", {$config['jump_delay']});
} else {
$("#result").modal();
$("#msg").html(data.msg);
}
},
error: function (jqXHR) {
$("#result").modal();
$("#msg").html(data.msg+" 发生了错误。");
}
});
window.addEventListener('load', () => {
function submit() {
if (document.getElementById('is_admin').checked) {
var is_admin = 1;
} else {
var is_admin = 0;
}
$("html").keydown(function (event) {
if (event.keyCode == 13) {
login();
if (document.getElementById('enable').checked) {
var enable = 1;
} else {
var enable = 0;
}
if (document.getElementById('ga_enable').checked) {
var ga_enable = 1;
} else {
var ga_enable=0;
}
$.ajax({
type: "PUT",
url: "/admin/user/{$edit_user->id}",
dataType: "json",
data: {
email: $$.getElementById('email').value,
pass: $$.getElementById('pass').value,
auto_reset_day: $$.getElementById('auto_reset_day').value,
auto_reset_bandwidth: $$.getElementById('auto_reset_bandwidth').value,
is_multi_user: $$.getElementById('is_multi_user').value,
port: $$.getElementById('port').value,
group: $$.getElementById('group').value,
passwd: $$.getElementById('passwd').value,
transfer_enable: $$.getElementById('transfer_enable').value,
invite_num: $$.getElementById('invite_num').value,
node_speedlimit: $$.getElementById('node_speedlimit').value,
method: $$.getElementById('method').value,
remark: $$.getElementById('remark').value,
money: $$.getElementById('money').value,
enable,
is_admin,
ga_enable,
ref_by: $$.getElementById('ref_by').value,
forbidden_ip: $$.getElementById('forbidden_ip').value,
forbidden_port: $$.getElementById('forbidden_port').value,
class: $$.getElementById('class').value,
class_expire: $$.getElementById('class_expire').value,
expire_in: $$.getElementById('expire_in').value,
node_connector: $$.getElementById('node_connector').value,
protocol: $$.getElementById('protocol').value,
protocol_param: $$.getElementById('protocol_param').value,
obfs: $$.getElementById('obfs').value,
obfs_param: $$.getElementById('obfs_param').value,
},
success: data => {
if (data.ret) {
$("result").modal();
$$.getElementById('msg').innerHTML = data.msg;
window.setTimeout("location.href=top.document.referrer", {$config['jump_delay']});
} else {
$("result").modal();
$$.getElementById('msg').innerHTML = data.msg;
}
},
error: jqXHR => {
$("result").modal();
$$.getElementById('msg').innerHTML = `${data.msg} 发生了错误。`;
}
});
$("#submit").click(function () {
submit();
});
}
$("html").keydown(event => {
if (event.keyCode == 13) {
login();
}
});
$$.getElementById('submit').addEventListener('click', submit);
})
})
</script>

@ -58,22 +58,21 @@
</main>
{include file='admin/footer.tpl'}
<script>
var $$ = document;
function goto(type) {
var countPage = $("#countPage").val();
var currentPage = $("#currentPage").val();
if ("pre" == type){
if (currentPage == 1 || currentPage == ""){
}else {
var countPage = $$.getElementById('countPage').value,
currentPage = $$.getElementById('currentPage').value;
if ("pre" === type) {
if (currentPage !== 1 && currentPage !== "") {
window.location.href = "/admin/yftOrder?page=" + {$currentPage -1};
}
}else if ("next" == type){
if (currentPage == countPage){
}else {
} else if ("next" === type) {
if (currentPage !== countPage) {
window.location.href = "/admin/yftOrder?page=" + {$currentPage +1};
}
}else if ("end" == type){
if (countPage == currentPage){
}else {
} else if ("end" == type) {
if (countPage !== currentPage) {
window.location.href = "/admin/yftOrder?page=" + countPage;
}
}

Loading…
Cancel
Save