profunctional
22 Oct 2010, 8:58 AM
I used to have a datetimepicker but after upgrading to .97 everything broke. Anyone have a working example?
Here is what USED to work.
custom.controls.DateTimePicker = Ext.extend(Ext.DatePicker, {
initComponent: function() {
var yearsFrom = this.yearFrom;
var yearsTo = this.yearTo;
var years = [];
// swap values if user mixes them up.
if (yearsFrom > yearsTo) {
var tmp = yearsFrom;
yearsFrom = yearsTo;
yearsTo = tmp;
}
for (var i = yearsFrom; i <= yearsTo; i++) {
years.push({
key: i,
value: i
});
}
var daysInMonth;
if (this.value) {
daysInMonth = this.getDaysInMonth(this.value.month, this.value.year);
} else {
daysInMonth = this.getDaysInMonth(0, new Date().getFullYear());
}
var days = [];
for (i = 0; i < daysInMonth; i++) {
days.push({
key: i+1,
value: i+1
});
}
var months = [];
for (i = 0, ln = Date.monthNames.length; i < ln; i++) {
months.push({
key: Date.getShortMonthName(i),
value: i
});
}
var hours = [
{key: '1am', value: 1},
{key: '2am', value: 2},
{key: '3am', value: 3},
{key: '4am', value: 4},
{key: '5am', value: 5},
{key: '6am', value: 6},
{key: '7am', value: 7},
{key: '8am', value: 8},
{key: '9am', value: 9},
{key: '10am', value: 10},
{key: '11am', value: 11},
{key: '12pm', value: 12},
{key: '1pm', value: 13},
{key: '2pm', value: 14},
{key: '3pm', value: 15},
{key: '4pm', value: 16},
{key: '5pm', value: 17},
{key: '6pm', value: 18},
{key: '7pm', value: 19},
{key: '8pm', value: 20},
{key: '9pm', value: 21},
{key: '10pm', value: 22},
{key: '11pm', value: 23},
{key: '12am', value: 0}
];
var minutes = [
{key: '00', value: 00},
{key: '05', value: 05},
{key: '10', value: 10},
{key: '15', value: 15},
{key: '20', value: 20},
{key: '25', value: 25},
{key: '30', value: 30},
{key: '35', value: 35},
{key: '40', value: 40},
{key: '45', value: 45},
{key: '50', value: 50},
{key: '55', value: 55}
];
this.slots = [{
text: 'Month',
name: 'month',
align: 'left',
items: months
},{
text: 'Day',
name: 'day',
align: 'center',
items: days
},{
text: 'Year',
name: 'year',
align: 'right',
items: years
},{
text: 'Hour',
name: 'hour',
align: 'left',
items: hours
}, {
text: 'Minute',
name: 'minute',
align: 'left',
items: minutes
}
];
Ext.DatePicker.superclass.initComponent.call(this);
this.on('pick', this.onPick, this);
},
getValue: function() {
var v = Ext.DatePicker.superclass.getValue.call(this),
day,
daysInMonth = this.getDaysInMonth(v.month, v.year);
if (v.day !== "") {
day = Math.min(v.day, daysInMonth);
} else {
day = daysInMonth;
var dv = this.items.itemAt(1),
idx = dv.store.find(this.valueField, daysInMonth),
r = dv.store.getAt(idx),
n = dv.getNode(r);
this.scrollToNode(dv, n);
}
return new Date(v.year, v.month, day, v.hour, v.minute);
}
});
Here is what USED to work.
custom.controls.DateTimePicker = Ext.extend(Ext.DatePicker, {
initComponent: function() {
var yearsFrom = this.yearFrom;
var yearsTo = this.yearTo;
var years = [];
// swap values if user mixes them up.
if (yearsFrom > yearsTo) {
var tmp = yearsFrom;
yearsFrom = yearsTo;
yearsTo = tmp;
}
for (var i = yearsFrom; i <= yearsTo; i++) {
years.push({
key: i,
value: i
});
}
var daysInMonth;
if (this.value) {
daysInMonth = this.getDaysInMonth(this.value.month, this.value.year);
} else {
daysInMonth = this.getDaysInMonth(0, new Date().getFullYear());
}
var days = [];
for (i = 0; i < daysInMonth; i++) {
days.push({
key: i+1,
value: i+1
});
}
var months = [];
for (i = 0, ln = Date.monthNames.length; i < ln; i++) {
months.push({
key: Date.getShortMonthName(i),
value: i
});
}
var hours = [
{key: '1am', value: 1},
{key: '2am', value: 2},
{key: '3am', value: 3},
{key: '4am', value: 4},
{key: '5am', value: 5},
{key: '6am', value: 6},
{key: '7am', value: 7},
{key: '8am', value: 8},
{key: '9am', value: 9},
{key: '10am', value: 10},
{key: '11am', value: 11},
{key: '12pm', value: 12},
{key: '1pm', value: 13},
{key: '2pm', value: 14},
{key: '3pm', value: 15},
{key: '4pm', value: 16},
{key: '5pm', value: 17},
{key: '6pm', value: 18},
{key: '7pm', value: 19},
{key: '8pm', value: 20},
{key: '9pm', value: 21},
{key: '10pm', value: 22},
{key: '11pm', value: 23},
{key: '12am', value: 0}
];
var minutes = [
{key: '00', value: 00},
{key: '05', value: 05},
{key: '10', value: 10},
{key: '15', value: 15},
{key: '20', value: 20},
{key: '25', value: 25},
{key: '30', value: 30},
{key: '35', value: 35},
{key: '40', value: 40},
{key: '45', value: 45},
{key: '50', value: 50},
{key: '55', value: 55}
];
this.slots = [{
text: 'Month',
name: 'month',
align: 'left',
items: months
},{
text: 'Day',
name: 'day',
align: 'center',
items: days
},{
text: 'Year',
name: 'year',
align: 'right',
items: years
},{
text: 'Hour',
name: 'hour',
align: 'left',
items: hours
}, {
text: 'Minute',
name: 'minute',
align: 'left',
items: minutes
}
];
Ext.DatePicker.superclass.initComponent.call(this);
this.on('pick', this.onPick, this);
},
getValue: function() {
var v = Ext.DatePicker.superclass.getValue.call(this),
day,
daysInMonth = this.getDaysInMonth(v.month, v.year);
if (v.day !== "") {
day = Math.min(v.day, daysInMonth);
} else {
day = daysInMonth;
var dv = this.items.itemAt(1),
idx = dv.store.find(this.valueField, daysInMonth),
r = dv.store.getAt(idx),
n = dv.getNode(r);
this.scrollToNode(dv, n);
}
return new Date(v.year, v.month, day, v.hour, v.minute);
}
});