source: trunk/www/lims/plates/events/index.jsp @ 2486

Last change on this file since 2486 was 2486, checked in by Martin Svensson, 16 years ago

References #173. Possible to attach a hardware to a PlateEvent? in the GUI

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 9.6 KB
Line 
1<%-- $Id: index.jsp 2486 2006-08-03 15:20:10Z 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.Hardware"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.Plate"
34  import="net.sf.basedb.core.PlateEvent"
35  import="net.sf.basedb.core.PlateEventType"
36  import="net.sf.basedb.core.Protocol"
37  import="net.sf.basedb.core.ItemQuery"
38  import="net.sf.basedb.core.Permission"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.util.RemovableUtil"
41  import="net.sf.basedb.clients.web.Base"
42  import="net.sf.basedb.clients.web.WebException"
43  import="net.sf.basedb.clients.web.util.HTML"
44  import="net.sf.basedb.clients.web.util.Values"
45  import="java.util.List"
46  import="java.util.Collections"
47%>
48<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
49<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
50<%!
51  private static final ItemContext defaultContext = Base.createDefaultContext("plateEventType.ordinal", "eventType,ordinal,entryDate,eventDate,protocol,comment");
52  private static final Item itemType = Item.PLATEEVENT;
53%>
54<%
55final int plateId = Values.getInt(request.getParameter("plate_id"));
56
57final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
58final String ID = sc.getId();
59final String cmd = request.getParameter("cmd");
60final String root = request.getContextPath()+"/";
61final String mode = request.getParameter("mode");
62final String callback = request.getParameter("callback");
63final String itemId = request.getParameter("item_id");
64final String listPage = "list_events.jsp?ID="+ID
65  +"&plate_id="+plateId
66  +(mode == null ? "" : "&mode="+mode)
67  +(callback == null ? "" : "&callback="+callback)
68  +(itemId == null ? "" : "&item_id="+itemId);
69final String viewPage = "view_event.jsp?ID="+ID+"&plate_id="+plateId;
70final String editPage = "edit_event.jsp?ID="+ID+"&plate_id="+plateId;
71
72String forward = null;
73String redirect = null;
74String message = null;
75DbControl dc = null;
76
77try
78{
79  if (cmd == null || "List".equals(cmd))
80  {
81    // Display the list page without updatinging the current context
82    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
83    redirect = listPage;
84  }
85  else if ("UpdateContext".equals(cmd))
86  {
87    // Display the list page after updating the current context from the request parameters
88    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
89    redirect = listPage;
90  }
91  else if ("LoadContext".equals(cmd))
92  {
93    // Display the list page after loading a saved context
94    int contextId = Values.getInt(request.getParameter("context"));
95    Base.loadContext(sc, contextId, defaultContext);
96    redirect = listPage;
97  }
98  else if ("ViewItem".equals(cmd))
99  {
100    // Display the view page for a single item
101    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
102    forward = viewPage;
103  }
104  else if ("EditItem".equals(cmd))
105  {
106    // Display the edit page for a single item (should be opened in a popup)
107    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
108    redirect = editPage;
109  }
110  else if ("NewItem".equals(cmd))
111  {
112    // Display the edit page for a new item (should be opened in a popup)
113    if (!sc.hasPermission(Permission.CREATE, itemType))
114    {
115      throw new PermissionDeniedException(Permission.CREATE, itemType.toString());
116    }
117    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
118    cc.setId(0);
119    redirect = editPage;
120  }
121  else if ("UpdateItem".equals(cmd))
122  {
123    // Update the properties on an item (will close the popup)
124    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
125    dc = sc.newDbControl();
126    PlateEvent event = (PlateEvent)cc.getObject("item");
127    if (event == null)
128    {
129      Plate plate = Plate.getById(dc, plateId);
130      int eventTypeId = Values.getInt(request.getParameter("plateeventtype_id"));
131      PlateEventType eventType = PlateEventType.getById(dc, eventTypeId);
132      event = plate.getEvent(eventType);
133      message = "Event created";
134      dc.saveItem(event);
135    }
136    else
137    {
138      dc.reattachItem(event);
139      message = "Event updated";
140    }
141    event.setComment(Values.getStringOrNull(request.getParameter("comment")));
142    event.setEventDate(Values.getDate(request.getParameter("event_date")));
143    int protocolId = Values.getInt(request.getParameter("protocol_id"), -1);
144    if (protocolId >= 0) // < 0 = denied or unchanged
145    {
146      Protocol pt = protocolId == 0 ? null : Protocol.getById(dc, protocolId);
147      event.setProtocol(pt);
148    }
149    int hardwareId = Values.getInt(request.getParameter("hardware_id"), -1);
150    if (hardwareId >= 0) // < 0 = denied or unchanged
151    {
152      Hardware hw = hardwareId == 0 ? null : Hardware.getById(dc, hardwareId);
153      event.setHardware(hw);
154    }
155    dc.commit();
156    cc.removeObject("item");
157  }
158  else if ("DeleteItem".equals(cmd))
159  {
160    // Delete a single item and then return to the view page
161    dc = sc.newDbControl();
162    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
163    RemovableUtil.delete(dc, itemType, Collections.singleton(cc.getId()));
164    dc.commit();
165    redirect = listPage;
166  }
167  else if ("DeleteItems".equals(cmd))
168  {
169    // Delete all selected items on the list page
170    dc = sc.newDbControl();
171    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
172    int numTotal = cc.getSelected().size();
173    int numDeleted = RemovableUtil.delete(dc, itemType, cc.getSelected());
174    dc.commit();
175    if (numTotal != numDeleted)
176    {
177      message = (numDeleted == 0 ? "No" : "Only "+numDeleted+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
178    }
179    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
180  }
181  else if ("ExportItems".equals(cmd))
182  {
183    // Run an export plugin in a list context
184    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
185    dc = sc.newDbControl();
186    final Plate plate = Plate.getById(dc, plateId);
187    dc.close();
188    final ItemQuery<PlateEvent> query = plate.getEvents();
189    cc.configureQuery(query, true);
190    cc.setQuery(query);
191    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+event+types";
192  }
193  else if ("ExportItem".equals(cmd))
194  {
195    // Run an export plugin in single-item context
196    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
197    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+event+type";
198  }
199  else if ("ImportItems".equals(cmd))
200  {
201    // Run an import plugin in a list context
202    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
203    dc = sc.newDbControl();
204    final Plate plate = Plate.getById(dc, plateId);
205    dc.close();
206    final ItemQuery<PlateEvent> query = plate.getEvents();
207    cc.configureQuery(query, true);
208    cc.setQuery(query);
209    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+event+types";
210  }
211  else if ("ImportItem".equals(cmd))
212  {
213    // Run an import plugin in single-item context
214    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
215    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+event+type";
216  }
217  else if ("RunListPlugin".equals(cmd))
218  {
219    // Run another plugin in a list context
220    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
221    dc = sc.newDbControl();
222    final Plate plate = Plate.getById(dc, plateId);
223    dc.close();
224    final ItemQuery<PlateEvent> query = plate.getEvents();
225    cc.configureQuery(query, true);
226    cc.setQuery(query);
227    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
228  }
229  else if ("RunPlugin".equals(cmd))
230  {
231    // Run another plugin in single-item context
232    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
233    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
234  }
235  else
236  {
237    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
238  }
239
240}
241finally
242{
243  if (dc != null) dc.close();
244}
245if (forward != null)
246{
247  pageContext.forward(forward);
248}
249else if (redirect != null)
250{
251  response.sendRedirect(redirect);
252}
253else if (message == null)
254{
255  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
256}
257else
258{
259  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
260}
261
262%>
Note: See TracBrowser for help on using the repository browser.