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