source: trunk/www/lims/plates/wells/index.jsp @ 4866

Last change on this file since 4866 was 4866, checked in by Martin Svensson, 13 years ago

Fixes #1282 Change display-format of well coordinates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.4 KB
Line 
1<%-- $Id: index.jsp 4866 2009-03-31 07:36:06Z martin $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Hakkinen, 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 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.Plate"
31  import="net.sf.basedb.core.Well"
32  import="net.sf.basedb.core.ItemQuery"
33  import="net.sf.basedb.core.DataQuery"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.PermissionDeniedException"
36  import="net.sf.basedb.core.data.ReporterData"
37  import="net.sf.basedb.core.query.Hql"
38  import="net.sf.basedb.core.query.Orders"
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.util.Values"
44  import="net.sf.basedb.util.formatter.WellCoordinateFormatter"
45  import="java.util.List"
46  import="java.util.Collections"
47%>
48<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
49<%@ taglib prefix="tbl" uri="/WEB-INF/table.tld" %>
50<%!
51  private static final ItemContext defaultContext = Base.createDefaultContext("row", "row,column,reporter.name,reporter.externalId");
52  private static final Item itemType = Item.WELL;
53 
54  private static void registerExportFormatters(ItemContext cc)
55  {
56    cc.setObject("export.formatter.row", new WellCoordinateFormatter(true));
57    cc.setObject("export.formatter.column", new WellCoordinateFormatter(false));
58  }
59%>
60<%
61final int plateId = Values.getInt(request.getParameter("plate_id"));
62
63final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
64final String ID = sc.getId();
65final String cmd = request.getParameter("cmd");
66final String root = request.getContextPath()+"/";
67final String mode = request.getParameter("mode");
68final String callback = request.getParameter("callback");
69final String itemId = request.getParameter("item_id");
70final String listPage = "list_wells.jsp?ID="+ID
71  +"&plate_id="+plateId
72  +(mode == null ? "" : "&mode="+mode)
73  +(callback == null ? "" : "&callback="+callback)
74  +(itemId == null ? "" : "&item_id="+itemId);
75final String viewPage = "view_well.jsp?ID="+ID+"&plate_id="+plateId;
76final String editPage = "edit_well.jsp?ID="+ID+"&plate_id="+plateId;
77
78String forward = null;
79String redirect = null;
80String message = null;
81DbControl dc = null;
82
83try
84{
85  if (cmd == null || "List".equals(cmd))
86  {
87    // Display the list page without updatinging the current context
88    Base.getAndSetCurrentContext(sc, itemType, null, defaultContext, true);
89    redirect = listPage;
90  }
91  else if ("UpdateContext".equals(cmd))
92  {
93    // Display the list page after updating the current context from the request parameters
94    Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
95    redirect = listPage;
96  }
97  else if ("LoadContext".equals(cmd))
98  {
99    // Display the list page after loading a saved context
100    int contextId = Values.getInt(request.getParameter("context"));
101    Base.loadContext(sc, contextId, defaultContext);
102    redirect = listPage;
103  }
104  else if ("ViewItem".equals(cmd))
105  {
106    // Display the view page for a single item
107    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
108    forward = viewPage;
109  }
110  else if ("EditItem".equals(cmd))
111  {
112    // Display the edit page for a single item (should be opened in a popup)
113    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
114    redirect = editPage;
115  }
116  else if ("UpdateItem".equals(cmd))
117  {
118    // Update the properties on an item (will close the popup)
119    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, defaultContext);
120    dc = sc.newDbControl();
121    Well well = (Well)cc.getObject("item");
122    dc.reattachItem(well);
123    message = "Well updated";
124   
125    // Annotations tab
126    Base.updateAnnotations(dc, well, well, request);
127   
128    dc.commit();
129    cc.removeObject("item");
130  }
131  else if ("ExportItems".equals(cmd))
132  {
133    // Run an export plugin in a list context
134    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
135    dc = sc.newDbControl();
136    final Plate plate = Plate.getById(dc, plateId);
137    dc.close();
138    final ItemQuery<Well> query = plate.getWells();
139    cc.configureQuery(query, true);
140    if (!"row".equals(cc.getSortProperty()))
141    {
142      query.order(Orders.asc(Hql.property("row")));
143    }
144    if (!"column".equals(cc.getSortProperty()))
145    {
146      query.order(Orders.asc(Hql.property("column")));
147    }
148    registerExportFormatters(cc);
149   
150    cc.setQuery(query);
151    redirect = "../../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Export+wells";
152  }
153  else if ("ExportItem".equals(cmd))
154  {
155    // Run an export plugin in single-item context
156    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
157    registerExportFormatters(cc);
158    redirect = "../../common/export/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Export+well";
159  }
160  else if ("ImportItems".equals(cmd))
161  {
162    // Run an import plugin in a list context
163    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
164    dc = sc.newDbControl();
165    final Plate plate = Plate.getById(dc, plateId);
166    dc.close();
167    final ItemQuery<Well> query = plate.getWells();
168    cc.configureQuery(query, true);
169    cc.setQuery(query);
170    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&title=Import+wells";
171  }
172  else if ("ImportItem".equals(cmd))
173  {
174    // Run an import plugin in single-item context
175    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
176    redirect = "../../common/import/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&title=Import+well";
177  }
178  else if ("RunListPlugin".equals(cmd))
179  {
180    // Run another plugin in a list context
181    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
182    dc = sc.newDbControl();
183    final Plate plate = Plate.getById(dc, plateId);
184    dc.close();
185    final ItemQuery<Well> query = plate.getWells();
186    cc.configureQuery(query, true);
187    cc.setQuery(query);
188    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=LIST&main_type=OTHER&title=Run+plugin";
189  }
190  else if ("RunPlugin".equals(cmd))
191  {
192    // Run another plugin in single-item context
193    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
194    redirect = "../../common/plugin/index.jsp?ID="+ID+"&cmd=SelectPlugin&item_type="+itemType.name()+"&context_type=ITEM&main_type=OTHER&title=Run+plugin";
195  }
196  else if ("CreateReporterList".equals(cmd))
197  {
198    ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, pageContext, defaultContext);
199    dc = sc.newDbControl();   
200    final Plate plate = Plate.getById(dc, plateId);
201    final DataQuery<ReporterData> query = plate.getReporters();
202    cc.configureQuery(query, true);
203    cc.setQuery(query);
204    redirect = "../../../views/reporterlists/index.jsp?ID="+ID+
205      "&cmd=NewItem&addReporters=1&formId=wells&fromContext=WELL"+
206      "&name=" + HTML.urlEncode(plate.getName());
207  }
208  else
209  {
210    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
211  }
212
213}
214finally
215{
216  if (dc != null) dc.close();
217}
218if (forward != null)
219{
220  pageContext.forward(forward);
221}
222else if (redirect != null)
223{
224  response.sendRedirect(redirect);
225}
226else if (message == null)
227{
228  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
229}
230else
231{
232  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
233}
234
235%>
Note: See TracBrowser for help on using the repository browser.