File: table.js

package info (click to toggle)
webcit 8.24-dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 10,888 kB
  • ctags: 4,214
  • sloc: ansic: 33,336; sh: 4,468; makefile: 340; xml: 90; sed: 9
file content (114 lines) | stat: -rw-r--r-- 3,289 bytes parent folder | download | duplicates (5)
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
var categories;
/** 
 * Task view table sorter
 * Written by Mathew McBride <matt@mcbridematt.dhs.org>
 * Copyright 2009 The Citadel Team
 * Licensed under the GPL V3
 */
function gatherCategoriesFromTable() {
	var tbody = document.getElementById("taskview");
	var childNodes = tbody.childNodes;
	for (i=0; i<=childNodes.length; i++) {
		var child = childNodes[i]; // Should be TR
		if (child != undefined && child.nodeName == "TR") {
			var childTds = child.getElementsByTagName("TD");
			if (childTds.length == 4) {
			var categoryTd = childTds[3];
			if (categoryTd != undefined) {
				// Get text child
				if (categoryTd.childNodes.length > 0 &&
					categoryTd.childNodes[0].nodeType == 3) {
						categories[categoryTd.childNodes[0].nodeValue]
							= categoryTd.childNodes[0].nodeValue;
					}
			}
		}
	}
}
}
function addCategoriesToSelector() {
	var selector = document.getElementById("selectcategory");
	for (description in categories) {
		var newOptionElement = document.createElement("option");
		newOptionElement.setAttribute("value", categories[description]);
		var text = document.createTextNode(categories[description]);
		newOptionElement.appendChild(text);
		selector.appendChild(newOptionElement);
	}
}
function filterCategories(event) {
	hideAllExistingRows();
	var selector = document.getElementById("selectcategory");
	var selected = selector.selectedIndex;
	var selectedCategory = selector.options[selected];
		var tbody = document.getElementById("taskview");
	var cat = selectedCategory.getAttribute("value");
	var nodesToUnhide = new Array();
	var curIndex = 0;
	// Hunt down all the rows with this category using XPath
	if (document.evaluate) { // Only if we can do so, of course 
		var debugText = "";
		var toEvaluate = null;
		if (cat != 'showall') {
		toEvaluate = "//tr[td='"+cat+"']";
		} else {
			toEvaluate = "//tr[td]";
		}
		var trNodes = document.evaluate(toEvaluate,
		document,
		null,
		XPathResult.ANY_TYPE,
		null);
	var trNode = trNodes.iterateNext();
	while(trNode) {
		debugText += "<br>"+trNode.nodeName;
		nodesToUnhide[curIndex++] = trNode;
		trNode = trNodes.iterateNext();
	} 
		
	}
	for (i=0;i<curIndex;i++) {
		nodesToUnhide[i].style.display = "table-row";
		if (((i-1) % 2) == 0) {
			nodesToUnhide[i].setAttribute("class","table-alt-row");
		}
	}
}
function hideAllExistingRows() {
	var nodes = new Array();
	var curIndex = 0;
	if (document.evaluate) { // Only if we can do so, of course 
		var debugText = "";
		var toEvaluate = "//tr/td";
		var tdNodes = document.evaluate(toEvaluate,
		document,
		null,
		XPathResult.ANY_TYPE,
		null);
	var tdNode = tdNodes.iterateNext();
	while(tdNode) {
		// Get parent
		var parent = tdNode.parentNode;
		nodes[curIndex++] = parent;
		tdNode = tdNodes.iterateNext();
	} 
	}
	for(i=0;i<curIndex;i++) {
		nodes[i].style.display = "none";
		nodes[i].removeAttribute("class");
	}
}

function taskViewActivate(event ) {
	// Do not run if not tasks, do not run without XPath3
	if (document.getElementById("taskview") != null && document.evaluate != null) {
	// var count = countRowsInTaskView();
	categories = new Object();
	gatherCategoriesFromTable();
	addCategoriesToSelector();
	
	$('selectcategory').observe('change', filterCategories);
	filterCategories(null); // color the rows first
	}
}