1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
function DeleteAllFromTree
(tree, view, table, deletedTable, removeButton, removeAllButton) {
gTreeUtils.deleteAll(tree, view, table, deletedTable);
// disable buttons
document.getElementById(removeButton).setAttribute("disabled", "true")
document.getElementById(removeAllButton).setAttribute("disabled","true");
}
function DeleteSelectedItemFromTree
(tree, view, table, deletedTable, removeButton, removeAllButton) {
gTreeUtils.deleteSelectedItems(tree, view, table, deletedTable);
// disable buttons if nothing left in the table
if (!table.length) {
document.getElementById(removeButton).setAttribute("disabled", "true")
document.getElementById(removeAllButton).setAttribute("disabled","true");
}
}
function GetTreeSelections(tree) {
var selections = [];
var select = tree.view.selection;
if (select) {
var count = select.getRangeCount();
var min = new Object();
var max = new Object();
for (var i=0; i<count; i++) {
select.getRangeAt(i, min, max);
for (var k=min.value; k<=max.value; k++) {
if (k != -1) {
selections[selections.length] = k;
}
}
}
}
return selections;
}
function SortTree(tree, view, table, column, lastSortColumn, lastSortAscending, updateSelection) {
// remember which item was selected so we can restore it after the sort
var selections = GetTreeSelections(tree);
var selectedNumber = selections.length ? table[selections[0]].id : -1;
// do the sort or re-sort
// this is a temporary hack for 1.7, we should implement
// display and sort variables here for trees in general
var sortColumn;
var comparator;
if (column == "expires") {
sortColumn = "expiresSortValue";
comparator = function compare(a, b) { return a - b; };
} else {
sortColumn = column;
comparator = function compare(a, b) {
return a.toLowerCase().localeCompare(b.toLowerCase());
};
}
if (lastSortColumn == "expires") {
lastSortColumn = "expiresSortValue";
}
var ascending = gTreeUtils.sort(tree, view, table, sortColumn, comparator,
lastSortColumn, lastSortAscending);
// restore the selection
if (selectedNumber >= 0 && updateSelection) {
var selectedRow = -1;
for (var s = 0; s < table.length; s++) {
if (table[s].id == selectedNumber) {
selectedRow = s;
break;
}
}
if (selectedRow > 0) {
// update selection and display the results
tree.view.selection.select(selectedRow);
tree.treeBoxObject.invalidate();
tree.treeBoxObject.ensureRowIsVisible(selectedRow);
}
}
return ascending;
}
function handleHostInput(aValue) {
// trim any leading and trailing spaces and scheme
// and set buttons appropiately
btnDisable(!trimSpacesAndScheme(aValue));
}
function trimSpacesAndScheme(aString) {
if (!aString)
return "";
return aString.trim().replace(/([-\w]*:\/+)?/, "");
}
function btnDisable(aDisabled) {
document.getElementById("btnSession").disabled = aDisabled;
document.getElementById("btnBlock").disabled = aDisabled;
document.getElementById("btnAllow").disabled = aDisabled;
}
function PermissionSelected(tree) {
var hasSelection = tree.view.selection.count > 0;
document.getElementById("removePermission").disabled = !hasSelection;
}
function SetSortDirection(tree, column, ascending) {
// first we need to get the right elements
for (let col of tree.getElementsByTagName("treecol")) {
if (col.id == column) {
// set the sortDirection attribute to get the styling going
col.setAttribute("sortDirection", ascending ? "ascending" : "descending");
}
else {
// clear out the sortDirection attribute on the rest of the columns
col.removeAttribute("sortDirection");
}
}
}
|