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

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

References #721: Store data in files instead of in the database

Remember most recently used platform/variant when creating raw bioassays/array designs

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