4000 |
17 Jun 16 |
nicklas |
var Delivery = function() |
4000 |
17 Jun 16 |
nicklas |
2 |
{ |
4000 |
17 Jun 16 |
nicklas |
var delivery = {}; |
4000 |
17 Jun 16 |
nicklas |
var debug = 0; |
4000 |
17 Jun 16 |
nicklas |
5 |
|
4009 |
23 Jun 16 |
nicklas |
// Information about the currently logged in user |
4007 |
21 Jun 16 |
nicklas |
var currentUser = null; |
4009 |
23 Jun 16 |
nicklas |
// The last URL used for loading specimen |
4009 |
23 Jun 16 |
nicklas |
// We need it to be able to re-load the list after a download |
4006 |
21 Jun 16 |
nicklas |
var loadUrl = null; |
4009 |
23 Jun 16 |
nicklas |
// If the URL is loading the default (last 30 days) or has other search parameters |
4006 |
21 Jun 16 |
nicklas |
var hasSearchParameters = false; |
4000 |
17 Jun 16 |
nicklas |
13 |
|
4009 |
23 Jun 16 |
nicklas |
// Months in the "select month" list |
4008 |
22 Jun 16 |
nicklas |
var FIRST_YEAR = debug ? 2010 : 2016; |
4008 |
22 Jun 16 |
nicklas |
var MONTHS = [ |
4008 |
22 Jun 16 |
nicklas |
'Januari', 'Februari', 'Mars', 'April', 'Maj', 'Juni', |
4008 |
22 Jun 16 |
nicklas |
'Juli', 'Augusti', 'September', 'Oktober', 'November', 'December' |
4008 |
22 Jun 16 |
nicklas |
19 |
]; |
4008 |
22 Jun 16 |
nicklas |
20 |
|
4009 |
23 Jun 16 |
nicklas |
// Number of minutes before session timeout to display a warning |
4009 |
23 Jun 16 |
nicklas |
var WARN_BEFORE_TIMEOUT = 5; |
4008 |
22 Jun 16 |
nicklas |
23 |
|
4000 |
17 Jun 16 |
nicklas |
// Page initialization |
4000 |
17 Jun 16 |
nicklas |
delivery.initPage = function() |
4000 |
17 Jun 16 |
nicklas |
26 |
{ |
4009 |
23 Jun 16 |
nicklas |
// The month selection list |
4009 |
23 Jun 16 |
nicklas |
delivery.createMonthSelectionList(); |
4009 |
23 Jun 16 |
nicklas |
Events.addEventHandler('search-by-month', 'click', delivery.showMonthList); |
4009 |
23 Jun 16 |
nicklas |
Events.addEventHandler(document.body, 'click', delivery.hideMonthList); |
4009 |
23 Jun 16 |
nicklas |
Events.addEventHandler('month-list', 'click', delivery.searchByMonth); |
4008 |
22 Jun 16 |
nicklas |
32 |
|
4009 |
23 Jun 16 |
nicklas |
// The default search (last 30 days) |
4009 |
23 Jun 16 |
nicklas |
Events.addEventHandler('search-last-30', 'click', delivery.searchLast30Days); |
4009 |
23 Jun 16 |
nicklas |
35 |
|
4009 |
23 Jun 16 |
nicklas |
// The manual search box |
4009 |
23 Jun 16 |
nicklas |
Events.doOnEnter('search', delivery.searchReports); |
4009 |
23 Jun 16 |
nicklas |
Events.addEventHandler('btnSearch', 'click', delivery.searchReports); |
4009 |
23 Jun 16 |
nicklas |
39 |
|
4009 |
23 Jun 16 |
nicklas |
// Logout button |
4009 |
23 Jun 16 |
nicklas |
Buttons.addClickHandler('btnLogout', delivery.logout); |
4009 |
23 Jun 16 |
nicklas |
42 |
|
4009 |
23 Jun 16 |
nicklas |
// Start timout check timer |
4009 |
23 Jun 16 |
nicklas |
delivery.updateTimeout(); |
4009 |
23 Jun 16 |
nicklas |
45 |
|
4009 |
23 Jun 16 |
nicklas |
// Perform the default search |
4009 |
23 Jun 16 |
nicklas |
delivery.searchLast30Days(); |
4009 |
23 Jun 16 |
nicklas |
48 |
} |
4009 |
23 Jun 16 |
nicklas |
49 |
|
4009 |
23 Jun 16 |
nicklas |
50 |
/** |
4009 |
23 Jun 16 |
nicklas |
Initialize the month selection list. |
4009 |
23 Jun 16 |
nicklas |
52 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.createMonthSelectionList = function() |
4009 |
23 Jun 16 |
nicklas |
54 |
{ |
4008 |
22 Jun 16 |
nicklas |
var now = new Date(); |
4008 |
22 Jun 16 |
nicklas |
var year = now.getFullYear(); |
4008 |
22 Jun 16 |
nicklas |
var month = now.getMonth(); |
4008 |
22 Jun 16 |
nicklas |
58 |
|
4008 |
22 Jun 16 |
nicklas |
var html = ''; |
4008 |
22 Jun 16 |
nicklas |
var numMonths = 0; |
4008 |
22 Jun 16 |
nicklas |
while (year > FIRST_YEAR || year == FIRST_YEAR && month >= 0) |
4008 |
22 Jun 16 |
nicklas |
62 |
{ |
4008 |
22 Jun 16 |
nicklas |
var monthClass = 'month'; |
4008 |
22 Jun 16 |
nicklas |
if (month < 0) |
4008 |
22 Jun 16 |
nicklas |
65 |
{ |
4008 |
22 Jun 16 |
nicklas |
month = 11; |
4008 |
22 Jun 16 |
nicklas |
year--; |
4008 |
22 Jun 16 |
nicklas |
monthClass += ' new-year full-year'; |
4008 |
22 Jun 16 |
nicklas |
69 |
} |
4008 |
22 Jun 16 |
nicklas |
if (numMonths == 0) monthClass += ' full-year'; |
4008 |
22 Jun 16 |
nicklas |
html += '<div class="'+monthClass+'" data-year="'+year+'" data-month="'+month+'">'; |
4008 |
22 Jun 16 |
nicklas |
if (month == 11 || numMonths == 0) |
4008 |
22 Jun 16 |
nicklas |
73 |
{ |
4008 |
22 Jun 16 |
nicklas |
html += year + ' '; |
4008 |
22 Jun 16 |
nicklas |
75 |
} |
4008 |
22 Jun 16 |
nicklas |
html += MONTHS[month] + '</div>'; |
4008 |
22 Jun 16 |
nicklas |
month--; |
4008 |
22 Jun 16 |
nicklas |
numMonths++; |
4008 |
22 Jun 16 |
nicklas |
79 |
} |
4008 |
22 Jun 16 |
nicklas |
80 |
|
4009 |
23 Jun 16 |
nicklas |
Doc.element('month-list').innerHTML = html; |
4006 |
21 Jun 16 |
nicklas |
82 |
} |
4006 |
21 Jun 16 |
nicklas |
83 |
|
4009 |
23 Jun 16 |
nicklas |
84 |
/** |
4009 |
23 Jun 16 |
nicklas |
Display the month selection list. It is |
4009 |
23 Jun 16 |
nicklas |
placed in relation to the current moust |
4009 |
23 Jun 16 |
nicklas |
position. |
4009 |
23 Jun 16 |
nicklas |
88 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.showMonthList = function(event) |
4008 |
22 Jun 16 |
nicklas |
90 |
{ |
4009 |
23 Jun 16 |
nicklas |
var monthList = Doc.element('month-list'); |
4008 |
22 Jun 16 |
nicklas |
var x = event.clientX; |
4008 |
22 Jun 16 |
nicklas |
var y = event.clientY+2; |
4008 |
22 Jun 16 |
nicklas |
94 |
|
4009 |
23 Jun 16 |
nicklas |
monthList.style.left = (x)+'px'; |
4009 |
23 Jun 16 |
nicklas |
monthList.style.top = (y)+'px'; |
4008 |
22 Jun 16 |
nicklas |
event.stopPropagation(); |
4008 |
22 Jun 16 |
nicklas |
98 |
|
4009 |
23 Jun 16 |
nicklas |
Doc.show(monthList); |
4008 |
22 Jun 16 |
nicklas |
100 |
} |
4008 |
22 Jun 16 |
nicklas |
101 |
|
4009 |
23 Jun 16 |
nicklas |
102 |
/** |
4009 |
23 Jun 16 |
nicklas |
Hide the month selection list. |
4009 |
23 Jun 16 |
nicklas |
104 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.hideMonthList = function() |
4008 |
22 Jun 16 |
nicklas |
106 |
{ |
4009 |
23 Jun 16 |
nicklas |
Doc.hide('month-list'); |
4008 |
22 Jun 16 |
nicklas |
108 |
} |
4008 |
22 Jun 16 |
nicklas |
109 |
|
4009 |
23 Jun 16 |
nicklas |
110 |
/** |
4009 |
23 Jun 16 |
nicklas |
Search for samples from the given month that |
4009 |
23 Jun 16 |
nicklas |
was clicked. |
4009 |
23 Jun 16 |
nicklas |
113 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.searchByMonth = function(event) |
4008 |
22 Jun 16 |
nicklas |
115 |
{ |
4008 |
22 Jun 16 |
nicklas |
var target = event.target; |
4008 |
22 Jun 16 |
nicklas |
117 |
|
4008 |
22 Jun 16 |
nicklas |
var month = Data.int(target, 'month'); |
4008 |
22 Jun 16 |
nicklas |
var year = Data.int(target, 'year'); |
4008 |
22 Jun 16 |
nicklas |
120 |
|
4008 |
22 Jun 16 |
nicklas |
var title = 'Prov med ankomstdatum ' + MONTHS[month] + ' ' + year; |
4008 |
22 Jun 16 |
nicklas |
var parameters = '&year='+year+'&month='+month; |
4008 |
22 Jun 16 |
nicklas |
delivery.prepareForNewSearch(title, parameters); |
4008 |
22 Jun 16 |
nicklas |
124 |
} |
4008 |
22 Jun 16 |
nicklas |
125 |
|
4009 |
23 Jun 16 |
nicklas |
126 |
/** |
4009 |
23 Jun 16 |
nicklas |
Search for samples from the last 30 days (default search). |
4009 |
23 Jun 16 |
nicklas |
128 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.searchLast30Days = function() |
4007 |
21 Jun 16 |
nicklas |
130 |
{ |
4009 |
23 Jun 16 |
nicklas |
var title = 'Prov med ankomstdatum de senaste 30 dagarna'; |
4009 |
23 Jun 16 |
nicklas |
delivery.prepareForNewSearch(title, null); |
4009 |
23 Jun 16 |
nicklas |
133 |
} |
4009 |
23 Jun 16 |
nicklas |
134 |
|
4009 |
23 Jun 16 |
nicklas |
135 |
/** |
4009 |
23 Jun 16 |
nicklas |
Manual query for personal number, SCANB-ID, etc. |
4009 |
23 Jun 16 |
nicklas |
137 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.searchReports = function() |
4009 |
23 Jun 16 |
nicklas |
139 |
{ |
4009 |
23 Jun 16 |
nicklas |
var query = Doc.element('search').value; |
4009 |
23 Jun 16 |
nicklas |
if (!query) |
4007 |
21 Jun 16 |
nicklas |
142 |
{ |
4009 |
23 Jun 16 |
nicklas |
Doc.element('search').focus(); |
4009 |
23 Jun 16 |
nicklas |
return; |
4007 |
21 Jun 16 |
nicklas |
145 |
} |
4007 |
21 Jun 16 |
nicklas |
146 |
|
4009 |
23 Jun 16 |
nicklas |
var title = 'Prov som matchar \'' + Strings.encodeTags(query) + '\''; |
4009 |
23 Jun 16 |
nicklas |
var parameters = '&query='+encodeURIComponent(query); |
4009 |
23 Jun 16 |
nicklas |
delivery.prepareForNewSearch(title, parameters); |
4007 |
21 Jun 16 |
nicklas |
150 |
} |
4009 |
23 Jun 16 |
nicklas |
151 |
|
4009 |
23 Jun 16 |
nicklas |
152 |
/** |
4009 |
23 Jun 16 |
nicklas |
Prepare for a search by updating the title elements on |
4009 |
23 Jun 16 |
nicklas |
the web page and generating the query url. |
4009 |
23 Jun 16 |
nicklas |
155 |
*/ |
4006 |
21 Jun 16 |
nicklas |
delivery.prepareForNewSearch = function(title, urlParameters) |
4006 |
21 Jun 16 |
nicklas |
157 |
{ |
4009 |
23 Jun 16 |
nicklas |
// Update titles and clear the search box |
4009 |
23 Jun 16 |
nicklas |
if (title) delivery.setDocumentTitle(title); |
4006 |
21 Jun 16 |
nicklas |
Doc.element('search').value = ''; |
4006 |
21 Jun 16 |
nicklas |
161 |
|
4009 |
23 Jun 16 |
nicklas |
// Hide existing results... |
4006 |
21 Jun 16 |
nicklas |
Doc.hide('new-reports-section'); |
4006 |
21 Jun 16 |
nicklas |
Doc.hide('work-in-progress-section'); |
4006 |
21 Jun 16 |
nicklas |
Doc.hide('archive-section'); |
4009 |
23 Jun 16 |
nicklas |
166 |
|
4009 |
23 Jun 16 |
nicklas |
// Show a message for the user |
4009 |
23 Jun 16 |
nicklas |
delivery.showMessage('Ett ögonblick, informationen hämtas...'); |
4006 |
21 Jun 16 |
nicklas |
169 |
|
4006 |
21 Jun 16 |
nicklas |
loadUrl = '../Delivery.servlet?ID='+App.getSessionId(); |
4006 |
21 Jun 16 |
nicklas |
loadUrl += '&cmd=LoadYellowSpecimen'; |
4008 |
22 Jun 16 |
nicklas |
if (debug) loadUrl += '&debug=1'; |
4006 |
21 Jun 16 |
nicklas |
if (urlParameters) |
4006 |
21 Jun 16 |
nicklas |
174 |
{ |
4006 |
21 Jun 16 |
nicklas |
loadUrl += urlParameters; |
4006 |
21 Jun 16 |
nicklas |
hasSearchParameters = true; |
4006 |
21 Jun 16 |
nicklas |
177 |
} |
4006 |
21 Jun 16 |
nicklas |
else |
4006 |
21 Jun 16 |
nicklas |
179 |
{ |
4006 |
21 Jun 16 |
nicklas |
hasSearchParameters = false; |
4006 |
21 Jun 16 |
nicklas |
181 |
} |
4005 |
21 Jun 16 |
nicklas |
delivery.loadSpecimenInformation(); |
4005 |
21 Jun 16 |
nicklas |
183 |
} |
4009 |
23 Jun 16 |
nicklas |
184 |
|
4009 |
23 Jun 16 |
nicklas |
185 |
/** |
4009 |
23 Jun 16 |
nicklas |
Update titles on the web page. Typically used |
4009 |
23 Jun 16 |
nicklas |
to reflect the current search. |
4009 |
23 Jun 16 |
nicklas |
188 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.setDocumentTitle = function(title) |
4006 |
21 Jun 16 |
nicklas |
190 |
{ |
4009 |
23 Jun 16 |
nicklas |
Doc.element('page-title').innerHTML = title; |
4009 |
23 Jun 16 |
nicklas |
document.title = title; |
4006 |
21 Jun 16 |
nicklas |
193 |
} |
4005 |
21 Jun 16 |
nicklas |
194 |
|
4009 |
23 Jun 16 |
nicklas |
195 |
/** |
4009 |
23 Jun 16 |
nicklas |
Display a message for the user. |
4009 |
23 Jun 16 |
nicklas |
197 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.showMessage = function(msg) |
4006 |
21 Jun 16 |
nicklas |
199 |
{ |
4009 |
23 Jun 16 |
nicklas |
Doc.element('message-text').innerHTML = msg; |
4009 |
23 Jun 16 |
nicklas |
Doc.show('message-section'); |
4006 |
21 Jun 16 |
nicklas |
202 |
} |
4009 |
23 Jun 16 |
nicklas |
203 |
|
4009 |
23 Jun 16 |
nicklas |
204 |
/** |
4009 |
23 Jun 16 |
nicklas |
Set information about the current user. |
4009 |
23 Jun 16 |
nicklas |
206 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.setUserInformation = function(userInfo) |
4006 |
21 Jun 16 |
nicklas |
208 |
{ |
4009 |
23 Jun 16 |
nicklas |
currentUser = userInfo; |
4009 |
23 Jun 16 |
nicklas |
Doc.element('current-username').innerHTML = Strings.encodeTags(currentUser.username); |
4009 |
23 Jun 16 |
nicklas |
Doc.show('user-section'); |
4006 |
21 Jun 16 |
nicklas |
212 |
} |
4006 |
21 Jun 16 |
nicklas |
213 |
|
4009 |
23 Jun 16 |
nicklas |
214 |
/** |
4009 |
23 Jun 16 |
nicklas |
Load specimen and report information. |
4009 |
23 Jun 16 |
nicklas |
216 |
*/ |
4005 |
21 Jun 16 |
nicklas |
delivery.loadSpecimenInformation = function() |
4005 |
21 Jun 16 |
nicklas |
218 |
{ |
4006 |
21 Jun 16 |
nicklas |
if (loadUrl == null) |
4006 |
21 Jun 16 |
nicklas |
220 |
{ |
4006 |
21 Jun 16 |
nicklas |
loadUrl = '../Delivery.servlet?ID='+App.getSessionId(); |
4006 |
21 Jun 16 |
nicklas |
loadUrl += '&cmd=LoadYellowSpecimen'; |
4006 |
21 Jun 16 |
nicklas |
223 |
} |
4009 |
23 Jun 16 |
nicklas |
Wizard.asyncJsonRequest(loadUrl, delivery.onSpecimenLoaded, 'GET', null, delivery.errorHandler); |
4000 |
17 Jun 16 |
nicklas |
225 |
} |
4009 |
23 Jun 16 |
nicklas |
226 |
|
4009 |
23 Jun 16 |
nicklas |
227 |
/** |
4009 |
23 Jun 16 |
nicklas |
Callback when specimen information has been successfully loaded. |
4009 |
23 Jun 16 |
nicklas |
229 |
*/ |
4000 |
17 Jun 16 |
nicklas |
delivery.onSpecimenLoaded = function(response) |
4000 |
17 Jun 16 |
nicklas |
231 |
{ |
4009 |
23 Jun 16 |
nicklas |
Doc.hide('message-section'); |
4009 |
23 Jun 16 |
nicklas |
233 |
|
4009 |
23 Jun 16 |
nicklas |
// Update information about current user |
4009 |
23 Jun 16 |
nicklas |
if (response.user) delivery.setUserInformation(response.user); |
4009 |
23 Jun 16 |
nicklas |
236 |
|
4000 |
17 Jun 16 |
nicklas |
// For debugging! |
4000 |
17 Jun 16 |
nicklas |
//response.newReports = []; |
4000 |
17 Jun 16 |
nicklas |
//response.workInProgress = []; |
4000 |
17 Jun 16 |
nicklas |
//response.archived = []; |
4000 |
17 Jun 16 |
nicklas |
241 |
|
4009 |
23 Jun 16 |
nicklas |
// Generate a table with 3 sections: new reports, work in progres and archive. |
4000 |
17 Jun 16 |
nicklas |
var html; |
4000 |
17 Jun 16 |
nicklas |
var numReports = 0; |
4000 |
17 Jun 16 |
nicklas |
numReports += response.newReports.length; |
4005 |
21 Jun 16 |
nicklas |
html = delivery.createTBodySection(response.newReports, 'new-report', 'Nya rapporter', 'Det finns inga nya rapporter.'); |
4000 |
17 Jun 16 |
nicklas |
Doc.element('new-reports-section').innerHTML = html; |
4006 |
21 Jun 16 |
nicklas |
Doc.showHide('new-reports-section', response.newReports.length > 0 || !hasSearchParameters); |
4005 |
21 Jun 16 |
nicklas |
249 |
|
4000 |
17 Jun 16 |
nicklas |
numReports += response.workInProgress.length; |
4000 |
17 Jun 16 |
nicklas |
html = delivery.createTBodySection(response.workInProgress, 'work-in-progress', 'Arbete pågår'); |
4000 |
17 Jun 16 |
nicklas |
Doc.element('work-in-progress-section').innerHTML = html; |
4000 |
17 Jun 16 |
nicklas |
Doc.showHide('work-in-progress-section', response.workInProgress.length > 0); |
4000 |
17 Jun 16 |
nicklas |
254 |
|
4000 |
17 Jun 16 |
nicklas |
numReports += response.archived.length; |
4000 |
17 Jun 16 |
nicklas |
html = delivery.createTBodySection(response.archived, 'archived-report'); |
4000 |
17 Jun 16 |
nicklas |
Doc.element('archive-section').innerHTML = html; |
4000 |
17 Jun 16 |
nicklas |
Doc.showHide('archive-section', response.archived.length > 0); |
4000 |
17 Jun 16 |
nicklas |
259 |
|
4009 |
23 Jun 16 |
nicklas |
if (numReports == 0) |
4009 |
23 Jun 16 |
nicklas |
261 |
{ |
4009 |
23 Jun 16 |
nicklas |
delivery.showMessage('Det finns inga rapporter.'); |
4009 |
23 Jun 16 |
nicklas |
Doc.hide('new-reports-section'); |
4009 |
23 Jun 16 |
nicklas |
264 |
} |
4004 |
20 Jun 16 |
nicklas |
265 |
|
4009 |
23 Jun 16 |
nicklas |
// Handle links to PDF documents |
4004 |
20 Jun 16 |
nicklas |
var pdfLinks = document.getElementsByClassName('download-pdf'); |
4004 |
20 Jun 16 |
nicklas |
for (var pdfNo = 0; pdfNo < pdfLinks.length; pdfNo++) |
4004 |
20 Jun 16 |
nicklas |
269 |
{ |
4004 |
20 Jun 16 |
nicklas |
Events.addEventHandler(pdfLinks[pdfNo], 'click', delivery.downloadPdf); |
4004 |
20 Jun 16 |
nicklas |
271 |
} |
4000 |
17 Jun 16 |
nicklas |
272 |
} |
4000 |
17 Jun 16 |
nicklas |
273 |
|
4004 |
20 Jun 16 |
nicklas |
274 |
|
4009 |
23 Jun 16 |
nicklas |
275 |
/** |
4009 |
23 Jun 16 |
nicklas |
Generate HTML for a section in the table. |
4009 |
23 Jun 16 |
nicklas |
specimen = List of specimen information |
4009 |
23 Jun 16 |
nicklas |
rowClass = Class attribute of each new <tr> tag |
4009 |
23 Jun 16 |
nicklas |
header = Header text for the section (rotated; may be null) |
4009 |
23 Jun 16 |
nicklas |
msgIfNoSpecimen = Message to display if the specimen list is emtpy |
4009 |
23 Jun 16 |
nicklas |
281 |
*/ |
4005 |
21 Jun 16 |
nicklas |
delivery.createTBodySection = function(specimen, rowClass, header, msgIfNoSpecimen) |
4000 |
17 Jun 16 |
nicklas |
283 |
{ |
4000 |
17 Jun 16 |
nicklas |
var html = ''; |
4005 |
21 Jun 16 |
nicklas |
if (specimen.length == 0 && msgIfNoSpecimen) |
4005 |
21 Jun 16 |
nicklas |
286 |
{ |
4005 |
21 Jun 16 |
nicklas |
html += '<tr class="'+rowClass+'">'; |
4005 |
21 Jun 16 |
nicklas |
if (header) |
4005 |
21 Jun 16 |
nicklas |
289 |
{ |
4005 |
21 Jun 16 |
nicklas |
html += '<td class="section-header small"></td>'; |
4005 |
21 Jun 16 |
nicklas |
291 |
} |
4005 |
21 Jun 16 |
nicklas |
else |
4005 |
21 Jun 16 |
nicklas |
293 |
{ |
4005 |
21 Jun 16 |
nicklas |
html += '<td></td>'; |
4005 |
21 Jun 16 |
nicklas |
295 |
} |
4005 |
21 Jun 16 |
nicklas |
html += '<td colspan="8">' + msgIfNoSpecimen + '</td>'; |
4005 |
21 Jun 16 |
nicklas |
html += '</tr>'; |
4005 |
21 Jun 16 |
nicklas |
298 |
} |
4005 |
21 Jun 16 |
nicklas |
299 |
|
4000 |
17 Jun 16 |
nicklas |
for (var spNo = 0; spNo < specimen.length; spNo++) |
4000 |
17 Jun 16 |
nicklas |
301 |
{ |
4000 |
17 Jun 16 |
nicklas |
var sp = specimen[spNo]; |
4000 |
17 Jun 16 |
nicklas |
var pat = sp.patient; |
4000 |
17 Jun 16 |
nicklas |
var report = sp.pilotReport; |
4000 |
17 Jun 16 |
nicklas |
305 |
|
4000 |
17 Jun 16 |
nicklas |
html += '<tr class="'+rowClass+'">'; |
4000 |
17 Jun 16 |
nicklas |
if (header) |
4000 |
17 Jun 16 |
nicklas |
308 |
{ |
4000 |
17 Jun 16 |
nicklas |
if (spNo == 0) |
4000 |
17 Jun 16 |
nicklas |
310 |
{ |
4000 |
17 Jun 16 |
nicklas |
html += '<td rowspan="'+specimen.length+'" class="section-header">'; |
4000 |
17 Jun 16 |
nicklas |
html += '<div class="rotate">'+header+'</div>'; |
4000 |
17 Jun 16 |
nicklas |
html += '</td>'; |
4000 |
17 Jun 16 |
nicklas |
314 |
} |
4000 |
17 Jun 16 |
nicklas |
315 |
} |
4000 |
17 Jun 16 |
nicklas |
else |
4000 |
17 Jun 16 |
nicklas |
317 |
{ |
4000 |
17 Jun 16 |
nicklas |
html += '<td></td>'; |
4000 |
17 Jun 16 |
nicklas |
319 |
} |
4000 |
17 Jun 16 |
nicklas |
320 |
|
4000 |
17 Jun 16 |
nicklas |
html += '<td>'+Strings.encodeTags(pat.PersonalNo)+'</td>'; |
4000 |
17 Jun 16 |
nicklas |
html += '<td>'+Strings.encodeTags(pat.AllFirstNames + ' ' + pat.FamilyName)+'</td>'; |
4037 |
29 Jul 16 |
nicklas |
html += '<td>'+Strings.encodeTags(sp.PAD)+'</td>'; |
4000 |
17 Jun 16 |
nicklas |
html += '<td>'+Strings.encodeTags(sp.name)+'</td>'; |
4000 |
17 Jun 16 |
nicklas |
html += '<td>'+Reggie.reformatDate(sp.ArrivalDate)+'</td>'; |
4000 |
17 Jun 16 |
nicklas |
326 |
|
4000 |
17 Jun 16 |
nicklas |
if (report) |
4000 |
17 Jun 16 |
nicklas |
328 |
{ |
4000 |
17 Jun 16 |
nicklas |
html += '<td>'+Reggie.reformatDate(report.lastUpdatedDate)+'</td>'; |
4000 |
17 Jun 16 |
nicklas |
if (report.downloadCount) |
4000 |
17 Jun 16 |
nicklas |
331 |
{ |
4000 |
17 Jun 16 |
nicklas |
html += '<td>'+Reggie.reformatDate(report.downloadedDate)+' ('+report.downloadCount+')</td>'; |
4000 |
17 Jun 16 |
nicklas |
333 |
} |
4000 |
17 Jun 16 |
nicklas |
else |
4000 |
17 Jun 16 |
nicklas |
335 |
{ |
4000 |
17 Jun 16 |
nicklas |
html += '<td>Nej</td>'; |
4000 |
17 Jun 16 |
nicklas |
337 |
} |
4004 |
20 Jun 16 |
nicklas |
html += '<td><img src="images/pdf-26.png" class="link download-pdf"'; |
4009 |
23 Jun 16 |
nicklas |
html += ' title="Ladda ner den här rapporten"'; |
4004 |
20 Jun 16 |
nicklas |
html += ' data-file-id="'+report.id+'" data-specimen-id="'+sp.id+'"></td>'; |
4000 |
17 Jun 16 |
nicklas |
341 |
} |
4040 |
29 Jul 16 |
nicklas |
else if (sp.CompletedDate) |
4040 |
29 Jul 16 |
nicklas |
343 |
{ |
4040 |
29 Jul 16 |
nicklas |
html += '<td class="completed-without-report" colspan="3">'; |
4182 |
27 Oct 16 |
nicklas |
html += 'Rapport saknas. Kontakta SCAN-B lab för information.</td>'; |
4040 |
29 Jul 16 |
nicklas |
346 |
} |
4000 |
17 Jun 16 |
nicklas |
else |
4000 |
17 Jun 16 |
nicklas |
348 |
{ |
4000 |
17 Jun 16 |
nicklas |
html += '<td colspan="3"></td>'; |
4000 |
17 Jun 16 |
nicklas |
350 |
} |
4000 |
17 Jun 16 |
nicklas |
351 |
|
4000 |
17 Jun 16 |
nicklas |
html += '</tr>'; |
4000 |
17 Jun 16 |
nicklas |
353 |
} |
4000 |
17 Jun 16 |
nicklas |
354 |
|
4000 |
17 Jun 16 |
nicklas |
return html; |
4000 |
17 Jun 16 |
nicklas |
356 |
} |
4009 |
23 Jun 16 |
nicklas |
357 |
|
4009 |
23 Jun 16 |
nicklas |
358 |
/** |
4009 |
23 Jun 16 |
nicklas |
Download a PDF document. |
4009 |
23 Jun 16 |
nicklas |
360 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.downloadPdf = function(event) |
4009 |
23 Jun 16 |
nicklas |
362 |
{ |
4009 |
23 Jun 16 |
nicklas |
var target = event.currentTarget; |
4009 |
23 Jun 16 |
nicklas |
364 |
|
4009 |
23 Jun 16 |
nicklas |
var url = '../Delivery.servlet?ID='+App.getSessionId(); |
4009 |
23 Jun 16 |
nicklas |
url += '&cmd=DownloadReport'; |
4009 |
23 Jun 16 |
nicklas |
url += '&fileId='+Data.int(target, 'file-id'); |
4009 |
23 Jun 16 |
nicklas |
url += '&specimenId='+Data.int(target, 'specimen-id'); |
4009 |
23 Jun 16 |
nicklas |
369 |
|
4009 |
23 Jun 16 |
nicklas |
// The timeout will update the list with specimen |
4009 |
23 Jun 16 |
nicklas |
// (since the report may move between sections) |
4009 |
23 Jun 16 |
nicklas |
setTimeout(delivery.loadSpecimenInformation, 1500); |
4009 |
23 Jun 16 |
nicklas |
373 |
|
4009 |
23 Jun 16 |
nicklas |
window.open(url, 'DownloadPdf', 'width=600,height=400'); |
4009 |
23 Jun 16 |
nicklas |
375 |
} |
4009 |
23 Jun 16 |
nicklas |
376 |
|
4009 |
23 Jun 16 |
nicklas |
377 |
/** |
4009 |
23 Jun 16 |
nicklas |
Logout. |
4009 |
23 Jun 16 |
nicklas |
379 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.logout = function() |
4009 |
23 Jun 16 |
nicklas |
381 |
{ |
4009 |
23 Jun 16 |
nicklas |
Doc.element('auto-logout').innerHTML = 'Loggar ut...'; |
4009 |
23 Jun 16 |
nicklas |
var url = '../Delivery.servlet?ID='+App.getSessionId(); |
4009 |
23 Jun 16 |
nicklas |
url += '&cmd=Logout'; |
4009 |
23 Jun 16 |
nicklas |
// Request for logging out, all responses will trigger the redirect |
4009 |
23 Jun 16 |
nicklas |
Wizard.asyncJsonRequest(url, delivery.onLoggedOut, 'GET', null, delivery.onLoggedOut); |
4009 |
23 Jun 16 |
nicklas |
387 |
} |
4000 |
17 Jun 16 |
nicklas |
388 |
|
4009 |
23 Jun 16 |
nicklas |
389 |
/** |
4009 |
23 Jun 16 |
nicklas |
Redirect to the login page without history. |
4009 |
23 Jun 16 |
nicklas |
391 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.onLoggedOut = function() |
4009 |
23 Jun 16 |
nicklas |
393 |
{ |
4009 |
23 Jun 16 |
nicklas |
location.replace('index.jsp'); |
4009 |
23 Jun 16 |
nicklas |
395 |
} |
4005 |
21 Jun 16 |
nicklas |
396 |
|
4009 |
23 Jun 16 |
nicklas |
397 |
/** |
4009 |
23 Jun 16 |
nicklas |
Update timeout information for the current session. If the |
4009 |
23 Jun 16 |
nicklas |
timeout has been passed and automatick logout request is |
4009 |
23 Jun 16 |
nicklas |
sent. |
4009 |
23 Jun 16 |
nicklas |
401 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.updateTimeout = function() |
4009 |
23 Jun 16 |
nicklas |
403 |
{ |
4009 |
23 Jun 16 |
nicklas |
if (currentUser) |
4009 |
23 Jun 16 |
nicklas |
405 |
{ |
4009 |
23 Jun 16 |
nicklas |
var timeout = currentUser.timeout; |
4009 |
23 Jun 16 |
nicklas |
var now = new Date().getTime(); |
4009 |
23 Jun 16 |
nicklas |
408 |
|
4009 |
23 Jun 16 |
nicklas |
if (timeout < now) |
4009 |
23 Jun 16 |
nicklas |
410 |
{ |
4009 |
23 Jun 16 |
nicklas |
// Auto logout should happen now |
4009 |
23 Jun 16 |
nicklas |
delivery.logout(); |
4009 |
23 Jun 16 |
nicklas |
return; |
4009 |
23 Jun 16 |
nicklas |
414 |
} |
4009 |
23 Jun 16 |
nicklas |
415 |
|
4009 |
23 Jun 16 |
nicklas |
// Minutes to timeout rounded up |
4009 |
23 Jun 16 |
nicklas |
var minutesToTimeout = Math.ceil((timeout - now) / 60000); |
4009 |
23 Jun 16 |
nicklas |
// Seconds to timeout rounded up to nearest 15 seconds |
4009 |
23 Jun 16 |
nicklas |
var secondsToTimeout = 15 * Math.ceil((timeout - now) / 15000); |
4009 |
23 Jun 16 |
nicklas |
420 |
|
4009 |
23 Jun 16 |
nicklas |
var autoLogout = ''; |
4009 |
23 Jun 16 |
nicklas |
if (minutesToTimeout > 1) |
4009 |
23 Jun 16 |
nicklas |
423 |
{ |
4009 |
23 Jun 16 |
nicklas |
// There is still more than one minute |
4009 |
23 Jun 16 |
nicklas |
// Display a warning if it is less than the warning limit |
4009 |
23 Jun 16 |
nicklas |
if (minutesToTimeout <= WARN_BEFORE_TIMEOUT) |
4009 |
23 Jun 16 |
nicklas |
427 |
{ |
4009 |
23 Jun 16 |
nicklas |
autoLogout = 'Automatisk utloggning om <b>'+minutesToTimeout+' minuter</b>'; |
4009 |
23 Jun 16 |
nicklas |
429 |
} |
4009 |
23 Jun 16 |
nicklas |
430 |
} |
4009 |
23 Jun 16 |
nicklas |
else |
4009 |
23 Jun 16 |
nicklas |
432 |
{ |
4009 |
23 Jun 16 |
nicklas |
autoLogout = 'Automatisk utloggning om <b>'+secondsToTimeout+' sekunder</b>'; |
4009 |
23 Jun 16 |
nicklas |
434 |
} |
4009 |
23 Jun 16 |
nicklas |
Doc.element('auto-logout').innerHTML = autoLogout; |
4009 |
23 Jun 16 |
nicklas |
436 |
} |
4009 |
23 Jun 16 |
nicklas |
437 |
|
4009 |
23 Jun 16 |
nicklas |
// Repeat every 5 seconds |
4009 |
23 Jun 16 |
nicklas |
setTimeout(delivery.updateTimeout, 5000); |
4009 |
23 Jun 16 |
nicklas |
440 |
} |
4009 |
23 Jun 16 |
nicklas |
441 |
|
4009 |
23 Jun 16 |
nicklas |
442 |
/** |
4009 |
23 Jun 16 |
nicklas |
Error handler for AJAX requests |
4009 |
23 Jun 16 |
nicklas |
444 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.errorHandler = function(response, error) |
4009 |
23 Jun 16 |
nicklas |
446 |
{ |
4009 |
23 Jun 16 |
nicklas |
if (debug) |
4009 |
23 Jun 16 |
nicklas |
448 |
{ |
4009 |
23 Jun 16 |
nicklas |
App.debug(response); |
4009 |
23 Jun 16 |
nicklas |
App.debug(error); |
4009 |
23 Jun 16 |
nicklas |
451 |
} |
4009 |
23 Jun 16 |
nicklas |
452 |
|
4009 |
23 Jun 16 |
nicklas |
// Try to translate the error to Swedish |
4009 |
23 Jun 16 |
nicklas |
var err = delivery.translateError(response ? response.message : error.toString()); |
4009 |
23 Jun 16 |
nicklas |
455 |
|
4009 |
23 Jun 16 |
nicklas |
var msg = 'Det gick inte att hämta information om proven!'; |
4009 |
23 Jun 16 |
nicklas |
msg += '<div class="error-text" title="'+Strings.encodeTags(err.originalMessage)+'">'; |
4009 |
23 Jun 16 |
nicklas |
msg += Strings.encodeTags(err.message); |
4009 |
23 Jun 16 |
nicklas |
msg += '</div>'; |
4009 |
23 Jun 16 |
nicklas |
460 |
|
4009 |
23 Jun 16 |
nicklas |
delivery.showMessage(msg); |
4009 |
23 Jun 16 |
nicklas |
462 |
} |
4009 |
23 Jun 16 |
nicklas |
463 |
|
4009 |
23 Jun 16 |
nicklas |
464 |
/** |
4009 |
23 Jun 16 |
nicklas |
Translate some common error messages to Swedish. Returns an object with |
4009 |
23 Jun 16 |
nicklas |
* originalMessage: The original error message |
4009 |
23 Jun 16 |
nicklas |
* message: The translated error message (or the original if no translation was found) |
4009 |
23 Jun 16 |
nicklas |
468 |
|
4009 |
23 Jun 16 |
nicklas |
If the error message indicates that the session is no longer active the |
4009 |
23 Jun 16 |
nicklas |
browser will be redirected to the login page. |
4009 |
23 Jun 16 |
nicklas |
471 |
*/ |
4009 |
23 Jun 16 |
nicklas |
delivery.translateError = function(message) |
4009 |
23 Jun 16 |
nicklas |
473 |
{ |
4009 |
23 Jun 16 |
nicklas |
var err = {}; |
4009 |
23 Jun 16 |
nicklas |
err.originalMessage = message; |
4009 |
23 Jun 16 |
nicklas |
err.message = message; |
4009 |
23 Jun 16 |
nicklas |
477 |
|
4009 |
23 Jun 16 |
nicklas |
// The user has logged out! |
4009 |
23 Jun 16 |
nicklas |
if (message.indexOf('Not logged in') >= 0 || |
4009 |
23 Jun 16 |
nicklas |
(message.indexOf('Item not found') >= 0 && message.indexOf('SessionControl') >= 0)) |
4009 |
23 Jun 16 |
nicklas |
481 |
{ |
4009 |
23 Jun 16 |
nicklas |
delivery.onLoggedOut(); |
4009 |
23 Jun 16 |
nicklas |
483 |
} |
4009 |
23 Jun 16 |
nicklas |
484 |
|
4009 |
23 Jun 16 |
nicklas |
if (message.indexOf('Permission denied') >= 0 || |
4009 |
23 Jun 16 |
nicklas |
(message.indexOf('Item not found') >= 0 && message.indexOf('AnnotationType') >= 0)) |
4009 |
23 Jun 16 |
nicklas |
487 |
{ |
4009 |
23 Jun 16 |
nicklas |
err.message = 'Behörighet saknas'; |
4009 |
23 Jun 16 |
nicklas |
489 |
|
4009 |
23 Jun 16 |
nicklas |
if (message.indexOf('Biosource') >= 0) |
4009 |
23 Jun 16 |
nicklas |
491 |
{ |
4009 |
23 Jun 16 |
nicklas |
err.message += ' för åtkomst till patient-information'; |
4009 |
23 Jun 16 |
nicklas |
493 |
} |
4009 |
23 Jun 16 |
nicklas |
else if (message.indexOf('Sample') >= 0) |
4009 |
23 Jun 16 |
nicklas |
495 |
{ |
4009 |
23 Jun 16 |
nicklas |
err.message += ' för åtkomst till prov-information'; |
4009 |
23 Jun 16 |
nicklas |
497 |
} |
4009 |
23 Jun 16 |
nicklas |
else if (message.indexOf('Annotation') >= 0) |
4009 |
23 Jun 16 |
nicklas |
499 |
{ |
4009 |
23 Jun 16 |
nicklas |
if (message.indexOf('PersonalNumber') >= 0 || |
4009 |
23 Jun 16 |
nicklas |
message.indexOf('AllFirstNames') >= 0 || |
4009 |
23 Jun 16 |
nicklas |
message.indexOf('FamilyName') >= 0) |
4009 |
23 Jun 16 |
nicklas |
503 |
{ |
4009 |
23 Jun 16 |
nicklas |
err.message += ' för åtkomst till patient-information'; |
4009 |
23 Jun 16 |
nicklas |
505 |
} |
4009 |
23 Jun 16 |
nicklas |
else |
4009 |
23 Jun 16 |
nicklas |
507 |
{ |
4009 |
23 Jun 16 |
nicklas |
err.message += ' för åtkomst till prov-information'; |
4009 |
23 Jun 16 |
nicklas |
509 |
} |
4009 |
23 Jun 16 |
nicklas |
510 |
} |
4009 |
23 Jun 16 |
nicklas |
511 |
} |
4009 |
23 Jun 16 |
nicklas |
512 |
|
4009 |
23 Jun 16 |
nicklas |
return err; |
4009 |
23 Jun 16 |
nicklas |
514 |
} |
4009 |
23 Jun 16 |
nicklas |
515 |
|
4000 |
17 Jun 16 |
nicklas |
return delivery; |
4000 |
17 Jun 16 |
nicklas |
517 |
}(); |
4000 |
17 Jun 16 |
nicklas |
518 |
|
4000 |
17 Jun 16 |
nicklas |
Doc.onLoad(Delivery.initPage); |
4000 |
17 Jun 16 |
nicklas |
520 |
|
4000 |
17 Jun 16 |
nicklas |
521 |
|
4000 |
17 Jun 16 |
nicklas |
522 |
|