source: trunk/www/views/rawbioassays/edit_rawbioassay.jsp @ 6314

Last change on this file since 6314 was 6314, checked in by Nicklas Nordborg, 10 years ago

References #1729 and #1730. Several edit dialogs in the 'View' menu. Expression builder, which required changes to the 'Validate' function which is now done on the server side instead of in the browser (due to the use of eval() on user input).

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 18.6 KB
Line 
1<%-- $Id: edit_rawbioassay.jsp 6314 2013-09-02 12:47:53Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5  Copyright (C) 2007 Nicklas Nordborg
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 3
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with BASE. If not, see <http://www.gnu.org/licenses/>.
22  ------------------------------------------------------------------
23
24
25  @author Nicklas
26  @version 2.0
27--%>
28<%@ page pageEncoding="UTF-8" session="false"
29  import="net.sf.basedb.core.SessionControl"
30  import="net.sf.basedb.core.DbControl"
31  import="net.sf.basedb.core.Item"
32  import="net.sf.basedb.core.ItemContext"
33  import="net.sf.basedb.core.SystemItems"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.RawBioAssay"
36  import="net.sf.basedb.core.Platform"
37  import="net.sf.basedb.core.PlatformVariant"
38  import="net.sf.basedb.core.Protocol"
39  import="net.sf.basedb.core.Project"
40  import="net.sf.basedb.core.Software"
41  import="net.sf.basedb.core.ArrayDesign"
42  import="net.sf.basedb.core.Extract"
43  import="net.sf.basedb.core.DerivedBioAssay"
44  import="net.sf.basedb.core.ItemSubtype"
45  import="net.sf.basedb.core.File"
46  import="net.sf.basedb.core.RawDataType"
47  import="net.sf.basedb.core.RawDataTypes"
48  import="net.sf.basedb.core.ItemQuery"
49  import="net.sf.basedb.core.ItemResultList"
50  import="net.sf.basedb.core.PermissionDeniedException"
51  import="net.sf.basedb.core.BaseException"
52  import="net.sf.basedb.core.query.Orders"
53  import="net.sf.basedb.core.query.Hql"
54  import="net.sf.basedb.core.query.Restrictions"
55  import="net.sf.basedb.clients.web.Base"
56  import="net.sf.basedb.clients.web.util.HTML"
57  import="net.sf.basedb.util.Values"
58  import="net.sf.basedb.core.Include"
59  import="net.sf.basedb.core.plugin.GuiContext"
60  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
61  import="net.sf.basedb.clients.web.extensions.JspContext"
62  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
63  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
64  import="java.util.List"
65  import="java.util.Set"
66  import="java.util.HashSet"
67%>
68<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
69<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
70<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
71<%
72final Item itemType = Item.RAWBIOASSAY;
73final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
74final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
75final String tabId = Values.getString(request.getParameter("tab"), null);
76final int itemId = cc.getId();
77final String ID = sc.getId();
78final float scale = Base.getScale(sc);
79final DbControl dc = sc.newDbControl();
80try
81{
82  String title = null;
83  RawBioAssay rawBioAssay = null;
84  String name = null;
85  boolean hasDbSpots = false;
86
87  boolean deniedPlatform = false;
88  Platform currentPlatform = null;
89  List<Platform> defaultPlatforms = null;
90  PlatformVariant currentVariant = null;
91  List<PlatformVariant> defaultVariants = null;
92 
93  boolean readCurrentBioAssay = true;
94  DerivedBioAssay currentBioAssay = null;
95  boolean readCurrentExtract = true;
96  Extract currentExtract = null;
97  boolean readCurrentProtocol = true;
98  Protocol currentProtocol = null;
99  List<Protocol> defaultProtocols = null;
100  boolean readCurrentSoftware = true;
101  Software currentSoftware = null;
102  List<Software> defaultSoftware = null;
103  boolean readCurrentArrayDesign = true;
104  ArrayDesign currentArrayDesign = null;
105  List<ArrayDesign> defaultArrayDesigns = null;
106  RawDataType currentRawDataType = null;
107  RawDataType defaultRawDataType = null;
108
109  // Load recently used items
110  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL);
111  List<Software> recentSoftware = (List<Software>)cc.getRecent(dc, Item.SOFTWARE);
112  List<ArrayDesign> recentArrayDesigns = (List<ArrayDesign>)cc.getRecent(dc, Item.ARRAYDESIGN);
113  List<File> recentFiles = (List<File>)cc.getRecent(dc, Item.FILE);
114  List<DerivedBioAssay> recentBioAssays = (List<DerivedBioAssay>)cc.getRecent(dc, Item.DERIVEDBIOASSAY);
115  List<Extract> recentExtracts = (List<Extract>)cc.getRecent(dc, Item.EXTRACT);
116 
117  int activeProjectId = sc.getActiveProjectId();
118  if (activeProjectId > 0)
119  {
120    Project activeProject = Project.getById(dc, activeProjectId);
121    try
122    {
123      defaultProtocols = (List<Protocol>)activeProject.findDefaultItems(dc, 
124          ItemSubtype.getById(dc, SystemItems.getId(Protocol.FEATURE_EXTRACTION)), false);
125    }
126    catch (PermissionDeniedException pdex)
127    {}
128    try
129    {
130      defaultSoftware = (List<Software>)activeProject.findDefaultItems(dc, 
131          ItemSubtype.getById(dc, SystemItems.getId(Software.FEATURE_EXTRACTION)), false);
132    }
133    catch (PermissionDeniedException pdex)
134    {}
135    try
136    {
137      defaultArrayDesigns = (List<ArrayDesign>)activeProject.findDefaultItems(dc, Item.ARRAYDESIGN, true);
138    }
139    catch (PermissionDeniedException pdex)
140    {}
141    try
142    {
143      defaultPlatforms = (List<Platform>)activeProject.findDefaultItems(dc, Item.PLATFORM, true);
144    }
145    catch (PermissionDeniedException pdex)
146    {}
147    try
148    {
149      defaultVariants = (List<PlatformVariant>)activeProject.findDefaultItems(dc, Item.PLATFORMVARIANT, true);
150    }
151    catch (PermissionDeniedException pdex)
152    {}
153    defaultRawDataType = activeProject.getDefaultRawDataType();
154  }
155  if (itemId == 0)
156  {
157    title = "Create raw bioassay";
158    cc.removeObject("item");
159   
160    int currentPlatformId = Values.getInt(cc.getPropertyValue("platform"), 0);
161    if (currentPlatformId == 0)
162    {
163      currentPlatformId = Values.getInt(cc.getRecent(Item.PLATFORM.name(), 0), 0);
164    }
165    int currentVariantId = Values.getInt(cc.getRecent(Item.PLATFORMVARIANT.name(), 0), 0);
166   
167    try
168    {
169      if (currentVariantId != 0) currentVariant = PlatformVariant.getById(dc, currentVariantId);
170      if (currentPlatformId != 0) currentPlatform = Platform.getById(dc, currentPlatformId);
171    }
172    catch (Throwable t)
173    {}
174    if (currentPlatform == null && defaultPlatforms != null && defaultPlatforms.size() > 0) 
175    {
176      currentPlatform = defaultPlatforms.get(0);
177    }
178    if (currentVariant == null && defaultVariants != null && defaultVariants.size() > 0)
179    {
180      currentVariant = defaultVariants.get(0);
181    }
182   
183    currentRawDataType = RawDataTypes.getRawDataType(cc.getPropertyValue("rawDataType"));
184    if (currentRawDataType == null)
185    {
186      currentRawDataType = RawDataTypes.getRawDataType(cc.getRecent("RawDataType", 0));
187    }
188    if (currentRawDataType == null) currentRawDataType = defaultRawDataType;
189
190   
191    int bioAssayId = Values.getInt(request.getParameter("bioassay_id"));
192    if (bioAssayId != 0)
193    {
194      currentBioAssay = DerivedBioAssay.getById(dc, bioAssayId);
195    }
196    else if (cc.getPropertyFilter("parentBioAssay.name") != null)
197    {
198      currentBioAssay = Base.getFirstMatching(dc, DerivedBioAssay.getQuery(), "name", cc.getPropertyFilter("parentBioAssay.name"));
199    }
200   
201    int extractId = Values.getInt(request.getParameter("extract_id"));
202    if (extractId != 0)
203    {
204      currentExtract = Extract.getById(dc, extractId);
205    }
206    else if (cc.getPropertyFilter("parentExtract.name") != null)
207    {
208      currentExtract = Base.getFirstMatching(dc, Extract.getQuery(), "name", cc.getPropertyFilter("parentExtract.name"));
209    }
210
211    if (currentBioAssay != null)
212    {
213      name = currentBioAssay.getName() + ".r" + (currentBioAssay.countRawBioAssays() + 1);
214    }
215    else
216    {
217      name = Values.getString(cc.getPropertyValue("name"), "New raw bioassay");
218    }
219
220    if (cc.getPropertyFilter("protocol.name") != null)
221    {
222      currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("protocol.name"));
223    }
224   
225    if (cc.getPropertyFilter("software.name") != null)
226    {
227      currentSoftware = Base.getFirstMatching(dc, Software.getQuery(), "name", cc.getPropertyFilter("software.name"));
228    }
229
230    if (currentBioAssay != null)
231    {
232      try
233      {
234        currentArrayDesign = currentBioAssay.getArrayDesign();
235      }
236      catch (PermissionDeniedException ex)
237      {}
238      try
239      {
240        currentExtract = currentBioAssay.getExtract();
241      }
242      catch (PermissionDeniedException ex)
243      {}
244    }
245    if (currentArrayDesign == null && cc.getPropertyFilter("arrayDesign.name") != null)
246    {
247      currentArrayDesign = Base.getFirstMatching(dc, ArrayDesign.getQuery(), "name", cc.getPropertyFilter("arrayDesign.name"));
248    }
249  }
250  else
251  {
252    rawBioAssay = RawBioAssay.getById(dc, itemId);
253    rawBioAssay.checkPermission(Permission.WRITE);
254    hasDbSpots = rawBioAssay.getNumDbSpots() > 0;
255    cc.setObject("item", rawBioAssay);
256    name = rawBioAssay.getName();
257    try
258    {
259      currentRawDataType = rawBioAssay.getRawDataType();
260    }
261    catch (Throwable t)
262    {}
263    title = "Edit raw bioassay -- " + HTML.encodeTags(rawBioAssay.getName());
264   
265    try
266    {
267      currentPlatform = rawBioAssay.getPlatform();
268      currentVariant = rawBioAssay.getVariant();
269    }
270    catch (PermissionDeniedException ex)
271    {
272      deniedPlatform = true;
273    }
274   
275    try
276    {
277      currentBioAssay = rawBioAssay.getParentBioAssay();
278    }
279    catch (PermissionDeniedException ex)
280    {
281      readCurrentBioAssay = false;
282    }
283    try
284    {
285      currentExtract = rawBioAssay.getParentExtract();
286    }
287    catch (PermissionDeniedException ex)
288    {
289      readCurrentExtract = false;
290    }
291    try
292    {
293      currentProtocol = rawBioAssay.getProtocol();
294    }
295    catch (PermissionDeniedException ex)
296    {
297      readCurrentProtocol = false;
298    }
299    try
300    {
301      currentSoftware = rawBioAssay.getSoftware();
302    }
303    catch (PermissionDeniedException ex)
304    {
305      readCurrentSoftware = false;
306    }
307    try
308    {
309      currentArrayDesign = rawBioAssay.getArrayDesign();
310    }
311    catch (PermissionDeniedException ex)
312    {
313      readCurrentArrayDesign = false;
314    }
315  }
316 
317  ItemQuery<Platform> platformQuery = Platform.getQuery();
318  platformQuery.include(Include.REMOVED, Include.NOT_REMOVED);
319  platformQuery.order(Orders.asc(Hql.property("name")));
320  platformQuery.setCacheResult(true);
321  ItemResultList<Platform> platforms = platformQuery.list(dc);
322
323  ItemQuery<PlatformVariant> variantQuery = PlatformVariant.getQuery();
324  variantQuery.include(Include.REMOVED, Include.NOT_REMOVED);
325  variantQuery.order(Orders.asc(Hql.property("name")));
326  variantQuery.restrict(Restrictions.eq(Hql.property("platform"), Hql.entityParameter("platform", Item.PLATFORM)));
327 
328  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), rawBioAssay);
329  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
330  %>
331  <base:page type="popup" title="<%=title%>" id="edit-page">
332  <base:head scripts="tabcontrol-2.js,~bioassays.js" styles="tabcontrol.css">
333    <ext:scripts context="<%=jspContext%>" />
334    <ext:stylesheets context="<%=jspContext%>" />
335    <style>
336    .platform
337    {
338      font-weight: bold;
339      margin-top: 2px;
340    }
341    </style>
342  </base:head>
343  <base:body>
344    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
345    <div id="page-data" class="datacontainer"
346      data-has-db-spots="<%=hasDbSpots ? 1 : 0 %>"
347      data-feature-extraction-protocol="<%=SystemItems.getId(Protocol.FEATURE_EXTRACTION)%>"
348      data-feature-extraction-software="<%=SystemItems.getId(Software.FEATURE_EXTRACTION)%>"
349    ></div>
350    <form action="index.jsp?ID=<%=ID%>" method="post" name="rawbioassay">
351    <input type="hidden" name="cmd" value="UpdateItem">
352
353    <t:tabcontrol id="settings" 
354      subclass="content dialogtabcontrol"
355      position="bottom" active="<%=tabId%>" 
356      remember="<%=tabId == null && rawBioAssay != null%>" 
357      extensions="<%=invoker%>">
358    <t:tab id="info" title="Raw bioassay" helpid="rawbioassay.edit">
359      <table class="fullform input100">
360      <tr>
361        <th>Name</th>
362        <td><input class="text required auto-init" data-auto-init="<%=rawBioAssay == null ? "focus-select" : "focus" %>" 
363          type="text" name="name" 
364          value="<%=HTML.encodeTags(name)%>" 
365          maxlength="<%=RawBioAssay.MAX_NAME_LENGTH%>"></td>
366        <td></td>
367      </tr>
368      <tr>
369        <th>Platform</th>
370        <td>
371          <select name="platform" id="platform" class="required"
372            <%=deniedPlatform || hasDbSpots ? "disabled" : "" %>>
373          <%
374          if (deniedPlatform)
375          {
376            %>
377            <option value="-1">- denied -
378            <%
379          }
380          else
381          {
382            for (Platform p : platforms)
383            {
384              if (!p.isRemoved() || p.equals(currentPlatform))
385              {
386                boolean selected = p.equals(currentPlatform) && currentVariant == null;
387                RawDataType rdt = p.isFileOnly() ? null : p.getRawDataType();
388                %>
389                <option class="platform"
390                  value="PLATFORM:<%=p.getId()%>"
391                  data-platform="<%=p.getId()%>"
392                  data-file-only="<%=p.isFileOnly() ? 1 : 0 %>"
393                  data-raw-data-type="<%=rdt == null ? "" : rdt.getId() %>"
394                  <%=selected ? "selected" : ""%>><%=HTML.encodeTags(p.getName()) %>
395                <%
396              }
397              variantQuery.setEntityParameter("platform", p);
398              List<PlatformVariant> variants = variantQuery.list(dc);
399              PlatformVariant lastVariant = variants.size()>0 ? variants.get(variants.size()-1) : null;
400              for (PlatformVariant v : variants)
401              {
402                if ((!v.isRemoved() || v.equals(currentVariant)) && (!p.isRemoved() || p.equals(currentPlatform)))
403                {
404                  boolean selected = v.equals(currentVariant);
405                  RawDataType rdt = v.isFileOnly() ? null : v.getRawDataType();
406                  String prefix = v == lastVariant ? " └ " : " ├ ";
407                  %>
408                  <option class="variant"
409                    value="VARIANT:<%=v.getId()%>"
410                    data-platform="<%=p.getId()%>"
411                    data-variant="<%=v.getId()%>"
412                    data-file-only="<%=v.isFileOnly() ? 1 : 0 %>"
413                    data-raw-data-type="<%=rdt == null ? "" : rdt.getId() %>"
414                    <%=selected ? "selected" : ""%>><%=prefix%><%=HTML.encodeTags(v.getName()) %>
415                  <%
416                }
417              }
418            }
419          }
420          %>
421          </select>
422        </td>
423        <td></td>
424      </tr>
425      <tr>
426        <th>Raw data type</th>
427        <td>
428          <select name="rawdatatype" class="required"
429            <%=hasDbSpots ? "disabled" : "" %>>
430          <%
431          for (RawDataType rdt : RawDataTypes.getSortedRawDataTypes(new RawDataTypes.NameComparator()))
432          {
433            if (rdt.isStoredInDb())
434            {
435              String selected = rdt.equals(currentRawDataType) ? "selected" : "";
436              %>
437              <option value="<%=rdt.getId()%>" <%=selected%>><%=HTML.encodeTags(rdt.getName())%>
438              <%
439            }
440          }
441          %>
442          </select>
443        </td>
444        <td></td>
445      </tr>
446      <tr>
447        <th>Parent bioassay</th>
448        <td>
449          <base:select 
450            id="bioassay_id"
451            clazz="selectionlist"
452            required="false"
453            current="<%=currentBioAssay%>"
454            denied="<%=!readCurrentBioAssay%>"
455            recent="<%=recentBioAssays%>"
456            newitem="<%=rawBioAssay == null%>"
457            selectrecent="<%=currentExtract == null %>"
458          />
459        </td>
460        <td></td>
461      </tr>
462      <tr>
463        <th>Parent extract</th>
464        <td>
465          <base:select 
466            id="extract_id"
467            clazz="selectionlist"
468            required="false"
469            current="<%=currentExtract%>"
470            denied="<%=!readCurrentExtract%>"
471            recent="<%=recentExtracts%>"
472            newitem="<%=rawBioAssay == null%>"
473            selectrecent="false"
474          />
475        </td>
476        <td></td>
477      </tr>
478      <tr>
479        <th>Array design</th>
480        <td>
481          <base:select 
482            id="arraydesign_id"
483            clazz="selectionlist"
484            required="false"
485            current="<%=currentArrayDesign%>"
486            data-current-array-design="<%=currentArrayDesign == null ? "" : currentArrayDesign.getId() %>"
487            denied="<%=!readCurrentArrayDesign%>"
488            recent="<%=recentArrayDesigns%>"
489            defaultitems="<%=defaultArrayDesigns%>"
490            newitem="<%=rawBioAssay == null%>"
491          />
492        </td>
493        <td></td>
494      </tr>
495      <tr id="fiMethod" style="display: none;">
496        <th></th>
497        <td>
498        <select name="fiMethod">
499        <option value="">-auto- (array design decides)
500        <option value="COORDINATES">Coordinates
501        <option value="POSITION">Position
502        <option value="FEATURE_ID">Feature ID (*)
503        </select>
504        <div class="messagecontainer help">
505        Select a method for feature identification. <br>
506        (*) The Feature ID method only works if the raw data is currently
507        connected to an array design which has Feature ID values.
508        </div>
509        </td>
510        <td></td>
511      </tr>
512      <tr>
513        <th>Protocol</th>
514        <td>
515          <base:select 
516            id="protocol_id"
517            clazz="selectionlist"
518            required="false"
519            current="<%=currentProtocol%>"
520            denied="<%=!readCurrentProtocol%>"
521            recent="<%=recentProtocols%>"
522            defaultitems="<%=defaultProtocols%>"
523            newitem="<%=rawBioAssay == null%>"
524          />
525        </td>
526        <td></td>
527      </tr>
528      <tr>
529        <th>Software</th>
530        <td>
531          <base:select 
532            id="software_id"
533            clazz="selectionlist"
534            required="false"
535            current="<%=currentSoftware%>"
536            denied="<%=!readCurrentSoftware%>"
537            recent="<%=recentSoftware%>"
538            defaultitems="<%=defaultSoftware%>"
539            newitem="<%=rawBioAssay == null%>"
540          />
541        </td>
542        <td></td>
543      </tr>
544      <tr class="dynamic">
545        <th>Description</th>
546        <td>
547          <textarea class="text" rows="6" name="description" id="description"
548            ><%=HTML.encodeTags(rawBioAssay == null ? cc.getPropertyValue("description") : rawBioAssay.getDescription())%></textarea>
549        </td>
550        <td style="width: 20px;">
551          <base:zoom textarea="description" title="Description" />
552        </td>
553      </tr>
554      </table>
555    </t:tab>
556   
557    <t:tab id="datafiles" title="Data files" helpid="datafiles.edit">
558      <jsp:include page="../../common/datafiles/select_frameset.jsp">
559        <jsp:param name="item_type" value="<%=itemType.name()%>" />
560        <jsp:param name="item_id" value="<%=itemId%>" />
561        <jsp:param name="ID" value="<%=ID%>" />
562      </jsp:include>
563    </t:tab>
564
565    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit">
566      <jsp:include page="../../common/annotations/annotate_frameset.jsp">
567        <jsp:param name="item_type" value="<%=itemType.name()%>" />
568        <jsp:param name="item_id" value="<%=itemId%>" />
569        <jsp:param name="ID" value="<%=ID%>" />
570      </jsp:include>
571    </t:tab>
572   
573    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
574      helpid="annotations.edit.inherited">
575      <jsp:include page="../../common/annotations/inherit_frameset.jsp">
576        <jsp:param name="item_type" value="<%=itemType.name()%>" />
577        <jsp:param name="item_id" value="<%=itemId%>" />
578        <jsp:param name="ID" value="<%=ID%>" />
579      </jsp:include>
580    </t:tab>
581    </t:tabcontrol>
582    </form>
583
584    <div class="legend">
585      <base:icon image="required.png" />= required information
586    </div>
587
588    <base:buttongroup subclass="dialogbuttons">
589      <base:button id="btnSave" title="Save" />
590      <base:button id="close" title="Cancel" />
591    </base:buttongroup>
592  </base:body>
593  </base:page>
594  <%
595}
596finally
597{
598  if (dc != null) dc.close();
599}
600%>
Note: See TracBrowser for help on using the repository browser.