source: trunk/www/biomaterials/bioplatetypes/edit_platetype.jsp @ 5709

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

References #1597: Subtypes of items

Added link to item subtype from bioplate type which makes it possible to restrict/filter on the biomaterial subtype when selecting biomaterial for a plate. The "restriction" is in the gui only and is not checked by the core since it is possible to change the subtype of a biomaterial after it has been placed on a plate.

As a result of this the "Labeled extract reaction plate" is brought back to life again.

Also discovered that the bioplate event wizards should probably be able to utilize subtype information for some improvements. So there are still some things to fix before this ticket can be closed.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 9.8 KB
Line 
1<%-- $Id $
2  ------------------------------------------------------------------
3  Copyright (C) 2010 Nicklas Nordborg
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.BioPlateType"
35  import="net.sf.basedb.core.BioWell"
36  import="net.sf.basedb.core.ItemSubtype"
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.Expressions"
42  import="net.sf.basedb.core.query.Restrictions"
43  import="net.sf.basedb.core.query.Orders"
44  import="net.sf.basedb.core.query.Hql"
45  import="net.sf.basedb.clients.web.Base"
46  import="net.sf.basedb.clients.web.util.HTML"
47  import="net.sf.basedb.util.Values"
48  import="net.sf.basedb.core.plugin.GuiContext"
49  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
50  import="net.sf.basedb.clients.web.extensions.JspContext"
51  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
52  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
53  import="java.util.List"
54  import="java.util.Set"
55  import="java.util.HashSet"
56  import="java.util.Date"
57%>
58<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
59<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
60<%
61final Item itemType = Item.BIOPLATETYPE;
62final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
63final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
64final int itemId = cc.getId();
65final String ID = sc.getId();
66final float scale = Base.getScale(sc);
67final DbControl dc = sc.newDbControl();
68try
69{
70  String title = null;
71  BioPlateType bioPlateType = null;
72  BioWell.LockMode lockMode = BioWell.LockMode.UNLOCKED;
73  boolean readCurrentSubtype = true;
74  ItemSubtype currentSubtype = null;
75  ItemQuery<ItemSubtype> subtypesQuery = null;
76 
77  if (itemId == 0)
78  {
79    title = "Create bioplate type";
80    cc.removeObject("item");
81    int lm = Values.getInt(cc.getPropertyValue("lockMode"));
82    lockMode = BioWell.LockMode.fromValue(lm);
83    subtypesQuery = Base.getSubtypesQuery(null);
84    subtypesQuery.restrict(
85        Restrictions.in(
86          Hql.property("itemType"), 
87          Expressions.integer(Item.SAMPLE.getValue()), Expressions.integer(Item.EXTRACT.getValue())
88        ));
89  }
90  else
91  {
92    bioPlateType = BioPlateType.getById(dc, itemId);
93    bioPlateType.checkPermission(Permission.WRITE);
94    lockMode = bioPlateType.getLockMode();
95    cc.setObject("item", bioPlateType);
96    title = "Edit bioplate type -- " + HTML.encodeTags(bioPlateType.getName());
97    try
98    {
99      currentSubtype = bioPlateType.getItemSubtype();
100    }
101    catch (PermissionDeniedException ex)
102    {
103      readCurrentSubtype = false;
104    }
105    if (bioPlateType.getBioMaterialType() != null)
106    {
107      subtypesQuery = Base.getSubtypesQuery(bioPlateType.getBioMaterialType());
108    }
109  }
110  final String clazz = "class=\"text\"";
111  final String requiredClazz = "class=\"text required\"";
112  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), bioPlateType);
113  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
114
115  %>
116  <base:page type="popup" title="<%=title%>">
117  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
118    <ext:scripts context="<%=jspContext%>" />
119    <ext:stylesheets context="<%=jspContext%>" />
120    <script language="JavaScript">
121    // Validate the "BioPlateType" tab
122    function validateBioPlateType()
123    {
124      var frm = document.forms['bioPlateType'];
125      if (Main.trimString(frm.name.value) == '')
126      {
127        alert("You must enter a name");
128        frm.name.focus();
129        return false;
130      }
131      return true;
132    }
133
134    // Submit the form
135    function saveSettings()
136    {
137      var frm = document.forms['bioPlateType'];
138      if (TabControl.validateActiveTab('settings'))
139      {
140        frm.submit();
141      }
142    }
143   
144    function init()
145    {
146      var frm = document.forms['bioPlateType'];
147      <%
148      if (bioPlateType == null)
149      {
150        %>
151        frm.name.focus();
152        frm.name.select();
153        bioMaterialTypeOnChange();
154        <%
155      }
156      %>
157    }
158   
159    var subtypeOptions = null;
160    function bioMaterialTypeOnChange()
161    {
162      var frm = document.forms['bioPlateType'];
163      if (subtypeOptions == null)
164      {
165        // Cache all options in the list
166        subtypeOptions = new Array();
167        for (var i = 1; i < frm.subtype_id.length; i++)
168        {
169          var opt = frm.subtype_id[i];
170          subtypeOptions[subtypeOptions.length] = frm.subtype_id[i];
171        }
172      }
173     
174      var bmType = frm.bioMaterialType[frm.bioMaterialType.selectedIndex].value;
175     
176      frm.subtype_id.selectedIndex = 0;
177      if (bmType == '')
178      {
179        frm.subtype_id.disabled = true;
180      }
181      else
182      {
183        frm.subtype_id.disabled = false;
184        // Clean the list...
185        frm.subtype_id.length = 1;
186        // ...and re-populate from the cache
187        for (var i = 0; i < subtypeOptions.length; i++)
188        {
189          if (subtypeOptions[i].attributes['bmtype'].value == bmType)
190          {
191            frm.subtype_id[frm.subtype_id.length] = subtypeOptions[i];
192          }
193        }
194      }
195    }
196    </script>
197  </base:head>
198  <base:body onload="init()">
199    <p>
200    <form action="index.jsp?ID=<%=ID%>" method="post" name="bioPlateType" onsubmit="return false;">
201    <input type="hidden" name="cmd" value="UpdateItem">
202
203    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
204    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*260)+"px;"%>" 
205      position="bottom"  remember="<%=bioPlateType != null%>"
206      extensions="<%=invoker%>">
207    <t:tab id="info" title="Bioplate type" validate="validateBioPlateType()" helpid="bioplatetype.edit">
208      <table class="form" cellspacing=0>
209      <tr>
210        <td class="prompt">Name</td>
211        <td><input <%=requiredClazz%> type="text" name="name" 
212          value="<%=HTML.encodeTags(bioPlateType == null ? Values.getString(cc.getPropertyValue("name"), "New bioplate type") : bioPlateType.getName())%>" 
213          size="40" maxlength="<%=BioPlateType.MAX_NAME_LENGTH%>"></td>
214      </tr>
215      <tr valign=top>
216        <td class="prompt">Biomaterial type</td>
217        <%
218        if (bioPlateType == null)
219        {
220          %>
221            <td>
222              <select name="bioMaterialType" class="required unchangeable" onchange="bioMaterialTypeOnChange()">
223              <option value="">- any -
224              <option value="<%=Item.SAMPLE.name()%>">Sample
225              <option value="<%=Item.EXTRACT.name()%>">Extract
226              </select>
227            </td>
228          <%
229        }
230        else
231        {
232          %>
233          <td><%=bioPlateType.getBioMaterialType() == null ? "- any -" : bioPlateType.getBioMaterialType()%></td>
234          <%
235        }
236        %>
237      </tr>
238      <%
239      if (subtypesQuery != null)
240      {
241        %>
242        <tr valign="top">
243          <td class="prompt">Biomaterial subtype</td>
244          <td colspan="2">
245            <select name="subtype_id"
246              <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>
247              onchange="subtypeOnChange()"
248              >
249            <%
250            if (!readCurrentSubtype)
251            {
252              %>
253              <option value="-1">- denied -
254              <%
255            }
256            else
257            {
258              %>
259              <option value="0">-any-
260              <%
261              int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
262              for (ItemSubtype subtype : subtypesQuery.list(dc))
263              {
264                int id = subtype.getId();
265                if (id != currentSubtypeId && subtype.isRemoved()) continue;
266                %>
267                <option value="<%=id == currentSubtypeId && bioPlateType != null ? -id : id%>" 
268                  <%=id == currentSubtypeId ? "selected" : ""%>
269                  title="<%=HTML.encodeTags(subtype.getDescription()) %>"
270                  bmtype="<%=subtype.getMainItemType().name() %>"
271                  ><%=HTML.encodeTags(subtype.getName())%>
272                <%
273              }
274            }
275            %>
276            </select>
277          </td>
278        </tr>
279        <%
280      }
281      %>
282      <tr>
283        <td class="prompt">Well lock mode</td>
284        <td>
285          <select name="lockMode">
286          <%
287          for (BioWell.LockMode lm : BioWell.LockMode.values())
288          {
289            String selected = lm == lockMode ? "selected" : "";
290            %>
291            <option value="<%=lm.name()%>" <%=selected%>><%=lm%>
292            <%
293          }
294          %>
295          </select>
296        </td>
297      </tr>
298      <tr valign=top>
299        <td class="prompt">Description</td>
300        <td nowrap>
301          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
302            ><%=HTML.encodeTags(bioPlateType == null ? cc.getPropertyValue("description") : bioPlateType.getDescription())%></textarea>
303          <a href="javascript:Main.zoom('Description', 'bioPlateType', 'description')"
304            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
305        </td>
306      </tr>
307      </table>
308      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i>
309      <%if (bioPlateType == null) {%><br>
310        <i><base:icon image="unchangeable.gif" /> = can't be changed later</i>
311        <%}%>
312      </div>
313    </t:tab>
314    </t:tabcontrol>
315
316    <table align="center">
317    <tr>
318      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
319      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
320    </tr>
321    </table>
322    </form>
323  </base:body>
324  </base:page>
325  <%
326}
327finally
328{
329  if (dc != null) dc.close();
330}
331%>
Note: See TracBrowser for help on using the repository browser.