Browse Source

Pull request #1731: BI-79930 日期类型控件全系列可设置最大最小日期

Merge in VISUAL/fineui from ~WINDY/fui:master to master

* commit 'e4c64fe83df059d0ae4b753bd2e24a6b587e5c8d':
  BI-79930 日期类型控件全系列可设置最大最小日期
es6
windy 4 years ago
parent
commit
28d9a4b9e1
  1. 1
      changelog.md
  2. 6
      i18n/i18n.cn.js
  3. 6
      src/core/platform/web/dom.js
  4. 30
      src/widget/datepane/card.static.datepane.js
  5. 17
      src/widget/datepane/datepane.js
  6. 30
      src/widget/datetimepane/card.static.datetimepane.js
  7. 16
      src/widget/datetimepane/datetimepane.js
  8. 97
      src/widget/dynamicdate/dynamicdate.card.js
  9. 21
      src/widget/dynamicdate/dynamicdate.param.item.js
  10. 8
      src/widget/dynamicdate/dynamicdate.popup.js
  11. 2
      src/widget/dynamicdatetime/dynamicdatetime.combo.js
  12. 4
      src/widget/dynamicdatetime/dynamicdatetime.popup.js
  13. 17
      src/widget/timeinterval/dateinterval.js
  14. 17
      src/widget/timeinterval/timeinterval.js
  15. 32
      src/widget/year/card.dynamic.year.js
  16. 32
      src/widget/year/card.year.js
  17. 28
      src/widget/year/combo.year.js
  18. 18
      src/widget/year/popup.year.js
  19. 12
      src/widget/year/trigger.year.js
  20. 50
      src/widget/yearmonth/card.dynamic.yearmonth.js
  21. 1
      src/widget/yearmonth/card.static.yearmonth.js
  22. 16
      src/widget/yearmonth/combo.yearmonth.js
  23. 8
      src/widget/yearmonth/popup.yearmonth.js
  24. 14
      src/widget/yearmonth/trigger.yearmonth.js
  25. 17
      src/widget/yearmonthinterval/yearmonthinterval.js
  26. 50
      src/widget/yearquarter/card.dynamic.yearquarter.js
  27. 42
      src/widget/yearquarter/card.static.yearquarter.js
  28. 28
      src/widget/yearquarter/combo.yearquarter.js
  29. 18
      src/widget/yearquarter/popup.yearquarter.js
  30. 14
      src/widget/yearquarter/trigger.yearquarter.js

1
changelog.md

@ -1,5 +1,6 @@
# 更新日志
2.0(2021-01)
- 日期类型控件全系列可设置最大最小日期
- 调整了combo的popup显示位置计算逻辑
2.0(2020-12)

6
i18n/i18n.cn.js

@ -189,5 +189,9 @@ BI.i18n = {
"BI-Basic_Quarter": "季度",
"BI-Basic_No_Select": "不选",
"BI-Basic_Now": "此刻",
"BI-Color_Picker_Error_Text_Hex": "请输入6位16进制颜色编号"
"BI-Color_Picker_Error_Text_Hex": "请输入6位16进制颜色编号",
"BI-Basic_Date_Range_Error": "请选择{R1}年{R2}月{R3}日-{R4}年{R5}月{R6}日的日期",
"BI-Basic_Year_Range_Error": "请选择{R1}年-{R2}年的日期",
"BI-Basic_Year_Month_Range_Error": "请选择{R1}年{R2}月-{R3}年{R4}月的日期",
"BI-Basic_Year_Quarter_Range_Error": "请选择{R1}年{R2}季度-{R3}年{R4}季度的日期",
};

6
src/core/platform/web/dom.js

@ -659,7 +659,7 @@
} else {
pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight);
}
pos.dir = "right" + pos.dir;
pos.dir = "right," + pos.dir;
if (tbFirst) {
pos.change = "right";
}
@ -721,7 +721,7 @@
} else {
pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight);
}
pos.dir = "innerLeft" + pos.dir;
pos.dir = "innerLeft," + pos.dir;
if (tbFirst) {
pos.change = "innerLeft";
}
@ -741,7 +741,7 @@
} else {
pos = BI.DOM.getBottomAlignPosition(combo, popup, tH, needAdaptHeight);
}
pos.dir = "innerLeft" + pos.dir;
pos.dir = "innerLeft," + pos.dir;
if (tbFirst) {
pos.change = "innerRight";
}

30
src/widget/datepane/card.static.datepane.js

@ -141,6 +141,36 @@ BI.StaticDatePaneCard = BI.inherit(BI.Widget, {
}
},
_checkMin: function () {
var o = this.options;
BI.each(this.calendar.getAllCard(), function (idx, calendar) {
calendar.setMinDate(o.min);
});
},
_checkMax: function () {
var o = this.options;
BI.each(this.calendar.getAllCard(), function (idx, calendar) {
calendar.setMaxDate(o.max);
});
},
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
this.datePicker.setMinDate(minDate);
this._checkMin();
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
this.datePicker.setMaxDate(maxDate);
this._checkMax();
}
},
setValue: function (timeOb) {
this._setDatePicker(timeOb);
this._setCalendar(timeOb);

17
src/widget/datepane/datepane.js

@ -63,6 +63,8 @@ BI.DynamicDatePane = BI.inherit(BI.Widget, {
case BI.DynamicDatePane.Static:
return {
type: "bi.static_date_pane_card",
min: o.minDate,
max: o.maxDate,
behaviors: o.behaviors,
listeners: [{
eventName: "EVENT_CHANGE",
@ -119,6 +121,21 @@ BI.DynamicDatePane = BI.inherit(BI.Widget, {
}
},
setMinDate: function (minDate) {
if (this.options.minDate !== minDate) {
this.options.minDate = minDate;
this.ymd.setMinDate(minDate);
}
},
setMaxDate: function (maxDate) {
if (this.options.maxDate !== maxDate) {
this.options.maxDate = maxDate;
this.ymd.setMaxDate(maxDate);
}
},
setValue: function (v) {
v = v || {};
var type = v.type || BI.DynamicDateCombo.Static;

30
src/widget/datetimepane/card.static.datetimepane.js

@ -155,6 +155,36 @@ BI.StaticDateTimePaneCard = BI.inherit(BI.Widget, {
}
},
_checkMin: function () {
var o = this.options;
BI.each(this.calendar.getAllCard(), function (idx, calendar) {
calendar.setMinDate(o.min);
});
},
_checkMax: function () {
var o = this.options;
BI.each(this.calendar.getAllCard(), function (idx, calendar) {
calendar.setMaxDate(o.max);
});
},
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
this.datePicker.setMinDate(minDate);
this._checkMin();
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
this.datePicker.setMaxDate(maxDate);
this._checkMax();
}
},
setValue: function (timeOb) {
timeOb = timeOb || {};
this._setDatePicker(timeOb);

16
src/widget/datetimepane/datetimepane.js

@ -62,6 +62,8 @@ BI.DynamicDateTimePane = BI.inherit(BI.Widget, {
case BI.DynamicDateTimePane.Static:
return {
type: "bi.static_date_time_pane_card",
min: o.minDate,
max: o.maxDate,
behaviors: o.behaviors,
listeners: [{
eventName: "EVENT_CHANGE",
@ -118,6 +120,20 @@ BI.DynamicDateTimePane = BI.inherit(BI.Widget, {
}
},
setMinDate: function (minDate) {
if (this.options.minDate !== minDate) {
this.options.minDate = minDate;
this.ymd.setMinDate(minDate);
}
},
setMaxDate: function (maxDate) {
if (this.options.maxDate !== maxDate) {
this.options.maxDate = maxDate;
this.ymd.setMaxDate(maxDate);
}
},
setValue: function (v) {
v = v || {};
var type = v.type || BI.DynamicDateTimePane.Static;

97
src/widget/dynamicdate/dynamicdate.card.js

@ -134,11 +134,24 @@ BI.DynamicDateCard = BI.inherit(BI.Widget, {
},
_getParamJson: function (values, positionValue) {
var self = this;
var self = this, o = this.options;
var items = BI.map(values, function (idx, value) {
return {
el: {
type: "bi.dynamic_date_param_item",
validationChecker: BI.bind(self._checkDate, self),
errorText: function () {
var start = BI.parseDateTime(o.min, "%Y-%X-%d");
var end = BI.parseDateTime(o.max, "%Y-%X-%d");
return BI.i18nText("BI-Basic_Date_Range_Error",
start.getFullYear(),
start.getMonth() + 1,
start.getDate(),
end.getFullYear(),
end.getMonth() + 1,
end.getDate()
);
},
dateType: value.dateType,
value: value.value,
offset: value.offset,
@ -165,7 +178,7 @@ BI.DynamicDateCard = BI.inherit(BI.Widget, {
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
self.position = this.getValue()[0];
this.setValue(self._checkPositionValue(this.getValue()[0]));
self.fireEvent("EVENT_CHANGE");
}
}]
@ -181,7 +194,7 @@ BI.DynamicDateCard = BI.inherit(BI.Widget, {
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
self.position = this.getValue()[0];
this.setValue(self._checkPositionValue(this.getValue()[0]));
self.fireEvent("EVENT_CHANGE");
}
}]
@ -193,6 +206,22 @@ BI.DynamicDateCard = BI.inherit(BI.Widget, {
return items;
},
_checkPositionValue: function (v) {
var lastPosition = this.position;
this.position = v;
if (!this._checkDate({})) {
this.position = lastPosition;
}
return this.position;
},
_checkDate: function (obj) {
var o = this.options;
var date = BI.DynamicDateHelper.getCalculation(BI.extend(this.getValue(), this._digestDateTypeValue(obj)));
return !BI.checkDateVoid(date.getFullYear(), date.getMonth() + 1, date.getDate(), o.min, o.max)[0];
},
_getText: function (lastValue) {
switch (lastValue) {
case BI.DynamicDateCard.TYPE.YEAR:
@ -251,6 +280,45 @@ BI.DynamicDateCard = BI.inherit(BI.Widget, {
};
},
_digestDateTypeValue: function (value) {
var valueMap = {};
switch (value.dateType) {
case BI.DynamicDateCard.TYPE.YEAR:
valueMap.year = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.QUARTER:
valueMap.quarter = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.MONTH:
valueMap.month = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.WEEK:
valueMap.week = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.DAY:
valueMap.day = (value.offset === 0 ? -value.value : value.value);
break;
default:
break;
}
if(BI.isNull(value.dateType)) {
valueMap.position = self.position || BI.DynamicDateCard.OFFSET.CURRENT;
}
return valueMap;
},
setMinDate: function(minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
setValue: function (v) {
v = v || {};
this.position = v.position || BI.DynamicDateCard.OFFSET.CURRENT;
@ -293,28 +361,7 @@ BI.DynamicDateCard = BI.inherit(BI.Widget, {
if(selectValues.length !== 0) {
BI.each(buttons, function (idx, button) {
var value = button.getValue();
switch (value.dateType) {
case BI.DynamicDateCard.TYPE.YEAR:
valueMap.year = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.QUARTER:
valueMap.quarter = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.MONTH:
valueMap.month = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.WEEK:
valueMap.week = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.DAY:
valueMap.day = (value.offset === 0 ? -value.value : value.value);
break;
default:
break;
}
if(BI.isNull(value.dateType)) {
valueMap.position = self.position || BI.DynamicDateCard.OFFSET.CURRENT;
}
BI.extend(valueMap, self._digestDateTypeValue(value));
});
}
if(this.workDayBox.isSelected()) {

21
src/widget/dynamicdate/dynamicdate.param.item.js

@ -3,6 +3,12 @@ BI.DynamicDateParamItem = BI.inherit(BI.Widget, {
props: {
baseCls: "bi-dynamic-date-param-item",
dateType: BI.DynamicDateCard.TYPE.YEAR,
validationChecker: function() {
return true;
},
errorText: function () {
return BI.i18nText("BI-Please_Input_Natural_Number");
},
value: 0,
offset: 0,
height: 24
@ -18,17 +24,23 @@ BI.DynamicDateParamItem = BI.inherit(BI.Widget, {
cls: "bi-border",
height: 22,
validationChecker: function (v) {
return BI.isNaturalNumber(v);
return BI.isNaturalNumber(v) && o.validationChecker(BI.extend({}, self.getValue(), {
value: v
}));
},
value: o.value,
ref: function () {
self.editor = this;
},
errorText: function (v) {
if(BI.isEmptyString(v)) {
if (BI.isEmptyString(v)) {
return BI.i18nText("BI-Basic_Please_Input_Content");
}
return BI.i18nText("BI-Please_Input_Natural_Number");
if (!BI.isNumeric(v)) {
return BI.i18nText("BI-Please_Input_Natural_Number");
}
return o.errorText(v);
},
allowBlank: false,
listeners: [{
@ -64,6 +76,9 @@ BI.DynamicDateParamItem = BI.inherit(BI.Widget, {
listeners: [{
eventName: BI.TextValueCombo.EVENT_CHANGE,
action: function () {
if (!o.validationChecker(self.getValue())) {
self.editor.setValue(0);
}
self.fireEvent(BI.DynamicDateParamItem.EVENT_CHANGE);
}
}]

8
src/widget/dynamicdate/dynamicdate.popup.js

@ -101,6 +101,8 @@ BI.DynamicDatePopup = BI.inherit(BI.Widget, {
self._setInnerValue(self.year, v);
}
}],
min: self.options.min,
max: self.options.max,
ref: function () {
self.dynamicPane = this;
}
@ -179,14 +181,16 @@ BI.DynamicDatePopup = BI.inherit(BI.Widget, {
setMinDate: function (minDate) {
if (this.options.min !== minDate) {
this.options.min = minDate;
this.ymd.setMinDate(minDate);
this.ymd && this.ymd.setMinDate(minDate);
this.dynamicPane && this.ymd.setMinDate(minDate);
}
},
setMaxDate: function (maxDate) {
if (this.options.max !== maxDate) {
this.options.max = maxDate;
this.ymd.setMaxDate(maxDate);
this.ymd && this.ymd.setMaxDate(maxDate);
this.dynamicPane && this.ymd.setMaxDate(maxDate);
}
},

2
src/widget/dynamicdatetime/dynamicdatetime.combo.js

@ -199,9 +199,9 @@ BI.DynamicDateTimeCombo = BI.inherit(BI.Single, {
listeners: [{
eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW,
action: function () {
self.popup.setValue(self.storeValue);
self.popup.setMinDate(opts.minDate);
self.popup.setMaxDate(opts.maxDate);
self.popup.setValue(self.storeValue);
self.fireEvent(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW);
}
}],

4
src/widget/dynamicdatetime/dynamicdatetime.popup.js

@ -103,7 +103,9 @@ BI.DynamicDateTimePopup = BI.inherit(BI.Widget, {
}],
ref: function () {
self.dynamicPane = this;
}
},
min: self.options.min,
max: self.options.max,
};
case BI.DynamicDateCombo.Static:
default:

17
src/widget/timeinterval/dateinterval.js

@ -68,6 +68,8 @@ BI.DateInterval = BI.inherit(BI.Single, {
var self = this, o = this.options;
var combo = BI.createWidget({
type: "bi.dynamic_date_combo",
minDate: o.minDate,
maxDate: o.maxDate,
behaviors: o.behaviors,
value: v,
height: o.height,
@ -174,6 +176,21 @@ BI.DateInterval = BI.inherit(BI.Single, {
this.right.setTitle("");
this.label.setTitle("");
},
setMinDate: function (minDate) {
var o = this.options;
o.minDate = minDate;
this.left.setMinDate(minDate);
this.right.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
var o = this.options;
o.maxDate = maxDate;
this.left.setMaxDate(maxDate);
this.right.setMaxDate(maxDate);
},
setValue: function (date) {
date = date || {};
this.left.setValue(date.start);

17
src/widget/timeinterval/timeinterval.js

@ -68,6 +68,8 @@ BI.TimeInterval = BI.inherit(BI.Single, {
var self = this, o = this.options;
var combo = BI.createWidget({
type: "bi.dynamic_date_time_combo",
minDate: o.minDate,
maxDate: o.maxDate,
behaviors: o.behaviors,
value: v,
height: o.height,
@ -169,6 +171,21 @@ BI.TimeInterval = BI.inherit(BI.Single, {
this.right.setTitle("");
this.label.setTitle("");
},
setMinDate: function (minDate) {
var o = this.options;
o.minDate = minDate;
this.left.setMinDate(minDate);
this.right.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
var o = this.options;
o.maxDate = maxDate;
this.left.setMaxDate(maxDate);
this.right.setMaxDate(maxDate);
},
setValue: function (date) {
date = date || {};
this.left.setValue(date.start);

32
src/widget/year/card.dynamic.year.js

@ -12,7 +12,7 @@ BI.DynamicYearCard = BI.inherit(BI.Widget, {
},
render: function () {
var self = this;
var self = this, o = this.options;
return {
type: "bi.vertical",
items: [{
@ -25,6 +25,15 @@ BI.DynamicYearCard = BI.inherit(BI.Widget, {
ref: function () {
self.item = this;
},
validationChecker: BI.bind(self._checkDate, self),
errorText: function () {
var start = BI.parseDateTime(o.min, "%Y-%X-%d");
var end = BI.parseDateTime(o.max, "%Y-%X-%d");
return BI.i18nText("BI-Basic_Year_Range_Error",
start.getFullYear(),
end.getFullYear(),
);
},
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
@ -37,6 +46,15 @@ BI.DynamicYearCard = BI.inherit(BI.Widget, {
};
},
_checkDate: function (obj) {
var o = this.options;
var date = BI.DynamicDateHelper.getCalculation({
year: (obj.offset === 0 ? -obj.value : obj.value)
});
return !BI.checkDateVoid(date.getFullYear(), date.getMonth() + 1, date.getDate(), o.min, o.max)[0];
},
_createValue: function (type, v) {
return {
dateType: type,
@ -45,6 +63,18 @@ BI.DynamicYearCard = BI.inherit(BI.Widget, {
};
},
setMinDate: function(minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
setValue: function (v) {
v = v || {year: 0};
this.item.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year));

32
src/widget/year/card.year.js

@ -134,6 +134,38 @@ BI.StaticYearCard = BI.inherit(BI.Widget, {
return valid;
},
_checkMin: function () {
var o = this.options;
BI.each(this.navigation.getAllCard(), function (idx, calendar) {
calendar.setMinDate(o.min);
});
},
_checkMax: function () {
var o = this.options;
BI.each(this.navigation.getAllCard(), function (idx, calendar) {
calendar.setMaxDate(o.max);
});
},
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
this._checkLeftValid();
this._checkRightValid();
this._checkMin();
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
this._checkLeftValid();
this._checkRightValid();
this._checkMax();
}
},
getValue: function () {
return {
year: this.selectedYear

28
src/widget/year/combo.year.js

@ -3,8 +3,8 @@ BI.DynamicYearCombo = BI.inherit(BI.Widget, {
props: {
baseCls: "bi-year-combo bi-border bi-border-radius bi-focus-shadow",
behaviors: {},
min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期
minDate: "1900-01-01", // 最小日期
maxDate: "2099-12-31", // 最大日期
height: 22
},
@ -14,8 +14,8 @@ BI.DynamicYearCombo = BI.inherit(BI.Widget, {
this.storeValue = o.value;
this.trigger = BI.createWidget({
type: "bi.dynamic_year_trigger",
min: o.min,
max: o.max,
min: o.minDate,
max: o.maxDate,
height: o.height,
value: o.value || ""
});
@ -96,13 +96,15 @@ BI.DynamicYearCombo = BI.inherit(BI.Widget, {
}
}],
behaviors: o.behaviors,
min: o.min,
max: o.max
min: o.minDate,
max: o.maxDate
},
value: o.value || ""
}
});
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () {
self.popup.setMinDate(o.minDate);
self.popup.setMaxDate(o.maxDate);
self.popup.setValue(self.storeValue);
self.fireEvent(BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW);
});
@ -148,6 +150,20 @@ BI.DynamicYearCombo = BI.inherit(BI.Widget, {
}
},
setMinDate: function (minDate) {
var o = this.options;
o.minDate = minDate;
this.trigger.setMinDate(minDate);
this.popup && this.popup.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
var o = this.options;
o.maxDate = maxDate;
this.trigger.setMaxDate(maxDate);
this.popup && this.popup.setMaxDate(maxDate);
},
setValue: function (v) {
this.storeValue = v;
this.trigger.setValue(v);

18
src/widget/year/popup.year.js

@ -114,6 +114,8 @@ BI.DynamicYearPopup = BI.inherit(BI.Widget, {
case BI.DynamicYearCombo.Dynamic:
return {
type: "bi.dynamic_year_card",
min: self.options.min,
max: self.options.max,
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
@ -170,6 +172,22 @@ BI.DynamicYearPopup = BI.inherit(BI.Widget, {
};
},
setMinDate: function (minDate) {
if (this.options.min !== minDate) {
this.options.min = minDate;
this.year && this.year.setMinDate(minDate);
this.dynamicPane && this.dynamicPane.setMinDate(minDate);
}
},
setMaxDate: function (maxDate) {
if (this.options.max !== maxDate) {
this.options.max = maxDate;
this.year && this.year.setMaxDate(maxDate);
this.dynamicPane && this.dynamicPane.setMaxDate(maxDate);
}
},
setValue: function (v) {
this.storeValue = v;
var self = this;

12
src/widget/year/trigger.year.js

@ -157,6 +157,18 @@ BI.DynamicYearTrigger = BI.inherit(BI.Trigger, {
}
},
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
getValue: function () {
return this.storeValue;
},

50
src/widget/yearmonth/card.dynamic.yearmonth.js

@ -22,6 +22,8 @@ BI.DynamicYearMonthCard = BI.inherit(BI.Widget, {
height: 24
}, {
type: "bi.dynamic_date_param_item",
validationChecker: BI.bind(self._checkDate, self),
errorText: BI.bind(this._errorTextGetter, this),
ref: function () {
self.year = this;
},
@ -33,6 +35,8 @@ BI.DynamicYearMonthCard = BI.inherit(BI.Widget, {
}]
}, {
type: "bi.dynamic_date_param_item",
validationChecker: BI.bind(self._checkDate, self),
errorText: BI.bind(this._errorTextGetter, this),
dateType: BI.DynamicDateCard.TYPE.MONTH,
ref: function () {
self.month = this;
@ -49,6 +53,40 @@ BI.DynamicYearMonthCard = BI.inherit(BI.Widget, {
};
},
_errorTextGetter: function () {
var o = this.options;
var start = BI.parseDateTime(o.min, "%Y-%X-%d");
var end = BI.parseDateTime(o.max, "%Y-%X-%d");
return BI.i18nText("BI-Basic_Year_Month_Range_Error",
start.getFullYear(),
start.getMonth() + 1,
end.getFullYear(),
end.getMonth() + 1,
);
},
_checkDate: function (obj) {
var o = this.options;
var date = BI.DynamicDateHelper.getCalculation(BI.extend(this.getValue(), this._digestDateTypeValue(obj)));
return !BI.checkDateVoid(date.getFullYear(), date.getMonth() + 1, date.getDate(), o.min, o.max)[0];
},
_digestDateTypeValue: function (value) {
var valueMap = {};
switch (value.dateType) {
case BI.DynamicDateCard.TYPE.YEAR:
valueMap.year = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.MONTH:
valueMap.month = (value.offset === 0 ? -value.value : value.value);
break;
default:
break;
}
return valueMap;
},
_createValue: function (type, v) {
return {
dateType: type,
@ -57,6 +95,18 @@ BI.DynamicYearMonthCard = BI.inherit(BI.Widget, {
};
},
setMinDate: function(minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
setValue: function (v) {
v = v || {year: 0, month: 0};
this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year));

1
src/widget/yearmonth/card.static.yearmonth.js

@ -153,6 +153,7 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, {
this.yearPicker.setValue(this.selectedYear);
this.month.setValue(this.selectedMonth);
}
this._checkMonthStatus(this.selectedYear);
}
});
BI.StaticYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE";

16
src/widget/yearmonth/combo.yearmonth.js

@ -107,6 +107,8 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Single, {
}
});
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () {
self.popup.setMinDate(o.minDate);
self.popup.setMaxDate(o.maxDate);
self.popup.setValue(self.storeValue);
self.fireEvent(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW);
});
@ -152,6 +154,20 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Single, {
}
},
setMinDate: function (minDate) {
var o = this.options;
o.minDate = minDate;
this.trigger.setMinDate(minDate);
this.popup && this.popup.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
var o = this.options;
o.maxDate = maxDate;
this.trigger.setMaxDate(maxDate);
this.popup && this.popup.setMaxDate(maxDate);
},
hideView: function () {
this.combo.hideView();
},

8
src/widget/yearmonth/popup.yearmonth.js

@ -114,6 +114,8 @@ BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, {
case BI.DynamicYearCombo.Dynamic:
return {
type: "bi.dynamic_year_month_card",
min: self.options.min,
max: self.options.max,
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
@ -173,14 +175,16 @@ BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, {
setMinDate: function (minDate) {
if (this.options.min !== minDate) {
this.options.min = minDate;
this.year.setMinDate(minDate);
this.year && this.year.setMinDate(minDate);
this.dynamicPane && this.dynamicPane.setMinDate(minDate);
}
},
setMaxDate: function (maxDate) {
if (this.options.max !== maxDate) {
this.options.max = maxDate;
this.year.setMaxDate(maxDate);
this.year && this.year.setMaxDate(maxDate);
this.dynamicPane && this.dynamicPane.setMaxDate(maxDate);
}
},

14
src/widget/yearmonth/trigger.yearmonth.js

@ -71,7 +71,7 @@ BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, {
return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, parseInt(v, 10) === minDate.getFullYear() ? minDate.getMonth() + 1 : 1, 1, o.min, o.max)[0]);
}
return v === "" || ((BI.isPositiveInteger(v) && v >= 1 && v <= 12) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]);
return v === "" || ((BI.isPositiveInteger(v) && v >= 1 && v <= 12) && !BI.checkDateVoid(self.yearEditor.getValue(), v, 1, o.min, o.max)[0]);
},
quitChecker: function () {
return false;
@ -215,6 +215,18 @@ BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, {
}
},
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
setValue: function (v) {
var type, value;
var date = BI.getDate();

17
src/widget/yearmonthinterval/yearmonthinterval.js

@ -64,6 +64,8 @@ BI.YearMonthInterval = BI.inherit(BI.Single, {
var self = this, o = this.options;
var combo = BI.createWidget({
type: "bi.dynamic_year_month_combo",
minDate: o.minDate,
maxDate: o.maxDate,
behaviors: o.behaviors,
value: v,
listeners: [{
@ -174,6 +176,21 @@ BI.YearMonthInterval = BI.inherit(BI.Single, {
self.element.removeClass(self.constants.timeErrorCls);
}
},
setMinDate: function (minDate) {
var o = this.options;
o.minDate = minDate;
this.left.setMinDate(minDate);
this.right.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
var o = this.options;
o.maxDate = maxDate;
this.left.setMaxDate(maxDate);
this.right.setMaxDate(maxDate);
},
setValue: function (date) {
date = date || {};
this.left.setValue(date.start);

50
src/widget/yearquarter/card.dynamic.yearquarter.js

@ -22,6 +22,8 @@ BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, {
height: 24
}, {
type: "bi.dynamic_date_param_item",
validationChecker: BI.bind(self._checkDate, self),
errorText: BI.bind(this._errorTextGetter, this),
ref: function () {
self.year = this;
},
@ -33,6 +35,8 @@ BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, {
}]
}, {
type: "bi.dynamic_date_param_item",
validationChecker: BI.bind(self._checkDate, self),
errorText: BI.bind(this._errorTextGetter, this),
dateType: BI.DynamicDateCard.TYPE.QUARTER,
ref: function () {
self.quarter = this;
@ -49,6 +53,40 @@ BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, {
};
},
_errorTextGetter: function () {
var o = this.options;
var start = BI.parseDateTime(o.min, "%Y-%X-%d");
var end = BI.parseDateTime(o.max, "%Y-%X-%d");
return BI.i18nText("BI-Basic_Year_Quarter_Range_Error",
start.getFullYear(),
BI.getQuarter(start),
end.getFullYear(),
BI.getQuarter(end),
);
},
_checkDate: function (obj) {
var o = this.options;
var date = BI.DynamicDateHelper.getCalculation(BI.extend(this.getValue(), this._digestDateTypeValue(obj)));
return !BI.checkDateVoid(date.getFullYear(), date.getMonth() + 1, date.getDate(), o.min, o.max)[0];
},
_digestDateTypeValue: function (value) {
var valueMap = {};
switch (value.dateType) {
case BI.DynamicDateCard.TYPE.YEAR:
valueMap.year = (value.offset === 0 ? -value.value : value.value);
break;
case BI.DynamicDateCard.TYPE.MONTH:
valueMap.quarter = (value.offset === 0 ? -value.value : value.value);
break;
default:
break;
}
return valueMap;
},
_createValue: function (type, v) {
return {
dateType: type,
@ -57,6 +95,18 @@ BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, {
};
},
setMinDate: function(minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
setValue: function (v) {
v = v || {year: 0, month: 0};
this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year));

42
src/widget/yearquarter/card.static.yearquarter.js

@ -6,7 +6,7 @@ BI.StaticYearQuarterCard = BI.inherit(BI.Widget, {
},
_createQuarter: function () {
var self = this;
var items = [{
text: BI.Date._QN[1],
value: 1
@ -28,13 +28,17 @@ BI.StaticYearQuarterCard = BI.inherit(BI.Widget, {
whiteSpace: "nowrap",
once: false,
forceSelected: true,
height: 24
height: 24,
ref: function (_ref) {
self.quarterMap[j + 1] = _ref;
}
});
});
},
render: function () {
var self = this, o = this.options;
this.quarterMap = {};
return {
type: "bi.vertical",
items: [{
@ -42,12 +46,15 @@ BI.StaticYearQuarterCard = BI.inherit(BI.Widget, {
ref: function () {
self.yearPicker = this;
},
min: o.min,
max: o.max,
behaviors: o.behaviors,
height: 30,
listeners: [{
eventName: BI.YearPicker.EVENT_CHANGE,
action: function () {
var value = this.getValue();
self._checkQuarterStatus(value);
self.setValue({
year: value,
quarter: self.selectedQuarter
@ -78,6 +85,36 @@ BI.StaticYearQuarterCard = BI.inherit(BI.Widget, {
};
},
_checkQuarterStatus: function (year) {
var o = this.options;
var minDate = BI.parseDateTime(o.min, "%Y-%X-%d"), maxDate = BI.parseDateTime(o.max, "%Y-%X-%d");
var minYear = minDate.getFullYear(), maxYear = maxDate.getFullYear();
var minQuarter = 1; var maxQuarter = 4;
minYear === year && (minQuarter = BI.parseInt(BI.getQuarter(minDate)));
maxYear === year && (maxQuarter = BI.parseInt(BI.getQuarter(maxDate)));
var yearInvalid = year < minYear || year > maxYear;
BI.each(this.quarterMap, function (quarter, obj) {
var quarterInvalid = quarter < minQuarter || quarter > maxQuarter;
obj.setEnable(!yearInvalid && !quarterInvalid);
});
},
setMinDate: function (minDate) {
if (this.options.min !== minDate) {
this.options.min = minDate;
this.yearPicker.setMinDate(minDate);
this._checkQuarterStatus(this.selectedYear);
}
},
setMaxDate: function (maxDate) {
if (this.options.max !== maxDate) {
this.options.max = maxDate;
this.yearPicker.setMaxDate(maxDate);
this._checkQuarterStatus(this.selectedYear);
}
},
getValue: function () {
return {
@ -103,6 +140,7 @@ BI.StaticYearQuarterCard = BI.inherit(BI.Widget, {
this.yearPicker.setValue(this.selectedYear);
this.quarter.setValue(this.selectedQuarter);
}
this._checkQuarterStatus(this.selectedYear);
}
});
BI.StaticYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE";

28
src/widget/yearquarter/combo.yearquarter.js

@ -3,8 +3,8 @@ BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, {
props: {
baseCls: "bi-year-quarter-combo bi-border bi-border-radius bi-focus-shadow",
behaviors: {},
min: "1900-01-01", // 最小日期
max: "2099-12-31", // 最大日期
minDate: "1900-01-01", // 最小日期
maxDate: "2099-12-31", // 最大日期
height: 22
},
@ -15,8 +15,8 @@ BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, {
self.storeTriggerValue = "";
this.trigger = BI.createWidget({
type: "bi.dynamic_year_quarter_trigger",
min: o.min,
max: o.max,
min: o.minDate,
max: o.maxDate,
height: o.height,
value: o.value || ""
});
@ -95,13 +95,15 @@ BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, {
}
}],
behaviors: o.behaviors,
min: o.min,
max: o.max
min: o.minDate,
max: o.maxDate
},
value: o.value || ""
}
});
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () {
self.popup.setMinDate(o.minDate);
self.popup.setMaxDate(o.maxDate);
self.popup.setValue(self.storeValue);
self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW);
});
@ -147,6 +149,20 @@ BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, {
}
},
setMinDate: function (minDate) {
var o = this.options;
o.minDate = minDate;
this.trigger.setMinDate(minDate);
this.popup && this.popup.setMinDate(minDate);
},
setMaxDate: function (maxDate) {
var o = this.options;
o.maxDate = maxDate;
this.trigger.setMaxDate(maxDate);
this.popup && this.popup.setMaxDate(maxDate);
},
setValue: function (v) {
this.storeValue = v;
this.trigger.setValue(v);

18
src/widget/yearquarter/popup.yearquarter.js

@ -107,6 +107,8 @@ BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, {
case BI.DynamicYearQuarterCombo.Dynamic:
return {
type: "bi.dynamic_year_quarter_card",
min: self.options.min,
max: self.options.max,
listeners: [{
eventName: "EVENT_CHANGE",
action: function () {
@ -163,6 +165,22 @@ BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, {
};
},
setMinDate: function (minDate) {
if (this.options.min !== minDate) {
this.options.min = minDate;
this.year && this.year.setMinDate(minDate);
this.dynamicPane && this.dynamicPane.setMinDate(minDate);
}
},
setMaxDate: function (maxDate) {
if (this.options.max !== maxDate) {
this.options.max = maxDate;
this.year && this.year.setMaxDate(maxDate);
this.dynamicPane && this.dynamicPane.setMaxDate(maxDate);
}
},
setValue: function (v) {
this.storeValue = v;
var self = this;

14
src/widget/yearquarter/trigger.yearquarter.js

@ -67,7 +67,7 @@ BI.DynamicYearQuarterTrigger = BI.inherit(BI.Trigger, {
if(isYear) {
return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]);
}
return v === "" || ((BI.isPositiveInteger(v) && v >= 1 && v <= 4) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]);
return v === "" || ((BI.isPositiveInteger(v) && v >= 1 && v <= 4) && !BI.checkDateVoid(self.yearEditor.getValue(), (v - 1) * 3 + 1, 1, o.min, o.max)[0]);
},
quitChecker: function () {
return false;
@ -185,6 +185,18 @@ BI.DynamicYearQuarterTrigger = BI.inherit(BI.Trigger, {
this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr));
},
setMinDate: function (minDate) {
if (BI.isNotEmptyString(this.options.min)) {
this.options.min = minDate;
}
},
setMaxDate: function (maxDate) {
if (BI.isNotEmptyString(this.options.max)) {
this.options.max = maxDate;
}
},
setValue: function (v) {
var type, value;
var date = BI.getDate();

Loading…
Cancel
Save