Changeset 1532


Ignore:
Timestamp:
Feb 7, 2012, 2:58:02 PM (11 years ago)
Author:
Nicklas Nordborg
Message:

References #355: Partition wizard should use local storage to save form

The partition wizard now remember all values in step 3 (Enter weight information). It is saved in the web browser local storage if the browser supports it (FF9 and IE9 should work). If something goes wrong with the registration the user can simply restart the wizard and select the same specimen tubes in step 1 (they are marked with a *) and continue as if nothing has happened.

Note that this feature is browser-specific and locally stored data can only be accesed with the same browser that saved it in the first place.

Location:
extensions/net.sf.basedb.reggie/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.reggie/trunk/resources/partitionform.jsp

    r1530 r1532  
    3939var oneOrMoreWeightsAreSet;
    4040var nofPiecesAreValid;
     41var isRestoringFromLocalStorage = false; // A flag to keep track of what is happening
    4142
    4243function init()
     
    5253    {
    5354      var tube = specimenTubes[i];
    54       selectList.options[selectList.length] = new Option(tube.name, tube.name);
     55      var storeInfo = getStoredInfo(tube.id);
     56      selectList.options[selectList.length] = new Option(tube.name + (storeInfo ? ' [*]' : ''), tube.name, storeInfo ? true : false);
    5557    }
    5658  }
     
    189191    }
    190192   
    191     inputWeightHtml = '';
     193    inputWeightHtml = '<table border="0" cellspacing="0" cellpadding="0" width="100%">';
    192194    var spTitle = 'SpWeight<br>';
    193195    var apTitle = 'ApWeight<br>';
     
    226228      var tube = selectedTubes[i];
    227229      var nextStep = i<(selectedTubes.length-1) ? 'focusOnEnter(event, \'bloody'+(i+1)+'\')' : '';
    228      
     230       
    229231      inputWeightHtml += '<tr>';
    230232      inputWeightHtml += '<td rowspan=2 class=prompt>'+tube.name;
     
    238240      inputWeightHtml += '<td style="width:400px;">';
    239241      inputWeightHtml += '<table style="width:100%"><tr>';     
    240       inputWeightHtml += '<td>'+bloodyTitle+'<input type=checkbox onkeypress="checkOnNumber(event, this);focusOnEnter(event, \'appearance'+i+'\')" onfocus="messageOnFocus(0,'+i+')" name=bloody'+i+' /></td>';
    241       inputWeightHtml += '<td>'+appearanceTitle+'<select name=appearance'+i+' onfocus="messageOnFocus(1,'+i+')" onkeypress="focusOnEnter(event, \'necrosis'+i+'\')">'+appearanceOptions+'</select></td>';
    242       inputWeightHtml += '<td>'+necrosisTitle+'<select name=necrosis'+i+' onfocus="messageOnFocus(2,'+i+')" onkeypress="focusOnEnter(event, \'fat'+i+'\')">'+necrosisOptions+'</select></td>'; 
    243       inputWeightHtml += '<td>'+fatTitle+'<select name=fat'+i+' onfocus="messageOnFocus(3,'+i+')" onkeypress="focusOnEnter(event, \'coloured'+i+'\')">'+fatOptions+'</select></td>';
    244       inputWeightHtml += '<td>'+colouredTitle+'<input type=checkbox name=coloured'+i+' onfocus="messageOnFocus(4,'+i+')" onkeypress="checkOnNumber(event, this);focusOnEnter(event, \'nofPieces'+i+'\')" /></td>'
     242      inputWeightHtml += '<td>'+bloodyTitle+'<input type=checkbox onkeypress="checkOnNumber(event, this);focusOnEnter(event, \'appearance'+i+'\')" onchange="saveToLocalStorage('+i+')" onfocus="messageOnFocus(0,'+i+')" name=bloody'+i+' /></td>';
     243      inputWeightHtml += '<td>'+appearanceTitle+'<select name=appearance'+i+' onfocus="messageOnFocus(1,'+i+')" onchange="saveToLocalStorage('+i+')" onkeypress="focusOnEnter(event, \'necrosis'+i+'\')">'+appearanceOptions+'</select></td>';
     244      inputWeightHtml += '<td>'+necrosisTitle+'<select name=necrosis'+i+' onfocus="messageOnFocus(2,'+i+')" onchange="saveToLocalStorage('+i+')" onkeypress="focusOnEnter(event, \'fat'+i+'\')">'+necrosisOptions+'</select></td>';
     245      inputWeightHtml += '<td>'+fatTitle+'<select name=fat'+i+' onfocus="messageOnFocus(3,'+i+')" onchange="saveToLocalStorage('+i+')" onkeypress="focusOnEnter(event, \'coloured'+i+'\')">'+fatOptions+'</select></td>';
     246      inputWeightHtml += '<td>'+colouredTitle+'<input type=checkbox name=coloured'+i+' onfocus="messageOnFocus(4,'+i+')" onchange="saveToLocalStorage('+i+')" onkeypress="checkOnNumber(event, this);focusOnEnter(event, \'nofPieces'+i+'\')" /></td>'
    245247      inputWeightHtml += '<td>'+nofTitle+'<input name="nofPieces'+i+'" onfocus="messageOnFocus(5,'+i+')" onblur="nofPiecesOnChange('+i+')" onkeypress="focusOnEnter(event, \'spWeight'+i+'\');return isNumberKey(event)" size=2 /></td>';
    246248      inputWeightHtml += '<td>'+spTitle+'<input name="spWeight'+i+'" onfocus="messageOnFocus(6,'+i+')" onblur="spWeightOnChange('+i+')" onkeypress="focusOnEnter(event, \'hisWeight'+i+'\');return isNumberKey(event)" size=4 /></td>';
     
    250252      inputWeightHtml += '</table>';
    251253      inputWeightHtml += '</td>';
    252       inputWeightHtml += '<td rowspan=2 class="status" id="'+i+'.status"></td>';     
     254      inputWeightHtml += '<td rowspan=2 class="status" id="'+i+'.status"></td>';
    253255      inputWeightHtml += '</tr>';
    254256     
     
    258260      inputWeightHtml += '<tr><td>&nbsp;</td></tr>';
    259261    }
     262    inputWeightHtml += '</table>';
    260263    setInnerHTML('weightInputs', inputWeightHtml);
    261   }
     264   
     265    // Restore saved information
     266    isRestoringFromLocalStorage = true;
     267    for (var i=0;i<selectedTubes.length; i++)
     268    {
     269      var tube = selectedTubes[i];
     270      var storeInfo = getStoredInfo(tube.id);
     271      if (storeInfo)
     272      {
     273        frm['bloody'+i].checked = storeInfo.bloody;
     274        setSelectedValue(frm['appearance'+i], storeInfo.appearance);
     275        setSelectedValue(frm['necrosis'+i], storeInfo.necrosis);
     276        setSelectedValue(frm['fat'+i], storeInfo.fat);
     277        frm['coloured'+i].checked = storeInfo.coloured;
     278        frm['nofPieces'+i].value = storeInfo.nofPieces;
     279        frm['spWeight'+i].value = storeInfo.spWeight;
     280        frm['hisWeight'+i].value = storeInfo.hisWeight;
     281        frm['apWeight'+i].value = storeInfo.apWeight;
     282        nofPiecesOnChange(i);
     283        spWeightOnChange(i);
     284        hisWeightOnChange(i);
     285        apWeightOnChange(i);
     286      }
     287    }
     288    isRestoringFromLocalStorage = false;
     289  }
     290 
     291 
     292 
    262293  Main.show('weightSection');
    263294  Main.hide('gonext');
     
    340371}
    341372
     373
     374
     375/**
     376  Save as much information as possible about the partitioned
     377  specimen tube. The information is stored in the localStorage()
     378  under the key 'reggie.specimen.<id>.partitionInfo' where
     379  <id> is the ID of the specimen tube.
     380*/
     381function saveToLocalStorage(tubeIndex)
     382{
     383  if (window.localStorage && !isRestoringFromLocalStorage)
     384  {
     385    var tube = selectedTubes[tubeIndex];
     386    var frm = document.forms['reggie'];
     387    var storeInfo = new Object();
     388    storeInfo.tubeId = tube.id;
     389    storeInfo.bloody = frm['bloody'+tubeIndex].checked;
     390    storeInfo.appearance = getSelectedValue(frm['appearance'+tubeIndex]);
     391    storeInfo.necrosis = getSelectedValue(frm['necrosis'+tubeIndex]);
     392    storeInfo.fat = getSelectedValue(frm['fat'+tubeIndex]);
     393    storeInfo.coloured = frm['coloured'+tubeIndex].checked;
     394    storeInfo.nofPieces = frm['nofPieces'+tubeIndex].value;
     395    storeInfo.spWeight = frm['spWeight'+tubeIndex].value;
     396    storeInfo.hisWeight = frm['hisWeight'+tubeIndex].value;
     397    storeInfo.apWeight = frm['apWeight'+tubeIndex].value;
     398    window.localStorage.setItem('reggie.specimen.' + tube.id + '.partitionInfo', JSON.stringify(storeInfo));
     399    if (debug)
     400    {
     401      Main.debug(tubeIndex + ': ' + window.localStorage.getItem('reggie.specimen.' + tube.id + '.partitionInfo'));
     402    }
     403  }
     404}
     405
     406function removeFromLocalStorage(tubeId)
     407{
     408  if (!window.localStorage) return;
     409  if (debug) Main.debug('removeFromLocalStorage:' + tubeId);
     410  window.localStorage.removeItem('reggie.specimen.' + tubeId + '.partitionInfo');
     411}
     412 
     413function getStoredInfo(tubeId)
     414{
     415  if (!window.localStorage) return null;
     416  try
     417  {
     418    var stored = window.localStorage.getItem('reggie.specimen.' + tubeId + '.partitionInfo');
     419    if (debug) Main.debug(stored);
     420    return stored ? JSON.parse(stored) : null;
     421  }
     422  catch (e)
     423  {
     424    Main.debug('Could not load stored information for tube ' + tubeId + ': ' + e);
     425  }
     426}
     427
    342428function updateInputStatus(tubeIndex)
    343429{
     430  saveToLocalStorage(tubeIndex);
    344431  var frm = document.forms['reggie'];
    345432  if(nofPiecesAreValid[tubeIndex] == false)
     
    586673  submitInfo.tubeInfo = tubeInfo;
    587674 
    588   if (debug) Main.debug(JSON.stringify(caseInfo));     
     675  if (debug) Main.debug(JSON.stringify(submitInfo));     
    589676  var request = Ajax.getXmlHttpRequest();
    590677  var url = 'PartitionRegistration.servlet?ID=<%=ID%>&cmd=CreatePartitions';
     
    610697  setInnerHTML('done', msg);
    611698 
     699  for (var i = 0; i < response.partitioned.length; i++)
     700  {
     701    removeFromLocalStorage(response.partitioned[i]);
     702  }
    612703 
    613704  Main.show('done');
     
    664755        <td class="input"><select style="width:50%" name="tubeSelect" id="tubesSelect" multiple="multiple" size="12" onkeypress='doOnTab(event, goNextAuto)'></select></td>
    665756        <td class="status" id="tubes.status"></td>
    666         <td class="help"><span id="tubes.message" class="message" style="display: none;"></span>Select specimen tubes to include in the partition.</td>
     757        <td class="help"><span id="tubes.message" class="message" style="display: none;"></span>Select specimen tubes to include in the partition.<br>
     758        * = There is unsaved partitioning information for this tube
     759        </td>
    667760      </tr>
    668761      </table>
     
    711804    </tr>
    712805    <tr>
    713       <td class="stepfields">
    714         <table id="weightInputs" border="0" cellspacing="0" cellpadding="0" width="100%"></table>
     806      <td class="stepfields" id="weightInputs">
     807       
    715808      </td>
    716809    </tr>
  • extensions/net.sf.basedb.reggie/trunk/resources/reggie.js

    r1531 r1532  
    247247  return caseName.match(/^\d{7}$/);
    248248}
     249
     250/**
     251  Get the selected value from a selection list.
     252*/
     253function getSelectedValue(list)
     254{
     255  if (list.selectedIndex < 0) return '';
     256  return list[list.selectedIndex].value;
     257}
     258/**
     259  Select the first option in the list that has the given value.
     260*/
     261function setSelectedValue(list, value)
     262{
     263  for (var i = 0; i < list.length; i++)
     264  {
     265    if (list[i].value == value)
     266    {
     267      list.selectedIndex = i;
     268      return;
     269    }
     270  }
     271}
  • extensions/net.sf.basedb.reggie/trunk/src/net/sf/basedb/reggie/servlet/PartitionRegistrationServlet.java

    r1502 r1532  
    154154        JSONObject jsonInfo = (JSONObject)jsonReq.get("tubeInfo");       
    155155        JSONArray jsonSpecimens = (JSONArray)jsonInfo.get("specimens");
     156        JSONArray jsonPartitioned = new JSONArray();
    156157       
    157158        AnnotationType partitionDateType = Reggie.findAnnotationType(dc, new Item[]{Item.EXTRACT, Item.SAMPLE}, Reggie.ANNOTATION_PARTITION_DATE, true);
     
    253254            specimen.setOriginalQuantity(originalQuantity);
    254255           
    255             jsonMessages.add("Specimen tube " + specimen.getName() + " partitioned successfully");           
     256            jsonMessages.add("Specimen tube " + specimen.getName() + " partitioned successfully");
     257            jsonPartitioned.add(specimen.getId());
    256258          }
    257259        }
    258260        dc.commit();
     261        json.put("partitioned", jsonPartitioned);
    259262      }
    260263      json.put("messages", jsonMessages);
Note: See TracChangeset for help on using the changeset viewer.