5428 |
15 May 19 |
nicklas |
var Pool = function() |
5428 |
15 May 19 |
nicklas |
2 |
{ |
5428 |
15 May 19 |
nicklas |
var pool = {}; |
5428 |
15 May 19 |
nicklas |
var debug = 0; |
5428 |
15 May 19 |
nicklas |
5 |
|
5428 |
15 May 19 |
nicklas |
var plates; |
5428 |
15 May 19 |
nicklas |
var nextPoolName; |
5428 |
15 May 19 |
nicklas |
var poolsAreValid = false; |
5428 |
15 May 19 |
nicklas |
9 |
|
5428 |
15 May 19 |
nicklas |
// Page initialization |
5428 |
15 May 19 |
nicklas |
pool.initPage = function() |
5428 |
15 May 19 |
nicklas |
12 |
{ |
5428 |
15 May 19 |
nicklas |
// Step 1 |
5428 |
15 May 19 |
nicklas |
Events.addEventHandler('bioplate', 'change', pool.bioplateOnChange); |
5428 |
15 May 19 |
nicklas |
Events.addEventHandler('step-1', 'wizard-validate', pool.validateStep1); |
5428 |
15 May 19 |
nicklas |
16 |
|
5428 |
15 May 19 |
nicklas |
// Step 2 |
5428 |
15 May 19 |
nicklas |
Events.addEventHandler('step-2', 'wizard-initialize', pool.initializeStep2); |
5428 |
15 May 19 |
nicklas |
Events.addEventHandler('step-2', 'wizard-validate', pool.validateStep2); |
5428 |
15 May 19 |
nicklas |
Events.addEventHandler('poolDate', 'blur', Wizard.validateDate); |
5428 |
15 May 19 |
nicklas |
21 |
|
5428 |
15 May 19 |
nicklas |
// Navigation |
5428 |
15 May 19 |
nicklas |
Buttons.addClickHandler('gocancel', Wizard.cancelWizard); |
5428 |
15 May 19 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
5428 |
15 May 19 |
nicklas |
Buttons.addClickHandler('gonext', Wizard.goNextOnClick); |
5428 |
15 May 19 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
5428 |
15 May 19 |
nicklas |
27 |
|
5428 |
15 May 19 |
nicklas |
// Final registration |
5428 |
15 May 19 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', pool.submit); |
5428 |
15 May 19 |
nicklas |
30 |
|
5428 |
15 May 19 |
nicklas |
var url = '../Mips.servlet?ID='+App.getSessionId(); |
5428 |
15 May 19 |
nicklas |
url += '&cmd=GetLibraryPlatesForPooling'; |
5428 |
15 May 19 |
nicklas |
Wizard.showLoadingAnimation('Loading MIPs plates...'); |
5428 |
15 May 19 |
nicklas |
Wizard.asyncJsonRequest(url, pool.initializeStep1); |
5428 |
15 May 19 |
nicklas |
35 |
} |
5428 |
15 May 19 |
nicklas |
36 |
|
5428 |
15 May 19 |
nicklas |
37 |
|
5428 |
15 May 19 |
nicklas |
pool.initializeStep1 = function(response) |
5428 |
15 May 19 |
nicklas |
39 |
{ |
5428 |
15 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5428 |
15 May 19 |
nicklas |
nextPoolName = response.nextPoolName; |
5428 |
15 May 19 |
nicklas |
Doc.element('poolName').innerHTML = Strings.encodeTags(nextPoolName); |
5428 |
15 May 19 |
nicklas |
43 |
|
5428 |
15 May 19 |
nicklas |
var bioplates = response.bioplates; |
5428 |
15 May 19 |
nicklas |
var plates = frm.bioplate; |
5428 |
15 May 19 |
nicklas |
if (bioplates.length > 0) |
5428 |
15 May 19 |
nicklas |
47 |
{ |
5430 |
16 May 19 |
nicklas |
var usedBarcodeTemplate = {}; |
5428 |
15 May 19 |
nicklas |
for (var i=0; i < bioplates.length; i++) |
5428 |
15 May 19 |
nicklas |
50 |
{ |
5428 |
15 May 19 |
nicklas |
var plate = bioplates[i]; |
5430 |
16 May 19 |
nicklas |
var sameTemplate = usedBarcodeTemplate[plate.barcodeTemplate] || false; |
5430 |
16 May 19 |
nicklas |
usedBarcodeTemplate[plate.barcodeTemplate] = true; |
5430 |
16 May 19 |
nicklas |
var option = new Option(plate.name+' ('+(plate.barcodeTemplate || 'no barcode template')+')', plate.id, !sameTemplate, !sameTemplate); |
5428 |
15 May 19 |
nicklas |
option.plate = plate; |
5428 |
15 May 19 |
nicklas |
plates.options[plates.length] = option; |
5428 |
15 May 19 |
nicklas |
57 |
} |
5428 |
15 May 19 |
nicklas |
Events.sendChangeEvent('bioplate'); |
5428 |
15 May 19 |
nicklas |
59 |
} |
5428 |
15 May 19 |
nicklas |
else |
5428 |
15 May 19 |
nicklas |
61 |
{ |
5428 |
15 May 19 |
nicklas |
Wizard.setFatalError('No MIPs plates available for pooling.'); |
5428 |
15 May 19 |
nicklas |
Doc.hide('gorestart'); |
5428 |
15 May 19 |
nicklas |
return; |
5428 |
15 May 19 |
nicklas |
65 |
} |
5428 |
15 May 19 |
nicklas |
66 |
|
5428 |
15 May 19 |
nicklas |
Doc.show('step-1'); |
5428 |
15 May 19 |
nicklas |
Doc.show('gonext'); |
5428 |
15 May 19 |
nicklas |
69 |
} |
5428 |
15 May 19 |
nicklas |
70 |
|
5428 |
15 May 19 |
nicklas |
71 |
|
5428 |
15 May 19 |
nicklas |
// Add pools to the pools list based on the bioplate selection |
5428 |
15 May 19 |
nicklas |
pool.bioplateOnChange = function() |
5428 |
15 May 19 |
nicklas |
74 |
{ |
5428 |
15 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5428 |
15 May 19 |
nicklas |
Wizard.setInputStatus('bioplate'); |
5428 |
15 May 19 |
nicklas |
poolsAreValid = false; |
5428 |
15 May 19 |
nicklas |
78 |
|
5428 |
15 May 19 |
nicklas |
var numSelected = 0; |
5428 |
15 May 19 |
nicklas |
var duplicateBarcodes = false; |
5430 |
16 May 19 |
nicklas |
var usedBarcodes = {}; |
5428 |
15 May 19 |
nicklas |
for (var i = 0; i < frm.bioplate.length; i++) |
5428 |
15 May 19 |
nicklas |
83 |
{ |
5428 |
15 May 19 |
nicklas |
if (frm.bioplate[i].selected) |
5428 |
15 May 19 |
nicklas |
85 |
{ |
5428 |
15 May 19 |
nicklas |
numSelected++; |
5430 |
16 May 19 |
nicklas |
var plate = frm.bioplate[i].plate; |
5430 |
16 May 19 |
nicklas |
for (var libNo = 0; libNo < plate.libraries.length; libNo++) |
5430 |
16 May 19 |
nicklas |
89 |
{ |
5430 |
16 May 19 |
nicklas |
var barcode = plate.libraries[libNo].barcode; |
5430 |
16 May 19 |
nicklas |
if (usedBarcodes[barcode]) |
5430 |
16 May 19 |
nicklas |
92 |
{ |
5430 |
16 May 19 |
nicklas |
usedBarcodes[barcode]++; |
5430 |
16 May 19 |
nicklas |
duplicateBarcodes = true; |
5430 |
16 May 19 |
nicklas |
95 |
} |
5430 |
16 May 19 |
nicklas |
else |
5430 |
16 May 19 |
nicklas |
97 |
{ |
5430 |
16 May 19 |
nicklas |
usedBarcodes[barcode] = 1; |
5430 |
16 May 19 |
nicklas |
99 |
} |
5430 |
16 May 19 |
nicklas |
100 |
} |
5428 |
15 May 19 |
nicklas |
101 |
} |
5428 |
15 May 19 |
nicklas |
102 |
} |
5428 |
15 May 19 |
nicklas |
103 |
|
5428 |
15 May 19 |
nicklas |
if (numSelected == 0) |
5428 |
15 May 19 |
nicklas |
105 |
{ |
5428 |
15 May 19 |
nicklas |
Wizard.setInputStatus('bioplate', 'invalid', 'Please select at least one plate.'); |
5428 |
15 May 19 |
nicklas |
return; |
5428 |
15 May 19 |
nicklas |
108 |
} |
5428 |
15 May 19 |
nicklas |
else if (duplicateBarcodes) |
5428 |
15 May 19 |
nicklas |
110 |
{ |
5430 |
16 May 19 |
nicklas |
var numDuplicates = 0; |
5430 |
16 May 19 |
nicklas |
for (var v in usedBarcodes) |
5430 |
16 May 19 |
nicklas |
113 |
{ |
5430 |
16 May 19 |
nicklas |
if (usedBarcodes[v] > 1) numDuplicates += usedBarcodes[v]; |
5430 |
16 May 19 |
nicklas |
115 |
} |
5430 |
16 May 19 |
nicklas |
Wizard.setInputStatus('bioplate', 'invalid', 'The selected plates have ' + numDuplicates + ' libraries with duplicate barcode.'); |
5428 |
15 May 19 |
nicklas |
return; |
5428 |
15 May 19 |
nicklas |
118 |
} |
5428 |
15 May 19 |
nicklas |
119 |
|
5428 |
15 May 19 |
nicklas |
poolsAreValid = true; |
5428 |
15 May 19 |
nicklas |
Wizard.setInputStatus('bioplate', 'valid'); |
5428 |
15 May 19 |
nicklas |
122 |
} |
5428 |
15 May 19 |
nicklas |
123 |
|
5428 |
15 May 19 |
nicklas |
pool.validateStep1 = function(event) |
5428 |
15 May 19 |
nicklas |
125 |
{ |
5428 |
15 May 19 |
nicklas |
if (!poolsAreValid) event.preventDefault(); |
5428 |
15 May 19 |
nicklas |
127 |
} |
5428 |
15 May 19 |
nicklas |
128 |
|
5428 |
15 May 19 |
nicklas |
pool.initializeStep2 = function() |
5428 |
15 May 19 |
nicklas |
130 |
{ |
5428 |
15 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5428 |
15 May 19 |
nicklas |
Wizard.setCurrentStep(2); |
5428 |
15 May 19 |
nicklas |
Doc.show('gocancel'); |
5428 |
15 May 19 |
nicklas |
Doc.show('goregister'); |
5428 |
15 May 19 |
nicklas |
135 |
|
5452 |
28 May 19 |
nicklas |
Reggie.loadProtocols('POOLING_PROTOCOL', 'poolProtocol', 'LIBPREP_TARGET', 'MIPs'); |
5428 |
15 May 19 |
nicklas |
137 |
|
5428 |
15 May 19 |
nicklas |
frm.poolDate.focus(); |
5428 |
15 May 19 |
nicklas |
139 |
} |
5428 |
15 May 19 |
nicklas |
140 |
|
5428 |
15 May 19 |
nicklas |
pool.validateStep2 = function(event) |
5428 |
15 May 19 |
nicklas |
142 |
{ |
5428 |
15 May 19 |
nicklas |
if (!Wizard.isValid('poolDate')) |
5428 |
15 May 19 |
nicklas |
144 |
{ |
5428 |
15 May 19 |
nicklas |
event.preventDefault(); |
5428 |
15 May 19 |
nicklas |
146 |
} |
5428 |
15 May 19 |
nicklas |
147 |
} |
5428 |
15 May 19 |
nicklas |
148 |
|
5428 |
15 May 19 |
nicklas |
pool.submit = function() |
5428 |
15 May 19 |
nicklas |
150 |
{ |
5428 |
15 May 19 |
nicklas |
var frm = document.forms['reggie']; |
5428 |
15 May 19 |
nicklas |
152 |
|
5428 |
15 May 19 |
nicklas |
var plates = []; |
5428 |
15 May 19 |
nicklas |
for (var i = 0; i < frm.bioplate.length; i++) |
5428 |
15 May 19 |
nicklas |
155 |
{ |
5428 |
15 May 19 |
nicklas |
if (frm.bioplate[i].selected) |
5428 |
15 May 19 |
nicklas |
157 |
{ |
5428 |
15 May 19 |
nicklas |
plates[plates.length] = frm.bioplate[i].plate.id; |
5428 |
15 May 19 |
nicklas |
159 |
} |
5428 |
15 May 19 |
nicklas |
160 |
} |
5428 |
15 May 19 |
nicklas |
161 |
|
5428 |
15 May 19 |
nicklas |
var submitInfo = {}; |
5428 |
15 May 19 |
nicklas |
submitInfo.plates = plates; |
5428 |
15 May 19 |
nicklas |
submitInfo.poolName = nextPoolName; |
5428 |
15 May 19 |
nicklas |
submitInfo.poolDate = frm.poolDate.value; |
5428 |
15 May 19 |
nicklas |
submitInfo.poolProtocol = parseInt(frm.poolProtocol.value, 10); |
5428 |
15 May 19 |
nicklas |
submitInfo.poolOperator = frm.poolOperator.value; |
5428 |
15 May 19 |
nicklas |
168 |
|
5428 |
15 May 19 |
nicklas |
var url = '../Mips.servlet?ID='+App.getSessionId(); |
5428 |
15 May 19 |
nicklas |
url += '&cmd=RegisterPooledLibraries'; |
5428 |
15 May 19 |
nicklas |
Wizard.showLoadingAnimation('Performing registration...'); |
5428 |
15 May 19 |
nicklas |
Wizard.asyncJsonRequest(url, pool.submissionResults, 'POST', JSON.stringify(submitInfo)); |
5428 |
15 May 19 |
nicklas |
173 |
} |
5428 |
15 May 19 |
nicklas |
174 |
|
5428 |
15 May 19 |
nicklas |
pool.submissionResults = function(response) |
5428 |
15 May 19 |
nicklas |
176 |
{ |
5428 |
15 May 19 |
nicklas |
Wizard.showFinalMessage(response.messages); |
5428 |
15 May 19 |
nicklas |
Doc.show('gorestart'); |
5428 |
15 May 19 |
nicklas |
179 |
} |
5428 |
15 May 19 |
nicklas |
180 |
|
5428 |
15 May 19 |
nicklas |
return pool; |
5428 |
15 May 19 |
nicklas |
182 |
}(); |
5428 |
15 May 19 |
nicklas |
183 |
|
5428 |
15 May 19 |
nicklas |
Doc.onLoad(Pool.initPage); |
5428 |
15 May 19 |
nicklas |
185 |
|