File: TemplateRender.js

package info (click to toggle)
phpldapadmin 1.2.6.7-3~bpo12%2B1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm-backports
  • size: 5,432 kB
  • sloc: php: 17,675; javascript: 5,299; xml: 1,498; sh: 379; python: 148; makefile: 23
file content (84 lines) | stat: -rw-r--r-- 2,525 bytes parent folder | download | duplicates (10)
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
function pla_getComponentById(id) {
	return document.getElementById(id);
}

function pla_getComponentsByName(name) {
	return document.getElementsByName(name);
}

function pla_getComponentValue(component) {
	if (component.type == "checkbox") {
		if (component.checked) return component.value;
	} else if (component.type == "select-one") {
		if (component.selectedIndex >= 0) return component.options[component.selectedIndex].value;
	} else if (component.type == "select-multiple") {
		if (component.selectedIndex >= 0) return component.options[component.selectedIndex].value;
	} else if (component.type == undefined) { // option
		if (component.selected) return component.value;
	} else {
		return component.value;
	}
	return "";
}

function pla_setComponentValue(component,value) {
	if (component.type == "checkbox") {
		if (component.value == value) component.checked = true;
		else component.checked = false;
	} else if (component.type == "select-one") {
		for (var i = 0; i < component.options.length; i++) {
			if (component.options[i].value == value) component.options[i].selected = true;
		}
	} else if (component.type == "select-multiple") {
		for (var i = 0; i < component.options.length; i++) {
			if (component.options[i].value == value) component.options[i].selected = true;
		}
	} else if (component.type == undefined) { // option
		if (component.value == value) component.selected = true;
		else component.selected = false;
	} else {
		component.value = value;
	}
}

function getAttributeComponents(prefix,name) {
	var components = new Array();
	var i = 0;
	var j = 0;
	var c = pla_getComponentsByName(prefix + "_values[" + name + "][" + j + "]");
	while (c && (c.length > 0)) {
		for (var k = 0; k < c.length; k++) {
			components[i++] = c[k];
		}
		++j;
		c = pla_getComponentsByName(prefix + "_values[" + name + "][" + j + "]");
	}
	c = pla_getComponentsByName(prefix + "_values[" + name + "][]");
	if (c && (c.length > 0)) {
		for (var k = 0; k < c.length; k++) {
			components[i++] = c[k];
		}
	}
	return components;
}

function getAttributeValues(prefix,name) {
	var components = getAttributeComponents(prefix,name);
	var values = new Array();
	for (var k = 0; k < components.length; k++) {
		var val = pla_getComponentValue(components[k]);
		if (val) values[values.length] = val;
	}
	return values;
}

function submitForm(form) {
	for (var i = 0; i < form.elements.length; i++) {
		form.elements[i].blur();
	}
	return validateForm(true);
}

function alertError(err,silence) {
	if (!silence) alert(err);
}