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

Last change on this file since 2446 was 2446, checked in by Nicklas Nordborg, 16 years ago

References #270: Make array lims web gui more user friendly

Updated pages for Plate geometries, Plate type, Plate event types, Plates, Plate events and
wells.

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