source: trunk/www/biomaterials/samples/edit_sample.jsp @ 5767

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

Fixes #1626: Center-align text on buttons

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 29.1 KB
Line 
1<%-- $Id: edit_sample.jsp 5767 2011-09-28 07:31:39Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Johan Enell, Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page pageEncoding="UTF-8" session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.Type"
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.Sample"
36  import="net.sf.basedb.core.BioSource"
37  import="net.sf.basedb.core.ItemSubtype"
38  import="net.sf.basedb.core.BioMaterialEvent"
39  import="net.sf.basedb.core.BioPlate"
40  import="net.sf.basedb.core.BioWell"
41  import="net.sf.basedb.core.Protocol"
42  import="net.sf.basedb.core.Project"
43  import="net.sf.basedb.core.PermissionDeniedException"
44  import="net.sf.basedb.core.BaseException"
45  import="net.sf.basedb.core.ItemQuery"
46  import="net.sf.basedb.core.ItemResultList"
47  import="net.sf.basedb.core.Include"
48  import="net.sf.basedb.core.query.Orders"
49  import="net.sf.basedb.core.query.Hql"
50  import="net.sf.basedb.core.query.Expressions"
51  import="net.sf.basedb.core.query.Restrictions"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.Values"
55  import="net.sf.basedb.util.ListUtil"
56  import="net.sf.basedb.util.formatter.WellCoordinateFormatter"
57  import="net.sf.basedb.util.formatter.Formatter"
58  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
59  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
60  import="net.sf.basedb.core.plugin.GuiContext"
61  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
62  import="net.sf.basedb.clients.web.extensions.JspContext"
63  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
64  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
65  import="java.util.List"
66  import="java.util.Set"
67  import="java.util.HashSet"
68  import="java.util.Date"
69  import="java.util.Collections"
70%>
71<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
72<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
73<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
74<%
75final Item itemType = Item.SAMPLE;
76final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
77final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
78final int itemId = cc.getId();
79final String ID = sc.getId();
80final float scale = Base.getScale(sc);
81final DbControl dc = sc.newDbControl();
82try
83{
84  String title = null;
85  Sample sample = null;
86  BioMaterialEvent creationEvent = null;
87  Date eventDate = null;
88  Item parentType = null;
89  String name = null;
90  boolean lockEventProperties = false;
91
92  boolean readCurrentSubtype = true;
93  ItemSubtype currentSubtype = null;
94  boolean readCurrentProtocol = true;
95  Protocol currentProtocol = null;
96  boolean readCurrentBioSource = true;
97  BioSource currentBioSource = null;
98  ItemQuery<Sample> samplesQuery = null; 
99  boolean readCurrentBioWell = true;
100  BioWell currentBioWell = null;
101  boolean lockedWell = false;
102  boolean readCurrentBioPlate = true;
103  BioPlate currentBioPlate = null;
104 
105  WellCoordinateFormatter rowFormatter = new WellCoordinateFormatter(true);
106  WellCoordinateFormatter columnFormatter = new WellCoordinateFormatter(false);
107 
108  if (itemId == 0)
109  {
110    title = "Create sample";
111    cc.removeObject("item");
112    if (cc.getPropertyFilter("creationEvent.protocol.name") != null)
113    {
114      currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("creationEvent.protocol.name"));
115    }
116    int bioSourceId = Values.getInt(request.getParameter("biosource_id"));
117    int sampleId = Values.getInt(request.getParameter("sample_id"));
118    int currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
119    List<ItemSubtype> relatedToParent = Collections.emptyList();
120    if (bioSourceId != 0)
121    {
122      currentBioSource = BioSource.getById(dc, bioSourceId);
123      parentType = Item.BIOSOURCE;
124      name = currentBioSource.getName() + ".s" + (currentBioSource.countSamples() + 1);
125      if (currentSubtypeId == 0)
126      {
127        relatedToParent = ItemSubtype.getParentSubtypes(dc, currentBioSource, Item.SAMPLE);
128      }
129    }
130    else if (sampleId != 0)
131    {
132      parentType = Item.SAMPLE;
133      Sample s = Sample.getById(dc, sampleId);
134      name = s.getName() + ".s" + (s.countSamples()+1);
135      samplesQuery = Sample.getQuery();
136      samplesQuery.restrict(Restrictions.eq(Hql.property("id"), Expressions.integer(sampleId)));
137      if (currentSubtypeId == 0)
138      {
139        relatedToParent = ItemSubtype.getParentSubtypes(dc, s, Item.SAMPLE);
140      }
141    }
142    else if (Values.getBoolean(request.getParameter("pooled")))
143    {   
144      parentType = Item.SAMPLE;
145      name = Values.getString(cc.getPropertyValue("name"), "New pooled sample");
146      samplesQuery = Sample.getQuery();
147      samplesQuery.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("selected")));
148      samplesQuery.setParameter("selected", cc.getSelected(), Type.INT);
149    }
150    else
151    {
152      name = Values.getString(cc.getPropertyValue("name"), "New sample");
153    }
154    if (currentSubtypeId == 0) 
155    {
156      if (relatedToParent.size() > 0)
157      {
158        // Find most recently used related subtype
159        List<ItemSubtype> recentSubtypes = (List<ItemSubtype>)cc.getRecent(dc, Item.ITEMSUBTYPE);
160        currentSubtype = ListUtil.findFirstCommon(recentSubtypes, relatedToParent, relatedToParent.get(0));
161      }
162      else
163      {
164        int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
165        currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);
166        if (currentSubtypeId > 0) currentSubtype = ItemSubtype.getById(dc, currentSubtypeId);
167      }
168    }
169    eventDate = (Date)cc.getPropertyObject("creationEvent.eventDate");
170  }
171  else
172  {
173    sample = Sample.getById(dc, itemId);
174    sample.checkPermission(Permission.WRITE);
175    cc.setObject("item", sample);
176    title = "Edit sample -- " + HTML.encodeTags(sample.getName());
177 
178    creationEvent = sample.getCreationEvent();
179    eventDate = creationEvent.getEventDate();
180    parentType = sample.getParentType();
181    name = sample.getName();
182    lockEventProperties = !creationEvent.hasPermission(Permission.WRITE);
183   
184    try
185    {
186      currentSubtype = sample.getItemSubtype();
187    }
188    catch (PermissionDeniedException ex)
189    {
190      readCurrentSubtype = false;
191    }
192
193    try
194    {
195      currentProtocol = creationEvent.getProtocol();
196    }
197    catch (PermissionDeniedException ex)
198    {
199      readCurrentProtocol = false;
200    }
201 
202    try
203    {
204      if (parentType == Item.BIOSOURCE)
205      {
206        currentBioSource = (BioSource)sample.getParent();
207      }
208    }
209    catch (PermissionDeniedException ex)
210    {
211      readCurrentBioSource = false;
212    }
213   
214    try
215    {
216      currentBioWell = sample.getBioWell();
217      lockedWell = sample.isLockedInWell();
218      if (currentBioWell != null)
219      {
220        currentBioPlate = currentBioWell.getPlate();
221      }
222    }
223    catch (PermissionDeniedException ex)
224    {
225      readCurrentBioWell = false;
226      readCurrentBioPlate = false;
227    }
228 
229    // Query to retrieve parent samples
230    if (parentType == Item.SAMPLE)
231    {
232      samplesQuery = (ItemQuery<Sample>)creationEvent.getSources();
233    }
234  }
235 
236  // Default items
237  int activeProjectId = sc.getActiveProjectId();
238  List<Protocol> defaultProtocols = null;
239  if (activeProjectId > 0)
240  {
241    Project activeProject = Project.getById(dc, activeProjectId);
242    ItemSubtype protocolSubtype = currentSubtype == null ? null : currentSubtype.getRelatedSubtype(Item.PROTOCOL);
243    if (protocolSubtype == null) protocolSubtype = ItemSubtype.getById(dc, SystemItems.getId(Protocol.SAMPLING));
244    defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc, protocolSubtype, false);
245  }
246 
247  // Load recently used items
248  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL, currentSubtype);
249  List<BioSource> recentBioSources = (List<BioSource>)cc.getRecent(dc, Item.BIOSOURCE);
250  List<BioPlate> recentBioPlates = (List<BioPlate>)cc.getRecent(dc, Item.BIOPLATE, currentSubtype);
251 
252  // Query to retrieve item types
253  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
254  subtypesQuery.include(Include.ALL);
255 
256  final String clazz = "class=\"text\"";
257  final String requiredClazz = "class=\"text required\"";
258  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
259  String dateFormat = FormatterSettings.getDateFormat(sc);
260  String jsDateFormat = HTML.javaScriptEncode(dateFormat);
261  String htmlDateFormat = HTML.encodeTags(dateFormat);
262  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), sample);
263  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
264  %>
265  <base:page type="popup" title="<%=title%>">
266  <base:head scripts="tabcontrol.js,annotations.js,linkitems.js,subtypes.js,ajax.js,json2.js" styles="tabcontrol.css">
267    <ext:scripts context="<%=jspContext%>" />
268    <ext:stylesheets context="<%=jspContext%>" />
269    <script language="JavaScript">
270    // Validate the "Sample" tab
271    function validateSample()
272    {
273      var frm = document.forms['sample'];
274      if (Main.trimString(frm.name.value) == '')
275      {
276        alert("You must enter a name");
277        frm.name.focus();
278        return false;
279      }
280      if (Main.trimString(frm.bioplate_id.value) != 0 && Main.trimString(frm.biowell_id.value) == 0)
281      {
282        alert("You must choose a biowell from the bioplate");
283        return false;
284      }
285      return true;
286    }
287
288    // Submit the form
289    function saveSettings()
290    {
291      var frm = document.forms['sample'];
292      if (TabControl.validateActiveTab('settings'))
293      {
294        if (annotationsLoaded)
295        {
296          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
297        }
298        if (inheritedAnnotationsLoaded)
299        {
300          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
301        }
302        frm.modifiedSamples.value = Link.exportModified(frm, 'S', true).join(',');
303        frm.removedSamples.value = Link.getActionIds(-1, 'S').join(',');
304        frm.submit();
305      }
306    }
307   
308    var annotationsLoaded = false;
309    var inheritedAnnotationsLoaded = false;
310    var parentsChanged = false;
311    var protocolChanged = false;
312    function switchTab(tabControlId, tabId)
313    {
314      if (TabControl.setActiveTab(tabControlId, tabId))
315      {
316        if (tabId == 'annotations' && (protocolChanged || !annotationsLoaded))
317        {
318          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getProtocolId(), ItemSubtype.getSubtypeId('sample'));
319          annotationsLoaded = true;
320          protocolChanged = false;
321        }
322        else if (tabId == 'inheritedAnnotations' && 
323          (parentsChanged || !inheritedAnnotationsLoaded))
324        {
325          Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
326          inheritedAnnotationsLoaded = true;
327          parentsChanged = false;
328        }
329      }
330    }
331   
332    function getProtocolId()
333    {
334      var frm = document.forms['sample'];
335      var protocolId = 0;
336      if (frm.protocol_id.length > 0 && !frm.protocol_id.disabled)
337      {
338        protocolId = Math.abs(parseInt(frm.protocol_id[frm.protocol_id.selectedIndex].value));       
339      }
340      return protocolId;
341    }
342   
343    function getParents()
344    {
345      var frm = document.forms['sample'];
346      var parents = new Array();
347      if (frm.parentType[0].checked)
348      {
349        var bioSourceId = Math.abs(parseInt(frm.biosource_id[frm.biosource_id.selectedIndex].value));
350        if (bioSourceId > 0) parents[parents.length] = 'BIOSOURCE:'+bioSourceId;
351      }
352      else
353      {
354        var ids = Link.getListIds(frm.samples, 'S');
355        if (ids.length > 0)
356        {
357          parents[parents.length] = 'SAMPLE:'+ids.join(':');
358        }
359      }
360      return parents;
361    }
362   
363    function subtypeOnChange()
364    {
365      var frm = document.forms['sample'];
366      var subtypeId = ItemSubtype.getSubtypeId('sample');
367      var recentInfo = ItemSubtype.getRecentAndRelatedInfo(subtypeId, 'SAMPLE', ['PROTOCOL', 'BIOPLATE', 'BIOSOURCE', 'SAMPLE']);
368      protocolChanged = ItemSubtype.updateSelectionList(frm.protocol_id, recentInfo.PROTOCOL['recent'], recentInfo.PROTOCOL['default']);
369      ItemSubtype.updateSelectionList(frm.bioplate_id, recentInfo.BIOPLATE['recent']);
370    }
371   
372    function selectProtocolOnClick()
373    {
374      var frm = document.forms['sample'];
375      var url = '../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone';
376      url += '&callback=setProtocolCallback&resetTemporary=1';
377      url += ItemSubtype.createRelatedFilter('sample', 'PROTOCOL', <%=SystemItems.getId(Protocol.SAMPLING)%>);
378      if (frm.protocol_id.length > 1)
379      {
380        var id = Math.abs(parseInt(frm.protocol_id[1].value));       
381        url += '&item_id='+id;
382      }
383      Main.openPopup(url, 'SelectProtocol', 1000, 700);
384    }
385    function setProtocolCallback(id, name)
386    {
387      var frm = document.forms['sample'];
388      var list = frm.protocol_id;
389      if (list.length < 2 || list[1].value == '0') // >
390      {
391        Forms.addListOption(list, 1, new Option());
392      }
393      list[1].value = id;
394      list[1].text = name;
395      list.selectedIndex = 1;
396      protocolChanged = true;
397    }
398    function protocolOnChange()
399    {
400      protocolChanged = true;
401    }
402
403    function selectBioPlateOnClick()
404    {
405      var frm = document.forms['sample'];
406      var url = '../bioplates/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setBioPlateCallback';
407      if (frm.bioplate_id.length > 1)
408      {
409        var id = Math.abs(parseInt(frm.bioplate_id[1].value));       
410        url += '&item_id='+id;
411      }
412      url += '&resetTemporary=1&tmpfilter:INT:bioPlateType.lockMode=<><%=BioWell.LockMode.LOCKED_AFTER_CREATE.getValue()%>';
413      // Restrict to plates that can holds samples
414      url += '&tmpfilter:INT:bioPlateType.bioMaterialType=|<%=itemType.getValue()%>';
415      var subtypeId = ItemSubtype.getSubtypeId('sample');
416      // Restrict to plates with the given subtype
417      url += '&tmpfilter:INT:bioPlateType.itemSubtype='+(subtypeId ? '|' + subtypeId : '=');
418      url += '&tmpfilter:BOOLEAN:destroyed=false';
419      Main.openPopup(url, 'SelectBioplate', 1000, 700);
420    }
421    function setBioPlateCallback(id, name)
422    {
423      var frm = document.forms['sample'];
424      var list = frm.bioplate_id;
425      if (list.length < 2 || list[1].value == '0') // >
426      {
427        Forms.addListOption(list, 1, new Option());
428      }
429      list[1].value = id;
430      list[1].text = name;
431      list.selectedIndex = 1;
432      frm.biowell_id.remove(1);
433      frm.biowell_id.disabled = false;
434    }
435    function bioPlateOnChange()
436    {
437      var frm = document.forms['sample'];
438      var list = frm.bioplate_id;
439      frm.biowell_id.selectedIndex=0;
440      frm.biowell_id.remove(1);     
441    }
442
443    function initBioWell()
444    {
445      var frm = document.forms['sample'];
446      <%
447      if (currentBioWell != null)
448      {
449        %>
450        var list = frm.biowell_id;
451        var wellId = <%=currentBioWell.getId()%>;
452        Forms.addListOption(list, 1, new Option());
453        list[1].value = '<%=currentBioWell.getId()*(sample == null ? 1 : -1)%>';
454        list[1].text = '<%=rowFormatter.format(currentBioWell.getRow())%><%=columnFormatter.format(currentBioWell.getColumn())%>';
455        list.selectedIndex = 1;
456      <%
457      }
458      %>
459    }         
460    function selectBioWellOnClick()
461    {
462      var frm = document.forms['sample'];
463      var bioplate_list = frm.bioplate_id;     
464      var bioplateId = Math.abs(parseInt(bioplate_list[bioplate_list.selectedIndex].value))
465      if (Main.trimString(frm.bioplate_id.value) == 0)
466      {
467        alert("You must first select the bioplate where the biowell is located");
468        return;
469      }     
470       
471      var url = '../bioplates/wells/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setBioWellCallback';
472      if (frm.biowell_id.length > 1)
473      {
474        var id = Math.abs(parseInt(frm.biowell_id[1].value));       
475        url += '&item_id='+id;
476      }
477      url += '&bioplate_id='+bioplateId;
478      url += '&resetTemporary=1&tmpfilter:STRING:$mbm.name='+escape('=');
479      url += '&tmpfilter:STRING:originalBioMaterial.name='+escape('=');
480      url += '&columns=row,column';
481      Main.openPopup(url, 'SelectBiowell', 700, 700);
482    }
483    function setBioWellCallback(id, name)
484    {
485      var frm = document.forms['sample'];
486      var list = frm.biowell_id;
487      if (list.length < 2 || list[1].value == '0') // >
488      {
489        Forms.addListOption(list, 1, new Option());
490      }
491      list[1].value = id;
492      list[1].text = name;
493      list.selectedIndex = 1;
494    }
495   
496    function parentTypeOnClick()
497    {
498      var frm = document.forms['sample'];
499      var useSamples = frm.parentType[1].checked;
500      frm.biosource_id.disabled = useSamples;
501      frm.samples.disabled = !useSamples;
502      frm.used_quantity.disabled = !useSamples;
503      parentsChanged = true;
504    }
505    function bioSourceOnChange()
506    {
507      parentsChanged = true;
508    }
509    function selectBioSourceOnClick()
510    {
511      var frm = document.forms['sample'];
512      var url = '../biosources/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone';
513      url += '&callback=setBioSourceCallback&resetTemporary=1';
514      url += ItemSubtype.createRelatedFilter('sample', 'BIOSOURCE');
515      if (frm.biosource_id.length > 1)
516      {
517        var id = Math.abs(parseInt(frm.biosource_id[1].value));       
518        url += '&item_id='+id;
519      }
520      Main.openPopup(url, 'SelectBioSource', 1000, 700);
521    }
522    function setBioSourceCallback(id, name)
523    {
524      var frm = document.forms['sample'];
525      var list = frm.biosource_id;
526      if (list.length < 2 || list[1].value == '0') // >
527      {
528        Forms.addListOption(list, 1, new Option());
529      }
530      list[1].value = id;
531      list[1].text = name;
532      list.selectedIndex = 1;
533
534      frm.parentType[0].checked = true;
535      frm.parentType[1].checked = false;
536      parentTypeOnClick();
537      parentsChanged = true;
538    }
539   
540    function addSamplesOnClick()
541    {
542      var frm = document.forms['sample'];
543      var url = 'index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple';
544      url += '&callback=addSampleCallback&resetTemporary=1';
545      url += ItemSubtype.createRelatedFilter('sample', 'SAMPLE');
546      Main.openPopup(url, 'AddSamples', 1000, 700);
547    }
548    function addSampleCallback(sampleId, name)
549    {
550      var frm = document.forms['sample'];
551      var item = Link.getItem('S', sampleId);
552      if (!item) item = new Item('S', sampleId, name+' [-]', '', '');
553      Link.addItem(frm.samples, item);
554      frm.parentType[0].checked = false;
555      frm.parentType[1].checked = true;
556      parentTypeOnClick();
557      parentsChanged = true;
558    }
559    function samplesOnChange()
560    {
561      var frm = document.forms['sample'];
562      var item = frm.samples[frm.samples.selectedIndex].item;
563      if (item && item.id)
564      {
565        frm.used_quantity.value = item.value;
566        frm.used_quantity.focus();
567      }
568      else
569      {
570        frm.used_quantity.value = '';
571      }
572    }
573    function usedQuantityOnBlur()
574    {
575      var frm = document.forms['sample'];
576      var usedQuantity = frm.used_quantity.value;
577      var displayQuantity = usedQuantity == '' ? '-' : usedQuantity+' µg';
578      for (var i = 0; i < frm.samples.length; i++)  // >
579      {
580        var option = frm.samples[i];
581        if (option.selected && option.item.id)
582        {
583          option.item.value = usedQuantity;
584          var text = option.text.replace(/\[.*\]/, '['+displayQuantity+']');
585          option.text = text;
586        }
587      }
588    }
589
590    function removeOnClick()
591    {
592      Link.removeSelected(document.forms['sample'].samples);
593      parentsChanged = true;
594    }
595
596    function init()
597    {
598      <%
599      if (sample == null)
600      {
601        %>
602        var frm = document.forms['sample'];
603        frm.name.focus();
604        frm.name.select();
605        <%
606      }
607      %>
608      initBioWell();
609      initSamples();
610      parentTypeOnClick();   
611    }
612    function initSamples()
613    {
614      var samples = document.forms['sample'].samples;
615      <%
616      if (samplesQuery != null)
617      {
618        samplesQuery.include(Include.ALL);
619        samplesQuery.order(Orders.asc(Hql.property("name")));
620        ItemResultList<Sample> samples = samplesQuery.list(dc);
621        for (Sample s : samples)
622        {
623          if (sample != null)
624          {
625            String usedQuantity = Values.formatNumber(creationEvent.getUsedQuantity(s), -1);
626            %>
627            Link.addNewItem(samples, new Item('S', <%=s.getId()%>, '<%=HTML.javaScriptEncode(s.getName())%> [<%=usedQuantity%> µg]', '<%=usedQuantity%>'));
628            <%
629          }
630          else
631          {
632            %>
633            Link.addItem(samples, new Item('S', <%=s.getId()%>, '<%=HTML.javaScriptEncode(s.getName())%> [-]', '', ''));
634            <%
635          }
636        }
637      }
638      %>
639    }
640    </script>
641  </base:head>
642  <base:body onload="init()">
643    <p>
644    <form action="index.jsp?ID=<%=ID%>" method="post" name="sample" onsubmit="return false;">
645    <input type="hidden" name="cmd" value="UpdateItem">
646
647    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
648    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
649      position="bottom"  remember="<%=sample != null%>" switch="switchTab"
650      extensions="<%=invoker%>">
651    <t:tab id="info" title="Sample" validate="validateSample()" helpid="sample.edit">
652      <table class="form" cellspacing=0>
653      <tr>
654        <td class="prompt">Name</td>
655        <td><input <%=requiredClazz%> type="text" name="name" 
656          value="<%=HTML.encodeTags(name)%>" 
657          size="40" maxlength="<%=Sample.MAX_NAME_LENGTH%>"></td>
658      </tr>
659      <tr valign="top">
660        <td class="prompt">Type</td>
661        <td colspan="2">
662          <select name="subtype_id"
663            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>
664            onchange="subtypeOnChange()"
665            >
666          <%
667          if (!readCurrentSubtype)
668          {
669            %>
670            <option value="-1">- denied -
671            <%
672          }
673          else
674          {
675            %>
676            <option value="0">-none-
677            <%
678            int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
679            for (ItemSubtype subtype : subtypesQuery.list(dc))
680            {
681              int id = subtype.getId();
682              if (id != currentSubtypeId && subtype.isRemoved()) continue;
683              %>
684              <option value="<%=id == currentSubtypeId && sample != null ? -id : id%>" 
685                <%=id == currentSubtypeId ? "selected" : ""%>
686                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
687                ><%=HTML.encodeTags(subtype.getName())%>
688              <%
689            }
690          }
691          %>
692          </select>
693        </td>
694      </tr>
695      <tr>
696        <td class="prompt">External ID</td>
697        <td><input <%=clazz%> type="text" name="external_id" 
698          value="<%=HTML.encodeTags(sample == null ? Values.getString(cc.getPropertyValue("externalId"), "") : sample.getExternalId())%>" 
699          size="40" maxlength="<%=Sample.MAX_EXTERNAL_ID_LENGTH%>"></td>
700      </tr>
701      <tr>
702        <td class="prompt">Original quantity</td>
703        <td><input <%=clazz%> type="text" name="original_quantity" 
704          value="<%=Values.formatNumber(sample == null ? Values.getFloat(cc.getPropertyValue("originalQuantity"), null): sample.getOriginalQuantity(), -1)%>" size="12" 
705          maxlength="10" onkeypress="return Numbers.numberOnly(event)"> (µg)</td>
706      </tr>
707      <tr>
708        <td class="prompt">Created</td>
709        <td>
710          <table border="0" cellspacing="0" cellpadding="0">
711          <tr>
712          <td>
713            <input <%=clazz%> type="text" name="event_date" <%=lockEventProperties ? "disabled" : ""%>
714              value="<%=HTML.encodeTags(dateFormatter.format(eventDate))%>" 
715              size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>">
716            &nbsp;
717          </td>
718          <td>
719          <base:button 
720            onclick="<%="Dates.selectDate('Created', 'sample', 'event_date', null, '"+jsDateFormat+"')"%>"
721            image="calendar.png" 
722            title="Calendar&hellip;" 
723            tooltip="Select a date from a calendar" 
724            disabled="<%=lockEventProperties%>"
725          />
726          </td>
727          </tr>
728          </table>
729        </td>
730      </tr>
731      <tr>
732        <td class="prompt">Registered</td>
733        <td><%=dateFormatter.format(creationEvent == null ? new Date() : creationEvent.getEntryDate())%></td>
734      </tr>
735      <tr>
736        <td class="prompt">Protocol</td>
737        <td>
738          <base:select 
739            id="protocol_id"
740            clazz="selectionlist"
741            required="false"
742            current="<%=currentProtocol%>"
743            denied="<%=!readCurrentProtocol%>"
744            recent="<%=recentProtocols%>"
745            defaultitems="<%=defaultProtocols%>"
746            newitem="<%=sample == null%>"
747            onselect="selectProtocolOnClick()"
748            onchange="protocolOnChange()"
749            disabled="<%=lockEventProperties %>"
750          />
751        </td>
752      </tr>
753      <tr>
754        <td class="prompt">Bioplate</td>
755        <td>
756          <base:select 
757            id="bioplate_id"
758            clazz="selectionlist"
759            required="false"
760            current="<%=currentBioPlate%>"
761            denied="<%=!readCurrentBioPlate%>"
762            recent="<%=recentBioPlates%>"
763            newitem="<%=sample == null%>"
764            onselect="selectBioPlateOnClick()"
765            onchange="bioPlateOnChange()"
766            disabled="<%=lockedWell%>"
767          />
768        </td>
769      </tr>
770      <tr>
771        <td class="prompt">Biowell</td>
772        <td>
773          <base:select 
774            id="biowell_id"
775            clazz="selectionlist"
776            required="false"           
777            current="<%=null %>"
778            denied="<%=!readCurrentBioWell%>"
779            newitem="<%=sample == null%>"
780            onselect="selectBioWellOnClick()"
781            onchange="bioWellOnChange()"
782            disabled="<%=lockedWell%>"
783          />
784        </td>
785      </tr>
786      <tr valign=top>
787        <td class="prompt">Description</td>
788        <td nowrap>
789          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
790            ><%=HTML.encodeTags(sample == null ? cc.getPropertyValue("description") : sample.getDescription())%></textarea>
791          <a href="javascript:Main.zoom('Description', 'sample', 'description')"
792            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
793        </td>
794      </tr>
795      </table>
796      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
797    </t:tab>
798   
799    <t:tab id="parents" title="Parents" helpid="sample.parents" >
800      <table class="form" cellspacing=0>
801      <tr>
802        <td class="prompt">Parent type</td>
803        <td>
804          <input type="radio" name="parentType" id="parentType.biosource" 
805            value="BIOSOURCE" onclick="parentTypeOnClick()"
806            <%=parentType != Item.SAMPLE ? "checked" : ""%>
807            ><label for="parentType.biosource">Biosource</label>
808          <input type="radio" name="parentType" id="parentType.sample" 
809            value="SAMPLE" onclick="parentTypeOnClick()"
810            <%=parentType == Item.SAMPLE ? "checked" : ""%>
811            ><label for="parentType.sample">Sample</label>
812        </td>
813      </tr>
814      <tr>
815        <td class="prompt">Biosource</td>
816        <td>
817          <base:select 
818            id="biosource_id"
819            clazz="selectionlist"
820            buttonstyle="width: 150px;"
821            buttonicon="add.png"
822            buttontitle="Select biosource&hellip;"
823            buttonclass="leftaligned buttonclass"
824            required="false"
825            current="<%=currentBioSource%>"
826            denied="<%=!readCurrentBioSource%>"
827            recent="<%=recentBioSources%>"
828            selectrecent="false"
829            newitem="<%=sample == null%>"
830            onselect="selectBioSourceOnClick()"
831            onchange="bioSourceOnChange()"
832          />
833        </td>
834      </tr>
835      <tr valign="top">
836        <td class="prompt">Samples</td>
837        <td>
838          <table border="0" cellspacing="0" cellpadding="0">
839          <tr valign="top">
840          <td>
841            <select name="samples" size="12" multiple class="selectionlist" 
842              onchange="samplesOnChange()">
843            </select>&nbsp;
844            <input type="hidden" name="modifiedSamples" value="">
845            <input type="hidden" name="removedSamples" value="">
846          </td>
847          <td>
848            <table border="0" cellspacing="0" cellpadding="0">
849            <tr><td style="padding: 1px 0px 4px 0px;"><base:button 
850              clazz="leftaligned buttonclass"
851              style="width: 150px;"
852              onclick="addSamplesOnClick()" 
853              title="Add&nbsp;samples&hellip;" 
854              tooltip="Add samples"
855              /></td></tr>
856            <tr><td><base:button 
857              clazz="leftaligned buttonclass"
858              style="width: 150px;"
859              onclick="removeOnClick()" 
860              title="Remove" 
861              tooltip="Remove the selected samples"
862            /></td></tr>
863            </table>
864          </td>
865          </tr>
866          </table>
867        </td>
868      </tr>
869      <tr>
870        <td class="subprompt">-</td>
871        <td>used quantity
872        <input <%=clazz%> type="text" name="used_quantity" value=""
873              size="12" maxlength="10" onkeypress="return Numbers.numberOnly(event)"
874              onkeyup="usedQuantityOnBlur();"
875            > (µg)
876        </td>
877      </tr>         
878      </table>
879    </t:tab>
880
881    <t:tab id="annotations" title="Annotations &amp; parameters" 
882      helpid="annotations.edit" tooltip="Enter values for annotations and protocol parameters">
883      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
884        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
885        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
886    </t:tab>
887   
888    <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited">
889   
890      <iframe name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
891        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
892        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
893    </t:tab>
894    </t:tabcontrol>
895
896    <table align="center">
897    <tr>
898      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
899      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
900    </tr>
901    </table>
902    </form>
903  </base:body>
904  </base:page>
905  <%
906}
907finally
908{
909  if (dc != null) dc.close();
910}
911%>
Note: See TracBrowser for help on using the repository browser.