source: trunk/www/admin/itemsubtypes/ajax.jsp @ 5645

Last change on this file since 5645 was 5645, checked in by Nicklas Nordborg, 11 years ago

References #1597: Subtypes of items

Added subtype functionality for sample list, view and edit dialog. Show the inversely related subtypes on the subtype view page.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 2.7 KB
Line 
1<%-- $Id: ajax.jsp 5645 2011-05-27 07:48:13Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2011 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--%>
24<%@ page pageEncoding="UTF-8" session="false" contentType="application/json"
25  import="net.sf.basedb.core.SessionControl"
26  import="net.sf.basedb.core.DbControl"
27  import="net.sf.basedb.core.Item"
28  import="net.sf.basedb.core.ItemSubtype"
29  import="net.sf.basedb.core.InvalidDataException"
30  import="net.sf.basedb.util.Values"
31  import="net.sf.basedb.util.error.ThrowableUtil"
32  import="net.sf.basedb.clients.web.Base"
33  import="net.sf.basedb.clients.web.WebException"
34  import="org.json.simple.JSONObject"
35%>
36<%
37final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
38final String ID = sc.getId();
39final String cmd = request.getParameter("cmd");
40final String root = request.getContextPath()+"/";
41final int itemId = Values.getInt(request.getParameter("item_id"));
42DbControl dc = null;
43out.clear();
44JSONObject json = new JSONObject();
45json.put("status", "ok");
46try
47{
48  if ("GetRelatedSubtype".equals(cmd))
49  {
50    Item relatedType = Item.valueOf(request.getParameter("relatedType"));
51    int defaultRelatedId = Values.getInt(request.getParameter("defaultRelatedId"));
52    dc = sc.newDbControl();
53    ItemSubtype related = null;
54    if (itemId > 0)
55    {
56      ItemSubtype subtype = ItemSubtype.getById(dc, itemId);
57      related = subtype.getRelatedSubtype(relatedType);
58    }
59    if (related == null && defaultRelatedId > 0)
60    {
61      related = ItemSubtype.getById(dc, defaultRelatedId);
62    }
63    if (related != null)
64    {
65      json.put("id", related.getId());
66      json.put("name", related.getName());
67    }
68    dc.close();
69  }
70  else
71  {
72    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
73  }
74}
75catch (Throwable t)
76{
77  t.printStackTrace();
78  json.clear();
79  json.put("status", "error");
80  json.put("message", t.getMessage());
81  json.put("stacktrace", ThrowableUtil.stackTraceToString(t));
82}
83finally
84{
85  json.writeJSONString(out);
86  out.flush();
87  if (dc != null) dc.close();
88}
89%>
Note: See TracBrowser for help on using the repository browser.