source: trunk/www/views/physicalbioassays/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: 16.4 KB
Line 
1<%-- $Id: edit_bioassay.jsp 6314 2013-09-02 12:47:53Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg, Gregory Vincic
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  @author Nicklas
24  @version 2.0
25--%>
26<%@ page pageEncoding="UTF-8" session="false"
27  import="net.sf.basedb.core.SessionControl"
28  import="net.sf.basedb.core.DbControl"
29  import="net.sf.basedb.core.Item"
30  import="net.sf.basedb.core.ItemContext"
31  import="net.sf.basedb.core.SystemItems"
32  import="net.sf.basedb.core.Permission"
33  import="net.sf.basedb.core.Include"
34  import="net.sf.basedb.core.Hardware"
35  import="net.sf.basedb.core.PhysicalBioAssay"
36  import="net.sf.basedb.core.BioMaterialEvent"
37  import="net.sf.basedb.core.BioMaterialEventSource"
38  import="net.sf.basedb.core.ItemSubtype"
39  import="net.sf.basedb.core.ArraySlide"
40  import="net.sf.basedb.core.Protocol"
41  import="net.sf.basedb.core.Project"
42  import="net.sf.basedb.core.Extract"
43  import="net.sf.basedb.core.ItemQuery"
44  import="net.sf.basedb.core.ItemResultList"
45  import="net.sf.basedb.core.PermissionDeniedException"
46  import="net.sf.basedb.core.BaseException"
47  import="net.sf.basedb.core.Type"
48  import="net.sf.basedb.core.query.Restrictions"
49  import="net.sf.basedb.core.query.Expressions"
50  import="net.sf.basedb.core.query.Orders"
51  import="net.sf.basedb.core.query.Hql"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.Values"
55  import="net.sf.basedb.util.ListUtil"
56  import="net.sf.basedb.util.formatter.Formatter"
57  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
58  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
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="net.sf.basedb.util.json.JsonUtil"
65  import="net.sf.basedb.util.json.NameableConverter"
66  import="org.json.simple.JSONObject"
67  import="java.util.List"
68  import="java.util.Set"
69  import="java.util.HashSet"
70  import="java.util.Date"
71  import="java.util.Collections"
72%>
73<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
74<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
75<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
76<%
77final Item itemType = Item.PHYSICALBIOASSAY;
78final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
79final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
80final int itemId = cc.getId();
81final String ID = sc.getId();
82final float scale = Base.getScale(sc);
83final DbControl dc = sc.newDbControl();
84try
85{
86  String title = null;
87  String name = null;
88  PhysicalBioAssay pba = null;
89  BioMaterialEvent creationEvent = null;
90  Date eventDate = null;
91  List<Extract> parentExtracts = null;
92 
93  boolean readCurrentSubtype = true;
94  ItemSubtype currentSubtype = null;
95  boolean readCurrentArraySlide = true;
96  ArraySlide currentArraySlide = null;
97 
98  boolean readCurrentProtocol = true;
99  Protocol currentProtocol = null;
100 
101  boolean readCurrentHardware = true;
102  Hardware currentHardware = null;
103
104  if (itemId == 0)
105  {
106    title = "Create physical bioassay";
107    cc.removeObject("item");
108    if (cc.getPropertyFilter("creationEvent.protocol.name") != null)
109    {
110      currentProtocol = Base.getFirstMatching(dc, Protocol.getQuery(), "name", cc.getPropertyFilter("creationEvent.protocol.name"));
111    }
112    if (cc.getPropertyFilter("creationEvent.hardware.name") != null)
113    {
114      currentHardware = Base.getFirstMatching(dc, Hardware.getQuery(), "name", cc.getPropertyFilter("creationEvent.hardware.name"));
115    }
116    if (cc.getPropertyFilter("arraySlide.name") != null)
117    {
118      currentArraySlide = Base.getFirstMatching(dc, ArraySlide.getQuery(), "name", cc.getPropertyFilter("arraySlide.name"));
119    }
120    name = Values.getString(cc.getPropertyValue("name"), "New physical bioassay");
121    eventDate = (Date)cc.getPropertyObject("creationEvent.eventDate");
122   
123    int currentSubtypeId = Values.getInt(request.getParameter("subtype_id"));
124    List<ItemSubtype> relatedToParent = Collections.emptyList();
125    ItemQuery<Extract> extractsQuery = null;
126    if (Values.getBoolean(request.getParameter("useParents")))
127    {
128      ItemContext lc = sc.getCurrentContext(Item.EXTRACT);
129      if (lc.getSelected().size() > 0)
130      {
131        extractsQuery = Extract.getQuery();
132        extractsQuery.include(Include.ALL);
133        extractsQuery.order(Orders.asc(Hql.property("name")));
134        extractsQuery.restrict(Restrictions.in(Hql.property("id"), 
135          Expressions.parameter("selected", lc.getSelected(), Type.INT)));
136      }
137    }
138    else if (request.getParameter("extract_id") != null)
139    {
140      int leId = Values.getInt(request.getParameter("extract_id"));
141      extractsQuery = Extract.getQuery();
142      extractsQuery.include(Include.ALL);
143      extractsQuery.restrict(Restrictions.eq(Hql.property("id"), 
144        Expressions.integer(leId)));
145    }
146   
147    if (extractsQuery != null)
148    {
149      parentExtracts = extractsQuery.list(dc);
150      if (currentSubtypeId == 0 && parentExtracts.size() > 0)
151      {
152        relatedToParent = ItemSubtype.getParentSubtypes(dc, parentExtracts.get(0), Item.PHYSICALBIOASSAY);
153      }
154    }
155   
156    if (currentSubtypeId == 0) 
157    {
158      if (relatedToParent.size() > 0)
159      {
160        // Find most recently used related subtype
161        List<ItemSubtype> recentSubtypes = (List<ItemSubtype>)cc.getRecent(dc, Item.ITEMSUBTYPE);
162        currentSubtype = ListUtil.findFirstCommon(recentSubtypes, relatedToParent, relatedToParent.get(0));
163      }
164      else
165      {
166        int recentSubtypeId = Values.getInt(cc.getRecent(Item.ITEMSUBTYPE.name(), 0));
167        currentSubtypeId = Values.getInt(cc.getPropertyValue("itemSubtype"), recentSubtypeId);
168        if (currentSubtypeId > 0) currentSubtype = ItemSubtype.getById(dc, currentSubtypeId);
169      }
170    }
171  }
172  else
173  {
174    pba = PhysicalBioAssay.getById(dc, itemId);
175    pba.checkPermission(Permission.WRITE);
176    creationEvent = pba.getCreationEvent();
177    eventDate = creationEvent.getEventDate();
178    cc.setObject("item", pba);
179    title = "Edit physical bioassay -- " + HTML.encodeTags(pba.getName());
180    name = pba.getName();
181   
182    try
183    {
184      currentSubtype = pba.getItemSubtype();
185    }
186    catch (PermissionDeniedException ex)
187    {
188      readCurrentSubtype = false;
189    }
190
191    try
192    {
193      currentArraySlide = pba.getArraySlide();
194    }
195    catch (PermissionDeniedException ex)
196    {
197      readCurrentArraySlide = false;
198    }
199    try
200    {
201      currentProtocol = creationEvent.getProtocol();
202    }
203    catch (PermissionDeniedException ex)
204    {
205      readCurrentProtocol = false;
206    }
207    try
208    {
209      currentHardware = creationEvent.getHardware();
210    }
211    catch (PermissionDeniedException ex)
212    {
213      readCurrentHardware = false;
214    }
215   
216    // Query to retrieve source extracts
217    ItemQuery<Extract> extractsQuery = (ItemQuery<Extract>)creationEvent.getSources();
218    extractsQuery.include(Include.ALL);
219    extractsQuery.order(Orders.asc(Hql.property("name")));
220    parentExtracts = extractsQuery.list(dc);
221   
222  }
223 
224  // Default items
225  int activeProjectId = sc.getActiveProjectId();
226  List<Protocol> defaultProtocols = null;
227  List<Hardware> defaultHardware = null;
228  if (activeProjectId > 0)
229  {
230    Project activeProject = Project.getById(dc, activeProjectId);
231    defaultProtocols = (List<Protocol>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.PROTOCOL);
232    defaultHardware = (List<Hardware>)activeProject.findDefaultItemsOfRelatedSubtype(dc, currentSubtype, Item.HARDWARE);
233  }
234 
235  // Load recently used items
236  List<Protocol> recentProtocols = (List<Protocol>)cc.getRecent(dc, Item.PROTOCOL, currentSubtype);
237  List<Hardware> recentHardware = (List<Hardware>)cc.getRecent(dc, Item.HARDWARE, currentSubtype);
238 
239  // Query to retrieve item types
240  final ItemQuery<ItemSubtype> subtypesQuery = Base.getSubtypesQuery(itemType);
241  subtypesQuery.include(Include.ALL);
242
243  JSONObject jsonExtracts = new JSONObject();
244  jsonExtracts.put("itemType", "EXTRACT");
245  if (parentExtracts != null)
246  {
247    final BioMaterialEvent event = creationEvent;
248    jsonExtracts.put("items", JsonUtil.toArray(parentExtracts, new NameableConverter<Extract>()
249    {
250      protected void setMore(JSONObject json, Extract e)
251      {
252        String value = ":1";
253        String usedQuantity = null;
254        if (event != null)
255        {
256          BioMaterialEventSource evtSrc = event.getEventSource(e);
257          Float used = evtSrc.getUsedQuantity();
258          usedQuantity = Values.formatNumber(used, -1);
259          int position = evtSrc.getPosition();
260          value = usedQuantity+":"+position;
261        }
262        json.put("name", e.getName() + (usedQuantity == null ? " [-]" : " [" +  usedQuantity + " µg]"));
263        json.put("value", value);
264      }
265    }));
266  }
267
268  Formatter<Date> dateFormatter = FormatterFactory.getDateFormatter(sc);
269  String dateFormat = FormatterSettings.getDateFormat(sc);
270  String jsDateFormat = HTML.javaScriptEncode(dateFormat);
271  String htmlDateFormat = HTML.encodeTags(dateFormat);
272  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), pba);
273  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
274  %>
275  <base:page type="popup" title="<%=title%>" id="edit-page">
276  <base:head scripts="tabcontrol-2.js,linkitems-2.js,subtypes.js,~bioassays.js" styles="tabcontrol.css">
277    <ext:scripts context="<%=jspContext%>" />
278    <ext:stylesheets context="<%=jspContext%>" />
279  </base:head>
280  <base:body>
281    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
282
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"  remember="<%=pba != null%>" 
289      extensions="<%=invoker%>">
290    <t:tab id="info" title="Physical bioassay" helpid="physicalbioassay.edit">
291      <table class="fullform input100">
292      <tr>
293        <th>Name</th>
294        <td><input class="text required auto-init" data-auto-init="<%=pba == null ? "focus-select" : "focus" %>"
295          type="text" name="name" 
296          value="<%=name%>" 
297          maxlength="<%=PhysicalBioAssay.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            int currentSubtypeId = currentSubtype == null ? 0 : currentSubtype.getId();
315            %>
316            <option value="0">-none-
317            <%
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 && pba != 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      <tr>
336        <th>Size</th>
337        <td><input class="text required" type="text" name="size" id="size" style="width: 15em;"
338          value="<%=pba == null ? Values.getString(cc.getPropertyValue("size"), "1") : pba.getSize()%>" 
339          maxlength="10"></td>
340        <td></td>
341      </tr>
342      <tr>
343        <th>Created</th>
344        <td>
345          <table>
346          <tr>
347          <td>
348            <input class="text" type="text" name="event_date" id="event_date" style="width: 15em;"
349              value="<%=HTML.encodeTags(dateFormatter.format(eventDate))%>" 
350              maxlength="20" title="Enter date in format: <%=htmlDateFormat%>">
351          </td>
352          <td>
353            <base:calendar textarea="event_date" title="Created" />
354          </td>
355          </tr>
356          </table>
357        </td>
358        <td></td>
359      </tr>
360      <tr>
361        <th>Registered</th>
362        <td><%=dateFormatter.format(creationEvent == null ? new Date() : creationEvent.getEntryDate())%></td>
363        <td></td>
364      </tr>
365      <tr>
366        <th>Protocol</th>
367        <td>
368          <base:select 
369            id="protocol_id"
370            clazz="selectionlist"
371            required="false"
372            current="<%=currentProtocol%>"
373            denied="<%=!readCurrentProtocol%>"
374            recent="<%=recentProtocols%>"
375            defaultitems="<%=defaultProtocols%>"
376            newitem="<%=pba == null%>"
377          />
378        </td>
379        <td></td>
380      </tr>
381      <tr>
382        <th>Hardware</th>
383        <td>
384          <base:select 
385            id="hardware_id"
386            clazz="selectionlist"
387            required="false"
388            current="<%=currentHardware%>"
389            denied="<%=!readCurrentHardware%>"
390            recent="<%=recentHardware%>"
391            defaultitems="<%=defaultHardware%>"
392            newitem="<%=pba == null%>"
393          />
394        </td>
395        <td></td>
396      </tr>
397      <tr>
398        <th>Array slide</th>
399        <td>
400          <base:select 
401            id="arrayslide_id"
402            clazz="selectionlist"
403            required="false"
404            current="<%=currentArraySlide%>"
405            denied="<%=!readCurrentArraySlide%>"
406            newitem="<%=pba == null%>"
407          />
408        </td>
409        <td></td>
410      </tr>
411      <tr class="dynamic">
412        <th>Description</th>
413        <td>
414          <textarea class="text" rows="6" name="description" id="description"
415            ><%=HTML.encodeTags(pba == null ? cc.getPropertyValue("description") : pba.getDescription())%></textarea>
416        </td>
417        <td style="width: 20px;">
418          <base:zoom textarea="description" title="Description" />
419        </td>
420      </tr>
421      </table>
422    </t:tab>
423   
424    <t:tab id="extracts" title="Extracts" helpid="physicalbioassay.extracts">
425      <table class="fullform input100">
426      <tr class="big">
427        <th>Extracts</th>
428        <td>
429          <div class="selectionlist">
430          <table>
431          <tr>
432          <td>
433            <select name="extracts" id="extracts" 
434              class="auto-init"
435              data-auto-init="link-container"
436              data-initial-items="[<%=HTML.encodeTags(jsonExtracts.toJSONString()) %>]"
437              data-initial-action="<%=pba == null ? 1 : 0 %>"
438              size="15" multiple>
439            </select>
440          </td>
441          <td style="vertical-align: top;">
442            <base:buttongroup vertical="true">
443              <base:button 
444                id="btnAddExtracts"
445                subclass="leftaligned"
446                style="width: 12em;"
447                title="Add&nbsp;extracts&hellip;" 
448                tooltip="Add extracts"
449              />
450              <base:button 
451                subclass="leftaligned auto-init"
452                data-auto-init="remove-link"
453                data-list-id="extracts"
454                style="width: 12em;"
455                title="Remove" 
456                tooltip="Remove the selected extracts"
457              />
458            </base:buttongroup>
459          </td>
460          </tr>
461          </table>
462          </div>
463        </td>
464      </tr>
465     
466      <tr>
467        <th class="subprompt">used quantity</th>
468        <td>
469            <input class="text" type="text" name="used_quantity" id="used_quantity"
470              style="width: 15em;" value="" maxlength="10"> (µg)
471        </td>
472      </tr>
473
474      <tr>
475        <th class="subprompt">position</th>
476        <td>
477            <input class="text" type="text" name="position" id="position"
478              style="width: 15em;" maxlength="10"> (1 -- size of bioassay)
479        </td>
480      </tr>
481      <tr class="dynamic">
482        <th></th>
483        <td></td>
484      </tr>
485      </table>
486    </t:tab>
487
488    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit">
489      <jsp:include page="../../common/annotations/annotate_frameset.jsp">
490        <jsp:param name="item_type" value="<%=itemType.name()%>" />
491        <jsp:param name="item_id" value="<%=itemId%>" />
492        <jsp:param name="ID" value="<%=ID%>" />
493      </jsp:include>
494    </t:tab>
495   
496    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
497      helpid="annotations.edit.inherited">
498      <jsp:include page="../../common/annotations/inherit_frameset.jsp">
499        <jsp:param name="item_type" value="<%=itemType.name()%>" />
500        <jsp:param name="item_id" value="<%=itemId%>" />
501        <jsp:param name="ID" value="<%=ID%>" />
502      </jsp:include>
503    </t:tab>
504    </t:tabcontrol>
505    </form>
506   
507    <div class="legend">
508      <base:icon image="required.png" />= required information
509    </div>
510
511    <base:buttongroup subclass="dialogbuttons">
512      <base:button id="btnSave" title="Save" />
513      <base:button id="close" title="Cancel" />
514    </base:buttongroup>
515  </base:body>
516  </base:page>
517  <%
518}
519finally
520{
521  if (dc != null) dc.close();
522}
523%>
Note: See TracBrowser for help on using the repository browser.