Changeset 6246


Ignore:
Timestamp:
Feb 25, 2013, 4:56:27 PM (9 years ago)
Author:
Nicklas Nordborg
Message:

References #1729 and #1730. Implement lazy loading of 'Annotations'/'Inherited annotations' as a tab activation event instead of replacing the 'switchTab' function in the tab-control taglib. Done for the biosurce and sample edit dialogs.

Also improved the implementation so that the last parameters used are kept in the common code and the edit dialogs no longer has to keep track of when a protocol is changed or when the parent item selection changes.

Location:
trunk/www
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/biomaterials/biosources/biosources.js

    r6245 r6246  
    124124    if (TabControl.validateActiveTab('settings'))
    125125    {
    126       if (annotationsLoaded)
    127       {
    128         Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
    129       }
     126      Annotations.saveModifiedAnnotationsToForm(frm);
    130127      frm.submit();
    131128    }
     
    134131  biosources.loadAnnotationsFrame = function()
    135132  {
    136     if (!annotationsLoaded)
    137     {
    138       Annotations.loadAnnotateFrame(frames.annotations, App.getSessionId(), 'BIOSOURCE', Data.get('page-data', 'item-id'), 0, ItemSubtype.getSubtypeId('biosource'));
    139       annotationsLoaded = true;
    140     }
     133    Annotations.autoLoadEditFrame(0, ItemSubtype.getSubtypeId('biosource'));
    141134  }
    142135 
  • trunk/www/biomaterials/biosources/edit_biosource.jsp

    r6245 r6246  
    107107  %>
    108108  <base:page type="popup" title="<%=title%>" id="edit-page">
    109   <base:head scripts="tabcontrol-2.js,annotations.js,subtypes.js,~biosources.js" styles="tabcontrol.css">
     109  <base:head scripts="tabcontrol-2.js,subtypes.js,~biosources.js" styles="tabcontrol.css">
    110110    <ext:scripts context="<%=jspContext%>" />
    111111    <ext:stylesheets context="<%=jspContext%>" />
     
    113113  <base:body>
    114114    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
    115    
    116     <div id="page-data" class="data-container"
    117       data-item-id="<%=itemId%>"
    118       ></div>
    119    
     115     
    120116    <form action="index.jsp?ID=<%=ID%>" method="post" name="biosource">
    121117    <input type="hidden" name="cmd" value="UpdateItem">
     
    189185    </t:tab>
    190186
    191     <t:tab id="annotations" title="Annotations" helpid="annotations.edit"><iframe
    192       name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp"
    193       class="absolutefull" style="width: 100%; height: 100%;"></iframe></t:tab>
     187    <t:tab id="annotations" title="Annotations" helpid="annotations.edit">
     188      <jsp:include page="../../common/annotations/annotate_frameset.jsp">
     189        <jsp:param name="item_type" value="<%=itemType.name()%>" />
     190        <jsp:param name="item_id" value="<%=itemId%>" />
     191        <jsp:param name="ID" value="<%=ID%>" />
     192      </jsp:include>
     193    </t:tab>
    194194    </t:tabcontrol>
    195195    </form>
  • trunk/www/biomaterials/samples/edit_sample.jsp

    r6217 r6246  
    264264  %>
    265265  <base:page type="popup" title="<%=title%>">
    266   <base:head scripts="tabcontrol.js,annotations.js,linkitems.js,subtypes.js" styles="tabcontrol.css">
     266  <base:head scripts="tabcontrol.js,linkitems.js,subtypes.js" styles="tabcontrol.css">
    267267    <ext:scripts context="<%=jspContext%>" />
    268268    <ext:stylesheets context="<%=jspContext%>" />
     
    291291      if (TabControl.validateActiveTab('settings'))
    292292      {
    293         if (annotationsLoaded)
    294         {
    295           Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
    296         }
    297         if (inheritedAnnotationsLoaded)
    298         {
    299           Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
    300         }
     293        Annotations.saveModifiedAnnotationsToForm(frm);
     294        Annotations.saveInheritedAnnotationsToForm(frm);
    301295        frm.modifiedSamples.value = Link.exportModified(frm, 'S', true).join(',');
    302296        frm.removedSamples.value = Link.getActionIds(-1, 'S').join(',');
     
    305299    }
    306300   
    307     var annotationsLoaded = false;
    308     var inheritedAnnotationsLoaded = false;
    309     var parentsChanged = false;
    310     var protocolChanged = false;
    311     function switchTab(tabControlId, tabId)
    312     {
    313       if (TabControl.setActiveTab(tabControlId, tabId))
    314       {
    315         if (tabId == 'annotations' && (protocolChanged || !annotationsLoaded))
    316         {
    317           Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getProtocolId(), ItemSubtype.getSubtypeId('sample'));
    318           annotationsLoaded = true;
    319           protocolChanged = false;
    320         }
    321         else if (tabId == 'inheritedAnnotations' &&
    322           (parentsChanged || !inheritedAnnotationsLoaded))
    323         {
    324           Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
    325           inheritedAnnotationsLoaded = true;
    326           parentsChanged = false;
    327         }
    328       }
     301    function loadAnnotationsFrame()
     302    {
     303      Annotations.autoLoadEditFrame(getProtocolId(), ItemSubtype.getSubtypeId('sample'));
     304    }
     305   
     306    function loadInheritedAnnotationsFrame()
     307    {
     308      Annotations.autoLoadInheritFrame(getParents());
    329309    }
    330310   
     
    365345      var subtypeId = ItemSubtype.getSubtypeId('sample');
    366346      var recentInfo = ItemSubtype.getRecentAndRelatedInfo(subtypeId, 'SAMPLE', ['PROTOCOL', 'BIOPLATE', 'BIOSOURCE', 'SAMPLE']);
    367       protocolChanged = ItemSubtype.updateSelectionList(frm.protocol_id, recentInfo.PROTOCOL['recent'], recentInfo.PROTOCOL['default']);
     347      ItemSubtype.updateSelectionList(frm.protocol_id, recentInfo.PROTOCOL['recent'], recentInfo.PROTOCOL['default']);
    368348      ItemSubtype.updateSelectionList(frm.bioplate_id, recentInfo.BIOPLATE['recent']);
    369349    }
     
    393373      list[1].text = name;
    394374      list.selectedIndex = 1;
    395       protocolChanged = true;
    396     }
    397     function protocolOnChange()
    398     {
    399       protocolChanged = true;
    400375    }
    401376
     
    500475      frm.samples.disabled = !useSamples;
    501476      frm.used_quantity.disabled = !useSamples;
    502       parentsChanged = true;
    503     }
    504     function bioSourceOnChange()
    505     {
    506       parentsChanged = true;
    507477    }
    508478    function selectBioSourceOnClick()
     
    534504      frm.parentType[1].checked = false;
    535505      parentTypeOnClick();
    536       parentsChanged = true;
    537506    }
    538507   
     
    554523      frm.parentType[1].checked = true;
    555524      parentTypeOnClick();
    556       parentsChanged = true;
    557525    }
    558526    function samplesOnChange()
     
    590558    {
    591559      Link.removeSelected(document.forms['sample'].samples);
    592       parentsChanged = true;
    593560    }
    594561
     
    646613    <t:tabcontrol id="settings"
    647614      subclass="content dialogtabcontrol"
    648       position="bottom"  remember="<%=sample != null%>" switch="switchTab"
     615      position="bottom"  remember="<%=sample != null%>"
    649616      extensions="<%=invoker%>">
    650617    <t:tab id="info" title="Sample" validate="validateSample()" helpid="sample.edit">
     
    747714            newitem="<%=sample == null%>"
    748715            onselect="selectProtocolOnClick()"
    749             onchange="protocolOnChange()"
    750716            disabled="<%=lockEventProperties %>"
    751717          />
     
    833799            newitem="<%=sample == null%>"
    834800            onselect="selectBioSourceOnClick()"
    835             onchange="bioSourceOnChange()"
    836801          />
    837802        </td>
     
    888853    </t:tab>
    889854
    890     <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit"><iframe
    891       name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp"
    892       class="absolutefull" style="width: 100%; height: 100%;"></iframe></t:tab>
     855    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit" activate="loadAnnotationsFrame()">
     856      <jsp:include page="../../common/annotations/annotate_frameset.jsp">
     857        <jsp:param name="item_type" value="<%=itemType.name()%>" />
     858        <jsp:param name="item_id" value="<%=itemId%>" />
     859        <jsp:param name="ID" value="<%=ID%>" />
     860      </jsp:include>
     861    </t:tab>
    893862   
    894863    <t:tab id="inheritedAnnotations" title="Inherited annotations"
    895       helpid="annotations.edit.inherited"><iframe
    896         name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp"
    897         class="absolutefull" style="width: 100%; height: 100%;"></iframe></t:tab>
     864      helpid="annotations.edit.inherited" activate="loadInheritedAnnotationsFrame()">
     865      <jsp:include page="../../common/annotations/inherit_frameset.jsp">
     866        <jsp:param name="item_type" value="<%=itemType.name()%>" />
     867        <jsp:param name="item_id" value="<%=itemId%>" />
     868        <jsp:param name="ID" value="<%=ID%>" />
     869      </jsp:include>
     870    </t:tab>
    898871    </t:tabcontrol>
    899872    </form>
  • trunk/www/common/annotations/annotate.jsp

    r6202 r6246  
    292292  }
    293293  %>
    294   <base:page type="popup" title="<%=title%>">
     294  <base:page type="<%=standalone ? "popup" : "iframe"%>" title="<%=title%>">
    295295  <base:head scripts="~annotate.js" styles="parameters.css" />
    296296  <base:body>
  • trunk/www/include/scripts/annotations.js

    r6202 r6246  
    2828*/
    2929
    30 var Annotations = new AnnotationsClass();
    31 function AnnotationsClass()
     30var Annotations = function()
    3231{
    33 
    34   this.loadAnnotateFrame = function(theFrame, ID, itemType, itemId, protocolId, subtypeId)
     32  var annotations = {};
     33  var internal = {};
     34 
     35  var lastProtocolId = null;
     36  var editFrameLoaded = false;
     37 
     38  var lastParents = null;
     39  var inheritFrameLoaded = false;
     40 
     41  /**
     42    Automatically load or reload the 'Edit annotations' frame. The
     43    frame is loaded if it has not previously been loaded, or if
     44    the protocolId parameter has changed since last time this method
     45    was called.
     46  */
     47  annotations.autoLoadEditFrame = function(protocolId, subtypeId)
     48  {
     49    if (editFrameLoaded && lastProtocolId == protocolId) return;
     50    lastProtocolId = protocolId;
     51    editFrameLoaded = true;
     52   
     53    var url = App.getRoot() + 'common/annotations/annotate.jsp?ID='+App.getSessionId();
     54    url += '&item_type='+Data.get('annotate-data', 'item-type');
     55    url += '&item_id='+Data.get('annotate-data', 'item-id');;
     56    if (protocolId) url += '&protocol_id='+protocolId;
     57    if (subtypeId) url += '&subtype_id='+subtypeId;
     58    frames['annotations'].location.replace(url);
     59  }
     60 
     61  /**
     62    Save all modified annotations to the given form. If
     63    the 'Edit annotations' frame hasn't been loaded, this
     64    call is ignored.
     65  */
     66  annotations.saveModifiedAnnotationsToForm = function(frm)
     67  {
     68    if (!editFrameLoaded) return;
     69    frames['annotations'].Annotate.saveModifiedAnnotationToForm(frm);
     70  }
     71 
     72  /**
     73    Automatically load or reload the 'Inherit annotations' frame. The
     74    frame is loaded if it has not previously been loaded, or if
     75    the parents parameter has changed since last time this method
     76    was called.
     77  */
     78  annotations.autoLoadInheritFrame = function(parents)
     79  {
     80    if (inheritFrameLoaded)
     81    {
     82      if (internal.equalArrays(parents, lastParents)) return;
     83    }
     84    lastParents = parents;
     85    inheritFrameLoaded = true;
     86   
     87    var url = App.getRoot()+'common/annotations/inherit.jsp?ID='+App.getSessionId();
     88    url += '&item_type='+Data.get('annotate-data', 'item-type');
     89    url += '&item_id='+Data.get('annotate-data', 'item-id');
     90    if (parents && parents.length)
     91    {
     92      for (var i = 0; i < parents.length; i++)
     93      {
     94        url += '&parents='+parents[i];
     95      }
     96    }
     97    frames['inheritedAnnotations'].location.replace(url);
     98  }
     99
     100  /**
     101    Save all changes to inherited annotations to the given form. If
     102    the 'Inherit annotations' frame hasn't been loaded, this
     103    call is ignored.
     104  */
     105  annotations.saveInheritedAnnotationsToForm = function(frm)
     106  {
     107    if (!inheritFrameLoaded) return;
     108   
     109    var theFrame = frames['inheritedAnnotations'];
     110    var addedAnnotations = theFrame.Link.getActionIds(1, 'A');
     111    var removedAnnotations = theFrame.Link.getActionIds(-1, 'A');
     112    var addedAnnotationSets = theFrame.Link.getActionIds(1, 'AS');
     113    var removedAnnotationSets = theFrame.Link.getActionIds(-1, 'AS');
     114
     115    if (frm.addedAnnotations)
     116    {
     117      frm.addedAnnotations.value = addedAnnotations.join(',');
     118    }
     119    else
     120    {
     121      Forms.createHidden(frm, 'addedAnnotations', addedAnnotations.join(','));
     122    }
     123    if (frm.removedAnnotations)
     124    {
     125      frm.removedAnnotations.value = removedAnnotations.join(',');
     126    }
     127    else
     128    {
     129      Forms.createHidden(frm, 'removedAnnotations', removedAnnotations.join(','));
     130    }
     131    if (frm.addedAnnotationSets)
     132    {
     133      frm.addedAnnotationSets.value = addedAnnotationSets.join(',');
     134    }
     135    else
     136    {
     137      Forms.createHidden(frm, 'addedAnnotationSets', addedAnnotationSets.join(','));
     138    }
     139    if (frm.removedAnnotationSets)
     140    {
     141      frm.removedAnnotationSets.value = removedAnnotationSets.join(',');
     142    }
     143    else
     144    {
     145      Forms.createHidden(frm, 'removedAnnotationSets', removedAnnotationSets.join(','));
     146    }
     147  }
     148 
     149  // Check if two arrays have the same elements
     150  internal.equalArrays = function(a1, a2)
     151  {
     152    if (a1.length != a2.length) return false;
     153   
     154    for (var i = 0; i < a1.length; i++)
     155    {
     156      if (a1[i] != a2[i]) return false;
     157    }
     158   
     159    return true;
     160  }
     161 
     162  return annotations;
     163}();
     164
     165
     166  Annotations.loadAnnotateFrame = function(theFrame, ID, itemType, itemId, protocolId, subtypeId)
    35167  {
    36168    var url = getRoot()+'common/annotations/annotate.jsp?ID='+ID;
     
    41173  }
    42174 
    43   this.loadInheritFrame = function(theFrame, ID, itemType, itemId, parents)
     175  Annotations.loadInheritFrame = function(theFrame, ID, itemType, itemId, parents)
    44176  {
    45177    var url = getRoot()+'common/annotations/inherit.jsp?ID='+ID+'&item_type='+itemType+'&item_id='+itemId;
     
    54186  }
    55187
    56   this.addModifiedAnnotationsToForm = function(theFrame, frm)
     188  Annotations.addModifiedAnnotationsToForm = function(theFrame, frm)
    57189  {
    58190    theFrame.Annotate.saveModifiedAnnotationToForm(frm);
    59191  }
    60192 
    61   this.addInheritedAnnotationsToForm = function(theFrame, frm)
     193  Annotations.addInheritedAnnotationsToForm = function(theFrame, frm)
    62194  {
    63195    var addedAnnotations = theFrame.Link.getActionIds(1, 'A');
     
    99231    }
    100232  }
    101 }
    102 
     233
Note: See TracChangeset for help on using the changeset viewer.