source: trunk/www/biomaterials/biosources/list_biosources.jsp @ 6605

Last change on this file since 6605 was 6605, checked in by Nicklas Nordborg, 9 years ago

References #1890: Improve skinnability of BASE

Updated regular view pages and edit dialogs.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 19.3 KB
Line 
1<%-- $Id: list_biosources.jsp 6605 2014-11-18 12:48:42Z 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.BioSource"
31  import="net.sf.basedb.core.Sample"
32  import="net.sf.basedb.core.AnnotationType"
33  import="net.sf.basedb.core.ItemSubtype"
34  import="net.sf.basedb.core.AnnotationSet"
35  import="net.sf.basedb.core.Annotation"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.Include"
38  import="net.sf.basedb.core.ItemResultIterator"
39  import="net.sf.basedb.core.ItemResultList"
40  import="net.sf.basedb.core.ItemContext"
41  import="net.sf.basedb.core.Nameable"
42  import="net.sf.basedb.core.Permission"
43  import="net.sf.basedb.core.PluginDefinition"
44  import="net.sf.basedb.core.Type"
45  import="net.sf.basedb.core.query.Hql"
46  import="net.sf.basedb.core.query.Restrictions"
47  import="net.sf.basedb.core.query.Expressions"
48  import="net.sf.basedb.core.query.Orders"
49  import="net.sf.basedb.core.plugin.GuiContext"
50  import="net.sf.basedb.core.plugin.Plugin"
51  import="net.sf.basedb.core.snapshot.AnnotationLoaderUtil"
52  import="net.sf.basedb.core.snapshot.AnnotationTypeFilter"
53  import="net.sf.basedb.core.snapshot.AnnotationSnapshot"
54  import="net.sf.basedb.core.snapshot.AnnotationSetSnapshot"
55  import="net.sf.basedb.core.snapshot.SnapshotManager"
56  import="net.sf.basedb.util.Enumeration"
57  import="net.sf.basedb.util.ShareableUtil"
58  import="net.sf.basedb.clients.web.Base"
59  import="net.sf.basedb.clients.web.ModeInfo"
60  import="net.sf.basedb.clients.web.PermissionUtil"
61  import="net.sf.basedb.clients.web.util.HTML"
62  import="net.sf.basedb.util.formatter.Formatter"
63  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
64  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
65  import="net.sf.basedb.clients.web.extensions.JspContext"
66  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
67  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
68  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
69  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
70  import="net.sf.basedb.util.Values"
71  import="java.util.Iterator"
72  import="java.util.Date"
73  import="java.util.List"
74  import="java.util.Map"
75  import="java.util.ArrayList"
76%>
77<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
78<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
79<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
80<%!
81  private static final Item itemType = Item.BIOSOURCE;
82  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
83%>
84<%
85final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
86final String ID = sc.getId();
87final boolean createPermission = sc.hasPermission(Permission.CREATE, itemType);
88final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
89
90final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
91final String callback = request.getParameter("callback");
92final String title = mode.generateTitle("biosource", "biosources");
93final DbControl dc = sc.newDbControl();
94ItemResultIterator<BioSource> bioSources = null;
95List<AnnotationLoaderUtil> annotationLoaders = new ArrayList<AnnotationLoaderUtil>();
96try
97{
98  final ItemQuery<AnnotationType> annotationTypeQuery = Base.getAnnotationTypesQuery(itemType);
99  SnapshotManager manager = new SnapshotManager();
100  for (AnnotationType at : annotationTypeQuery.list(dc))
101  {
102    annotationLoaders.add(new AnnotationLoaderUtil(dc, manager, at));
103  }
104  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
105
106  final ItemQuery<Sample> sampleQuery = Sample.getQuery();
107  sampleQuery.include(cc.getInclude());
108  sampleQuery.restrict(Restrictions.eq(Hql.property("parent"), Expressions.parameter("bioSource")));
109  sampleQuery.order(Orders.asc(Hql.property("name")));
110  final boolean createSamplePermission = sc.hasPermission(Permission.CREATE, Item.SAMPLE);
111
112  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
113  try
114  {
115    final ItemQuery<BioSource> query = Base.getConfiguredQuery(dc, cc, true, BioSource.getQuery(), mode);
116    bioSources = query.iterate(dc);
117  }
118  catch (Throwable t)
119  {
120    cc.setMessage(t.getMessage());
121    t.printStackTrace();
122  }
123  int numListed = 0;
124  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
125  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, null);
126  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
127  ExtensionsInvoker columnsInvoker = ListColumnUtil.useExtensions(jspContext);
128  %>
129  <base:page title="<%=title==null ? "Biosources" : title%>" type="<%=mode.getPageType()%>" id="list-page">
130  <base:head scripts="table.js,~biosources.js" styles="table.css,toolbar.css">
131    <ext:scripts context="<%=jspContext%>" />
132    <ext:stylesheets context="<%=jspContext%>" />
133  </base:head>
134 
135  <base:body >
136    <h1><%=title==null ? "Biosources" : title%></h1>
137    <div class="content">
138      <tbl:table 
139        id="biosources" 
140        columns="<%=cc.getSetting("columns")%>"
141        sortby="<%=cc.getSortProperty()%>" 
142        direction="<%=cc.getSortDirection()%>"
143        action="index.jsp"
144        sc="<%=sc%>"
145        item="<%=itemType%>"
146        subclass="fulltable"
147      >
148      <tbl:hidden 
149        name="mode" 
150        value="<%=mode.getName()%>" 
151      />
152      <tbl:hidden 
153        name="callback" 
154        value="<%=callback%>" 
155        skip="<%=callback == null%>" 
156      />
157      <tbl:columndef 
158        id="name"
159        property="name"
160        datatype="string"
161        title="Name"
162        sortable="true" 
163        filterable="true"
164        exportable="true"
165        show="always" 
166      />
167      <tbl:columndef 
168        id="itemSubtype"
169        property="itemSubtype"
170        sortproperty="itemSubtype.name"
171        exportproperty="itemSubtype.name:string"
172        datatype="int"
173        enumeration="<%=Enumeration.fromItems(subtypesQuery.list(dc), "-none-")%>"
174        title="Type"
175        sortable="true" 
176        filterable="true"
177        exportable="true"
178      />
179      <tbl:columndef 
180         id="id"
181        clazz="uniquecol"
182         property="id"
183         datatype="int"
184         title="ID"
185         sortable="true" 
186         filterable="true"
187         exportable="true"
188      />
189      <tbl:columndef 
190        id="externalId"
191        property="externalId"
192        datatype="string"
193        title="External id"
194        sortable="true" 
195        filterable="true"
196        exportable="true"
197      />
198      <tbl:columndef 
199        id="entryDate"
200        property="entryDate"
201        datatype="date"
202        title="Registered"
203        sortable="true" 
204        filterable="true"
205        exportable="true"
206        formatter="<%=dateFormatter%>"
207      />
208      <tbl:columndef
209        id="samples"
210        title="Samples"
211        property="&children(name)"
212        datatype="string"
213        filterable="true"
214        exportable="true"
215      />
216      <tbl:columndef 
217        id="owner"
218        property="owner.name"
219        datatype="string"
220        title="Owner"
221        sortable="true" 
222        filterable="true"
223        exportable="true"
224      />
225      <tbl:columndef 
226        id="description"
227        property="description"
228        datatype="string"
229        title="Description" 
230        sortable="true" 
231        filterable="true" subclass="foobar"
232        exportable="true"
233      />     
234      <tbl:columndef
235        id="bioMaterialList"
236        property="@bioMaterialLists"
237        datatype="int"
238        title="Biomaterial list"
239        filterable="true" 
240        enumeration="<%=Base.getBioMaterialListsEnum(dc, itemType, cc.getInclude())%>"
241        multiple="false"
242      />
243      <%
244      for (AnnotationLoaderUtil loader : annotationLoaders)
245      {
246        AnnotationType at = loader.getAnnotationType();
247        Enumeration<String, String> annotationEnum = null;
248        Formatter formatter = FormatterFactory.getTypeFormatter(sc, at.getValueType());
249        if (at.isEnumeration())
250        {
251          annotationEnum = new Enumeration<String, String>();
252          List<?> values = at.getValues();
253          for (Object value : values)
254          {
255            String encoded = formatter.format(value);
256            annotationEnum.add(encoded, encoded);
257          }
258        }
259        %>
260        <tbl:columndef 
261          id="<%="at"+at.getId()%>"
262          title="<%=HTML.encodeTags(at.getName())+" [A]"%>" 
263          property="<%="#"+at.getId()%>"
264          annotation="true"
265          datatype="<%=at.getValueType().getStringValue()%>"
266          enumeration="<%=annotationEnum%>"
267          smartenum="<%=at.getDisplayAsList() %>"
268          sortable="<%=at.getMultiplicity() == 1%>" 
269          filterable="true" 
270          exportable="true"
271          formatter="<%=formatter%>"
272          unit="<%=at.getDefaultUnit()%>"
273        />
274        <%
275      }
276      %>
277      <tbl:columndef
278        id="permission"
279        title="Permission"
280      />
281      <tbl:columndef
282        id="sharedTo"
283        title="Shared to"
284        filterable="true"
285        filterproperty="!sharedTo.name"
286        datatype="string"
287      />
288      <tbl:columndef 
289        id="xt-columns" 
290        extensions="<%=columnsInvoker%>" 
291        jspcontext="<%=jspContext%>" 
292      />
293      <div class="panelgroup bg-filled-50 bottomborder">
294        <tbl:toolbar
295          visible="<%=mode.hasToolbar()%>"
296          subclass="bottomborder"
297          >
298          <tbl:button 
299            id="btnNewItem"
300            disabled="<%=!createPermission%>" 
301            image="new.png" 
302            title="New&hellip;" 
303            tooltip="<%=createPermission ? "Create new biosource" : "You do not have permission to create biosources"%>" 
304          />
305          <tbl:button 
306            id="btnDeleteItems"
307            image="delete.png"
308            title="Delete" 
309            tooltip="Delete the selected items" 
310          />
311          <tbl:button 
312            id="btnRestoreItems"
313            image="restore.png"
314            title="Restore" 
315            tooltip="Restore the selected (deleted) items"
316          />
317          <tbl:button 
318            id="btnShareItems"
319            image="share.png"
320            title="Share&hellip;" 
321            tooltip="Share the selected items"
322          />
323          <tbl:button 
324            id="btnSetOwner"
325            image="take_ownership.png"
326            title="Set owner&hellip;"
327            tooltip="Change owner of the selected items"
328          />
329          <tbl:button 
330            id="btnColumns"
331            image="columns.png" 
332            title="Columns&hellip;" 
333            tooltip="Show, hide and re-order columns" 
334          />
335          <tbl:button
336            id="btnNewBioMaterialList"
337            image="add.png"
338            title="New biomaterial list&hellip;"
339            tooltip="Create a new biomaterial list from matching biosources"
340            visible="<%=sc.hasPermission(Permission.CREATE, Item.BIOMATERIALLIST)%>"
341          />
342          <tbl:button 
343            id="btnImport"
344            data-plugin-type="IMPORT"
345            image="import.png" 
346            title="Import&hellip;" 
347            tooltip="Import data" 
348            visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
349          />
350          <tbl:button 
351            id="btnExport"
352            data-plugin-type="EXPORT"
353            image="export.png" 
354            title="Export&hellip;" 
355            tooltip="Export data" 
356            visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
357          />
358          <tbl:button 
359            id="btnRunPlugin"
360            data-plugin-type="OTHER"
361            image="runplugin.png" 
362            title="Run plugin&hellip;" 
363            tooltip="Run a plugin" 
364            visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
365          />
366          <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
367            wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
368        </tbl:toolbar>
369        <tbl:panel>
370          <tbl:presetselector />
371          <tbl:navigator
372            page="<%=cc.getPage()%>" 
373            rowsperpage="<%=cc.getRowsPerPage()%>" 
374            totalrows="<%=bioSources == null ? 0 : bioSources.getTotalCount()%>" 
375            visible="<%=mode.hasNavigator()%>"
376          />
377        </tbl:panel>
378      </div>
379      <tbl:data>
380        <tbl:headers>
381          <tbl:headerrow>
382            <tbl:header colspan="3" />
383            <tbl:columnheaders />
384          </tbl:headerrow>
385          <tbl:headerrow>
386            <tbl:header subclass="index" />
387            <tbl:header 
388              subclass="check" 
389              visible="<%=mode.hasCheck()%>"
390              ><base:icon 
391                id="check.uncheck"
392                image="check_uncheck.png" 
393                tooltip="Check/uncheck all" 
394              /></tbl:header>
395            <tbl:header 
396              subclass="check" 
397              visible="<%=mode.hasRadio()%>"
398              />
399            <tbl:header 
400              subclass="icons" 
401              visible="<%=mode.hasIcons()%>"
402              />
403            <tbl:propertyfilter />
404          </tbl:headerrow>
405        </tbl:headers>
406        <tbl:rows>
407          <%
408          if (cc.getMessage() != null)
409          {
410            %>
411            <tbl:panel subclass="bg-filled-50">
412              <div class="messagecontainer error"><%=cc.getMessage()%></div>
413            </tbl:panel>
414            <%
415            cc.setMessage(null);
416          }
417          int index = cc.getPage()*cc.getRowsPerPage();
418          int selectedItemId = cc.getId();
419          if (bioSources != null)
420          {           
421            while (bioSources.hasNext())
422            {
423              BioSource item = bioSources.next();
424              int itemId = item.getId();
425              boolean usePermission = item.hasPermission(Permission.USE);
426             
427             
428              boolean deletePermission = item.hasPermission(Permission.DELETE);
429              boolean sharePermission = item.hasPermission(Permission.SET_PERMISSION);
430              boolean writePermission = item.hasPermission(Permission.WRITE);
431              String tooltip = mode.isSelectionMode() ? 
432                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
433              String name = HTML.encodeTags(item.getName());
434              index++;
435              numListed++;
436              %>
437              <tbl:row>
438                <tbl:header 
439                  clazz="index"
440                  ><%=index%></tbl:header>
441                <tbl:header 
442                  clazz="check" 
443                  visible="<%=mode.hasCheck()%>"
444                  ><input 
445                    type="checkbox" 
446                    name="<%=itemId%>" 
447                    value="<%=itemId%>" 
448                    title="<%=name%>" 
449                    <%=cc.getSelected().contains(itemId) ? "checked" : ""%> 
450                  ></tbl:header>
451                <tbl:header 
452                  clazz="check" 
453                  visible="<%=mode.hasRadio()%>"
454                  ><input 
455                    type="radio" 
456                    name="item_id" 
457                    value="<%=itemId%>" 
458                    title="<%=name%>" 
459                    <%=selectedItemId == itemId ? "checked" : ""%>
460                  ></tbl:header>
461                <tbl:header 
462                  clazz="icons" 
463                  visible="<%=mode.hasIcons()%>"
464                  ><base:icon 
465                    image="deleted.png"
466                    id="<%="delete."+itemId %>"
467                    subclass="<%=deletePermission ? "table-delete-item" : null %>"
468                    data-item-id="<%=itemId%>"
469                    tooltip="This item has been scheduled for deletion" 
470                    visible="<%=item.isRemoved()%>"
471                  /><base:icon 
472                    image="shared.png" 
473                    id="<%="share."+itemId %>"
474                    subclass="<%=sharePermission ? "table-share-item" : null %>"
475                    data-item-id="<%=itemId%>"
476                    tooltip="This item is shared to other users, groups and/or projects" 
477                    visible="<%=item.isShared()%>"
478                  />&nbsp;</tbl:header>
479                <tbl:cell column="name"><div 
480                  class="link table-item"
481                  data-item-id="<%=itemId%>"
482                  data-no-edit="<%=writePermission ? 0 : 1 %>" 
483                  tabindex="0"
484                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
485                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
486                <tbl:cell column="itemSubtype"><base:propertyvalue 
487                    item="<%=item%>" 
488                    property="itemSubtype"
489                    enableEditLink="<%=mode.hasEditLink()%>" 
490                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
491                  /></tbl:cell>
492                <tbl:cell column="externalId"><%=HTML.encodeTags(item.getExternalId())%></tbl:cell>
493                <tbl:cell column="samples">
494                  <%
495                  sampleQuery.setParameter("bioSource", itemId, Type.INT);
496                  try
497                  {
498                    String separator = "";
499                    for (Sample s : sampleQuery.list(dc))
500                    {
501                      out.write(separator);
502                      if (mode.hasPropertyLink())
503                      {
504                        out.write(Base.getLinkedName(ID, s, false, mode.hasEditLink()));
505                      }
506                      else
507                      {
508                        out.write(HTML.encodeTags(s.getName()));
509                      }
510                      separator = ", ";
511                    }
512                  }
513                  catch (Throwable t)
514                  {
515                    %>
516                    <div class="error"><%=t.getMessage()%></div>
517                    <%
518                  }
519                  %>
520                  <base:icon
521                    id="<%="newsample."+itemId%>"
522                    image="add.png" 
523                    subclass="auto-init"
524                    data-auto-init="new-sample"
525                    data-item-id="<%=itemId %>"
526                    tooltip="Create new sample" 
527                    visible="<%=mode.hasEditLink() && createSamplePermission && usePermission %>"
528                  />
529                </tbl:cell>
530                <tbl:cell column="owner"
531                  ><base:propertyvalue 
532                    item="<%=item%>" 
533                    property="owner"
534                    enableEditLink="<%=mode.hasEditLink()%>" 
535                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
536                  /></tbl:cell>
537                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
538                <tbl:cell column="description"><%=HTML.encodeTags(item.getDescription())%></tbl:cell>               
539                <%
540                if (item.isAnnotated())
541                {
542                  AnnotationSetSnapshot snapshot = manager.getSnapshot(dc, item.getAnnotationSet().getId());
543                  for (AnnotationLoaderUtil loader : annotationLoaders)
544                  {
545                    if (loader.find(snapshot))
546                    {
547                      %>
548                      <tbl:cell 
549                        column="<%="at"+loader.getId()%>"
550                        ><tbl:cellvalue 
551                          list="<%=loader.getValues()%>"
552                          suffix="<%=loader.getUnitSymbol()%>"
553                      /></tbl:cell>
554                      <%
555                    }
556                  }
557                }
558                %>
559                <tbl:cell column="permission"><%=PermissionUtil.getShortPermissions(item)%></tbl:cell>
560                <tbl:cell column="sharedTo">
561                  <%
562                  Iterator<Nameable> sharees = ShareableUtil.getSharedTo(dc, item).iterator();
563                  while(sharees.hasNext())
564                  {
565                    Nameable n = sharees.next();
566                    if (mode.hasPropertyLink())
567                    {
568                      out.write(Base.getLinkedName(ID, n, false, mode.hasEditLink()));
569                    }
570                    else
571                    {
572                      out.write(HTML.encodeTags(n.getName()));
573                    }
574                    out.write(sharees.hasNext() ? ", " : "");
575                  }
576                  %>
577                </tbl:cell>
578                <tbl:xt-cells dc="<%=dc%>" item="<%=item%>">
579                  <tbl:cell column="xt-columns" />
580                </tbl:xt-cells>
581              </tbl:row>
582              <%
583              }
584            }
585            if (numListed == 0)
586            {
587              %>
588              <tbl:panel subclass="bg-filled-50">
589                <div class="messagecontainer note">
590                <%=bioSources == null || bioSources.getTotalCount() == 0 ? "No biosources were found" : "No biosources on this page. Please select another page!" %>
591                </div>
592              </tbl:panel>
593              <%
594            }
595          %>
596        </tbl:rows>
597      </tbl:data>
598    </tbl:table>
599    </div>
600
601    <base:buttongroup subclass="dialogbuttons">
602      <base:button id="btnOk" title="Ok" visible="<%=mode.hasOkButton()%>" />
603      <base:button id="close" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
604      <base:button id="close" title="Close" visible="<%=mode.hasCloseButton()%>" />
605    </base:buttongroup>
606  </base:body>
607  </base:page>
608  <%
609}
610finally
611{
612  if (bioSources != null) bioSources.close();
613  if (dc != null) dc.close();
614}
615%>
Note: See TracBrowser for help on using the repository browser.