1 | <%-- $Id: configure.jsp 2978 2006-11-30 07:27:42Z 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 | Configure the order and visibility of columns in a table of items. |
---|
25 | This page will use the TableColumn.getTableColumns(item) to retreive the |
---|
26 | list of all available columns for that item type and |
---|
27 | getSession().getSetting(item+".columns") to retreive a comma-separated |
---|
28 | list of the current order of visible columns. |
---|
29 | |
---|
30 | @param item The type of items in the table |
---|
31 | |
---|
32 | @author Nicklas |
---|
33 | @version 2.0 |
---|
34 | --%> |
---|
35 | <%@ page session="false" |
---|
36 | import="net.sf.basedb.core.SessionControl" |
---|
37 | import="net.sf.basedb.core.Item" |
---|
38 | import="net.sf.basedb.core.ItemContext" |
---|
39 | import="net.sf.basedb.util.Enumeration" |
---|
40 | import="net.sf.basedb.clients.web.util.HTML" |
---|
41 | import="net.sf.basedb.util.Values" |
---|
42 | import="net.sf.basedb.clients.web.Base" |
---|
43 | import="java.util.Set" |
---|
44 | import="java.util.TreeSet" |
---|
45 | %> |
---|
46 | <%@ taglib prefix="base" uri="/WEB-INF/base.tld" %> |
---|
47 | <%@ taglib prefix="t" uri="/WEB-INF/tab.tld" %> |
---|
48 | |
---|
49 | <% |
---|
50 | final SessionControl sc = Base.getExistingSessionControl(pageContext, true); |
---|
51 | final String ID = sc.getId(); |
---|
52 | final Item itemType = Item.valueOf(request.getParameter("item_type")); |
---|
53 | final String subContext = Values.getString(request.getParameter("subcontext"), ""); |
---|
54 | final String tableId = request.getParameter("table_id"); |
---|
55 | final String defaultColumns = request.getParameter("default"); |
---|
56 | |
---|
57 | %> |
---|
58 | <base:page type="popup" title="Set column order and visibility"> |
---|
59 | <base:head> |
---|
60 | <script language="JavaScript"> |
---|
61 | |
---|
62 | // Initialise the visible and hidden column lists |
---|
63 | function initColumns(columns) |
---|
64 | { |
---|
65 | var frm = document.forms['columns']; |
---|
66 | var visible = frm.visible; |
---|
67 | var hidden = frm.hidden; |
---|
68 | visible.length = 0; |
---|
69 | hidden.length = 0; |
---|
70 | |
---|
71 | // The visibled columns (comma-separated) |
---|
72 | var allVisible = columns == 'all'; |
---|
73 | var visibleCols = columns.split(','); |
---|
74 | |
---|
75 | // All column definitions |
---|
76 | var columnDefs = window.opener.Table.columns; |
---|
77 | |
---|
78 | // Put all column in the hidden or visible list |
---|
79 | var toList = allVisible ? visible : hidden; |
---|
80 | for (var i = 0; i < columnDefs.length; i++) |
---|
81 | { |
---|
82 | var col = columnDefs[i]; |
---|
83 | if (!col.alwaysHide) addCol(toList, col); |
---|
84 | } |
---|
85 | |
---|
86 | // Move visible columns to the visible list |
---|
87 | if (!allVisible) |
---|
88 | { |
---|
89 | for (var i = 0; i < visibleCols.length; i++) |
---|
90 | { |
---|
91 | var colId = visibleCols[i]; |
---|
92 | var col = columnDefs['id'+colId]; |
---|
93 | for (var j = 0; j < hidden.length; j++) |
---|
94 | { |
---|
95 | if (hidden[j].value == colId) |
---|
96 | { |
---|
97 | addCol(visible, col); |
---|
98 | hidden[j] = null; |
---|
99 | j = hidden.length; |
---|
100 | } |
---|
101 | } |
---|
102 | } |
---|
103 | |
---|
104 | // Move columns that must be visible to the visible list |
---|
105 | for (var i = 0; i < hidden.length; i++) |
---|
106 | { |
---|
107 | var col = columnDefs['id'+hidden.options[i].value]; |
---|
108 | if (col && col.alwaysShow) |
---|
109 | { |
---|
110 | addCol(visible, col); |
---|
111 | hidden[i] = null; |
---|
112 | i--; |
---|
113 | } |
---|
114 | } |
---|
115 | } |
---|
116 | } |
---|
117 | |
---|
118 | function addCol(toList, col) |
---|
119 | { |
---|
120 | var option = new Option(col.title, col.id); |
---|
121 | if (col.alwaysShow) |
---|
122 | { |
---|
123 | option.style.fontWeight = 'bold'; |
---|
124 | option.text = option.text+' ×'; |
---|
125 | } |
---|
126 | toList[toList.length] = option; |
---|
127 | } |
---|
128 | |
---|
129 | // Moves all selected items in list1 to list2 |
---|
130 | function moveBetween(list1, list2) |
---|
131 | { |
---|
132 | var moved = 0; |
---|
133 | var columnDefs = window.opener.Table.columns; |
---|
134 | for(i=0; i < list1.options.length; i++) // > |
---|
135 | { |
---|
136 | if (list1.options[i].selected) |
---|
137 | { |
---|
138 | var col = columnDefs['id'+list1.options[i].value]; |
---|
139 | if (col.alwaysShow) |
---|
140 | { |
---|
141 | alert("'" + col.title + "' must always be visible"); |
---|
142 | } |
---|
143 | else |
---|
144 | { |
---|
145 | moved++; |
---|
146 | list2.options[list2.options.length] = new Option(list1.options[i].text, list1.options[i].value, false, true); |
---|
147 | list1.options[i] = null; |
---|
148 | i--; |
---|
149 | } |
---|
150 | } |
---|
151 | } |
---|
152 | if (moved > 0) clearPreset(); |
---|
153 | } |
---|
154 | |
---|
155 | // Move all selected items in the list up or down |
---|
156 | function moveSelected(list, up) |
---|
157 | { |
---|
158 | var moved = Forms.moveListOptions(list, up); |
---|
159 | if (moved > 0) clearPreset(); |
---|
160 | } |
---|
161 | |
---|
162 | // Sets the preset selection list to the first (empty) element |
---|
163 | function clearPreset() |
---|
164 | { |
---|
165 | var frm = document.forms['columns']; |
---|
166 | frm.presets.selectedIndex = 0; |
---|
167 | } |
---|
168 | |
---|
169 | // Update the settings according to the selection in the presets list |
---|
170 | function updateColumns() |
---|
171 | { |
---|
172 | var frm = document.forms['columns']; |
---|
173 | var presets = frm.presets; |
---|
174 | var columns = presets.options[presets.selectedIndex].value; |
---|
175 | if (columns == '') return; |
---|
176 | if (columns == '_default_') columns = '<%=defaultColumns%>'; |
---|
177 | if (columns == '_current_') columns = window.opener.Table.getColumns('<%=tableId%>'); |
---|
178 | if (columns == '_minimal_') |
---|
179 | { |
---|
180 | var columnDefs = window.opener.Table.columns; |
---|
181 | var temp = new Array(); |
---|
182 | for (var i = 0; i < columnDefs.length; i++) // > |
---|
183 | { |
---|
184 | var col = columnDefs[i]; |
---|
185 | var option = new Option(col.title, col.id); |
---|
186 | if (col.alwaysShow) temp[temp.length] = col.id; |
---|
187 | } |
---|
188 | columns = temp.join(','); |
---|
189 | } |
---|
190 | initColumns(columns); |
---|
191 | } |
---|
192 | |
---|
193 | function savePresetAs() |
---|
194 | { |
---|
195 | var selected = getVisibleColumns(); |
---|
196 | Main.openPopup('save_preset.jsp?ID=<%=ID%>&item_type=<%=itemType.name()%>&subcontext=<%=subContext%>&columns='+selected, 'SavePreset', 360, 200); |
---|
197 | } |
---|
198 | |
---|
199 | // Save the configuration to the parent window |
---|
200 | function saveColumns() |
---|
201 | { |
---|
202 | var selected = getVisibleColumns() |
---|
203 | window.opener.Table.setColumns('<%=tableId%>', selected); |
---|
204 | window.close(); |
---|
205 | } |
---|
206 | |
---|
207 | // Get all visible columns as a comma-separated string |
---|
208 | function getVisibleColumns() |
---|
209 | { |
---|
210 | var list = document.forms['columns'].visible; |
---|
211 | var selected = ''; |
---|
212 | for (var i = 0; i < list.options.length; i++) |
---|
213 | { |
---|
214 | if (i > 0) selected += ','; |
---|
215 | selected += list.options[i].value; |
---|
216 | } |
---|
217 | return selected; |
---|
218 | } |
---|
219 | </script> |
---|
220 | </base:head> |
---|
221 | <base:body onload="<%="initColumns(window.opener.Table.getColumns('"+tableId+"'))"%>"> |
---|
222 | <form name="columns" onsubmit="return false;"> |
---|
223 | |
---|
224 | <h3 class="docked">Set column order and visiblity <base:help helpid="columns.configure" /></h3> |
---|
225 | <div class="boxed" align="center"> |
---|
226 | <table border=0 cellspacing=0 cellpadding=2 width="100%"> |
---|
227 | <tr> |
---|
228 | <td style="vertical-align: middle"> |
---|
229 | <br> |
---|
230 | <base:button |
---|
231 | onclick="moveSelected(document.forms['columns'].visible, false)" |
---|
232 | title="<img src='../../images/move_up.gif' alt='' style='vertical-align: middle;'>" |
---|
233 | tooltip="Move up" |
---|
234 | /><p> |
---|
235 | <base:button |
---|
236 | onclick="moveSelected(document.forms['columns'].visible, true)" |
---|
237 | title="<img src='../../images/move_down.gif' alt='' style='vertical-align: middle;'>" |
---|
238 | tooltip="Move down" |
---|
239 | /> |
---|
240 | <br> |
---|
241 | </td> |
---|
242 | |
---|
243 | <td width="50%"> |
---|
244 | <b>Visible columns</b><br> |
---|
245 | <select name="visible" multiple size="14" style="width: 100%;" |
---|
246 | ondblclick="moveBetween(document.forms['columns'].visible, document.forms['columns'].hidden)"> |
---|
247 | </select> |
---|
248 | </td> |
---|
249 | |
---|
250 | <td style="vertical-align: middle"> |
---|
251 | <br> |
---|
252 | <base:button |
---|
253 | onclick="moveBetween(document.forms['columns'].hidden, document.forms['columns'].visible)" |
---|
254 | title="<img src='../../images/move_left.gif' alt='' style='vertical-align: middle;'>" |
---|
255 | tooltip="Make the selected hidden column(s) visible" |
---|
256 | /><p> |
---|
257 | <base:button |
---|
258 | onclick="moveBetween(document.forms['columns'].visible, document.forms['columns'].hidden)" |
---|
259 | title="<img src='../../images/move_right.gif' alt='' style='vertical-align: middle;'>" |
---|
260 | tooltip="Make the selected visible column(s) hidden" |
---|
261 | /> |
---|
262 | <br> |
---|
263 | </td> |
---|
264 | |
---|
265 | <td width="50%"> |
---|
266 | <b>Hidden columns</b><br> |
---|
267 | <select name="hidden" multiple size="14" style="width: 100%;" |
---|
268 | ondblclick="moveBetween(document.forms['columns'].hidden, document.forms['columns'].visible)"> |
---|
269 | </select> |
---|
270 | </td> |
---|
271 | </tr> |
---|
272 | <tr> |
---|
273 | <td> </td> |
---|
274 | <td colspan="3"> |
---|
275 | <div align="right"> |
---|
276 | <b>×</b> = This column cannot be hidden |
---|
277 | </div> |
---|
278 | <center> |
---|
279 | <table> |
---|
280 | <tr> |
---|
281 | <td> |
---|
282 | <b>Presets</b><br> |
---|
283 | <select name="presets" onChange="updateColumns()"> |
---|
284 | <option value="">-- predefined -- |
---|
285 | <option value="all">All |
---|
286 | <option value="_minimal_">Required |
---|
287 | <option value="_current_">Current |
---|
288 | <% |
---|
289 | if (defaultColumns != null) |
---|
290 | { |
---|
291 | %> |
---|
292 | <option value="_default_">Default |
---|
293 | <% |
---|
294 | } |
---|
295 | %> |
---|
296 | <option value="">-- user defined -- |
---|
297 | <% |
---|
298 | Enumeration<Integer, String> contexts = sc.getContextNames(itemType, subContext); |
---|
299 | for (int i = 0; i < contexts.size(); ++i) |
---|
300 | { |
---|
301 | ItemContext context = sc.getContext(contexts.getKey(i)); |
---|
302 | if (context != null && !ItemContext.DEFAULT_NAME.equals(context.getName())) |
---|
303 | { |
---|
304 | String columns = context.getSetting("columns"); |
---|
305 | %> |
---|
306 | <option value="<%=columns%>"><%=HTML.encodeTags(context.getName())%> |
---|
307 | <% |
---|
308 | } |
---|
309 | } |
---|
310 | %> |
---|
311 | </select> |
---|
312 | </td> |
---|
313 | <% |
---|
314 | if (request.getParameter("nosavedelete") == null) |
---|
315 | { |
---|
316 | %> |
---|
317 | <td><br><base:button onclick="savePresetAs();" title="Save as…" /></td> |
---|
318 | <% |
---|
319 | } |
---|
320 | %> |
---|
321 | </tr> |
---|
322 | </table> |
---|
323 | </center> |
---|
324 | </td> |
---|
325 | </tr> |
---|
326 | </table> |
---|
327 | </div> |
---|
328 | </form> |
---|
329 | <table align="center"> |
---|
330 | <tr> |
---|
331 | <td width="50%"><base:button onclick="saveColumns();" title="Ok" /></td> |
---|
332 | <td width="50%"><base:button onclick="window.close();" title="Cancel" /></td> |
---|
333 | </tr> |
---|
334 | </table> |
---|
335 | </base:body> |
---|
336 | </base:page> |
---|
337 | |
---|