source: trunk/www/common/datafiles/select_files.jsp @ 3820

Last change on this file since 3820 was 3820, checked in by Nicklas Nordborg, 15 years ago

Merged branches/filedb into trunk.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 8.6 KB
Line 
1<%-- $Id: select_files.jsp 3820 2007-10-12 10:03:18Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) 2005 Nicklas Nordborg
4  Copyright (C) 2006 Jari Hakkinen, Nicklas Nordborg
5  Copyright (C) 2007 Nicklas Nordborg
6
7  This file is part of BASE - BioArray Software Environment.
8  Available at http://base.thep.lu.se/
9
10  BASE is free software; you can redistribute it and/or
11  modify it under the terms of the GNU General Public License
12  as published by the Free Software Foundation; either version 2
13  of the License, or (at your option) any later version.
14
15  BASE is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  GNU General Public License for more details.
19
20  You should have received a copy of the GNU General Public License
21  along with this program; if not, write to the Free Software
22  Foundation, Inc., 59 Temple Place - Suite 330,
23  Boston, MA  02111-1307, USA.
24  ------------------------------------------------------------------
25 
26--%>
27<%@ page
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.Type"
33  import="net.sf.basedb.core.BasicItem"
34  import="net.sf.basedb.core.Permission"
35  import="net.sf.basedb.core.Nameable"
36  import="net.sf.basedb.core.FileStoreEnabled"
37  import="net.sf.basedb.core.FileSet"
38  import="net.sf.basedb.core.FileSetMember"
39  import="net.sf.basedb.core.File"
40  import="net.sf.basedb.core.Platform"
41  import="net.sf.basedb.core.PlatformVariant"
42  import="net.sf.basedb.core.PlatformFileType"
43  import="net.sf.basedb.core.DataFileType"
44  import="net.sf.basedb.core.ItemQuery"
45  import="net.sf.basedb.core.Include"
46  import="net.sf.basedb.core.ItemResultList"
47  import="net.sf.basedb.core.PermissionDeniedException"
48  import="net.sf.basedb.core.query.Expressions"
49  import="net.sf.basedb.core.query.Restrictions"
50  import="net.sf.basedb.core.query.Hql"
51  import="net.sf.basedb.core.query.Orders"
52  import="net.sf.basedb.clients.web.Base"
53  import="net.sf.basedb.clients.web.util.HTML"
54  import="net.sf.basedb.util.formatter.Formatter"
55  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
56  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
57  import="net.sf.basedb.util.Values"
58  import="java.util.ArrayList"
59  import="java.util.List"
60  import="java.util.Date"
61  import="java.util.Set"
62  import="java.util.HashSet"
63  import="java.util.TreeSet"
64%>
65<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
66<%
67final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
68final String ID = sc.getId();
69final float scale = Base.getScale(sc);
70final Item itemType = Item.valueOf(request.getParameter("item_type"));
71final int itemId = Values.getInt(request.getParameter("item_id"));
72final int platformId = Values.getInt(request.getParameter("platform_id"), -1);
73final int variantId = Values.getInt(request.getParameter("variant_id"), -1);
74final ItemContext cc = sc.getCurrentContext(itemType);
75
76final DbControl dc = sc.newDbControl();
77try
78{
79
80  // Get the current item; null if we are editing a new item
81  final FileStoreEnabled item = itemId == 0 ? null : (FileStoreEnabled)itemType.getById(dc, itemId);
82  FileSet fileSet = null;
83  if (item != null && item.hasFileSet())
84  {
85    fileSet = item.getFileSet();
86  }
87
88  // Get the current platform/variant
89  // -- if not submitted in URL use values from current item
90  PlatformVariant variant = null;
91  Platform platform = null;
92  boolean deniedPlatform = false;
93  try
94  {
95    if (variantId > 0)
96    {
97      variant = PlatformVariant.getById(dc, variantId);
98      platform = variant.getPlatform();
99    }
100    else if (platformId > 0)
101    {
102      platform = Platform.getById(dc, platformId);
103    }
104    else if (item != null)
105    {
106      variant = item.getVariant();
107      platform = item.getPlatform();
108    }
109  }
110  catch (PermissionDeniedException ex)
111  {
112    deniedPlatform = true; 
113  }
114 
115  // Query to load data file types for specific itemType/platform/variant
116  final ItemQuery<DataFileType> fileTypeQuery = 
117    Base.getDataFileTypes(itemType, platform, variant);
118  List<DataFileType> fileTypes = fileTypeQuery.list(dc);
119 
120  String title = "Select data files for " + 
121    HTML.encodeTags((item instanceof Nameable ? ((Nameable)item).getName() : 
122      (item == null ? " new item" : item.toString())));
123
124  final String clazz = "class=\"text\"";
125  final String requiredClazz = "class=\"text required\"";
126  final StringBuilder sb = new StringBuilder();
127  List<File> recentFiles = null;
128 
129  %>
130<%@page import="net.sf.basedb.core.PlatformFileType"%>
131<base:page type="popup" title="<%=title%>">
132  <base:head scripts="" styles="parameters.css">
133 
134  <script language="JavaScript">
135  function init()
136  {
137  }
138  var lastFileInputName;
139  function browseOnClick(inputName)
140  {
141    var frm = document.forms['datafiles'];
142    var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&callback=setFileCallback';
143    lastFileInputName = inputName;
144    Main.openPopup(url, 'SelectFile', 1000, 700);
145  }
146  function setFileCallback(fileId, path)
147  {
148    var frm = document.forms['datafiles'];
149    frm[lastFileInputName].value = path;
150    fileOnChange(lastFileInputName);
151  }
152  function fileOnChange(inputName)
153  {
154    var frm = document.forms['datafiles'];
155    if (frm[inputName].value != '')
156    {
157      frm['datafiles.validate'].checked = true;
158      frm['datafiles.metadata'].checked = true;
159    }
160  }
161  function recentOnChange(inputName)
162  {
163    var frm = document.forms['datafiles'];
164    var recentInput = frm['recent.'+inputName];
165    if (recentInput.selectedIndex > 0)
166    {
167      var path = recentInput[recentInput.selectedIndex].text;
168      if (frm[inputName].value != path)
169      {
170        frm[inputName].value = path;
171        fileOnChange(inputName);
172      }
173      recentInput.selectedIndex = 0;
174    }
175  }
176  </script>
177  </base:head>
178 
179  <base:body onload="init()" style="background: #E0E0E0;">
180
181    <form name="datafiles">
182    <%
183    if (fileTypes.size() == 0)
184    {
185      %>
186      <div class="error">
187        The <%=platform == null ? "" : "'" + HTML.encodeTags(platform.getName()) + "'" %>
188        platform doesn't define any file types for <%=itemType.toString() %>
189        items.
190      </div>
191      <%
192    }
193    else if (deniedPlatform)
194    {
195      %>
196      <div class="error">Denied</div>
197      <%
198    }
199    else
200    {
201      %>
202      <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%">
203      <%
204      for (DataFileType dft : fileTypes)
205      {
206        PlatformFileType pft = platform == null ?
207          null : platform.getFileType(dft, variant);
208        boolean isRequired = pft == null ? false : pft.isRequired();
209        FileSetMember member = fileSet == null || !fileSet.hasMember(dft) ?
210          null : fileSet.getMember(dft);
211        File file = null;
212        boolean deniedFile = false;
213        if (member != null)
214        {
215          try
216          {
217            file = member.getFile();
218          }
219          catch (PermissionDeniedException ex)
220          {
221            deniedFile = true;
222          }
223        }
224       
225        String path = "";
226        if (file != null)
227        {
228          path = file.getPath().toString();
229        }
230        else if (deniedFile || deniedPlatform)
231        {
232          path = "- denied -";
233        }
234        String inputName= "datafile."+dft.getId();
235        recentFiles = (List<File>)cc.getRecent(dc, Item.FILE, dft.getExternalId());
236        %>
237        <tr>
238          <td class="prompt"><%=HTML.encodeTags(dft.getName())%></td>
239          <td>
240            <table border="0" cellspacing="0" cellpadding="0">
241            <tr>
242              <td>     
243                <input <%=isRequired ? requiredClazz : clazz%> type="text" 
244                name="<%=inputName%>" value="<%=HTML.encodeTags(path)%>"
245                size="50" title="<%=HTML.encodeTags(dft.getDescription())%>"
246                <%=deniedFile || deniedPlatform ? "disabled" : "" %>
247                onchange="fileOnChange('<%=inputName%>')">&nbsp;
248              </td>
249              <td><base:button 
250                  title="Browse&hellip;"
251                  onclick="<%="browseOnClick('"+inputName+"')"%>"
252                  disabled="<%=deniedFile || deniedPlatform %>"
253                  />
254              </td>
255            </tr>
256            </table>
257          </td>
258        </tr>
259        <tr>
260          <td align="right"></td>
261          <td>
262          <%
263          if (recentFiles != null && recentFiles.size() > 0)
264          {
265            %>
266            <select name="recent.<%=inputName%>" onchange="recentOnChange('<%=inputName%>')">
267            <option value="">- recently used -
268            <%
269            for (File recent : recentFiles)
270            {
271              %>
272              <option value="<%=recent.getId()%>"><%=HTML.encodeTags(recent.getPath().toString())%>
273              <%
274            }
275            %>
276            </select>
277            <%
278          }
279          %>
280          </td>
281        </tr>
282        <%
283      }
284      %>
285      <tr>
286        <td class="prompt">Validate</td>
287        <td><input type="checkbox" value="1" name="datafiles.validate"></td>
288      </tr>
289      <tr>
290        <td class="prompt">Extract metadata</td>
291        <td><input type="checkbox" value="1" name="datafiles.metadata"></td>
292      </tr>
293      </table>
294      <%
295    }
296    %>
297
298    </form>
299   
300  </base:body>
301  </base:page>
302  <%
303}
304finally
305{
306  if (dc != null) dc.close();
307}
308%>
Note: See TracBrowser for help on using the repository browser.