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

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

References #1655: GUI improvements

  • File manager dialogs
  • File server edit dialog
  • Changed zoom.gif to png
  • 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 5908 2011-12-13 13:48:46Z 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    <p>
160    <form action="index.jsp?ID=<%=ID%>" method="post" name="platetype" onsubmit="return false;">
161    <input type="hidden" name="cmd" value="UpdateItem">
162
163    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
164    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*160)+"px;"%>" 
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="form" cellspacing=0>
169      <tr>
170        <td class="prompt">Name</td>
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          size="40" maxlength="<%=PlateType.MAX_NAME_LENGTH%>"></td>
174      </tr>
175      <tr>
176        <td class="prompt">Geometry</td>
177        <td>
178          <%
179          if (plateType == null)
180          {
181            %>
182            <select name="plategeometry_id" class="required">
183            <%
184            for (PlateGeometry pg : plateGeometries)
185            {
186              if (pg.isRemoved() && pg.getId() != currentGeometryId) continue;
187              %>
188              <option value="<%=pg.getId()%>" <%=pg.getId() == currentGeometryId ? "selected" : ""%>><%=HTML.encodeTags(pg.getName())%>
189              <%
190            }
191            %>
192            </select>
193            can't be changed later
194            <%
195          }
196          else
197          {
198            %>
199            <%=Base.getEncodedName(currentGeometry, !readCurrentGeometry)%>
200            <%
201          }
202          %>
203        </td>
204      </tr>
205
206
207
208      <tr >
209        <td class="prompt">Description</td>
210        <td nowrap>
211          <textarea <%=clazz%> rows="4" cols="40" name="description" 
212            ><%=HTML.encodeTags(plateType == null ? cc.getPropertyValue("description") : plateType.getDescription())%></textarea>
213          <a href="javascript:Main.zoom('Description', 'platetype', 'description')"
214            title="Edit in larger window"><base:icon image="zoom.png" /></a>
215        </td>
216      </tr>
217      </table>
218      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
219    </t:tab>
220    </t:tabcontrol>
221
222    <table align="center">
223    <tr>
224      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
225      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
226    </tr>
227    </table>
228    </form>
229  </base:body>
230  </base:page>
231  <%
232}
233finally
234{
235  if (dc != null) dc.close();
236}
237%>
Note: See TracBrowser for help on using the repository browser.