2306 |
22 May 06 |
jari |
/* $Id$ |
417 |
19 Apr 05 |
nicklas |
2 |
------------------------------------------------------------------ |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2005 Nicklas Nordborg |
4889 |
06 Apr 09 |
nicklas |
Copyright (C) 2006 Jari Häkkinen, Nicklas Nordborg, Martin Svensson, Gregory Vincic |
3675 |
16 Aug 07 |
jari |
Copyright (C) 2007 Johan Enell, Nicklas Nordborg |
417 |
19 Apr 05 |
nicklas |
6 |
|
2304 |
22 May 06 |
jari |
This file is part of BASE - BioArray Software Environment. |
2304 |
22 May 06 |
jari |
Available at http://base.thep.lu.se/ |
417 |
19 Apr 05 |
nicklas |
9 |
|
417 |
19 Apr 05 |
nicklas |
BASE is free software; you can redistribute it and/or |
417 |
19 Apr 05 |
nicklas |
modify it under the terms of the GNU General Public License |
4476 |
05 Sep 08 |
jari |
as published by the Free Software Foundation; either version 3 |
417 |
19 Apr 05 |
nicklas |
of the License, or (at your option) any later version. |
417 |
19 Apr 05 |
nicklas |
14 |
|
417 |
19 Apr 05 |
nicklas |
BASE is distributed in the hope that it will be useful, |
417 |
19 Apr 05 |
nicklas |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
417 |
19 Apr 05 |
nicklas |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
417 |
19 Apr 05 |
nicklas |
GNU General Public License for more details. |
417 |
19 Apr 05 |
nicklas |
19 |
|
417 |
19 Apr 05 |
nicklas |
You should have received a copy of the GNU General Public License |
4510 |
11 Sep 08 |
jari |
along with BASE. If not, see <http://www.gnu.org/licenses/>. |
417 |
19 Apr 05 |
nicklas |
22 |
------------------------------------------------------------------ |
417 |
19 Apr 05 |
nicklas |
23 |
|
417 |
19 Apr 05 |
nicklas |
JavaScript functions for the Table taglib. |
417 |
19 Apr 05 |
nicklas |
25 |
|
417 |
19 Apr 05 |
nicklas |
@author Nicklas |
417 |
19 Apr 05 |
nicklas |
@version 2.0 |
417 |
19 Apr 05 |
nicklas |
28 |
*/ |
7419 |
03 Nov 17 |
nicklas |
'use strict'; |
7419 |
03 Nov 17 |
nicklas |
30 |
|
6182 |
23 Oct 12 |
nicklas |
var Table = function() |
417 |
19 Apr 05 |
nicklas |
32 |
{ |
6183 |
24 Oct 12 |
nicklas |
// Hold parsed column definitions -- initialized lazily when Table.getColumnDefs is called |
6183 |
24 Oct 12 |
nicklas |
var columnDefs = []; |
417 |
19 Apr 05 |
nicklas |
35 |
|
6182 |
23 Oct 12 |
nicklas |
var table = {}; |
6182 |
23 Oct 12 |
nicklas |
var internal = {}; |
6182 |
23 Oct 12 |
nicklas |
38 |
|
417 |
19 Apr 05 |
nicklas |
39 |
/** |
6182 |
23 Oct 12 |
nicklas |
Initialize all control elements in the table, such as |
6182 |
23 Oct 12 |
nicklas |
sorting, filtering, pageing, etc. |
6182 |
23 Oct 12 |
nicklas |
42 |
*/ |
6182 |
23 Oct 12 |
nicklas |
internal.initTable = function(element, autoInit) |
6182 |
23 Oct 12 |
nicklas |
44 |
{ |
6182 |
23 Oct 12 |
nicklas |
if (autoInit != 'table') return; |
6182 |
23 Oct 12 |
nicklas |
var tableId = element.id; |
6182 |
23 Oct 12 |
nicklas |
var tableFrm = document.forms[tableId]; |
6220 |
10 Jan 13 |
nicklas |
var itemType = Data.get(element, 'item-type'); |
6220 |
10 Jan 13 |
nicklas |
var attributes = {'table-id': tableId, 'item-type': itemType}; |
6182 |
23 Oct 12 |
nicklas |
50 |
|
7894 |
08 Dec 20 |
nicklas |
// Set flag to enable 'please wait...' overlay if re-loading takes time |
7894 |
08 Dec 20 |
nicklas |
Data.set(tableFrm, 'enable-please-wait', 1000); // Display a message after 1s |
7894 |
08 Dec 20 |
nicklas |
53 |
|
6182 |
23 Oct 12 |
nicklas |
// Add 'click' handler to page navigator |
6182 |
23 Oct 12 |
nicklas |
// A single handler is added to the main div and relies |
6182 |
23 Oct 12 |
nicklas |
// on event bubbling from the actual targets |
6183 |
24 Oct 12 |
nicklas |
var navigator = element.getElementsByClassName('table-navigator'); |
6183 |
24 Oct 12 |
nicklas |
for (var i = 0; i < navigator.length; i++) |
6183 |
24 Oct 12 |
nicklas |
59 |
{ |
6183 |
24 Oct 12 |
nicklas |
Events.addEventHandler(navigator[i], 'click', Table.navigatorOnClick); |
6183 |
24 Oct 12 |
nicklas |
61 |
} |
6182 |
23 Oct 12 |
nicklas |
62 |
|
6182 |
23 Oct 12 |
nicklas |
// Limit the 'rowsperpage' field to numbers and submit the form if ENTER is pressed |
6182 |
23 Oct 12 |
nicklas |
var rowsPerPage = tableFrm.rowsperpage; |
6197 |
02 Nov 12 |
nicklas |
if (rowsPerPage) |
6197 |
02 Nov 12 |
nicklas |
66 |
{ |
6197 |
02 Nov 12 |
nicklas |
Events.addEventHandler(rowsPerPage, 'keypress', Events.integerOnly); |
6197 |
02 Nov 12 |
nicklas |
Events.doOnEnter(rowsPerPage, Forms.submit); |
6197 |
02 Nov 12 |
nicklas |
69 |
} |
6182 |
23 Oct 12 |
nicklas |
70 |
|
6182 |
23 Oct 12 |
nicklas |
// Add event handler for the 'view/preset' selection list |
6183 |
24 Oct 12 |
nicklas |
// and icons for clearing the filter and show hidden columns with a filter |
6197 |
02 Nov 12 |
nicklas |
if (tableFrm.presetselector) |
6197 |
02 Nov 12 |
nicklas |
74 |
{ |
6220 |
10 Jan 13 |
nicklas |
Events.addEventHandler(tableFrm.presetselector, 'change', table.presetOnChange); |
6220 |
10 Jan 13 |
nicklas |
Events.addEventHandler(tableId+'.clearfilter', 'click', table.clearFilterOnClick, attributes); |
6220 |
10 Jan 13 |
nicklas |
Events.addEventHandler(tableId+'.showcolumns', 'click', table.showColumnsOnClick, attributes); |
6197 |
02 Nov 12 |
nicklas |
78 |
} |
6182 |
23 Oct 12 |
nicklas |
79 |
|
6182 |
23 Oct 12 |
nicklas |
// Add 'click' handlers to column headers for sorting |
6182 |
23 Oct 12 |
nicklas |
var sort = element.getElementsByClassName('table-sort'); |
6182 |
23 Oct 12 |
nicklas |
for (var i = 0; i < sort.length; i++) |
6182 |
23 Oct 12 |
nicklas |
83 |
{ |
6220 |
10 Jan 13 |
nicklas |
Events.addEventHandler(sort[i], 'click', table.sortOnClick, attributes); |
6182 |
23 Oct 12 |
nicklas |
85 |
} |
6182 |
23 Oct 12 |
nicklas |
86 |
|
7083 |
01 Mar 16 |
nicklas |
// Add 'drag-drop' handlers for moving columns |
7083 |
01 Mar 16 |
nicklas |
var cols = element.getElementsByClassName('table-col-draggable'); |
7083 |
01 Mar 16 |
nicklas |
for (var i = 0; i < cols.length; i++) |
7083 |
01 Mar 16 |
nicklas |
90 |
{ |
7083 |
01 Mar 16 |
nicklas |
var dropTarget = cols[i]; |
7083 |
01 Mar 16 |
nicklas |
Data.set(dropTarget, 'column-index', i); |
7083 |
01 Mar 16 |
nicklas |
Events.addEventHandler(dropTarget, 'dragstart', table.beginColumnDrag, attributes); |
7083 |
01 Mar 16 |
nicklas |
Events.addEventHandler(dropTarget, 'dragover', table.checkColumnDropTarget); |
7083 |
01 Mar 16 |
nicklas |
Events.addEventHandler(dropTarget, 'dragleave', table.leaveColumnDropTarget); |
7083 |
01 Mar 16 |
nicklas |
Events.addEventHandler(dropTarget, 'drop', table.columnDropped); |
7083 |
01 Mar 16 |
nicklas |
Events.addEventHandler(dropTarget, 'dragend', table.endColumnDrag); |
7085 |
02 Mar 16 |
nicklas |
98 |
|
7085 |
02 Mar 16 |
nicklas |
// Right-clicking should bring up a menu with selection of columns |
7085 |
02 Mar 16 |
nicklas |
Events.addEventHandler(dropTarget, 'mouseup', table.showColumnSelectionMenu); |
7085 |
02 Mar 16 |
nicklas |
Events.addEventHandler(dropTarget, 'contextmenu', table.showColumnSelectionMenu); |
7083 |
01 Mar 16 |
nicklas |
102 |
} |
7083 |
01 Mar 16 |
nicklas |
103 |
|
7084 |
01 Mar 16 |
nicklas |
// Add 'hide column' handler to column headers |
7084 |
01 Mar 16 |
nicklas |
var cols = element.getElementsByClassName('table-col-hide'); |
7084 |
01 Mar 16 |
nicklas |
for (var i = 0; i < cols.length; i++) |
7084 |
01 Mar 16 |
nicklas |
107 |
{ |
7084 |
01 Mar 16 |
nicklas |
Events.addEventHandler(cols[i], 'click', table.hideColumnOnClick, attributes); |
7084 |
01 Mar 16 |
nicklas |
109 |
} |
7084 |
01 Mar 16 |
nicklas |
110 |
|
6182 |
23 Oct 12 |
nicklas |
// Submit form when clicked or ENTER is pressed |
6182 |
23 Oct 12 |
nicklas |
var submit = element.getElementsByClassName('table-submit'); |
6182 |
23 Oct 12 |
nicklas |
for (var i = 0; i < submit.length; i++) |
6182 |
23 Oct 12 |
nicklas |
114 |
{ |
6182 |
23 Oct 12 |
nicklas |
var field = submit[i]; |
6182 |
23 Oct 12 |
nicklas |
var type = field.type; |
6182 |
23 Oct 12 |
nicklas |
if (type == 'radio' || type == 'checkbox') |
6182 |
23 Oct 12 |
nicklas |
118 |
{ |
6182 |
23 Oct 12 |
nicklas |
// Radio and checkboxes react to 'click' |
7892 |
07 Dec 20 |
nicklas |
Events.addEventHandler(field, 'click', Forms.submit); |
6182 |
23 Oct 12 |
nicklas |
121 |
} |
6182 |
23 Oct 12 |
nicklas |
else if (type == 'text') |
6182 |
23 Oct 12 |
nicklas |
123 |
{ |
6182 |
23 Oct 12 |
nicklas |
// Text fields react to ENTER key |
7892 |
07 Dec 20 |
nicklas |
Events.doOnEnter(field, Forms.submit); |
6182 |
23 Oct 12 |
nicklas |
126 |
} |
6182 |
23 Oct 12 |
nicklas |
else if (type == 'select-one') |
6182 |
23 Oct 12 |
nicklas |
128 |
{ |
6182 |
23 Oct 12 |
nicklas |
// Selection list react to 'onchange' |
7892 |
07 Dec 20 |
nicklas |
Events.addEventHandler(field, 'change', Forms.submit); |
6182 |
23 Oct 12 |
nicklas |
131 |
} |
6182 |
23 Oct 12 |
nicklas |
132 |
} |
6220 |
10 Jan 13 |
nicklas |
133 |
|
6834 |
08 Apr 15 |
nicklas |
// Add 'click' handler to the 'Toggle all' icon |
6834 |
08 Apr 15 |
nicklas |
var tableCheck = element.getElementsByClassName('table-check'); |
6834 |
08 Apr 15 |
nicklas |
for (var i = 0; i < tableCheck.length; i++) |
6834 |
08 Apr 15 |
nicklas |
137 |
{ |
6834 |
08 Apr 15 |
nicklas |
Buttons.addClickHandler(tableCheck[i], table.checkUncheckOnClick, attributes); |
6834 |
08 Apr 15 |
nicklas |
if (i == 0) element.tableCheck = tableCheck[i]; |
6834 |
08 Apr 15 |
nicklas |
140 |
} |
6220 |
10 Jan 13 |
nicklas |
141 |
|
6697 |
29 Jan 15 |
nicklas |
// Add 'click' handler to the 'Add filter row' and 'Remove filter rows' icons |
6699 |
30 Jan 15 |
nicklas |
var filterRowActions = element.getElementsByClassName('table-filter-row-action'); |
6699 |
30 Jan 15 |
nicklas |
for (var i = 0; i < filterRowActions.length; i++) |
6697 |
29 Jan 15 |
nicklas |
145 |
{ |
6699 |
30 Jan 15 |
nicklas |
Buttons.addClickHandler(filterRowActions[i], table.filterRowActionOnClick, attributes); |
6697 |
29 Jan 15 |
nicklas |
147 |
} |
6697 |
29 Jan 15 |
nicklas |
148 |
|
6220 |
10 Jan 13 |
nicklas |
// Add 'click' handlers to all main table items |
6220 |
10 Jan 13 |
nicklas |
// This must be different from the regular item click handler |
6220 |
10 Jan 13 |
nicklas |
// since we must also support returning selected items from a |
6220 |
10 Jan 13 |
nicklas |
// popup dialog (the regular click handler only supports navigating |
6220 |
10 Jan 13 |
nicklas |
// to the 'view' or 'edit' page. |
6220 |
10 Jan 13 |
nicklas |
var items = element.getElementsByClassName('table-item'); |
6220 |
10 Jan 13 |
nicklas |
for (var i = 0; i < items.length; i++) |
6220 |
10 Jan 13 |
nicklas |
156 |
{ |
6220 |
10 Jan 13 |
nicklas |
var item = items[i]; |
6220 |
10 Jan 13 |
nicklas |
Buttons.addClickHandler(item, table.mainItemOnClick, attributes); |
6220 |
10 Jan 13 |
nicklas |
159 |
} |
6220 |
10 Jan 13 |
nicklas |
160 |
|
6220 |
10 Jan 13 |
nicklas |
// Add 'click' handler to all 'Marked for removal' trashcan icons |
6220 |
10 Jan 13 |
nicklas |
// This will delete the clicked item permanently |
6220 |
10 Jan 13 |
nicklas |
var items = element.getElementsByClassName('table-delete-item'); |
6220 |
10 Jan 13 |
nicklas |
for (var i = 0; i < items.length; i++) |
6220 |
10 Jan 13 |
nicklas |
165 |
{ |
6220 |
10 Jan 13 |
nicklas |
var item = items[i]; |
6220 |
10 Jan 13 |
nicklas |
Buttons.addClickHandler(item, Buttons.deleteItemPermanently, attributes); |
6220 |
10 Jan 13 |
nicklas |
168 |
} |
6221 |
10 Jan 13 |
nicklas |
169 |
|
6221 |
10 Jan 13 |
nicklas |
// Add 'click' handler to all 'Shared item' icons |
6221 |
10 Jan 13 |
nicklas |
// This will open the Share popup dialog |
6221 |
10 Jan 13 |
nicklas |
var items = element.getElementsByClassName('table-share-item'); |
6221 |
10 Jan 13 |
nicklas |
for (var i = 0; i < items.length; i++) |
6221 |
10 Jan 13 |
nicklas |
174 |
{ |
6221 |
10 Jan 13 |
nicklas |
var item = items[i]; |
6221 |
10 Jan 13 |
nicklas |
Buttons.addClickHandler(item, Buttons.shareItem, attributes); |
6221 |
10 Jan 13 |
nicklas |
177 |
} |
7943 |
04 May 21 |
nicklas |
178 |
|
7943 |
04 May 21 |
nicklas |
// Add handler for detecting when a sticky-col is stuck |
7943 |
04 May 21 |
nicklas |
// The area is defined by the <tbl:data> element |
7943 |
04 May 21 |
nicklas |
// If there is a "row-index" column we must apply a margin since the |
7943 |
04 May 21 |
nicklas |
// sticky-col:s will stick to the right of the row-index column. |
7943 |
04 May 21 |
nicklas |
var stickyCols = element.getElementsByClassName('sticky-col'); |
7943 |
04 May 21 |
nicklas |
var data = element.getElementsByClassName('data'); |
7943 |
04 May 21 |
nicklas |
if (stickyCols.length > 0 && data.length > 0) |
7943 |
04 May 21 |
nicklas |
186 |
{ |
7943 |
04 May 21 |
nicklas |
// Need to run this later since the table may be hidden and leftCol=0 |
7943 |
04 May 21 |
nicklas |
Doc.addFinalizer( |
7943 |
04 May 21 |
nicklas |
function() |
7943 |
04 May 21 |
nicklas |
190 |
{ |
7943 |
04 May 21 |
nicklas |
var rowIndex = element.getElementsByClassName('row-index'); |
7943 |
04 May 21 |
nicklas |
var leftPos = rowIndex.length > 0 ? Doc.getElementPosition(rowIndex[0]).right : 0; |
7943 |
04 May 21 |
nicklas |
if (leftPos > 0) |
7943 |
04 May 21 |
nicklas |
194 |
{ |
7943 |
04 May 21 |
nicklas |
var leftPos1 = leftPos-1; |
7943 |
04 May 21 |
nicklas |
for (var i = 0; i < stickyCols.length; i++) |
7943 |
04 May 21 |
nicklas |
197 |
{ |
7943 |
04 May 21 |
nicklas |
stickyCols[i].style.left = leftPos1+'px'; |
7943 |
04 May 21 |
nicklas |
199 |
} |
7943 |
04 May 21 |
nicklas |
200 |
} |
7943 |
04 May 21 |
nicklas |
201 |
|
7943 |
04 May 21 |
nicklas |
var observer = new IntersectionObserver(internal.handleStickyCol, |
7943 |
04 May 21 |
nicklas |
203 |
{ |
7943 |
04 May 21 |
nicklas |
root: data[0], |
7943 |
04 May 21 |
nicklas |
rootMargin: '0px 0px 0px -'+(leftPos)+'px', |
7943 |
04 May 21 |
nicklas |
threshold: 1.0 |
7943 |
04 May 21 |
nicklas |
207 |
}); |
7943 |
04 May 21 |
nicklas |
observer.table = element; |
7943 |
04 May 21 |
nicklas |
observer.observe(stickyCols[0]); |
7943 |
04 May 21 |
nicklas |
210 |
}); |
7943 |
04 May 21 |
nicklas |
211 |
} |
6182 |
23 Oct 12 |
nicklas |
212 |
} |
6182 |
23 Oct 12 |
nicklas |
Doc.addElementInitializer(internal.initTable); |
6182 |
23 Oct 12 |
nicklas |
214 |
|
7943 |
04 May 21 |
nicklas |
internal.handleStickyCol = function(entries, observer) |
7943 |
04 May 21 |
nicklas |
216 |
{ |
7943 |
04 May 21 |
nicklas |
for (var i = 0; i < entries.length; i++) |
7943 |
04 May 21 |
nicklas |
218 |
{ |
7943 |
04 May 21 |
nicklas |
var e = entries[i]; |
7943 |
04 May 21 |
nicklas |
Doc.addOrRemoveClass(observer.table, 'stuck-left', e.intersectionRatio < 1 && e.boundingClientRect.x < e.intersectionRect.x); |
7943 |
04 May 21 |
nicklas |
Doc.addOrRemoveClass(observer.table, 'stuck-right', e.intersectionRatio < 1 && e.boundingClientRect.right > e.intersectionRect.right); |
7943 |
04 May 21 |
nicklas |
222 |
} |
7943 |
04 May 21 |
nicklas |
223 |
} |
7943 |
04 May 21 |
nicklas |
224 |
|
6182 |
23 Oct 12 |
nicklas |
225 |
/** |
7085 |
02 Mar 16 |
nicklas |
Event handler for showing a column selection menu |
7085 |
02 Mar 16 |
nicklas |
when right-clicking a column header. |
7085 |
02 Mar 16 |
nicklas |
228 |
*/ |
7085 |
02 Mar 16 |
nicklas |
table.showColumnSelectionMenu = function(event) |
7085 |
02 Mar 16 |
nicklas |
230 |
{ |
7085 |
02 Mar 16 |
nicklas |
var frm = document.forms['reggie']; |
7085 |
02 Mar 16 |
nicklas |
// Context menu on 'right' mouse button |
7085 |
02 Mar 16 |
nicklas |
// Can't just check the button since two events are sent ('mouseup' and 'contextmenu') |
7085 |
02 Mar 16 |
nicklas |
var showContext = event.type == 'contextmenu' && event.button == 2; |
7085 |
02 Mar 16 |
nicklas |
235 |
|
7085 |
02 Mar 16 |
nicklas |
if (showContext) |
7085 |
02 Mar 16 |
nicklas |
237 |
{ |
7085 |
02 Mar 16 |
nicklas |
event.preventDefault(); // Prevents the default right-click menu from appearing |
7085 |
02 Mar 16 |
nicklas |
239 |
|
7085 |
02 Mar 16 |
nicklas |
var tableId = Data.get(event.currentTarget, 'table-id'); |
7085 |
02 Mar 16 |
nicklas |
var afterColumnId = Data.get(event.currentTarget, 'column-id'); |
7085 |
02 Mar 16 |
nicklas |
242 |
|
7085 |
02 Mar 16 |
nicklas |
var ctxMenu = Doc.element(tableId+'-select-visible-columns'); |
7162 |
30 May 16 |
nicklas |
var filterDiv = Doc.element(tableId+'-select-visible-columns-filter'); |
7162 |
30 May 16 |
nicklas |
var noMatchDiv = Doc.element(tableId+'-select-visible-columns-nomatch'); |
7162 |
30 May 16 |
nicklas |
246 |
|
7085 |
02 Mar 16 |
nicklas |
if (!ctxMenu) |
7085 |
02 Mar 16 |
nicklas |
248 |
{ |
7085 |
02 Mar 16 |
nicklas |
// Create the <div> with the menu items |
7085 |
02 Mar 16 |
nicklas |
// One per table (in the rare case that there is more than one per page) |
7085 |
02 Mar 16 |
nicklas |
ctxMenu = document.createElement('div'); |
7085 |
02 Mar 16 |
nicklas |
ctxMenu.className = 'menu vertical bg-filled-100 table-select-columns'; |
7085 |
02 Mar 16 |
nicklas |
ctxMenu.id = tableId+'-select-visible-columns'; |
7162 |
30 May 16 |
nicklas |
ctxMenu.tabIndex = 0; |
7085 |
02 Mar 16 |
nicklas |
document.body.appendChild(ctxMenu); |
7162 |
30 May 16 |
nicklas |
256 |
|
7162 |
30 May 16 |
nicklas |
// Submit changes when ENTER key is pressed |
7162 |
30 May 16 |
nicklas |
ctxMenu.form = document.forms[tableId]; |
7162 |
30 May 16 |
nicklas |
Events.doOnEnter(ctxMenu, Forms.submit) |
7162 |
30 May 16 |
nicklas |
260 |
|
7085 |
02 Mar 16 |
nicklas |
var colDefs = table.getColumnDefs(tableId); |
7162 |
30 May 16 |
nicklas |
var activateFilter = colDefs.length > 30; |
7162 |
30 May 16 |
nicklas |
if (activateFilter) |
7162 |
30 May 16 |
nicklas |
264 |
{ |
7162 |
30 May 16 |
nicklas |
// Add a filter <div> |
7162 |
30 May 16 |
nicklas |
filterDiv = document.createElement('div'); |
7162 |
30 May 16 |
nicklas |
filterDiv.className = 'menuitem column-filter bottomborder'; |
7162 |
30 May 16 |
nicklas |
filterDiv.id = tableId+'-select-visible-columns-filter'; |
7162 |
30 May 16 |
nicklas |
ctxMenu.appendChild(filterDiv); |
7162 |
30 May 16 |
nicklas |
// Need to catch both events to handle {backspace} correctly in IE |
7162 |
30 May 16 |
nicklas |
Events.addEventHandler(ctxMenu, 'keypress', table.filterColumnSelectionMenu); |
7162 |
30 May 16 |
nicklas |
Events.addEventHandler(ctxMenu, 'keydown', table.filterColumnSelectionMenu); |
7162 |
30 May 16 |
nicklas |
273 |
|
7162 |
30 May 16 |
nicklas |
// Add 'no matching columns' <div> |
7162 |
30 May 16 |
nicklas |
noMatchDiv = document.createElement('div'); |
7162 |
30 May 16 |
nicklas |
noMatchDiv.className = 'menuitem'; |
7162 |
30 May 16 |
nicklas |
noMatchDiv.innerHTML = 'No matching columns'; |
7162 |
30 May 16 |
nicklas |
noMatchDiv.id = tableId+'-select-visible-columns-nomatch'; |
7162 |
30 May 16 |
nicklas |
279 |
} |
7162 |
30 May 16 |
nicklas |
280 |
|
7162 |
30 May 16 |
nicklas |
var allCols = document.createElement('div'); |
7162 |
30 May 16 |
nicklas |
allCols.className = 'table-all-columns'; |
7162 |
30 May 16 |
nicklas |
ctxMenu.appendChild(allCols); |
7162 |
30 May 16 |
nicklas |
284 |
|
7085 |
02 Mar 16 |
nicklas |
var hasAnnotationSeparator = false; |
7085 |
02 Mar 16 |
nicklas |
for (var i = 0; i < colDefs.length; i++) |
7085 |
02 Mar 16 |
nicklas |
287 |
{ |
7085 |
02 Mar 16 |
nicklas |
var col = colDefs[i]; |
7952 |
12 May 21 |
nicklas |
if (!col.alwaysShow && !col.alwaysHide) |
7085 |
02 Mar 16 |
nicklas |
290 |
{ |
7085 |
02 Mar 16 |
nicklas |
if (col.isAnnotation != hasAnnotationSeparator) |
7085 |
02 Mar 16 |
nicklas |
292 |
{ |
7085 |
02 Mar 16 |
nicklas |
// Insert separator when switching |
7085 |
02 Mar 16 |
nicklas |
// between regular and annotation columns |
7085 |
02 Mar 16 |
nicklas |
hasAnnotationSeparator = col.isAnnotation; |
7085 |
02 Mar 16 |
nicklas |
var sep = document.createElement('div'); |
7085 |
02 Mar 16 |
nicklas |
sep.className = 'menuseparator'; |
7162 |
30 May 16 |
nicklas |
allCols.appendChild(sep); |
7085 |
02 Mar 16 |
nicklas |
299 |
} |
7085 |
02 Mar 16 |
nicklas |
300 |
|
7162 |
30 May 16 |
nicklas |
var html = '<span class="padding">'; |
7085 |
02 Mar 16 |
nicklas |
html += ' </span>'+Strings.encodeTags(col.title); |
7085 |
02 Mar 16 |
nicklas |
303 |
|
7085 |
02 Mar 16 |
nicklas |
var mnuItem = document.createElement('div'); |
7162 |
30 May 16 |
nicklas |
mnuItem.className = 'menuitem interactable table-col' + (col.visible?' visible-column':''); |
7085 |
02 Mar 16 |
nicklas |
mnuItem.title = col.title; |
7162 |
30 May 16 |
nicklas |
mnuItem.filterText = col.title.toLowerCase(); |
7085 |
02 Mar 16 |
nicklas |
mnuItem.innerHTML = html; |
7085 |
02 Mar 16 |
nicklas |
Data.set(mnuItem, 'column-id', col.id); |
7085 |
02 Mar 16 |
nicklas |
Data.set(mnuItem, 'table-id', tableId); |
7085 |
02 Mar 16 |
nicklas |
Data.set(mnuItem, 'after-column-id', afterColumnId); |
7085 |
02 Mar 16 |
nicklas |
Events.addEventHandler(mnuItem, 'click', table.showOrHideSelectedColumn); |
7162 |
30 May 16 |
nicklas |
allCols.appendChild(mnuItem); |
7085 |
02 Mar 16 |
nicklas |
314 |
} |
7085 |
02 Mar 16 |
nicklas |
315 |
} |
7162 |
30 May 16 |
nicklas |
316 |
|
7162 |
30 May 16 |
nicklas |
if (activateFilter) ctxMenu.appendChild(noMatchDiv); |
7085 |
02 Mar 16 |
nicklas |
318 |
} |
7085 |
02 Mar 16 |
nicklas |
else |
7085 |
02 Mar 16 |
nicklas |
320 |
{ |
7085 |
02 Mar 16 |
nicklas |
// If the menu already has been created we |
7085 |
02 Mar 16 |
nicklas |
// only need to update the 'after-column-id' attribute |
7162 |
30 May 16 |
nicklas |
var menuItems = ctxMenu.getElementsByClassName('table-col'); |
7085 |
02 Mar 16 |
nicklas |
for (var i = 0; i < menuItems.length; i++) |
7085 |
02 Mar 16 |
nicklas |
325 |
{ |
7163 |
30 May 16 |
nicklas |
var item = menuItems[i]; |
7163 |
30 May 16 |
nicklas |
Data.set(item, 'after-column-id', afterColumnId); |
7163 |
30 May 16 |
nicklas |
item.innerHTML = '<span class="padding"> </span>'+Strings.encodeTags(item.title); |
7163 |
30 May 16 |
nicklas |
Doc.show(item); |
7085 |
02 Mar 16 |
nicklas |
330 |
} |
7085 |
02 Mar 16 |
nicklas |
331 |
} |
7085 |
02 Mar 16 |
nicklas |
332 |
|
7162 |
30 May 16 |
nicklas |
if (filterDiv) filterDiv.innerHTML = 'Type to filter columns'; |
7162 |
30 May 16 |
nicklas |
if (noMatchDiv) Doc.hide(noMatchDiv); |
7162 |
30 May 16 |
nicklas |
335 |
|
7085 |
02 Mar 16 |
nicklas |
// Position the menu near the mouse |
7085 |
02 Mar 16 |
nicklas |
var winPos = App.getWindowPosition(); |
7085 |
02 Mar 16 |
nicklas |
var alignToRight = event.clientX + 200 > winPos.width; |
7085 |
02 Mar 16 |
nicklas |
Menu.showTopMenu(ctxMenu, alignToRight ? winPos.width-event.clientX : event.clientX, event.clientY, alignToRight); |
7162 |
30 May 16 |
nicklas |
ctxMenu.filterText = ''; |
7162 |
30 May 16 |
nicklas |
ctxMenu.focus(); |
7085 |
02 Mar 16 |
nicklas |
342 |
} |
7085 |
02 Mar 16 |
nicklas |
343 |
} |
7085 |
02 Mar 16 |
nicklas |
344 |
|
7162 |
30 May 16 |
nicklas |
// Reacts to keys and either insert or delete a character from the filter field |
7162 |
30 May 16 |
nicklas |
table.filterColumnSelectionMenu = function(event) |
7162 |
30 May 16 |
nicklas |
347 |
{ |
7162 |
30 May 16 |
nicklas |
var target = event.currentTarget; |
7162 |
30 May 16 |
nicklas |
if (event.keyCode == 8) |
7162 |
30 May 16 |
nicklas |
350 |
{ |
7162 |
30 May 16 |
nicklas |
// Backspace delete one character |
7162 |
30 May 16 |
nicklas |
target.filterText = target.filterText.substring(0, target.filterText.length-1); |
7162 |
30 May 16 |
nicklas |
event.preventDefault(); |
7162 |
30 May 16 |
nicklas |
354 |
} |
7162 |
30 May 16 |
nicklas |
else if (event.charCode > 0) |
7162 |
30 May 16 |
nicklas |
356 |
{ |
7162 |
30 May 16 |
nicklas |
// Add the typed character to the filter |
7162 |
30 May 16 |
nicklas |
target.filterText += String.fromCharCode(event.charCode); |
7162 |
30 May 16 |
nicklas |
359 |
} |
7162 |
30 May 16 |
nicklas |
else |
7162 |
30 May 16 |
nicklas |
361 |
{ |
7162 |
30 May 16 |
nicklas |
return; |
7162 |
30 May 16 |
nicklas |
363 |
} |
7162 |
30 May 16 |
nicklas |
364 |
|
7162 |
30 May 16 |
nicklas |
// Update the displayed filter text |
7162 |
30 May 16 |
nicklas |
Doc.element(target.id+'-filter').innerHTML = Strings.encodeTags(target.filterText || 'Type to filter columns'); |
7162 |
30 May 16 |
nicklas |
367 |
|
7162 |
30 May 16 |
nicklas |
var items = target.getElementsByClassName('table-col'); |
7162 |
30 May 16 |
nicklas |
var numMatching = 0; |
7162 |
30 May 16 |
nicklas |
var filterText = target.filterText.toLowerCase(); |
7162 |
30 May 16 |
nicklas |
for (var i = 0; i < items.length; i++) |
7162 |
30 May 16 |
nicklas |
372 |
{ |
7162 |
30 May 16 |
nicklas |
var item = items[i]; |
7163 |
30 May 16 |
nicklas |
var startIndex = item.filterText.indexOf(filterText); |
7163 |
30 May 16 |
nicklas |
if (startIndex >= 0) |
7162 |
30 May 16 |
nicklas |
376 |
{ |
7162 |
30 May 16 |
nicklas |
numMatching++; |
7162 |
30 May 16 |
nicklas |
Doc.show(item); |
7163 |
30 May 16 |
nicklas |
var endIndex = startIndex+filterText.length; |
7163 |
30 May 16 |
nicklas |
var html = '<span class="padding"> </span>'; |
7163 |
30 May 16 |
nicklas |
if (endIndex > startIndex) |
7163 |
30 May 16 |
nicklas |
382 |
{ |
7163 |
30 May 16 |
nicklas |
html += Strings.encodeTags(item.title.substring(0, startIndex)); |
7163 |
30 May 16 |
nicklas |
html += '<b>'+Strings.encodeTags(item.title.substring(startIndex, endIndex))+'</b>'; |
7163 |
30 May 16 |
nicklas |
html += Strings.encodeTags(item.title.substring(endIndex)); |
7163 |
30 May 16 |
nicklas |
386 |
} |
7163 |
30 May 16 |
nicklas |
else |
7163 |
30 May 16 |
nicklas |
388 |
{ |
7163 |
30 May 16 |
nicklas |
html += Strings.encodeTags(item.title); |
7163 |
30 May 16 |
nicklas |
390 |
} |
7163 |
30 May 16 |
nicklas |
item.innerHTML = html; |
7162 |
30 May 16 |
nicklas |
392 |
} |
7162 |
30 May 16 |
nicklas |
else |
7162 |
30 May 16 |
nicklas |
394 |
{ |
7162 |
30 May 16 |
nicklas |
Doc.hide(item); |
7162 |
30 May 16 |
nicklas |
396 |
} |
7162 |
30 May 16 |
nicklas |
397 |
} |
7162 |
30 May 16 |
nicklas |
Doc.showHide(target.id+'-nomatch', numMatching==0); |
7162 |
30 May 16 |
nicklas |
399 |
} |
7162 |
30 May 16 |
nicklas |
400 |
|
7085 |
02 Mar 16 |
nicklas |
401 |
/** |
7085 |
02 Mar 16 |
nicklas |
Event handler invoked when selecting a column from the |
7085 |
02 Mar 16 |
nicklas |
context menu. If the selected column is visible it is hidden, |
7085 |
02 Mar 16 |
nicklas |
otherwise it is inserted after the column that was clicked |
7085 |
02 Mar 16 |
nicklas |
to bring up the context menu. |
7085 |
02 Mar 16 |
nicklas |
406 |
*/ |
7085 |
02 Mar 16 |
nicklas |
table.showOrHideSelectedColumn = function(event) |
7085 |
02 Mar 16 |
nicklas |
408 |
{ |
7085 |
02 Mar 16 |
nicklas |
var tableId = Data.get(event.currentTarget, 'table-id'); |
7085 |
02 Mar 16 |
nicklas |
var afterColumnId = Data.get(event.currentTarget, 'after-column-id'); |
7085 |
02 Mar 16 |
nicklas |
var columnId = Data.get(event.currentTarget, 'column-id'); |
7085 |
02 Mar 16 |
nicklas |
412 |
|
7085 |
02 Mar 16 |
nicklas |
var visibleCols = table.getVisibleColumnIdsAsArray(tableId); |
7085 |
02 Mar 16 |
nicklas |
var index = visibleCols.indexOf(columnId); |
7085 |
02 Mar 16 |
nicklas |
if (index >= 0) |
7085 |
02 Mar 16 |
nicklas |
416 |
{ |
7085 |
02 Mar 16 |
nicklas |
// Hide this column |
7085 |
02 Mar 16 |
nicklas |
visibleCols.splice(index, 1); |
7162 |
30 May 16 |
nicklas |
Doc.removeClass(event.currentTarget, 'visible-column'); |
7085 |
02 Mar 16 |
nicklas |
420 |
} |
7085 |
02 Mar 16 |
nicklas |
else |
7085 |
02 Mar 16 |
nicklas |
422 |
{ |
7085 |
02 Mar 16 |
nicklas |
// Insert after the column that was clicked |
7085 |
02 Mar 16 |
nicklas |
var afterIndex = visibleCols.indexOf(afterColumnId); |
7085 |
02 Mar 16 |
nicklas |
visibleCols.splice(afterIndex+1, 0, columnId); |
7162 |
30 May 16 |
nicklas |
Doc.addClass(event.currentTarget, 'visible-column'); |
7085 |
02 Mar 16 |
nicklas |
427 |
} |
7162 |
30 May 16 |
nicklas |
428 |
|
7162 |
30 May 16 |
nicklas |
if (event.altKey || event.ctrlKey || event.shiftKey) |
7162 |
30 May 16 |
nicklas |
430 |
{ |
7162 |
30 May 16 |
nicklas |
// Keep the context menu open and make it possible to select more columns |
7162 |
30 May 16 |
nicklas |
var frm = document.forms[tableId]; |
7162 |
30 May 16 |
nicklas |
frm.columns.value = visibleCols.join(','); |
7162 |
30 May 16 |
nicklas |
event.stopPropagation(); |
7162 |
30 May 16 |
nicklas |
435 |
} |
7162 |
30 May 16 |
nicklas |
else |
7162 |
30 May 16 |
nicklas |
437 |
{ |
7162 |
30 May 16 |
nicklas |
table.setColumns(tableId, visibleCols.join(',')); |
7162 |
30 May 16 |
nicklas |
439 |
} |
7085 |
02 Mar 16 |
nicklas |
440 |
} |
7085 |
02 Mar 16 |
nicklas |
441 |
|
7085 |
02 Mar 16 |
nicklas |
442 |
/** |
6182 |
23 Oct 12 |
nicklas |
Click handler that changes the sort order of the table. The sort property |
6182 |
23 Oct 12 |
nicklas |
and sort direction should be stored in the data-sort-property and data-sort-direction |
6182 |
23 Oct 12 |
nicklas |
properties of the target element. |
6182 |
23 Oct 12 |
nicklas |
446 |
*/ |
6182 |
23 Oct 12 |
nicklas |
table.sortOnClick = function(event) |
6182 |
23 Oct 12 |
nicklas |
448 |
{ |
6182 |
23 Oct 12 |
nicklas |
var column = event.currentTarget; |
6182 |
23 Oct 12 |
nicklas |
var sortProperty = Data.get(column, 'sort-property'); |
6182 |
23 Oct 12 |
nicklas |
var sortDirection = Data.get(column, 'sort-direction'); |
6220 |
10 Jan 13 |
nicklas |
var tableId = Data.get(column, 'table-id'); |
6182 |
23 Oct 12 |
nicklas |
var frm = document.forms[tableId]; |
6336 |
28 Oct 13 |
nicklas |
var mainDirection = frm.direction.value; |
6336 |
28 Oct 13 |
nicklas |
if (frm.sortby.value != sortProperty || mainDirection != sortDirection) |
6182 |
23 Oct 12 |
nicklas |
456 |
{ |
6182 |
23 Oct 12 |
nicklas |
if (event.altKey || event.ctrlKey || event.shiftKey) |
6182 |
23 Oct 12 |
nicklas |
458 |
{ |
6182 |
23 Oct 12 |
nicklas |
// Append the current sort property to the list of already sorted columns |
6336 |
28 Oct 13 |
nicklas |
// If the sort property is already used we keep it, but use the new sort direction |
6182 |
23 Oct 12 |
nicklas |
var sortArray = frm.sortby.value.split(','); |
6182 |
23 Oct 12 |
nicklas |
var index = sortArray.indexOf(sortProperty); |
6336 |
28 Oct 13 |
nicklas |
// Check for '+' and '-' prefix if the sort order is different from main direction |
6336 |
28 Oct 13 |
nicklas |
if (index == -1) index = sortArray.indexOf('+'+sortProperty); |
6336 |
28 Oct 13 |
nicklas |
if (index == -1) index = sortArray.indexOf('-'+sortProperty); |
6336 |
28 Oct 13 |
nicklas |
// Currently not sorted, insert at end |
6336 |
28 Oct 13 |
nicklas |
if (index == -1) index = sortArray.length; |
6182 |
23 Oct 12 |
nicklas |
// Add the sort property as the last property |
6336 |
28 Oct 13 |
nicklas |
if (sortDirection != mainDirection) |
6336 |
28 Oct 13 |
nicklas |
470 |
{ |
6336 |
28 Oct 13 |
nicklas |
sortProperty = (sortDirection == 'ASC' ? '+' : '-') + sortProperty; |
6336 |
28 Oct 13 |
nicklas |
sortDirection = mainDirection; |
6336 |
28 Oct 13 |
nicklas |
473 |
} |
6336 |
28 Oct 13 |
nicklas |
sortArray[index] = sortProperty; |
6182 |
23 Oct 12 |
nicklas |
sortProperty = sortArray.join(','); |
6182 |
23 Oct 12 |
nicklas |
476 |
} |
6182 |
23 Oct 12 |
nicklas |
frm.sortby.value = sortProperty; |
6182 |
23 Oct 12 |
nicklas |
frm.direction.value = sortDirection; |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
6182 |
23 Oct 12 |
nicklas |
480 |
} |
6182 |
23 Oct 12 |
nicklas |
481 |
} |
6182 |
23 Oct 12 |
nicklas |
482 |
|
6182 |
23 Oct 12 |
nicklas |
483 |
/** |
7083 |
01 Mar 16 |
nicklas |
Start dragging a table column. Store table-id, column-id |
7083 |
01 Mar 16 |
nicklas |
and column-index on the table element. |
7083 |
01 Mar 16 |
nicklas |
486 |
*/ |
7083 |
01 Mar 16 |
nicklas |
table.beginColumnDrag = function(event) |
7083 |
01 Mar 16 |
nicklas |
488 |
{ |
7083 |
01 Mar 16 |
nicklas |
var dragSrc = {}; |
7083 |
01 Mar 16 |
nicklas |
dragSrc.tableId = Data.get(event.currentTarget, 'table-id'); |
7083 |
01 Mar 16 |
nicklas |
dragSrc.columnId = Data.get(event.currentTarget, 'column-id'); |
7083 |
01 Mar 16 |
nicklas |
dragSrc.columnIndex = Data.int(event.currentTarget, 'column-index'); |
7083 |
01 Mar 16 |
nicklas |
493 |
|
7083 |
01 Mar 16 |
nicklas |
// Store the drag data on the <table> div |
7083 |
01 Mar 16 |
nicklas |
Doc.element(dragSrc.tableId).dragSrc = dragSrc; |
7083 |
01 Mar 16 |
nicklas |
event.dataTransfer.effectAllowed = 'move'; |
7083 |
01 Mar 16 |
nicklas |
// In FF, we also need to call setData() or the drag event will not start |
7083 |
01 Mar 16 |
nicklas |
// but this results in an exception in IE!!! |
7083 |
01 Mar 16 |
nicklas |
try |
7083 |
01 Mar 16 |
nicklas |
500 |
{ |
7083 |
01 Mar 16 |
nicklas |
event.dataTransfer.setData('application/json', JSON.stringify(dragSrc)); |
7083 |
01 Mar 16 |
nicklas |
502 |
} |
7083 |
01 Mar 16 |
nicklas |
catch (e) |
7083 |
01 Mar 16 |
nicklas |
504 |
{} |
7083 |
01 Mar 16 |
nicklas |
505 |
} |
7083 |
01 Mar 16 |
nicklas |
506 |
|
7083 |
01 Mar 16 |
nicklas |
507 |
/** |
7083 |
01 Mar 16 |
nicklas |
Clean up after dragging. |
7083 |
01 Mar 16 |
nicklas |
509 |
*/ |
7083 |
01 Mar 16 |
nicklas |
table.endColumnDrag = function(event) |
7083 |
01 Mar 16 |
nicklas |
511 |
{ |
7083 |
01 Mar 16 |
nicklas |
var tableId = Data.get(event.currentTarget, 'table-id'); |
7083 |
01 Mar 16 |
nicklas |
Doc.element(tableId).dragSrc = null; |
7083 |
01 Mar 16 |
nicklas |
514 |
} |
7083 |
01 Mar 16 |
nicklas |
515 |
|
7083 |
01 Mar 16 |
nicklas |
516 |
/** |
7083 |
01 Mar 16 |
nicklas |
Checks if dropping is allowed at this target. |
7083 |
01 Mar 16 |
nicklas |
We only allow dragging within the same table, |
7083 |
01 Mar 16 |
nicklas |
and the target column must be different from the |
7083 |
01 Mar 16 |
nicklas |
source column. |
7083 |
01 Mar 16 |
nicklas |
521 |
*/ |
7083 |
01 Mar 16 |
nicklas |
table.checkColumnDropTarget = function(event) |
7083 |
01 Mar 16 |
nicklas |
523 |
{ |
7083 |
01 Mar 16 |
nicklas |
var tableId = Data.get(event.currentTarget, 'table-id'); |
7083 |
01 Mar 16 |
nicklas |
var dragSrc = Doc.element(tableId).dragSrc; |
7083 |
01 Mar 16 |
nicklas |
526 |
|
7083 |
01 Mar 16 |
nicklas |
var dropLocation = table.checkTheDropTarget(dragSrc, event.currentTarget); |
7083 |
01 Mar 16 |
nicklas |
if (dropLocation) |
7083 |
01 Mar 16 |
nicklas |
529 |
{ |
7083 |
01 Mar 16 |
nicklas |
// Enable drop target! |
7083 |
01 Mar 16 |
nicklas |
event.preventDefault(); |
7083 |
01 Mar 16 |
nicklas |
event.dataTransfer.dropEffect = 'move'; |
7083 |
01 Mar 16 |
nicklas |
// Left or right depending on the order or columns |
7083 |
01 Mar 16 |
nicklas |
Doc.addClass(event.currentTarget, dropLocation < 0 ? 'table-drop-left' : 'table-drop-right'); |
7083 |
01 Mar 16 |
nicklas |
535 |
} |
7083 |
01 Mar 16 |
nicklas |
536 |
} |
7083 |
01 Mar 16 |
nicklas |
537 |
|
7083 |
01 Mar 16 |
nicklas |
538 |
/** |
7083 |
01 Mar 16 |
nicklas |
Checks if dropping is allowed at this target. |
7083 |
01 Mar 16 |
nicklas |
We only allow dragging within the same table, |
7083 |
01 Mar 16 |
nicklas |
and the target column must be different from the |
7083 |
01 Mar 16 |
nicklas |
source column. |
7083 |
01 Mar 16 |
nicklas |
returns: 0 = no drop, -1 drop to left, +1 drop to right |
7083 |
01 Mar 16 |
nicklas |
544 |
*/ |
7083 |
01 Mar 16 |
nicklas |
table.checkTheDropTarget = function(dragSrc, dragTarget) |
7083 |
01 Mar 16 |
nicklas |
546 |
{ |
7083 |
01 Mar 16 |
nicklas |
if (!dragSrc) return false; |
7083 |
01 Mar 16 |
nicklas |
var tableId = Data.get(dragTarget, 'table-id'); |
7083 |
01 Mar 16 |
nicklas |
var columnIndex = Data.int(dragTarget, 'column-index'); |
7083 |
01 Mar 16 |
nicklas |
return tableId == dragSrc.tableId ? columnIndex - dragSrc.columnIndex : 0; |
7083 |
01 Mar 16 |
nicklas |
551 |
} |
7083 |
01 Mar 16 |
nicklas |
552 |
|
7083 |
01 Mar 16 |
nicklas |
553 |
/** |
7083 |
01 Mar 16 |
nicklas |
Remove drop indicator classes when leaving. |
7083 |
01 Mar 16 |
nicklas |
555 |
*/ |
7083 |
01 Mar 16 |
nicklas |
table.leaveColumnDropTarget = function(event) |
7083 |
01 Mar 16 |
nicklas |
557 |
{ |
7083 |
01 Mar 16 |
nicklas |
Doc.removeClass(event.currentTarget, 'table-drop-right'); |
7083 |
01 Mar 16 |
nicklas |
Doc.removeClass(event.currentTarget, 'table-drop-left'); |
7083 |
01 Mar 16 |
nicklas |
560 |
} |
7083 |
01 Mar 16 |
nicklas |
561 |
|
7083 |
01 Mar 16 |
nicklas |
562 |
/** |
7084 |
01 Mar 16 |
nicklas |
Get the visibile columns as an array with column id values. |
7084 |
01 Mar 16 |
nicklas |
The special case is that 'all' is expanded into actual |
7084 |
01 Mar 16 |
nicklas |
column ids. |
7083 |
01 Mar 16 |
nicklas |
566 |
*/ |
7084 |
01 Mar 16 |
nicklas |
table.getVisibleColumnIdsAsArray = function(tableId) |
7083 |
01 Mar 16 |
nicklas |
568 |
{ |
7083 |
01 Mar 16 |
nicklas |
var columns = table.getColumns(tableId); |
7083 |
01 Mar 16 |
nicklas |
var colArray; |
7083 |
01 Mar 16 |
nicklas |
if (columns == 'all') |
7083 |
01 Mar 16 |
nicklas |
572 |
{ |
7083 |
01 Mar 16 |
nicklas |
// Special case, load the existing columns |
7083 |
01 Mar 16 |
nicklas |
var colDefs = table.getColumnDefs(tableId); |
7083 |
01 Mar 16 |
nicklas |
colArray = []; |
7083 |
01 Mar 16 |
nicklas |
for (var colNo = 0; colNo < colDefs.length; colNo++) |
7083 |
01 Mar 16 |
nicklas |
577 |
{ |
7083 |
01 Mar 16 |
nicklas |
var col = colDefs[colNo]; |
7083 |
01 Mar 16 |
nicklas |
if (!col.alwaysHide) colArray[colArray.length] = col.id; |
7083 |
01 Mar 16 |
nicklas |
580 |
} |
7083 |
01 Mar 16 |
nicklas |
581 |
} |
7083 |
01 Mar 16 |
nicklas |
else |
7083 |
01 Mar 16 |
nicklas |
583 |
{ |
7083 |
01 Mar 16 |
nicklas |
colArray = columns.split(','); |
7083 |
01 Mar 16 |
nicklas |
585 |
} |
7084 |
01 Mar 16 |
nicklas |
return colArray; |
7084 |
01 Mar 16 |
nicklas |
587 |
} |
7084 |
01 Mar 16 |
nicklas |
588 |
|
7084 |
01 Mar 16 |
nicklas |
589 |
/** |
7084 |
01 Mar 16 |
nicklas |
Another column was dropped here! |
7084 |
01 Mar 16 |
nicklas |
591 |
*/ |
7084 |
01 Mar 16 |
nicklas |
table.columnDropped = function(event) |
7084 |
01 Mar 16 |
nicklas |
593 |
{ |
7084 |
01 Mar 16 |
nicklas |
Doc.removeClass(event.currentTarget, 'table-drop-right'); |
7084 |
01 Mar 16 |
nicklas |
Doc.removeClass(event.currentTarget, 'table-drop-left'); |
7083 |
01 Mar 16 |
nicklas |
596 |
|
7084 |
01 Mar 16 |
nicklas |
// Check that we can drop here |
7084 |
01 Mar 16 |
nicklas |
var tableId = Data.get(event.currentTarget, 'table-id'); |
7084 |
01 Mar 16 |
nicklas |
var dragSrc = Doc.element(tableId).dragSrc; |
7084 |
01 Mar 16 |
nicklas |
if (!table.checkTheDropTarget(dragSrc, event.currentTarget)) return; |
7084 |
01 Mar 16 |
nicklas |
601 |
|
7084 |
01 Mar 16 |
nicklas |
// Get the existing columns as an array |
7084 |
01 Mar 16 |
nicklas |
var colArray = table.getVisibleColumnIdsAsArray(tableId); |
7084 |
01 Mar 16 |
nicklas |
604 |
|
7083 |
01 Mar 16 |
nicklas |
var indexSrc = colArray.indexOf(dragSrc.columnId); |
7083 |
01 Mar 16 |
nicklas |
var indexDest = colArray.indexOf(Data.get(event.currentTarget, 'column-id')); |
7083 |
01 Mar 16 |
nicklas |
// Remove the dragged column from the array |
7083 |
01 Mar 16 |
nicklas |
if (indexSrc >= 0) colArray.splice(indexSrc, 1); |
7083 |
01 Mar 16 |
nicklas |
// Insert the dragged column before or after the column it was dropped on |
7083 |
01 Mar 16 |
nicklas |
if (indexDest >= 0) colArray.splice(indexDest, 0, dragSrc.columnId); |
7083 |
01 Mar 16 |
nicklas |
611 |
|
7083 |
01 Mar 16 |
nicklas |
// Update and submit the table |
7084 |
01 Mar 16 |
nicklas |
table.setColumns(tableId, colArray.join(',')); |
7083 |
01 Mar 16 |
nicklas |
614 |
} |
7083 |
01 Mar 16 |
nicklas |
615 |
|
7084 |
01 Mar 16 |
nicklas |
616 |
/** |
7084 |
01 Mar 16 |
nicklas |
Event handler for hiding a single column. |
7084 |
01 Mar 16 |
nicklas |
618 |
*/ |
7084 |
01 Mar 16 |
nicklas |
table.hideColumnOnClick = function(event) |
7084 |
01 Mar 16 |
nicklas |
620 |
{ |
7084 |
01 Mar 16 |
nicklas |
var columnId = Data.get(event.currentTarget, 'column-id'); |
7084 |
01 Mar 16 |
nicklas |
var tableId = Data.get(event.currentTarget, 'table-id'); |
7084 |
01 Mar 16 |
nicklas |
623 |
|
7084 |
01 Mar 16 |
nicklas |
var colArray = table.getVisibleColumnIdsAsArray(tableId); |
7084 |
01 Mar 16 |
nicklas |
var colIndex = colArray.indexOf(columnId); |
7084 |
01 Mar 16 |
nicklas |
626 |
|
7084 |
01 Mar 16 |
nicklas |
if (colIndex >= 0) |
7084 |
01 Mar 16 |
nicklas |
628 |
{ |
7084 |
01 Mar 16 |
nicklas |
colArray.splice(colIndex, 1); |
7084 |
01 Mar 16 |
nicklas |
table.setColumns(tableId, colArray.join(',')); |
7084 |
01 Mar 16 |
nicklas |
631 |
} |
7084 |
01 Mar 16 |
nicklas |
632 |
} |
7083 |
01 Mar 16 |
nicklas |
633 |
|
7083 |
01 Mar 16 |
nicklas |
634 |
/** |
6182 |
23 Oct 12 |
nicklas |
Event handler for the page navigator. The actual target should |
6182 |
23 Oct 12 |
nicklas |
have a table-page attribute that specify the page to move to. |
6182 |
23 Oct 12 |
nicklas |
637 |
*/ |
6182 |
23 Oct 12 |
nicklas |
table.navigatorOnClick = function(event) |
6182 |
23 Oct 12 |
nicklas |
639 |
{ |
6182 |
23 Oct 12 |
nicklas |
var target = event.target; |
6182 |
23 Oct 12 |
nicklas |
var page = Data.get(target, 'table-page'); |
6182 |
23 Oct 12 |
nicklas |
if (page == null) return; |
6182 |
23 Oct 12 |
nicklas |
643 |
|
6182 |
23 Oct 12 |
nicklas |
var tableId = Data.get(event.currentTarget, 'table-id'); |
6182 |
23 Oct 12 |
nicklas |
table.setPage(tableId, page); |
6182 |
23 Oct 12 |
nicklas |
646 |
} |
6182 |
23 Oct 12 |
nicklas |
647 |
|
6182 |
23 Oct 12 |
nicklas |
648 |
/** |
6183 |
24 Oct 12 |
nicklas |
Event handler for showing all hidden columns that have a filter. |
6183 |
24 Oct 12 |
nicklas |
The hidden columns should be stored as a comma-separated list |
6220 |
10 Jan 13 |
nicklas |
in 'data-hidden-columns' attribute and the element must have the |
6220 |
10 Jan 13 |
nicklas |
table id stored in 'data-table-id' attribute. |
1606 |
14 Nov 05 |
nicklas |
653 |
*/ |
6183 |
24 Oct 12 |
nicklas |
table.showColumnsOnClick = function(event) |
417 |
19 Apr 05 |
nicklas |
655 |
{ |
6183 |
24 Oct 12 |
nicklas |
var target = event.currentTarget; |
6183 |
24 Oct 12 |
nicklas |
var hiddenColumns = Data.get(target, 'hidden-columns'); |
6220 |
10 Jan 13 |
nicklas |
var tableId = Data.get(target, 'table-id'); |
6183 |
24 Oct 12 |
nicklas |
table.showColumns(tableId, hiddenColumns); |
6183 |
24 Oct 12 |
nicklas |
660 |
} |
6183 |
24 Oct 12 |
nicklas |
661 |
|
6183 |
24 Oct 12 |
nicklas |
662 |
/** |
6220 |
10 Jan 13 |
nicklas |
Event handler for removing all filters from the table. |
6220 |
10 Jan 13 |
nicklas |
The element must have the table id stored in 'data-table-id' |
6220 |
10 Jan 13 |
nicklas |
attribute. |
6220 |
10 Jan 13 |
nicklas |
666 |
*/ |
6220 |
10 Jan 13 |
nicklas |
table.clearFilterOnClick = function(event) |
6220 |
10 Jan 13 |
nicklas |
668 |
{ |
6220 |
10 Jan 13 |
nicklas |
var target = event.currentTarget; |
6220 |
10 Jan 13 |
nicklas |
var tableId = Data.get(target, 'table-id'); |
6220 |
10 Jan 13 |
nicklas |
table.clearFilter(tableId); |
6220 |
10 Jan 13 |
nicklas |
672 |
} |
6220 |
10 Jan 13 |
nicklas |
673 |
|
6220 |
10 Jan 13 |
nicklas |
674 |
/** |
6183 |
24 Oct 12 |
nicklas |
Event handler for the 'view/presets' selection list. |
6183 |
24 Oct 12 |
nicklas |
676 |
*/ |
6183 |
24 Oct 12 |
nicklas |
table.presetOnChange = function(event) |
6183 |
24 Oct 12 |
nicklas |
678 |
{ |
6183 |
24 Oct 12 |
nicklas |
var presetSelector = event.currentTarget; |
6183 |
24 Oct 12 |
nicklas |
var selected = presetSelector[presetSelector.selectedIndex]; |
6183 |
24 Oct 12 |
nicklas |
var cmd = selected.value; |
6183 |
24 Oct 12 |
nicklas |
var tableId = presetSelector.form.name; |
6183 |
24 Oct 12 |
nicklas |
683 |
|
6183 |
24 Oct 12 |
nicklas |
// Reset the list to no selection |
6183 |
24 Oct 12 |
nicklas |
presetSelector.selectedIndex = 0; |
6183 |
24 Oct 12 |
nicklas |
686 |
|
6183 |
24 Oct 12 |
nicklas |
// Perform whatever command as indicated by the selected value |
6183 |
24 Oct 12 |
nicklas |
if (cmd == 'save-as') |
3077 |
22 Jan 07 |
nicklas |
689 |
{ |
6183 |
24 Oct 12 |
nicklas |
table.saveCurrentContext(tableId); |
3077 |
22 Jan 07 |
nicklas |
691 |
} |
6183 |
24 Oct 12 |
nicklas |
else if (cmd == 'manage') |
935 |
14 Jul 05 |
nicklas |
693 |
{ |
6183 |
24 Oct 12 |
nicklas |
table.manageContexts(tableId); |
935 |
14 Jul 05 |
nicklas |
695 |
} |
6183 |
24 Oct 12 |
nicklas |
else if (cmd == 'load-preset') |
6183 |
24 Oct 12 |
nicklas |
697 |
{ |
6183 |
24 Oct 12 |
nicklas |
var presetId = Data.get(selected, 'preset-id'); |
6183 |
24 Oct 12 |
nicklas |
table.loadContext(tableId, presetId); |
6183 |
24 Oct 12 |
nicklas |
700 |
} |
6183 |
24 Oct 12 |
nicklas |
else if (cmd == 'manage-columns') |
6183 |
24 Oct 12 |
nicklas |
702 |
{ |
6183 |
24 Oct 12 |
nicklas |
table.configureColumns(tableId); |
6183 |
24 Oct 12 |
nicklas |
704 |
} |
6183 |
24 Oct 12 |
nicklas |
else if (cmd == 'clear-filter') |
6183 |
24 Oct 12 |
nicklas |
706 |
{ |
6183 |
24 Oct 12 |
nicklas |
table.clearFilter(tableId); |
6183 |
24 Oct 12 |
nicklas |
708 |
} |
6183 |
24 Oct 12 |
nicklas |
else if (cmd == 'option') |
6183 |
24 Oct 12 |
nicklas |
710 |
{ |
6183 |
24 Oct 12 |
nicklas |
var key = Data.get(selected, 'option-key'); |
6183 |
24 Oct 12 |
nicklas |
var value = Data.get(selected, 'option-value'); |
6183 |
24 Oct 12 |
nicklas |
table.setOption(tableId, key, value); |
6183 |
24 Oct 12 |
nicklas |
714 |
} |
417 |
19 Apr 05 |
nicklas |
715 |
} |
6183 |
24 Oct 12 |
nicklas |
716 |
|
6220 |
10 Jan 13 |
nicklas |
717 |
/** |
6220 |
10 Jan 13 |
nicklas |
Event handler for the 'Check/uncheck all' icon that select |
6220 |
10 Jan 13 |
nicklas |
or deselect all checkboxes on the current table page. |
6220 |
10 Jan 13 |
nicklas |
The element must have the table id stored in 'data-table-id' |
6220 |
10 Jan 13 |
nicklas |
attribute. The 'data-regexp' may be used to specify a regular |
6220 |
10 Jan 13 |
nicklas |
expression to match checkbox names, otherwise all numeric |
6220 |
10 Jan 13 |
nicklas |
checkboxes are included. |
6220 |
10 Jan 13 |
nicklas |
724 |
*/ |
6220 |
10 Jan 13 |
nicklas |
table.checkUncheckOnClick = function(event) |
6220 |
10 Jan 13 |
nicklas |
726 |
{ |
6220 |
10 Jan 13 |
nicklas |
var target = event.currentTarget; |
6220 |
10 Jan 13 |
nicklas |
var tableId = Data.get(target, 'table-id'); |
6220 |
10 Jan 13 |
nicklas |
var regexp = Data.get(target, 'regexp'); |
6834 |
08 Apr 15 |
nicklas |
var specialKey = event.altKey || event.ctrlKey || event.shiftKey; |
6834 |
08 Apr 15 |
nicklas |
if (specialKey) |
6834 |
08 Apr 15 |
nicklas |
732 |
{ |
6834 |
08 Apr 15 |
nicklas |
Forms.checkUncheck(document.forms[tableId], regexp); |
6834 |
08 Apr 15 |
nicklas |
734 |
} |
6834 |
08 Apr 15 |
nicklas |
else |
6834 |
08 Apr 15 |
nicklas |
736 |
{ |
6834 |
08 Apr 15 |
nicklas |
Forms.toggleCheckboxes(document.forms[tableId], regexp); |
6834 |
08 Apr 15 |
nicklas |
738 |
} |
6834 |
08 Apr 15 |
nicklas |
739 |
|
6220 |
10 Jan 13 |
nicklas |
740 |
} |
3077 |
22 Jan 07 |
nicklas |
741 |
|
3077 |
22 Jan 07 |
nicklas |
742 |
/** |
6699 |
30 Jan 15 |
nicklas |
Event handler for the 'Add filter row' and 'Remove filter row' icons |
6699 |
30 Jan 15 |
nicklas |
that adds or remove filter rows to/from the table. |
6697 |
29 Jan 15 |
nicklas |
The element must have the table id stored in 'data-table-id' |
6699 |
30 Jan 15 |
nicklas |
attribute. If 'remove-row' is set, a the given row is removed, |
6699 |
30 Jan 15 |
nicklas |
otherwise a new row is added. |
6697 |
29 Jan 15 |
nicklas |
748 |
*/ |
6699 |
30 Jan 15 |
nicklas |
table.filterRowActionOnClick = function(event) |
6697 |
29 Jan 15 |
nicklas |
750 |
{ |
6697 |
29 Jan 15 |
nicklas |
var target = event.currentTarget; |
6697 |
29 Jan 15 |
nicklas |
var tableId = Data.get(target, 'table-id'); |
6699 |
30 Jan 15 |
nicklas |
var removeRow = Data.get(target, 'remove-row'); |
6699 |
30 Jan 15 |
nicklas |
if (removeRow != null) |
6699 |
30 Jan 15 |
nicklas |
755 |
{ |
6699 |
30 Jan 15 |
nicklas |
table.removeFilterRow(tableId, removeRow); |
6699 |
30 Jan 15 |
nicklas |
757 |
} |
6699 |
30 Jan 15 |
nicklas |
else |
6699 |
30 Jan 15 |
nicklas |
759 |
{ |
6699 |
30 Jan 15 |
nicklas |
table.addFilterRow(tableId); |
6699 |
30 Jan 15 |
nicklas |
761 |
} |
6697 |
29 Jan 15 |
nicklas |
762 |
} |
6697 |
29 Jan 15 |
nicklas |
763 |
|
6697 |
29 Jan 15 |
nicklas |
764 |
/** |
6220 |
10 Jan 13 |
nicklas |
Event handler for clicking on the main item on the table. In normal |
6220 |
10 Jan 13 |
nicklas |
list mode, the event handler simply forwards to the Item.itemOnClick |
6220 |
10 Jan 13 |
nicklas |
method. In selection mode, the corresponding checkbox/radio button |
6220 |
10 Jan 13 |
nicklas |
is selected and returned to the caller and the window is closed. |
6220 |
10 Jan 13 |
nicklas |
769 |
*/ |
6220 |
10 Jan 13 |
nicklas |
table.mainItemOnClick = function(event) |
6220 |
10 Jan 13 |
nicklas |
771 |
{ |
6220 |
10 Jan 13 |
nicklas |
var target = event.currentTarget; |
6220 |
10 Jan 13 |
nicklas |
var tableId = Data.get(target, 'table-id'); |
6220 |
10 Jan 13 |
nicklas |
var itemId = Data.int(target, 'item-id'); |
6308 |
20 Aug 13 |
nicklas |
775 |
|
6220 |
10 Jan 13 |
nicklas |
var frm = document.forms[tableId]; |
6220 |
10 Jan 13 |
nicklas |
var mode = frm.mode ? frm.mode.value : 'default'; |
6220 |
10 Jan 13 |
nicklas |
if (mode == 'selectone') |
6220 |
10 Jan 13 |
nicklas |
779 |
{ |
6220 |
10 Jan 13 |
nicklas |
var index = Forms.checkRadio(frm.item_id, itemId); |
6222 |
14 Jan 13 |
nicklas |
table.returnSelectedItems(tableId); |
6222 |
14 Jan 13 |
nicklas |
App.closeWindow(); |
6220 |
10 Jan 13 |
nicklas |
783 |
} |
6220 |
10 Jan 13 |
nicklas |
else if (mode == 'selectmultiple' || mode == 'selectmultiplenobuttons') |
6220 |
10 Jan 13 |
nicklas |
785 |
{ |
6220 |
10 Jan 13 |
nicklas |
var checkbox = table.toggleCheckBox(tableId, itemId); |
6222 |
14 Jan 13 |
nicklas |
table.returnSelectedItems(tableId); |
6222 |
14 Jan 13 |
nicklas |
App.closeWindow(); |
6220 |
10 Jan 13 |
nicklas |
789 |
} |
6840 |
09 Apr 15 |
nicklas |
else if (mode == 'selectfilter') |
6840 |
09 Apr 15 |
nicklas |
791 |
{ |
6840 |
09 Apr 15 |
nicklas |
table.toggleCheckBox(tableId, itemId); |
6840 |
09 Apr 15 |
nicklas |
793 |
} |
6220 |
10 Jan 13 |
nicklas |
else |
6220 |
10 Jan 13 |
nicklas |
795 |
{ |
6220 |
10 Jan 13 |
nicklas |
Items.itemOnClick(event); |
6220 |
10 Jan 13 |
nicklas |
797 |
} |
6220 |
10 Jan 13 |
nicklas |
798 |
} |
6220 |
10 Jan 13 |
nicklas |
799 |
|
6220 |
10 Jan 13 |
nicklas |
800 |
/** |
3077 |
22 Jan 07 |
nicklas |
Get all columns defined for the specified table. |
6188 |
30 Oct 12 |
nicklas |
@param tableDiv The ID or main table element |
3077 |
22 Jan 07 |
nicklas |
803 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.getColumnDefs = function(tableDiv) |
3077 |
22 Jan 07 |
nicklas |
805 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var columns = columnDefs[tableDiv.id]; |
6183 |
24 Oct 12 |
nicklas |
if (!columns) |
6183 |
24 Oct 12 |
nicklas |
809 |
{ |
6188 |
30 Oct 12 |
nicklas |
columns = Data.json(tableDiv.id+'.table-data', 'column-defs'); |
6186 |
29 Oct 12 |
nicklas |
// Store each definitition using the 'id' as a key |
6183 |
24 Oct 12 |
nicklas |
for (var i = 0; i < columns.length; i++) |
6183 |
24 Oct 12 |
nicklas |
813 |
{ |
6183 |
24 Oct 12 |
nicklas |
columns['id'+columns[i].id] = columns[i]; |
6183 |
24 Oct 12 |
nicklas |
815 |
} |
6183 |
24 Oct 12 |
nicklas |
816 |
|
6188 |
30 Oct 12 |
nicklas |
columnDefs[tableDiv.id] = columns; |
6183 |
24 Oct 12 |
nicklas |
818 |
} |
6183 |
24 Oct 12 |
nicklas |
return columns; |
3077 |
22 Jan 07 |
nicklas |
820 |
} |
417 |
19 Apr 05 |
nicklas |
821 |
|
417 |
19 Apr 05 |
nicklas |
822 |
/** |
417 |
19 Apr 05 |
nicklas |
Change the page of the table. |
6188 |
30 Oct 12 |
nicklas |
@param tableDiv The ID or main table element |
6182 |
23 Oct 12 |
nicklas |
@param page The new page number |
417 |
19 Apr 05 |
nicklas |
826 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.setPage = function(tableDiv, page) |
417 |
19 Apr 05 |
nicklas |
828 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var frm = document.forms[tableDiv.id]; |
417 |
19 Apr 05 |
nicklas |
if (frm.page.value != page) |
417 |
19 Apr 05 |
nicklas |
832 |
{ |
417 |
19 Apr 05 |
nicklas |
frm.page.value = page; |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
417 |
19 Apr 05 |
nicklas |
835 |
} |
417 |
19 Apr 05 |
nicklas |
836 |
} |
417 |
19 Apr 05 |
nicklas |
837 |
|
417 |
19 Apr 05 |
nicklas |
838 |
/** |
417 |
19 Apr 05 |
nicklas |
Change the visible columns of the table. |
6188 |
30 Oct 12 |
nicklas |
@param tableDiv The ID or main table element |
417 |
19 Apr 05 |
nicklas |
@param columns Comma-separated list of column ID:s of the visible columns, or the value 'all' |
417 |
19 Apr 05 |
nicklas |
842 |
*/ |
7982 |
14 Jun 21 |
nicklas |
table.setColumns = function(tableDiv, columns, stickyColumn) |
417 |
19 Apr 05 |
nicklas |
844 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var frm = document.forms[tableDiv.id]; |
7982 |
14 Jun 21 |
nicklas |
var submit = false; |
417 |
19 Apr 05 |
nicklas |
if (frm.columns.value != columns) |
417 |
19 Apr 05 |
nicklas |
849 |
{ |
417 |
19 Apr 05 |
nicklas |
frm.columns.value = columns; |
7982 |
14 Jun 21 |
nicklas |
submit = true; |
417 |
19 Apr 05 |
nicklas |
852 |
} |
7982 |
14 Jun 21 |
nicklas |
if (stickyColumn && frm.sticky_column && frm.sticky_column.value != stickyColumn) |
7982 |
14 Jun 21 |
nicklas |
854 |
{ |
7982 |
14 Jun 21 |
nicklas |
frm.sticky_column.value = stickyColumn; |
7982 |
14 Jun 21 |
nicklas |
submit = true; |
7982 |
14 Jun 21 |
nicklas |
857 |
} |
7982 |
14 Jun 21 |
nicklas |
if (submit) Forms.submit(frm); |
417 |
19 Apr 05 |
nicklas |
859 |
} |
526 |
04 May 05 |
nicklas |
860 |
|
417 |
19 Apr 05 |
nicklas |
861 |
/** |
1760 |
12 Jan 06 |
nicklas |
Show columns in the table, preserving the currently visible columns. |
6188 |
30 Oct 12 |
nicklas |
@param tableDiv The ID or main table element |
1760 |
12 Jan 06 |
nicklas |
@param columns Comma-separated list of column ID:s of the visible columns, or the value 'all' |
1760 |
12 Jan 06 |
nicklas |
865 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.showColumns = function(tableDiv, columns) |
1760 |
12 Jan 06 |
nicklas |
867 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var frm = document.forms[tableDiv.id]; |
1760 |
12 Jan 06 |
nicklas |
if (frm.columns.value != columns) |
1760 |
12 Jan 06 |
nicklas |
871 |
{ |
1760 |
12 Jan 06 |
nicklas |
frm.columns.value += ',' + columns; |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
1760 |
12 Jan 06 |
nicklas |
874 |
} |
1760 |
12 Jan 06 |
nicklas |
875 |
} |
1760 |
12 Jan 06 |
nicklas |
876 |
|
452 |
25 Apr 05 |
nicklas |
877 |
|
452 |
25 Apr 05 |
nicklas |
878 |
/** |
424 |
20 Apr 05 |
nicklas |
Get the visible columns of the table. |
6188 |
30 Oct 12 |
nicklas |
@param tableDiv The ID or main table element |
424 |
20 Apr 05 |
nicklas |
881 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.getColumns = function(tableDiv) |
424 |
20 Apr 05 |
nicklas |
883 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var frm = document.forms[tableDiv.id]; |
424 |
20 Apr 05 |
nicklas |
return frm.columns.value; |
424 |
20 Apr 05 |
nicklas |
887 |
} |
424 |
20 Apr 05 |
nicklas |
888 |
|
7982 |
14 Jun 21 |
nicklas |
table.getStickyColumn = function(tableDiv) |
7982 |
14 Jun 21 |
nicklas |
890 |
{ |
7982 |
14 Jun 21 |
nicklas |
tableDiv = Doc.element(tableDiv); |
7982 |
14 Jun 21 |
nicklas |
var frm = document.forms[tableDiv.id]; |
7982 |
14 Jun 21 |
nicklas |
return frm.sticky_column ? frm.sticky_column.value : null; |
7982 |
14 Jun 21 |
nicklas |
894 |
} |
452 |
25 Apr 05 |
nicklas |
895 |
|
6182 |
23 Oct 12 |
nicklas |
896 |
/** |
6182 |
23 Oct 12 |
nicklas |
Clear the all filters |
6188 |
30 Oct 12 |
nicklas |
@param tableDiv The ID or main table element |
6182 |
23 Oct 12 |
nicklas |
899 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.clearFilter = function(tableDiv) |
1714 |
14 Dec 05 |
nicklas |
901 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6182 |
23 Oct 12 |
nicklas |
Forms.addHidden(frm, 'filter:clearAll', '1'); |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
1714 |
14 Dec 05 |
nicklas |
906 |
} |
1714 |
14 Dec 05 |
nicklas |
907 |
|
6182 |
23 Oct 12 |
nicklas |
908 |
/** |
6697 |
29 Jan 15 |
nicklas |
Add a new filter row to the table |
6697 |
29 Jan 15 |
nicklas |
@param tableDiv The ID or main table element |
6697 |
29 Jan 15 |
nicklas |
911 |
*/ |
6697 |
29 Jan 15 |
nicklas |
table.addFilterRow = function(tableDiv) |
6697 |
29 Jan 15 |
nicklas |
913 |
{ |
6697 |
29 Jan 15 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6697 |
29 Jan 15 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6697 |
29 Jan 15 |
nicklas |
Forms.addHidden(frm, 'addFilterRows', '1'); |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
6697 |
29 Jan 15 |
nicklas |
918 |
} |
6697 |
29 Jan 15 |
nicklas |
919 |
|
6697 |
29 Jan 15 |
nicklas |
920 |
/** |
6697 |
29 Jan 15 |
nicklas |
Remove a filter row from the table |
6697 |
29 Jan 15 |
nicklas |
@param tableDiv The ID or main table element |
6697 |
29 Jan 15 |
nicklas |
@param filterIndex The index of the filter row, starting at 0 |
6697 |
29 Jan 15 |
nicklas |
924 |
*/ |
6697 |
29 Jan 15 |
nicklas |
table.removeFilterRow = function(tableDiv, filterIndex) |
6697 |
29 Jan 15 |
nicklas |
926 |
{ |
6697 |
29 Jan 15 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6697 |
29 Jan 15 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6697 |
29 Jan 15 |
nicklas |
Forms.addHidden(frm, 'removeFilterRow', filterIndex); |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
6697 |
29 Jan 15 |
nicklas |
931 |
} |
6697 |
29 Jan 15 |
nicklas |
932 |
|
6697 |
29 Jan 15 |
nicklas |
933 |
/** |
6183 |
24 Oct 12 |
nicklas |
Open a popup window that allows a user to configure which columns |
6183 |
24 Oct 12 |
nicklas |
that should be visible and their order. |
6183 |
24 Oct 12 |
nicklas |
@param table The ID or main table element |
6183 |
24 Oct 12 |
nicklas |
@param settingName The name of the setting that is used to store the |
6183 |
24 Oct 12 |
nicklas |
column visibility and order, if not specified the default is 'columns' |
6183 |
24 Oct 12 |
nicklas |
939 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.configureColumns = function(tableDiv, settingName) |
6183 |
24 Oct 12 |
nicklas |
941 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
7982 |
14 Jun 21 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6188 |
30 Oct 12 |
nicklas |
var itemType = Data.get(tableDiv, 'item-type'); |
6188 |
30 Oct 12 |
nicklas |
var subContext = Data.get(tableDiv, 'subcontext', ''); |
6689 |
21 Jan 15 |
nicklas |
var enableInheritedAnnotations = Data.get(tableDiv, 'inherited-annotations'); |
7842 |
01 Sep 20 |
nicklas |
var enableRelatedItemColumns = Data.get(tableDiv, 'relateditem-columns'); |
7851 |
14 Oct 20 |
nicklas |
var disableLinkedItemColumns = Data.get(tableDiv, 'no-linkeditem-columns'); |
6183 |
24 Oct 12 |
nicklas |
949 |
|
6183 |
24 Oct 12 |
nicklas |
var url = App.getRoot()+'common/columns/configure.jsp?ID='+App.getSessionId(); |
6188 |
30 Oct 12 |
nicklas |
url += '&table_id='+tableDiv.id+'&item_type='+itemType+'&subcontext='+subContext; |
7851 |
14 Oct 20 |
nicklas |
if (enableInheritedAnnotations) url += '&enableInheritedAnnotations=1'; |
7851 |
14 Oct 20 |
nicklas |
if (enableRelatedItemColumns) url += '&enableRelatedItemColumns=1'; |
7851 |
14 Oct 20 |
nicklas |
if (!disableLinkedItemColumns) url += '&enableLinkedItemColumns=1'; |
7982 |
14 Jun 21 |
nicklas |
if (frm.sticky_column) url += '&enableStickyColumn=1'; |
7851 |
14 Oct 20 |
nicklas |
956 |
|
6183 |
24 Oct 12 |
nicklas |
if (settingName) url += '&settingName='+settingName; |
6576 |
22 Oct 14 |
nicklas |
Dialogs.openPopup(url, 'ConfigureColumns', 750, 450); |
6183 |
24 Oct 12 |
nicklas |
959 |
} |
6183 |
24 Oct 12 |
nicklas |
960 |
|
6183 |
24 Oct 12 |
nicklas |
961 |
/** |
6182 |
23 Oct 12 |
nicklas |
Open a popup dialog that allows the user to save the current |
6182 |
23 Oct 12 |
nicklas |
table settings to a named preset. |
6182 |
23 Oct 12 |
nicklas |
@param table The ID or main table element |
6182 |
23 Oct 12 |
nicklas |
965 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.saveCurrentContext = function(tableDiv) |
1714 |
14 Dec 05 |
nicklas |
967 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var itemType = Data.get(tableDiv, 'item-type'); |
6188 |
30 Oct 12 |
nicklas |
var subContext = Data.get(tableDiv, 'subcontext', ''); |
6182 |
23 Oct 12 |
nicklas |
var url = App.getRoot()+'common/context/saveas.jsp?ID='+App.getSessionId(); |
6182 |
23 Oct 12 |
nicklas |
url += '&item_type='+itemType+'&subcontext='+subContext; |
6182 |
23 Oct 12 |
nicklas |
Dialogs.openPopup(url, 'SaveCurrentContext', 450, 300); |
6182 |
23 Oct 12 |
nicklas |
974 |
} |
6183 |
24 Oct 12 |
nicklas |
975 |
|
6182 |
23 Oct 12 |
nicklas |
976 |
/** |
6182 |
23 Oct 12 |
nicklas |
Open a popup dialog that allows the user to manage (eg. load or delete) |
6182 |
23 Oct 12 |
nicklas |
all table setting presets that have been saved for the given table. |
6182 |
23 Oct 12 |
nicklas |
@param table The ID or main table element |
6182 |
23 Oct 12 |
nicklas |
980 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.manageContexts = function(tableDiv) |
6182 |
23 Oct 12 |
nicklas |
982 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var itemType = Data.get(tableDiv, 'item-type'); |
6188 |
30 Oct 12 |
nicklas |
var subContext = Data.get(tableDiv, 'subcontext', ''); |
6182 |
23 Oct 12 |
nicklas |
var url = App.getRoot()+'common/context/manage.jsp?ID='+App.getSessionId(); |
6182 |
23 Oct 12 |
nicklas |
url += '&item_type='+itemType+'&subcontext='+subContext; |
6182 |
23 Oct 12 |
nicklas |
Dialogs.openPopup(url, 'ManageContexts', 450, 300); |
6182 |
23 Oct 12 |
nicklas |
989 |
} |
6183 |
24 Oct 12 |
nicklas |
990 |
|
6182 |
23 Oct 12 |
nicklas |
991 |
/** |
6182 |
23 Oct 12 |
nicklas |
Load the table settings preset with the given id. |
6182 |
23 Oct 12 |
nicklas |
@param table The ID or main table element |
6182 |
23 Oct 12 |
nicklas |
994 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.loadContext = function(tableDiv, contextId) |
6182 |
23 Oct 12 |
nicklas |
996 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6182 |
23 Oct 12 |
nicklas |
Forms.addHidden(frm, 'context', contextId); |
6182 |
23 Oct 12 |
nicklas |
frm.cmd.value = 'LoadContext'; |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
1714 |
14 Dec 05 |
nicklas |
1002 |
} |
6183 |
24 Oct 12 |
nicklas |
1003 |
|
6182 |
23 Oct 12 |
nicklas |
1004 |
/** |
6182 |
23 Oct 12 |
nicklas |
Change a table option and reload the table. |
6182 |
23 Oct 12 |
nicklas |
1006 |
|
6182 |
23 Oct 12 |
nicklas |
@param table The ID or main table element |
6182 |
23 Oct 12 |
nicklas |
@param name The name of the option |
6182 |
23 Oct 12 |
nicklas |
@param value The value of the option |
6182 |
23 Oct 12 |
nicklas |
1010 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.setOption = function(tableDiv, name, value) |
1714 |
14 Dec 05 |
nicklas |
1012 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6182 |
23 Oct 12 |
nicklas |
frm[name].value = value; |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
1714 |
14 Dec 05 |
nicklas |
1017 |
} |
1714 |
14 Dec 05 |
nicklas |
1018 |
|
6183 |
24 Oct 12 |
nicklas |
1019 |
|
6188 |
30 Oct 12 |
nicklas |
1020 |
/** |
6188 |
30 Oct 12 |
nicklas |
Open a popup window with the given width and height |
6188 |
30 Oct 12 |
nicklas |
and submit the table form (POST) to that popup. |
6220 |
10 Jan 13 |
nicklas |
@param tableDiv The ID or main table element |
6188 |
30 Oct 12 |
nicklas |
@param cmd The command value to use when sending the form |
6188 |
30 Oct 12 |
nicklas |
(the old command is restored afterwards) |
6188 |
30 Oct 12 |
nicklas |
@param width The width in pixels of the popup (may be scaled) |
6188 |
30 Oct 12 |
nicklas |
@param height The height in pixels of the popup (may be scaled) |
6188 |
30 Oct 12 |
nicklas |
1028 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.submitToPopup = function(tableDiv, cmd, width, height) |
1714 |
14 Dec 05 |
nicklas |
1030 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6188 |
30 Oct 12 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6183 |
24 Oct 12 |
nicklas |
var oldCmd = frm.cmd.value; |
6188 |
30 Oct 12 |
nicklas |
var oldTarget = frm.target; |
6183 |
24 Oct 12 |
nicklas |
frm.cmd.value = cmd; |
6200 |
05 Nov 12 |
nicklas |
frm.target = tableDiv.id+cmd; |
6188 |
30 Oct 12 |
nicklas |
Dialogs.openPopup('', frm.target, width, height); |
6183 |
24 Oct 12 |
nicklas |
frm.submit(); |
6188 |
30 Oct 12 |
nicklas |
frm.target = oldTarget; |
6183 |
24 Oct 12 |
nicklas |
frm.cmd.value = oldCmd; |
1714 |
14 Dec 05 |
nicklas |
1041 |
} |
6182 |
23 Oct 12 |
nicklas |
1042 |
|
6188 |
30 Oct 12 |
nicklas |
1043 |
/** |
6289 |
05 Jun 13 |
nicklas |
Submit the table using the given cmd if there is |
6289 |
05 Jun 13 |
nicklas |
at least one item selected. |
6289 |
05 Jun 13 |
nicklas |
@param tableDiv The ID or main table element |
6289 |
05 Jun 13 |
nicklas |
@param cmd The command value to use when sending the form |
6289 |
05 Jun 13 |
nicklas |
@param regexp A regular expression to use for matching checkboxes in the table, |
6289 |
05 Jun 13 |
nicklas |
if not specified all checkboxes with a numeric name are used |
6289 |
05 Jun 13 |
nicklas |
1050 |
*/ |
6289 |
05 Jun 13 |
nicklas |
table.submitSelected = function(tableDiv, cmd, regexp) |
6289 |
05 Jun 13 |
nicklas |
1052 |
{ |
6289 |
05 Jun 13 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6289 |
05 Jun 13 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6289 |
05 Jun 13 |
nicklas |
if (!table.checkIfSelected(tableDiv, regexp)) |
6289 |
05 Jun 13 |
nicklas |
1056 |
{ |
6289 |
05 Jun 13 |
nicklas |
return; |
6289 |
05 Jun 13 |
nicklas |
1058 |
} |
6289 |
05 Jun 13 |
nicklas |
frm.cmd.value = cmd; |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
6289 |
05 Jun 13 |
nicklas |
1061 |
} |
6289 |
05 Jun 13 |
nicklas |
1062 |
|
6289 |
05 Jun 13 |
nicklas |
1063 |
/** |
6220 |
10 Jan 13 |
nicklas |
Submit a request to delete (or put in trashcan) all selected items |
6220 |
10 Jan 13 |
nicklas |
in the table. |
6220 |
10 Jan 13 |
nicklas |
@param tableDiv The ID or main table element |
6220 |
10 Jan 13 |
nicklas |
@param regexp A regular expression to use for matching checkboxes in the table, |
6220 |
10 Jan 13 |
nicklas |
if not specified all checkboxes with a numeric name are used |
6260 |
27 Mar 13 |
nicklas |
@param confirmFirst If set, ask for confirmation before deleting the items |
6220 |
10 Jan 13 |
nicklas |
1070 |
*/ |
6260 |
27 Mar 13 |
nicklas |
table.deleteItems = function(tableDiv, regexp, confirmFirst) |
6220 |
10 Jan 13 |
nicklas |
1072 |
{ |
6220 |
10 Jan 13 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6220 |
10 Jan 13 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6260 |
27 Mar 13 |
nicklas |
var numSelected = table.checkIfSelected(tableDiv, regexp); |
6260 |
27 Mar 13 |
nicklas |
if (numSelected == 0) return; |
6260 |
27 Mar 13 |
nicklas |
if (confirmFirst) |
6220 |
10 Jan 13 |
nicklas |
1078 |
{ |
6220 |
10 Jan 13 |
nicklas |
if (!confirm('You are about to delete '+numSelected+' items. This can\'t be undone. Continue?')) |
6220 |
10 Jan 13 |
nicklas |
1080 |
{ |
6220 |
10 Jan 13 |
nicklas |
return; |
6220 |
10 Jan 13 |
nicklas |
1082 |
} |
6220 |
10 Jan 13 |
nicklas |
1083 |
} |
6220 |
10 Jan 13 |
nicklas |
frm.cmd.value = 'DeleteItems'; |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
6220 |
10 Jan 13 |
nicklas |
1086 |
} |
6220 |
10 Jan 13 |
nicklas |
1087 |
|
6220 |
10 Jan 13 |
nicklas |
1088 |
/** |
6220 |
10 Jan 13 |
nicklas |
Submit a request to undelete (remove from trashcan) all selected items |
6220 |
10 Jan 13 |
nicklas |
in the table. |
6220 |
10 Jan 13 |
nicklas |
@param tableDiv The ID or main table element |
6220 |
10 Jan 13 |
nicklas |
@param regexp A regular expression to use for matching checkboxes in the table, |
6220 |
10 Jan 13 |
nicklas |
if not specified all checkboxes with a numeric name are used |
6220 |
10 Jan 13 |
nicklas |
1094 |
*/ |
6220 |
10 Jan 13 |
nicklas |
table.restoreItems = function(tableDiv, regexp) |
6220 |
10 Jan 13 |
nicklas |
1096 |
{ |
6220 |
10 Jan 13 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6220 |
10 Jan 13 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6260 |
27 Mar 13 |
nicklas |
if (!table.checkIfSelected(tableDiv, regexp)) |
6220 |
10 Jan 13 |
nicklas |
1100 |
{ |
6260 |
27 Mar 13 |
nicklas |
return; |
6220 |
10 Jan 13 |
nicklas |
1102 |
} |
6220 |
10 Jan 13 |
nicklas |
frm.cmd.value = 'RestoreItems'; |
7894 |
08 Dec 20 |
nicklas |
Forms.submit(frm); |
6220 |
10 Jan 13 |
nicklas |
1105 |
} |
6220 |
10 Jan 13 |
nicklas |
1106 |
|
6220 |
10 Jan 13 |
nicklas |
1107 |
|
6220 |
10 Jan 13 |
nicklas |
1108 |
/** |
6188 |
30 Oct 12 |
nicklas |
Open a popup dialog that allows a user to select a new owner for |
6188 |
30 Oct 12 |
nicklas |
all items that are selected in the given table. |
6188 |
30 Oct 12 |
nicklas |
@param tableDiv The ID or main table element |
6188 |
30 Oct 12 |
nicklas |
@param regexp An optional regular expression matching the names |
6188 |
30 Oct 12 |
nicklas |
of checkboxes that can be selected, if not specified it matches |
6188 |
30 Oct 12 |
nicklas |
checkboxes with numeric names (eg. the name is the id of the item |
6188 |
30 Oct 12 |
nicklas |
in the table) |
6188 |
30 Oct 12 |
nicklas |
1116 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.setOwnerOfItems = function(tableDiv, regexp) |
1714 |
14 Dec 05 |
nicklas |
1118 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6260 |
27 Mar 13 |
nicklas |
if (!table.checkIfSelected(tableDiv, regexp)) |
1714 |
14 Dec 05 |
nicklas |
1121 |
{ |
6260 |
27 Mar 13 |
nicklas |
return; |
1714 |
14 Dec 05 |
nicklas |
1123 |
} |
6188 |
30 Oct 12 |
nicklas |
table.submitToPopup(tableDiv, 'SetOwnerOfItems', 450, 300); |
6188 |
30 Oct 12 |
nicklas |
1125 |
} |
6188 |
30 Oct 12 |
nicklas |
1126 |
|
6188 |
30 Oct 12 |
nicklas |
1127 |
/** |
6188 |
30 Oct 12 |
nicklas |
Open a popup dialog that allows a user to specify sharing permissions |
6188 |
30 Oct 12 |
nicklas |
for all items that are selected in the given table. |
6188 |
30 Oct 12 |
nicklas |
@param tableDiv The ID or main table element |
6188 |
30 Oct 12 |
nicklas |
@param regexp An optional regular expression matching the names |
6188 |
30 Oct 12 |
nicklas |
of checkboxes that can be selected, if not specified it matches |
6188 |
30 Oct 12 |
nicklas |
checkboxes with numeric names (eg. the name is the id of the item |
6188 |
30 Oct 12 |
nicklas |
in the table) |
6188 |
30 Oct 12 |
nicklas |
1135 |
*/ |
6188 |
30 Oct 12 |
nicklas |
table.shareItems = function(tableDiv, regexp) |
6183 |
24 Oct 12 |
nicklas |
1137 |
{ |
6188 |
30 Oct 12 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6260 |
27 Mar 13 |
nicklas |
if (!table.checkIfSelected(tableDiv, regexp)) |
1714 |
14 Dec 05 |
nicklas |
1140 |
{ |
6260 |
27 Mar 13 |
nicklas |
return; |
1714 |
14 Dec 05 |
nicklas |
1142 |
} |
6188 |
30 Oct 12 |
nicklas |
table.submitToPopup(tableDiv, 'ShareItems', 600, 400); |
6188 |
30 Oct 12 |
nicklas |
1144 |
} |
6188 |
30 Oct 12 |
nicklas |
1145 |
|
6220 |
10 Jan 13 |
nicklas |
1146 |
/** |
6694 |
26 Jan 15 |
nicklas |
Open a popup dialog that allows a user to bathc inherit annotations |
6694 |
26 Jan 15 |
nicklas |
to all items that are selected in the given table. |
6694 |
26 Jan 15 |
nicklas |
@param tableDiv The ID or main table element |
6694 |
26 Jan 15 |
nicklas |
@param regexp An optional regular expression matching the names |
6694 |
26 Jan 15 |
nicklas |
of checkboxes that can be selected, if not specified it matches |
6694 |
26 Jan 15 |
nicklas |
checkboxes with numeric names (eg. the name is the id of the item |
6694 |
26 Jan 15 |
nicklas |
in the table) |
6694 |
26 Jan 15 |
nicklas |
1154 |
*/ |
6694 |
26 Jan 15 |
nicklas |
table.inheritAnnotations = function(tableDiv, regexp) |
6694 |
26 Jan 15 |
nicklas |
1156 |
{ |
6694 |
26 Jan 15 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6694 |
26 Jan 15 |
nicklas |
if (!table.checkIfSelected(tableDiv, regexp)) |
6694 |
26 Jan 15 |
nicklas |
1159 |
{ |
6694 |
26 Jan 15 |
nicklas |
return; |
6694 |
26 Jan 15 |
nicklas |
1161 |
} |
6694 |
26 Jan 15 |
nicklas |
table.submitToPopup(tableDiv, 'InheritAnnotations', 750, 500); |
6694 |
26 Jan 15 |
nicklas |
1163 |
} |
6694 |
26 Jan 15 |
nicklas |
1164 |
|
6694 |
26 Jan 15 |
nicklas |
1165 |
|
6694 |
26 Jan 15 |
nicklas |
1166 |
/** |
6220 |
10 Jan 13 |
nicklas |
Open a popup window for selecting a plug-in that can run in the |
6220 |
10 Jan 13 |
nicklas |
current list context |
6220 |
10 Jan 13 |
nicklas |
@param tableDiv The ID or main table element |
6315 |
06 Sep 13 |
nicklas |
@param pluginType One of: IMPORT, EXPORT, ANALYZE or OTHER (default) |
6315 |
06 Sep 13 |
nicklas |
@param cmd Override the default command for running the plugin |
6220 |
10 Jan 13 |
nicklas |
1172 |
*/ |
6315 |
06 Sep 13 |
nicklas |
table.runPlugin = function(tableDiv, pluginType, cmd) |
6220 |
10 Jan 13 |
nicklas |
1174 |
{ |
6315 |
06 Sep 13 |
nicklas |
if (!cmd) |
6220 |
10 Jan 13 |
nicklas |
1176 |
{ |
6315 |
06 Sep 13 |
nicklas |
if (pluginType == 'EXPORT') |
6315 |
06 Sep 13 |
nicklas |
1178 |
{ |
6315 |
06 Sep 13 |
nicklas |
cmd = 'ExportItems'; |
6315 |
06 Sep 13 |
nicklas |
1180 |
} |
6315 |
06 Sep 13 |
nicklas |
else if (pluginType == 'IMPORT') |
6315 |
06 Sep 13 |
nicklas |
1182 |
{ |
6315 |
06 Sep 13 |
nicklas |
cmd = 'ImportItems'; |
6315 |
06 Sep 13 |
nicklas |
1184 |
} |
6315 |
06 Sep 13 |
nicklas |
else if (pluginType == 'ANALYZE') |
6315 |
06 Sep 13 |
nicklas |
1186 |
{ |
6315 |
06 Sep 13 |
nicklas |
cmd = 'RunListAnalysisPlugin'; |
6315 |
06 Sep 13 |
nicklas |
1188 |
} |
6315 |
06 Sep 13 |
nicklas |
else |
6315 |
06 Sep 13 |
nicklas |
1190 |
{ |
6315 |
06 Sep 13 |
nicklas |
cmd = 'RunListPlugin'; |
6315 |
06 Sep 13 |
nicklas |
1192 |
} |
6220 |
10 Jan 13 |
nicklas |
1193 |
} |
6220 |
10 Jan 13 |
nicklas |
table.submitToPopup(tableDiv, cmd, 750, 500); |
6220 |
10 Jan 13 |
nicklas |
1195 |
} |
6188 |
30 Oct 12 |
nicklas |
1196 |
|
6337 |
28 Oct 13 |
nicklas |
1197 |
/** |
6337 |
28 Oct 13 |
nicklas |
Toggle the selected status of a checkbox with |
6337 |
28 Oct 13 |
nicklas |
@param tableDiv The ID or main table element |
6337 |
28 Oct 13 |
nicklas |
1200 |
|
6337 |
28 Oct 13 |
nicklas |
@returns The toggled element or null if no element was found |
6337 |
28 Oct 13 |
nicklas |
1202 |
*/ |
6337 |
28 Oct 13 |
nicklas |
table.toggleCheckBox = function(tableDiv, itemId) |
6337 |
28 Oct 13 |
nicklas |
1204 |
{ |
6337 |
28 Oct 13 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6337 |
28 Oct 13 |
nicklas |
var frm = document.forms[tableDiv.id]; |
7419 |
03 Nov 17 |
nicklas |
1207 |
|
6337 |
28 Oct 13 |
nicklas |
for (var i=0; i < frm.elements.length; i++) |
6337 |
28 Oct 13 |
nicklas |
1209 |
{ |
6337 |
28 Oct 13 |
nicklas |
var element = frm.elements[i]; |
6337 |
28 Oct 13 |
nicklas |
if (element.type == 'checkbox' && element.name == itemId) |
6337 |
28 Oct 13 |
nicklas |
1212 |
{ |
6337 |
28 Oct 13 |
nicklas |
element.checked = !element.checked; |
6576 |
22 Oct 14 |
nicklas |
Events.sendChangeEvent(element); |
6337 |
28 Oct 13 |
nicklas |
return element; |
6337 |
28 Oct 13 |
nicklas |
1216 |
} |
6337 |
28 Oct 13 |
nicklas |
1217 |
} |
6337 |
28 Oct 13 |
nicklas |
return null; |
6337 |
28 Oct 13 |
nicklas |
1219 |
} |
6337 |
28 Oct 13 |
nicklas |
1220 |
|
6337 |
28 Oct 13 |
nicklas |
1221 |
/** |
6337 |
28 Oct 13 |
nicklas |
Get the ID of all selected items in a table. |
6337 |
28 Oct 13 |
nicklas |
1223 |
|
6337 |
28 Oct 13 |
nicklas |
@param tableDiv The ID or main table element |
6337 |
28 Oct 13 |
nicklas |
@param regexp An optional regular expression matching the names |
6337 |
28 Oct 13 |
nicklas |
of checkboxes that can be selected, if not specified it matches |
6337 |
28 Oct 13 |
nicklas |
checkboxes with numeric names (eg. the name is the id of the item |
6337 |
28 Oct 13 |
nicklas |
in the table) |
6337 |
28 Oct 13 |
nicklas |
@return An array object with the ID:s |
6337 |
28 Oct 13 |
nicklas |
1230 |
*/ |
6834 |
08 Apr 15 |
nicklas |
table.getSelected = function(tableDiv, regexp, messageIfNoneSelected) |
6337 |
28 Oct 13 |
nicklas |
1232 |
{ |
6337 |
28 Oct 13 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6337 |
28 Oct 13 |
nicklas |
if (!regexp) regexp = /\d+/; |
6337 |
28 Oct 13 |
nicklas |
1235 |
|
6337 |
28 Oct 13 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6337 |
28 Oct 13 |
nicklas |
var items = []; |
6337 |
28 Oct 13 |
nicklas |
if (frm.item_id) |
6337 |
28 Oct 13 |
nicklas |
1239 |
{ |
6337 |
28 Oct 13 |
nicklas |
// Radio buttons |
6337 |
28 Oct 13 |
nicklas |
var element = Forms.getCheckedRadio(frm.item_id); |
6337 |
28 Oct 13 |
nicklas |
if (element != null) |
6337 |
28 Oct 13 |
nicklas |
1243 |
{ |
6337 |
28 Oct 13 |
nicklas |
items[items.length] = element.value; |
6337 |
28 Oct 13 |
nicklas |
1245 |
} |
6337 |
28 Oct 13 |
nicklas |
1246 |
} |
6337 |
28 Oct 13 |
nicklas |
else |
6337 |
28 Oct 13 |
nicklas |
1248 |
{ |
6337 |
28 Oct 13 |
nicklas |
// Checkboxes |
6337 |
28 Oct 13 |
nicklas |
for (var i=0; i < frm.elements.length; i++) |
6337 |
28 Oct 13 |
nicklas |
1251 |
{ |
6337 |
28 Oct 13 |
nicklas |
var element = frm.elements[i]; |
6337 |
28 Oct 13 |
nicklas |
if (element.type == 'checkbox' && element.name.match(regexp) && element.checked) |
6337 |
28 Oct 13 |
nicklas |
1254 |
{ |
6337 |
28 Oct 13 |
nicklas |
items[items.length] = element.value; |
6337 |
28 Oct 13 |
nicklas |
1256 |
} |
6337 |
28 Oct 13 |
nicklas |
1257 |
} |
6337 |
28 Oct 13 |
nicklas |
1258 |
} |
6834 |
08 Apr 15 |
nicklas |
1259 |
|
6834 |
08 Apr 15 |
nicklas |
if (items.length == 0 && messageIfNoneSelected) |
6834 |
08 Apr 15 |
nicklas |
1261 |
{ |
6834 |
08 Apr 15 |
nicklas |
Forms.showNotification(tableDiv.tableCheck, messageIfNoneSelected, null, 'pointer-left'); |
6834 |
08 Apr 15 |
nicklas |
1263 |
} |
6834 |
08 Apr 15 |
nicklas |
1264 |
|
6337 |
28 Oct 13 |
nicklas |
return items; |
6337 |
28 Oct 13 |
nicklas |
1266 |
} |
6337 |
28 Oct 13 |
nicklas |
1267 |
|
6222 |
14 Jan 13 |
nicklas |
1268 |
|
6222 |
14 Jan 13 |
nicklas |
1269 |
/** |
6222 |
14 Jan 13 |
nicklas |
Return the selected items to the parent window using either a callback |
6222 |
14 Jan 13 |
nicklas |
method (older way) or an event notification (new way). |
6222 |
14 Jan 13 |
nicklas |
1272 |
|
6337 |
28 Oct 13 |
nicklas |
@param tableDiv The ID or main table element |
6337 |
28 Oct 13 |
nicklas |
@param regexp An optional regular expression matching the names |
6337 |
28 Oct 13 |
nicklas |
of checkboxes that can be selected, if not specified it matches |
6337 |
28 Oct 13 |
nicklas |
checkboxes with numeric names (eg. the name is the id of the item |
6337 |
28 Oct 13 |
nicklas |
in the table) |
6222 |
14 Jan 13 |
nicklas |
1278 |
|
6222 |
14 Jan 13 |
nicklas |
@return The number of selected items |
6222 |
14 Jan 13 |
nicklas |
1280 |
*/ |
6222 |
14 Jan 13 |
nicklas |
table.returnSelectedItems = function(tableDiv, regexp) |
6222 |
14 Jan 13 |
nicklas |
1282 |
{ |
6222 |
14 Jan 13 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6222 |
14 Jan 13 |
nicklas |
if (!regexp) regexp = /\d+/; |
6222 |
14 Jan 13 |
nicklas |
1285 |
|
6222 |
14 Jan 13 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6291 |
11 Jun 13 |
nicklas |
var itemType = Data.get(tableDiv, 'item-type'); |
6222 |
14 Jan 13 |
nicklas |
1288 |
|
6222 |
14 Jan 13 |
nicklas |
// Should we use 'callback method' or 'event notification'? |
6308 |
20 Aug 13 |
nicklas |
var callback = frm.callback ? frm.callback.value : null; |
6308 |
20 Aug 13 |
nicklas |
var notifyTarget = callback ? window.top.opener.document.getElementById(callback) : null; |
6308 |
20 Aug 13 |
nicklas |
var callbackMethod = callback ? window.top.opener[callback] : null; |
6222 |
14 Jan 13 |
nicklas |
1293 |
|
6308 |
20 Aug 13 |
nicklas |
if (!notifyTarget && !callbackMethod) |
6308 |
20 Aug 13 |
nicklas |
1295 |
{ |
6308 |
20 Aug 13 |
nicklas |
notifyTarget = tableDiv; |
6308 |
20 Aug 13 |
nicklas |
1297 |
} |
6308 |
20 Aug 13 |
nicklas |
1298 |
|
6576 |
22 Oct 14 |
nicklas |
var selected = []; |
6222 |
14 Jan 13 |
nicklas |
if (frm.item_id) |
6222 |
14 Jan 13 |
nicklas |
1301 |
{ |
6222 |
14 Jan 13 |
nicklas |
// Radio buttons allow single selection |
6222 |
14 Jan 13 |
nicklas |
var element = Forms.getCheckedRadio(frm.item_id); |
6222 |
14 Jan 13 |
nicklas |
if (element != null) |
6222 |
14 Jan 13 |
nicklas |
1305 |
{ |
6372 |
06 Dec 13 |
nicklas |
var id = element.value.match(/^\d+$/) ? parseInt(element.value) : element.value; |
6576 |
22 Oct 14 |
nicklas |
selected[selected.length] = {'id': id, 'name': element.title, 'itemType': itemType}; |
6222 |
14 Jan 13 |
nicklas |
1308 |
} |
6222 |
14 Jan 13 |
nicklas |
1309 |
} |
6222 |
14 Jan 13 |
nicklas |
else |
6222 |
14 Jan 13 |
nicklas |
1311 |
{ |
6222 |
14 Jan 13 |
nicklas |
// Check boxes allow multiple selections |
6308 |
20 Aug 13 |
nicklas |
for (var i=0; i < frm.elements.length; i++) |
6222 |
14 Jan 13 |
nicklas |
1314 |
{ |
6222 |
14 Jan 13 |
nicklas |
var element = frm.elements[i]; |
6222 |
14 Jan 13 |
nicklas |
if (element.type == 'checkbox' && element.name.match(regexp) && element.checked) |
6222 |
14 Jan 13 |
nicklas |
1317 |
{ |
6372 |
06 Dec 13 |
nicklas |
var id = element.value.match(/^\d+$/) ? parseInt(element.value) : element.value; |
6576 |
22 Oct 14 |
nicklas |
selected[selected.length] = {'id': id, 'name': element.title, 'itemType': itemType}; |
6222 |
14 Jan 13 |
nicklas |
1320 |
} |
6222 |
14 Jan 13 |
nicklas |
1321 |
} |
6222 |
14 Jan 13 |
nicklas |
1322 |
} |
6576 |
22 Oct 14 |
nicklas |
1323 |
|
6576 |
22 Oct 14 |
nicklas |
var remaining = selected.length-1; |
6770 |
13 Mar 15 |
nicklas |
if (notifyTarget) |
6770 |
13 Mar 15 |
nicklas |
1326 |
{ |
6770 |
13 Mar 15 |
nicklas |
Events.sendCustomEvent(notifyTarget, 'base-selected-start', { 'numSelected': selected.length }); |
6770 |
13 Mar 15 |
nicklas |
1328 |
} |
6576 |
22 Oct 14 |
nicklas |
for (var i = 0; i < selected.length; i++) |
6576 |
22 Oct 14 |
nicklas |
1330 |
{ |
6576 |
22 Oct 14 |
nicklas |
var s = selected[i]; |
6576 |
22 Oct 14 |
nicklas |
s.remaining = remaining--; |
6576 |
22 Oct 14 |
nicklas |
if (notifyTarget) |
6576 |
22 Oct 14 |
nicklas |
1334 |
{ |
6576 |
22 Oct 14 |
nicklas |
// Send event to the target in the opener window |
6576 |
22 Oct 14 |
nicklas |
Events.sendCustomEvent(notifyTarget, 'base-selected', s); |
6576 |
22 Oct 14 |
nicklas |
1337 |
} |
6576 |
22 Oct 14 |
nicklas |
else if (callbackMethod) |
6576 |
22 Oct 14 |
nicklas |
1339 |
{ |
6576 |
22 Oct 14 |
nicklas |
// Call the callback method in the opener window |
6576 |
22 Oct 14 |
nicklas |
callbackMethod.call(null, s.id, s.name); |
6576 |
22 Oct 14 |
nicklas |
1342 |
} |
6576 |
22 Oct 14 |
nicklas |
1343 |
} |
6576 |
22 Oct 14 |
nicklas |
1344 |
|
6576 |
22 Oct 14 |
nicklas |
return selected.length; |
6222 |
14 Jan 13 |
nicklas |
1346 |
} |
6222 |
14 Jan 13 |
nicklas |
1347 |
|
6260 |
27 Mar 13 |
nicklas |
table.checkIfSelected = function(tableDiv, regexp, messageIfNoneSelected) |
6260 |
27 Mar 13 |
nicklas |
1349 |
{ |
6260 |
27 Mar 13 |
nicklas |
tableDiv = Doc.element(tableDiv); |
6260 |
27 Mar 13 |
nicklas |
var frm = document.forms[tableDiv.id]; |
6260 |
27 Mar 13 |
nicklas |
var numSelected = Forms.numChecked(frm, regexp); |
6260 |
27 Mar 13 |
nicklas |
if (numSelected == 0) |
6260 |
27 Mar 13 |
nicklas |
1354 |
{ |
6260 |
27 Mar 13 |
nicklas |
if (!messageIfNoneSelected) |
6260 |
27 Mar 13 |
nicklas |
1356 |
{ |
6260 |
27 Mar 13 |
nicklas |
messageIfNoneSelected = 'Please select at least one item in the list'; |
6260 |
27 Mar 13 |
nicklas |
1358 |
} |
6834 |
08 Apr 15 |
nicklas |
Forms.showNotification(tableDiv.tableCheck, messageIfNoneSelected, null, 'pointer-left'); |
6260 |
27 Mar 13 |
nicklas |
1360 |
} |
6260 |
27 Mar 13 |
nicklas |
return numSelected; |
6260 |
27 Mar 13 |
nicklas |
1362 |
} |
6222 |
14 Jan 13 |
nicklas |
1363 |
|
6182 |
23 Oct 12 |
nicklas |
return table; |
6182 |
23 Oct 12 |
nicklas |
1365 |
}(); |
1775 |
16 Jan 06 |
nicklas |
1366 |
|
417 |
19 Apr 05 |
nicklas |
1367 |
|