source: branches/filedb/www/common/datafiles/select_files.jsp @ 3801

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

References #721: It is now possible to select files for an array design

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 6.1 KB
Line 
1<%-- $Id: select_files.jsp 3801 2007-10-02 07:12:24Z 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.Type"
32  import="net.sf.basedb.core.BasicItem"
33  import="net.sf.basedb.core.Permission"
34  import="net.sf.basedb.core.Nameable"
35  import="net.sf.basedb.core.FileStoreEnabled"
36  import="net.sf.basedb.core.FileSet"
37  import="net.sf.basedb.core.FileSetMember"
38  import="net.sf.basedb.core.File"
39  import="net.sf.basedb.core.Platform"
40  import="net.sf.basedb.core.PlatformVariant"
41  import="net.sf.basedb.core.PlatformFileType"
42  import="net.sf.basedb.core.DataFileType"
43  import="net.sf.basedb.core.ItemQuery"
44  import="net.sf.basedb.core.Include"
45  import="net.sf.basedb.core.ItemResultList"
46  import="net.sf.basedb.core.PermissionDeniedException"
47  import="net.sf.basedb.core.query.Expressions"
48  import="net.sf.basedb.core.query.Restrictions"
49  import="net.sf.basedb.core.query.Hql"
50  import="net.sf.basedb.core.query.Orders"
51  import="net.sf.basedb.clients.web.Base"
52  import="net.sf.basedb.clients.web.util.HTML"
53  import="net.sf.basedb.util.formatter.Formatter"
54  import="net.sf.basedb.clients.web.formatter.FormatterFactory"
55  import="net.sf.basedb.clients.web.formatter.FormatterSettings"
56  import="net.sf.basedb.util.Values"
57  import="java.util.ArrayList"
58  import="java.util.List"
59  import="java.util.Date"
60  import="java.util.Set"
61  import="java.util.HashSet"
62  import="java.util.TreeSet"
63%>
64<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
65<%
66final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
67final String ID = sc.getId();
68final float scale = Base.getScale(sc);
69final Item itemType = Item.valueOf(request.getParameter("item_type"));
70final int itemId = Values.getInt(request.getParameter("item_id"));
71final int platformId = Values.getInt(request.getParameter("platform_id"), -1);
72final int variantId = Values.getInt(request.getParameter("variant_id"), -1);
73
74final DbControl dc = sc.newDbControl();
75try
76{
77
78  // Get the current item; null if we are editing a new item
79  final FileStoreEnabled item = itemId == 0 ? null : (FileStoreEnabled)itemType.getById(dc, itemId);
80  FileSet fileSet = null;
81  if (item != null && item.hasFileSet())
82  {
83    fileSet = item.getFileSet();
84  }
85
86  // Get the current platform/variant
87  // -- if not submitted in URL use values from current item
88  PlatformVariant variant = null;
89  Platform platform = null;
90 
91  if (variantId > 0)
92  {
93    variant = PlatformVariant.getById(dc, variantId);
94    platform = variant.getPlatform();
95  }
96  else if (platformId > 0)
97  {
98    platform = Platform.getById(dc, platformId);
99  }
100  else if (item != null)
101  {
102    variant = item.getVariant();
103    platform = item.getPlatform();
104  }
105 
106  // Query to load data file types for specific itemType/platform/variant
107  final ItemQuery<DataFileType> fileTypeQuery = 
108    Base.getDataFileTypes(itemType, platform, variant);
109  List<DataFileType> fileTypes = fileTypeQuery.list(dc);
110 
111 
112  String title = "Select data files for " + 
113    HTML.encodeTags((item instanceof Nameable ? ((Nameable)item).getName() : 
114      (item == null ? " new item" : item.toString())));
115
116  final String clazz = "class=\"text\"";
117  final String requiredClazz = "class=\"text required\"";
118  final StringBuilder sb = new StringBuilder();
119  List<File> recentFiles = null;
120  %>
121<%@page import="net.sf.basedb.core.PlatformFileType"%>
122<base:page type="popup" title="<%=title%>">
123  <base:head scripts="" styles="parameters.css">
124 
125  <script language="JavaScript">
126  function init()
127  {
128  }
129  var lastFileInputName;
130  function browseOnClick(inputName)
131  {
132    var frm = document.forms['datafiles'];
133    var url = '../../filemanager/index.jsp?ID=<%=ID%>&cmd=SelectOne&callback=setFileCallback';
134    lastFileInputName = inputName;
135    Main.openPopup(url, 'SelectFile', 1000, 700);
136  }
137  function setFileCallback(fileId, path)
138  {
139    var frm = document.forms['datafiles'];
140    frm[lastFileInputName].value = path;
141  }
142  </script>
143  </base:head>
144 
145  <base:body onload="init()" style="background: #E0E0E0;">
146
147    <form name="datafiles">
148    <table class="form" cellspacing="2" border="0" cellpadding="0" width="100%">
149    <%
150    for (DataFileType dft : fileTypes)
151    {
152      PlatformFileType pft = platform == null ?
153      null : platform.getFileType(dft, variant);
154      boolean isRequired = pft == null ? false : pft.isRequired();
155      FileSetMember member = fileSet == null || !fileSet.hasMember(dft) ?
156        null : fileSet.getMember(dft);
157      File file = member == null ? null : member.getFile();
158      String path = file == null ? "" : file.getPath().toString();
159      String inputName= "datafile."+dft.getId();
160      %>
161      <tr>
162        <td class="prompt"><%=HTML.encodeTags(dft.getName())%></td>
163        <td>
164          <table border="0" cellspacing="0" cellpadding="0">
165          <tr>
166            <td><input <%=isRequired ? requiredClazz : clazz%> type="text" 
167              name="<%=inputName%>" value="<%=HTML.encodeTags(path)%>"
168              size="50" title="<%=HTML.encodeTags(dft.getDescription())%>">&nbsp;</td>
169            <td><base:button 
170                title="Browse&hellip;"
171                onclick="<%="browseOnClick('"+inputName+"')"%>"
172                />
173            </td>
174          </tr>
175          </table>
176        </td>
177      </tr>
178      <%
179    }
180    %>
181    </table>
182
183    </form>
184   
185  </base:body>
186  </base:page>
187  <%
188}
189finally
190{
191  if (dc != null) dc.close();
192}
193%>
Note: See TracBrowser for help on using the repository browser.