source: trunk/www/lims/arraybatches/edit_batch.jsp @ 6254

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

References #1729 and #1730. Use lazy loading of 'Annotations'/'Inherited annotations' for all other items.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 13.7 KB
Line 
1<%-- $Id: edit_batch.jsp 6254 2013-03-22 07:28:26Z 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.ArrayBatch"
35  import="net.sf.basedb.core.ArrayDesign"
36  import="net.sf.basedb.core.Protocol"
37  import="net.sf.basedb.core.ItemSubtype"
38  import="net.sf.basedb.core.Project"
39  import="net.sf.basedb.core.Hardware"
40  import="net.sf.basedb.core.ItemQuery"
41  import="net.sf.basedb.core.ItemResultList"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.core.BaseException"
44  import="net.sf.basedb.core.query.Orders"
45  import="net.sf.basedb.core.query.Hql"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.util.HTML"
48  import="net.sf.basedb.util.Values"
49  import="net.sf.basedb.core.plugin.GuiContext"
50  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
51  import="net.sf.basedb.clients.web.extensions.JspContext"
52  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
53  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
54  import="java.util.List"
55  import="java.util.Set"
56  import="java.util.HashSet"
57  import="java.util.Date"
58%>
59<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
60<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
61<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
62<%
63final Item itemType = Item.ARRAYBATCH;
64final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
65final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
66final int itemId = cc.getId();
67final String ID = sc.getId();
68final float scale = Base.getScale(sc);
69final DbControl dc = sc.newDbControl();
70try
71{
72  String title = null;
73  ArrayBatch batch = null;
74 
75  boolean readCurrentArrayDesign = true;
76  ArrayDesign currentArrayDesign = null;
77  List<ArrayDesign> defaultArrayDesigns = null;
78  boolean readCurrentProtocol = true;
79  Protocol currentProtocol = null;
80  List<Protocol> defaultProtocols = null;
81  boolean readCurrentPrintRobot = true;
82  Hardware currentPrintRobot = null;
83  List<Hardware> defaultPrintRobots = null;
84
85  // Load recently used items
86  List<ArrayDesign> recentArrayDesigns = (List<ArrayDesign>)cc.getRecent(dc, Item.ARRAYDESIGN);
87  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL);
88  List<Hardware> recentPrintRobots = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE);
89 
90  int activeProjectId = sc.getActiveProjectId();
91  if (activeProjectId > 0)
92  {
93    Project activeProject = Project.getById(dc, activeProjectId);
94    try
95    {
96      defaultArrayDesigns = (List<ArrayDesign>)activeProject.findDefaultItems(dc, Item.ARRAYDESIGN, true);
97    }
98    catch (PermissionDeniedException pdex)
99    {}
100    try
101    {
102      defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc, 
103          ItemSubtype.getById(dc, SystemItems.getId(Protocol.PRINTING)), false);
104    }
105    catch (PermissionDeniedException pdex)
106    {}
107    try
108    {
109      defaultPrintRobots = (List<Hardware>)activeProject.findDefaultItems(dc, 
110          ItemSubtype.getById(dc, SystemItems.getId(Hardware.PRINT_ROBOT)), false);
111    }
112    catch (PermissionDeniedException pdex)
113    {}
114  }
115  if (itemId == 0)
116  {
117    title = "Create array batch";
118    cc.removeObject("item");
119    int arrayDesignId = Values.getInt(request.getParameter("arraydesign_id"));
120    if (arrayDesignId != 0)
121    {
122      currentArrayDesign = ArrayDesign.getById(dc, arrayDesignId);
123    }
124    else if (cc.getPropertyFilter("arrayDesign.name") != null)
125    {
126      currentArrayDesign = Base.getFirstMatching(dc, ArrayDesign.getQuery(), "name", cc.getPropertyFilter("arrayDesign.name"));
127    }
128    if (cc.getPropertyFilter("printRobot.name") != null)
129    {
130      currentPrintRobot = Base.getFirstMatching(dc, Hardware.getQuery(), "name", cc.getPropertyFilter("printRobot.name"));
131    }
132    if (cc.getPropertyFilter("protocol.name") != null)
133    {
134      currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("protocol.name"));
135    }
136  }
137  else
138  {
139    batch = ArrayBatch.getById(dc, itemId);
140    cc.setObject("item", batch);
141    title = "Edit array batch -- " + HTML.encodeTags(batch.getName());
142    try
143    {
144      currentArrayDesign = batch.getArrayDesign();
145    }
146    catch (PermissionDeniedException ex)
147    {
148      readCurrentArrayDesign = false;
149    }
150    try
151    {
152      currentPrintRobot = batch.getPrintRobot();     
153    }
154    catch (PermissionDeniedException ex)
155    {
156      readCurrentPrintRobot = false;
157    }
158    try
159    {
160      currentProtocol = batch.getProtocol();     
161    }
162    catch (PermissionDeniedException ex)
163    {
164      readCurrentProtocol = false;
165    }
166  }
167  if (batch != null && !batch.hasPermission(Permission.WRITE))
168  {
169    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
170  }
171 
172 
173  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), batch);
174  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
175  %>
176  <base:page type="popup" title="<%=title%>">
177  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
178    <ext:scripts context="<%=jspContext%>" />
179    <ext:stylesheets context="<%=jspContext%>" />
180    <script>
181    // Validate the "ArrayBatch" tab
182    function validateArrayBatch()
183    {
184      var frm = document.forms['batch'];
185      if (Main.trimString(frm.name.value) == '')
186      {
187        Forms.showNotification(frm.name, 'You must enter a name');
188        return false;
189      }
190      if (frm.arraydesign_id && !frm.arraydesign_id.value)
191      {
192        Forms.showNotification('arraydesign_id.select', 'You must select an array design');
193        return false;
194      }
195      return true;
196    }
197
198    // Submit the form
199    function saveSettings()
200    {
201      var frm = document.forms['batch'];
202      if (TabControl.validateActiveTab('settings'))
203      {
204        Annotations.saveModifiedAnnotationsToForm(frm);
205        Annotations.saveInheritedAnnotationsToForm(frm);
206        frm.submit();
207      }
208    }
209   
210    function loadAnnotationsFrame()
211    {
212      Annotations.autoLoadEditFrame(getProtocolId());
213    }
214   
215    function loadInheritedAnnotationsFrame()
216    {
217      Annotations.autoLoadInheritFrame(getParents());
218    }
219
220    function getProtocolId()
221    {
222      var frm = document.forms['batch'];
223      var protocolId = 0;
224      if (frm.protocol_id.length > 0 && !frm.protocol_id.disabled)
225      {
226        protocolId = Math.abs(parseInt(frm.protocol_id[frm.protocol_id.selectedIndex].value));       
227      }
228      return protocolId;
229    }
230
231    function getParents()
232    {
233      var frm = document.forms['batch'];
234      var parents = new Array();
235      if (frm.arraydesign_id)
236      {
237        var arrayDesignId = Math.abs(parseInt(frm.arraydesign_id[frm.arraydesign_id.selectedIndex].value));
238        if (arrayDesignId > 0) parents[parents.length] = 'ARRAYDESIGN:'+arrayDesignId;
239      }
240      return parents;
241    }
242
243    function selectArrayDesignOnClick()
244    {
245      var frm = document.forms['batch'];
246      var url = '../../lims/arraydesigns/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setArrayDesignCallback';
247      if (frm.arraydesign_id.length > 0)
248      {
249        var id = Math.abs(parseInt(frm.arraydesign_id[0].value));       
250        url += '&item_id='+id;
251      }
252      Main.openPopup(url, 'SelectArrayDesign', 1050, 700);
253    }
254    function setArrayDesignCallback(id, name)
255    {
256      var frm = document.forms['batch'];
257      var list = frm.arraydesign_id;
258      if (list.length < 1 || list[0].value == '0') // >
259      {
260        Forms.addListOption(list, 0, new Option());
261      }
262      list[0].value = id;
263      list[0].text = name;
264      list.selectedIndex = 0;
265    }
266
267    function selectProtocolOnClick()
268    {
269      var frm = document.forms['batch'];
270      var url = '../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setProtocolCallback';
271      if (frm.protocol_id.length > 1)
272      {
273        var id = Math.abs(parseInt(frm.protocol_id[1].value));       
274        url += '&item_id='+id;
275      }
276      url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=<%=SystemItems.getId(Protocol.PRINTING)%>';
277      Main.openPopup(url, 'SelectProtocol', 1050, 700);
278    }
279    function setProtocolCallback(id, name)
280    {
281      var frm = document.forms['batch'];
282      var list = frm.protocol_id;
283      if (list.length < 2 || list[1].value == '0') // >
284      {
285        Forms.addListOption(list, 1, new Option());
286      }
287      list[1].value = id;
288      list[1].text = name;
289      list.selectedIndex = 1;
290    }
291    function selectPrintRobotOnClick()
292    {
293      var frm = document.forms['batch'];
294      var url = '../../admin/hardware/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setPrintRobotCallback';
295      if (frm.printrobot_id.length > 1)
296      {
297        var id = Math.abs(parseInt(frm.printrobot_id[1].value));       
298        url += '&item_id='+id;
299      }
300      url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=<%=SystemItems.getId(Hardware.PRINT_ROBOT)%>';
301      Main.openPopup(url, 'SelectPrintRobot', 1050, 700);
302    }
303    function setPrintRobotCallback(id, name)
304    {
305      var frm = document.forms['batch'];
306      var list = frm.printrobot_id;
307      if (list.length < 2 || list[1].value == '0') // >
308      {
309        Forms.addListOption(list, 1, new Option());
310      }
311      list[1].value = id;
312      list[1].text = name;
313      list.selectedIndex = 1;
314    }
315
316   
317    function init()
318    {
319      var frm = document.forms['batch'];
320      <%
321      if (batch == null)
322      {
323        %>
324        frm.name.focus();
325        frm.name.select();
326        <%
327      }
328      %>
329    }
330    </script>
331  </base:head>
332  <base:body onload="init()">
333    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
334    <form action="index.jsp?ID=<%=ID%>" method="post" name="batch">
335    <input type="hidden" name="cmd" value="UpdateItem">
336
337    <t:tabcontrol id="settings" 
338      subclass="content dialogtabcontrol"
339      position="bottom"  remember="<%=batch != null%>" 
340      extensions="<%=invoker%>">
341    <t:tab id="info" title="Array batch" validate="validateArrayBatch()" helpid="arraybatch.edit">
342      <table class="fullform input100">
343      <tr>
344        <th>Name</th>
345        <td><input class="text required" type="text" name="name" 
346          value="<%=HTML.encodeTags(batch == null ? Values.getString(cc.getPropertyValue("name"), "New array batch") : batch.getName())%>" 
347          maxlength="<%=ArrayBatch.MAX_NAME_LENGTH%>"></td>
348        <td></td>
349      </tr>
350      <tr>
351        <th>Array design</th>
352        <td>
353          <%
354          if (batch != null)
355          {
356            %>
357            <%=Base.getEncodedName(currentArrayDesign, !readCurrentArrayDesign)%>
358            <%
359          }
360          else
361          {
362            %>
363            <base:select 
364              id="arraydesign_id"
365              clazz="selectionlist required"
366              required="true"
367              current="<%=currentArrayDesign%>"
368              denied="<%=!readCurrentArrayDesign%>"
369              recent="<%=recentArrayDesigns%>"
370              defaultitems="<%=defaultArrayDesigns%>"
371              newitem="true"
372              onselect="selectArrayDesignOnClick()"
373            />
374            <%
375          }
376          %>
377        </td>
378        <td></td>
379      </tr>
380      <tr>
381        <th>Print robot</th>
382        <td>
383          <base:select 
384            id="printrobot_id"
385            clazz="selectionlist"
386            required="false"
387            current="<%=currentPrintRobot%>"
388            denied="<%=!readCurrentPrintRobot%>"
389            recent="<%=recentPrintRobots%>"
390            defaultitems="<%=defaultPrintRobots%>"
391            newitem="<%=batch == null%>"
392            onselect="selectPrintRobotOnClick()"
393          />
394        </td>
395        <td></td>
396      </tr>
397      <tr>
398        <th>Protocol</th>
399        <td>
400          <base:select 
401            id="protocol_id"
402            clazz="selectionlist"
403            required="false"
404            current="<%=currentProtocol%>"
405            denied="<%=!readCurrentProtocol%>"
406            recent="<%=recentProtocols%>"
407            defaultitems="<%=defaultProtocols%>"
408            newitem="<%=batch == null%>"
409            onselect="selectProtocolOnClick()"
410          />
411        </td>
412        <td></td>
413      </tr>
414      <tr class="dynamic">
415        <th>Description</th>
416        <td>
417          <textarea class="text" rows="6" name="description" id="description"
418            ><%=HTML.encodeTags(batch == null ? cc.getPropertyValue("description") : batch.getDescription())%></textarea>
419        </td>
420        <td style="width: 20px;">
421          <base:zoom textarea="description" title="Description" />
422        </td>
423      </tr>
424      </table>
425    </t:tab>
426   
427    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit" activate="loadAnnotationsFrame()">
428      <jsp:include page="../../common/annotations/annotate_frameset.jsp">
429        <jsp:param name="item_type" value="<%=itemType.name()%>" />
430        <jsp:param name="item_id" value="<%=itemId%>" />
431        <jsp:param name="ID" value="<%=ID%>" />
432      </jsp:include>
433    </t:tab>
434   
435    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
436      helpid="annotations.edit.inherited" activate="loadInheritedAnnotationsFrame()">
437      <jsp:include page="../../common/annotations/inherit_frameset.jsp">
438        <jsp:param name="item_type" value="<%=itemType.name()%>" />
439        <jsp:param name="item_id" value="<%=itemId%>" />
440        <jsp:param name="ID" value="<%=ID%>" />
441      </jsp:include>
442    </t:tab>
443    </t:tabcontrol>
444    </form>
445
446    <div class="legend">
447      <base:icon image="required.png" />= required information
448    </div>
449
450    <base:buttongroup subclass="dialogbuttons">
451      <base:button onclick="saveSettings()" title="Save" />
452      <base:button onclick="window.close()" title="Cancel" />
453    </base:buttongroup>
454  </base:body>
455  </base:page>
456  <%
457}
458finally
459{
460  if (dc != null) dc.close();
461}
462%>
Note: See TracBrowser for help on using the repository browser.