source: branches/filedb/www/lims/arraydesigns/edit_design.jsp @ 3802

Last change on this file since 3802 was 3802, checked in by Nicklas Nordborg, 15 years ago

References #721: File validation is now in place. More robust code for users with not enough
permissions.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.8 KB
Line 
1<%-- $Id: edit_design.jsp 3802 2007-10-03 11:58:56Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2006 Jari Hakkinen, 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 2
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 this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page session="false"
28  import="net.sf.basedb.core.SessionControl"
29  import="net.sf.basedb.core.DbControl"
30  import="net.sf.basedb.core.Item"
31  import="net.sf.basedb.core.ItemContext"
32  import="net.sf.basedb.core.SystemItems"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Include"
35  import="net.sf.basedb.core.ArrayDesign"
36  import="net.sf.basedb.core.File"
37  import="net.sf.basedb.core.Platform"
38  import="net.sf.basedb.core.PlatformVariant"
39  import="net.sf.basedb.core.Affymetrix"
40  import="net.sf.basedb.core.ItemQuery"
41  import="net.sf.basedb.core.ItemResultList"
42  import="net.sf.basedb.core.PermissionDeniedException"
43  import="net.sf.basedb.core.BaseException"
44  import="net.sf.basedb.core.query.Orders"
45  import="net.sf.basedb.core.query.Hql"
46  import="net.sf.basedb.clients.web.Base"
47  import="net.sf.basedb.clients.web.util.HTML"
48  import="net.sf.basedb.util.Values"
49  import="java.util.List"
50  import="java.util.Set"
51  import="java.util.HashSet"
52  import="java.util.Date"
53%>
54<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
55<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
56<%
57final Item itemType = Item.ARRAYDESIGN;
58final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
59final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
60final int itemId = cc.getId();
61final String ID = sc.getId();
62final float scale = Base.getScale(sc);
63final DbControl dc = sc.newDbControl();
64try
65{
66  String title = null;
67  ArrayDesign design = null;
68 
69  boolean deniedPlatform = false;
70  Platform currentPlatform = null;
71  PlatformVariant currentVariant = null;
72 
73  if (itemId == 0)
74  {
75    title = "Create array design";
76    cc.removeObject("item");
77  }
78  else
79  {
80    design = ArrayDesign.getById(dc, itemId);
81    cc.setObject("item", design);
82    title = "Edit array design -- " + HTML.encodeTags(design.getName());
83   
84    try
85    {
86      currentPlatform = design.getPlatform();
87      currentVariant = design.getVariant();
88    }
89    catch (PermissionDeniedException ex)
90    {
91      deniedPlatform = true;
92    }
93    design.checkPermission(Permission.WRITE);
94  }
95
96  ItemQuery<Platform> platformQuery = Platform.getQuery();
97  platformQuery.order(Orders.asc(Hql.property("name")));
98  platformQuery.setCacheResult(true);
99  ItemResultList<Platform> platforms = platformQuery.list(dc);
100
101  ItemQuery<PlatformVariant> variantQuery = PlatformVariant.getQuery();
102  variantQuery.order(Orders.asc(Hql.property("name")));
103  variantQuery.setCacheResult(true);
104  ItemResultList<PlatformVariant> variants = variantQuery.list(dc);
105 
106  final String clazz = "class=\"text\"";
107  final String requiredClazz = "class=\"text required\"";
108  %>
109
110  <base:page type="popup" title="<%=title%>">
111  <base:head scripts="tabcontrol.js,annotations.js,platforms.js" styles="tabcontrol.css">
112    <script language="JavaScript">
113    // Validate the "ArrayDesign" tab
114    function validateArrayDesign()
115    {
116      var frm = document.forms['design'];
117      if (Main.trimString(frm.name.value) == '')
118      {
119        alert("You must enter a name");
120        frm.name.focus();
121        return false;
122      }
123      return true;
124    }
125
126    // Submit the form
127    function saveSettings()
128    {
129      var frm = document.forms['design'];
130      if (TabControl.validateActiveTab('settings'))
131      {
132        if (annotationsLoaded)
133        {
134          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
135        }
136        if (inheritedAnnotationsLoaded)
137        {
138          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
139        }
140        if (dataFilesLoaded)
141        {
142          Platforms.addDataFilesToForm(frames.datafiles, frm);
143        }
144        frm.submit();
145      }
146    }
147   
148    var annotationsLoaded = false;
149    var inheritedAnnotationsLoaded = false;
150    var parentsChanged = false;
151    var dataFilesLoaded = false;
152    var platformChanged = false;
153    function switchTab(tabControlId, tabId)
154    {
155      if (TabControl.setActiveTab(tabControlId, tabId))
156      {
157        if (tabId == 'annotations' && !annotationsLoaded)
158        {
159          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=design == null ? 0 : design.getId()%>);
160          annotationsLoaded = true;
161        }
162        else if (tabId == 'inheritedAnnotations' && 
163          (parentsChanged || !inheritedAnnotationsLoaded))
164        {
165          Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
166          inheritedAnnotationsLoaded = true;
167          parentsChanged = false;
168        }
169        else if (tabId == 'datafiles' && (platformChanged || !dataFilesLoaded))
170        {
171          var platformId = getPlatform();
172          var variantId = getVariant();
173          Platforms.loadDataFilesFrame(frames.datafiles, '<%=ID%>', '<%=itemType.name()%>', <%=design == null ? 0 : design.getId()%>, platformId, variantId);
174          dataFilesLoaded = true;
175          platformChanged = false;
176        }
177      }
178    }
179   
180    function getParents()
181    {
182      return new Array();
183    }
184   
185    function getPlatform()
186    {
187      var frm = document.forms['design'];
188      if (frm.platform.length == 0) return 0;
189      var pv = frm.platform[frm.platform.selectedIndex].value.split(':');
190      return pv[0];
191    }
192   
193    function getVariant()
194    {
195      var frm = document.forms['design'];
196      if (frm.platform.length == 0) return 0;
197      var pv = frm.platform[frm.platform.selectedIndex].value.split(':');
198      return pv.length > 1 ? pv[1] : null;
199    }
200
201    function platformOnChange()
202    {
203      platformChanged = true;
204    }
205
206    function init()
207    {
208      var frm = document.forms['design'];
209      <%
210      if (design == null)
211      {
212        %>
213        frm.name.focus();
214        frm.name.select();
215        <%
216      }
217      %>
218      initPlatforms(<%=currentPlatform == null ? 0 : currentPlatform.getId()%>, <%=currentVariant == null ? 0 : currentVariant.getId()%>);
219    }
220   
221    function initPlatforms(platformId, variantId)
222    {
223      var platforms = new Array();
224      var variants = new Array();
225      <%
226      for (Platform p : platforms)
227      {
228        %>
229        platforms[platforms.length] = { name:'<%=p.getName()%>', id:<%=p.getId()%> };
230        variants['platform.<%=p.getId()%>'] = new Array();
231        <%
232      }
233      for (PlatformVariant v : variants)
234      {
235        Platform p = v.getPlatform();
236        String index = "platform." + p.getId();
237        %>
238        variants['<%=index%>'][variants['<%=index%>'].length] = { name:'<%=v.getName()%>', id:<%=v.getId()%> };
239        <%
240      }
241      %>
242      var frm = document.forms['design'];
243      for (var p = 0; p < platforms.length; p++)
244      {
245        var platform = platforms[p];
246        var index = 'platform.' + platform.id;
247        var option = new Option(platform.name, platform.id, false, platformId == platform.id && !variantId);
248        frm.platform[frm.platform.length] = option;
249        option.className = 'selectoptionheader';
250        for (var v = 0; v < variants[index].length; v++)
251        {
252          var variant = variants[index][v];
253          option = new Option(variant.name, platform.id + ':' + variant.id, false, platformId == platform.id && variantId == variant.id);
254          option.className = 'selectoptionindent';
255          frm.platform[frm.platform.length] = option;
256        }
257      }
258    }
259    </script>
260  </base:head>
261  <base:body onload="init()">
262    <p>
263    <form action="index.jsp?ID=<%=ID%>" method="post" name="design" onsubmit="return false;">
264    <input type="hidden" name="cmd" value="UpdateItem">
265
266    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
267    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
268      position="bottom"  remember="<%=design != null%>" switch="switchTab">
269    <t:tab id="info" title="Array design" validate="validateArrayDesign()" helpid="arraydesign.edit">
270      <table class="form" cellspacing=0>
271      <tr>
272        <td class="prompt">Name</td>
273        <td><input <%=requiredClazz%> type="text" name="name" 
274          value="<%=HTML.encodeTags(design == null ? Values.getString(cc.getPropertyValue("name"), "New array design") : design.getName())%>" 
275          size="40" maxlength="<%=ArrayDesign.MAX_NAME_LENGTH%>"></td>
276      </tr>
277      <tr>
278        <td class="prompt">Platform</td>
279        <td>
280          <select name="platform" onchange="platformOnChange()" <%=deniedPlatform ? "disabled" : "" %>>
281          <%
282          if (deniedPlatform)
283          {
284            %>
285            <option value="-1">- denied -
286            <%
287          }
288          %>
289          </select>
290        </td>
291      </tr>
292      <tr valign=top>
293        <td class="prompt">Description</td>
294        <td nowrap>
295          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
296            ><%=HTML.encodeTags(design == null ? cc.getPropertyValue("description") : design.getDescription())%></textarea>
297          <a href="javascript:Main.zoom('Description', 'design', 'description')"
298            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
299        </td>
300      </tr>
301      </table>
302      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
303    </t:tab>
304
305    <t:tab id="datafiles" title="Data files" helpid="datafiles.edit">
306      <iframe name="datafiles" id="idDatafiles" src="../../common/datafiles/wait.jsp" 
307        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
308        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
309    </t:tab>
310   
311    <t:tab id="annotations" title="Annotations" helpid="annotations.edit">
312      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
313        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
314        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
315    </t:tab>
316   
317    <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited">
318   
319      <iframe name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
320        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
321        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
322    </t:tab>
323    </t:tabcontrol>
324
325    <table align="center">
326    <tr>
327      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
328      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
329    </tr>
330    </table>
331    </form>
332  </base:body>
333  </base:page>
334  <%
335}
336finally
337{
338  if (dc != null) dc.close();
339}
340%>
Note: See TracBrowser for help on using the repository browser.