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/2] 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 cb5c21da0..49f4f9a39 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 be372e602..d52ed6ff0 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 8e5f37c84..6d6eee6e5 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 48d29334c..f4c100ea5 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 abbaaad8d..a779189f8 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 fb9eb1346..a72edba2a 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 ae0948cc1..bf2dd6b31 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/2] =?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 9d9a687af..cd42165d2 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 000000000..a87de534c --- /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 8889bf1a1..5737345d2 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 6d6eee6e5..c3ad53d8a 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 f4c100ea5..fa5c315a4 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 bdbde73f8..9f5d7719a 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 0fbd10ee6..241b48e97 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 a779189f8..83b9dc386 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 59229928f..26f946e8c 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 000000000..741ccfeaa --- /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 954f52169..4c832f6db 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 000000000..d66deb475 --- /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 abe633f6e..9f140d6a6 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 e56e28645..313816222 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 83a948237..b1dddfcef 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 521dda8c7..893ea58a1 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 cde12ef08..5e2e35ca8 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 efc88ee3e..ee489b8cc 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 226d560d6..df767b5f9 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 e14b34d28..5fc6e3881 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 000000000..2d199d67f --- /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