Ext.override(Ext.form.DateField, {
/// Datejs uses standard Java/.NET date and time format specifers.
/// See http://code.google.com/p/datejs/wiki/FormatSpecifiers for more information
format : "M/d/yy",
///format : "m/d/y",
// private
parseDate : function(value){
/// Use Datejs .parse() and just return here.
return Date.parse(value);
/// The rest of this function is not required and can be deleted
if(!value || value instanceof Date){
return value;
}
var v = Date.parseDate(value, this.format);
if(!v && this.altFormats){
if(!this.altFormatsArray){
this.altFormatsArray = this.altFormats.split("|");
}
for(var i = 0, len = this.altFormatsArray.length; i < len && !v; i++){
v = Date.parseDate(value, this.altFormatsArray[i]);
}
}
return v;
},
// private
formatDate : function(date){
/// Use Datejs .toString() instead of Ext .dateFormat()
return (!date || !(date instanceof Date)) ?
date : date.toString(this.format);
///return (!date || !(date instanceof Date)) ?
///date : date.dateFormat(this.format);
}
});
Ext.override(Ext.DatePicker, {
/// Datejs uses standard Java/.NET date and time format specifers.
/// See http://code.google.com/p/datejs/wiki/FormatSpecifiers for more information
format : "M/d/yy",
///format : "m/d/y",
/**
* Sets the value of the date field
* @param {Date} value The date to set
*/
setValue : function(value){
var old = this.value;
/// clone before clearing time.
this.value = value.clone().clearTime();
///this.value = value.clearTime(true);
if(this.el){
this.update(this.value);
}
},
// private
onRender : function(container, position){
var m = [
'
',
' | | |
',
''];
/// Obsolete
var dn = this.dayNames;
for(var i = 0; i < 7; i++){
var d = this.startDay+i;
if(d > 6){
d = d-7;
}
/// Pull the one character strings directly from Date.CultureInfo.firstLetterDayNames
m.push("", Date.CultureInfo.firstLetterDayNames[d], " | ");
///m.push("", dn[d].substr(0,1), " | ");
}
m[m.length] = " ";
for(var i = 0; i < 42; i++) {
if(i % 7 == 0 && i != 0){
m[m.length] = " ";
}
m[m.length] = ' | ';
}
m[m.length] = '
|
|
';
var el = document.createElement("div");
el.className = "x-date-picker";
el.innerHTML = m.join("");
container.dom.insertBefore(el, position);
this.el = Ext.get(el);
this.eventEl = Ext.get(el.firstChild);
new Ext.util.ClickRepeater(this.el.child("td.x-date-left a"), {
handler: this.showPrevMonth,
scope: this,
preventDefault:true,
stopDefault:true
});
new Ext.util.ClickRepeater(this.el.child("td.x-date-right a"), {
handler: this.showNextMonth,
scope: this,
preventDefault:true,
stopDefault:true
});
this.eventEl.on("mousewheel", this.handleMouseWheel, this);
this.monthPicker = this.el.down('div.x-date-mp');
this.monthPicker.enableDisplayMode('block');
var kn = new Ext.KeyNav(this.eventEl, {
"left" : function(e){
e.ctrlKey ?
this.showPrevMonth() :
/// other options include...
/// .add(1).day()
/// .add({days: 1})
/// ... but .addDays() has the fastest performance
this.update(this.activeDate.clone().addDays(-1));
///this.update(this.activeDate.add("d", -1));
},
"right" : function(e){
e.ctrlKey ?
this.showNextMonth() :
this.update(this.activeDate.clone().addDays(1));
///this.update(this.activeDate.add("d", 1));
},
"up" : function(e){
e.ctrlKey ?
this.showNextYear() :
this.update(this.activeDate.clone().addDays(-7));
///this.update(this.activeDate.add("d", -7));
},
"down" : function(e){
e.ctrlKey ?
this.showPrevYear() :
this.update(this.activeDate.clone().addDays(7));
///this.update(this.activeDate.add("d", 7));
},
"pageUp" : function(e){
this.showNextMonth();
},
"pageDown" : function(e){
this.showPrevMonth();
},
"enter" : function(e){
e.stopPropagation();
return true;
},
scope : this
});
this.eventEl.on("click", this.handleDateClick, this, {delegate: "a.x-date-date"});
this.eventEl.addKeyListener(Ext.EventObject.SPACE, this.selectToday, this);
this.el.unselectable();
this.cells = this.el.select("table.x-date-inner tbody td");
this.textNodes = this.el.query("table.x-date-inner tbody span");
this.mbtn = new Ext.Button(this.el.child("td.x-date-middle", true), {
text: " ",
tooltip: this.monthYearText
});
this.mbtn.on('click', this.showMonthPicker, this);
this.mbtn.el.child(this.mbtn.menuClassTarget).addClass("x-btn-with-menu");
/// Use Datejs .toString() instead of Ext dateFormat
var today = Date.tod().toString(this.format);
///var today = (new Date()).dateFormat(this.format);
var todayBtn = new Ext.Button(this.el.child("td.x-date-bottom", true), {
text: String.format(this.todayText, today),
tooltip: String.format(this.todayTip, today),
handler: this.selectToday,
scope: this
});
if(Ext.isIE){
this.el.repaint();
}
this.update(this.value);
},
// private
showPrevMonth : function(e){
/// other options include...
/// .add(1).month()
/// .add({months: 1})
/// ... but .addMonths() has the fastest performance
this.update(this.activeDate.clone().addMonths(-1));
///this.update(this.activeDate.add("mo", -1));
},
// private
showNextMonth : function(e){
this.update(this.activeDate.clone().addMonths(1));
///this.update(this.activeDate.add("mo", 1));
},
// private
showPrevYear : function(){
/// other options include...
/// .add(1).year()
/// .add({years: 1})
/// ... but .addYears() has the fastest performance
this.update(this.activeDate.clone().addYears(-1));
///this.update(this.activeDate.add("y", -1));
},
// private
showNextYear : function(){
this.update(this.activeDate.clone().addYears(1));
///this.update(this.activeDate.add("y", 1));
},
// private
selectToday : function(){
/// Same as Date.today(), but shorter.
this.setValue(Date.tod());
///this.setValue(new Date().clearTime());
this.fireEvent("select", this, this.value);
},
// private
update : function(date){
var vd = this.activeDate;
/// .clone() just to be safe.
this.activeDate = date.clone();
///this.activeDate = date;
if(vd && this.el){
var t = date.getTime();
if(vd.getMonth() == date.getMonth() && vd.getFullYear() == date.getFullYear()){
this.cells.removeClass("x-date-selected");
this.cells.each(function(c){
if(c.dom.firstChild.dateValue == t){
c.addClass("x-date-selected");
setTimeout(function(){
try{c.dom.firstChild.focus();}catch(e){}
}, 50);
return false;
}
});
return;
}
}
var days = date.getDaysInMonth();
/// .clone() the date and move the clone to the first of the month
var firstOfMonth = date.clone().moveToFirstDayOfMonth();
///var firstOfMonth = date.getFirstDateOfMonth();
var startingPos = firstOfMonth.getDay()-this.startDay;
if(startingPos <= this.startDay){
startingPos += 7;
}
var pm = date.clone().addMonths(-1);
///var pm = date.add("mo", -1);
var prevStart = pm.getDaysInMonth()-startingPos;
var cells = this.cells.elements;
var textEls = this.textNodes;
days += startingPos;
// convert everything to numbers so it's fast
var day = 86400000;
var d = (new Date(pm.getFullYear(), pm.getMonth(), prevStart)).clearTime();
/// Same as Date.today(), but shorter.
var today = Date.tod().getTime();
///var today = new Date().clearTime().getTime();
var sel = date.clearTime().getTime();
var min = this.minDate ? this.minDate.clearTime() : Number.NEGATIVE_INFINITY;
var max = this.maxDate ? this.maxDate.clearTime() : Number.POSITIVE_INFINITY;
var ddMatch = this.disabledDatesRE;
var ddText = this.disabledDatesText;
var ddays = this.disabledDays ? this.disabledDays.join("") : false;
var ddaysText = this.disabledDaysText;
var format = this.format;
var setCellClass = function(cal, cell){
cell.title = "";
var t = d.getTime();
cell.firstChild.dateValue = t;
if(t == today){
cell.className += " x-date-today";
cell.title = cal.todayText;
}
if(t == sel){
cell.className += " x-date-selected";
setTimeout(function(){
try{cell.firstChild.focus();}catch(e){}
}, 50);
}
// disabling
if(t < min) {
cell.className = " x-date-disabled";
cell.title = cal.minText;
return;
}
if(t > max) {
cell.className = " x-date-disabled";
cell.title = cal.maxText;
return;
}
if(ddays){
if(ddays.indexOf(d.getDay()) != -1){
cell.title = ddaysText;
cell.className = " x-date-disabled";
}
}
if(ddMatch && format){
/// Use Datejs .toString() instead of Ext .dateFormat()
var fvalue = d.toString(format);
///var fvalue = d.dateFormat(format);
if(ddMatch.test(fvalue)){
cell.title = ddText.replace("%0", fvalue);
cell.className = " x-date-disabled";
}
}
};
var i = 0;
for(; i < startingPos; i++) {
textEls[i].innerHTML = (++prevStart);
d.setDate(d.getDate()+1);
cells[i].className = "x-date-prevday";
setCellClass(this, cells[i]);
}
for(; i < days; i++){
intDay = i - startingPos + 1;
textEls[i].innerHTML = (intDay);
d.setDate(d.getDate()+1);
cells[i].className = "x-date-active";
setCellClass(this, cells[i]);
}
var extraDays = 0;
for(; i < 42; i++) {
textEls[i].innerHTML = (++extraDays);
d.setDate(d.getDate()+1);
cells[i].className = "x-date-nextday";
setCellClass(this, cells[i]);
}
this.mbtn.setText(Date.CultureInfo.monthNames[date.getMonth()] + " " + date.getFullYear());
if(!this.internalRender){
var main = this.el.dom.firstChild;
var w = main.offsetWidth;
this.el.setWidth(w + this.el.getBorderWidth("lr"));
Ext.fly(main).setWidth(w);
this.internalRender = true;
// opera does not respect the auto grow header center column
// then, after it gets a width opera refuses to recalculate
// without a second pass
if(Ext.isOpera && !this.secondPass){
main.rows[0].cells[1].style.width = (w - (main.rows[0].cells[0].offsetWidth+main.rows[0].cells[2].offsetWidth)) + "px";
this.secondPass = true;
this.update.defer(10, this, [date]);
}
}
}
});