source: trunk/www/plugins/net/sf/basedb/clients/web/plugins/simple_export.jsp @ 3077

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

Fixes #431: Multiple tables from the Table taglib on the same HTML page interfere with each other

  • Property svn:eol-style set to native
  • Property svn:keywords set to Date Id
File size: 13.4 KB
Line 
1<%-- $Id: simple_export.jsp 3077 2007-01-22 13:15:31Z nicklas $
2  ------------------------------------------------------------------
3  Copyright (C) Authors contributing to this file.
4
5  This file is part of BASE - BioArray Software Environment.
6  Available at http://base.thep.lu.se/
7
8  BASE is free software; you can redistribute it and/or
9  modify it under the terms of the GNU General Public License
10  as published by the Free Software Foundation; either version 2
11  of the License, or (at your option) any later version.
12
13  BASE is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  GNU General Public License for more details.
17
18  You should have received a copy of the GNU General Public License
19  along with this program; if not, write to the Free Software
20  Foundation, Inc., 59 Temple Place - Suite 330,
21  Boston, MA  02111-1307, USA.
22  ------------------------------------------------------------------
23
24  @author Nicklas
25  @version 2.0
26--%>
27<%@ page 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.util.Enumeration"
33  import="net.sf.basedb.clients.web.Base"
34  import="net.sf.basedb.clients.web.util.HTML"
35  import="net.sf.basedb.util.Values"
36  import="java.util.Set"
37  import="java.util.List"
38 
39%>
40<%@ taglib prefix="base" uri="/WEB-INF/base.tld" %>
41<%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %>
42
43<%
44final SessionControl sc = Base.getExistingSessionControl(pageContext, true);
45final String ID = sc.getId();
46final Item itemType = Item.valueOf(request.getParameter("item_type"));
47final String subContext = Values.getString(request.getParameter("subcontext"), "");
48final ItemContext cc = sc.getCurrentContext(itemType, subContext);
49final String defaultColumns = (String)cc.getObject("defaultColumns");
50String errorMessage = (String)sc.getSessionSetting("plugin.configure.errors.message");
51List<Throwable> errors = (List<Throwable>)sc.getSessionSetting("plugin.configure.errors.list");
52
53%>
54  <base:page type="popup" title="Export">
55  <base:head styles="parameters.css">
56    <script language="JavaScript">
57    // Works as long as we don't have more than one list per page
58    var tableId = window.opener.document.forms[0].name;
59   
60    function init()
61    {
62      updateColumns();
63      if (getSelectedItems().length == 0)
64      {
65        var frm = document.forms['export'];
66        frm['parameter:whichItems'][0].disabled = true;
67        var aSelected = document.getElementById('which.selected');
68        aSelected.href = 'javascript:void(0)';
69        aSelected.disabled = true;
70        Main.addClass(aSelected, 'disabled');
71      }
72    }
73   
74    // Initialise the visible and hidden column lists
75    function initColumns(columns)
76    {
77      var frm = document.forms['export'];
78      var exported = frm.exported;
79      var notExported = frm.not_exported;
80      exported.length = 0;
81      notExported.length = 0;
82
83      var columnDefs = window.opener.Table.getColumnDefs(tableId);
84      // Move all columns into the not exported or exported list
85      var list = columns == 'all' ? exported : notExported;
86      for (var i = 0; i < columnDefs.length; i++) // >
87      {
88        var col = columnDefs[i];
89        if (col.exportable)
90        {
91          var option = new Option(col.title, col.id);
92          list.options[list.options.length] = option;
93        }
94      }
95      if (columns != 'all')
96      {
97        // Scan columns and move back those that should be exported
98        var cols = columns.split(',');
99        for (var ic = 0; ic < cols.length; ic++) // >
100        {
101          var col = columnDefs['id'+cols[ic]];
102          if (col)
103          {
104            for (var ih = 0; ih < notExported.length; ih++) // >
105            {
106              if (col.id == notExported[ih].value)
107              {
108                var option = new Option(col.title, col.id);
109                exported[exported.length] = option;
110                notExported[ih] = null;
111                ih = notExported.length;
112              }
113            }
114          }
115        }
116      }
117    }
118
119    // Moves all selected items in list1 to list2
120    function moveBetween(list1, list2)
121    {
122      var moved = 0;
123      for(i=0; i < list1.options.length; i++) // >
124      {
125        if (list1.options[i].selected)
126        {
127          moved++;
128          list2.options[list2.options.length] = new Option(list1.options[i].text, list1.options[i].value, false, true);
129          list1.options[i] = null;
130          i--;
131        }
132      }
133      if (moved > 0) clearPreset();
134    }
135   
136    // Move all selected items in the list up or down
137    function moveSelected(list, up)
138    {
139      var moved = Forms.moveListOptions(list, up);
140      if (moved > 0) clearPreset();
141    }
142   
143    // Sets the preset selection list to the first (empty) element
144    function clearPreset()
145    {
146      var frm = document.forms['export'];
147      frm.presets.selectedIndex = 0;
148    }
149   
150    // Update the settings according to the selection in the presets list
151    function updateColumns()
152    {
153      var frm = document.forms['export'];
154      var presets = frm.presets;
155      var columns = presets.options[presets.selectedIndex].value;
156      if (columns == '') return;
157      if (columns == '_default_') columns = '<%=defaultColumns%>';
158      if (columns == '_current_') columns = window.opener.Table.getColumns(tableId);
159      initColumns(columns);
160    }
161    // Get the "exportProperty" of all exported columns as an array
162    function getExportedColumnProperties()
163    {
164      var list = document.forms['export'].exported;
165      var columnDefs = window.opener.Table.getColumnDefs(tableId);
166      var selected = new Array();
167      for (i = 0; i < list.options.length; i++) // >
168      {
169        selected[selected.length] = columnDefs['id'+list.options[i].value].exportProperty;
170      }
171      return selected;
172    }
173    // Get the "title" of all exported columns as an array
174    function getExportedColumnTitles()
175    {
176      var list = document.forms['export'].exported;
177      var columnDefs = window.opener.Table.getColumnDefs(tableId);
178      var selected = new Array();
179      for (i = 0; i < list.options.length; i++) // >
180      {
181        selected[selected.length] = columnDefs['id'+list.options[i].value].title;
182      }
183      return selected;
184    }
185    // Get the ID:s of all selected items
186    var selectedItems;
187    function getSelectedItems()
188    {
189      if (!selectedItems)
190      {
191        selectedItems = window.opener.Table.getSelected(tableId);
192      }
193      return selectedItems;
194    }
195    function checkRadio(radio, name)
196    {
197      Forms.checkRadio(radio, name);
198    }
199    function doExport()
200    {
201      var frm = document.forms['export'];
202      var exportedProperties = getExportedColumnProperties();
203      var exportedTitles = getExportedColumnTitles();
204      if (exportedProperties.length == 0)
205      {
206        alert('You must select at least one column to export');
207        return;
208      }
209      for (var i = 0; i < exportedProperties.length; i++)
210      {
211        var value = exportedProperties[i] + ':' + exportedTitles[i];
212        Forms.createHidden(frm, 'parameter:whichProperties', value);
213      }
214      if (Forms.getCheckedRadio(frm['parameter:whichItems']).value == 'selected')
215      {
216        var selectedItems = getSelectedItems();
217        for (var i = 0; i < selectedItems.length; i++)
218        {
219          Forms.createHidden(frm, 'parameter:item', selectedItems[i]);
220        }
221      }
222      if (frm.path.value != '')
223      {
224        Forms.createHidden(frm, 'parameter:saveAs', frm.path.value);
225      }
226      frm.submit();
227    }
228    function browseOnClick()
229    {
230      Main.openPopup(getRoot()+'filemanager/save_as.jsp?ID=<%=ID%>&callback=setFileCallback', 'SaveAs', 1000, 700);
231    }
232    function setFileCallback(path)
233    {
234      var frm = document.forms['export'];
235      frm['path'].value = path;
236    }
237    function hideErrorList()
238    {
239      Main.hide('errorlist');
240      Main.show('showerrorlist');
241    }
242    function showErrorList()
243    {
244      Main.show('errorlist');
245      Main.hide('showerrorlist');
246    }
247    </script>
248  </base:head>
249  <base:body onload="init()">
250    <form name="export" action="index.jsp" method="get" onsubmit="return false;">
251    <input type="hidden" name="ID" value="<%=ID%>">
252    <input type="hidden" name="cmd" value="SetParameters">
253    <input type="hidden" name="item_type" value="<%=itemType.name()%>">
254    <input type="hidden" name="subcontext" value="<%=subContext == null ? "" : subContext%>">
255   
256    <h3 class="docked">Export options <base:help helpid="simpleexport.options" /></h3>
257    <div class="boxed">
258   
259    <%
260    if (errorMessage != null || (errors != null && errors.size() > 0))
261    {
262      %>
263      <div id="errors" style="margin-bottom: 12px;" class="parameterhelp">
264        <div class="error" style="margin: 0px;">
265        <%=errorMessage %>
266        </div>
267        <%
268        if (errors != null && errors.size() > 0)
269        {
270          %>
271          <div id="showerrorlist" style="display: none;">
272            <base:icon image="bullet.gif" /><a href="javascript:showErrorList()">Show details</a>
273          </div>
274          <div id="errorlist">
275          <ol>
276          <%
277          for (Throwable t : errors)
278          {
279            %>
280            <li><%=t.getMessage()%><br>
281            <%
282          }
283          %>
284          </ol>
285          <base:icon image="bullet.gif" /><a href="javascript:hideErrorList()">Hide details</a>
286          </div>
287          <%
288        }
289        %>
290      </div>
291      <%
292    }
293    %>
294      <table class="form" width="100%">
295      <tr valign="top">
296        <td class="prompt">Format</td>
297        <td>
298          <input type="radio" name="parameter:format" value="text" checked><a 
299            href="javascript:checkRadio(document.forms['export']['parameter:format'], 'text');"
300            >Tab-separated text file</a><br>
301          <input type="radio" name="parameter:format" value="xml"><a 
302            href="javascript:checkRadio(document.forms['export']['parameter:format'], 'xml');"
303            >XML</a><br>
304        </td>
305      </tr>
306      <tr valign="top">
307        <td class="prompt">Which items?</td>
308        <td>
309          <input type="radio" name="parameter:whichItems" value="selected"><a 
310            id="which.selected"
311            href="javascript:checkRadio(document.forms['export']['parameter:whichItems'], 'selected');"
312            >Selected items</a><br>
313          <input type="radio" name="parameter:whichItems" value="page"><a 
314            href="javascript:checkRadio(document.forms['export']['parameter:whichItems'], 'page');"
315            >Current page</a><br>
316          <input type="radio" name="parameter:whichItems" value="all" checked><a 
317            href="javascript:checkRadio(document.forms['export']['parameter:whichItems'], 'all');"
318            >All pages</a><br>
319        </td>
320      </tr>
321      <tr valign="top">
322        <td class="prompt">
323          Which columns?<br>
324          <select name="presets" onChange="updateColumns()">
325            <option>
326            <option value="all" title="Export all columns">All
327            <option value="_current_" title="Export the currently visible columns" selected>Current
328            <%
329            if (defaultColumns != null)
330            {
331              %>
332              <option value="_default_" title="Export the default visible columns">Default
333              <%
334            }
335            Enumeration<Integer, String> contexts = sc.getContextNames(itemType, subContext);
336            for (int i = 0; i < contexts.size(); ++i)
337            {
338              ItemContext context = sc.getContext(contexts.getKey(i));
339              if (context != null && !ItemContext.DEFAULT_NAME.equals(context.getName()))
340              {
341                String columns = context.getSetting("columns");
342                %>
343                <option value="<%=columns%>"><%=HTML.encodeTags(context.getName())%>
344                <%
345              }
346            }
347            %>
348          </select>
349          <br>
350          <table align="right">
351          <tr>
352          <td>
353            <base:button
354              onclick="moveSelected(document.forms['export'].exported, false)" 
355              title="<img src='../../images/move_up.gif' alt='' style='vertical-align: middle;'>" 
356              tooltip="Move up" 
357            /><p>
358            <base:button 
359              onclick="moveSelected(document.forms['export'].exported, true)" 
360              title="<img src='../../images/move_down.gif' alt='' style='vertical-align: middle;'>" 
361              tooltip="Move down" 
362            />
363          </td>
364          </tr>
365          </table>
366        </td>
367        <td>
368          <table border=0 cellspacing=0 cellpadding=2 width="100%">
369          <tr>
370            <td width="50%">
371              <b>Exported columns</b><br>
372              <select name="exported" multiple size=10 style="width: 100%;"
373                ondblclick="moveBetween(document.forms['export'].exported, document.forms['export'].not_exported)">
374              </select>
375            </td>
376       
377            <td>
378              <br>
379              <base:button
380                onclick="moveBetween(document.forms['export'].not_exported, document.forms['export'].exported)" 
381                title="<img src='../../images/move_left.gif' alt='' style='vertical-align: middle;'>" 
382                tooltip="Make the selected hidden column(s) visible" 
383              /><p>
384              <base:button 
385                onclick="moveBetween(document.forms['export'].exported, document.forms['export'].not_exported)" 
386                title="<img src='../../images/move_right.gif' alt='' style='vertical-align: middle;'>" 
387                tooltip="Make the selected visible column(s) hidden" 
388              />
389              <br>
390            </td>
391            <td width="50%">
392              <b>Not exported</b><br>
393              <select name="not_exported" multiple size=10 style="width: 100%;" 
394                ondblclick="moveBetween(document.forms['export'].not_exported, document.forms['export'].exported)">
395              </select>
396            </td>
397          </tr>
398          </table>
399        </td>
400      </tr>
401      <tr valign="top">
402        <td class="prompt">Save as</td>
403        <td>
404          <table>
405          <tr>
406          <td><input type="text" class="text" name="path" size="50" value=""><br>
407          Leave empty to download immediately</td>
408          <td><base:button 
409              title="Browse..."
410              onclick="browseOnClick()"
411              />
412          </td>
413          </tr>
414          </table>
415          <input type="checkbox" name="parameter:overwrite" value="true">
416            <a href="javascript:Forms.toggleCheckbox(document.forms['export']['parameter:overwrite'])">Overwrite existing file</a><br>
417        </td>
418      </tr>
419      </table>
420    </div>
421    </form>
422 
423    <table align="center">
424    <tr>
425      <td width="50%"><base:button onclick="doExport();" title="Ok" /></td>
426      <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td>
427    </tr>
428    </table>
429  </base:body>
430  </base:page>
431
Note: See TracBrowser for help on using the repository browser.