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

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

References #1730: Move in-page onEvent attributes to external *.js files

Got rid of 'clazz' and 'requiredClazz' string constatns used in several JSP scripts. Better to specify class="" directly on each element since there are cases were we want to add more variants.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.6 KB
Line 
1<%-- $Id: edit_slide.jsp 6217 2012-12-14 13:05:00Z 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,annotations.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        if (annotationsLoaded)
148        {
149          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
150        }
151        if (inheritedAnnotationsLoaded)
152        {
153          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
154        }
155        frm.submit();
156      }
157    }
158   
159    var annotationsLoaded = false;
160    var inheritedAnnotationsLoaded = false;
161    var parentsChanged = false;
162    function switchTab(tabControlId, tabId)
163    {
164      if (TabControl.setActiveTab(tabControlId, tabId))
165      {
166        if (tabId == 'annotations' && !annotationsLoaded)
167        {
168          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=slide == null ? 0 : slide.getId()%>);
169          annotationsLoaded = true;
170        }
171        else if (tabId == 'inheritedAnnotations' && 
172          (parentsChanged || !inheritedAnnotationsLoaded))
173        {
174          Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
175          inheritedAnnotationsLoaded = true;
176          parentsChanged = false;
177        }
178      }
179    }
180   
181    function getParents()
182    {
183      var frm = document.forms['slide'];
184      var parents = new Array();
185      if (frm.arraybatch_id)
186      {
187        var batchId = Math.abs(parseInt(frm.arraybatch_id[frm.arraybatch_id.selectedIndex].value));
188        if (batchId > 0) parents[parents.length] = 'ARRAYBATCH:'+batchId;
189      }
190      return parents;
191    }
192   
193    function arrayBatchOnChange()
194    {
195      parentsChanged = true;
196    }   
197    function selectArrayBatchOnClick()
198    {
199      var frm = document.forms['slide'];
200      var url = '../../lims/arraybatches/index.jsp?ID=<%=ID%>&cmd=UpdateContext&mode=selectone&callback=setArrayBatchCallback';
201      if (frm.arraybatch_id.length > 0) url += '&item_id='+frm.arraybatch_id[0].value;
202      Main.openPopup(url, 'SelectArrayBatch', 1050, 700);
203    }
204    function setArrayBatchCallback(id, name)
205    {
206      var frm = document.forms['slide'];
207      var list = frm.arraybatch_id;
208      if (list.length < 1 || list[0].value == '0') // >
209      {
210        Forms.addListOption(list, 0, new Option());
211      }
212      list[0].value = id;
213      list[0].text = name;
214      list.selectedIndex = 0;
215      parentsChanged = true;
216    }
217
218    function init()
219    {
220      var frm = document.forms['slide'];
221      <%
222      if (slide == null)
223      {
224        %>
225        frm.name.focus();
226        frm.name.select();
227        <%
228      }
229      %>
230    }
231    </script>
232  </base:head>
233  <base:body onload="init()">
234    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
235    <form action="index.jsp?ID=<%=ID%>" method="post" name="slide">
236    <input type="hidden" name="cmd" value="UpdateItem">
237
238    <t:tabcontrol id="settings"
239      subclass="content dialogtabcontrol"
240      position="bottom"  remember="<%=slide != null%>" switch="switchTab"
241      extensions="<%=invoker%>">
242    <t:tab id="info" title="Array slide" validate="validateArraySlide()" helpid="arrayslide.edit">
243      <table class="fullform input100">
244      <tr>
245        <th>Name</th>
246        <td><input class="text required" type="text" name="name" 
247          value="<%=HTML.encodeTags(slide == null ? Values.getString(cc.getPropertyValue("name"), "New array slide") : slide.getName())%>" 
248          maxlength="<%=ArraySlide.MAX_NAME_LENGTH%>"></td>
249        <td></td>
250      </tr>
251      <tr>
252        <th>Barcode</th>
253        <td><input class="text" type="text" name="barcode" 
254          value="<%=HTML.encodeTags(slide == null ? Values.getString(cc.getPropertyValue("barcode"), "") : slide.getBarcode())%>" 
255          maxlength="<%=ArraySlide.MAX_BARCODE_LENGTH%>"></td>
256        <td></td>
257      </tr>
258      <tr>
259        <th><label for="destroyed">Destroyed</label></th>
260        <td><input type="checkbox" name="destroyed" id="destroyed" value="1"
261          <%=(slide != null && slide.isDestroyed()) || (slide == null && Values.getBoolean(cc.getPropertyValue("destroyed"))) ? "checked" : ""%>>
262        </td>
263        <td></td>
264      </tr>
265      <tr>
266        <th>Array batch</th>
267        <td>
268          <%
269          if (slide != null)
270          {
271            %>
272            <%=Base.getEncodedName(currentArrayBatch, !readCurrentArrayBatch)%>
273            <%
274          }
275          else
276          {
277            %>
278            <base:select 
279              id="arraybatch_id"
280              clazz="selectionlist required"
281              required="true"
282              current="<%=currentArrayBatch%>"
283              denied="<%=!readCurrentArrayBatch%>"
284              recent="<%=recentArrayBatches%>"
285              newitem="true"
286              onselect="selectArrayBatchOnClick()"
287              onchange="arrayBatchOnChange()()"
288            />
289            <%
290          }
291          %>
292        </td>
293        <td></td>
294      </tr>
295      <tr>
296        <th>Index</th>
297        <td><input class="text" type="text" name="batch_index" value="<%=slide == null ? Values.getInt(cc.getPropertyValue("batchIndex"), maxIndex + 1) : slide.getBatchIndex()%>" 
298          maxlength="10" style="width: 15em;"
299          onkeypress="return Numbers.integerOnly(event)"></td>
300        <td></td>
301      </tr>
302      <tr class="dynamic">
303        <th>Description</th>
304        <td>
305          <textarea class="text" rows="6" name="description" id="description"
306            ><%=HTML.encodeTags(slide == null ? cc.getPropertyValue("description") : slide.getDescription())%></textarea>
307        </td>
308        <td style="width: 20px;">
309          <base:zoom textarea="description" title="Description" />
310        </td>
311      </tr>
312      </table>
313    </t:tab>
314   
315    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit"><iframe 
316      name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
317      class="absolutefull" style="width: 100%; height: 100%;"></iframe></t:tab>
318   
319    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
320      helpid="annotations.edit.inherited"><iframe 
321        name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
322        class="absolutefull" style="width: 100%; height: 100%;"></iframe></t:tab>
323    </t:tabcontrol>
324    </form>
325
326    <div class="legend">
327      <base:icon image="required.png" />= required information
328    </div>
329
330    <base:buttongroup subclass="dialogbuttons">
331      <base:button onclick="saveSettings()" title="Save" />
332      <base:button onclick="window.close()" title="Cancel" />
333    </base:buttongroup>
334  </base:body>
335  </base:page>
336  <%
337}
338finally
339{
340  if (dc != null) dc.close();
341}
342%>
Note: See TracBrowser for help on using the repository browser.