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

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

References #1655: GUI improvements

  • Use correct width/height (1050/700) of popups for selecting items from a list.
  • Got rid of the <tbl:columns> tag.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 30.8 KB
Line 
1<%-- $Id: edit_extract.jsp 5949 2012-02-08 14:35:29Z 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', 1050, 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', 1050, 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', 1050, 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', 750, 500);
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', 1050, 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', 1050, 700);
594    }
595   
596    function addExtractCallback(extractId, name)
597    {
598      var frm = document.forms['extract'];
599      var item = Link.getItem('E', extractId);
600      if (!item) item = new Item('E', extractId, name+' [-]', '', '');
601      Link.addItem(frm.extracts, item);
602      frm.parentType[0].checked = false;
603      frm.parentType[1].checked = true;
604      parentTypeOnClick();
605      parentsChanged = true;
606    }
607    function extractsOnChange()
608    {
609      var frm = document.forms['extract'];
610      var item = frm.extracts[frm.extracts.selectedIndex].item;
611      if (item && item.id)
612      {
613        frm.used_quantity.value = item.value;
614        frm.used_quantity.focus();
615      }
616      else
617      {
618        frm.used_quantity.value = '';
619      }
620    }
621    function usedQuantityOnBlur()
622    {
623      var frm = document.forms['extract'];
624      var usedQuantity = frm.used_quantity.value;
625      var displayQuantity = usedQuantity == '' ? '-' : usedQuantity+' µg';
626      for (var i = 0; i < frm.extracts.length; i++) // >
627      {
628        var option = frm.extracts[i];
629        if (option.selected && option.item.id)
630        {
631          option.item.value = usedQuantity;
632          var text = option.text.replace(/\[.*\]/, '['+displayQuantity+']');
633          option.text = text;
634        }
635      }
636    }
637    function usedFromSampleOnBlur()
638    {
639      var frm = document.forms['extract'];
640     
641      var sampleId = parseInt(frm.sample_id[frm.sample_id.selectedIndex].value);
642      if (sampleId < 0)
643      {
644        frm.sample_id[frm.sample_id.selectedIndex].value = -sampleId;
645      }
646    }
647   
648
649    function removeOnClick()
650    {
651      Link.removeSelected(document.forms['extract'].extracts);
652      parentsChanged = true;
653    }
654
655    function init()
656    {
657      <%
658      if (extract == null)
659      {
660        %>
661        var frm = document.forms['extract'];
662        frm.name.focus();
663        frm.name.select();
664        <%
665      }
666      %>
667      initBioWell();     
668      initExtracts();
669      parentTypeOnClick();
670    }
671    function initExtracts()
672    {
673      var extracts = document.forms['extract'].extracts;
674      <%
675      if (extractsQuery != null)
676      {
677        extractsQuery.include(Include.ALL);
678        extractsQuery.order(Orders.asc(Hql.property("name")));
679        ItemResultList<Extract> extracts = extractsQuery.list(dc);
680        for (Extract e : extracts)
681        {
682          if (extract != null)
683          {
684            String usedQuantity = Values.formatNumber(creationEvent.getUsedQuantity(e), -1);
685            %>
686            Link.addNewItem(extracts, new Item('E', <%=e.getId()%>, '<%=HTML.javaScriptEncode(e.getName())%> [<%=usedQuantity%> µg]', '<%=usedQuantity%>'));
687            <%
688          }
689          else
690          {
691            %>
692            Link.addItem(extracts, new Item('E', <%=e.getId()%>, '<%=HTML.javaScriptEncode(e.getName())%> [-]', '', ''));
693            <%
694           
695          }
696        }
697      }
698      %>
699    }
700    </script>
701  </base:head>
702  <base:body onload="init()">
703    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
704    <form action="index.jsp?ID=<%=ID%>" method="post" name="extract" onsubmit="return false;">
705    <input type="hidden" name="cmd" value="UpdateItem">
706
707    <t:tabcontrol id="settings"
708      subclass="content dialogtabcontrol" 
709      position="bottom"  remember="<%=extract != null%>" switch="switchTab"
710      extensions="<%=invoker%>">
711    <t:tab id="info" title="Extract" validate="validateExtract()" helpid="extract.edit">
712      <table class="fullform input100">
713      <tr>
714        <th>Name</th>
715        <td><input <%=requiredClazz%> type="text" name="name" 
716          value="<%=HTML.encodeTags(name)%>" 
717          maxlength="<%=Extract.MAX_NAME_LENGTH%>"></td>
718        <td></td>
719      </tr>
720      <tr >
721        <th>Type</th>
722        <td>
723          <select name="subtype_id"
724            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>
725            onchange="subtypeOnChange()"
726            >
727          <%
728          if (!readCurrentSubtype)
729          {
730            %>
731            <option value="-1">- denied -
732            <%
733          }
734          else
735          {
736            %>
737            <option value="0">-none-
738            <%
739            int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
740            for (ItemSubtype subtype : subtypesQuery.list(dc))
741            {
742              int id = subtype.getId();
743              if (id != currentSubtypeId && subtype.isRemoved()) continue;
744              %>
745              <option value="<%=id == currentSubtypeId && extract != null ? -id : id%>" 
746                <%=id == currentSubtypeId ? "selected" : ""%>
747                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
748                ><%=HTML.encodeTags(subtype.getName())%>
749              <%
750            }
751          }
752          %>
753          </select>
754        </td>
755        <td></td>
756      </tr>
757      <tr>
758        <th>Tag</th>
759        <td>
760          <base:select 
761            id="tag_id"
762            clazz="selectionlist"
763            required="false"
764            current="<%=currentTag%>"
765            denied="<%=!readCurrentTag%>"
766            recent="<%=recentTags%>"
767            newitem="<%=extract == null%>"
768            onselect="selectTagOnClick()"
769          />
770        </td>
771        <td></td>
772      </tr>
773      <tr>
774        <th>External ID</th>
775        <td><input <%=clazz%> type="text" name="external_id" 
776          value="<%=HTML.encodeTags(extract == null ? Values.getString(cc.getPropertyValue("externalId"), "") : extract.getExternalId())%>" 
777          maxlength="<%=Extract.MAX_EXTERNAL_ID_LENGTH%>"></td>
778        <td></td>
779      </tr>
780      <tr>
781        <th>Original quantity</th>
782        <td><input <%=clazz%> type="text" name="original_quantity" style="width: 15em;"
783          value="<%=Values.formatNumber(extract == null ? Values.getFloat(cc.getPropertyValue("originalQuantity"), null): extract.getOriginalQuantity(), -1)%>"
784          maxlength="10" onkeypress="return Numbers.numberOnly(event)"> (µg)</td>
785        <td></td>
786      </tr>
787      <tr>
788        <th>Created</th>
789        <td>
790          <table>
791          <tr>
792          <td>
793            <input <%=clazz%> style="width: 15em;" type="text" name="event_date" <%=lockEventProperties ? "disabled" : ""%>
794              value="<%=HTML.encodeTags(dateFormatter.format(eventDate))%>" 
795               maxlength="20" title="Enter date in format: <%=htmlDateFormat%>">
796          </td>
797          <td>
798          <base:button 
799            onclick="<%="Dates.selectDate('Created', 'extract', 'event_date', null, '"+jsDateFormat+"')"%>"
800            image="calendar.png" 
801            title="Calendar&hellip;" 
802            tooltip="Select a date from a calendar" 
803            disabled="<%=lockEventProperties%>"
804          />
805          </td>
806          </tr>
807          </table>
808        </td>
809        <td></td>
810      </tr>
811      <tr>
812        <th>Registered</th>
813        <td><%=dateFormatter.format(creationEvent == null ? new Date() : creationEvent.getEntryDate())%></td>
814        <td></td>
815      </tr>
816      <tr>
817        <th>Protocol</th>
818        <td>
819          <base:select 
820            id="protocol_id"
821            clazz="selectionlist"
822            required="false"
823            current="<%=currentProtocol%>"
824            denied="<%=!readCurrentProtocol%>"
825            recent="<%=recentProtocols%>"
826            defaultitems="<%=defaultProtocols%>"
827            newitem="<%=extract == null%>"
828            onselect="selectProtocolOnClick()"
829            onchange="protocolOnChange()"
830            disabled="<%=lockEventProperties%>"
831          />
832        </td>
833        <td></td>
834      </tr>
835      <tr>
836        <th>Bioplate</th>
837        <td>
838          <base:select 
839            id="bioplate_id"
840            clazz="selectionlist"
841            required="false"
842            current="<%=currentBioPlate%>"
843            denied="<%=!readCurrentBioPlate%>"
844            recent="<%=recentBioPlates%>"
845            newitem="<%=extract == null%>"
846            onselect="selectBioPlateOnClick()"
847            onchange="bioPlateOnChange()"
848            disabled="<%=lockedWell%>"
849          />
850        </td>
851        <td></td>
852      </tr>
853      <tr>
854        <th class="subprompt">- well</th>
855        <td>
856          <base:select 
857            id="biowell_id"
858            clazz="selectionlist"
859            required="false"           
860            current="<%=null %>"
861            denied="<%=!readCurrentBioWell%>"
862            newitem="<%=extract == null%>"
863            onselect="selectBioWellOnClick()"
864            onchange="bioWellOnChange()"
865            disabled="<%=lockedWell%>"
866          />
867        </td>
868        <td></td>
869      </tr>
870      <tr class="dynamic">
871        <th>Description</th>
872        <td>
873          <textarea <%=clazz%> rows="6" name="description" 
874            ><%=HTML.encodeTags(extract == null ? cc.getPropertyValue("description") : extract.getDescription())%></textarea>
875        </td>
876        <td style="width: 20px;">
877          <base:icon image="zoom.png" 
878            onclick="Main.zoom('Description', 'extract', 'description')"
879            tooltip="Edit in larger window"
880          />
881        </td>
882      </tr>
883      </table>
884    </t:tab>
885   
886    <t:tab id="parents" title="Parents" helpid="extract.parents">
887      <table class="fullform input100">
888      <tr>
889        <th>Parent type</th>
890        <td>
891          <input type="radio" name="parentType" id="parentType.sample" 
892            value="SAMPLE" onclick="parentTypeOnClick()"
893            <%=parentType != Item.EXTRACT ? "checked" : ""%>
894            ><label for="parentType.sample">Sample</label>
895          <input type="radio" name="parentType" id="parentType.extract" 
896            value="EXTRACT" onclick="parentTypeOnClick()"
897            <%=parentType == Item.EXTRACT ? "checked" : ""%>
898            ><label for="parentType.extract">Extract</label>
899        </td>
900      </tr>
901      <tr>
902        <th>Sample</th>
903        <td>
904          <base:select 
905            id="sample_id"
906            clazz="selectionlist"
907            buttonstyle="width: 12em;"
908            buttonicon="add.png"
909            buttontitle="Select sample&hellip;"
910            buttonclass="leftaligned basicbutton"
911            required="false"
912            current="<%=currentSample%>"
913            denied="<%=!readCurrentSample%>"
914            recent="<%=recentSamples%>"
915            selectrecent="false"
916            newitem="<%=extract == null%>"
917            onselect="selectSampleOnClick()"
918            onchange="sampleOnChange()"
919          />
920        </td>
921      </tr>
922      <tr>
923        <th class="subprompt">used quantity</td>
924        <td>
925          <input <%=clazz%> style="width: 15em;" type="text" name="used_from_sample" 
926            value="<%=Values.formatNumber(usedFromSample, -1)%>"
927            maxlength="10" onkeypress="return Numbers.numberOnly(event)"
928            onblur="usedFromSampleOnBlur()"> (µg)
929        </td>
930      </tr>
931      <tr class="big">
932        <th>Extracts</td>
933        <td>
934          <div class="selectionlist">
935          <table>
936          <tr>
937          <td>
938            <select name="extracts" size="12" multiple onchange="extractsOnChange()">
939            </select>
940          </td>
941          <td>
942          <td style="vertical-align: top;">
943            <base:buttongroup vertical="true">
944              <base:button 
945                subclass="leftaligned"
946                style="width: 12em;"
947                onclick="addExtractsOnClick()" 
948                title="Add&nbsp;extracts&hellip;" 
949                tooltip="Add extracts"
950              />
951              <base:button 
952                subclass="leftaligned"
953                style="width: 12em;"
954                onclick="removeOnClick()" 
955                title="Remove" 
956                tooltip="Remove the selected extracts"
957              />
958            </base:buttongroup>
959            <input type="hidden" name="modifiedExtracts" value="">
960            <input type="hidden" name="removedExtracts" value="">
961          </td>
962          </tr>
963          </table>
964          </div>
965        </td>
966      </tr>
967      <tr>
968        <th class="subprompt">used quantity</th>
969        <td>
970          <input <%=clazz%> style="width: 15em;" type="text" name="used_quantity" 
971              value=""
972              maxlength="10" onkeypress="return Numbers.numberOnly(event)"
973              onkeyup="usedQuantityOnBlur();"
974            > (µg)
975        </td>
976      </tr>         
977      <tr class="dynamic">
978        <th></th>
979        <td></td>
980      </tr>
981      </table>
982    </t:tab>
983
984    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit"><iframe 
985      name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
986      style="width: 100%; height: 100%;"></iframe></t:tab>
987   
988    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
989      helpid="annotations.edit.inherited"><iframe 
990        name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
991        style="width: 100%; height: 100%;"></iframe></t:tab>
992    </t:tabcontrol>
993    </form>
994
995    <div class="legend">
996      <base:icon image="required.png" />= required information
997    </div>
998
999    <base:buttongroup subclass="dialogbuttons">
1000      <base:button onclick="saveSettings()" title="Save" />
1001      <base:button onclick="window.close()" title="Cancel" />
1002    </base:buttongroup>
1003  </base:body>
1004  </base:page>
1005  <%
1006}
1007finally
1008{
1009  if (dc != null) dc.close();
1010}
1011%>
Note: See TracBrowser for help on using the repository browser.