source: trunk/www/biomaterials/samples/list_samples.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: 29.8 KB
Line 
1<%-- $Id: list_samples.jsp 5674 2011-06-27 12:29:52Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.Sample"
31  import="net.sf.basedb.core.Extract"
32  import="net.sf.basedb.core.BioPlate"
33  import="net.sf.basedb.core.BioSource"
34  import="net.sf.basedb.core.BioMaterialEvent"
35  import="net.sf.basedb.core.BioWell"
36  import="net.sf.basedb.core.AnnotationType"
37  import="net.sf.basedb.core.ItemSubtype"
38  import="net.sf.basedb.core.AnnotationSet"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.Include"
41  import="net.sf.basedb.core.ItemResultIterator"
42  import="net.sf.basedb.core.ItemResultList"
43  import="net.sf.basedb.core.ItemContext"
44  import="net.sf.basedb.core.Nameable"
45  import="net.sf.basedb.core.Permission"
46  import="net.sf.basedb.core.PermissionDeniedException"
47  import="net.sf.basedb.core.PlateGeometry"
48  import="net.sf.basedb.core.PluginDefinition"
49  import="net.sf.basedb.core.Annotation"
50  import="net.sf.basedb.core.Quantity"
51  import="net.sf.basedb.core.Unit"
52  import="net.sf.basedb.core.query.Hql"
53  import="net.sf.basedb.core.query.Restrictions"
54  import="net.sf.basedb.core.query.Expressions"
55  import="net.sf.basedb.core.query.Orders"
56  import="net.sf.basedb.core.plugin.GuiContext"
57  import="net.sf.basedb.core.plugin.Plugin"
58  import="net.sf.basedb.core.Type"
59  import="net.sf.basedb.util.Enumeration"
60  import="net.sf.basedb.util.ShareableUtil"
61  import="net.sf.basedb.util.units.UnitUtil"
62  import="net.sf.basedb.clients.web.Base"
63  import="net.sf.basedb.clients.web.ModeInfo"
64  import="net.sf.basedb.clients.web.PermissionUtil"
65  import="net.sf.basedb.clients.web.util.HTML"
66  import="net.sf.basedb.util.Values"
67  import="net.sf.basedb.util.formatter.Formatter"
68  import="net.sf.basedb.util.formatter.WellCoordinateFormatter"
69  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
70  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
71  import="net.sf.basedb.clients.web.extensions.JspContext"
72  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
73  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
74  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
75  import="java.util.Iterator" 
76  import="java.util.List"
77  import="java.util.Map"
78  import="java.util.Date"
79%>
80<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
81<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
82<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
83<%!
84  private static final Item itemType = Item.SAMPLE;
85  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
86%>
87<%
88final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
89final String ID = sc.getId();
90final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
91final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
92
93final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
94final String callback = request.getParameter("callback");
95final String title = mode.generateTitle("sample", "samples");
96final DbControl dc = sc.newDbControl();
97ItemResultIterator<Sample> samples = null;
98ItemResultList<AnnotationType> annotationTypes = null;
99try
100{
101  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
102  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
103 
104  // Child extracts
105  final ItemQuery<Extract> extractQuery = Extract.getQuery();
106  extractQuery.include(cc.getInclude());
107  extractQuery.restrict(Restrictions.eq(Hql.property("parent"), Hql.entityParameter("sample", Item.SAMPLE)));
108  extractQuery.order(Orders.asc(Hql.property("name")));
109  final boolean createExtractPermission = sc.hasPermission(Permission.CREATE, Item.EXTRACT);
110
111  // Child samples
112  final 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"), Hql.entityParameter("sample", Item.SAMPLE)));
116  childSamplesQuery.order(Orders.asc(Hql.property("name")));
117  childSamplesQuery.include(cc.getInclude());
118 
119  // Parent samples
120  final ItemQuery<Sample> parentSamplesQuery = Sample.getQuery();
121  parentSamplesQuery.join(Hql.innerJoin("childCreationEvents", "cce"));
122  parentSamplesQuery.join(Hql.innerJoin("cce", "event", "evt"));
123  parentSamplesQuery.restrict(Restrictions.eq(Hql.alias("evt"), Hql.entityParameter("creationEvent", Item.BIOMATERIALEVENT)));
124  parentSamplesQuery.order(Orders.asc(Hql.property("name")));
125  parentSamplesQuery.include(cc.getInclude());
126
127  Unit microGram = UnitUtil.getUnit(dc, Quantity.MASS, "µg");
128  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
129  annotationTypes = annotationTypeQuery.list(dc);
130  try
131  {
132    final ItemQuery<Sample> query = Base.getConfiguredQuery(dc, cc, true, Sample.getQuery(), mode);
133    samples = query.iterate(dc);
134  }
135  catch (Throwable t)
136  {
137    cc.setMessage(t.getMessage());
138    t.printStackTrace();
139  }
140  int numListed = 0;
141  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
142  WellCoordinateFormatter rowFormatter = new WellCoordinateFormatter(true);
143  WellCoordinateFormatter columnFormatter = new WellCoordinateFormatter(false);
144 
145  Enumeration<String, String> wellRows = new Enumeration<String, String>();
146  ItemQuery<PlateGeometry> geometryQuery = PlateGeometry.getQuery(); 
147  geometryQuery.order(Orders.desc(Hql.property("rows")));
148  ItemResultIterator<PlateGeometry> result = geometryQuery.iterate(dc);
149  int maxRows = result.next().getRows();
150  for (int r = 0; r < maxRows; r++)
151  {
152    wellRows.add(Integer.toString(r), rowFormatter.format(r));
153  }
154  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
155  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
156  %>
157  <base:page title="<%=title==null ? "Samples" : title%>" type="<%=mode.getPageType()%>">
158  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
159    <ext:scripts context="<%=jspContext%>" />
160    <ext:stylesheets context="<%=jspContext%>" />
161    <script language="JavaScript">
162    var submitPage = 'index.jsp';
163    var formId = 'samples';
164    function newItem()
165    {
166      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
167    }
168    function newPooledItem()
169    {
170      Table.poolItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'NewPooledItem');
171    }
172    function editItem(itemId)
173    {
174      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
175    }
176    function viewItem(itemId)
177    {
178      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
179    }
180    function itemOnClick(evt, itemId)
181    {
182      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
183    }
184    function newSample(sampleId)
185    {
186      Main.viewOrEditItem('<%=ID%>', 'SAMPLE', 0, true, '&sample_id='+sampleId);
187    }
188    function newExtract(sampleId)
189    {
190      Main.viewOrEditItem('<%=ID%>', 'EXTRACT', 0, true, '&sample_id='+sampleId);
191    }
192    function deleteItems()
193    {
194      var frm = document.forms[formId];
195      if (Forms.numChecked(frm) == 0)
196      {
197        alert('Please select at least one item in the list');
198        return;
199      }
200      frm.action = submitPage;
201      frm.cmd.value = 'DeleteItems';
202      frm.submit();
203    }
204    function restoreItems()
205    {
206      var frm = document.forms[formId];
207      if (Forms.numChecked(frm) == 0)
208      {
209        alert('Please select at least one item in the list');
210        return;
211      }
212      frm.action = submitPage;
213      frm.cmd.value = 'RestoreItems';
214      frm.submit();
215    }
216    function deleteItemPermanently(itemId)
217    {
218      Main.deleteItemPermanently('<%=ID%>', true, '<%=itemType.name()%>', itemId);
219    }
220    function setOwner()
221    {
222      Table.setOwnerOfItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'SetOwnerOfItems');
223    }
224    function shareItem(itemId)
225    {
226      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareSamples', 600, 400);
227    }
228    function shareItems()
229    {
230      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
231    }
232    function configureColumns()
233    {
234      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
235    }
236    function runPlugin(cmd)
237    {
238      Table.submitToPopup(formId, cmd, 740, 540);
239    }
240    function returnSelected()
241    {
242      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
243      window.close();
244    }
245    function presetOnChange()
246    {
247      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
248    }
249    function newBioMaterialList()
250    {
251      var controller = Main.getController('BIOMATERIALLIST');
252      Table.submitToPopup(formId, 'CreateBioMaterialList', controller.width, controller.height);
253    }
254    function placeOnPlate()
255    {
256      Table.submitToPopup(formId, 'PlaceOnPlate', 900, 600);
257    }
258    </script>
259  </base:head>
260 
261  <base:body>
262    <%
263    if (cc.getMessage() != null)
264    {
265      %>
266      <div class="error"><%=cc.getMessage()%></div>
267      <%
268      cc.setMessage(null);
269    }
270    %>
271    <tbl:table 
272      id="samples" 
273      clazz="itemlist" 
274      columns="<%=cc.getSetting("columns")%>"
275      sortby="<%=cc.getSortProperty()%>" 
276      direction="<%=cc.getSortDirection()%>"
277      title="<%=title%>"
278      action="index.jsp"
279      sc="<%=sc%>"
280      item="<%=itemType%>"
281      >
282      <tbl:hidden 
283        name="mode" 
284        value="<%=mode.getName()%>" 
285      />
286      <tbl:hidden 
287        name="callback" 
288        value="<%=callback%>" 
289        skip="<%=callback == null%>" 
290      />
291      <tbl:columndef 
292        id="name"
293        property="name"
294        datatype="string"
295        title="Name"
296        sortable="true" 
297        filterable="true"
298        exportable="true"
299        show="always" 
300      />
301      <tbl:columndef 
302        id="itemSubtype"
303        property="itemSubtype"
304        sortproperty="itemSubtype.name"
305        exportproperty="itemSubtype.name:string"
306        datatype="int"
307        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
308        title="Type"
309        sortable="true" 
310        filterable="true"
311        exportable="true"
312      />
313      <tbl:columndef 
314        id="id"
315        clazz="uniquecol"
316        property="id"
317        datatype="int"
318        title="ID"
319        sortable="true" 
320        filterable="true"
321        exportable="true" 
322      />
323      <tbl:columndef 
324        id="externalId"
325        property="externalId"
326        datatype="string"
327        title="External id"
328        sortable="true" 
329        filterable="true"
330        exportable="true"
331      />     
332      <tbl:columndef 
333        id="originalQuantity"
334        property="originalQuantity"
335        datatype="float"
336        title="Original quantity (µg)"
337        sortable="true" 
338        filterable="true"
339        exportable="true"
340        unit="<%=microGram%>"
341      />
342      <tbl:columndef 
343        id="remainingQuantity"
344        property="remainingQuantity"
345        datatype="float"
346        title="Remaining quantity (µg)"
347        sortable="true" 
348        filterable="true"
349        exportable="true"
350        unit="<%=microGram%>"
351      />
352      <tbl:columndef 
353        id="protocol"
354        property="creationEvent.protocol"
355        sortproperty="creationEvent.protocol.name"
356        filterproperty="creationEvent.protocol.name"
357        exportproperty="creationEvent.protocol.name"
358        datatype="string"
359        title="Protocol"
360        sortable="true" 
361        filterable="true"
362        exportable="true"
363      />
364      <tbl:columndef 
365        id="eventDate"
366        property="creationEvent.eventDate"
367        datatype="date"
368        title="Created"
369        sortable="true" 
370        filterable="true"
371        exportable="true"
372        formatter="<%=dateFormatter%>"
373      />
374      <tbl:columndef 
375        id="entryDate"
376        property="creationEvent.entryDate"
377        datatype="date"
378        title="Registered"
379        sortable="true" 
380        filterable="true"
381        exportable="true"
382        formatter="<%=dateFormatter%>"
383      />
384      <%
385      Enumeration<String, String> parentTypes = new Enumeration<String, String>();
386      parentTypes.add("", "-none-");
387      parentTypes.add(Integer.toString(Item.BIOSOURCE.getValue()), Item.BIOSOURCE.toString());
388      parentTypes.add(Integer.toString(Item.SAMPLE.getValue()), Item.SAMPLE.toString());
389      %>
390      <tbl:columndef
391        id="parentType"
392        title="Parent type"
393        property="parentType"
394        enumeration="<%=parentTypes%>"
395        datatype="int"
396        filterable="true"
397        exportable="true"
398        sortable="true"
399      />
400      <tbl:columndef
401        id="parents"
402        title="Parent items"
403        property="&creationEvent.sources(bioMaterial.name)"
404        sortproperty="parent.name"
405        datatype="string"
406        filterable="true"
407        exportable="true"
408        sortable="true"
409      />
410      <tbl:columndef
411        id="children"
412        title="Child samples"
413        property="&childCreationEvents(event.bioMaterial.name)"
414        datatype="string"
415        filterable="true"
416        exportable="true"
417      />
418      <tbl:columndef
419        id="extracts"
420        title="Extracts"
421        property="&children(name)"
422        datatype="string"
423        filterable="true"
424        exportable="true"
425      />
426      <tbl:columndef 
427        id="bioPlate"
428        property="bioWell.bioPlate.name"
429        sortproperty="bioWell.bioPlate.name"
430        filterproperty="bioWell.bioPlate.name"
431        exportproperty="bioWell.bioPlate.name"
432        datatype="string"
433        title="Bioplate"
434        sortable="true" 
435        filterable="true"
436        exportable="true"
437      />
438      <tbl:columndef 
439        id="bioWellRow"
440        property="bioWell.row"
441        sortproperty="bioWell.row"
442        datatype="int"
443        title="Biowell row" 
444        filterable="true"
445        enumeration="<%=wellRows%>"
446        exportable="true"
447        sortable="true"
448        formatter="<%=rowFormatter%>"
449      />
450      <tbl:columndef 
451        id="bioWellColumn"
452        property="bioWell.column"
453        sortproperty="bioWell.column"
454        datatype="int"
455        title="Biowell column"   
456        filterable="true"
457        exportable="true"
458        sortable="true"
459        formatter="<%=columnFormatter%>"
460      />     
461      <tbl:columndef 
462        id="owner"
463        property="owner.name"
464        datatype="string"
465        title="Owner"
466        sortable="true" 
467        filterable="true"
468        exportable="true"
469      />
470      <tbl:columndef 
471        id="description"
472        property="description"
473        datatype="string"
474        title="Description" 
475        sortable="true" 
476        filterable="true" 
477        exportable="true"
478      />     
479      <tbl:columndef
480        id="bioMaterialList"
481        property="@bioMaterialLists"
482        datatype="int"
483        title="Biomaterial list"
484        filterable="true"
485        enumeration="<%=Base.getBioMaterialListsEnum(dc, itemType, cc.getInclude())%>"
486        multiple="false"
487      />
488      <%
489      for (AnnotationType at : annotationTypes)
490      {
491        Enumeration<String, String> annotationEnum = null;
492        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
493        if (at.isEnumeration())
494        {
495          annotationEnum = new Enumeration<String, String>();
496          List<?> values = at.getValues();
497          for (Object value : values)
498          {
499            String encoded = formatter.format(value);
500            annotationEnum.add(encoded, encoded);
501          }
502        }
503        %>
504        <tbl:columndef 
505          id="<%="at"+at.getId()%>"
506          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
507          property="<%="#"+at.getId()%>"
508          annotation="true"
509          datatype="<%=at.getValueType().getStringValue()%>"
510          enumeration="<%=annotationEnum%>"
511          smartenum="<%=at.getDisplayAsList() %>"
512          sortable="false" 
513          filterable="true" 
514          exportable="true"
515          formatter="<%=formatter%>"
516          unit="<%=at.getDefaultUnit()%>"
517        />
518        <%
519      }
520      %>
521      <tbl:columndef
522        id="permission"
523        title="Permission"
524      />
525      <tbl:columndef
526        id="sharedTo"
527        title="Shared to"
528        filterable="true"
529        filterproperty="!sharedTo.name"
530        datatype="string"
531      />
532      <tbl:toolbar
533        visible="<%=mode.hasToolbar()%>"
534        >
535        <tbl:button 
536          disabled="<%=createPermission ? false : true%>" 
537          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
538          onclick="newItem()" 
539          title="New&hellip;" 
540          tooltip="<%=createPermission ? "Create new sample" : "You do not have permission to create samples"%>" 
541        />
542        <tbl:button 
543          disabled="<%=createPermission ? false : true%>" 
544          image="<%=createPermission ? "new_pooled.gif" : "new_pooled_disabled.gif"%>" 
545          onclick="newPooledItem()" 
546          title="Pool&hellip;" 
547          tooltip="<%=createPermission ? "Create new pooled sample" : "You do not have permission to create samples"%>" 
548        />
549        <tbl:button 
550          image="delete.gif"
551          onclick="deleteItems()" 
552          title="Delete" 
553          tooltip="Delete the selected items" 
554        />
555        <tbl:button 
556          image="restore.gif"
557          onclick="restoreItems()" 
558          title="Restore" 
559          tooltip="Restore the selected (deleted) items"
560        />
561        <tbl:button 
562          image="share.gif"
563          onclick="shareItems()" 
564          title="Share&hellip;" 
565          tooltip="Share the selected items"
566        />
567        <tbl:button 
568          image="take_ownership.png"
569          onclick="setOwner()" 
570          title="Set owner&hellip;"
571          tooltip="Change owner of the selected items"
572        />
573        <tbl:button 
574          image="columns.gif" 
575          onclick="configureColumns()" 
576          title="Columns&hellip;" 
577          tooltip="Show, hide and re-order columns" 
578        />
579        <tbl:button
580          image="add.png"
581          onclick="newBioMaterialList()"
582          title="New biomaterial list&hellip;"
583          tooltip="Create a new biomaterial list from matching samples"
584          visible="<%=sc.hasPermission(Permission.CREATE, Item.BIOMATERIALLIST)%>"
585        />
586        <tbl:button 
587          image="place_on_plate.png" 
588          onclick="placeOnPlate()" 
589          title="Place on plate&hellip;" 
590          tooltip="Place the selected/matching samples on a bioplate" 
591        />
592        <tbl:button 
593          image="import.gif" 
594          onclick="runPlugin('ImportItems')" 
595          title="Import&hellip;" 
596          tooltip="Import data" 
597          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
598        />
599        <tbl:button 
600          image="export.gif" 
601          onclick="runPlugin('ExportItems')" 
602          title="Export&hellip;" 
603          tooltip="Export data" 
604          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
605        />
606        <tbl:button 
607          image="runplugin.gif" 
608          onclick="runPlugin('RunListPlugin')" 
609          title="Run plugin&hellip;" 
610          tooltip="Run a plugin" 
611          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
612        />
613        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
614          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
615      </tbl:toolbar>
616      <tbl:navigator
617        page="<%=cc.getPage()%>" 
618        rowsperpage="<%=cc.getRowsPerPage()%>" 
619        totalrows="<%=samples == null ? 0 : samples.getTotalCount()%>" 
620        visible="<%=mode.hasNavigator()%>"
621      />
622      <tbl:data>
623        <tbl:columns>
624        <tbl:presetselector 
625          clazz="columnheader"
626          colspan="3"
627          onchange="presetOnChange()"
628        />
629        </tbl:columns>
630
631        <tr>
632          <tbl:header 
633            clazz="index"
634            >&nbsp;</tbl:header>
635          <tbl:header 
636            clazz="check" 
637            visible="<%=mode.hasCheck()%>"
638            ><base:icon 
639              image="check_uncheck.gif" 
640              tooltip="Check/uncheck all" 
641              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
642            /></tbl:header>
643          <tbl:header 
644            clazz="check" 
645            visible="<%=mode.hasRadio()%>"
646            >&nbsp;</tbl:header>
647          <tbl:header 
648            clazz="icons" 
649            visible="<%=mode.hasIcons()%>"
650            >&nbsp;</tbl:header>
651          <tbl:propertyfilter />
652        </tr>
653         
654          <tbl:rows>
655          <%
656          int index = cc.getPage()*cc.getRowsPerPage();
657          int selectedItemId = cc.getId();
658          if (samples != null)
659          {           
660            while (samples.hasNext())
661            {
662              Sample item = samples.next();
663              Item parentType = item.getParentType();
664              BioMaterialEvent creationEvent = item.getCreationEvent();
665              int itemId = item.getId();
666              boolean usePermission = item.hasPermission(Permission.USE);
667              String openSharePopup = "shareItem("+itemId+")";
668              String deletePermanently = "deleteItemPermanently("+itemId+")";
669              boolean deletePermission = item.hasPermission(Permission.DELETE);
670              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
671              boolean writePermission = item.hasPermission(Permission.WRITE);
672              String tooltip = mode.isSelectionMode() ?
673                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
674              String name = HTML.encodeTags(item.getName());
675              index++;
676              numListed++;
677              %>
678              <tbl:row>
679                <tbl:header 
680                  clazz="index"
681                  ><%=index%></tbl:header>
682                <tbl:header 
683                  clazz="check" 
684                  visible="<%=mode.hasCheck()%>"
685                  ><input 
686                    type="checkbox" 
687                    name="<%=itemId%>" 
688                    value="<%=itemId%>" 
689                    title="<%=name%>" 
690                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
691                  ></tbl:header>
692                <tbl:header 
693                  clazz="check" 
694                  visible="<%=mode.hasRadio()%>"
695                  ><input 
696                    type="radio" 
697                    name="item_id" 
698                    value="<%=itemId%>" 
699                    title="<%=name%>" 
700                    <%=selectedItemId == itemId ? "checked" : ""%>
701                  ></tbl:header>
702                <tbl:header 
703                  clazz="icons" 
704                  visible="<%=mode.hasIcons()%>"
705                  ><base:icon 
706                    image="<%=deletePermission ? "deleted.gif" : "deleted_disabled.gif"%>"
707                    onclick="<%=deletePermission ? deletePermanently : null%>"
708                    tooltip="This item has been scheduled for deletion" 
709                    visible="<%=item.isRemoved()%>"
710                  /><base:icon 
711                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
712                    onclick="<%=sharePermission ? openSharePopup : null%>"
713                    tooltip="This item is shared to other users, groups and/or projects" 
714                    visible="<%=item.isShared()%>"
715                  />&nbsp;</tbl:header>
716                <tbl:cell column="name"><div class="link" 
717                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)"
718                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
719                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
720                <tbl:cell column="itemSubtype"><base:propertyvalue 
721                    item="<%=item%>" 
722                    property="itemSubtype"
723                    enableEditLink="<%=mode.hasEditLink()%>" 
724                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
725                  /></tbl:cell>
726                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>               
727                <tbl:cell column="originalQuantity"><%=Values.formatNumber(item.getOriginalQuantity(), 2)%></tbl:cell>
728                <tbl:cell column="remainingQuantity"><%=Values.formatNumber(item.getRemainingQuantity(), 2)%></tbl:cell>
729                <tbl:cell column="protocol"
730                  ><base:propertyvalue 
731                    item="<%=creationEvent%>" 
732                    property="protocol"
733                    enableEditLink="<%=mode.hasEditLink()%>" 
734                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
735                  /></tbl:cell>
736                <%               
737                BioWell well = null;
738                boolean readBioWell = true;
739                try
740                {
741                  well = item.getBioWell();
742                }
743                catch(PermissionDeniedException e)
744                {
745                  readBioWell = false;
746                }
747                if (!readBioWell)
748                {
749                  %>
750                  <tbl:cell column="bioWellRow"><i>- denied -</i> </tbl:cell>
751                  <tbl:cell column="bioWellColumn"><i>- denied -</i> </tbl:cell>
752                  <tbl:cell column="bioPlate"><i>- denied -</i> </tbl:cell>
753                  <%
754                }
755                else if (well == null)
756                {
757                  %>
758                  <tbl:cell column="bioWellRow"><i>- none -</i> </tbl:cell>
759                  <tbl:cell column="bioWellColumn"><i>- none -</i> </tbl:cell>
760                  <tbl:cell column="bioPlate"><i>- none -</i> </tbl:cell>
761                  <%
762                 
763                }
764                else
765                {               
766                  %>
767                  <tbl:cell column="bioWellRow">
768                    <tbl:cellvalue value="<%=well.getRow()%>"/>
769                  </tbl:cell>
770                  <tbl:cell column="bioWellColumn">
771                    <tbl:cellvalue value="<%=well.getColumn()%>"/>
772                  </tbl:cell>
773                  <tbl:cell column="bioPlate"><%=Base.getLinkedName(ID, well.getPlate(), false, true)%></tbl:cell>
774                  <%
775                }
776                %>
777                <tbl:cell column="eventDate" value="<%=creationEvent.getEventDate()%>" />
778                <tbl:cell column="entryDate" value="<%=creationEvent.getEntryDate()%>" />
779                <tbl:cell column="parentType"><%=parentType == null ? "" : parentType.toString() %></tbl:cell>
780                <tbl:cell column="parents">
781                  <%
782                  if (item.hasSingleParent() || parentType == null)
783                  {
784                    %>
785                    <base:propertyvalue item="<%=item%>" property="parent"/>
786                    <%
787                  }
788                  else
789                  {
790                    String separator = "";
791                    parentSamplesQuery.setEntityParameter("creationEvent", creationEvent);
792                    for (Sample s : parentSamplesQuery.list(dc))
793                    {
794                      out.write(separator);
795                      if (mode.hasPropertyLink())
796                      {
797                        out.write(Base.getLinkedName(ID, s, false, mode.hasEditLink()));
798                      }
799                      else
800                      {
801                        out.write(HTML.encodeTags(s.getName()));
802                      }
803                      separator = ", ";
804                    }
805                  }
806                  %>
807                  <%=parentType != null ? "<span class=\"itemtype\">(" + parentType + ")</span>" : "" %>
808                </tbl:cell>
809                <tbl:cell column="children">
810                  <%
811                  childSamplesQuery.setEntityParameter("sample", item);
812                  String separator = "";
813                  for (Sample s : childSamplesQuery.list(dc))
814                  {
815                    out.write(separator);
816                    if (mode.hasPropertyLink())
817                    {
818                      out.write(Base.getLinkedName(ID, s, false, mode.hasEditLink()));
819                    }
820                    else
821                    {
822                      out.write(HTML.encodeTags(s.getName()));
823                    }
824                    separator = ", ";
825                  }
826                  %>
827                  <base:icon
828                    image="add.png" 
829                    onclick="<%="newSample("+itemId+")"%>" 
830                    tooltip="Create new child sample" 
831                    visible="<%=mode.hasEditLink() && createPermission && usePermission %>"
832                  />
833                </tbl:cell>
834                <tbl:cell column="extracts">
835                  <%
836                  extractQuery.setEntityParameter("sample", item);
837                  try
838                  {
839                    String separator = "";
840                    for(Extract e : extractQuery.list(dc))
841                    {
842                      out.write(separator);
843                      if (mode.hasPropertyLink())
844                      {
845                        out.write(Base.getLinkedName(ID, e, false, mode.hasEditLink()));
846                      }
847                      else
848                      {
849                        out.write(HTML.encodeTags(e.getName()));
850                      }
851                      separator = ", ";
852                    }
853                  }
854                  catch (Throwable t)
855                  {
856                    %>
857                    <div class="error"><%=t.getMessage()%></div>
858                    <%
859                  }
860                  %>
861                  <base:icon
862                    image="add.png" 
863                    onclick="<%="newExtract("+itemId+")"%>" 
864                    tooltip="Create new extract" 
865                    visible="<%=mode.hasEditLink() && createExtractPermission && usePermission %>"
866                  />
867                </tbl:cell>
868                <tbl:cell column="owner"
869                  ><base:propertyvalue 
870                    item="<%=item%>" 
871                    property="owner"
872                    enableEditLink="<%=mode.hasEditLink()%>" 
873                    enablePropertyLink="<%=mode.hasPropertyLink()%>" 
874                  /></tbl:cell>
875                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>               
876                <%
877                AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
878                if (as != null)
879                {
880                  for (AnnotationType at : annotationTypes)
881                  {
882                    if (as.hasAnnotation(at))
883                    {
884                      Annotation a = as.getAnnotation(at);
885                      String suffix = a.getUnitSymbol(null);
886                      if (suffix != null) suffix = "&nbsp;" + suffix;
887                      %>
888                      <tbl:cell 
889                        column="<%="at"+at.getId()%>"
890                        ><tbl:cellvalue 
891                          list="<%=a.getValues(null)%>"
892                          suffix="<%=suffix%>"
893                      /></tbl:cell>
894                      <%
895                    }
896                  }
897                }
898                %>
899                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
900                <tbl:cell column="sharedTo">
901                  <%
902                  Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator();
903                  while(sharees.hasNext())
904                  {
905                    Nameable n = sharees.next();
906                    if (mode.hasPropertyLink())
907                    {
908                      out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
909                    }
910                    else
911                    {
912                      out.write(HTML.encodeTags(n.getName()));
913                    }
914                    out.write(sharees.hasNext() ? ", " : "");
915                  }
916                  %>
917                </tbl:cell>
918              </tbl:row>
919              <%
920              }
921            }
922          %>
923          </tbl:rows>
924      </tbl:data>
925      <%
926      if (numListed == 0)
927      {
928        %>
929        <tbl:panel><%=samples == null || samples.getTotalCount() == 0 ? "No samples were found" : "No samples on this page. Please select another page!" %></tbl:panel>
930        <%
931      }
932      else
933      {
934        %>
935        <tbl:navigator
936          page="<%=cc.getPage()%>" 
937          rowsperpage="<%=cc.getRowsPerPage()%>" 
938          totalrows="<%=samples == null ? 0 : samples.getTotalCount()%>" 
939          visible="<%=mode.hasNavigator()%>"
940          locked="true"
941        />
942        <%
943      }
944      %>
945    </tbl:table>
946    <base:buttongroup align="center" clazz="fixedatbottom">
947      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
948      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
949      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
950    </base:buttongroup>
951    <br><br><br>
952  </base:body>
953  </base:page>
954  <%
955}
956finally
957{
958  if (samples != null) samples.close();
959  if (dc != null) dc.close();
960}
961%>
Note: See TracBrowser for help on using the repository browser.