1
function selectUpdater(xmldoc, param) {
3
var sel = param.select;
5
var values = xmldoc.getElementsByTagName("Value");
6
if (values.length > 0) {
8
var selnode = sel.node;
10
while (selnode.hasChildNodes()) selnode.removeChild(selnode.firstChild);
12
for (var i = 0; i < values.length; i++) {
13
var value = values[i];
14
var item_value = value.getAttribute("value");
15
var item_text = value.getAttribute("name");
16
if (!item_text) item_text = item_value;
18
var opt = document.createElement('option');
19
opt.setAttribute("value", item_value);
20
if ((param.value)&&(item_value == param.value)) opt.setAttribute("selected", 1);
21
opt.appendChild(document.createTextNode(item_text));
22
selnode.appendChild(opt);
25
innerHTML is not working due to the bug Q276228 in IE
26
sel.node.innerHTML = res;
29
sel.callback(sel.cbattr, sel.GetValue()/*values[0].getAttribute("value")*/, param.opts);
33
var errors = xmldoc.getElementsByTagName("Error");
35
if (errors.length > 0)
36
error = errors[0].firstChild.data;
38
var errors = xmldoc.getElementsByTagName("parsererror");
39
if (errors.length > 0)
40
error = errors[0].firstChild.data;
42
error = "Empty response";
45
adeiReportError(translate("SELECT \"%s\" update is failed. Error: %s", sel.id, error));
51
function SELECT(id, cb, cbattr) {
52
if (typeof cb == "undefined") this.callback = null;
53
else this.callback = cb;
54
if (typeof cbattr == "undefined") this.cbattr = null;
55
else this.cbattr = cbattr;
58
this.node = document.getElementById(this.id);
59
if (!this.node) adeiReportError(translate('SELECT "%s" is not found', this.id));
62
/* DS: Should do something if request failed */
63
SELECT.prototype.Update = function(url, opts, value) {
64
var param = new Object;
67
if (typeof opts == "undefined") param.opts = null;
68
else param.opts = opts;
69
if (typeof value == "undefined") param.value = null;
70
else param.value = value;
72
queueXML(url, selectUpdater, param);
75
SELECT.prototype.GetLastIndex = function() {
76
return this.node.length - 1;
79
SELECT.prototype.GetValue = function(idx) {
80
if (typeof idx == "undefined")
81
return this.node.value
82
else if ((idx < this.node.length)&&(idx>=0))
83
return this.node[idx].value;
85
adeiReportError(translate('SELECT "%s". Index (%i) is out of range', this.id, idx));
88
SELECT.prototype.GetIndex = function(value) {
89
if (typeof value == "undefined")
90
return this.node.selectedIndex;
92
for (var i = 0; i < this.node.length; i++) {
93
if (this.node[i].value == value) {
99
adeiReportError(translate('SELECT "%s". Accessing non-exisiting value: %s', this.id, value));
103
SELECT.prototype.SetIndex = function(idx) {
104
if ((idx < this.node.length)&&(idx >= 0))
105
this.node.selectedIndex = idx;
107
adeiReportError(translate('SELECT "%s". Index (%i) is out of range', this.id, idx));
110
SELECT.prototype.SetValue = function(value) {
111
for (var i = 0; i < this.node.length; i++) {
112
if (this.node[i].value == value) {
113
this.node.selectedIndex = i;
118
adeiReportError(translate('SELECT "%s". Setting non-exisiting value: %s', this.id, value));
122
SELECT.prototype.GetTitle = function(idx) {
123
if (typeof idx == "undefined")
124
idx = this.node.selectedIndex;
125
else if ((idx<0)||(idx>=this.node.length))
126
return adeiReportError(translate('SELECT "%s". Index (%i) is out of range', this.id, idx));
128
var node = this.node.childNodes[idx];
130
var text = node.firstChild;
131
if (text) return text.nodeValue;
137
SELECT.prototype.Show = function() {
138
if (this.node) this.node.style.display = "inline";
141
SELECT.prototype.Hide = function() {
142
if (this.node) this.node.style.display = "none";