source: trunk/www/lims/plates/events/list_events.jsp @ 4889

Last change on this file since 4889 was 4889, checked in by Nicklas Nordborg, 14 years ago

References #1290: Change source files to UTF-8

Changed 'Hakkinen' to 'Häkkinen'.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 15.4 KB
Line 
1<%-- $Id: list_events.jsp 4889 2009-04-06 12:52:39Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
4  Copyright (C) 2007 Johan Enell
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 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.ItemContext"
31  import="net.sf.basedb.core.Plate"
32  import="net.sf.basedb.core.PlateEvent"
33  import="net.sf.basedb.core.PlateEventType"
34  import="net.sf.basedb.core.ItemQuery"
35  import="net.sf.basedb.core.ItemResultIterator"
36  import="net.sf.basedb.core.Permission"
37  import="net.sf.basedb.core.PluginDefinition"
38  import="net.sf.basedb.core.PermissionDeniedException"
39  import="net.sf.basedb.core.query.Restrictions"
40  import="net.sf.basedb.core.query.Expressions"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.query.Hql"
43  import="net.sf.basedb.core.plugin.GuiContext"
44  import="net.sf.basedb.core.plugin.Plugin"
45  import="net.sf.basedb.clients.web.Base"
46  import="net.sf.basedb.clients.web.ModeInfo"
47  import="net.sf.basedb.clients.web.PermissionUtil"
48  import="net.sf.basedb.clients.web.util.HTML"
49  import="net.sf.basedb.util.Values"
50  import="net.sf.basedb.util.formatter.Formatter"
51  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
52  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
53  import="net.sf.basedb.clients.web.extensions.JspContext"
54  import="net.sf.basedb.clients.web.extensions.renderer.PrefixSuffixRenderer"
55  import="net.sf.basedb.clients.web.extensions.toolbar.ToolbarUtil"
56  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
57  import="java.util.List"
58  import="java.util.Map"
59  import="java.util.Date"
60%>
61<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
62<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
63<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
64<%@ taglib prefix="p" uri="/WEB-INF/path.tld" %>
65<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
66<%!
67  private static final Item itemType = Item.PLATEEVENT;
68  private static final GuiContext guiContext = new GuiContext(itemType, GuiContext.Type.LIST);
69%>
70<%
71final int plateId = Values.getInt(request.getParameter("plate_id"));
72final SessionControl sc = Base.getExistingSessionControl(pageContext, Permission.DENIED, itemType);
73final String ID = sc.getId();
74final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
75
76final ModeInfo mode = ModeInfo.get(request.getParameter("mode"));
77final String callback = request.getParameter("callback");
78final String title = mode.generateTitle("event", "events");
79final DbControl dc = sc.newDbControl();
80ItemResultIterator<PlateEvent> events = null;
81try
82{
83  final Plate plate = Plate.getById(dc, plateId);
84  final boolean createPermission = plate.hasPermission(Permission.WRITE);
85  final boolean deletePermission = createPermission;
86
87  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
88
89  Map<Plugin.MainType, Integer> pluginCount = PluginDefinition.countPlugins(dc, guiContext);
90  try
91  {
92    final ItemQuery<PlateEvent> query = Base.getConfiguredQuery(cc, true, plate.getEvents(), mode);
93    events = query.iterate(dc);
94  }
95  catch (Throwable t)
96  {
97    cc.setMessage(t.getMessage());
98  }
99  int numListed = 0;
100  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, guiContext, plate);
101  ExtensionsInvoker invoker = ToolbarUtil.useExtensions(jspContext);
102  %>
103  <base:page title="<%=title%>" type="<%=mode.getPageType()%>">
104  <base:head scripts="table.js,tabcontrol.js" styles="table.css,headertabcontrol.css,path.css">
105    <ext:scripts context="<%=jspContext%>" />
106    <ext:stylesheets context="<%=jspContext%>" />
107    <script language="JavaScript">
108    var submitPage = 'index.jsp';
109    var formId = 'events';
110    function newItem()
111    {
112      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', 0, true, '&plate_id=<%=plateId%>');
113    }
114    function editItem(itemId)
115    {
116      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, true);
117    }
118    function viewItem(itemId)
119    {
120      Main.viewOrEditItem('<%=ID%>', '<%=itemType.name()%>', itemId, false);
121    }
122    function itemOnClick(evt, itemId)
123    {
124      Table.itemOnClick(formId, evt, itemId, '<%=mode.getName()%>', viewItem, editItem, returnSelected);
125    }
126    function deleteItems()
127    {
128      var frm = document.forms[formId];
129      var numChecked = Forms.numChecked(frm);
130      if (numChecked == 0)
131      {
132        alert('Please select at least one item in the list');
133        return;
134      }
135      else
136      {
137        var rep = numChecked == 1 ? 'event' : 'events';
138        if (!confirm('You are about to delete '+numChecked+' '+rep+'. This can\'t be undone. Continue?'))
139        {
140          return;
141        }
142      }
143      frm.action = submitPage;
144      frm.cmd.value = 'DeleteItems';
145      frm.submit();
146    }
147    function configureColumns()
148    {
149      Table.configureColumns('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
150    }
151    function runPlugin(cmd)
152    {
153      Table.submitToPopup(formId, cmd, 540, 460);
154    }
155    function returnSelected()
156    {
157      Table.returnSelected(formId, <%=callback != null ? "window.opener."+callback : "null" %>);
158      window.close();
159    }
160    function presetOnChange()
161    {
162      Table.presetOnChange('<%=ID%>', formId, '<%=itemType.name()%>', '<%=(String)cc.getObject("defaultColumns")%>');
163    }
164    function switchTab(tabControlId, tabId)
165    {
166      if (tabId == 'properties' || tabId == 'annotations')
167      {
168        location.href = '../index.jsp?ID=<%=ID%>&cmd=ViewItem&item_id=<%=plateId%>&tab='+tabId;
169      }
170      else if (tabId == 'wells')
171      {
172        location.href = '../wells/index.jsp?ID=<%=ID%>&plate_id=<%=plateId%>';
173      }
174      else
175      {
176        TabControl.setActiveTab(tabControlId, tabId);
177      }
178    }
179    </script>
180  </base:head>
181 
182  <base:body>
183    <p>
184    <p:path>
185      <p:pathelement title="Plates" href="<%="../index.jsp?ID="+ID%>" />
186      <p:pathelement title="<%=HTML.encodeTags(plate.getName())%>" />
187    </p:path>
188
189    <t:tabcontrol id="main" active="events" switch="switchTab">
190    <t:tab id="properties" title="Properties" />
191    <t:tab id="annotations" title="Annotations" />
192   
193    <t:tab id="events" title="Events">
194   
195    <%
196    if (cc.getMessage() != null)
197    {
198      %>
199      <div class="error"><%=cc.getMessage()%></div>
200      <%
201      cc.setMessage(null);
202    }
203    %>
204    <tbl:table 
205      id="events" 
206      clazz="itemlist" 
207      columns="<%=cc.getSetting("columns")%>"
208      sortby="<%=cc.getSortProperty()%>" 
209      direction="<%=cc.getSortDirection()%>"
210      title="<%=title%>"
211      action="index.jsp"
212      sc="<%=sc%>"
213      item="<%=itemType%>"
214      >
215      <tbl:hidden 
216        name="mode" 
217        value="<%=mode.getName()%>" 
218      />
219      <tbl:hidden 
220        name="plate_id" 
221        value="<%=String.valueOf(plateId)%>" 
222      />
223      <tbl:hidden 
224        name="callback" 
225        value="<%=callback%>" 
226        skip="<%=callback == null%>" 
227      />
228      <tbl:columndef 
229        id="ordinal"
230        property="plateEventType.ordinal"
231        datatype="int"
232        title="Ordinal"
233        sortable="true" 
234        filterable="true"
235        exportable="true"
236        show="always" 
237      />
238      <tbl:columndef 
239        id="id"
240        clazz="uniquecol"
241        property="id"
242        datatype="int"
243        title="ID"
244        sortable="true"
245        filterable="true"
246        exportable="true"
247      />
248      <tbl:columndef 
249        id="eventType"
250        property="plateEventType.name"
251        datatype="string"
252        title="Event type"
253        sortable="true" 
254        filterable="true"
255        exportable="true"
256        show="always" 
257      />
258      <tbl:columndef 
259        id="eventDate"
260        property="eventDate"
261        datatype="date"
262        title="Created"
263        sortable="true" 
264        filterable="true"
265        exportable="true"
266        formatter="<%=dateFormatter%>"
267      />
268      <tbl:columndef 
269        id="entryDate"
270        property="entryDate"
271        datatype="date"
272        title="Registered"
273        sortable="true" 
274        filterable="true"
275        exportable="true"
276        formatter="<%=dateFormatter%>"
277      />
278      <tbl:columndef 
279        id="protocol"
280        property="protocol.name"
281        datatype="string"
282        title="Protocol"
283        sortable="true" 
284        filterable="true"
285        exportable="true"
286      />
287      <tbl:columndef
288        id="hardware"
289        property="hardware.name"
290        datatype="string"
291        title="Hardware"
292        sortable="true"
293        filterable="true"
294        exportable="true"
295      />
296      <tbl:columndef 
297        id="comment"
298        property="comment"
299        datatype="string"
300        title="Comment" 
301        sortable="true" 
302        filterable="true" 
303        exportable="true"
304      />
305      <tbl:columndef 
306        id="user"
307        property="user.name"
308        datatype="string"
309        title="User"
310        sortable="true" 
311        filterable="true"
312        exportable="true"
313      />
314      <tbl:toolbar
315        visible="<%=mode.hasToolbar()%>"
316        >
317        <tbl:button 
318          disabled="<%=createPermission ? false : true%>" 
319          image="<%=createPermission ? "new.gif" : "new_disabled.gif"%>" 
320          onclick="newItem()" 
321          title="New&hellip;" 
322          tooltip="<%=createPermission ? "Create new event" : "You do not have permission to create events"%>" 
323        />
324        <tbl:button 
325          disabled="<%=deletePermission ? false : true%>" 
326          image="<%=deletePermission ? "delete.gif" : "delete_disabled.gif"%>" 
327          title="Delete&hellip;"
328          onclick="deleteItems()" 
329          tooltip="<%=deletePermission ? "Delete the selected events" : "You do not have permission to delete events"%>" 
330        />
331        <tbl:button 
332          image="columns.gif" 
333          onclick="configureColumns()" 
334          title="Columns&hellip;" 
335          tooltip="Show, hide and re-order columns" 
336        />
337        <tbl:button 
338          image="import.gif" 
339          onclick="runPlugin('ImportItems')" 
340          title="Import&hellip;" 
341          tooltip="Import data" 
342          visible="<%=pluginCount.containsKey(Plugin.MainType.IMPORT)%>"
343        />
344        <tbl:button 
345          image="export.gif" 
346          onclick="runPlugin('ExportItems')" 
347          title="Export&hellip;" 
348          tooltip="Export data" 
349          visible="<%=pluginCount.containsKey(Plugin.MainType.EXPORT)%>"
350        />
351        <tbl:button 
352          image="runplugin.gif" 
353          onclick="runPlugin('RunListPlugin')" 
354          title="Run plugin&hellip;" 
355          tooltip="Run a plugin" 
356          visible="<%=pluginCount.containsKey(Plugin.MainType.OTHER)%>"
357        />
358        <ext:render extensions="<%=invoker%>" context="<%=jspContext%>" 
359          wrapper="<%=new PrefixSuffixRenderer(jspContext, "<td>", "</td>") %>"/>
360      </tbl:toolbar>
361      <tbl:navigator
362        page="<%=cc.getPage()%>" 
363        rowsperpage="<%=cc.getRowsPerPage()%>" 
364        totalrows="<%=events == null ? 0 : events.getTotalCount()%>" 
365        visible="<%=mode.hasNavigator()%>"
366      />
367      <tbl:data>
368        <tbl:columns>
369        <tbl:presetselector 
370          clazz="columnheader"
371          colspan="3"
372          onchange="presetOnChange()"
373        />
374        </tbl:columns>
375         
376        <tr>
377          <tbl:header 
378            clazz="index"
379            >&nbsp;</tbl:header>
380          <tbl:header 
381            clazz="check" 
382            visible="<%=mode.hasCheck()%>"
383            ><base:icon 
384              image="check_uncheck.gif" 
385              tooltip="Check/uncheck all" 
386              onclick="Forms.checkUncheck(document.forms[formId])" style="align: left;"
387            /></tbl:header>
388          <tbl:header 
389            clazz="check" 
390            visible="<%=mode.hasRadio()%>"
391            />
392          <tbl:header 
393            clazz="icons" 
394            visible="<%=mode.hasIcons()%>"
395            >&nbsp;</tbl:header>
396          <tbl:propertyfilter />
397        </tr>
398   
399          <tbl:rows>
400          <%
401          int index = cc.getPage()*cc.getRowsPerPage();
402          int selectedItemId = cc.getId();
403          if (events != null)
404          {
405            while (events.hasNext())
406            {
407              PlateEvent item = events.next();
408              PlateEventType eventType = item.getPlateEventType();
409              int itemId = item.getId();
410              String name = HTML.encodeTags(eventType.getName());
411              boolean writePermission = item.hasPermission(Permission.WRITE);
412              String tooltip = mode.isSelectionMode() ? 
413                  "Select this item" : "View this item" + (writePermission ? " (use CTRL, ALT or SHIFT to edit)" : "");
414              index++;
415              numListed++;
416              %>
417              <tbl:row>
418                <tbl:header 
419                  clazz="index"
420                  ><%=index%></tbl:header>
421                <tbl:header 
422                  clazz="check" 
423                  visible="<%=mode.hasCheck()%>"
424                  ><input 
425                      type="checkbox" 
426                      name="<%=itemId%>" 
427                      value="<%=itemId%>" 
428                      title="<%=name%>" 
429                      <%=cc.getSelected().contains(itemId) ? "checked" : ""%>
430                    ></tbl:header>
431                <tbl:header 
432                  clazz="check" 
433                  visible="<%=mode.hasRadio()%>"
434                  ><input 
435                      type="radio" 
436                      name="item_id" 
437                      value="<%=itemId%>" 
438                      title="<%=name%>" 
439                      <%=selectedItemId == itemId ? "checked" : ""%>
440                    ></tbl:header>
441                <tbl:header 
442                  clazz="icons" 
443                  visible="<%=mode.hasIcons()%>"
444                  >&nbsp;</tbl:header>
445                <tbl:cell column="ordinal"><%=eventType.getOrdinal()%></tbl:cell>
446                <tbl:cell column="id"><%=item.getId()%></tbl:cell>
447                <tbl:cell column="eventType"><div class="link" 
448                  onclick="itemOnClick(<%=writePermission ? "event" : null%>, <%=itemId%>)" 
449                  title="<%=tooltip%>"><%=name%></div></tbl:cell>
450                <tbl:cell column="protocol"
451                  ><base:propertyvalue 
452                    item="<%=item%>" 
453                    property="protocol"
454                    enableEditLink="<%=mode.hasEditLink()%>" 
455                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
456                  /></tbl:cell>
457                <tbl:cell column="hardware"
458                  ><base:propertyvalue 
459                    item="<%=item%>"
460                    property="hardware"
461                    enableEditLink="<%=mode.hasEditLink()%>"
462                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
463                  /></tbl:cell>
464                <tbl:cell column="entryDate" value="<%=item.getEntryDate()%>" />
465                <tbl:cell column="eventDate" value="<%=item.getEventDate()%>" />
466                <tbl:cell column="comment"><%=HTML.encodeTags(item.getComment())%></tbl:cell>
467                <tbl:cell column="user"
468                  ><base:propertyvalue 
469                    item="<%=item%>" 
470                    property="user"
471                    enableEditLink="<%=mode.hasEditLink()%>" 
472                    enablePropertyLink="<%=mode.hasPropertyLink()%>"
473                  /></tbl:cell>
474              </tbl:row>
475              <%
476            }
477          }
478          %>
479          </tbl:rows>
480        </tbl:data>
481      <%
482      if (numListed == 0)
483      {
484        %>
485        <tbl:panel><%=events == null || events.getTotalCount() == 0 ? "No events were found" : "No events on this page. Please select another page!" %></tbl:panel>
486        <%
487      }
488      else
489      {
490        %>
491        <tbl:navigator
492          page="<%=cc.getPage()%>" 
493          rowsperpage="<%=cc.getRowsPerPage()%>" 
494          totalrows="<%=events == null ? 0 : events.getTotalCount()%>" 
495          visible="<%=mode.hasNavigator()%>"
496          locked="true"
497        />
498        <%
499      }
500      %>
501    </tbl:table>
502    <base:buttongroup align="center">
503      <base:button onclick="returnSelected();" title="Ok" visible="<%=mode.hasOkButton()%>" />
504      <base:button onclick="window.close();" title="Cancel" visible="<%=mode.hasCancelButton()%>" />
505      <base:button onclick="window.close();" title="Close" visible="<%=mode.hasCloseButton()%>" />
506    </base:buttongroup>
507    </t:tab>
508   
509    <t:tab id="wells" title="Wells" />
510    </t:tabcontrol>
511
512 
513  </base:body>
514  </base:page>
515  <%
516}
517finally
518{
519  if (events != null) events.close();
520  if (dc != null) dc.close();
521}
522%>
Note: See TracBrowser for help on using the repository browser.