source: trunk/www/biomaterials/lists/members/list_members.jsp @ 5674

Last change on this file since 5674 was 5674, checked in by Nicklas Nordborg, 12 years ago

Fixes #1611: Checkbox enabled lists for enumerated annotations

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.4 KB
Line 
1<%-- $Id: list_members.jsp 5674 2011-06-27 12:29:52Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2008 Nicklas Nordborg
4 
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7 
8  BASE is free software; you can redistribute it and/or modify it
9  under the terms of the GNU General Public License as published by
10  the Free Software Foundation; either version 3 of the License, or
11  (at your option) any later version.
12 
13  BASE is distributed in the hope that it will be useful, but
14  WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.10
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.SystemItems"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.ItemContext"
31  import="net.sf.basedb.core.ItemQuery"
32  import="net.sf.basedb.core.ItemResultList"
33  import="net.sf.basedb.core.ItemResultIterator"
34  import="net.sf.basedb.core.BioMaterialList"
35  import="net.sf.basedb.core.BioMaterial"
36  import="net.sf.basedb.core.AnnotationSet"
37  import="net.sf.basedb.core.Annotation"
38  import="net.sf.basedb.core.AnnotationType"
39  import="net.sf.basedb.core.PluginDefinition"
40  import="net.sf.basedb.core.Permission"
41  import="net.sf.basedb.core.Nameable"
42  import="net.sf.basedb.core.query.Orders"
43  import="net.sf.basedb.core.query.Hql"
44  import="net.sf.basedb.core.plugin.GuiContext"
45  import="net.sf.basedb.core.plugin.Plugin"
46  import="net.sf.basedb.util.Enumeration"
47  import="net.sf.basedb.util.ShareableUtil"
48  import="net.sf.basedb.clients.web.PermissionUtil"
49  import="net.sf.basedb.clients.web.Base"
50  import="net.sf.basedb.clients.web.ModeInfo"
51  import="net.sf.basedb.clients.web.util.HTML"
52  import="net.sf.basedb.util.Values"
53  import="net.sf.basedb.util.formatter.Formatter"
54  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
55  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
56  import="net.sf.basedb.clients.web.extensions.JspContext"
57  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
58  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
59  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
60  import="java.util.Date"
61  import="java.util.Map"
62  import="java.util.List"
63  import="java.util.Iterator"
64%>
65<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
66<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
67<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
68<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
69<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
70<%
71final int bioMaterialListId = Values.getInt(request.getParameter("list_id"));
72final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, Item.BIOMATERIALLIST);
73final String ID = sc.getId();
74final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
75final String callback = request.getParameter("callback");
76final String title = mode.generateTitle("member", "members");
77final DbControl dc = sc.newDbControl();
78
79ItemResultIterator<? extends BioMaterial> members = null;
80try
81{
82  final BioMaterialList list = BioMaterialList.getById(dc, bioMaterialListId);
83  final Item itemType = list.getMemberType();
84  final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST, "listmembers");
85  final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, "listmembers", null, null);
86
87  final boolean addPermission = list.hasPermission(Permission.WRITE);
88  final boolean removePermission = addPermission;
89
90  final Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
91  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
92  final ItemResultList<AnnotationType> annotationTypes = annotationTypeQuery.list(dc);
93  try
94  {
95    final ItemQuery<? extends BioMaterial> query = list.getMemberBioMaterials();
96    cc.configureQuery(dc, query, true);
97    members = query.iterate(dc);
98  }
99  catch (Throwable t)
100  {
101    cc.setMessage(t.getMessage());
102    t.printStackTrace();
103  }
104  int numListed = 0;
105  Formatter<Date> dateFormatter = FormatterFactory.getDateTimeFormatter(sc);
106  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, list);
107  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
108  %>
109  <base:page title="<%=title%>" type="<%=mode.getPageType()%>">
110  <base:head scripts="table.js,tabcontrol.js" styles="table.css,headertabcontrol.css,path.css">
111    <ext:scripts context="<%=jspContext%>" />
112    <ext:stylesheets context="<%=jspContext%>" />
113    <script language="JavaScript">
114    var submitPage = 'index.jsp';
115    var formId = 'members';
116    function editItem(itemId)
117    {
118      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
119    }
120    function viewItem(itemId)
121    {
122      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
123    }
124    function itemOnClick(evt, itemId)
125    {
126      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
127    }
128    function addItems()
129    {
130      Main.openPopup('add_members_frameset.jsp?ID=<%=ID%>&list_id=<%=bioMaterialListId%>', 'AddMembers', 1000, 700);
131    }
132    function removeItems()
133    {
134      var frm = document.forms[formId];
135      var numChecked = Forms.numChecked(frm);
136      if (numChecked == 0)
137      {
138        alert('Please select at least one item in the list');
139        return;
140      }
141      else
142      {
143        if (!confirm('You are about to remove '+numChecked+' item(s) from the list. Continue?'))
144        {
145          return;
146        }
147      }
148      frm.action = submitPage;
149      frm.cmd.value = 'RemoveMembers';
150      frm.submit();
151    }
152    function deleteItems()
153    {
154      var frm = document.forms[formId];
155      if (Forms.numChecked(frm) == 0)
156      {
157        alert('Please select at least one item in the list');
158        return;
159      }
160      frm.action = submitPage;
161      frm.cmd.value = 'DeleteItems';
162      frm.submit();
163    }
164    function restoreItems()
165    {
166      var frm = document.forms[formId];
167      if (Forms.numChecked(frm) == 0)
168      {
169        alert('Please select at least one item in the list');
170        return;
171      }
172      frm.action = submitPage;
173      frm.cmd.value = 'RestoreItems';
174      frm.submit();
175    }
176    function configureColumns()
177    {
178      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
179    }
180    function deleteItemPermanently(itemId)
181    {
182      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', itemId);
183    }
184    function setOwner()
185    {
186      Table.setOwnerOfItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'SetOwnerOfItems');
187    }
188    function shareItem(itemId)
189    {
190      Main.openPopup('index.jsp?ID=<%=ID%>&list_id=<%=bioMaterialListId%>&cmd=ShareItem&item_id='+itemId, 'ShareItem', 600, 400);
191    }
192    function shareItems()
193    {
194      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
195    }
196    function runPlugin(cmd)
197    {
198      Table.submitToPopup(formId, cmd, 740, 540);
199    }
200    function returnSelected()
201    {
202      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
203      window.close();
204    }
205    function presetOnChange()
206    {
207      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
208    }
209    function switchTab(tabControlId, tabId)
210    {
211      if (tabId == 'properties')
212      {
213        location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=bioMaterialListId%>&tab='+tabId;
214      }
215      else
216      {
217        TabControl.setActiveTab(tabControlId, tabId);
218      }
219    }
220    function placeOnPlate()
221    {
222      Table.submitToPopup(formId, 'PlaceOnPlate', 900, 600);
223    }
224    </script>
225  </base:head>
226 
227  <base:body>
228  <p>
229    <p:path>
230      <p:pathelement title="Biomaterial lists" href="<%="../index.jsp?ID="+ID%>" />
231      <p:pathelement title="<%=HTML.encodeTags(list.getName())%>" />
232    </p:path>
233 
234    <t:tabcontrol id="main" active="members" switch="switchTab">
235    <t:tab id="properties" title="Properties" />
236   
237    <t:tab id="members" title="Members">
238
239    <%
240    if (cc.getMessage() != null)
241    {
242      %>
243      <div class="error"><%=cc.getMessage()%></div>
244      <%
245      cc.setMessage(null);
246    }
247    %>
248    <tbl:table 
249      id="members" 
250      clazz="itemlist" 
251      columns="<%=cc.getSetting("columns")%>"
252      sortby="<%=cc.getSortProperty()%>" 
253      direction="<%=cc.getSortDirection()%>"
254      title="<%=title%>"
255      action="index.jsp"
256      sc="<%=sc%>"
257      item="<%=itemType%>"
258      subcontext="listmembers"
259      >
260      <tbl:hidden 
261        name="mode" 
262        value="<%=mode.getName()%>" 
263      />
264      <tbl:hidden 
265        name="callback" 
266        value="<%=callback%>" 
267        skip="<%=callback == null%>" 
268      />
269      <tbl:hidden 
270        name="list_id" 
271        value="<%=String.valueOf(bioMaterialListId)%>" 
272      />
273      <tbl:columndef 
274        id="name"
275        property="name"
276        datatype="string"
277        title="Name"
278        sortable="true" 
279        filterable="true"
280        exportable="true"
281        show="always" 
282      />
283      <tbl:columndef 
284         id="id"
285        clazz="uniquecol"
286         property="id"
287         datatype="int"
288         title="ID"
289         sortable="true" 
290         filterable="true"
291         exportable="true"
292      />
293      <tbl:columndef 
294        id="externalId"
295        property="externalId"
296        datatype="string"
297        title="External id"
298        sortable="true" 
299        filterable="true"
300        exportable="true"
301      />
302      <tbl:columndef 
303        id="owner"
304        property="owner.name"
305        datatype="string"
306        title="Owner"
307        sortable="true" 
308        filterable="true"
309        exportable="true"
310      />
311      <tbl:columndef 
312        id="description"
313        property="description"
314        datatype="string"
315        title="Description" 
316        sortable="true" 
317        filterable="true" 
318        exportable="true"
319      />     
320      <%
321      for (AnnotationType at : annotationTypes)
322      {
323        Enumeration<String, String> annotationEnum = null;
324        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
325        if (at.isEnumeration())
326        {
327          annotationEnum = new Enumeration<String, String>();
328          List<?> values = at.getValues();
329          for (Object value : values)
330          {
331            String encoded = formatter.format(value);
332            annotationEnum.add(encoded, encoded);
333          }
334        }
335        %>
336        <tbl:columndef 
337          id="<%="at"+at.getId()%>"
338          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
339          property="<%="#"+at.getId()%>"
340          annotation="true"
341          datatype="<%=at.getValueType().getStringValue()%>"
342          enumeration="<%=annotationEnum%>"
343          smartenum="<%=at.getDisplayAsList() %>"
344          sortable="false" 
345          filterable="true" 
346          exportable="true"
347          formatter="<%=formatter%>"
348          unit="<%=at.getDefaultUnit()%>"
349        />
350        <%
351      }
352      %>
353      <tbl:columndef
354        id="permission"
355        title="Permission"
356      />
357      <tbl:columndef
358        id="sharedTo"
359        title="Shared to"
360        filterable="true"
361        filterproperty="!sharedTo.name"
362        datatype="string"
363      />
364      <tbl:toolbar
365        visible="<%=mode.hasToolbar()%>"
366        >
367        <tbl:button 
368          disabled="<%=addPermission ? false : true%>" 
369          image="<%=addPermission ? "add.png" : "add_disabled.png"%>" 
370          onclick="addItems()" 
371          title="Add&hellip;" 
372          tooltip="<%=addPermission ? "Add more biomaterials to this list" : "You do not have permission to add biomaterial" %>" 
373        />
374        <tbl:button 
375          disabled="<%=removePermission ? false : true%>" 
376          image="<%=removePermission ? "remove.png" : "remove_disabled.png"%>" 
377          onclick="removeItems()" 
378          title="Remove&hellip;" 
379          tooltip="<%=removePermission ? "Remove the selected items from this list" : "You do not have permission to remove items" %>" 
380        />
381        <tbl:button 
382          image="delete.gif"
383          onclick="deleteItems()" 
384          title="Delete" 
385          tooltip="Delete the selected items" 
386        />
387        <tbl:button 
388          image="restore.gif"
389          onclick="restoreItems()" 
390          title="Restore" 
391          tooltip="Restore the selected (deleted) items"
392        />
393        <tbl:button 
394          image="share.gif"
395          onclick="shareItems()" 
396          title="Share&hellip;" 
397          tooltip="Share the selected items"
398        />
399        <tbl:button 
400          image="take_ownership.png"
401          onclick="setOwner()" 
402          title="Set owner&hellip;"
403          tooltip="Change owner of the selected items"
404        />
405        <tbl:button 
406          image="columns.gif" 
407          onclick="configureColumns()" 
408          title="Columns&hellip;" 
409          tooltip="Show, hide and re-order columns" 
410        />
411        <tbl:button 
412          image="place_on_plate.png" 
413          onclick="placeOnPlate()" 
414          title="Place on plate&hellip;" 
415          tooltip="Place the selected/matching biomaterial on a bioplate" 
416          visible="<%=itemType != Item.BIOSOURCE%>"
417        />
418        <tbl:button 
419          image="import.gif" 
420          onclick="runPlugin('ImportItems')" 
421          title="Import&hellip;" 
422          tooltip="Import data" 
423          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
424        />
425        <tbl:button 
426          image="export.gif" 
427          onclick="runPlugin('ExportItems')" 
428          title="Export&hellip;" 
429          tooltip="Export data" 
430          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
431        />
432        <tbl:button 
433          image="runplugin.gif" 
434          onclick="runPlugin('RunListPlugin')" 
435          title="Run plugin&hellip;" 
436          tooltip="Run a plugin" 
437          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
438        />
439        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
440          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
441      </tbl:toolbar>
442      <tbl:navigator
443        page="<%=cc.getPage()%>" 
444        rowsperpage="<%=cc.getRowsPerPage()%>" 
445        totalrows="<%=members == null ? 0 : members.getTotalCount()%>" 
446        visible="<%=mode.hasNavigator()%>"
447      />
448      <tbl:data>
449        <tbl:columns>
450        <tbl:presetselector 
451          clazz="columnheader"
452          colspan="3"
453          onchange="presetOnChange()"
454        />
455        </tbl:columns>
456        <tr>
457          <tbl:header 
458            clazz="index"
459            >&nbsp;</tbl:header>
460          <tbl:header 
461            clazz="check" 
462            visible="<%=mode.hasCheck()%>"
463            ><base:icon 
464              image="check_uncheck.gif" 
465              tooltip="Check/uncheck all" 
466              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
467            /></tbl:header>
468          <tbl:header 
469            clazz="check" 
470            visible="<%=mode.hasRadio()%>"
471            >&nbsp;</tbl:header>
472          <tbl:header 
473            clazz="icons" 
474            visible="<%=mode.hasIcons()%>"
475            >&nbsp;</tbl:header>
476          <tbl:propertyfilter />
477        </tr>
478          <tbl:rows>
479          <%
480          int index = cc.getPage()*cc.getRowsPerPage();
481          int selectedItemId = cc.getId();
482          if (members != null)
483          {           
484            while (members.hasNext())
485            {
486              BioMaterial item = members.next();
487              int itemId = item.getId();
488              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
489              boolean writePermission = item.hasPermission(Permission.WRITE);
490              String openSharePopup = "shareItem("+itemId+")";
491              String deletePermanently = "deleteItemPermanently("+itemId+")";
492              boolean deletePermission = item.hasPermission(Permission.DELETE);
493              String name = HTML.encodeTags(item.getName());
494              String tooltip = mode.isSelectionMode() ?
495                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
496              index++;
497              numListed++;
498              %>
499              <tbl:row>
500                <tbl:header 
501                  clazz="index"
502                  ><%=index%></tbl:header>
503                <tbl:header 
504                  clazz="check" 
505                  visible="<%=mode.hasCheck()%>"
506                  ><input 
507                    type="checkbox" 
508                    name="<%=itemId%>" 
509                    value="<%=itemId%>" 
510                    title="<%=name%>" 
511                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
512                  ></tbl:header>
513                <tbl:header 
514                  clazz="check" 
515                  visible="<%=mode.hasRadio()%>"
516                  ><input 
517                    type="radio" 
518                    name="item_id" 
519                    value="<%=itemId%>" 
520                    title="<%=name%>" 
521                    <%=selectedItemId == itemId ? "checked" : ""%>
522                  ></tbl:header>
523                <tbl:header 
524                  clazz="icons" 
525                  visible="<%=mode.hasIcons()%>"
526                  ><base:icon 
527                    image="<%=deletePermission ? "deleted.gif" : "deleted_disabled.gif"%>"
528                    onclick="<%=deletePermission ? deletePermanently : null%>"
529                    tooltip="This item has been scheduled for deletion" 
530                    visible="<%=item.isRemoved()%>"
531                  /><base:icon 
532                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
533                    onclick="<%=sharePermission ? openSharePopup : null%>"
534                    tooltip="This item is shared to other users, groups and/or projects" 
535                    visible="<%=item.isShared()%>"
536                  />&nbsp;</tbl:header>
537                <tbl:cell column="name"><div class="link" 
538                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
539                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
540                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
541                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
542                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>
543                <tbl:cell column="owner"
544                  ><base:propertyvalue 
545                    item="<%=item%>" 
546                    property="owner"
547                    enableEditLink="<%=mode.hasEditLink()%>" 
548                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
549                  /></tbl:cell>
550                <%
551                AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
552                if (as != null)
553                {
554                  for (AnnotationType at : annotationTypes)
555                  {
556                    if (as.hasAnnotation(at))
557                    {
558                      Annotation a = as.getAnnotation(at);
559                      String suffix = a.getUnitSymbol(null);
560                      if (suffix != null) suffix = "&nbsp;" + suffix;
561                      %>
562                      <tbl:cell 
563                        column="<%="at"+at.getId()%>"
564                        ><tbl:cellvalue 
565                          list="<%=a.getValues(null)%>"
566                          suffix="<%=suffix%>"
567                      /></tbl:cell>
568                      <%
569                    }
570                  }
571                }
572                %>
573                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
574                <tbl:cell column="sharedTo">
575                  <%
576                  Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator();
577                  while(sharees.hasNext())
578                  {
579                    Nameable n = sharees.next();
580                    if (mode.hasPropertyLink())
581                    {
582                      out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
583                    }
584                    else
585                    {
586                      out.write(HTML.encodeTags(n.getName()));
587                    }
588                    out.write(sharees.hasNext() ? ", " : "");
589                  }
590                  %>
591                </tbl:cell>
592              </tbl:row>
593              <%
594            }
595          }
596          %>
597          </tbl:rows>
598      </tbl:data>
599      <%
600      if (numListed == 0)
601      {
602        %>
603        <tbl:panel><%=members == null || members.getTotalCount() == 0 ? "No members were found" : "No members on this page. Please select another page!" %></tbl:panel>
604        <%
605      }
606      else
607      {
608        %>
609        <tbl:navigator
610          page="<%=cc.getPage()%>" 
611          rowsperpage="<%=cc.getRowsPerPage()%>" 
612          totalrows="<%=members == null ? 0 : members.getTotalCount()%>" 
613          visible="<%=mode.hasNavigator()%>"
614          locked="true"
615        />
616        <%
617      }
618      %>
619    </tbl:table>
620    <base:buttongroup align="center" clazz="fixedatbottom">
621      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
622      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
623      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
624    </base:buttongroup>
625
626    </t:tab>
627    </t:tabcontrol>
628
629  </base:body>
630  </base:page>
631  <%
632}
633finally
634{
635  if (members != null) members.close();
636  if (dc != null) dc.close();
637}
638%>
Note: See TracBrowser for help on using the repository browser.