source: trunk/www/biomaterials/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.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.BioMaterialEvent"
33  import="net.sf.basedb.core.MeasuredBioMaterial"
34  import="net.sf.basedb.core.Protocol"
35  import="net.sf.basedb.core.ItemQuery"
36  import="net.sf.basedb.core.Permission"
37  import="net.sf.basedb.core.PermissionDeniedException"
38  import="net.sf.basedb.util.RemovableUtil"
39  import="net.sf.basedb.clients.web.Base"
40  import="net.sf.basedb.clients.web.WebException"
41  import="net.sf.basedb.clients.web.util.HTML"
42  import="net.sf.basedb.util.Values"
43  import="net.sf.basedb.util.formatter.Formatter"
44  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
45  import="java.util.Date"
46  import="java.util.List"
47  import="java.util.Collections"
48%>
49<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
50<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
51<%!
52  private static final ItemContext defaultContext = Base.createDefaultContext("entryDate", "type,entryDate,eventDate,quantity,protocol,comment");
53  private static final Item itemType = Item.BIOMATERIALEVENT;
54%>
55<%
56final int bioMaterialId = Values.getInt(request.getParameter("biomaterial_id"));
57final Item bioMaterialType = Item.valueOf(request.getParameter("biomaterial_type"));
58
59final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
60final String ID = sc.getId();
61final String cmd = request.getParameter("cmd");
62final String root = request.getContextPath()+"/";
63final String mode = request.getParameter("mode");
64final String callback = request.getParameter("callback");
65final String itemId = request.getParameter("item_id");
66final String listPage = "list_events.jsp?ID="+ID
67  +"&biomaterial_id="+bioMaterialId
68  +"&biomaterial_type="+bioMaterialType.name()
69  +(mode == null ? "" : "&mode="+mode)
70  +(callback == null ? "" : "&callback="+callback)
71  +(itemId == null ? "" : "&item_id="+itemId);
72final String viewPage = "view_event.jsp?ID="+ID+"&biomaterial_id="+bioMaterialId+"&biomaterial_type="+bioMaterialType.name();
73final String editPage = "edit_event.jsp?ID="+ID+"&biomaterial_id="+bioMaterialId+"&biomaterial_type="+bioMaterialType.name();
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    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    final int maxRecent = Base.getMaxRecent(sc);
125    dc = sc.newDbControl();
126    BioMaterialEvent event = (BioMaterialEvent)cc.getObject("item");
127    if (event == null)
128    {
129      MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId);
130      event = BioMaterialEvent.getNew(dc, bioMaterial);
131      message = "Event created";
132      dc.saveItem(event);
133    }
134    else
135    {
136      dc.reattachItem(event);
137      message = "Event updated";
138    }
139    Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
140    event.setComment(Values.getStringOrNull(request.getParameter("comment")));
141    event.setEventDate(dateFormatter.parseString(request.getParameter("event_date")));
142    event.setUsedQuantity(Values.getFloat(request.getParameter("used_quantity"), null));
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      if (pt != null) cc.setRecent(pt, maxRecent);
149    }
150    dc.commit();
151    cc.removeObject("item");
152  }
153  else if ("DeleteItem".equals(cmd))
154  {
155    // Delete a single item and then return to the view page
156    dc = sc.newDbControl();
157    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
158    RemovableUtil.delete(dc, itemType, Collections.singleton(cc.getId()));
159    dc.commit();
160    redirect = listPage;
161  }
162  else if ("DeleteItems".equals(cmd))
163  {
164    // Delete all selected items on the list page
165    dc = sc.newDbControl();
166    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
167    int numTotal = cc.getSelected().size();
168    int numDeleted = RemovableUtil.delete(dc, itemType, cc.getSelected());
169    dc.commit();
170    if (numTotal != numDeleted)
171    {
172      message = (numDeleted == 0 ? "No" : "Only "+numDeleted+" of "+numTotal) + " items could be deleted, because you have no DELETE permission";
173    }
174    redirect = listPage+(message != null ? "&popmessage="+HTML.urlEncode(message) : "");
175  }
176  else if ("ExportItems".equals(cmd))
177  {
178    // Run an export plugin in a list context
179    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
180    dc = sc.newDbControl();
181    MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId);
182    final ItemQuery<BioMaterialEvent> query = BioMaterialEvent.getQuery(bioMaterial);
183    cc.configureQuery(query, true);
184    cc.setQuery(query);
185    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+events";
186  }
187  else if ("ExportItem".equals(cmd))
188  {
189    // Run an export plugin in single-item context
190    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
191    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+event";
192  }
193  else if ("ImportItems".equals(cmd))
194  {
195    // Run an import plugin in a list context
196    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
197    dc = sc.newDbControl();
198    MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId);
199    final ItemQuery<BioMaterialEvent> query = BioMaterialEvent.getQuery(bioMaterial);
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+events";
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";
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    MeasuredBioMaterial bioMaterial = (MeasuredBioMaterial)bioMaterialType.getById(dc, bioMaterialId);
216    final ItemQuery<BioMaterialEvent> query = BioMaterialEvent.getQuery(bioMaterial);
217    cc.configureQuery(query, true);
218    cc.setQuery(query);
219    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
220  }
221  else if ("RunPlugin".equals(cmd))
222  {
223    // Run another plugin in single-item context
224    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
225    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
226  }
227  else
228  {
229    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
230  }
231
232}
233finally
234{
235  if (dc != null) dc.close();
236}
237if (forward != null)
238{
239  pageContext.forward(forward);
240}
241else if (redirect != null)
242{
243  response.sendRedirect(redirect);
244}
245else if (message == null)
246{
247  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
248}
249else
250{
251  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
252}
253
254%>
Note: See TracBrowser for help on using the repository browser.