Changeset 6744


Ignore:
Timestamp:
Feb 18, 2015, 9:56:25 AM (7 years ago)
Author:
Nicklas Nordborg
Message:

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

Adding functionality for manually adding/removing members to a list.

Location:
trunk/www/views/itemlists/members
Files:
2 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/www/views/itemlists/members/index.jsp

    r6743 r6744  
    2323  @version 2.10
    2424--%>
    25 <%@page import="net.sf.basedb.core.Listable"%>
    2625<%@ page pageEncoding="UTF-8" session="false"
    2726  import="net.sf.basedb.core.SessionControl"
     
    3130  import="net.sf.basedb.core.Type"
    3231  import="net.sf.basedb.core.ItemQuery"
    33   import="net.sf.basedb.core.ItemResultIterator"
    3432  import="net.sf.basedb.core.ItemList"
    3533  import="net.sf.basedb.core.BasicItem"
    36   import="net.sf.basedb.core.Sample"
    37   import="net.sf.basedb.core.Extract"
    38   import="net.sf.basedb.core.PhysicalBioAssay"
    39   import="net.sf.basedb.core.BioPlateEventType"
    40   import="net.sf.basedb.core.OwnedItem"
     34  import="net.sf.basedb.core.Listable"
    4135  import="net.sf.basedb.core.query.Restrictions"
    4236  import="net.sf.basedb.core.query.Expressions"
     
    5448  import="net.sf.basedb.core.plugin.GuiContext"
    5549  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
    56   import="net.sf.basedb.util.formatter.NameableFormatter"
    57   import="net.sf.basedb.util.formatter.WellCoordinateFormatter"
    58   import="net.sf.basedb.util.formatter.ItemTypeFormatter"
    59   import="net.sf.basedb.clients.web.plugins.BioMaterialEventSourceFormatter"
    60   import="net.sf.basedb.clients.web.plugins.ItemQueryLoader"
    61   import="net.sf.basedb.clients.web.plugins.ParentBioMaterialEventSourceLoader"
    6250  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
    6351  import="net.sf.basedb.clients.web.extensions.JspContext"
     
    7664  {
    7765    Item memberType = cc.getItemType();
    78     if (memberType == Item.BIOSOURCE)
    79     {
    80       // Register formatters
    81       cc.setObject("export.formatter.&children(name)", new NameableFormatter());
    82          
    83       // Register dataloaders
    84       String bioSourceParameter = "bioSource";
    85       final ItemQuery<Sample> sampleQuery = Sample.getQuery();
    86       sampleQuery.include(cc.getInclude());
    87       sampleQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter(bioSourceParameter)));
    88       sampleQuery.order(Orders.asc(Hql.property("name")));
    89       cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader(sampleQuery, bioSourceParameter));
    90     }
    91     else if (memberType == Item.SAMPLE)
    92     {
    93       // Register formatters
    94       cc.setObject("export.formatter.bioWell.row", new WellCoordinateFormatter(true));
    95       cc.setObject("export.formatter.bioWell.column", new WellCoordinateFormatter(false));
    96       cc.setObject("export.formatter.&creationEvent.sources(bioMaterial.name)", new BioMaterialEventSourceFormatter());
    97       cc.setObject("export.formatter.&childCreationEvents(event.bioMaterial.name)", new NameableFormatter());
    98       cc.setObject("export.formatter.&children(name)", new NameableFormatter());
    99       cc.setObject("export.formatter.parentType", new ItemTypeFormatter());
    100      
    101       // Register dataloaders
    102       String sampleParameter = "sample";
    103 
    104       // Child extracts
    105       ItemQuery<Extract> extractQuery = Extract.getQuery();
    106       extractQuery.include(cc.getInclude());
    107       extractQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter(sampleParameter)));
    108       extractQuery.order(Orders.asc(Hql.property("name")));
    109       cc.setObject("export.dataloader.&children(name)", new ItemQueryLoader(extractQuery, sampleParameter));
    110 
    111       // Child samples
    112       ItemQuery<Sample> childSamplesQuery = Sample.getQuery();
    113       childSamplesQuery.join(Hql.innerJoin("creationEvent", "ce"));
    114       childSamplesQuery.join(Hql.innerJoin("ce", "sources", "src"));
    115       childSamplesQuery.restrict(Restrictions.eq(Hql.property("src", "bioMaterial"), Expressions.parameter(sampleParameter)));
    116       childSamplesQuery.order(Orders.asc(Hql.property("name")));
    117       childSamplesQuery.include(cc.getInclude());
    118       cc.setObject("export.dataloader.&childCreationEvents(event.bioMaterial.name)", new ItemQueryLoader(childSamplesQuery, sampleParameter));
    119      
    120       // Parent samples
    121       cc.setObject("export.dataloader.&creationEvent.sources(bioMaterial.name)", new ParentBioMaterialEventSourceLoader());
    122     }
    123     else if (memberType == Item.EXTRACT)
    124     {
    125       cc.setObject("export.formatter.bioWell.row", new WellCoordinateFormatter(true));
    126       cc.setObject("export.formatter.bioWell.column", new WellCoordinateFormatter(false));
    127       cc.setObject("export.formatter.&children(name)", new NameableFormatter());
    128       cc.setObject("export.formatter.&creationEvent.sources(bioMaterial.name)", new BioMaterialEventSourceFormatter());
    129       cc.setObject("export.formatter.&childCreationEvents(event.physicalBioAssay.name)", new NameableFormatter());
    130       cc.setObject("export.formatter.&childCreationEvents(event.bioMaterial.name)", new NameableFormatter());
    131       cc.setObject("export.formatter.parentType", new ItemTypeFormatter());
    132      
    133       String restrictionParameter = "extract";
    134 
    135       // Physical bioassays
    136       ItemQuery<PhysicalBioAssay> bioAssayQuery = PhysicalBioAssay.getQuery();
    137       bioAssayQuery.join(Hql.innerJoin("creationEvent", "ce"));
    138       bioAssayQuery.join(Hql.innerJoin("ce", "sources", "src"));
    139       bioAssayQuery.restrict(Restrictions.eq(Hql.property("src", "bioMaterial"), Expressions.parameter(restrictionParameter)));
    140       bioAssayQuery.order(Orders.asc(Hql.property("name")));
    141       bioAssayQuery.include(cc.getInclude());
    142       cc.setObject("export.dataloader.&childCreationEvents(event.physicalBioAssay.name)", new ItemQueryLoader(bioAssayQuery, restrictionParameter));
    143 
    144       // Child extracts
    145       ItemQuery<Extract> childExtractsQuery = Extract.getQuery();
    146       childExtractsQuery.join(Hql.innerJoin("creationEvent", "ce"));
    147       childExtractsQuery.join(Hql.innerJoin("ce", "sources", "src"));
    148       childExtractsQuery.restrict(Restrictions.eq(Hql.property("src", "bioMaterial"), Expressions.parameter(restrictionParameter)));
    149       childExtractsQuery.order(Orders.asc(Hql.property("name")));
    150       childExtractsQuery.include(cc.getInclude());
    151       cc.setObject("export.dataloader.&childCreationEvents(event.bioMaterial.name)", new ItemQueryLoader(childExtractsQuery, restrictionParameter));
    152      
    153       // Parent items
    154       cc.setObject("export.dataloader.&creationEvent.sources(bioMaterial.name)", new ParentBioMaterialEventSourceLoader());
    155     }
    15666  }
    15767%>
     
    235145    redirect = "../../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&subcontext="+subContext+"&main_type=OTHER&title=Run+plugin";
    236146  }
     147  else if ("AddMembers".equals(cmd))
     148  {
     149    ItemContext memberContext = sc.getCurrentContext(itemType);
     150    final ItemQuery<? extends Listable> query = list.getAllItems();
     151    memberContext.configureQuery(dc, query, true);
     152    String which = request.getParameter("which");
     153    if ("selected".equals(which))
     154    {
     155      query.setFirstResult(0);
     156      query.setMaxResults(-1);
     157      Integer[] itemIds = Values.getInt(request.getParameter("items").split(","));
     158      query.restrict(
     159        Restrictions.in(
     160          Hql.property("id"),
     161          Expressions.parameter("selectedItems")
     162        )
     163      );
     164      query.setParameter("selectedItems", Arrays.asList(itemIds), Type.INT);     
     165    }
     166    else if ("all".equals(which))
     167    {
     168      query.setFirstResult(0);
     169      query.setMaxResults(-1);
     170    }
     171    int count = list.add(query.iterate(dc));
     172    dc.commit();
     173    message = count + " members added to list";
     174  }
     175  else if ("RemoveMembers".equals(cmd))
     176  {
     177    // Delete all selected items on the list page
     178    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, subContext, pageContext, defaultContext);
     179    for (int itemId : cc.getSelected())
     180    {
     181      list.remove((Listable)itemType.getById(dc, itemId));
     182    }
     183    dc.commit();
     184    redirect = listPage;
     185  }
     186
    237187  else
    238188  {
  • trunk/www/views/itemlists/members/members.js

    r6743 r6744  
    3838    Buttons.addClickHandler('btnImport', Buttons.runListPlugin, tableAttributes);
    3939    Buttons.addClickHandler('btnRunPlugin', Buttons.runListPlugin, tableAttributes);
     40    Buttons.addClickHandler('btnAddMembers', members.addMembersOnClick, tableAttributes);
     41    Buttons.addClickHandler('btnRemoveMembers', members.removeMembersOnClick, tableAttributes);
    4042
    4143    TabControl.setSwitchFunction('main', members.switchTab);
     
    5860  }
    5961 
     62  members.addMembersOnClick = function()
     63  {
     64    var frm = document.forms['members'];
     65    var url = 'add_members_frameset.jsp?ID='+App.getSessionId();
     66    url += '&list_id='+frm.list_id.value;
     67    Dialogs.openPopup(url, 'AddMembers', 1050, 700);
     68  }
     69 
     70  members.removeMembersOnClick = function()
     71  {
     72    var numSelected = Table.checkIfSelected('members');
     73    if (numSelected == 0) return;
     74   
     75    if (!confirm('You are about to remove '+numSelected+' item(s) from the list. Continue?'))
     76    {
     77      return;
     78    }
     79    var frm = document.forms['members'];
     80    frm.cmd.value = 'RemoveMembers';
     81    frm.submit();
     82  }
     83
    6084 
    6185 
Note: See TracChangeset for help on using the changeset viewer.