6157 |
02 Mar 21 |
nicklas |
var VarSearchOptions = function() |
6157 |
02 Mar 21 |
nicklas |
2 |
{ |
6157 |
02 Mar 21 |
nicklas |
var options = {}; |
6157 |
02 Mar 21 |
nicklas |
4 |
|
6157 |
02 Mar 21 |
nicklas |
// Page initialization |
6157 |
02 Mar 21 |
nicklas |
options.initPage = function() |
6157 |
02 Mar 21 |
nicklas |
7 |
{ |
6176 |
19 Mar 21 |
nicklas |
var frm = document.forms['options']; |
6176 |
19 Mar 21 |
nicklas |
9 |
|
6176 |
19 Mar 21 |
nicklas |
// Initialise checkboxes and sort order list |
6176 |
19 Mar 21 |
nicklas |
var visible = frm.visibleColumns.value.split(','); |
6176 |
19 Mar 21 |
nicklas |
for (var i = 0; i < visible.length; i++) |
6176 |
19 Mar 21 |
nicklas |
13 |
{ |
6176 |
19 Mar 21 |
nicklas |
var colId = visible[i]; |
6176 |
19 Mar 21 |
nicklas |
if (frm[colId]) |
6176 |
19 Mar 21 |
nicklas |
16 |
{ |
6176 |
19 Mar 21 |
nicklas |
frm[colId].checked = true; |
6176 |
19 Mar 21 |
nicklas |
frm.sortOrder[frm.sortOrder.length] = new Option(frm[colId].parentNode.textContent, colId); |
6176 |
19 Mar 21 |
nicklas |
19 |
} |
6176 |
19 Mar 21 |
nicklas |
20 |
} |
6176 |
19 Mar 21 |
nicklas |
21 |
|
6176 |
19 Mar 21 |
nicklas |
// Add event handlers |
6176 |
19 Mar 21 |
nicklas |
for (var i = 0; i < frm.elements.length; i++) |
6176 |
19 Mar 21 |
nicklas |
24 |
{ |
6176 |
19 Mar 21 |
nicklas |
if (frm[i].type == 'checkbox') Events.addEventHandler(frm[i], 'change', options.toggleColumn);; |
6176 |
19 Mar 21 |
nicklas |
26 |
} |
6176 |
19 Mar 21 |
nicklas |
27 |
|
6176 |
19 Mar 21 |
nicklas |
Events.addEventHandler('sortOrder', 'dblclick', options.hideColumn); |
6176 |
19 Mar 21 |
nicklas |
Buttons.addClickHandler('moveUp', options.moveVisibleUpOrDown); |
6176 |
19 Mar 21 |
nicklas |
Buttons.addClickHandler('moveDown', options.moveVisibleUpOrDown); |
6176 |
19 Mar 21 |
nicklas |
31 |
|
6157 |
02 Mar 21 |
nicklas |
Buttons.addClickHandler('close', App.closeWindow); |
6157 |
02 Mar 21 |
nicklas |
Buttons.addClickHandler('btnOk', options.saveOptions); |
6157 |
02 Mar 21 |
nicklas |
34 |
} |
6157 |
02 Mar 21 |
nicklas |
35 |
|
6157 |
02 Mar 21 |
nicklas |
options.saveOptions = function() |
6157 |
02 Mar 21 |
nicklas |
37 |
{ |
6157 |
02 Mar 21 |
nicklas |
// At least one option should be selected |
6157 |
02 Mar 21 |
nicklas |
var frm = document.forms['options']; |
6157 |
02 Mar 21 |
nicklas |
var visible = []; |
6176 |
19 Mar 21 |
nicklas |
for (var i = 0; i < frm.sortOrder.length; i++) |
6157 |
02 Mar 21 |
nicklas |
42 |
{ |
6176 |
19 Mar 21 |
nicklas |
visible[visible.length] = frm.sortOrder[i].value; |
6157 |
02 Mar 21 |
nicklas |
44 |
} |
6157 |
02 Mar 21 |
nicklas |
45 |
|
6157 |
02 Mar 21 |
nicklas |
if (visible.length == 0) |
6157 |
02 Mar 21 |
nicklas |
47 |
{ |
6176 |
19 Mar 21 |
nicklas |
Forms.showNotification('LINKS', 'At least one column must be selected'); |
6157 |
02 Mar 21 |
nicklas |
return; |
6157 |
02 Mar 21 |
nicklas |
50 |
} |
6157 |
02 Mar 21 |
nicklas |
51 |
|
6157 |
02 Mar 21 |
nicklas |
frm.visibleColumns.value = visible.join(','); |
6157 |
02 Mar 21 |
nicklas |
frm.submit(); |
6157 |
02 Mar 21 |
nicklas |
54 |
} |
6157 |
02 Mar 21 |
nicklas |
55 |
|
6176 |
19 Mar 21 |
nicklas |
options.toggleColumn = function(event) |
6176 |
19 Mar 21 |
nicklas |
57 |
{ |
6176 |
19 Mar 21 |
nicklas |
var checkbox = event.currentTarget; |
6176 |
19 Mar 21 |
nicklas |
var frm = document.forms['options']; |
6176 |
19 Mar 21 |
nicklas |
if (checkbox.checked) |
6176 |
19 Mar 21 |
nicklas |
61 |
{ |
6176 |
19 Mar 21 |
nicklas |
var option = new Option(checkbox.parentNode.textContent, checkbox.id, true, true); |
6176 |
19 Mar 21 |
nicklas |
var atIndex = frm.sortOrder.length; |
6176 |
19 Mar 21 |
nicklas |
for (var i = atIndex-1; i>=0; i--) |
6176 |
19 Mar 21 |
nicklas |
65 |
{ |
6176 |
19 Mar 21 |
nicklas |
if (frm.sortOrder[i].selected) |
6176 |
19 Mar 21 |
nicklas |
67 |
{ |
6176 |
19 Mar 21 |
nicklas |
atIndex = i+1; |
6176 |
19 Mar 21 |
nicklas |
break; |
6176 |
19 Mar 21 |
nicklas |
70 |
} |
6176 |
19 Mar 21 |
nicklas |
71 |
} |
6176 |
19 Mar 21 |
nicklas |
72 |
|
6176 |
19 Mar 21 |
nicklas |
if (atIndex == 0) atIndex = frm.sortOrder.length; |
6176 |
19 Mar 21 |
nicklas |
Forms.addListOption(frm.sortOrder, atIndex, option); |
6176 |
19 Mar 21 |
nicklas |
75 |
} |
6176 |
19 Mar 21 |
nicklas |
else |
6176 |
19 Mar 21 |
nicklas |
77 |
{ |
6176 |
19 Mar 21 |
nicklas |
for (var i = 0; i < frm.sortOrder.length; i++) |
6176 |
19 Mar 21 |
nicklas |
79 |
{ |
6176 |
19 Mar 21 |
nicklas |
if (frm.sortOrder[i].value == checkbox.id) |
6176 |
19 Mar 21 |
nicklas |
81 |
{ |
6176 |
19 Mar 21 |
nicklas |
sortOrder[i] = null; |
6176 |
19 Mar 21 |
nicklas |
break; |
6176 |
19 Mar 21 |
nicklas |
84 |
} |
6176 |
19 Mar 21 |
nicklas |
85 |
} |
6176 |
19 Mar 21 |
nicklas |
86 |
} |
6176 |
19 Mar 21 |
nicklas |
87 |
} |
6176 |
19 Mar 21 |
nicklas |
88 |
|
6176 |
19 Mar 21 |
nicklas |
options.moveVisibleUpOrDown = function(event) |
6176 |
19 Mar 21 |
nicklas |
90 |
{ |
6176 |
19 Mar 21 |
nicklas |
var moveDown = Data.int(event.currentTarget, 'down'); |
6176 |
19 Mar 21 |
nicklas |
Forms.moveListOptions('sortOrder', moveDown); |
6176 |
19 Mar 21 |
nicklas |
93 |
} |
6176 |
19 Mar 21 |
nicklas |
94 |
|
6176 |
19 Mar 21 |
nicklas |
options.hideColumn = function() |
6176 |
19 Mar 21 |
nicklas |
96 |
{ |
6176 |
19 Mar 21 |
nicklas |
97 |
|
6176 |
19 Mar 21 |
nicklas |
var frm = document.forms['options']; |
6176 |
19 Mar 21 |
nicklas |
for (var i = 0; i < frm.sortOrder.length; i++) |
6176 |
19 Mar 21 |
nicklas |
100 |
{ |
6176 |
19 Mar 21 |
nicklas |
var option = frm.sortOrder[i]; |
6176 |
19 Mar 21 |
nicklas |
if (option.selected) |
6176 |
19 Mar 21 |
nicklas |
103 |
{ |
6176 |
19 Mar 21 |
nicklas |
frm.sortOrder[i] = null; |
6176 |
19 Mar 21 |
nicklas |
frm[option.value].checked = false; |
6176 |
19 Mar 21 |
nicklas |
i--; |
6176 |
19 Mar 21 |
nicklas |
107 |
} |
6176 |
19 Mar 21 |
nicklas |
108 |
} |
6176 |
19 Mar 21 |
nicklas |
109 |
} |
6176 |
19 Mar 21 |
nicklas |
110 |
|
6157 |
02 Mar 21 |
nicklas |
return options; |
6157 |
02 Mar 21 |
nicklas |
112 |
}(); |
6157 |
02 Mar 21 |
nicklas |
113 |
|
6157 |
02 Mar 21 |
nicklas |
Doc.onLoad(VarSearchOptions.initPage); |
6157 |
02 Mar 21 |
nicklas |
115 |
|