| 1 |
lars |
1 |
Prado.WebUI = Class.create();
|
|
|
2 |
|
|
|
3 |
Prado.WebUI.PostBackControl = Class.create();
|
|
|
4 |
|
|
|
5 |
Prado.WebUI.PostBackControl.prototype =
|
|
|
6 |
{
|
|
|
7 |
initialize : function(options)
|
|
|
8 |
{
|
|
|
9 |
this._elementOnClick = null, //capture the element's onclick function
|
|
|
10 |
|
|
|
11 |
this.element = $(options.ID);
|
|
|
12 |
if(this.element)
|
|
|
13 |
{
|
|
|
14 |
if(this.onInit)
|
|
|
15 |
this.onInit(options);
|
|
|
16 |
}
|
|
|
17 |
},
|
|
|
18 |
|
|
|
19 |
onInit : function(options)
|
|
|
20 |
{
|
|
|
21 |
if(typeof(this.element.onclick)=="function")
|
|
|
22 |
{
|
|
|
23 |
this._elementOnClick = this.element.onclick.bind(this.element);
|
|
|
24 |
this.element.onclick = null;
|
|
|
25 |
}
|
|
|
26 |
Event.observe(this.element, "click", this.elementClicked.bindEvent(this,options));
|
|
|
27 |
},
|
|
|
28 |
|
|
|
29 |
elementClicked : function(event, options)
|
|
|
30 |
{
|
|
|
31 |
var src = Event.element(event);
|
|
|
32 |
var doPostBack = true;
|
|
|
33 |
var onclicked = null;
|
|
|
34 |
|
|
|
35 |
if(this._elementOnClick)
|
|
|
36 |
{
|
|
|
37 |
var onclicked = this._elementOnClick(event);
|
|
|
38 |
if(typeof(onclicked) == "boolean")
|
|
|
39 |
doPostBack = onclicked;
|
|
|
40 |
}
|
|
|
41 |
if(doPostBack && !Prado.Element.isDisabled(src))
|
|
|
42 |
this.onPostBack(event,options);
|
|
|
43 |
if(typeof(onclicked) == "boolean" && !onclicked)
|
|
|
44 |
Event.stop(event);
|
|
|
45 |
},
|
|
|
46 |
|
|
|
47 |
onPostBack : function(event, options)
|
|
|
48 |
{
|
|
|
49 |
Prado.PostBack(event,options);
|
|
|
50 |
}
|
|
|
51 |
};
|
|
|
52 |
|
|
|
53 |
Prado.WebUI.TButton = Class.extend(Prado.WebUI.PostBackControl);
|
|
|
54 |
Prado.WebUI.TLinkButton = Class.extend(Prado.WebUI.PostBackControl);
|
|
|
55 |
Prado.WebUI.TCheckBox = Class.extend(Prado.WebUI.PostBackControl);
|
|
|
56 |
Prado.WebUI.TBulletedList = Class.extend(Prado.WebUI.PostBackControl);
|
|
|
57 |
Prado.WebUI.TImageMap = Class.extend(Prado.WebUI.PostBackControl);
|
|
|
58 |
|
|
|
59 |
/**
|
|
|
60 |
* TImageButton client-side behaviour. With validation, Firefox needs
|
|
|
61 |
* to capture the x,y point of the clicked image in hidden form fields.
|
|
|
62 |
*/
|
|
|
63 |
Prado.WebUI.TImageButton = Class.extend(Prado.WebUI.PostBackControl);
|
|
|
64 |
Object.extend(Prado.WebUI.TImageButton.prototype,
|
|
|
65 |
{
|
|
|
66 |
/**
|
|
|
67 |
* Override parent onPostBack function, tried to add hidden forms
|
|
|
68 |
* inputs to capture x,y clicked point.
|
|
|
69 |
*/
|
|
|
70 |
onPostBack : function(event, options)
|
|
|
71 |
{
|
|
|
72 |
this.addXYInput(event,options);
|
|
|
73 |
Prado.PostBack(event, options);
|
|
|
74 |
this.removeXYInput(event,options);
|
|
|
75 |
},
|
|
|
76 |
|
|
|
77 |
/**
|
|
|
78 |
* Add hidden inputs to capture the x,y point clicked on the image.
|
|
|
79 |
* @param event DOM click event.
|
|
|
80 |
* @param array image button options.
|
|
|
81 |
*/
|
|
|
82 |
addXYInput : function(event,options)
|
|
|
83 |
{
|
|
|
84 |
imagePos = this.element.cumulativeOffset();
|
|
|
85 |
clickedPos = [event.clientX, event.clientY];
|
|
|
86 |
x = clickedPos[0]-imagePos[0]+1;
|
|
|
87 |
y = clickedPos[1]-imagePos[1]+1;
|
|
|
88 |
x = x < 0 ? 0 : x;
|
|
|
89 |
y = y < 0 ? 0 : y;
|
|
|
90 |
id = options['EventTarget'];
|
|
|
91 |
x_input = $(id+"_x");
|
|
|
92 |
y_input = $(id+"_y");
|
|
|
93 |
if(x_input)
|
|
|
94 |
{
|
|
|
95 |
x_input.value = x;
|
|
|
96 |
}
|
|
|
97 |
else
|
|
|
98 |
{
|
|
|
99 |
x_input = INPUT({type:'hidden',name:id+'_x','id':id+'_x',value:x});
|
|
|
100 |
this.element.parentNode.appendChild(x_input);
|
|
|
101 |
}
|
|
|
102 |
if(y_input)
|
|
|
103 |
{
|
|
|
104 |
y_input.value = y;
|
|
|
105 |
}
|
|
|
106 |
else
|
|
|
107 |
{
|
|
|
108 |
y_input = INPUT({type:'hidden',name:id+'_y','id':id+'_y',value:y});
|
|
|
109 |
this.element.parentNode.appendChild(y_input);
|
|
|
110 |
}
|
|
|
111 |
},
|
|
|
112 |
|
|
|
113 |
/**
|
|
|
114 |
* Remove hidden inputs for x,y-click capturing
|
|
|
115 |
* @param event DOM click event.
|
|
|
116 |
* @param array image button options.
|
|
|
117 |
*/
|
|
|
118 |
removeXYInput : function(event,options)
|
|
|
119 |
{
|
|
|
120 |
id = options['EventTarget'];
|
|
|
121 |
this.element.parentNode.removeChild($(id+"_x"));
|
|
|
122 |
this.element.parentNode.removeChild($(id+"_y"));
|
|
|
123 |
}
|
|
|
124 |
});
|
|
|
125 |
|
|
|
126 |
|
|
|
127 |
/**
|
|
|
128 |
* Radio button, only initialize if not already checked.
|
|
|
129 |
*/
|
|
|
130 |
Prado.WebUI.TRadioButton = Class.extend(Prado.WebUI.PostBackControl);
|
|
|
131 |
Prado.WebUI.TRadioButton.prototype.onRadioButtonInitialize = Prado.WebUI.TRadioButton.prototype.initialize;
|
|
|
132 |
Object.extend(Prado.WebUI.TRadioButton.prototype,
|
|
|
133 |
{
|
|
|
134 |
initialize : function(options)
|
|
|
135 |
{
|
|
|
136 |
this.element = $(options['ID']);
|
|
|
137 |
if(this.element)
|
|
|
138 |
{
|
|
|
139 |
if(!this.element.checked)
|
|
|
140 |
this.onRadioButtonInitialize(options);
|
|
|
141 |
}
|
|
|
142 |
}
|
|
|
143 |
});
|
|
|
144 |
|
|
|
145 |
|
|
|
146 |
Prado.WebUI.TTextBox = Class.extend(Prado.WebUI.PostBackControl,
|
|
|
147 |
{
|
|
|
148 |
onInit : function(options)
|
|
|
149 |
{
|
|
|
150 |
this.options=options;
|
|
|
151 |
if(options['TextMode'] != 'MultiLine')
|
|
|
152 |
Event.observe(this.element, "keydown", this.handleReturnKey.bind(this));
|
|
|
153 |
if(this.options['AutoPostBack']==true)
|
|
|
154 |
Event.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
|
|
|
155 |
},
|
|
|
156 |
|
|
|
157 |
handleReturnKey : function(e)
|
|
|
158 |
{
|
|
|
159 |
if(Event.keyCode(e) == Event.KEY_RETURN)
|
|
|
160 |
{
|
|
|
161 |
var target = Event.element(e);
|
|
|
162 |
if(target)
|
|
|
163 |
{
|
|
|
164 |
if(this.options['AutoPostBack']==true)
|
|
|
165 |
{
|
|
|
166 |
Event.fireEvent(target, "change");
|
|
|
167 |
Event.stop(e);
|
|
|
168 |
}
|
|
|
169 |
else
|
|
|
170 |
{
|
|
|
171 |
if(this.options['CausesValidation'] && typeof(Prado.Validation) != "undefined")
|
|
|
172 |
{
|
|
|
173 |
if(!Prado.Validation.validate(this.options['FormID'], this.options['ValidationGroup'], $(this.options['ID'])))
|
|
|
174 |
return Event.stop(e);
|
|
|
175 |
}
|
|
|
176 |
}
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
}
|
|
|
180 |
});
|
|
|
181 |
|
|
|
182 |
Prado.WebUI.TListControl = Class.extend(Prado.WebUI.PostBackControl,
|
|
|
183 |
{
|
|
|
184 |
onInit : function(options)
|
|
|
185 |
{
|
|
|
186 |
Event.observe(this.element, "change", Prado.PostBack.bindEvent(this,options));
|
|
|
187 |
}
|
|
|
188 |
});
|
|
|
189 |
|
|
|
190 |
Prado.WebUI.TListBox = Class.extend(Prado.WebUI.TListControl);
|
|
|
191 |
Prado.WebUI.TDropDownList = Class.extend(Prado.WebUI.TListControl);
|
|
|
192 |
|
|
|
193 |
Prado.WebUI.DefaultButton = Class.create();
|
|
|
194 |
Prado.WebUI.DefaultButton.prototype =
|
|
|
195 |
{
|
|
|
196 |
initialize : function(options)
|
|
|
197 |
{
|
|
|
198 |
this.options = options;
|
|
|
199 |
this._event = this.triggerEvent.bindEvent(this);
|
|
|
200 |
Event.observe(options['Panel'], 'keydown', this._event);
|
|
|
201 |
},
|
|
|
202 |
|
|
|
203 |
triggerEvent : function(ev, target)
|
|
|
204 |
{
|
|
|
205 |
var enterPressed = Event.keyCode(ev) == Event.KEY_RETURN;
|
|
|
206 |
var isTextArea = Event.element(ev).tagName.toLowerCase() == "textarea";
|
|
|
207 |
if(enterPressed && !isTextArea)
|
|
|
208 |
{
|
|
|
209 |
var defaultButton = $(this.options['Target']);
|
|
|
210 |
if(defaultButton)
|
|
|
211 |
{
|
|
|
212 |
this.triggered = true;
|
|
|
213 |
$('PRADO_POSTBACK_TARGET').value = this.options.EventTarget;
|
|
|
214 |
Event.fireEvent(defaultButton, this.options['Event']);
|
|
|
215 |
Event.stop(ev);
|
|
|
216 |
}
|
|
|
217 |
}
|
|
|
218 |
}
|
|
|
219 |
};
|
|
|
220 |
|
|
|
221 |
Prado.WebUI.TTextHighlighter=Class.create();
|
|
|
222 |
Prado.WebUI.TTextHighlighter.prototype=
|
|
|
223 |
{
|
|
|
224 |
initialize:function(id)
|
|
|
225 |
{
|
|
|
226 |
if(!window.clipboardData) return;
|
|
|
227 |
var options =
|
|
|
228 |
{
|
|
|
229 |
href : 'javascript:;/'+'/copy code to clipboard',
|
|
|
230 |
onclick : 'Prado.WebUI.TTextHighlighter.copy(this)',
|
|
|
231 |
onmouseover : 'Prado.WebUI.TTextHighlighter.hover(this)',
|
|
|
232 |
onmouseout : 'Prado.WebUI.TTextHighlighter.out(this)'
|
|
|
233 |
}
|
|
|
234 |
var div = DIV({className:'copycode'}, A(options, 'Copy Code'));
|
|
|
235 |
document.write(DIV(null,div).innerHTML);
|
|
|
236 |
}
|
|
|
237 |
};
|
|
|
238 |
|
|
|
239 |
Object.extend(Prado.WebUI.TTextHighlighter,
|
|
|
240 |
{
|
|
|
241 |
copy : function(obj)
|
|
|
242 |
{
|
|
|
243 |
var parent = obj.parentNode.parentNode.parentNode;
|
|
|
244 |
var text = '';
|
|
|
245 |
for(var i = 0; i < parent.childNodes.length; i++)
|
|
|
246 |
{
|
|
|
247 |
var node = parent.childNodes[i];
|
|
|
248 |
if(node.innerText)
|
|
|
249 |
text += node.innerText == 'Copy Code' ? '' : node.innerText;
|
|
|
250 |
else
|
|
|
251 |
text += node.nodeValue;
|
|
|
252 |
}
|
|
|
253 |
if(text.length > 0)
|
|
|
254 |
window.clipboardData.setData("Text", text);
|
|
|
255 |
},
|
|
|
256 |
|
|
|
257 |
hover : function(obj)
|
|
|
258 |
{
|
|
|
259 |
obj.parentNode.className = "copycode copycode_hover";
|
|
|
260 |
},
|
|
|
261 |
|
|
|
262 |
out : function(obj)
|
|
|
263 |
{
|
|
|
264 |
obj.parentNode.className = "copycode";
|
|
|
265 |
}
|
|
|
266 |
});
|
|
|
267 |
|
|
|
268 |
|
|
|
269 |
Prado.WebUI.TCheckBoxList = Base.extend(
|
|
|
270 |
{
|
|
|
271 |
constructor : function(options)
|
|
|
272 |
{
|
|
|
273 |
for(var i = 0; i<options.ItemCount; i++)
|
|
|
274 |
{
|
|
|
275 |
var checkBoxOptions = Object.extend(
|
|
|
276 |
{
|
|
|
277 |
ID : options.ListID+"_c"+i,
|
|
|
278 |
EventTarget : options.ListName+"$c"+i
|
|
|
279 |
}, options);
|
|
|
280 |
new Prado.WebUI.TCheckBox(checkBoxOptions);
|
|
|
281 |
}
|
|
|
282 |
}
|
|
|
283 |
});
|
|
|
284 |
|
|
|
285 |
Prado.WebUI.TRadioButtonList = Base.extend(
|
|
|
286 |
{
|
|
|
287 |
constructor : function(options)
|
|
|
288 |
{
|
|
|
289 |
for(var i = 0; i<options.ItemCount; i++)
|
|
|
290 |
{
|
|
|
291 |
var radioButtonOptions = Object.extend(
|
|
|
292 |
{
|
|
|
293 |
ID : options.ListID+"_c"+i,
|
|
|
294 |
EventTarget : options.ListName+"$c"+i
|
|
|
295 |
}, options);
|
|
|
296 |
new Prado.WebUI.TRadioButton(radioButtonOptions);
|
|
|
297 |
}
|
|
|
298 |
}
|
|
|
299 |
});
|