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

Last change on this file since 5917 was 5917, checked in by Nicklas Nordborg, 12 years ago

References #1655: GUI improvements

Edit dialogs for array lims.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.7 KB
Line 
1<%-- $Id: edit_slide.jsp 5917 2011-12-19 11:28:45Z 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.selectedIndex < 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    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
235    <form action="index.jsp?ID=<%=ID%>" method="post" name="slide" onsubmit="return false;">
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 <%=requiredClazz%> 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 <%=clazz%> 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 <%=clazz%> 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 <%=clazz%> rows="6" name="description" 
306            ><%=HTML.encodeTags(slide == null ? cc.getPropertyValue("description") : slide.getDescription())%></textarea>
307        </td>
308        <td style="width: 20px;">
309          <base:icon image="zoom.png" 
310            onclick="Main.zoom('Description', 'slide', 'description')"
311            tooltip="Edit in larger window"
312          />
313        </td>
314      </tr>
315      </table>
316    </t:tab>
317   
318    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit"><iframe 
319      name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
320      style="width: 100%; height: 100%;"></iframe></t:tab>
321   
322    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
323      helpid="annotations.edit.inherited"><iframe 
324        name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
325        style="width: 100%; height: 100%;"></iframe></t:tab>
326    </t:tabcontrol>
327    </form>
328
329    <div class="legend">
330      <base:icon image="required.gif" /> = required information
331    </div>
332
333    <base:buttongroup subclass="dialogbuttons">
334      <base:button onclick="saveSettings()" title="Save" />
335      <base:button onclick="window.close()" title="Cancel" />
336    </base:buttongroup>
337  </base:body>
338  </base:page>
339  <%
340}
341finally
342{
343  if (dc != null) dc.close();
344}
345%>
Note: See TracBrowser for help on using the repository browser.