source: trunk/www/biomaterials/extracts/list_extracts.jsp @ 2893

Last change on this file since 2893 was 2893, checked in by Martin Svensson, 17 years ago

Fixes #428 HTML tags in annotation values are not escaped.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.8 KB
Line 
1<%-- $Id: list_extracts.jsp 2893 2006-11-10 09:35:34Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
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
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.Extract"
32  import="net.sf.basedb.core.LabeledExtract"
33  import="net.sf.basedb.core.Sample"
34  import="net.sf.basedb.core.BioMaterialEvent"
35  import="net.sf.basedb.core.AnnotationType"
36  import="net.sf.basedb.core.AnnotationSet"
37  import="net.sf.basedb.core.ItemQuery"
38  import="net.sf.basedb.core.Include"
39  import="net.sf.basedb.core.ItemResultIterator"
40  import="net.sf.basedb.core.ItemResultList"
41  import="net.sf.basedb.core.ItemContext"
42  import="net.sf.basedb.core.Permission"
43  import="net.sf.basedb.core.PluginDefinition"
44  import="net.sf.basedb.core.query.Hql"
45  import="net.sf.basedb.core.query.Restrictions"
46  import="net.sf.basedb.core.query.Expressions"
47  import="net.sf.basedb.core.query.Orders"
48  import="net.sf.basedb.core.plugin.GuiContext"
49  import="net.sf.basedb.core.plugin.Plugin"
50  import="net.sf.basedb.core.Type"
51  import="net.sf.basedb.util.Enumeration"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.ModeInfo"
54  import="net.sf.basedb.clients.web.PermissionUtil"
55  import="net.sf.basedb.clients.web.util.HTML"
56  import="net.sf.basedb.util.Values"
57  import="java.util.List"
58  import="java.util.Map"
59%>
60<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
61<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
62<%!
63  private static final Item itemType = Item.EXTRACT;
64  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
65%>
66<%
67final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
68final String ID = sc.getId();
69final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
70final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
71
72final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
73final String callback = request.getParameter("callback");
74final String title = mode.generateTitle("extract", "extracts");
75final DbControl dc = sc.newDbControl();
76ItemResultIterator<Extract> extracts = null;
77ItemResultList<AnnotationType> annotationTypes = null;
78try
79{
80  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
81  final ItemQuery<Extract> query = Base.getConfiguredQuery(cc, true, Extract.getQuery(), mode);
82  final boolean createLabeledExtractPermission = sc.hasPermission(Permission.CREATE, Item.LABELEDEXTRACT);
83  final ItemQuery<LabeledExtract> labeledExtractQuery = LabeledExtract.getQuery();
84  labeledExtractQuery.include(cc.getInclude());
85  labeledExtractQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter("extracts")));
86  labeledExtractQuery.order(Orders.asc(Hql.property("name"))); 
87
88  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
89  annotationTypes = annotationTypeQuery.list(dc);
90  try
91  {
92    extracts = query.iterate(dc);
93  }
94  catch (Throwable t)
95  {
96    cc.setMessage(t.getMessage());
97  }
98  int numListed = 0;
99  %>
100  <base:page title="<%=title==null ? "Extracts" : title%>" type="<%=mode.getPageType()%>">
101  <base:head scripts="menu.js,table.js" styles="menu.css,table.css">
102    <script language="JavaScript">
103    var submitPage = 'index.jsp';
104    var formId = 'extracts';
105    function newItem()
106    {
107      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true);
108    }
109    function newPooledItem()
110    {
111      Table.poolItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'NewPooledItem');
112    }
113    function editItem(itemId)
114    {
115      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
116    }
117    function viewItem(itemId)
118    {
119      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
120    }
121    function itemOnClick(evt, itemId)
122    {
123      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
124    }
125    function newLabeledExtract(extractId)
126    {
127      Main.viewOrEditItem('<%=ID%>', 'LABELEDEXTRACT', 0, true, '&extract_id='+extractId);
128    }
129    function deleteItems()
130    {
131      var frm = document.forms[formId];
132      if (Forms.numChecked(frm) == 0)
133      {
134        alert('Please select at least one item in the list');
135        return;
136      }
137      frm.action = submitPage;
138      frm.cmd.value = 'DeleteItems';
139      frm.submit();
140    }
141    function restoreItems()
142    {
143      var frm = document.forms[formId];
144      if (Forms.numChecked(frm) == 0)
145      {
146        alert('Please select at least one item in the list');
147        return;
148      }
149      frm.action = submitPage;
150      frm.cmd.value = 'RestoreItems';
151      frm.submit();
152    }
153    function shareItem(itemId)
154    {
155      Main.openPopup('index.jsp?ID=<%=ID%>&cmd=ShareItem&item_id='+itemId, 'ShareExtracts', 500, 400);
156    }
157    function shareItems()
158    {
159      Table.shareItems(submitPage, '<%=ID%>', formId, '<%=itemType.name()%>', 'ShareItems');
160    }
161    function configureColumns()
162    {
163      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
164    }
165    function runPlugin(cmd)
166    {
167      Table.submitToPopup(formId, cmd, 740, 540);
168    }
169    function returnSelected()
170    {
171      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
172      window.close();
173    }
174    function presetOnChange()
175    {
176      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
177    }
178    </script>
179  </base:head>
180 
181  <base:body>
182    <%
183    if (cc.getMessage() != null)
184    {
185      %>
186      <div class="error"><%=cc.getMessage()%></div>
187      <%
188      cc.setMessage(null);
189    }
190    %>
191    <tbl:table 
192      id="extracts" 
193      clazz="itemlist" 
194      columns="<%=cc.getSetting("columns")%>"
195      sortby="<%=cc.getSortProperty()%>" 
196      direction="<%=cc.getSortDirection()%>"
197      title="<%=title%>"
198      action="index.jsp"
199      sc="<%=sc%>"
200      item="<%=itemType%>"
201      >
202      <tbl:hidden 
203        name="mode" 
204        value="<%=mode.getName()%>" 
205      />
206      <tbl:hidden 
207        name="callback" 
208        value="<%=callback%>" 
209        skip="<%=callback == null%>" 
210      />
211      <tbl:columndef 
212        id="name"
213        property="name"
214        datatype="string"
215        title="Name"
216        sortable="true" 
217        filterable="true"
218        exportable="true"
219        show="always" 
220      />
221      <tbl:columndef 
222        id="externalId"
223        property="externalId"
224        datatype="string"
225        title="External id"
226        sortable="true" 
227        filterable="true"
228        exportable="true"
229      />
230      <tbl:columndef 
231        id="originalQuantity"
232        property="originalQuantity"
233        datatype="float"
234        title="Original quantity (µg)"
235        sortable="true" 
236        filterable="true"
237        exportable="true"
238      />
239      <tbl:columndef 
240        id="remainingQuantity"
241        property="remainingQuantity"
242        datatype="float"
243        title="Remaining quantity (µg)"
244        sortable="true" 
245        filterable="true"
246        exportable="true"
247      />
248      <tbl:columndef 
249        id="protocol"
250        property="creationEvent.protocol"
251        sortproperty="creationEvent.protocol.name"
252        filterproperty="creationEvent.protocol.name"
253        exportproperty="creationEvent.protocol.name"
254        datatype="string"
255        title="Protocol"
256        sortable="true" 
257        filterable="true"
258        exportable="true"
259      />
260      <tbl:columndef 
261        id="eventDate"
262        property="creationEvent.eventDate"
263        datatype="date"
264        title="Created"
265        sortable="true" 
266        filterable="true"
267        exportable="true"
268      />
269      <tbl:columndef 
270        id="entryDate"
271        property="creationEvent.entryDate"
272        datatype="date"
273        title="Registered"
274        sortable="true" 
275        filterable="true"
276        exportable="true"
277      />
278      <tbl:columndef 
279        id="pooled"
280        property="pooled"
281        datatype="boolean"
282        title="Pooled"
283        sortable="true" 
284        filterable="true"
285        exportable="true"
286      />
287      <tbl:columndef
288        id="parents"
289        title="Parents"
290      />
291      <tbl:columndef
292        id="labeledextracts"
293        title="Labeled extracts"
294      />
295      <tbl:columndef 
296        id="owner"
297        property="owner.name"
298        datatype="string"
299        title="Owner"
300        sortable="true" 
301        filterable="true"
302        exportable="true"
303      />
304      <tbl:columndef 
305        id="description"
306        property="description"
307        datatype="string"
308        title="Description" 
309        sortable="true" 
310        filterable="true" 
311        exportable="true"
312      />     
313      <%
314      for (AnnotationType at : annotationTypes)
315      {
316        Enumeration<String, String> annotationEnum = null;
317        if (at.isEnumeration())
318        {
319          annotationEnum = new Enumeration<String, String>();
320          List<?> values = at.getValues();
321          for (Object value : values)
322          {
323            String encoded = HTML.encodeTags(value.toString());
324            annotationEnum.add(encoded, encoded);
325          }
326        }
327        %>
328        <tbl:columndef 
329          id="<%="at"+at.getId()%>"
330          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
331          property="<%="#"+at.getId()%>"
332          annotation="true"
333          datatype="<%=at.getValueType().getStringValue()%>"
334          enumeration="<%=annotationEnum%>"
335          sortable="false" 
336          filterable="true" 
337          exportable="true"
338        />
339        <%
340      }
341      %>
342      <tbl:columndef
343        id="permission"
344        title="Permission"
345      />
346      <tbl:toolbar
347        visible="<%=mode.hasToolbar()%>"
348        >
349        <tbl:button 
350          disabled="<%=createPermission ? false : true%>" 
351          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
352          onclick="newItem()" 
353          title="New&hellip;" 
354          tooltip="<%=createPermission ? "Create new extract" : "You do not have permission to create extracts"%>" 
355        />
356        <tbl:button 
357          disabled="<%=createPermission ? false : true%>" 
358          image="<%=createPermission ? "new_pooled.gif" : "new_pooled_disabled.gif"%>" 
359          onclick="newPooledItem()" 
360          title="Pool&hellip;" 
361          tooltip="<%=createPermission ? "Create new pooled extract" : "You do not have permission to create extracts"%>" 
362        />
363        <tbl:button 
364          image="delete.gif"
365          onclick="deleteItems()" 
366          title="Delete" 
367          tooltip="Delete the selected items" 
368        />
369        <tbl:button 
370          image="restore.gif"
371          onclick="restoreItems()" 
372          title="Restore" 
373          tooltip="Restore the selected (deleted) items"
374        />
375        <tbl:button 
376          image="share.gif"
377          onclick="shareItems()" 
378          title="Share&hellip;" 
379          tooltip="Share the selected items"
380        />
381        <tbl:button 
382          image="columns.gif" 
383          onclick="configureColumns()" 
384          title="Columns&hellip;" 
385          tooltip="Show, hide and re-order columns" 
386        />
387        <tbl:button 
388          image="import.gif" 
389          onclick="runPlugin('ImportItems')" 
390          title="Import&hellip;" 
391          tooltip="Import data" 
392          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
393        />
394        <tbl:button 
395          image="export.gif" 
396          onclick="runPlugin('ExportItems')" 
397          title="Export&hellip;" 
398          tooltip="Export data" 
399          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
400        />
401        <tbl:button 
402          image="runplugin.gif" 
403          onclick="runPlugin('RunListPlugin')" 
404          title="Run plugin&hellip;" 
405          tooltip="Run a plugin" 
406          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
407        />
408      </tbl:toolbar>
409      <tbl:navigator
410        page="<%=cc.getPage()%>" 
411        rowsperpage="<%=cc.getRowsPerPage()%>" 
412        totalrows="<%=extracts == null ? 0 : extracts.getTotalCount()%>" 
413        visible="<%=mode.hasNavigator()%>"
414      />
415      <tbl:data>
416        <tbl:columns>
417        <tbl:presetselector 
418          clazz="columnheader"
419          colspan="3"
420          onchange="presetOnChange()"
421        />
422        </tbl:columns>
423
424        <tr>
425          <tbl:header 
426            clazz="index"
427            >&nbsp;</tbl:header>
428          <tbl:header 
429            clazz="check" 
430            visible="<%=mode.hasCheck()%>"
431            ><base:icon 
432              image="check_uncheck.gif" 
433              tooltip="Check/uncheck all" 
434              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
435            /></tbl:header>
436          <tbl:header 
437            clazz="check" 
438            visible="<%=mode.hasRadio()%>"
439            >&nbsp;</tbl:header>
440          <tbl:header 
441            clazz="icons" 
442            visible="<%=mode.hasIcons()%>"
443            >&nbsp;</tbl:header>
444          <tbl:propertyfilter />
445        </tr>
446         
447          <tbl:rows>
448          <%
449          int index = cc.getPage()*cc.getRowsPerPage();
450          int selectedItemId = cc.getId();
451          if (extracts != null)
452          {           
453            while (extracts.hasNext())
454            {
455              Extract item = extracts.next();
456              BioMaterialEvent creationEvent = item.getCreationEvent();
457              int itemId = item.getId();
458              boolean usePermission = item.hasPermission(Permission.USE);
459              String openSharePopup = "shareItem("+itemId+")";
460              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
461              boolean writePermission = item.hasPermission(Permission.WRITE);
462              String tooltip = mode.isSelectionMode() ? 
463                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
464              String name = HTML.encodeTags(item.getName());
465              index++;
466              numListed++;
467              %>
468              <tbl:row>
469                <tbl:header 
470                  clazz="index"
471                  ><%=index%></tbl:header>
472                <tbl:header 
473                  clazz="check" 
474                  visible="<%=mode.hasCheck()%>"
475                  ><input 
476                    type="checkbox" 
477                    name="<%=itemId%>" 
478                    value="<%=itemId%>" 
479                    title="<%=name%>" 
480                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
481                  ></tbl:header>
482                <tbl:header 
483                  clazz="check" 
484                  visible="<%=mode.hasRadio()%>"
485                  ><input 
486                    type="radio" 
487                    name="item_id" 
488                    value="<%=itemId%>" 
489                    title="<%=name%>" 
490                    <%=selectedItemId == itemId ? "checked" : ""%>
491                  ></tbl:header>
492                <tbl:header 
493                  clazz="icons" 
494                  visible="<%=mode.hasIcons()%>"
495                  ><base:icon 
496                    image="deleted.gif" 
497                    tooltip="This item has been scheduled for deletion" 
498                    visible="<%=item.isRemoved()%>"
499                  /><base:icon 
500                    image="<%=sharePermission ? "shared.gif" : "shared_disabled.gif"%>" 
501                    onclick="<%=sharePermission ? openSharePopup : null%>"
502                    tooltip="This item is shared to other users, groups and/or projects" 
503                    visible="<%=item.isShared()%>"
504                  />&nbsp;</tbl:header>
505                <tbl:cell column="name"><div class="link" 
506                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
507                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
508                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
509                <tbl:cell column="originalQuantity"><%=Values.formatNumber(item.getOriginalQuantity(), 2)%></tbl:cell>
510                <tbl:cell column="remainingQuantity"><%=Values.formatNumber(item.getRemainingQuantity(), 2)%></tbl:cell>
511                <tbl:cell column="pooled"><%=item.isPooled()%></tbl:cell>
512                <tbl:cell column="protocol"
513                  ><base:propertyvalue 
514                    item="<%=creationEvent%>" 
515                    property="protocol"
516                    enableEditLink="<%=mode.hasEditLink()%>" 
517                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
518                  /></tbl:cell>
519                <tbl:cell column="eventDate"><%=Values.formatDate(creationEvent.getEventDate())%></tbl:cell>
520                <tbl:cell column="entryDate"><%=Values.formatDate(creationEvent.getEntryDate())%></tbl:cell>
521                <tbl:cell column="parents">
522                  <%
523                  if (!item.isPooled())
524                  {
525                    %>
526                    <base:propertyvalue item="<%=item%>" property="parent"/>
527                    <%
528                  }
529                  else
530                  {
531                    String separator = "";
532                    ItemQuery<Extract> parentQuery  = (ItemQuery<Extract>)item.getCreationEvent().getSources();
533                    parentQuery.include(Include.MINE, Include.OTHERS, Include.IN_PROJECT, Include.SHARED);
534                    parentQuery.order(Orders.asc(Hql.property("name")));
535                   
536                    for (Extract e : parentQuery.list(dc))
537                    {
538                      out.write(separator);
539                      if (mode.hasPropertyLink())
540                      {
541                        out.write(Base.getLinkedName(ID, e, false, mode.hasEditLink()));
542                      }
543                      else
544                      {
545                        out.write(HTML.encodeTags(e.getName()));
546                      }
547                      separator = ", ";
548                    }
549                  }
550                  %>
551                </tbl:cell>
552                <tbl:cell column="labeledextracts">
553                  <%
554                  labeledExtractQuery.setParameter("extracts", itemId, Type.INT);
555                  try
556                  {
557                    String separator = "";
558                    for (LabeledExtract le : labeledExtractQuery.list(dc))
559                    {
560                      out.write(separator);
561                      if (mode.hasPropertyLink())
562                      {
563                        out.write(Base.getLinkedName(ID, le, false, mode.hasEditLink()));
564                      }
565                      else
566                      {
567                        out.write(HTML.encodeTags(le.getName()));
568                      }
569                      %>
570                      (<base:propertyvalue 
571                        item="<%=le%>" property="label" 
572                        enableEditLink="<%=mode.hasEditLink()%>" 
573                        enablePropertyLink="<%=mode.hasPropertyLink()%>"/>)
574                      <%
575                      separator = ", ";
576                    }
577                  }
578                  catch (Throwable t)
579                  {
580                    %>
581                    <div class="error"><%=t.getMessage()%></div>
582                    <%
583                  }
584                  %>
585                  <base:icon
586                    image="add.png"
587                    onclick="<%="newLabeledExtract("+itemId+")"%>"
588                    tooltip="Create a new labeled extract"
589                    visible="<%=mode.hasEditLink() && createLabeledExtractPermission && usePermission%>"
590                  /></tbl:cell>
591                <tbl:cell column="owner"
592                  ><base:propertyvalue 
593                    item="<%=item%>" 
594                    property="owner"
595                    enableEditLink="<%=mode.hasEditLink()%>" 
596                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
597                  /></tbl:cell>
598                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>               
599                <%
600                AnnotationSet as = item.isAnnotated() ? item.getAnnotationSet() : null;
601                for (AnnotationType at : annotationTypes)
602                {
603                  %>
604                  <tbl:cell column="<%="at"+at.getId()%>">
605                    <%
606                    List<?> values = as == null || !as.hasAnnotation(at) ? null : as.getAnnotation(at).getValues();
607                    %>
608                    <%=values == null || values.size() == 0 ? "" : HTML.encodeTags(Values.getString(values, ", ", true))%>
609                  </tbl:cell>
610                  <%
611                }
612                %>
613                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
614              </tbl:row>
615              <%
616              }
617            }
618          %>         
619          </tbl:rows>
620      </tbl:data>
621      <%
622      if (numListed == 0)
623      {
624        %>
625        <tbl:panel><%=extracts == null || extracts.getTotalCount() == 0 ? "No extracts where found" : "No extracts on this page. Please select another page!" %></tbl:panel>
626        <%
627      }
628      else
629      {
630        %>
631        <tbl:navigator
632          page="<%=cc.getPage()%>" 
633          rowsperpage="<%=cc.getRowsPerPage()%>" 
634          totalrows="<%=extracts == null ? 0 : extracts.getTotalCount()%>" 
635          visible="<%=mode.hasNavigator()%>"
636          locked="true"
637        />
638        <%
639      }
640      %>
641    </tbl:table>
642    <base:buttongroup align="center" clazz="fixedatbottom">
643      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
644      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
645      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
646    </base:buttongroup>
647    <br><br><br>
648  </base:body>
649  </base:page>
650  <%
651}
652finally
653{
654  if (extracts != null) extracts.close();
655  if (dc != null) dc.close();
656}
657%>
Note: See TracBrowser for help on using the repository browser.