Changeset 6750


Ignore:
Timestamp:
Feb 19, 2015, 3:02:57 PM (7 years ago)
Author:
Nicklas Nordborg
Message:

References #1325: Lists of items (similar funcion as biomaterial lists)

Added functionality for creating a new item list from the regular list view. The samples list view has been used for testing.

Note that there is no support for walking up the parent/child chain here any longer since it felt like a confusing way to do things.

The new idea is that lists should be created at various levels and then use the "union/intersection" functionality to create a final list by checking for members using the entire parent/child chain.

Location:
trunk/www
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/biomaterials/samples/index.jsp

    r6695 r6750  
    487487    redirect = "../lists/index.jsp?ID="+ID+"&cmd=NewItem&addBioMaterials=1&formId=samples&fromContext=SAMPLE";
    488488  }
     489  else if ("CreateItemList".equals(cmd))
     490  {
     491    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     492    final ItemQuery<Sample> query = Sample.getQuery();
     493    dc = sc.newDbControl();
     494    cc.configureQuery(dc, query, true);
     495    dc.close();
     496    cc.setQuery(query);
     497    redirect = "../../views/itemlists/index.jsp?ID="+ID+"&cmd=NewItem&addItems=1&memberType=SAMPLE&formId=samples";
     498  }
    489499  else if ("PlaceOnPlate".equals(cmd))
    490500  {
  • trunk/www/biomaterials/samples/list_samples.jsp

    r6749 r6750  
    529529            tooltip="Create a new biomaterial list from matching samples"
    530530            visible="<%=sc.hasPermission(Permission.CREATE, Item.BIOMATERIALLIST)%>"
     531          />
     532          <tbl:button
     533            id="btnNewItemList"
     534            image="add.png"
     535            title="New item list&hellip;"
     536            tooltip="Create a new item list from matching samples"
     537            visible="<%=sc.hasPermission(Permission.CREATE, Item.ITEMLIST)%>"
    531538          />
    532539          <tbl:button
  • trunk/www/biomaterials/samples/samples.js

    r6695 r6750  
    114114      Buttons.addClickHandler('btnRunPlugin', Buttons.runListPlugin, tableAttributes);
    115115      Buttons.addClickHandler('btnNewBioMaterialList', samples.newBioMaterialListOnClick);
     116      Buttons.addClickHandler('btnNewItemList', samples.newItemListOnClick);
    116117      Buttons.addClickHandler('btnPlaceOnPlate', samples.placeOnPlateOnClick);
    117118      Buttons.addClickHandler('btnNewPooledItem', samples.newPooledItemOnClick);
     
    159160    var controller = Items.getController('BIOMATERIALLIST');
    160161    Table.submitToPopup('samples', 'CreateBioMaterialList', controller.width, controller.height);
     162  }
     163 
     164  // Create a new biomaterial list with the selected biosources as members
     165  samples.newItemListOnClick = function()
     166  {
     167    var controller = Items.getController('ITEMLIST');
     168    Table.submitToPopup('samples', 'CreateItemList', controller.width, controller.height);
    161169  }
    162170 
  • trunk/www/include/styles/main.css

    r6621 r6750  
    754754{
    755755  vertical-align: top;
     756  height: auto;
     757  max-height: 100%;
    756758}
    757759
  • trunk/www/views/itemlists/edit_list.jsp

    r6742 r6750  
    5555  String title = null;
    5656  ItemList list = null;
    57   Item memberType = null;
    58 
     57  boolean addItems = Values.getBoolean(request.getParameter("addItems"));
     58  Item memberType = addItems ? Item.valueOf(request.getParameter("memberType")) : null;
     59  String formId = addItems ? Values.getStringOrNull(request.getParameter("formId")) : null;
     60  String subContext = addItems ? Values.getStringOrNull(request.getParameter("subContext")) : null;
     61 
    5962  if (itemId == 0)
    6063  {
    6164    title = "Create item list";
    6265    cc.removeObject("item");
     66   
    6367    if (memberType == null)
    6468    {
     
    8791    <form action="index.jsp?ID=<%=ID%>" method="post" name="list">
    8892    <input type="hidden" name="cmd" value="UpdateItem">
     93    <%
     94    if (subContext != null)
     95    {
     96      %>
     97      <input type="hidden" name="subContext" value="<%=subContext%>">
     98      <%
     99    }
     100    %>
    89101
    90102    <t:tabcontrol id="settings"
     
    105117        <th>Member type</th>
    106118        <td>
    107           <select name="memberType" <%=list != null ? "disabled" : "" %> style="width: 15em;" class="unchangeable">
     119          <select name="memberType" <%=list != null || (addItems && memberType != null) ? "disabled" : "" %> style="width: 15em;" class="unchangeable">
    108120          <%
    109121          for (Item mt : Metadata.getListableItems())
     
    125137        <td></td>
    126138      </tr>
     139      <%
     140      if (addItems)
     141      {
     142        %>
     143        <tr class="big">
     144          <th>Source items</th>
     145          <td>
     146            <input type="radio" name="source" id="sourceSelected" value="selected"
     147              data-parent-form="<%=formId%>"
     148              ><label for="sourceSelected" id="lblSelected">Selected items</label><br>
     149            <input type="radio" name="source" id="sourcePage" value="page"
     150              ><label for="sourcePage">Current page</label><br>
     151            <input type="radio" name="source" id="sourceAll" value="all" checked
     152              ><label for="sourceAll">All pages</label><br>
     153          </td>
     154          <td></td>
     155        </tr>
     156        <%
     157      }
     158      %>
     159     
    127160      <tr class="dynamic">
    128161        <th>Description</th>
  • trunk/www/views/itemlists/index.jsp

    r6742 r6750  
    3636  import="net.sf.basedb.core.MultiPermissions"
    3737  import="net.sf.basedb.core.OwnedItem"
     38  import="net.sf.basedb.core.Listable"
    3839  import="net.sf.basedb.core.PermissionDeniedException"
    3940  import="net.sf.basedb.core.ItemAlreadyExistsException"
     
    165166      Base.updateAnnotations(dc, list, list, request);
    166167
     168      if (!list.isInDatabase())
     169      {
     170        // Add individual items from selected from a list page
     171        String source = request.getParameter("source");
     172        if (source != null)
     173        {
     174          String subContext = Values.getString(request.getParameter("subContext"), "");
     175         
     176          ItemQuery<? extends Listable> query =
     177            (ItemQuery<? extends Listable>)sc.getCurrentContext(list.getMemberType(), subContext).getQuery();
     178          if ("all".equals(source))
     179          {
     180            query.setFirstResult(0);
     181            query.setMaxResults(-1);
     182          }
     183          else if ("selected".equals(source))
     184          {
     185            query.setFirstResult(0);
     186            query.setMaxResults(-1);
     187            Integer[] itemIds = Values.getInt(request.getParameter("items").split(","));
     188            query.restrict(
     189              Restrictions.in(
     190                Hql.property("id"),
     191                Expressions.parameter("selectedItems")
     192              )
     193            );
     194            query.setParameter("selectedItems", Arrays.asList(itemIds), Type.INT);     
     195          }
     196          // else -- no modifications to the query mean that we only get the current page
     197         
     198          int numAdded = list.add(query.iterate(dc));
     199        }
     200       
     201        message = "List created with " + list.getSize() + " item(s)";
     202      }
     203
     204     
    167205      // OnSave extensions
    168206      invoker.render(OnSaveRenderer.ON_SAVE);
  • trunk/www/views/itemlists/lists.js

    r6743 r6750  
    2626{
    2727  var lists = {};
     28  var selectedItemsInParentForm;
    2829 
    2930  /**
     
    4243      TabControl.addTabValidator('settings.info', lists.validateList);
    4344      TabControl.addTabActivateListener('settings.annotations', Annotations.autoLoadEditFrame);
     45     
     46      var frm = document.forms['list'];
     47      if (frm.source)
     48      {
     49        // Create biomaterial list from selection of biomaterials
     50        var parentForm = Data.get('sourceSelected', 'parent-form');
     51        selectedItemsInParentForm = window.opener.Table.getSelected(parentForm)
     52        if (selectedItemsInParentForm.length == 0)
     53        {
     54          Doc.element('sourceSelected').disabled = true;
     55        }
     56        else
     57        {
     58          Forms.checkRadio(frm.source, 'selected');
     59          Doc.element('lblSelected').innerHTML += ' ['+selectedItemsInParentForm.length+']';
     60        }
     61      }
     62
    4463    }
    4564    else if (pageId == 'view-page')
     
    129148    {
    130149      Annotations.saveModifiedAnnotationsToForm(frm);
     150      if (selectedItemsInParentForm)
     151      {
     152        Forms.addHidden(frm, 'items', selectedItemsInParentForm.join(','));
     153      }
    131154      frm.memberType.disabled = false;
    132155      frm.submit();
Note: See TracChangeset for help on using the changeset viewer.