From e4c64fe83df059d0ae4b753bd2e24a6b587e5c8d Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 7 Jan 2021 19:02:46 +0800 Subject: [PATCH] =?UTF-8?q?BI-79930=20=E6=97=A5=E6=9C=9F=E7=B1=BB=E5=9E=8B?= =?UTF-8?q?=E6=8E=A7=E4=BB=B6=E5=85=A8=E7=B3=BB=E5=88=97=E5=8F=AF=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=9C=80=E5=A4=A7=E6=9C=80=E5=B0=8F=E6=97=A5=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.md | 1 + i18n/i18n.cn.js | 6 +- src/core/platform/web/dom.js | 6 +- src/widget/datepane/card.static.datepane.js | 30 ++++++ src/widget/datepane/datepane.js | 17 ++++ .../datetimepane/card.static.datetimepane.js | 30 ++++++ src/widget/datetimepane/datetimepane.js | 16 +++ src/widget/dynamicdate/dynamicdate.card.js | 97 ++++++++++++++----- .../dynamicdate/dynamicdate.param.item.js | 21 +++- src/widget/dynamicdate/dynamicdate.popup.js | 8 +- .../dynamicdatetime/dynamicdatetime.combo.js | 2 +- .../dynamicdatetime/dynamicdatetime.popup.js | 4 +- src/widget/timeinterval/dateinterval.js | 17 ++++ src/widget/timeinterval/timeinterval.js | 17 ++++ src/widget/year/card.dynamic.year.js | 32 +++++- src/widget/year/card.year.js | 32 ++++++ src/widget/year/combo.year.js | 28 ++++-- src/widget/year/popup.year.js | 18 ++++ src/widget/year/trigger.year.js | 12 +++ .../yearmonth/card.dynamic.yearmonth.js | 50 ++++++++++ src/widget/yearmonth/card.static.yearmonth.js | 1 + src/widget/yearmonth/combo.yearmonth.js | 16 +++ src/widget/yearmonth/popup.yearmonth.js | 8 +- src/widget/yearmonth/trigger.yearmonth.js | 14 ++- .../yearmonthinterval/yearmonthinterval.js | 17 ++++ .../yearquarter/card.dynamic.yearquarter.js | 50 ++++++++++ .../yearquarter/card.static.yearquarter.js | 42 +++++++- src/widget/yearquarter/combo.yearquarter.js | 28 ++++-- src/widget/yearquarter/popup.yearquarter.js | 18 ++++ src/widget/yearquarter/trigger.yearquarter.js | 14 ++- 30 files changed, 597 insertions(+), 55 deletions(-) diff --git a/changelog.md b/changelog.md index a7dbb0565c..1455a9f726 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,6 @@ # 更新日志 2.0(2021-01) +- 日期类型控件全系列可设置最大最小日期 - 调整了combo的popup显示位置计算逻辑 2.0(2020-12) diff --git a/i18n/i18n.cn.js b/i18n/i18n.cn.js index ab83491bca..fca0e61aad 100644 --- a/i18n/i18n.cn.js +++ b/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}季度的日期", }; \ No newline at end of file diff --git a/src/core/platform/web/dom.js b/src/core/platform/web/dom.js index 602d7884a4..98609123ac 100644 --- a/src/core/platform/web/dom.js +++ b/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"; } diff --git a/src/widget/datepane/card.static.datepane.js b/src/widget/datepane/card.static.datepane.js index 1b4a59afaf..34ed5ac14d 100644 --- a/src/widget/datepane/card.static.datepane.js +++ b/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); diff --git a/src/widget/datepane/datepane.js b/src/widget/datepane/datepane.js index ffe4772aa8..52b8beacd5 100644 --- a/src/widget/datepane/datepane.js +++ b/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; diff --git a/src/widget/datetimepane/card.static.datetimepane.js b/src/widget/datetimepane/card.static.datetimepane.js index 67579bbc7f..b63b83c9a4 100644 --- a/src/widget/datetimepane/card.static.datetimepane.js +++ b/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); diff --git a/src/widget/datetimepane/datetimepane.js b/src/widget/datetimepane/datetimepane.js index 21477d72c8..b822b7fb24 100644 --- a/src/widget/datetimepane/datetimepane.js +++ b/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; diff --git a/src/widget/dynamicdate/dynamicdate.card.js b/src/widget/dynamicdate/dynamicdate.card.js index e5448e8359..259e6df515 100644 --- a/src/widget/dynamicdate/dynamicdate.card.js +++ b/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()) { diff --git a/src/widget/dynamicdate/dynamicdate.param.item.js b/src/widget/dynamicdate/dynamicdate.param.item.js index 4b3a68443c..2399568efa 100644 --- a/src/widget/dynamicdate/dynamicdate.param.item.js +++ b/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); } }] diff --git a/src/widget/dynamicdate/dynamicdate.popup.js b/src/widget/dynamicdate/dynamicdate.popup.js index 9d84e7742b..246b6514bd 100644 --- a/src/widget/dynamicdate/dynamicdate.popup.js +++ b/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); } }, diff --git a/src/widget/dynamicdatetime/dynamicdatetime.combo.js b/src/widget/dynamicdatetime/dynamicdatetime.combo.js index dfda4ff8af..9dbc16b081 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.combo.js +++ b/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); } }], diff --git a/src/widget/dynamicdatetime/dynamicdatetime.popup.js b/src/widget/dynamicdatetime/dynamicdatetime.popup.js index 0e3c6d79da..b086e768f3 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.popup.js +++ b/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: diff --git a/src/widget/timeinterval/dateinterval.js b/src/widget/timeinterval/dateinterval.js index 38f080d7ea..d11c46af71 100644 --- a/src/widget/timeinterval/dateinterval.js +++ b/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); diff --git a/src/widget/timeinterval/timeinterval.js b/src/widget/timeinterval/timeinterval.js index 36d980b779..43ee571f00 100644 --- a/src/widget/timeinterval/timeinterval.js +++ b/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); diff --git a/src/widget/year/card.dynamic.year.js b/src/widget/year/card.dynamic.year.js index 102629276c..bc7506137e 100644 --- a/src/widget/year/card.dynamic.year.js +++ b/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)); diff --git a/src/widget/year/card.year.js b/src/widget/year/card.year.js index 4f687bc71d..bc3fe6a587 100644 --- a/src/widget/year/card.year.js +++ b/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 diff --git a/src/widget/year/combo.year.js b/src/widget/year/combo.year.js index a2a757492d..5778694013 100644 --- a/src/widget/year/combo.year.js +++ b/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); diff --git a/src/widget/year/popup.year.js b/src/widget/year/popup.year.js index 0320120188..2be398e5f0 100644 --- a/src/widget/year/popup.year.js +++ b/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; diff --git a/src/widget/year/trigger.year.js b/src/widget/year/trigger.year.js index 84237e41e5..b32ce636ad 100644 --- a/src/widget/year/trigger.year.js +++ b/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; }, diff --git a/src/widget/yearmonth/card.dynamic.yearmonth.js b/src/widget/yearmonth/card.dynamic.yearmonth.js index 983fd84564..cbc41b1b87 100644 --- a/src/widget/yearmonth/card.dynamic.yearmonth.js +++ b/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)); diff --git a/src/widget/yearmonth/card.static.yearmonth.js b/src/widget/yearmonth/card.static.yearmonth.js index 740dcf6d10..4274a923a8 100644 --- a/src/widget/yearmonth/card.static.yearmonth.js +++ b/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"; diff --git a/src/widget/yearmonth/combo.yearmonth.js b/src/widget/yearmonth/combo.yearmonth.js index c82de18136..7b0d596069 100644 --- a/src/widget/yearmonth/combo.yearmonth.js +++ b/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(); }, diff --git a/src/widget/yearmonth/popup.yearmonth.js b/src/widget/yearmonth/popup.yearmonth.js index 6c874b2b3f..f2ffe7164f 100644 --- a/src/widget/yearmonth/popup.yearmonth.js +++ b/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); } }, diff --git a/src/widget/yearmonth/trigger.yearmonth.js b/src/widget/yearmonth/trigger.yearmonth.js index fb947bff51..e6c1f7630f 100644 --- a/src/widget/yearmonth/trigger.yearmonth.js +++ b/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(); diff --git a/src/widget/yearmonthinterval/yearmonthinterval.js b/src/widget/yearmonthinterval/yearmonthinterval.js index 835cbc5e8b..5a5fc436f8 100644 --- a/src/widget/yearmonthinterval/yearmonthinterval.js +++ b/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); diff --git a/src/widget/yearquarter/card.dynamic.yearquarter.js b/src/widget/yearquarter/card.dynamic.yearquarter.js index 90cc87d4af..f9837ee216 100644 --- a/src/widget/yearquarter/card.dynamic.yearquarter.js +++ b/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)); diff --git a/src/widget/yearquarter/card.static.yearquarter.js b/src/widget/yearquarter/card.static.yearquarter.js index de236ccdf0..fbc1d2ff03 100644 --- a/src/widget/yearquarter/card.static.yearquarter.js +++ b/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"; diff --git a/src/widget/yearquarter/combo.yearquarter.js b/src/widget/yearquarter/combo.yearquarter.js index a8540bb855..384555c145 100644 --- a/src/widget/yearquarter/combo.yearquarter.js +++ b/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); diff --git a/src/widget/yearquarter/popup.yearquarter.js b/src/widget/yearquarter/popup.yearquarter.js index 51a2b42b3f..41883314fd 100644 --- a/src/widget/yearquarter/popup.yearquarter.js +++ b/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; diff --git a/src/widget/yearquarter/trigger.yearquarter.js b/src/widget/yearquarter/trigger.yearquarter.js index f021b8d64a..47cb0b82ef 100644 --- a/src/widget/yearquarter/trigger.yearquarter.js +++ b/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();