source: trunk/www/lims/arraydesigns/edit_design.jsp @ 3859

Last change on this file since 3859 was 3859, checked in by Nicklas Nordborg, 14 years ago

References #789: Extend "Experiment overview" to check for problems related to platform and data files

  • The validation options and rules have been added. Need a bit more testing.
  • Fixes some other issues with FileSet? and validation of data files.
  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 10.5 KB
Line 
1<%-- $Id: edit_design.jsp 3859 2007-10-18 10:03:33Z 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.RawDataType"
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 String tabId = Values.getString(request.getParameter("tab"), 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  ArrayDesign design = null;
69 
70  boolean deniedPlatform = false;
71  Platform currentPlatform = null;
72  PlatformVariant currentVariant = null;
73 
74  if (itemId == 0)
75  {
76    title = "Create array design";
77    cc.removeObject("item");
78  }
79  else
80  {
81    design = ArrayDesign.getById(dc, itemId);
82    cc.setObject("item", design);
83    title = "Edit array design -- " + HTML.encodeTags(design.getName());
84   
85    try
86    {
87      currentPlatform = design.getPlatform();
88      currentVariant = design.getVariant();
89    }
90    catch (PermissionDeniedException ex)
91    {
92      deniedPlatform = true;
93    }
94    design.checkPermission(Permission.WRITE);
95  }
96
97  ItemQuery<Platform> platformQuery = Platform.getQuery();
98  platformQuery.include(Include.REMOVED, Include.NOT_REMOVED);
99  platformQuery.order(Orders.asc(Hql.property("name")));
100  platformQuery.setCacheResult(true);
101  ItemResultList<Platform> platforms = platformQuery.list(dc);
102
103  ItemQuery<PlatformVariant> variantQuery = PlatformVariant.getQuery();
104  variantQuery.include(Include.REMOVED, Include.NOT_REMOVED);
105  variantQuery.order(Orders.asc(Hql.property("name")));
106  variantQuery.setCacheResult(true);
107  ItemResultList<PlatformVariant> variants = variantQuery.list(dc);
108 
109  final String clazz = "class=\"text\"";
110  final String requiredClazz = "class=\"text required\"";
111  %>
112
113  <base:page type="popup" title="<%=title%>">
114  <base:head scripts="tabcontrol.js,annotations.js,platforms.js" styles="tabcontrol.css">
115    <script language="JavaScript">
116    // Validate the "ArrayDesign" tab
117    function validateArrayDesign()
118    {
119      var frm = document.forms['design'];
120      if (Main.trimString(frm.name.value) == '')
121      {
122        alert("You must enter a name");
123        frm.name.focus();
124        return false;
125      }
126      return true;
127    }
128
129    // Submit the form
130    function saveSettings()
131    {
132      var frm = document.forms['design'];
133      if (TabControl.validateActiveTab('settings'))
134      {
135        if (annotationsLoaded)
136        {
137          Annotations.addModifiedAnnotationsToForm(frames.annotations, frm);
138        }
139        if (inheritedAnnotationsLoaded)
140        {
141          Annotations.addInheritedAnnotationsToForm(frames.inheritedAnnotations, frm);
142        }
143        if (dataFilesLoaded)
144        {
145          Platforms.addDataFilesToForm(frames.datafiles, frm);
146        }
147        frm.submit();
148      }
149    }
150   
151    var annotationsLoaded = false;
152    var inheritedAnnotationsLoaded = false;
153    var parentsChanged = false;
154    var dataFilesLoaded = false;
155    var platformChanged = false;
156    function switchTab(tabControlId, tabId)
157    {
158      var frm = document.forms['design'];
159      if (TabControl.setActiveTab(tabControlId, tabId))
160      {
161        if (tabId == 'annotations' && !annotationsLoaded)
162        {
163          Annotations.loadAnnotateFrame(frames.annotations, '<%=ID%>', '<%=itemType.name()%>', <%=design == null ? 0 : design.getId()%>);
164          annotationsLoaded = true;
165        }
166        else if (tabId == 'inheritedAnnotations' && 
167          (parentsChanged || !inheritedAnnotationsLoaded))
168        {
169          Annotations.loadInheritFrame(frames.inheritedAnnotations, '<%=ID%>', '<%=itemType.name()%>', <%=itemId%>, getParents());
170          inheritedAnnotationsLoaded = true;
171          parentsChanged = false;
172        }
173        else if (tabId == 'datafiles' && (platformChanged || !dataFilesLoaded))
174        {
175          var platform = Platforms.getSelectedPlatform(frm.platform);
176          var variant = Platforms.getSelectedVariant(frm.platform);
177          Platforms.loadDataFilesFrame(frames.datafiles, '<%=ID%>', '<%=itemType.name()%>', <%=design == null ? 0 : design.getId()%>, platform == null ? 0 : platform.id, variant == null ? 0 : variant.id);
178          dataFilesLoaded = true;
179          platformChanged = false;
180        }
181      }
182    }
183   
184    function getParents()
185    {
186      return new Array();
187    }
188   
189    function platformOnChange()
190    {
191      platformChanged = true;
192    }
193
194    function init()
195    {
196      var frm = document.forms['design'];
197      <%
198      if (design == null)
199      {
200        %>
201        frm.name.focus();
202        frm.name.select();
203        <%
204      }
205      %>
206      initPlatforms(<%=currentPlatform == null ? 0 : currentPlatform.getId()%>, <%=currentVariant == null ? 0 : currentVariant.getId()%>);
207    }
208   
209    function initPlatforms(platformId, variantId)
210    {
211      <%
212      for (Platform p : platforms)
213      {
214        if (!p.isRemoved() || p.equals(currentPlatform))
215        {
216          RawDataType rdt = p.isFileOnly() ? null : p.getRawDataType();
217          %>
218          var p<%=p.getId()%> = new Platform(<%=p.getId()%>, '<%=HTML.javaScriptEncode(p.getExternalId())%>', '<%=HTML.javaScriptEncode(p.getName())%>', <%=p.isFileOnly()%>, '<%=rdt == null ? "" : rdt.getId()%>');
219          <%
220        }
221      }
222      for (PlatformVariant v : variants)
223      {
224        Platform p = v.getPlatform();
225        if ((!v.isRemoved() || v.equals(currentVariant)) && (!p.isRemoved() || p.equals(currentPlatform)))
226        {
227          RawDataType rdt = v.isFileOnly() ? null : v.getRawDataType();
228          %>
229          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()%>');
230          <%
231        }
232      }
233      %>
234      var frm = document.forms['design'];
235      Platforms.populateList(frm.platform, platformId, variantId);
236    }
237    </script>
238  </base:head>
239  <base:body onload="init()">
240    <p>
241    <form action="index.jsp?ID=<%=ID%>" method="post" name="design" onsubmit="return false;">
242    <input type="hidden" name="cmd" value="UpdateItem">
243
244    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
245    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*370)+"px;"%>" 
246      position="bottom" active="<%=tabId%>" remember="<%=tabId == null && design != null%>" switch="switchTab">
247    <t:tab id="info" title="Array design" validate="validateArrayDesign()" helpid="arraydesign.edit">
248      <table class="form" cellspacing=0>
249      <tr>
250        <td class="prompt">Name</td>
251        <td><input <%=requiredClazz%> type="text" name="name" 
252          value="<%=HTML.encodeTags(design == null ? Values.getString(cc.getPropertyValue("name"), "New array design") : design.getName())%>" 
253          size="40" maxlength="<%=ArrayDesign.MAX_NAME_LENGTH%>"></td>
254      </tr>
255      <tr>
256        <td class="prompt">Platform</td>
257        <td>
258          <select name="platform" onchange="platformOnChange()" class="required"
259            <%=deniedPlatform ? "disabled" : "" %>>
260          <%
261          if (deniedPlatform)
262          {
263            %>
264            <option value="-1">- denied -
265            <%
266          }
267          %>
268          </select>
269        </td>
270      </tr>
271      <tr valign=top>
272        <td class="prompt">Description</td>
273        <td nowrap>
274          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
275            ><%=HTML.encodeTags(design == null ? cc.getPropertyValue("description") : design.getDescription())%></textarea>
276          <a href="javascript:Main.zoom('Description', 'design', 'description')"
277            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
278        </td>
279      </tr>
280      </table>
281      <div align=right>&nbsp;<i><base:icon image="required.gif" /> = required information</i></div>
282    </t:tab>
283
284    <t:tab id="datafiles" title="Data files" helpid="datafiles.edit">
285      <iframe name="datafiles" id="idDatafiles" src="../../common/datafiles/wait.jsp" 
286        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
287        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
288    </t:tab>
289   
290    <t:tab id="annotations" title="Annotations" helpid="annotations.edit">
291      <iframe name="annotations" id="idAnnotations" src="../../common/annotations/wait.jsp" 
292        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
293        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
294    </t:tab>
295   
296    <t:tab id="inheritedAnnotations" title="Inherited annotations" helpid="annotations.edit.inherited">
297   
298      <iframe name="inheritedAnnotations" id="idInheritedAnnotations" src="../../common/annotations/wait.jsp" 
299        width="100%"  height="<%=(int)(scale*370)%>" frameborder=0 vspace=0 hspace=0
300        marginwidth=0 marginheight=0 scrolling="auto" style="overflow: visible"></iframe>
301    </t:tab>
302    </t:tabcontrol>
303
304    <table align="center">
305    <tr>
306      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
307      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
308    </tr>
309    </table>
310    </form>
311  </base:body>
312  </base:page>
313  <%
314}
315finally
316{
317  if (dc != null) dc.close();
318}
319%>
Note: See TracBrowser for help on using the repository browser.