source: trunk/www/admin/protocols/list_protocol.jsp @ 6604

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

References #1890: Improve skinnability of BASE

Updated table listings with some new css classes to make it easier to modify background color.

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