source: trunk/www/lims/arraydesigns/edit_design.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: 12.9 KB
Line 
1<%-- $Id: edit_design.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  @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    <p>
297    <form action="index.jsp?ID=<%=ID%>" method="post" name="design" onsubmit="return false;">
298    <input type="hidden" name="cmd" value="UpdateItem">
299
300    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
301    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
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="form" cellspacing=0>
306      <tr>
307        <td class="prompt">Name</td>
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          size="40" maxlength="<%=ArrayDesign.MAX_NAME_LENGTH%>"></td>
311      </tr>
312      <tr>
313        <td class="prompt">Platform</td>
314        <td>
315          <select name="platform" onchange="platformOnChange()" class="required"
316            <%=deniedPlatform ? "disabled" : "" %>>
317          <%
318          if (deniedPlatform)
319          {
320            %>
321            <option value="-1">- denied -
322            <%
323          }
324          %>
325          </select>
326        </td>
327      </tr>
328      <tr>
329        <td class="prompt">Arrays / slide</td>
330        <td><input <%=requiredClazz%> type="text" name="numArrays" 
331          value="<%=design == null ? Values.getString(cc.getPropertyValue("numArrays"), "1") : design.getNumArrays()%>" 
332          size="12" maxlength="10" onkeypress="return Numbers.integerOnly(event)"></td>
333      </tr>
334      <tr >
335        <td class="prompt">Description</td>
336        <td nowrap>
337          <textarea <%=clazz%> rows="4" cols="40" name="description" 
338            ><%=HTML.encodeTags(design == null ? cc.getPropertyValue("description") : design.getDescription())%></textarea>
339          <a href="javascript:Main.zoom('Description', 'design', 'description')"
340            title="Edit in larger window"><base:icon image="zoom.png" /></a>
341        </td>
342      </tr>
343      </table>
344      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
345    </t:tab>
346
347    <t:tab id="datafiles" title="Data files" helpid="datafiles.edit">
348      <iframe name="datafiles" id="idDatafiles" src="../../common/datafiles/wait.jsp" 
349        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
350        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
351    </t:tab>
352   
353    <t:tab id="annotations" title="Annotations" helpid="annotations.edit">
354      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
355        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
356        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
357    </t:tab>
358   
359    <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited">
360   
361      <iframe name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
362        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
363        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
364    </t:tab>
365    </t:tabcontrol>
366
367    <table align="center">
368    <tr>
369      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
370      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
371    </tr>
372    </table>
373    </form>
374  </base:body>
375  </base:page>
376  <%
377}
378finally
379{
380  if (dc != null) dc.close();
381}
382%>
Note: See TracBrowser for help on using the repository browser.