source: trunk/www/lims/arraydesigns/features/index.jsp @ 6192

Last change on this file since 6192 was 6192, checked in by Nicklas Nordborg, 10 years ago

References #1729 and #1730.

Refactored the code for displaying a popup message when loading a page. The message should now be stored as a session setting instead: sc.setSessionSetting("alert-message", message). The added benefit is that the message is only displayed once and is not re-displayed if the page is reloaded.

Removed onunload, onkeypress and attributes from the <base:body> tag. Added support for dynamic attributes instead.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 6.0 KB
Line 
1<%-- $Id: index.jsp 6192 2012-10-31 12:34:19Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg
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 3
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 BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21
22  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.ItemContext"
30  import="net.sf.basedb.core.ItemQuery"
31  import="net.sf.basedb.core.DataQuery"
32  import="net.sf.basedb.core.DataResultIterator"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.PermissionDeniedException"
35  import="net.sf.basedb.core.ArrayDesign"
36  import="net.sf.basedb.core.data.FeatureData"
37  import="net.sf.basedb.core.data.ReporterData"
38  import="net.sf.basedb.clients.web.Base"
39  import="net.sf.basedb.clients.web.WebException"
40  import="net.sf.basedb.clients.web.util.HTML"
41  import="net.sf.basedb.util.Values"
42  import="net.sf.basedb.util.formatter.WellCoordinateFormatter"
43  import="net.sf.basedb.core.plugin.GuiContext"
44  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
45  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
46  import="net.sf.basedb.clients.web.extensions.JspContext"
47  import="net.sf.basedb.clients.web.extensions.list.ListColumnExportRenderer"
48  import="net.sf.basedb.clients.web.extensions.list.ListColumnUtil"
49  import="java.util.List"
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("position", 
55    "position,externalId,block,row,column,reporter.name,reporter.externalId");
56  private static final Item itemType = Item.FEATURE;
57 
58  private static void registerExportFormatters(ItemContext cc)
59  {
60    cc.setObject("export.formatter.well.row", new WellCoordinateFormatter(true));
61    cc.setObject("export.formatter.well.column", new WellCoordinateFormatter(false));
62  }
63%>
64<%
65final int arrayDesignId = Values.getInt(request.getParameter("arraydesign_id"));
66
67final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
68final String ID = sc.getId();
69final String cmd = request.getParameter("cmd");
70final String root = request.getContextPath()+"/";
71final String listPage = "list_features.jsp?ID="+ID+"&arraydesign_id="+arrayDesignId;
72final String viewPage = "view_feature.jsp?ID="+ID+"&arraydesign_id="+arrayDesignId;
73
74String forward = null;
75String redirect = null;
76String message = null;
77DbControl dc = null;
78
79try
80{
81  if (cmd == null || "List".equals(cmd))
82  {
83    // Display the list page without updatinging the current context
84    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
85    redirect = listPage;
86  }
87  else if ("UpdateContext".equals(cmd))
88  {
89    // Display the list page after updating the current context from the request parameters
90    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
91    redirect = listPage;
92  }
93  else if ("LoadContext".equals(cmd))
94  {
95    // Display the list page after loading a saved context
96    int contextId = Values.getInt(request.getParameter("context"));
97    Base.loadContext(sc, contextId, defaultContext);
98    redirect = listPage;
99  }
100  else if ("ViewItem".equals(cmd))
101  {
102    // Display the view page for a single item
103    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
104    forward = viewPage;
105  }
106  else if ("ExportItems".equals(cmd))
107  {
108    // Run an export plugin in a list context
109    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
110    dc = sc.newDbControl();   
111    final ArrayDesign arrayDesign = ArrayDesign.getById(dc, arrayDesignId);
112    final DataQuery<FeatureData> query = arrayDesign.getFeatures();
113    cc.configureQuery(dc, query, true);
114    cc.setQuery(query);
115    registerExportFormatters(cc);
116    JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.list(itemType), null);
117    ExtensionsInvoker listInvoker = ListColumnUtil.useExtensions(jspContext);
118    listInvoker.render(new ListColumnExportRenderer(cc));
119    dc.close();
120    redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+features+of+array+design";
121  }
122  else if ("CreateReporterList".equals(cmd))
123  {
124    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
125    dc = sc.newDbControl();   
126    final ArrayDesign arrayDesign = ArrayDesign.getById(dc, arrayDesignId);
127    final DataQuery<ReporterData> query = arrayDesign.getReporters();
128    cc.configureQuery(dc, query, true);
129    dc.close();
130    cc.setQuery(query);
131    redirect = "../../../views/reporterlists/index.jsp?ID="+ID+
132      "&cmd=NewItem&addReporters=1&formId=features&fromContext=FEATURE" +
133      "&name=" + HTML.urlEncode(arrayDesign.getName());
134  }
135  else
136  {
137    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
138  }
139
140}
141finally
142{
143  if (dc != null) dc.close();
144}
145if (forward != null)
146{
147  sc.setSessionSetting("alert-message", message);
148  pageContext.forward(forward);
149}
150else if (redirect != null)
151{
152  sc.setSessionSetting("alert-message", message);
153  response.sendRedirect(redirect);
154}
155else if (message == null)
156{
157  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
158}
159else
160{
161  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
162}
163
164%>
Note: See TracBrowser for help on using the repository browser.