Changeset 5644


Ignore:
Timestamp:
May 26, 2011, 2:50:32 PM (10 years ago)
Author:
Nicklas Nordborg
Message:

References #1597: Subtypes of items

Implemented a function that automatically selects the "Annotation category" in the "Annotations" tab in edit dialogs that has a name matching the name of the current subtype for a Subtypable item.

So, by naming annotation categories with the same name as item subtypes a sort of "soft" links are created that may make data input easier when there are many annotation types for the main item type, but only a few are actually used for each subtype.

Note that this doesn't prevent annotations with other annotation types.

Location:
trunk/www
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/biomaterials/biosources/edit_biosource.jsp

    r5643 r5644  
    109109  %>
    110110  <base:page type="popup" title="<%=title%>">
    111   <base:head scripts="tabcontrol.js,annotations.js" styles="tabcontrol.css">
     111  <base:head scripts="tabcontrol.js,annotations.js,subtypes.js" styles="tabcontrol.css">
    112112    <ext:scripts context="<%=jspContext%>" />
    113113    <ext:stylesheets context="<%=jspContext%>" />
     
    147147        if (tabId == 'annotations' && !annotationsLoaded)
    148148        {
    149           Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>);
     149          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, 0, ItemSubtype.getSubtypeId('biosource'));
    150150          annotationsLoaded = true;
    151151        }
    152152      }
    153153    }
    154 
     154   
    155155    function init()
    156156    {
  • trunk/www/common/annotations/annotate.jsp

    r5426 r5644  
    3535  import="net.sf.basedb.core.Nameable"
    3636  import="net.sf.basedb.core.Protocol"
     37  import="net.sf.basedb.core.Subtypable"
     38  import="net.sf.basedb.core.ItemSubtype"
    3739  import="net.sf.basedb.core.AnnotationSet"
    3840  import="net.sf.basedb.core.Annotation"
     
    7476final int itemId = Values.getInt(request.getParameter("item_id"));
    7577final int protocolId = Values.getInt(request.getParameter("protocol_id"), -1);
     78final int subtypeId = Values.getInt(request.getParameter("subtype_id"), -1);
    7679final int annotationTypeId = Values.getInt(request.getParameter("annotationtype_id"));
    7780final boolean standalone = Values.getBoolean(request.getParameter("standalone"));
     
    112115    readProtocol = false;
    113116  }
     117  String selectedCategoryName = null;
     118  try
     119  {
     120    ItemSubtype subtype = null;
     121    if (subtypeId == -1 && item != null && item instanceof Subtypable)
     122    {
     123      subtype = ((Subtypable)item).getItemSubtype();
     124    }
     125    else if (subtypeId > 0)
     126    {
     127      subtype = ItemSubtype.getById(dc, subtypeId);
     128    }
     129    if (subtype != null) selectedCategoryName = subtype.getName();
     130  }
     131  catch (PermissionDeniedException ex)
     132  {}
     133 
    114134  if (standalone)
    115135  {
     
    228248        }
    229249      }
     250      boolean checkCategoryNameAgainstSubtype = at.getId() == annotationTypeId;
     251      boolean foundCategoryForSubtype = false;
    230252      for (AnnotationTypeCategory category : categoryQuery.list(dc))
    231253      {
     254        if (checkCategoryNameAgainstSubtype)
     255        {
     256          if (category.getName().equals(selectedCategoryName)) foundCategoryForSubtype = true;
     257        }
    232258        allCategories.add(category);
    233259        %>
     
    235261        <%
    236262      }
     263      if (checkCategoryNameAgainstSubtype && !foundCategoryForSubtype) selectedCategoryName = null;
    237264
    238265      String icon = "";
     
    265292    }
    266293    %>
     294    categoryOnChange();
    267295  }
    268296
     
    590618        for (AnnotationTypeCategory category : allCategories)
    591619        {
     620          boolean selected = category.getName().equals(selectedCategoryName);
    592621          %>
    593622          <option value="<%=category.getId()%>"
    594623            title="<%=HTML.encodeTags(category.getDescription())%>"
     624            <%=selected ? "selected" : "" %>
    595625          ><%=HTML.encodeTags(category.getName())%>
    596626          <%
     
    598628        %>
    599629        </select>
    600      
     630      <%=selectedCategoryName %>
    601631        <div class="parameterlist" style="height: <%=(int)(scale*300)%>px; margin-top: 4px;">
    602632        <%=sb.toString()%>
  • trunk/www/include/scripts/annotations.js

    r4889 r5644  
    3232{
    3333
    34   this.loadAnnotateFrame = function(theFrame, ID, itemType, itemId, protocolId)
     34  this.loadAnnotateFrame = function(theFrame, ID, itemType, itemId, protocolId, subtypeId)
    3535  {
    3636    var url = getRoot()+'common/annotations/annotate.jsp?ID='+ID;
    3737    url += '&item_type='+itemType+'&item_id='+itemId;
    38     if (protocolId != undefined && protocolId != null) url += '&protocol_id='+protocolId;
     38    if (protocolId) url += '&protocol_id='+protocolId;
     39    if (subtypeId) url += '&subtype_id='+subtypeId;
    3940    theFrame.location.href = url;
    4041  }
  • trunk/www/include/scripts/subtypes.js

    r5631 r5644  
    4949
    5050  }
     51
     52  this.getSubtypeId = function(formId)
     53  {
     54    var frm = document.forms[formId];
     55    if (!frm) return null;
     56    var list = frm['subtype_id'];
     57    if (!list || list.disabled || list.length == 0) return null;
     58    return Math.abs(parseInt(list[list.selectedIndex].value));
     59  }
     60 
    5161 
    5262}
Note: See TracChangeset for help on using the changeset viewer.