extensions/net.sf.basedb.reggie/trunk/resources/sampleproc/rnaqc_plate_import.js

Code
Comments
Other
Rev Date Author Line
2698 25 Sep 14 nicklas 1 var RnaQcImport = function()
2698 25 Sep 14 nicklas 2 {
2698 25 Sep 14 nicklas 3   var rnaqc = {};
3555 21 Oct 15 nicklas 4   var bioplate;
3555 21 Oct 15 nicklas 5   var THIN_SPACE = ' ';
2702 26 Sep 14 nicklas 6   var debug = 0;
2698 25 Sep 14 nicklas 7   
2698 25 Sep 14 nicklas 8   // Page initialization
2698 25 Sep 14 nicklas 9   rnaqc.initPage = function()
2698 25 Sep 14 nicklas 10   {
2698 25 Sep 14 nicklas 11     // Step 1
2698 25 Sep 14 nicklas 12     Wizard.initFileSelectionField('csv');
2698 25 Sep 14 nicklas 13     Wizard.initFileSelectionField('gxdstd');
2698 25 Sep 14 nicklas 14     Wizard.initFileSelectionField('gxdhi');
2698 25 Sep 14 nicklas 15     Wizard.initFileSelectionField('pdf');
2698 25 Sep 14 nicklas 16     Events.addEventHandler('csv', 'change', rnaqc.preValidateCsvFile);
2698 25 Sep 14 nicklas 17     Events.addEventHandler('qcRunDate', 'change', Wizard.validateDate);
2698 25 Sep 14 nicklas 18     Events.addEventHandler('step-1', 'wizard-validate', rnaqc.validateStep1);
2698 25 Sep 14 nicklas 19     Events.addEventHandler('bioplate.name', 'click', rnaqc.bioplateOnClick);
2698 25 Sep 14 nicklas 20
3555 21 Oct 15 nicklas 21     Events.addEventHandler('extraAliquot.Yes', 'click', rnaqc.extraAliquotOnClick);
3555 21 Oct 15 nicklas 22     Events.addEventHandler('extraAliquot.No', 'click', rnaqc.extraAliquotOnClick);
3555 21 Oct 15 nicklas 23     
2698 25 Sep 14 nicklas 24     // Navigation
2698 25 Sep 14 nicklas 25     Buttons.addClickHandler('gocancel', Wizard.cancelWizard);
2698 25 Sep 14 nicklas 26     Buttons.addClickHandler('gorestart', Wizard.restartWizard);
2698 25 Sep 14 nicklas 27     Buttons.addClickHandler('gonext', Wizard.goNextOnClick);
2698 25 Sep 14 nicklas 28     Buttons.addClickHandler('goregister', Wizard.goRegister);
2698 25 Sep 14 nicklas 29
2698 25 Sep 14 nicklas 30     // Final registration
2698 25 Sep 14 nicklas 31     Events.addEventHandler('wizard', 'wizard-submit', rnaqc.submit);
2698 25 Sep 14 nicklas 32
2698 25 Sep 14 nicklas 33     var frm = document.forms['reggie'];
2698 25 Sep 14 nicklas 34     frm.csv.focus();
2698 25 Sep 14 nicklas 35     Doc.show('step-1');
2698 25 Sep 14 nicklas 36     Doc.show('goregister');
2698 25 Sep 14 nicklas 37   }
2698 25 Sep 14 nicklas 38   
6824 30 Aug 22 nicklas 39   rnaqc.preValidateCsvFile = function()
2698 25 Sep 14 nicklas 40   {
2698 25 Sep 14 nicklas 41     var frm = document.forms['reggie'];
2698 25 Sep 14 nicklas 42     var csv = frm.csv.value;
2698 25 Sep 14 nicklas 43     if (!csv) return;
2698 25 Sep 14 nicklas 44     
3555 21 Oct 15 nicklas 45     Wizard.setInputStatus('bioplate');
3555 21 Oct 15 nicklas 46     Doc.element('bioplate.name').innerHTML = '<i>(no file loaded)</i>';
3555 21 Oct 15 nicklas 47     Doc.element('extraAliquot.No').click();
3555 21 Oct 15 nicklas 48     Doc.element('extraAliquot.Yes').disabled = true;
2698 25 Sep 14 nicklas 49     Data.set('bioplate.name', 'item-id', 0);
2698 25 Sep 14 nicklas 50     Doc.removeClass('bioplate.name', 'link');
2698 25 Sep 14 nicklas 51     Wizard.setInputStatus('csv', 'checking', 'Checking...');
2698 25 Sep 14 nicklas 52     
2698 25 Sep 14 nicklas 53     var url = '../RnaQc.servlet?ID='+App.getSessionId();
2698 25 Sep 14 nicklas 54     url += '&cmd=PreValidateCaliperResults&csv='+encodeURIComponent(csv);
2698 25 Sep 14 nicklas 55     Wizard.asyncJsonRequest(url, rnaqc.onCsvValidated, 'POST');
2698 25 Sep 14 nicklas 56   }
2698 25 Sep 14 nicklas 57
2698 25 Sep 14 nicklas 58   rnaqc.onCsvValidated = function(response)
2698 25 Sep 14 nicklas 59   {
2698 25 Sep 14 nicklas 60     var frm = document.forms['reggie'];
2698 25 Sep 14 nicklas 61     Wizard.setInputStatus('csv');
2698 25 Sep 14 nicklas 62     Wizard.showFinalMessage(response.messages);
3555 21 Oct 15 nicklas 63     Wizard.setNoConfirmOnFirstStep(false);
2698 25 Sep 14 nicklas 64
3555 21 Oct 15 nicklas 65     bioplate = null;
2698 25 Sep 14 nicklas 66     if (!response.valid)
2698 25 Sep 14 nicklas 67     {
2698 25 Sep 14 nicklas 68       Wizard.setInputStatus('csv', 'invalid');
2698 25 Sep 14 nicklas 69       Data.set('csv', 'valid', 0);
2698 25 Sep 14 nicklas 70       return;
2698 25 Sep 14 nicklas 71     }
2698 25 Sep 14 nicklas 72
2698 25 Sep 14 nicklas 73     Wizard.setInputStatus('csv', response.warnings > 0 ? 'warning' : 'valid');
2698 25 Sep 14 nicklas 74     Data.set('csv', 'valid', 1);
2698 25 Sep 14 nicklas 75     
3555 21 Oct 15 nicklas 76     bioplate = response.plate;
2698 25 Sep 14 nicklas 77     
2698 25 Sep 14 nicklas 78     Doc.element('bioplate.name').innerHTML = Strings.encodeTags(bioplate.name);
2698 25 Sep 14 nicklas 79     Data.set('bioplate.name', 'item-id', bioplate.id);
2698 25 Sep 14 nicklas 80     Doc.addClass('bioplate.name', 'link');
2836 20 Oct 14 nicklas 81     frm.comments.value = bioplate.comments;
3555 21 Oct 15 nicklas 82     Doc.element('extraAliquot.Yes').disabled = false;
2698 25 Sep 14 nicklas 83     
2698 25 Sep 14 nicklas 84     Wizard.setInputStatus('bioplate', 'valid');
2698 25 Sep 14 nicklas 85     if (bioplate.QCRunDate)
2698 25 Sep 14 nicklas 86     {
2698 25 Sep 14 nicklas 87       frm.qcRunDate.value = bioplate.QCRunDate;
2698 25 Sep 14 nicklas 88       Events.sendChangeEvent('qcRunDate');
2698 25 Sep 14 nicklas 89       Wizard.setInputStatus('bioplate', 'warning', 'Data has already been imported to this plate');
2698 25 Sep 14 nicklas 90     }
2698 25 Sep 14 nicklas 91     else
2698 25 Sep 14 nicklas 92     {
2698 25 Sep 14 nicklas 93       // Try to get date from the filename
2698 25 Sep 14 nicklas 94       var dates = frm.csv.value.match(/\d\d\d\d-\d\d-\d\d/);
2698 25 Sep 14 nicklas 95       if (dates && dates.length >= 1)
2698 25 Sep 14 nicklas 96       {
2698 25 Sep 14 nicklas 97         var date = dates[0];
2698 25 Sep 14 nicklas 98         frm.qcRunDate.value = date.substr(0, 4)+date.substr(5, 2)+date.substr(8, 2);
2698 25 Sep 14 nicklas 99         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 103     if (bioplate.QCOperator)
2698 25 Sep 14 nicklas 104     {
2698 25 Sep 14 nicklas 105       frm.qcOperator.value = bioplate.QCOperator;  
2698 25 Sep 14 nicklas 106     }
2698 25 Sep 14 nicklas 107     
3555 21 Oct 15 nicklas 108     var html = rnaqc.buildExtraAliquotPlate(bioplate);
3555 21 Oct 15 nicklas 109     Doc.element('extraAliquotPlate').innerHTML = html;
3555 21 Oct 15 nicklas 110     
3555 21 Oct 15 nicklas 111     var wells = Doc.element('extraAliquotPlate').getElementsByClassName('selectable');
3555 21 Oct 15 nicklas 112     for (var wellNo = 0; wellNo < wells.length; wellNo++)
3555 21 Oct 15 nicklas 113     {
3555 21 Oct 15 nicklas 114       Events.addEventHandler(wells[wellNo], 'click', rnaqc.wellOnClick);
3555 21 Oct 15 nicklas 115       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 120   rnaqc.wellOnClick = function(event)
3555 21 Oct 15 nicklas 121   {
3555 21 Oct 15 nicklas 122     var wellId = Data.int(event.currentTarget, 'well-id');
3555 21 Oct 15 nicklas 123     var well = rnaqc.getBioWellById(wellId);
3555 21 Oct 15 nicklas 124     
3555 21 Oct 15 nicklas 125     var url = 'rnaqc_extra_aliquot.jsp?ID='+App.getSessionId();
3555 21 Oct 15 nicklas 126     url += '&well='+wellId;
3555 21 Oct 15 nicklas 127     url += '&rnaqc='+encodeURIComponent(well.bioMaterial.name);
3555 21 Oct 15 nicklas 128     Dialogs.openPopup(url, 'EditExtraAliquot', 450, 300);  
3555 21 Oct 15 nicklas 129   }
3555 21 Oct 15 nicklas 130   
3555 21 Oct 15 nicklas 131   rnaqc.extraVolumeOnChange = function(event)
3555 21 Oct 15 nicklas 132   {
3555 21 Oct 15 nicklas 133     var wellId = Data.int(event.currentTarget, 'well-id');
3555 21 Oct 15 nicklas 134     var well = rnaqc.getBioWellById(wellId);
3555 21 Oct 15 nicklas 135     
3555 21 Oct 15 nicklas 136     Doc.addOrRemoveClass(event.currentTarget, 'has-extra', well.extraVolume);
3555 21 Oct 15 nicklas 137     event.currentTarget.innerHTML = well.extraVolume+THIN_SPACE+'µl';
3555 21 Oct 15 nicklas 138     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 141   rnaqc.getBioWellById = function(wellId)
3555 21 Oct 15 nicklas 142   {
3555 21 Oct 15 nicklas 143     if (!bioplate) return null;
3555 21 Oct 15 nicklas 144     for (var wellNo = 0; wellNo < bioplate.bioWells.length; wellNo++)
3555 21 Oct 15 nicklas 145     {
3555 21 Oct 15 nicklas 146       var well = bioplate.bioWells[wellNo];
3555 21 Oct 15 nicklas 147       if (well.id == wellId) return well;
3555 21 Oct 15 nicklas 148     }
3555 21 Oct 15 nicklas 149     return null;
3555 21 Oct 15 nicklas 150   }
3555 21 Oct 15 nicklas 151   
2698 25 Sep 14 nicklas 152   rnaqc.bioplateOnClick = function()
2698 25 Sep 14 nicklas 153   {
2698 25 Sep 14 nicklas 154     var plateId = Data.int('bioplate.name', 'item-id');
2698 25 Sep 14 nicklas 155     if (!plateId) return;
2698 25 Sep 14 nicklas 156     Items.viewItem('BIOPLATE', plateId);
2698 25 Sep 14 nicklas 157   }
2698 25 Sep 14 nicklas 158   
2698 25 Sep 14 nicklas 159   rnaqc.validateStep1 = function(event)
2698 25 Sep 14 nicklas 160   {
2698 25 Sep 14 nicklas 161     var valid = true;
2698 25 Sep 14 nicklas 162     
2698 25 Sep 14 nicklas 163     valid &= Wizard.isValid('csv');
2698 25 Sep 14 nicklas 164     valid &= Wizard.isValid('qcRunDate');
2698 25 Sep 14 nicklas 165
2698 25 Sep 14 nicklas 166     if (!valid) event.preventDefault();
2698 25 Sep 14 nicklas 167   }
2698 25 Sep 14 nicklas 168
3555 21 Oct 15 nicklas 169   rnaqc.extraAliquotOnClick = function()
3555 21 Oct 15 nicklas 170   {
3555 21 Oct 15 nicklas 171     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 174   rnaqc.buildExtraAliquotPlate = function(plate)
3555 21 Oct 15 nicklas 175   {
3555 21 Oct 15 nicklas 176     var html = '';
3555 21 Oct 15 nicklas 177     html += '<table class="plate">';
3555 21 Oct 15 nicklas 178     html += '<tr class="header"><th></th>';
3555 21 Oct 15 nicklas 179     for (var colNo = 0; colNo < plate.geometry.columns; colNo++)
3555 21 Oct 15 nicklas 180     {
3555 21 Oct 15 nicklas 181       html += '<th>'+(colNo+1)+'</th>';
3555 21 Oct 15 nicklas 182     }
3555 21 Oct 15 nicklas 183     html += '</tr>';
3555 21 Oct 15 nicklas 184     var wells = plate.bioWells;
3555 21 Oct 15 nicklas 185     var wellNo = 0;
3555 21 Oct 15 nicklas 186     for (var rowNo = 0; rowNo < plate.geometry.rows; rowNo++)
3555 21 Oct 15 nicklas 187     {
3555 21 Oct 15 nicklas 188       html += '<tr class="row-'+rowNo+'">';
3555 21 Oct 15 nicklas 189       html += '<th>'+Reggie.wellToAlpha(rowNo)+'</th>';
3555 21 Oct 15 nicklas 190       for (var colNo = 0; colNo < plate.geometry.columns; colNo++)
3555 21 Oct 15 nicklas 191       {
3555 21 Oct 15 nicklas 192         var well = wells[wellNo];
3555 21 Oct 15 nicklas 193         well.extraVolume = 0;
3555 21 Oct 15 nicklas 194         well.comment = '';
3555 21 Oct 15 nicklas 195
3555 21 Oct 15 nicklas 196         if (well.bioMaterial)
3555 21 Oct 15 nicklas 197         {
3555 21 Oct 15 nicklas 198           html += '<td id="well-'+well.id+'"';
3555 21 Oct 15 nicklas 199           html += ' class="well selectable col-'+colNo+'"';
3555 21 Oct 15 nicklas 200           html += ' title="'+Strings.encodeTags(well.bioMaterial.name)+'" data-well-id="'+well.id+'"';
3555 21 Oct 15 nicklas 201           html += '>0'+THIN_SPACE+'µl</td>';
3555 21 Oct 15 nicklas 202         }
3555 21 Oct 15 nicklas 203         else
3555 21 Oct 15 nicklas 204         {
3555 21 Oct 15 nicklas 205           html += '<td class="well empty col-'+colNo+'"></td>';
3555 21 Oct 15 nicklas 206         }
3555 21 Oct 15 nicklas 207         wellNo++;
3555 21 Oct 15 nicklas 208       }
3555 21 Oct 15 nicklas 209       html += '</tr>';
3555 21 Oct 15 nicklas 210     }
3555 21 Oct 15 nicklas 211     return html;
3555 21 Oct 15 nicklas 212   }
3555 21 Oct 15 nicklas 213   
2698 25 Sep 14 nicklas 214   rnaqc.submit = function()
2698 25 Sep 14 nicklas 215   {
2698 25 Sep 14 nicklas 216     Doc.hide('wizard-status');
2698 25 Sep 14 nicklas 217     var frm = document.forms['reggie'];
2698 25 Sep 14 nicklas 218       
2698 25 Sep 14 nicklas 219     var submitInfo = {};
2698 25 Sep 14 nicklas 220     submitInfo.csv = frm.csv.value;
2698 25 Sep 14 nicklas 221     submitInfo.gxdStd = frm.gxdstd.value;
2698 25 Sep 14 nicklas 222     submitInfo.gxdHi = frm.gxdhi.value;
2698 25 Sep 14 nicklas 223     submitInfo.pdf = frm.pdf.value;
2698 25 Sep 14 nicklas 224     submitInfo.QCRunDate = frm.qcRunDate.value;
2698 25 Sep 14 nicklas 225     submitInfo.QCOperator = frm.qcOperator.value;
2836 20 Oct 14 nicklas 226     submitInfo.comments = frm.comments.value;
3555 21 Oct 15 nicklas 227     var extra = [];
3555 21 Oct 15 nicklas 228     submitInfo.extraAliquots = extra;
3555 21 Oct 15 nicklas 229     
3555 21 Oct 15 nicklas 230     if (Doc.element('extraAliquot.Yes').checked)
3555 21 Oct 15 nicklas 231     {
3555 21 Oct 15 nicklas 232       for (var wellNo = 0; wellNo < bioplate.bioWells.length; wellNo++)
3555 21 Oct 15 nicklas 233       {
3555 21 Oct 15 nicklas 234         var well = bioplate.bioWells[wellNo];
3555 21 Oct 15 nicklas 235         if (well.extraVolume > 0)
3555 21 Oct 15 nicklas 236         {
3555 21 Oct 15 nicklas 237           var tmp = {};
3555 21 Oct 15 nicklas 238           tmp.id = well.bioMaterial.id;
3555 21 Oct 15 nicklas 239           tmp.volume = well.extraVolume;
3555 21 Oct 15 nicklas 240           tmp.comment = well.comment;
3555 21 Oct 15 nicklas 241           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 246     var url = '../RnaQc.servlet?ID='+App.getSessionId();
2698 25 Sep 14 nicklas 247     url += '&cmd=ImportCaliperResults';
2698 25 Sep 14 nicklas 248       
2698 25 Sep 14 nicklas 249     Wizard.showLoadingAnimation('Importing RQS values...');
2698 25 Sep 14 nicklas 250     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 253   rnaqc.submissionResults = function(response)
2698 25 Sep 14 nicklas 254   {
2698 25 Sep 14 nicklas 255     Wizard.showFinalMessage(response.messages);
2698 25 Sep 14 nicklas 256     Doc.show('gorestart');
2698 25 Sep 14 nicklas 257   }
2698 25 Sep 14 nicklas 258   
2698 25 Sep 14 nicklas 259   return rnaqc;
2698 25 Sep 14 nicklas 260 }();
2698 25 Sep 14 nicklas 261
2698 25 Sep 14 nicklas 262 Doc.onLoad(RnaQcImport.initPage);
2698 25 Sep 14 nicklas 263