Diffstat (limited to 'frontend/beta/js/Clipperz/Profile.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/beta/js/Clipperz/Profile.js | 22 |
1 files changed, 10 insertions, 12 deletions
diff --git a/frontend/beta/js/Clipperz/Profile.js b/frontend/beta/js/Clipperz/Profile.js index fb12417..98c1e53 100644 --- a/frontend/beta/js/Clipperz/Profile.js +++ b/frontend/beta/js/Clipperz/Profile.js | |||
@@ -1,214 +1,212 @@ | |||
1 | /* | 1 | /* |
2 | 2 | ||
3 | Copyright 2008-2011 Clipperz Srl | 3 | Copyright 2008-2013 Clipperz Srl |
4 | 4 | ||
5 | This file is part of Clipperz Community Edition. | 5 | This file is part of Clipperz, the online password manager. |
6 | Clipperz Community Edition is an online password manager. | ||
7 | For further information about its features and functionalities please | 6 | For further information about its features and functionalities please |
8 | refer to http://www.clipperz.com. | 7 | refer to http://www.clipperz.com. |
9 | 8 | ||
10 | * Clipperz Community Edition is free software: you can redistribute | 9 | * Clipperz is free software: you can redistribute it and/or modify it |
11 | it and/or modify it under the terms of the GNU Affero General Public | 10 | under the terms of the GNU Affero General Public License as published |
12 | License as published by the Free Software Foundation, either version | 11 | by the Free Software Foundation, either version 3 of the License, or |
13 | 3 of the License, or (at your option) any later version. | 12 | (at your option) any later version. |
14 | 13 | ||
15 | * Clipperz Community Edition is distributed in the hope that it will | 14 | * Clipperz is distributed in the hope that it will be useful, but |
16 | be useful, but WITHOUT ANY WARRANTY; without even the implied | 15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
17 | warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
18 | See the GNU Affero General Public License for more details. | 17 | See the GNU Affero General Public License for more details. |
19 | 18 | ||
20 | * You should have received a copy of the GNU Affero General Public | 19 | * You should have received a copy of the GNU Affero General Public |
21 | License along with Clipperz Community Edition. If not, see | 20 | License along with Clipperz. If not, see http://www.gnu.org/licenses/. |
22 | <http://www.gnu.org/licenses/>. | ||
23 | 21 | ||
24 | */ | 22 | */ |
25 | 23 | ||
26 | addEvent(window, "load", sortables_init); | 24 | addEvent(window, "load", sortables_init); |
27 | 25 | ||
28 | var SORT_COLUMN_INDEX; | 26 | var SORT_COLUMN_INDEX; |
29 | 27 | ||
30 | function sortables_init() { | 28 | function sortables_init() { |
31 | // Find all tables with class sortable and make them sortable | 29 | // Find all tables with class sortable and make them sortable |
32 | if (!document.getElementsByTagName) return; | 30 | if (!document.getElementsByTagName) return; |
33 | tbls = document.getElementsByTagName("table"); | 31 | tbls = document.getElementsByTagName("table"); |
34 | for (ti=0;ti<tbls.length;ti++) { | 32 | for (ti=0;ti<tbls.length;ti++) { |
35 | thisTbl = tbls[ti]; | 33 | thisTbl = tbls[ti]; |
36 | if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id)) { | 34 | if (((' '+thisTbl.className+' ').indexOf("sortable") != -1) && (thisTbl.id)) { |
37 | //initTable(thisTbl.id); | 35 | //initTable(thisTbl.id); |
38 | ts_makeSortable(thisTbl); | 36 | ts_makeSortable(thisTbl); |
39 | } | 37 | } |
40 | } | 38 | } |
41 | } | 39 | } |
42 | 40 | ||
43 | function ts_makeSortable(table) { | 41 | function ts_makeSortable(table) { |
44 | if (table.rows && table.rows.length > 0) { | 42 | if (table.rows && table.rows.length > 0) { |
45 | var firstRow = table.rows[0]; | 43 | var firstRow = table.rows[0]; |
46 | } | 44 | } |
47 | if (!firstRow) return; | 45 | if (!firstRow) return; |
48 | 46 | ||
49 | // We have a first row: assume it's the header, and make its contents clickable links | 47 | // We have a first row: assume it's the header, and make its contents clickable links |
50 | for (var i=0;i<firstRow.cells.length;i++) { | 48 | for (var i=0;i<firstRow.cells.length;i++) { |
51 | var cell = firstRow.cells[i]; | 49 | var cell = firstRow.cells[i]; |
52 | var txt = ts_getInnerText(cell); | 50 | var txt = ts_getInnerText(cell); |
53 | cell.innerHTML = '<a href="#" class="sortheader" '+ | 51 | cell.innerHTML = '<a href="#" class="sortheader" '+ |
54 | 'onclick="ts_resortTable(this, '+i+');return false;">' + | 52 | 'onclick="ts_resortTable(this, '+i+');return false;">' + |
55 | txt+'<span class="sortarrow"> </span></a>'; | 53 | txt+'<span class="sortarrow"> </span></a>'; |
56 | } | 54 | } |
57 | } | 55 | } |
58 | 56 | ||
59 | function ts_getInnerText(el) { | 57 | function ts_getInnerText(el) { |
60 | if (typeof el == "string") return el; | 58 | if (typeof el == "string") return el; |
61 | if (typeof el == "undefined") { return el }; | 59 | if (typeof el == "undefined") { return el }; |
62 | if (el.innerText) return el.innerText;//Not needed but it is faster | 60 | if (el.innerText) return el.innerText;//Not needed but it is faster |
63 | var str = ""; | 61 | var str = ""; |
64 | 62 | ||
65 | var cs = el.childNodes; | 63 | var cs = el.childNodes; |
66 | var l = cs.length; | 64 | var l = cs.length; |
67 | for (var i = 0; i < l; i++) { | 65 | for (var i = 0; i < l; i++) { |
68 | switch (cs[i].nodeType) { | 66 | switch (cs[i].nodeType) { |
69 | case 1: //ELEMENT_NODE | 67 | case 1: //ELEMENT_NODE |
70 | str += ts_getInnerText(cs[i]); | 68 | str += ts_getInnerText(cs[i]); |
71 | break; | 69 | break; |
72 | case 3://TEXT_NODE | 70 | case 3://TEXT_NODE |
73 | str += cs[i].nodeValue; | 71 | str += cs[i].nodeValue; |
74 | break; | 72 | break; |
75 | } | 73 | } |
76 | } | 74 | } |
77 | return str; | 75 | return str; |
78 | } | 76 | } |
79 | 77 | ||
80 | function ts_resortTable(lnk,clid) { | 78 | function ts_resortTable(lnk,clid) { |
81 | // get the span | 79 | // get the span |
82 | var span; | 80 | var span; |
83 | for (var ci=0;ci<lnk.childNodes.length;ci++) { | 81 | for (var ci=0;ci<lnk.childNodes.length;ci++) { |
84 | if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci]; | 82 | if (lnk.childNodes[ci].tagName && lnk.childNodes[ci].tagName.toLowerCase() == 'span') span = lnk.childNodes[ci]; |
85 | } | 83 | } |
86 | var spantext = ts_getInnerText(span); | 84 | var spantext = ts_getInnerText(span); |
87 | var td = lnk.parentNode; | 85 | var td = lnk.parentNode; |
88 | var column = clid || td.cellIndex; | 86 | var column = clid || td.cellIndex; |
89 | var table = getParent(td,'TABLE'); | 87 | var table = getParent(td,'TABLE'); |
90 | 88 | ||
91 | // Work out a type for the column | 89 | // Work out a type for the column |
92 | if (table.rows.length <= 1) return; | 90 | if (table.rows.length <= 1) return; |
93 | var itm = ts_getInnerText(table.rows[1].cells[column]); | 91 | var itm = ts_getInnerText(table.rows[1].cells[column]); |
94 | sortfn = ts_sort_caseinsensitive; | 92 | sortfn = ts_sort_caseinsensitive; |
95 | if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) { | 93 | if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d\d\d$/)) { |
96 | sortfn = ts_sort_date; | 94 | sortfn = ts_sort_date; |
97 | } | 95 | } |
98 | if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) { | 96 | if (itm.match(/^\d\d[\/-]\d\d[\/-]\d\d$/)) { |
99 | sortfn = ts_sort_date; | 97 | sortfn = ts_sort_date; |
100 | } | 98 | } |
101 | if (itm.match(/^[£$]/)) { | 99 | if (itm.match(/^[£$]/)) { |
102 | sortfn = ts_sort_currency; | 100 | sortfn = ts_sort_currency; |
103 | } | 101 | } |
104 | if (itm.match(/^[\d\.]+$/)) { | 102 | if (itm.match(/^[\d\.]+$/)) { |
105 | sortfn = ts_sort_numeric; | 103 | sortfn = ts_sort_numeric; |
106 | } | 104 | } |
107 | SORT_COLUMN_INDEX = column; | 105 | SORT_COLUMN_INDEX = column; |
108 | var firstRow = new Array(); | 106 | var firstRow = new Array(); |
109 | var newRows = new Array(); | 107 | var newRows = new Array(); |
110 | for (i=0;i<table.rows[0].length;i++) { | 108 | for (i=0;i<table.rows[0].length;i++) { |
111 | firstRow[i] = table.rows[0][i]; | 109 | firstRow[i] = table.rows[0][i]; |
112 | } | 110 | } |
113 | 111 | ||
114 | for (j=1;j<table.rows.length;j++) { | 112 | for (j=1;j<table.rows.length;j++) { |
115 | newRows[j-1] = table.rows[j]; | 113 | newRows[j-1] = table.rows[j]; |
116 | } | 114 | } |
117 | newRows.sort(sortfn); | 115 | newRows.sort(sortfn); |
118 | 116 | ||
119 | if (span.getAttribute("sortdir") == 'down') { | 117 | if (span.getAttribute("sortdir") == 'down') { |
120 | ARROW = ' ↑'; | 118 | ARROW = ' ↑'; |
121 | newRows.reverse(); | 119 | newRows.reverse(); |
122 | span.setAttribute('sortdir','up'); | 120 | span.setAttribute('sortdir','up'); |
123 | } else { | 121 | } else { |
124 | ARROW = ' ↓'; | 122 | ARROW = ' ↓'; |
125 | span.setAttribute('sortdir','down'); | 123 | span.setAttribute('sortdir','down'); |
126 | } | 124 | } |
127 | 125 | ||
128 | // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones | 126 | // We appendChild rows that already exist to the tbody, so it moves them rather than creating new ones |
129 | // don't do sortbottom rows | 127 | // don't do sortbottom rows |
130 | for (i=0;i<newRows.length;i++) { | 128 | for (i=0;i<newRows.length;i++) { |
131 | if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) { | 129 | if (!newRows[i].className || (newRows[i].className && (newRows[i].className.indexOf('sortbottom') == -1))) { |
132 | table.tBodies[0].appendChild(newRows[i]); | 130 | table.tBodies[0].appendChild(newRows[i]); |
133 | } | 131 | } |
134 | } | 132 | } |
135 | // do sortbottom rows only | 133 | // do sortbottom rows only |
136 | for (i=0;i<newRows.length;i++) { | 134 | for (i=0;i<newRows.length;i++) { |
137 | if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) { | 135 | if (newRows[i].className && (newRows[i].className.indexOf('sortbottom') != -1)) { |
138 | table.tBodies[0].appendChild(newRows[i]); | 136 | table.tBodies[0].appendChild(newRows[i]); |
139 | } | 137 | } |
140 | } | 138 | } |
141 | 139 | ||
142 | // Delete any other arrows there may be showing | 140 | // Delete any other arrows there may be showing |
143 | var allspans = document.getElementsByTagName("span"); | 141 | var allspans = document.getElementsByTagName("span"); |
144 | for (var ci=0;ci<allspans.length;ci++) { | 142 | for (var ci=0;ci<allspans.length;ci++) { |
145 | if (allspans[ci].className == 'sortarrow') { | 143 | if (allspans[ci].className == 'sortarrow') { |
146 | if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us? | 144 | if (getParent(allspans[ci],"table") == getParent(lnk,"table")) { // in the same table as us? |
147 | allspans[ci].innerHTML = ' '; | 145 | allspans[ci].innerHTML = ' '; |
148 | } | 146 | } |
149 | } | 147 | } |
150 | } | 148 | } |
151 | 149 | ||
152 | span.innerHTML = ARROW; | 150 | span.innerHTML = ARROW; |
153 | } | 151 | } |
154 | 152 | ||
155 | function getParent(el, pTagName) { | 153 | function getParent(el, pTagName) { |
156 | if (el == null) return null; | 154 | if (el == null) return null; |
157 | else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())// Gecko bug, supposed to be uppercase | 155 | else if (el.nodeType == 1 && el.tagName.toLowerCase() == pTagName.toLowerCase())// Gecko bug, supposed to be uppercase |
158 | return el; | 156 | return el; |
159 | else | 157 | else |
160 | return getParent(el.parentNode, pTagName); | 158 | return getParent(el.parentNode, pTagName); |
161 | } | 159 | } |
162 | function ts_sort_date(a,b) { | 160 | function ts_sort_date(a,b) { |
163 | // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX | 161 | // y2k notes: two digit years less than 50 are treated as 20XX, greater than 50 are treated as 19XX |
164 | aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]); | 162 | aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]); |
165 | bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]); | 163 | bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]); |
166 | if (aa.length == 10) { | 164 | if (aa.length == 10) { |
167 | dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2); | 165 | dt1 = aa.substr(6,4)+aa.substr(3,2)+aa.substr(0,2); |
168 | } else { | 166 | } else { |
169 | yr = aa.substr(6,2); | 167 | yr = aa.substr(6,2); |
170 | if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; } | 168 | if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; } |
171 | dt1 = yr+aa.substr(3,2)+aa.substr(0,2); | 169 | dt1 = yr+aa.substr(3,2)+aa.substr(0,2); |
172 | } | 170 | } |
173 | if (bb.length == 10) { | 171 | if (bb.length == 10) { |
174 | dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2); | 172 | dt2 = bb.substr(6,4)+bb.substr(3,2)+bb.substr(0,2); |
175 | } else { | 173 | } else { |
176 | yr = bb.substr(6,2); | 174 | yr = bb.substr(6,2); |
177 | if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; } | 175 | if (parseInt(yr) < 50) { yr = '20'+yr; } else { yr = '19'+yr; } |
178 | dt2 = yr+bb.substr(3,2)+bb.substr(0,2); | 176 | dt2 = yr+bb.substr(3,2)+bb.substr(0,2); |
179 | } | 177 | } |
180 | if (dt1==dt2) return 0; | 178 | if (dt1==dt2) return 0; |
181 | if (dt1<dt2) return -1; | 179 | if (dt1<dt2) return -1; |
182 | return 1; | 180 | return 1; |
183 | } | 181 | } |
184 | 182 | ||
185 | function ts_sort_currency(a,b) { | 183 | function ts_sort_currency(a,b) { |
186 | aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,''); | 184 | aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,''); |
187 | bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,''); | 185 | bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).replace(/[^0-9.]/g,''); |
188 | return parseFloat(aa) - parseFloat(bb); | 186 | return parseFloat(aa) - parseFloat(bb); |
189 | } | 187 | } |
190 | 188 | ||
191 | function ts_sort_numeric(a,b) { | 189 | function ts_sort_numeric(a,b) { |
192 | aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX])); | 190 | aa = parseFloat(ts_getInnerText(a.cells[SORT_COLUMN_INDEX])); |
193 | if (isNaN(aa)) aa = 0; | 191 | if (isNaN(aa)) aa = 0; |
194 | bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX])); | 192 | bb = parseFloat(ts_getInnerText(b.cells[SORT_COLUMN_INDEX])); |
195 | if (isNaN(bb)) bb = 0; | 193 | if (isNaN(bb)) bb = 0; |
196 | return aa-bb; | 194 | return aa-bb; |
197 | } | 195 | } |
198 | 196 | ||
199 | function ts_sort_caseinsensitive(a,b) { | 197 | function ts_sort_caseinsensitive(a,b) { |
200 | aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase(); | 198 | aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]).toLowerCase(); |
201 | bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase(); | 199 | bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]).toLowerCase(); |
202 | if (aa==bb) return 0; | 200 | if (aa==bb) return 0; |
203 | if (aa<bb) return -1; | 201 | if (aa<bb) return -1; |
204 | return 1; | 202 | return 1; |
205 | } | 203 | } |
206 | 204 | ||
207 | function ts_sort_default(a,b) { | 205 | function ts_sort_default(a,b) { |
208 | aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]); | 206 | aa = ts_getInnerText(a.cells[SORT_COLUMN_INDEX]); |
209 | bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]); | 207 | bb = ts_getInnerText(b.cells[SORT_COLUMN_INDEX]); |
210 | if (aa==bb) return 0; | 208 | if (aa==bb) return 0; |
211 | if (aa<bb) return -1; | 209 | if (aa<bb) return -1; |
212 | return 1; | 210 | return 1; |
213 | } | 211 | } |
214 | 212 | ||