Subversion-Projekte lars-tiefland.prado

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
/**
2
 * Generic postback control.
3
 */
4
Prado.WebUI.CallbackControl = Class.extend(Prado.WebUI.PostBackControl,
5
{
6
	onPostBack : function(event, options)
7
	{
8
		var request = new Prado.CallbackRequest(options.EventTarget, options);
9
		request.dispatch();
10
		Event.stop(event);
11
	}
12
});
13
 
14
/**
15
 * TActiveButton control.
16
 */
17
Prado.WebUI.TActiveButton = Class.extend(Prado.WebUI.CallbackControl);
18
/**
19
 * TActiveLinkButton control.
20
 */
21
Prado.WebUI.TActiveLinkButton = Class.extend(Prado.WebUI.CallbackControl);
22
 
23
Prado.WebUI.TActiveImageButton = Class.extend(Prado.WebUI.TImageButton,
24
{
25
	onPostBack : function(event, options)
26
	{
27
		this.addXYInput(event,options);
28
		var request = new Prado.CallbackRequest(options.EventTarget, options);
29
		request.dispatch();
30
		Event.stop(event);
31
		this.removeXYInput(event,options);
32
	}
33
});
34
/**
35
 * Active check box.
36
 */
37
Prado.WebUI.TActiveCheckBox = Class.extend(Prado.WebUI.CallbackControl,
38
{
39
	onPostBack : function(event, options)
40
	{
41
		var request = new Prado.CallbackRequest(options.EventTarget, options);
42
		if(request.dispatch()==false)
43
			Event.stop(event);
44
	}
45
});
46
 
47
/**
48
 * TActiveRadioButton control.
49
 */
50
Prado.WebUI.TActiveRadioButton = Class.extend(Prado.WebUI.TActiveCheckBox);
51
 
52
 
53
Prado.WebUI.TActiveCheckBoxList = Base.extend(
54
{
55
	constructor : function(options)
56
	{
57
		for(var i = 0; i<options.ItemCount; i++)
58
		{
59
			var checkBoxOptions = Object.extend(
60
			{
61
				ID : options.ListID+"_c"+i,
62
				EventTarget : options.ListName+"$c"+i
63
			}, options);
64
			new Prado.WebUI.TActiveCheckBox(checkBoxOptions);
65
		}
66
	}
67
});
68
 
69
Prado.WebUI.TActiveRadioButtonList = Prado.WebUI.TActiveCheckBoxList;
70
 
71
/**
72
 * TActiveTextBox control, handles onchange event.
73
 */
74
Prado.WebUI.TActiveTextBox = Class.extend(Prado.WebUI.TTextBox,
75
{
76
	onInit : function(options)
77
	{
78
		this.options=options;
79
		if(options['TextMode'] != 'MultiLine')
80
			Event.observe(this.element, "keydown", this.handleReturnKey.bind(this));
81
		if(this.options['AutoPostBack']==true)
82
			Event.observe(this.element, "change", this.doCallback.bindEvent(this,options));
83
	},
84
 
85
	doCallback : function(event, options)
86
	{
87
		var request = new Prado.CallbackRequest(options.EventTarget, options);
88
		request.dispatch();
89
        if (!Prototype.Browser.IE)
90
		    Event.stop(event);
91
	}
92
});
93
 
94
/**
95
 * TAutoComplete control.
96
 */
97
Prado.WebUI.TAutoComplete = Class.extend(Autocompleter.Base, Prado.WebUI.TActiveTextBox.prototype);
98
Prado.WebUI.TAutoComplete = Class.extend(Prado.WebUI.TAutoComplete,
99
{
100
	initialize : function(options)
101
	{
102
		this.options = options;
103
		this.hasResults = false;
104
		this.baseInitialize(options.ID, options.ResultPanel, options);
105
		Object.extend(this.options,
106
		{
107
			onSuccess : this.onComplete.bind(this)
108
		});
109
 
110
		if(options.AutoPostBack)
111
			this.onInit(options);
112
	},
113
 
114
	doCallback : function(event, options)
115
	{
116
		if(!this.active)
117
		{
118
			var request = new Prado.CallbackRequest(this.options.EventTarget, options);
119
			request.dispatch();
120
			Event.stop(event);
121
		}
122
	},
123
 
124
	 //Overrides parent implementation, fires onchange event.
125
	onClick: function(event)
126
	{
127
	    var element = Event.findElement(event, 'LI');
128
	    this.index = element.autocompleteIndex;
129
	    this.selectEntry();
130
	    this.hide();
131
		Event.fireEvent(this.element, "change");
132
	},
133
 
134
	getUpdatedChoices : function()
135
	{
136
		var options = new Array(this.getToken(),"__TAutoComplete_onSuggest__");
137
		Prado.Callback(this.options.EventTarget, options, null, this.options);
138
	},
139
 
140
	/**
141
	 * Overrides parent implements, don't update if no results.
142
	 */
143
	selectEntry: function()
144
	{
145
		if(this.hasResults)
146
		{
147
			this.active = false;
148
			this.updateElement(this.getCurrentEntry());
149
			var options = [this.index, "__TAutoComplete_onSuggestionSelected__"];
150
			Prado.Callback(this.options.EventTarget, options, null, this.options);
151
		}
152
	},
153
 
154
	onComplete : function(request, boundary)
155
  	{
156
  		var result = Prado.Element.extractContent(request.transport.responseText, boundary);
157
  		if(typeof(result) == "string")
158
		{
159
			if(result.length > 0)
160
			{
161
				this.hasResults = true;
162
				this.updateChoices(result);
163
			}
164
			else
165
			{
166
				this.active = false;
167
				this.hasResults = false;
168
				this.hide();
169
			}
170
		}
171
	}
172
});
173
 
174
/**
175
 * Time Triggered Callback class.
176
 */
177
Prado.WebUI.TTimeTriggeredCallback = Base.extend(
178
{
179
	constructor : function(options)
180
	{
181
		this.options = Object.extend({ Interval : 1	}, options || {});
182
		Prado.WebUI.TTimeTriggeredCallback.register(this);
183
	},
184
 
185
	startTimer : function()
186
	{
187
		setTimeout(this.onTimerEvent.bind(this), 100);
188
		if(typeof(this.timer) == 'undefined' || this.timer == null)
189
			this.timer = setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
190
	},
191
 
192
	stopTimer : function()
193
	{
194
		if(typeof(this.timer) != 'undefined')
195
		{
196
			clearInterval(this.timer);
197
			this.timer = null;
198
		}
199
	},
200
 
201
	resetTimer : function()
202
	{
203
		if(typeof(this.timer) != 'undefined')
204
		{
205
			clearInterval(this.timer);
206
			this.timer = null;
207
			this.timer = setInterval(this.onTimerEvent.bind(this),this.options.Interval*1000);
208
		}
209
	},
210
 
211
	onTimerEvent : function()
212
	{
213
		var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
214
		request.dispatch();
215
	},
216
 
217
	setInterval : function(value)
218
	{
219
		if (this.options.Interval != value){
220
			this.options.Interval = value;
221
			this.resetTimer();
222
		}
223
	}
224
},
225
//class methods
226
{
227
	timers : {},
228
 
229
	register : function(timer)
230
	{
231
		Prado.WebUI.TTimeTriggeredCallback.timers[timer.options.ID] = timer;
232
	},
233
 
234
	start : function(id)
235
	{
236
		if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
237
			Prado.WebUI.TTimeTriggeredCallback.timers[id].startTimer();
238
	},
239
 
240
	stop : function(id)
241
	{
242
		if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
243
			Prado.WebUI.TTimeTriggeredCallback.timers[id].stopTimer();
244
	},
245
 
246
	setInterval : function (id,value)
247
	{
248
		if(Prado.WebUI.TTimeTriggeredCallback.timers[id])
249
			Prado.WebUI.TTimeTriggeredCallback.timers[id].setInterval(value);
250
	}
251
});
252
 
253
Prado.WebUI.ActiveListControl = Base.extend(
254
{
255
	constructor : function(options)
256
	{
257
		this.element = $(options.ID);
258
		if(this.element)
259
		{
260
			this.options = options;
261
			Event.observe(this.element, "change", this.doCallback.bind(this));
262
		}
263
	},
264
 
265
	doCallback : function(event)
266
	{
267
		var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
268
		request.dispatch();
269
		Event.stop(event);
270
	}
271
});
272
 
273
Prado.WebUI.TActiveDropDownList = Prado.WebUI.ActiveListControl;
274
Prado.WebUI.TActiveListBox = Prado.WebUI.ActiveListControl;
275
 
276
/**
277
 * Observe event of a particular control to trigger a callback request.
278
 */
279
Prado.WebUI.TEventTriggeredCallback = Base.extend(
280
{
281
	constructor : function(options)
282
	{
283
		this.options = options;
284
		var element = $(options['ControlID']);
285
		if(element)
286
			Event.observe(element, this.getEventName(element), this.doCallback.bind(this));
287
	},
288
 
289
	getEventName : function(element)
290
	{
291
		var name = this.options.EventName;
292
   		if(typeof(name) == "undefined" && element.type)
293
		{
294
      		switch (element.type.toLowerCase())
295
			{
296
          		case 'password':
297
		        case 'text':
298
		        case 'textarea':
299
		        case 'select-one':
300
		        case 'select-multiple':
301
          			return 'change';
302
      		}
303
		}
304
		return typeof(name) == "undefined"  || name == "undefined" ? 'click' : name;
305
    },
306
 
307
	doCallback : function(event)
308
	{
309
		var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
310
		request.dispatch();
311
		if(this.options.StopEvent == true)
312
			Event.stop(event);
313
	}
314
});
315
 
316
/**
317
 * Observe changes to a property of a particular control to trigger a callback.
318
 */
319
Prado.WebUI.TValueTriggeredCallback = Base.extend(
320
{
321
	count : 1,
322
 
323
	observing : true,
324
 
325
	constructor : function(options)
326
	{
327
		this.options = options;
328
		this.options.PropertyName = this.options.PropertyName || 'value';
329
		var element = $(options['ControlID']);
330
		this.value = element ? element[this.options.PropertyName] : undefined;
331
		Prado.WebUI.TValueTriggeredCallback.register(this);
332
		this.startObserving();
333
	},
334
 
335
	stopObserving : function()
336
	{
337
		clearTimeout(this.timer);
338
		this.observing = false;
339
	},
340
 
341
	startObserving : function()
342
	{
343
		this.timer = setTimeout(this.checkChanges.bind(this), this.options.Interval*1000);
344
	},
345
 
346
	checkChanges : function()
347
	{
348
		var element = $(this.options.ControlID);
349
		if(element)
350
		{
351
			var value = element[this.options.PropertyName];
352
			if(this.value != value)
353
			{
354
				this.doCallback(this.value, value);
355
				this.value = value;
356
				this.count=1;
357
			}
358
			else
359
				this.count = this.count + this.options.Decay;
360
			if(this.observing)
361
				this.time = setTimeout(this.checkChanges.bind(this),
362
					parseInt(this.options.Interval*1000*this.count));
363
		}
364
	},
365
 
366
	doCallback : function(oldValue, newValue)
367
	{
368
		var request = new Prado.CallbackRequest(this.options.EventTarget, this.options);
369
		var param = {'OldValue' : oldValue, 'NewValue' : newValue};
370
		request.setCallbackParameter(param);
371
		request.dispatch();
372
	}
373
},
374
//class methods
375
{
376
	timers : {},
377
 
378
	register : function(timer)
379
	{
380
		Prado.WebUI.TValueTriggeredCallback.timers[timer.options.ID] = timer;
381
	},
382
 
383
	stop : function(id)
384
	{
385
		Prado.WebUI.TValueTriggeredCallback.timers[id].stopObserving();
386
	}
387
});