source: trunk/www/views/reporters/index.jsp @ 3679

Last change on this file since 3679 was 3679, checked in by Jari Häkkinen, 15 years ago

Changing the pesky "a (ä) character to a.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.3 KB
Line 
1<%-- $Id: index.jsp 3679 2007-08-17 07:18:29Z jari $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Johan Enell, Jari Hakkinen, Nicklas Nordborg
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 2
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 this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330,
22  Boston, MA  02111-1307, USA.
23  ------------------------------------------------------------------
24
25  @author Nicklas
26  @version 2.0
27--%>
28<%@ page session="false"
29  import="net.sf.basedb.core.SessionControl"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.ExtendedProperties"
34  import="net.sf.basedb.core.ExtendedProperty"
35  import="net.sf.basedb.core.ReporterBatcher"
36  import="net.sf.basedb.core.Reporter"
37  import="net.sf.basedb.core.ReporterType"
38  import="net.sf.basedb.core.FileType"
39  import="net.sf.basedb.core.data.ReporterData"
40  import="net.sf.basedb.core.Permission"
41  import="net.sf.basedb.core.DataQuery"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.util.RemovableUtil"
44  import="net.sf.basedb.util.ShareableUtil"
45  import="net.sf.basedb.clients.web.Base"
46  import="net.sf.basedb.clients.web.WebException"
47  import="net.sf.basedb.util.Values"
48  import="net.sf.basedb.clients.web.util.HTML"
49  import="java.util.Enumeration"
50  import="java.util.List"
51%>
52<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
53<%!
54  private static final ItemContext defaultContext = Base.createDefaultContext("name", "name,externalId,symbol,description");
55  private static final Item itemType = Item.REPORTER;
56%>
57<%
58final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
59final String ID = sc.getId();
60final String cmd = request.getParameter("cmd");
61final String root = request.getContextPath()+"/";
62final String mode = request.getParameter("mode");
63final String callback = request.getParameter("callback");
64final String itemId = request.getParameter("item_id");
65final String listPage = "list_reporters.jsp?ID="+ID
66  +(mode == null ? "" : "&mode="+mode)
67  +(callback == null ? "" : "&callback="+callback)
68  +(itemId == null ? "" : "&item_id="+itemId);
69final String viewPage = "view_reporter.jsp?ID="+ID;
70final String editPage = "edit_reporter.jsp?ID="+ID;
71
72String forward = null;
73String redirect = null;
74String message = null;
75DbControl dc = null;
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, true);
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 
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    final int maxRecent = Base.getMaxRecent(sc);
126    dc = sc.newDbControl();
127    ReporterData reporter = (ReporterData)cc.getObject("item");
128    if (reporter == null)
129    {
130      reporter = Reporter.getNew(Values.getStringOrNull(request.getParameter("externalId")));
131    }
132    else
133    {
134      reporter.setExternalId(Values.getStringOrNull(request.getParameter("externalId")));
135    }
136    reporter.setName(Values.getStringOrNull(request.getParameter("name")));
137    reporter.setDescription(Values.getStringOrNull(request.getParameter("description")));
138    reporter.setSymbol(Values.getStringOrNull(request.getParameter("symbol")));
139    int reporterTypeId = Values.getInt(request.getParameter("reportertype_id"), -1);
140    if (reporterTypeId >= 0) // < 0 = denied or unchanged
141    {
142      ReporterType rt = reporterTypeId == 0 ? null : ReporterType.getById(dc, reporterTypeId);
143      Reporter.setReporterType(reporter, rt);
144      if (rt != null) cc.setRecent(rt, maxRecent);
145    }
146    List<ExtendedProperty> reporterProperties = ExtendedProperties.getProperties("ReporterData");
147    if (reporterProperties != null)
148    {
149      for (ExtendedProperty ep : reporterProperties)
150      {
151        String name = ep.getName();
152        Object value = ep.getType().parseString(Values.getStringOrNull(request.getParameter(name)));
153        reporter.setExtended(name, value);
154      }
155    }
156    ReporterBatcher batcher = ReporterBatcher.getNew(dc);
157    if (reporter.getId() != 0)
158    {
159      message = "Reporter updated";
160      batcher.update(reporter);
161    }
162    else
163    {
164      message = "Reporter created";
165      batcher.insert(reporter);
166    }
167    batcher.close();
168    dc.commit();
169    cc.removeObject("item");
170  }
171  else if ("DeleteItem".equals(cmd))
172  {
173    // Delete a single item and then return to the list page
174    dc = sc.newDbControl();
175    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
176    ReporterBatcher batcher = ReporterBatcher.getNew(dc);
177    batcher.delete(cc.getId());
178    batcher.close();
179    dc.commit();
180    redirect = listPage;
181  }
182  else if ("DeleteItems".equals(cmd))
183  {
184    // Delete all selected items on the list page
185    dc = sc.newDbControl();
186    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
187    ReporterBatcher batcher = ReporterBatcher.getNew(dc);
188    for (int reporterId : cc.getSelected())
189    {
190      batcher.delete(reporterId);
191    }
192    batcher.close();
193    dc.commit();
194    redirect = listPage;
195  }
196  else if ("ExportItems".equals(cmd))
197  {
198    // Run an export plugin in a list context
199    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
200    final DataQuery<ReporterData> query = Reporter.getQuery();
201    cc.configureQuery(query, true);
202    cc.setQuery(query);
203    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+reporters";
204  }
205  else if ("ExportItem".equals(cmd))
206  {
207    // Run an export plugin in single-item context
208    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
209    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+reporter";
210  }
211  else if ("ImportItems".equals(cmd))
212  {
213    // Run an import plugin in a list context
214    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
215    final DataQuery<ReporterData> query = Reporter.getQuery();
216    cc.configureQuery(query, true);
217    cc.setQuery(query);
218    // Set file type filter
219    ItemContext fileContext = sc.getCurrentContext(Item.FILE);
220    fileContext.setPropertyFilter(FileType.getPropertyFilter(FileType.REPORTER));
221    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+reporters";
222  }
223  else if ("ImportItem".equals(cmd))
224  {
225    // Run an import plugin in single-item context
226    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
227    // Set file type filter
228    ItemContext fileContext = sc.getCurrentContext(Item.FILE);
229    fileContext.setPropertyFilter(FileType.getPropertyFilter(FileType.REPORTER));
230    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+reporter";
231  }
232  else if ("RunListPlugin".equals(cmd))
233  {
234    // Run another plugin in a list context
235    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
236    final DataQuery<ReporterData> query = Reporter.getQuery();
237    cc.configureQuery(query, true);
238    cc.setQuery(query);
239    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
240  }
241  else if ("RunPlugin".equals(cmd))
242  {
243    // Run another plugin in single-item context
244    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
245    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
246  }
247  else if ("CreateReporterList".equals(cmd))
248  {
249    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
250    final DataQuery<ReporterData> query = Reporter.getQuery();
251    cc.configureQuery(query, true);
252    cc.setQuery(query);
253    redirect = "../reporterlists/index.jsp?ID="+ID+"&cmd=NewItem&addReporters=1";
254  }
255  else
256  {
257    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
258  }
259}
260finally
261{
262  if (dc != null) dc.close();
263}
264
265if (forward != null)
266{
267  pageContext.forward(forward);
268}
269else if (redirect != null)
270{
271  response.sendRedirect(redirect);
272}
273else if (message == null)
274{
275  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
276}
277else
278{
279  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
280}
281%>
282
Note: See TracBrowser for help on using the repository browser.