source: trunk/www/lims/platemappings/edit_mapping.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: 9.4 KB
Line 
1<%-- $Id: edit_mapping.jsp 5908 2011-12-13 13:48:46Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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
23  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.ItemContext"
31  import="net.sf.basedb.core.SystemItems"
32  import="net.sf.basedb.core.Permission"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.PlateMapping"
35  import="net.sf.basedb.core.PlateGeometry"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.ItemResultList"
38  import="net.sf.basedb.core.PermissionDeniedException"
39  import="net.sf.basedb.core.BaseException"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.util.HTML"
44  import="net.sf.basedb.util.Values"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
47  import="net.sf.basedb.clients.web.extensions.JspContext"
48  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
49  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
50  import="java.util.List"
51  import="java.util.Set"
52  import="java.util.HashSet"
53  import="java.util.Date"
54%>
55<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
56<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
57<%
58final Item itemType = Item.PLATEMAPPING;
59final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
60final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
61final int itemId = cc.getId();
62final String ID = sc.getId();
63final float scale = Base.getScale(sc);
64final DbControl dc = sc.newDbControl();
65try
66{
67  String title = null;
68  PlateMapping mapping = null;
69  ItemResultList<PlateGeometry> plateGeometries = null;
70 
71  boolean readCurrentSourceGeometry = true;
72  PlateGeometry currentSourceGeometry = null;
73  int currentSourceGeometryId = 0;
74 
75  boolean readCurrentDestinationGeometry = true;
76  PlateGeometry currentDestinationGeometry = null;
77  int currentDestinationGeometryId = 0;
78 
79  if (itemId == 0)
80  {
81    title = "Create plate mapping";
82    cc.removeObject("item");
83   
84    ItemQuery<PlateGeometry> geometryQuery = PlateGeometry.getQuery();
85    geometryQuery.order(Orders.asc(Hql.property("name")));
86    geometryQuery.setCacheResult(true);
87
88    plateGeometries = geometryQuery.list(dc);
89    currentSourceGeometryId = Values.getInt(cc.getPropertyValue("sourceGeometry"), 0);
90    currentDestinationGeometryId = Values.getInt(cc.getPropertyValue("destinationGeometry"), 0);
91  }
92  else
93  {
94    mapping = PlateMapping.getById(dc, itemId);
95    cc.setObject("item", mapping);
96    title = "Edit plate mapping -- " + HTML.encodeTags(mapping.getName());
97   
98    try
99    {
100      currentSourceGeometry = mapping.getSourceGeometry();
101    }
102    catch (PermissionDeniedException ex)
103    {
104      readCurrentSourceGeometry = false;
105    }
106    try
107    {
108      currentDestinationGeometry = mapping.getDestinationGeometry();
109    }
110    catch (PermissionDeniedException ex)
111    {
112      readCurrentDestinationGeometry = false;
113    }
114  }
115  if (mapping != null && !mapping.hasPermission(Permission.WRITE))
116  {
117    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
118  }
119  final String clazz = "class=\"text\"";
120  final String requiredClazz = "class=\"text required\"";
121  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), mapping);
122  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
123  %>
124  <base:page type="popup" title="<%=title%>">
125  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
126    <ext:scripts context="<%=jspContext%>" />
127    <ext:stylesheets context="<%=jspContext%>" />
128    <script language="JavaScript">
129    // Validate the "PlateMapping" tab
130    function validatePlateMapping()
131    {
132      var frm = document.forms['mapping'];
133      if (Main.trimString(frm.name.value) == '')
134      {
135        alert("You must enter a name");
136        frm.name.focus();
137        return false;
138      }
139      return true;
140    }
141
142    // Submit the form
143    function saveSettings()
144    {
145      var frm = document.forms['mapping'];
146      if (TabControl.validateActiveTab('settings'))
147      {
148        frm.submit();
149      }
150    }
151
152    function updateImage()
153    {
154      var frm = document.forms['mapping'];
155      var newSrc = frm.image.value;
156      var imageSrc = '../../images/platemappings/'+newSrc;
157      var image = document.getElementById('mappingImage');
158      if (image && newSrc && imageSrc != image.src)
159      {
160        image.src = imageSrc;
161      }
162    }
163
164    function init()
165    {
166      var frm = document.forms['mapping'];
167      <%
168      if (mapping == null)
169      {
170        %>
171        frm.name.focus();
172        frm.name.select();
173        <%
174      }
175      %>
176    }
177    </script>
178  </base:head>
179  <base:body onload="init()">
180    <p>
181    <form action="index.jsp?ID=<%=ID%>" method="post" name="mapping" onsubmit="return false;">
182    <input type="hidden" name="cmd" value="UpdateItem">
183
184    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
185    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*280)+"px;"%>" 
186      position="bottom" remember="<%=mapping != null%>"
187      extensions="<%=invoker%>">
188    <t:tab id="info" title="Plate mapping" validate="validatePlateMapping()" helpid="platemapping.edit">
189      <table class="form" cellspacing=0>
190      <tr>
191        <td class="prompt">Name</td>
192        <td><input <%=requiredClazz%> type="text" name="name" 
193          value="<%=HTML.encodeTags(mapping == null ? Values.getString(cc.getPropertyValue("name"), "New plate mapping") : mapping.getName())%>" 
194          size="40" maxlength="<%=PlateMapping.MAX_NAME_LENGTH%>"></td>
195      </tr>
196      <tr >
197        <td class="prompt">Source plates</td>
198        <td>
199          <%
200          if (mapping == null)
201          {
202            %>
203            <input <%=requiredClazz%> type="text" name="source_count" 
204              value="<%=Values.getInt(cc.getPropertyValue("sourceCount"), 1)%>" 
205              size="12" maxlength="10" onkeypress="return Numbers.integerOnly(event)">
206            plate(s) of
207            <select name="sourcegeometry_id" class="required">
208            <%
209            for (PlateGeometry pg : plateGeometries)
210            {
211              %>
212              <option value="<%=pg.getId()%>" <%=pg.getId() == currentSourceGeometryId ? "selected" : ""%>><%=HTML.encodeTags(pg.getName())%>
213              <%
214            }
215            %>
216            </select><br>
217            can't be changed later
218            <%
219          }
220          else
221          {
222            %>
223            <%=mapping.getSourceCount()%> plate(s) of
224            <%=Base.getEncodedName(currentSourceGeometry, !readCurrentSourceGeometry)%>
225            <%
226          }
227          %>
228        </td>
229      </tr>
230      <tr >
231        <td class="prompt">Destination plates</td>
232        <td>
233          <%
234          if (mapping == null)
235          {
236            %>
237            <input <%=requiredClazz%> type="text" name="destination_count" 
238              value="<%=Values.getInt(cc.getPropertyValue("destinationCount"), 1)%>" 
239              size="12" maxlength="10" onkeypress="return Numbers.integerOnly(event)">
240            plate(s) of
241            <select name="destinationgeometry_id" class="required">
242            <%
243            for (PlateGeometry pg : plateGeometries)
244            {
245              %>
246              <option value="<%=pg.getId()%>" <%=pg.getId() == currentDestinationGeometryId ? "selected" : ""%>><%=HTML.encodeTags(pg.getName())%>
247              <%
248            }
249            %>
250            </select><br>
251            can't be changed later
252            <%
253          }
254          else
255          {
256            %>
257            <%=mapping.getDestinationCount()%> plate(s) of
258            <%=Base.getEncodedName(currentDestinationGeometry, !readCurrentDestinationGeometry)%>
259            <%
260          }
261          %>
262        </td>
263      </tr>
264      <tr >
265        <td class="prompt">Image</td>
266        <td>
267          <input <%=clazz%> type="text" name="image" 
268            value="<%=HTML.encodeTags(mapping == null ? "" : mapping.getImage())%>" 
269            size="40" maxlength="<%=PlateMapping.MAX_IMAGE_LENGTH%>" 
270            onBlur="updateImage()">
271            <br><br>
272            <%
273            String src = "noimage.gif";
274            if (mapping != null && mapping.getImage() != null)
275            {
276              src = mapping.getImage();
277            }
278            %>
279            <img id="mappingImage" src="../../images/platemappings/<%=src%>">
280        </td>
281      </tr>
282      <tr >
283        <td class="prompt">Description</td>
284        <td nowrap>
285          <textarea <%=clazz%> rows="4" cols="40" name="description" 
286            ><%=HTML.encodeTags(mapping == null ? cc.getPropertyValue("description") : mapping.getDescription())%></textarea>
287          <a href="javascript:Main.zoom('Description', 'mapping', 'description')"
288            title="Edit in larger window"><base:icon image="zoom.png" /></a>
289        </td>
290      </tr>
291      </table>
292      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
293    </t:tab>
294    </t:tabcontrol>
295
296    <table align="center">
297    <tr>
298      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
299      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
300    </tr>
301    </table>
302    </form>
303  </base:body>
304  </base:page>
305  <%
306}
307finally
308{
309  if (dc != null) dc.close();
310}
311%>
Note: See TracBrowser for help on using the repository browser.