source: trunk/www/lims/plates/edit_plate.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: 10.1 KB
Line 
1<%-- $Id: edit_plate.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  Copyright (C) 2007 Nicklas Nordborg
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 3
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with BASE. If not, see <http://www.gnu.org/licenses/>.
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.Plate"
36  import="net.sf.basedb.core.PlateType"
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.PLATE;
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  Plate plate = null;
70 
71  boolean readCurrentPlateType = true;
72  PlateType currentPlateType = null;
73
74  if (itemId == 0)
75  {
76    title = "Create plate";
77    cc.removeObject("item");
78   
79    int plateTypeId = Values.getInt(request.getParameter("platetype_id"));
80    if (plateTypeId != 0)
81    {
82      currentPlateType = PlateType.getById(dc, plateTypeId);
83    }
84    else if (cc.getPropertyFilter("plateType.name") != null)
85    {
86      currentPlateType = Base.getFirstMatching(dc, PlateType.getQuery(), "name", cc.getPropertyFilter("plateType.name"));
87    }
88  }
89  else
90  {
91    plate = Plate.getById(dc, itemId);
92    cc.setObject("item", plate);
93    title = "Edit plate -- " + HTML.encodeTags(plate.getName());
94    try
95    {
96      currentPlateType = plate.getPlateType();
97    }
98    catch (PermissionDeniedException ex)
99    {
100      readCurrentPlateType = false;
101    }
102  }
103  if (plate != null && !plate.hasPermission(Permission.WRITE))
104  {
105    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
106  }
107  final String clazz = "class=\"text\"";
108  final String requiredClazz = "class=\"text required\"";
109  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), plate);
110  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
111  %>
112  <base:page type="popup" title="<%=title%>">
113  <base:head scripts="tabcontrol.js,annotations.js" styles="tabcontrol.css">
114    <ext:scripts context="<%=jspContext%>" />
115    <ext:stylesheets context="<%=jspContext%>" />
116    <script language="JavaScript">
117    // Validate the "Plate" tab
118    function validatePlate()
119    {
120      var frm = document.forms['plate'];
121      if (Main.trimString(frm.name.value) == '')
122      {
123        alert("You must enter a name");
124        frm.name.focus();
125        return false;
126      }
127      if (frm.platetype_id && frm.platetype_id.length == 0)
128      {
129        alert("You must select a plate type");
130        return false;
131      }
132      return true;
133    }
134
135    // Submit the form
136    function saveSettings()
137    {
138      var frm = document.forms['plate'];
139      if (TabControl.validateActiveTab('settings'))
140      {
141        if (annotationsLoaded)
142        {
143          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
144        }
145        if (inheritedAnnotationsLoaded)
146        {
147          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
148        }
149        frm.submit();
150      }
151    }
152   
153    var annotationsLoaded = false;
154    var inheritedAnnotationsLoaded = false;
155    var parentsChanged = false;
156    function switchTab(tabControlId, tabId)
157    {
158      if (TabControl.setActiveTab(tabControlId, tabId))
159      {
160        if (tabId == 'annotations' && !annotationsLoaded)
161        {
162          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=plate == null ? 0 : plate.getId()%>);
163          annotationsLoaded = true;
164        }
165        else if (tabId == 'inheritedAnnotations' && 
166          (parentsChanged || !inheritedAnnotationsLoaded))
167        {
168          Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
169          inheritedAnnotationsLoaded = true;
170          parentsChanged = false;
171        }
172      }
173    }
174    function getParents()
175    {
176      return new Array();
177    }
178    function selectPlateTypeOnClick()
179    {
180      var frm = document.forms['plate'];
181      var url = '../platetypes/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setPlateTypeCallback';
182      if (frm.platetype_id.length > 0) url += '&item_id='+frm.platetype_id[0].value;
183      Main.openPopup(url, 'SelectArrayBatch', 1000, 700);
184    }
185    function setPlateTypeCallback(plateTypeId, name)
186    {
187      var frm = document.forms['plate'];
188      if (frm.platetype_id.length < 1) // >
189      {
190        frm.platetype_id[frm.platetype_id.length] = new Option();
191      }
192      frm.platetype_id[0].value = plateTypeId;
193      frm.platetype_id[0].text = name;
194      frm.platetype_id.selectedIndex = 0;
195    }
196
197    function init()
198    {
199      var frm = document.forms['plate'];
200      <%
201      if (plate == null)
202      {
203        %>
204        frm.name.focus();
205        frm.name.select();
206        <%
207      }
208      %>
209    }
210    </script>
211  </base:head>
212  <base:body onload="init()">
213    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
214    <form action="index.jsp?ID=<%=ID%>" method="post" name="plate" onsubmit="return false;">
215    <input type="hidden" name="cmd" value="UpdateItem">
216
217    <t:tabcontrol id="settings" 
218      subclass="content dialogtabcontrol"
219      position="bottom"  remember="<%=plate != null%>" switch="switchTab"
220      extensions="<%=invoker%>">
221    <t:tab id="info" title="Plate" validate="validatePlate()" helpid="plate.edit">
222      <table class="fullform input100 smaller">
223      <tr>
224        <th>Name</th>
225        <td><input <%=requiredClazz%> type="text" name="name" 
226          value="<%=HTML.encodeTags(plate == null ? Values.getString(cc.getPropertyValue("name"), "New plate") : plate.getName())%>" 
227          maxlength="<%=Plate.MAX_NAME_LENGTH%>"></td>
228        <td></td>
229      </tr>
230      <tr>
231        <th>Barcode</th>
232        <td><input <%=clazz%> type="text" name="barcode" 
233          value="<%=HTML.encodeTags(plate == null ? Values.getString(cc.getPropertyValue("barcode"), "") : plate.getBarcode())%>" 
234          maxlength="<%=Plate.MAX_BARCODE_LENGTH%>"></td>
235        <td></td>
236      </tr>
237      <tr>
238        <th><label for="destroyed">Destroyed</label></th>
239        <td><input type="checkbox" name="destroyed" id="destroyed" value="1"
240          <%=(plate != null && plate.isDestroyed()) || (plate == null && Values.getBoolean(cc.getPropertyValue("destroyed"))) ? "checked" : ""%>>
241        </td>
242        <td></td>
243      </tr>
244      <tr>
245        <th>Plate type</th>
246        <td>
247          <%
248          if (plate != null)
249          {
250            %>
251            <%=Base.getEncodedName(currentPlateType, !readCurrentPlateType)%>
252            <%
253          }
254          else
255          {
256            %>
257            <table>
258            <tr>
259            <td>
260              <select name="platetype_id" size="1" 
261                <%=!readCurrentPlateType ? "disabled readonly class=\"disabled\"" : "class=\"required\""%>
262                style="width: 20em;">
263              <%
264              if (!readCurrentPlateType)
265              {
266                %>
267                <option value="-1">- denied -
268                <%
269              }
270              else
271              {
272                if (currentPlateType != null)
273                {
274                  %>
275                  <option value="<%=currentPlateType.getId()%>" selected><%=HTML.encodeTags(currentPlateType.getName())%>
276                  <%
277                }
278              }
279              %>
280              </select>
281            </td>
282            <td><base:button onclick="selectPlateTypeOnClick()" title="Select&hellip;" /></td>
283            </tr>
284            </table>
285            <%
286          }
287          %>
288        </td>
289        <td></td>
290      </tr>
291      <tr class="dynamic">
292        <th>Description</th>
293        <td>
294          <textarea <%=clazz%> rows="6" name="description" 
295            ><%=HTML.encodeTags(plate == null ? cc.getPropertyValue("description") : plate.getDescription())%></textarea>
296        </td>
297        <td style="width: 20px;">
298          <base:icon image="zoom.png" 
299            onclick="Main.zoom('Description', 'plate', 'description')"
300            tooltip="Edit in larger window"
301          />
302        </td>
303      </tr>
304      </table>
305    </t:tab>
306   
307    <t:tab id="annotations" title="Annotations" helpid="annotations.edit"><iframe 
308      name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
309      style="width: 100%; height: 100%;"></iframe></t:tab>   
310   
311    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
312      helpid="annotations.edit.inherited"><iframe 
313        name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
314        style="width: 100%; height: 100%;"></iframe></t:tab>
315
316    </t:tabcontrol>
317    </form>
318   
319    <div class="legend">
320      <base:icon image="required.gif" /> = required information
321    </div>
322
323    <base:buttongroup subclass="dialogbuttons">
324      <base:button onclick="saveSettings()" title="Save" />
325      <base:button onclick="window.close()" title="Cancel" />
326    </base:buttongroup>
327  </base:body>
328  </base:page>
329  <%
330}
331finally
332{
333  if (dc != null) dc.close();
334}
335%>
Note: See TracBrowser for help on using the repository browser.