5425 |
14 May 19 |
nicklas |
var LibReg = function() |
5425 |
14 May 19 |
nicklas |
2 |
{ |
5425 |
14 May 19 |
nicklas |
var libreg = {}; |
5425 |
14 May 19 |
nicklas |
var debug = 0; |
5425 |
14 May 19 |
nicklas |
5 |
|
5425 |
14 May 19 |
nicklas |
var libCommentsIsValid = false; |
5429 |
16 May 19 |
nicklas |
var barcodeTemplateIsValid = false; |
5425 |
14 May 19 |
nicklas |
8 |
|
5425 |
14 May 19 |
nicklas |
// Page initialization |
5425 |
14 May 19 |
nicklas |
libreg.initPage = function() |
5425 |
14 May 19 |
nicklas |
11 |
{ |
5425 |
14 May 19 |
nicklas |
// Step 1 |
5425 |
14 May 19 |
nicklas |
Events.addEventHandler('bioplate', 'change', libreg.bioPlateOnChange); |
5425 |
14 May 19 |
nicklas |
Events.addEventHandler('outcomeSuccess', 'click', libreg.outcomeOnChange); |
5425 |
14 May 19 |
nicklas |
Events.addEventHandler('outcomeFailed', 'click', libreg.outcomeOnChange); |
5425 |
14 May 19 |
nicklas |
Events.addEventHandler('step-1', 'wizard-validate', libreg.validateStep1); |
5425 |
14 May 19 |
nicklas |
17 |
|
5425 |
14 May 19 |
nicklas |
// Step 2 |
5425 |
14 May 19 |
nicklas |
Events.addEventHandler('step-2', 'wizard-initialize', libreg.initializeStep2); |
5425 |
14 May 19 |
nicklas |
Events.addEventHandler('step-2', 'wizard-validate', libreg.validateStep2); |
5450 |
27 May 19 |
nicklas |
Events.addEventHandler('hybridizationDate', 'blur', Wizard.validateDate); |
5450 |
27 May 19 |
nicklas |
Events.addEventHandler('pcrDate', 'blur', Wizard.validateDate); |
5425 |
14 May 19 |
nicklas |
Events.addEventHandler('cleanupDate', 'blur', Wizard.validateDate); |
5425 |
14 May 19 |
nicklas |
Events.addEventHandler('libComments', 'blur', libreg.libCommentsOnChange); |
5760 |
26 Nov 19 |
nicklas |
Events.addEventHandler('barcodeTemplate', 'change', libreg.barcodeTemplateOnChange); |
5425 |
14 May 19 |
nicklas |
26 |
|
5425 |
14 May 19 |
nicklas |
// Navigation |
5425 |
14 May 19 |
nicklas |
Buttons.addClickHandler('gocancel', Wizard.cancelWizard); |
5425 |
14 May 19 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
5425 |
14 May 19 |
nicklas |
Buttons.addClickHandler('gonext', Wizard.goNextOnClick); |
5425 |
14 May 19 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
5425 |
14 May 19 |
nicklas |
32 |
|
5425 |
14 May 19 |
nicklas |
// Final registration |
5425 |
14 May 19 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', libreg.submit); |
5425 |
14 May 19 |
nicklas |
35 |
|
5425 |
14 May 19 |
nicklas |
var url = '../Mips.servlet?ID='+App.getSessionId(); |
5425 |
14 May 19 |
nicklas |
url += '&cmd=GetUnprocessedPlates&plateType=MIPS'; |
5425 |
14 May 19 |
nicklas |
Wizard.showLoadingAnimation('Loading MIPs plates...'); |
5425 |
14 May 19 |
nicklas |
Wizard.asyncJsonRequest(url, libreg.initializeStep1); |
5425 |
14 May 19 |
nicklas |
40 |
} |
5425 |
14 May 19 |
nicklas |
41 |
|
5425 |
14 May 19 |
nicklas |
42 |
|
5425 |
14 May 19 |
nicklas |
libreg.initializeStep1 = function(response) |
5425 |
14 May 19 |
nicklas |
44 |
{ |
5425 |
14 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5425 |
14 May 19 |
nicklas |
var bioplates = response.bioplates; |
5425 |
14 May 19 |
nicklas |
47 |
|
5425 |
14 May 19 |
nicklas |
var plates = frm.bioplate; |
5425 |
14 May 19 |
nicklas |
if (bioplates.length > 0) |
5425 |
14 May 19 |
nicklas |
50 |
{ |
5425 |
14 May 19 |
nicklas |
for (var i=0; i < bioplates.length; i++) |
5425 |
14 May 19 |
nicklas |
52 |
{ |
5425 |
14 May 19 |
nicklas |
var bioplate = bioplates[i]; |
5425 |
14 May 19 |
nicklas |
var name = bioplate.name; |
5425 |
14 May 19 |
nicklas |
var option = new Option(name, bioplate.id); |
5425 |
14 May 19 |
nicklas |
option.bioplate = bioplate; |
5425 |
14 May 19 |
nicklas |
plates.options[plates.length] = option; |
5425 |
14 May 19 |
nicklas |
58 |
} |
5425 |
14 May 19 |
nicklas |
59 |
} |
5425 |
14 May 19 |
nicklas |
else |
5425 |
14 May 19 |
nicklas |
61 |
{ |
5425 |
14 May 19 |
nicklas |
Wizard.setFatalError('No MIPs plates available for processing.'); |
5425 |
14 May 19 |
nicklas |
return; |
5425 |
14 May 19 |
nicklas |
64 |
} |
5425 |
14 May 19 |
nicklas |
65 |
|
5425 |
14 May 19 |
nicklas |
libreg.bioPlateOnChange(); |
5425 |
14 May 19 |
nicklas |
libreg.outcomeOnChange(); |
5425 |
14 May 19 |
nicklas |
frm.bioplate.focus(); |
5425 |
14 May 19 |
nicklas |
69 |
|
5425 |
14 May 19 |
nicklas |
Doc.show('step-1'); |
5425 |
14 May 19 |
nicklas |
Doc.show('gonext'); |
5425 |
14 May 19 |
nicklas |
72 |
} |
5425 |
14 May 19 |
nicklas |
73 |
|
5425 |
14 May 19 |
nicklas |
libreg.bioPlateOnChange = function() |
5425 |
14 May 19 |
nicklas |
75 |
{ |
5425 |
14 May 19 |
nicklas |
Wizard.setInputStatus('bioplate', 'valid'); |
5425 |
14 May 19 |
nicklas |
77 |
} |
5425 |
14 May 19 |
nicklas |
78 |
|
5425 |
14 May 19 |
nicklas |
libreg.outcomeOnChange = function() |
5425 |
14 May 19 |
nicklas |
80 |
{ |
5425 |
14 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5425 |
14 May 19 |
nicklas |
var failed = Doc.element('outcomeFailed').checked |
5425 |
14 May 19 |
nicklas |
if (failed) |
5425 |
14 May 19 |
nicklas |
84 |
{ |
5425 |
14 May 19 |
nicklas |
Doc.addClass(frm.libComments, 'required'); |
5425 |
14 May 19 |
nicklas |
86 |
} |
5425 |
14 May 19 |
nicklas |
else |
5425 |
14 May 19 |
nicklas |
88 |
{ |
5425 |
14 May 19 |
nicklas |
Doc.removeClass(frm.libComments, 'required'); |
5425 |
14 May 19 |
nicklas |
90 |
} |
5425 |
14 May 19 |
nicklas |
91 |
} |
5425 |
14 May 19 |
nicklas |
92 |
|
5425 |
14 May 19 |
nicklas |
93 |
|
5425 |
14 May 19 |
nicklas |
libreg.validateStep1 = function(event) |
5425 |
14 May 19 |
nicklas |
95 |
{} |
5425 |
14 May 19 |
nicklas |
96 |
|
5425 |
14 May 19 |
nicklas |
libreg.initializeStep2 = function() |
5425 |
14 May 19 |
nicklas |
98 |
{ |
5425 |
14 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5425 |
14 May 19 |
nicklas |
100 |
|
5425 |
14 May 19 |
nicklas |
var failed = Doc.element('outcomeFailed').checked; |
5425 |
14 May 19 |
nicklas |
Wizard.setCurrentStep(2); |
5425 |
14 May 19 |
nicklas |
if (failed) |
5425 |
14 May 19 |
nicklas |
104 |
{ |
5425 |
14 May 19 |
nicklas |
Wizard.showGoNextConfirmation(true, 'Check to verify registration of failure.'); |
5425 |
14 May 19 |
nicklas |
libreg.libCommentsOnChange(); |
5425 |
14 May 19 |
nicklas |
107 |
} |
5425 |
14 May 19 |
nicklas |
108 |
|
5425 |
14 May 19 |
nicklas |
Doc.show('gocancel'); |
5425 |
14 May 19 |
nicklas |
Doc.show('goregister'); |
5425 |
14 May 19 |
nicklas |
111 |
|
5425 |
14 May 19 |
nicklas |
var plateName = frm.bioplate[frm.bioplate.selectedIndex].bioplate.name; |
5425 |
14 May 19 |
nicklas |
113 |
|
5450 |
27 May 19 |
nicklas |
frm.hybridizationDate.focus(); |
5425 |
14 May 19 |
nicklas |
115 |
|
5425 |
14 May 19 |
nicklas |
// Load Library protocols |
5425 |
14 May 19 |
nicklas |
Reggie.loadProtocols('LIBRARY_PROTOCOL', 'libProtocol', 'LIBPREP_TARGET', 'MIPs'); |
5429 |
16 May 19 |
nicklas |
118 |
|
5429 |
16 May 19 |
nicklas |
// Load barcode templates |
5429 |
16 May 19 |
nicklas |
var url = '../Mips.servlet?ID='+App.getSessionId() + '&cmd=GetBarcodeTemplates'; |
5429 |
16 May 19 |
nicklas |
Doc.addClass('barcodeTemplate', 'list-loading'); |
5429 |
16 May 19 |
nicklas |
frm.barcodeTemplate[0] = new Option('loading...'); |
5429 |
16 May 19 |
nicklas |
Wizard.asyncJsonRequest(url, libreg.barcodeTemplatesLoaded); |
5429 |
16 May 19 |
nicklas |
124 |
|
5425 |
14 May 19 |
nicklas |
125 |
} |
5429 |
16 May 19 |
nicklas |
126 |
|
5429 |
16 May 19 |
nicklas |
libreg.barcodeTemplatesLoaded = function(response) |
5429 |
16 May 19 |
nicklas |
128 |
{ |
5429 |
16 May 19 |
nicklas |
Doc.removeClass('barcodeTemplate', 'list-loading'); |
5429 |
16 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5429 |
16 May 19 |
nicklas |
var templates = response.templates; |
5429 |
16 May 19 |
nicklas |
132 |
|
5429 |
16 May 19 |
nicklas |
frm.barcodeTemplate.length = 0; |
5760 |
26 Nov 19 |
nicklas |
frm.barcodeTemplate[0] = new Option('', ''); |
5429 |
16 May 19 |
nicklas |
for (var i = 0; i < templates.length; i++) |
5429 |
16 May 19 |
nicklas |
136 |
{ |
5429 |
16 May 19 |
nicklas |
var tmp = templates[i]; |
5429 |
16 May 19 |
nicklas |
var option = new Option(tmp.name, tmp.id); |
5760 |
26 Nov 19 |
nicklas |
option.template = tmp; |
5429 |
16 May 19 |
nicklas |
frm.barcodeTemplate[frm.barcodeTemplate.length] = option; |
5429 |
16 May 19 |
nicklas |
141 |
} |
5760 |
26 Nov 19 |
nicklas |
libreg.barcodeTemplateOnChange(); |
5760 |
26 Nov 19 |
nicklas |
143 |
} |
5760 |
26 Nov 19 |
nicklas |
144 |
|
5760 |
26 Nov 19 |
nicklas |
libreg.barcodeTemplateOnChange = function() |
5760 |
26 Nov 19 |
nicklas |
146 |
{ |
5760 |
26 Nov 19 |
nicklas |
var frm = document.forms['reggie']; |
5760 |
26 Nov 19 |
nicklas |
148 |
|
5760 |
26 Nov 19 |
nicklas |
Wizard.setInputStatus('barcodeTemplate'); |
5760 |
26 Nov 19 |
nicklas |
Wizard.hideGoNextConfirmation(); |
5760 |
26 Nov 19 |
nicklas |
barcodeTemplateIsValid = false; |
5760 |
26 Nov 19 |
nicklas |
152 |
|
5760 |
26 Nov 19 |
nicklas |
if (frm.barcodeTemplate.length == 1) |
5429 |
16 May 19 |
nicklas |
154 |
{ |
5429 |
16 May 19 |
nicklas |
Wizard.setInputStatus('barcodeTemplate', 'invalid', 'No available barcode templates'); |
5429 |
16 May 19 |
nicklas |
barcodeTemplateIsValid = false; |
5429 |
16 May 19 |
nicklas |
return; |
5429 |
16 May 19 |
nicklas |
158 |
} |
5760 |
26 Nov 19 |
nicklas |
159 |
|
5760 |
26 Nov 19 |
nicklas |
if (frm.barcodeTemplate.value == '') |
5760 |
26 Nov 19 |
nicklas |
161 |
{ |
5760 |
26 Nov 19 |
nicklas |
Wizard.setInputStatus('barcodeTemplate', 'invalid', 'A barcode template must be selected'); |
5760 |
26 Nov 19 |
nicklas |
barcodeTemplateIsValid = false; |
5760 |
26 Nov 19 |
nicklas |
return; |
5760 |
26 Nov 19 |
nicklas |
165 |
} |
5760 |
26 Nov 19 |
nicklas |
166 |
|
5429 |
16 May 19 |
nicklas |
barcodeTemplateIsValid = true; |
5760 |
26 Nov 19 |
nicklas |
168 |
|
5760 |
26 Nov 19 |
nicklas |
var template = frm.barcodeTemplate[frm.barcodeTemplate.selectedIndex].template; |
5760 |
26 Nov 19 |
nicklas |
if (template.otherPlates && template.otherPlates.length > 0) |
5760 |
26 Nov 19 |
nicklas |
171 |
{ |
5760 |
26 Nov 19 |
nicklas |
var msg = 'This template is also used by ' + Strings.encodeTags(template.otherPlates[0].name); |
5760 |
26 Nov 19 |
nicklas |
if (template.otherPlates.length > 1) |
5760 |
26 Nov 19 |
nicklas |
174 |
{ |
5760 |
26 Nov 19 |
nicklas |
msg += ' and '+(template.otherPlates.length-1)+' more plate(s)'; |
5760 |
26 Nov 19 |
nicklas |
176 |
} |
5760 |
26 Nov 19 |
nicklas |
Wizard.setInputStatus('barcodeTemplate', 'warning', msg); |
5760 |
26 Nov 19 |
nicklas |
Wizard.showGoNextConfirmation(true, 'Verify registration of plate with duplicate barcode template'); |
5760 |
26 Nov 19 |
nicklas |
179 |
} |
5760 |
26 Nov 19 |
nicklas |
else |
5760 |
26 Nov 19 |
nicklas |
181 |
{ |
5760 |
26 Nov 19 |
nicklas |
Wizard.setInputStatus('barcodeTemplate', 'valid'); |
5760 |
26 Nov 19 |
nicklas |
183 |
} |
5429 |
16 May 19 |
nicklas |
184 |
} |
5429 |
16 May 19 |
nicklas |
185 |
|
5425 |
14 May 19 |
nicklas |
libreg.libCommentsOnChange = function() |
5425 |
14 May 19 |
nicklas |
187 |
{ |
5425 |
14 May 19 |
nicklas |
var failed = Doc.element('outcomeFailed').checked; |
5425 |
14 May 19 |
nicklas |
if (!failed) return; |
5425 |
14 May 19 |
nicklas |
190 |
|
5425 |
14 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5425 |
14 May 19 |
nicklas |
libCommentsIsValid = false; |
5425 |
14 May 19 |
nicklas |
Wizard.setInputStatus('libComments'); |
5425 |
14 May 19 |
nicklas |
194 |
|
5425 |
14 May 19 |
nicklas |
var comments = frm.libComments.value; |
5425 |
14 May 19 |
nicklas |
if (comments == '') |
5425 |
14 May 19 |
nicklas |
197 |
{ |
5425 |
14 May 19 |
nicklas |
Wizard.setInputStatus('libComments', 'invalid', 'Missing'); |
5425 |
14 May 19 |
nicklas |
return; |
5425 |
14 May 19 |
nicklas |
200 |
} |
5425 |
14 May 19 |
nicklas |
201 |
|
5425 |
14 May 19 |
nicklas |
Wizard.setInputStatus('libComments', 'valid'); |
5425 |
14 May 19 |
nicklas |
libCommentsIsValid = true; |
5425 |
14 May 19 |
nicklas |
204 |
} |
5425 |
14 May 19 |
nicklas |
205 |
|
5425 |
14 May 19 |
nicklas |
libreg.validateStep2 = function(event) |
5425 |
14 May 19 |
nicklas |
207 |
{ |
5429 |
16 May 19 |
nicklas |
var valid = barcodeTemplateIsValid; |
5425 |
14 May 19 |
nicklas |
209 |
|
5450 |
27 May 19 |
nicklas |
valid &= Wizard.isValid('hybridizationDate'); |
5450 |
27 May 19 |
nicklas |
valid &= Wizard.isValid('pcrDate'); |
5425 |
14 May 19 |
nicklas |
valid &= Wizard.isValid('cleanupDate'); |
5425 |
14 May 19 |
nicklas |
213 |
|
5425 |
14 May 19 |
nicklas |
var failed = Doc.element('outcomeFailed').checked; |
5425 |
14 May 19 |
nicklas |
if (failed) |
5425 |
14 May 19 |
nicklas |
216 |
{ |
5425 |
14 May 19 |
nicklas |
valid &= libCommentsIsValid; |
5425 |
14 May 19 |
nicklas |
218 |
} |
5425 |
14 May 19 |
nicklas |
if (!valid) event.preventDefault(); |
5425 |
14 May 19 |
nicklas |
220 |
} |
5425 |
14 May 19 |
nicklas |
221 |
|
5425 |
14 May 19 |
nicklas |
222 |
|
5425 |
14 May 19 |
nicklas |
libreg.submit = function() |
5425 |
14 May 19 |
nicklas |
224 |
{ |
5425 |
14 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5425 |
14 May 19 |
nicklas |
226 |
|
5425 |
14 May 19 |
nicklas |
var submitInfo = {}; |
5425 |
14 May 19 |
nicklas |
submitInfo.bioplate = parseInt(frm.bioplate.value, 10); |
5425 |
14 May 19 |
nicklas |
229 |
|
5425 |
14 May 19 |
nicklas |
var failed = Doc.element('outcomeFailed').checked; |
5425 |
14 May 19 |
nicklas |
submitInfo.failed = failed; |
5425 |
14 May 19 |
nicklas |
232 |
|
5450 |
27 May 19 |
nicklas |
submitInfo.hybridizationDate = frm.hybridizationDate.value; |
5450 |
27 May 19 |
nicklas |
submitInfo.hybridizationOperator = frm.hybridizationOperator.value; |
5450 |
27 May 19 |
nicklas |
submitInfo.pcrDate = frm.pcrDate.value; |
5450 |
27 May 19 |
nicklas |
submitInfo.pcrOperator = frm.pcrOperator.value; |
5425 |
14 May 19 |
nicklas |
submitInfo.cleanupDate = frm.cleanupDate.value; |
5425 |
14 May 19 |
nicklas |
submitInfo.cleanupOperator = frm.cleanupOperator.value; |
5425 |
14 May 19 |
nicklas |
239 |
|
5429 |
16 May 19 |
nicklas |
submitInfo.barcodeTemplate = parseInt(frm.barcodeTemplate.value, 10); |
5425 |
14 May 19 |
nicklas |
submitInfo.libProtocol = parseInt(frm.libProtocol.value, 10); |
5425 |
14 May 19 |
nicklas |
submitInfo.libComments = frm.libComments.value; |
5425 |
14 May 19 |
nicklas |
243 |
|
5425 |
14 May 19 |
nicklas |
var url = '../Mips.servlet?ID='+App.getSessionId(); |
5425 |
14 May 19 |
nicklas |
url += '&cmd=RegisterLibraryPrep'; |
5425 |
14 May 19 |
nicklas |
Wizard.showLoadingAnimation('Performing registration...'); |
5425 |
14 May 19 |
nicklas |
Wizard.asyncJsonRequest(url, libreg.submissionResults, 'POST', JSON.stringify(submitInfo)); |
5425 |
14 May 19 |
nicklas |
248 |
} |
5425 |
14 May 19 |
nicklas |
249 |
|
5425 |
14 May 19 |
nicklas |
libreg.submissionResults = function(response) |
5425 |
14 May 19 |
nicklas |
251 |
{ |
5425 |
14 May 19 |
nicklas |
Wizard.showFinalMessage(response.messages); |
5425 |
14 May 19 |
nicklas |
Doc.show('gorestart'); |
5425 |
14 May 19 |
nicklas |
254 |
} |
5425 |
14 May 19 |
nicklas |
255 |
|
5425 |
14 May 19 |
nicklas |
return libreg; |
5425 |
14 May 19 |
nicklas |
257 |
}(); |
5425 |
14 May 19 |
nicklas |
258 |
|
5425 |
14 May 19 |
nicklas |
Doc.onLoad(LibReg.initPage); |
5425 |
14 May 19 |
nicklas |
260 |
|