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

Last change on this file since 5687 was 5687, checked in by Nicklas Nordborg, 12 years ago

References #1597: Subtypes of items

Smarter selection of default subtypes and related items (protocols, etc) have now been implemented in the other important edit dialogs.

Added support for also loading and displaying project default items dynamically based on the selected subtype.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 15.0 KB
Line 
1<%-- $Id: edit_batch.jsp 5687 2011-08-09 11:39:40Z 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<%
62final Item itemType = Item.ARRAYBATCH;
63final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
64final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
65final int itemId = cc.getId();
66final String ID = sc.getId();
67final float scale = Base.getScale(sc);
68final DbControl dc = sc.newDbControl();
69try
70{
71  String title = null;
72  ArrayBatch batch = null;
73 
74  boolean readCurrentArrayDesign = true;
75  ArrayDesign currentArrayDesign = null;
76  List<ArrayDesign> defaultArrayDesigns = null;
77  boolean readCurrentProtocol = true;
78  Protocol currentProtocol = null;
79  List<Protocol> defaultProtocols = null;
80  boolean readCurrentPrintRobot = true;
81  Hardware currentPrintRobot = null;
82  List<Hardware> defaultPrintRobots = null;
83
84  // Load recently used items
85  List<ArrayDesign> recentArrayDesigns = (List<ArrayDesign>)cc.getRecent(dc, Item.ARRAYDESIGN);
86  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL);
87  List<Hardware> recentPrintRobots = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE);
88 
89  int activeProjectId = sc.getActiveProjectId();
90  if (activeProjectId > 0)
91  {
92    Project activeProject = Project.getById(dc, activeProjectId);
93    try
94    {
95      defaultArrayDesigns = (List<ArrayDesign>)activeProject.findDefaultItems(dc, Item.ARRAYDESIGN, true);
96    }
97    catch (PermissionDeniedException pdex)
98    {}
99    try
100    {
101      defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc, 
102          ItemSubtype.getById(dc, SystemItems.getId(Protocol.PRINTING)), false);
103    }
104    catch (PermissionDeniedException pdex)
105    {}
106    try
107    {
108      defaultPrintRobots = (List<Hardware>)activeProject.findDefaultItems(dc, 
109          ItemSubtype.getById(dc, SystemItems.getId(Hardware.PRINT_ROBOT)), false);
110    }
111    catch (PermissionDeniedException pdex)
112    {}
113  }
114  if (itemId == 0)
115  {
116    title = "Create array batch";
117    cc.removeObject("item");
118    int arrayDesignId = Values.getInt(request.getParameter("arraydesign_id"));
119    if (arrayDesignId != 0)
120    {
121      currentArrayDesign = ArrayDesign.getById(dc, arrayDesignId);
122    }
123    else if (cc.getPropertyFilter("arrayDesign.name") != null)
124    {
125      currentArrayDesign = Base.getFirstMatching(dc, ArrayDesign.getQuery(), "name", cc.getPropertyFilter("arrayDesign.name"));
126    }
127    if (cc.getPropertyFilter("printRobot.name") != null)
128    {
129      currentPrintRobot = Base.getFirstMatching(dc, Hardware.getQuery(), "name", cc.getPropertyFilter("printRobot.name"));
130    }
131    if (cc.getPropertyFilter("protocol.name") != null)
132    {
133      currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("protocol.name"));
134    }
135  }
136  else
137  {
138    batch = ArrayBatch.getById(dc, itemId);
139    cc.setObject("item", batch);
140    title = "Edit array batch -- " + HTML.encodeTags(batch.getName());
141    try
142    {
143      currentArrayDesign = batch.getArrayDesign();
144    }
145    catch (PermissionDeniedException ex)
146    {
147      readCurrentArrayDesign = false;
148    }
149    try
150    {
151      currentPrintRobot = batch.getPrintRobot();     
152    }
153    catch (PermissionDeniedException ex)
154    {
155      readCurrentPrintRobot = false;
156    }
157    try
158    {
159      currentProtocol = batch.getProtocol();     
160    }
161    catch (PermissionDeniedException ex)
162    {
163      readCurrentProtocol = false;
164    }
165  }
166  if (batch != null && !batch.hasPermission(Permission.WRITE))
167  {
168    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
169  }
170  final String clazz = "class=\"text\"";
171  final String requiredClazz = "class=\"text required\"";
172  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), batch);
173  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
174  %>
175  <base:page type="popup" title="<%=title%>">
176  <base:head scripts="tabcontrol.js,annotations.js" styles="tabcontrol.css">
177    <ext:scripts context="<%=jspContext%>" />
178    <ext:stylesheets context="<%=jspContext%>" />
179    <script language="JavaScript">
180    // Validate the "ArrayBatch" tab
181    function validateArrayBatch()
182    {
183      var frm = document.forms['batch'];
184      if (Main.trimString(frm.name.value) == '')
185      {
186        alert("You must enter a name");
187        frm.name.focus();
188        return false;
189      }
190      if (frm.arraydesign_id && frm.arraydesign_id[frm.arraydesign_id.selectedIndex].value == 0)
191      {
192        alert("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        if (annotationsLoaded)
205        {
206          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
207        }
208        if (inheritedAnnotationsLoaded)
209        {
210          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
211        }
212        frm.submit();
213      }
214    }
215   
216    var annotationsLoaded = false;
217    var inheritedAnnotationsLoaded = false;
218    var parentsChanged = false;
219    var protocolChanged = false;
220    function switchTab(tabControlId, tabId)
221    {
222      if (TabControl.setActiveTab(tabControlId, tabId))
223      {
224        if (tabId == 'annotations' && (protocolChanged || !annotationsLoaded))
225        {
226          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=batch == null ? 0 : batch.getId()%>, getProtocolId());
227          annotationsLoaded = true;
228          protocolChanged = false;
229        }
230        else if (tabId == 'inheritedAnnotations' && 
231          (parentsChanged || !inheritedAnnotationsLoaded))
232        {
233          Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
234          inheritedAnnotationsLoaded = true;
235          parentsChanged = false;
236        }
237      }
238    }
239   
240    function getProtocolId()
241    {
242      var frm = document.forms['batch'];
243      var protocolId = 0;
244      if (frm.protocol_id.length > 0 && !frm.protocol_id.disabled)
245      {
246        protocolId = Math.abs(parseInt(frm.protocol_id[frm.protocol_id.selectedIndex].value));       
247      }
248      return protocolId;
249    }
250
251    function getParents()
252    {
253      var frm = document.forms['batch'];
254      var parents = new Array();
255      if (frm.arraydesign_id)
256      {
257        var arrayDesignId = Math.abs(parseInt(frm.arraydesign_id[frm.arraydesign_id.selectedIndex].value));
258        if (arrayDesignId > 0) parents[parents.length] = 'ARRAYDESIGN:'+arrayDesignId;
259      }
260      return parents;
261    }
262
263    function arrayDesignOnChange()
264    {
265      parentsChanged = true;
266    }
267    function selectArrayDesignOnClick()
268    {
269      var frm = document.forms['batch'];
270      var url = '../../lims/arraydesigns/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setArrayDesignCallback';
271      if (frm.arraydesign_id.length > 0)
272      {
273        var id = Math.abs(parseInt(frm.arraydesign_id[0].value));       
274        url += '&item_id='+id;
275      }
276      Main.openPopup(url, 'SelectArrayDesign', 1000, 700);
277    }
278    function setArrayDesignCallback(id, name)
279    {
280      var frm = document.forms['batch'];
281      var list = frm.arraydesign_id;
282      if (list.length < 1 || list[0].value == '0') // >
283      {
284        Forms.addListOption(list, 0, new Option());
285      }
286      list[0].value = id;
287      list[0].text = name;
288      list.selectedIndex = 0;
289      parentsChanged = true;
290    }
291
292    function selectProtocolOnClick()
293    {
294      var frm = document.forms['batch'];
295      var url = '../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setProtocolCallback';
296      if (frm.protocol_id.length > 1)
297      {
298        var id = Math.abs(parseInt(frm.protocol_id[1].value));       
299        url += '&item_id='+id;
300      }
301      url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=<%=SystemItems.getId(Protocol.PRINTING)%>';
302      Main.openPopup(url, 'SelectProtocol', 1000, 700);
303    }
304    function setProtocolCallback(id, name)
305    {
306      var frm = document.forms['batch'];
307      var list = frm.protocol_id;
308      if (list.length < 2 || list[1].value == '0') // >
309      {
310        Forms.addListOption(list, 1, new Option());
311      }
312      list[1].value = id;
313      list[1].text = name;
314      list.selectedIndex = 1;
315      protocolChanged = true;
316    }
317    function protocolOnChange()
318    {
319      protocolChanged = true;
320    }
321
322    function selectPrintRobotOnClick()
323    {
324      var frm = document.forms['batch'];
325      var url = '../../admin/hardware/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setPrintRobotCallback';
326      if (frm.printrobot_id.length > 1)
327      {
328        var id = Math.abs(parseInt(frm.printrobot_id[1].value));       
329        url += '&item_id='+id;
330      }
331      url += '&resetTemporary=1&tmpfilter:INT:itemSubtype=<%=SystemItems.getId(Hardware.PRINT_ROBOT)%>';
332      Main.openPopup(url, 'SelectPrintRobot', 1000, 700);
333    }
334    function setPrintRobotCallback(id, name)
335    {
336      var frm = document.forms['batch'];
337      var list = frm.printrobot_id;
338      if (list.length < 2 || list[1].value == '0') // >
339      {
340        Forms.addListOption(list, 1, new Option());
341      }
342      list[1].value = id;
343      list[1].text = name;
344      list.selectedIndex = 1;
345    }
346
347   
348    function init()
349    {
350      var frm = document.forms['batch'];
351      <%
352      if (batch == null)
353      {
354        %>
355        frm.name.focus();
356        frm.name.select();
357        <%
358      }
359      %>
360    }
361    </script>
362  </base:head>
363  <base:body onload="init()">
364    <p>
365    <form action="index.jsp?ID=<%=ID%>" method="post" name="batch" onsubmit="return false;">
366    <input type="hidden" name="cmd" value="UpdateItem">
367
368    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
369    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
370      position="bottom"  remember="<%=batch != null%>" switch="switchTab"
371      extensions="<%=invoker%>">
372    <t:tab id="info" title="Array batch" validate="validateArrayBatch()" helpid="arraybatch.edit">
373      <table class="form" cellspacing=0>
374      <tr>
375        <td class="prompt">Name</td>
376        <td><input <%=requiredClazz%> type="text" name="name" 
377          value="<%=HTML.encodeTags(batch == null ? Values.getString(cc.getPropertyValue("name"), "New array batch") : batch.getName())%>" 
378          size="40" maxlength="<%=ArrayBatch.MAX_NAME_LENGTH%>"></td>
379      </tr>
380      <tr>
381        <td class="prompt">Array design</td>
382        <td>
383          <%
384          if (batch != null)
385          {
386            %>
387            <%=Base.getEncodedName(currentArrayDesign, !readCurrentArrayDesign)%>
388            <%
389          }
390          else
391          {
392            %>
393            <base:select 
394              id="arraydesign_id"
395              clazz="selectionlist required"
396              required="true"
397              current="<%=currentArrayDesign%>"
398              denied="<%=!readCurrentArrayDesign%>"
399              recent="<%=recentArrayDesigns%>"
400              defaultitems="<%=defaultArrayDesigns%>"
401              newitem="true"
402              onselect="selectArrayDesignOnClick()"
403              onchange="arrayDesignOnChange()"
404            />
405            <%
406          }
407          %>
408        </td>
409      </tr>
410      <tr>
411        <td class="prompt">Print robot</td>
412        <td>
413          <base:select 
414            id="printrobot_id"
415            clazz="selectionlist"
416            required="false"
417            current="<%=currentPrintRobot%>"
418            denied="<%=!readCurrentPrintRobot%>"
419            recent="<%=recentPrintRobots%>"
420            defaultitems="<%=defaultPrintRobots%>"
421            newitem="<%=batch == null%>"
422            onselect="selectPrintRobotOnClick()"
423          />
424        </td>
425      </tr>
426      <tr>
427        <td class="prompt">Protocol</td>
428        <td>
429          <base:select 
430            id="protocol_id"
431            clazz="selectionlist"
432            required="false"
433            current="<%=currentProtocol%>"
434            denied="<%=!readCurrentProtocol%>"
435            recent="<%=recentProtocols%>"
436            defaultitems="<%=defaultProtocols%>"
437            newitem="<%=batch == null%>"
438            onselect="selectProtocolOnClick()"
439            onchange="protocolOnChange()"
440          />
441        </td>
442      </tr>
443      <tr valign=top>
444        <td class="prompt">Description</td>
445        <td nowrap>
446          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
447            ><%=HTML.encodeTags(batch == null ? cc.getPropertyValue("description") : batch.getDescription())%></textarea>
448          <a href="javascript:Main.zoom('Description', 'batch', 'description')"
449            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
450        </td>
451      </tr>
452      </table>
453      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
454    </t:tab>
455   
456    <t:tab id="annotations" title="Annotations &amp; parameters" 
457      helpid="annotations.edit" tooltip="Enter values for annotations and protocol parameters">
458      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
459        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
460        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
461    </t:tab>
462   
463    <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited">
464   
465      <iframe name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
466        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
467        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
468    </t:tab>
469    </t:tabcontrol>
470
471    <table align="center">
472    <tr>
473      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
474      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
475    </tr>
476    </table>
477    </form>
478  </base:body>
479  </base:page>
480  <%
481}
482finally
483{
484  if (dc != null) dc.close();
485}
486%>
Note: See TracBrowser for help on using the repository browser.