2803 |
14 Oct 14 |
nicklas |
var AutoSelect = function() |
2803 |
14 Oct 14 |
nicklas |
2 |
{ |
2803 |
14 Oct 14 |
nicklas |
var autoselect = {}; |
2803 |
14 Oct 14 |
nicklas |
var debug = 0; |
3270 |
23 Apr 15 |
nicklas |
var hasInitProtocols = false; |
2803 |
14 Oct 14 |
nicklas |
6 |
|
2803 |
14 Oct 14 |
nicklas |
// Page initialization |
2803 |
14 Oct 14 |
nicklas |
autoselect.initPage = function() |
2803 |
14 Oct 14 |
nicklas |
9 |
{ |
2803 |
14 Oct 14 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
2803 |
14 Oct 14 |
nicklas |
Buttons.addClickHandler('btnOk', autoselect.doAutoSelect); |
2803 |
14 Oct 14 |
nicklas |
12 |
|
2803 |
14 Oct 14 |
nicklas |
Events.addEventHandler('quantity_regular', 'keypress', Events.numberOnly); |
2803 |
14 Oct 14 |
nicklas |
Events.addEventHandler('quality_score', 'keypress', Events.numberOnly); |
2906 |
07 Nov 14 |
nicklas |
15 |
|
2906 |
07 Nov 14 |
nicklas |
Events.addEventHandler('preNormalized.0', 'click', autoselect.setPreNormalize); |
2906 |
07 Nov 14 |
nicklas |
Events.addEventHandler('preNormalized.1', 'click', autoselect.setPreNormalize); |
3270 |
23 Apr 15 |
nicklas |
18 |
|
3270 |
23 Apr 15 |
nicklas |
Events.addEventHandler('normalizationProtocol', 'change', autoselect.protocolOnChange); |
5882 |
26 Mar 20 |
nicklas |
Reggie.loadProtocols('RNA_NORMALIZATION_PROTOCOL', 'normalizationProtocol', 'LIBPREP_TARGET,RNA_TARGET_AMOUNT,RNA_MINIMAL_AMOUNT,RNA_TARGET_VOLUME', 'Manual'); |
2906 |
07 Nov 14 |
nicklas |
autoselect.setPreNormalize(); |
2803 |
14 Oct 14 |
nicklas |
22 |
} |
2803 |
14 Oct 14 |
nicklas |
23 |
|
2906 |
07 Nov 14 |
nicklas |
autoselect.setPreNormalize = function() |
2906 |
07 Nov 14 |
nicklas |
25 |
{ |
2906 |
07 Nov 14 |
nicklas |
var frm = document.forms['options']; |
2906 |
07 Nov 14 |
nicklas |
var preNormalize = frm.preNormalized[1].checked; |
2906 |
07 Nov 14 |
nicklas |
28 |
|
3270 |
23 Apr 15 |
nicklas |
Doc.element('normalizationProtocol').disabled = !preNormalize; |
2906 |
07 Nov 14 |
nicklas |
Doc.element('remainingQuantity').disabled = preNormalize; |
2906 |
07 Nov 14 |
nicklas |
Doc.element('quantity_regular').disabled = preNormalize; |
2906 |
07 Nov 14 |
nicklas |
Doc.element('qualityScore').disabled = preNormalize; |
2906 |
07 Nov 14 |
nicklas |
Doc.element('quality_score').disabled = preNormalize; |
2906 |
07 Nov 14 |
nicklas |
Doc.element('reProcess').disabled = preNormalize; |
2906 |
07 Nov 14 |
nicklas |
Doc.element('flag').disabled = preNormalize; |
2906 |
07 Nov 14 |
nicklas |
36 |
} |
2906 |
07 Nov 14 |
nicklas |
37 |
|
3270 |
23 Apr 15 |
nicklas |
autoselect.protocolOnChange = function() |
3270 |
23 Apr 15 |
nicklas |
39 |
{ |
3270 |
23 Apr 15 |
nicklas |
var frm = document.forms['options']; |
3270 |
23 Apr 15 |
nicklas |
41 |
|
3270 |
23 Apr 15 |
nicklas |
if (!hasInitProtocols) |
3270 |
23 Apr 15 |
nicklas |
43 |
{ |
3270 |
23 Apr 15 |
nicklas |
hasInitProtocols = true; |
3832 |
07 Apr 16 |
nicklas |
var selectedProtocol = Data.int('page-data', 'protocol-id'); |
3316 |
08 May 15 |
nicklas |
46 |
|
3270 |
23 Apr 15 |
nicklas |
if (frm.normalizationProtocol.length == 0) |
3270 |
23 Apr 15 |
nicklas |
48 |
{ |
3270 |
23 Apr 15 |
nicklas |
Wizard.setFatalError('No RNA normalization protocols found. Please ask the server administrator to create at least one protocol.'); |
3270 |
23 Apr 15 |
nicklas |
return; |
3270 |
23 Apr 15 |
nicklas |
51 |
} |
3316 |
08 May 15 |
nicklas |
52 |
|
3270 |
23 Apr 15 |
nicklas |
for (var i=0; i < frm.normalizationProtocol.length; i++) |
3270 |
23 Apr 15 |
nicklas |
54 |
{ |
3270 |
23 Apr 15 |
nicklas |
var p = frm.normalizationProtocol[i].item; |
3832 |
07 Apr 16 |
nicklas |
var unit = 'µg'; |
3832 |
07 Apr 16 |
nicklas |
var factor = 1; |
3832 |
07 Apr 16 |
nicklas |
if (p.RNATargetAmount < 0.5) |
3316 |
08 May 15 |
nicklas |
59 |
{ |
3832 |
07 Apr 16 |
nicklas |
unit = 'ng'; |
3832 |
07 Apr 16 |
nicklas |
factor = 1000; |
3316 |
08 May 15 |
nicklas |
62 |
} |
3832 |
07 Apr 16 |
nicklas |
63 |
|
3832 |
07 Apr 16 |
nicklas |
var text = p.name + ' ('; |
3832 |
07 Apr 16 |
nicklas |
if (p.RNAMinimalAmount) text += Reggie.formatNumber(p.RNAMinimalAmount * factor, '', 1) + '-'; |
3832 |
07 Apr 16 |
nicklas |
text += p.RNATargetAmount ? Reggie.formatNumber(p.RNATargetAmount * factor, '', 1) : '? '; |
3832 |
07 Apr 16 |
nicklas |
text += unit; |
3832 |
07 Apr 16 |
nicklas |
text += ' in '+(p.RNATargetVolume || '? ')+'µl)'; |
3832 |
07 Apr 16 |
nicklas |
frm.normalizationProtocol[i].text = text; |
3832 |
07 Apr 16 |
nicklas |
70 |
|
3832 |
07 Apr 16 |
nicklas |
if (p.id == selectedProtocol) frm.normalizationProtocol.selectedIndex = i; |
3270 |
23 Apr 15 |
nicklas |
72 |
} |
3316 |
08 May 15 |
nicklas |
73 |
|
3270 |
23 Apr 15 |
nicklas |
74 |
} |
3270 |
23 Apr 15 |
nicklas |
75 |
} |
3270 |
23 Apr 15 |
nicklas |
76 |
|
3270 |
23 Apr 15 |
nicklas |
77 |
|
2803 |
14 Oct 14 |
nicklas |
autoselect.doAutoSelect = function() |
2803 |
14 Oct 14 |
nicklas |
79 |
{ |
2803 |
14 Oct 14 |
nicklas |
var options = {}; |
2803 |
14 Oct 14 |
nicklas |
var frm = document.forms['options']; |
2803 |
14 Oct 14 |
nicklas |
82 |
|
2906 |
07 Nov 14 |
nicklas |
var preNormalize = frm.preNormalized[1].checked; |
2803 |
14 Oct 14 |
nicklas |
var startDate = frm.startDate.value; |
2803 |
14 Oct 14 |
nicklas |
if (startDate && !Dates.isDate(startDate, 'yyyyMMdd')) |
2803 |
14 Oct 14 |
nicklas |
86 |
{ |
2803 |
14 Oct 14 |
nicklas |
Forms.showNotification('startDate', 'Not a valid date'); |
2803 |
14 Oct 14 |
nicklas |
return; |
2803 |
14 Oct 14 |
nicklas |
89 |
} |
2803 |
14 Oct 14 |
nicklas |
90 |
|
2906 |
07 Nov 14 |
nicklas |
if (!preNormalize) |
2803 |
14 Oct 14 |
nicklas |
92 |
{ |
2906 |
07 Nov 14 |
nicklas |
var qRegular = parseFloat(frm.quantity_regular.value); |
2906 |
07 Nov 14 |
nicklas |
if (!(qRegular > 0)) |
2906 |
07 Nov 14 |
nicklas |
95 |
{ |
2906 |
07 Nov 14 |
nicklas |
Forms.showNotification('quantity_regular', 'Remaining quantity must be a number >0'); |
2906 |
07 Nov 14 |
nicklas |
return; |
2906 |
07 Nov 14 |
nicklas |
98 |
} |
2906 |
07 Nov 14 |
nicklas |
99 |
|
2906 |
07 Nov 14 |
nicklas |
var qualityScore = parseFloat(frm.quality_score.value); |
2906 |
07 Nov 14 |
nicklas |
if (!(qualityScore > 0)) |
2906 |
07 Nov 14 |
nicklas |
102 |
{ |
2906 |
07 Nov 14 |
nicklas |
Forms.showNotification('quality_score', 'RQS/RIN must be a number >0') |
2906 |
07 Nov 14 |
nicklas |
return; |
2906 |
07 Nov 14 |
nicklas |
105 |
} |
2803 |
14 Oct 14 |
nicklas |
106 |
} |
3270 |
23 Apr 15 |
nicklas |
else |
3270 |
23 Apr 15 |
nicklas |
108 |
{ |
3270 |
23 Apr 15 |
nicklas |
options.normalizationProtocol = parseInt(frm.normalizationProtocol.value); |
3270 |
23 Apr 15 |
nicklas |
110 |
} |
2803 |
14 Oct 14 |
nicklas |
111 |
|
2906 |
07 Nov 14 |
nicklas |
112 |
|
2906 |
07 Nov 14 |
nicklas |
if (startDate) options.startDate = startDate; |
2906 |
07 Nov 14 |
nicklas |
if (preNormalize) |
2803 |
14 Oct 14 |
nicklas |
115 |
{ |
2906 |
07 Nov 14 |
nicklas |
options.preNormalized = 1; |
2803 |
14 Oct 14 |
nicklas |
117 |
} |
2906 |
07 Nov 14 |
nicklas |
else |
2906 |
07 Nov 14 |
nicklas |
119 |
{ |
2906 |
07 Nov 14 |
nicklas |
if (frm.remainingQuantity.checked) options.remainingQuantity = qRegular; |
2906 |
07 Nov 14 |
nicklas |
if (frm.qualityScore.checked) options.qualityScore = qualityScore; |
2906 |
07 Nov 14 |
nicklas |
if (frm.flag.checked) options.flag = 1; |
2906 |
07 Nov 14 |
nicklas |
if (frm.reProcess.checked) options.reProcess = 1; |
2906 |
07 Nov 14 |
nicklas |
124 |
} |
2803 |
14 Oct 14 |
nicklas |
125 |
|
2803 |
14 Oct 14 |
nicklas |
options.ignore = Data.json('page-data', 'ignore'); |
2803 |
14 Oct 14 |
nicklas |
127 |
|
2803 |
14 Oct 14 |
nicklas |
var url = '../MRna.servlet?ID='+App.getSessionId(); |
2803 |
14 Oct 14 |
nicklas |
url += '&cmd=AutoSelectRnaForMRna&numToSelect='+Data.get('page-data', 'num-to-select'); |
2803 |
14 Oct 14 |
nicklas |
130 |
|
2803 |
14 Oct 14 |
nicklas |
Wizard.showLoadingAnimation('Finding RNA. Please wait...'); |
2803 |
14 Oct 14 |
nicklas |
Wizard.asyncJsonRequest(url, autoselect.rnaSelected, 'POST', JSON.stringify(options)); |
2803 |
14 Oct 14 |
nicklas |
133 |
} |
2803 |
14 Oct 14 |
nicklas |
134 |
|
2803 |
14 Oct 14 |
nicklas |
autoselect.rnaSelected = function(response) |
2803 |
14 Oct 14 |
nicklas |
136 |
{ |
2803 |
14 Oct 14 |
nicklas |
var rna = response.rna; |
2803 |
14 Oct 14 |
nicklas |
if (rna.length == 0) |
2803 |
14 Oct 14 |
nicklas |
139 |
{ |
2803 |
14 Oct 14 |
nicklas |
Doc.addClass('btnOk', 'disabled'); |
2981 |
25 Nov 14 |
nicklas |
Wizard.setFatalError('Could not find any unprocessed RNA at this time.'); |
2981 |
25 Nov 14 |
nicklas |
return; |
2803 |
14 Oct 14 |
nicklas |
143 |
} |
2803 |
14 Oct 14 |
nicklas |
144 |
|
2803 |
14 Oct 14 |
nicklas |
window.opener.SelectRna.rnaSelected(response); |
2803 |
14 Oct 14 |
nicklas |
window.close(); |
2803 |
14 Oct 14 |
nicklas |
147 |
} |
2803 |
14 Oct 14 |
nicklas |
148 |
|
2803 |
14 Oct 14 |
nicklas |
return autoselect; |
2803 |
14 Oct 14 |
nicklas |
150 |
}(); |
2803 |
14 Oct 14 |
nicklas |
151 |
|
2803 |
14 Oct 14 |
nicklas |
Doc.onLoad(AutoSelect.initPage); |
2803 |
14 Oct 14 |
nicklas |
153 |
|