|
1
|
|
|
function renderUID(data, type, row) |
|
|
|
|
|
|
2
|
|
|
{ |
|
3
|
|
|
return '<a href="user_edit.php?uid='+data+'">'+data+'</a>'; |
|
4
|
|
|
} |
|
5
|
|
|
|
|
6
|
|
|
function renderName(data, type, row, meta) |
|
|
|
|
|
|
7
|
|
|
{ |
|
8
|
|
|
if(row['givenName'] !== false) |
|
9
|
|
|
{ |
|
10
|
|
|
return row['givenName']+' '+data; |
|
11
|
|
|
} |
|
12
|
|
|
return data; |
|
13
|
|
|
} |
|
14
|
|
|
|
|
15
|
|
|
function onUserTableBodyClick() |
|
16
|
|
|
{ |
|
17
|
|
|
if($(this).hasClass('selected')) |
|
18
|
|
|
{ |
|
19
|
|
|
$(this).removeClass('selected'); |
|
20
|
|
|
} |
|
21
|
|
|
else |
|
22
|
|
|
{ |
|
23
|
|
|
$(this).addClass('selected'); |
|
24
|
|
|
} |
|
25
|
|
|
} |
|
26
|
|
|
|
|
27
|
|
|
function storageAvailable(type) |
|
28
|
|
|
{ |
|
29
|
|
|
try |
|
30
|
|
|
{ |
|
31
|
|
|
var storage = window[type], |
|
32
|
|
|
x = '__storage_test__'; |
|
33
|
|
|
storage.setItem(x, x); |
|
34
|
|
|
storage.removeItem(x); |
|
35
|
|
|
return true; |
|
36
|
|
|
} |
|
37
|
|
|
catch(e) |
|
38
|
|
|
{ |
|
39
|
|
|
return e instanceof DOMException && ( |
|
|
|
|
|
|
40
|
|
|
// everything except Firefox |
|
41
|
|
|
e.code === 22 || |
|
42
|
|
|
// Firefox |
|
43
|
|
|
e.code === 1014 || |
|
44
|
|
|
// test name field too, because code might not be present |
|
45
|
|
|
// everything except Firefox |
|
46
|
|
|
e.name === 'QuotaExceededError' || |
|
47
|
|
|
// Firefox |
|
48
|
|
|
e.name === 'NS_ERROR_DOM_QUOTA_REACHED') && |
|
49
|
|
|
// acknowledge QuotaExceededError only if there's something already stored |
|
50
|
|
|
storage.length !== 0; |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
function populateTableNoStorage() |
|
55
|
|
|
{ |
|
56
|
|
|
$('#user_table').dataTable({ |
|
57
|
|
|
'ajax': '../api/v1/users?fmt=data-table&$select=uid,displayName,sn,mail,givenName', |
|
58
|
|
|
'columns': [ |
|
59
|
|
|
{'data': 'uid', 'render': renderUID}, |
|
60
|
|
|
{'data': 'displayName'}, |
|
61
|
|
|
{'data': 'sn'}, |
|
62
|
|
|
{'data': 'mail'}, |
|
63
|
|
|
{'data': 'givenName', 'visible': false} |
|
64
|
|
|
] |
|
65
|
|
|
}); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
function populateTableFromArray(array) |
|
69
|
|
|
{ |
|
70
|
|
|
if(!$.fn.DataTable.isDataTable('#user_table')) |
|
71
|
|
|
{ |
|
72
|
|
|
$('#user_table').dataTable({ |
|
73
|
|
|
'data': array, |
|
74
|
|
|
'columns': [ |
|
75
|
|
|
{'data': 'uid', 'render': renderUID}, |
|
76
|
|
|
{'data': 'displayName'}, |
|
77
|
|
|
{'data': 'sn'}, |
|
78
|
|
|
{'data': 'mail'}, |
|
79
|
|
|
{'data': 'givenName', 'visible': false} |
|
80
|
|
|
], |
|
81
|
|
|
'deferRender': true |
|
82
|
|
|
}); |
|
83
|
|
|
} |
|
84
|
|
|
else |
|
85
|
|
|
{ |
|
86
|
|
|
var table = $('#user_table').DataTable(); |
|
87
|
|
|
table.clear(); |
|
88
|
|
|
for(var i = 0; i < array.length; i++) |
|
89
|
|
|
{ |
|
90
|
|
|
table.row.add(array[i]); |
|
91
|
|
|
} |
|
92
|
|
|
table.draw(); |
|
93
|
|
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
function gotUserList(jqXHR) |
|
97
|
|
|
{ |
|
98
|
|
|
if(jqXHR.status !== 200) |
|
99
|
|
|
{ |
|
100
|
|
|
alert('Unable to obtain user list!'); |
|
101
|
|
|
console.log(jqXHR); |
|
|
|
|
|
|
102
|
|
|
return; |
|
103
|
|
|
} |
|
104
|
|
|
var cache = {users: jqXHR.responseJSON, time: Date.now()}; |
|
105
|
|
|
window.localStorage.setItem('FlipsideUserCache', JSON.stringify(cache)); |
|
106
|
|
|
populateTableFromArray(jqXHR.responseJSON); |
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
function refreshCache() |
|
110
|
|
|
{ |
|
111
|
|
|
$.ajax({ |
|
112
|
|
|
url: '../api/v1/users?$select=uid,displayName,sn,mail,givenName', |
|
113
|
|
|
type: 'get', |
|
114
|
|
|
dataType: 'json', |
|
115
|
|
|
complete: gotUserList |
|
116
|
|
|
}); |
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
function do_users_init() |
|
120
|
|
|
{ |
|
121
|
|
|
if($("#user_table").length > 0) |
|
122
|
|
|
{ |
|
123
|
|
|
if(storageAvailable('localStorage')) |
|
124
|
|
|
{ |
|
125
|
|
|
var cache = window.localStorage.getItem('FlipsideUserCache'); |
|
126
|
|
|
if(!cache) |
|
127
|
|
|
{ |
|
128
|
|
|
refreshCache(); |
|
129
|
|
|
} |
|
130
|
|
|
else |
|
131
|
|
|
{ |
|
132
|
|
|
cache = JSON.parse(cache); |
|
133
|
|
|
if(cache.time < Date.now()-1200000) |
|
134
|
|
|
{ |
|
135
|
|
|
//Cache is 2 minutes old... refresh |
|
136
|
|
|
refreshCache(); |
|
137
|
|
|
} |
|
138
|
|
|
else |
|
139
|
|
|
{ |
|
140
|
|
|
populateTableFromArray(cache.users); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
} |
|
144
|
|
|
else |
|
145
|
|
|
{ |
|
146
|
|
|
$('.fa-refresh').hide(); |
|
147
|
|
|
populateTableNoStorage(); |
|
148
|
|
|
} |
|
149
|
|
|
$("#user_table tbody").on('click', 'tr', onUserTableBodyClick); |
|
150
|
|
|
} |
|
151
|
|
|
} |
|
152
|
|
|
|
|
153
|
|
|
$(do_users_init); |
|
154
|
|
|
|
This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.