source: trunk/www/views/hybridizations/edit_hybridization.jsp @ 2753

Last change on this file since 2753 was 2753, checked in by Nicklas Nordborg, 17 years ago

Fixes #404: Replace deprecated Values class with the new one in all JSP pages

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 17.7 KB
Line 
1<%-- $Id: edit_hybridization.jsp 2753 2006-10-20 11:04:36Z 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
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.Include"
36  import="net.sf.basedb.core.Hardware"
37  import="net.sf.basedb.core.HardwareType"
38  import="net.sf.basedb.core.Hybridization"
39  import="net.sf.basedb.core.BioMaterialEvent"
40  import="net.sf.basedb.core.ArraySlide"
41  import="net.sf.basedb.core.Protocol"
42  import="net.sf.basedb.core.ProtocolType"
43  import="net.sf.basedb.core.LabeledExtract"
44  import="net.sf.basedb.core.ItemQuery"
45  import="net.sf.basedb.core.ItemResultList"
46  import="net.sf.basedb.core.PermissionDeniedException"
47  import="net.sf.basedb.core.BaseException"
48  import="net.sf.basedb.core.query.Orders"
49  import="net.sf.basedb.core.query.Hql"
50  import="net.sf.basedb.clients.web.Base"
51  import="net.sf.basedb.clients.web.util.HTML"
52  import="net.sf.basedb.util.Values"
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.HYBRIDIZATION;
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  String name = null;
72  Hybridization hyb = null;
73  BioMaterialEvent creationEvent = null;
74  ItemQuery<LabeledExtract> labeledExtractsQuery = null;
75 
76  boolean readCurrentArraySlide = true;
77  ArraySlide currentArraySlide = null;
78 
79  boolean readCurrentProtocol = true;
80  Protocol currentProtocol = null;
81 
82  boolean readCurrentHybStation = true;
83  Hardware currentHybStation = null;
84
85  // Load recently used items
86  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL);
87  List<Hardware> recentStations = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE);
88 
89  if (itemId == 0)
90  {
91    title = "Create hybridization";
92    cc.removeObject("item");
93    if (cc.getPropertyFilter("creationEvent.protocol.name") != null)
94    {
95      currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("creationEvent.protocol.name"));
96    }
97    if (cc.getPropertyFilter("creationEvent.hardware.name") != null)
98    {
99      currentHybStation = Base.getFirstMatching(dc, Hardware.getQuery(), "name", cc.getPropertyFilter("creationEvent.hardware.name"));
100    }
101    if (cc.getPropertyFilter("arraySlide.name") != null)
102    {
103      currentArraySlide = Base.getFirstMatching(dc, ArraySlide.getQuery(), "name", cc.getPropertyFilter("arraySlide.name"));
104    }
105    name = Values.getString(cc.getPropertyValue("name"), "New hybridization");
106  }
107  else
108  {
109    hyb = Hybridization.getById(dc, itemId);
110    creationEvent = hyb.getCreationEvent();
111    cc.setObject("item", hyb);
112    title = "Edit hybridization -- " + HTML.encodeTags(hyb.getName());
113    name = hyb.getName();
114    try
115    {
116      currentArraySlide = hyb.getArraySlide();
117    }
118    catch (PermissionDeniedException ex)
119    {
120      readCurrentArraySlide = false;
121    }
122    try
123    {
124      currentProtocol = creationEvent.getProtocol();
125    }
126    catch (PermissionDeniedException ex)
127    {
128      readCurrentProtocol = false;
129    }
130    try
131    {
132      currentHybStation = creationEvent.getHardware();
133    }
134    catch (PermissionDeniedException ex)
135    {
136      readCurrentHybStation = false;
137    }
138   
139    // Query to retrieve source labeled extracts
140    labeledExtractsQuery = (ItemQuery<LabeledExtract>)creationEvent.getSources();
141    labeledExtractsQuery.include(Include.MINE, Include.SHARED, Include.OTHERS, Include.IN_PROJECT);
142    labeledExtractsQuery.order(Orders.asc(Hql.property("name")));
143   
144  }
145  if (hyb != null) hyb.checkPermission(Permission.WRITE);
146
147  final String clazz = "class=\"text\"";
148  final String requiredClazz = "class=\"text required\"";
149  %>
150
151  <base:page type="popup" title="<%=title%>">
152  <base:head scripts="tabcontrol.js,annotations.js,linkitems.js" styles="tabcontrol.css">
153    <script language="JavaScript">
154    // Validate the "Hybridization" tab
155    function validateHybridization()
156    {
157      var frm = document.forms['hybridization'];
158      if (Main.trimString(frm.name.value) == '')
159      {
160        alert("You must enter a name");
161        frm.name.focus();
162        return false;
163      }
164      return true;
165    }
166
167    // Submit the form
168    function saveSettings()
169    {
170      var frm = document.forms['hybridization'];
171      if (TabControl.validateActiveTab('settings'))
172      {
173        if (annotationsLoaded)
174        {
175          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
176        }
177        if (inheritedAnnotationsLoaded)
178        {
179          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
180        }
181        frm.modifiedLabeledExtracts.value = Link.exportModified(frm, 'L', true).join(',');
182        frm.removedLabeledExtracts.value = Link.getActionIds(-1, 'L').join(',');
183        frm.submit();
184      }
185    }
186   
187    var annotationsLoaded = false;
188    var inheritedAnnotationsLoaded = false;
189    var parentsChanged = false;
190    function switchTab(tabControlId, tabId)
191    {
192      if (TabControl.setActiveTab(tabControlId, tabId))
193      {
194        if (tabId == 'annotations' && !annotationsLoaded)
195        {
196          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=hyb == null ? 0 : hyb.getId()%>);
197          annotationsLoaded = true;
198        }
199        else if (tabId == 'inheritedAnnotations' && 
200          (parentsChanged || !inheritedAnnotationsLoaded))
201        {
202          Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
203          inheritedAnnotationsLoaded = true;
204          parentsChanged = false;
205        }
206      }
207    }
208   
209    function getParents()
210    {
211      var frm = document.forms['hybridization'];
212      var parents = new Array();
213
214      var arraySlideId = Math.abs(parseInt(frm.arrayslide_id[frm.arrayslide_id.selectedIndex].value));
215      if (arraySlideId > 0) parents[parents.length] = 'ARRAYSLIDE:'+arraySlideId;
216
217      var ids = Link.getListIds(frm.labeled_extracts, 'L');
218      if (ids.length > 0)
219      {
220        parents[parents.length] = 'LABELEDEXTRACT:'+ids.join(':');
221      }
222      return parents;
223    }
224
225    function selectProtocolOnClick()
226    {
227      var frm = document.forms['hybridization'];
228      var url = '../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setProtocolCallback';
229      if (frm.protocol_id.length > 1)
230      {
231        var id = Math.abs(parseInt(frm.protocol_id[1].value));       
232        url += '&item_id='+id;
233      }
234      url += '&filter:INT:protocolType=<%=SystemItems.getId(ProtocolType.HYBRIDIZATION)%>';
235      Main.openPopup(url, 'SelectProtocol', 1000, 700);
236    }
237    function setProtocolCallback(id, name)
238    {
239      var frm = document.forms['hybridization'];
240      var list = frm.protocol_id;
241      if (list.length < 2 || list[1].value == '0') // >
242      {
243        Forms.addListOption(list, 1, new Option());
244      }
245      list[1].value = id;
246      list[1].text = name;
247      list.selectedIndex = 1;
248    }
249   
250    function selectHybStationOnClick()
251    {
252      var frm = document.forms['hybridization'];
253      var url = '../../admin/hardware/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setHybStationCallback';
254      if (frm.hardware_id.length > 1)
255      {
256        var id = Math.abs(parseInt(frm.hardware_id[1].value));       
257        url += '&item_id='+id;
258      }
259      url += '&filter:INT:hardwareType=<%=SystemItems.getId(HardwareType.HYBRIDIZATION_STATION)%>';
260      Main.openPopup(url, 'SelectHybStation', 1000, 700);
261    }
262    function setHybStationCallback(id, name)
263    {
264      var frm = document.forms['hybridization'];
265      var list = frm.hardware_id;
266      if (list.length < 2 || list[1].value == '0') // >
267      {
268        Forms.addListOption(list, 1, new Option());
269      }
270      list[1].value = id;
271      list[1].text = name;
272      list.selectedIndex = 1;
273    }
274   
275    function arraySlideOnChange()
276    {
277      parentsChanged = true;
278    }
279    function selectArraySlideOnClick()
280    {
281      var frm = document.forms['hybridization'];
282      var url = '../../lims/arrayslides/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setArraySlideCallback';
283      if (frm.arrayslide_id.length > 1)
284      {
285        var id = Math.abs(parseInt(frm.arrayslide_id[1].value));       
286        url += '&item_id='+id;
287      }
288      url += '&filter:STRING:hybridization.name==';
289      url += '&filter:BOOLEAN:destroyed=false';
290      Main.openPopup(url, 'SelectArraySlide', 1000, 700);
291    }
292    function setArraySlideCallback(arraySlideId, name)
293    {
294      var frm = document.forms['hybridization'];
295      if (frm.arrayslide_id.length < 2) // >
296      {
297        frm.arrayslide_id[frm.arrayslide_id.length] = new Option();
298      }
299      frm.arrayslide_id[1].value = arraySlideId;
300      frm.arrayslide_id[1].text = name;
301      frm.arrayslide_id.selectedIndex = 1;
302      parentsChanged = true;
303    }
304
305    function addLabeledExtractsOnClick()
306    {
307      var frm = document.forms['hybridization'];
308      var ids = Link.getListIds(frm.labeled_extracts, 'L');
309      var excludes = ids.join(',');
310     
311      var url = '../../biomaterials/labeledextracts/index.jsp?ID=<%=ID%>&mode=selectmultiple&callback=addLabeledExtractCallback';
312      url += '&exclude='+excludes;
313      Main.openPopup(url, 'AddLabeledExtracts', 1000, 700);
314    }
315    function addLabeledExtractCallback(labeledExtractId, name)
316    {
317      var item = Link.getItem('L', labeledExtractId);
318      if (!item) item = new Item('L', labeledExtractId, name+' [-]', '', '');
319      Link.addItem(document.forms['hybridization'].labeled_extracts, item);
320      parentsChanged = true;
321    }
322    function labeledExtractsOnChange()
323    {
324      var frm = document.forms['hybridization'];
325      var item = frm.labeled_extracts[frm.labeled_extracts.selectedIndex].item;
326      if (item && item.id)
327      {
328        frm.used_quantity.value = item.value;
329        frm.used_quantity.focus();
330      }
331      else
332      {
333        frm.used_quantity.value = '';
334      }
335    }
336    function usedQuantityOnBlur()
337    {
338      var frm = document.forms['hybridization'];
339      var usedQuantity = frm.used_quantity.value;
340      usedQuantity = usedQuantity == '' ? '-' : usedQuantity+' µg';
341      for (var i = 0; i < frm.labeled_extracts.length; i++) // >
342      {
343        var option = frm.labeled_extracts[i];
344        if (option.selected && option.item.id)
345        {
346          option.item.value = usedQuantity;
347          var text = option.text.replace(/\[.*\]/, '['+usedQuantity+']');
348          option.text = text;
349        }
350      }
351    }
352
353    function removeOnClick()
354    {
355      Link.removeSelected(document.forms['hybridization'].labeled_extracts);
356      parentsChanged = true;
357    }
358
359   
360    function init()
361    {
362      var frm = document.forms['hybridization'];
363      var labeledExtracts = frm.labeled_extracts;
364      <%
365      if (hyb == null)
366      {
367        %>
368        frm.name.focus();
369        frm.name.select();
370        <%
371        if (Values.getBoolean(request.getParameter("useParents")))
372        {
373          ItemContext lc = sc.getCurrentContext(Item.LABELEDEXTRACT);
374          for (int id : lc.getSelected())
375          {
376            LabeledExtract e = LabeledExtract.getById(dc, id);
377            %>
378            Link.addItem(labeledExtracts, new Item('L', <%=e.getId()%>, '<%=HTML.javaScriptEncode(e.getName())%> [-]', '', ''));
379            <%
380          }
381        }
382      }
383      else
384      {
385        ItemResultList<LabeledExtract> labeledExtracts = labeledExtractsQuery.list(dc);
386        for (LabeledExtract le : labeledExtracts)
387        {
388          String usedQuantity = Values.formatNumber(creationEvent.getUsedQuantity(le), -1);
389          %>
390          Link.addNewItem(labeledExtracts, new Item('L', <%=le.getId()%>, '<%=HTML.javaScriptEncode(le.getName())%> [<%=usedQuantity%> µg]', '<%=usedQuantity%>'));
391          <%
392        }
393      }
394      %>
395    }
396    </script>
397  </base:head>
398  <base:body onload="init()">
399    <p>
400    <form action="index.jsp?ID=<%=ID%>" method="post" name="hybridization" onsubmit="return false;">
401    <input type="hidden" name="cmd" value="UpdateItem">
402
403    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
404    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
405      position="bottom"  remember="<%=hyb != null%>" switch="switchTab">
406    <t:tab id="info" title="Hybridization" validate="validateHybridization()" helpid="hybridization.edit">
407      <table class="form" cellspacing=0>
408      <tr>
409        <td class="prompt">Name</td>
410        <td><input <%=requiredClazz%> type="text" name="name" 
411          value="<%=name%>" 
412          size="40" maxlength="<%=Hybridization.MAX_NAME_LENGTH%>"></td>
413      </tr>
414      <tr>
415        <td class="prompt">Created</td>
416        <td>
417          <table border="0" cellspacing="0" cellpadding="0">
418          <tr>
419          <td>
420            <input <%=clazz%> type="text" name="event_date" 
421              value="<%=Values.formatDate(creationEvent == null ? new Date() : creationEvent.getEventDate())%>" 
422              size="12" maxlength="10" onkeypress="return Dates.dateOnly(event)">
423            (yyyy-mm-dd)&nbsp;
424          </td>
425          <td>
426          <base:button 
427            onclick="Dates.selectDate('Date', 'hybridization', 'event_date')" 
428            image="calendar.png"
429            title="Calendar&hellip;" 
430            tooltip="Select a date from a calendar" 
431          />
432          </td>
433          </tr>
434          </table>
435        </td>
436      </tr>
437      <tr>
438        <td class="prompt">Registered</td>
439        <td><%=Values.formatDate(creationEvent == null ? new Date() : creationEvent.getEntryDate())%></td>
440      </tr>
441      <tr>
442        <td class="prompt">Protocol</td>
443        <td>
444          <base:select 
445            id="protocol_id"
446            clazz="selectionlist"
447            required="false"
448            current="<%=currentProtocol%>"
449            denied="<%=!readCurrentProtocol%>"
450            recent="<%=recentProtocols%>"
451            newitem="<%=hyb == null%>"
452            onselect="selectProtocolOnClick()"
453          />
454        </td>
455      </tr>
456      <tr>
457        <td class="prompt">Hardware</td>
458        <td>
459          <base:select 
460            id="hardware_id"
461            clazz="selectionlist"
462            required="false"
463            current="<%=currentHybStation%>"
464            denied="<%=!readCurrentHybStation%>"
465            recent="<%=recentStations%>"
466            newitem="<%=hyb == null%>"
467            onselect="selectHybStationOnClick()"
468          />
469        </td>
470      </tr>
471      <tr>
472        <td class="prompt">Array slide</td>
473        <td>
474          <base:select 
475            id="arrayslide_id"
476            clazz="selectionlist"
477            required="false"
478            current="<%=currentArraySlide%>"
479            denied="<%=!readCurrentArraySlide%>"
480            newitem="<%=hyb == null%>"
481            onselect="selectArraySlideOnClick()"
482          />
483        </td>
484      </tr>
485      <tr valign=top>
486        <td class="prompt">Description</td>
487        <td nowrap>
488          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
489            ><%=HTML.encodeTags(hyb == null ? cc.getPropertyValue("description") : hyb.getDescription())%></textarea>
490          <a href="javascript:Main.zoom('Description', 'hybridization', 'description')"
491            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
492        </td>
493      </tr>
494      </table>
495      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
496    </t:tab>
497   
498    <t:tab id="labeledExtracts" title="Labeled extracts" helpid="hybridization.labeledextracts">
499   
500      <table class="form" cellspacing=0>
501      <tr valign="top">
502        <td class="prompt">Labeled extracts</td>
503        <td>
504          <table border="0" cellspacing="0" cellpadding="0">
505          <tr valign="top">
506          <td>
507            <select name="labeled_extracts" size="5" multiple style="width: 20em;" 
508              onchange="labeledExtractsOnChange()">
509            </select>&nbsp;<br>
510            Used
511            <input <%=clazz%> type="text" name="used_quantity" value=""
512              size="12" maxlength="10" onkeypress="return Numbers.numberOnly(event)"
513              onkeyup="usedQuantityOnBlur()"
514            > (µg)
515            <input type="hidden" name="modifiedLabeledExtracts" value="">
516            <input type="hidden" name="removedLabeledExtracts" value="">
517         
518          </td>
519          <td>
520            <table border="0">
521            <tr><td width="150"><base:button 
522              onclick="addLabeledExtractsOnClick()" 
523              title="Add&nbsp;labeled&nbsp;extracts&hellip;" 
524              tooltip="Add labeled extracts"
525              /></td></tr>
526            <tr><td width="150"><base:button 
527              onclick="removeOnClick()" 
528              title="Remove" 
529              tooltip="Remove the selected labeled extracts"
530            /></td></tr>
531            </table>
532          </td>
533          </tr>
534          </table>
535        </td>
536      </tr>
537      </table>
538    </t:tab>
539
540    <t:tab id="annotations" title="Annotations" helpid="annotations.edit">
541      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
542        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
543        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
544    </t:tab>
545   
546    <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited">
547   
548      <iframe name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
549        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
550        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
551    </t:tab>
552    </t:tabcontrol>
553
554    <table align="center">
555    <tr>
556      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
557      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
558    </tr>
559    </table>
560    </form>
561  </base:body>
562  </base:page>
563  <%
564}
565finally
566{
567  if (dc != null) dc.close();
568}
569%>
Note: See TracBrowser for help on using the repository browser.