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

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

References #1655: GUI improvements

Edit dialogs for array lims.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 14.6 KB
Line 
1<%-- $Id: edit_batch.jsp 5917 2011-12-19 11:28:45Z 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    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
365    <form action="index.jsp?ID=<%=ID%>" method="post" name="batch" onsubmit="return false;">
366    <input type="hidden" name="cmd" value="UpdateItem">
367
368    <t:tabcontrol id="settings" 
369      subclass="content dialogtabcontrol"
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="fullform input100">
374      <tr>
375        <th>Name</th>
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          maxlength="<%=ArrayBatch.MAX_NAME_LENGTH%>"></td>
379        <td></td>
380      </tr>
381      <tr>
382        <th>Array design</th>
383        <td>
384          <%
385          if (batch != null)
386          {
387            %>
388            <%=Base.getEncodedName(currentArrayDesign, !readCurrentArrayDesign)%>
389            <%
390          }
391          else
392          {
393            %>
394            <base:select 
395              id="arraydesign_id"
396              clazz="selectionlist required"
397              required="true"
398              current="<%=currentArrayDesign%>"
399              denied="<%=!readCurrentArrayDesign%>"
400              recent="<%=recentArrayDesigns%>"
401              defaultitems="<%=defaultArrayDesigns%>"
402              newitem="true"
403              onselect="selectArrayDesignOnClick()"
404              onchange="arrayDesignOnChange()"
405            />
406            <%
407          }
408          %>
409        </td>
410        <td></td>
411      </tr>
412      <tr>
413        <th>Print robot</th>
414        <td>
415          <base:select 
416            id="printrobot_id"
417            clazz="selectionlist"
418            required="false"
419            current="<%=currentPrintRobot%>"
420            denied="<%=!readCurrentPrintRobot%>"
421            recent="<%=recentPrintRobots%>"
422            defaultitems="<%=defaultPrintRobots%>"
423            newitem="<%=batch == null%>"
424            onselect="selectPrintRobotOnClick()"
425          />
426        </td>
427        <td></td>
428      </tr>
429      <tr>
430        <th>Protocol</th>
431        <td>
432          <base:select 
433            id="protocol_id"
434            clazz="selectionlist"
435            required="false"
436            current="<%=currentProtocol%>"
437            denied="<%=!readCurrentProtocol%>"
438            recent="<%=recentProtocols%>"
439            defaultitems="<%=defaultProtocols%>"
440            newitem="<%=batch == null%>"
441            onselect="selectProtocolOnClick()"
442            onchange="protocolOnChange()"
443          />
444        </td>
445        <td></td>
446      </tr>
447      <tr class="dynamic">
448        <th>Description</th>
449        <td>
450          <textarea <%=clazz%> rows="6" name="description" 
451            ><%=HTML.encodeTags(batch == null ? cc.getPropertyValue("description") : batch.getDescription())%></textarea>
452        </td>
453        <td style="width: 20px;">
454          <base:icon image="zoom.png" 
455            onclick="Main.zoom('Description', 'batch', 'description')"
456            tooltip="Edit in larger window"
457          />
458        </td>
459      </tr>
460      </table>
461    </t:tab>
462   
463    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit"><iframe 
464      name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
465      style="width: 100%; height: 100%;"></iframe></t:tab>
466   
467    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
468      helpid="annotations.edit.inherited"><iframe 
469        name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
470        style="width: 100%; height: 100%;"></iframe></t:tab>
471    </t:tabcontrol>
472    </form>
473
474    <div class="legend">
475      <base:icon image="required.gif" /> = required information
476    </div>
477
478    <base:buttongroup subclass="dialogbuttons">
479      <base:button onclick="saveSettings()" title="Save" />
480      <base:button onclick="window.close()" title="Cancel" />
481    </base:buttongroup>
482  </base:body>
483  </base:page>
484  <%
485}
486finally
487{
488  if (dc != null) dc.close();
489}
490%>
Note: See TracBrowser for help on using the repository browser.