source: trunk/www/lims/arraydesigns/edit_design.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: 12.5 KB
Line 
1<%-- $Id: edit_design.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  @author Nicklas
23  @version 2.0
24--%>
25<%@ page pageEncoding="UTF-8" session="false"
26  import="net.sf.basedb.core.SessionControl"
27  import="net.sf.basedb.core.DbControl"
28  import="net.sf.basedb.core.Item"
29  import="net.sf.basedb.core.ItemContext"
30  import="net.sf.basedb.core.SystemItems"
31  import="net.sf.basedb.core.Permission"
32  import="net.sf.basedb.core.Include"
33  import="net.sf.basedb.core.ArrayDesign"
34  import="net.sf.basedb.core.File"
35  import="net.sf.basedb.core.Project"
36  import="net.sf.basedb.core.Platform"
37  import="net.sf.basedb.core.PlatformVariant"
38  import="net.sf.basedb.core.RawDataType"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.ItemResultList"
41  import="net.sf.basedb.core.PermissionDeniedException"
42  import="net.sf.basedb.core.BaseException"
43  import="net.sf.basedb.core.query.Orders"
44  import="net.sf.basedb.core.query.Hql"
45  import="net.sf.basedb.clients.web.Base"
46  import="net.sf.basedb.clients.web.util.HTML"
47  import="net.sf.basedb.util.Values"
48  import="net.sf.basedb.core.plugin.GuiContext"
49  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
50  import="net.sf.basedb.clients.web.extensions.JspContext"
51  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
52  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
53  import="java.util.List"
54  import="java.util.Set"
55  import="java.util.HashSet"
56  import="java.util.Date"
57%>
58<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
59<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
60<%
61final Item itemType = Item.ARRAYDESIGN;
62final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
63final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
64final String tabId = Values.getString(request.getParameter("tab"), null);
65final int itemId = cc.getId();
66final String ID = sc.getId();
67final float scale = Base.getScale(sc);
68final DbControl dc = sc.newDbControl();
69try
70{
71  String title = null;
72  ArrayDesign design = null;
73 
74  boolean deniedPlatform = false;
75  Platform currentPlatform = null;
76  PlatformVariant currentVariant = null;
77  List<Platform> defaultPlatforms = null;
78  List<PlatformVariant> defaultVariants = null;
79 
80  int activeProjectId = sc.getActiveProjectId();
81  if (activeProjectId > 0)
82  {
83    Project activeProject = Project.getById(dc, activeProjectId);
84    try
85    {
86      defaultPlatforms = (List<Platform>)activeProject.findDefaultItems(dc, Item.PLATFORM, true);
87    }
88    catch (PermissionDeniedException pdex)
89    {}
90    try
91    {
92      defaultVariants = (List<PlatformVariant>)activeProject.findDefaultItems(dc, Item.PLATFORMVARIANT, true);
93    }
94    catch (PermissionDeniedException pdex)
95    {}
96
97  }
98  if (itemId == 0)
99  {
100    title = "Create array design";
101    cc.removeObject("item");
102    int currentPlatformId = Values.getInt(cc.getRecent(Item.PLATFORM.name(), 0), 0);
103    int currentVariantId = Values.getInt(cc.getRecent(Item.PLATFORMVARIANT.name(), 0), 0);
104    try
105    {
106      if (currentPlatformId != 0) currentPlatform = Platform.getById(dc, currentPlatformId);
107      if (currentVariantId != 0) currentVariant = PlatformVariant.getById(dc, currentVariantId);
108    }
109    catch (Throwable t)
110    {}
111    if (currentPlatform == null && defaultPlatforms != null && defaultPlatforms.size() > 0)
112    {
113      currentPlatform = defaultPlatforms.get(0);
114    }
115    if (currentVariant == null && defaultVariants != null && defaultVariants.size() > 0)
116    {
117      currentVariant = defaultVariants.get(0);
118    }
119  }
120  else
121  {
122    design = ArrayDesign.getById(dc, itemId);
123    cc.setObject("item", design);
124    title = "Edit array design -- " + HTML.encodeTags(design.getName());
125   
126    try
127    {
128      currentPlatform = design.getPlatform();
129      currentVariant = design.getVariant();
130    }
131    catch (PermissionDeniedException ex)
132    {
133      deniedPlatform = true;
134    }
135    design.checkPermission(Permission.WRITE);
136  }
137
138  ItemQuery<Platform> platformQuery = Platform.getQuery();
139  platformQuery.include(Include.REMOVED, Include.NOT_REMOVED);
140  platformQuery.order(Orders.asc(Hql.property("name")));
141  platformQuery.setCacheResult(true);
142  ItemResultList<Platform> platforms = platformQuery.list(dc);
143
144  ItemQuery<PlatformVariant> variantQuery = PlatformVariant.getQuery();
145  variantQuery.include(Include.REMOVED, Include.NOT_REMOVED);
146  variantQuery.order(Orders.asc(Hql.property("name")));
147  variantQuery.setCacheResult(true);
148  ItemResultList<PlatformVariant> variants = variantQuery.list(dc);
149 
150  final String clazz = "class=\"text\"";
151  final String requiredClazz = "class=\"text required\"";
152  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), design);
153  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
154  %>
155  <base:page type="popup" title="<%=title%>">
156  <base:head scripts="tabcontrol.js,annotations.js,platforms.js" styles="tabcontrol.css">
157    <ext:scripts context="<%=jspContext%>" />
158    <ext:stylesheets context="<%=jspContext%>" />
159    <script language="JavaScript">
160    // Validate the "ArrayDesign" tab
161    function validateArrayDesign()
162    {
163      var frm = document.forms['design'];
164      if (Main.trimString(frm.name.value) == '')
165      {
166        alert("You must enter a name");
167        frm.name.focus();
168        return false;
169      }
170      else if (!Numbers.isInteger(frm.numArrays.value))
171      {
172        alert("'" + frm.numArrays.value + "' is not a valid number");
173        frm.numArrays.focus();
174        return false;
175      }
176      else if (parseInt(frm.numArrays.value) <= 0)
177      {
178        alert("Number of arrays must be > 0");
179        frm.numArrays.focus();
180        return false;
181      }
182      return true;
183    }
184
185    // Submit the form
186    function saveSettings()
187    {
188      var frm = document.forms['design'];
189      if (TabControl.validateActiveTab('settings'))
190      {
191        if (annotationsLoaded)
192        {
193          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
194        }
195        if (inheritedAnnotationsLoaded)
196        {
197          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
198        }
199        if (dataFilesLoaded)
200        {
201          frames.datafiles.writeFileActionsToForm(frm);
202        }
203        frm.submit();
204      }
205    }
206   
207    var annotationsLoaded = false;
208    var inheritedAnnotationsLoaded = false;
209    var parentsChanged = false;
210    var dataFilesLoaded = false;
211    var platformChanged = false;
212    function switchTab(tabControlId, tabId)
213    {
214      var frm = document.forms['design'];
215      if (TabControl.setActiveTab(tabControlId, tabId))
216      {
217        if (tabId == 'annotations' && !annotationsLoaded)
218        {
219          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=design == null ? 0 : design.getId()%>);
220          annotationsLoaded = true;
221        }
222        else if (tabId == 'inheritedAnnotations' && 
223          (parentsChanged || !inheritedAnnotationsLoaded))
224        {
225          Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
226          inheritedAnnotationsLoaded = true;
227          parentsChanged = false;
228        }
229        else if (tabId == 'datafiles' && (platformChanged || !dataFilesLoaded))
230        {
231          var platform = Platforms.getSelectedPlatform(frm.platform);
232          var variant = Platforms.getSelectedVariant(frm.platform);
233          Platforms.loadDataFilesFrame(frames.datafiles, '<%=ID%>', '<%=itemType.name()%>', <%=design == null ? 0 : design.getId()%>, platform == null ? 0 : platform.id, variant == null ? 0 : variant.id);
234          dataFilesLoaded = true;
235          platformChanged = false;
236        }
237      }
238    }
239   
240    function getParents()
241    {
242      return new Array();
243    }
244   
245    function platformOnChange()
246    {
247      platformChanged = true;
248    }
249
250    function init()
251    {
252      var frm = document.forms['design'];
253      <%
254      if (design == null)
255      {
256        %>
257        frm.name.focus();
258        frm.name.select();
259        <%
260      }
261      %>
262      initPlatforms(<%=currentPlatform == null ? 0 : currentPlatform.getId()%>, <%=currentVariant == null ? 0 : currentVariant.getId()%>);
263    }
264   
265    function initPlatforms(platformId, variantId)
266    {
267      <%
268      for (Platform p : platforms)
269      {
270        if (!p.isRemoved() || p.equals(currentPlatform))
271        {
272          RawDataType rdt = p.isFileOnly() ? null : p.getRawDataType();
273          %>
274          var p<%=p.getId()%> = new Platform(<%=p.getId()%>, '<%=HTML.javaScriptEncode(p.getExternalId())%>', '<%=HTML.javaScriptEncode(p.getName())%>', <%=p.isFileOnly()%>, '<%=rdt == null ? "" : rdt.getId()%>');
275          <%
276        }
277      }
278      for (PlatformVariant v : variants)
279      {
280        Platform p = v.getPlatform();
281        if ((!v.isRemoved() || v.equals(currentVariant)) && (!p.isRemoved() || p.equals(currentPlatform)))
282        {
283          RawDataType rdt = v.isFileOnly() ? null : v.getRawDataType();
284          %>
285          var v<%=v.getId()%> = new Variant(p<%=p.getId()%>, <%=v.getId()%>, '<%=HTML.javaScriptEncode(v.getExternalId())%>', '<%=HTML.javaScriptEncode(v.getName())%>', <%=v.isFileOnly()%>, '<%=rdt == null ? "" : rdt.getId()%>');
286          <%
287        }
288      }
289      %>
290      var frm = document.forms['design'];
291      Platforms.populateList(frm.platform, platformId, variantId);
292    }
293    </script>
294  </base:head>
295  <base:body onload="init()">
296    <h1><%=title%> <base:help tabcontrol="settings" /></h1>
297    <form action="index.jsp?ID=<%=ID%>" method="post" name="design" onsubmit="return false;">
298    <input type="hidden" name="cmd" value="UpdateItem">
299
300    <t:tabcontrol id="settings" 
301      subclass="content dialogtabcontrol" 
302      position="bottom" active="<%=tabId%>" remember="<%=tabId == null && design != null%>" switch="switchTab"
303      extensions="<%=invoker%>">
304    <t:tab id="info" title="Array design" validate="validateArrayDesign()" helpid="arraydesign.edit">
305      <table class="fullform input100">
306      <tr>
307        <th>Name</th>
308        <td><input <%=requiredClazz%> type="text" name="name" 
309          value="<%=HTML.encodeTags(design == null ? Values.getString(cc.getPropertyValue("name"), "New array design") : design.getName())%>" 
310          maxlength="<%=ArrayDesign.MAX_NAME_LENGTH%>"></td>
311        <td></td>
312      </tr>
313      <tr>
314        <th>Platform</th>
315        <td>
316          <select name="platform" onchange="platformOnChange()" class="required"
317            <%=deniedPlatform ? "disabled" : "" %>>
318          <%
319          if (deniedPlatform)
320          {
321            %>
322            <option value="-1">- denied -
323            <%
324          }
325          %>
326          </select>
327        </td>
328        <td></td>
329      </tr>
330      <tr>
331        <th>Arrays / slide</th>
332        <td><input <%=requiredClazz%> type="text" name="numArrays" style="width: 15em;"
333          value="<%=design == null ? Values.getString(cc.getPropertyValue("numArrays"), "1") : design.getNumArrays()%>" 
334          maxlength="10" onkeypress="return Numbers.integerOnly(event)"></td>
335        <td></td>
336      </tr>
337      <tr class="dynamic">
338        <th>Description</th>
339        <td nowrap>
340          <textarea <%=clazz%> rows="6" name="description" 
341            ><%=HTML.encodeTags(design == null ? cc.getPropertyValue("description") : design.getDescription())%></textarea>
342        </td>
343        <td style="width: 20px;">
344          <base:icon image="zoom.png" 
345            onclick="Main.zoom('Description', 'design', 'description')"
346            tooltip="Edit in larger window"
347          />
348        </td>
349      </tr>
350      </table>
351    </t:tab>
352
353    <t:tab id="datafiles" title="Data files" helpid="datafiles.edit"><iframe 
354      name="datafiles" id="idDatafiles" src="../../common/datafiles/wait.jsp" 
355      style="width: 100%; height: 100%;"></iframe></t:tab>
356
357    <t:tab id="annotations" title="Annotations &amp; parameters" helpid="annotations.edit"><iframe 
358      name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
359      style="width: 100%; height: 100%;"></iframe></t:tab>
360   
361    <t:tab id="inheritedAnnotations" title="Inherited annotations" 
362      helpid="annotations.edit.inherited"><iframe 
363        name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
364        style="width: 100%; height: 100%;"></iframe></t:tab>
365    </t:tabcontrol>
366    </form>
367
368    <div class="legend">
369      <base:icon image="required.gif" /> = required information
370    </div>
371
372    <base:buttongroup subclass="dialogbuttons">
373      <base:button onclick="saveSettings()" title="Save" />
374      <base:button onclick="window.close()" title="Cancel" />
375    </base:buttongroup>
376  </base:body>
377  </base:page>
378  <%
379}
380finally
381{
382  if (dc != null) dc.close();
383}
384%>
Note: See TracBrowser for help on using the repository browser.