Changeset 7801


Ignore:
Timestamp:
Apr 30, 2020, 12:02:00 PM (21 months ago)
Author:
Nicklas Nordborg
Message:

References #2209: Add items to existing item list from list page

Implemented a popup dialog for selecting an item list and which items to add from the current list. As usual there are three options: selected items, current page, or all items.

A button and supporting functionality for using the new feature has been added to the Biosource list page.

Location:
branches/3.16-stable
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3.16-stable/src/core/net/sf/basedb/core/ItemContext.java

    r7770 r7801  
    12511251 
    12521252 
    1253   public BasicItem getRecent(DbControl dc, Item itemType, int index)
     1253  public <T extends BasicItem> T getRecent(DbControl dc, Item itemType, int index)
    12541254  {
    12551255    return loadRecent(dc, itemType, itemType.name(), index);
    12561256  }
    12571257 
    1258   public BasicItem getRecent(DbControl dc, Item itemType, String subList, int index)
     1258  public <T extends BasicItem> T getRecent(DbControl dc, Item itemType, String subList, int index)
    12591259  {
    12601260    return loadRecent(dc, itemType, itemType.name() + "." + subList, index);
    12611261  }
    12621262 
    1263   private BasicItem loadRecent(DbControl dc, Item itemType, String key, int index)
     1263  private  <T extends BasicItem> T loadRecent(DbControl dc, Item itemType, String key, int index)
    12641264  {
    12651265    List<String> recentIds = getRecent(key);
    1266     BasicItem item = null;
     1266    T item = null;
    12671267    if (index >= 0 && index < recentIds.size())
    12681268    {
  • branches/3.16-stable/www/biomaterials/biosources/biosources.js

    r7604 r7801  
    7878      Buttons.addClickHandler('btnRunPlugin', Buttons.runListPlugin, tableAttributes);
    7979      Buttons.addClickHandler('btnNewItemList', biosources.newItemListOnClick);
     80      Buttons.addClickHandler('btnAddToItemList', biosources.addToItemListOnClick);
    8081     
    8182      Buttons.addClickHandler('close', App.closeWindow);
     
    107108    var controller = Items.getController('ITEMLIST');
    108109    Table.submitToPopup('biosources', 'CreateItemList', controller.width, controller.height);
     110  }
     111
     112  // Add selected biosources to an existing item list
     113  biosources.addToItemListOnClick = function()
     114  {
     115    Table.submitToPopup('biosources', 'AddItemsToList', 400, 300);
    109116  }
    110117 
  • branches/3.16-stable/www/biomaterials/biosources/index.jsp

    r7703 r7801  
    361361    redirect = "../../views/itemlists/index.jsp?ID="+ID+"&cmd=NewItem&addItems=1&memberType=BIOSOURCE&formId=biosources";
    362362  }
     363  else if ("AddItemsToList".equals(cmd))
     364  {
     365    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
     366    final ItemQuery<BioSource> query = BioSource.getQuery();
     367    dc = sc.newDbControl();
     368    cc.configureQuery(dc, query, true);
     369    dc.close();
     370    cc.setQuery(query);
     371    redirect = "../../views/itemlists/add_items.jsp?ID="+ID+"&memberType=BIOSOURCE&formId=biosources";
     372  }
    363373  else
    364374  {
  • branches/3.16-stable/www/biomaterials/biosources/list_biosources.jsp

    r7799 r7801  
    355355            tooltip="Create a new item list from matching biosources"
    356356            visible="<%=sc.hasPermission(Permission.CREATE, Item.ITEMLIST)%>"
     357          />
     358          <tbl:button
     359            id="btnAddToItemList"
     360            image="add.png"
     361            title="Add to item list&hellip;"
     362            tooltip="Add items to an existing item list"
    357363          />
    358364          <tbl:button
  • branches/3.16-stable/www/views/itemlists/index.jsp

    r7800 r7801  
    557557    dc.commit();
    558558  }
     559  else if ("AddMembers".equals(cmd))
     560  {
     561    dc = sc.newDbControl();
     562    ItemList list = ItemList.getById(dc, Values.getInt(itemId));
     563    String subContext = Values.getString(request.getParameter("subContext"), "");
     564
     565    ItemContext memberContext = sc.getCurrentContext(list.getMemberType(), subContext);
     566    memberContext.setRecent(Item.ITEMLIST, list, "AddMembers", 1);
     567    ItemQuery<? extends Listable> query = memberContext.getQuery();
     568    String source = request.getParameter("source");
     569    if ("all".equals(source))
     570    {
     571      query.setFirstResult(0);
     572      query.setMaxResults(-1);
     573    }
     574    else if ("selected".equals(source))
     575    {
     576      query.setFirstResult(0);
     577      query.setMaxResults(-1);
     578      Integer[] itemIds = Values.getInt(request.getParameter("items").split(","));
     579      query.restrict(
     580        Restrictions.in(
     581          Hql.property("id"),
     582          Expressions.parameter("selectedItems")
     583        )
     584      );
     585      query.setParameter("selectedItems", Arrays.asList(itemIds), Type.INT);     
     586    }
     587    // else -- no modifications to the query mean that we only get the current page
     588
     589    int count = list.add(query.iterate(dc));
     590    dc.commit();
     591    message = count + " members added to list";
     592  }
    559593  else
    560594  {
Note: See TracChangeset for help on using the changeset viewer.