fineui是帆软报表和BI产品线所使用的前端框架。
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

163 lines
4.8 KiB

7 years ago
/**
* Created by GUY on 2015/9/7.
* @class BI.DatePicker
* @extends BI.Widget
*/
BI.DatePicker = BI.inherit(BI.Widget, {
_defaultConfig: function () {
var conf = BI.DatePicker.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, {
baseCls: "bi-date-picker",
height: 40,
7 years ago
min: "1900-01-01", // 最小日期
max: "2099-12-31" // 最大日期
});
7 years ago
},
_init: function () {
BI.DatePicker.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this._year = BI.getDate().getFullYear();
this._month = BI.getDate().getMonth() + 1;
7 years ago
this.left = BI.createWidget({
type: "bi.icon_button",
cls: "pre-page-h-font",
width: 24,
height: 24
7 years ago
});
this.left.on(BI.IconButton.EVENT_CHANGE, function () {
if (self._month === 1) {
7 years ago
self.setValue({
year: self.year.getValue() - 1,
month: 12
7 years ago
});
7 years ago
} else {
self.setValue({
year: self.year.getValue(),
month: self.month.getValue() - 1
7 years ago
});
7 years ago
}
self.fireEvent(BI.DatePicker.EVENT_CHANGE);
7 years ago
self._checkLeftValid();
self._checkRightValid();
7 years ago
});
this.right = BI.createWidget({
type: "bi.icon_button",
cls: "next-page-h-font",
width: 24,
height: 24
7 years ago
});
this.right.on(BI.IconButton.EVENT_CHANGE, function () {
if (self._month === 12) {
7 years ago
self.setValue({
year: self.year.getValue() + 1,
month: 1
7 years ago
});
7 years ago
} else {
self.setValue({
year: self.year.getValue(),
month: self.month.getValue() + 1
7 years ago
});
7 years ago
}
self.fireEvent(BI.DatePicker.EVENT_CHANGE);
7 years ago
self._checkLeftValid();
self._checkRightValid();
7 years ago
});
this.year = BI.createWidget({
type: "bi.year_date_combo",
behaviors: o.behaviors,
7 years ago
min: o.min,
max: o.max
});
this.year.on(BI.YearDateCombo.EVENT_CHANGE, function () {
self.setValue({
year: self.year.getValue(),
month: self.month.getValue()
});
self.fireEvent(BI.DatePicker.EVENT_CHANGE);
7 years ago
});
7 years ago
this.month = BI.createWidget({
type: "bi.month_date_combo",
behaviors: o.behaviors
7 years ago
});
this.month.on(BI.MonthDateCombo.EVENT_CHANGE, function () {
self.setValue({
year: self.year.getValue(),
month: self.month.getValue()
});
self.fireEvent(BI.DatePicker.EVENT_CHANGE);
});
BI.createWidget({
type: "bi.htape",
7 years ago
element: this,
7 years ago
items: [{
el: {
type: "bi.center_adapt",
items: [this.left]
},
width: 24
7 years ago
}, {
type: "bi.center_adapt",
items: [{
el: {
type: "bi.horizontal",
width: 120,
rgap: 10,
items: [{
el: this.year,
lgap: 10
}, this.month]
}
7 years ago
}]
}, {
el: {
type: "bi.center_adapt",
items: [this.right]
},
width: 24
7 years ago
}]
7 years ago
});
7 years ago
this.setValue({
year: this._year,
month: this._month
7 years ago
});
7 years ago
},
7 years ago
_checkLeftValid: function () {
var o = this.options;
var valid = !(this._month === 1 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear());
7 years ago
this.left.setEnable(valid);
return valid;
},
_checkRightValid: function () {
var o = this.options;
var valid = !(this._month === 12 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear());
7 years ago
this.right.setEnable(valid);
return valid;
},
7 years ago
setValue: function (ob) {
this._year = BI.parseInt(ob.year);
this._month = BI.parseInt(ob.month);
7 years ago
this.year.setValue(ob.year);
this.month.setValue(ob.month);
7 years ago
this._checkLeftValid();
this._checkRightValid();
7 years ago
},
getValue: function () {
return {
year: this.year.getValue(),
month: this.month.getValue()
7 years ago
};
7 years ago
}
});
7 years ago
BI.DatePicker.EVENT_CHANGE = "EVENT_CHANGE";
7 years ago
BI.shortcut("bi.date_picker", BI.DatePicker);