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

Last change on this file since 2978 was 2978, checked in by Nicklas Nordborg, 17 years ago

Added session="false" to all jsp pages so we no longer generate unneeded cookies

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