source: trunk/www/views/derivedbioassays/edit_bioassay.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: 17.6 KB
Line 
1<%-- $Id $
2  ------------------------------------------------------------------
3  Copyright (C) 2011 Nicklas Nordborg
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 3
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with BASE. If not, see <http://www.gnu.org/licenses/>.
20  ------------------------------------------------------------------
21--%>
22<%@ page pageEncoding="UTF-8" session="false"
23  import="net.sf.basedb.core.SessionControl"
24  import="net.sf.basedb.core.DbControl"
25  import="net.sf.basedb.core.DerivedBioAssay"
26  import="net.sf.basedb.core.PhysicalBioAssay"
27  import="net.sf.basedb.core.Extract"
28  import="net.sf.basedb.core.ItemSubtype"
29  import="net.sf.basedb.core.Protocol"
30  import="net.sf.basedb.core.Hardware"
31  import="net.sf.basedb.core.Software"
32  import="net.sf.basedb.core.Project"
33  import="net.sf.basedb.core.Item"
34  import="net.sf.basedb.core.ItemContext"
35  import="net.sf.basedb.core.Permission"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.ItemResultList"
38  import="net.sf.basedb.core.Include"
39  import="net.sf.basedb.core.Type"
40  import="net.sf.basedb.core.query.Expressions"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.query.Hql"
43  import="net.sf.basedb.core.query.Restrictions"
44  import="net.sf.basedb.core.PermissionDeniedException"
45  import="net.sf.basedb.core.BaseException"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.util.HTML"
48  import="net.sf.basedb.util.Values"
49  import="net.sf.basedb.util.ListUtil"
50  import="net.sf.basedb.core.plugin.GuiContext"
51  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
52  import="net.sf.basedb.clients.web.extensions.JspContext"
53  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
54  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
55  import="net.sf.basedb.util.json.JsonUtil"
56  import="net.sf.basedb.util.json.NameableConverter"
57  import="org.json.simple.JSONObject"
58  import="java.util.Date"
59  import="java.util.List"
60  import="java.util.Collections"
61%>
62<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
63<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
64<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
65<%
66final Item itemType = Item.DERIVEDBIOASSAY;
67final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
68final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
69final String tabId = Values.getString(request.getParameter("tab"), null);
70final int itemId = cc.getId();
71final String ID = sc.getId();
72final float scale = Base.getScale(sc);
73final DbControl dc = sc.newDbControl();
74try
75{
76  DerivedBioAssay bioAssay = null;
77  String title = null;
78 
79  boolean readCurrentSubtype = true;
80  ItemSubtype currentSubtype = null;
81
82  boolean readCurrentExtract = true;
83  Extract currentExtract = null;
84
85  boolean readCurrentProtocol = true;
86  Protocol currentProtocol = null;
87 
88  boolean readCurrentHardware = true;
89  Hardware currentHardware = null;
90 
91  boolean readCurrentSoftware = true;
92  Software currentSoftware = null;
93
94  ItemQuery<PhysicalBioAssay> physicalQuery = null;
95  ItemQuery<DerivedBioAssay> parentQuery = null;
96 
97  Item parentType = null;
98 
99  if (itemId == 0)
100  {
101    title = "New derived bioassay";
102    cc.removeObject("item");
103    int parentId = Values.getInt(request.getParameter("parent_id"));
104    int physicalBioAssayId = Values.getInt(request.getParameter("physicalbioassay_id"));
105    int currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
106    List<ItemSubtype> relatedToParent = Collections.emptyList();
107   
108    if (parentId != 0)
109    {
110      parentType = Item.DERIVEDBIOASSAY;
111      DerivedBioAssay dba = DerivedBioAssay.getById(dc, parentId);
112      parentQuery = DerivedBioAssay.getQuery();
113      parentQuery.restrict(Restrictions.eq(Hql.property("id"), Expressions.integer(parentId)));
114      if (currentSubtypeId == 0)
115      {
116        relatedToParent = ItemSubtype.getParentSubtypes(dc, dba, Item.DERIVEDBIOASSAY);
117      }
118    }
119    else if (physicalBioAssayId != 0)
120    {
121      parentType = Item.PHYSICALBIOASSAY;
122      PhysicalBioAssay pba = PhysicalBioAssay.getById(dc, physicalBioAssayId);
123      physicalQuery = PhysicalBioAssay.getQuery();
124      physicalQuery.restrict(Restrictions.eq(Hql.property("id"), Expressions.integer(physicalBioAssayId)));
125      if (currentSubtypeId == 0)
126      {
127        relatedToParent = ItemSubtype.getParentSubtypes(dc, pba, Item.DERIVEDBIOASSAY);
128      }
129    }
130    else if ("PHYISCALBIOASSAY".equals(request.getParameter("useParents")))
131    {
132      parentType = Item.PHYSICALBIOASSAY;
133      physicalQuery = PhysicalBioAssay.getQuery();
134      physicalQuery.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("selected")));
135      physicalQuery.setParameter("selected", sc.getCurrentContext(Item.PHYSICALBIOASSAY).getSelected(), Type.INT);
136    }
137    else if ("DERIVEDBIOASSAY".equals(request.getParameter("useParents")))
138    {
139      parentType = Item.DERIVEDBIOASSAY;
140      parentQuery = DerivedBioAssay.getQuery();
141      parentQuery.restrict(Restrictions.in(Hql.property("id"), Expressions.parameter("selected")));
142      parentQuery.setParameter("selected", cc.getSelected(), Type.INT);
143    }
144
145    if (currentSubtypeId == 0) 
146    {
147      if (relatedToParent.size() > 0)
148      {
149        // Find most recently used related subtype
150        List<ItemSubtype> recentSubtypes = (List<ItemSubtype>)cc.getRecent(dc, Item.ITEMSUBTYPE);
151        currentSubtype = ListUtil.findFirstCommon(recentSubtypes, relatedToParent, relatedToParent.get(0));
152      }
153      else
154      {
155        int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
156        currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);
157        if (currentSubtypeId > 0) currentSubtype = ItemSubtype.getById(dc, currentSubtypeId);
158      }
159    }
160  }
161  else
162  {
163    bioAssay = DerivedBioAssay.getById(dc, itemId);
164    bioAssay.checkPermission(Permission.WRITE);
165    cc.setObject("item", bioAssay);
166    title = "Edit bioassay -- " + HTML.encodeTags(bioAssay.getName());
167   
168    if (bioAssay.isRoot())
169    {
170      physicalQuery = bioAssay.getPhysicalBioAssays();
171      parentType = Item.PHYSICALBIOASSAY;
172    }
173    else
174    {
175      parentQuery = bioAssay.getParents();
176      parentType = Item.DERIVEDBIOASSAY;
177    }
178   
179    try
180    {
181      currentSubtype = bioAssay.getItemSubtype();
182    }
183    catch (PermissionDeniedException ex)
184    {
185      readCurrentSubtype = false;
186    }
187    try
188    {
189      currentExtract = bioAssay.getExtract();
190    }
191    catch (PermissionDeniedException ex)
192    {
193      readCurrentExtract = false;
194    }
195    try
196    {
197      currentProtocol = bioAssay.getProtocol();
198    }
199    catch (PermissionDeniedException ex)
200    {
201      readCurrentProtocol = false;
202    }
203    try
204    {
205      currentHardware = bioAssay.getHardware();
206    }
207    catch (PermissionDeniedException ex)
208    {
209      readCurrentHardware = false;
210    }
211    try
212    {
213      currentSoftware = bioAssay.getSoftware();
214    }
215    catch (PermissionDeniedException ex)
216    {
217      readCurrentSoftware = false;
218    }
219  }
220
221  // Default items
222  int activeProjectId = sc.getActiveProjectId();
223  List<Protocol> defaultProtocols = null;
224  List<Hardware> defaultHardware = null;
225  List<Software> defaultSoftware = null;
226  if (activeProjectId > 0)
227  {
228    Project activeProject = Project.getById(dc, activeProjectId);
229    defaultProtocols = (List<Protocol>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.PROTOCOL);
230    defaultHardware = (List<Hardware>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.HARDWARE);
231    defaultSoftware = (List<Software>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.SOFTWARE);
232  }
233
234  // Load recently used items
235  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL, currentSubtype);
236  List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE, currentSubtype);
237  List<Software> recentSoftware = (List<Software>)cc.getRecent(dc, Item.SOFTWARE, currentSubtype);
238 
239  // Query to retrieve item types
240  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
241  subtypesQuery.include(Include.ALL);
242
243  // Load parent physical bioassays
244  JSONObject jsonPhysicalBioAssays = new JSONObject();
245  jsonPhysicalBioAssays.put("itemType", "PHYSICALBIOASSAY");
246  if (physicalQuery != null)
247  {
248    physicalQuery.include(Include.ALL);
249    physicalQuery.order(Orders.asc(Hql.property("name")));
250    jsonPhysicalBioAssays.put("items", JsonUtil.toArray(physicalQuery.iterate(dc), new NameableConverter()));
251  }
252
253  // Load parent derived bioassays
254  JSONObject jsonParents = new JSONObject();
255  jsonParents.put("itemType", "DERIVEDBIOASSAY");
256  if (parentQuery != null)
257  {
258    parentQuery.include(Include.ALL);
259    parentQuery.order(Orders.asc(Hql.property("name")));
260    ItemResultList<DerivedBioAssay> parents = parentQuery.list(dc);
261    jsonParents.put("items", JsonUtil.toArray(parents, new NameableConverter()));
262    if (parents.size() == 1 && currentExtract == null)
263    {
264      try
265      {
266        currentExtract = parents.get(0).getExtract();
267      }
268      catch (PermissionDeniedException ex)
269      {}
270    }
271  }
272 
273  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), bioAssay);
274  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
275  %>
276  <base:page type="popup" title="<%=title%>" id="edit-page">
277  <base:head scripts="tabcontrol-2.js,subtypes.js,linkitems-2.js,~bioassays.js" styles="tabcontrol.css">
278    <ext:scripts context="<%=jspContext%>" />
279    <ext:stylesheets context="<%=jspContext%>" />
280  </base:head>
281  <base:body>
282    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
283    <form action="index.jsp?ID=<%=ID%>" method="post" name="bioAssay">
284    <input type="hidden" name="cmd" value="UpdateItem">
285   
286    <t:tabcontrol id="settings"
287      subclass="content dialogtabcontrol"
288      position="bottom" active="<%=tabId%>" remember="<%=tabId == null && bioAssay != null%>" 
289      extensions="<%=invoker%>">
290    <t:tab id="info" title="Bioassay" helpid="derivedbioassay.edit">
291      <table class="fullform input100">
292      <tr>
293        <th>Name</th>
294        <td><input class="text required auto-init" data-auto-init="<%=bioAssay == null ? "focus-select" : "focus" %>"
295          type="text" name="name" 
296          value="<%=HTML.encodeTags(bioAssay == null ? Values.getString(cc.getPropertyValue("name"), "New derived bioassay") : bioAssay.getName())%>" 
297          maxlength="<%=DerivedBioAssay.MAX_NAME_LENGTH%>"></td>
298        <td></td>
299      </tr>
300      <tr>
301        <th>Type</th>
302        <td>
303          <select name="subtype_id" id="subtype_id"
304            <%=!readCurrentSubtype ? "disabled readonly class=\"disabled selectionlist\"" : "class=\"selectionlist\""%>>
305          <%
306          if (!readCurrentSubtype)
307          {
308            %>
309            <option value="-1">- denied -
310            <%
311          }
312          else
313          {
314            %>
315            <option value="0">-none-
316            <%
317            int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
318            for (ItemSubtype subtype : subtypesQuery.list(dc))
319            {
320              int id = subtype.getId();
321              if (id != currentSubtypeId && subtype.isRemoved()) continue;
322              %>
323              <option value="<%=id == currentSubtypeId && bioAssay != null ? -id : id%>" 
324                <%=id == currentSubtypeId ? "selected" : ""%>
325                title="<%=HTML.encodeTags(subtype.getDescription()) %>"
326                ><%=HTML.encodeTags(subtype.getName())%>
327              <%
328            }
329          }
330          %>
331          </select>
332        </td>
333        <td></td>
334      </tr>
335      <%
336      if (bioAssay == null)
337      {
338        %>
339        <tr>
340          <th>Parent type</th>
341          <td>
342            <input id="isRoot" type="radio" name="isRoot" value="1" 
343              <%=parentType == Item.PHYSICALBIOASSAY ? "checked" : "" %>
344              ><label for="isRoot">Physical bioassay</label>
345            <input id="isChild" type="radio" name="isRoot" value="0"
346              <%=parentType != Item.PHYSICALBIOASSAY ? "checked" : "" %>
347              ><label for="isChild">Derived bioassay</label><br>
348          </td>
349          <td></td>
350        </tr>
351        <%
352      }
353      %>
354      <%
355      if (bioAssay == null || bioAssay.isRoot())
356      {
357        %>
358        <tr id="physicalBioAssaySection">
359          <th class="subprompt">- physical bioassays</th>
360          <td>
361            <div class="selectionlist">
362            <table>
363            <tr>
364            <td>
365              <select name="physicalBioAssays" id="physicalBioAssays"
366                class="auto-init"
367                data-auto-init="link-container"
368                data-initial-items="[<%=HTML.encodeTags(jsonPhysicalBioAssays.toJSONString()) %>]"
369                data-initial-action="<%=bioAssay == null ? 1 : 0 %>"
370                size="4" multiple>
371              </select>
372            </td>
373            <td>
374            <td style="vertical-align: top;">
375              <base:buttongroup vertical="true">
376                <base:button 
377                  id="btnAddPhysicalBioAssays"
378                  subclass="leftaligned"
379                  style="width: 12em;"
380                  title="Add&nbsp;bioassays&hellip;" 
381                  tooltip="Add physical bioassays"
382                />
383                <base:button 
384                  subclass="leftaligned auto-init"
385                  data-auto-init="remove-link"
386                  data-list-id="physicalBioAssays"
387                  style="width: 12em;"
388                  title="Remove" 
389                  tooltip="Remove the selected physical bioassays"
390                />
391              </base:buttongroup>
392            </td>
393            </tr>
394            </table>
395            </div>
396          </td>
397          <td></td>
398        </tr>
399        <%
400      }
401      if (bioAssay == null || !bioAssay.isRoot())
402      {
403        %>
404        <tr id="parentBioAssaySection">
405          <th class="subprompt">- bioassays</th>
406          <td>
407            <div class="selectionlist">
408            <table>
409            <tr>
410            <td>
411              <select name="parents" id="parents" 
412                class="auto-init"
413                data-auto-init="link-container"
414                data-initial-items="[<%=HTML.encodeTags(jsonParents.toJSONString()) %>]"
415                data-initial-action="<%=bioAssay == null ? 1 : 0 %>"
416                size="4" multiple>
417              </select>
418            </td>
419            <td>
420            <td style="vertical-align: top;">
421              <base:buttongroup vertical="true">
422                <base:button 
423                  id="btnAddParents"
424                  subclass="leftaligned"
425                  style="width: 12em;"
426                  title="Add&nbsp;bioassays&hellip;" 
427                  tooltip="Add parent derived bioassays"
428                />
429                <base:button 
430                  subclass="leftaligned auto-init"
431                  data-auto-init="remove-link"
432                  data-list-id="parents"
433                  style="width: 12em;"
434                  title="Remove" 
435                  tooltip="Remove the selected derived bioassays"
436                />
437              </base:buttongroup>
438            </td>
439            </tr>
440            </table>
441            </div>
442           
443          </td>
444          <td></td>
445        </tr>
446        <%
447      }
448      %>
449      <tr>
450        <th>Extract</th>
451        <td>
452          <base:select 
453            id="extract_id"
454            clazz="selectionlist"
455            required="false"
456            current="<%=currentExtract%>"
457            denied="<%=!readCurrentExtract%>"
458            newitem="<%=bioAssay == null%>"
459          />
460        </td>
461        <td></td>
462      </tr>
463      <tr>
464        <th>Protocol</th>
465        <td>
466          <base:select 
467            id="protocol_id"
468            clazz="selectionlist"
469            required="false"
470            current="<%=currentProtocol%>"
471            denied="<%=!readCurrentProtocol%>"
472            recent="<%=recentProtocols%>"
473            defaultitems="<%=defaultProtocols%>"
474            newitem="<%=bioAssay == null%>"
475          />
476        </td>
477        <td></td>
478      </tr>
479      <tr>
480        <th>Hardware</th>
481        <td>
482          <base:select 
483            id="hardware_id"
484            clazz="selectionlist"
485            required="false"
486            current="<%=currentHardware%>"
487            denied="<%=!readCurrentHardware%>"
488            recent="<%=recentHardware%>"
489            defaultitems="<%=defaultHardware%>"
490            newitem="<%=bioAssay == null%>"
491          />
492        </td>
493        <td></td>
494      </tr>
495      <tr>
496        <th>Software</th>
497        <td>
498          <base:select 
499            id="software_id"
500            clazz="selectionlist"
501            required="false"
502            current="<%=currentSoftware%>"
503            denied="<%=!readCurrentSoftware%>"
504            recent="<%=recentSoftware%>"
505            defaultitems="<%=defaultSoftware%>"
506            newitem="<%=bioAssay == null%>"
507          />
508        </td>
509        <td></td>
510      </tr>
511
512      <tr class="dynamic">
513        <th>Description</th>
514        <td>
515          <textarea class="text" rows="6" name="description" id="description"
516            ><%=HTML.encodeTags(bioAssay == null ? cc.getPropertyValue("description") : bioAssay.getDescription())%></textarea>
517        </td>
518        <td style="width: 20px;">
519          <base:zoom textarea="description" title="Description" />
520        </td>
521      </tr>
522      </table>
523    </t:tab>
524
525    <t:tab id="datafiles" title="Data files" helpid="datafiles.edit">
526      <jsp:include page="../../common/datafiles/select_frameset.jsp">
527        <jsp:param name="item_type" value="<%=itemType.name()%>" />
528        <jsp:param name="item_id" value="<%=itemId%>" />
529        <jsp:param name="ID" value="<%=ID%>" />
530      </jsp:include>   
531    </t:tab>
532
533    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit">
534      <jsp:include page="../../common/annotations/annotate_frameset.jsp">
535        <jsp:param name="item_type" value="<%=itemType.name()%>" />
536        <jsp:param name="item_id" value="<%=itemId%>" />
537        <jsp:param name="ID" value="<%=ID%>" />
538      </jsp:include>
539    </t:tab>
540   
541    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
542      helpid="annotations.edit.inherited">
543      <jsp:include page="../../common/annotations/inherit_frameset.jsp">
544        <jsp:param name="item_type" value="<%=itemType.name()%>" />
545        <jsp:param name="item_id" value="<%=itemId%>" />
546        <jsp:param name="ID" value="<%=ID%>" />
547      </jsp:include>
548    </t:tab>
549    </t:tabcontrol>
550    </form>
551
552    <div class="legend">
553      <base:icon image="required.png" />= required information
554      <%if (bioAssay == null) {%><br>
555        <base:icon image="unchangeable.png" />= can't be changed later
556      <%}%>
557    </div>
558
559    <base:buttongroup subclass="dialogbuttons">
560      <base:button id="btnSave" title="Save" />
561      <base:button id="close" title="Cancel" />
562    </base:buttongroup>
563
564  </base:body>
565  </base:page>
566  <%
567}
568finally
569{
570  if (dc != null) dc.close();
571}
572%>
Note: See TracBrowser for help on using the repository browser.