From a48195e52865532add00af44788c938071eb0e1d Mon Sep 17 00:00:00 2001 From: wei <> Date: Fri, 20 Jan 2006 07:02:43 +0000 Subject: Update date picker --- framework/Web/Javascripts/datepicker/calendar.png | Bin 0 -> 775 bytes framework/Web/Javascripts/datepicker/datepicker.js | 592 +++++++++++++++++++++ framework/Web/Javascripts/datepicker/default.css | 86 +++ framework/Web/Javascripts/extended/date.js | 10 +- framework/Web/Javascripts/js/datepicker.js | 192 +++---- framework/Web/Javascripts/js/prado.js | 147 ++--- framework/Web/Javascripts/prado/datepicker.js | 586 -------------------- .../Web/Javascripts/prado/datepicker_default.css | 69 --- framework/Web/Javascripts/prado/test.html | 105 ---- 9 files changed, 859 insertions(+), 928 deletions(-) create mode 100644 framework/Web/Javascripts/datepicker/calendar.png create mode 100644 framework/Web/Javascripts/datepicker/datepicker.js create mode 100644 framework/Web/Javascripts/datepicker/default.css delete mode 100644 framework/Web/Javascripts/prado/datepicker.js delete mode 100644 framework/Web/Javascripts/prado/datepicker_default.css delete mode 100644 framework/Web/Javascripts/prado/test.html (limited to 'framework/Web/Javascripts') diff --git a/framework/Web/Javascripts/datepicker/calendar.png b/framework/Web/Javascripts/datepicker/calendar.png new file mode 100644 index 00000000..c245f1b4 Binary files /dev/null and b/framework/Web/Javascripts/datepicker/calendar.png differ diff --git a/framework/Web/Javascripts/datepicker/datepicker.js b/framework/Web/Javascripts/datepicker/datepicker.js new file mode 100644 index 00000000..5468fb6c --- /dev/null +++ b/framework/Web/Javascripts/datepicker/datepicker.js @@ -0,0 +1,592 @@ +Prado.WebUI.TDatePicker = Class.create(); +Prado.WebUI.TDatePicker.prototype = +{ + MonthNames : [ "January", "February", "March", "April", + "May", "June", "July", "August", + "September", "October", "November", "December" + ], + + ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], + + Format : "yyyy-MM-dd", + + FirstDayOfWeek : 1, // 0 for sunday + + ClassName : "TDatePicker", + + FromYear : 2000, UpToYear: 2015, + + initialize : function(control, attr) + { + this.attr = attr || []; + this.control = $(control); + this.dateSlot = new Array(42); + this.weekSlot = new Array(6); + this.minimalDaysInFirstWeek = 4; + this.selectedDate = this.newDate(); + + //which element to trigger to show the calendar + if(this.attr.Trigger) + { + this.trigger = $(this.attr.Trigger) ; + var triggerEvent = this.attr.TriggerEvent || "click"; + } + else + { + this.trigger = this.control; + var triggerEvent = this.attr.TriggerEvent || "focus"; + } + + Event.observe(this.trigger, triggerEvent, this.show.bindEvent(this)); + + Object.extend(this,attr); + + this.create(); + }, + + create : function() + { + var div; + var table; + var tbody; + var tr; + var td; + + // Create the top-level div element + this._calDiv = document.createElement("div"); + this._calDiv.className = this.ClassName; + this._calDiv.style.display = "none"; + this._calDiv.style.position = "absolute" + + // header div + div = document.createElement("div"); + div.className = "calendarHeader"; + this._calDiv.appendChild(div); + + table = document.createElement("table"); + table.style.cellSpacing = 0; + div.appendChild(table); + + tbody = document.createElement("tbody"); + table.appendChild(tbody); + + tr = document.createElement("tr"); + tbody.appendChild(tr); + + // Previous Month Button + td = document.createElement("td"); + var previousMonth = document.createElement("button"); + previousMonth.className = "prevMonthButton"; + previousMonth.appendChild(document.createTextNode("<<")); + td.appendChild(previousMonth); + tr.appendChild(td); + + + + // + // Create the month drop down + // + td = document.createElement("td"); + tr.appendChild(td); + this._monthSelect = document.createElement("select"); + this._monthSelect.className = "months"; + for (var i = 0 ; i < this.MonthNames.length ; i++) { + var opt = document.createElement("option"); + opt.innerHTML = this.MonthNames[i]; + opt.value = i; + if (i == this.selectedDate.getMonth()) { + opt.selected = true; + } + this._monthSelect.appendChild(opt); + } + td.appendChild(this._monthSelect); + + + // + // Create the year drop down + // + td = document.createElement("td"); + td.className = "labelContainer"; + tr.appendChild(td); + this._yearSelect = document.createElement("select"); + for(var i=this.FromYear; i <= this.UpToYear; ++i) { + var opt = document.createElement("option"); + opt.innerHTML = i; + opt.value = i; + if (i == this.selectedDate.getFullYear()) { + opt.selected = false; + } + this._yearSelect.appendChild(opt); + } + td.appendChild(this._yearSelect); + + + td = document.createElement("td"); + td.className = "nextMonthButton"; + var nextMonth = document.createElement("button"); + nextMonth.appendChild(document.createTextNode(">>")); + td.appendChild(nextMonth); + tr.appendChild(td); + + // Calendar body + div = document.createElement("div"); + div.className = "calendarBody"; + this._calDiv.appendChild(div); + var calendarBody = div; + + // Create the inside of calendar body + + var text; + table = document.createElement("table"); + table.className = "grid"; + + div.appendChild(table); + var thead = document.createElement("thead"); + table.appendChild(thead); + tr = document.createElement("tr"); + thead.appendChild(tr); + + for(i=0; i < 7; ++i) { + td = document.createElement("th"); + text = document.createTextNode(this.ShortWeekDayNames[(i+this.FirstDayOfWeek)%7]); + td.appendChild(text); + td.className = "weekDayHead"; + tr.appendChild(td); + } + + // Date grid + tbody = document.createElement("tbody"); + table.appendChild(tbody); + + for(week=0; week<6; ++week) { + tr = document.createElement("tr"); + tbody.appendChild(tr); + + for(day=0; day<7; ++day) { + td = document.createElement("td"); + td.className = "calendarDate"; + text = document.createTextNode(String.fromCharCode(160)); + td.appendChild(text); + + tr.appendChild(td); + var tmp = new Object(); + tmp.tag = "DATE"; + tmp.value = -1; + tmp.data = text; + this.dateSlot[(week*7)+day] = tmp; + + Event.observe(td, "mouseover", this.hover.bindEvent(this)); + Event.observe(td, "mouseout", this.hover.bindEvent(this)); + + } + } + + // Calendar Footer + div = document.createElement("div"); + div.className = "calendarFooter"; + this._calDiv.appendChild(div); + + var todayButton = document.createElement("button"); + todayButton.className = "todayButton"; + var today = this.newDate(); + var buttonText = today.SimpleFormat(this.Format); + todayButton.appendChild(document.createTextNode(buttonText)); + div.appendChild(todayButton); + + /*var clearButton = document.createElement("button"); + clearButton.className = "clearButton"; + buttonText = "Clear"; + clearButton.appendChild(document.createTextNode(buttonText)); + div.appendChild(clearButton); + */ + + if(Prado.Browser().ie) + { + this.iePopUp = document.createElement('iframe'); + this.iePopUp.src = ""; + this.iePopUp.style.position = "absolute" + this.iePopUp.scrolling="no" + this.iePopUp.frameBorder="0" + document.body.appendChild(this.iePopUp); + } + + document.body.appendChild(this._calDiv); + + this.update(); + this.updateHeader(); + + this.ieHack(true); + + // IE55+ extension + previousMonth.hideFocus = true; + nextMonth.hideFocus = true; + todayButton.hideFocus = true; + // end IE55+ extension + + // hook up events + Event.observe(previousMonth, "click", this.prevMonth.bindEvent(this)); + Event.observe(nextMonth, "click", this.nextMonth.bindEvent(this)); + Event.observe(todayButton, "click", this.selectToday.bindEvent(this)); + //Event.observe(clearButton, "click", this.clearSelection.bindEvent(this)); + Event.observe(this._monthSelect, "change", this.monthSelect.bindEvent(this)); + Event.observe(this._yearSelect, "change", this.yearSelect.bindEvent(this)); + + // ie6 extension + Event.observe(this._calDiv, "mousewheel", this.mouseWheelChange.bindEvent(this)); + + Event.observe(calendarBody, "click", this.selectDate.bindEvent(this)); + + }, + + ieHack : function(cleanup) + { + // IE hack + if(this.iePopUp) + { + this.iePopUp.style.display = "block"; + this.iePopUp.style.top = (this._calDiv.offsetTop -1 ) + "px"; + this.iePopUp.style.left = (this._calDiv.offsetLeft -1)+ "px"; + this.iePopUp.style.width = Math.abs(this._calDiv.offsetWidth -2)+ "px"; + this.iePopUp.style.height = (this._calDiv.offsetHeight + 1)+ "px"; + if(cleanup) this.iePopUp.style.display = "none"; + } + }, + + keyPressed : function(ev) + { + if(!this.showing) return; + if (!ev) ev = document.parentWindow.event; + var kc = ev.keyCode != null ? ev.keyCode : ev.charCode; + + if(kc == Event.KEY_RETURN) + { + this.setSelectedDate(this.selectedDate); + Event.stop(ev); + this.hide(); + } + if(kc == Event.KEY_ESC) + { + Event.stop(ev); this.hide(); + } + + + var getDaysPerMonth = function (nMonth, nYear) + { + nMonth = (nMonth + 12) % 12; + var days= [31,28,31,30,31,30,31,31,30,31,30,31]; + var res = days[nMonth]; + if (nMonth == 1) //feburary, leap years has 29 + res += nYear % 4 == 0 && !(nYear % 400 == 0) ? 1 : 0; + return res; + } + + if(kc < 37 || kc > 40) return true; + + var current = this.selectedDate; + var d = current.valueOf(); + if(kc == Event.KEY_LEFT) + { + if(ev.ctrlKey || ev.shiftKey) // -1 month + { + current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() - 1,current.getFullYear())) ); // no need to catch dec -> jan for the year + d = current.setMonth( current.getMonth() - 1 ); + } + else + d -= 86400000; //-1 day + } + else if (kc == Event.KEY_RIGHT) + { + if(ev.ctrlKey || ev.shiftKey) // +1 month + { + current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() + 1,current.getFullYear())) ); // no need to catch dec -> jan for the year + d = current.setMonth( current.getMonth() + 1 ); + } + else + d += 86400000; //+1 day + } + else if (kc == Event.KEY_UP) + { + if(ev.ctrlKey || ev.shiftKey) //-1 year + { + current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() - 1)) ); // no need to catch dec -> jan for the year + d = current.setFullYear( current.getFullYear() - 1 ); + } + else + d -= 604800000; // -7 days + } + else if (kc == Event.KEY_DOWN) + { + if(ev.ctrlKey || ev.shiftKey) // +1 year + { + current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() + 1)) ); // no need to catch dec -> jan for the year + d = current.setFullYear( current.getFullYear() + 1 ); + } + else + d += 7 * 24 * 61 * 60 * 1000; // +7 days + } + this.setSelectedDate(d); + Event.stop(ev); + }, + + selectDate : function(ev) + { + var el = Event.element(ev); + while (el.nodeType != 1) + el = el.parentNode; + + while (el != null && el.tagName && el.tagName.toLowerCase() != "td") + el = el.parentNode; + + // if no td found, return + if (el == null || el.tagName == null || el.tagName.toLowerCase() != "td") + return; + + var d = this.newDate(this.selectedDate); + var n = Number(el.firstChild.data); + if (isNaN(n) || n <= 0 || n == null) + return; + + d.setDate(n); + this.setSelectedDate(d); + this.hide(); + }, + + selectToday : function() + { + if(this.selectedDate.toISODate() == this.newDate().toISODate()) + this.hide(); + + this.setSelectedDate(this.newDate()); + }, + + clearSelection : function() + { + this.setSelectedDate(this.newDate()); + this.hide(); + }, + + monthSelect : function(ev) + { + this.setMonth(Form.Element.getValue(Event.element(ev))); + }, + + yearSelect : function(ev) + { + this.setYear(Form.Element.getValue(Event.element(ev))); + }, + + // ie6 extension + mouseWheelChange : function (e) + { + if (e == null) e = document.parentWindow.event; + var n = - e.wheelDelta / 120; + var d = this.newDate(this.selectedDate); + var m = d.getMonth() + n; + this.setMonth(m); + + return false; + }, + + onchange : function() + { + this.control.value = this.formatDate(); + }, + + formatDate : function() + { + return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format) : ''; + }, + + newDate : function(date) + { + if(!date) + date = new Date(); + if(isString(date) || isNumber(date)) + date = new Date(date); + return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0,0,0); + }, + + setSelectedDate : function(date) + { + if (date == null) + return; + this.selectedDate = this.newDate(date); + + this.updateHeader(); + this.update(); + if (isFunction(this.onchange)) + this.onchange(); + }, + + getElement : function() + { + return this._calDiv; + }, + + getSelectedDate : function () + { + return isNull(this.selectedDate) ? null : this.newDate(this.selectedDate); + }, + + setYear : function(year) + { + var d = this.newDate(this.selectedDate); + d.setFullYear(year); + this.setSelectedDate(d); + }, + + setMonth : function (month) + { + var d = this.newDate(this.selectedDate); + d.setMonth(month); + this.setSelectedDate(d); + }, + + nextMonth : function () + { + this.setMonth(this.selectedDate.getMonth()+1); + }, + + prevMonth : function () + { + this.setMonth(this.selectedDate.getMonth()-1); + }, + + show : function() + { + if(!this.showing) + { + var pos = Position.cumulativeOffset(this.control); + pos[1] += this.control.offsetHeight; + this._calDiv.style.display = "block"; + this._calDiv.style.top = (pos[1]-1) + "px"; + this._calDiv.style.left = pos[0] + "px"; + + this.ieHack(false); + this.documentClickEvent = this.hideOnClick.bindEvent(this); + this.documentKeyDownEvent = this.keyPressed.bindEvent(this); + Event.observe(document.body, "click", this.documentClickEvent); + var date = Date.SimpleParse(Form.Element.getValue(this.control), this.Format); + if(!isNull(date)) + { + this.selectedDate = date; + this.setSelectedDate(date); + } + Event.observe(document,"keydown", this.documentKeyDownEvent); + this.showing = true; + } + }, + + //hide the calendar when clicked outside any calendar + hideOnClick : function(ev) + { + if(!this.showing) return; + var el = Event.element(ev); + var within = false; + do + { + within = within || el.className == this.ClassName; + within = within || el == this.trigger; + within = within || el == this.control; + if(within) break; + el = el.parentNode; + } + while(el); + if(!within) this.hide(); + }, + + hide : function() + { + if(this.showing) + { + this._calDiv.style.display = "none"; + if(this.iePopUp) + this.iePopUp.style.display = "none"; + this.showing = false; + Event.stopObserving(document.body, "click", this.documentClickEvent); + Event.stopObserving(document,"keydown", this.documentKeyDownEvent); + } + }, + + update : function() + { + // Calculate the number of days in the month for the selected date + var date = this.selectedDate; + var today = (this.newDate()).toISODate(); + + var selected = date.toISODate(); + var d1 = new Date(date.getFullYear(), date.getMonth(), 1); + var d2 = new Date(date.getFullYear(), date.getMonth()+1, 1); + var monthLength = Math.round((d2 - d1) / (24 * 60 * 60 * 1000)); + + // Find out the weekDay index for the first of this month + var firstIndex = (d1.getDay() - this.FirstDayOfWeek) % 7 ; + if (firstIndex < 0) + firstIndex += 7; + + var index = 0; + while (index < firstIndex) { + this.dateSlot[index].value = -1; + this.dateSlot[index].data.data = String.fromCharCode(160); + this.dateSlot[index].data.parentNode.className = "empty"; + index++; + } + + for (i = 1; i <= monthLength; i++, index++) { + var slot = this.dateSlot[index]; + var slotNode = slot.data.parentNode; + slot.value = i; + slot.data.data = i; + slotNode.className = "date"; + //slotNode.style.color = ""; + if (d1.toISODate() == today) { + slotNode.className += " today"; + } + if (d1.toISODate() == selected) { + // slotNode.style.color = "blue"; + slotNode.className += " selected"; + } + d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()+1); + } + + var lastDateIndex = index; + + while(index < 42) { + this.dateSlot[index].value = -1; + this.dateSlot[index].data.data = String.fromCharCode(160); + this.dateSlot[index].data.parentNode.className = "empty"; + ++index; + } + + }, + + hover : function(ev) + { + //conditionally add the hover class to the event target element. + Element.condClassName(Event.element(ev), "hover", ev.type=="mouseover"); + }, + + updateHeader : function () { + + var options = this._monthSelect.options; + var m = this.selectedDate.getMonth(); + for(var i=0; i < options.length; ++i) { + options[i].selected = false; + if (options[i].value == m) { + options[i].selected = true; + } + } + + options = this._yearSelect.options; + var year = this.selectedDate.getFullYear(); + for(var i=0; i < options.length; ++i) { + options[i].selected = false; + if (options[i].value == year) { + options[i].selected = true; + } + } + + } + + +}; \ No newline at end of file diff --git a/framework/Web/Javascripts/datepicker/default.css b/framework/Web/Javascripts/datepicker/default.css new file mode 100644 index 00000000..cd03bb27 --- /dev/null +++ b/framework/Web/Javascripts/datepicker/default.css @@ -0,0 +1,86 @@ +.TDatePicker +{ + border: 1px solid #919EA9; + background-color: White; + text-align: center; + font-size: 11px; + font-family: Tahoma, Arial, Helvetica, sans-serif; + cursor: default; +} + +.TDatePickerButton +{ + width: 30px; +} + +.TDatePickerImageButton +{ + padding: 2px; + border: 1px solid #919EA9; + vertical-align: top; + margin-left: 1px; +} + +.TDatePickerImageButton:hover +{ + border-color: #ddd; +} + +.TDatePicker select +{ + font-size: 11px; +} + +.TDatePicker .calendarHeader button +{ + font-size: 12px; + width: 32px; +} + +.TDatePicker .date +{ + padding: 4px 0; + border: 1px solid white; +} +.TDatePicker .hover +{ + border: 1px solid blue; +} +.TDatePicker .selected +{ + background-color: blue; + border: 1px solid blue; + color: white; +} +.TDatePicker .today +{ + font-weight: bold; +} + +.TDatePicker td.empty +{ + background-color: #ffe; + border: 1px solid white; + cursor: default; + height: 23px; +} +.TDatePicker th +{ + width: 28px; +} +.TDatePicker .grid +{ + border-spacing: 0px; + margin: 3px; +} +.TDatePicker .calendarFooter +{ + margin: 2px; + border-top: 1px solid #919EA9; + padding-top: 2px; +} +.TDatePicker .calendarFooter button +{ + font-size: 12px; + margin: 4px; +} \ No newline at end of file diff --git a/framework/Web/Javascripts/extended/date.js b/framework/Web/Javascripts/extended/date.js index 9e56ff64..b27f9da2 100644 --- a/framework/Web/Javascripts/extended/date.js +++ b/framework/Web/Javascripts/extended/date.js @@ -1,20 +1,24 @@ Object.extend(Date.prototype, { - SimpleFormat: function(format) + SimpleFormat: function(format, data) { + data = data || {}; var bits = new Array(); bits['d'] = this.getDate(); bits['dd'] = String(this.getDate()).zerofill(2); bits['M'] = this.getMonth()+1; bits['MM'] = String(this.getMonth()+1).zerofill(2); - + if(data.AbbreviatedMonthNames) + bits['MMM'] = data.AbbreviatedMonthNames[this.getMonth()]; + if(data.MonthNames) + bits['MMMM'] = data.MonthNames[this.getMonth()]; var yearStr = "" + this.getFullYear(); yearStr = (yearStr.length == 2) ? '19' + yearStr: yearStr; bits['yyyy'] = yearStr; bits['yy'] = bits['yyyy'].toString().substr(2,2); - + // do some funky regexs to replace the format string // with the real values var frm = new String(format); diff --git a/framework/Web/Javascripts/js/datepicker.js b/framework/Web/Javascripts/js/datepicker.js index e840fc68..4ab5cd68 100644 --- a/framework/Web/Javascripts/js/datepicker.js +++ b/framework/Web/Javascripts/js/datepicker.js @@ -25,6 +25,7 @@ var td; this._calDiv=document.createElement("div"); this._calDiv.className=this.ClassName; this._calDiv.style.display="none"; +this._calDiv.style.position="absolute"; _4=document.createElement("div"); _4.className="calendarHeader"; this._calDiv.appendChild(_4); @@ -120,14 +121,9 @@ this._calDiv.appendChild(_4); var _17=document.createElement("button"); _17.className="todayButton"; var _18=this.newDate(); -var _19=_18.getDate()+" "+this.MonthNames[_18.getMonth()]+", "+_18.getFullYear(); +var _19=_18.SimpleFormat(this.Format); _17.appendChild(document.createTextNode(_19)); _4.appendChild(_17); -var _20=document.createElement("button"); -_20.className="clearButton"; -_19="Clear"; -_20.appendChild(document.createTextNode(_19)); -_4.appendChild(_20); if(Prado.Browser().ie){ this.iePopUp=document.createElement("iframe"); this.iePopUp.src=""; @@ -146,19 +142,18 @@ _17.hideFocus=true; Event.observe(_9,"click",this.prevMonth.bindEvent(this)); Event.observe(_12,"click",this.nextMonth.bindEvent(this)); Event.observe(_17,"click",this.selectToday.bindEvent(this)); -Event.observe(_20,"click",this.clearSelection.bindEvent(this)); Event.observe(this._monthSelect,"change",this.monthSelect.bindEvent(this)); Event.observe(this._yearSelect,"change",this.yearSelect.bindEvent(this)); Event.observe(this._calDiv,"mousewheel",this.mouseWheelChange.bindEvent(this)); Event.observe(_13,"click",this.selectDate.bindEvent(this)); -},ieHack:function(_21){ +},ieHack:function(_20){ if(this.iePopUp){ this.iePopUp.style.display="block"; this.iePopUp.style.top=(this._calDiv.offsetTop-1)+"px"; this.iePopUp.style.left=(this._calDiv.offsetLeft-1)+"px"; this.iePopUp.style.width=Math.abs(this._calDiv.offsetWidth-2)+"px"; this.iePopUp.style.height=(this._calDiv.offsetHeight+1)+"px"; -if(_21){ +if(_20){ this.iePopUp.style.display="none"; } } @@ -171,51 +166,56 @@ ev=document.parentWindow.event; } var kc=ev.keyCode!=null?ev.keyCode:ev.charCode; if(kc==Event.KEY_RETURN){ +this.setSelectedDate(this.selectedDate); Event.stop(ev); this.hide(); } -var _24=function(_25,_26){ -_25=(_25+12)%12; -var _27=[31,28,31,30,31,30,31,31,30,31,30,31]; -var res=_27[_25]; -if(_25==1){ -res+=_26%4==0&&!(_26%400==0)?1:0; +if(kc==Event.KEY_ESC){ +Event.stop(ev); +this.hide(); +} +var _23=function(_24,_25){ +_24=(_24+12)%12; +var _26=[31,28,31,30,31,30,31,31,30,31,30,31]; +var res=_26[_24]; +if(_24==1){ +res+=_25%4==0&&!(_25%400==0)?1:0; } return res; }; if(kc<37||kc>40){ return true; } -var _29=this.selectedDate; -var d=_29.valueOf(); +var _28=this.selectedDate; +var d=_28.valueOf(); if(kc==Event.KEY_LEFT){ if(ev.ctrlKey||ev.shiftKey){ -_29.setDate(Math.min(_29.getDate(),_24(_29.getMonth()-1,_29.getFullYear()))); -d=_29.setMonth(_29.getMonth()-1); +_28.setDate(Math.min(_28.getDate(),_23(_28.getMonth()-1,_28.getFullYear()))); +d=_28.setMonth(_28.getMonth()-1); }else{ d-=86400000; } }else{ if(kc==Event.KEY_RIGHT){ if(ev.ctrlKey||ev.shiftKey){ -_29.setDate(Math.min(_29.getDate(),_24(_29.getMonth()+1,_29.getFullYear()))); -d=_29.setMonth(_29.getMonth()+1); +_28.setDate(Math.min(_28.getDate(),_23(_28.getMonth()+1,_28.getFullYear()))); +d=_28.setMonth(_28.getMonth()+1); }else{ d+=86400000; } }else{ if(kc==Event.KEY_UP){ if(ev.ctrlKey||ev.shiftKey){ -_29.setDate(Math.min(_29.getDate(),_24(_29.getMonth(),_29.getFullYear()-1))); -d=_29.setFullYear(_29.getFullYear()-1); +_28.setDate(Math.min(_28.getDate(),_23(_28.getMonth(),_28.getFullYear()-1))); +d=_28.setFullYear(_28.getFullYear()-1); }else{ d-=604800000; } }else{ if(kc==Event.KEY_DOWN){ if(ev.ctrlKey||ev.shiftKey){ -_29.setDate(Math.min(_29.getDate(),_24(_29.getMonth(),_29.getFullYear()+1))); -d=_29.setFullYear(_29.getFullYear()+1); +_28.setDate(Math.min(_28.getDate(),_23(_28.getMonth(),_28.getFullYear()+1))); +d=_28.setFullYear(_28.getFullYear()+1); }else{ d+=7*24*61*60*1000; } @@ -245,8 +245,10 @@ d.setDate(n); this.setSelectedDate(d); this.hide(); },selectToday:function(){ -this.setSelectedDate(this.newDate()); +if(this.selectedDate.toISODate()==this.newDate().toISODate()){ this.hide(); +} +this.setSelectedDate(this.newDate()); },clearSelection:function(){ this.setSelectedDate(this.newDate()); this.hide(); @@ -267,19 +269,19 @@ return false; this.control.value=this.formatDate(); },formatDate:function(){ return this.selectedDate?this.selectedDate.SimpleFormat(this.Format):""; -},newDate:function(_35){ -if(!_35){ -_35=new Date(); +},newDate:function(_34){ +if(!_34){ +_34=new Date(); } -if(isString(_35)||isNumber(_35)){ -_35=new Date(_35); +if(isString(_34)||isNumber(_34)){ +_34=new Date(_34); } -return new Date(_35.getFullYear(),_35.getMonth(),_35.getDate(),0,0,0); -},setSelectedDate:function(_36){ -if(_36==null){ +return new Date(_34.getFullYear(),_34.getMonth(),_34.getDate(),0,0,0); +},setSelectedDate:function(_35){ +if(_35==null){ return; } -this.selectedDate=this.newDate(_36); +this.selectedDate=this.newDate(_35); this.updateHeader(); this.update(); if(isFunction(this.onchange)){ @@ -289,13 +291,13 @@ this.onchange(); return this._calDiv; },getSelectedDate:function(){ return isNull(this.selectedDate)?null:this.newDate(this.selectedDate); -},setYear:function(_37){ +},setYear:function(_36){ var d=this.newDate(this.selectedDate); -d.setFullYear(_37); +d.setFullYear(_36); this.setSelectedDate(d); -},setMonth:function(_38){ +},setMonth:function(_37){ var d=this.newDate(this.selectedDate); -d.setMonth(_38); +d.setMonth(_37); this.setSelectedDate(d); },nextMonth:function(){ this.setMonth(this.selectedDate.getMonth()+1); @@ -312,10 +314,10 @@ this.ieHack(false); this.documentClickEvent=this.hideOnClick.bindEvent(this); this.documentKeyDownEvent=this.keyPressed.bindEvent(this); Event.observe(document.body,"click",this.documentClickEvent); -var _40=Date.SimpleParse(Form.Element.getValue(this.control),this.Format); -if(!isNull(_40)){ -this.selectedDate=_40; -this.setSelectedDate(_40); +var _39=Date.SimpleParse(Form.Element.getValue(this.control),this.Format); +if(!isNull(_39)){ +this.selectedDate=_39; +this.setSelectedDate(_39); } Event.observe(document,"keydown",this.documentKeyDownEvent); this.showing=true; @@ -325,17 +327,17 @@ if(!this.showing){ return; } var el=Event.element(ev); -var _41=false; +var _40=false; do{ -_41=_41||el.className==this.ClassName; -_41=_41||el==this.trigger; -_41=_41||el==this.control; -if(_41){ +_40=_40||el.className==this.ClassName; +_40=_40||el==this.trigger; +_40=_40||el==this.control; +if(_40){ break; } el=el.parentNode; }while(el); -if(!_41){ +if(!_40){ this.hide(); } },hide:function(){ @@ -349,61 +351,61 @@ Event.stopObserving(document.body,"click",this.documentClickEvent); Event.stopObserving(document,"keydown",this.documentKeyDownEvent); } },update:function(){ -var _42=this.selectedDate; -var _43=(this.newDate()).toISODate(); -var _44=_42.toISODate(); -var d1=new Date(_42.getFullYear(),_42.getMonth(),1); -var d2=new Date(_42.getFullYear(),_42.getMonth()+1,1); -var _47=Math.round((d2-d1)/(24*60*60*1000)); -var _48=(d1.getDay()-this.FirstDayOfWeek)%7; -if(_48<0){ -_48+=7; -} -var _49=0; -while(_49<_48){ -this.dateSlot[_49].value=-1; -this.dateSlot[_49].data.data=String.fromCharCode(160); -this.dateSlot[_49].data.parentNode.className="empty"; -_49++; -} -for(i=1;i<=_47;i++,_49++){ -var _50=this.dateSlot[_49]; -var _51=_50.data.parentNode; -_50.value=i; -_50.data.data=i; -_51.className="date"; -if(d1.toISODate()==_43){ -_51.className+=" today"; +var _41=this.selectedDate; +var _42=(this.newDate()).toISODate(); +var _43=_41.toISODate(); +var d1=new Date(_41.getFullYear(),_41.getMonth(),1); +var d2=new Date(_41.getFullYear(),_41.getMonth()+1,1); +var _46=Math.round((d2-d1)/(24*60*60*1000)); +var _47=(d1.getDay()-this.FirstDayOfWeek)%7; +if(_47<0){ +_47+=7; +} +var _48=0; +while(_48<_47){ +this.dateSlot[_48].value=-1; +this.dateSlot[_48].data.data=String.fromCharCode(160); +this.dateSlot[_48].data.parentNode.className="empty"; +_48++; +} +for(i=1;i<=_46;i++,_48++){ +var _49=this.dateSlot[_48]; +var _50=_49.data.parentNode; +_49.value=i; +_49.data.data=i; +_50.className="date"; +if(d1.toISODate()==_42){ +_50.className+=" today"; } -if(d1.toISODate()==_44){ -_51.className+=" selected"; +if(d1.toISODate()==_43){ +_50.className+=" selected"; } d1=new Date(d1.getFullYear(),d1.getMonth(),d1.getDate()+1); } -var _52=_49; -while(_49<42){ -this.dateSlot[_49].value=-1; -this.dateSlot[_49].data.data=String.fromCharCode(160); -this.dateSlot[_49].data.parentNode.className="empty"; -++_49; +var _51=_48; +while(_48<42){ +this.dateSlot[_48].value=-1; +this.dateSlot[_48].data.data=String.fromCharCode(160); +this.dateSlot[_48].data.parentNode.className="empty"; +++_48; } },hover:function(ev){ Element.condClassName(Event.element(ev),"hover",ev.type=="mouseover"); },updateHeader:function(){ -var _53=this._monthSelect.options; +var _52=this._monthSelect.options; var m=this.selectedDate.getMonth(); -for(var i=0;i<_53.length;++i){ -_53[i].selected=false; -if(_53[i].value==m){ -_53[i].selected=true; -} -} -_53=this._yearSelect.options; -var _54=this.selectedDate.getFullYear(); -for(var i=0;i<_53.length;++i){ -_53[i].selected=false; -if(_53[i].value==_54){ -_53[i].selected=true; +for(var i=0;i<_52.length;++i){ +_52[i].selected=false; +if(_52[i].value==m){ +_52[i].selected=true; +} +} +_52=this._yearSelect.options; +var _53=this.selectedDate.getFullYear(); +for(var i=0;i<_52.length;++i){ +_52[i].selected=false; +if(_52[i].value==_53){ +_52[i].selected=true; } } }}; diff --git a/framework/Web/Javascripts/js/prado.js b/framework/Web/Javascripts/js/prado.js index 92bd4921..590882fa 100644 --- a/framework/Web/Javascripts/js/prado.js +++ b/framework/Web/Javascripts/js/prado.js @@ -1961,144 +1961,151 @@ _89.push(_88[i]); return _89; }}; -Object.extend(Date.prototype,{SimpleFormat:function(_1){ -var _2=new Array(); -_2["d"]=this.getDate(); -_2["dd"]=String(this.getDate()).zerofill(2); -_2["M"]=this.getMonth()+1; -_2["MM"]=String(this.getMonth()+1).zerofill(2); -var _3=""+this.getFullYear(); -_3=(_3.length==2)?"19"+_3:_3; -_2["yyyy"]=_3; -_2["yy"]=_2["yyyy"].toString().substr(2,2); -var _4=new String(_1); -for(var _5 in _2){ -var _6=new RegExp("\\b"+_5+"\\b","g"); -_4=_4.replace(_6,_2[_5]); +Object.extend(Date.prototype,{SimpleFormat:function(_1,_2){ +_2=_2||{}; +var _3=new Array(); +_3["d"]=this.getDate(); +_3["dd"]=String(this.getDate()).zerofill(2); +_3["M"]=this.getMonth()+1; +_3["MM"]=String(this.getMonth()+1).zerofill(2); +if(_2.AbbreviatedMonthNames){ +_3["MMM"]=_2.AbbreviatedMonthNames[this.getMonth()]; +} +if(_2.MonthNames){ +_3["MMMM"]=_2.MonthNames[this.getMonth()]; +} +var _4=""+this.getFullYear(); +_4=(_4.length==2)?"19"+_4:_4; +_3["yyyy"]=_4; +_3["yy"]=_3["yyyy"].toString().substr(2,2); +var _5=new String(_1); +for(var _6 in _3){ +var _7=new RegExp("\\b"+_6+"\\b","g"); +_5=_5.replace(_7,_3[_6]); } -return _4; +return _5; },toISODate:function(){ var y=this.getFullYear(); var m=String(this.getMonth()+1).zerofill(2); var d=String(this.getDate()).zerofill(2); return String(y)+String(m)+String(d); }}); -Object.extend(Date,{SimpleParse:function(_10,_11){ -val=String(_10); -_11=String(_11); +Object.extend(Date,{SimpleParse:function(_11,_12){ +val=String(_11); +_12=String(_12); if(val.length<=0){ return null; } -if(_11.length<=0){ -return new Date(_10); +if(_12.length<=0){ +return new Date(_11); } -var _12=function(val){ -var _14="1234567890"; +var _13=function(val){ +var _15="1234567890"; for(var i=0;i=_18;x--){ -var _21=str.substring(i,i+x); -if(_21.length<_18){ +var _17=function(str,i,_19,_20){ +for(var x=_20;x>=_19;x--){ +var _22=str.substring(i,i+x); +if(_22.length<_19){ return null; } -if(_12(_21)){ -return _21; +if(_13(_22)){ +return _22; } } return null; }; -var _22=0; var _23=0; +var _24=0; var c=""; -var _25=""; var _26=""; +var _27=""; var x,y; var now=new Date(); -var _28=now.getFullYear(); -var _29=now.getMonth()+1; -var _30=1; -while(_23<_11.length){ -c=_11.charAt(_23); -_25=""; -while((_11.charAt(_23)==c)&&(_23<_11.length)){ -_25+=_11.charAt(_23++); -} -if(_25=="yyyy"||_25=="yy"||_25=="y"){ -if(_25=="yyyy"){ +var _29=now.getFullYear(); +var _30=now.getMonth()+1; +var _31=1; +while(_24<_12.length){ +c=_12.charAt(_24); +_26=""; +while((_12.charAt(_24)==c)&&(_24<_12.length)){ +_26+=_12.charAt(_24++); +} +if(_26=="yyyy"||_26=="yy"||_26=="y"){ +if(_26=="yyyy"){ x=4; y=4; } -if(_25=="yy"){ +if(_26=="yy"){ x=2; y=2; } -if(_25=="y"){ +if(_26=="y"){ x=2; y=4; } -_28=_16(val,_22,x,y); -if(_28==null){ +_29=_17(val,_23,x,y); +if(_29==null){ return null; } -_22+=_28.length; -if(_28.length==2){ -if(_28>70){ -_28=1900+(_28-0); +_23+=_29.length; +if(_29.length==2){ +if(_29>70){ +_29=1900+(_29-0); }else{ -_28=2000+(_28-0); +_29=2000+(_29-0); } } }else{ -if(_25=="MM"||_25=="M"){ -_29=_16(val,_22,_25.length,2); -if(_29==null||(_29<1)||(_29>12)){ +if(_26=="MM"||_26=="M"){ +_30=_17(val,_23,_26.length,2); +if(_30==null||(_30<1)||(_30>12)){ return null; } -_22+=_29.length; +_23+=_30.length; }else{ -if(_25=="dd"||_25=="d"){ -_30=_16(val,_22,_25.length,2); -if(_30==null||(_30<1)||(_30>31)){ +if(_26=="dd"||_26=="d"){ +_31=_17(val,_23,_26.length,2); +if(_31==null||(_31<1)||(_31>31)){ return null; } -_22+=_30.length; +_23+=_31.length; }else{ -if(val.substring(_22,_22+_25.length)!=_25){ +if(val.substring(_23,_23+_26.length)!=_26){ return null; }else{ -_22+=_25.length; +_23+=_26.length; } } } } } -if(_22!=val.length){ +if(_23!=val.length){ return null; } -if(_29==2){ -if(((_28%4==0)&&(_28%100!=0))||(_28%400==0)){ -if(_30>29){ +if(_30==2){ +if(((_29%4==0)&&(_29%100!=0))||(_29%400==0)){ +if(_31>29){ return null; } }else{ -if(_30>28){ +if(_31>28){ return null; } } } -if((_29==4)||(_29==6)||(_29==9)||(_29==11)){ -if(_30>30){ +if((_30==4)||(_30==6)||(_30==9)||(_30==11)){ +if(_31>30){ return null; } } -var _31=new Date(_28,_29-1,_30,0,0,0); -return _31; +var _32=new Date(_29,_30-1,_31,0,0,0); +return _32; }}); var Prado={Version:"3.0a",Browser:function(){ diff --git a/framework/Web/Javascripts/prado/datepicker.js b/framework/Web/Javascripts/prado/datepicker.js deleted file mode 100644 index f3c6ff27..00000000 --- a/framework/Web/Javascripts/prado/datepicker.js +++ /dev/null @@ -1,586 +0,0 @@ -Prado.WebUI.TDatePicker = Class.create(); -Prado.WebUI.TDatePicker.prototype = -{ - MonthNames : [ "January", "February", "March", "April", - "May", "June", "July", "August", - "September", "October", "November", "December" - ], - - ShortWeekDayNames : ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" ], - - Format : "yyyy-MM-dd", - - FirstDayOfWeek : 1, // 0 for sunday - - ClassName : "TDatePicker", - - FromYear : 2000, UpToYear: 2015, - - initialize : function(control, attr) - { - this.attr = attr || []; - this.control = $(control); - this.dateSlot = new Array(42); - this.weekSlot = new Array(6); - this.minimalDaysInFirstWeek = 4; - this.selectedDate = this.newDate(); - - //which element to trigger to show the calendar - if(this.attr.Trigger) - { - this.trigger = $(this.attr.Trigger) ; - var triggerEvent = this.attr.TriggerEvent || "click"; - } - else - { - this.trigger = this.control; - var triggerEvent = this.attr.TriggerEvent || "focus"; - } - - Event.observe(this.trigger, triggerEvent, this.show.bindEvent(this)); - - Object.extend(this,attr); - - this.create(); - }, - - create : function() - { - var div; - var table; - var tbody; - var tr; - var td; - - // Create the top-level div element - this._calDiv = document.createElement("div"); - this._calDiv.className = this.ClassName; - this._calDiv.style.display = "none"; - - // header div - div = document.createElement("div"); - div.className = "calendarHeader"; - this._calDiv.appendChild(div); - - table = document.createElement("table"); - table.style.cellSpacing = 0; - div.appendChild(table); - - tbody = document.createElement("tbody"); - table.appendChild(tbody); - - tr = document.createElement("tr"); - tbody.appendChild(tr); - - // Previous Month Button - td = document.createElement("td"); - var previousMonth = document.createElement("button"); - previousMonth.className = "prevMonthButton"; - previousMonth.appendChild(document.createTextNode("<<")); - td.appendChild(previousMonth); - tr.appendChild(td); - - - - // - // Create the month drop down - // - td = document.createElement("td"); - tr.appendChild(td); - this._monthSelect = document.createElement("select"); - this._monthSelect.className = "months"; - for (var i = 0 ; i < this.MonthNames.length ; i++) { - var opt = document.createElement("option"); - opt.innerHTML = this.MonthNames[i]; - opt.value = i; - if (i == this.selectedDate.getMonth()) { - opt.selected = true; - } - this._monthSelect.appendChild(opt); - } - td.appendChild(this._monthSelect); - - - // - // Create the year drop down - // - td = document.createElement("td"); - td.className = "labelContainer"; - tr.appendChild(td); - this._yearSelect = document.createElement("select"); - for(var i=this.FromYear; i <= this.UpToYear; ++i) { - var opt = document.createElement("option"); - opt.innerHTML = i; - opt.value = i; - if (i == this.selectedDate.getFullYear()) { - opt.selected = false; - } - this._yearSelect.appendChild(opt); - } - td.appendChild(this._yearSelect); - - - td = document.createElement("td"); - td.className = "nextMonthButton"; - var nextMonth = document.createElement("button"); - nextMonth.appendChild(document.createTextNode(">>")); - td.appendChild(nextMonth); - tr.appendChild(td); - - // Calendar body - div = document.createElement("div"); - div.className = "calendarBody"; - this._calDiv.appendChild(div); - var calendarBody = div; - - // Create the inside of calendar body - - var text; - table = document.createElement("table"); - //table.style.width="100%"; - table.className = "grid"; - - div.appendChild(table); - var thead = document.createElement("thead"); - table.appendChild(thead); - tr = document.createElement("tr"); - thead.appendChild(tr); - - for(i=0; i < 7; ++i) { - td = document.createElement("th"); - text = document.createTextNode(this.ShortWeekDayNames[(i+this.FirstDayOfWeek)%7]); - td.appendChild(text); - td.className = "weekDayHead"; - tr.appendChild(td); - } - - // Date grid - tbody = document.createElement("tbody"); - table.appendChild(tbody); - - for(week=0; week<6; ++week) { - tr = document.createElement("tr"); - tbody.appendChild(tr); - - for(day=0; day<7; ++day) { - td = document.createElement("td"); - td.className = "calendarDate"; - text = document.createTextNode(String.fromCharCode(160)); - td.appendChild(text); - - tr.appendChild(td); - var tmp = new Object(); - tmp.tag = "DATE"; - tmp.value = -1; - tmp.data = text; - this.dateSlot[(week*7)+day] = tmp; - - Event.observe(td, "mouseover", this.hover.bindEvent(this)); - Event.observe(td, "mouseout", this.hover.bindEvent(this)); - - } - } - - // Calendar Footer - div = document.createElement("div"); - div.className = "calendarFooter"; - this._calDiv.appendChild(div); - - var todayButton = document.createElement("button"); - todayButton.className = "todayButton"; - var today = this.newDate(); - var buttonText = today.getDate() + " " + this.MonthNames[today.getMonth()] + ", " + today.getFullYear(); - todayButton.appendChild(document.createTextNode(buttonText)); - div.appendChild(todayButton); - - var clearButton = document.createElement("button"); - clearButton.className = "clearButton"; - buttonText = "Clear"; - clearButton.appendChild(document.createTextNode(buttonText)); - div.appendChild(clearButton); - - if(Prado.Browser().ie) - { - this.iePopUp = document.createElement('iframe'); - this.iePopUp.src = ""; - this.iePopUp.style.position = "absolute" - this.iePopUp.scrolling="no" - this.iePopUp.frameBorder="0" - document.body.appendChild(this.iePopUp); - } - - document.body.appendChild(this._calDiv); - - this.update(); - this.updateHeader(); - - this.ieHack(true); - - // IE55+ extension - previousMonth.hideFocus = true; - nextMonth.hideFocus = true; - todayButton.hideFocus = true; - // end IE55+ extension - - // hook up events - Event.observe(previousMonth, "click", this.prevMonth.bindEvent(this)); - Event.observe(nextMonth, "click", this.nextMonth.bindEvent(this)); - Event.observe(todayButton, "click", this.selectToday.bindEvent(this)); - Event.observe(clearButton, "click", this.clearSelection.bindEvent(this)); - Event.observe(this._monthSelect, "change", this.monthSelect.bindEvent(this)); - Event.observe(this._yearSelect, "change", this.yearSelect.bindEvent(this)); - - // ie6 extension - Event.observe(this._calDiv, "mousewheel", this.mouseWheelChange.bindEvent(this)); - - Event.observe(calendarBody, "click", this.selectDate.bindEvent(this)); - - }, - - ieHack : function(cleanup) - { - // IE hack - if(this.iePopUp) - { - this.iePopUp.style.display = "block"; - this.iePopUp.style.top = (this._calDiv.offsetTop -1 ) + "px"; - this.iePopUp.style.left = (this._calDiv.offsetLeft -1)+ "px"; - this.iePopUp.style.width = Math.abs(this._calDiv.offsetWidth -2)+ "px"; - this.iePopUp.style.height = (this._calDiv.offsetHeight + 1)+ "px"; - if(cleanup) this.iePopUp.style.display = "none"; - } - }, - - keyPressed : function(ev) - { - if(!this.showing) return; - if (!ev) ev = document.parentWindow.event; - var kc = ev.keyCode != null ? ev.keyCode : ev.charCode; - - if(kc == Event.KEY_RETURN) - { - //var d = new Date(this.currentDate); - //this.setSelectedDate(this.currentDate); - Event.stop(ev); - this.hide(); - } - - - var getDaysPerMonth = function (nMonth, nYear) - { - nMonth = (nMonth + 12) % 12; - var days= [31,28,31,30,31,30,31,31,30,31,30,31]; - var res = days[nMonth]; - if (nMonth == 1) //feburary, leap years has 29 - res += nYear % 4 == 0 && !(nYear % 400 == 0) ? 1 : 0; - return res; - } - - if(kc < 37 || kc > 40) return true; - - var current = this.selectedDate; - var d = current.valueOf(); - if(kc == Event.KEY_LEFT) - { - if(ev.ctrlKey || ev.shiftKey) // -1 month - { - current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() - 1,current.getFullYear())) ); // no need to catch dec -> jan for the year - d = current.setMonth( current.getMonth() - 1 ); - } - else - d -= 86400000; //-1 day - } - else if (kc == Event.KEY_RIGHT) - { - if(ev.ctrlKey || ev.shiftKey) // +1 month - { - current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth() + 1,current.getFullYear())) ); // no need to catch dec -> jan for the year - d = current.setMonth( current.getMonth() + 1 ); - } - else - d += 86400000; //+1 day - } - else if (kc == Event.KEY_UP) - { - if(ev.ctrlKey || ev.shiftKey) //-1 year - { - current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() - 1)) ); // no need to catch dec -> jan for the year - d = current.setFullYear( current.getFullYear() - 1 ); - } - else - d -= 604800000; // -7 days - } - else if (kc == Event.KEY_DOWN) - { - if(ev.ctrlKey || ev.shiftKey) // +1 year - { - current.setDate( Math.min(current.getDate(), getDaysPerMonth(current.getMonth(),current.getFullYear() + 1)) ); // no need to catch dec -> jan for the year - d = current.setFullYear( current.getFullYear() + 1 ); - } - else - d += 7 * 24 * 61 * 60 * 1000; // +7 days - } - this.setSelectedDate(d); - Event.stop(ev); - }, - - selectDate : function(ev) - { - var el = Event.element(ev); - while (el.nodeType != 1) - el = el.parentNode; - - while (el != null && el.tagName && el.tagName.toLowerCase() != "td") - el = el.parentNode; - - // if no td found, return - if (el == null || el.tagName == null || el.tagName.toLowerCase() != "td") - return; - - var d = this.newDate(this.selectedDate); - var n = Number(el.firstChild.data); - if (isNaN(n) || n <= 0 || n == null) - return; - - d.setDate(n); - this.setSelectedDate(d); - this.hide(); - }, - - selectToday : function() - { - this.setSelectedDate(this.newDate()); - this.hide(); - }, - - clearSelection : function() - { - this.setSelectedDate(this.newDate()); - this.hide(); - }, - - monthSelect : function(ev) - { - this.setMonth(Form.Element.getValue(Event.element(ev))); - }, - - yearSelect : function(ev) - { - this.setYear(Form.Element.getValue(Event.element(ev))); - }, - - // ie6 extension - mouseWheelChange : function (e) - { - if (e == null) e = document.parentWindow.event; - var n = - e.wheelDelta / 120; - var d = this.newDate(this.selectedDate); - var m = d.getMonth() + n; - this.setMonth(m); - - return false; - }, - - onchange : function() - { - this.control.value = this.formatDate(); - }, - - formatDate : function() - { - return this.selectedDate ? this.selectedDate.SimpleFormat(this.Format) : ''; - }, - - newDate : function(date) - { - if(!date) - date = new Date(); - if(isString(date) || isNumber(date)) - date = new Date(date); - return new Date(date.getFullYear(), date.getMonth(), date.getDate(), 0,0,0); - }, - - setSelectedDate : function(date) - { - if (date == null) - return; - this.selectedDate = this.newDate(date); - - this.updateHeader(); - this.update(); - if (isFunction(this.onchange)) - this.onchange(); - }, - - getElement : function() - { - return this._calDiv; - }, - - getSelectedDate : function () - { - return isNull(this.selectedDate) ? null : this.newDate(this.selectedDate); - }, - - setYear : function(year) - { - var d = this.newDate(this.selectedDate); - d.setFullYear(year); - this.setSelectedDate(d); - }, - - setMonth : function (month) - { - var d = this.newDate(this.selectedDate); - d.setMonth(month); - this.setSelectedDate(d); - }, - - nextMonth : function () - { - this.setMonth(this.selectedDate.getMonth()+1); - }, - - prevMonth : function () - { - this.setMonth(this.selectedDate.getMonth()-1); - }, - - show : function() - { - if(!this.showing) - { - var pos = Position.cumulativeOffset(this.control); - pos[1] += this.control.offsetHeight; - this._calDiv.style.display = "block"; - this._calDiv.style.top = (pos[1]-1) + "px"; - this._calDiv.style.left = pos[0] + "px"; - - this.ieHack(false); - this.documentClickEvent = this.hideOnClick.bindEvent(this); - this.documentKeyDownEvent = this.keyPressed.bindEvent(this); - Event.observe(document.body, "click", this.documentClickEvent); - var date = Date.SimpleParse(Form.Element.getValue(this.control), this.Format); - if(!isNull(date)) - { - this.selectedDate = date; - this.setSelectedDate(date); - } - Event.observe(document,"keydown", this.documentKeyDownEvent); - this.showing = true; - } - }, - - //hide the calendar when clicked outside any calendar - hideOnClick : function(ev) - { - if(!this.showing) return; - var el = Event.element(ev); - var within = false; - do - { - within = within || el.className == this.ClassName; - within = within || el == this.trigger; - within = within || el == this.control; - if(within) break; - el = el.parentNode; - } - while(el); - if(!within) this.hide(); - }, - - hide : function() - { - if(this.showing) - { - this._calDiv.style.display = "none"; - if(this.iePopUp) - this.iePopUp.style.display = "none"; - this.showing = false; - Event.stopObserving(document.body, "click", this.documentClickEvent); - Event.stopObserving(document,"keydown", this.documentKeyDownEvent); - } - }, - - update : function() - { - // Calculate the number of days in the month for the selected date - var date = this.selectedDate; - var today = (this.newDate()).toISODate(); - - var selected = date.toISODate(); - var d1 = new Date(date.getFullYear(), date.getMonth(), 1); - var d2 = new Date(date.getFullYear(), date.getMonth()+1, 1); - var monthLength = Math.round((d2 - d1) / (24 * 60 * 60 * 1000)); - - // Find out the weekDay index for the first of this month - var firstIndex = (d1.getDay() - this.FirstDayOfWeek) % 7 ; - if (firstIndex < 0) - firstIndex += 7; - - var index = 0; - while (index < firstIndex) { - this.dateSlot[index].value = -1; - this.dateSlot[index].data.data = String.fromCharCode(160); - this.dateSlot[index].data.parentNode.className = "empty"; - index++; - } - - for (i = 1; i <= monthLength; i++, index++) { - var slot = this.dateSlot[index]; - var slotNode = slot.data.parentNode; - slot.value = i; - slot.data.data = i; - slotNode.className = "date"; - //slotNode.style.color = ""; - if (d1.toISODate() == today) { - slotNode.className += " today"; - } - if (d1.toISODate() == selected) { - // slotNode.style.color = "blue"; - slotNode.className += " selected"; - } - d1 = new Date(d1.getFullYear(), d1.getMonth(), d1.getDate()+1); - } - - var lastDateIndex = index; - - while(index < 42) { - this.dateSlot[index].value = -1; - this.dateSlot[index].data.data = String.fromCharCode(160); - this.dateSlot[index].data.parentNode.className = "empty"; - ++index; - } - - }, - - hover : function(ev) - { - //conditionally add the hover class to the event target element. - Element.condClassName(Event.element(ev), "hover", ev.type=="mouseover"); - }, - - updateHeader : function () { - - var options = this._monthSelect.options; - var m = this.selectedDate.getMonth(); - for(var i=0; i < options.length; ++i) { - options[i].selected = false; - if (options[i].value == m) { - options[i].selected = true; - } - } - - options = this._yearSelect.options; - var year = this.selectedDate.getFullYear(); - for(var i=0; i < options.length; ++i) { - options[i].selected = false; - if (options[i].value == year) { - options[i].selected = true; - } - } - - } - - -}; \ No newline at end of file diff --git a/framework/Web/Javascripts/prado/datepicker_default.css b/framework/Web/Javascripts/prado/datepicker_default.css deleted file mode 100644 index 3d57370b..00000000 --- a/framework/Web/Javascripts/prado/datepicker_default.css +++ /dev/null @@ -1,69 +0,0 @@ -.TDatePicker -{ - border: 1px solid #919EA9; - position: absolute; - background-color: White; - text-align: center; - font-size: 11px; - font-family: Tahoma, Arial, Helvetica, sans-serif; - cursor: default; -} - -.TDatePicker select -{ - font-size: 11px; -} - -.TDatePicker .calendarHeader button -{ - font-size: 12px; - width: 32px; -} - -.TDatePicker .date -{ - padding: 4px 0; - border: 1px solid white; -} -.TDatePicker .hover -{ - border: 1px solid blue; -} -.TDatePicker .selected -{ - background-color: blue; - border: 1px solid blue; - color: white; -} -.TDatePicker .today -{ - font-weight: bold; -} - -.TDatePicker td.empty -{ - background-color: #ffe; - border: 1px solid white; - cursor: default; - height: 23px; -} -.TDatePicker th -{ - width: 28px; -} -.TDatePicker .grid -{ - border-spacing: 0px; - margin: 3px; -} -.TDatePicker .calendarFooter -{ - margin: 2px; - border-top: 1px solid #919EA9; - padding-top: 2px; -} -.TDatePicker .calendarFooter button -{ - font-size: 12px; - margin: 4px; -} \ No newline at end of file diff --git a/framework/Web/Javascripts/prado/test.html b/framework/Web/Javascripts/prado/test.html deleted file mode 100644 index ab4ff973..00000000 --- a/framework/Web/Javascripts/prado/test.html +++ /dev/null @@ -1,105 +0,0 @@ - - - - - Prado Date Picker - - - - - - -
- - -
-
- - - - - -
- - -as
-dv
-as
-d
-as
-d
-asd
-a
-sd
-dv
-as
-d
-as
-d
-asd
-a
-sd
-dv
-as
-d
-as
-d
-asd
-a
-sd
-
- -
-d
-as
-d
-asd
-a
-sd
-dv
-as
-d
-as
-d
-asd
-a
-sd
- - - - -- cgit v1.2.3