agent-backend/contracts/LicenceManager/html/datatableSet.js

178 lines
5.7 KiB
JavaScript
Raw Permalink Normal View History

2021-09-26 04:49:24 +00:00
var dtLang = {
"sProcessing": "处理中...",
"lengthMenu": '显示 <select>' + '<option value="5">5</option>' + '<option value="20">20</option>' + '<option value="100">100</option>' + '<option value="-1">全部</option>' + '</select> 项结果',
"sZeroRecords": "没有匹配结果",
"sInfo": "显示第 _START_ 至 _END_ 项结果,共 _TOTAL_ 项",
"sInfoEmpty": "显示第 0 至 0 项结果,共 0 项",
"sInfoFiltered": "(由 _MAX_ 项结果过滤)",
"sInfoPostFix": "",
"sSearch": "搜索:",
"sUrl": "",
"sEmptyTable": "表中数据为空",
"sLoadingRecords": "载入中...",
"sInfoThousands": ",",
"oPaginate": {
"sFirst": "首页",
"sPrevious": "上页",
"sNext": "下页",
"sLast": "末页"
}
,
"oAria": {
"sSortAscending": ": 以升序排列此列",
"sSortDescending": ": 以降序排列此列"
}
};
var tableHead = "<table id='authorizedUsersTab' class='table display row-border'><thead><tr><th>序号</th><th>UUID</th><th>备注</th><th>过期时间</th><th>节点数</th><th>下载</th></tr></thead><tbody>";
var tableTail = "</tbody></table>";
var fillAcceptList = function(data) {
console.log("fillAcceptData");
var html = tableHead;
var lines = data;
for (var i = 0; i < lines.length; i++) {
html += "<tr><td>";
html += (i + 1);
html += "</td><td>";
html += lines[i].uuid;
html += "</td><td>";
html += lines[i].remark;
html += "</td><td>";
html += lines[i].expiredDate;
html += "</td><td>";
html += lines[i].nodeCount;
html += "</td><td>";
html += "<button class='btn btn-outline-primary'>下载</button>";
html += "</td></tr>";
}
html += tableTail;
$("#authoriedDiv").html(html);
$("#authoriedDiv").off("click", ":button").on(
"click",
":button",
function(event) {
var acceptInfo = {
};
var pos = ($(this).closest("tr").find("td").eq(0)
.text() - 1) / 1;
var licence = global.acceptList[pos].licence;
var uri = "data:text/html,";
uri+=licence
var link = document.createElement("a");
link.download = "licence.txt";
link.href = uri;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
delete link;
}
);
$("#authorizedUsersTab").DataTable({
"language": dtLang,
"rowCallback": function(row, data, displayNum, displayIndex, dataIndex) {
}
,
"headerCallback": function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
}
,
scrollCollapse: false,
paging: true,
pageLength: 5,
order: [[1, 'asc']],
"columnDefs": [{
"targets": 3,
"render": function(data, type, row, meta) {
return new Date(data / 1).toLocaleString();
}
}
,
{
"targets": 1,
"render": function(data, type, row, meta) {
if (data.length > 15) return "<span title='" + data + "'>" + data.substring(0, 15) + " ...</span>";
else return data;
}
}
]
}
);
};
var tableApplyHead = "<table id='applyListTab' class='table display row-border'><thead><tr><th>序号</th><th>UUID</th><th>备注</th><th>授权过期时间</th><th>节点数量</th><th>管理</th></tr></thead><tbody>";
var tableApplyTail = "</tbody></table>";
var onAccept = function(data){
console.log("acceptResult");
console.log(data);
if (data.result=="true"){
flushApplylist();
flushAcceptlist();
}
};
var fillApplyData = function(data) {
console.log("fillApplyListData");
var html = tableApplyHead;
var lines = data;
for (var i = 0; i < lines.length; i++) {
html += "<tr><td>";
html += (i + 1);
html += "</td><td>";
html += lines[i].uuid;
html += "</td><td>";
html += lines[i].remark;
html += "</td><td>";
html += "<input id='timeInput"+i+"'></input>";
html += "</td><td>";
html += "<input id='nodeCountInput"+i+"'></input>";
html += "</td><td>";
html += "<button class='btn btn-outline-primary'>通过申请</button>";
html += "</td></tr>";
}
html += tableTail;
$("#unauthoriedDiv").html(html);
$("#unauthoriedDiv").off("click", ":button").on(
"click",
":button",
function(event) {
var acceptInfo = {
};
var pos = ($(this).closest("tr").find("td").eq(0)
.text() - 1) / 1;
acceptInfo.uuid = global.applyList[pos].uuid;
acceptInfo.expiredDate = $("#timeInput"+pos)[0].value;
if (acceptInfo.expiredDate==undefined || acceptInfo.expiredDate<new Date().getTime()){
alert("日期无效,重填");
return;
}
acceptInfo.nodeCount = $("#nodeCountInput"+pos)[0].value;
if (acceptInfo.nodeCount/1!=acceptInfo.nodeCount){
alert("节点数量得是数字");
return;
}
executeCurrentContract("accept",JSON.stringify(acceptInfo),onAccept);
}
);
console.log("tryToCall DataTable");
$("#applyListTab").DataTable({
"language": dtLang,
"rowCallback": function(row, data, displayNum, displayIndex, dataIndex) {
}
,
"headerCallback": function(thead, data, start, end, display) {
$(thead).css("background", primaryColor);
$(thead).css("color", "white");
$(thead).children().css("background", primaryColor);
$(thead).children().css("color", "white");
}
,
scrollCollapse: false,
paging: true,
pageLength: 10,
order: [[1, 'asc']],
"columnDefs": [
]
}
);
};