source: trunk/www/lims/platetypes/edit_platetype.jsp @ 5920

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

References #1655: GUI improvements

Edit dialogs in plates section of Array LIMS.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 7.3 KB
Line 
1<%-- $Id: edit_platetype.jsp 5920 2012-01-10 09:41:59Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page pageEncoding="UTF-8" session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.SystemItems"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Include"
35  import="net.sf.basedb.core.PlateType"
36  import="net.sf.basedb.core.PlateGeometry"
37  import="net.sf.basedb.core.ItemQuery"
38  import="net.sf.basedb.core.ItemResultList"
39  import="net.sf.basedb.core.PermissionDeniedException"
40  import="net.sf.basedb.core.BaseException"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.query.Hql"
43  import="net.sf.basedb.clients.web.Base"
44  import="net.sf.basedb.clients.web.util.HTML"
45  import="net.sf.basedb.util.Values"
46  import="net.sf.basedb.core.plugin.GuiContext"
47  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
48  import="net.sf.basedb.clients.web.extensions.JspContext"
49  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
50  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
51  import="java.util.List"
52  import="java.util.Set"
53  import="java.util.HashSet"
54  import="java.util.Date"
55%>
56<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
57<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
58<%
59final Item itemType = Item.PLATETYPE;
60final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
61final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
62final int itemId = cc.getId();
63final String ID = sc.getId();
64final float scale = Base.getScale(sc);
65final DbControl dc = sc.newDbControl();
66try
67{
68  String title = null;
69  PlateType plateType = null;
70  ItemResultList<PlateGeometry> plateGeometries = null;
71  boolean readCurrentGeometry = true;
72  PlateGeometry currentGeometry = null;
73  int currentGeometryId = 0;
74
75  if (itemId == 0)
76  {
77    title = "Create plate type";
78    cc.removeObject("item");
79   
80    ItemQuery<PlateGeometry> geometryQuery = PlateGeometry.getQuery();
81    geometryQuery.include(Include.ALL);
82    geometryQuery.order(Orders.asc(Hql.property("name")));
83    geometryQuery.setCacheResult(true);
84    plateGeometries = geometryQuery.list(dc);
85    currentGeometryId = Values.getInt(request.getParameter("plategeometry_id"));
86    if (currentGeometryId == 0)
87    {
88      int recentGeometry = Values.getInt(cc.getRecent(Item.PLATEGEOMETRY.name(), 0), 0);
89      currentGeometryId = Values.getInt(cc.getPropertyValue("plateGeometry"), recentGeometry);
90    }
91  }
92  else
93  {
94    plateType = PlateType.getById(dc, itemId);
95    cc.setObject("item", plateType);
96    title = "Edit plate type -- " + HTML.encodeTags(plateType.getName());
97    try
98    {
99      currentGeometry = plateType.getPlateGeometry();
100    }
101    catch (PermissionDeniedException ex)
102    {
103      readCurrentGeometry = false;
104    }
105  }
106  if (plateType != null && !plateType.hasPermission(Permission.WRITE))
107  {
108    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
109  }
110  final String clazz = "class=\"text\"";
111  final String requiredClazz = "class=\"text required\"";
112  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), plateType);
113  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
114  %>
115  <base:page type="popup" title="<%=title%>">
116  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
117    <ext:scripts context="<%=jspContext%>" />
118    <ext:stylesheets context="<%=jspContext%>" />
119    <script language="JavaScript">
120    // Validate the "PlateType" tab
121    function validatePlateType()
122    {
123      var frm = document.forms['platetype'];
124      if (Main.trimString(frm.name.value) == '')
125      {
126        alert("You must enter a name");
127        frm.name.focus();
128        return false;
129      }
130      return true;
131    }
132
133    // Submit the form
134    function saveSettings()
135    {
136      var frm = document.forms['platetype'];
137      if (TabControl.validateActiveTab('settings'))
138      {
139        frm.submit();
140      }
141    }
142   
143    function init()
144    {
145      var frm = document.forms['platetype'];
146      <%
147      if (plateType == null)
148      {
149        %>
150        frm.name.focus();
151        frm.name.select();
152        <%
153      }
154      %>
155    }
156    </script>
157  </base:head>
158  <base:body onload="init()">
159    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
160    <form action="index.jsp?ID=<%=ID%>" method="post" name="platetype" onsubmit="return false;">
161    <input type="hidden" name="cmd" value="UpdateItem">
162
163    <t:tabcontrol id="settings" 
164      subclass="content dialogtabcontrol" 
165      position="bottom" remember="<%=plateType != null%>"
166      extensions="<%=invoker%>">
167    <t:tab id="info" title="Plate type" validate="validatePlateType()" helpid="platetype.edit">
168      <table class="fullform input100 smaller">
169      <tr>
170        <th>Name</th>
171        <td><input <%=requiredClazz%> type="text" name="name" 
172          value="<%=HTML.encodeTags(plateType == null ? Values.getString(cc.getPropertyValue("name"), "New plate type") : plateType.getName())%>" 
173          maxlength="<%=PlateType.MAX_NAME_LENGTH%>"></td>
174        <td></td>
175      </tr>
176      <tr>
177        <th>Geometry</th>
178        <td>
179          <%
180          if (plateType == null)
181          {
182            %>
183            <select name="plategeometry_id" class="unchangeable">
184            <%
185            for (PlateGeometry pg : plateGeometries)
186            {
187              if (pg.isRemoved() && pg.getId() != currentGeometryId) continue;
188              %>
189              <option value="<%=pg.getId()%>" <%=pg.getId() == currentGeometryId ? "selected" : ""%>><%=HTML.encodeTags(pg.getName())%>
190              <%
191            }
192            %>
193            </select>
194            <%
195          }
196          else
197          {
198            %>
199            <%=Base.getEncodedName(currentGeometry, !readCurrentGeometry)%>
200            <%
201          }
202          %>
203        </td>
204        <td></td>
205      </tr>
206      <tr class="dynamic">
207        <th>Description</th>
208        <td>
209          <textarea <%=clazz%> rows="4" name="description" 
210            ><%=HTML.encodeTags(plateType == null ? cc.getPropertyValue("description") : plateType.getDescription())%></textarea>
211        </td>
212        <td style="width: 20px;">
213          <base:icon image="zoom.png" 
214            onclick="Main.zoom('Description', 'platetype', 'description')"
215            tooltip="Edit in larger window"
216          />
217        </td>
218      </tr>
219      </table>
220    </t:tab>
221    </t:tabcontrol>
222    </form>
223   
224    <div class="legend">
225      <base:icon image="required.gif" /> = required information
226      <%if (plateType == null) {%><br>
227        <base:icon image="unchangeable.gif" /> = can't be changed later
228      <%}%>
229    </div>
230
231    <base:buttongroup subclass="dialogbuttons">
232      <base:button onclick="saveSettings()" title="Save" />
233      <base:button onclick="window.close()" title="Cancel" />
234    </base:buttongroup>
235  </base:body>
236  </base:page>
237  <%
238}
239finally
240{
241  if (dc != null) dc.close();
242}
243%>
Note: See TracBrowser for help on using the repository browser.