2698 |
25 Sep 14 |
nicklas |
var RnaQcImport = function() |
2698 |
25 Sep 14 |
nicklas |
2 |
{ |
2698 |
25 Sep 14 |
nicklas |
var rnaqc = {}; |
3555 |
21 Oct 15 |
nicklas |
var bioplate; |
3555 |
21 Oct 15 |
nicklas |
var THIN_SPACE = ' '; |
2702 |
26 Sep 14 |
nicklas |
var debug = 0; |
2698 |
25 Sep 14 |
nicklas |
7 |
|
2698 |
25 Sep 14 |
nicklas |
// Page initialization |
2698 |
25 Sep 14 |
nicklas |
rnaqc.initPage = function() |
2698 |
25 Sep 14 |
nicklas |
10 |
{ |
2698 |
25 Sep 14 |
nicklas |
// Step 1 |
2698 |
25 Sep 14 |
nicklas |
Wizard.initFileSelectionField('csv'); |
2698 |
25 Sep 14 |
nicklas |
Wizard.initFileSelectionField('gxdstd'); |
2698 |
25 Sep 14 |
nicklas |
Wizard.initFileSelectionField('gxdhi'); |
2698 |
25 Sep 14 |
nicklas |
Wizard.initFileSelectionField('pdf'); |
2698 |
25 Sep 14 |
nicklas |
Events.addEventHandler('csv', 'change', rnaqc.preValidateCsvFile); |
2698 |
25 Sep 14 |
nicklas |
Events.addEventHandler('qcRunDate', 'change', Wizard.validateDate); |
2698 |
25 Sep 14 |
nicklas |
Events.addEventHandler('step-1', 'wizard-validate', rnaqc.validateStep1); |
2698 |
25 Sep 14 |
nicklas |
Events.addEventHandler('bioplate.name', 'click', rnaqc.bioplateOnClick); |
2698 |
25 Sep 14 |
nicklas |
20 |
|
3555 |
21 Oct 15 |
nicklas |
Events.addEventHandler('extraAliquot.Yes', 'click', rnaqc.extraAliquotOnClick); |
3555 |
21 Oct 15 |
nicklas |
Events.addEventHandler('extraAliquot.No', 'click', rnaqc.extraAliquotOnClick); |
3555 |
21 Oct 15 |
nicklas |
23 |
|
2698 |
25 Sep 14 |
nicklas |
// Navigation |
2698 |
25 Sep 14 |
nicklas |
Buttons.addClickHandler('gocancel', Wizard.cancelWizard); |
2698 |
25 Sep 14 |
nicklas |
Buttons.addClickHandler('gorestart', Wizard.restartWizard); |
2698 |
25 Sep 14 |
nicklas |
Buttons.addClickHandler('gonext', Wizard.goNextOnClick); |
2698 |
25 Sep 14 |
nicklas |
Buttons.addClickHandler('goregister', Wizard.goRegister); |
2698 |
25 Sep 14 |
nicklas |
29 |
|
2698 |
25 Sep 14 |
nicklas |
// Final registration |
2698 |
25 Sep 14 |
nicklas |
Events.addEventHandler('wizard', 'wizard-submit', rnaqc.submit); |
2698 |
25 Sep 14 |
nicklas |
32 |
|
2698 |
25 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2698 |
25 Sep 14 |
nicklas |
frm.csv.focus(); |
2698 |
25 Sep 14 |
nicklas |
Doc.show('step-1'); |
2698 |
25 Sep 14 |
nicklas |
Doc.show('goregister'); |
2698 |
25 Sep 14 |
nicklas |
37 |
} |
2698 |
25 Sep 14 |
nicklas |
38 |
|
6824 |
30 Aug 22 |
nicklas |
rnaqc.preValidateCsvFile = function() |
2698 |
25 Sep 14 |
nicklas |
40 |
{ |
2698 |
25 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2698 |
25 Sep 14 |
nicklas |
var csv = frm.csv.value; |
2698 |
25 Sep 14 |
nicklas |
if (!csv) return; |
2698 |
25 Sep 14 |
nicklas |
44 |
|
3555 |
21 Oct 15 |
nicklas |
Wizard.setInputStatus('bioplate'); |
3555 |
21 Oct 15 |
nicklas |
Doc.element('bioplate.name').innerHTML = '<i>(no file loaded)</i>'; |
3555 |
21 Oct 15 |
nicklas |
Doc.element('extraAliquot.No').click(); |
3555 |
21 Oct 15 |
nicklas |
Doc.element('extraAliquot.Yes').disabled = true; |
2698 |
25 Sep 14 |
nicklas |
Data.set('bioplate.name', 'item-id', 0); |
2698 |
25 Sep 14 |
nicklas |
Doc.removeClass('bioplate.name', 'link'); |
2698 |
25 Sep 14 |
nicklas |
Wizard.setInputStatus('csv', 'checking', 'Checking...'); |
2698 |
25 Sep 14 |
nicklas |
52 |
|
2698 |
25 Sep 14 |
nicklas |
var url = '../RnaQc.servlet?ID='+App.getSessionId(); |
2698 |
25 Sep 14 |
nicklas |
url += '&cmd=PreValidateCaliperResults&csv='+encodeURIComponent(csv); |
2698 |
25 Sep 14 |
nicklas |
Wizard.asyncJsonRequest(url, rnaqc.onCsvValidated, 'POST'); |
2698 |
25 Sep 14 |
nicklas |
56 |
} |
2698 |
25 Sep 14 |
nicklas |
57 |
|
2698 |
25 Sep 14 |
nicklas |
rnaqc.onCsvValidated = function(response) |
2698 |
25 Sep 14 |
nicklas |
59 |
{ |
2698 |
25 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2698 |
25 Sep 14 |
nicklas |
Wizard.setInputStatus('csv'); |
2698 |
25 Sep 14 |
nicklas |
Wizard.showFinalMessage(response.messages); |
3555 |
21 Oct 15 |
nicklas |
Wizard.setNoConfirmOnFirstStep(false); |
2698 |
25 Sep 14 |
nicklas |
64 |
|
3555 |
21 Oct 15 |
nicklas |
bioplate = null; |
2698 |
25 Sep 14 |
nicklas |
if (!response.valid) |
2698 |
25 Sep 14 |
nicklas |
67 |
{ |
2698 |
25 Sep 14 |
nicklas |
Wizard.setInputStatus('csv', 'invalid'); |
2698 |
25 Sep 14 |
nicklas |
Data.set('csv', 'valid', 0); |
2698 |
25 Sep 14 |
nicklas |
return; |
2698 |
25 Sep 14 |
nicklas |
71 |
} |
2698 |
25 Sep 14 |
nicklas |
72 |
|
2698 |
25 Sep 14 |
nicklas |
Wizard.setInputStatus('csv', response.warnings > 0 ? 'warning' : 'valid'); |
2698 |
25 Sep 14 |
nicklas |
Data.set('csv', 'valid', 1); |
2698 |
25 Sep 14 |
nicklas |
75 |
|
3555 |
21 Oct 15 |
nicklas |
bioplate = response.plate; |
2698 |
25 Sep 14 |
nicklas |
77 |
|
2698 |
25 Sep 14 |
nicklas |
Doc.element('bioplate.name').innerHTML = Strings.encodeTags(bioplate.name); |
2698 |
25 Sep 14 |
nicklas |
Data.set('bioplate.name', 'item-id', bioplate.id); |
2698 |
25 Sep 14 |
nicklas |
Doc.addClass('bioplate.name', 'link'); |
2836 |
20 Oct 14 |
nicklas |
frm.comments.value = bioplate.comments; |
3555 |
21 Oct 15 |
nicklas |
Doc.element('extraAliquot.Yes').disabled = false; |
2698 |
25 Sep 14 |
nicklas |
83 |
|
2698 |
25 Sep 14 |
nicklas |
Wizard.setInputStatus('bioplate', 'valid'); |
2698 |
25 Sep 14 |
nicklas |
if (bioplate.QCRunDate) |
2698 |
25 Sep 14 |
nicklas |
86 |
{ |
2698 |
25 Sep 14 |
nicklas |
frm.qcRunDate.value = bioplate.QCRunDate; |
2698 |
25 Sep 14 |
nicklas |
Events.sendChangeEvent('qcRunDate'); |
2698 |
25 Sep 14 |
nicklas |
Wizard.setInputStatus('bioplate', 'warning', 'Data has already been imported to this plate'); |
2698 |
25 Sep 14 |
nicklas |
90 |
} |
2698 |
25 Sep 14 |
nicklas |
else |
2698 |
25 Sep 14 |
nicklas |
92 |
{ |
2698 |
25 Sep 14 |
nicklas |
// Try to get date from the filename |
2698 |
25 Sep 14 |
nicklas |
var dates = frm.csv.value.match(/\d\d\d\d-\d\d-\d\d/); |
2698 |
25 Sep 14 |
nicklas |
if (dates && dates.length >= 1) |
2698 |
25 Sep 14 |
nicklas |
96 |
{ |
2698 |
25 Sep 14 |
nicklas |
var date = dates[0]; |
2698 |
25 Sep 14 |
nicklas |
frm.qcRunDate.value = date.substr(0, 4)+date.substr(5, 2)+date.substr(8, 2); |
2698 |
25 Sep 14 |
nicklas |
Events.sendChangeEvent('qcRunDate'); |
2698 |
25 Sep 14 |
nicklas |
100 |
} |
2698 |
25 Sep 14 |
nicklas |
101 |
} |
2698 |
25 Sep 14 |
nicklas |
102 |
|
2698 |
25 Sep 14 |
nicklas |
if (bioplate.QCOperator) |
2698 |
25 Sep 14 |
nicklas |
104 |
{ |
2698 |
25 Sep 14 |
nicklas |
frm.qcOperator.value = bioplate.QCOperator; |
2698 |
25 Sep 14 |
nicklas |
106 |
} |
2698 |
25 Sep 14 |
nicklas |
107 |
|
3555 |
21 Oct 15 |
nicklas |
var html = rnaqc.buildExtraAliquotPlate(bioplate); |
3555 |
21 Oct 15 |
nicklas |
Doc.element('extraAliquotPlate').innerHTML = html; |
3555 |
21 Oct 15 |
nicklas |
110 |
|
3555 |
21 Oct 15 |
nicklas |
var wells = Doc.element('extraAliquotPlate').getElementsByClassName('selectable'); |
3555 |
21 Oct 15 |
nicklas |
for (var wellNo = 0; wellNo < wells.length; wellNo++) |
3555 |
21 Oct 15 |
nicklas |
113 |
{ |
3555 |
21 Oct 15 |
nicklas |
Events.addEventHandler(wells[wellNo], 'click', rnaqc.wellOnClick); |
3555 |
21 Oct 15 |
nicklas |
Events.addEventHandler(wells[wellNo], 'change', rnaqc.extraVolumeOnChange); |
3555 |
21 Oct 15 |
nicklas |
116 |
} |
3555 |
21 Oct 15 |
nicklas |
117 |
|
2698 |
25 Sep 14 |
nicklas |
118 |
} |
2698 |
25 Sep 14 |
nicklas |
119 |
|
3555 |
21 Oct 15 |
nicklas |
rnaqc.wellOnClick = function(event) |
3555 |
21 Oct 15 |
nicklas |
121 |
{ |
3555 |
21 Oct 15 |
nicklas |
var wellId = Data.int(event.currentTarget, 'well-id'); |
3555 |
21 Oct 15 |
nicklas |
var well = rnaqc.getBioWellById(wellId); |
3555 |
21 Oct 15 |
nicklas |
124 |
|
3555 |
21 Oct 15 |
nicklas |
var url = 'rnaqc_extra_aliquot.jsp?ID='+App.getSessionId(); |
3555 |
21 Oct 15 |
nicklas |
url += '&well='+wellId; |
3555 |
21 Oct 15 |
nicklas |
url += '&rnaqc='+encodeURIComponent(well.bioMaterial.name); |
3555 |
21 Oct 15 |
nicklas |
Dialogs.openPopup(url, 'EditExtraAliquot', 450, 300); |
3555 |
21 Oct 15 |
nicklas |
129 |
} |
3555 |
21 Oct 15 |
nicklas |
130 |
|
3555 |
21 Oct 15 |
nicklas |
rnaqc.extraVolumeOnChange = function(event) |
3555 |
21 Oct 15 |
nicklas |
132 |
{ |
3555 |
21 Oct 15 |
nicklas |
var wellId = Data.int(event.currentTarget, 'well-id'); |
3555 |
21 Oct 15 |
nicklas |
var well = rnaqc.getBioWellById(wellId); |
3555 |
21 Oct 15 |
nicklas |
135 |
|
3555 |
21 Oct 15 |
nicklas |
Doc.addOrRemoveClass(event.currentTarget, 'has-extra', well.extraVolume); |
3555 |
21 Oct 15 |
nicklas |
event.currentTarget.innerHTML = well.extraVolume+THIN_SPACE+'µl'; |
3555 |
21 Oct 15 |
nicklas |
event.currentTarget.title = Strings.encodeTags(well.bioMaterial.name + '\n'+well.comment); |
3555 |
21 Oct 15 |
nicklas |
139 |
} |
3555 |
21 Oct 15 |
nicklas |
140 |
|
3555 |
21 Oct 15 |
nicklas |
rnaqc.getBioWellById = function(wellId) |
3555 |
21 Oct 15 |
nicklas |
142 |
{ |
3555 |
21 Oct 15 |
nicklas |
if (!bioplate) return null; |
3555 |
21 Oct 15 |
nicklas |
for (var wellNo = 0; wellNo < bioplate.bioWells.length; wellNo++) |
3555 |
21 Oct 15 |
nicklas |
145 |
{ |
3555 |
21 Oct 15 |
nicklas |
var well = bioplate.bioWells[wellNo]; |
3555 |
21 Oct 15 |
nicklas |
if (well.id == wellId) return well; |
3555 |
21 Oct 15 |
nicklas |
148 |
} |
3555 |
21 Oct 15 |
nicklas |
return null; |
3555 |
21 Oct 15 |
nicklas |
150 |
} |
3555 |
21 Oct 15 |
nicklas |
151 |
|
2698 |
25 Sep 14 |
nicklas |
rnaqc.bioplateOnClick = function() |
2698 |
25 Sep 14 |
nicklas |
153 |
{ |
2698 |
25 Sep 14 |
nicklas |
var plateId = Data.int('bioplate.name', 'item-id'); |
2698 |
25 Sep 14 |
nicklas |
if (!plateId) return; |
2698 |
25 Sep 14 |
nicklas |
Items.viewItem('BIOPLATE', plateId); |
2698 |
25 Sep 14 |
nicklas |
157 |
} |
2698 |
25 Sep 14 |
nicklas |
158 |
|
2698 |
25 Sep 14 |
nicklas |
rnaqc.validateStep1 = function(event) |
2698 |
25 Sep 14 |
nicklas |
160 |
{ |
2698 |
25 Sep 14 |
nicklas |
var valid = true; |
2698 |
25 Sep 14 |
nicklas |
162 |
|
2698 |
25 Sep 14 |
nicklas |
valid &= Wizard.isValid('csv'); |
2698 |
25 Sep 14 |
nicklas |
valid &= Wizard.isValid('qcRunDate'); |
2698 |
25 Sep 14 |
nicklas |
165 |
|
2698 |
25 Sep 14 |
nicklas |
if (!valid) event.preventDefault(); |
2698 |
25 Sep 14 |
nicklas |
167 |
} |
2698 |
25 Sep 14 |
nicklas |
168 |
|
3555 |
21 Oct 15 |
nicklas |
rnaqc.extraAliquotOnClick = function() |
3555 |
21 Oct 15 |
nicklas |
170 |
{ |
3555 |
21 Oct 15 |
nicklas |
Doc.showHide('extraAliquotPlateSection', Doc.element('extraAliquot.Yes').checked); |
3555 |
21 Oct 15 |
nicklas |
172 |
} |
3555 |
21 Oct 15 |
nicklas |
173 |
|
3555 |
21 Oct 15 |
nicklas |
rnaqc.buildExtraAliquotPlate = function(plate) |
3555 |
21 Oct 15 |
nicklas |
175 |
{ |
3555 |
21 Oct 15 |
nicklas |
var html = ''; |
3555 |
21 Oct 15 |
nicklas |
html += '<table class="plate">'; |
3555 |
21 Oct 15 |
nicklas |
html += '<tr class="header"><th></th>'; |
3555 |
21 Oct 15 |
nicklas |
for (var colNo = 0; colNo < plate.geometry.columns; colNo++) |
3555 |
21 Oct 15 |
nicklas |
180 |
{ |
3555 |
21 Oct 15 |
nicklas |
html += '<th>'+(colNo+1)+'</th>'; |
3555 |
21 Oct 15 |
nicklas |
182 |
} |
3555 |
21 Oct 15 |
nicklas |
html += '</tr>'; |
3555 |
21 Oct 15 |
nicklas |
var wells = plate.bioWells; |
3555 |
21 Oct 15 |
nicklas |
var wellNo = 0; |
3555 |
21 Oct 15 |
nicklas |
for (var rowNo = 0; rowNo < plate.geometry.rows; rowNo++) |
3555 |
21 Oct 15 |
nicklas |
187 |
{ |
3555 |
21 Oct 15 |
nicklas |
html += '<tr class="row-'+rowNo+'">'; |
3555 |
21 Oct 15 |
nicklas |
html += '<th>'+Reggie.wellToAlpha(rowNo)+'</th>'; |
3555 |
21 Oct 15 |
nicklas |
for (var colNo = 0; colNo < plate.geometry.columns; colNo++) |
3555 |
21 Oct 15 |
nicklas |
191 |
{ |
3555 |
21 Oct 15 |
nicklas |
var well = wells[wellNo]; |
3555 |
21 Oct 15 |
nicklas |
well.extraVolume = 0; |
3555 |
21 Oct 15 |
nicklas |
well.comment = ''; |
3555 |
21 Oct 15 |
nicklas |
195 |
|
3555 |
21 Oct 15 |
nicklas |
if (well.bioMaterial) |
3555 |
21 Oct 15 |
nicklas |
197 |
{ |
3555 |
21 Oct 15 |
nicklas |
html += '<td id="well-'+well.id+'"'; |
3555 |
21 Oct 15 |
nicklas |
html += ' class="well selectable col-'+colNo+'"'; |
3555 |
21 Oct 15 |
nicklas |
html += ' title="'+Strings.encodeTags(well.bioMaterial.name)+'" data-well-id="'+well.id+'"'; |
3555 |
21 Oct 15 |
nicklas |
html += '>0'+THIN_SPACE+'µl</td>'; |
3555 |
21 Oct 15 |
nicklas |
202 |
} |
3555 |
21 Oct 15 |
nicklas |
else |
3555 |
21 Oct 15 |
nicklas |
204 |
{ |
3555 |
21 Oct 15 |
nicklas |
html += '<td class="well empty col-'+colNo+'"></td>'; |
3555 |
21 Oct 15 |
nicklas |
206 |
} |
3555 |
21 Oct 15 |
nicklas |
wellNo++; |
3555 |
21 Oct 15 |
nicklas |
208 |
} |
3555 |
21 Oct 15 |
nicklas |
html += '</tr>'; |
3555 |
21 Oct 15 |
nicklas |
210 |
} |
3555 |
21 Oct 15 |
nicklas |
return html; |
3555 |
21 Oct 15 |
nicklas |
212 |
} |
3555 |
21 Oct 15 |
nicklas |
213 |
|
2698 |
25 Sep 14 |
nicklas |
rnaqc.submit = function() |
2698 |
25 Sep 14 |
nicklas |
215 |
{ |
2698 |
25 Sep 14 |
nicklas |
Doc.hide('wizard-status'); |
2698 |
25 Sep 14 |
nicklas |
var frm = document.forms['reggie']; |
2698 |
25 Sep 14 |
nicklas |
218 |
|
2698 |
25 Sep 14 |
nicklas |
var submitInfo = {}; |
2698 |
25 Sep 14 |
nicklas |
submitInfo.csv = frm.csv.value; |
2698 |
25 Sep 14 |
nicklas |
submitInfo.gxdStd = frm.gxdstd.value; |
2698 |
25 Sep 14 |
nicklas |
submitInfo.gxdHi = frm.gxdhi.value; |
2698 |
25 Sep 14 |
nicklas |
submitInfo.pdf = frm.pdf.value; |
2698 |
25 Sep 14 |
nicklas |
submitInfo.QCRunDate = frm.qcRunDate.value; |
2698 |
25 Sep 14 |
nicklas |
submitInfo.QCOperator = frm.qcOperator.value; |
2836 |
20 Oct 14 |
nicklas |
submitInfo.comments = frm.comments.value; |
3555 |
21 Oct 15 |
nicklas |
var extra = []; |
3555 |
21 Oct 15 |
nicklas |
submitInfo.extraAliquots = extra; |
3555 |
21 Oct 15 |
nicklas |
229 |
|
3555 |
21 Oct 15 |
nicklas |
if (Doc.element('extraAliquot.Yes').checked) |
3555 |
21 Oct 15 |
nicklas |
231 |
{ |
3555 |
21 Oct 15 |
nicklas |
for (var wellNo = 0; wellNo < bioplate.bioWells.length; wellNo++) |
3555 |
21 Oct 15 |
nicklas |
233 |
{ |
3555 |
21 Oct 15 |
nicklas |
var well = bioplate.bioWells[wellNo]; |
3555 |
21 Oct 15 |
nicklas |
if (well.extraVolume > 0) |
3555 |
21 Oct 15 |
nicklas |
236 |
{ |
3555 |
21 Oct 15 |
nicklas |
var tmp = {}; |
3555 |
21 Oct 15 |
nicklas |
tmp.id = well.bioMaterial.id; |
3555 |
21 Oct 15 |
nicklas |
tmp.volume = well.extraVolume; |
3555 |
21 Oct 15 |
nicklas |
tmp.comment = well.comment; |
3555 |
21 Oct 15 |
nicklas |
extra[extra.length] = tmp; |
3555 |
21 Oct 15 |
nicklas |
242 |
} |
3555 |
21 Oct 15 |
nicklas |
243 |
} |
3555 |
21 Oct 15 |
nicklas |
244 |
} |
3555 |
21 Oct 15 |
nicklas |
245 |
|
2698 |
25 Sep 14 |
nicklas |
var url = '../RnaQc.servlet?ID='+App.getSessionId(); |
2698 |
25 Sep 14 |
nicklas |
url += '&cmd=ImportCaliperResults'; |
2698 |
25 Sep 14 |
nicklas |
248 |
|
2698 |
25 Sep 14 |
nicklas |
Wizard.showLoadingAnimation('Importing RQS values...'); |
2698 |
25 Sep 14 |
nicklas |
Wizard.asyncJsonRequest(url, rnaqc.submissionResults, 'POST', JSON.stringify(submitInfo)); |
2698 |
25 Sep 14 |
nicklas |
251 |
} |
2698 |
25 Sep 14 |
nicklas |
252 |
|
2698 |
25 Sep 14 |
nicklas |
rnaqc.submissionResults = function(response) |
2698 |
25 Sep 14 |
nicklas |
254 |
{ |
2698 |
25 Sep 14 |
nicklas |
Wizard.showFinalMessage(response.messages); |
2698 |
25 Sep 14 |
nicklas |
Doc.show('gorestart'); |
2698 |
25 Sep 14 |
nicklas |
257 |
} |
2698 |
25 Sep 14 |
nicklas |
258 |
|
2698 |
25 Sep 14 |
nicklas |
return rnaqc; |
2698 |
25 Sep 14 |
nicklas |
260 |
}(); |
2698 |
25 Sep 14 |
nicklas |
261 |
|
2698 |
25 Sep 14 |
nicklas |
Doc.onLoad(RnaQcImport.initPage); |
2698 |
25 Sep 14 |
nicklas |
263 |
|