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

Code
Comments
Other
Rev Date Author Line
2784 10 Oct 14 nicklas 1 var Histology = function()
2784 10 Oct 14 nicklas 2 {
2784 10 Oct 14 nicklas 3   var histology = {};
2853 23 Oct 14 nicklas 4   var debug = 0;
2784 10 Oct 14 nicklas 5   
2784 10 Oct 14 nicklas 6   var nameIsValid = true;
2784 10 Oct 14 nicklas 7   var histologyIsValid = false;
2784 10 Oct 14 nicklas 8   var subtypeHistology = null;
2784 10 Oct 14 nicklas 9   
2784 10 Oct 14 nicklas 10   // Page initialization
2784 10 Oct 14 nicklas 11   histology.initPage = function()
2784 10 Oct 14 nicklas 12   {
2784 10 Oct 14 nicklas 13     // Step 1
2784 10 Oct 14 nicklas 14     Events.addEventHandler('step-1', 'wizard-validate', histology.validateStep1);
2784 10 Oct 14 nicklas 15     Events.addEventHandler('name', 'change', histology.nameOnChange);
2784 10 Oct 14 nicklas 16     Events.addEventHandler('histology', 'change', histology.histologyOnChange);
2784 10 Oct 14 nicklas 17     Buttons.addClickHandler('btnSelectHistologyItems', histology.selectHistologyItems);
2784 10 Oct 14 nicklas 18     Events.addEventHandler('histology', 'base-selected', histology.onHistologySelected);
2784 10 Oct 14 nicklas 19     
2784 10 Oct 14 nicklas 20     // Navigation
2784 10 Oct 14 nicklas 21     Buttons.addClickHandler('gocancel', histology.cancelWizard);
2784 10 Oct 14 nicklas 22     Buttons.addClickHandler('gorestart', Wizard.restartWizard);
2784 10 Oct 14 nicklas 23     Buttons.addClickHandler('gonext', Wizard.goNextOnClick);
2784 10 Oct 14 nicklas 24     Buttons.addClickHandler('goregister', Wizard.goRegister);
2784 10 Oct 14 nicklas 25     Buttons.addClickHandler('goprotocol', histology.showProtocol);
2784 10 Oct 14 nicklas 26
2784 10 Oct 14 nicklas 27     // Final registration
2784 10 Oct 14 nicklas 28     Events.addEventHandler('wizard', 'wizard-submit', histology.submit);
2784 10 Oct 14 nicklas 29     
2784 10 Oct 14 nicklas 30     var url = '../Histology.servlet?ID='+App.getSessionId();
2784 10 Oct 14 nicklas 31     url += '&cmd=GetUnembeddedHistologyItems';
2784 10 Oct 14 nicklas 32     Wizard.showLoadingAnimation('Loading unembedded histology items...');
2784 10 Oct 14 nicklas 33     Wizard.asyncJsonRequest(url, histology.histologyItemsLoaded);
2784 10 Oct 14 nicklas 34   }
2784 10 Oct 14 nicklas 35   
2784 10 Oct 14 nicklas 36   histology.histologyItemsLoaded = function(response)
2784 10 Oct 14 nicklas 37   {
2784 10 Oct 14 nicklas 38     var frm = document.forms['reggie'];
2784 10 Oct 14 nicklas 39     var items = response.histology;
2784 10 Oct 14 nicklas 40     
2784 10 Oct 14 nicklas 41     var histologyList = frm.histology;
2784 10 Oct 14 nicklas 42     if (items.length > 0)
2784 10 Oct 14 nicklas 43     {
2784 10 Oct 14 nicklas 44       for (var i=0; i < items.length; i++)
2784 10 Oct 14 nicklas 45       {
2784 10 Oct 14 nicklas 46         var his = items[i];
2784 10 Oct 14 nicklas 47         var name = (i+1) + ': ' + his.name;
2784 10 Oct 14 nicklas 48         if (his.bioWell)
2784 10 Oct 14 nicklas 49         {
2784 10 Oct 14 nicklas 50           name += ' -- ' + his.bioWell.bioPlate.name + ' (' + his.bioWell.location+')';
2784 10 Oct 14 nicklas 51         }
2784 10 Oct 14 nicklas 52         var option = new Option(name, his.id);
2784 10 Oct 14 nicklas 53         option.histology = his;
2784 10 Oct 14 nicklas 54         histologyList.options[histologyList.length] = option;
2784 10 Oct 14 nicklas 55       }
2784 10 Oct 14 nicklas 56       histology.histologyOnChange();
2784 10 Oct 14 nicklas 57     }
2784 10 Oct 14 nicklas 58     else
2784 10 Oct 14 nicklas 59     {  
2784 10 Oct 14 nicklas 60       Wizard.setInputStatus('histology', 'invalid', 'No Histology items available for processing.');
2784 10 Oct 14 nicklas 61     }
2784 10 Oct 14 nicklas 62     
2784 10 Oct 14 nicklas 63     Doc.show('goregister');
2784 10 Oct 14 nicklas 64     Doc.show('gocancel');
2784 10 Oct 14 nicklas 65     Doc.show('step-1');
2784 10 Oct 14 nicklas 66   }
2784 10 Oct 14 nicklas 67
2784 10 Oct 14 nicklas 68   histology.nameOnChange = function()
2784 10 Oct 14 nicklas 69   {
2784 10 Oct 14 nicklas 70     var frm = document.forms['reggie'];
2784 10 Oct 14 nicklas 71     var name = frm.name.value;
2784 10 Oct 14 nicklas 72     
2784 10 Oct 14 nicklas 73     nameIsValid = false;
2784 10 Oct 14 nicklas 74     if (name == '')
2784 10 Oct 14 nicklas 75     {
2784 10 Oct 14 nicklas 76       Wizard.setInputStatus('name', 'invalid', 'Missing');
2784 10 Oct 14 nicklas 77       return;
2784 10 Oct 14 nicklas 78     }
2784 10 Oct 14 nicklas 79     Wizard.setInputStatus('name', 'valid');
2784 10 Oct 14 nicklas 80     nameIsValid = true;
2784 10 Oct 14 nicklas 81   }
2784 10 Oct 14 nicklas 82   
2784 10 Oct 14 nicklas 83   histology.histologyOnChange = function()
2784 10 Oct 14 nicklas 84   {
2784 10 Oct 14 nicklas 85     histologyIsValid = false;
2784 10 Oct 14 nicklas 86     
2784 10 Oct 14 nicklas 87     var frm = document.forms['reggie'];
2784 10 Oct 14 nicklas 88     var histologyList = frm.histology;
2784 10 Oct 14 nicklas 89     
2784 10 Oct 14 nicklas 90     var numSelected = 0;
2784 10 Oct 14 nicklas 91     for (var i = 0; i < histologyList.length; i++)
2784 10 Oct 14 nicklas 92     {
2784 10 Oct 14 nicklas 93       if (histologyList[i].selected) numSelected++;
2784 10 Oct 14 nicklas 94     }
2784 10 Oct 14 nicklas 95
2784 10 Oct 14 nicklas 96     Doc.element('numSelected').innerHTML = numSelected + ' selected';
2784 10 Oct 14 nicklas 97     
2784 10 Oct 14 nicklas 98     if (numSelected == 0 || numSelected % 5 != 0)
2784 10 Oct 14 nicklas 99     {
2784 10 Oct 14 nicklas 100       Wizard.setInputStatus('histology', 'invalid', 'Must select items in blocks of 5.');
2784 10 Oct 14 nicklas 101       return;
2784 10 Oct 14 nicklas 102     }
2784 10 Oct 14 nicklas 103     
2784 10 Oct 14 nicklas 104     histologyIsValid = true;
2784 10 Oct 14 nicklas 105     Wizard.setInputStatus('histology', 'valid');
2784 10 Oct 14 nicklas 106   }
2784 10 Oct 14 nicklas 107
2784 10 Oct 14 nicklas 108   histology.selectHistologyItems = function()
2784 10 Oct 14 nicklas 109   {
2784 10 Oct 14 nicklas 110     var frm = document.forms['reggie'];
2784 10 Oct 14 nicklas 111     if (frm.histology.disabled) return;
2784 10 Oct 14 nicklas 112     
2784 10 Oct 14 nicklas 113     if (subtypeHistology == null)
2784 10 Oct 14 nicklas 114     {
2784 10 Oct 14 nicklas 115       subtypeHistology = Reggie.getSubtypeInfo('HISTOLOGY');
2784 10 Oct 14 nicklas 116     }
2784 10 Oct 14 nicklas 117     
2784 10 Oct 14 nicklas 118     var url = '&resetTemporary=1';
2784 10 Oct 14 nicklas 119     url += '&tmpfilter:INT:itemSubtype='+subtypeHistology.id;
2784 10 Oct 14 nicklas 120     url += '&tmpfilter:DATE:creationEvent.eventDate='+encodeURIComponent('=');
2784 10 Oct 14 nicklas 121     Dialogs.selectItem('SAMPLE', 'histology', 1, url);
2784 10 Oct 14 nicklas 122   }
2784 10 Oct 14 nicklas 123
2784 10 Oct 14 nicklas 124   histology.onHistologySelected = function(event)
2784 10 Oct 14 nicklas 125   {
2784 10 Oct 14 nicklas 126     var his = event.detail;
2784 10 Oct 14 nicklas 127     
2784 10 Oct 14 nicklas 128     var frm = document.forms['reggie'];
2784 10 Oct 14 nicklas 129     var histologyList = frm.histology;
2808 15 Oct 14 nicklas 130     var isNew = true;
2784 10 Oct 14 nicklas 131     for (var i = 0; i < histologyList.length; i++)
2784 10 Oct 14 nicklas 132     {
2784 10 Oct 14 nicklas 133       if (histologyList[i].value == his.id)
2784 10 Oct 14 nicklas 134       {
2784 10 Oct 14 nicklas 135         histologyList[i].selected = true;
2808 15 Oct 14 nicklas 136         isNew = false;
2784 10 Oct 14 nicklas 137       }
2784 10 Oct 14 nicklas 138     }
2784 10 Oct 14 nicklas 139
2808 15 Oct 14 nicklas 140     if (isNew)
2808 15 Oct 14 nicklas 141     {
2808 15 Oct 14 nicklas 142       var option = new Option(his.name, his.id, true, true);
2808 15 Oct 14 nicklas 143       histologyList[histologyList.length] = option;
2808 15 Oct 14 nicklas 144     }
2808 15 Oct 14 nicklas 145     
2808 15 Oct 14 nicklas 146     if (event.detail.remaining == 0)
2808 15 Oct 14 nicklas 147     {
2808 15 Oct 14 nicklas 148       histology.histologyOnChange();
2808 15 Oct 14 nicklas 149     }
2784 10 Oct 14 nicklas 150   }
2784 10 Oct 14 nicklas 151   
2784 10 Oct 14 nicklas 152   histology.validateStep1 = function(event)
2784 10 Oct 14 nicklas 153   {
2784 10 Oct 14 nicklas 154     var valid = nameIsValid;
2784 10 Oct 14 nicklas 155     valid &= histologyIsValid;
2784 10 Oct 14 nicklas 156     
2784 10 Oct 14 nicklas 157     if (!valid) event.preventDefault();
2784 10 Oct 14 nicklas 158   }
2784 10 Oct 14 nicklas 159
2784 10 Oct 14 nicklas 160   histology.submit = function()
2784 10 Oct 14 nicklas 161   {
2784 10 Oct 14 nicklas 162     var frm = document.forms['reggie'];
2784 10 Oct 14 nicklas 163
2784 10 Oct 14 nicklas 164     var submitInfo = {};
2784 10 Oct 14 nicklas 165     submitInfo.name = frm.name.value;
2784 10 Oct 14 nicklas 166     submitInfo.comments = frm.comments.value;
2784 10 Oct 14 nicklas 167     
2784 10 Oct 14 nicklas 168     var items = [];
2784 10 Oct 14 nicklas 169     for (var i = 0; i < frm.histology.length; i++)
2784 10 Oct 14 nicklas 170     {
2784 10 Oct 14 nicklas 171       if (frm.histology[i].selected) 
2784 10 Oct 14 nicklas 172       {
2784 10 Oct 14 nicklas 173         items[items.length] = parseInt(frm.histology[i].value, 10);
2784 10 Oct 14 nicklas 174       }
2784 10 Oct 14 nicklas 175     }
2784 10 Oct 14 nicklas 176     
2784 10 Oct 14 nicklas 177     submitInfo.histology = items;
2784 10 Oct 14 nicklas 178
2784 10 Oct 14 nicklas 179     var url = '../Histology.servlet?ID='+App.getSessionId();
2784 10 Oct 14 nicklas 180     url += '&cmd=CreateWorkList';    
2784 10 Oct 14 nicklas 181     Wizard.showLoadingAnimation('Creating Histology work list...');
2784 10 Oct 14 nicklas 182     Wizard.asyncJsonRequest(url, histology.submissionResults, 'POST', JSON.stringify(submitInfo));
2784 10 Oct 14 nicklas 183   }
2784 10 Oct 14 nicklas 184     
2784 10 Oct 14 nicklas 185   histology.submissionResults = function(response)
2784 10 Oct 14 nicklas 186   {
2784 10 Oct 14 nicklas 187     Wizard.showFinalMessage(response.messages);
2784 10 Oct 14 nicklas 188     
2784 10 Oct 14 nicklas 189     Doc.show('gorestart');
2784 10 Oct 14 nicklas 190     if (response.workList)
2784 10 Oct 14 nicklas 191     {
2784 10 Oct 14 nicklas 192       var printFrm = document.forms['print'];
2784 10 Oct 14 nicklas 193       printFrm.workList.value = response.workList.id;
2784 10 Oct 14 nicklas 194       Doc.show('goprotocol');
2784 10 Oct 14 nicklas 195     }
2784 10 Oct 14 nicklas 196   }
2784 10 Oct 14 nicklas 197   
2784 10 Oct 14 nicklas 198   histology.cancelWizard = function()
2784 10 Oct 14 nicklas 199   {
2784 10 Oct 14 nicklas 200     location.href = 'histology_protocol.jsp?ID='+App.getSessionId();
2784 10 Oct 14 nicklas 201   }
2784 10 Oct 14 nicklas 202   
2784 10 Oct 14 nicklas 203   histology.showProtocol = function()
2784 10 Oct 14 nicklas 204   {
2784 10 Oct 14 nicklas 205     var printFrm = document.forms['print'];
2784 10 Oct 14 nicklas 206     printFrm.submit();
2784 10 Oct 14 nicklas 207   }
2784 10 Oct 14 nicklas 208
2784 10 Oct 14 nicklas 209   return histology;
2784 10 Oct 14 nicklas 210 }();
2784 10 Oct 14 nicklas 211
2784 10 Oct 14 nicklas 212 Doc.onLoad(Histology.initPage);
2784 10 Oct 14 nicklas 213