source: trunk/www/lims/platemappings/edit_mapping.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: 9.4 KB
Line 
1<%-- $Id: edit_mapping.jsp 5920 2012-01-10 09:41:59Z 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    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
181    <form action="index.jsp?ID=<%=ID%>" method="post" name="mapping" onsubmit="return false;">
182    <input type="hidden" name="cmd" value="UpdateItem">
183
184    <t:tabcontrol id="settings"
185      subclass="content dialogtabcontrol"
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="fullform input100 smaller">
190      <tr>
191        <th>Name</th>
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          maxlength="<%=PlateMapping.MAX_NAME_LENGTH%>"></td>
195        <td></td>
196      </tr>
197      <tr>
198        <th>Source plates</th>
199        <td>
200          <%
201          if (mapping == null)
202          {
203            %>
204            <input <%=requiredClazz%> type="text" name="source_count" style="width: 15em;"
205              value="<%=Values.getInt(cc.getPropertyValue("sourceCount"), 1)%>" 
206              maxlength="10" onkeypress="return Numbers.integerOnly(event)">
207            plate(s) of
208            <select name="sourcegeometry_id" class="required">
209            <%
210            for (PlateGeometry pg : plateGeometries)
211            {
212              %>
213              <option value="<%=pg.getId()%>" <%=pg.getId() == currentSourceGeometryId ? "selected" : ""%>><%=HTML.encodeTags(pg.getName())%>
214              <%
215            }
216            %>
217            </select><br>
218            can't be changed later
219            <%
220          }
221          else
222          {
223            %>
224            <%=mapping.getSourceCount()%> plate(s) of
225            <%=Base.getEncodedName(currentSourceGeometry, !readCurrentSourceGeometry)%>
226            <%
227          }
228          %>
229        </td>
230        <td></td>
231      </tr>
232      <tr>
233        <th>Destination plates</th>
234        <td>
235          <%
236          if (mapping == null)
237          {
238            %>
239            <input <%=requiredClazz%> type="text" name="destination_count" style="width: 15em;"
240              value="<%=Values.getInt(cc.getPropertyValue("destinationCount"), 1)%>" 
241              maxlength="10" onkeypress="return Numbers.integerOnly(event)">
242            plate(s) of
243            <select name="destinationgeometry_id" class="required">
244            <%
245            for (PlateGeometry pg : plateGeometries)
246            {
247              %>
248              <option value="<%=pg.getId()%>" <%=pg.getId() == currentDestinationGeometryId ? "selected" : ""%>><%=HTML.encodeTags(pg.getName())%>
249              <%
250            }
251            %>
252            </select><br>
253            can't be changed later
254            <%
255          }
256          else
257          {
258            %>
259            <%=mapping.getDestinationCount()%> plate(s) of
260            <%=Base.getEncodedName(currentDestinationGeometry, !readCurrentDestinationGeometry)%>
261            <%
262          }
263          %>
264        </td>
265        <td></td>
266      </tr>
267      <tr class="big">
268        <th>Image</th>
269        <td>
270          <input <%=clazz%> type="text" name="image" 
271            value="<%=HTML.encodeTags(mapping == null ? "" : mapping.getImage())%>" 
272            maxlength="<%=PlateMapping.MAX_IMAGE_LENGTH%>" 
273            onBlur="updateImage()">
274            <br><br>
275            <%
276            String src = "noimage.gif";
277            if (mapping != null && mapping.getImage() != null)
278            {
279              src = mapping.getImage();
280            }
281            %>
282            <img id="mappingImage" src="../../images/platemappings/<%=src%>">
283        </td>
284        <td></td>
285      </tr>
286      <tr class="dynamic">
287        <th>Description</th>
288        <td>
289          <textarea <%=clazz%> rows="6" name="description" 
290            ><%=HTML.encodeTags(mapping == null ? cc.getPropertyValue("description") : mapping.getDescription())%></textarea>
291        </td>
292        <td style="width: 20px;">
293          <base:icon image="zoom.png" 
294            onclick="Main.zoom('Description', 'mapping', 'description')"
295            tooltip="Edit in larger window"
296          />
297        </td>
298      </tr>
299      </table>
300    </t:tab>
301    </t:tabcontrol>
302    </form>
303   
304    <div class="legend">
305      <base:icon image="required.gif" /> = required information
306    </div>
307
308    <base:buttongroup subclass="dialogbuttons">
309      <base:button onclick="saveSettings()" title="Save" />
310      <base:button onclick="window.close()" title="Cancel" />
311    </base:buttongroup>
312  </base:body>
313  </base:page>
314  <%
315}
316finally
317{
318  if (dc != null) dc.close();
319}
320%>
Note: See TracBrowser for help on using the repository browser.