source: trunk/www/common/annotations/index.jsp @ 5075

Last change on this file since 5075 was 5075, checked in by Nicklas Nordborg, 14 years ago

Fixes #1361: Unhandled item: ANNOTATION

The only "issue" is that there is no "view" page for annotations. So the "edit" page is used for that as well. The "Save" button will be disabled if the current user doesn't have write permission.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 3.4 KB
Line 
1<%-- $Id: index.jsp 5075 2009-08-24 11:05:40Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 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.BasicItem"
31  import="net.sf.basedb.core.Annotation"
32  import="net.sf.basedb.core.AnnotationType"
33  import="net.sf.basedb.core.Annotatable"
34  import="net.sf.basedb.core.BaseException"
35  import="net.sf.basedb.clients.web.Base"
36  import="net.sf.basedb.clients.web.WebException"
37  import="net.sf.basedb.util.Values"
38  import="net.sf.basedb.clients.web.util.HTML"
39%>
40<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
41<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
42
43<%
44final String root = request.getContextPath()+"/";
45final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
46final String ID = sc.getId();
47final String cmd = request.getParameter("cmd");
48final int itemId = Values.getInt(request.getParameter("item_id"));
49
50DbControl newDc = null;
51DbControl oldDc = null;
52String forward = null;
53String message = null;
54String redirect = null;
55try
56{
57  if ("EditItem".equals(cmd))
58  {
59    newDc = sc.newDbControl();
60    Annotation a = Annotation.getById(newDc, itemId);
61    AnnotationType at = a.getAnnotationType();
62    Annotatable item = a.getAnnotationSet().getItem();
63   
64    redirect = "annotate.jsp?ID=" + ID + "&item_id=" + item.getId() + 
65        "&item_type=" + item.getType().name() + 
66        "&annotationtype_id=" + at.getId() + "&standalone=1";
67    newDc.close();
68  }
69  else if ("SaveAnnotations".equals(cmd))
70  {
71    final Item itemType = Item.valueOf(request.getParameter("item_type"));
72    newDc = sc.newDbControl();
73    oldDc = sc.newDbControl();
74    ItemContext cc = sc.getCurrentContext(itemType);
75    Annotatable oldItem = (Annotatable)cc.getObject("item");
76    Annotatable newItem = (Annotatable)itemType.getById(newDc, itemId);
77    oldDc.reattachItem((BasicItem)oldItem, false);
78    Base.updateAnnotations(newDc, oldItem, newItem, request);
79    oldDc.close();
80    newDc.commit();
81    cc.removeObject("item");
82    message = "Annotations saved";
83  }
84  else
85  {
86    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
87  }
88}
89finally
90{
91  if (oldDc != null) oldDc.close();
92  if (newDc != null) newDc.close();
93}
94
95if (forward != null)
96{
97  pageContext.forward(forward);
98}
99else if (redirect != null)
100{
101  response.sendRedirect(redirect);
102}
103else if (message == null)
104{
105  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&wait=0");
106}
107else
108{
109  response.sendRedirect(root + "common/close_popup.jsp?refresh_opener=1&message="+HTML.urlEncode(message));
110}
111%>
112
Note: See TracBrowser for help on using the repository browser.