Ignore:
Timestamp:
Apr 30, 2020, 12:02:00 PM (2 years 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.