source: trunk/www/admin/platforms/edit_platform.jsp @ 5574

Last change on this file since 5574 was 5574, checked in by Nicklas Nordborg, 12 years ago

erged patch release 2.16.2 to the trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.2 KB
Line 
1<%-- $Id:edit_platform.jsp 3820 2007-10-12 10:03:18Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson
5
6  This file is part of BASE - BioArray Software Environment.
7  Available at http://base.thep.lu.se/
8
9  BASE is free software; you can redistribute it and/or
10  modify it under the terms of the GNU General Public License
11  as published by the Free Software Foundation; either version 3
12  of the License, or (at your option) any later version.
13
14  BASE is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  GNU General Public License for more details.
18
19  You should have received a copy of the GNU General Public License
20  along with BASE. If not, see <http://www.gnu.org/licenses/>.
21  ------------------------------------------------------------------
22
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page pageEncoding="UTF-8" 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.Include"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Platform"
35  import="net.sf.basedb.core.PlatformFileType"
36  import="net.sf.basedb.core.DataFileType"
37  import="net.sf.basedb.core.RawDataType"
38  import="net.sf.basedb.core.RawDataTypes"
39  import="net.sf.basedb.core.ItemQuery"
40  import="net.sf.basedb.core.ItemResultList"
41  import="net.sf.basedb.core.query.Orders"
42  import="net.sf.basedb.core.query.Hql"
43  import="net.sf.basedb.core.PermissionDeniedException"
44  import="net.sf.basedb.clients.web.Base"
45  import="net.sf.basedb.clients.web.util.HTML"
46  import="net.sf.basedb.util.Values"
47  import="net.sf.basedb.core.plugin.GuiContext"
48  import="net.sf.basedb.clients.web.extensions.ExtensionsControl"
49  import="net.sf.basedb.clients.web.extensions.JspContext"
50  import="net.sf.basedb.clients.web.extensions.edit.EditUtil"
51  import="net.sf.basedb.util.extensions.ExtensionsInvoker"
52%>
53<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
54<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
55<%
56final Item itemType = Item.PLATFORM;
57final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
58final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
59final String tabId = Values.getString(request.getParameter("tab"), 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  Platform platform = null;
68  boolean isFileOnly = false;
69  ItemQuery<PlatformFileType> fileTypeQuery = null;
70  if (itemId == 0)
71  {
72    title = "Create platform";
73    isFileOnly = Values.getBoolean(cc.getPropertyValue("fileOnly"), isFileOnly);
74    cc.removeObject("item");
75  }
76  else
77  {
78    platform = Platform.getById(dc, itemId);
79    isFileOnly = platform.isFileOnly();
80    cc.setObject("item", platform);
81    title = "Edit platform -- " + HTML.encodeTags(platform.getName());
82    platform.checkPermission(Permission.WRITE);
83    fileTypeQuery = platform.getFileTypes(null, true);
84    fileTypeQuery.include(Include.ALL);
85    fileTypeQuery.order(Orders.asc(Hql.property("dataFileType.name")));
86  }
87
88  final String clazz = "class=\"text\"";
89  final String requiredClazz = "class=\"text required\"";
90  final String unchangeableClazz = "class=\"text required unchangeable\"";
91  JspContext jspContext = ExtensionsControl.createContext(dc, pageContext, GuiContext.item(itemType), platform);
92  ExtensionsInvoker invoker = EditUtil.useEditExtensions(jspContext);
93  %>
94  <base:page type="popup" title="<%=title%>">
95  <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css">
96    <ext:scripts context="<%=jspContext%>" />
97    <ext:stylesheets context="<%=jspContext%>" />
98    <script language="JavaScript">
99    // Validate the "Platform" tab
100    function validatePlatform()
101    {
102      var frm = document.forms['platform'];
103      if (Main.trimString(frm.name.value) == '')
104      {
105        alert("You must enter a name");
106        frm.name.focus();
107        return false;
108      }
109      if (frm.externalId)
110      {
111        var fileOnly = Forms.getCheckedRadio(frm.fileOnly).value == '1';
112        if (Main.trimString(frm.externalId.value) == '')
113        {
114          alert("You must enter an external ID");
115          frm.externalId.focus();
116          return false;
117        }
118        else if (fileOnly)
119        {
120          if (!Numbers.isInteger(frm.channels.value))
121          {
122            alert("You must enter the number of channels");
123            frm.channels.focus();
124            return false;
125          }
126          if (parseInt(frm.channels.value) <= 0)
127          {
128            alert("The number of channels must be > 0");
129            frm.channels.focus();
130            return false;
131          }
132        }
133      }
134      return true;
135    }
136
137    // Submit the form
138    function saveSettings()
139    {
140      var frm = document.forms['platform'];
141      if (TabControl.validateActiveTab('settings'))
142      {
143        frm.modifiedFileTypes.value = Link.exportModified(frm, 'F', true).join(',');
144        frm.removedFileTypes.value = Link.getActionIds(-1, 'F').join(',');
145        frm.submit();
146      }
147    }
148   
149    function init()
150    {
151      <%
152      if (platform == null)
153      {
154        %>
155        var frm = document.forms['platform'];
156        frm.name.focus();
157        frm.name.select();
158        fileOnlyOnClick();
159        <%
160      }
161      %>
162      initFileTypes();
163    }
164    function fileOnlyOnClick()
165    {
166      var frm = document.forms['platform'];
167      var fileOnly = Forms.getCheckedRadio(frm.fileOnly).value == '1';
168      frm.rawdatatype.disabled = fileOnly;
169      frm.channels.disabled = !fileOnly;
170      Main.addOrRemoveClass(frm.rawdatatype, 'required', !frm.rawdatatype.disabled);
171      Main.addOrRemoveClass(frm.channels, 'required', !frm.channels.disabled);
172    }
173    function initFileTypes()
174    {
175      var fileTypes = document.forms['platform'].fileTypes;
176      <%
177      if (fileTypeQuery != null)
178      {
179        ItemResultList<PlatformFileType> fileTypes = fileTypeQuery.list(dc);
180        for (PlatformFileType ft : fileTypes)
181        {
182          DataFileType dft = ft.getDataFileType();
183          boolean required = ft.isRequired();
184          %>
185          Link.addNewItem(fileTypes, new Item('F', <%=dft.getId()%>, '<%=HTML.javaScriptEncode(dft.getName())%> <%=required ? "[×]" : "[-]"%>', '<%=required ? "1" : "0"%>'));
186          <%
187        }
188      }
189      %>
190    }
191    function addFileTypesOnClick()
192    {
193      var frm = document.forms['platform'];
194      Main.openPopup('../datafiletypes/index.jsp?ID=<%=ID%>&mode=selectmultiple&callback=addFileTypeCallback', 'AddFileTypes', 1000, 700);
195    }
196    function addFileTypeCallback(fileTypeId, name)
197    {
198      var item = Link.getItem('F', fileTypeId);
199      var frm = document.forms['platform'];
200      var required = frm.required.checked;
201      if (!item) item = new Item('F', fileTypeId, name+(required ? '[×]' : '[-]'), required ? '1' : '0', '');
202      Link.addItem(frm.fileTypes, item);
203    }
204    function removeOnClick()
205    {
206      Link.removeSelected(document.forms['platform'].fileTypes);
207    }
208    function fileTypesOnChange()
209    {
210      var frm = document.forms['platform'];
211      var item = frm.fileTypes[frm.fileTypes.selectedIndex].item;
212      if (item && item.id)
213      {
214        frm.required.checked = item.value != '0';
215      }
216      else
217      {
218        frm.required.checked = false;
219      }
220    }
221    function requiredOnClick()
222    {
223      var frm = document.forms['platform'];
224      var required = frm.required.checked;
225      for (var i = 0; i < frm.fileTypes.length; i++)  // >
226      {
227        var option = frm.fileTypes[i];
228        if (option.selected && option.item.id)
229        {
230          option.item.value = required ? '1' : '0';
231          var text = option.text.replace(/\[.*\]/, '['+(required ? '×' : '-') +']');
232          option.text = text;
233        }
234      }
235    }
236    </script>
237  </base:head>
238  <base:body onload="init()">
239    <p>
240    <form action="index.jsp?ID=<%=ID%>" method="post" name="platform" onsubmit="return false;">
241    <input type="hidden" name="cmd" value="UpdateItem">
242
243    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
244    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*260)+"px;"%>" 
245      position="bottom" active="<%=tabId%>" remember="<%=tabId == null && platform != null%>"
246      extensions="<%=invoker%>">
247    <t:tab id="info" title="Platform" validate="validatePlatform()" helpid="platform.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(platform == null ? Values.getString(cc.getPropertyValue("name"), "New platform") : platform.getName())%>" 
253          size="40" maxlength="<%=Platform.MAX_NAME_LENGTH%>"></td>
254      </tr>
255      <%
256      if (platform == null)
257      {
258        // For new platforms only
259        RawDataType currentRawDataType = 
260          RawDataTypes.getRawDataType(cc.getPropertyValue("rawDataType"));
261        if (currentRawDataType == null)
262        {
263          currentRawDataType = RawDataTypes.getRawDataType(cc.getRecent("RawDataType", 0));
264        }
265       
266        %>
267        <tr>
268          <td class="prompt">External ID</td>
269          <td><input <%=unchangeableClazz%> type="text" name="externalId" 
270            value="<%=HTML.encodeTags(cc.getPropertyValue("externalId"))%>" 
271            size="40" maxlength="<%=Platform.MAX_EXTERNAL_ID_LENGTH%>"></td>
272        </tr>
273        <tr>
274          <td class="prompt">File-only</td>
275          <td>
276            <input <%=unchangeableClazz%> type="radio" name="fileOnly" value="0" <%=!isFileOnly ? "checked" : ""%>
277              onclick="fileOnlyOnClick()">no
278            <input <%=unchangeableClazz%> type="radio" name="fileOnly" value="1" <%=isFileOnly ? "checked" : ""%>
279              onclick="fileOnlyOnClick()">yes
280          </td>
281        </tr>
282
283        <tr>
284          <td class="prompt">Raw data type</td>
285          <td>
286            <select name="rawdatatype" <%=unchangeableClazz%>>
287            <option value="">- any -
288            <%
289            for (RawDataType rdt : RawDataTypes.getSortedRawDataTypes(new RawDataTypes.NameComparator()))
290            {
291              if (rdt.isStoredInDb())
292              {
293                String selected = rdt.equals(currentRawDataType) ? "selected" : "";
294                %>
295                <option value="<%=rdt.getId()%>" <%=selected%>><%=HTML.encodeTags(rdt.getName())%>
296                <%
297              }
298            }
299            %>
300            </select>
301          </td>
302        </tr>
303        <tr>
304          <td class="prompt">Channels</td>
305          <td><input <%=unchangeableClazz%> type="text" name="channels" 
306            value="<%=Values.getInt(cc.getPropertyValue("channels"), 1)%>" 
307            size="12" maxlength="10" 
308            onkeypress="return Numbers.integerOnly(event)"></td>
309        </tr>
310        <%
311      }
312      %>
313      <tr valign=top>
314        <td class="prompt">Description</td>
315        <td nowrap>
316          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
317            ><%=HTML.encodeTags(platform == null ? cc.getPropertyValue("description") : platform.getDescription())%></textarea>
318          <a href="javascript:Main.zoom('Description', 'platform', 'description')"
319            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
320        </td>
321      </tr>
322      </table>
323      <div align=right>
324        &nbsp;<i><base:icon image="required.gif" /> = required information</i>
325        <%if (platform == null) {%><br>
326        <i><base:icon image="unchangeable.gif" /> = can't be changed later</i>
327        <%}%>
328        </div>
329    </t:tab>
330   
331    <t:tab id="datafiles" title="Data file types"
332      tooltip="Associate this platform with date file types"
333      helpid="platform.edit.filetypes"
334      >
335      <table >
336      <tr valign="top">
337      <td>
338        <b>Data file types</b><br>
339        <select name="fileTypes" size="10" multiple style="width: 20em;" 
340          onchange="fileTypesOnChange()">
341        </select>&nbsp;<br>
342        × = Required
343        <input type="checkbox" name="required" value="1" onchange="requiredOnClick()">
344        <input type="hidden" name="modifiedFileTypes" value="">
345        <input type="hidden" name="removedFileTypes" value="">
346      </td>
347      <td>
348        <br>
349        <table width="150">
350        <tr><td width="150"><base:button 
351          onclick="addFileTypesOnClick()" 
352          title="Add&nbsp;data file types&hellip;" 
353          tooltip="Add more data file types to this platform"
354          /></td></tr>
355        <tr><td width="150"><base:button 
356          onclick="removeOnClick()" 
357          title="Remove" 
358          tooltip="Remove the selected data file types"
359        /></td></tr>
360        </table>
361      </td>
362      </tr>     
363      </table>
364    </t:tab>
365   
366    </t:tabcontrol>
367
368    <table align="center">
369    <tr>
370      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
371      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
372    </tr>
373    </table>
374    </form>
375  </base:body>
376  </base:page>
377  <%
378}
379finally
380{
381  if (dc != null) dc.close();
382}
383%>
Note: See TracBrowser for help on using the repository browser.