source: trunk/www/lims/arrayslides/edit_slide.jsp @ 6254

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

References #1729 and #1730. Use lazy loading of 'Annotations'/'Inherited annotations' for all other items.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.0 KB
Line 
1<%-- $Id: edit_slide.jsp 6254 2013-03-22 07:28:26Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
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
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.ArraySlide"
35  import="net.sf.basedb.core.ArrayBatch"
36  import="net.sf.basedb.core.ItemQuery"
37  import="net.sf.basedb.core.ItemResultList"
38  import="net.sf.basedb.core.PermissionDeniedException"
39  import="net.sf.basedb.core.BaseException"
40  import="net.sf.basedb.core.query.Orders"
41  import="net.sf.basedb.core.query.Hql"
42  import="net.sf.basedb.clients.web.Base"
43  import="net.sf.basedb.clients.web.util.HTML"
44  import="net.sf.basedb.util.Values"
45  import="net.sf.basedb.core.plugin.GuiContext"
46  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
47  import="net.sf.basedb.clients.web.extensions.JspContext"
48  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
49  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
50  import="java.util.List"
51  import="java.util.Set"
52  import="java.util.HashSet"
53  import="java.util.Date"
54%>
55<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
56<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
57<%@ taglib prefix="ext" uri="/WEB-INF/extensions.tld" %>
58<%
59final Item itemType = Item.ARRAYSLIDE;
60final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
61final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
62final int itemId = cc.getId();
63final String ID = sc.getId();
64final float scale = Base.getScale(sc);
65final DbControl dc = sc.newDbControl();
66try
67{
68  String title = null;
69  ArraySlide slide = null;
70 
71  boolean readCurrentArrayBatch = true;
72  ArrayBatch currentArrayBatch = null;
73  int maxIndex = 0;
74 
75  // Load recently used items
76  List<ArrayBatch> recentArrayBatches = (List<ArrayBatch>)cc.getRecent(dc, Item.ARRAYBATCH);
77
78  if (itemId == 0)
79  {
80    title = "Create array slide";
81    cc.removeObject("item");
82    int arrayBatchId = Values.getInt(request.getParameter("arraybatch_id"));
83    if (arrayBatchId != 0)
84    {
85      currentArrayBatch = ArrayBatch.getById(dc, arrayBatchId);
86    }
87    else if (cc.getPropertyFilter("arrayBatch.name") != null)
88    {
89      currentArrayBatch = Base.getFirstMatching(dc, ArrayBatch.getQuery(), "name", cc.getPropertyFilter("arrayBatch.name"));
90    }
91    if (currentArrayBatch != null)
92    {
93      maxIndex = (int)currentArrayBatch.getArraySlides().count(dc);
94    }
95  }
96  else
97  {
98    slide = ArraySlide.getById(dc, itemId);
99    cc.setObject("item", slide);
100    title = "Edit array slide -- " + HTML.encodeTags(slide.getName());
101    try
102    {
103      currentArrayBatch = slide.getArrayBatch();
104    }
105    catch (PermissionDeniedException ex)
106    {
107      readCurrentArrayBatch = false;
108    }
109  }
110  if (slide != null && !slide.hasPermission(Permission.WRITE))
111  {
112    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
113  }
114 
115 
116  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), slide);
117  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
118  %>
119  <base:page type="popup" title="<%=title%>">
120  <base:head scripts="tabcontrol.js" styles="tabcontrol.css">
121    <ext:scripts context="<%=jspContext%>" />
122    <ext:stylesheets context="<%=jspContext%>" />
123    <script>
124    // Validate the "ArraySlide" tab
125    function validateArraySlide()
126    {
127      var frm = document.forms['slide'];
128      if (Main.trimString(frm.name.value) == '')
129      {
130        Forms.showNotification(frm.name, 'You must enter a name');
131        return false;
132      }
133      if (frm.arraybatch_id && !frm.arraybatch_id.value)
134      {
135        Forms.showNotification('arraybatch_id.select', 'You must select an array batch');
136        return false;
137      }
138      return true;
139    }
140
141    // Submit the form
142    function saveSettings()
143    {
144      var frm = document.forms['slide'];
145      if (TabControl.validateActiveTab('settings'))
146      {
147        Annotations.saveModifiedAnnotationsToForm(frm);
148        Annotations.saveInheritedAnnotationsToForm(frm);
149        frm.submit();
150      }
151    }
152   
153    function loadAnnotationsFrame()
154    {
155      Annotations.autoLoadEditFrame();
156    }
157   
158    function loadInheritedAnnotationsFrame()
159    {
160      Annotations.autoLoadInheritFrame(getParents());
161    }
162   
163    function getParents()
164    {
165      var frm = document.forms['slide'];
166      var parents = new Array();
167      if (frm.arraybatch_id)
168      {
169        var batchId = Math.abs(parseInt(frm.arraybatch_id[frm.arraybatch_id.selectedIndex].value));
170        if (batchId > 0) parents[parents.length] = 'ARRAYBATCH:'+batchId;
171      }
172      return parents;
173    }
174   
175    function selectArrayBatchOnClick()
176    {
177      var frm = document.forms['slide'];
178      var url = '../../lims/arraybatches/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setArrayBatchCallback';
179      if (frm.arraybatch_id.length > 0) url += '&item_id='+frm.arraybatch_id[0].value;
180      Main.openPopup(url, 'SelectArrayBatch', 1050, 700);
181    }
182    function setArrayBatchCallback(id, name)
183    {
184      var frm = document.forms['slide'];
185      var list = frm.arraybatch_id;
186      if (list.length < 1 || list[0].value == '0') // >
187      {
188        Forms.addListOption(list, 0, new Option());
189      }
190      list[0].value = id;
191      list[0].text = name;
192      list.selectedIndex = 0;
193    }
194
195    function init()
196    {
197      var frm = document.forms['slide'];
198      <%
199      if (slide == null)
200      {
201        %>
202        frm.name.focus();
203        frm.name.select();
204        <%
205      }
206      %>
207    }
208    </script>
209  </base:head>
210  <base:body onload="init()">
211    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
212    <form action="index.jsp?ID=<%=ID%>" method="post" name="slide">
213    <input type="hidden" name="cmd" value="UpdateItem">
214
215    <t:tabcontrol id="settings"
216      subclass="content dialogtabcontrol"
217      position="bottom"  remember="<%=slide != null%>" 
218      extensions="<%=invoker%>">
219    <t:tab id="info" title="Array slide" validate="validateArraySlide()" helpid="arrayslide.edit">
220      <table class="fullform input100">
221      <tr>
222        <th>Name</th>
223        <td><input class="text required" type="text" name="name" 
224          value="<%=HTML.encodeTags(slide == null ? Values.getString(cc.getPropertyValue("name"), "New array slide") : slide.getName())%>" 
225          maxlength="<%=ArraySlide.MAX_NAME_LENGTH%>"></td>
226        <td></td>
227      </tr>
228      <tr>
229        <th>Barcode</th>
230        <td><input class="text" type="text" name="barcode" 
231          value="<%=HTML.encodeTags(slide == null ? Values.getString(cc.getPropertyValue("barcode"), "") : slide.getBarcode())%>" 
232          maxlength="<%=ArraySlide.MAX_BARCODE_LENGTH%>"></td>
233        <td></td>
234      </tr>
235      <tr>
236        <th><label for="destroyed">Destroyed</label></th>
237        <td><input type="checkbox" name="destroyed" id="destroyed" value="1"
238          <%=(slide != null && slide.isDestroyed()) || (slide == null && Values.getBoolean(cc.getPropertyValue("destroyed"))) ? "checked" : ""%>>
239        </td>
240        <td></td>
241      </tr>
242      <tr>
243        <th>Array batch</th>
244        <td>
245          <%
246          if (slide != null)
247          {
248            %>
249            <%=Base.getEncodedName(currentArrayBatch, !readCurrentArrayBatch)%>
250            <%
251          }
252          else
253          {
254            %>
255            <base:select 
256              id="arraybatch_id"
257              clazz="selectionlist required"
258              required="true"
259              current="<%=currentArrayBatch%>"
260              denied="<%=!readCurrentArrayBatch%>"
261              recent="<%=recentArrayBatches%>"
262              newitem="true"
263              onselect="selectArrayBatchOnClick()"
264            />
265            <%
266          }
267          %>
268        </td>
269        <td></td>
270      </tr>
271      <tr>
272        <th>Index</th>
273        <td><input class="text" type="text" name="batch_index" value="<%=slide == null ? Values.getInt(cc.getPropertyValue("batchIndex"), maxIndex + 1) : slide.getBatchIndex()%>" 
274          maxlength="10" style="width: 15em;"
275          onkeypress="return Numbers.integerOnly(event)"></td>
276        <td></td>
277      </tr>
278      <tr class="dynamic">
279        <th>Description</th>
280        <td>
281          <textarea class="text" rows="6" name="description" id="description"
282            ><%=HTML.encodeTags(slide == null ? cc.getPropertyValue("description") : slide.getDescription())%></textarea>
283        </td>
284        <td style="width: 20px;">
285          <base:zoom textarea="description" title="Description" />
286        </td>
287      </tr>
288      </table>
289    </t:tab>
290   
291    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit" activate="loadAnnotationsFrame()">
292      <jsp:include page="../../common/annotations/annotate_frameset.jsp">
293        <jsp:param name="item_type" value="<%=itemType.name()%>" />
294        <jsp:param name="item_id" value="<%=itemId%>" />
295        <jsp:param name="ID" value="<%=ID%>" />
296      </jsp:include>
297    </t:tab>
298   
299    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
300      helpid="annotations.edit.inherited" activate="loadInheritedAnnotationsFrame()">
301      <jsp:include page="../../common/annotations/inherit_frameset.jsp">
302        <jsp:param name="item_type" value="<%=itemType.name()%>" />
303        <jsp:param name="item_id" value="<%=itemId%>" />
304        <jsp:param name="ID" value="<%=ID%>" />
305      </jsp:include>
306    </t:tab>
307    </t:tabcontrol>
308    </form>
309
310    <div class="legend">
311      <base:icon image="required.png" />= required information
312    </div>
313
314    <base:buttongroup subclass="dialogbuttons">
315      <base:button onclick="saveSettings()" title="Save" />
316      <base:button onclick="window.close()" title="Cancel" />
317    </base:buttongroup>
318  </base:body>
319  </base:page>
320  <%
321}
322finally
323{
324  if (dc != null) dc.close();
325}
326%>
Note: See TracBrowser for help on using the repository browser.