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

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

References #1604: Support for multiple files of the same type in a FileSet?

Added data and core layer classes. Started with the gui and seems to work when adding single files of a type. There are some remaining things to implement when used with multiple files. File validation is not yet fully functional. Some of the batch importers need to be fixed as well to be able to handle multiple files of the same type.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 12.8 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          boolean multiple = ft.getAllowMultiple();
185          int value = 0;
186          if (required) value += 1;
187          if (multiple) value += 2;
188          %>
189          Link.addNewItem(fileTypes, new Item('F', <%=dft.getId()%>, '<%=HTML.javaScriptEncode(dft.getName())%> <%=required ? "[×]" : "[-]"%>', <%=value%>));
190          <%
191        }
192      }
193      %>
194    }
195    function addFileTypesOnClick()
196    {
197      var frm = document.forms['platform'];
198      Main.openPopup('../datafiletypes/index.jsp?ID=<%=ID%>&mode=selectmultiple&callback=addFileTypeCallback', 'AddFileTypes', 1000, 700);
199    }
200    function addFileTypeCallback(fileTypeId, name)
201    {
202      var item = Link.getItem('F', fileTypeId);
203      var frm = document.forms['platform'];
204      var required = frm.required.checked;
205      var multiple = frm.multiple.checked;
206      var newValue = 0;
207      if (required) newValue += 1;
208      if (multiple) newValue += 2;
209      if (!item) item = new Item('F', fileTypeId, name+(required ? '[×]' : '[-]'), newValue, '');
210      Link.addItem(frm.fileTypes, item);
211    }
212    function removeOnClick()
213    {
214      Link.removeSelected(document.forms['platform'].fileTypes);
215    }
216    function fileTypesOnChange()
217    {
218      var frm = document.forms['platform'];
219      var item = frm.fileTypes[frm.fileTypes.selectedIndex].item;
220      if (item && item.id)
221      {
222        frm.required.checked = (item.value & 1) > 0;
223        frm.multiple.checked = (item.value & 2) > 0;
224      }
225      else
226      {
227        frm.required.checked = false;
228        frm.multiple.checked = false;
229      }
230    }
231    function requiredOnClick()
232    {
233      var frm = document.forms['platform'];
234      var required = frm.required.checked;
235      var multiple = frm.multiple.checked;
236      var newValue = 0;
237      if (required) newValue += 1;
238      if (multiple) newValue += 2;
239      for (var i = 0; i < frm.fileTypes.length; i++)  // >
240      {
241        var option = frm.fileTypes[i];
242        if (option.selected && option.item.id)
243        {
244          option.item.value = newValue;
245          var text = option.text.replace(/\[.*\]/, '['+(required ? '×' : '-') +']');
246          option.text = text;
247        }
248      }
249    }
250    function multipleOnClick()
251    {
252      requiredOnClick();
253    }
254    </script>
255  </base:head>
256  <base:body onload="init()">
257    <p>
258    <form action="index.jsp?ID=<%=ID%>" method="post" name="platform" onsubmit="return false;">
259    <input type="hidden" name="cmd" value="UpdateItem">
260
261    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
262    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*260)+"px;"%>" 
263      position="bottom" active="<%=tabId%>" remember="<%=tabId == null && platform != null%>"
264      extensions="<%=invoker%>">
265    <t:tab id="info" title="Platform" validate="validatePlatform()" helpid="platform.edit">
266      <table class="form" cellspacing=0>
267      <tr>
268        <td class="prompt">Name</td>
269        <td><input <%=requiredClazz%> type="text" name="name" 
270          value="<%=HTML.encodeTags(platform == null ? Values.getString(cc.getPropertyValue("name"), "New platform") : platform.getName())%>" 
271          size="40" maxlength="<%=Platform.MAX_NAME_LENGTH%>"></td>
272      </tr>
273      <%
274      if (platform == null)
275      {
276        // For new platforms only
277        RawDataType currentRawDataType = 
278          RawDataTypes.getRawDataType(cc.getPropertyValue("rawDataType"));
279        if (currentRawDataType == null)
280        {
281          currentRawDataType = RawDataTypes.getRawDataType(cc.getRecent("RawDataType", 0));
282        }
283       
284        %>
285        <tr>
286          <td class="prompt">External ID</td>
287          <td><input <%=unchangeableClazz%> type="text" name="externalId" 
288            value="<%=HTML.encodeTags(cc.getPropertyValue("externalId"))%>" 
289            size="40" maxlength="<%=Platform.MAX_EXTERNAL_ID_LENGTH%>"></td>
290        </tr>
291        <tr>
292          <td class="prompt">File-only</td>
293          <td>
294            <input <%=unchangeableClazz%> type="radio" name="fileOnly" value="0" <%=!isFileOnly ? "checked" : ""%>
295              onclick="fileOnlyOnClick()">no
296            <input <%=unchangeableClazz%> type="radio" name="fileOnly" value="1" <%=isFileOnly ? "checked" : ""%>
297              onclick="fileOnlyOnClick()">yes
298          </td>
299        </tr>
300
301        <tr>
302          <td class="prompt">Raw data type</td>
303          <td>
304            <select name="rawdatatype" <%=unchangeableClazz%>>
305            <option value="">- any -
306            <%
307            for (RawDataType rdt : RawDataTypes.getSortedRawDataTypes(new RawDataTypes.NameComparator()))
308            {
309              if (rdt.isStoredInDb())
310              {
311                String selected = rdt.equals(currentRawDataType) ? "selected" : "";
312                %>
313                <option value="<%=rdt.getId()%>" <%=selected%>><%=HTML.encodeTags(rdt.getName())%>
314                <%
315              }
316            }
317            %>
318            </select>
319          </td>
320        </tr>
321        <tr>
322          <td class="prompt">Channels</td>
323          <td><input <%=unchangeableClazz%> type="text" name="channels" 
324            value="<%=Values.getInt(cc.getPropertyValue("channels"), 1)%>" 
325            size="12" maxlength="10" 
326            onkeypress="return Numbers.integerOnly(event)"></td>
327        </tr>
328        <%
329      }
330      %>
331      <tr valign=top>
332        <td class="prompt">Description</td>
333        <td nowrap>
334          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
335            ><%=HTML.encodeTags(platform == null ? cc.getPropertyValue("description") : platform.getDescription())%></textarea>
336          <a href="javascript:Main.zoom('Description', 'platform', 'description')"
337            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
338        </td>
339      </tr>
340      </table>
341      <div align=right>
342        &nbsp;<i><base:icon image="required.gif" /> = required information</i>
343        <%if (platform == null) {%><br>
344        <i><base:icon image="unchangeable.gif" /> = can't be changed later</i>
345        <%}%>
346        </div>
347    </t:tab>
348   
349    <t:tab id="datafiles" title="Data file types"
350      tooltip="Associate this platform with date file types"
351      helpid="platform.edit.filetypes"
352      >
353      <table >
354      <tr valign="top">
355      <td>
356        <b>Data file types</b><br>
357        <select name="fileTypes" size="10" multiple style="width: 20em;" 
358          onchange="fileTypesOnChange()">
359        </select>&nbsp;<br>
360        <input type="hidden" name="modifiedFileTypes" value="">
361        <input type="hidden" name="removedFileTypes" value="">
362      </td>
363      <td>
364        <br>
365        <table width="150">
366        <tr><td width="150"><base:button 
367          onclick="addFileTypesOnClick()" 
368          title="Add&nbsp;data file types&hellip;" 
369          tooltip="Add more data file types to this platform"
370          /></td></tr>
371        <tr><td width="150"><base:button 
372          onclick="removeOnClick()" 
373          title="Remove" 
374          tooltip="Remove the selected data file types"
375        /></td></tr>
376        </table>
377        <input type="checkbox" id="required" name="required" value="1" onchange="requiredOnClick()">
378          <label for="required">Required</label><br>
379        <input type="checkbox" id="multiple" name="multiple" value="1" onchange="multipleOnClick()">
380          <label for="multiple">Allow multiple files</label>
381      </td>
382      </tr>     
383      </table>
384    </t:tab>
385   
386    </t:tabcontrol>
387
388    <table align="center">
389    <tr>
390      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
391      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
392    </tr>
393    </table>
394    </form>
395  </base:body>
396  </base:page>
397  <%
398}
399finally
400{
401  if (dc != null) dc.close();
402}
403%>
Note: See TracBrowser for help on using the repository browser.