summaryrefslogtreecommitdiff
path: root/framework/Web/Javascripts/source/prado/activecontrols/activedatepicker.js
blob: 1b0b1492de6fd7d050d7ba5373df946c8d70ea3a (plain)
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
/**
 * TActiveDatePicker control
 */
Prado.WebUI.TActiveDatePicker = Class.create(Prado.WebUI.TDatePicker,
{
	onInit : function(options)
	{
		this.options = options || [];
		this.control = $(options.ID);
		this.dateSlot = new Array(42);
		this.weekSlot = new Array(6);
		this.minimalDaysInFirstWeek	= 4;
		this.selectedDate = this.newDate();
		this.positionMode = 'Bottom';


		//which element to trigger to show the calendar
		if(this.options.Trigger)
		{
			this.trigger = $(this.options.Trigger) ;
			var triggerEvent = this.options.TriggerEvent || "click";
		}
		else
		{
			this.trigger  = this.control;
			var triggerEvent = this.options.TriggerEvent || "focus";
		}
		
		// Popup position
		if(this.options.PositionMode == 'Top')
		{
			this.positionMode = this.options.PositionMode;
		}

		Object.extend(this,options);

		if (this.options.ShowCalendar)
			this.observe(this.trigger, triggerEvent, this.show.bindEvent(this));
		
		// Listen to change event 
		if(this.options.InputMode == "TextBox")
		{
			this.observe(this.control, "change", this.onDateChanged.bindEvent(this));
		} 
		else
		{
			var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
			var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
			var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
			if (day) this.observe (day, "change", this.onDateChanged.bindEvent(this));
			if (month) this.observe (month, "change", this.onDateChanged.bindEvent(this));
			if (year) this.observe (year, "change", this.onDateChanged.bindEvent(this));
				
		}

	},	
	
	// Respond to change event on the textbox or dropdown list
	// This method raises OnDateChanged event on client side if it has been defined,
	// and raise the callback request
	onDateChanged : function ()
	{
		var date;
		if (this.options.InputMode == "TextBox")
		{
			date=this.control.value;
		 } 
		 else
		 {
		 	var day = Prado.WebUI.TDatePicker.getDayListControl(this.control);
			if (day) day=day.selectedIndex+1;
			var month = Prado.WebUI.TDatePicker.getMonthListControl(this.control);
			if (month) month=month.selectedIndex;
			var year = Prado.WebUI.TDatePicker.getYearListControl(this.control);
			if (year) year=year.value;
			date=new Date(year, month, day, 0,0,0).SimpleFormat(this.Format, this);
		}
		if (typeof(this.options.OnDateChanged) == "function") this.options.OnDateChanged(this, date);
		
		if(this.options['AutoPostBack']==true)
		{
			// Make callback request
			var request = new Prado.CallbackRequest(this.options.EventTarget,this.options);
			request.dispatch();
		}
	}
});