3449 |
28 Jul 15 |
olle |
var AutoSelect = function() |
3449 |
28 Jul 15 |
olle |
2 |
{ |
3449 |
28 Jul 15 |
olle |
var autoselect = {}; |
3449 |
28 Jul 15 |
olle |
var debug = 0; |
3449 |
28 Jul 15 |
olle |
var hasInitProtocols = false; |
3449 |
28 Jul 15 |
olle |
6 |
|
3449 |
28 Jul 15 |
olle |
// Page initialization |
3449 |
28 Jul 15 |
olle |
autoselect.initPage = function() |
3449 |
28 Jul 15 |
olle |
9 |
{ |
3449 |
28 Jul 15 |
olle |
Buttons.addClickHandler('close', App.closeWindow); |
3449 |
28 Jul 15 |
olle |
Buttons.addClickHandler('btnOk', autoselect.doAutoSelect); |
3449 |
28 Jul 15 |
olle |
12 |
|
3449 |
28 Jul 15 |
olle |
Events.addEventHandler('quantity_regular', 'keypress', Events.numberOnly); |
3449 |
28 Jul 15 |
olle |
Events.addEventHandler('quality_score', 'keypress', Events.numberOnly); |
3449 |
28 Jul 15 |
olle |
15 |
|
3449 |
28 Jul 15 |
olle |
16 |
/* |
3449 |
28 Jul 15 |
olle |
Events.addEventHandler('preNormalized.0', 'click', autoselect.setPreNormalize); |
3449 |
28 Jul 15 |
olle |
Events.addEventHandler('preNormalized.1', 'click', autoselect.setPreNormalize); |
3449 |
28 Jul 15 |
olle |
19 |
*/ |
3449 |
28 Jul 15 |
olle |
20 |
|
3449 |
28 Jul 15 |
olle |
21 |
/* |
3449 |
28 Jul 15 |
olle |
Events.addEventHandler('normalizationProtocol', 'change', autoselect.protocolOnChange); |
3449 |
28 Jul 15 |
olle |
Meludi.loadProtocols('DNA_NORMALIZATION_PROTOCOL', 'normalizationProtocol', 'DNA_TARGET_AMOUNT,DNA_TARGET_VOLUME'); |
3449 |
28 Jul 15 |
olle |
autoselect.setPreNormalize(); |
3449 |
28 Jul 15 |
olle |
25 |
*/ |
3449 |
28 Jul 15 |
olle |
26 |
} |
3449 |
28 Jul 15 |
olle |
27 |
|
3449 |
28 Jul 15 |
olle |
autoselect.setPreNormalize = function() |
3449 |
28 Jul 15 |
olle |
29 |
{ |
3449 |
28 Jul 15 |
olle |
var frm = document.forms['options']; |
3449 |
28 Jul 15 |
olle |
var preNormalize = frm.preNormalized[1].checked; |
3449 |
28 Jul 15 |
olle |
32 |
|
3449 |
28 Jul 15 |
olle |
Doc.element('normalizationProtocol').disabled = !preNormalize; |
3449 |
28 Jul 15 |
olle |
Doc.element('remainingQuantity').disabled = preNormalize; |
3449 |
28 Jul 15 |
olle |
Doc.element('quantity_regular').disabled = preNormalize; |
3449 |
28 Jul 15 |
olle |
Doc.element('qualityScore').disabled = preNormalize; |
3449 |
28 Jul 15 |
olle |
Doc.element('quality_score').disabled = preNormalize; |
3449 |
28 Jul 15 |
olle |
Doc.element('reProcess').disabled = preNormalize; |
3449 |
28 Jul 15 |
olle |
Doc.element('flag').disabled = preNormalize; |
3449 |
28 Jul 15 |
olle |
40 |
} |
3449 |
28 Jul 15 |
olle |
41 |
|
3449 |
28 Jul 15 |
olle |
autoselect.protocolOnChange = function() |
3449 |
28 Jul 15 |
olle |
43 |
{ |
3449 |
28 Jul 15 |
olle |
var frm = document.forms['options']; |
3449 |
28 Jul 15 |
olle |
45 |
|
3449 |
28 Jul 15 |
olle |
if (!hasInitProtocols) |
3449 |
28 Jul 15 |
olle |
47 |
{ |
3449 |
28 Jul 15 |
olle |
hasInitProtocols = true; |
3449 |
28 Jul 15 |
olle |
49 |
|
3449 |
28 Jul 15 |
olle |
if (frm.normalizationProtocol.length == 0) |
3449 |
28 Jul 15 |
olle |
51 |
{ |
3449 |
28 Jul 15 |
olle |
Wizard.setFatalError('No DNA normalization protocols found. Please ask the server administrator to create at least one protocol.'); |
3449 |
28 Jul 15 |
olle |
return; |
3449 |
28 Jul 15 |
olle |
54 |
} |
3449 |
28 Jul 15 |
olle |
55 |
|
3449 |
28 Jul 15 |
olle |
var targetDnaAmount = parseFloat(frm.quantity_regular.value); |
3449 |
28 Jul 15 |
olle |
var closestAlternateProtocolIndex = -1; |
3449 |
28 Jul 15 |
olle |
var closestDnaAmount = 999; |
3449 |
28 Jul 15 |
olle |
59 |
|
3449 |
28 Jul 15 |
olle |
for (var i=0; i < frm.normalizationProtocol.length; i++) |
3449 |
28 Jul 15 |
olle |
61 |
{ |
3449 |
28 Jul 15 |
olle |
var p = frm.normalizationProtocol[i].item; |
3449 |
28 Jul 15 |
olle |
frm.normalizationProtocol[i].text = p.name + ' (' + (p.DNATargetAmount || '? ') + 'µg in '+(p.DNATargetVolume || '? ')+'µl)'; |
3449 |
28 Jul 15 |
olle |
64 |
|
3449 |
28 Jul 15 |
olle |
// Adjust default selected protocol to match the expected DNA amount |
3449 |
28 Jul 15 |
olle |
// The protocol must be an alternate project default and have a DNATargetAmount value |
3449 |
28 Jul 15 |
olle |
if (p.alternateDefault && p.DNATargetAmount) |
3449 |
28 Jul 15 |
olle |
68 |
{ |
3449 |
28 Jul 15 |
olle |
var tmp = Math.abs(targetDnaAmount-p.DNATargetAmount); |
3449 |
28 Jul 15 |
olle |
if (tmp < closestDnaAmount) |
3449 |
28 Jul 15 |
olle |
71 |
{ |
3449 |
28 Jul 15 |
olle |
closestDnaAmount = tmp; |
3449 |
28 Jul 15 |
olle |
closestAlternateProtocolIndex = i; |
3449 |
28 Jul 15 |
olle |
74 |
} |
3449 |
28 Jul 15 |
olle |
75 |
} |
3449 |
28 Jul 15 |
olle |
76 |
} |
3449 |
28 Jul 15 |
olle |
77 |
|
3449 |
28 Jul 15 |
olle |
if (closestAlternateProtocolIndex != -1) |
3449 |
28 Jul 15 |
olle |
79 |
{ |
3449 |
28 Jul 15 |
olle |
frm.normalizationProtocol.selectedIndex = closestAlternateProtocolIndex; |
3449 |
28 Jul 15 |
olle |
81 |
} |
3449 |
28 Jul 15 |
olle |
82 |
} |
3449 |
28 Jul 15 |
olle |
83 |
} |
3449 |
28 Jul 15 |
olle |
84 |
|
3449 |
28 Jul 15 |
olle |
85 |
|
3449 |
28 Jul 15 |
olle |
autoselect.doAutoSelect = function() |
3449 |
28 Jul 15 |
olle |
87 |
{ |
3449 |
28 Jul 15 |
olle |
var options = {}; |
3449 |
28 Jul 15 |
olle |
var frm = document.forms['options']; |
3449 |
28 Jul 15 |
olle |
90 |
|
3449 |
28 Jul 15 |
olle |
91 |
/* |
3449 |
28 Jul 15 |
olle |
var preNormalize = frm.preNormalized[1].checked; |
3449 |
28 Jul 15 |
olle |
93 |
*/ |
3449 |
28 Jul 15 |
olle |
var preNormalize = false; |
3449 |
28 Jul 15 |
olle |
var startDate = frm.startDate.value; |
3449 |
28 Jul 15 |
olle |
if (startDate && !Dates.isDate(startDate, 'yyyyMMdd')) |
3449 |
28 Jul 15 |
olle |
97 |
{ |
3449 |
28 Jul 15 |
olle |
Forms.showNotification('startDate', 'Not a valid date'); |
3449 |
28 Jul 15 |
olle |
return; |
3449 |
28 Jul 15 |
olle |
100 |
} |
3449 |
28 Jul 15 |
olle |
101 |
|
3449 |
28 Jul 15 |
olle |
if (!preNormalize) |
3449 |
28 Jul 15 |
olle |
103 |
{ |
3449 |
28 Jul 15 |
olle |
var qRegular = parseFloat(frm.quantity_regular.value); |
3449 |
28 Jul 15 |
olle |
if (!(qRegular > 0)) |
3449 |
28 Jul 15 |
olle |
106 |
{ |
3449 |
28 Jul 15 |
olle |
Forms.showNotification('quantity_regular', 'Remaining quantity must be a number >0'); |
3449 |
28 Jul 15 |
olle |
return; |
3449 |
28 Jul 15 |
olle |
109 |
} |
3449 |
28 Jul 15 |
olle |
110 |
|
3449 |
28 Jul 15 |
olle |
var qualityScore = parseFloat(frm.quality_score.value); |
3449 |
28 Jul 15 |
olle |
112 |
/* |
3449 |
28 Jul 15 |
olle |
if (!(qualityScore > 0)) |
3449 |
28 Jul 15 |
olle |
114 |
{ |
3449 |
28 Jul 15 |
olle |
Forms.showNotification('quality_score', 'RQS/RIN must be a number >0') |
3449 |
28 Jul 15 |
olle |
return; |
3449 |
28 Jul 15 |
olle |
117 |
} |
3449 |
28 Jul 15 |
olle |
118 |
*/ |
3449 |
28 Jul 15 |
olle |
119 |
} |
3449 |
28 Jul 15 |
olle |
else |
3449 |
28 Jul 15 |
olle |
121 |
{ |
3449 |
28 Jul 15 |
olle |
options.normalizationProtocol = parseInt(frm.normalizationProtocol.value); |
3449 |
28 Jul 15 |
olle |
123 |
} |
3449 |
28 Jul 15 |
olle |
124 |
|
3449 |
28 Jul 15 |
olle |
125 |
|
3449 |
28 Jul 15 |
olle |
if (startDate) options.startDate = startDate; |
3449 |
28 Jul 15 |
olle |
if (preNormalize) |
3449 |
28 Jul 15 |
olle |
128 |
{ |
3449 |
28 Jul 15 |
olle |
options.preNormalized = 1; |
3449 |
28 Jul 15 |
olle |
130 |
} |
3449 |
28 Jul 15 |
olle |
else |
3449 |
28 Jul 15 |
olle |
132 |
{ |
3449 |
28 Jul 15 |
olle |
if (frm.remainingQuantity.checked) options.remainingQuantity = qRegular; |
3449 |
28 Jul 15 |
olle |
if (frm.qualityScore.checked) options.qualityScore = qualityScore; |
3449 |
28 Jul 15 |
olle |
135 |
/* |
3449 |
28 Jul 15 |
olle |
if (frm.flag.checked) options.flag = 1; |
3449 |
28 Jul 15 |
olle |
137 |
*/ |
3449 |
28 Jul 15 |
olle |
138 |
/* |
3449 |
28 Jul 15 |
olle |
if (frm.reProcess.checked) options.reProcess = 1; |
3449 |
28 Jul 15 |
olle |
140 |
*/ |
3449 |
28 Jul 15 |
olle |
141 |
} |
3449 |
28 Jul 15 |
olle |
142 |
|
3449 |
28 Jul 15 |
olle |
options.ignore = Data.json('page-data', 'ignore'); |
3449 |
28 Jul 15 |
olle |
144 |
|
3449 |
28 Jul 15 |
olle |
var url = '../Dna.servlet?ID='+App.getSessionId(); |
3449 |
28 Jul 15 |
olle |
146 |
/* |
3449 |
28 Jul 15 |
olle |
url += '&cmd=AutoSelectRnaForMRna&numToSelect='+Data.get('page-data', 'num-to-select'); |
3449 |
28 Jul 15 |
olle |
148 |
*/ |
3449 |
28 Jul 15 |
olle |
149 |
/* |
3449 |
28 Jul 15 |
olle |
url += '&cmd=AutoSelectDna&numToSelect='+Data.get('page-data', 'num-to-select'); |
3449 |
28 Jul 15 |
olle |
151 |
*/ |
3449 |
28 Jul 15 |
olle |
url += '&cmd=AutoSelectDna'; |
3449 |
28 Jul 15 |
olle |
url += '&numToSelect='+Data.get('page-data', 'num-to-select'); |
3449 |
28 Jul 15 |
olle |
url += '&startDate='+Data.get('page-data', 'start-date'); |
3449 |
28 Jul 15 |
olle |
155 |
|
3449 |
28 Jul 15 |
olle |
Wizard.showLoadingAnimation('Finding DNA. Please wait...'); |
3449 |
28 Jul 15 |
olle |
Wizard.asyncJsonRequest(url, autoselect.dnaSelected, 'POST', JSON.stringify(options)); |
3449 |
28 Jul 15 |
olle |
158 |
} |
3449 |
28 Jul 15 |
olle |
159 |
|
3449 |
28 Jul 15 |
olle |
autoselect.dnaSelected = function(response) |
3449 |
28 Jul 15 |
olle |
161 |
{ |
3449 |
28 Jul 15 |
olle |
var dna = response.dna; |
3449 |
28 Jul 15 |
olle |
if (dna.length == 0) |
3449 |
28 Jul 15 |
olle |
164 |
{ |
3449 |
28 Jul 15 |
olle |
Doc.addClass('btnOk', 'disabled'); |
3449 |
28 Jul 15 |
olle |
Wizard.setFatalError('Could not find any unprocessed DNA at this time.'); |
3449 |
28 Jul 15 |
olle |
return; |
3449 |
28 Jul 15 |
olle |
168 |
} |
3449 |
28 Jul 15 |
olle |
169 |
|
3449 |
28 Jul 15 |
olle |
window.opener.SelectDna.dnaSelected(response); |
3449 |
28 Jul 15 |
olle |
window.close(); |
3449 |
28 Jul 15 |
olle |
172 |
} |
3449 |
28 Jul 15 |
olle |
173 |
|
3449 |
28 Jul 15 |
olle |
return autoselect; |
3449 |
28 Jul 15 |
olle |
175 |
}(); |
3449 |
28 Jul 15 |
olle |
176 |
|
3449 |
28 Jul 15 |
olle |
Doc.onLoad(AutoSelect.initPage); |
3449 |
28 Jul 15 |
olle |
178 |
|