2 /** Task view table sorter
3 * Written by Mathew McBride <matt@mcbridematt.dhs.org>
5 function gatherCategoriesFromTable() {
6 var tbody = document.getElementById("taskview");
7 var childNodes = tbody.childNodes;
8 for (i=0; i<=childNodes.length; i++) {
9 var child = childNodes[i]; // Should be TR
10 if (child != undefined && child.nodeName == "TR") {
11 var childTds = child.getElementsByTagName("TD");
12 if (childTds.length == 4) {
13 var categoryTd = childTds[3];
14 if (categoryTd != undefined) {
16 if (categoryTd.childNodes.length > 0 &&
17 categoryTd.childNodes[0].nodeType == 3) {
18 categories[categoryTd.childNodes[0].nodeValue]
19 = categoryTd.childNodes[0].nodeValue;
26 function addCategoriesToSelector() {
27 var selector = document.getElementById("selectcategory");
28 for (description in categories) {
29 var newOptionElement = document.createElement("option");
30 newOptionElement.setAttribute("value", categories[description]);
31 var text = document.createTextNode(categories[description]);
32 newOptionElement.appendChild(text);
33 selector.appendChild(newOptionElement);
36 function filterCategories(event) {
37 hideAllExistingRows();
38 var selector = document.getElementById("selectcategory");
39 var selected = selector.selectedIndex;
40 var selectedCategory = selector.options[selected];
41 var tbody = document.getElementById("taskview");
42 var cat = selectedCategory.getAttribute("value");
43 var nodesToUnhide = new Array();
45 // Hunt down all the rows with this category using XPath
46 if (document.evaluate) { // Only if we can do so, of course
48 var toEvaluate = null;
49 if (cat != 'showall') {
50 toEvaluate = "//tr[td='"+cat+"']";
52 toEvaluate = "//tr[td]";
54 var trNodes = document.evaluate(toEvaluate,
59 var trNode = trNodes.iterateNext();
61 debugText += "<br>"+trNode.nodeName;
62 nodesToUnhide[curIndex++] = trNode;
63 trNode = trNodes.iterateNext();
67 for (i=0;i<curIndex;i++) {
68 nodesToUnhide[i].style.display = "table-row";
69 if (((i-1) % 2) == 0) {
70 nodesToUnhide[i].setAttribute("class","table-alt-row");
74 function hideAllExistingRows() {
75 var nodes = new Array();
77 if (document.evaluate) { // Only if we can do so, of course
79 var toEvaluate = "//tr/td";
80 var tdNodes = document.evaluate(toEvaluate,
85 var tdNode = tdNodes.iterateNext();
88 var parent = tdNode.parentNode;
89 nodes[curIndex++] = parent;
90 tdNode = tdNodes.iterateNext();
93 for(i=0;i<curIndex;i++) {
94 nodes[i].style.display = "none";
95 nodes[i].removeAttribute("class");
99 function taskViewActivate(event ) {
100 // Do not run if not tasks, do not run without XPath3
101 if (document.getElementById("taskview") != null && document.evaluate != null) {
102 // var count = countRowsInTaskView();
103 categories = new Object();
104 gatherCategoriesFromTable();
105 addCategoriesToSelector();
107 $('selectcategory').observe('change', filterCategories);
108 filterCategories(null); // color the rows first