-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.js
137 lines (127 loc) · 4.25 KB
/
api.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
// For local
//var serverURL = "http://localhost:57772/csp/gridserver/";
// For cert/prod
var serverURL = "https://glhc-c-hc1.core.domain/csp/gridserver/";
var authURL = "https://glhc-c-hc1.core.domain/csp/authentication/";
var failOverServerURL = "https://glhc-c-hc2.core.domain/csp/gridserver/";
//The first thing we do is check if we have a token from a previous session. If so we try it, if it fails or is missing
// then we just load the login page
$( document ).ready(function() {
if(getCookie("page")) {
navigate(getCookie("page"));
}
else navigate("search.html");
});
// Pass the name of a cookie to get its value
function getCookie(cname) {
var name = cname + "=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
// Pass a value, name, and expiration time for a new cookie
function setCookie(cname, cvalue, exdays) {
var d = new Date();
d.setTime(d.getTime() + (exdays*24*60*60*1000));
var expires = "expires="+ d.toGMTString();
document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
// Any nav links just navigate viewer to their href via ajax
$(document).on("click", ".nav button", function (e) {
e.preventDefault();
//($(this).attr('href') != "home.html") {
var pageRef = $(this).attr('href');
navigate(pageRef);
//if(pageRef != "login.html")
setCookie("page", pageRef, 1)
//}
});
// Event handling specific to the logout button
$(document).on("click", "#logout", function (e) {
window.location.href = '?CacheLogout=1';
setCookie("page", "", 0);
});
// Function that uses AJAX shorthand for dumping html contents into element
function navigate(pageRef) {
$('#detailColumnPopupSearch').iziModal('close');
$('#detailColumnPopupRoute').iziModal('close');
try {
table.settings()[0].jqXHR.abort()
ajaxDetail.settings()[0].jqXHR.abort()
}
catch(e){}
$('.content').load(pageRef);
}
// Handles hiding columns
function hideColumns(table, dynamicColumns) {
var firstFind = 1;
for(var key in dynamicColumns) {
if(dynamicColumns[key][0] > 0) break
else firstFind++;
}
var leftOver = Object.keys(dynamicColumns).length + 1 - firstFind
var range = [...Array(leftOver).keys()].map(i => i + firstFind)
table.columns(range).visible( false );
}
function buildDynamicDataTable(table, list) {
var hiddenClass = "detail"
var ths = "<th>Details</th>"
var dict = list
// Build headers
for (var key in dict){
if (typeof list[key][1] == 'undefined') {
if(list[key][0] > 0) { ths += '<th class="'+hiddenClass+'">'+key+'</th>' }
else { ths += "<th>"+key+"</th>" }
continue
}
if(list[key][0] > 0) { ths += '<th class="'+hiddenClass+'">'+list[key][1]+'</th>' }
else { ths += "<th>"+list[key][1]+"</th>" }
}
// Build footers
var foot = "<tfoot><tr><th class='detailInvisible'></th>"
for (var key in dict){
if (typeof list[key][1] == 'undefined') {
if(list[key][0] > 0) { foot += '<th class="'+hiddenClass+'">'+key+'</th>' }
else { foot += "<th>"+key+"</th>" }
continue
}
if(list[key][0] > 0) { foot += '<th class="'+hiddenClass+'">'+list[key][1]+'</th>' }
else { foot += "<th>"+list[key][1]+"</th>" }
}
foot += "</tr></tfoot>"
table.append("<thead></thead>").append("<tr></tr>").append(ths)
table.append(foot)
// Programatic generation of datatable columns
var columns = '[{"column":['
for(var key in list) {
columns += '{data:"'+key+'"},'
}
columns = columns.slice(0, -1)
columns += ']}]'
columns = eval(columns)
var customColumn = {
"className": 'details-control',
"orderable": false,
"data": null,
"defaultContent": '<div class="trigger"><button class="hamburger hamburger--collapse" type="button">' +
'<span class="hamburger-box">' +
'<span class="hamburger-inner"></span>' +
'</span>' +
'</button></div>'
}
var dynamicColumns = []
dynamicColumns.push(customColumn)
columns[0].column.forEach(function(i) {
dynamicColumns.push(i)
})
return dynamicColumns
}