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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
Prado.Element =
{
/**
* Set the value of a particular element.
* @param string element id
* @param string new element value.
*/
setValue : function(element, value)
{
var el = $(element);
if(el && typeof(el.value) != "undefined")
el.value = value;
},
select : function(element, method, value)
{
var el = $(element);
var isList = element.indexOf('[]') > -1;
if(!el && !isList) return;
method = isList ? 'check'+method : el.tagName.toLowerCase()+method;
var selection = Prado.Element.Selection;
if(typeof(selection[method]) == "function")
selection[method](isList ? element : el,value);
},
click : function(element)
{
var el = $(element);
if(el)
Event.fireEvent(el,'click');
},
setAttribute : function(element, attribute, value)
{
var el = $(element);
if(attribute == "disabled" && value==false)
el.removeAttribute(attribute);
else
el.setAttribute(attribute, value);
},
setOptions : function(element, options)
{
var el = $(element);
if(el && el.tagName.toLowerCase() == "select")
{
while(el.length > 0)
el.remove(0);
for(var i = 0; i<options.length; i++)
el.options[el.options.length] = new Option(options[i][0],options[i][1]);
}
},
/**
* A delayed focus on a particular element
* @param {element} element to apply focus()
*/
focus : function(element)
{
var obj = $(element);
if(typeof(obj) != "undefined" && typeof(obj.focus) != "undefined")
setTimeout(function(){ obj.focus(); }, 100);
return false;
},
replace : function(element, method, content, boundary, transport)
{
if(boundary)
{
result = Prado.Element.extractContent(transport.responseText, boundary);
if(result != null)
content = result;
}
if(typeof(element) == "string")
{
if($(element))
method.toFunction().apply(this,[element,content]);
}
else
{
method.toFunction().apply(this,[content]);
}
},
extractContent : function(text, boundary)
{
f = RegExp('(<!--'+boundary+'-->)([\\s\\S\\w\\W]*)(<!--//'+boundary+'-->)',"m");
result = text.match(f);
if(result && result.length >= 2)
return result[2];
else
return null;
},
evaluateScript : function(content)
{
content.evalScripts();
}
}
Prado.Element.Selection =
{
inputValue : function(el, value)
{
switch(el.type.toLowerCase())
{
case 'checkbox':
case 'radio':
return el.checked = value;
}
},
selectValue : function(el, value)
{
$A(el.options).each(function(option)
{
option.selected = option.value == value;
});
},
selectIndex : function(el, index)
{
if(el.type == 'select-one')
el.selectedIndex = index;
else
{
for(var i = 0; i<el.length; i++)
{
if(i == index)
el.options[i].selected = true;
}
}
},
selectClear : function(el)
{
el.selectedIndex = -1;
},
selectAll : function(el)
{
$A(el.options).each(function(option)
{
option.selected = true;
Logger.warn(option.value);
});
},
selectInvert : function(el)
{
$A(el.options).each(function(option)
{
option.selected = !option.selected;
});
},
checkValue : function(name, value)
{
$A(document.getElementsByName(name)).each(function(el)
{
el.checked = el.value == value
});
},
checkIndex : function(name, index)
{
var elements = $A(document.getElementsByName(name));
for(var i = 0; i<elements.length; i++)
{
if(i == index)
elements[i].checked = true;
}
},
checkClear : function(name)
{
$A(document.getElementsByName(name)).each(function(el)
{
el.checked = false;
});
},
checkAll : function(name)
{
$A(document.getElementsByName(name)).each(function(el)
{
el.checked = true;
});
},
checkInvert : function(name)
{
$A(document.getElementsByName(name)).each(function(el)
{
el.checked = !el.checked;
});
}
};
|