source: branches/filedb/www/admin/platforms/variants/edit_variant.jsp @ 3800

Last change on this file since 3800 was 3800, checked in by Nicklas Nordborg, 16 years ago

References #721: It is now possible to edit platforms and data file types throguh the web
interface. Added proper permissions to all items.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 11.9 KB
Line 
1<%-- $Id: edit_variant.jsp 3800 2007-09-28 11:47:54Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Hakkinen, 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 2
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 this program; if not, write to the Free Software
21  Foundation, Inc., 59 Temple Place - Suite 330,
22  Boston, MA  02111-1307, USA.
23  ------------------------------------------------------------------
24
25
26  @author Nicklas
27  @version 2.0
28--%>
29<%@ page session="false"
30  import="net.sf.basedb.core.SessionControl"
31  import="net.sf.basedb.core.DbControl"
32  import="net.sf.basedb.core.Item"
33  import="net.sf.basedb.core.ItemContext"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.Platform"
36  import="net.sf.basedb.core.PlatformVariant"
37  import="net.sf.basedb.core.PlatformFileType"
38  import="net.sf.basedb.core.DataFileType"
39  import="net.sf.basedb.core.RawDataType"
40  import="net.sf.basedb.core.RawDataTypes"
41  import="net.sf.basedb.core.PermissionDeniedException"
42  import="net.sf.basedb.core.ItemQuery"
43  import="net.sf.basedb.core.ItemResultList"
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%>
50<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
51<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
52<%
53final int platformId = Values.getInt(request.getParameter("platform_id"));
54final Item itemType = Item.PLATFORMVARIANT;
55final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
56final ItemContext cc = Base.getAndSetCurrentContext(sc, itemType, null, null);
57final int itemId = cc.getId();
58final String ID = sc.getId();
59final float scale = Base.getScale(sc);
60final DbControl dc = sc.newDbControl();
61try
62{
63  String title = null;
64  Platform platform = null;
65  PlatformVariant variant = null;
66  boolean isFileOnly = false;
67  ItemQuery<PlatformFileType> fileTypeQuery = null;
68 
69  if (itemId == 0)
70  {
71    title = "Create platform variant";
72    platform = Platform.getById(dc, platformId);
73    isFileOnly = Values.getBoolean(cc.getPropertyValue("fileOnly"), platform.isFileOnly());
74    cc.removeObject("item");
75    platform.checkPermission(Permission.WRITE);
76  }
77  else
78  {
79    variant = PlatformVariant.getById(dc, itemId);
80    platform = variant.getPlatform();
81    isFileOnly = variant.isFileOnly();
82    cc.setObject("item", variant);
83    title = "Edit platform variant -- " + HTML.encodeTags(variant.getName());
84    variant.checkPermission(Permission.WRITE);
85    fileTypeQuery = platform.getFileTypes(variant, true);
86    fileTypeQuery.order(Orders.asc(Hql.property("dataFileType.name")));
87  }
88 
89  final String clazz = "class=\"text\"";
90  final String requiredClazz = "class=\"text required\"";
91  final String unchangeableClazz = "class=\"text required unchangeable\"";
92  %>
93
94  <base:page type="popup" title="<%=title%>">
95  <base:head scripts="tabcontrol.js,linkitems.js" styles="tabcontrol.css">
96    <script language="JavaScript">
97    // Validate the "Variant" tab
98    function validateVariant()
99    {
100      var frm = document.forms['variant'];
101      if (Main.trimString(frm.name.value) == '')
102      {
103        alert("You must enter a name");
104        frm.name.focus();
105        return false;
106      }
107      if (frm.externalId)
108      {
109        var fileOnly = Forms.getCheckedRadio(frm.fileOnly).value == '1';
110        if (Main.trimString(frm.externalId.value) == '')
111        {
112          alert("You must enter an external ID");
113          frm.externalId.focus();
114          return false;
115        }
116        else if (fileOnly)
117        {
118          if (!Numbers.isInteger(frm.channels.value))
119          {
120            alert("You must enter the number of channels");
121            frm.channels.focus();
122            return false;
123          }
124          if (parseInt(frm.channels.value) <= 0)
125          {
126            alert("The number of channels must be > 0");
127            frm.channels.focus();
128            return false;
129          }
130        }
131      }
132      return true;
133    }
134
135    // Submit the form
136    function saveSettings()
137    {
138      var frm = document.forms['variant'];
139      if (TabControl.validateActiveTab('settings'))
140      {
141        frm.modifiedFileTypes.value = Link.exportModified(frm, 'F', true).join(',');
142        frm.removedFileTypes.value = Link.getActionIds(-1, 'F').join(',');
143        frm.submit();
144      }
145    }
146   
147    function init()
148    {
149      <%
150      if (variant == null)
151      {
152        %>
153        var frm = document.forms['variant'];
154        frm.name.focus();
155        frm.name.select();
156        fileOnlyOnClick();
157        <%
158      }
159      %>
160      initFileTypes();
161    }
162    function fileOnlyOnClick()
163    {
164      var frm = document.forms['variant'];
165      var fileOnly = Forms.getCheckedRadio(frm.fileOnly).value == '1';
166      frm.rawdatatype.disabled = fileOnly;
167      frm.channels.disabled = !fileOnly;
168      Main.addOrRemoveClass(frm.rawdatatype, 'required', !frm.rawdatatype.disabled);
169      Main.addOrRemoveClass(frm.channels, 'required', !frm.channels.disabled);
170    }
171    function initFileTypes()
172    {
173      var fileTypes = document.forms['variant'].fileTypes;
174      <%
175      if (fileTypeQuery != null)
176      {
177        ItemResultList<PlatformFileType> fileTypes = fileTypeQuery.list(dc);
178        for (PlatformFileType ft : fileTypes)
179        {
180          DataFileType dft = ft.getDataFileType();
181          boolean required = ft.isRequired();
182          %>
183          Link.addNewItem(fileTypes, new Item('F', <%=dft.getId()%>, '<%=HTML.javaScriptEncode(dft.getName())%> <%=required ? "[×]" : "[-]"%>', '<%=required ? "1" : "0"%>'));
184          <%
185        }
186      }
187      %>
188    }
189    function addFileTypesOnClick()
190    {
191      var frm = document.forms['variant'];
192      Main.openPopup('../../datafiletypes/index.jsp?ID=<%=ID%>&mode=selectmultiple&callback=addFileTypeCallback', 'AddFileTypes', 1000, 700);
193    }
194    function addFileTypeCallback(fileTypeId, name)
195    {
196      var item = Link.getItem('F', fileTypeId);
197      var frm = document.forms['variant'];
198      var required = frm.required.checked;
199      if (!item) item = new Item('F', fileTypeId, name+(required ? '[×]' : '[-]'), required ? '1' : '0', '');
200      Link.addItem(frm.fileTypes, item);
201    }
202    function removeOnClick()
203    {
204      Link.removeSelected(document.forms['variant'].fileTypes);
205    }
206    function fileTypesOnChange()
207    {
208      var frm = document.forms['variant'];
209      var item = frm.fileTypes[frm.fileTypes.selectedIndex].item;
210      if (item && item.id)
211      {
212        frm.required.checked = item.value != '0';
213      }
214      else
215      {
216        frm.required.checked = false;
217      }
218    }
219    function requiredOnClick()
220    {
221      var frm = document.forms['variant'];
222      var required = frm.required.checked;
223      for (var i = 0; i < frm.fileTypes.length; i++)  // >
224      {
225        var option = frm.fileTypes[i];
226        if (option.selected && option.item.id)
227        {
228          option.item.value = required ? '1' : '0';
229          var text = option.text.replace(/\[.*\]/, '['+(required ? '×' : '-') +']');
230          option.text = text;
231        }
232      }
233    }
234    </script>
235  </base:head>
236  <base:body onload="init()">
237    <p>
238    <form action="index.jsp?ID=<%=ID%>" method="post" name="variant" onsubmit="return false;">
239    <input type="hidden" name="cmd" value="UpdateItem">
240    <input type="hidden" name="platform_id" value="<%=platformId%>">
241
242    <h3 class="docked"><%=title%> <base:help tabcontrol="settings" /></h3>
243    <t:tabcontrol id="settings" contentstyle="<%="height: "+(int)(scale*260)+"px;"%>" 
244      position="bottom"  remember="<%=variant != null%>">
245    <t:tab id="info" title="Platform" validate="validateVariant()" helpid="platformvariant.edit">
246      <table class="form" cellspacing=0>
247      <tr>
248        <td class="prompt">Name</td>
249        <td><input <%=requiredClazz%> type="text" name="name" 
250          value="<%=HTML.encodeTags(variant == null ? 
251              Values.getString(cc.getPropertyValue("name"), "New " + platform.getName() + " variant") : 
252              variant.getName())%>" 
253          size="40" maxlength="<%=PlatformVariant.MAX_NAME_LENGTH%>"></td>
254      </tr>
255      <%
256      if (variant == null)
257      {
258        // For new platforms only
259        RawDataType currentRawDataType = 
260          RawDataTypes.getRawDataType(cc.getPropertyValue("rawDataType"));
261        if (currentRawDataType == null)
262        {
263          currentRawDataType = platform.getRawDataType();
264        }
265        %>
266        <tr>
267          <td class="prompt">External ID</td>
268          <td><input <%=unchangeableClazz%> type="text" name="externalId" 
269            value="<%=HTML.encodeTags(Values.getString(cc.getPropertyValue("externalId"), platform.getExternalId() + ".new"))%>" 
270            size="40" maxlength="<%=PlatformVariant.MAX_EXTERNAL_ID_LENGTH%>"></td>
271        </tr>
272        <tr>
273          <td class="prompt">File-only</td>
274          <td>
275            <input <%=unchangeableClazz%> type="radio" name="fileOnly" value="0" <%=!isFileOnly ? "checked" : ""%>
276              onclick="fileOnlyOnClick()">no
277            <input <%=unchangeableClazz%> type="radio" name="fileOnly" value="1" <%=isFileOnly ? "checked" : ""%>
278              onclick="fileOnlyOnClick()">yes
279          </td>
280        </tr>
281
282        <tr>
283          <td class="prompt">Raw data type</td>
284          <td>
285            <select name="rawdatatype" <%=unchangeableClazz%>>
286            <option value="">- any -
287            <%
288            for (RawDataType rdt : RawDataTypes.getRawDataTypes())
289            {
290              String selected = rdt.equals(currentRawDataType) ? "selected" : "";
291              %>
292              <option value="<%=rdt.getId()%>" <%=selected%>><%=HTML.encodeTags(rdt.getName())%>
293              <%
294            }
295            %>
296            </select>
297          </td>
298        </tr>
299        <tr>
300          <td class="prompt">Channels</td>
301          <td><input <%=unchangeableClazz%> type="text" name="channels" 
302            value="<%=Values.getInt(cc.getPropertyValue("channels"), currentRawDataType == null ? 1 : currentRawDataType.getChannels())%>" 
303            size="12" maxlength="10" 
304            onkeypress="return Numbers.integerOnly(event)"></td>
305        </tr>
306        <%
307      }
308      %>
309      <tr valign=top>
310        <td class="prompt">Description</td>
311        <td nowrap>
312          <textarea <%=clazz%> rows="4" cols="40" name="description" wrap="virtual"
313            ><%=HTML.encodeTags(variant == null ? cc.getPropertyValue("description") : variant.getDescription())%></textarea>
314          <a href="javascript:Main.zoom('Description', 'variant', 'description')"
315            title="Edit in larger window"><base:icon image="zoom.gif" /></a>
316        </td>
317      </tr>
318      </table>
319      <div align=right>
320        &nbsp;<i><base:icon image="required.gif" /> = required information</i>
321        <%if (variant == null) {%><br>
322        <i><base:icon image="unchangeable.gif" /> = can't be changed later</i>
323        <%}%>
324        </div>
325    </t:tab>
326    <t:tab id="fileTypes" title="Data file types"
327      tooltip="Associate this platform variant with date file types"
328      helpid="platformvariant.edit.filetypes"
329      >
330      <table >
331      <tr valign="top">
332      <td>
333        <b>Data file types</b><br>
334        <select name="fileTypes" size="10" multiple style="width: 20em;" 
335          onchange="fileTypesOnChange()">
336        </select>&nbsp;<br>
337        × = Required
338        <input type="checkbox" name="required" value="1" onchange="requiredOnClick()">
339        <input type="hidden" name="modifiedFileTypes" value="">
340        <input type="hidden" name="removedFileTypes" value="">
341      </td>
342      <td>
343        <br>
344        <table width="150">
345        <tr><td width="150"><base:button 
346          onclick="addFileTypesOnClick()" 
347          title="Add&nbsp;data file types&hellip;" 
348          tooltip="Add more data file types to this platform variant"
349          /></td></tr>
350        <tr><td width="150"><base:button 
351          onclick="removeOnClick()" 
352          title="Remove" 
353          tooltip="Remove the selected data file types"
354        /></td></tr>
355        </table>
356      </td>
357      </tr>     
358      </table>
359    </t:tab>   
360    </t:tabcontrol>
361
362    <table align="center">
363    <tr>
364      <td width="50%"><base:button onclick="saveSettings()" title="Save" /></td>
365      <td width="50%"><base:button onclick="window.close()" title="Cancel" /></td>
366    </tr>
367    </table>
368    </form>
369  </base:body>
370  </base:page>
371  <%
372}
373finally
374{
375  if (dc != null) dc.close();
376}
377%>
Note: See TracBrowser for help on using the repository browser.