6277 |
03 Jun 21 |
nicklas |
var Xport = function() |
4014 |
06 Jul 16 |
olle |
2 |
{ |
6277 |
03 Jun 21 |
nicklas |
var xport = {}; |
4014 |
06 Jul 16 |
olle |
var debug = 0; |
4014 |
06 Jul 16 |
olle |
5 |
|
6277 |
03 Jun 21 |
nicklas |
var siteIsValid = false; |
6277 |
03 Jun 21 |
nicklas |
var startNumberIsValid = false; |
6277 |
03 Jun 21 |
nicklas |
var numKitsIsValid = false; |
4014 |
06 Jul 16 |
olle |
9 |
|
6277 |
03 Jun 21 |
nicklas |
xport.initPage = function() |
4014 |
06 Jul 16 |
olle |
11 |
{ |
4014 |
06 Jul 16 |
olle |
// Step 1 |
6277 |
03 Jun 21 |
nicklas |
Events.addEventHandler('step-1', 'wizard-validate', xport.validateStep1); |
6277 |
03 Jun 21 |
nicklas |
Events.addEventHandler('site', 'change', xport.siteOnChange); |
6277 |
03 Jun 21 |
nicklas |
Events.addEventHandler('startNumber', 'blur', xport.startNumberOnChange); |
6277 |
03 Jun 21 |
nicklas |
Events.addEventHandler('startNumber', 'keypress', Events.integerOnly); |
6277 |
03 Jun 21 |
nicklas |
Events.addEventHandler('numKits', 'blur', xport.numKitsOnChange); |
6277 |
03 Jun 21 |
nicklas |
Events.addEventHandler('numKits', 'keypress', Events.integerOnly); |
6277 |
03 Jun 21 |
nicklas |
Events.addEventHandler('viewLogFile', 'click', xport.viewLogFile); |
4014 |
06 Jul 16 |
olle |
20 |
|
4014 |
06 Jul 16 |
olle |
// Navigation |
4014 |
06 Jul 16 |
olle |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
6277 |
03 Jun 21 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
6277 |
03 Jun 21 |
nicklas |
Buttons.addClickHandler('gopreview', xport.goPreview); |
6277 |
03 Jun 21 |
nicklas |
Buttons.addClickHandler('viewLogFile2', xport.viewLogFile); |
6277 |
03 Jun 21 |
nicklas |
Buttons.addClickHandler('godownload', xport.downloadBD47File); |
6277 |
03 Jun 21 |
nicklas |
27 |
|
6277 |
03 Jun 21 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', xport.goExport); |
4014 |
06 Jul 16 |
olle |
29 |
|
4014 |
06 Jul 16 |
olle |
Doc.show('step-1'); |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('site', 'invalid'); |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('startNumber', 'invalid'); |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('numKits', 'invalid'); |
4014 |
06 Jul 16 |
olle |
34 |
|
4014 |
06 Jul 16 |
olle |
// Load sites |
4014 |
06 Jul 16 |
olle |
var frm = document.forms['reggie']; |
6277 |
03 Jun 21 |
nicklas |
var url = '../ReferralGenerator.servlet?ID='+App.getSessionId(); |
6277 |
03 Jun 21 |
nicklas |
url += '&cmd=GetSitesAndStartNumber'; |
6277 |
03 Jun 21 |
nicklas |
Doc.addClass('site', 'list-loading'); |
6277 |
03 Jun 21 |
nicklas |
frm.site[0] = new Option('loading...'); |
6277 |
03 Jun 21 |
nicklas |
Wizard.asyncJsonRequest(url, xport.sitesLoaded); |
4014 |
06 Jul 16 |
olle |
42 |
} |
4014 |
06 Jul 16 |
olle |
43 |
|
6277 |
03 Jun 21 |
nicklas |
xport.sitesLoaded = function(response) |
4014 |
06 Jul 16 |
olle |
45 |
{ |
6277 |
03 Jun 21 |
nicklas |
Doc.removeClass('site', 'list-loading'); |
4014 |
06 Jul 16 |
olle |
var frm = document.forms['reggie']; |
4014 |
06 Jul 16 |
olle |
var sites = response.sites; |
6277 |
03 Jun 21 |
nicklas |
frm.site.length = 0; |
6277 |
03 Jun 21 |
nicklas |
frm.site[0] = new Option('- Select site -', ''); |
4014 |
06 Jul 16 |
olle |
for (var i = 0; i < sites.length; i++) |
4014 |
06 Jul 16 |
olle |
52 |
{ |
4014 |
06 Jul 16 |
olle |
var s = sites[i]; |
6277 |
03 Jun 21 |
nicklas |
var option = new Option(s.name + ' [' + s.prefix + ']', s.prefix); |
6277 |
03 Jun 21 |
nicklas |
frm.site[frm.site.length] = option; |
4014 |
06 Jul 16 |
olle |
56 |
} |
6277 |
03 Jun 21 |
nicklas |
frm.site.focus(); |
6277 |
03 Jun 21 |
nicklas |
58 |
|
6277 |
03 Jun 21 |
nicklas |
frm.startNumber.value = response.lastReferralID || ''; |
6277 |
03 Jun 21 |
nicklas |
xport.startNumberOnChange(); |
6277 |
03 Jun 21 |
nicklas |
61 |
|
6277 |
03 Jun 21 |
nicklas |
frm.numKits.value = response.lastNumKits || '25'; |
6277 |
03 Jun 21 |
nicklas |
xport.numKitsOnChange(); |
6277 |
03 Jun 21 |
nicklas |
64 |
|
6277 |
03 Jun 21 |
nicklas |
if (response.logFile) |
6277 |
03 Jun 21 |
nicklas |
66 |
{ |
6277 |
03 Jun 21 |
nicklas |
Doc.show('viewLogFile', 'inline'); |
6277 |
03 Jun 21 |
nicklas |
Data.set('viewLogFile', 'file-id', response.logFile); |
6277 |
03 Jun 21 |
nicklas |
69 |
} |
6277 |
03 Jun 21 |
nicklas |
70 |
|
6277 |
03 Jun 21 |
nicklas |
Doc.show('gopreview'); |
6277 |
03 Jun 21 |
nicklas |
Doc.show('goregister'); |
4014 |
06 Jul 16 |
olle |
73 |
} |
6277 |
03 Jun 21 |
nicklas |
74 |
|
6277 |
03 Jun 21 |
nicklas |
xport.siteOnChange = function() |
4080 |
06 Sep 16 |
olle |
76 |
{ |
4080 |
06 Sep 16 |
olle |
var frm = document.forms['reggie']; |
6277 |
03 Jun 21 |
nicklas |
siteIsValid = false; |
6277 |
03 Jun 21 |
nicklas |
Doc.element('sitePrefix').innerHTML = '00 -'; |
6277 |
03 Jun 21 |
nicklas |
80 |
|
6277 |
03 Jun 21 |
nicklas |
if (frm.site.value == '') |
4080 |
06 Sep 16 |
olle |
82 |
{ |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('site', 'invalid', 'Select a site'); |
6277 |
03 Jun 21 |
nicklas |
frm.site.focus(); |
6277 |
03 Jun 21 |
nicklas |
return; |
4080 |
06 Sep 16 |
olle |
86 |
} |
6277 |
03 Jun 21 |
nicklas |
87 |
|
6277 |
03 Jun 21 |
nicklas |
Doc.element('sitePrefix').innerHTML = frm.site.value+' -'; |
6277 |
03 Jun 21 |
nicklas |
siteIsValid = true; |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('site', 'valid'); |
6277 |
03 Jun 21 |
nicklas |
if (frm.startNumber.value == '') |
4080 |
06 Sep 16 |
olle |
92 |
{ |
6277 |
03 Jun 21 |
nicklas |
frm.startNumber.focus(); |
4080 |
06 Sep 16 |
olle |
94 |
} |
4080 |
06 Sep 16 |
olle |
else |
4080 |
06 Sep 16 |
olle |
96 |
{ |
6277 |
03 Jun 21 |
nicklas |
frm.numKits.focus(); |
4080 |
06 Sep 16 |
olle |
98 |
} |
4080 |
06 Sep 16 |
olle |
99 |
} |
6277 |
03 Jun 21 |
nicklas |
100 |
|
6277 |
03 Jun 21 |
nicklas |
xport.startNumberOnChange = function() |
4080 |
06 Sep 16 |
olle |
102 |
{ |
4080 |
06 Sep 16 |
olle |
var frm = document.forms['reggie']; |
6277 |
03 Jun 21 |
nicklas |
startNumberIsValid = false; |
6277 |
03 Jun 21 |
nicklas |
105 |
|
6277 |
03 Jun 21 |
nicklas |
var startNumber = frm.startNumber.value; |
6277 |
03 Jun 21 |
nicklas |
if (startNumber == '') |
4080 |
06 Sep 16 |
olle |
108 |
{ |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('startNumber', 'invalid', 'Missing'); |
4080 |
06 Sep 16 |
olle |
return; |
4080 |
06 Sep 16 |
olle |
111 |
} |
4014 |
06 Jul 16 |
olle |
112 |
|
6277 |
03 Jun 21 |
nicklas |
if (!startNumber.match(/^\d{5}$/)) |
4014 |
06 Jul 16 |
olle |
114 |
{ |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('startNumber', 'invalid', 'It must be 5 digits.'); |
6277 |
03 Jun 21 |
nicklas |
return; |
4014 |
06 Jul 16 |
olle |
117 |
} |
4014 |
06 Jul 16 |
olle |
118 |
|
6277 |
03 Jun 21 |
nicklas |
startNumberIsValid = true; |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('startNumber', 'valid'); |
4014 |
06 Jul 16 |
olle |
121 |
} |
6277 |
03 Jun 21 |
nicklas |
122 |
|
6277 |
03 Jun 21 |
nicklas |
xport.numKitsOnChange = function() |
4014 |
06 Jul 16 |
olle |
124 |
{ |
4014 |
06 Jul 16 |
olle |
var frm = document.forms['reggie']; |
6277 |
03 Jun 21 |
nicklas |
numKitsIsValid = false; |
6277 |
03 Jun 21 |
nicklas |
127 |
|
6277 |
03 Jun 21 |
nicklas |
var numKits = frm.numKits.value; |
6277 |
03 Jun 21 |
nicklas |
if (numKits == '') |
4014 |
06 Jul 16 |
olle |
130 |
{ |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('numKits', 'invalid', 'Missing'); |
4014 |
06 Jul 16 |
olle |
return; |
4014 |
06 Jul 16 |
olle |
133 |
} |
6277 |
03 Jun 21 |
nicklas |
134 |
|
6277 |
03 Jun 21 |
nicklas |
if (!numKits.match(/^\d+$/)) |
4014 |
06 Jul 16 |
olle |
136 |
{ |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('numKits', 'invalid', 'It must be a number.'); |
4014 |
06 Jul 16 |
olle |
return; |
4014 |
06 Jul 16 |
olle |
139 |
} |
6277 |
03 Jun 21 |
nicklas |
140 |
|
6277 |
03 Jun 21 |
nicklas |
var nk = parseInt(numKits); |
6277 |
03 Jun 21 |
nicklas |
if (nk < 1 || nk > 100) |
4074 |
02 Sep 16 |
olle |
143 |
{ |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('numKits', 'invalid', 'It must be between 1 and 100'); |
4074 |
02 Sep 16 |
olle |
return; |
4074 |
02 Sep 16 |
olle |
146 |
} |
6277 |
03 Jun 21 |
nicklas |
147 |
|
6277 |
03 Jun 21 |
nicklas |
numKitsIsValid = true; |
6277 |
03 Jun 21 |
nicklas |
Wizard.setInputStatus('numKits', 'valid'); |
4074 |
02 Sep 16 |
olle |
150 |
} |
4014 |
06 Jul 16 |
olle |
151 |
|
6277 |
03 Jun 21 |
nicklas |
xport.viewLogFile = function(event) |
4074 |
02 Sep 16 |
olle |
153 |
{ |
6277 |
03 Jun 21 |
nicklas |
Dialogs.openPopup('', 'LogFile', 1050, 700); |
6277 |
03 Jun 21 |
nicklas |
Files.viewFile(Data.get(event.currentTarget, 'file-id'), 'LogFile'); |
4014 |
06 Jul 16 |
olle |
156 |
} |
4014 |
06 Jul 16 |
olle |
157 |
|
6277 |
03 Jun 21 |
nicklas |
xport.downloadBD47File = function(event) |
4014 |
06 Jul 16 |
olle |
159 |
{ |
6864 |
04 Nov 22 |
nicklas |
var format = Data.get(event.currentTarget, 'format'); |
6864 |
04 Nov 22 |
nicklas |
if (format == 'zip') |
6864 |
04 Nov 22 |
nicklas |
162 |
{ |
6864 |
04 Nov 22 |
nicklas |
var fileId = Data.get(event.currentTarget, 'file-id'); |
6864 |
04 Nov 22 |
nicklas |
var url = '../download-as-zip.jsp?ID='+App.getSessionId(); |
6864 |
04 Nov 22 |
nicklas |
url += '&fileId='+fileId; |
6864 |
04 Nov 22 |
nicklas |
Dialogs.openPopup(url, 'DownloadAsZip'+fileId, 450, 300); |
6864 |
04 Nov 22 |
nicklas |
167 |
} |
6864 |
04 Nov 22 |
nicklas |
else |
6864 |
04 Nov 22 |
nicklas |
169 |
{ |
6864 |
04 Nov 22 |
nicklas |
var url = App.getRoot()+'filemanager/files/download/-'+App.getSessionId()+'-'; |
6864 |
04 Nov 22 |
nicklas |
url += Data.get(event.currentTarget, 'file-path'); |
6864 |
04 Nov 22 |
nicklas |
location.href = url; |
6864 |
04 Nov 22 |
nicklas |
173 |
} |
4014 |
06 Jul 16 |
olle |
174 |
} |
4014 |
06 Jul 16 |
olle |
175 |
|
6277 |
03 Jun 21 |
nicklas |
xport.validateStep1 = function(event) |
4014 |
06 Jul 16 |
olle |
177 |
{ |
6277 |
03 Jun 21 |
nicklas |
var valid = siteIsValid; |
6277 |
03 Jun 21 |
nicklas |
valid &= startNumberIsValid; |
6277 |
03 Jun 21 |
nicklas |
valid &= numKitsIsValid; |
6277 |
03 Jun 21 |
nicklas |
if (!valid) event.preventDefault(); |
4014 |
06 Jul 16 |
olle |
182 |
} |
4014 |
06 Jul 16 |
olle |
183 |
|
6277 |
03 Jun 21 |
nicklas |
xport.goPreview = function() |
4014 |
06 Jul 16 |
olle |
185 |
{ |
6277 |
03 Jun 21 |
nicklas |
if (!Wizard.validateCurrentStep()) return; |
6277 |
03 Jun 21 |
nicklas |
xport.doExport(true); |
4014 |
06 Jul 16 |
olle |
188 |
} |
6277 |
03 Jun 21 |
nicklas |
189 |
|
6277 |
03 Jun 21 |
nicklas |
xport.goExport = function() |
4014 |
06 Jul 16 |
olle |
191 |
{ |
6277 |
03 Jun 21 |
nicklas |
xport.doExport(false); |
4014 |
06 Jul 16 |
olle |
193 |
} |
4014 |
06 Jul 16 |
olle |
194 |
|
6277 |
03 Jun 21 |
nicklas |
xport.doExport = function(preview) |
4014 |
06 Jul 16 |
olle |
196 |
{ |
4014 |
06 Jul 16 |
olle |
var frm = document.forms['reggie']; |
6277 |
03 Jun 21 |
nicklas |
var url = '../ReferralGenerator.servlet?ID='+App.getSessionId(); |
6277 |
03 Jun 21 |
nicklas |
url += '&cmd=ExportToBD47'; |
4014 |
06 Jul 16 |
olle |
200 |
|
6277 |
03 Jun 21 |
nicklas |
var submitInfo = {}; |
6277 |
03 Jun 21 |
nicklas |
submitInfo.site = frm.site.value; |
6277 |
03 Jun 21 |
nicklas |
submitInfo.kitType = frm.kitType.value; |
6277 |
03 Jun 21 |
nicklas |
submitInfo.startNumber = parseInt(frm.startNumber.value); |
6277 |
03 Jun 21 |
nicklas |
submitInfo.numKits = parseInt(frm.numKits.value); |
6277 |
03 Jun 21 |
nicklas |
206 |
|
6277 |
03 Jun 21 |
nicklas |
Doc.hide('previewWrapper'); |
6277 |
03 Jun 21 |
nicklas |
if (preview) |
6277 |
03 Jun 21 |
nicklas |
209 |
{ |
6277 |
03 Jun 21 |
nicklas |
url += '&preview=1'; |
6277 |
03 Jun 21 |
nicklas |
Wizard.asyncJsonRequest(url, xport.onPreviewLoaded, 'POST', JSON.stringify(submitInfo)); |
6277 |
03 Jun 21 |
nicklas |
212 |
} |
6277 |
03 Jun 21 |
nicklas |
else |
6277 |
03 Jun 21 |
nicklas |
214 |
{ |
6277 |
03 Jun 21 |
nicklas |
Wizard.asyncJsonRequest(url, xport.submissionResults, 'POST', JSON.stringify(submitInfo)); |
6277 |
03 Jun 21 |
nicklas |
216 |
} |
4014 |
06 Jul 16 |
olle |
217 |
} |
6277 |
03 Jun 21 |
nicklas |
218 |
|
6277 |
03 Jun 21 |
nicklas |
xport.submissionResults = function(response) |
4014 |
06 Jul 16 |
olle |
220 |
{ |
6277 |
03 Jun 21 |
nicklas |
var msg = response.messages; |
6864 |
04 Nov 22 |
nicklas |
msg[msg.length] = '[HTML]BD47 file save to: '+response.bd47Path; |
6864 |
04 Nov 22 |
nicklas |
msg[msg.length] = '[HTML]Download as <span id="downloadBd47CSV" class="link" data-format="csv" title="Download as CSV">CSV</span>'+ |
6864 |
04 Nov 22 |
nicklas |
' <span id="downloadBd47ZIP" class="link" data-format="zip" title="Download as ZIP">ZIP</span>'; |
6277 |
03 Jun 21 |
nicklas |
msg[msg.length] = '[HTML]<span id="viewLogFile2" class="link">View log file</span>'; |
6277 |
03 Jun 21 |
nicklas |
Wizard.showFinalMessage(msg); |
6277 |
03 Jun 21 |
nicklas |
Data.set('viewLogFile2', 'file-id', response.logFile); |
6864 |
04 Nov 22 |
nicklas |
Data.set('downloadBd47CSV', 'file-path', response.bd47Path); |
6864 |
04 Nov 22 |
nicklas |
Data.set('downloadBd47ZIP', 'file-id', response.bd47File); |
6277 |
03 Jun 21 |
nicklas |
Events.addEventHandler('viewLogFile2', 'click', xport.viewLogFile); |
6864 |
04 Nov 22 |
nicklas |
Events.addEventHandler('downloadBd47CSV', 'click', xport.downloadBD47File); |
6864 |
04 Nov 22 |
nicklas |
Events.addEventHandler('downloadBd47ZIP', 'click', xport.downloadBD47File); |
6277 |
03 Jun 21 |
nicklas |
Doc.show('gorestart'); |
4014 |
06 Jul 16 |
olle |
234 |
} |
4014 |
06 Jul 16 |
olle |
235 |
|
6277 |
03 Jun 21 |
nicklas |
236 |
|
6277 |
03 Jun 21 |
nicklas |
xport.onPreviewLoaded = function(response) |
6277 |
03 Jun 21 |
nicklas |
238 |
{ |
6277 |
03 Jun 21 |
nicklas |
var allLines = response.csv.split('\n'); |
6277 |
03 Jun 21 |
nicklas |
var maxLine = allLines.length - 2; // First line is a header line |
6277 |
03 Jun 21 |
nicklas |
241 |
|
6277 |
03 Jun 21 |
nicklas |
var html = '<tr><th>'+allLines[0].replace(/;/g, '</th><th>')+'</th></tr>'; |
6277 |
03 Jun 21 |
nicklas |
for (var i = 1 ; i <= maxLine; i++) |
4014 |
06 Jul 16 |
olle |
244 |
{ |
6277 |
03 Jun 21 |
nicklas |
html += '<tr><td>'+allLines[i].replace(/;/g, '</td><td>')+'</td></tr>'; |
4014 |
06 Jul 16 |
olle |
246 |
} |
6277 |
03 Jun 21 |
nicklas |
247 |
|
6277 |
03 Jun 21 |
nicklas |
previewList.innerHTML = '<table>'+html+'</table>'; |
6277 |
03 Jun 21 |
nicklas |
Doc.show('previewWrapper'); |
4014 |
06 Jul 16 |
olle |
250 |
} |
4014 |
06 Jul 16 |
olle |
251 |
|
6277 |
03 Jun 21 |
nicklas |
252 |
|
6277 |
03 Jun 21 |
nicklas |
return xport; |
4014 |
06 Jul 16 |
olle |
254 |
}(); |
4014 |
06 Jul 16 |
olle |
255 |
|
6277 |
03 Jun 21 |
nicklas |
Doc.onLoad(Xport.initPage); |
4014 |
06 Jul 16 |
olle |
257 |
|