source: trunk/www/biomaterials/bioplates/wells/ajax.jsp @ 5722

Last change on this file since 5722 was 5722, checked in by Nicklas Nordborg, 12 years ago

References #1597: Subtypes of items

Update the "Move biomaterial" plate event wizard to use item subtypes when possible.

Display item subtype for biomaterials in tooltip on the single-item page for plates.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 3.8 KB
Line 
1<%-- $Id $
2  ------------------------------------------------------------------
3  Copyright (C) 2010 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.Permission"
28  import="net.sf.basedb.core.BioWell"
29  import="net.sf.basedb.core.MeasuredBioMaterial"
30  import="net.sf.basedb.core.ItemSubtype"
31  import="net.sf.basedb.core.InvalidDataException"
32  import="net.sf.basedb.core.PermissionDeniedException"
33  import="net.sf.basedb.util.Values"
34  import="net.sf.basedb.util.error.ThrowableUtil"
35  import="net.sf.basedb.clients.web.Base"
36  import="net.sf.basedb.clients.web.WebException"
37  import="net.sf.basedb.clients.web.util.HTML"
38  import="org.json.simple.JSONObject"
39  import="org.json.simple.JSONArray"
40%>
41<%
42final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
43final String ID = sc.getId();
44final String cmd = request.getParameter("cmd");
45final String root = request.getContextPath()+"/";
46final int itemId = Values.getInt(request.getParameter("item_id"));
47DbControl dc = null;
48out.clear();
49JSONObject json = new JSONObject();
50json.put("status", "ok");
51try
52{
53  if ("WellInfo".equals(cmd))
54  {
55    dc = sc.newDbControl();
56    boolean encodeStrings = Values.getBoolean(request.getParameter("encodeStrings"));
57    BioWell well = BioWell.getById(dc, itemId);
58    boolean isEmpty = well.isEmpty();
59    boolean hasBeenUsed = well.hasBeenUsed();
60   
61    json.put("id", well.getId());
62    json.put("isEmpty", isEmpty);
63   
64    if (!isEmpty || hasBeenUsed)
65    {
66      JSONObject jsonBioMaterial = new JSONObject();
67      try
68      {
69        MeasuredBioMaterial bioMaterial = isEmpty ? well.getOriginalBioMaterial() : well.getBioMaterial();
70        jsonBioMaterial.put("id", bioMaterial.getId());
71        jsonBioMaterial.put("type", bioMaterial.getType().name());
72        jsonBioMaterial.put("name", encodeStrings ? HTML.encodeTags(bioMaterial.getName()) : bioMaterial.getName());
73        jsonBioMaterial.put("description", encodeStrings ? HTML.niceFormat(bioMaterial.getDescription()) : bioMaterial.getDescription());
74        jsonBioMaterial.put("editable", bioMaterial.hasPermission(Permission.WRITE));
75        ItemSubtype subtype = bioMaterial.getItemSubtype();
76        if (subtype != null)
77        {
78          JSONObject jsonSubtype = new JSONObject();
79          jsonSubtype.put("id", subtype.getId());
80          jsonSubtype.put("name", HTML.encodeTags(subtype.getName()));
81          jsonBioMaterial.put("subtype", jsonSubtype);
82        }
83      }
84      catch (PermissionDeniedException ex)
85      {
86        jsonBioMaterial.put("denied", true);
87      }
88      json.put("bioMaterial", jsonBioMaterial);
89    }
90    dc.close();
91  }
92  else
93  {
94    throw new WebException("popup", "Invalid command", "The command {1} is not recognised as a valid command.", cmd);
95  }
96}
97catch (Throwable t)
98{
99  t.printStackTrace();
100  json.clear();
101  json.put("status", "error");
102  json.put("message", t.getMessage());
103  json.put("stacktrace", ThrowableUtil.stackTraceToString(t));
104}
105finally
106{
107  json.writeJSONString(out);
108  out.flush();
109  if (dc != null) dc.close();
110}
111%>
Note: See TracBrowser for help on using the repository browser.