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

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

References #1655: GUI improvements

  • File manager dialogs
  • File server edit dialog
  • Changed zoom.gif to png
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 11.0 KB
Line 
1<%-- $Id: edit_slide.jsp 5908 2011-12-13 13:48:46Z 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<%
58final Item itemType = Item.ARRAYSLIDE;
59final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
60final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
61final int itemId = cc.getId();
62final String ID = sc.getId();
63final float scale = Base.getScale(sc);
64final DbControl dc = sc.newDbControl();
65try
66{
67  String title = null;
68  ArraySlide slide = null;
69 
70  boolean readCurrentArrayBatch = true;
71  ArrayBatch currentArrayBatch = null;
72  int maxIndex = 0;
73 
74  // Load recently used items
75  List<ArrayBatch> recentArrayBatches = (List<ArrayBatch>)cc.getRecent(dc, Item.ARRAYBATCH);
76
77  if (itemId == 0)
78  {
79    title = "Create array slide";
80    cc.removeObject("item");
81    int arrayBatchId = Values.getInt(request.getParameter("arraybatch_id"));
82    if (arrayBatchId != 0)
83    {
84      currentArrayBatch = ArrayBatch.getById(dc, arrayBatchId);
85    }
86    else if (cc.getPropertyFilter("arrayBatch.name") != null)
87    {
88      currentArrayBatch = Base.getFirstMatching(dc, ArrayBatch.getQuery(), "name", cc.getPropertyFilter("arrayBatch.name"));
89    }
90    if (currentArrayBatch != null)
91    {
92      maxIndex = (int)currentArrayBatch.getArraySlides().count(dc);
93    }
94  }
95  else
96  {
97    slide = ArraySlide.getById(dc, itemId);
98    cc.setObject("item", slide);
99    title = "Edit array slide -- " + HTML.encodeTags(slide.getName());
100    try
101    {
102      currentArrayBatch = slide.getArrayBatch();
103    }
104    catch (PermissionDeniedException ex)
105    {
106      readCurrentArrayBatch = false;
107    }
108  }
109  if (slide != null && !slide.hasPermission(Permission.WRITE))
110  {
111    throw new PermissionDeniedException(Permission.WRITE, itemType.toString());
112  }
113  final String clazz = "class=\"text\"";
114  final String requiredClazz = "class=\"text required\"";
115  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), slide);
116  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
117  %>
118  <base:page type="popup" title="<%=title%>">
119  <base:head scripts="tabcontrol.js,annotations.js" styles="tabcontrol.css">
120    <ext:scripts context="<%=jspContext%>" />
121    <ext:stylesheets context="<%=jspContext%>" />
122    <script language="JavaScript">
123    // Validate the "ArraySlide" tab
124    function validateArraySlide()
125    {
126      var frm = document.forms['slide'];
127      if (Main.trimString(frm.name.value) == '')
128      {
129        alert("You must enter a name");
130        frm.name.focus();
131        return false;
132      }
133      if (frm.arraybatch_id && frm.arraybatch_id[frm.arraybatch_id.selectedIndex].value == 0)
134      {
135        alert("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', 1000, 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    <p>
235    <form action="index.jsp?ID=<%=ID%>" method="post" name="slide" onsubmit="return false;">
236    <input type="hidden" name="cmd" value="UpdateItem">
237
238    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
239    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
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="form" cellspacing=0>
244      <tr>
245        <td class="prompt">Name</td>
246        <td><input <%=requiredClazz%> type="text" name="name" 
247          value="<%=HTML.encodeTags(slide == null ? Values.getString(cc.getPropertyValue("name"), "New array slide") : slide.getName())%>" 
248          size="40" maxlength="<%=ArraySlide.MAX_NAME_LENGTH%>"></td>
249      </tr>
250      <tr>
251        <td class="prompt">Barcode</td>
252        <td><input <%=clazz%> type="text" name="barcode" 
253          value="<%=HTML.encodeTags(slide == null ? Values.getString(cc.getPropertyValue("barcode"), "") : slide.getBarcode())%>" 
254          size="40" maxlength="<%=ArraySlide.MAX_BARCODE_LENGTH%>"></td>
255      </tr>
256      <tr>
257        <td class="prompt"><label for="destroyed">Destroyed</label></td>
258        <td><input type="checkbox" name="destroyed" id="destroyed" value="1"
259          <%=(slide != null && slide.isDestroyed()) || (slide == null && Values.getBoolean(cc.getPropertyValue("destroyed"))) ? "checked" : ""%>>
260        </td>
261      </tr>
262      <tr>
263        <td class="prompt">Array batch</td>
264        <td>
265          <%
266          if (slide != null)
267          {
268            %>
269            <%=Base.getEncodedName(currentArrayBatch, !readCurrentArrayBatch)%>
270            <%
271          }
272          else
273          {
274            %>
275            <base:select 
276              id="arraybatch_id"
277              clazz="selectionlist required"
278              required="true"
279              current="<%=currentArrayBatch%>"
280              denied="<%=!readCurrentArrayBatch%>"
281              recent="<%=recentArrayBatches%>"
282              newitem="true"
283              onselect="selectArrayBatchOnClick()"
284              onchange="arrayBatchOnChange()()"
285            />
286            <%
287          }
288          %>
289        </td>
290      </tr>
291      <tr>
292        <td class="prompt">Index</td>
293        <td><input <%=clazz%> type="text" name="batch_index" value="<%=slide == null ? Values.getInt(cc.getPropertyValue("batchIndex"), maxIndex + 1) : slide.getBatchIndex()%>" 
294          size="12" maxlength="10" 
295          onkeypress="return Numbers.integerOnly(event)"></td>
296      </tr>
297      <tr >
298        <td class="prompt">Description</td>
299        <td nowrap>
300          <textarea <%=clazz%> rows="4" cols="40" name="description" 
301            ><%=HTML.encodeTags(slide == null ? cc.getPropertyValue("description") : slide.getDescription())%></textarea>
302          <a href="javascript:Main.zoom('Description', 'slide', 'description')"
303            title="Edit in larger window"><base:icon image="zoom.png" /></a>
304        </td>
305      </tr>
306      </table>
307      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
308    </t:tab>
309   
310    <t:tab id="annotations" title="Annotations" helpid="annotations.edit">
311      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
312        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
313        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
314    </t:tab>
315   
316    <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited">
317   
318      <iframe name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
319        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
320        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
321    </t:tab>
322    </t:tabcontrol>
323
324    <table align="center">
325    <tr>
326      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
327      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
328    </tr>
329    </table>
330    </form>
331  </base:body>
332  </base:page>
333  <%
334}
335finally
336{
337  if (dc != null) dc.close();
338}
339%>
Note: See TracBrowser for help on using the repository browser.