* Removed the 'New User' button from openid_login; new and existing users are handled...
[citadel.git] / webcit / static / table.js
blob98321d9d93b16706845dc5229a28e89503ffbfdf
1 var categories;
2 /** Task view table sorter
3  * Written by Mathew McBride <matt@mcbridematt.dhs.org>
4  */
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) {
15                                 // Get text child
16                                 if (categoryTd.childNodes.length > 0 &&
17                                         categoryTd.childNodes[0].nodeType == 3) {
18                                                 categories[categoryTd.childNodes[0].nodeValue]
19                                                         = categoryTd.childNodes[0].nodeValue;
20                                         }
21                         }
22                 }
23         }
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);
34         }
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();
44         var curIndex = 0;
45         // Hunt down all the rows with this category using XPath
46         if (document.evaluate) { // Only if we can do so, of course 
47                 var debugText = "";
48                 var toEvaluate = null;
49                 if (cat != 'showall') {
50                 toEvaluate = "//tr[td='"+cat+"']";
51                 } else {
52                         toEvaluate = "//tr[td]";
53                 }
54                 var trNodes = document.evaluate(toEvaluate,
55                 document,
56                 null,
57                 XPathResult.ANY_TYPE,
58                 null);
59         var trNode = trNodes.iterateNext();
60         while(trNode) {
61                 debugText += "<br>"+trNode.nodeName;
62                 nodesToUnhide[curIndex++] = trNode;
63                 trNode = trNodes.iterateNext();
64         } 
65                 
66         }
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");
71                 }
72         }
74 function hideAllExistingRows() {
75         var nodes = new Array();
76         var curIndex = 0;
77         if (document.evaluate) { // Only if we can do so, of course 
78                 var debugText = "";
79                 var toEvaluate = "//tr/td";
80                 var tdNodes = document.evaluate(toEvaluate,
81                 document,
82                 null,
83                 XPathResult.ANY_TYPE,
84                 null);
85         var tdNode = tdNodes.iterateNext();
86         while(tdNode) {
87                 // Get parent
88                 var parent = tdNode.parentNode;
89                 nodes[curIndex++] = parent;
90                 tdNode = tdNodes.iterateNext();
91         } 
92         }
93         for(i=0;i<curIndex;i++) {
94                 nodes[i].style.display = "none";
95                 nodes[i].removeAttribute("class");
96         }
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();
106         
107         $('selectcategory').observe('change', filterCategories);
108         filterCategories(null); // color the rows first
109         }