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

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

References #1597: Subtypes of items

Smarter selection of default subtypes and related items (protocols, etc) have now been implemented in the other important edit dialogs.

Added support for also loading and displaying project default items dynamically based on the selected subtype.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 30.9 KB
Line 
1<%-- $Id: edit_extract.jsp 5687 2011-08-09 11:39:40Z 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.updateRecentItemsInList(frm.protocol_id, recentInfo.PROTOCOL['recent']);
390      ItemSubtype.updateDefaultItemsInList(frm.protocol_id, recentInfo.PROTOCOL['default']);
391      ItemSubtype.updateRecentItemsInList(frm.tag_id, recentInfo.TAG['recent']);
392      ItemSubtype.updateRecentItemsInList(frm.bioplate_id, recentInfo.BIOPLATE['recent']);
393    }
394   
395    function selectProtocolOnClick()
396    {
397      var frm = document.forms['extract'];
398      var url = '../../admin/protocols/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone';
399      url += '&callback=setProtocolCallback&resetTemporary=1';
400      url += ItemSubtype.createRelatedFilter('extract', 'PROTOCOL', <%=SystemItems.getId(Protocol.EXTRACTION)%>);
401      if (frm.protocol_id.length > 1)
402      {
403        var id = Math.abs(parseInt(frm.protocol_id[1].value));       
404        url += '&item_id='+id;
405      }
406      Main.openPopup(url, 'SelectProtocol', 1000, 700);
407    }
408    function setProtocolCallback(id, name)
409    {
410      var frm = document.forms['extract'];
411      var list = frm.protocol_id;
412      if (list.length < 2 || list[1].value == '0') // >
413      {
414        Forms.addListOption(list, 1, new Option());
415      }
416      list[1].value = id;
417      list[1].text = name;
418      list.selectedIndex = 1;
419      protocolChanged = true;
420    }
421    function protocolOnChange()
422    {
423      protocolChanged = true;
424    }
425    function selectTagOnClick()
426    {
427      var frm = document.forms['extract'];
428      var url = '../tags/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone';
429      url += '&callback=setTagCallback&resetTemporary=1';
430      url += ItemSubtype.createRelatedFilter('extract', 'TAG');
431      if (frm.tag_id.length > 1)
432      {
433        var id = Math.abs(parseInt(frm.tag_id[1].value));       
434        url += '&item_id='+id;
435      }
436      Main.openPopup(url, 'SelectTag', 1000, 700);
437    }
438    function setTagCallback(id, name)
439    {
440      var frm = document.forms['extract'];
441      var list = frm.tag_id;
442      if (list.length < 2 || list[1].value == '0') // >
443      {
444        Forms.addListOption(list, 1, new Option());
445      }
446      list[1].value = id;
447      list[1].text = name;
448      list.selectedIndex = 1;
449    }
450    function selectBioPlateOnClick()
451    {
452      var frm = document.forms['extract'];
453      var url = '../bioplates/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setBioPlateCallback';
454      if (frm.bioplate_id.length > 1)
455      {
456        var id = Math.abs(parseInt(frm.bioplate_id[1].value));       
457        url += '&item_id='+id;
458      }
459      url += '&resetTemporary=1&tmpfilter:INT:bioPlateType.lockMode=<><%=BioWell.LockMode.LOCKED_AFTER_CREATE.getValue()%>';
460      url += '&tmpfilter:BOOLEAN:destroyed=false';
461      Main.openPopup(url, 'SelectBioplate', 1000, 700);
462    }
463    function setBioPlateCallback(id, name)
464    {
465      var frm = document.forms['extract'];
466      var list = frm.bioplate_id;
467      if (list.length < 2 || list[1].value == '0') // >
468      {
469        Forms.addListOption(list, 1, new Option());
470      }
471      list[1].value = id;
472      list[1].text = name;
473      list.selectedIndex = 1;
474      frm.biowell_id.remove(1);
475      frm.biowell_id.disabled = false;
476    }
477    function bioPlateOnChange()
478    {
479      var frm = document.forms['extract'];
480      var list = frm.bioplate_id;
481      frm.biowell_id.selectedIndex=0;
482      frm.biowell_id.remove(1);     
483    }
484
485    function initBioWell()
486    {
487      var frm = document.forms['extract'];
488      <%
489      if (currentBioWell != null)
490      {
491        %>
492        var list = frm.biowell_id;
493        var wellId = <%=currentBioWell.getId()%>;
494        Forms.addListOption(list, 1, new Option());
495        list[1].value = '<%=currentBioWell.getId()*(extract == null ? 1 : -1)%>';
496        list[1].text = '[<%=rowFormatter.format(currentBioWell.getRow())%>,<%=columnFormatter.format(currentBioWell.getColumn())%>]';
497        list.selectedIndex = 1;
498      <%
499      }
500      %>
501    }         
502    function selectBioWellOnClick()
503    {
504      var frm = document.forms['extract'];
505      var bioplate_list = frm.bioplate_id;     
506      var bioplateId = Math.abs(parseInt(bioplate_list[bioplate_list.selectedIndex].value))
507      if (Main.trimString(frm.bioplate_id.value) == 0)
508      {
509        alert("You must first select the bioplate where the biowell is located");
510        return;
511      }     
512       
513      var url = '../bioplates/wells/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setBioWellCallback';
514      if (frm.biowell_id.length > 1)
515      {
516        var id = Math.abs(parseInt(frm.biowell_id[1].value));       
517        url += '&item_id='+id;
518      }
519      url += '&bioplate_id='+bioplateId;
520      url += '&resetTemporary=1&tmpfilter:STRING:$mbm.name='+escape('=');
521      url += '&tmpfilter:STRING:originalBioMaterial.name='+escape('=');
522      url += '&columns=row,column';
523      Main.openPopup(url, 'SelectBiowell', 700, 700);
524    }
525    function setBioWellCallback(id, name)
526    {
527      var frm = document.forms['extract'];
528      var list = frm.biowell_id;
529      if (list.length < 2 || list[1].value == '0') // >
530      {
531        Forms.addListOption(list, 1, new Option());
532      }
533      list[1].value = id;
534      list[1].text = name;
535      list.selectedIndex = 1;
536    }
537   
538    function parentTypeOnClick()
539    {
540      var frm = document.forms['extract'];
541      var useExtracts = frm.parentType[1].checked;
542      frm.sample_id.disabled = useExtracts;
543      frm.used_from_sample.disabled = useExtracts;
544      frm.extracts.disabled = !useExtracts;
545      frm.used_quantity.disabled = !useExtracts;
546      parentsChanged = true;
547    }
548    function sampleOnChange()
549    {
550      parentsChanged = true;
551    }
552   
553    function selectSampleOnClick()
554    {
555      var frm = document.forms['extract'];
556      var url = '../samples/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone';
557      url += '&callback=setSampleCallback&resetTemporary=1';
558      url += ItemSubtype.createRelatedFilter('extract', 'SAMPLE');
559      if (frm.sample_id.length > 1)
560      {
561        var id = Math.abs(parseInt(frm.sample_id[1].value));       
562        url += '&item_id='+id;
563      }
564      Main.openPopup(url, 'SelectSample', 1000, 700);
565    }
566    function setSampleCallback(id, name)
567    {
568      var frm = document.forms['extract'];
569      var list = frm.sample_id;
570      if (list.length < 2 || list[1].value == '0') // >
571      {
572        Forms.addListOption(list, 1, new Option());
573      }
574      list[1].value = id;
575      list[1].text = name;
576      list.selectedIndex = 1;
577      frm.parentType[0].checked = true;
578      frm.parentType[1].checked = false;
579      parentTypeOnClick();
580      parentsChanged = true;
581    }
582   
583    function addExtractsOnClick()
584    {
585      var frm = document.forms['extract'];
586      var url = 'index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectmultiple';
587      url += '&callback=addExtractCallback&resetTemporary=1';
588      url += ItemSubtype.createRelatedFilter('extract', 'EXTRACT');
589      Main.openPopup(url, 'AddExtracts', 1000, 700);
590    }
591   
592    function addExtractCallback(extractId, name)
593    {
594      var item = Link.getItem('E', extractId);
595      if (!item) item = new Item('E', extractId, name+' [-]', '', '');
596      Link.addItem(document.forms['extract'].extracts, item);
597      frm.parentType[0].checked = false;
598      frm.parentType[1].checked = true;
599      parentTypeOnClick();
600      parentsChanged = true;
601    }
602    function extractsOnChange()
603    {
604      var frm = document.forms['extract'];
605      var item = frm.extracts[frm.extracts.selectedIndex].item;
606      if (item && item.id)
607      {
608        frm.used_quantity.value = item.value;
609        frm.used_quantity.focus();
610      }
611      else
612      {
613        frm.used_quantity.value = '';
614      }
615    }
616    function usedQuantityOnBlur()
617    {
618      var frm = document.forms['extract'];
619      var usedQuantity = frm.used_quantity.value;
620      var displayQuantity = usedQuantity == '' ? '-' : usedQuantity+' µg';
621      for (var i = 0; i < frm.extracts.length; i++) // >
622      {
623        var option = frm.extracts[i];
624        if (option.selected && option.item.id)
625        {
626          option.item.value = usedQuantity;
627          var text = option.text.replace(/\[.*\]/, '['+displayQuantity+']');
628          option.text = text;
629        }
630      }
631    }
632    function usedFromSampleOnBlur()
633    {
634      var frm = document.forms['extract'];
635     
636      var sampleId = parseInt(frm.sample_id[frm.sample_id.selectedIndex].value);
637      if (sampleId < 0)
638      {
639        frm.sample_id[frm.sample_id.selectedIndex].value = -sampleId;
640      }
641    }
642   
643
644    function removeOnClick()
645    {
646      Link.removeSelected(document.forms['extract'].extracts);
647      parentsChanged = true;
648    }
649
650    function init()
651    {
652      <%
653      if (extract == null)
654      {
655        %>
656        var frm = document.forms['extract'];
657        frm.name.focus();
658        frm.name.select();
659        <%
660      }
661      %>
662      initBioWell();     
663      initExtracts();
664      parentTypeOnClick();
665    }
666    function initExtracts()
667    {
668      var extracts = document.forms['extract'].extracts;
669      <%
670      if (extractsQuery != null)
671      {
672        extractsQuery.include(Include.ALL);
673        extractsQuery.order(Orders.asc(Hql.property("name")));
674        ItemResultList<Extract> extracts = extractsQuery.list(dc);
675        for (Extract e : extracts)
676        {
677          if (extract != null)
678          {
679            String usedQuantity = Values.formatNumber(creationEvent.getUsedQuantity(e), -1);
680            %>
681            Link.addNewItem(extracts, new Item('E', <%=e.getId()%>, '<%=HTML.javaScriptEncode(e.getName())%> [<%=usedQuantity%> µg]', '<%=usedQuantity%>'));
682            <%
683          }
684          else
685          {
686            %>
687            Link.addItem(extracts, new Item('E', <%=e.getId()%>, '<%=HTML.javaScriptEncode(e.getName())%> [-]', '', ''));
688            <%
689           
690          }
691        }
692      }
693      %>
694    }
695    </script>
696  </base:head>
697  <base:body onload="init()">
698    <p>
699    <form action="index.jsp?ID=<%=ID%>" method="post" name="extract" onsubmit="return false;">
700    <input type="hidden" name="cmd" value="UpdateItem">
701
702    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
703    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
704      position="bottom"  remember="<%=extract != null%>" switch="switchTab"
705      extensions="<%=invoker%>">
706    <t:tab id="info" title="Extract" validate="validateExtract()" helpid="extract.edit">
707      <table class="form" cellspacing=0>
708      <tr>
709        <td class="prompt">Name</td>
710        <td><input <%=requiredClazz%> type="text" name="name" 
711          value="<%=HTML.encodeTags(name)%>" 
712          size="40" maxlength="<%=Extract.MAX_NAME_LENGTH%>"></td>
713      </tr>
714      <tr valign="top">
715        <td class="prompt">Type</td>
716        <td colspan="2">
717          <select name="subtype_id"
718            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>
719            onchange="subtypeOnChange()"
720            >
721          <%
722          if (!readCurrentSubtype)
723          {
724            %>
725            <option value="-1">- denied -
726            <%
727          }
728          else
729          {
730            %>
731            <option value="0">-none-
732            <%
733            int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
734            for (ItemSubtype subtype : subtypesQuery.list(dc))
735            {
736              int id = subtype.getId();
737              if (id != currentSubtypeId && subtype.isRemoved()) continue;
738              %>
739              <option value="<%=id == currentSubtypeId && extract != null ? -id : id%>" 
740                <%=id == currentSubtypeId ? "selected" : ""%>
741                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
742                ><%=HTML.encodeTags(subtype.getName())%>
743              <%
744            }
745          }
746          %>
747          </select>
748        </td>
749      </tr>
750      <tr>
751        <td class="prompt">Tag</td>
752        <td>
753          <base:select 
754            id="tag_id"
755            clazz="selectionlist"
756            required="false"
757            current="<%=currentTag%>"
758            denied="<%=!readCurrentTag%>"
759            recent="<%=recentTags%>"
760            newitem="<%=extract == null%>"
761            onselect="selectTagOnClick()"
762          />
763        </td>
764      </tr>
765      <tr>
766        <td class="prompt">External ID</td>
767        <td><input <%=clazz%> type="text" name="external_id" 
768          value="<%=HTML.encodeTags(extract == null ? Values.getString(cc.getPropertyValue("externalId"), "") : extract.getExternalId())%>" 
769          size="40" maxlength="<%=Extract.MAX_EXTERNAL_ID_LENGTH%>"></td>
770      </tr>
771      <tr>
772        <td class="prompt">Original quantity</td>
773        <td><input <%=clazz%> type="text" name="original_quantity" 
774          value="<%=Values.formatNumber(extract == null ? Values.getFloat(cc.getPropertyValue("originalQuantity"), null): extract.getOriginalQuantity(), -1)%>" size="12" 
775          maxlength="10" onkeypress="return Numbers.numberOnly(event)"> (µg)</td>
776      </tr>
777      <tr>
778        <td class="prompt">Created</td>
779        <td>
780          <table border="0" cellspacing="0" cellpadding="0">
781          <tr>
782          <td>
783            <input <%=clazz%> type="text" name="event_date" <%=lockEventProperties ? "disabled" : ""%>
784              value="<%=HTML.encodeTags(dateFormatter.format(eventDate))%>" 
785              size="20" maxlength="20" title="Enter date in format: <%=htmlDateFormat%>">
786            &nbsp;
787          </td>
788          <td>
789          <base:button 
790            onclick="<%="Dates.selectDate('Created', 'extract', 'event_date', null, '"+jsDateFormat+"')"%>"
791            image="calendar.png" 
792            title="Calendar&hellip;" 
793            tooltip="Select a date from a calendar" 
794            disabled="<%=lockEventProperties%>"
795          />
796          </td>
797          </tr>
798          </table>
799        </td>
800      </tr>
801      <tr>
802        <td class="prompt">Registered</td>
803        <td><%=dateFormatter.format(creationEvent == null ? new Date() : creationEvent.getEntryDate())%></td>
804      </tr>
805      <tr>
806        <td class="prompt">Protocol</td>
807        <td>
808          <base:select 
809            id="protocol_id"
810            clazz="selectionlist"
811            required="false"
812            current="<%=currentProtocol%>"
813            denied="<%=!readCurrentProtocol%>"
814            recent="<%=recentProtocols%>"
815            defaultitems="<%=defaultProtocols%>"
816            newitem="<%=extract == null%>"
817            onselect="selectProtocolOnClick()"
818            onchange="protocolOnChange()"
819            disabled="<%=lockEventProperties%>"
820          />
821        </td>
822      </tr>
823      <tr>
824        <td class="prompt">Bioplate</td>
825        <td>
826          <base:select 
827            id="bioplate_id"
828            clazz="selectionlist"
829            required="false"
830            current="<%=currentBioPlate%>"
831            denied="<%=!readCurrentBioPlate%>"
832            recent="<%=recentBioPlates%>"
833            newitem="<%=extract == null%>"
834            onselect="selectBioPlateOnClick()"
835            onchange="bioPlateOnChange()"
836            disabled="<%=lockedWell%>"
837          />
838        </td>
839      </tr>
840      <tr>
841        <td class="prompt">Biowell</td>
842        <td>
843          <base:select 
844            id="biowell_id"
845            clazz="selectionlist"
846            required="false"           
847            current="<%=null %>"
848            denied="<%=!readCurrentBioWell%>"
849            newitem="<%=extract == null%>"
850            onselect="selectBioWellOnClick()"
851            onchange="bioWellOnChange()"
852            disabled="<%=lockedWell%>"
853          />
854        </td>
855      </tr>
856      <tr valign=top>
857        <td class="prompt">Description</td>
858        <td nowrap>
859          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
860            ><%=HTML.encodeTags(extract == null ? cc.getPropertyValue("description") : extract.getDescription())%></textarea>
861          <a href="javascript:Main.zoom('Description', 'extract', 'description')"
862            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
863        </td>
864      </tr>
865      </table>
866      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
867    </t:tab>
868   
869    <t:tab id="parents" title="Parents" helpid="extract.parent">
870      <table class="form" cellspacing=0>
871      <tr>
872        <td class="prompt">Parent type</td>
873        <td>
874          <input type="radio" name="parentType" id="parentType.sample" 
875            value="SAMPLE" onclick="parentTypeOnClick()"
876            <%=parentType != Item.EXTRACT ? "checked" : ""%>
877            ><label for="parentType.sample">Sample</label>
878          <input type="radio" name="parentType" id="parentType.extract" 
879            value="EXTRACT" onclick="parentTypeOnClick()"
880            <%=parentType == Item.EXTRACT ? "checked" : ""%>
881            ><label for="parentType.extract">Extract</label>
882        </td>
883      </tr>
884      <tr valign="top">
885        <td class="prompt">Sample</td>
886        <td>
887          <base:select 
888            id="sample_id"
889            clazz="selectionlist"
890            buttonstyle="width: 150px;"
891            buttonicon="add.png"
892            buttontitle="Select sample&hellip;"
893            required="false"
894            current="<%=currentSample%>"
895            denied="<%=!readCurrentSample%>"
896            recent="<%=recentSamples%>"
897            selectrecent="false"
898            newitem="<%=extract == null%>"
899            onselect="selectSampleOnClick()"
900            onchange="sampleOnChange()"
901          />
902        </td>
903      </tr>
904      <tr>
905        <td class="subprompt">-</td>
906        <td>
907          used quantity
908          <input <%=clazz%> type="text" name="used_from_sample" value="<%=Values.formatNumber(usedFromSample, -1)%>"
909            size="12" maxlength="10" onkeypress="return Numbers.numberOnly(event)"
910            onblur="usedFromSampleOnBlur()"> (µg)
911        </td>
912      </tr>
913      <tr valign="top">
914        <td class="prompt">Extracts</td>
915        <td>
916          <table border="0" cellspacing="0" cellpadding="0">
917          <tr valign="top">
918          <td>
919            <select name="extracts" size="5" multiple class="selectionlist" 
920              onchange="extractsOnChange()">
921            </select>&nbsp;
922            <input type="hidden" name="modifiedExtracts" value="">
923            <input type="hidden" name="removedExtracts" value="">
924          </td>
925          <td>
926            <table border="0" cellspacing="0" cellpadding="0">
927            <tr><td style="padding: 1px 0px 4px 0px;"><base:button 
928              style="width: 150px;"
929              onclick="addExtractsOnClick()" 
930              title="Add&nbsp;extracts&hellip;" 
931              tooltip="Add extracts"
932              /></td></tr>
933            <tr><td width="150"><base:button 
934              style="width: 150px;"
935              onclick="removeOnClick()" 
936              title="Remove" 
937              tooltip="Remove the selected extracts"
938            /></td></tr>
939            </table>
940          </td>
941          </tr>
942          </table>
943        </td>
944      </tr>
945      <tr>
946        <td class="subprompt">-</td>
947        <td>used quantity
948        <input <%=clazz%> type="text" name="used_quantity" value=""
949              size="12" maxlength="10" onkeypress="return Numbers.numberOnly(event)"
950              onkeyup="usedQuantityOnBlur();"
951            > (µg)
952        </td>
953      </tr>         
954      </table>
955    </t:tab>
956
957    <t:tab id="annotations" title="Annotations &amp; parameters" 
958      helpid="annotations.edit" tooltip="Enter values for annotations and protocol parameters">
959      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
960        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
961        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
962    </t:tab>
963   
964    <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited">
965   
966      <iframe name="inheritedAnnotations" id="idInheritedAnnotations" 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    </t:tabcontrol>
971
972    <table align="center">
973    <tr>
974      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
975      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
976    </tr>
977    </table>
978    </form>
979  </base:body>
980  </base:page>
981  <%
982}
983finally
984{
985  if (dc != null) dc.close();
986}
987%>
Note: See TracBrowser for help on using the repository browser.