source: trunk/www/biomaterials/extracts/edit_extract.jsp @ 5767

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