5462 |
03 Jun 19 |
nicklas |
var FlowCell = function() |
5462 |
03 Jun 19 |
nicklas |
2 |
{ |
5462 |
03 Jun 19 |
nicklas |
var flowcell = {}; |
5462 |
03 Jun 19 |
nicklas |
var debug = 0; |
5462 |
03 Jun 19 |
nicklas |
5 |
|
5462 |
03 Jun 19 |
nicklas |
var COLORS = ['blue', 'green', 'yellow', 'red']; |
5462 |
03 Jun 19 |
nicklas |
var nextColor = 0; |
5462 |
03 Jun 19 |
nicklas |
8 |
|
5462 |
03 Jun 19 |
nicklas |
// Page initialization |
5462 |
03 Jun 19 |
nicklas |
flowcell.initPage = function() |
5462 |
03 Jun 19 |
nicklas |
11 |
{ |
5462 |
03 Jun 19 |
nicklas |
var pageId = Doc.getPageId(); |
5462 |
03 Jun 19 |
nicklas |
if (pageId == 'protocol') |
5462 |
03 Jun 19 |
nicklas |
14 |
{ |
5462 |
03 Jun 19 |
nicklas |
Buttons.addClickHandler('print-button', Wizard.goPrint); |
5462 |
03 Jun 19 |
nicklas |
var idList = Data.get('page-data', 'flowcells'); |
5470 |
05 Jun 19 |
nicklas |
var url = '../FlowCell.servlet?ID='+App.getSessionId(); |
5462 |
03 Jun 19 |
nicklas |
url += '&cmd=GetFlowCellInfo'; |
5462 |
03 Jun 19 |
nicklas |
url += '&idlist='+idList; |
5462 |
03 Jun 19 |
nicklas |
Wizard.showLoadingAnimation('Loading flow cell info...'); |
5462 |
03 Jun 19 |
nicklas |
Wizard.asyncJsonRequest(url, flowcell.initializeProtocol); |
5462 |
03 Jun 19 |
nicklas |
22 |
} |
5462 |
03 Jun 19 |
nicklas |
else |
5462 |
03 Jun 19 |
nicklas |
24 |
{ |
5462 |
03 Jun 19 |
nicklas |
Buttons.addClickHandler('gocreate', flowcell.createProtocol); |
5470 |
05 Jun 19 |
nicklas |
var url = '../FlowCell.servlet?ID='+App.getSessionId(); |
5470 |
05 Jun 19 |
nicklas |
url += '&cmd=GetUnprocessedFlowCells&pipeline=MIPS'; |
5462 |
03 Jun 19 |
nicklas |
Wizard.showLoadingAnimation('Loading flow cells...'); |
5462 |
03 Jun 19 |
nicklas |
Wizard.asyncJsonRequest(url, flowcell.initializeStep1); |
5462 |
03 Jun 19 |
nicklas |
30 |
} |
5462 |
03 Jun 19 |
nicklas |
31 |
} |
5462 |
03 Jun 19 |
nicklas |
32 |
|
5462 |
03 Jun 19 |
nicklas |
33 |
|
5462 |
03 Jun 19 |
nicklas |
flowcell.initializeStep1 = function(response) |
5462 |
03 Jun 19 |
nicklas |
35 |
{ |
5462 |
03 Jun 19 |
nicklas |
var frm = document.forms['reggie']; |
5462 |
03 Jun 19 |
nicklas |
var flowCells = response.flowCells; |
5462 |
03 Jun 19 |
nicklas |
38 |
|
5462 |
03 Jun 19 |
nicklas |
if (flowCells.length > 0) |
5462 |
03 Jun 19 |
nicklas |
40 |
{ |
5462 |
03 Jun 19 |
nicklas |
var lastOption = null; |
5462 |
03 Jun 19 |
nicklas |
for (var fcNo=0; fcNo < flowCells.length; fcNo++) |
5462 |
03 Jun 19 |
nicklas |
43 |
{ |
5462 |
03 Jun 19 |
nicklas |
var fc = flowCells[fcNo]; |
5462 |
03 Jun 19 |
nicklas |
var option = flowcell.getOptionForFlowCell(fc); |
5462 |
03 Jun 19 |
nicklas |
if (fcNo == 0 || (lastOption != null && lastOption.selected && lastOption.title == option.title)) |
5462 |
03 Jun 19 |
nicklas |
47 |
{ |
5462 |
03 Jun 19 |
nicklas |
// Select the first option and more if they have the same pool(s) |
5462 |
03 Jun 19 |
nicklas |
option.selected = true; |
5462 |
03 Jun 19 |
nicklas |
50 |
} |
5462 |
03 Jun 19 |
nicklas |
frm.flowcells[frm.flowcells.length] = option; |
5462 |
03 Jun 19 |
nicklas |
lastOption = option; |
5462 |
03 Jun 19 |
nicklas |
53 |
} |
5462 |
03 Jun 19 |
nicklas |
54 |
} |
5462 |
03 Jun 19 |
nicklas |
else |
5462 |
03 Jun 19 |
nicklas |
56 |
{ |
5462 |
03 Jun 19 |
nicklas |
Wizard.setFatalError('No flow cells available for processing.'); |
5462 |
03 Jun 19 |
nicklas |
return; |
5462 |
03 Jun 19 |
nicklas |
59 |
} |
5462 |
03 Jun 19 |
nicklas |
60 |
|
5462 |
03 Jun 19 |
nicklas |
// All is ok |
5462 |
03 Jun 19 |
nicklas |
Doc.show('step-1'); |
5462 |
03 Jun 19 |
nicklas |
Doc.show('gocreate') |
5462 |
03 Jun 19 |
nicklas |
frm.flowcells.focus(); |
5462 |
03 Jun 19 |
nicklas |
65 |
} |
5462 |
03 Jun 19 |
nicklas |
66 |
|
5462 |
03 Jun 19 |
nicklas |
67 |
|
5462 |
03 Jun 19 |
nicklas |
flowcell.getOptionForFlowCell = function(fc) |
5462 |
03 Jun 19 |
nicklas |
69 |
{ |
5462 |
03 Jun 19 |
nicklas |
var name = fc.name +': '; |
5462 |
03 Jun 19 |
nicklas |
71 |
|
5462 |
03 Jun 19 |
nicklas |
var numPools = fc.pools.length; |
5462 |
03 Jun 19 |
nicklas |
var firstPoolNum = flowcell.getPoolNum(fc.pools[0].name); |
5462 |
03 Jun 19 |
nicklas |
var lastPoolNum = flowcell.getPoolNum(fc.pools[fc.pools.length-1].name); |
5462 |
03 Jun 19 |
nicklas |
75 |
|
5462 |
03 Jun 19 |
nicklas |
if (lastPoolNum - firstPoolNum == numPools - 1) |
5462 |
03 Jun 19 |
nicklas |
77 |
{ |
5462 |
03 Jun 19 |
nicklas |
if (numPools > 1) |
5462 |
03 Jun 19 |
nicklas |
79 |
{ |
5462 |
03 Jun 19 |
nicklas |
// Display: PoolN -- PoolY |
5462 |
03 Jun 19 |
nicklas |
name += fc.pools[0].name + ' — ' + fc.pools[fc.pools.length-1].name; |
5462 |
03 Jun 19 |
nicklas |
82 |
} |
5462 |
03 Jun 19 |
nicklas |
else |
5462 |
03 Jun 19 |
nicklas |
84 |
{ |
5462 |
03 Jun 19 |
nicklas |
name += fc.pools[0].name; |
5462 |
03 Jun 19 |
nicklas |
86 |
} |
5462 |
03 Jun 19 |
nicklas |
87 |
} |
5462 |
03 Jun 19 |
nicklas |
else |
5462 |
03 Jun 19 |
nicklas |
89 |
{ |
5462 |
03 Jun 19 |
nicklas |
// Display: PoolN + x more... |
5462 |
03 Jun 19 |
nicklas |
name += fc.pools[0].name + ' + ' + (numPools-1) + ' more...'; |
5462 |
03 Jun 19 |
nicklas |
92 |
} |
5462 |
03 Jun 19 |
nicklas |
93 |
|
5470 |
05 Jun 19 |
nicklas |
name += ' ['; |
5470 |
05 Jun 19 |
nicklas |
if (fc.FlowCellType) name += fc.FlowCellType + '; '; |
5470 |
05 Jun 19 |
nicklas |
name += fc.pipeline + ']'; |
5462 |
03 Jun 19 |
nicklas |
97 |
|
5462 |
03 Jun 19 |
nicklas |
// Tooltip is always all pools |
5462 |
03 Jun 19 |
nicklas |
var title = ''; |
5462 |
03 Jun 19 |
nicklas |
for (var poolNo=0; poolNo < numPools; poolNo++) |
5462 |
03 Jun 19 |
nicklas |
101 |
{ |
5462 |
03 Jun 19 |
nicklas |
var pool = fc.pools[poolNo]; |
5462 |
03 Jun 19 |
nicklas |
if (poolNo > 0) title += ', '; |
5462 |
03 Jun 19 |
nicklas |
title += pool.name; |
5462 |
03 Jun 19 |
nicklas |
105 |
} |
5462 |
03 Jun 19 |
nicklas |
106 |
|
5462 |
03 Jun 19 |
nicklas |
var option = new Option(name, fc.id); |
5462 |
03 Jun 19 |
nicklas |
option.title = title; |
5462 |
03 Jun 19 |
nicklas |
option.flowCell = fc; |
5462 |
03 Jun 19 |
nicklas |
110 |
|
5462 |
03 Jun 19 |
nicklas |
return option; |
5462 |
03 Jun 19 |
nicklas |
112 |
} |
5462 |
03 Jun 19 |
nicklas |
113 |
|
5462 |
03 Jun 19 |
nicklas |
flowcell.getPoolNum = function(poolName) |
5462 |
03 Jun 19 |
nicklas |
115 |
{ |
5462 |
03 Jun 19 |
nicklas |
var num = poolName.match(/Pool(\d+)/); |
5462 |
03 Jun 19 |
nicklas |
return num ? parseInt(num[1], 10) : null; |
5462 |
03 Jun 19 |
nicklas |
118 |
} |
5462 |
03 Jun 19 |
nicklas |
119 |
|
5462 |
03 Jun 19 |
nicklas |
120 |
|
5462 |
03 Jun 19 |
nicklas |
flowcell.createProtocol = function() |
5462 |
03 Jun 19 |
nicklas |
122 |
{ |
5462 |
03 Jun 19 |
nicklas |
var frm = document.forms['reggie']; |
5462 |
03 Jun 19 |
nicklas |
124 |
|
5462 |
03 Jun 19 |
nicklas |
var selected = []; |
5462 |
03 Jun 19 |
nicklas |
for (var i = 0; i < frm.flowcells.length; i++) |
5462 |
03 Jun 19 |
nicklas |
127 |
{ |
5462 |
03 Jun 19 |
nicklas |
if (frm.flowcells[i].selected) |
5462 |
03 Jun 19 |
nicklas |
129 |
{ |
5462 |
03 Jun 19 |
nicklas |
selected[selected.length] = frm.flowcells[i].value; |
5462 |
03 Jun 19 |
nicklas |
131 |
} |
5462 |
03 Jun 19 |
nicklas |
132 |
} |
5462 |
03 Jun 19 |
nicklas |
133 |
|
5462 |
03 Jun 19 |
nicklas |
if (selected.length == 0) |
5462 |
03 Jun 19 |
nicklas |
135 |
{ |
5462 |
03 Jun 19 |
nicklas |
Wizard.setInputStatus('flowcells', 'invalid', 'Select at least one flow cell'); |
5462 |
03 Jun 19 |
nicklas |
Wizard.notifyError(); |
5462 |
03 Jun 19 |
nicklas |
return; |
5462 |
03 Jun 19 |
nicklas |
139 |
} |
5462 |
03 Jun 19 |
nicklas |
140 |
|
5462 |
03 Jun 19 |
nicklas |
frm.submit(); |
5462 |
03 Jun 19 |
nicklas |
142 |
} |
5462 |
03 Jun 19 |
nicklas |
143 |
|
5462 |
03 Jun 19 |
nicklas |
flowcell.initializeProtocol = function(response) |
5462 |
03 Jun 19 |
nicklas |
145 |
{ |
5462 |
03 Jun 19 |
nicklas |
var flowCells = response.flowCells; |
5462 |
03 Jun 19 |
nicklas |
147 |
|
5462 |
03 Jun 19 |
nicklas |
var allColors = []; |
5462 |
03 Jun 19 |
nicklas |
var useDarker = false; |
5462 |
03 Jun 19 |
nicklas |
150 |
|
5462 |
03 Jun 19 |
nicklas |
var names = []; |
5462 |
03 Jun 19 |
nicklas |
152 |
|
5462 |
03 Jun 19 |
nicklas |
for (var fcNo = 0; fcNo < flowCells.length; fcNo++) |
5462 |
03 Jun 19 |
nicklas |
154 |
{ |
5462 |
03 Jun 19 |
nicklas |
var fc = flowCells[fcNo]; |
5462 |
03 Jun 19 |
nicklas |
names[names.length] = fc.name; |
5462 |
03 Jun 19 |
nicklas |
157 |
|
5462 |
03 Jun 19 |
nicklas |
var poolColors = []; |
5462 |
03 Jun 19 |
nicklas |
var poolsRow = Doc.element('all-pools-'+fcNo); |
5462 |
03 Jun 19 |
nicklas |
160 |
|
5462 |
03 Jun 19 |
nicklas |
Doc.element('flowCellName.'+fcNo).innerHTML = Strings.encodeTags(fc.name); |
5462 |
03 Jun 19 |
nicklas |
Doc.element('flowCellDescription.'+fcNo).innerHTML = Strings.encodeTags(fc.description); |
5462 |
03 Jun 19 |
nicklas |
Doc.element('sequencingCycles.'+fcNo).innerHTML = Strings.encodeTags(fc.SequencingCycles); |
5462 |
03 Jun 19 |
nicklas |
Doc.element('flowCellId.'+fcNo).innerHTML = Strings.encodeTags(fc.externalId); |
5470 |
05 Jun 19 |
nicklas |
Doc.element('flowCellType.'+fcNo).innerHTML = Strings.encodeTags(fc.FlowCellType || '') + '; ' + Strings.encodeTags(fc.pipeline || ''); |
5462 |
03 Jun 19 |
nicklas |
166 |
|
5462 |
03 Jun 19 |
nicklas |
if (fc.FlowCellType == 'NextSeq') Doc.hide('pos.b.'+fcNo); |
5462 |
03 Jun 19 |
nicklas |
168 |
|
5462 |
03 Jun 19 |
nicklas |
var lanesHtml = ''; |
5462 |
03 Jun 19 |
nicklas |
for (var laneNo = 0; laneNo < fc.numLanes; laneNo++) |
5462 |
03 Jun 19 |
nicklas |
171 |
{ |
5462 |
03 Jun 19 |
nicklas |
var pool = fc.lanes[laneNo]; |
5462 |
03 Jun 19 |
nicklas |
var poolName = pool.name; |
5462 |
03 Jun 19 |
nicklas |
var color = poolColors[poolName]; |
5462 |
03 Jun 19 |
nicklas |
if (!color) |
5462 |
03 Jun 19 |
nicklas |
176 |
{ |
5462 |
03 Jun 19 |
nicklas |
color = allColors[poolName]; |
5462 |
03 Jun 19 |
nicklas |
if (!color) |
5462 |
03 Jun 19 |
nicklas |
179 |
{ |
5462 |
03 Jun 19 |
nicklas |
color = COLORS[nextColor] + (useDarker ? ' darker' : ''); |
5462 |
03 Jun 19 |
nicklas |
allColors[poolName] = color; |
5462 |
03 Jun 19 |
nicklas |
nextColor++; |
5462 |
03 Jun 19 |
nicklas |
if (nextColor == COLORS.length) |
5462 |
03 Jun 19 |
nicklas |
184 |
{ |
5462 |
03 Jun 19 |
nicklas |
nextColor = 0; |
5462 |
03 Jun 19 |
nicklas |
useDarker = !useDarker; |
5462 |
03 Jun 19 |
nicklas |
187 |
} |
5462 |
03 Jun 19 |
nicklas |
188 |
} |
5462 |
03 Jun 19 |
nicklas |
poolColors[poolName] = color; |
5462 |
03 Jun 19 |
nicklas |
var td = document.createElement('td'); |
5462 |
03 Jun 19 |
nicklas |
td.className = 'pool-legend ' + color; |
5462 |
03 Jun 19 |
nicklas |
td.innerHTML = poolName; |
5462 |
03 Jun 19 |
nicklas |
poolsRow.appendChild(td); |
5462 |
03 Jun 19 |
nicklas |
194 |
} |
5462 |
03 Jun 19 |
nicklas |
195 |
|
5462 |
03 Jun 19 |
nicklas |
lanesHtml += '<tr>'; |
5462 |
03 Jun 19 |
nicklas |
lanesHtml += '<td class="lane-no">'+(laneNo+1)+'</td>'; |
5462 |
03 Jun 19 |
nicklas |
lanesHtml += '<td class="pool-name '+color+'">'+Strings.encodeTags(poolName)+'</td>'; |
5462 |
03 Jun 19 |
nicklas |
lanesHtml += '<td class="remarks">'; |
5462 |
03 Jun 19 |
nicklas |
lanesHtml += '</td>'; |
5462 |
03 Jun 19 |
nicklas |
lanesHtml += '</tr>'; |
5462 |
03 Jun 19 |
nicklas |
202 |
} |
5462 |
03 Jun 19 |
nicklas |
203 |
|
5462 |
03 Jun 19 |
nicklas |
Doc.element('pools.'+fcNo).innerHTML = lanesHtml; |
5462 |
03 Jun 19 |
nicklas |
205 |
|
5462 |
03 Jun 19 |
nicklas |
if (poolColors.length <= 6) |
5462 |
03 Jun 19 |
nicklas |
207 |
{ |
5462 |
03 Jun 19 |
nicklas |
// White-space at end to avoid pools getting to wide |
5462 |
03 Jun 19 |
nicklas |
var td = document.createElement('td'); |
5462 |
03 Jun 19 |
nicklas |
td.innerHTML = ''; |
5462 |
03 Jun 19 |
nicklas |
poolsRow.appendChild(td); |
5462 |
03 Jun 19 |
nicklas |
212 |
} |
5462 |
03 Jun 19 |
nicklas |
213 |
} |
5462 |
03 Jun 19 |
nicklas |
214 |
|
5462 |
03 Jun 19 |
nicklas |
document.title = 'Lab protocol for ' + names.join(', '); |
5462 |
03 Jun 19 |
nicklas |
Doc.show('all-protocol'); |
5462 |
03 Jun 19 |
nicklas |
217 |
} |
5462 |
03 Jun 19 |
nicklas |
218 |
|
5462 |
03 Jun 19 |
nicklas |
return flowcell; |
5462 |
03 Jun 19 |
nicklas |
220 |
}(); |
5462 |
03 Jun 19 |
nicklas |
221 |
|
5462 |
03 Jun 19 |
nicklas |
Doc.onLoad(FlowCell.initPage); |
5462 |
03 Jun 19 |
nicklas |
223 |
|