source: trunk/www/views/scans/edit_scan.jsp @ 3400

Last change on this file since 3400 was 3400, checked in by Nicklas Nordborg, 14 years ago

Fixes #534.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 13.8 KB
Line 
1<%-- $Id: edit_scan.jsp 3400 2007-05-29 06:47:04Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
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 2
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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24
25  @author Nicklas
26  @version 2.0
27--%>
28<%@ page session="false"
29  import="net.sf.basedb.core.SessionControl"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.SystemItems"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.Scan"
36  import="net.sf.basedb.core.Hybridization"
37  import="net.sf.basedb.core.Protocol"
38  import="net.sf.basedb.core.ProtocolType"
39  import="net.sf.basedb.core.Project"
40  import="net.sf.basedb.core.Hardware"
41  import="net.sf.basedb.core.HardwareType"
42  import="net.sf.basedb.core.ItemQuery"
43  import="net.sf.basedb.core.ItemResultList"
44  import="net.sf.basedb.core.PermissionDeniedException"
45  import="net.sf.basedb.core.BaseException"
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="java.util.List"
50  import="java.util.Set"
51  import="java.util.HashSet"
52%>
53<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
54<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
55<%
56final Item itemType = Item.SCAN;
57final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
58final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
59final int itemId = cc.getId();
60final String ID = sc.getId();
61final float scale = Base.getScale(sc);
62final DbControl dc = sc.newDbControl();
63try
64{
65  String title = null;
66  Scan scan = null;
67  String name = null;
68 
69  boolean readCurrentHybridization = true;
70  Hybridization currentHybridization = null;
71  boolean readCurrentProtocol = true;
72  Protocol currentProtocol = null; 
73  Protocol defaultProtocol = null;
74  boolean readCurrentScanner = true;
75  Hardware currentScanner = null;
76  Hardware defaultScanner = null;
77
78  // Load recently used items
79  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL);
80  List<Hardware> recentScanners = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE);
81  List<Hybridization> recentHybridizations = (List<Hybridization>)cc.getRecent(dc, Item.HYBRIDIZATION);
82
83  int activeProjectId = sc.getActiveProjectId();
84  if (activeProjectId > 0)
85  {
86    Project activeProject = Project.getById(dc, activeProjectId);
87    try
88    {
89      defaultProtocol = (Protocol)activeProject.getDefaultItem(dc, Project.Default.SCANNING_PROTOCOL);     
90    }
91    catch (PermissionDeniedException pdex)
92    {
93      defaultProtocol = null;
94    }
95    try
96    {
97      defaultScanner = (Hardware)activeProject.getDefaultItem(dc, Project.Default.SCANNER_HARDWARE);     
98    }
99    catch (PermissionDeniedException pdex)
100    {
101      defaultScanner = null;
102    }
103  }
104  if (itemId == 0)
105  {
106    title = "Create scan";
107    cc.removeObject("item");
108    if (cc.getPropertyFilter("protocol.name") != null)
109    {
110      currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("protocol.name"));
111    }
112    if (cc.getPropertyFilter("scanner.name") != null)
113    {
114      currentScanner = Base.getFirstMatching(dc, Hardware.getQuery(), "name", cc.getPropertyFilter("scanner.name"));
115    }
116    int hybridizationId = Values.getInt(request.getParameter("hybridization_id"));
117    if (hybridizationId != 0)
118    {
119      currentHybridization = Hybridization.getById(dc, hybridizationId);
120    }
121    else if (cc.getPropertyFilter("hybridization.name") != null)
122    {
123      currentHybridization = Base.getFirstMatching(dc, Hybridization.getQuery(), "name", cc.getPropertyFilter("hybridization.name"));
124    }
125     
126    if (currentHybridization != null)
127    {
128      name = currentHybridization.getName() + ".s" + (currentHybridization.countScans() + 1);
129    }
130    else
131    {
132      name = Values.getString(cc.getPropertyValue("name"), "New scan");
133    }
134  }
135  else
136  {
137    scan = Scan.getById(dc, itemId);
138    scan.checkPermission(Permission.WRITE);
139    name = scan.getName();
140    cc.setObject("item", scan);
141    title = "Edit scan -- " + HTML.encodeTags(scan.getName());
142    try
143    {
144      currentHybridization = scan.getHybridization();
145    }
146    catch (PermissionDeniedException ex)
147    {
148      readCurrentHybridization = false;
149    }
150    try
151    {
152      currentProtocol = scan.getProtocol();
153    }
154    catch (PermissionDeniedException ex)
155    {
156      readCurrentProtocol = false;
157    }
158    try
159    {
160      currentScanner = scan.getScanner();
161    }
162    catch (PermissionDeniedException ex)
163    {
164      readCurrentScanner = false;
165    }
166  }
167
168  final String clazz = "class=\"text\"";
169  final String requiredClazz = "class=\"text required\"";
170  %>
171
172  <base:page type="popup" title="<%=title%>">
173  <base:head scripts="tabcontrol.js,annotations.js" styles="tabcontrol.css">
174    <script language="JavaScript">
175    // Validate the "Scan" tab
176    function validateScan()
177    {
178      var frm = document.forms['scan'];
179      if (Main.trimString(frm.name.value) == '')
180      {
181        alert("You must enter a name");
182        frm.name.focus();
183        return false;
184      }
185      var hybId = frm.hybridization_id.length == 0 ?
186        0 : frm.hybridization_id[frm.hybridization_id.selectedIndex].value;
187      if (hybId == 0)
188      {
189        alert("You must select a hybridization");
190        return false;
191      }
192      return true;
193    }
194
195    // Submit the form
196    function saveSettings()
197    {
198      var frm = document.forms['scan'];
199      if (TabControl.validateActiveTab('settings'))
200      {
201        if (annotationsLoaded)
202        {
203          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
204        }
205        if (inheritedAnnotationsLoaded)
206        {
207          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
208        }
209        frm.submit();
210      }
211    }
212   
213    var annotationsLoaded = false;
214    var inheritedAnnotationsLoaded = false;
215    var parentsChanged = false;
216    var protocolChanged = false;
217    function switchTab(tabControlId, tabId)
218    {
219      if (TabControl.setActiveTab(tabControlId, tabId))
220      {
221        if (tabId == 'annotations' && (protocolChanged || !annotationsLoaded))
222        {
223          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=scan == null ? 0 : scan.getId()%>, getProtocolId());
224          annotationsLoaded = true;
225          protocolChanged = false;
226        }
227        else if (tabId == 'inheritedAnnotations' && 
228          (parentsChanged || !inheritedAnnotationsLoaded))
229        {
230          Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
231          inheritedAnnotationsLoaded = true;
232          parentsChanged = false;
233        }
234      }
235    }
236   
237    function getProtocolId()
238    {
239      var frm = document.forms['scan'];
240      var protocolId = 0;
241      if (frm.protocol_id.length > 0 && !frm.protocol_id.disabled)
242      {
243        protocolId = Math.abs(parseInt(frm.protocol_id[frm.protocol_id.selectedIndex].value));       
244      }
245      return protocolId;
246    }
247
248    function getParents()
249    {
250      var frm = document.forms['scan'];
251      var parents = new Array();
252      var hybridizationId = Math.abs(parseInt(frm.hybridization_id[frm.hybridization_id.selectedIndex].value));
253      if (hybridizationId > 0) parents[parents.length] = 'HYBRIDIZATION:'+hybridizationId;
254      return parents;
255    }
256
257    function selectProtocolOnClick()
258    {
259      var frm = document.forms['scan'];
260      var url = '../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setProtocolCallback';
261      if (frm.protocol_id.length > 1)
262      {
263        var id = Math.abs(parseInt(frm.protocol_id[1].value));       
264        url += '&item_id='+id;
265      }
266      url += '&filter:INT:protocolType=<%=SystemItems.getId(ProtocolType.SCANNING)%>';
267      Main.openPopup(url, 'SelectProtocol', 1000, 700);
268    }
269    function setProtocolCallback(id, name)
270    {
271      var frm = document.forms['scan'];
272      var list = frm.protocol_id;
273      if (list.length < 2 || list[1].value == '0') // >
274      {
275        Forms.addListOption(list, 1, new Option());
276      }
277      list[1].value = id;
278      list[1].text = name;
279      list.selectedIndex = 1;
280      protocolChanged = true;
281    }
282    function protocolOnChange()
283    {
284      protocolChanged = true;
285    }
286
287    function selectScannerOnClick()
288    {
289      var frm = document.forms['scan'];
290      var url = '../../admin/hardware/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setScannerCallback';
291      if (frm.scanner_id.length > 1)
292      {
293        var id = Math.abs(parseInt(frm.scanner_id[1].value));       
294        url += '&item_id='+id;
295      }
296      url += '&filter:INT:hardwareType=<%=SystemItems.getId(HardwareType.SCANNER)%>';
297      Main.openPopup(url, 'SelectScanner', 1000, 700);
298    }
299    function setScannerCallback(id, name)
300    {
301      var frm = document.forms['scan'];
302      var list = frm.scanner_id;
303      if (list.length < 2 || list[1].value == '0') // >
304      {
305        Forms.addListOption(list, 1, new Option());
306      }
307      list[1].value = id;
308      list[1].text = name;
309      list.selectedIndex = 1;
310    }
311   
312    function hybridizationOnChange()
313    {
314      parentsChanged = true;
315    }
316
317    function selectHybridizationOnClick()
318    {
319      var frm = document.forms['scan'];
320      var url = '../hybridizations/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setHybridizationCallback';
321      if (frm.hybridization_id.length > 0)
322      {
323        var id = Math.abs(parseInt(frm.hybridization_id[0].value));       
324        url += '&item_id='+id;
325      }
326      Main.openPopup(url, 'SelectHybridization', 1000, 700);
327    }
328    function setHybridizationCallback(id, name)
329    {
330      var frm = document.forms['scan'];
331      var list = frm.hybridization_id;
332      if (list.length < 2 || list[1].value == '0') // >
333      {
334        Forms.addListOption(list, 1, new Option());
335      }
336      list[1].value = id;
337      list[1].text = name;
338      list.selectedIndex = 1;
339      parentsChanged = true;
340    }
341
342    function init()
343    {
344      <%
345      if (scan == null)
346      {
347        %>
348        var frm = document.forms['scan'];
349        frm.name.focus();
350        frm.name.select();
351        <%
352      }
353      %>
354    }
355    </script>
356  </base:head>
357  <base:body onload="init()">
358    <p>
359    <form action="index.jsp?ID=<%=ID%>" method="post" name="scan" onsubmit="return false;">
360    <input type="hidden" name="cmd" value="UpdateItem">
361
362    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
363    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
364      position="bottom"  remember="<%=scan != null%>" switch="switchTab">
365    <t:tab id="info" title="Scan" validate="validateScan()" helpid="scan.edit">
366      <table class="form" cellspacing=0>
367      <tr>
368        <td class="prompt">Name</td>
369        <td><input <%=requiredClazz%> type="text" name="name" 
370          value="<%=HTML.encodeTags(name)%>" 
371          size="40" maxlength="<%=Scan.MAX_NAME_LENGTH%>"></td>
372      </tr>
373      <tr>
374        <td class="prompt">Hybridization</td>
375        <td>
376          <base:select 
377            id="hybridization_id"
378            clazz="selectionlist"
379            required="true"
380            current="<%=currentHybridization%>"
381            denied="<%=!readCurrentHybridization%>"
382            recent="<%=recentHybridizations%>"
383            newitem="<%=scan == null%>"
384            onselect="selectHybridizationOnClick()"
385            onchange="hybridizationOnChange()"
386          />
387        </td>
388      </tr>
389      <tr>
390        <td class="prompt">Scanner</td>
391        <td>
392          <base:select 
393            id="scanner_id"
394            clazz="selectionlist"
395            required="false"
396            current="<%=currentScanner%>"
397            denied="<%=!readCurrentScanner%>"
398            recent="<%=recentScanners%>"
399            defaultitem="<%=defaultScanner%>"
400            newitem="<%=scan == null%>"
401            onselect="selectScannerOnClick()"
402          />
403        </td>
404      </tr>
405      <tr>
406        <td class="prompt">Protocol</td>
407        <td>
408          <base:select 
409            id="protocol_id"
410            clazz="selectionlist"
411            required="false"
412            current="<%=currentProtocol%>"
413            denied="<%=!readCurrentProtocol%>"
414            recent="<%=recentProtocols%>"
415            defaultitem="<%=defaultProtocol%>"
416            newitem="<%=scan == null%>"
417            onselect="selectProtocolOnClick()"
418            onchange="protocolOnChange()"
419          />
420        </td>
421      </tr>
422      <tr valign=top>
423        <td class="prompt">Description</td>
424        <td nowrap>
425          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
426            ><%=HTML.encodeTags(scan == null ? cc.getPropertyValue("description") : scan.getDescription())%></textarea>
427          <a href="javascript:Main.zoom('Description', 'scan', 'description')"
428            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
429        </td>
430      </tr>
431      </table>
432      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
433    </t:tab>
434
435    <t:tab id="annotations" title="Annotations &amp; parameters" 
436      helpid="annotations.edit" tooltip="Enter values for annotations and protocol parameters">
437      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
438        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
439        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
440    </t:tab>
441   
442    <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited">
443   
444      <iframe name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
445        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
446        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
447    </t:tab>
448    </t:tabcontrol>
449
450    <table align="center">
451    <tr>
452      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
453      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
454    </tr>
455    </table>
456    </form>
457  </base:body>
458  </base:page>
459  <%
460}
461finally
462{
463  if (dc != null) dc.close();
464}
465%>
Note: See TracBrowser for help on using the repository browser.