2369 |
22 Apr 14 |
nicklas |
var Index = function() |
2369 |
22 Apr 14 |
nicklas |
2 |
{ |
2369 |
22 Apr 14 |
nicklas |
var index = {}; |
3744 |
12 Feb 16 |
nicklas |
var debug = 0; |
2369 |
22 Apr 14 |
nicklas |
var myPermissions = {}; |
3124 |
09 Feb 15 |
nicklas |
var counterInfo = null; |
2369 |
22 Apr 14 |
nicklas |
7 |
|
2369 |
22 Apr 14 |
nicklas |
index.initPage = function() |
2369 |
22 Apr 14 |
nicklas |
9 |
{ |
2369 |
22 Apr 14 |
nicklas |
Events.doOnEnter('caseName', index.caseSummary); |
2801 |
13 Oct 14 |
nicklas |
Events.addEventHandler('caseName', 'keypress', index.testSnake); |
2369 |
22 Apr 14 |
nicklas |
Buttons.addClickHandler('btnCaseSummary', index.caseSummary); |
4691 |
13 Mar 18 |
nicklas |
Buttons.addClickHandler('counter-refresh', index.forceLoadCounts); |
4691 |
13 Mar 18 |
nicklas |
Doc.removeClass('counter-loading', 'link'); |
4691 |
13 Mar 18 |
nicklas |
15 |
|
5374 |
18 Apr 19 |
nicklas |
var groupMenus = document.getElementsByClassName('group-menu'); |
5374 |
18 Apr 19 |
nicklas |
for (var groupNo = 0; groupNo < groupMenus.length; groupNo++) |
5374 |
18 Apr 19 |
nicklas |
18 |
{ |
5374 |
18 Apr 19 |
nicklas |
var grp = groupMenus[groupNo]; |
5374 |
18 Apr 19 |
nicklas |
if (!Doc.isDisabled(grp)) |
5374 |
18 Apr 19 |
nicklas |
21 |
{ |
5374 |
18 Apr 19 |
nicklas |
Buttons.addClickHandler(grp, index.showWizardGroup); |
5374 |
18 Apr 19 |
nicklas |
23 |
} |
5374 |
18 Apr 19 |
nicklas |
24 |
} |
5374 |
18 Apr 19 |
nicklas |
25 |
|
2369 |
22 Apr 14 |
nicklas |
index.initPermissions(); |
3059 |
19 Dec 14 |
nicklas |
index.loadCounts(); |
4691 |
13 Mar 18 |
nicklas |
index.updateCounterAge(); |
2620 |
01 Sep 14 |
nicklas |
29 |
|
2620 |
01 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2620 |
01 Sep 14 |
nicklas |
frm.caseName.disabled = !App.getActiveProjectId(); |
2369 |
22 Apr 14 |
nicklas |
32 |
} |
2369 |
22 Apr 14 |
nicklas |
33 |
|
5374 |
18 Apr 19 |
nicklas |
index.showWizardGroup = function(event) |
5374 |
18 Apr 19 |
nicklas |
35 |
{ |
5374 |
18 Apr 19 |
nicklas |
var group = Data.get(event.currentTarget, 'wizard-group'); |
5374 |
18 Apr 19 |
nicklas |
Data.set('wizard', 'wizard-group', group); |
5375 |
18 Apr 19 |
nicklas |
var url = 'Session.servlet?ID='+App.getSessionId(); |
5375 |
18 Apr 19 |
nicklas |
url += '&cmd=SetLastWizardGroup'; |
5375 |
18 Apr 19 |
nicklas |
url += '&group='+encodeURIComponent(group); |
5375 |
18 Apr 19 |
nicklas |
Wizard.asyncJsonRequest(url, null, 'POST'); |
5374 |
18 Apr 19 |
nicklas |
42 |
} |
5374 |
18 Apr 19 |
nicklas |
43 |
|
2369 |
22 Apr 14 |
nicklas |
index.initPermissions = function() |
2369 |
22 Apr 14 |
nicklas |
45 |
{ |
2369 |
22 Apr 14 |
nicklas |
// Get permission information |
2369 |
22 Apr 14 |
nicklas |
var url = 'Install.servlet?ID='+App.getSessionId(); |
2369 |
22 Apr 14 |
nicklas |
url += '&cmd=GetPermissions'; |
2369 |
22 Apr 14 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
2369 |
22 Apr 14 |
nicklas |
request.open("GET", url, true); |
2369 |
22 Apr 14 |
nicklas |
Ajax.setReadyStateHandler(request, index.onPermissionsLoaded, index.onPermissionsLoaded); |
2369 |
22 Apr 14 |
nicklas |
request.send(null); |
2369 |
22 Apr 14 |
nicklas |
53 |
} |
2369 |
22 Apr 14 |
nicklas |
54 |
|
2369 |
22 Apr 14 |
nicklas |
// Callback when permission information is ready |
2369 |
22 Apr 14 |
nicklas |
index.onPermissionsLoaded = function(request) |
2369 |
22 Apr 14 |
nicklas |
57 |
{ |
2369 |
22 Apr 14 |
nicklas |
if (debug) App.debug(Strings.encodeTags(request.responseText)); |
2369 |
22 Apr 14 |
nicklas |
var response; |
2369 |
22 Apr 14 |
nicklas |
var error = false; |
2369 |
22 Apr 14 |
nicklas |
try |
2369 |
22 Apr 14 |
nicklas |
62 |
{ |
2369 |
22 Apr 14 |
nicklas |
response = JSON.parse(request.responseText); |
2369 |
22 Apr 14 |
nicklas |
if (response.status != 'ok') |
2369 |
22 Apr 14 |
nicklas |
65 |
{ |
2369 |
22 Apr 14 |
nicklas |
error = response.message || response.stacktrace || 'Unexpected error'; |
2369 |
22 Apr 14 |
nicklas |
67 |
} |
2369 |
22 Apr 14 |
nicklas |
68 |
} |
2369 |
22 Apr 14 |
nicklas |
catch (ex) |
2369 |
22 Apr 14 |
nicklas |
70 |
{ |
2369 |
22 Apr 14 |
nicklas |
error = ex; |
2369 |
22 Apr 14 |
nicklas |
72 |
} |
2369 |
22 Apr 14 |
nicklas |
73 |
|
2369 |
22 Apr 14 |
nicklas |
if (error) |
2369 |
22 Apr 14 |
nicklas |
75 |
{ |
2369 |
22 Apr 14 |
nicklas |
alert(error); |
2369 |
22 Apr 14 |
nicklas |
return; |
2369 |
22 Apr 14 |
nicklas |
78 |
} |
2369 |
22 Apr 14 |
nicklas |
79 |
|
2369 |
22 Apr 14 |
nicklas |
myPermissions = response.permissions; |
3743 |
12 Feb 16 |
nicklas |
var experimentalFeatures = response.experimentalFeatures; |
2369 |
22 Apr 14 |
nicklas |
var isAdmin = myPermissions['Administrator'] == 1; |
2620 |
01 Sep 14 |
nicklas |
var noProjectIsActive = !App.getActiveProjectId(); |
2369 |
22 Apr 14 |
nicklas |
84 |
|
2369 |
22 Apr 14 |
nicklas |
// Enable links based on the permission |
2369 |
22 Apr 14 |
nicklas |
var wizards = document.getElementsByClassName('require-permission'); |
2369 |
22 Apr 14 |
nicklas |
// NOTE! Loop backwards since changing the classname |
2369 |
22 Apr 14 |
nicklas |
// of an element so that 'require-permission' no longer is included |
2369 |
22 Apr 14 |
nicklas |
// removes the element from the 'wizards' list |
2369 |
22 Apr 14 |
nicklas |
for (var wizardNo = wizards.length-1; wizardNo >= 0; wizardNo--) |
2369 |
22 Apr 14 |
nicklas |
91 |
{ |
2369 |
22 Apr 14 |
nicklas |
var wizard = wizards[wizardNo]; |
3743 |
12 Feb 16 |
nicklas |
if (wizard.className.indexOf('experimental') >= 0) |
3743 |
12 Feb 16 |
nicklas |
94 |
{ |
3743 |
12 Feb 16 |
nicklas |
if (experimentalFeatures[wizard.id] == 1) Doc.removeClass(wizard, 'not-implemented'); |
3743 |
12 Feb 16 |
nicklas |
96 |
} |
3743 |
12 Feb 16 |
nicklas |
97 |
|
2369 |
22 Apr 14 |
nicklas |
if (wizard.className.indexOf('not-implemented') == -1) |
2369 |
22 Apr 14 |
nicklas |
99 |
{ |
2369 |
22 Apr 14 |
nicklas |
var role = wizard.getAttribute('data-role'); |
2620 |
01 Sep 14 |
nicklas |
if (noProjectIsActive) |
2369 |
22 Apr 14 |
nicklas |
102 |
{ |
2620 |
01 Sep 14 |
nicklas |
wizard.title = 'You must select a project before using this wizard'; |
2620 |
01 Sep 14 |
nicklas |
104 |
} |
2620 |
01 Sep 14 |
nicklas |
else if (!role || myPermissions[role] == 1 || isAdmin) |
2620 |
01 Sep 14 |
nicklas |
106 |
{ |
2369 |
22 Apr 14 |
nicklas |
wizard.className = 'link'; |
2369 |
22 Apr 14 |
nicklas |
wizard.addEventListener('click', index.wizardOnClick); |
2369 |
22 Apr 14 |
nicklas |
109 |
} |
2369 |
22 Apr 14 |
nicklas |
else |
2369 |
22 Apr 14 |
nicklas |
111 |
{ |
3163 |
04 Mar 15 |
nicklas |
wizard.title = role + ' permission is required to use this wizard'; |
2369 |
22 Apr 14 |
nicklas |
113 |
} |
2369 |
22 Apr 14 |
nicklas |
114 |
} |
2369 |
22 Apr 14 |
nicklas |
115 |
} |
4624 |
17 Nov 17 |
nicklas |
116 |
|
6684 |
20 Apr 22 |
nicklas |
if (response.configIsModified) |
6684 |
20 Apr 22 |
nicklas |
118 |
{ |
6684 |
20 Apr 22 |
nicklas |
Doc.show('reload-config-wizard'); |
6684 |
20 Apr 22 |
nicklas |
Events.addEventHandler('reload-config', 'click', index.reloadConfig); |
6684 |
20 Apr 22 |
nicklas |
121 |
} |
7399 |
07 Nov 23 |
nicklas |
122 |
|
7399 |
07 Nov 23 |
nicklas |
// Show the "auto-processing is disabled" icon |
7399 |
07 Nov 23 |
nicklas |
for (var i = 0; i < response.autoProcessingDisabled.length; i++) |
7399 |
07 Nov 23 |
nicklas |
125 |
{ |
7399 |
07 Nov 23 |
nicklas |
Doc.show(response.autoProcessingDisabled[i], 'inline-block'); |
7399 |
07 Nov 23 |
nicklas |
127 |
} |
7399 |
07 Nov 23 |
nicklas |
128 |
|
7399 |
07 Nov 23 |
nicklas |
// Hiden hidden wizards |
7399 |
07 Nov 23 |
nicklas |
for (var i = 0; i < response.hiddenWizards.length; i++) |
7399 |
07 Nov 23 |
nicklas |
131 |
{ |
7399 |
07 Nov 23 |
nicklas |
Doc.hide(response.hiddenWizards[i]); |
7399 |
07 Nov 23 |
nicklas |
133 |
} |
2369 |
22 Apr 14 |
nicklas |
134 |
} |
2369 |
22 Apr 14 |
nicklas |
135 |
|
2369 |
22 Apr 14 |
nicklas |
index.wizardOnClick = function(event) |
2369 |
22 Apr 14 |
nicklas |
137 |
{ |
2369 |
22 Apr 14 |
nicklas |
var role = Data.get(event.currentTarget, 'role'); |
2369 |
22 Apr 14 |
nicklas |
var isAdmin = myPermissions['Administrator'] == 1; |
2705 |
29 Sep 14 |
nicklas |
if (!role || myPermissions[role] == 1 || isAdmin) |
2369 |
22 Apr 14 |
nicklas |
141 |
{ |
2369 |
22 Apr 14 |
nicklas |
var link = Data.get(event.currentTarget, 'link'); |
6684 |
20 Apr 22 |
nicklas |
if (link) location.href = link; |
2369 |
22 Apr 14 |
nicklas |
144 |
} |
2369 |
22 Apr 14 |
nicklas |
else |
2369 |
22 Apr 14 |
nicklas |
146 |
{ |
2369 |
22 Apr 14 |
nicklas |
Forms.showNotification(event.currentTarget, 'You do not have permission to use this wizard!', null, null, 'left'); |
2369 |
22 Apr 14 |
nicklas |
148 |
} |
2369 |
22 Apr 14 |
nicklas |
149 |
} |
2369 |
22 Apr 14 |
nicklas |
150 |
|
6684 |
20 Apr 22 |
nicklas |
index.reloadConfig = function() |
6684 |
20 Apr 22 |
nicklas |
152 |
{ |
6684 |
20 Apr 22 |
nicklas |
var url = 'Admin.servlet?ID='+App.getSessionId(); |
6684 |
20 Apr 22 |
nicklas |
url += '&cmd=ReloadConfig' |
6684 |
20 Apr 22 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
6684 |
20 Apr 22 |
nicklas |
request.open("GET", url, true); |
6684 |
20 Apr 22 |
nicklas |
Ajax.setReadyStateHandler(request, App.reloadWindow, App.reloadWindow); |
6684 |
20 Apr 22 |
nicklas |
request.send(null); |
6684 |
20 Apr 22 |
nicklas |
159 |
} |
6684 |
20 Apr 22 |
nicklas |
160 |
|
3124 |
09 Feb 15 |
nicklas |
index.forceLoadCounts = function() |
2369 |
22 Apr 14 |
nicklas |
162 |
{ |
4691 |
13 Mar 18 |
nicklas |
Doc.hide('counter-refresh'); |
4691 |
13 Mar 18 |
nicklas |
Doc.show('counter-loading', 'inline'); |
4691 |
13 Mar 18 |
nicklas |
counterInfo = null; |
3124 |
09 Feb 15 |
nicklas |
index.loadCounts(true); |
3124 |
09 Feb 15 |
nicklas |
167 |
} |
3124 |
09 Feb 15 |
nicklas |
168 |
|
3124 |
09 Feb 15 |
nicklas |
index.loadCounts = function(forceUpdate) |
3124 |
09 Feb 15 |
nicklas |
170 |
{ |
3059 |
19 Dec 14 |
nicklas |
var url = 'Session.servlet?ID='+App.getSessionId(); |
5376 |
23 Apr 19 |
nicklas |
url += '&cmd=GetCountersAndActivityLog' |
3124 |
09 Feb 15 |
nicklas |
if (forceUpdate) url += '&forceUpdate=1'; |
3059 |
19 Dec 14 |
nicklas |
var request = Ajax.getXmlHttpRequest(); |
3059 |
19 Dec 14 |
nicklas |
request.open("GET", url, true); |
3059 |
19 Dec 14 |
nicklas |
Ajax.setReadyStateHandler(request, index.onCounted, index.onCounted); |
3059 |
19 Dec 14 |
nicklas |
request.send(null); |
2369 |
22 Apr 14 |
nicklas |
178 |
} |
2369 |
22 Apr 14 |
nicklas |
179 |
|
2369 |
22 Apr 14 |
nicklas |
index.onCounted = function(request) |
2369 |
22 Apr 14 |
nicklas |
181 |
{ |
2369 |
22 Apr 14 |
nicklas |
if (debug) |
2369 |
22 Apr 14 |
nicklas |
183 |
{ |
3059 |
19 Dec 14 |
nicklas |
App.debug(Strings.encodeTags(request.responseText)); |
2369 |
22 Apr 14 |
nicklas |
185 |
} |
2369 |
22 Apr 14 |
nicklas |
186 |
|
2369 |
22 Apr 14 |
nicklas |
var response; |
2369 |
22 Apr 14 |
nicklas |
var error = false; |
2369 |
22 Apr 14 |
nicklas |
try |
2369 |
22 Apr 14 |
nicklas |
190 |
{ |
2369 |
22 Apr 14 |
nicklas |
response = JSON.parse(request.responseText); |
2369 |
22 Apr 14 |
nicklas |
if (response.status != 'ok') |
2369 |
22 Apr 14 |
nicklas |
193 |
{ |
2369 |
22 Apr 14 |
nicklas |
error = response.message || response.stacktrace || 'Unexpected error'; |
2369 |
22 Apr 14 |
nicklas |
195 |
} |
2369 |
22 Apr 14 |
nicklas |
196 |
} |
2369 |
22 Apr 14 |
nicklas |
catch (ex) |
2369 |
22 Apr 14 |
nicklas |
198 |
{ |
2369 |
22 Apr 14 |
nicklas |
error = ex; |
2369 |
22 Apr 14 |
nicklas |
200 |
} |
4691 |
13 Mar 18 |
nicklas |
if (error) |
4691 |
13 Mar 18 |
nicklas |
202 |
{ |
4691 |
13 Mar 18 |
nicklas |
App.debug(error); |
4691 |
13 Mar 18 |
nicklas |
return; |
4691 |
13 Mar 18 |
nicklas |
205 |
} |
2369 |
22 Apr 14 |
nicklas |
206 |
|
3124 |
09 Feb 15 |
nicklas |
counterInfo = response; |
3124 |
09 Feb 15 |
nicklas |
counterInfo.infoTime = new Date().getTime(); |
4691 |
13 Mar 18 |
nicklas |
var counts = response.counts || {}; |
3124 |
09 Feb 15 |
nicklas |
210 |
|
3059 |
19 Dec 14 |
nicklas |
var counters = document.getElementsByClassName('counter'); |
3059 |
19 Dec 14 |
nicklas |
for (var counterNo = 0; counterNo < counters.length; counterNo++) |
2369 |
22 Apr 14 |
nicklas |
213 |
{ |
3059 |
19 Dec 14 |
nicklas |
var counter = counters[counterNo]; |
3059 |
19 Dec 14 |
nicklas |
var countId = Data.get(counter, 'counter'); |
3059 |
19 Dec 14 |
nicklas |
216 |
|
3059 |
19 Dec 14 |
nicklas |
var count = counts[countId]; |
3059 |
19 Dec 14 |
nicklas |
Doc.addClass(counter, 'done'); |
3059 |
19 Dec 14 |
nicklas |
if (count == null) |
3059 |
19 Dec 14 |
nicklas |
220 |
{ |
3059 |
19 Dec 14 |
nicklas |
counter.innerHTML = '-'; |
3059 |
19 Dec 14 |
nicklas |
222 |
} |
3059 |
19 Dec 14 |
nicklas |
else |
3059 |
19 Dec 14 |
nicklas |
224 |
{ |
4047 |
04 Aug 16 |
nicklas |
counter.innerHTML = count < 1000 ? count : Math.floor(count / 1000) + ',' + index.zeroPad(count % 1000); |
3059 |
19 Dec 14 |
nicklas |
226 |
} |
2369 |
22 Apr 14 |
nicklas |
227 |
} |
3124 |
09 Feb 15 |
nicklas |
228 |
|
7138 |
26 Apr 23 |
nicklas |
if (counts['empty-storage-boxes'] < 2 || counts['empty-paused-storage-boxes'] < 2 || counts['empty-external-storage-boxes'] < 2) |
4544 |
28 Jun 17 |
nicklas |
230 |
{ |
6684 |
20 Apr 22 |
nicklas |
Doc.show('more-boxes-are-needed', 'inline'); |
4544 |
28 Jun 17 |
nicklas |
232 |
} |
4544 |
28 Jun 17 |
nicklas |
233 |
|
6091 |
01 Dec 20 |
nicklas |
if (!counterInfo.isRunning) |
6091 |
01 Dec 20 |
nicklas |
235 |
{ |
6091 |
01 Dec 20 |
nicklas |
Doc.element('counter-age').innerHTML = '<img src="images/warning.png"> The counter service is not running'; |
6091 |
01 Dec 20 |
nicklas |
Doc.element('counter-age').title = 'Go to Administrate › Services to start the service.'; |
6091 |
01 Dec 20 |
nicklas |
Doc.hide('counter-loading'); |
6091 |
01 Dec 20 |
nicklas |
Doc.hide('counter-refresh'); |
6091 |
01 Dec 20 |
nicklas |
240 |
} |
6091 |
01 Dec 20 |
nicklas |
else |
6091 |
01 Dec 20 |
nicklas |
242 |
{ |
6091 |
01 Dec 20 |
nicklas |
index.displayCounterAge(); |
6091 |
01 Dec 20 |
nicklas |
244 |
} |
5376 |
23 Apr 19 |
nicklas |
245 |
|
5376 |
23 Apr 19 |
nicklas |
var activityLog = response.activityLog; |
5376 |
23 Apr 19 |
nicklas |
if (activityLog) |
5376 |
23 Apr 19 |
nicklas |
248 |
{ |
5376 |
23 Apr 19 |
nicklas |
var html = ''; |
5376 |
23 Apr 19 |
nicklas |
var currentDay = ''; |
5376 |
23 Apr 19 |
nicklas |
for (var activityNo = 0; activityNo < activityLog.length; activityNo++) |
5376 |
23 Apr 19 |
nicklas |
252 |
{ |
5376 |
23 Apr 19 |
nicklas |
var activity = activityLog[activityNo]; |
5376 |
23 Apr 19 |
nicklas |
if (activity.day != currentDay) |
5376 |
23 Apr 19 |
nicklas |
255 |
{ |
5376 |
23 Apr 19 |
nicklas |
html += '<div class="activity-day">'+Strings.encodeTags(activity.day)+'</div>'; |
5376 |
23 Apr 19 |
nicklas |
currentDay = activity.day; |
5376 |
23 Apr 19 |
nicklas |
258 |
} |
5388 |
26 Apr 19 |
nicklas |
html += '<div class="activity '+(activity.subclass||'')+'">'; |
5376 |
23 Apr 19 |
nicklas |
html += '<span class="activity-time">'+Strings.encodeTags(activity.time)+'</span>'; |
5376 |
23 Apr 19 |
nicklas |
html += '<span class="activity-message">' + Strings.encodeTags(activity.message) + '</span>'; |
5761 |
28 Nov 19 |
nicklas |
if (activity.quoteOfTheDay && activityNo == 0) |
5761 |
28 Nov 19 |
nicklas |
263 |
{ |
5761 |
28 Nov 19 |
nicklas |
html += '<span class="activity-author">' + Strings.encodeTags(activity.author) + '</span>'; |
5761 |
28 Nov 19 |
nicklas |
html += '<div class="activity-link">'; |
5761 |
28 Nov 19 |
nicklas |
html += '<a href="https://theysaidso.com" title="Powered by quotes from The Said So" target="_blank" rel="noopener noreferrer">theysaidso.com</a>'; |
5761 |
28 Nov 19 |
nicklas |
html += '</div>'; |
5761 |
28 Nov 19 |
nicklas |
268 |
} |
5376 |
23 Apr 19 |
nicklas |
html += '</div>'; |
5761 |
28 Nov 19 |
nicklas |
if (activity.quoteOfTheDay && activityNo == 0) |
5761 |
28 Nov 19 |
nicklas |
271 |
{ |
5761 |
28 Nov 19 |
nicklas |
Doc.element('quote-of-the-day').innerHTML = html; |
5761 |
28 Nov 19 |
nicklas |
html = ''; |
5761 |
28 Nov 19 |
nicklas |
274 |
} |
5376 |
23 Apr 19 |
nicklas |
275 |
} |
5404 |
08 May 19 |
nicklas |
Doc.element('activity-log-entries').innerHTML = html; |
5376 |
23 Apr 19 |
nicklas |
277 |
} |
2369 |
22 Apr 14 |
nicklas |
278 |
} |
2369 |
22 Apr 14 |
nicklas |
279 |
|
4047 |
04 Aug 16 |
nicklas |
// Pad a numeric value with leading zeros so that a string with at least 3 digits is created |
4047 |
04 Aug 16 |
nicklas |
index.zeroPad = function(val) |
4047 |
04 Aug 16 |
nicklas |
282 |
{ |
4047 |
04 Aug 16 |
nicklas |
if (val < 10) return '00'+val; |
4047 |
04 Aug 16 |
nicklas |
if (val < 100) return '0'+val; |
4047 |
04 Aug 16 |
nicklas |
return val; |
4047 |
04 Aug 16 |
nicklas |
286 |
} |
4047 |
04 Aug 16 |
nicklas |
287 |
|
4691 |
13 Mar 18 |
nicklas |
index.displayCounterAge = function() |
3124 |
09 Feb 15 |
nicklas |
289 |
{ |
6091 |
01 Dec 20 |
nicklas |
if (counterInfo == null || !counterInfo.countTime) return; |
4691 |
13 Mar 18 |
nicklas |
291 |
|
4691 |
13 Mar 18 |
nicklas |
// We have count information |
4691 |
13 Mar 18 |
nicklas |
var formattedDate = Reggie.reformatDate(counterInfo.countTime); |
4691 |
13 Mar 18 |
nicklas |
294 |
|
4691 |
13 Mar 18 |
nicklas |
// Generate a message |
4691 |
13 Mar 18 |
nicklas |
var counterAge = ''; |
3124 |
09 Feb 15 |
nicklas |
var time = new Date().getTime(); |
4691 |
13 Mar 18 |
nicklas |
counterInfo.infoAgeInSeconds = Math.floor((time - counterInfo.infoTime) / 1000); |
4691 |
13 Mar 18 |
nicklas |
counterInfo.ageInSeconds = counterInfo.countAge + counterInfo.infoAgeInSeconds; |
4691 |
13 Mar 18 |
nicklas |
counterInfo.ageInMinutes = Math.floor(counterInfo.ageInSeconds / 60); |
3124 |
09 Feb 15 |
nicklas |
301 |
|
4691 |
13 Mar 18 |
nicklas |
if (counterInfo.ageInSeconds < 60) |
3124 |
09 Feb 15 |
nicklas |
303 |
{ |
3124 |
09 Feb 15 |
nicklas |
// Counters are less than 1 minute old, display age in seconds |
4691 |
13 Mar 18 |
nicklas |
counterAge += counterInfo.ageInSeconds == 1 ? '1 second ago' : counterInfo.ageInSeconds + ' seconds ago'; |
3124 |
09 Feb 15 |
nicklas |
306 |
} |
4691 |
13 Mar 18 |
nicklas |
else if (counterInfo.ageInMinutes < 60) |
3124 |
09 Feb 15 |
nicklas |
308 |
{ |
4691 |
13 Mar 18 |
nicklas |
// Counters are less than 1 hour old, display age in minutes |
4691 |
13 Mar 18 |
nicklas |
counterAge += counterInfo.ageInMinutes == 1 ? '1 minute ago' : counterInfo.ageInMinutes + ' minutes ago'; |
4691 |
13 Mar 18 |
nicklas |
311 |
} |
4691 |
13 Mar 18 |
nicklas |
else |
4691 |
13 Mar 18 |
nicklas |
313 |
{ |
4691 |
13 Mar 18 |
nicklas |
// Display age as date and time |
4691 |
13 Mar 18 |
nicklas |
counterAge += formattedDate; |
4691 |
13 Mar 18 |
nicklas |
316 |
} |
4691 |
13 Mar 18 |
nicklas |
Doc.element('counter-age').innerHTML = counterAge; |
4691 |
13 Mar 18 |
nicklas |
Doc.element('counter-age').title = formattedDate; |
4691 |
13 Mar 18 |
nicklas |
319 |
|
4691 |
13 Mar 18 |
nicklas |
// Show or hide icons |
4691 |
13 Mar 18 |
nicklas |
Doc.hide('counter-loading'); |
4691 |
13 Mar 18 |
nicklas |
Doc.hide('counter-refresh'); |
4691 |
13 Mar 18 |
nicklas |
if (counterInfo.isCounting) |
4691 |
13 Mar 18 |
nicklas |
324 |
{ |
4691 |
13 Mar 18 |
nicklas |
Doc.show('counter-loading', 'inline'); |
4691 |
13 Mar 18 |
nicklas |
326 |
} |
4691 |
13 Mar 18 |
nicklas |
else if (counterInfo.ageInMinutes >= 5) |
4691 |
13 Mar 18 |
nicklas |
328 |
{ |
4691 |
13 Mar 18 |
nicklas |
Doc.show('counter-refresh', 'inline'); |
4691 |
13 Mar 18 |
nicklas |
330 |
} |
4691 |
13 Mar 18 |
nicklas |
331 |
} |
4691 |
13 Mar 18 |
nicklas |
332 |
|
4691 |
13 Mar 18 |
nicklas |
index.updateCounterAge = function() |
4691 |
13 Mar 18 |
nicklas |
334 |
{ |
4691 |
13 Mar 18 |
nicklas |
var nextUpdate = 15; // 15 seconds until next update |
4691 |
13 Mar 18 |
nicklas |
var reloadCounts = false; // By default, no reload of counts |
4691 |
13 Mar 18 |
nicklas |
337 |
|
4691 |
13 Mar 18 |
nicklas |
if (counterInfo == null) |
4691 |
13 Mar 18 |
nicklas |
339 |
{ |
4691 |
13 Mar 18 |
nicklas |
// We have no info yet, try again in 1 second... |
4691 |
13 Mar 18 |
nicklas |
nextUpdate = 1; |
4691 |
13 Mar 18 |
nicklas |
342 |
} |
4691 |
13 Mar 18 |
nicklas |
else |
4691 |
13 Mar 18 |
nicklas |
344 |
{ |
4691 |
13 Mar 18 |
nicklas |
if (counterInfo.countTime) |
3124 |
09 Feb 15 |
nicklas |
346 |
{ |
4691 |
13 Mar 18 |
nicklas |
index.displayCounterAge(); |
4691 |
13 Mar 18 |
nicklas |
if (counterInfo.ageInSeconds < 60) |
4691 |
13 Mar 18 |
nicklas |
349 |
{ |
4691 |
13 Mar 18 |
nicklas |
// Next update should be on even 5 second intervals |
4691 |
13 Mar 18 |
nicklas |
nextUpdate = 5 - counterInfo.ageInSeconds % 5; |
4691 |
13 Mar 18 |
nicklas |
352 |
} |
4691 |
13 Mar 18 |
nicklas |
if (counterInfo.infoAgeInSeconds > 300) |
4691 |
13 Mar 18 |
nicklas |
354 |
{ |
4691 |
13 Mar 18 |
nicklas |
// If our information is more than 5 minutes old, request an update from the server |
4691 |
13 Mar 18 |
nicklas |
reloadCounts = true; |
4691 |
13 Mar 18 |
nicklas |
357 |
} |
3124 |
09 Feb 15 |
nicklas |
358 |
} |
3124 |
09 Feb 15 |
nicklas |
359 |
|
4691 |
13 Mar 18 |
nicklas |
// If a count is in progress request an update from the server |
4691 |
13 Mar 18 |
nicklas |
if (counterInfo.isCounting) |
3124 |
09 Feb 15 |
nicklas |
362 |
{ |
4691 |
13 Mar 18 |
nicklas |
reloadCounts = true; |
4691 |
13 Mar 18 |
nicklas |
nextUpdate = 2; |
3124 |
09 Feb 15 |
nicklas |
365 |
} |
6091 |
01 Dec 20 |
nicklas |
366 |
|
6091 |
01 Dec 20 |
nicklas |
// If the service is not running, we need an update from the server |
6091 |
01 Dec 20 |
nicklas |
if (!counterInfo.isRunning) |
6091 |
01 Dec 20 |
nicklas |
369 |
{ |
6091 |
01 Dec 20 |
nicklas |
reloadCounts = true; |
6091 |
01 Dec 20 |
nicklas |
371 |
} |
3124 |
09 Feb 15 |
nicklas |
372 |
} |
4691 |
13 Mar 18 |
nicklas |
373 |
|
4691 |
13 Mar 18 |
nicklas |
if (reloadCounts) index.loadCounts(); |
4691 |
13 Mar 18 |
nicklas |
setTimeout(index.updateCounterAge, nextUpdate * 1000); |
3124 |
09 Feb 15 |
nicklas |
376 |
} |
3124 |
09 Feb 15 |
nicklas |
377 |
|
2369 |
22 Apr 14 |
nicklas |
index.caseSummary = function() |
2369 |
22 Apr 14 |
nicklas |
379 |
{ |
2369 |
22 Apr 14 |
nicklas |
var frm = document.forms['reggie']; |
2369 |
22 Apr 14 |
nicklas |
381 |
|
2369 |
22 Apr 14 |
nicklas |
var caseName = frm.caseName.value; |
2369 |
22 Apr 14 |
nicklas |
if (!caseName) |
2369 |
22 Apr 14 |
nicklas |
384 |
{ |
2369 |
22 Apr 14 |
nicklas |
Forms.showNotification('caseName', 'Please enter a 7-digit case id', null, null, 'left'); |
2369 |
22 Apr 14 |
nicklas |
return; |
2369 |
22 Apr 14 |
nicklas |
387 |
} |
2369 |
22 Apr 14 |
nicklas |
var url = 'reports/case_summary.jsp?ID='+App.getSessionId(); |
2369 |
22 Apr 14 |
nicklas |
url += '&caseName='+encodeURIComponent(caseName); |
5019 |
10 Oct 18 |
nicklas |
url += '&highlight='+encodeURIComponent(caseName); |
2369 |
22 Apr 14 |
nicklas |
location.href = url; |
2369 |
22 Apr 14 |
nicklas |
392 |
} |
2801 |
13 Oct 14 |
nicklas |
393 |
|
2801 |
13 Oct 14 |
nicklas |
index.testSnake = function(event) |
2801 |
13 Oct 14 |
nicklas |
395 |
{ |
2801 |
13 Oct 14 |
nicklas |
if (event.currentTarget.value == 'Snak' && event.charCode == 101) |
2801 |
13 Oct 14 |
nicklas |
397 |
{ |
2801 |
13 Oct 14 |
nicklas |
setTimeout(index.showSnake, 500); |
2801 |
13 Oct 14 |
nicklas |
399 |
} |
2801 |
13 Oct 14 |
nicklas |
400 |
} |
2369 |
22 Apr 14 |
nicklas |
401 |
|
2801 |
13 Oct 14 |
nicklas |
index.showSnake = function() |
2801 |
13 Oct 14 |
nicklas |
403 |
{ |
2844 |
21 Oct 14 |
nicklas |
var msg = '<img src="images/snake-icon-64.png" style="float: right;">' |
2844 |
21 Oct 14 |
nicklas |
msg += '– There\'s a big snake in the plane, Jock!<br>'; |
2801 |
13 Oct 14 |
nicklas |
msg += '– Oh, that\'s just my pet snake, Reggie!<br>'; |
2801 |
13 Oct 14 |
nicklas |
msg += '– I hate snakes, Jock! I hate \'em!<br>'; |
2801 |
13 Oct 14 |
nicklas |
msg += '– Come on! Show a little backbone, will ya?<br>'; |
2801 |
13 Oct 14 |
nicklas |
msg += '<div class="snake-quote-source">Indiana Jones - Raiders of the Lost Ark</div>'; |
2846 |
21 Oct 14 |
nicklas |
Forms.showNotification('caseName', msg, 'snake-quote', 'pointer-above'); |
5740 |
20 Nov 19 |
nicklas |
var url = 'Session.servlet?ID='+App.getSessionId(); |
5740 |
20 Nov 19 |
nicklas |
url += '&cmd=ReggieTheSnakeWasSummoned'; |
5740 |
20 Nov 19 |
nicklas |
Wizard.asyncJsonRequest(url); |
2801 |
13 Oct 14 |
nicklas |
414 |
} |
2369 |
22 Apr 14 |
nicklas |
415 |
|
2369 |
22 Apr 14 |
nicklas |
return index; |
2369 |
22 Apr 14 |
nicklas |
417 |
}(); |
2369 |
22 Apr 14 |
nicklas |
418 |
|
2369 |
22 Apr 14 |
nicklas |
Doc.onLoad(Index.initPage); |
2369 |
22 Apr 14 |
nicklas |
420 |
|