From 34f123a0b9b624271aa855c7e57e7eafddbdfcb0 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 22 Mar 2018 11:10:57 +0800 Subject: [PATCH 1/3] BI-17050 multi_layer_single_tree --- .../tree/demo.multilayer_single_level_tree.js | 16 ++++++++++------ dist/base.js | 7 ++++--- dist/bundle.js | 12 ++++++++---- dist/demo.js | 16 ++++++++++------ dist/widget.js | 5 ++++- src/base/tree/customtree.js | 7 ++++--- .../multilayersingletree.leveltree.js | 5 ++++- 7 files changed, 44 insertions(+), 24 deletions(-) diff --git a/demo/js/widget/tree/demo.multilayer_single_level_tree.js b/demo/js/widget/tree/demo.multilayer_single_level_tree.js index cb5c21da0b..49f4f9a39f 100644 --- a/demo/js/widget/tree/demo.multilayer_single_level_tree.js +++ b/demo/js/widget/tree/demo.multilayer_single_level_tree.js @@ -7,23 +7,23 @@ Demo.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { render: function () { var self = this; - var tree = BI.createWidget({ + this.tree = BI.createWidget({ type: "bi.multilayer_single_level_tree", - items: BI.deepClone(Demo.CONSTANTS.TREE), - value: "第五级文件1" + items: [], + value: "第二级文件1" }); return { type: "bi.vtape", items: [{ - el: tree + el: this.tree }, { el: { type: "bi.button", height: 25, text: "getValue", handler: function () { - BI.Msg.alert("", JSON.stringify(tree.getValue())); + BI.Msg.alert("", JSON.stringify(self.tree.getValue())); } }, height: 25 @@ -33,7 +33,7 @@ Demo.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { height: 25, text: "setValue (第二级文件1)", handler: function () { - tree.setValue(["第二级文件1"]); + self.tree.setValue(["第二级文件1"]); } }, height: 25 @@ -41,6 +41,10 @@ Demo.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { width: 500, hgap: 300 }; + }, + + mounted: function () { + this.tree.populate(BI.deepClone(Demo.CONSTANTS.TREE)); } }); diff --git a/dist/base.js b/dist/base.js index be372e602c..d52ed6ff0d 100644 --- a/dist/base.js +++ b/dist/base.js @@ -34238,12 +34238,13 @@ BI.CustomTree = BI.inherit(BI.Widget, { if (BI.isNotEmptyArray(node.children) || node.isParent === true) { var item = BI.extend({ type: "bi.expander", - el: {}, + el: { + value: node.value + }, popup: {type: "bi.custom_tree"} }, BI.deepClone(o.expander), { id: node.id, - pId: node.pId, - value: node.value + pId: node.pId }); var el = BI.stripEL(node); if (!BI.isWidget(el)) { diff --git a/dist/bundle.js b/dist/bundle.js index 8e5f37c847..6d6eee6e55 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -69724,12 +69724,13 @@ BI.CustomTree = BI.inherit(BI.Widget, { if (BI.isNotEmptyArray(node.children) || node.isParent === true) { var item = BI.extend({ type: "bi.expander", - el: {}, + el: { + value: node.value + }, popup: {type: "bi.custom_tree"} }, BI.deepClone(o.expander), { id: node.id, - pId: node.pId, - value: node.value + pId: node.pId }); var el = BI.stripEL(node); if (!BI.isWidget(el)) { @@ -97156,7 +97157,10 @@ BI.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { }, getValue: function () { - return BI.uniq(this.tree.getValue()); + return BI.filter(BI.uniq(this.tree.getValue()), function (idx, value) { + return BI.isNotNull(value); + }); + }, getAllLeaves: function () { diff --git a/dist/demo.js b/dist/demo.js index 48d29334c7..f4c100ea52 100644 --- a/dist/demo.js +++ b/dist/demo.js @@ -14231,23 +14231,23 @@ Demo.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { render: function () { var self = this; - var tree = BI.createWidget({ + this.tree = BI.createWidget({ type: "bi.multilayer_single_level_tree", - items: BI.deepClone(Demo.CONSTANTS.TREE), - value: "第五级文件1" + items: [], + value: "第二级文件1" }); return { type: "bi.vtape", items: [{ - el: tree + el: this.tree }, { el: { type: "bi.button", height: 25, text: "getValue", handler: function () { - BI.Msg.alert("", JSON.stringify(tree.getValue())); + BI.Msg.alert("", JSON.stringify(self.tree.getValue())); } }, height: 25 @@ -14257,7 +14257,7 @@ Demo.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { height: 25, text: "setValue (第二级文件1)", handler: function () { - tree.setValue(["第二级文件1"]); + self.tree.setValue(["第二级文件1"]); } }, height: 25 @@ -14265,6 +14265,10 @@ Demo.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { width: 500, hgap: 300 }; + }, + + mounted: function () { + this.tree.populate(BI.deepClone(Demo.CONSTANTS.TREE)); } }); diff --git a/dist/widget.js b/dist/widget.js index abbaaad8d6..a779189f83 100644 --- a/dist/widget.js +++ b/dist/widget.js @@ -10485,7 +10485,10 @@ BI.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { }, getValue: function () { - return BI.uniq(this.tree.getValue()); + return BI.filter(BI.uniq(this.tree.getValue()), function (idx, value) { + return BI.isNotNull(value); + }); + }, getAllLeaves: function () { diff --git a/src/base/tree/customtree.js b/src/base/tree/customtree.js index fb9eb13463..a72edba2a6 100644 --- a/src/base/tree/customtree.js +++ b/src/base/tree/customtree.js @@ -44,12 +44,13 @@ BI.CustomTree = BI.inherit(BI.Widget, { if (BI.isNotEmptyArray(node.children) || node.isParent === true) { var item = BI.extend({ type: "bi.expander", - el: {}, + el: { + value: node.value + }, popup: {type: "bi.custom_tree"} }, BI.deepClone(o.expander), { id: node.id, - pId: node.pId, - value: node.value + pId: node.pId }); var el = BI.stripEL(node); if (!BI.isWidget(el)) { diff --git a/src/widget/multilayersingletree/multilayersingletree.leveltree.js b/src/widget/multilayersingletree/multilayersingletree.leveltree.js index ae0948cc10..bf2dd6b315 100644 --- a/src/widget/multilayersingletree/multilayersingletree.leveltree.js +++ b/src/widget/multilayersingletree/multilayersingletree.leveltree.js @@ -112,7 +112,10 @@ BI.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { }, getValue: function () { - return BI.uniq(this.tree.getValue()); + return BI.filter(BI.uniq(this.tree.getValue()), function (idx, value) { + return BI.isNotNull(value); + }); + }, getAllLeaves: function () { From 4d385c2f0c71a424e1f765c1342a71927c56a69f Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Thu, 22 Mar 2018 14:09:03 +0800 Subject: [PATCH 2/3] =?UTF-8?q?BI-17245=20=E5=B9=B4=E6=9C=88=E5=8C=BA?= =?UTF-8?q?=E9=97=B4=E6=8E=A7=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/config/widget.js | 4 + .../demo.year_month_interval.js | 45 ++++ dist/bundle.css | 10 +- dist/bundle.js | 240 ++++++++++++++++-- dist/demo.js | 50 +++- dist/fineui.css | 10 +- dist/widget.css | 10 +- dist/widget.js | 240 ++++++++++++++++-- src/css/widget/timeinterval/timeinterval.css | 4 +- .../yearmonthinterval/yearmonthinterval.css | 6 + .../widget/timeinterval/timeinterval.less | 2 +- .../yearmonthinterval/yearmonthinterval.less | 10 + src/widget/dynamic/year/combo.year.js | 6 +- src/widget/dynamic/year/popup.year.js | 1 - .../dynamic/yearmonth/combo.yearmonth.js | 26 +- .../dynamic/yearmonth/popup.yearmonth.js | 1 - .../dynamic/yearmonth/trigger.yearmonth.js | 14 + .../dynamic/yearquarter/combo.yearquarter.js | 6 +- .../dynamic/yearquarter/popup.yearquarter.js | 1 - src/widget/dynamicdate/dynamicdate.combo.js | 4 +- .../yearmonthinterval/yearmonthinterval.js | 180 +++++++++++++ 21 files changed, 813 insertions(+), 57 deletions(-) create mode 100644 demo/js/widget/yearmonthinterval/demo.year_month_interval.js create mode 100644 src/css/widget/yearmonthinterval/yearmonthinterval.css create mode 100644 src/less/widget/yearmonthinterval/yearmonthinterval.less create mode 100644 src/widget/yearmonthinterval/yearmonthinterval.js diff --git a/demo/js/config/widget.js b/demo/js/config/widget.js index 9d9a687af1..cd42165d2e 100644 --- a/demo/js/config/widget.js +++ b/demo/js/config/widget.js @@ -198,6 +198,10 @@ Demo.WIDGET_CONFIG = [{ pId: 412, text: "bi.time_interval", value: "demo.time_interval" +}, { + pId: 412, + text: "bi.year_month_interval", + value: "demo.year_month_interval" }, { pId: 4, id: 413, diff --git a/demo/js/widget/yearmonthinterval/demo.year_month_interval.js b/demo/js/widget/yearmonthinterval/demo.year_month_interval.js new file mode 100644 index 0000000000..a87de534c2 --- /dev/null +++ b/demo/js/widget/yearmonthinterval/demo.year_month_interval.js @@ -0,0 +1,45 @@ +Demo.YearMonthInterval = BI.inherit(BI.Widget, { + props: { + baseCls: "" + }, + + render: function () { + var self = this; + return { + type: "bi.horizontal_auto", + items: [{ + type: "bi.year_month_interval", + ref: function (_ref) { + self.interval = _ref; + }, + value: { + start: { + type: 2, + value: { + year: -1, + month: 1 + } + }, + end: { + type: 1, + value: { + year: 2018, + month: 0 + } + } + }, + width: 400 + }, { + type: "bi.button", + text: "getValue", + handler: function () { + BI.Msg.toast(JSON.stringify(self.interval.getValue())); + }, + width: 300 + }], + vgap: 20 + }; + } +}); + +BI.shortcut("demo.year_month_interval", Demo.YearMonthInterval); \ No newline at end of file diff --git a/dist/bundle.css b/dist/bundle.css index 8889bf1a12..5737345d23 100644 --- a/dist/bundle.css +++ b/dist/bundle.css @@ -5088,10 +5088,10 @@ ul.ztree.zTreeDragUL { -moz-border-radius: 3px; border-radius: 3px; } -.bi-param-time-interval.time-error .bi-input { +.bi-time-interval.time-error .bi-input { color: #ff4949; } -.bi-param-time-interval.time-error .sign-editor-text { +.bi-time-interval.time-error .sign-editor-text { color: #ff4949; } .bi-year-popup .year-popup-navigation { @@ -5134,6 +5134,12 @@ ul.ztree.zTreeDragUL { -moz-border-radius: 2px; border-radius: 2px; } +.bi-year-month-interval.time-error .bi-input { + color: #ff4949; +} +.bi-year-month-interval.time-error .sign-editor-text { + color: #ff4949; +} html, button, input, diff --git a/dist/bundle.js b/dist/bundle.js index 6d6eee6e55..c3ad53d8a6 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -89688,7 +89688,7 @@ BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.i behaviors: {}, min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 25 + height: 24 }, _init: function () { @@ -89798,7 +89798,7 @@ BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.i self.changeIcon = this; } }, - width: 30 + width: 24 }, this.combo] }); this._checkDynamicValue(o.value); @@ -89812,7 +89812,7 @@ BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.i switch (type) { case BI.DynamicYearCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: @@ -89934,7 +89934,6 @@ BI.DynamicYearPopup = BI.inherit(BI.Widget, { var self = this, o = this.options; return { type: "bi.tab", - showIndex: BI.DynamicYearCombo.Static, ref: function () { self.dateTab = this; }, @@ -90383,14 +90382,14 @@ BI.shortcut("bi.dynamic_year_month_card", BI.DynamicYearMonthCard);BI.StaticYear } }); BI.StaticYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearMonthCombo = BI.inherit(BI.Widget, { +BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearMonthCombo = BI.inherit(BI.Single, { props: { baseCls: "bi-year-month-combo bi-border", behaviors: {}, min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 25 + height: 24 }, _init: function () { @@ -90411,6 +90410,10 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM }); this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_ERROR, function () { self.combo.isViewVisible() && self.combo.hideView(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_ERROR); + }); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_VALID, function () { + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_VALID); }); this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_CONFIRM, function () { if (self.combo.isViewVisible()) { @@ -90419,6 +90422,9 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM self.storeValue = self.trigger.getValue(); self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); }); + this.trigger.on(BI.DynamicYearMonthCombo.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_FOCUS); + }); this.combo = BI.createWidget({ type: "bi.combo", @@ -90491,7 +90497,7 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM self.changeIcon = this; } }, - width: 30 + width: 24 }, this.combo] }); this._checkDynamicValue(o.value); @@ -90505,7 +90511,7 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM switch (type) { case BI.DynamicYearMonthCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: @@ -90516,6 +90522,10 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM } }, + hideView: function () { + this.combo.hideView(); + }, + setValue: function (v) { this.storeValue = v; this.trigger.setValue(v); @@ -90524,9 +90534,16 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM getValue: function () { return this.storeValue; + }, + + getKey: function () { + return this.trigger.getKey(); } }); +BI.DynamicYearMonthCombo.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearMonthCombo.EVENT_VALID = "EVENT_VALID"; +BI.DynamicYearMonthCombo.EVENT_FOCUS = "EVENT_FOCUS"; BI.DynamicYearMonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; BI.shortcut("bi.dynamic_year_month_combo", BI.DynamicYearMonthCombo); @@ -90627,7 +90644,6 @@ BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { var self = this, o = this.options; return { type: "bi.tab", - showIndex: BI.DynamicYearCombo.Static, ref: function () { self.dateTab = this; }, @@ -90855,6 +90871,15 @@ BI.shortcut("bi.dynamic_year_month_popup", BI.DynamicYearMonthPopup);BI.DynamicY editor.on(BI.SignEditor.EVENT_ERROR, function () { self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_ERROR); }); + editor.on(BI.SignEditor.EVENT_VALID, function () { + var year = self.yearEditor.getValue(); + var month = self.monthEditor.getValue(); + if(BI.isNotEmptyString(year) && BI.isNotEmptyString(month)) { + if(BI.isPositiveInteger(year) && month >= 1 && month <= 12 && !BI.checkDateVoid(year, month, 1, o.min, o.max)[0]) { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_VALID); + } + } + }); editor.on(BI.SignEditor.EVENT_CHANGE, function () { if(isYear) { self._autoSwitch(editor.getValue()); @@ -90923,8 +90948,13 @@ BI.shortcut("bi.dynamic_year_month_popup", BI.DynamicYearMonthPopup);BI.DynamicY getValue: function () { return this.storeValue; + }, + + getKey: function () { + return this.yearEditor.getValue() + "-" + this.monthEditor.getValue(); } }); +BI.DynamicYearMonthTrigger.EVENT_VALID = "EVENT_FOCUS"; BI.DynamicYearMonthTrigger.EVENT_FOCUS = "EVENT_FOCUS"; BI.DynamicYearMonthTrigger.EVENT_ERROR = "EVENT_ERROR"; BI.DynamicYearMonthTrigger.EVENT_START = "EVENT_START"; @@ -91120,7 +91150,7 @@ BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicY behaviors: {}, min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 25 + height: 24 }, _init: function () { @@ -91221,7 +91251,7 @@ BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicY self.changeIcon = this; } }, - width: 30 + width: 24 }, this.combo] }); this._checkDynamicValue(o.value); @@ -91235,7 +91265,7 @@ BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicY switch (type) { case BI.DynamicYearQuarterCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: @@ -91350,7 +91380,6 @@ BI.extend(BI.DynamicYearQuarterCombo, { var self = this, o = this.options; return { type: "bi.tab", - showIndex: BI.DynamicYearQuarterCombo.Static, ref: function () { self.dateTab = this; }, @@ -92050,7 +92079,7 @@ BI.extend(BI.DynamicDateCard, { self.changeIcon = this; } }, - width: 30 + width: 24 }, { type: "bi.absolute", items: [{ @@ -92235,7 +92264,7 @@ BI.extend(BI.DynamicDateCard, { switch (type) { case BI.DynamicDateCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: @@ -108571,7 +108600,186 @@ BI.YearMonthCombo = BI.inherit(BI.Widget, { }); BI.YearMonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_month_combo", BI.YearMonthCombo);/** +BI.shortcut("bi.year_month_combo", BI.YearMonthCombo);BI.YearMonthInterval = BI.inherit(BI.Single, { + constants: { + height: 25, + width: 25, + lgap: 15, + offset: -15, + timeErrorCls: "time-error", + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" + }, + + props: { + extraCls: "bi-year-month-interval" + }, + + _init: function () { + var self = this, o = this.options; + BI.YearMonthInterval.superclass._init.apply(this, arguments); + + o.value = o.value || {}; + this.left = this._createCombo(o.value.start); + this.right = this._createCombo(o.value.end); + this.label = BI.createWidget({ + type: "bi.label", + height: this.constants.height, + width: this.constants.width, + text: "-" + }); + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, + items: [{ + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: this.constants.offset, + top: 0, + bottom: 0 + }] + }] + }); + BI.createWidget({ + type: "bi.horizontal_auto", + element: this, + items: [ + self.label + ] + }); + }, + + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_year_month_combo", + value: v + }); + combo.on(BI.DynamicYearMonthCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_VALID, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_FOCUS, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hideView(); + self.right.hideView(); + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_CONFIRM, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + }else{ + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.YearMonthInterval.EVENT_CHANGE); + } + }); + return combo; + }, + + + _dateCheck: function (date) { + return BI.parseDateTime(date, "%Y-%x").print("%Y-%x") === date || BI.parseDateTime(date, "%Y-%X").print("%Y-%X") === date; + }, + + + // 判是否在最大最小之间 + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, 1, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + }, + + // 判格式合法 + _check: function (smallDate, bigDate) { + var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ + year: smallObj[0], + month: smallObj[1], + day: 1 + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ + year: bigObj[0], + month: bigObj[1], + day: 1 + }); + }, + + _compare: function (smallDate, bigDate) { + smallDate = BI.parseDateTime(smallDate, "%Y-%X").print("%Y-%X"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X").print("%Y-%X"); + return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; + }, + _setTitle: function (v) { + this.left.setTitle(v); + this.right.setTitle(v); + this.label.setTitle(v); + }, + _clearTitle: function () { + this.left.setTitle(""); + this.right.setTitle(""); + this.label.setTitle(""); + }, + setValue: function (date) { + date = date || {}; + this.left.setValue(date.start); + this.right.setValue(date.end); + }, + getValue: function () { + return {start: this.left.getValue(), end: this.right.getValue()}; + } +}); +BI.YearMonthInterval.EVENT_VALID = "EVENT_VALID"; +BI.YearMonthInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.YearMonthInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.year_month_interval", BI.YearMonthInterval);/** * 年份 + 月份下拉框 * * @class BI.YearQuarterCombo diff --git a/dist/demo.js b/dist/demo.js index f4c100ea52..fa5c315a4d 100644 --- a/dist/demo.js +++ b/dist/demo.js @@ -5852,6 +5852,10 @@ Demo.FIX_CONFIG = [{ pId: 412, text: "bi.time_interval", value: "demo.time_interval" +}, { + pId: 412, + text: "bi.year_month_interval", + value: "demo.year_month_interval" }, { pId: 4, id: 413, @@ -14512,7 +14516,51 @@ Demo.YearMonthCombo = BI.inherit(BI.Widget, { } }); -BI.shortcut("demo.year_month_combo", Demo.YearMonthCombo);/** +BI.shortcut("demo.year_month_combo", Demo.YearMonthCombo);Demo.YearMonthInterval = BI.inherit(BI.Widget, { + props: { + baseCls: "" + }, + + render: function () { + var self = this; + return { + type: "bi.horizontal_auto", + items: [{ + type: "bi.year_month_interval", + ref: function (_ref) { + self.interval = _ref; + }, + value: { + start: { + type: 2, + value: { + year: -1, + month: 1 + } + }, + end: { + type: 1, + value: { + year: 2018, + month: 0 + } + } + }, + width: 400 + }, { + type: "bi.button", + text: "getValue", + handler: function () { + BI.Msg.toast(JSON.stringify(self.interval.getValue())); + }, + width: 300 + }], + vgap: 20 + }; + } +}); + +BI.shortcut("demo.year_month_interval", Demo.YearMonthInterval);/** * Created by Dailer on 2017/7/13. */ Demo.YearQuarterCombo = BI.inherit(BI.Widget, { diff --git a/dist/fineui.css b/dist/fineui.css index bdbde73f8a..9f5d7719a0 100644 --- a/dist/fineui.css +++ b/dist/fineui.css @@ -5088,10 +5088,10 @@ ul.ztree.zTreeDragUL { -moz-border-radius: 3px; border-radius: 3px; } -.bi-param-time-interval.time-error .bi-input { +.bi-time-interval.time-error .bi-input { color: #ff4949; } -.bi-param-time-interval.time-error .sign-editor-text { +.bi-time-interval.time-error .sign-editor-text { color: #ff4949; } .bi-year-popup .year-popup-navigation { @@ -5134,6 +5134,12 @@ ul.ztree.zTreeDragUL { -moz-border-radius: 2px; border-radius: 2px; } +.bi-year-month-interval.time-error .bi-input { + color: #ff4949; +} +.bi-year-month-interval.time-error .sign-editor-text { + color: #ff4949; +} html, button, input, diff --git a/dist/widget.css b/dist/widget.css index 0fbd10ee6e..241b48e971 100644 --- a/dist/widget.css +++ b/dist/widget.css @@ -612,10 +612,10 @@ -moz-border-radius: 3px; border-radius: 3px; } -.bi-param-time-interval.time-error .bi-input { +.bi-time-interval.time-error .bi-input { color: #ff4949; } -.bi-param-time-interval.time-error .sign-editor-text { +.bi-time-interval.time-error .sign-editor-text { color: #ff4949; } .bi-year-popup .year-popup-navigation { @@ -658,3 +658,9 @@ -moz-border-radius: 2px; border-radius: 2px; } +.bi-year-month-interval.time-error .bi-input { + color: #ff4949; +} +.bi-year-month-interval.time-error .sign-editor-text { + color: #ff4949; +} diff --git a/dist/widget.js b/dist/widget.js index a779189f83..83b9dc386c 100644 --- a/dist/widget.js +++ b/dist/widget.js @@ -3016,7 +3016,7 @@ BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.i behaviors: {}, min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 25 + height: 24 }, _init: function () { @@ -3126,7 +3126,7 @@ BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.i self.changeIcon = this; } }, - width: 30 + width: 24 }, this.combo] }); this._checkDynamicValue(o.value); @@ -3140,7 +3140,7 @@ BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.i switch (type) { case BI.DynamicYearCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: @@ -3262,7 +3262,6 @@ BI.DynamicYearPopup = BI.inherit(BI.Widget, { var self = this, o = this.options; return { type: "bi.tab", - showIndex: BI.DynamicYearCombo.Static, ref: function () { self.dateTab = this; }, @@ -3711,14 +3710,14 @@ BI.shortcut("bi.dynamic_year_month_card", BI.DynamicYearMonthCard);BI.StaticYear } }); BI.StaticYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearMonthCombo = BI.inherit(BI.Widget, { +BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearMonthCombo = BI.inherit(BI.Single, { props: { baseCls: "bi-year-month-combo bi-border", behaviors: {}, min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 25 + height: 24 }, _init: function () { @@ -3739,6 +3738,10 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM }); this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_ERROR, function () { self.combo.isViewVisible() && self.combo.hideView(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_ERROR); + }); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_VALID, function () { + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_VALID); }); this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_CONFIRM, function () { if (self.combo.isViewVisible()) { @@ -3747,6 +3750,9 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM self.storeValue = self.trigger.getValue(); self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); }); + this.trigger.on(BI.DynamicYearMonthCombo.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_FOCUS); + }); this.combo = BI.createWidget({ type: "bi.combo", @@ -3819,7 +3825,7 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM self.changeIcon = this; } }, - width: 30 + width: 24 }, this.combo] }); this._checkDynamicValue(o.value); @@ -3833,7 +3839,7 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM switch (type) { case BI.DynamicYearMonthCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: @@ -3844,6 +3850,10 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM } }, + hideView: function () { + this.combo.hideView(); + }, + setValue: function (v) { this.storeValue = v; this.trigger.setValue(v); @@ -3852,9 +3862,16 @@ BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearM getValue: function () { return this.storeValue; + }, + + getKey: function () { + return this.trigger.getKey(); } }); +BI.DynamicYearMonthCombo.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearMonthCombo.EVENT_VALID = "EVENT_VALID"; +BI.DynamicYearMonthCombo.EVENT_FOCUS = "EVENT_FOCUS"; BI.DynamicYearMonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; BI.shortcut("bi.dynamic_year_month_combo", BI.DynamicYearMonthCombo); @@ -3955,7 +3972,6 @@ BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { var self = this, o = this.options; return { type: "bi.tab", - showIndex: BI.DynamicYearCombo.Static, ref: function () { self.dateTab = this; }, @@ -4183,6 +4199,15 @@ BI.shortcut("bi.dynamic_year_month_popup", BI.DynamicYearMonthPopup);BI.DynamicY editor.on(BI.SignEditor.EVENT_ERROR, function () { self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_ERROR); }); + editor.on(BI.SignEditor.EVENT_VALID, function () { + var year = self.yearEditor.getValue(); + var month = self.monthEditor.getValue(); + if(BI.isNotEmptyString(year) && BI.isNotEmptyString(month)) { + if(BI.isPositiveInteger(year) && month >= 1 && month <= 12 && !BI.checkDateVoid(year, month, 1, o.min, o.max)[0]) { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_VALID); + } + } + }); editor.on(BI.SignEditor.EVENT_CHANGE, function () { if(isYear) { self._autoSwitch(editor.getValue()); @@ -4251,8 +4276,13 @@ BI.shortcut("bi.dynamic_year_month_popup", BI.DynamicYearMonthPopup);BI.DynamicY getValue: function () { return this.storeValue; + }, + + getKey: function () { + return this.yearEditor.getValue() + "-" + this.monthEditor.getValue(); } }); +BI.DynamicYearMonthTrigger.EVENT_VALID = "EVENT_FOCUS"; BI.DynamicYearMonthTrigger.EVENT_FOCUS = "EVENT_FOCUS"; BI.DynamicYearMonthTrigger.EVENT_ERROR = "EVENT_ERROR"; BI.DynamicYearMonthTrigger.EVENT_START = "EVENT_START"; @@ -4448,7 +4478,7 @@ BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicY behaviors: {}, min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 25 + height: 24 }, _init: function () { @@ -4549,7 +4579,7 @@ BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicY self.changeIcon = this; } }, - width: 30 + width: 24 }, this.combo] }); this._checkDynamicValue(o.value); @@ -4563,7 +4593,7 @@ BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicY switch (type) { case BI.DynamicYearQuarterCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: @@ -4678,7 +4708,6 @@ BI.extend(BI.DynamicYearQuarterCombo, { var self = this, o = this.options; return { type: "bi.tab", - showIndex: BI.DynamicYearQuarterCombo.Static, ref: function () { self.dateTab = this; }, @@ -5378,7 +5407,7 @@ BI.extend(BI.DynamicDateCard, { self.changeIcon = this; } }, - width: 30 + width: 24 }, { type: "bi.absolute", items: [{ @@ -5563,7 +5592,7 @@ BI.extend(BI.DynamicDateCard, { switch (type) { case BI.DynamicDateCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: @@ -21899,7 +21928,186 @@ BI.YearMonthCombo = BI.inherit(BI.Widget, { }); BI.YearMonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_month_combo", BI.YearMonthCombo);/** +BI.shortcut("bi.year_month_combo", BI.YearMonthCombo);BI.YearMonthInterval = BI.inherit(BI.Single, { + constants: { + height: 25, + width: 25, + lgap: 15, + offset: -15, + timeErrorCls: "time-error", + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" + }, + + props: { + extraCls: "bi-year-month-interval" + }, + + _init: function () { + var self = this, o = this.options; + BI.YearMonthInterval.superclass._init.apply(this, arguments); + + o.value = o.value || {}; + this.left = this._createCombo(o.value.start); + this.right = this._createCombo(o.value.end); + this.label = BI.createWidget({ + type: "bi.label", + height: this.constants.height, + width: this.constants.width, + text: "-" + }); + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, + items: [{ + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: this.constants.offset, + top: 0, + bottom: 0 + }] + }] + }); + BI.createWidget({ + type: "bi.horizontal_auto", + element: this, + items: [ + self.label + ] + }); + }, + + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_year_month_combo", + value: v + }); + combo.on(BI.DynamicYearMonthCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_VALID, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_FOCUS, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hideView(); + self.right.hideView(); + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_CONFIRM, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + }else{ + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.YearMonthInterval.EVENT_CHANGE); + } + }); + return combo; + }, + + + _dateCheck: function (date) { + return BI.parseDateTime(date, "%Y-%x").print("%Y-%x") === date || BI.parseDateTime(date, "%Y-%X").print("%Y-%X") === date; + }, + + + // 判是否在最大最小之间 + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, 1, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + }, + + // 判格式合法 + _check: function (smallDate, bigDate) { + var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ + year: smallObj[0], + month: smallObj[1], + day: 1 + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ + year: bigObj[0], + month: bigObj[1], + day: 1 + }); + }, + + _compare: function (smallDate, bigDate) { + smallDate = BI.parseDateTime(smallDate, "%Y-%X").print("%Y-%X"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X").print("%Y-%X"); + return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; + }, + _setTitle: function (v) { + this.left.setTitle(v); + this.right.setTitle(v); + this.label.setTitle(v); + }, + _clearTitle: function () { + this.left.setTitle(""); + this.right.setTitle(""); + this.label.setTitle(""); + }, + setValue: function (date) { + date = date || {}; + this.left.setValue(date.start); + this.right.setValue(date.end); + }, + getValue: function () { + return {start: this.left.getValue(), end: this.right.getValue()}; + } +}); +BI.YearMonthInterval.EVENT_VALID = "EVENT_VALID"; +BI.YearMonthInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.YearMonthInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.year_month_interval", BI.YearMonthInterval);/** * 年份 + 月份下拉框 * * @class BI.YearQuarterCombo diff --git a/src/css/widget/timeinterval/timeinterval.css b/src/css/widget/timeinterval/timeinterval.css index 59229928f6..26f946e8cb 100644 --- a/src/css/widget/timeinterval/timeinterval.css +++ b/src/css/widget/timeinterval/timeinterval.css @@ -1,6 +1,6 @@ -.bi-param-time-interval.time-error .bi-input { +.bi-time-interval.time-error .bi-input { color: #ff4949; } -.bi-param-time-interval.time-error .sign-editor-text { +.bi-time-interval.time-error .sign-editor-text { color: #ff4949; } diff --git a/src/css/widget/yearmonthinterval/yearmonthinterval.css b/src/css/widget/yearmonthinterval/yearmonthinterval.css new file mode 100644 index 0000000000..741ccfeaa8 --- /dev/null +++ b/src/css/widget/yearmonthinterval/yearmonthinterval.css @@ -0,0 +1,6 @@ +.bi-year-month-interval.time-error .bi-input { + color: #ff4949; +} +.bi-year-month-interval.time-error .sign-editor-text { + color: #ff4949; +} diff --git a/src/less/widget/timeinterval/timeinterval.less b/src/less/widget/timeinterval/timeinterval.less index 954f52169d..4c832f6db4 100644 --- a/src/less/widget/timeinterval/timeinterval.less +++ b/src/less/widget/timeinterval/timeinterval.less @@ -1,6 +1,6 @@ @import "../../index"; -.bi-param-time-interval{ +.bi-time-interval{ &.time-error .bi-input{ color:@color-bi-text-failure } diff --git a/src/less/widget/yearmonthinterval/yearmonthinterval.less b/src/less/widget/yearmonthinterval/yearmonthinterval.less new file mode 100644 index 0000000000..d66deb475d --- /dev/null +++ b/src/less/widget/yearmonthinterval/yearmonthinterval.less @@ -0,0 +1,10 @@ +@import "../../index"; + +.bi-year-month-interval{ + &.time-error .bi-input{ + color:@color-bi-text-failure + } + &.time-error .sign-editor-text{ + color:@color-bi-text-failure + } +} \ No newline at end of file diff --git a/src/widget/dynamic/year/combo.year.js b/src/widget/dynamic/year/combo.year.js index abe633f6e8..9f140d6a6b 100644 --- a/src/widget/dynamic/year/combo.year.js +++ b/src/widget/dynamic/year/combo.year.js @@ -5,7 +5,7 @@ BI.DynamicYearCombo = BI.inherit(BI.Widget, { behaviors: {}, min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 25 + height: 24 }, _init: function () { @@ -115,7 +115,7 @@ BI.DynamicYearCombo = BI.inherit(BI.Widget, { self.changeIcon = this; } }, - width: 30 + width: 24 }, this.combo] }); this._checkDynamicValue(o.value); @@ -129,7 +129,7 @@ BI.DynamicYearCombo = BI.inherit(BI.Widget, { switch (type) { case BI.DynamicYearCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: diff --git a/src/widget/dynamic/year/popup.year.js b/src/widget/dynamic/year/popup.year.js index e56e286451..3138162227 100644 --- a/src/widget/dynamic/year/popup.year.js +++ b/src/widget/dynamic/year/popup.year.js @@ -91,7 +91,6 @@ BI.DynamicYearPopup = BI.inherit(BI.Widget, { var self = this, o = this.options; return { type: "bi.tab", - showIndex: BI.DynamicYearCombo.Static, ref: function () { self.dateTab = this; }, diff --git a/src/widget/dynamic/yearmonth/combo.yearmonth.js b/src/widget/dynamic/yearmonth/combo.yearmonth.js index 83a9482378..b1dddfcefe 100644 --- a/src/widget/dynamic/yearmonth/combo.yearmonth.js +++ b/src/widget/dynamic/yearmonth/combo.yearmonth.js @@ -1,11 +1,11 @@ -BI.DynamicYearMonthCombo = BI.inherit(BI.Widget, { +BI.DynamicYearMonthCombo = BI.inherit(BI.Single, { props: { baseCls: "bi-year-month-combo bi-border", behaviors: {}, min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 25 + height: 24 }, _init: function () { @@ -26,6 +26,10 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Widget, { }); this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_ERROR, function () { self.combo.isViewVisible() && self.combo.hideView(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_ERROR); + }); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_VALID, function () { + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_VALID); }); this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_CONFIRM, function () { if (self.combo.isViewVisible()) { @@ -34,6 +38,9 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Widget, { self.storeValue = self.trigger.getValue(); self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); }); + this.trigger.on(BI.DynamicYearMonthCombo.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_FOCUS); + }); this.combo = BI.createWidget({ type: "bi.combo", @@ -106,7 +113,7 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Widget, { self.changeIcon = this; } }, - width: 30 + width: 24 }, this.combo] }); this._checkDynamicValue(o.value); @@ -120,7 +127,7 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Widget, { switch (type) { case BI.DynamicYearMonthCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: @@ -131,6 +138,10 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Widget, { } }, + hideView: function () { + this.combo.hideView(); + }, + setValue: function (v) { this.storeValue = v; this.trigger.setValue(v); @@ -139,9 +150,16 @@ BI.DynamicYearMonthCombo = BI.inherit(BI.Widget, { getValue: function () { return this.storeValue; + }, + + getKey: function () { + return this.trigger.getKey(); } }); +BI.DynamicYearMonthCombo.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearMonthCombo.EVENT_VALID = "EVENT_VALID"; +BI.DynamicYearMonthCombo.EVENT_FOCUS = "EVENT_FOCUS"; BI.DynamicYearMonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; BI.shortcut("bi.dynamic_year_month_combo", BI.DynamicYearMonthCombo); diff --git a/src/widget/dynamic/yearmonth/popup.yearmonth.js b/src/widget/dynamic/yearmonth/popup.yearmonth.js index 521dda8c7f..893ea58a13 100644 --- a/src/widget/dynamic/yearmonth/popup.yearmonth.js +++ b/src/widget/dynamic/yearmonth/popup.yearmonth.js @@ -91,7 +91,6 @@ BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { var self = this, o = this.options; return { type: "bi.tab", - showIndex: BI.DynamicYearCombo.Static, ref: function () { self.dateTab = this; }, diff --git a/src/widget/dynamic/yearmonth/trigger.yearmonth.js b/src/widget/dynamic/yearmonth/trigger.yearmonth.js index cde12ef083..5e2e35ca87 100644 --- a/src/widget/dynamic/yearmonth/trigger.yearmonth.js +++ b/src/widget/dynamic/yearmonth/trigger.yearmonth.js @@ -113,6 +113,15 @@ BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, { editor.on(BI.SignEditor.EVENT_ERROR, function () { self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_ERROR); }); + editor.on(BI.SignEditor.EVENT_VALID, function () { + var year = self.yearEditor.getValue(); + var month = self.monthEditor.getValue(); + if(BI.isNotEmptyString(year) && BI.isNotEmptyString(month)) { + if(BI.isPositiveInteger(year) && month >= 1 && month <= 12 && !BI.checkDateVoid(year, month, 1, o.min, o.max)[0]) { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_VALID); + } + } + }); editor.on(BI.SignEditor.EVENT_CHANGE, function () { if(isYear) { self._autoSwitch(editor.getValue()); @@ -181,8 +190,13 @@ BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, { getValue: function () { return this.storeValue; + }, + + getKey: function () { + return this.yearEditor.getValue() + "-" + this.monthEditor.getValue(); } }); +BI.DynamicYearMonthTrigger.EVENT_VALID = "EVENT_FOCUS"; BI.DynamicYearMonthTrigger.EVENT_FOCUS = "EVENT_FOCUS"; BI.DynamicYearMonthTrigger.EVENT_ERROR = "EVENT_ERROR"; BI.DynamicYearMonthTrigger.EVENT_START = "EVENT_START"; diff --git a/src/widget/dynamic/yearquarter/combo.yearquarter.js b/src/widget/dynamic/yearquarter/combo.yearquarter.js index efc88ee3e0..ee489b8ccc 100644 --- a/src/widget/dynamic/yearquarter/combo.yearquarter.js +++ b/src/widget/dynamic/yearquarter/combo.yearquarter.js @@ -5,7 +5,7 @@ BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { behaviors: {}, min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 - height: 25 + height: 24 }, _init: function () { @@ -106,7 +106,7 @@ BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { self.changeIcon = this; } }, - width: 30 + width: 24 }, this.combo] }); this._checkDynamicValue(o.value); @@ -120,7 +120,7 @@ BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { switch (type) { case BI.DynamicYearQuarterCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: diff --git a/src/widget/dynamic/yearquarter/popup.yearquarter.js b/src/widget/dynamic/yearquarter/popup.yearquarter.js index 226d560d66..df767b5f9a 100644 --- a/src/widget/dynamic/yearquarter/popup.yearquarter.js +++ b/src/widget/dynamic/yearquarter/popup.yearquarter.js @@ -84,7 +84,6 @@ BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, { var self = this, o = this.options; return { type: "bi.tab", - showIndex: BI.DynamicYearQuarterCombo.Static, ref: function () { self.dateTab = this; }, diff --git a/src/widget/dynamicdate/dynamicdate.combo.js b/src/widget/dynamicdate/dynamicdate.combo.js index e14b34d281..5fc6e38817 100644 --- a/src/widget/dynamicdate/dynamicdate.combo.js +++ b/src/widget/dynamicdate/dynamicdate.combo.js @@ -31,7 +31,7 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { self.changeIcon = this; } }, - width: 30 + width: 24 }, { type: "bi.absolute", items: [{ @@ -216,7 +216,7 @@ BI.DynamicDateCombo = BI.inherit(BI.Single, { switch (type) { case BI.DynamicDateCombo.Dynamic: this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 30; + this.comboWrapper.attr("items")[0].width = 24; this.comboWrapper.resize(); break; default: diff --git a/src/widget/yearmonthinterval/yearmonthinterval.js b/src/widget/yearmonthinterval/yearmonthinterval.js new file mode 100644 index 0000000000..2d199d67fe --- /dev/null +++ b/src/widget/yearmonthinterval/yearmonthinterval.js @@ -0,0 +1,180 @@ +BI.YearMonthInterval = BI.inherit(BI.Single, { + constants: { + height: 25, + width: 25, + lgap: 15, + offset: -15, + timeErrorCls: "time-error", + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" + }, + + props: { + extraCls: "bi-year-month-interval" + }, + + _init: function () { + var self = this, o = this.options; + BI.YearMonthInterval.superclass._init.apply(this, arguments); + + o.value = o.value || {}; + this.left = this._createCombo(o.value.start); + this.right = this._createCombo(o.value.end); + this.label = BI.createWidget({ + type: "bi.label", + height: this.constants.height, + width: this.constants.width, + text: "-" + }); + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, + items: [{ + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: this.constants.offset, + top: 0, + bottom: 0 + }] + }] + }); + BI.createWidget({ + type: "bi.horizontal_auto", + element: this, + items: [ + self.label + ] + }); + }, + + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_year_month_combo", + value: v + }); + combo.on(BI.DynamicYearMonthCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_VALID, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_FOCUS, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hideView(); + self.right.hideView(); + }); + + combo.on(BI.DynamicYearMonthCombo.EVENT_CONFIRM, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + }else{ + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.YearMonthInterval.EVENT_CHANGE); + } + }); + return combo; + }, + + + _dateCheck: function (date) { + return BI.parseDateTime(date, "%Y-%x").print("%Y-%x") === date || BI.parseDateTime(date, "%Y-%X").print("%Y-%X") === date; + }, + + + // 判是否在最大最小之间 + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, 1, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + }, + + // 判格式合法 + _check: function (smallDate, bigDate) { + var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ + year: smallObj[0], + month: smallObj[1], + day: 1 + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ + year: bigObj[0], + month: bigObj[1], + day: 1 + }); + }, + + _compare: function (smallDate, bigDate) { + smallDate = BI.parseDateTime(smallDate, "%Y-%X").print("%Y-%X"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X").print("%Y-%X"); + return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; + }, + _setTitle: function (v) { + this.left.setTitle(v); + this.right.setTitle(v); + this.label.setTitle(v); + }, + _clearTitle: function () { + this.left.setTitle(""); + this.right.setTitle(""); + this.label.setTitle(""); + }, + setValue: function (date) { + date = date || {}; + this.left.setValue(date.start); + this.right.setValue(date.end); + }, + getValue: function () { + return {start: this.left.getValue(), end: this.right.getValue()}; + } +}); +BI.YearMonthInterval.EVENT_VALID = "EVENT_VALID"; +BI.YearMonthInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.YearMonthInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.year_month_interval", BI.YearMonthInterval); \ No newline at end of file From 199f2d1e817ce3e7232bd0c9ed180c0f6eed5122 Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 23 Mar 2018 10:57:36 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=97=B6=E9=97=B4=E7=B2=92=E5=BA=A6?= =?UTF-8?q?=E7=BB=86=E5=8C=96=E5=88=B0=E6=97=B6=E5=88=86=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- demo/js/widget/date/demo.datepane.js | 23 + demo/js/widget/date/demo.multidate_combo.js | 37 +- .../widget/timeinterval/demo.time_interval.js | 34 +- demo/version.js | 4 +- dist/bundle.css | 15 +- dist/bundle.js | 1491 ++++++++++++++++- dist/config.js | 4 +- dist/demo.js | 94 +- dist/fineui.css | 15 +- dist/widget.css | 15 +- dist/widget.js | 1487 +++++++++++++++- public/js/index.js | 4 +- src/css/widget/timeinterval/dateinterval.css | 6 + src/css/widget/timeinterval/timeinterval.css | 9 +- .../widget/timeinterval/dateinterval.less | 10 + .../widget/timeinterval/timeinterval.less | 15 +- .../datetimepane/card.static.datetimepane.js | 130 ++ .../dynamic/datetimepane/datetimepane.js | 140 ++ .../dynamicdatetime/dynamicdatetime.combo.js | 261 +++ .../dynamicdatetime/dynamicdatetime.popup.js | 235 +++ .../dynamicdatetime.timeselect.js | 164 ++ .../dynamicdatetime.trigger.js | 232 +++ src/widget/numbereditor/number.editor.js | 4 + src/widget/timeinterval/dateinterval.js | 179 ++ src/widget/timeinterval/timeinterval.js | 23 +- ui/js/index.js | 4 +- 26 files changed, 4434 insertions(+), 201 deletions(-) create mode 100644 src/css/widget/timeinterval/dateinterval.css create mode 100644 src/less/widget/timeinterval/dateinterval.less create mode 100644 src/widget/dynamic/datetimepane/card.static.datetimepane.js create mode 100644 src/widget/dynamic/datetimepane/datetimepane.js create mode 100644 src/widget/dynamicdatetime/dynamicdatetime.combo.js create mode 100644 src/widget/dynamicdatetime/dynamicdatetime.popup.js create mode 100644 src/widget/dynamicdatetime/dynamicdatetime.timeselect.js create mode 100644 src/widget/dynamicdatetime/dynamicdatetime.trigger.js create mode 100644 src/widget/timeinterval/dateinterval.js diff --git a/demo/js/widget/date/demo.datepane.js b/demo/js/widget/date/demo.datepane.js index 636e9b0a66..5f687de49a 100644 --- a/demo/js/widget/date/demo.datepane.js +++ b/demo/js/widget/date/demo.datepane.js @@ -33,6 +33,29 @@ Demo.DatePane = BI.inherit(BI.Widget, { handler: function () { BI.Msg.toast("date" + JSON.stringify(self.datepane.getValue())); } + }, { + type: "bi.dynamic_date_time_pane", + value: { + type: 1, + value: { + year: 2017, + month: 11, + day: 11, + hour: 12, + minute: 12, + second: 12 + } + }, + ref: function (_ref) { + self.dateTimePane = _ref; + }, + height: 340 + }, { + type: "bi.button", + text: "getValue", + handler: function () { + BI.Msg.toast("date" + JSON.stringify(self.dateTimePane.getValue())); + } }, { type: "bi.button", text: "setValue '2017-12-31'", diff --git a/demo/js/widget/date/demo.multidate_combo.js b/demo/js/widget/date/demo.multidate_combo.js index 2656c4ada6..0177e32f82 100644 --- a/demo/js/widget/date/demo.multidate_combo.js +++ b/demo/js/widget/date/demo.multidate_combo.js @@ -14,7 +14,7 @@ Demo.Date = BI.inherit(BI.Widget, { var self = this; return { type: "bi.horizontal_auto", - vgap: 10, + vgap: 20, items: [{ type: "bi.dynamic_date_combo", ref: function () { @@ -22,31 +22,44 @@ Demo.Date = BI.inherit(BI.Widget, { }, width: 300, value: { - year: 2018, - month: 1, - day: 23 + type: 1, + value: { + year: 2018, + month: 1, + day: 23 + } } }, { - type: "bi.multidate_combo", + type: "bi.button", + text: "getValue", + width: 300, + handler: function () { + BI.Msg.alert("date", JSON.stringify(self.datecombo.getValue())); + } + }, { + type: "bi.dynamic_date_time_combo", ref: function () { - self.datecombo = this; + self.datetimecombo = this; }, width: 300, value: { - year: 2018, - month: 1, - day: 23 + type: 1, + value: { + year: 2018, + month: 1, + day: 23 + } } }, { type: "bi.button", - text: "getVlaue", + text: "getValue", width: 300, handler: function () { - BI.Msg.alert("date", JSON.stringify(self.datecombo.getValue())); + BI.Msg.alert("date", JSON.stringify(self.datetimecombo.getValue())); } }, { type: "bi.button", - text: "setVlaue '2017-12-31'", + text: "setValue '2017-12-31'", width: 300, handler: function () { self.datecombo.setValue({ diff --git a/demo/js/widget/timeinterval/demo.time_interval.js b/demo/js/widget/timeinterval/demo.time_interval.js index b7c8659329..879c659aaa 100644 --- a/demo/js/widget/timeinterval/demo.time_interval.js +++ b/demo/js/widget/timeinterval/demo.time_interval.js @@ -12,6 +12,36 @@ Demo.TimeInterval = BI.inherit(BI.Widget, { return { type: "bi.horizontal_auto", items: [{ + type: "bi.date_interval", + ref: function (_ref) { + self.dateInterval = _ref; + }, + value: { + start: { + type: 2, + value: { + year: -1, + position: 2 + } + }, + end: { + type: 1, + value: { + year: 2018, + month: 0, + day: 12 + } + } + }, + width: 300 + }, { + type: "bi.button", + text: "getValue", + handler: function () { + BI.Msg.toast(JSON.stringify(self.dateInterval.getValue())); + }, + width: 300 + }, { type: "bi.time_interval", ref: function (_ref) { self.interval = _ref; @@ -33,10 +63,10 @@ Demo.TimeInterval = BI.inherit(BI.Widget, { } } }, - width: 300 + width: 400 }, { type: "bi.button", - text: "getVlaue", + text: "getValue", handler: function () { BI.Msg.toast(JSON.stringify(self.interval.getValue())); }, diff --git a/demo/version.js b/demo/version.js index 9c65a2d7aa..b2e2b9a589 100644 --- a/demo/version.js +++ b/demo/version.js @@ -146,5 +146,7 @@ BI.i18n = { "BI-Basic_Current_Quarter": "本季度", "BI-Basic_Year_Month": "年月", "BI-Basic_Year_Quarter": "年季度", - "BI-Basic_Input_Can_Not_Null": "输入框不能为空" + "BI-Basic_Input_Can_Not_Null": "输入框不能为空", + "BI-Basic_Input_From_To_Number": "请输入{R1}的数值", + "BI-Basic_Date_Time_Error_Text": "日期格式示例:2015-3-11 00:00:00" }; \ No newline at end of file diff --git a/dist/bundle.css b/dist/bundle.css index 5737345d23..041a5471d0 100644 --- a/dist/bundle.css +++ b/dist/bundle.css @@ -5088,10 +5088,21 @@ ul.ztree.zTreeDragUL { -moz-border-radius: 3px; border-radius: 3px; } -.bi-time-interval.time-error .bi-input { +.bi-date-interval.time-error .bi-input { color: #ff4949; } -.bi-time-interval.time-error .sign-editor-text { +.bi-date-interval.time-error .sign-editor-text { + color: #ff4949; +} +.bi-time-interval .bi-date-time-trigger { + -webkit-border-radius: 2px; + -moz-border-radius: 2px; + border-radius: 2px; +} +.bi-time-interval.time-error .bi-date-time-trigger .bi-input { + color: #ff4949; +} +.bi-time-interval.time-error .bi-date-time-trigger .sign-editor-text { color: #ff4949; } .bi-year-popup .year-popup-navigation { diff --git a/dist/bundle.js b/dist/bundle.js index c3ad53d8a6..c5a3257bd2 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -89460,6 +89460,274 @@ BI.shortcut("bi.dynamic_date_pane", BI.DynamicDatePane); BI.extend(BI.DynamicDatePane, { Static: 1, Dynamic: 2 +});BI.StaticDateTimePaneCard = BI.inherit(BI.Widget, { + _defaultConfig: function () { + var conf = BI.StaticDateTimePaneCard.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: "bi-date-time-pane", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + selectedTime: null + }); + }, + _init: function () { + BI.StaticDateTimePaneCard.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.today = BI.getDate(); + this._year = this.today.getFullYear(); + this._month = this.today.getMonth(); + + this.selectedTime = o.selectedTime || { + year: this._year, + month: this._month + }; + + this.datePicker = BI.createWidget({ + type: "bi.date_picker", + min: o.min, + max: o.max + }); + this.datePicker.on(BI.DatePicker.EVENT_CHANGE, function () { + self.selectedTime = BI.extend(self.datePicker.getValue(), self.timeSelect.getValue()); + self.calendar.setSelect(BI.Calendar.getPageByDateJSON(self.selectedTime)); + }); + + this.calendar = BI.createWidget({ + direction: "top", + logic: { + dynamic: false + }, + type: "bi.navigation", + tab: this.datePicker, + cardCreator: BI.bind(this._createNav, this) + }); + this.calendar.on(BI.Navigation.EVENT_CHANGE, function () { + self.selectedTime = BI.extend(self.calendar.getValue(), self.timeSelect.getValue()); + self.calendar.empty(); + self.setValue(self.selectedTime); + self.fireEvent(BI.DateCalendarPopup.EVENT_CHANGE); + }); + + BI.createWidget({ + type: "bi.vtape", + element: this, + items: [this.calendar, { + el: { + type: "bi.dynamic_date_time_select", + ref: function () { + self.timeSelect = this; + } + }, + height: 40 + }] + }); + this.setValue(o.selectedTime); + + }, + + _createNav: function (v) { + var date = BI.Calendar.getDateJSONByPage(v); + var calendar = BI.createWidget({ + type: "bi.calendar", + logic: { + dynamic: false + }, + min: this.options.min, + max: this.options.max, + year: date.year, + month: date.month, + day: this.selectedTime.day + }); + return calendar; + }, + + _getNewCurrentDate: function () { + var today = BI.getDate(); + return { + year: today.getFullYear(), + month: today.getMonth() + }; + }, + + _setCalenderValue: function (date) { + this.calendar.setSelect(BI.Calendar.getPageByDateJSON(date)); + this.calendar.setValue(date); + this.selectedTime = BI.extend(date, this.timeSelect.getValue()); + }, + + _setDatePicker: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.year) || BI.isNull(timeOb.month)) { + this.datePicker.setValue(this._getNewCurrentDate()); + } else { + this.datePicker.setValue(timeOb); + } + }, + + _setCalendar: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { + this.calendar.empty(); + this._setCalenderValue(this._getNewCurrentDate()); + } else { + this._setCalenderValue(timeOb); + } + }, + + setValue: function (timeOb) { + timeOb = timeOb || {}; + this._setDatePicker(timeOb); + this._setCalendar(timeOb); + this.timeSelect.setValue({ + hour: timeOb.hour, + minute: timeOb.minute, + second: timeOb.second + }); + }, + + getValue: function () { + return this.selectedTime; + } + +}); +BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.DynamicDateTimePane = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-dynamic-date-pane" + }, + + render: function () { + var self = this; + return { + type: "bi.vtape", + items: [{ + el: { + type: "bi.linear_segment", + cls: "bi-border-bottom", + height: 30, + items: BI.createItems([{ + text: BI.i18nText("BI-Multi_Date_YMD"), + value: BI.DynamicDateTimePane.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDateTimePane.Dynamic + }], { + textAlign: "center" + }), + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + var value = this.getValue()[0]; + self.dateTab.setSelect(value); + switch (value) { + case BI.DynamicDateTimePane.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + break; + case BI.DynamicDateTimePane.Dynamic: + self.dynamicPane.setValue({ + year: 0 + }); + break; + default: + break; + } + } + }], + ref: function () { + self.switch = this; + } + }, + height: 30 + }, { + type: "bi.tab", + ref: function () { + self.dateTab = this; + }, + showIndex: BI.DynamicDateTimePane.Static, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDateTimePane.Static: + return { + type: "bi.static_date_time_pane_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.ymd = this; + } + }; + case BI.DynamicDateTimePane.Dynamic: + default: + return { + type: "bi.dynamic_date_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + } + } + }] + }; + }, + + mounted: function () { + this.setValue(this.options.value); + }, + + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + }, + + setValue: function (v) { + v = v || {}; + var type = v.type || BI.DynamicDateTimePane.Static; + var value = v.value || v; + this.switch.setValue(type); + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateTimePane.Dynamic: + this.dynamicPane.setValue(value); + break; + case BI.DynamicDateTimePane.Static: + default: + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth() + }); + } else { + this.ymd.setValue(value); + } + break; + } + }, + + getValue: function () { + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; + } +}); +BI.shortcut("bi.dynamic_date_time_pane", BI.DynamicDateTimePane); + +BI.extend(BI.DynamicDateTimePane, { + Static: 1, + Dynamic: 2 });/** * 年份展示面板 * @@ -92588,50 +92856,934 @@ BI.shortcut("bi.dynamic_date_param_item", BI.DynamicDateParamItem);BI.DynamicDat return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, - setValue: function (v) { - this.storeValue = v; - var self = this; - var type, value; - v = v || {}; - type = v.type || BI.DynamicDateCombo.Static; - value = v.value || v; - this.dateTab.setSelect(type); + setValue: function (v) { + this.storeValue = v; + var self = this; + var type, value; + v = v || {}; + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateCombo.Dynamic: + this.dynamicPane.setValue(value); + self._setInnerValue(); + break; + case BI.DynamicDateCombo.Static: + default: + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } else { + this.ymd.setValue(value); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } + this.textButton.setEnable(true); + break; + } + }, + + getValue: function () { + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; + } +}); +BI.DynamicDatePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + yearLength: 4, + yearMonthLength: 7 + }, + + props: { + extraCls: "bi-date-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 + }, + + _init: function () { + BI.DynamicDateTrigger.superclass._init.apply(this, arguments); + var self = this, o = this.options, c = this._const; + this.editor = BI.createWidget({ + type: "bi.sign_editor", + height: o.height, + validationChecker: function (v) { + var date = v.match(/\d+/g); + self._autoAppend(v, date); + return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ + year: date[0], + month: date[1], + day: date[2] + }); + }, + quitChecker: function () { + return false; + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + errorText: function () { + if (self.editor.isEditing()) { + return BI.i18nText("BI-Date_Trigger_Error_Text"); + } + return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + } + }); + this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); + }); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_FOCUS); + }); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_STOP); + }); + this.editor.on(BI.SignEditor.EVENT_VALID, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_VALID); + }); + this.editor.on(BI.SignEditor.EVENT_ERROR, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_ERROR); + }); + this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setState(value); + } + + if (BI.isNotEmptyString(value)) { + var date = value.split("-"); + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: date[0] | 0, + month: date[1] - 1, + day: date[2] | 0 + } + }; + } + self.fireEvent(BI.DynamicDateTrigger.EVENT_CONFIRM); + }); + this.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); + } + }); + this.editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_START); + }); + this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_CHANGE); + }); + BI.createWidget({ + type: "bi.htape", + element: this, + items: [{ + el: this.editor + }, { + el: BI.createWidget(), + width: 30 + }] + }); + this.setValue(o.value); + }, + _dateCheck: function (date) { + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || + BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") === date || + BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") === date || + BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") === date; + }, + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; + }, + _autoAppend: function (v, dateObj) { + if (BI.isNotNull(dateObj) && BI.checkDateLegal(v)) { + switch (v.length) { + case this._const.yearLength: + if (this._yearCheck(v)) { + this.editor.setValue(v + "-"); + } + break; + case this._const.yearMonthLength: + if (this._monthCheck(v)) { + this.editor.setValue(v + "-"); + } + break; + } + } + }, + + _yearCheck: function (v) { + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.parseDateTime(v, "%Y").print("%Y") === v && date >= this.options.min && date <= this.options.max; + }, + + _monthCheck: function (v) { + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.parseDateTime(v, "%Y-%X").print("%Y-%X") === v && date >= this.options.min && date <= this.options.max; + }, + + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y-%x-%e"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); + }, + + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year) && obj.year !== 0) { + value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Year"), obj.position); + } + if(BI.isNotNull(obj.quarter) && obj.quarter !== 0) { + value += Math.abs(obj.quarter) + BI.i18nText("BI-Basic_Single_Quarter") + (obj.quarter < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Year"), obj.position); + } + if(BI.isNotNull(obj.month) && obj.month !== 0) { + value += Math.abs(obj.month) + BI.i18nText("BI-Basic_Month") + (obj.month < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Month"), obj.position); + } + if(BI.isNotNull(obj.week) && obj.week !== 0) { + value += Math.abs(obj.week) + BI.i18nText("BI-Basic_Week") + (obj.week < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Week"), obj.position); + } + if(BI.isNotNull(obj.day) && obj.day !== 0) { + value += Math.abs(obj.day) + BI.i18nText("BI-Basic_Day") + (obj.day < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + BI.size(obj) === 1 ? getPositionText(BI.i18nText("BI-Basic_Month"), obj.position) : ""; + } + if(BI.isNotNull(obj.workDay) && obj.workDay !== 0) { + value += Math.abs(obj.workDay) + BI.i18nText("BI-Basic_Work_Day") + (obj.workDay < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + return value; + + function getPositionText (baseText, position) { + switch (position) { + case BI.DynamicDateCard.OFFSET.BEGIN: + return baseText + BI.i18nText("BI-Basic_Begin_Start"); + case BI.DynamicDateCard.OFFSET.END: + return baseText + BI.i18nText("BI-Basic_End_Stop"); + case BI.DynamicDateCard.OFFSET.CURRENT: + default: + return BI.i18nText("BI-Basic_Current_Day"); + } + } + }, + + setValue: function (v) { + var type, value, self = this; + var date = BI.getDate(); + this.storeValue = v; + if (BI.isNotNull(v)) { + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; + } + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = this._getText(value); + date = BI.DynamicDateHelper.getCalculation(value); + this._setInnerValue(date, text); + break; + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + this.editor.setState(""); + this.editor.setValue(""); + this.setTitle(""); + } else { + var dateStr = value.year + "-" + (value.month + 1) + "-" + value.day; + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(dateStr); + } + break; + } + }, + + getKey: function () { + return this.editor.getValue(); + }, + getValue: function () { + return this.storeValue; + } + +}); + +BI.DynamicDateTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateTrigger.EVENT_START = "EVENT_START"; +BI.DynamicDateTrigger.EVENT_STOP = "EVENT_STOP"; +BI.DynamicDateTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTrigger.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.DynamicDateTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.shortcut("bi.dynamic_date_trigger", BI.DynamicDateTrigger);BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { + constants: { + popupHeight: 259, + popupWidth: 270, + comboAdjustHeight: 1, + border: 1, + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" + }, + + props: { + baseCls: "bi-dynamic-date-combo bi-border", + height: 24 + }, + + + render: function () { + var self = this, opts = this.options; + this.storeTriggerValue = ""; + var date = BI.getDate(); + this.storeValue = opts.value; + return { + type: "bi.htape", + items: [{ + el: { + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, + ref: function () { + self.changeIcon = this; + } + }, + width: 24 + }, { + type: "bi.absolute", + items: [{ + el: { + type: "bi.combo", + ref: function () { + self.combo = this; + }, + toggle: false, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: { + type: "bi.dynamic_date_time_trigger", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.trigger = this; + }, + listeners: [{ + eventName: BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN, + action: function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_STOP, + action: function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_TRIGGER_CLICK, + action: function () { + self.combo.toggle(); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_FOCUS, + action: function () { + self.storeTriggerValue = self.trigger.getKey(); + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_FOCUS); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_ERROR, + action: function () { + self.storeValue = { + year: date.getFullYear(), + month: date.getMonth() + }; + self.popup.setValue(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_ERROR); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_VALID, + action: function () { + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_VALID); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CHANGE); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_CONFIRM, + action: function () { + if (self.combo.isViewVisible()) { + return; + } + var dateStore = self.storeTriggerValue; + var dateObj = self.trigger.getKey(); + if (BI.isNotEmptyString(dateObj) && !BI.isEqual(dateObj, dateStore)) { + self.storeValue = self.trigger.getValue(); + self.setValue(self.trigger.getValue()); + } else if (BI.isEmptyString(dateObj)) { + self.storeValue = null; + self.trigger.setValue(); + } + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }] + }, + adjustLength: this.constants.comboAdjustHeight, + popup: { + el: { + type: "bi.dynamic_date_time_popup", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate(), + hour: 0, + minute: 0, + second: 0 + }); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDateTimePopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }] + }, + stopPropagation: false + }, + listeners: [{ + eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, + action: function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW); + } + }] + }, + top: 0, + left: 0, + right: 0, + bottom: 0 + }, { + el: { + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-font", + width: 24, + height: 24, + listeners: [{ + eventName: BI.IconButton.EVENT_CHANGE, + action: function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } else { + self.combo.showView(); + } + } + }] + }, + top: 0, + right: 0 + }] + }], + ref: function (_ref) { + self.comboWrapper = _ref; + } + }; + }, + + mounted: function () { + this._checkDynamicValue(this.options.value); + }, + + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicDateTimeCombo.Dynamic: + this.changeIcon.setVisible(true); + this.comboWrapper.attr("items")[0].width = 24; + this.comboWrapper.resize(); + break; + default: + this.comboWrapper.attr("items")[0].width = 0; + this.comboWrapper.resize(); + this.changeIcon.setVisible(false); + break; + } + }, + + setValue: function (v) { + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); + }, + getValue: function () { + return this.storeValue; + }, + getKey: function () { + return this.trigger.getKey(); + }, + hidePopupView: function () { + this.combo.hideView(); + } +}); + +BI.DynamicDateTimeCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateTimeCombo.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateTimeCombo.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTimeCombo.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateTimeCombo.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + +BI.shortcut("bi.dynamic_date_time_combo", BI.DynamicDateTimeCombo); + +BI.extend(BI.DynamicDateTimeCombo, { + Static: 1, + Dynamic: 2 +});BI.DynamicDateTimePopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 + }, + + props: { + baseCls: "bi-dynamic-date-time-popup", + width: 248, + height: 385 + }, + + _init: function () { + BI.DynamicDateTimePopup.superclass._init.apply(this, arguments); + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicDateCombo.Static}; + BI.createWidget({ + element: this, + type: "bi.vtape", + items: [{ + el: this._getTabJson() + }, { + el: { + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-high-light bi-border-top", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-left bi-border-right bi-border-top", + shadow: true, + text: BI.i18nText("BI-Multi_Date_Today"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-high-light bi-border-top", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 + }] + }); + this.setValue(opts.value); + }, + + _getTabJson: function () { + var self = this; + return { + type: "bi.tab", + showIndex: BI.DynamicDateCombo.Static, + ref: function () { + self.dateTab = this; + }, + tab: { + type: "bi.linear_segment", + cls: "bi-border-bottom", + height: this.constants.tabHeight, + items: BI.createItems([{ + text: BI.i18nText("BI-Multi_Date_YMD"), + value: BI.DynamicDateCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDateCombo.Dynamic + }], { + textAlign: "center" + }) + }, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDateCombo.Dynamic: + return { + type: "bi.dynamic_date_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicDateCombo.Static: + default: + return { + type: "bi.vtape", + items: [{ + type: "bi.date_calendar_popup", + min: self.options.min, + max: self.options.max, + ref: function () { + self.ymd = this; + } + }, { + el: { + type: "bi.dynamic_date_time_select", + ref: function () { + self.timeSelect = this; + }, + listeners: [{ + eventName: BI.DynamicDateTimeSelect.EVENT_CONFIRM, + action: function () { + + } + }] + }, + height: 40 + }] + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicDateCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + self.timeSelect.setValue(); + self._setInnerValue(); + break; + case BI.DynamicDateCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicDateCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; + }, + + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y-%x-%e"); + this.textButton.setValue(date); + this.textButton.setEnable(false); + } + }, + + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + }, + + setValue: function (v) { + this.storeValue = v; + var self = this; + var type, value; + v = v || {}; + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateCombo.Dynamic: + this.dynamicPane.setValue(value); + self._setInnerValue(); + break; + case BI.DynamicDateCombo.Static: + default: + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + this.timeSelect.setValue(); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } else { + this.ymd.setValue(value); + this.timeSelect.setValue({ + hour: value.hour, + minute: value.minute, + second: value.second + }); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } + this.textButton.setEnable(true); + break; + } + }, + + getValue: function () { + var type = this.dateTab.getSelect(); + return { + type: type, + value: type === BI.DynamicDateTimeCombo.Static ? BI.extend(this.ymd.getValue(), this.timeSelect.getValue()) : this.dynamicPane.getValue() + }; + } +}); +BI.DynamicDateTimePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.shortcut("bi.dynamic_date_time_popup", BI.DynamicDateTimePopup);BI.DynamicDateTimeSelect = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-date-time-select bi-border-top" + }, + + render: function () { + var self = this; + return { + type: "bi.center_adapt", + items: [{ + type: "bi.vertical_adapt", + items: [{ + el: { + type: "bi.number_editor", + ref: function () { + self.hour = this; + }, + validationChecker: function (v) { + return BI.isNaturalNumber(v) && BI.parseInt(v) < 24; + }, + errorText: function () { + return BI.i18nText("BI-Basic_Input_From_To_Number", "\"00-23\""); + }, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + this.setValue(self._formatValueToDoubleDigit(this.getValue())); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }, { + eventName: BI.SignEditor.EVENT_CHANGE, + action: function () { + var value = self._autoSwitch(this.getValue(), BI.DynamicDateTimeSelect.HOUR); + this.setValue(value); + } + }], + width: 60, + height: 24 + }, + lgap: 14 + }, { + type: "bi.label", + text: ":", + width: 20 + }, { + type: "bi.number_editor", + ref: function () { + self.minute = this; + }, + validationChecker: function (v) { + return BI.isNaturalNumber(v) && BI.parseInt(v) < 60; + }, + errorText: function () { + return BI.i18nText("BI-Basic_Input_From_To_Number", "\"00-59\""); + }, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + this.setValue(self._formatValueToDoubleDigit(this.getValue()), BI.DynamicDateTimeSelect.MINUTE); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }, { + eventName: BI.SignEditor.EVENT_CHANGE, + action: function () { + var value = self._autoSwitch(this.getValue(), BI.DynamicDateTimeSelect.MINUTE); + this.setValue(value); + } + }], + width: 60, + height: 24 + }, { + type: "bi.label", + text: ":", + width: 20 + }, { + type: "bi.number_editor", + ref: function () { + self.second = this; + }, + validationChecker: function (v) { + return BI.isNaturalNumber(v) && BI.parseInt(v) < 60; + }, + errorText: function () { + return BI.i18nText("BI-Basic_Input_From_To_Number", "\"00-59\""); + }, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + this.setValue(self._formatValueToDoubleDigit(this.getValue())); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }], + width: 60, + height: 24 + }] + }] + }; + }, + + _autoSwitch: function (v, type) { + var limit = 0; + var value = v; switch (type) { - case BI.DynamicDateCombo.Dynamic: - this.dynamicPane.setValue(value); - self._setInnerValue(); + case BI.DynamicDateTimeSelect.HOUR: + limit = 2; + break; + case BI.DynamicDateTimeSelect.MINUTE: + limit = 6; break; - case BI.DynamicDateCombo.Static: default: - if (this._checkValueValid(value)) { - var date = BI.getDate(); - this.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } else { - this.ymd.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } - this.textButton.setEnable(true); break; } + if(v.length === 1 && BI.parseInt(v) > limit) { + value = "0" + value; + } + if (value.length === 2) { + type === BI.DynamicDateTimeSelect.HOUR ? this.minute.focus() : this.second.focus(); + } + return value; + }, + + _formatValueToDoubleDigit: function (v) { + if(BI.isNull(v) || BI.isEmptyString(v)) { + v = 0; + } + var value = BI.parseInt(v); + if(value < 10) { + value = "0" + value; + } + return value; + }, + + _assertValue: function (v) { + v = v || {}; + v.hour = this._formatValueToDoubleDigit(v.hour) || "00"; + v.minute = this._formatValueToDoubleDigit(v.minute) || "00"; + v.second = this._formatValueToDoubleDigit(v.second) || "00"; + return v; }, getValue: function () { return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() + hour: BI.parseInt(this.hour.getValue()), + minute: BI.parseInt(this.minute.getValue()), + second: BI.parseInt(this.second.getValue()) }; + }, + + setValue: function (v) { + v = this._assertValue(v); + this.hour.setValue(v.hour); + this.minute.setValue(v.minute); + this.second.setValue(v.second); } + }); -BI.DynamicDatePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { +BI.DynamicDateTimeSelect.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.shortcut("bi.dynamic_date_time_select", BI.DynamicDateTimeSelect); + +BI.extend(BI.DynamicDateTimeSelect, { + HOUR: 1, + MINUTE: 2 +});BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { _const: { hgap: 4, vgap: 2, @@ -92640,14 +93792,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger }, props: { - extraCls: "bi-date-trigger", + extraCls: "bi-date-time-trigger", min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24 }, _init: function () { - BI.DynamicDateTrigger.superclass._init.apply(this, arguments); + BI.DynamicDateTimeTrigger.superclass._init.apply(this, arguments); var self = this, o = this.options, c = this._const; this.editor = BI.createWidget({ type: "bi.sign_editor", @@ -92670,25 +93822,25 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger watermark: BI.i18nText("BI-Basic_Unrestricted"), errorText: function () { if (self.editor.isEditing()) { - return BI.i18nText("BI-Date_Trigger_Error_Text"); + return BI.i18nText("BI-Basic_Date_Time_Error_Text"); } return BI.i18nText("BI-Year_Trigger_Invalid_Text"); } }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN); }); this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_FOCUS); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_FOCUS); }); this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_STOP); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_STOP); }); this.editor.on(BI.SignEditor.EVENT_VALID, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_VALID); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_VALID); }); this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_ERROR); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_ERROR); }); this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { var value = self.editor.getValue(); @@ -92697,28 +93849,26 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger } if (BI.isNotEmptyString(value)) { - var date = value.split("-"); + var date = value.split(/-|\s|:/); self.storeValue = { type: BI.DynamicDateCombo.Static, value: { year: date[0] | 0, month: date[1] - 1, - day: date[2] | 0 + day: date[2] | 0, + hour: date[3] | 0, + minute: date[4] | 0, + second: date[5] | 0 } }; } - self.fireEvent(BI.DynamicDateTrigger.EVENT_CONFIRM); - }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); - } + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_CONFIRM); }); this.editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_START); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_START); }); this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_CHANGE); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_CHANGE); }); BI.createWidget({ type: "bi.htape", @@ -92733,7 +93883,12 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger this.setValue(o.value); }, _dateCheck: function (date) { - return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || + return BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S").print("%Y-%x-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%x-%e %H:%M:%S").print("%Y-%x-%e %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%e %H:%M:%S").print("%Y-%X-%e %H:%M:%S") === date || + + BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") === date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") === date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") === date; @@ -92769,7 +93924,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger }, _setInnerValue: function (date, text) { - var dateStr = date.print("%Y-%x-%e"); + var dateStr = date.print("%Y-%x-%e %H:%M:%S"); this.editor.setState(dateStr); this.editor.setValue(dateStr); this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); @@ -92831,7 +93986,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger this.editor.setValue(""); this.setTitle(""); } else { - var dateStr = value.year + "-" + (value.month + 1) + "-" + value.day; + var dateStr = value.year + "-" + (value.month + 1) + "-" + value.day + " " + + (value.hour || "00") + ":" + (value.minute || "00") + ":" + (value.second || "00"); this.editor.setState(dateStr); this.editor.setValue(dateStr); this.setTitle(dateStr); @@ -92849,16 +94005,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger }); -BI.DynamicDateTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DynamicDateTrigger.EVENT_START = "EVENT_START"; -BI.DynamicDateTrigger.EVENT_STOP = "EVENT_STOP"; -BI.DynamicDateTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicDateTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.DynamicDateTrigger.EVENT_VALID = "EVENT_VALID"; -BI.DynamicDateTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.DynamicDateTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; -BI.DynamicDateTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; -BI.shortcut("bi.dynamic_date_trigger", BI.DynamicDateTrigger);/** +BI.DynamicDateTimeTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateTimeTrigger.EVENT_START = "EVENT_START"; +BI.DynamicDateTimeTrigger.EVENT_STOP = "EVENT_STOP"; +BI.DynamicDateTimeTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateTimeTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTimeTrigger.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateTimeTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateTimeTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.shortcut("bi.dynamic_date_time_trigger", BI.DynamicDateTimeTrigger);/** * Created by roy on 15/9/14. */ BI.SearchEditor = BI.inherit(BI.Widget, { @@ -101574,6 +102730,10 @@ BI.NumberEditor = BI.inherit(BI.Widget, { }); }, + focus: function () { + this.editor.focus(); + }, + // 微调 _finetuning: function (add) { var v = BI.parseFloat(this.getValue()); @@ -108019,6 +109179,184 @@ BI.shortcut("bi.switch_tree", BI.SwitchTree); /** * Created by Baron on 2015/10/19. */ +BI.DateInterval = BI.inherit(BI.Single, { + constants: { + height: 25, + width: 25, + lgap: 15, + offset: -15, + timeErrorCls: "time-error", + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" + }, + _defaultConfig: function () { + var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-date-interval" + }); + }, + _init: function () { + var self = this, o = this.options; + BI.DateInterval.superclass._init.apply(this, arguments); + + o.value = o.value || {}; + this.left = this._createCombo(o.value.start); + this.right = this._createCombo(o.value.end); + this.label = BI.createWidget({ + type: "bi.label", + height: this.constants.height, + width: this.constants.width, + text: "-" + }); + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, + items: [{ + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: this.constants.offset, + top: 0, + bottom: 0 + }] + }] + }); + BI.createWidget({ + type: "bi.horizontal_auto", + element: this, + items: [ + self.label + ] + }); + }, + + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_date_combo", + value: v + }); + combo.on(BI.DynamicDateCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + }); + + combo.on(BI.DynamicDateCombo.EVENT_VALID, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicDateCombo.EVENT_FOCUS, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hidePopupView(); + self.right.hidePopupView(); + }); + + combo.on(BI.DynamicDateCombo.EVENT_CONFIRM, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + }else{ + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_CHANGE); + } + }); + return combo; + }, + _dateCheck: function (date) { + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || + BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") === date || + BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") === date || + BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") === date; + }, + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + }, + _check: function (smallDate, bigDate) { + var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ + year: smallObj[0], + month: smallObj[1], + day: smallObj[2] + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ + year: bigObj[0], + month: bigObj[1], + day: bigObj[2] + }); + }, + _compare: function (smallDate, bigDate) { + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; + }, + _setTitle: function (v) { + this.left.setTitle(v); + this.right.setTitle(v); + this.label.setTitle(v); + }, + _clearTitle: function () { + this.left.setTitle(""); + this.right.setTitle(""); + this.label.setTitle(""); + }, + setValue: function (date) { + date = date || {}; + this.left.setValue(date.start); + this.right.setValue(date.end); + }, + getValue: function () { + return {start: this.left.getValue(), end: this.right.getValue()}; + } +}); +BI.DateInterval.EVENT_VALID = "EVENT_VALID"; +BI.DateInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.DateInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.date_interval", BI.DateInterval);/** + * Created by Baron on 2015/10/19. + */ BI.TimeInterval = BI.inherit(BI.Single, { constants: { height: 25, @@ -108085,16 +109423,16 @@ BI.TimeInterval = BI.inherit(BI.Single, { _createCombo: function (v) { var self = this; var combo = BI.createWidget({ - type: "bi.dynamic_date_combo", + type: "bi.dynamic_date_time_combo", value: v }); - combo.on(BI.MultiDateCombo.EVENT_ERROR, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); self.fireEvent(BI.TimeInterval.EVENT_ERROR); }); - combo.on(BI.MultiDateCombo.EVENT_VALID, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_VALID, function () { BI.Bubbles.hide("error"); var smallDate = self.left.getKey(), bigDate = self.right.getKey(); if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -108110,7 +109448,7 @@ BI.TimeInterval = BI.inherit(BI.Single, { } }); - combo.on(BI.MultiDateCombo.EVENT_FOCUS, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_FOCUS, function () { BI.Bubbles.hide("error"); var smallDate = self.left.getKey(), bigDate = self.right.getKey(); if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -108126,11 +109464,11 @@ BI.TimeInterval = BI.inherit(BI.Single, { } }); - combo.on(BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW, function () { self.left.hidePopupView(); self.right.hidePopupView(); }); - // combo.on(BI.MultiDateCombo.EVENT_CHANGE, function () { + // combo.on(BI.DynamicDateTimeCombo.EVENT_CHANGE, function () { // BI.Bubbles.hide("error"); // var smallDate = self.left.getKey(), bigDate = self.right.getKey(); // if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -108146,7 +109484,7 @@ BI.TimeInterval = BI.inherit(BI.Single, { // } // }); - combo.on(BI.MultiDateCombo.EVENT_CONFIRM, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_CONFIRM, function () { BI.Bubbles.hide("error"); var smallDate = self.left.getKey(), bigDate = self.right.getKey(); if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -108162,7 +109500,10 @@ BI.TimeInterval = BI.inherit(BI.Single, { return combo; }, _dateCheck: function (date) { - return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S").print("%Y-%x-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%x-%e %H:%M:%S").print("%Y-%x-%e %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%e %H:%M:%S").print("%Y-%X-%e %H:%M:%S") === date; }, _checkVoid: function (obj) { return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; @@ -108180,8 +109521,8 @@ BI.TimeInterval = BI.inherit(BI.Single, { }); }, _compare: function (smallDate, bigDate) { - smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); - bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S"); return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; }, _setTitle: function (v) { @@ -110747,5 +112088,7 @@ BI.i18n = { "BI-Basic_Current_Quarter": "本季度", "BI-Basic_Year_Month": "年月", "BI-Basic_Year_Quarter": "年季度", - "BI-Basic_Input_Can_Not_Null": "输入框不能为空" + "BI-Basic_Input_From_To_Number": "请输入{R1}的数值", + "BI-Basic_Input_Can_Not_Null": "输入框不能为空", + "BI-Basic_Date_Time_Error_Text": "日期格式示例:2015-3-11 00:00:00" }; \ No newline at end of file diff --git a/dist/config.js b/dist/config.js index 9c65a2d7aa..b2e2b9a589 100644 --- a/dist/config.js +++ b/dist/config.js @@ -146,5 +146,7 @@ BI.i18n = { "BI-Basic_Current_Quarter": "本季度", "BI-Basic_Year_Month": "年月", "BI-Basic_Year_Quarter": "年季度", - "BI-Basic_Input_Can_Not_Null": "输入框不能为空" + "BI-Basic_Input_Can_Not_Null": "输入框不能为空", + "BI-Basic_Input_From_To_Number": "请输入{R1}的数值", + "BI-Basic_Date_Time_Error_Text": "日期格式示例:2015-3-11 00:00:00" }; \ No newline at end of file diff --git a/dist/demo.js b/dist/demo.js index fa5c315a4d..3933fd8ca4 100644 --- a/dist/demo.js +++ b/dist/demo.js @@ -12110,6 +12110,29 @@ BI.shortcut("demo.tips", Demo.Tips);Demo.DatePane = BI.inherit(BI.Widget, { handler: function () { BI.Msg.toast("date" + JSON.stringify(self.datepane.getValue())); } + }, { + type: "bi.dynamic_date_time_pane", + value: { + type: 1, + value: { + year: 2017, + month: 11, + day: 11, + hour: 12, + minute: 12, + second: 12 + } + }, + ref: function (_ref) { + self.dateTimePane = _ref; + }, + height: 340 + }, { + type: "bi.button", + text: "getValue", + handler: function () { + BI.Msg.toast("date" + JSON.stringify(self.dateTimePane.getValue())); + } }, { type: "bi.button", text: "setValue '2017-12-31'", @@ -12148,7 +12171,7 @@ Demo.Date = BI.inherit(BI.Widget, { var self = this; return { type: "bi.horizontal_auto", - vgap: 10, + vgap: 20, items: [{ type: "bi.dynamic_date_combo", ref: function () { @@ -12156,31 +12179,44 @@ Demo.Date = BI.inherit(BI.Widget, { }, width: 300, value: { - year: 2018, - month: 1, - day: 23 + type: 1, + value: { + year: 2018, + month: 1, + day: 23 + } } }, { - type: "bi.multidate_combo", + type: "bi.button", + text: "getValue", + width: 300, + handler: function () { + BI.Msg.alert("date", JSON.stringify(self.datecombo.getValue())); + } + }, { + type: "bi.dynamic_date_time_combo", ref: function () { - self.datecombo = this; + self.datetimecombo = this; }, width: 300, value: { - year: 2018, - month: 1, - day: 23 + type: 1, + value: { + year: 2018, + month: 1, + day: 23 + } } }, { type: "bi.button", - text: "getVlaue", + text: "getValue", width: 300, handler: function () { - BI.Msg.alert("date", JSON.stringify(self.datecombo.getValue())); + BI.Msg.alert("date", JSON.stringify(self.datetimecombo.getValue())); } }, { type: "bi.button", - text: "setVlaue '2017-12-31'", + text: "setValue '2017-12-31'", width: 300, handler: function () { self.datecombo.setValue({ @@ -14145,6 +14181,36 @@ Demo.TimeInterval = BI.inherit(BI.Widget, { return { type: "bi.horizontal_auto", items: [{ + type: "bi.date_interval", + ref: function (_ref) { + self.dateInterval = _ref; + }, + value: { + start: { + type: 2, + value: { + year: -1, + position: 2 + } + }, + end: { + type: 1, + value: { + year: 2018, + month: 0, + day: 12 + } + } + }, + width: 300 + }, { + type: "bi.button", + text: "getValue", + handler: function () { + BI.Msg.toast(JSON.stringify(self.dateInterval.getValue())); + }, + width: 300 + }, { type: "bi.time_interval", ref: function (_ref) { self.interval = _ref; @@ -14166,10 +14232,10 @@ Demo.TimeInterval = BI.inherit(BI.Widget, { } } }, - width: 300 + width: 400 }, { type: "bi.button", - text: "getVlaue", + text: "getValue", handler: function () { BI.Msg.toast(JSON.stringify(self.interval.getValue())); }, diff --git a/dist/fineui.css b/dist/fineui.css index 9f5d7719a0..c6bd67c56e 100644 --- a/dist/fineui.css +++ b/dist/fineui.css @@ -5088,10 +5088,21 @@ ul.ztree.zTreeDragUL { -moz-border-radius: 3px; border-radius: 3px; } -.bi-time-interval.time-error .bi-input { +.bi-date-interval.time-error .bi-input { color: #ff4949; } -.bi-time-interval.time-error .sign-editor-text { +.bi-date-interval.time-error .sign-editor-text { + color: #ff4949; +} +.bi-time-interval .bi-date-time-trigger { + -webkit-border-radius: 2px; + -moz-border-radius: 2px; + border-radius: 2px; +} +.bi-time-interval.time-error .bi-date-time-trigger .bi-input { + color: #ff4949; +} +.bi-time-interval.time-error .bi-date-time-trigger .sign-editor-text { color: #ff4949; } .bi-year-popup .year-popup-navigation { diff --git a/dist/widget.css b/dist/widget.css index 241b48e971..ca86d4eb2f 100644 --- a/dist/widget.css +++ b/dist/widget.css @@ -612,10 +612,21 @@ -moz-border-radius: 3px; border-radius: 3px; } -.bi-time-interval.time-error .bi-input { +.bi-date-interval.time-error .bi-input { color: #ff4949; } -.bi-time-interval.time-error .sign-editor-text { +.bi-date-interval.time-error .sign-editor-text { + color: #ff4949; +} +.bi-time-interval .bi-date-time-trigger { + -webkit-border-radius: 2px; + -moz-border-radius: 2px; + border-radius: 2px; +} +.bi-time-interval.time-error .bi-date-time-trigger .bi-input { + color: #ff4949; +} +.bi-time-interval.time-error .bi-date-time-trigger .sign-editor-text { color: #ff4949; } .bi-year-popup .year-popup-navigation { diff --git a/dist/widget.js b/dist/widget.js index 83b9dc386c..b24093c2d7 100644 --- a/dist/widget.js +++ b/dist/widget.js @@ -2788,6 +2788,274 @@ BI.shortcut("bi.dynamic_date_pane", BI.DynamicDatePane); BI.extend(BI.DynamicDatePane, { Static: 1, Dynamic: 2 +});BI.StaticDateTimePaneCard = BI.inherit(BI.Widget, { + _defaultConfig: function () { + var conf = BI.StaticDateTimePaneCard.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: "bi-date-time-pane", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + selectedTime: null + }); + }, + _init: function () { + BI.StaticDateTimePaneCard.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.today = BI.getDate(); + this._year = this.today.getFullYear(); + this._month = this.today.getMonth(); + + this.selectedTime = o.selectedTime || { + year: this._year, + month: this._month + }; + + this.datePicker = BI.createWidget({ + type: "bi.date_picker", + min: o.min, + max: o.max + }); + this.datePicker.on(BI.DatePicker.EVENT_CHANGE, function () { + self.selectedTime = BI.extend(self.datePicker.getValue(), self.timeSelect.getValue()); + self.calendar.setSelect(BI.Calendar.getPageByDateJSON(self.selectedTime)); + }); + + this.calendar = BI.createWidget({ + direction: "top", + logic: { + dynamic: false + }, + type: "bi.navigation", + tab: this.datePicker, + cardCreator: BI.bind(this._createNav, this) + }); + this.calendar.on(BI.Navigation.EVENT_CHANGE, function () { + self.selectedTime = BI.extend(self.calendar.getValue(), self.timeSelect.getValue()); + self.calendar.empty(); + self.setValue(self.selectedTime); + self.fireEvent(BI.DateCalendarPopup.EVENT_CHANGE); + }); + + BI.createWidget({ + type: "bi.vtape", + element: this, + items: [this.calendar, { + el: { + type: "bi.dynamic_date_time_select", + ref: function () { + self.timeSelect = this; + } + }, + height: 40 + }] + }); + this.setValue(o.selectedTime); + + }, + + _createNav: function (v) { + var date = BI.Calendar.getDateJSONByPage(v); + var calendar = BI.createWidget({ + type: "bi.calendar", + logic: { + dynamic: false + }, + min: this.options.min, + max: this.options.max, + year: date.year, + month: date.month, + day: this.selectedTime.day + }); + return calendar; + }, + + _getNewCurrentDate: function () { + var today = BI.getDate(); + return { + year: today.getFullYear(), + month: today.getMonth() + }; + }, + + _setCalenderValue: function (date) { + this.calendar.setSelect(BI.Calendar.getPageByDateJSON(date)); + this.calendar.setValue(date); + this.selectedTime = BI.extend(date, this.timeSelect.getValue()); + }, + + _setDatePicker: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.year) || BI.isNull(timeOb.month)) { + this.datePicker.setValue(this._getNewCurrentDate()); + } else { + this.datePicker.setValue(timeOb); + } + }, + + _setCalendar: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { + this.calendar.empty(); + this._setCalenderValue(this._getNewCurrentDate()); + } else { + this._setCalenderValue(timeOb); + } + }, + + setValue: function (timeOb) { + timeOb = timeOb || {}; + this._setDatePicker(timeOb); + this._setCalendar(timeOb); + this.timeSelect.setValue({ + hour: timeOb.hour, + minute: timeOb.minute, + second: timeOb.second + }); + }, + + getValue: function () { + return this.selectedTime; + } + +}); +BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.DynamicDateTimePane = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-dynamic-date-pane" + }, + + render: function () { + var self = this; + return { + type: "bi.vtape", + items: [{ + el: { + type: "bi.linear_segment", + cls: "bi-border-bottom", + height: 30, + items: BI.createItems([{ + text: BI.i18nText("BI-Multi_Date_YMD"), + value: BI.DynamicDateTimePane.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDateTimePane.Dynamic + }], { + textAlign: "center" + }), + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + var value = this.getValue()[0]; + self.dateTab.setSelect(value); + switch (value) { + case BI.DynamicDateTimePane.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + break; + case BI.DynamicDateTimePane.Dynamic: + self.dynamicPane.setValue({ + year: 0 + }); + break; + default: + break; + } + } + }], + ref: function () { + self.switch = this; + } + }, + height: 30 + }, { + type: "bi.tab", + ref: function () { + self.dateTab = this; + }, + showIndex: BI.DynamicDateTimePane.Static, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDateTimePane.Static: + return { + type: "bi.static_date_time_pane_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.ymd = this; + } + }; + case BI.DynamicDateTimePane.Dynamic: + default: + return { + type: "bi.dynamic_date_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + } + } + }] + }; + }, + + mounted: function () { + this.setValue(this.options.value); + }, + + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + }, + + setValue: function (v) { + v = v || {}; + var type = v.type || BI.DynamicDateTimePane.Static; + var value = v.value || v; + this.switch.setValue(type); + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateTimePane.Dynamic: + this.dynamicPane.setValue(value); + break; + case BI.DynamicDateTimePane.Static: + default: + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth() + }); + } else { + this.ymd.setValue(value); + } + break; + } + }, + + getValue: function () { + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; + } +}); +BI.shortcut("bi.dynamic_date_time_pane", BI.DynamicDateTimePane); + +BI.extend(BI.DynamicDateTimePane, { + Static: 1, + Dynamic: 2 });/** * 年份展示面板 * @@ -5916,50 +6184,934 @@ BI.shortcut("bi.dynamic_date_param_item", BI.DynamicDateParamItem);BI.DynamicDat return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, - setValue: function (v) { - this.storeValue = v; - var self = this; - var type, value; - v = v || {}; - type = v.type || BI.DynamicDateCombo.Static; - value = v.value || v; - this.dateTab.setSelect(type); + setValue: function (v) { + this.storeValue = v; + var self = this; + var type, value; + v = v || {}; + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateCombo.Dynamic: + this.dynamicPane.setValue(value); + self._setInnerValue(); + break; + case BI.DynamicDateCombo.Static: + default: + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } else { + this.ymd.setValue(value); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } + this.textButton.setEnable(true); + break; + } + }, + + getValue: function () { + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; + } +}); +BI.DynamicDatePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + yearLength: 4, + yearMonthLength: 7 + }, + + props: { + extraCls: "bi-date-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 + }, + + _init: function () { + BI.DynamicDateTrigger.superclass._init.apply(this, arguments); + var self = this, o = this.options, c = this._const; + this.editor = BI.createWidget({ + type: "bi.sign_editor", + height: o.height, + validationChecker: function (v) { + var date = v.match(/\d+/g); + self._autoAppend(v, date); + return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ + year: date[0], + month: date[1], + day: date[2] + }); + }, + quitChecker: function () { + return false; + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + errorText: function () { + if (self.editor.isEditing()) { + return BI.i18nText("BI-Date_Trigger_Error_Text"); + } + return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + } + }); + this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); + }); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_FOCUS); + }); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_STOP); + }); + this.editor.on(BI.SignEditor.EVENT_VALID, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_VALID); + }); + this.editor.on(BI.SignEditor.EVENT_ERROR, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_ERROR); + }); + this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setState(value); + } + + if (BI.isNotEmptyString(value)) { + var date = value.split("-"); + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: date[0] | 0, + month: date[1] - 1, + day: date[2] | 0 + } + }; + } + self.fireEvent(BI.DynamicDateTrigger.EVENT_CONFIRM); + }); + this.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); + } + }); + this.editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_START); + }); + this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_CHANGE); + }); + BI.createWidget({ + type: "bi.htape", + element: this, + items: [{ + el: this.editor + }, { + el: BI.createWidget(), + width: 30 + }] + }); + this.setValue(o.value); + }, + _dateCheck: function (date) { + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || + BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") === date || + BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") === date || + BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") === date; + }, + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; + }, + _autoAppend: function (v, dateObj) { + if (BI.isNotNull(dateObj) && BI.checkDateLegal(v)) { + switch (v.length) { + case this._const.yearLength: + if (this._yearCheck(v)) { + this.editor.setValue(v + "-"); + } + break; + case this._const.yearMonthLength: + if (this._monthCheck(v)) { + this.editor.setValue(v + "-"); + } + break; + } + } + }, + + _yearCheck: function (v) { + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.parseDateTime(v, "%Y").print("%Y") === v && date >= this.options.min && date <= this.options.max; + }, + + _monthCheck: function (v) { + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.parseDateTime(v, "%Y-%X").print("%Y-%X") === v && date >= this.options.min && date <= this.options.max; + }, + + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y-%x-%e"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); + }, + + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year) && obj.year !== 0) { + value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Year"), obj.position); + } + if(BI.isNotNull(obj.quarter) && obj.quarter !== 0) { + value += Math.abs(obj.quarter) + BI.i18nText("BI-Basic_Single_Quarter") + (obj.quarter < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Year"), obj.position); + } + if(BI.isNotNull(obj.month) && obj.month !== 0) { + value += Math.abs(obj.month) + BI.i18nText("BI-Basic_Month") + (obj.month < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Month"), obj.position); + } + if(BI.isNotNull(obj.week) && obj.week !== 0) { + value += Math.abs(obj.week) + BI.i18nText("BI-Basic_Week") + (obj.week < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Week"), obj.position); + } + if(BI.isNotNull(obj.day) && obj.day !== 0) { + value += Math.abs(obj.day) + BI.i18nText("BI-Basic_Day") + (obj.day < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + BI.size(obj) === 1 ? getPositionText(BI.i18nText("BI-Basic_Month"), obj.position) : ""; + } + if(BI.isNotNull(obj.workDay) && obj.workDay !== 0) { + value += Math.abs(obj.workDay) + BI.i18nText("BI-Basic_Work_Day") + (obj.workDay < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + return value; + + function getPositionText (baseText, position) { + switch (position) { + case BI.DynamicDateCard.OFFSET.BEGIN: + return baseText + BI.i18nText("BI-Basic_Begin_Start"); + case BI.DynamicDateCard.OFFSET.END: + return baseText + BI.i18nText("BI-Basic_End_Stop"); + case BI.DynamicDateCard.OFFSET.CURRENT: + default: + return BI.i18nText("BI-Basic_Current_Day"); + } + } + }, + + setValue: function (v) { + var type, value, self = this; + var date = BI.getDate(); + this.storeValue = v; + if (BI.isNotNull(v)) { + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; + } + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = this._getText(value); + date = BI.DynamicDateHelper.getCalculation(value); + this._setInnerValue(date, text); + break; + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + this.editor.setState(""); + this.editor.setValue(""); + this.setTitle(""); + } else { + var dateStr = value.year + "-" + (value.month + 1) + "-" + value.day; + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(dateStr); + } + break; + } + }, + + getKey: function () { + return this.editor.getValue(); + }, + getValue: function () { + return this.storeValue; + } + +}); + +BI.DynamicDateTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateTrigger.EVENT_START = "EVENT_START"; +BI.DynamicDateTrigger.EVENT_STOP = "EVENT_STOP"; +BI.DynamicDateTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTrigger.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.DynamicDateTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.shortcut("bi.dynamic_date_trigger", BI.DynamicDateTrigger);BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { + constants: { + popupHeight: 259, + popupWidth: 270, + comboAdjustHeight: 1, + border: 1, + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" + }, + + props: { + baseCls: "bi-dynamic-date-combo bi-border", + height: 24 + }, + + + render: function () { + var self = this, opts = this.options; + this.storeTriggerValue = ""; + var date = BI.getDate(); + this.storeValue = opts.value; + return { + type: "bi.htape", + items: [{ + el: { + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, + ref: function () { + self.changeIcon = this; + } + }, + width: 24 + }, { + type: "bi.absolute", + items: [{ + el: { + type: "bi.combo", + ref: function () { + self.combo = this; + }, + toggle: false, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: { + type: "bi.dynamic_date_time_trigger", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.trigger = this; + }, + listeners: [{ + eventName: BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN, + action: function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_STOP, + action: function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_TRIGGER_CLICK, + action: function () { + self.combo.toggle(); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_FOCUS, + action: function () { + self.storeTriggerValue = self.trigger.getKey(); + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_FOCUS); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_ERROR, + action: function () { + self.storeValue = { + year: date.getFullYear(), + month: date.getMonth() + }; + self.popup.setValue(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_ERROR); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_VALID, + action: function () { + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_VALID); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CHANGE); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_CONFIRM, + action: function () { + if (self.combo.isViewVisible()) { + return; + } + var dateStore = self.storeTriggerValue; + var dateObj = self.trigger.getKey(); + if (BI.isNotEmptyString(dateObj) && !BI.isEqual(dateObj, dateStore)) { + self.storeValue = self.trigger.getValue(); + self.setValue(self.trigger.getValue()); + } else if (BI.isEmptyString(dateObj)) { + self.storeValue = null; + self.trigger.setValue(); + } + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }] + }, + adjustLength: this.constants.comboAdjustHeight, + popup: { + el: { + type: "bi.dynamic_date_time_popup", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate(), + hour: 0, + minute: 0, + second: 0 + }); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDateTimePopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }] + }, + stopPropagation: false + }, + listeners: [{ + eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, + action: function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW); + } + }] + }, + top: 0, + left: 0, + right: 0, + bottom: 0 + }, { + el: { + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-font", + width: 24, + height: 24, + listeners: [{ + eventName: BI.IconButton.EVENT_CHANGE, + action: function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } else { + self.combo.showView(); + } + } + }] + }, + top: 0, + right: 0 + }] + }], + ref: function (_ref) { + self.comboWrapper = _ref; + } + }; + }, + + mounted: function () { + this._checkDynamicValue(this.options.value); + }, + + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicDateTimeCombo.Dynamic: + this.changeIcon.setVisible(true); + this.comboWrapper.attr("items")[0].width = 24; + this.comboWrapper.resize(); + break; + default: + this.comboWrapper.attr("items")[0].width = 0; + this.comboWrapper.resize(); + this.changeIcon.setVisible(false); + break; + } + }, + + setValue: function (v) { + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); + }, + getValue: function () { + return this.storeValue; + }, + getKey: function () { + return this.trigger.getKey(); + }, + hidePopupView: function () { + this.combo.hideView(); + } +}); + +BI.DynamicDateTimeCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateTimeCombo.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateTimeCombo.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTimeCombo.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateTimeCombo.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + +BI.shortcut("bi.dynamic_date_time_combo", BI.DynamicDateTimeCombo); + +BI.extend(BI.DynamicDateTimeCombo, { + Static: 1, + Dynamic: 2 +});BI.DynamicDateTimePopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 + }, + + props: { + baseCls: "bi-dynamic-date-time-popup", + width: 248, + height: 385 + }, + + _init: function () { + BI.DynamicDateTimePopup.superclass._init.apply(this, arguments); + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicDateCombo.Static}; + BI.createWidget({ + element: this, + type: "bi.vtape", + items: [{ + el: this._getTabJson() + }, { + el: { + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-high-light bi-border-top", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-left bi-border-right bi-border-top", + shadow: true, + text: BI.i18nText("BI-Multi_Date_Today"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-high-light bi-border-top", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 + }] + }); + this.setValue(opts.value); + }, + + _getTabJson: function () { + var self = this; + return { + type: "bi.tab", + showIndex: BI.DynamicDateCombo.Static, + ref: function () { + self.dateTab = this; + }, + tab: { + type: "bi.linear_segment", + cls: "bi-border-bottom", + height: this.constants.tabHeight, + items: BI.createItems([{ + text: BI.i18nText("BI-Multi_Date_YMD"), + value: BI.DynamicDateCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDateCombo.Dynamic + }], { + textAlign: "center" + }) + }, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDateCombo.Dynamic: + return { + type: "bi.dynamic_date_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicDateCombo.Static: + default: + return { + type: "bi.vtape", + items: [{ + type: "bi.date_calendar_popup", + min: self.options.min, + max: self.options.max, + ref: function () { + self.ymd = this; + } + }, { + el: { + type: "bi.dynamic_date_time_select", + ref: function () { + self.timeSelect = this; + }, + listeners: [{ + eventName: BI.DynamicDateTimeSelect.EVENT_CONFIRM, + action: function () { + + } + }] + }, + height: 40 + }] + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicDateCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + self.timeSelect.setValue(); + self._setInnerValue(); + break; + case BI.DynamicDateCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicDateCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; + }, + + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y-%x-%e"); + this.textButton.setValue(date); + this.textButton.setEnable(false); + } + }, + + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + }, + + setValue: function (v) { + this.storeValue = v; + var self = this; + var type, value; + v = v || {}; + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateCombo.Dynamic: + this.dynamicPane.setValue(value); + self._setInnerValue(); + break; + case BI.DynamicDateCombo.Static: + default: + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + this.timeSelect.setValue(); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } else { + this.ymd.setValue(value); + this.timeSelect.setValue({ + hour: value.hour, + minute: value.minute, + second: value.second + }); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } + this.textButton.setEnable(true); + break; + } + }, + + getValue: function () { + var type = this.dateTab.getSelect(); + return { + type: type, + value: type === BI.DynamicDateTimeCombo.Static ? BI.extend(this.ymd.getValue(), this.timeSelect.getValue()) : this.dynamicPane.getValue() + }; + } +}); +BI.DynamicDateTimePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.shortcut("bi.dynamic_date_time_popup", BI.DynamicDateTimePopup);BI.DynamicDateTimeSelect = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-date-time-select bi-border-top" + }, + + render: function () { + var self = this; + return { + type: "bi.center_adapt", + items: [{ + type: "bi.vertical_adapt", + items: [{ + el: { + type: "bi.number_editor", + ref: function () { + self.hour = this; + }, + validationChecker: function (v) { + return BI.isNaturalNumber(v) && BI.parseInt(v) < 24; + }, + errorText: function () { + return BI.i18nText("BI-Basic_Input_From_To_Number", "\"00-23\""); + }, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + this.setValue(self._formatValueToDoubleDigit(this.getValue())); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }, { + eventName: BI.SignEditor.EVENT_CHANGE, + action: function () { + var value = self._autoSwitch(this.getValue(), BI.DynamicDateTimeSelect.HOUR); + this.setValue(value); + } + }], + width: 60, + height: 24 + }, + lgap: 14 + }, { + type: "bi.label", + text: ":", + width: 20 + }, { + type: "bi.number_editor", + ref: function () { + self.minute = this; + }, + validationChecker: function (v) { + return BI.isNaturalNumber(v) && BI.parseInt(v) < 60; + }, + errorText: function () { + return BI.i18nText("BI-Basic_Input_From_To_Number", "\"00-59\""); + }, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + this.setValue(self._formatValueToDoubleDigit(this.getValue()), BI.DynamicDateTimeSelect.MINUTE); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }, { + eventName: BI.SignEditor.EVENT_CHANGE, + action: function () { + var value = self._autoSwitch(this.getValue(), BI.DynamicDateTimeSelect.MINUTE); + this.setValue(value); + } + }], + width: 60, + height: 24 + }, { + type: "bi.label", + text: ":", + width: 20 + }, { + type: "bi.number_editor", + ref: function () { + self.second = this; + }, + validationChecker: function (v) { + return BI.isNaturalNumber(v) && BI.parseInt(v) < 60; + }, + errorText: function () { + return BI.i18nText("BI-Basic_Input_From_To_Number", "\"00-59\""); + }, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + this.setValue(self._formatValueToDoubleDigit(this.getValue())); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }], + width: 60, + height: 24 + }] + }] + }; + }, + + _autoSwitch: function (v, type) { + var limit = 0; + var value = v; switch (type) { - case BI.DynamicDateCombo.Dynamic: - this.dynamicPane.setValue(value); - self._setInnerValue(); + case BI.DynamicDateTimeSelect.HOUR: + limit = 2; + break; + case BI.DynamicDateTimeSelect.MINUTE: + limit = 6; break; - case BI.DynamicDateCombo.Static: default: - if (this._checkValueValid(value)) { - var date = BI.getDate(); - this.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } else { - this.ymd.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } - this.textButton.setEnable(true); break; } + if(v.length === 1 && BI.parseInt(v) > limit) { + value = "0" + value; + } + if (value.length === 2) { + type === BI.DynamicDateTimeSelect.HOUR ? this.minute.focus() : this.second.focus(); + } + return value; + }, + + _formatValueToDoubleDigit: function (v) { + if(BI.isNull(v) || BI.isEmptyString(v)) { + v = 0; + } + var value = BI.parseInt(v); + if(value < 10) { + value = "0" + value; + } + return value; + }, + + _assertValue: function (v) { + v = v || {}; + v.hour = this._formatValueToDoubleDigit(v.hour) || "00"; + v.minute = this._formatValueToDoubleDigit(v.minute) || "00"; + v.second = this._formatValueToDoubleDigit(v.second) || "00"; + return v; }, getValue: function () { return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() + hour: BI.parseInt(this.hour.getValue()), + minute: BI.parseInt(this.minute.getValue()), + second: BI.parseInt(this.second.getValue()) }; + }, + + setValue: function (v) { + v = this._assertValue(v); + this.hour.setValue(v.hour); + this.minute.setValue(v.minute); + this.second.setValue(v.second); } + }); -BI.DynamicDatePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { +BI.DynamicDateTimeSelect.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.shortcut("bi.dynamic_date_time_select", BI.DynamicDateTimeSelect); + +BI.extend(BI.DynamicDateTimeSelect, { + HOUR: 1, + MINUTE: 2 +});BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { _const: { hgap: 4, vgap: 2, @@ -5968,14 +7120,14 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger }, props: { - extraCls: "bi-date-trigger", + extraCls: "bi-date-time-trigger", min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24 }, _init: function () { - BI.DynamicDateTrigger.superclass._init.apply(this, arguments); + BI.DynamicDateTimeTrigger.superclass._init.apply(this, arguments); var self = this, o = this.options, c = this._const; this.editor = BI.createWidget({ type: "bi.sign_editor", @@ -5998,25 +7150,25 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger watermark: BI.i18nText("BI-Basic_Unrestricted"), errorText: function () { if (self.editor.isEditing()) { - return BI.i18nText("BI-Date_Trigger_Error_Text"); + return BI.i18nText("BI-Basic_Date_Time_Error_Text"); } return BI.i18nText("BI-Year_Trigger_Invalid_Text"); } }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN); }); this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_FOCUS); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_FOCUS); }); this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_STOP); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_STOP); }); this.editor.on(BI.SignEditor.EVENT_VALID, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_VALID); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_VALID); }); this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_ERROR); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_ERROR); }); this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { var value = self.editor.getValue(); @@ -6025,28 +7177,26 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger } if (BI.isNotEmptyString(value)) { - var date = value.split("-"); + var date = value.split(/-|\s|:/); self.storeValue = { type: BI.DynamicDateCombo.Static, value: { year: date[0] | 0, month: date[1] - 1, - day: date[2] | 0 + day: date[2] | 0, + hour: date[3] | 0, + minute: date[4] | 0, + second: date[5] | 0 } }; } - self.fireEvent(BI.DynamicDateTrigger.EVENT_CONFIRM); - }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); - } + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_CONFIRM); }); this.editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_START); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_START); }); this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.DynamicDateTrigger.EVENT_CHANGE); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_CHANGE); }); BI.createWidget({ type: "bi.htape", @@ -6061,7 +7211,12 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger this.setValue(o.value); }, _dateCheck: function (date) { - return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || + return BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S").print("%Y-%x-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%x-%e %H:%M:%S").print("%Y-%x-%e %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%e %H:%M:%S").print("%Y-%X-%e %H:%M:%S") === date || + + BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") === date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") === date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") === date; @@ -6097,7 +7252,7 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger }, _setInnerValue: function (date, text) { - var dateStr = date.print("%Y-%x-%e"); + var dateStr = date.print("%Y-%x-%e %H:%M:%S"); this.editor.setState(dateStr); this.editor.setValue(dateStr); this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); @@ -6159,7 +7314,8 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger this.editor.setValue(""); this.setTitle(""); } else { - var dateStr = value.year + "-" + (value.month + 1) + "-" + value.day; + var dateStr = value.year + "-" + (value.month + 1) + "-" + value.day + " " + + (value.hour || "00") + ":" + (value.minute || "00") + ":" + (value.second || "00"); this.editor.setState(dateStr); this.editor.setValue(dateStr); this.setTitle(dateStr); @@ -6177,16 +7333,16 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger }); -BI.DynamicDateTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DynamicDateTrigger.EVENT_START = "EVENT_START"; -BI.DynamicDateTrigger.EVENT_STOP = "EVENT_STOP"; -BI.DynamicDateTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicDateTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.DynamicDateTrigger.EVENT_VALID = "EVENT_VALID"; -BI.DynamicDateTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.DynamicDateTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; -BI.DynamicDateTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; -BI.shortcut("bi.dynamic_date_trigger", BI.DynamicDateTrigger);/** +BI.DynamicDateTimeTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateTimeTrigger.EVENT_START = "EVENT_START"; +BI.DynamicDateTimeTrigger.EVENT_STOP = "EVENT_STOP"; +BI.DynamicDateTimeTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateTimeTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTimeTrigger.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateTimeTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateTimeTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.shortcut("bi.dynamic_date_time_trigger", BI.DynamicDateTimeTrigger);/** * Created by roy on 15/9/14. */ BI.SearchEditor = BI.inherit(BI.Widget, { @@ -14902,6 +16058,10 @@ BI.NumberEditor = BI.inherit(BI.Widget, { }); }, + focus: function () { + this.editor.focus(); + }, + // 微调 _finetuning: function (add) { var v = BI.parseFloat(this.getValue()); @@ -21347,6 +22507,184 @@ BI.shortcut("bi.switch_tree", BI.SwitchTree); /** * Created by Baron on 2015/10/19. */ +BI.DateInterval = BI.inherit(BI.Single, { + constants: { + height: 25, + width: 25, + lgap: 15, + offset: -15, + timeErrorCls: "time-error", + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" + }, + _defaultConfig: function () { + var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-date-interval" + }); + }, + _init: function () { + var self = this, o = this.options; + BI.DateInterval.superclass._init.apply(this, arguments); + + o.value = o.value || {}; + this.left = this._createCombo(o.value.start); + this.right = this._createCombo(o.value.end); + this.label = BI.createWidget({ + type: "bi.label", + height: this.constants.height, + width: this.constants.width, + text: "-" + }); + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, + items: [{ + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: this.constants.offset, + top: 0, + bottom: 0 + }] + }] + }); + BI.createWidget({ + type: "bi.horizontal_auto", + element: this, + items: [ + self.label + ] + }); + }, + + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_date_combo", + value: v + }); + combo.on(BI.DynamicDateCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + }); + + combo.on(BI.DynamicDateCombo.EVENT_VALID, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicDateCombo.EVENT_FOCUS, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hidePopupView(); + self.right.hidePopupView(); + }); + + combo.on(BI.DynamicDateCombo.EVENT_CONFIRM, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + }else{ + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_CHANGE); + } + }); + return combo; + }, + _dateCheck: function (date) { + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || + BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") === date || + BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") === date || + BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") === date; + }, + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + }, + _check: function (smallDate, bigDate) { + var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ + year: smallObj[0], + month: smallObj[1], + day: smallObj[2] + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ + year: bigObj[0], + month: bigObj[1], + day: bigObj[2] + }); + }, + _compare: function (smallDate, bigDate) { + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; + }, + _setTitle: function (v) { + this.left.setTitle(v); + this.right.setTitle(v); + this.label.setTitle(v); + }, + _clearTitle: function () { + this.left.setTitle(""); + this.right.setTitle(""); + this.label.setTitle(""); + }, + setValue: function (date) { + date = date || {}; + this.left.setValue(date.start); + this.right.setValue(date.end); + }, + getValue: function () { + return {start: this.left.getValue(), end: this.right.getValue()}; + } +}); +BI.DateInterval.EVENT_VALID = "EVENT_VALID"; +BI.DateInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.DateInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.date_interval", BI.DateInterval);/** + * Created by Baron on 2015/10/19. + */ BI.TimeInterval = BI.inherit(BI.Single, { constants: { height: 25, @@ -21413,16 +22751,16 @@ BI.TimeInterval = BI.inherit(BI.Single, { _createCombo: function (v) { var self = this; var combo = BI.createWidget({ - type: "bi.dynamic_date_combo", + type: "bi.dynamic_date_time_combo", value: v }); - combo.on(BI.MultiDateCombo.EVENT_ERROR, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); self.fireEvent(BI.TimeInterval.EVENT_ERROR); }); - combo.on(BI.MultiDateCombo.EVENT_VALID, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_VALID, function () { BI.Bubbles.hide("error"); var smallDate = self.left.getKey(), bigDate = self.right.getKey(); if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -21438,7 +22776,7 @@ BI.TimeInterval = BI.inherit(BI.Single, { } }); - combo.on(BI.MultiDateCombo.EVENT_FOCUS, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_FOCUS, function () { BI.Bubbles.hide("error"); var smallDate = self.left.getKey(), bigDate = self.right.getKey(); if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -21454,11 +22792,11 @@ BI.TimeInterval = BI.inherit(BI.Single, { } }); - combo.on(BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW, function () { self.left.hidePopupView(); self.right.hidePopupView(); }); - // combo.on(BI.MultiDateCombo.EVENT_CHANGE, function () { + // combo.on(BI.DynamicDateTimeCombo.EVENT_CHANGE, function () { // BI.Bubbles.hide("error"); // var smallDate = self.left.getKey(), bigDate = self.right.getKey(); // if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -21474,7 +22812,7 @@ BI.TimeInterval = BI.inherit(BI.Single, { // } // }); - combo.on(BI.MultiDateCombo.EVENT_CONFIRM, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_CONFIRM, function () { BI.Bubbles.hide("error"); var smallDate = self.left.getKey(), bigDate = self.right.getKey(); if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -21490,7 +22828,10 @@ BI.TimeInterval = BI.inherit(BI.Single, { return combo; }, _dateCheck: function (date) { - return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S").print("%Y-%x-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%x-%e %H:%M:%S").print("%Y-%x-%e %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%e %H:%M:%S").print("%Y-%X-%e %H:%M:%S") === date; }, _checkVoid: function (obj) { return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; @@ -21508,8 +22849,8 @@ BI.TimeInterval = BI.inherit(BI.Single, { }); }, _compare: function (smallDate, bigDate) { - smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); - bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S"); return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; }, _setTitle: function (v) { diff --git a/public/js/index.js b/public/js/index.js index 8be649cd57..98808bc306 100644 --- a/public/js/index.js +++ b/public/js/index.js @@ -146,5 +146,7 @@ BI.i18n = { "BI-Basic_Current_Quarter": "本季度", "BI-Basic_Year_Month": "年月", "BI-Basic_Year_Quarter": "年季度", - "BI-Basic_Input_Can_Not_Null": "输入框不能为空" + "BI-Basic_Input_From_To_Number": "请输入{R1}的数值", + "BI-Basic_Input_Can_Not_Null": "输入框不能为空", + "BI-Basic_Date_Time_Error_Text": "日期格式示例:2015-3-11 00:00:00" }; \ No newline at end of file diff --git a/src/css/widget/timeinterval/dateinterval.css b/src/css/widget/timeinterval/dateinterval.css new file mode 100644 index 0000000000..d4bb0050a6 --- /dev/null +++ b/src/css/widget/timeinterval/dateinterval.css @@ -0,0 +1,6 @@ +.bi-date-interval.time-error .bi-input { + color: #ff4949; +} +.bi-date-interval.time-error .sign-editor-text { + color: #ff4949; +} diff --git a/src/css/widget/timeinterval/timeinterval.css b/src/css/widget/timeinterval/timeinterval.css index 26f946e8cb..b1d92bd965 100644 --- a/src/css/widget/timeinterval/timeinterval.css +++ b/src/css/widget/timeinterval/timeinterval.css @@ -1,6 +1,11 @@ -.bi-time-interval.time-error .bi-input { +.bi-time-interval .bi-date-time-trigger { + -webkit-border-radius: 2px; + -moz-border-radius: 2px; + border-radius: 2px; +} +.bi-time-interval.time-error .bi-date-time-trigger .bi-input { color: #ff4949; } -.bi-time-interval.time-error .sign-editor-text { +.bi-time-interval.time-error .bi-date-time-trigger .sign-editor-text { color: #ff4949; } diff --git a/src/less/widget/timeinterval/dateinterval.less b/src/less/widget/timeinterval/dateinterval.less new file mode 100644 index 0000000000..c4cdaa2607 --- /dev/null +++ b/src/less/widget/timeinterval/dateinterval.less @@ -0,0 +1,10 @@ +@import "../../index"; + +.bi-date-interval{ + &.time-error .bi-input{ + color:@color-bi-text-failure + } + &.time-error .sign-editor-text{ + color:@color-bi-text-failure + } +} \ No newline at end of file diff --git a/src/less/widget/timeinterval/timeinterval.less b/src/less/widget/timeinterval/timeinterval.less index 4c832f6db4..6f24909408 100644 --- a/src/less/widget/timeinterval/timeinterval.less +++ b/src/less/widget/timeinterval/timeinterval.less @@ -1,10 +1,17 @@ @import "../../index"; .bi-time-interval{ - &.time-error .bi-input{ - color:@color-bi-text-failure + & .bi-date-time-trigger{ + .border-radius(2px); } - &.time-error .sign-editor-text{ - color:@color-bi-text-failure + &.time-error { + & .bi-date-time-trigger{ + & .bi-input{ + color:@color-bi-text-failure + } + & .sign-editor-text{ + color:@color-bi-text-failure + } + } } } \ No newline at end of file diff --git a/src/widget/dynamic/datetimepane/card.static.datetimepane.js b/src/widget/dynamic/datetimepane/card.static.datetimepane.js new file mode 100644 index 0000000000..385bf52946 --- /dev/null +++ b/src/widget/dynamic/datetimepane/card.static.datetimepane.js @@ -0,0 +1,130 @@ +BI.StaticDateTimePaneCard = BI.inherit(BI.Widget, { + _defaultConfig: function () { + var conf = BI.StaticDateTimePaneCard.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: "bi-date-time-pane", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + selectedTime: null + }); + }, + _init: function () { + BI.StaticDateTimePaneCard.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.today = BI.getDate(); + this._year = this.today.getFullYear(); + this._month = this.today.getMonth(); + + this.selectedTime = o.selectedTime || { + year: this._year, + month: this._month + }; + + this.datePicker = BI.createWidget({ + type: "bi.date_picker", + min: o.min, + max: o.max + }); + this.datePicker.on(BI.DatePicker.EVENT_CHANGE, function () { + self.selectedTime = BI.extend(self.datePicker.getValue(), self.timeSelect.getValue()); + self.calendar.setSelect(BI.Calendar.getPageByDateJSON(self.selectedTime)); + }); + + this.calendar = BI.createWidget({ + direction: "top", + logic: { + dynamic: false + }, + type: "bi.navigation", + tab: this.datePicker, + cardCreator: BI.bind(this._createNav, this) + }); + this.calendar.on(BI.Navigation.EVENT_CHANGE, function () { + self.selectedTime = BI.extend(self.calendar.getValue(), self.timeSelect.getValue()); + self.calendar.empty(); + self.setValue(self.selectedTime); + self.fireEvent(BI.DateCalendarPopup.EVENT_CHANGE); + }); + + BI.createWidget({ + type: "bi.vtape", + element: this, + items: [this.calendar, { + el: { + type: "bi.dynamic_date_time_select", + ref: function () { + self.timeSelect = this; + } + }, + height: 40 + }] + }); + this.setValue(o.selectedTime); + + }, + + _createNav: function (v) { + var date = BI.Calendar.getDateJSONByPage(v); + var calendar = BI.createWidget({ + type: "bi.calendar", + logic: { + dynamic: false + }, + min: this.options.min, + max: this.options.max, + year: date.year, + month: date.month, + day: this.selectedTime.day + }); + return calendar; + }, + + _getNewCurrentDate: function () { + var today = BI.getDate(); + return { + year: today.getFullYear(), + month: today.getMonth() + }; + }, + + _setCalenderValue: function (date) { + this.calendar.setSelect(BI.Calendar.getPageByDateJSON(date)); + this.calendar.setValue(date); + this.selectedTime = BI.extend(date, this.timeSelect.getValue()); + }, + + _setDatePicker: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.year) || BI.isNull(timeOb.month)) { + this.datePicker.setValue(this._getNewCurrentDate()); + } else { + this.datePicker.setValue(timeOb); + } + }, + + _setCalendar: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { + this.calendar.empty(); + this._setCalenderValue(this._getNewCurrentDate()); + } else { + this._setCalenderValue(timeOb); + } + }, + + setValue: function (timeOb) { + timeOb = timeOb || {}; + this._setDatePicker(timeOb); + this._setCalendar(timeOb); + this.timeSelect.setValue({ + hour: timeOb.hour, + minute: timeOb.minute, + second: timeOb.second + }); + }, + + getValue: function () { + return this.selectedTime; + } + +}); +BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard); \ No newline at end of file diff --git a/src/widget/dynamic/datetimepane/datetimepane.js b/src/widget/dynamic/datetimepane/datetimepane.js new file mode 100644 index 0000000000..64b41be516 --- /dev/null +++ b/src/widget/dynamic/datetimepane/datetimepane.js @@ -0,0 +1,140 @@ +BI.DynamicDateTimePane = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-dynamic-date-pane" + }, + + render: function () { + var self = this; + return { + type: "bi.vtape", + items: [{ + el: { + type: "bi.linear_segment", + cls: "bi-border-bottom", + height: 30, + items: BI.createItems([{ + text: BI.i18nText("BI-Multi_Date_YMD"), + value: BI.DynamicDateTimePane.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDateTimePane.Dynamic + }], { + textAlign: "center" + }), + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + var value = this.getValue()[0]; + self.dateTab.setSelect(value); + switch (value) { + case BI.DynamicDateTimePane.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + break; + case BI.DynamicDateTimePane.Dynamic: + self.dynamicPane.setValue({ + year: 0 + }); + break; + default: + break; + } + } + }], + ref: function () { + self.switch = this; + } + }, + height: 30 + }, { + type: "bi.tab", + ref: function () { + self.dateTab = this; + }, + showIndex: BI.DynamicDateTimePane.Static, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDateTimePane.Static: + return { + type: "bi.static_date_time_pane_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.ymd = this; + } + }; + case BI.DynamicDateTimePane.Dynamic: + default: + return { + type: "bi.dynamic_date_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + } + } + }] + }; + }, + + mounted: function () { + this.setValue(this.options.value); + }, + + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + }, + + setValue: function (v) { + v = v || {}; + var type = v.type || BI.DynamicDateTimePane.Static; + var value = v.value || v; + this.switch.setValue(type); + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateTimePane.Dynamic: + this.dynamicPane.setValue(value); + break; + case BI.DynamicDateTimePane.Static: + default: + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth() + }); + } else { + this.ymd.setValue(value); + } + break; + } + }, + + getValue: function () { + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; + } +}); +BI.shortcut("bi.dynamic_date_time_pane", BI.DynamicDateTimePane); + +BI.extend(BI.DynamicDateTimePane, { + Static: 1, + Dynamic: 2 +}); \ No newline at end of file diff --git a/src/widget/dynamicdatetime/dynamicdatetime.combo.js b/src/widget/dynamicdatetime/dynamicdatetime.combo.js new file mode 100644 index 0000000000..26385e91c6 --- /dev/null +++ b/src/widget/dynamicdatetime/dynamicdatetime.combo.js @@ -0,0 +1,261 @@ +BI.DynamicDateTimeCombo = BI.inherit(BI.Single, { + constants: { + popupHeight: 259, + popupWidth: 270, + comboAdjustHeight: 1, + border: 1, + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" + }, + + props: { + baseCls: "bi-dynamic-date-combo bi-border", + height: 24 + }, + + + render: function () { + var self = this, opts = this.options; + this.storeTriggerValue = ""; + var date = BI.getDate(); + this.storeValue = opts.value; + return { + type: "bi.htape", + items: [{ + el: { + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, + ref: function () { + self.changeIcon = this; + } + }, + width: 24 + }, { + type: "bi.absolute", + items: [{ + el: { + type: "bi.combo", + ref: function () { + self.combo = this; + }, + toggle: false, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: { + type: "bi.dynamic_date_time_trigger", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.trigger = this; + }, + listeners: [{ + eventName: BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN, + action: function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_STOP, + action: function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_TRIGGER_CLICK, + action: function () { + self.combo.toggle(); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_FOCUS, + action: function () { + self.storeTriggerValue = self.trigger.getKey(); + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_FOCUS); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_ERROR, + action: function () { + self.storeValue = { + year: date.getFullYear(), + month: date.getMonth() + }; + self.popup.setValue(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_ERROR); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_VALID, + action: function () { + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_VALID); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CHANGE); + } + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_CONFIRM, + action: function () { + if (self.combo.isViewVisible()) { + return; + } + var dateStore = self.storeTriggerValue; + var dateObj = self.trigger.getKey(); + if (BI.isNotEmptyString(dateObj) && !BI.isEqual(dateObj, dateStore)) { + self.storeValue = self.trigger.getValue(); + self.setValue(self.trigger.getValue()); + } else if (BI.isEmptyString(dateObj)) { + self.storeValue = null; + self.trigger.setValue(); + } + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }] + }, + adjustLength: this.constants.comboAdjustHeight, + popup: { + el: { + type: "bi.dynamic_date_time_popup", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate(), + hour: 0, + minute: 0, + second: 0 + }); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDateTimePopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_CONFIRM); + } + }] + }, + stopPropagation: false + }, + listeners: [{ + eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, + action: function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW); + } + }] + }, + top: 0, + left: 0, + right: 0, + bottom: 0 + }, { + el: { + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-font", + width: 24, + height: 24, + listeners: [{ + eventName: BI.IconButton.EVENT_CHANGE, + action: function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } else { + self.combo.showView(); + } + } + }] + }, + top: 0, + right: 0 + }] + }], + ref: function (_ref) { + self.comboWrapper = _ref; + } + }; + }, + + mounted: function () { + this._checkDynamicValue(this.options.value); + }, + + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicDateTimeCombo.Dynamic: + this.changeIcon.setVisible(true); + this.comboWrapper.attr("items")[0].width = 24; + this.comboWrapper.resize(); + break; + default: + this.comboWrapper.attr("items")[0].width = 0; + this.comboWrapper.resize(); + this.changeIcon.setVisible(false); + break; + } + }, + + setValue: function (v) { + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); + }, + getValue: function () { + return this.storeValue; + }, + getKey: function () { + return this.trigger.getKey(); + }, + hidePopupView: function () { + this.combo.hideView(); + } +}); + +BI.DynamicDateTimeCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateTimeCombo.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateTimeCombo.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTimeCombo.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateTimeCombo.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + +BI.shortcut("bi.dynamic_date_time_combo", BI.DynamicDateTimeCombo); + +BI.extend(BI.DynamicDateTimeCombo, { + Static: 1, + Dynamic: 2 +}); \ No newline at end of file diff --git a/src/widget/dynamicdatetime/dynamicdatetime.popup.js b/src/widget/dynamicdatetime/dynamicdatetime.popup.js new file mode 100644 index 0000000000..340794cfb6 --- /dev/null +++ b/src/widget/dynamicdatetime/dynamicdatetime.popup.js @@ -0,0 +1,235 @@ +BI.DynamicDateTimePopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 + }, + + props: { + baseCls: "bi-dynamic-date-time-popup", + width: 248, + height: 385 + }, + + _init: function () { + BI.DynamicDateTimePopup.superclass._init.apply(this, arguments); + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicDateCombo.Static}; + BI.createWidget({ + element: this, + type: "bi.vtape", + items: [{ + el: this._getTabJson() + }, { + el: { + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-high-light bi-border-top", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-left bi-border-right bi-border-top", + shadow: true, + text: BI.i18nText("BI-Multi_Date_Today"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-high-light bi-border-top", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 + }] + }); + this.setValue(opts.value); + }, + + _getTabJson: function () { + var self = this; + return { + type: "bi.tab", + showIndex: BI.DynamicDateCombo.Static, + ref: function () { + self.dateTab = this; + }, + tab: { + type: "bi.linear_segment", + cls: "bi-border-bottom", + height: this.constants.tabHeight, + items: BI.createItems([{ + text: BI.i18nText("BI-Multi_Date_YMD"), + value: BI.DynamicDateCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDateCombo.Dynamic + }], { + textAlign: "center" + }) + }, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDateCombo.Dynamic: + return { + type: "bi.dynamic_date_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicDateCombo.Static: + default: + return { + type: "bi.vtape", + items: [{ + type: "bi.date_calendar_popup", + min: self.options.min, + max: self.options.max, + ref: function () { + self.ymd = this; + } + }, { + el: { + type: "bi.dynamic_date_time_select", + ref: function () { + self.timeSelect = this; + }, + listeners: [{ + eventName: BI.DynamicDateTimeSelect.EVENT_CONFIRM, + action: function () { + + } + }] + }, + height: 40 + }] + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicDateCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + self.timeSelect.setValue(); + self._setInnerValue(); + break; + case BI.DynamicDateCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicDateCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; + }, + + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y-%x-%e"); + this.textButton.setValue(date); + this.textButton.setEnable(false); + } + }, + + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + }, + + setValue: function (v) { + this.storeValue = v; + var self = this; + var type, value; + v = v || {}; + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateCombo.Dynamic: + this.dynamicPane.setValue(value); + self._setInnerValue(); + break; + case BI.DynamicDateCombo.Static: + default: + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + this.timeSelect.setValue(); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } else { + this.ymd.setValue(value); + this.timeSelect.setValue({ + hour: value.hour, + minute: value.minute, + second: value.second + }); + this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); + } + this.textButton.setEnable(true); + break; + } + }, + + getValue: function () { + var type = this.dateTab.getSelect(); + return { + type: type, + value: type === BI.DynamicDateTimeCombo.Static ? BI.extend(this.ymd.getValue(), this.timeSelect.getValue()) : this.dynamicPane.getValue() + }; + } +}); +BI.DynamicDateTimePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTimePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicDateTimePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicDateTimePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.shortcut("bi.dynamic_date_time_popup", BI.DynamicDateTimePopup); \ No newline at end of file diff --git a/src/widget/dynamicdatetime/dynamicdatetime.timeselect.js b/src/widget/dynamicdatetime/dynamicdatetime.timeselect.js new file mode 100644 index 0000000000..83eb9ed4e7 --- /dev/null +++ b/src/widget/dynamicdatetime/dynamicdatetime.timeselect.js @@ -0,0 +1,164 @@ +BI.DynamicDateTimeSelect = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-date-time-select bi-border-top" + }, + + render: function () { + var self = this; + return { + type: "bi.center_adapt", + items: [{ + type: "bi.vertical_adapt", + items: [{ + el: { + type: "bi.number_editor", + ref: function () { + self.hour = this; + }, + validationChecker: function (v) { + return BI.isNaturalNumber(v) && BI.parseInt(v) < 24; + }, + errorText: function () { + return BI.i18nText("BI-Basic_Input_From_To_Number", "\"00-23\""); + }, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + this.setValue(self._formatValueToDoubleDigit(this.getValue())); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }, { + eventName: BI.SignEditor.EVENT_CHANGE, + action: function () { + var value = self._autoSwitch(this.getValue(), BI.DynamicDateTimeSelect.HOUR); + this.setValue(value); + } + }], + width: 60, + height: 24 + }, + lgap: 14 + }, { + type: "bi.label", + text: ":", + width: 20 + }, { + type: "bi.number_editor", + ref: function () { + self.minute = this; + }, + validationChecker: function (v) { + return BI.isNaturalNumber(v) && BI.parseInt(v) < 60; + }, + errorText: function () { + return BI.i18nText("BI-Basic_Input_From_To_Number", "\"00-59\""); + }, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + this.setValue(self._formatValueToDoubleDigit(this.getValue()), BI.DynamicDateTimeSelect.MINUTE); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }, { + eventName: BI.SignEditor.EVENT_CHANGE, + action: function () { + var value = self._autoSwitch(this.getValue(), BI.DynamicDateTimeSelect.MINUTE); + this.setValue(value); + } + }], + width: 60, + height: 24 + }, { + type: "bi.label", + text: ":", + width: 20 + }, { + type: "bi.number_editor", + ref: function () { + self.second = this; + }, + validationChecker: function (v) { + return BI.isNaturalNumber(v) && BI.parseInt(v) < 60; + }, + errorText: function () { + return BI.i18nText("BI-Basic_Input_From_To_Number", "\"00-59\""); + }, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + this.setValue(self._formatValueToDoubleDigit(this.getValue())); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }], + width: 60, + height: 24 + }] + }] + }; + }, + + _autoSwitch: function (v, type) { + var limit = 0; + var value = v; + switch (type) { + case BI.DynamicDateTimeSelect.HOUR: + limit = 2; + break; + case BI.DynamicDateTimeSelect.MINUTE: + limit = 6; + break; + default: + break; + } + if(v.length === 1 && BI.parseInt(v) > limit) { + value = "0" + value; + } + if (value.length === 2) { + type === BI.DynamicDateTimeSelect.HOUR ? this.minute.focus() : this.second.focus(); + } + return value; + }, + + _formatValueToDoubleDigit: function (v) { + if(BI.isNull(v) || BI.isEmptyString(v)) { + v = 0; + } + var value = BI.parseInt(v); + if(value < 10) { + value = "0" + value; + } + return value; + }, + + _assertValue: function (v) { + v = v || {}; + v.hour = this._formatValueToDoubleDigit(v.hour) || "00"; + v.minute = this._formatValueToDoubleDigit(v.minute) || "00"; + v.second = this._formatValueToDoubleDigit(v.second) || "00"; + return v; + }, + + getValue: function () { + return { + hour: BI.parseInt(this.hour.getValue()), + minute: BI.parseInt(this.minute.getValue()), + second: BI.parseInt(this.second.getValue()) + }; + }, + + setValue: function (v) { + v = this._assertValue(v); + this.hour.setValue(v.hour); + this.minute.setValue(v.minute); + this.second.setValue(v.second); + } + +}); +BI.DynamicDateTimeSelect.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.shortcut("bi.dynamic_date_time_select", BI.DynamicDateTimeSelect); + +BI.extend(BI.DynamicDateTimeSelect, { + HOUR: 1, + MINUTE: 2 +}); \ No newline at end of file diff --git a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js new file mode 100644 index 0000000000..b24772d562 --- /dev/null +++ b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js @@ -0,0 +1,232 @@ +BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + yearLength: 4, + yearMonthLength: 7 + }, + + props: { + extraCls: "bi-date-time-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 + }, + + _init: function () { + BI.DynamicDateTimeTrigger.superclass._init.apply(this, arguments); + var self = this, o = this.options, c = this._const; + this.editor = BI.createWidget({ + type: "bi.sign_editor", + height: o.height, + validationChecker: function (v) { + var date = v.match(/\d+/g); + self._autoAppend(v, date); + return self._dateCheck(v) && BI.checkDateLegal(v) && self._checkVoid({ + year: date[0], + month: date[1], + day: date[2] + }); + }, + quitChecker: function () { + return false; + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + errorText: function () { + if (self.editor.isEditing()) { + return BI.i18nText("BI-Basic_Date_Time_Error_Text"); + } + return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + } + }); + this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN); + }); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_FOCUS); + }); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_STOP); + }); + this.editor.on(BI.SignEditor.EVENT_VALID, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_VALID); + }); + this.editor.on(BI.SignEditor.EVENT_ERROR, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_ERROR); + }); + this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setState(value); + } + + if (BI.isNotEmptyString(value)) { + var date = value.split(/-|\s|:/); + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: date[0] | 0, + month: date[1] - 1, + day: date[2] | 0, + hour: date[3] | 0, + minute: date[4] | 0, + second: date[5] | 0 + } + }; + } + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_CONFIRM); + }); + this.editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_START); + }); + this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_CHANGE); + }); + BI.createWidget({ + type: "bi.htape", + element: this, + items: [{ + el: this.editor + }, { + el: BI.createWidget(), + width: 30 + }] + }); + this.setValue(o.value); + }, + _dateCheck: function (date) { + return BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S").print("%Y-%x-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%x-%e %H:%M:%S").print("%Y-%x-%e %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%e %H:%M:%S").print("%Y-%X-%e %H:%M:%S") === date || + + BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || + BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") === date || + BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") === date || + BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") === date; + }, + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; + }, + _autoAppend: function (v, dateObj) { + if (BI.isNotNull(dateObj) && BI.checkDateLegal(v)) { + switch (v.length) { + case this._const.yearLength: + if (this._yearCheck(v)) { + this.editor.setValue(v + "-"); + } + break; + case this._const.yearMonthLength: + if (this._monthCheck(v)) { + this.editor.setValue(v + "-"); + } + break; + } + } + }, + + _yearCheck: function (v) { + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.parseDateTime(v, "%Y").print("%Y") === v && date >= this.options.min && date <= this.options.max; + }, + + _monthCheck: function (v) { + var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.parseDateTime(v, "%Y-%X").print("%Y-%X") === v && date >= this.options.min && date <= this.options.max; + }, + + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y-%x-%e %H:%M:%S"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); + }, + + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year) && obj.year !== 0) { + value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Year"), obj.position); + } + if(BI.isNotNull(obj.quarter) && obj.quarter !== 0) { + value += Math.abs(obj.quarter) + BI.i18nText("BI-Basic_Single_Quarter") + (obj.quarter < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Year"), obj.position); + } + if(BI.isNotNull(obj.month) && obj.month !== 0) { + value += Math.abs(obj.month) + BI.i18nText("BI-Basic_Month") + (obj.month < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Month"), obj.position); + } + if(BI.isNotNull(obj.week) && obj.week !== 0) { + value += Math.abs(obj.week) + BI.i18nText("BI-Basic_Week") + (obj.week < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + getPositionText(BI.i18nText("BI-Basic_Week"), obj.position); + } + if(BI.isNotNull(obj.day) && obj.day !== 0) { + value += Math.abs(obj.day) + BI.i18nText("BI-Basic_Day") + (obj.day < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")) + BI.size(obj) === 1 ? getPositionText(BI.i18nText("BI-Basic_Month"), obj.position) : ""; + } + if(BI.isNotNull(obj.workDay) && obj.workDay !== 0) { + value += Math.abs(obj.workDay) + BI.i18nText("BI-Basic_Work_Day") + (obj.workDay < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + return value; + + function getPositionText (baseText, position) { + switch (position) { + case BI.DynamicDateCard.OFFSET.BEGIN: + return baseText + BI.i18nText("BI-Basic_Begin_Start"); + case BI.DynamicDateCard.OFFSET.END: + return baseText + BI.i18nText("BI-Basic_End_Stop"); + case BI.DynamicDateCard.OFFSET.CURRENT: + default: + return BI.i18nText("BI-Basic_Current_Day"); + } + } + }, + + setValue: function (v) { + var type, value, self = this; + var date = BI.getDate(); + this.storeValue = v; + if (BI.isNotNull(v)) { + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; + } + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = this._getText(value); + date = BI.DynamicDateHelper.getCalculation(value); + this._setInnerValue(date, text); + break; + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + this.editor.setState(""); + this.editor.setValue(""); + this.setTitle(""); + } else { + var dateStr = value.year + "-" + (value.month + 1) + "-" + value.day + " " + + (value.hour || "00") + ":" + (value.minute || "00") + ":" + (value.second || "00"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(dateStr); + } + break; + } + }, + + getKey: function () { + return this.editor.getValue(); + }, + getValue: function () { + return this.storeValue; + } + +}); + +BI.DynamicDateTimeTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateTimeTrigger.EVENT_START = "EVENT_START"; +BI.DynamicDateTimeTrigger.EVENT_STOP = "EVENT_STOP"; +BI.DynamicDateTimeTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateTimeTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateTimeTrigger.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateTimeTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateTimeTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.shortcut("bi.dynamic_date_time_trigger", BI.DynamicDateTimeTrigger); \ No newline at end of file diff --git a/src/widget/numbereditor/number.editor.js b/src/widget/numbereditor/number.editor.js index d634edf471..64caef61ba 100644 --- a/src/widget/numbereditor/number.editor.js +++ b/src/widget/numbereditor/number.editor.js @@ -81,6 +81,10 @@ BI.NumberEditor = BI.inherit(BI.Widget, { }); }, + focus: function () { + this.editor.focus(); + }, + // 微调 _finetuning: function (add) { var v = BI.parseFloat(this.getValue()); diff --git a/src/widget/timeinterval/dateinterval.js b/src/widget/timeinterval/dateinterval.js new file mode 100644 index 0000000000..fdb2106517 --- /dev/null +++ b/src/widget/timeinterval/dateinterval.js @@ -0,0 +1,179 @@ +/** + * Created by Baron on 2015/10/19. + */ +BI.DateInterval = BI.inherit(BI.Single, { + constants: { + height: 25, + width: 25, + lgap: 15, + offset: -15, + timeErrorCls: "time-error", + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" + }, + _defaultConfig: function () { + var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-date-interval" + }); + }, + _init: function () { + var self = this, o = this.options; + BI.DateInterval.superclass._init.apply(this, arguments); + + o.value = o.value || {}; + this.left = this._createCombo(o.value.start); + this.right = this._createCombo(o.value.end); + this.label = BI.createWidget({ + type: "bi.label", + height: this.constants.height, + width: this.constants.width, + text: "-" + }); + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, + items: [{ + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: this.constants.offset, + top: 0, + bottom: 0 + }] + }] + }); + BI.createWidget({ + type: "bi.horizontal_auto", + element: this, + items: [ + self.label + ] + }); + }, + + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_date_combo", + value: v + }); + combo.on(BI.DynamicDateCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + }); + + combo.on(BI.DynamicDateCombo.EVENT_VALID, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicDateCombo.EVENT_FOCUS, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + } + }); + + combo.on(BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hidePopupView(); + self.right.hidePopupView(); + }); + + combo.on(BI.DynamicDateCombo.EVENT_CONFIRM, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_ERROR); + }else{ + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_CHANGE); + } + }); + return combo; + }, + _dateCheck: function (date) { + return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") === date || + BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") === date || + BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") === date || + BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") === date; + }, + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + }, + _check: function (smallDate, bigDate) { + var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); + return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ + year: smallObj[0], + month: smallObj[1], + day: smallObj[2] + }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ + year: bigObj[0], + month: bigObj[1], + day: bigObj[2] + }); + }, + _compare: function (smallDate, bigDate) { + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; + }, + _setTitle: function (v) { + this.left.setTitle(v); + this.right.setTitle(v); + this.label.setTitle(v); + }, + _clearTitle: function () { + this.left.setTitle(""); + this.right.setTitle(""); + this.label.setTitle(""); + }, + setValue: function (date) { + date = date || {}; + this.left.setValue(date.start); + this.right.setValue(date.end); + }, + getValue: function () { + return {start: this.left.getValue(), end: this.right.getValue()}; + } +}); +BI.DateInterval.EVENT_VALID = "EVENT_VALID"; +BI.DateInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.DateInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.date_interval", BI.DateInterval); \ No newline at end of file diff --git a/src/widget/timeinterval/timeinterval.js b/src/widget/timeinterval/timeinterval.js index bb40270d79..73cf18c42d 100644 --- a/src/widget/timeinterval/timeinterval.js +++ b/src/widget/timeinterval/timeinterval.js @@ -67,16 +67,16 @@ BI.TimeInterval = BI.inherit(BI.Single, { _createCombo: function (v) { var self = this; var combo = BI.createWidget({ - type: "bi.dynamic_date_combo", + type: "bi.dynamic_date_time_combo", value: v }); - combo.on(BI.MultiDateCombo.EVENT_ERROR, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); self.fireEvent(BI.TimeInterval.EVENT_ERROR); }); - combo.on(BI.MultiDateCombo.EVENT_VALID, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_VALID, function () { BI.Bubbles.hide("error"); var smallDate = self.left.getKey(), bigDate = self.right.getKey(); if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -92,7 +92,7 @@ BI.TimeInterval = BI.inherit(BI.Single, { } }); - combo.on(BI.MultiDateCombo.EVENT_FOCUS, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_FOCUS, function () { BI.Bubbles.hide("error"); var smallDate = self.left.getKey(), bigDate = self.right.getKey(); if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -108,11 +108,11 @@ BI.TimeInterval = BI.inherit(BI.Single, { } }); - combo.on(BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW, function () { self.left.hidePopupView(); self.right.hidePopupView(); }); - // combo.on(BI.MultiDateCombo.EVENT_CHANGE, function () { + // combo.on(BI.DynamicDateTimeCombo.EVENT_CHANGE, function () { // BI.Bubbles.hide("error"); // var smallDate = self.left.getKey(), bigDate = self.right.getKey(); // if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -128,7 +128,7 @@ BI.TimeInterval = BI.inherit(BI.Single, { // } // }); - combo.on(BI.MultiDateCombo.EVENT_CONFIRM, function () { + combo.on(BI.DynamicDateTimeCombo.EVENT_CONFIRM, function () { BI.Bubbles.hide("error"); var smallDate = self.left.getKey(), bigDate = self.right.getKey(); if (self._check(smallDate, bigDate) && self._compare(smallDate, bigDate)) { @@ -144,7 +144,10 @@ BI.TimeInterval = BI.inherit(BI.Single, { return combo; }, _dateCheck: function (date) { - return BI.parseDateTime(date, "%Y-%x-%d").print("%Y-%x-%d") == date || BI.parseDateTime(date, "%Y-%X-%d").print("%Y-%X-%d") == date || BI.parseDateTime(date, "%Y-%x-%e").print("%Y-%x-%e") == date || BI.parseDateTime(date, "%Y-%X-%e").print("%Y-%X-%e") == date; + return BI.parseDateTime(date, "%Y-%x-%d %H:%M:%S").print("%Y-%x-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%x-%e %H:%M:%S").print("%Y-%x-%e %H:%M:%S") === date || + BI.parseDateTime(date, "%Y-%X-%e %H:%M:%S").print("%Y-%X-%e %H:%M:%S") === date; }, _checkVoid: function (obj) { return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; @@ -162,8 +165,8 @@ BI.TimeInterval = BI.inherit(BI.Single, { }); }, _compare: function (smallDate, bigDate) { - smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); - bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d %H:%M:%S").print("%Y-%X-%d %H:%M:%S"); return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; }, _setTitle: function (v) { diff --git a/ui/js/index.js b/ui/js/index.js index 49a347748a..ff38486911 100644 --- a/ui/js/index.js +++ b/ui/js/index.js @@ -147,5 +147,7 @@ BI.i18n = { "BI-Basic_Current_Quarter": "本季度", "BI-Basic_Year_Month": "年月", "BI-Basic_Year_Quarter": "年季度", - "BI-Basic_Input_Can_Not_Null": "输入框不能为空" + "BI-Basic_Input_Can_Not_Null": "输入框不能为空", + "BI-Basic_Date_Time_Error_Text": "日期格式示例:2015-3-11 00:00:00", + "BI-Basic_Input_From_To_Number": "请输入{R1}的数值" }; \ No newline at end of file