//覆盖 Ext.picker.Date
Ext.define('BSS.view.product.option.DatePicker', {
extend: 'Ext.picker.Date',
requires: [],
config:{
offSeasonDate:[],
busySeasonDate:[]
},
/**
* Update the contents of the picker for a new month
* @private
* @param {Date} date The new date
*/
fullUpdate: function(date) {
var me = this,
cells = me.cells.elements,
textNodes = me.textNodes,
disabledCls = me.disabledCellCls,
eDate = Ext.Date,
i = 0,
extraDays = 0,
newDate = +eDate.clearTime(date, true),
today = +eDate.clearTime(new Date()),
min = me.minDate ? eDate.clearTime(me.minDate, true) : Number.NEGATIVE_INFINITY,
max = me.maxDate ? eDate.clearTime(me.maxDate, true) : Number.POSITIVE_INFINITY,
ddMatch = me.disabledDatesRE,
ddText = me.disabledDatesText,
ddays = me.disabledDays ? me.disabledDays.join('') : false,
ddaysText = me.disabledDaysText,
format = me.format,
days = eDate.getDaysInMonth(date),
firstOfMonth = eDate.getFirstDateOfMonth(date),
startingPos = firstOfMonth.getDay() - me.startDay,
previousMonth = eDate.add(date, eDate.MONTH, -1),
ariaTitleDateFormat = me.ariaTitleDateFormat,
prevStart, current, disableToday, tempDate, setCellClass, html, cls,
formatValue, value,
offSeasonDate = me.offSeasonDate,
busySeasonDate = me.busySeasonDate;
if (startingPos < 0) {
startingPos += 7;
}
days += startingPos;
prevStart = eDate.getDaysInMonth(previousMonth) - startingPos;
current = new Date(previousMonth.getFullYear(), previousMonth.getMonth(), prevStart, me.initHour);
if (me.showToday) {
tempDate = eDate.clearTime(new Date());
disableToday = (tempDate < min || tempDate > max ||
(ddMatch && format && ddMatch.test(eDate.dateFormat(tempDate, format))) ||
(ddays && ddays.indexOf(tempDate.getDay()) != -1));
if (!me.disabled) {
me.todayBtn.setDisabled(disableToday);
}
}
setCellClass = function(cellIndex, cls){
var cell = cells[cellIndex];
value = +eDate.clearTime(current, true);
cell.setAttribute('aria-label', eDate.format(current, ariaTitleDateFormat));
// store dateValue number as an expando
cell.firstChild.dateValue = value;
if (value == today) {
cls += ' ' + me.todayCls;
cell.firstChild.title = me.todayText;
// Extra element for ARIA purposes
me.todayElSpan = Ext.DomHelper.append(cell.firstChild, {
tag: 'span',
cls: Ext.baseCSSPrefix + 'hidden-clip',
html: me.todayText
}, true);
}
if (value == newDate) {
me.activeCell = cell;
me.eventEl.dom.setAttribute('aria-activedescendant', cell.id);
cell.setAttribute('aria-selected', true);
cls += ' ' + me.selectedCls;
me.fireEvent('highlightitem', me, cell);
} else {
cell.setAttribute('aria-selected', false);
}
if (value < min) {
cls += ' ' + disabledCls;
cell.setAttribute('aria-label', me.minText);
}
else if (value > max) {
cls += ' ' + disabledCls;
cell.setAttribute('aria-label', me.maxText);
}
else if (ddays && ddays.indexOf(current.getDay()) !== -1){
cell.setAttribute('aria-label', ddaysText);
cls += ' ' + disabledCls;
}
else if (ddMatch && format){
formatValue = eDate.dateFormat(current, format);
if(ddMatch.test(formatValue)){
cell.setAttribute('aria-label', ddText.replace('%0', formatValue));
cls += ' ' + disabledCls;
}
}
var valueDateString = Ext.Date.format(new Date(value), 'Y-m-d');
设置淡季高亮时间
for(var j=0;j<offSeasonDate.length;j++){
if(Ext.Date.format(new Date(offSeasonDate[j]), 'Y-m-d') == valueDateString){
cls += ' ' + ‘off-season-date';
break;
}
}
//设置旺季高亮时间
for(var j=0;j<busySeasonDate.length;j++){
if(Ext.Date.format(new Date(busySeasonDate[j]), 'Y-m-d') == valueDateString){
cls += ' ' + ‘busy-season-date';
break;
}
}
cell.className = cls + ' ' + me.cellCls;
};
for(; i < me.numDays; ++i) {
if (i < startingPos) {
html = (++prevStart);
cls = me.prevCls;
} else if (i >= days) {
html = (++extraDays);
cls = me.nextCls;
} else {
html = i - startingPos + 1;
cls = me.activeCls;
}
textNodes[i].innerHTML = html;
current.setDate(current.getDate() + 1);
setCellClass(i, cls);
}
me.monthBtn.setText(Ext.Date.format(date, me.monthYearFormat));
}
});
//创建datepicker插件
{
xtype: 'datefield',
name: 'date',
minValue:new Date(),
value: new Date(),
format: 'Y-m-d',
padding:'0 15 0 0',
pickerAlign:'br-l?',
createPicker:function(){
var me = this,
format = Ext.String.format;
var availableDates = me.up("product-option-main").getViewModel().get("availableDates");
// Create floating Picker BoundList. It will acquire a floatParent by looking up
// its ancestor hierarchy (Pickers use their pickerField property as an upward link)
// for a floating component.
return Ext.create('BSS.view.product.option.DatePicker',{
pickerField: me,
floating: true,
preventRefocus: true,
hidden: true,
minDate: me.minValue,
maxDate: me.maxValue,
disabledDatesRE: me.disabledDatesRE,
disabledDatesText: me.disabledDatesText,
ariaDisabledDatesText: me.ariaDisabledDatesText,
disabledDays: me.disabledDays,
disabledDaysText: me.disabledDaysText,
ariaDisabledDaysText: me.ariaDisabledDaysText,
format: me.format,
showToday: me.showToday,
startDay: me.startDay,
minText: format(me.minText, me.formatDate(me.minValue)),
ariaMinText: format(me.ariaMinText, me.formatDate(me.minValue, me.ariaFormat)),
maxText: format(me.maxText, me.formatDate(me.maxValue)),
ariaMaxText: format(me.ariaMaxText, me.formatDate(me.maxValue, me.ariaFormat)),
listeners: {
scope: me,
select: me.onSelect
},
keyNavConfig: {
esc: function() {
me.inputEl.focus();
me.collapse();
}
},
offSeasonDate:offSeasonDate,
busySeasonDate:busySeasonDate
});
}
}
Ext.Ajax.request({
url: 'systemfunction/airlineCode/' + airlineCode,
timeout: 60000, method: 'POST', headers: {'Content-Type': 'application/json'}, success: function (res) { var result = Ext.util.JSON.decode(res.responseText); if (result.success) { var flowModel = result.data; me.flowEditView(flowModel); } else { //Ext.Msg.alert({ // title:me.getView().COMMIT_FAILED, // msg: result.msg, // buttons: Ext.Msg.OK, // icon: Ext.Msg.WARNING //}); } }, failure: function (res) { //Ext.Msg.alert({ // title: view.NETWORK_CONNECTION_FAILURE, // msg: res.responseText, // buttons: Ext.Msg.OK, // icon: Ext.Msg.WARNING //});
}
})