2659 |
12 Sep 14 |
nicklas |
var Pool = function() |
2659 |
12 Sep 14 |
nicklas |
2 |
{ |
2659 |
12 Sep 14 |
nicklas |
var pool = {}; |
2702 |
26 Sep 14 |
nicklas |
var debug = 0; |
2659 |
12 Sep 14 |
nicklas |
5 |
|
2659 |
12 Sep 14 |
nicklas |
var pools; |
2659 |
12 Sep 14 |
nicklas |
var poolsAreValid = false; |
2659 |
12 Sep 14 |
nicklas |
8 |
|
2659 |
12 Sep 14 |
nicklas |
// Page initialization |
2659 |
12 Sep 14 |
nicklas |
pool.initPage = function() |
2659 |
12 Sep 14 |
nicklas |
11 |
{ |
2659 |
12 Sep 14 |
nicklas |
// Step 1 |
2659 |
12 Sep 14 |
nicklas |
Events.addEventHandler('bioplate', 'change', pool.bioplateOnChange); |
2659 |
12 Sep 14 |
nicklas |
Events.addEventHandler('pools', 'change', pool.poolOnChange); |
2659 |
12 Sep 14 |
nicklas |
Events.addEventHandler('step-1', 'wizard-validate', pool.validateStep1); |
2659 |
12 Sep 14 |
nicklas |
16 |
|
2659 |
12 Sep 14 |
nicklas |
// Step 2 |
2659 |
12 Sep 14 |
nicklas |
Events.addEventHandler('step-2', 'wizard-initialize', pool.initializeStep2); |
2659 |
12 Sep 14 |
nicklas |
Events.addEventHandler('step-2', 'wizard-validate', pool.validateStep2); |
2659 |
12 Sep 14 |
nicklas |
Events.addEventHandler('poolDate', 'blur', Wizard.validateDate); |
2659 |
12 Sep 14 |
nicklas |
21 |
|
2659 |
12 Sep 14 |
nicklas |
// Navigation |
2659 |
12 Sep 14 |
nicklas |
Buttons.addClickHandler('gocancel', Wizard.cancelWizard); |
2659 |
12 Sep 14 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
2659 |
12 Sep 14 |
nicklas |
Buttons.addClickHandler('gonext', Wizard.goNextOnClick); |
2659 |
12 Sep 14 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
2659 |
12 Sep 14 |
nicklas |
27 |
|
2659 |
12 Sep 14 |
nicklas |
// Final registration |
2659 |
12 Sep 14 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', pool.submit); |
2659 |
12 Sep 14 |
nicklas |
30 |
|
2659 |
12 Sep 14 |
nicklas |
var url = '../Pool.servlet?ID='+App.getSessionId(); |
2659 |
12 Sep 14 |
nicklas |
url += '&cmd=GetUnprocessedPools'; |
2659 |
12 Sep 14 |
nicklas |
Wizard.showLoadingAnimation('Loading pools...'); |
2659 |
12 Sep 14 |
nicklas |
Wizard.asyncJsonRequest(url, pool.initializeStep1); |
2659 |
12 Sep 14 |
nicklas |
35 |
} |
2659 |
12 Sep 14 |
nicklas |
36 |
|
2659 |
12 Sep 14 |
nicklas |
37 |
|
2659 |
12 Sep 14 |
nicklas |
pool.initializeStep1 = function(response) |
2659 |
12 Sep 14 |
nicklas |
39 |
{ |
2659 |
12 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2659 |
12 Sep 14 |
nicklas |
pools = response.pools; |
2659 |
12 Sep 14 |
nicklas |
42 |
|
2659 |
12 Sep 14 |
nicklas |
// We get a list of pools from the servlet |
2659 |
12 Sep 14 |
nicklas |
// Each pool has a list of libraries |
2659 |
12 Sep 14 |
nicklas |
// We want to find the Library bioplates that are unique |
2659 |
12 Sep 14 |
nicklas |
// within a pool (eg. all libraries are from the same bioplate) |
2659 |
12 Sep 14 |
nicklas |
if (pools.length == 0) |
2659 |
12 Sep 14 |
nicklas |
48 |
{ |
2659 |
12 Sep 14 |
nicklas |
Wizard.setFatalError('No pools available for processing.'); |
2659 |
12 Sep 14 |
nicklas |
return; |
2659 |
12 Sep 14 |
nicklas |
51 |
} |
2659 |
12 Sep 14 |
nicklas |
52 |
|
2659 |
12 Sep 14 |
nicklas |
var poolsList = frm.pools; |
2659 |
12 Sep 14 |
nicklas |
var plateList = frm.bioplate; |
2659 |
12 Sep 14 |
nicklas |
var libPlates = []; |
2659 |
12 Sep 14 |
nicklas |
for (var poolNo=0; poolNo < pools.length; poolNo++) |
2659 |
12 Sep 14 |
nicklas |
57 |
{ |
2659 |
12 Sep 14 |
nicklas |
var p = pools[poolNo]; |
2659 |
12 Sep 14 |
nicklas |
59 |
|
2659 |
12 Sep 14 |
nicklas |
// Shortcut to single-plate pools |
2659 |
12 Sep 14 |
nicklas |
var libPlateForPool = p.libPlates.length == 1 && !p.isManual ? p.libPlates[0] : null; |
2659 |
12 Sep 14 |
nicklas |
p.libPlate = libPlateForPool; |
2659 |
12 Sep 14 |
nicklas |
63 |
|
2659 |
12 Sep 14 |
nicklas |
// If the pool has a single library bioplate add it to the selection list |
2659 |
12 Sep 14 |
nicklas |
// If the pool doesn't have a single library bioplate, nothing is added to |
2659 |
12 Sep 14 |
nicklas |
// the list and the pool can only be selected when the 'manual pools' option is |
2659 |
12 Sep 14 |
nicklas |
// active for the bioplates list |
2659 |
12 Sep 14 |
nicklas |
if (libPlateForPool != null && !libPlates[libPlateForPool.name]) |
2659 |
12 Sep 14 |
nicklas |
69 |
{ |
2659 |
12 Sep 14 |
nicklas |
libPlates[libPlateForPool.name] = libPlateForPool; |
2659 |
12 Sep 14 |
nicklas |
var plateOption = new Option(libPlateForPool.name, libPlateForPool.id); |
2659 |
12 Sep 14 |
nicklas |
plateOption.plate = libPlateForPool; |
2659 |
12 Sep 14 |
nicklas |
plateList[plateList.length] = plateOption; |
2659 |
12 Sep 14 |
nicklas |
74 |
} |
2659 |
12 Sep 14 |
nicklas |
75 |
|
2659 |
12 Sep 14 |
nicklas |
76 |
} |
2659 |
12 Sep 14 |
nicklas |
if (plateList.length > 1) plateList.selectedIndex = 1; |
2659 |
12 Sep 14 |
nicklas |
78 |
|
2659 |
12 Sep 14 |
nicklas |
pool.bioplateOnChange(); |
2659 |
12 Sep 14 |
nicklas |
Doc.show('step-1'); |
2659 |
12 Sep 14 |
nicklas |
Doc.show('gonext'); |
2659 |
12 Sep 14 |
nicklas |
82 |
} |
2659 |
12 Sep 14 |
nicklas |
83 |
|
2659 |
12 Sep 14 |
nicklas |
84 |
|
2659 |
12 Sep 14 |
nicklas |
// Add pools to the pools list based on the bioplate selection |
2659 |
12 Sep 14 |
nicklas |
pool.bioplateOnChange = function() |
2659 |
12 Sep 14 |
nicklas |
87 |
{ |
2659 |
12 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2659 |
12 Sep 14 |
nicklas |
89 |
|
2659 |
12 Sep 14 |
nicklas |
var libPlateId = parseInt(frm.bioplate.value); |
2659 |
12 Sep 14 |
nicklas |
91 |
|
2659 |
12 Sep 14 |
nicklas |
// Clear current list |
2659 |
12 Sep 14 |
nicklas |
frm.pools.length = 0; |
2659 |
12 Sep 14 |
nicklas |
94 |
|
2659 |
12 Sep 14 |
nicklas |
for (var poolNo = 0; poolNo < pools.length; poolNo++) |
2659 |
12 Sep 14 |
nicklas |
96 |
{ |
2659 |
12 Sep 14 |
nicklas |
var p = pools[poolNo]; |
2659 |
12 Sep 14 |
nicklas |
// If a libplate is selected, only show pools that have all libraries from that plate |
2659 |
12 Sep 14 |
nicklas |
// If no libplate is selected, only show pools that have libraries from multiple plates |
2659 |
12 Sep 14 |
nicklas |
var addPool = (libPlateId && p.libPlate && p.libPlate.id == libPlateId) || (!libPlateId && p.libPlate == null); |
2659 |
12 Sep 14 |
nicklas |
if (addPool) |
2659 |
12 Sep 14 |
nicklas |
102 |
{ |
2659 |
12 Sep 14 |
nicklas |
var name = p.name; |
2659 |
12 Sep 14 |
nicklas |
if (p.libPlate == null) |
2659 |
12 Sep 14 |
nicklas |
105 |
{ |
2659 |
12 Sep 14 |
nicklas |
106 |
|
2659 |
12 Sep 14 |
nicklas |
name += ' - '; |
2659 |
12 Sep 14 |
nicklas |
var numPlates = p.libPlates.length; |
2659 |
12 Sep 14 |
nicklas |
var title = ''; |
2659 |
12 Sep 14 |
nicklas |
if (numPlates <= 2) |
2659 |
12 Sep 14 |
nicklas |
111 |
{ |
2659 |
12 Sep 14 |
nicklas |
for (var plateNo=0; plateNo < numPlates; plateNo++) |
2659 |
12 Sep 14 |
nicklas |
113 |
{ |
2659 |
12 Sep 14 |
nicklas |
var libPlate = p.libPlates[plateNo]; |
2659 |
12 Sep 14 |
nicklas |
if (plateNo > 0) name += ', '; |
2659 |
12 Sep 14 |
nicklas |
name += libPlate.name; |
2659 |
12 Sep 14 |
nicklas |
117 |
} |
2659 |
12 Sep 14 |
nicklas |
118 |
} |
2659 |
12 Sep 14 |
nicklas |
else |
2659 |
12 Sep 14 |
nicklas |
120 |
{ |
2659 |
12 Sep 14 |
nicklas |
name += p.libPlates[0].name + ' + ' + (numPlates-1) + ' more...'; |
2659 |
12 Sep 14 |
nicklas |
for (var plateNo=0; plateNo < numPlates; plateNo++) |
2659 |
12 Sep 14 |
nicklas |
123 |
{ |
2659 |
12 Sep 14 |
nicklas |
var libPlate = p.libPlates[plateNo]; |
2659 |
12 Sep 14 |
nicklas |
if (plateNo > 0) title += ', '; |
2659 |
12 Sep 14 |
nicklas |
title += libPlate.name; |
2659 |
12 Sep 14 |
nicklas |
127 |
} |
2659 |
12 Sep 14 |
nicklas |
128 |
} |
2659 |
12 Sep 14 |
nicklas |
129 |
} |
2659 |
12 Sep 14 |
nicklas |
130 |
|
4583 |
21 Sep 17 |
nicklas |
var option = new Option(name, p.id, false, libPlateId || frm.pools.length == 0); |
2659 |
12 Sep 14 |
nicklas |
option.pool = p; |
2659 |
12 Sep 14 |
nicklas |
frm.pools[frm.pools.length] = option; |
2659 |
12 Sep 14 |
nicklas |
134 |
} |
2659 |
12 Sep 14 |
nicklas |
135 |
} |
2659 |
12 Sep 14 |
nicklas |
136 |
|
2659 |
12 Sep 14 |
nicklas |
Wizard.setInputStatus('pools'); |
2659 |
12 Sep 14 |
nicklas |
if (libPlateId) |
2659 |
12 Sep 14 |
nicklas |
139 |
{ |
2659 |
12 Sep 14 |
nicklas |
frm.pools.disabled = true; |
2659 |
12 Sep 14 |
nicklas |
141 |
} |
2659 |
12 Sep 14 |
nicklas |
else |
2659 |
12 Sep 14 |
nicklas |
143 |
{ |
2659 |
12 Sep 14 |
nicklas |
frm.pools.disabled = false; |
2659 |
12 Sep 14 |
nicklas |
145 |
} |
2659 |
12 Sep 14 |
nicklas |
pool.poolOnChange(); |
2659 |
12 Sep 14 |
nicklas |
147 |
} |
2659 |
12 Sep 14 |
nicklas |
148 |
|
2659 |
12 Sep 14 |
nicklas |
149 |
|
2659 |
12 Sep 14 |
nicklas |
pool.poolOnChange = function() |
2659 |
12 Sep 14 |
nicklas |
151 |
{ |
2659 |
12 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2659 |
12 Sep 14 |
nicklas |
153 |
|
2659 |
12 Sep 14 |
nicklas |
poolsAreValid = false; |
2659 |
12 Sep 14 |
nicklas |
Wizard.setInputStatus('pools'); |
2659 |
12 Sep 14 |
nicklas |
156 |
|
2659 |
12 Sep 14 |
nicklas |
for (var i = 0; i < frm.pools.length; i++) |
2659 |
12 Sep 14 |
nicklas |
158 |
{ |
2659 |
12 Sep 14 |
nicklas |
if (frm.pools[i].selected) poolsAreValid = true; |
2659 |
12 Sep 14 |
nicklas |
160 |
} |
2659 |
12 Sep 14 |
nicklas |
161 |
|
2659 |
12 Sep 14 |
nicklas |
if (!poolsAreValid) |
2659 |
12 Sep 14 |
nicklas |
163 |
{ |
2659 |
12 Sep 14 |
nicklas |
Wizard.setInputStatus('pools', 'invalid', 'Select at least one pool'); |
2659 |
12 Sep 14 |
nicklas |
return; |
2659 |
12 Sep 14 |
nicklas |
166 |
} |
2659 |
12 Sep 14 |
nicklas |
167 |
|
2659 |
12 Sep 14 |
nicklas |
Wizard.setInputStatus('pools', 'valid'); |
2659 |
12 Sep 14 |
nicklas |
169 |
} |
2659 |
12 Sep 14 |
nicklas |
170 |
|
2659 |
12 Sep 14 |
nicklas |
pool.validateStep1 = function(event) |
2659 |
12 Sep 14 |
nicklas |
172 |
{ |
2659 |
12 Sep 14 |
nicklas |
if (!poolsAreValid) event.preventDefault(); |
2659 |
12 Sep 14 |
nicklas |
174 |
} |
2659 |
12 Sep 14 |
nicklas |
175 |
|
2659 |
12 Sep 14 |
nicklas |
pool.initializeStep2 = function() |
2659 |
12 Sep 14 |
nicklas |
177 |
{ |
2659 |
12 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2659 |
12 Sep 14 |
nicklas |
Wizard.setCurrentStep(2); |
2659 |
12 Sep 14 |
nicklas |
Doc.show('gocancel'); |
2659 |
12 Sep 14 |
nicklas |
Doc.show('goregister'); |
2659 |
12 Sep 14 |
nicklas |
182 |
|
5452 |
28 May 19 |
nicklas |
Reggie.loadProtocols('POOLING_PROTOCOL', 'poolProtocol', 'LIBPREP_TARGET', 'Manual'); |
2659 |
12 Sep 14 |
nicklas |
184 |
|
2659 |
12 Sep 14 |
nicklas |
var html = ''; |
2659 |
12 Sep 14 |
nicklas |
for (var i = 0; i < frm.pools.length; i++) |
2659 |
12 Sep 14 |
nicklas |
187 |
{ |
2659 |
12 Sep 14 |
nicklas |
if (frm.pools[i].selected) |
2659 |
12 Sep 14 |
nicklas |
189 |
{ |
2659 |
12 Sep 14 |
nicklas |
var pool = frm.pools[i].pool; |
2659 |
12 Sep 14 |
nicklas |
html += '<tr class="align-top">'; |
2659 |
12 Sep 14 |
nicklas |
html += '<td class="subprompt">'+Strings.encodeTags(pool.name)+'</td>'; |
2659 |
12 Sep 14 |
nicklas |
html += '<td class="input"><textarea rows="3" name="comments.'+pool.id+'"></textarea></td>'; |
2659 |
12 Sep 14 |
nicklas |
html += '<td class="status"></td>'; |
2659 |
12 Sep 14 |
nicklas |
html += '<td class="help"></td>'; |
2659 |
12 Sep 14 |
nicklas |
html += '</tr>'; |
2659 |
12 Sep 14 |
nicklas |
197 |
} |
2659 |
12 Sep 14 |
nicklas |
198 |
} |
2659 |
12 Sep 14 |
nicklas |
Doc.element('pool-comments').innerHTML = html; |
2659 |
12 Sep 14 |
nicklas |
200 |
|
2659 |
12 Sep 14 |
nicklas |
for (var i = 0; i < frm.pools.length; i++) |
2659 |
12 Sep 14 |
nicklas |
202 |
{ |
2659 |
12 Sep 14 |
nicklas |
if (frm.pools[i].selected) |
2659 |
12 Sep 14 |
nicklas |
204 |
{ |
2659 |
12 Sep 14 |
nicklas |
var pool = frm.pools[i].pool; |
2659 |
12 Sep 14 |
nicklas |
frm['comments.'+pool.id].value = pool.comments; |
2659 |
12 Sep 14 |
nicklas |
207 |
} |
2659 |
12 Sep 14 |
nicklas |
208 |
} |
2659 |
12 Sep 14 |
nicklas |
209 |
|
2659 |
12 Sep 14 |
nicklas |
frm.poolDate.focus(); |
2659 |
12 Sep 14 |
nicklas |
211 |
} |
2659 |
12 Sep 14 |
nicklas |
212 |
|
2659 |
12 Sep 14 |
nicklas |
pool.validateStep2 = function(event) |
2659 |
12 Sep 14 |
nicklas |
214 |
{ |
2659 |
12 Sep 14 |
nicklas |
if (!Wizard.isValid('poolDate')) |
2659 |
12 Sep 14 |
nicklas |
216 |
{ |
2659 |
12 Sep 14 |
nicklas |
event.preventDefault(); |
2659 |
12 Sep 14 |
nicklas |
218 |
} |
2659 |
12 Sep 14 |
nicklas |
219 |
} |
2659 |
12 Sep 14 |
nicklas |
220 |
|
2659 |
12 Sep 14 |
nicklas |
pool.submit = function() |
2659 |
12 Sep 14 |
nicklas |
222 |
{ |
2659 |
12 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2659 |
12 Sep 14 |
nicklas |
224 |
|
2659 |
12 Sep 14 |
nicklas |
var pools = []; |
2659 |
12 Sep 14 |
nicklas |
for (var i = 0; i < frm.pools.length; i++) |
2659 |
12 Sep 14 |
nicklas |
227 |
{ |
2659 |
12 Sep 14 |
nicklas |
if (frm.pools[i].selected) |
2659 |
12 Sep 14 |
nicklas |
229 |
{ |
2659 |
12 Sep 14 |
nicklas |
var p = frm.pools[i].pool; |
2659 |
12 Sep 14 |
nicklas |
var poolInfo = {}; |
2659 |
12 Sep 14 |
nicklas |
poolInfo.id = p.id; |
2659 |
12 Sep 14 |
nicklas |
poolInfo.comments = frm['comments.'+p.id].value; |
2659 |
12 Sep 14 |
nicklas |
pools[pools.length] = poolInfo; |
2659 |
12 Sep 14 |
nicklas |
235 |
} |
2659 |
12 Sep 14 |
nicklas |
236 |
} |
2659 |
12 Sep 14 |
nicklas |
var submitInfo = {}; |
2659 |
12 Sep 14 |
nicklas |
submitInfo.pools = pools; |
2659 |
12 Sep 14 |
nicklas |
submitInfo.poolDate = frm.poolDate.value; |
2659 |
12 Sep 14 |
nicklas |
submitInfo.poolProtocol = parseInt(frm.poolProtocol.value, 10); |
2659 |
12 Sep 14 |
nicklas |
submitInfo.poolOperator = frm.poolOperator.value; |
2659 |
12 Sep 14 |
nicklas |
242 |
|
2659 |
12 Sep 14 |
nicklas |
var url = '../Pool.servlet?ID='+App.getSessionId(); |
2659 |
12 Sep 14 |
nicklas |
url += '&cmd=RegisterPooledLibraries'; |
2659 |
12 Sep 14 |
nicklas |
Wizard.showLoadingAnimation('Performing registration...'); |
2659 |
12 Sep 14 |
nicklas |
Wizard.asyncJsonRequest(url, pool.submissionResults, 'POST', JSON.stringify(submitInfo)); |
2659 |
12 Sep 14 |
nicklas |
247 |
} |
2659 |
12 Sep 14 |
nicklas |
248 |
|
2659 |
12 Sep 14 |
nicklas |
pool.submissionResults = function(response) |
2659 |
12 Sep 14 |
nicklas |
250 |
{ |
2659 |
12 Sep 14 |
nicklas |
Wizard.showFinalMessage(response.messages); |
2659 |
12 Sep 14 |
nicklas |
Doc.show('gorestart'); |
2659 |
12 Sep 14 |
nicklas |
253 |
} |
2659 |
12 Sep 14 |
nicklas |
254 |
|
2659 |
12 Sep 14 |
nicklas |
return pool; |
2659 |
12 Sep 14 |
nicklas |
256 |
}(); |
2659 |
12 Sep 14 |
nicklas |
257 |
|
2659 |
12 Sep 14 |
nicklas |
Doc.onLoad(Pool.initPage); |
2659 |
12 Sep 14 |
nicklas |
259 |
|