From 6f7854d17fa16991053b7d350ee7d903c422b11a Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Fri, 23 Mar 2018 15:09:18 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E4=B8=8E=E6=95=B4=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/bundle.js | 25808 ++++++++-------- dist/widget.js | 25776 ++++++++------- src/widget/date/calendar/popup.year.js | 110 + .../datepane/card.static.datepane.js | 0 src/widget/datepane/datepane.js | 220 +- .../datetimepane/card.static.datetimepane.js | 0 .../datetimepane/datetimepane.js | 0 src/widget/dynamic/datepane/datepane.js | 140 - src/widget/dynamic/year/combo.year.js | 161 - src/widget/dynamic/year/popup.year.js | 206 - src/widget/dynamic/year/trigger.year.js | 146 - .../dynamic/yearmonth/combo.yearmonth.js | 170 - .../dynamic/yearquarter/combo.yearquarter.js | 152 - .../multidate/abstract.multidate.datepane.js | 151 - src/widget/multidate/multidate.combo.js | 283 - src/widget/multidate/multidate.day.js | 43 - src/widget/multidate/multidate.month.js | 47 - src/widget/multidate/multidate.popup.js | 317 - src/widget/multidate/multidate.quarter.js | 48 - src/widget/multidate/multidate.segment.js | 127 - src/widget/multidate/multidate.week.js | 37 - src/widget/multidate/multidate.year.js | 47 - .../{dynamic => }/year/card.dynamic.year.js | 0 src/widget/{dynamic => }/year/card.year.js | 0 src/widget/year/combo.year.js | 154 +- src/widget/year/popup.year.js | 270 +- src/widget/year/trigger.year.js | 132 +- .../yearmonth/card.dynamic.yearmonth.js | 0 .../yearmonth/card.static.yearmonth.js | 0 src/widget/yearmonth/combo.yearmonth.js | 197 +- .../yearmonth/popup.yearmonth.js | 2 +- .../yearmonth/trigger.yearmonth.js | 0 .../yearquarter/card.dynamic.yearquarter.js | 0 .../yearquarter/card.static.yearquarter.js | 0 src/widget/yearquarter/combo.yearquarter.js | 178 +- .../yearquarter/popup.yearquarter.js | 2 +- .../yearquarter/trigger.yearquarter.js | 0 37 files changed, 25107 insertions(+), 29817 deletions(-) create mode 100644 src/widget/date/calendar/popup.year.js rename src/widget/{dynamic => }/datepane/card.static.datepane.js (100%) rename src/widget/{dynamic => }/datetimepane/card.static.datetimepane.js (100%) rename src/widget/{dynamic => }/datetimepane/datetimepane.js (100%) delete mode 100644 src/widget/dynamic/datepane/datepane.js delete mode 100644 src/widget/dynamic/year/combo.year.js delete mode 100644 src/widget/dynamic/year/popup.year.js delete mode 100644 src/widget/dynamic/year/trigger.year.js delete mode 100644 src/widget/dynamic/yearmonth/combo.yearmonth.js delete mode 100644 src/widget/dynamic/yearquarter/combo.yearquarter.js delete mode 100644 src/widget/multidate/abstract.multidate.datepane.js delete mode 100644 src/widget/multidate/multidate.combo.js delete mode 100644 src/widget/multidate/multidate.day.js delete mode 100644 src/widget/multidate/multidate.month.js delete mode 100644 src/widget/multidate/multidate.popup.js delete mode 100644 src/widget/multidate/multidate.quarter.js delete mode 100644 src/widget/multidate/multidate.segment.js delete mode 100644 src/widget/multidate/multidate.week.js delete mode 100644 src/widget/multidate/multidate.year.js rename src/widget/{dynamic => }/year/card.dynamic.year.js (100%) rename src/widget/{dynamic => }/year/card.year.js (100%) rename src/widget/{dynamic => }/yearmonth/card.dynamic.yearmonth.js (100%) rename src/widget/{dynamic => }/yearmonth/card.static.yearmonth.js (100%) rename src/widget/{dynamic => }/yearmonth/popup.yearmonth.js (98%) rename src/widget/{dynamic => }/yearmonth/trigger.yearmonth.js (100%) rename src/widget/{dynamic => }/yearquarter/card.dynamic.yearquarter.js (100%) rename src/widget/{dynamic => }/yearquarter/card.static.yearquarter.js (100%) rename src/widget/{dynamic => }/yearquarter/popup.yearquarter.js (98%) rename src/widget/{dynamic => }/yearquarter/trigger.yearquarter.js (100%) diff --git a/dist/bundle.js b/dist/bundle.js index dfa3abbdd..94a8ad78e 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -87378,6 +87378,115 @@ BI.DateCalendarPopup = BI.inherit(BI.Widget, { }); BI.DateCalendarPopup.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.date_calendar_popup", BI.DateCalendarPopup);/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.YearPopup + * @extends BI.Trigger + */ +BI.YearPopup = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.YearPopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-year-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31" // 最大日期 + }); + }, + + _createYearCalendar: function (v) { + var o = this.options, y = this._year; + + var calendar = BI.createWidget({ + type: "bi.year_calendar", + behaviors: o.behaviors, + min: o.min, + max: o.max, + logic: { + dynamic: true + }, + year: y + v * 12 + }); + calendar.setValue(this._year); + return calendar; + }, + + _init: function () { + BI.YearPopup.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.selectedYear = this._year = BI.getDate().getFullYear(); + + var backBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "pre-page-h-font", + width: 25, + height: 25, + value: -1 + }); + + var preBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "next-page-h-font", + width: 25, + height: 25, + value: 1 + }); + + this.navigation = BI.createWidget({ + type: "bi.navigation", + element: this, + single: true, + logic: { + dynamic: true + }, + tab: { + cls: "year-popup-navigation bi-high-light bi-border-top", + height: 25, + items: [backBtn, preBtn] + }, + cardCreator: BI.bind(this._createYearCalendar, this), + + afterCardShow: function () { + this.setValue(self.selectedYear); + var calendar = this.getSelectedCard(); + backBtn.setEnable(!calendar.isFrontYear()); + preBtn.setEnable(!calendar.isFinalYear()); + } + }); + + this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { + self.selectedYear = this.getValue(); + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + self.fireEvent(BI.YearPopup.EVENT_CHANGE, self.selectedYear); + }); + + if(BI.isKey(o.value)){ + this.setValue(o.value); + } + }, + + getValue: function () { + return this.selectedYear; + }, + + setValue: function (v) { + var o = this.options; + if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { + v = BI.getDate().getFullYear(); + this.selectedYear = ""; + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(""); + } else { + this.selectedYear = v; + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(v); + } + } +}); +BI.YearPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.year_popup", BI.YearPopup);/** * 日期控件中的年份或月份trigger * * Created by GUY on 2015/9/7. @@ -87824,9 +87933,9 @@ BI.DateTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; BI.shortcut("bi.date_trigger", BI.DateTrigger);/** * Created by zcf on 2017/2/20. */ -BI.DatePaneWidget = BI.inherit(BI.Widget, { +BI.StaticDatePaneCard = BI.inherit(BI.Widget, { _defaultConfig: function () { - var conf = BI.DatePaneWidget.superclass._defaultConfig.apply(this, arguments); + var conf = BI.StaticDatePaneCard.superclass._defaultConfig.apply(this, arguments); return BI.extend(conf, { baseCls: "bi-date-pane", min: "1900-01-01", // 最小日期 @@ -87835,7 +87944,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { }); }, _init: function () { - BI.DatePaneWidget.superclass._init.apply(this, arguments); + BI.StaticDatePaneCard.superclass._init.apply(this, arguments); var self = this, o = this.options; this.today = BI.getDate(); @@ -87934,7 +88043,146 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { } }); -BI.shortcut("bi.date_pane", BI.DatePaneWidget);/** +BI.shortcut("bi.static_date_pane_card", BI.StaticDatePaneCard);BI.DynamicDatePane = 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.DynamicDatePane.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDatePane.Dynamic + }], { + textAlign: "center" + }), + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + var value = this.getValue()[0]; + self.dateTab.setSelect(value); + switch (value) { + case BI.DynamicDatePane.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + break; + case BI.DynamicDatePane.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.DynamicDatePane.Static, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDatePane.Static: + return { + type: "bi.static_date_pane_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.ymd = this; + } + }; + case BI.DynamicDatePane.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.DynamicDateCombo.Static; + var value = v.value || v; + this.switch.setValue(type); + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateCombo.Dynamic: + this.dynamicPane.setValue(value); + break; + case BI.DynamicDateCombo.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_pane", BI.DynamicDatePane); + +BI.extend(BI.DynamicDatePane, { + Static: 1, + Dynamic: 2 +});/** * Created by Urthur on 2017/7/14. */ BI.DateTimeCombo = BI.inherit(BI.Single, { @@ -88401,309 +88649,577 @@ BI.DateTimeTrigger = BI.inherit(BI.Trigger, { } }); -BI.shortcut("bi.date_time_trigger", BI.DateTimeTrigger);/** - * Created by roy on 15/8/14. - */ -BI.DownListCombo = BI.inherit(BI.Widget, { +BI.shortcut("bi.date_time_trigger", BI.DateTimeTrigger);BI.StaticDateTimePaneCard = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.DownListCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-down-list-combo", - height: 24, - items: [], - adjustLength: 0, - direction: "bottom", - trigger: "click", - container: null, - stopPropagation: false, - el: {} + 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.DownListCombo.superclass._init.apply(this, arguments); + BI.StaticDateTimePaneCard.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.popupview = BI.createWidget({ - type: "bi.down_list_popup", - items: o.items, - chooseType: o.chooseType, - value: o.value - }); - this.popupview.on(BI.DownListPopup.EVENT_CHANGE, function (value) { - self.fireEvent(BI.DownListCombo.EVENT_CHANGE, value); - self.downlistcombo.hideView(); - }); + this.today = BI.getDate(); + this._year = this.today.getFullYear(); + this._month = this.today.getMonth(); - this.popupview.on(BI.DownListPopup.EVENT_SON_VALUE_CHANGE, function (value, fatherValue) { - self.fireEvent(BI.DownListCombo.EVENT_SON_VALUE_CHANGE, value, fatherValue); - self.downlistcombo.hideView(); + 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); + }); - this.downlistcombo = BI.createWidget({ + BI.createWidget({ + type: "bi.vtape", element: this, - type: "bi.combo", - trigger: o.trigger, - isNeedAdjustWidth: false, - container: o.container, - adjustLength: o.adjustLength, - direction: o.direction, - stopPropagation: o.stopPropagation, - el: BI.createWidget(o.el, { - type: "bi.icon_trigger", - extraCls: o.iconCls ? o.iconCls : "pull-down-font", - width: o.width, - height: o.height - }), - popup: { - el: this.popupview, - stopPropagation: true, - maxHeight: 1000 - } + items: [this.calendar, { + el: { + type: "bi.dynamic_date_time_select", + ref: function () { + self.timeSelect = this; + } + }, + height: 40 + }] }); + this.setValue(o.selectedTime); - this.downlistcombo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.DownListCombo.EVENT_BEFORE_POPUPVIEW); - }); }, - hideView: function () { - this.downlistcombo.hideView(); + _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; }, - showView: function () { - this.downlistcombo.showView(); + _getNewCurrentDate: function () { + var today = BI.getDate(); + return { + year: today.getFullYear(), + month: today.getMonth() + }; }, - populate: function (items) { - this.popupview.populate(items); + _setCalenderValue: function (date) { + this.calendar.setSelect(BI.Calendar.getPageByDateJSON(date)); + this.calendar.setValue(date); + this.selectedTime = BI.extend(date, this.timeSelect.getValue()); }, - setValue: function (v) { - this.popupview.setValue(v); + _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); + } }, - getValue: function () { - return this.popupview.getValue(); - } -}); -BI.DownListCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.DownListCombo.EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE"; -BI.DownListCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.down_list_combo", BI.DownListCombo);/** - * Created by roy on 15/9/6. - */ -BI.DownListGroup = BI.inherit(BI.Widget, { - constants: { - iconCls: "check-mark-ha-font" - }, - _defaultConfig: function () { - return BI.extend(BI.DownListGroup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-down-list-group", - items: [ - { - el: {} - } - ] - }); + _setCalendar: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { + this.calendar.empty(); + this._setCalenderValue(this._getNewCurrentDate()); + } else { + this._setCalenderValue(timeOb); + } }, - _init: function () { - BI.DownListGroup.superclass._init.apply(this, arguments); - var o = this.options, self = this; - this.downlistgroup = BI.createWidget({ - element: this, - type: "bi.button_tree", - items: o.items, - chooseType: 0, // 0单选,1多选 - layouts: [{ - type: "bi.vertical", - hgap: 0, - vgap: 0 - }], - value: o.value - }); - this.downlistgroup.on(BI.Controller.EVENT_CHANGE, function (type) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if(type === BI.Events.CLICK) { - self.fireEvent(BI.DownListGroup.EVENT_CHANGE, arguments); - } + 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.downlistgroup.getValue(); - }, - setValue: function (v) { - this.downlistgroup.setValue(v); + return this.selectedTime; } - }); -BI.DownListGroup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.down_list_group", BI.DownListGroup);BI.DownListItem = BI.inherit(BI.Single, { - _defaultConfig: function () { - var conf = BI.DownListItem.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: "bi-down-list-item bi-list-item-active", - cls: "", - height: 25, - logic: { - dynamic: true - }, - selected: false, - iconHeight: null, - iconWidth: null, - textHgap: 0, - textVgap: 0, - textLgap: 0, - textRgap: 0 - }); - }, - _init: function () { - BI.DownListItem.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.text = BI.createWidget({ - type: "bi.icon_text_item", - element: this, - height: o.height, - text: o.text, - value: o.value, - logic: o.logic, - selected: o.selected, - disabled: o.disabled, - iconHeight: o.iconHeight, - iconWidth: o.iconWidth, - textHgap: o.textHgap, - textVgap: o.textVgap, - textLgap: o.textLgap, - textRgap: o.textRgap, - father: o.father, - bubble: o.bubble - }); - this.text.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.text.on(BI.IconTextItem.EVENT_CHANGE, function () { - self.fireEvent(BI.DownListItem.EVENT_CHANGE); - }); - // this.setSelected(o.selected); - }, +BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.DynamicDateTimePane = BI.inherit(BI.Widget, { - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); + props: { + baseCls: "bi-dynamic-date-pane" }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); - }, + 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; + } + }; + } + } + }] + }; + }, - isSelected: function () { - return this.text.isSelected(); + mounted: function () { + this.setValue(this.options.value); }, - setSelected: function (b) { - this.text.setSelected(b); - // if (b === true) { - // this.element.addClass("dot-e-font"); - // } else { - // this.element.removeClass("dot-e-font"); - // } + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, setValue: function (v) { - this.text.setValue(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 this.text.getValue(); + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; } }); -BI.DownListItem.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.down_list_item", BI.DownListItem);BI.DownListGroupItem = BI.inherit(BI.BasicButton, { +BI.shortcut("bi.dynamic_date_time_pane", BI.DynamicDateTimePane); + +BI.extend(BI.DynamicDateTimePane, { + Static: 1, + Dynamic: 2 +});/** + * Created by roy on 15/8/14. + */ +BI.DownListCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { - var conf = BI.DownListGroupItem.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-down-list-group-item", - logic: { - dynamic: false - }, - // invalid: true, - iconCls1: "dot-e-font", - iconCls2: "pull-right-e-font" + return BI.extend(BI.DownListCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-down-list-combo", + height: 24, + items: [], + adjustLength: 0, + direction: "bottom", + trigger: "click", + container: null, + stopPropagation: false, + el: {} }); }, - _init: function () { - BI.DownListGroupItem.superclass._init.apply(this, arguments); - var o = this.options; - var self = this; - this.text = BI.createWidget({ - type: "bi.label", - cls: "list-group-item-text", - textAlign: "left", - text: o.text, - value: o.value, - height: o.height - }); - this.icon1 = BI.createWidget({ - type: "bi.icon_button", - cls: o.iconCls1, - width: 25, - forceNotSelected: true, - selected: this._digest(o.value) + _init: function () { + BI.DownListCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.popupview = BI.createWidget({ + type: "bi.down_list_popup", + items: o.items, + chooseType: o.chooseType, + value: o.value }); - this.icon2 = BI.createWidget({ - type: "bi.icon_button", - cls: o.iconCls2, - width: 25, - forceNotSelected: true + this.popupview.on(BI.DownListPopup.EVENT_CHANGE, function (value) { + self.fireEvent(BI.DownListCombo.EVENT_CHANGE, value); + self.downlistcombo.hideView(); }); - var blank = BI.createWidget({ - type: "bi.layout", - width: 25 - }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.icon2, - top: 0, - bottom: 0, - right: 0 - }] + this.popupview.on(BI.DownListPopup.EVENT_SON_VALUE_CHANGE, function (value, fatherValue) { + self.fireEvent(BI.DownListCombo.EVENT_SON_VALUE_CHANGE, value, fatherValue); + self.downlistcombo.hideView(); }); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { - items: BI.LogicFactory.createLogicItemsByDirection("left", this.icon1, this.text, blank) - })))); - this.element.hover(function () { - if (self.isEnabled()) { - self.hover(); - } - }, function () { - if (self.isEnabled()) { - self.dishover(); + this.downlistcombo = BI.createWidget({ + element: this, + type: "bi.combo", + trigger: o.trigger, + isNeedAdjustWidth: false, + container: o.container, + adjustLength: o.adjustLength, + direction: o.direction, + stopPropagation: o.stopPropagation, + el: BI.createWidget(o.el, { + type: "bi.icon_trigger", + extraCls: o.iconCls ? o.iconCls : "pull-down-font", + width: o.width, + height: o.height + }), + popup: { + el: this.popupview, + stopPropagation: true, + maxHeight: 1000 } }); - }, - _digest: function (v) { - var self = this, o = this.options; - v = BI.isArray(v) ? v : [v]; - return BI.any(v, function (idx, value) { - return BI.contains(o.childValues, value); + this.downlistcombo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.DownListCombo.EVENT_BEFORE_POPUPVIEW); }); }, - hover: function () { - BI.DownListGroupItem.superclass.hover.apply(this, arguments); - this.icon1.element.addClass("hover"); - this.icon2.element.addClass("hover"); + hideView: function () { + this.downlistcombo.hideView(); + }, + + showView: function () { + this.downlistcombo.showView(); + }, + + populate: function (items) { + this.popupview.populate(items); + }, + + setValue: function (v) { + this.popupview.setValue(v); + }, + getValue: function () { + return this.popupview.getValue(); + } +}); +BI.DownListCombo.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DownListCombo.EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE"; +BI.DownListCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + +BI.shortcut("bi.down_list_combo", BI.DownListCombo);/** + * Created by roy on 15/9/6. + */ +BI.DownListGroup = BI.inherit(BI.Widget, { + constants: { + iconCls: "check-mark-ha-font" + }, + _defaultConfig: function () { + return BI.extend(BI.DownListGroup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-down-list-group", + items: [ + { + el: {} + } + ] + }); + }, + _init: function () { + BI.DownListGroup.superclass._init.apply(this, arguments); + var o = this.options, self = this; + + this.downlistgroup = BI.createWidget({ + element: this, + type: "bi.button_tree", + items: o.items, + chooseType: 0, // 0单选,1多选 + layouts: [{ + type: "bi.vertical", + hgap: 0, + vgap: 0 + }], + value: o.value + }); + this.downlistgroup.on(BI.Controller.EVENT_CHANGE, function (type) { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + if(type === BI.Events.CLICK) { + self.fireEvent(BI.DownListGroup.EVENT_CHANGE, arguments); + } + }); + }, + getValue: function () { + return this.downlistgroup.getValue(); + }, + setValue: function (v) { + this.downlistgroup.setValue(v); + } + + +}); +BI.DownListGroup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.down_list_group", BI.DownListGroup);BI.DownListItem = BI.inherit(BI.Single, { + _defaultConfig: function () { + var conf = BI.DownListItem.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: "bi-down-list-item bi-list-item-active", + cls: "", + height: 25, + logic: { + dynamic: true + }, + selected: false, + iconHeight: null, + iconWidth: null, + textHgap: 0, + textVgap: 0, + textLgap: 0, + textRgap: 0 + }); + }, + _init: function () { + BI.DownListItem.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.text = BI.createWidget({ + type: "bi.icon_text_item", + element: this, + height: o.height, + text: o.text, + value: o.value, + logic: o.logic, + selected: o.selected, + disabled: o.disabled, + iconHeight: o.iconHeight, + iconWidth: o.iconWidth, + textHgap: o.textHgap, + textVgap: o.textVgap, + textLgap: o.textLgap, + textRgap: o.textRgap, + father: o.father, + bubble: o.bubble + }); + this.text.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + this.text.on(BI.IconTextItem.EVENT_CHANGE, function () { + self.fireEvent(BI.DownListItem.EVENT_CHANGE); + }); + // this.setSelected(o.selected); + }, + + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); + }, + + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); + }, + + isSelected: function () { + return this.text.isSelected(); + }, + + setSelected: function (b) { + this.text.setSelected(b); + // if (b === true) { + // this.element.addClass("dot-e-font"); + // } else { + // this.element.removeClass("dot-e-font"); + // } + }, + + setValue: function (v) { + this.text.setValue(v); + }, + + getValue: function () { + return this.text.getValue(); + } +}); +BI.DownListItem.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.down_list_item", BI.DownListItem);BI.DownListGroupItem = BI.inherit(BI.BasicButton, { + _defaultConfig: function () { + var conf = BI.DownListGroupItem.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-down-list-group-item", + logic: { + dynamic: false + }, + // invalid: true, + iconCls1: "dot-e-font", + iconCls2: "pull-right-e-font" + }); + }, + _init: function () { + BI.DownListGroupItem.superclass._init.apply(this, arguments); + var o = this.options; + var self = this; + this.text = BI.createWidget({ + type: "bi.label", + cls: "list-group-item-text", + textAlign: "left", + text: o.text, + value: o.value, + height: o.height + }); + + this.icon1 = BI.createWidget({ + type: "bi.icon_button", + cls: o.iconCls1, + width: 25, + forceNotSelected: true, + selected: this._digest(o.value) + }); + + this.icon2 = BI.createWidget({ + type: "bi.icon_button", + cls: o.iconCls2, + width: 25, + forceNotSelected: true + }); + + var blank = BI.createWidget({ + type: "bi.layout", + width: 25 + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.icon2, + top: 0, + bottom: 0, + right: 0 + }] + }); + + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { + items: BI.LogicFactory.createLogicItemsByDirection("left", this.icon1, this.text, blank) + })))); + + this.element.hover(function () { + if (self.isEnabled()) { + self.hover(); + } + }, function () { + if (self.isEnabled()) { + self.dishover(); + } + }); + }, + + _digest: function (v) { + var self = this, o = this.options; + v = BI.isArray(v) ? v : [v]; + return BI.any(v, function (idx, value) { + return BI.contains(o.childValues, value); + }); + }, + + hover: function () { + BI.DownListGroupItem.superclass.hover.apply(this, arguments); + this.icon1.element.addClass("hover"); + this.icon2.element.addClass("hover"); }, @@ -89012,7991 +89528,4150 @@ BI.DownListPopup = BI.inherit(BI.Pane, { BI.DownListPopup.EVENT_CHANGE = "EVENT_CHANGE"; BI.DownListPopup.EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE"; BI.shortcut("bi.down_list_popup", BI.DownListPopup);/** - * Created by zcf on 2017/2/20. + * 汇总表格帮助类 + * Created by Young's on 2017/1/19. */ -BI.StaticDatePaneCard = BI.inherit(BI.Widget, { - _defaultConfig: function () { - var conf = BI.StaticDatePaneCard.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: "bi-date-pane", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - selectedTime: null - }); - }, - _init: function () { - BI.StaticDatePaneCard.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 = self.datePicker.getValue(); - self.calendar.setSelect(BI.Calendar.getPageByDateJSON(self.selectedTime)); - }); - - this.calendar = BI.createWidget({ - direction: "top", - element: this, - 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 = self.calendar.getValue(); - self.calendar.empty(); - self.setValue(self.selectedTime); - self.fireEvent(BI.DateCalendarPopup.EVENT_CHANGE); - }); - 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 = date; - }, - - _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); - } - }, +!(function () { + BI.DynamicDateHelper = {}; + BI.extend(BI.DynamicDateHelper, { + getCalculation: function (obj) { + var date = BI.getDate(); + if (BI.isNotNull(obj.year)) { + date = BI.getDate((date.getFullYear() + BI.parseInt(obj.year)), date.getMonth(), date.getDate()); + } + if (BI.isNotNull(obj.quarter)) { + date = date.getAfterMulQuarter(obj.quarter); + } + if (BI.isNotNull(obj.month)) { + date = date.getAfterMultiMonth(obj.month); + } + if (BI.isNotNull(obj.week)) { + date = date.getOffsetDate(obj.week * 7); + } + if (BI.isNotNull(obj.day)) { + date = date.getOffsetDate(obj.day); + } + if (BI.isNotNull(obj.workDay)) { + // todo 根据工作日做偏移 + } + if (BI.isNotNull(obj.position) && obj.position !== BI.DynamicDateCard.OFFSET.CURRENT) { + date = this.getBeginDate(date, obj); + } + return date; + }, - _setCalendar: function (timeOb) { - if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { - this.calendar.empty(); - this._setCalenderValue(this._getNewCurrentDate()); - } else { - this._setCalenderValue(timeOb); + getBeginDate: function (date, obj) { + if (BI.isNotNull(obj.day)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), date.getMonth(), 1) : BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); + } + if (BI.isNotNull(obj.week)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? date.getWeekStartDate() : date.getWeekEndDate(); + } + if (BI.isNotNull(obj.month)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), date.getMonth(), 1) : BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); + } + if (BI.isNotNull(obj.quarter)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? date.getQuarterStartDate() : date.getQuarterEndDate(); + } + if (BI.isNotNull(obj.year)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), 0, 1) : BI.getDate(date.getFullYear(), 11, 31); + } } - }, - - setValue: function (timeOb) { - this._setDatePicker(timeOb); - this._setCalendar(timeOb); - }, - - getValue: function () { - return this.selectedTime; - } - -}); -BI.shortcut("bi.static_date_pane_card", BI.StaticDatePaneCard);BI.DynamicDatePane = BI.inherit(BI.Widget, { + }); +})();BI.DynamicDateCard = BI.inherit(BI.Widget, { props: { - baseCls: "bi-dynamic-date-pane" + baseCls: "bi-dynamic-date-card" }, render: function () { var self = this; + this.position = BI.DynamicDateCard.OFFSET.CURRENT; return { - type: "bi.vtape", + type: "bi.vertical", items: [{ el: { - type: "bi.linear_segment", - cls: "bi-border-bottom", - height: 30, - items: BI.createItems([{ - text: BI.i18nText("BI-Multi_Date_YMD"), - value: BI.DynamicDatePane.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicDatePane.Dynamic - }], { - textAlign: "center" - }), - listeners: [{ - eventName: BI.ButtonGroup.EVENT_CHANGE, - action: function () { - var value = this.getValue()[0]; - self.dateTab.setSelect(value); - switch (value) { - case BI.DynamicDatePane.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - break; - case BI.DynamicDatePane.Dynamic: - self.dynamicPane.setValue({ - year: 0 - }); - break; - default: - break; - } - } - }], - ref: function () { - self.switch = this; - } - }, - height: 30 + type: "bi.label", + text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), + textAlign: "left", + height: 24, + lgap: 10 + } }, { - type: "bi.tab", + type: "bi.button_group", ref: function () { - self.dateTab = this; + self.checkgroup = this; }, - showIndex: BI.DynamicDatePane.Static, - cardCreator: function (v) { - switch (v) { - case BI.DynamicDatePane.Static: - return { - type: "bi.static_date_pane_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }], - ref: function () { - self.ymd = this; - } - }; - case BI.DynamicDatePane.Dynamic: - default: + chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, + value: [BI.DynamicDateCard.TYPE.YEAR], + items: BI.createItems([{ + text: BI.i18nText("BI-Basic_Year"), + value: BI.DynamicDateCard.TYPE.YEAR + }, { + text: BI.i18nText("BI-Basic_Single_Quarter"), + value: BI.DynamicDateCard.TYPE.QUARTER + }, { + text: BI.i18nText("BI-Basic_Month"), + value: BI.DynamicDateCard.TYPE.MONTH + }, { + text: BI.i18nText("BI-Basic_Week"), + value: BI.DynamicDateCard.TYPE.WEEK + }, { + text: BI.i18nText("BI-Basic_Day"), + value: BI.DynamicDateCard.TYPE.DAY + }], { + type: "bi.multi_select_item", + logic: { + dynamic: true + } + }), + layouts: [{ + type: "bi.left" + }], + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + var value = self.checkgroup.getValue(); + if(value.length !== 0) { + self.workDayBox.setSelected(false); + } + self.resultPane.populate(self._getParamJson(BI.map(self.checkgroup.getValue(), function (idx, v) { return { - type: "bi.dynamic_date_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }], - ref: function () { - self.dynamicPane = this; - } + dateType: v }; + }))); + self.position = BI.DynamicDateCard.OFFSET.CURRENT; + self.fireEvent("EVENT_CHANGE"); } + }] + }, { + type: "bi.vertical_adapt", + items: [{ + type: "bi.multi_select_item", + ref: function () { + self.workDayBox = this; + }, + logic: { + dynamic: true + }, + text: BI.i18nText("BI-Basic_Work_Day"), + value: BI.DynamicDateCard.TYPE.WORK_DAY, + listeners: [{ + eventName: BI.MultiSelectItem.EVENT_CHANGE, + action: function () { + if(this.isSelected()) { + self.checkgroup.setValue(); + } + self.resultPane.populate(this.isSelected() ? self._getParamJson([{ + dateType: BI.DynamicDateCard.TYPE.WORK_DAY + }]) : []); + self.position = BI.DynamicDateCard.OFFSET.CURRENT; + self.fireEvent("EVENT_CHANGE"); + } + }] + }], + ref: function () { + self.workDay = this; } + }, { + type: "bi.button_group", + items: this._getParamJson([{ + dateType: BI.DynamicDateCard.TYPE.YEAR + }]), + ref: function () { + self.resultPane = this; + }, + layouts: [{ + type: "bi.vertical", + vgap: 10, + hgap: 10 + }] }] }; }, - mounted: function () { - this.setValue(this.options.value); + _getParamJson: function (values, positionValue) { + var self = this; + var items = BI.map(values, function (idx, value) { + return { + type: "bi.dynamic_date_param_item", + dateType: value.dateType, + value: value.value, + offset: value.offset, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }; + }); + + if(values.length === 1 && values[0] === BI.DynamicDateCard.TYPE.DAY) { + items.push = [{ + type: "bi.text_value_combo", + height: 24, + items: this._getText(BI.DynamicDateCard.TYPE.MONTH), + value: positionValue || BI.DynamicDateCard.OFFSET.CURRENT, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.position = this.getValue()[0]; + self.fireEvent("EVENT_CHANGE"); + } + }] + }]; + }else{ + if(values.length !== 0 && BI.last(values).dateType !== BI.DynamicDateCard.TYPE.DAY && BI.last(values).dateType !== BI.DynamicDateCard.TYPE.WORK_DAY) { + items.push({ + type: "bi.text_value_combo", + height: 24, + items: this._getText(BI.last(values).dateType), + value: positionValue || BI.DynamicDateCard.OFFSET.CURRENT, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.position = this.getValue()[0]; + self.fireEvent("EVENT_CHANGE"); + } + }] + }); + + } + } + + return items; }, - _checkValueValid: function (value) { - return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + _getText: function (lastValue) { + switch (lastValue) { + case BI.DynamicDateCard.TYPE.YEAR: + return [{ + text: BI.i18nText("BI-Basic_Current_Day"), + value: BI.DynamicDateCard.OFFSET.CURRENT + }, { + text: BI.i18nText("BI-Basic_Year_Begin"), + value: BI.DynamicDateCard.OFFSET.BEGIN + }, { + text: BI.i18nText("BI-Basic_Year_End"), + value: BI.DynamicDateCard.OFFSET.END + }]; + case BI.DynamicDateCard.TYPE.QUARTER: + return [{ + text: BI.i18nText("BI-Basic_Current_Day"), + value: BI.DynamicDateCard.OFFSET.CURRENT + }, { + text: BI.i18nText("BI-Basic_Quarter_Begin"), + value: BI.DynamicDateCard.OFFSET.BEGIN + }, { + text: BI.i18nText("BI-Basic_Quarter_End"), + value: BI.DynamicDateCard.OFFSET.END + }]; + case BI.DynamicDateCard.TYPE.MONTH: + return [{ + text: BI.i18nText("BI-Basic_Current_Day"), + value: BI.DynamicDateCard.OFFSET.CURRENT + }, { + text: BI.i18nText("BI-Basic_Month_Begin"), + value: BI.DynamicDateCard.OFFSET.BEGIN + }, { + text: BI.i18nText("BI-Basic_Month_End"), + value: BI.DynamicDateCard.OFFSET.END + }]; + case BI.DynamicDateCard.TYPE.WEEK: + default: + return [{ + text: BI.i18nText("BI-Basic_Current_Day"), + value: BI.DynamicDateCard.OFFSET.CURRENT + }, { + text: BI.i18nText("BI-Basic_Week_Begin"), + value: BI.DynamicDateCard.OFFSET.BEGIN + }, { + text: BI.i18nText("BI-Basic_Week_End"), + value: BI.DynamicDateCard.OFFSET.END + }]; + } + }, + + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, setValue: function (v) { v = v || {}; - var type = v.type || BI.DynamicDateCombo.Static; - var value = v.value || v; - this.switch.setValue(type); - this.dateTab.setSelect(type); - switch (type) { - case BI.DynamicDateCombo.Dynamic: - this.dynamicPane.setValue(value); - break; - case BI.DynamicDateCombo.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; + var values = []; + var valuesItems = []; + if(BI.isNotNull(v.year)) { + values.push(BI.DynamicDateCard.TYPE.YEAR); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); + } + if(BI.isNotNull(v.quarter)) { + values.push(BI.DynamicDateCard.TYPE.QUARTER); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); + } + if(BI.isNotNull(v.month)) { + values.push(BI.DynamicDateCard.TYPE.MONTH); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); + } + if(BI.isNotNull(v.week)) { + values.push(BI.DynamicDateCard.TYPE.WEEK); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.WEEK, v.week)); + } + if(BI.isNotNull(v.day)) { + values.push(BI.DynamicDateCard.TYPE.DAY); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.DAY, v.day)); + } + if(BI.isNotNull(v.workDay)) { + values.push(BI.DynamicDateCard.TYPE.WORK_DAY); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.WORK_DAY, v.workDay)); } + this.checkgroup.setValue(values); + this.workDayBox.setSelected(BI.isNotNull(v.workDay)); + this.resultPane.populate(this._getParamJson(valuesItems, v.position)); }, getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; + var self = this; + var valueMap = {}; + var selectValues = this.checkgroup.getValue(); + var buttons = this.resultPane.getAllButtons(); + if(selectValues.length !== 0) { + BI.each(buttons, function (idx, button) { + var value = button.getValue(); + switch (value.dateType) { + case BI.DynamicDateCard.TYPE.YEAR: + valueMap.year = (value.offset === 0 ? -value.value : value.value); + break; + case BI.DynamicDateCard.TYPE.QUARTER: + valueMap.quarter = (value.offset === 0 ? -value.value : value.value); + break; + case BI.DynamicDateCard.TYPE.MONTH: + valueMap.month = (value.offset === 0 ? -value.value : value.value); + break; + case BI.DynamicDateCard.TYPE.WEEK: + valueMap.week = (value.offset === 0 ? -value.value : value.value); + break; + case BI.DynamicDateCard.TYPE.DAY: + valueMap.day = (value.offset === 0 ? -value.value : value.value); + break; + default: + break; + } + if(BI.isNull(value.dateType)) { + valueMap.position = self.position || BI.DynamicDateCard.OFFSET.CURRENT; + } + }); + } + if(this.workDayBox.isSelected()) { + var value = buttons[0].getValue(); + valueMap.workDay = (value.offset === 0 ? -value.value : value.value); + } + return valueMap; } + }); -BI.shortcut("bi.dynamic_date_pane", BI.DynamicDatePane); +BI.shortcut("bi.dynamic_date_card", BI.DynamicDateCard); -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 - }); +BI.extend(BI.DynamicDateCard, { + TYPE: { + YEAR: 1, + QUARTER: 2, + MONTH: 3, + WEEK: 4, + DAY: 5, + WORK_DAY: 6 }, - - getValue: function () { - return this.selectedTime; + OFFSET: { + CURRENT: 1, + BEGIN: 2, + END: 3 } -}); -BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.DynamicDateTimePane = BI.inherit(BI.Widget, { +});BI.DynamicDateCombo = 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-pane" + baseCls: "bi-dynamic-date-combo bi-border", + height: 24 }, + render: function () { - var self = this; + var self = this, opts = this.options; + this.storeTriggerValue = ""; + var date = BI.getDate(); + this.storeValue = opts.value; return { - type: "bi.vtape", + type: "bi.htape", 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; - } - } - }], + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, ref: function () { - self.switch = this; + self.changeIcon = this; } }, - height: 30 + width: 24 }, { - 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"); + type: "bi.absolute", + items: [{ + el: { + type: "bi.combo", + ref: function () { + self.combo = this; + }, + toggle: false, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: { + type: "bi.dynamic_date_trigger", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.trigger = this; + }, + listeners: [{ + eventName: BI.DynamicDateTrigger.EVENT_KEY_DOWN, + action: function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); } - }], - 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"); + }, { + eventName: BI.DynamicDateTrigger.EVENT_STOP, + action: function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); } - }], - ref: function () { - self.dynamicPane = this; } - }; - } - } - }] - }; - }, - - mounted: function () { - this.setValue(this.options.value); + }, { + eventName: BI.DynamicDateTrigger.EVENT_TRIGGER_CLICK, + action: function () { + self.combo.toggle(); + } + }, { + eventName: BI.DynamicDateTrigger.EVENT_FOCUS, + action: function () { + self.storeTriggerValue = self.trigger.getKey(); + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + self.fireEvent(BI.DynamicDateCombo.EVENT_FOCUS); + } + }, { + eventName: BI.DynamicDateTrigger.EVENT_ERROR, + action: function () { + self.storeValue = { + year: date.getFullYear(), + month: date.getMonth() + }; + self.popup.setValue(); + self.fireEvent(BI.DynamicDateCombo.EVENT_ERROR); + } + }, { + eventName: BI.DynamicDateTrigger.EVENT_VALID, + action: function () { + self.fireEvent(BI.DynamicDateCombo.EVENT_VALID); + } + }, { + eventName: BI.DynamicDateTrigger.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateCombo.EVENT_CHANGE); + } + }, { + eventName: BI.DynamicDateTrigger.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.DynamicDateCombo.EVENT_CONFIRM); + } + }] + }, + adjustLength: this.constants.comboAdjustHeight, + popup: { + el: { + type: "bi.dynamic_date_popup", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDatePopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }] + }, + stopPropagation: false + }, + listeners: [{ + eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, + action: function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicDateCombo.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; + } + }; }, - _checkValueValid: function (value) { - return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + mounted: function () { + this._checkDynamicValue(this.options.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); + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } switch (type) { - case BI.DynamicDateTimePane.Dynamic: - this.dynamicPane.setValue(value); + case BI.DynamicDateCombo.Dynamic: + this.changeIcon.setVisible(true); + this.comboWrapper.attr("items")[0].width = 24; + this.comboWrapper.resize(); 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); - } + 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 { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; + return this.storeValue; + }, + getKey: function () { + return this.trigger.getKey(); + }, + hidePopupView: function () { + this.combo.hideView(); } }); -BI.shortcut("bi.dynamic_date_time_pane", BI.DynamicDateTimePane); -BI.extend(BI.DynamicDateTimePane, { +BI.DynamicDateCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateCombo.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateCombo.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateCombo.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateCombo.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW = "BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW"; + +BI.shortcut("bi.dynamic_date_combo", BI.DynamicDateCombo); + +BI.extend(BI.DynamicDateCombo, { Static: 1, Dynamic: 2 -});/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.YearCard - * @extends BI.Trigger - */ -BI.DynamicYearCard = BI.inherit(BI.Widget, { +});BI.DynamicDateParamItem = BI.inherit(BI.Widget, { props: { - baseCls: "bi-year-card" + baseCls: "bi-dynamic-date-param-item", + dateType: BI.DynamicDateCard.TYPE.YEAR, + value: 0, + offset: 0, + height: 24 }, render: function () { - var self = this; + var self = this, o = this.options; return { - type: "bi.vertical", + type: "bi.htape", items: [{ - type: "bi.label", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - textAlign: "left", - height: 24 - }, { - type: "bi.dynamic_date_param_item", - ref: function () { - self.item = this; + el: { + type: "bi.sign_editor", + cls: "bi-border", + height: 22, + validationChecker: function (v) { + return BI.isNaturalNumber(v); + }, + value: o.value, + ref: function () { + self.editor = this; + }, + errorText: function (v) { + if(BI.isEmptyString(v)) { + return BI.i18nText("BI-Basic_Input_Can_Not_Null"); + } + return BI.i18nText("BI-Please_Input_Positive_Integer"); + }, + allowBlank: false, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + self.fireEvent(BI.DynamicDateParamItem.EVENT_CHANGE); + } + }] }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); + width: 60 + }, { + el: { + type: "bi.label", + height: 24, + text: this._getText() + }, + width: 20 + }, { + type: "bi.text_value_combo", + height: 24, + items: [{ + text: BI.i18nText("BI-Basic_Front"), + value: 0 + }, { + text: BI.i18nText("BI-Basic_Behind"), + value: 1 + }], + ref: function () { + self.offsetCombo = this; + }, + value: o.offset, + listeners: [{ + eventName: BI.TextValueCombo.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateParamItem.EVENT_CHANGE); } }] - }], - vgap: 10, - hgap: 10 + }] }; }, - _createValue: function (type, v) { - return { - dateType: type, - value: Math.abs(v), - offset: v > 0 ? 1 : 0 - }; + _getText: function () { + var text = ""; + switch (this.options.dateType) { + case BI.DynamicDateCard.TYPE.YEAR: + text = BI.i18nText("BI-Basic_Year"); + break; + case BI.DynamicDateCard.TYPE.QUARTER: + text = BI.i18nText("BI-Basic_Single_Quarter"); + break; + case BI.DynamicDateCard.TYPE.MONTH: + text = BI.i18nText("BI-Basic_Month"); + break; + case BI.DynamicDateCard.TYPE.WEEK: + text = BI.i18nText("BI-Basic_Week"); + break; + case BI.DynamicDateCard.TYPE.DAY: + default: + text = BI.i18nText("BI-Basic_Day"); + break; + } + return text; }, setValue: function (v) { - v = v || {year: 0}; - this.item.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); + v = v || {}; + v.value = v.value || 0; + v.offset = v.offset || 0; + this.editor.setValue(v.value); + this.offsetCombo.setValue(v.offset); }, getValue: function () { - var value = this.item.getValue(); return { - year: (value.offset === 0 ? -value.value : value.value) + dateType: this.options.dateType, + value: this.editor.getValue(), + offset: this.offsetCombo.getValue()[0] }; } -}); -BI.DynamicYearCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_card", BI.DynamicYearCard);/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.StaticYearCard - * @extends BI.Trigger - */ -BI.StaticYearCard = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.StaticYearCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-card", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31" // 最大日期 - }); +}); +BI.DynamicDateParamItem.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_date_param_item", BI.DynamicDateParamItem);BI.DynamicDatePopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 }, - - _createYearCalendar: function (v) { - var o = this.options, y = this._year; - - var calendar = BI.createWidget({ - type: "bi.year_calendar", - behaviors: o.behaviors, - min: o.min, - max: o.max, - logic: { - dynamic: true - }, - year: y + v * 12 - }); - calendar.setValue(this._year); - return calendar; + + props: { + baseCls: "bi-dynamic-date-popup", + width: 248, + height: 344 }, - + _init: function () { - BI.StaticYearCard.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.selectedYear = this._year = BI.getDate().getFullYear(); - - this.backBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "pre-page-h-font", - width: 25, - height: 25, - value: -1, - listeners: [{ - eventName: BI.IconButton.EVENT_CHANGE, - action: function () { - self.navigation.setSelect(self.navigation.getSelect() - 1); - self._checkLeftValid(); - self._checkRightValid(); - } - }] - }); - - this.preBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "next-page-h-font", - width: 25, - height: 25, - value: 1, - listeners: [{ - eventName: BI.IconButton.EVENT_CHANGE, - action: function () { - self.navigation.setSelect(self.navigation.getSelect() + 1); - self._checkLeftValid(); - self._checkRightValid(); - } + BI.DynamicDatePopup.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.DynamicDatePopup.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.DynamicDatePopup.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.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 }] }); + this.setValue(opts.value); + }, - this.navigation = BI.createWidget({ - type: "bi.navigation", - direction: "top", - element: this, - single: true, - logic: { - dynamic: true + _getTabJson: function () { + var self = this; + return { + type: "bi.tab", + showIndex: BI.DynamicDateCombo.Static, + ref: function () { + self.dateTab = this; }, tab: { - type: "bi.htape", - cls: "bi-border-top bi-border-bottom", - height: 30, - items: [{ - el: { - type: "bi.center_adapt", - items: [self.backBtn] - }, - width: 25 - }, { - type: "bi.layout" + 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 }, { - el: { - type: "bi.center_adapt", - items: [self.preBtn] - }, - width: 25 - }] + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDateCombo.Dynamic + }], { + textAlign: "center" + }) }, - cardCreator: BI.bind(this._createYearCalendar, this), - - afterCardShow: function () { - this.setValue(self.selectedYear); - var calendar = this.getSelectedCard(); - self.backBtn.setEnable(!calendar.isFrontYear()); - self.preBtn.setEnable(!calendar.isFinalYear()); - } - }); - - this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { - self.selectedYear = this.getValue(); - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.StaticYearCard.EVENT_CHANGE, self.selectedYear); - }); + 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.date_calendar_popup", + min: self.options.min, + max: self.options.max, + listeners: [{ + eventName: BI.DateCalendarPopup.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDatePopup.EVENT_CHANGE); + } + }], + ref: function () { + self.ymd = this; + } + }; + } + }, + 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._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; + } + } + }] + }; + }, - if(BI.isKey(o.value)){ - this.setValue(o.value); + _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); } }, - _checkLeftValid: function () { - var o = this.options; - var valid = true; - this.backBtn.setEnable(valid); - return valid; + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, - _checkRightValid: function () { - var o = this.options; - var valid = true; - this.preBtn.setEnable(valid); - return valid; + 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 { - year: this.selectedYear + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() }; - }, - - setValue: function (obj) { - var o = this.options; - obj = obj || {}; - var v = obj.year; - if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { - v = BI.getDate().getFullYear(); - this.selectedYear = ""; - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(""); - } else { - this.selectedYear = BI.parseInt(v); - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(this.selectedYear); - } - this._checkLeftValid(); - this._checkRightValid(); } }); -BI.StaticYearCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.inherit(BI.Widget, { +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: { - baseCls: "bi-year-combo bi-border", - behaviors: {}, + extraCls: "bi-date-trigger", min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24 }, _init: function () { - BI.DynamicYearCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = o.value; - this.trigger = BI.createWidget({ - type: "bi.dynamic_year_trigger", - min: o.min, - max: o.max, - value: o.value || "" + 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.trigger.on(BI.DynamicYearTrigger.EVENT_FOCUS, function () { - self.storeTriggerValue = this.getKey(); + this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_FOCUS); }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_STOP, function () { - self.combo.showView(); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_STOP); }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); + this.editor.on(BI.SignEditor.EVENT_VALID, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_VALID); }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; + 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 (this.getKey() && this.getKey() !== self.storeTriggerValue) { - self.storeValue = self.trigger.getValue(); - self.setValue(self.storeValue); - } else if (!this.getKey()) { - self.storeValue = null; - self.setValue(); + + 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.DynamicYearCombo.EVENT_CONFIRM); + self.fireEvent(BI.DynamicDateTrigger.EVENT_CONFIRM); }); - - this.combo = BI.createWidget({ - type: "bi.combo", - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.dynamic_year_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicYearPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({year: date.getFullYear()}); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" + this.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); } }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW); + 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, - ref: function () { - self.comboWrapper = this; - }, 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 - }, this.combo] + el: this.editor + }, { + el: BI.createWidget(), + width: 30 + }] }); - this._checkDynamicValue(o.value); + 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; + } + } }, - _checkDynamicValue: function (v) { - var type = null; + _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; + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; } switch (type) { - case BI.DynamicYearCombo.Dynamic: - this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 24; - this.comboWrapper.resize(); + case BI.DynamicDateCombo.Dynamic: + var text = this._getText(value); + date = BI.DynamicDateHelper.getCalculation(value); + this._setInnerValue(date, text); break; + case BI.DynamicDateCombo.Static: default: - this.comboWrapper.attr("items")[0].width = 0; - this.comboWrapper.resize(); - this.changeIcon.setVisible(false); + 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; } }, - setValue: function (v) { - this.storeValue = v; - this.trigger.setValue(v); - this._checkDynamicValue(v); + getKey: function () { + return this.editor.getValue(); }, - getValue: function () { return this.storeValue; } }); -BI.DynamicYearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.dynamic_year_combo", BI.DynamicYearCombo); -BI.extend(BI.DynamicYearCombo, { - Static: 1, - Dynamic: 2 -});/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.DynamicYearPopup - * @extends BI.Trigger - */ -BI.DynamicYearPopup = BI.inherit(BI.Widget, { +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: { - tabHeight: 30 + popupHeight: 259, + popupWidth: 270, + comboAdjustHeight: 1, + border: 1, + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" }, props: { - baseCls: "bi-year-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期, - width: 180, - height: 240 + baseCls: "bi-dynamic-date-combo bi-border", + height: 24 }, + render: function () { var self = this, opts = this.options; - this.storeValue = {type: BI.DynamicYearCombo.Static}; + this.storeTriggerValue = ""; + var date = BI.getDate(); + this.storeValue = opts.value; return { - type: "bi.vtape", + type: "bi.htape", items: [{ - el: this._getTabJson() - }, { el: { - type: "bi.grid", - items: [[{ - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_Clear"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.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-Basic_Current_Year"), - ref: function () { - self.textButton = this; - }, - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE); - } - }] - }, { - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_OK"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE); - } - }] - }]] + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, + ref: function () { + self.changeIcon = this; + } }, - height: 24 - }] - }; - }, - - _setInnerValue: function () { - if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); - this.textButton.setEnable(true); - } else { - var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); - date = date.print("%Y"); - this.textButton.setValue(date); - this.textButton.setEnable(false); - } - }, - - _getTabJson: function () { - var self = this, o = this.options; - return { - type: "bi.tab", - 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-Basic_Year_Fen"), - value: BI.DynamicYearCombo.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicYearCombo.Dynamic - }], { - textAlign: "center" - }) - }, - cardCreator: function (v) { - switch (v) { - case BI.DynamicYearCombo.Dynamic: - return { - type: "bi.dynamic_year_card", + 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: "EVENT_CHANGE", + eventName: BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN, action: function () { - self._setInnerValue(self.year, v); + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } } - }], - ref: function () { - self.dynamicPane = this; - } - }; - case BI.DynamicYearCombo.Static: - default: - return { - type: "bi.static_year_card", - behaviors: o.behaviors, - min: self.options.min, - max: self.options.max, - listeners: [{ - eventName: BI.YearCard.EVENT_CHANGE, + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_STOP, action: function () { - self.fireEvent(BI.DynamicYearPopup.EVENT_CHANGE); + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } } - }], - ref: function () { - self.year = this; - } - }; - } - }, - listeners: [{ - eventName: BI.Tab.EVENT_CHANGE, - action: function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.DynamicYearCombo.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.year.setValue({year: date.getFullYear()}); - self._setInnerValue(); - break; - case BI.DynamicYearCombo.Dynamic: - default: - if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { - self.dynamicPane.setValue(self.storeValue.value); - }else{ - self.dynamicPane.setValue({ - year: 0 - }); + }, { + 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); } - self._setInnerValue(); - break; - } - } - }] - }; - }, - - 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: - this.year.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); - this.textButton.setEnable(true); - break; - } - }, - - getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; - } - -}); -BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.DynamicYearPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_popup", BI.DynamicYearPopup);BI.DynamicYearTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") - }, - - _defaultConfig: function () { - return BI.extend(BI.DynamicYearTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-year-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }); - }, - _init: function () { - BI.DynamicYearTrigger.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) { - return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - allowBlank: true, - errorText: function (v) { - return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; - } - }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_FOCUS); - }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_STOP); - }); - this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - } - if (BI.isNotEmptyString(value)) { - self.storeValue = { - type: BI.DynamicDateCombo.Static, - value: { - year: value - } - }; - } - - self.fireEvent(BI.DynamicYearTrigger.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.DynamicYearTrigger.EVENT_START); - }); - this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_ERROR); - }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [{ - el: this.editor - }, { - el: { - type: "bi.text_button", - baseCls: "bi-trigger-year-text", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, - width: o.height - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - }] - }); - this.setValue(o.value); - }, - - _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")); - } - return value; - }, - - _setInnerValue: function (date, text) { - var dateStr = date.print("%Y"); - this.editor.setState(dateStr); - this.editor.setValue(dateStr); - this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); - }, - - setValue: function (v) { - var type, value; - 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: - value = value || {}; - this.editor.setState(value.year); - this.editor.setValue(value.year); - this.editor.setTitle(value.year); - break; - } - }, - - getValue: function () { - return this.storeValue; - }, - - getKey: function () { - return this.editor.getValue() | 0; - } -}); -BI.DynamicYearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DynamicYearTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.DynamicYearTrigger.EVENT_START = "EVENT_START"; -BI.DynamicYearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.dynamic_year_trigger", BI.DynamicYearTrigger);/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.YearCard - * @extends BI.Trigger - */ -BI.DynamicYearMonthCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-year-month-card" - }, - - render: function () { - var self = this; - return { - type: "bi.vertical", - items: [{ - type: "bi.label", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - textAlign: "left", - height: 24 - }, { - type: "bi.dynamic_date_param_item", - ref: function () { - self.year = this; - }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }, { - type: "bi.dynamic_date_param_item", - dateType: BI.DynamicDateCard.TYPE.MONTH, - ref: function () { - self.month = this; - }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }], - vgap: 10, - hgap: 10 - }; - }, - - _createValue: function (type, v) { - return { - dateType: type, - value: Math.abs(v), - offset: v > 0 ? 1 : 0 - }; - }, - - setValue: function (v) { - v = v || {year: 0, month: 0}; - this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); - this.month.setValue(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); - }, - - getValue: function () { - var year = this.year.getValue(); - var month = this.month.getValue(); - return { - year: (year.offset === 0 ? -year.value : year.value), - month: (month.offset === 0 ? -month.value : month.value) - }; - } -}); -BI.DynamicYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_month_card", BI.DynamicYearMonthCard);BI.StaticYearMonthCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-static-year-month-card", - behaviors: {} - }, - - _createMonths: function () { - // 纵向排列月 - var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; - var items = []; - items.push(month.slice(0, 2)); - items.push(month.slice(2, 4)); - items.push(month.slice(4, 6)); - items.push(month.slice(6, 8)); - items.push(month.slice(8, 10)); - items.push(month.slice(10, 12)); - return BI.map(items, function (i, item) { - return BI.map(item, function (j, td) { - return { - type: "bi.text_item", - cls: "bi-list-item-active", - textAlign: "center", - whiteSpace: "nowrap", - once: false, - forceSelected: true, - height: 23, - width: 38, - value: td, - text: td + 1 - }; - }); - }); - }, - - render: function () { - var self = this, o = this.options; - return { - type: "bi.vertical", - items: [{ - type: "bi.year_picker", - ref: function () { - self.yearPicker = this; - }, - height: 30, - listeners: [{ - eventName: BI.YearPicker.EVENT_CHANGE, - action: function () { - var value = this.getValue(); - self.setValue({ - year: value, - month: self.selectedMonth - }); - } - }] - }, { - type: "bi.button_group", - behaviors: o.behaviors, - ref: function () { - self.month = this; - }, - items: this._createMonths(), - layouts: [BI.LogicFactory.createLogic("table", BI.extend({ - dynamic: true - }, { - columns: 2, - rows: 6, - columnSize: [1 / 2, 1 / 2], - rowSize: 25 - })), { - type: "bi.center_adapt", - vgap: 1, - hgap: 2 - }], - value: o.value, - listeners: [{ - eventName: BI.ButtonGroup.EVENT_CHANGE, - action: function () { - self.selectedYear = self.yearPicker.getValue(); - self.selectedMonth = this.getValue()[0]; - self.fireEvent(BI.StaticYearMonthCard.EVENT_CHANGE); - } - }] - }] - }; - }, - - - getValue: function () { - return { - year: this.selectedYear, - month: this.selectedMonth - }; - }, - - setValue: function (obj) { - var o = this.options; - obj = obj || {}; - obj.year = obj.year || 0; - obj.month = obj.month || 0; - if (BI.checkDateVoid(obj.year, obj.month, 1, o.min, o.max)[0]) { - var year = BI.getDate().getFullYear(); - var month = BI.getDate().getMonth(); - this.selectedYear = ""; - this.selectedMonth = ""; - this.yearPicker.setValue(year); - this.month.setValue(month); - } else { - this.selectedYear = BI.parseInt(obj.year); - this.selectedMonth = BI.parseInt(obj.month); - this.yearPicker.setValue(this.selectedYear); - this.month.setValue(this.selectedMonth); - } - } -}); -BI.StaticYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; -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: 24 - }, - - _init: function () { - BI.DynamicYearMonthCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = o.value; - this.trigger = BI.createWidget({ - type: "bi.dynamic_year_month_trigger", - min: o.min, - max: o.max, - value: o.value || "" - }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_STOP, function () { - self.combo.showView(); - }); - 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()) { - return; - } - 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", - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.dynamic_year_month_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicYearMonthPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({year: date.getFullYear()}); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - ref: function () { - self.comboWrapper = this; - }, - 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 - }, this.combo] - }); - this._checkDynamicValue(o.value); - }, - - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.DynamicYearMonthCombo.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; - } - }, - - hideView: function () { - this.combo.hideView(); - }, - - setValue: function (v) { - this.storeValue = v; - this.trigger.setValue(v); - this._checkDynamicValue(v); - }, - - 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); - -BI.extend(BI.DynamicYearMonthCombo, { - Static: 1, - Dynamic: 2 -});/** - * 年月 - * - * Created by GUY on 2015/9/2. - * @class BI.DynamicYearMonthPopup - * @extends BI.Trigger - */ -BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30 - }, - - props: { - baseCls: "bi-year-month-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期, - width: 180, - height: 240 - }, - - render: function () { - var self = this, opts = this.options; - this.storeValue = {type: BI.DynamicYearMonthCombo.Static}; - return { - type: "bi.vtape", - items: [{ - el: this._getTabJson() - }, { - el: { - type: "bi.grid", - items: [[{ - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_Clear"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearMonthPopup.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-Basic_Current_Month"), - ref: function () { - self.textButton = this; - }, - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE); - } - }] - }, { - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_OK"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE); - } - }] - }]] - }, - height: 24 - }] - }; - }, - - _setInnerValue: function () { - if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); - this.textButton.setEnable(true); - } else { - var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); - date = date.print("%Y-%x"); - this.textButton.setValue(date); - this.textButton.setEnable(false); - } - }, - - _getTabJson: function () { - var self = this, o = this.options; - return { - type: "bi.tab", - 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-Basic_Year_Fen"), - value: BI.DynamicYearCombo.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicYearCombo.Dynamic - }], { - textAlign: "center" - }) - }, - cardCreator: function (v) { - switch (v) { - case BI.DynamicYearCombo.Dynamic: - return { - type: "bi.dynamic_year_month_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self._setInnerValue(self.year, v); - } - }], - ref: function () { - self.dynamicPane = this; - } - }; - case BI.DynamicYearCombo.Static: - default: - return { - type: "bi.static_year_month_card", - behaviors: o.behaviors, - min: self.options.min, - max: self.options.max, - listeners: [{ - eventName: BI.YearCard.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearMonthPopup.EVENT_CHANGE); - } - }], - ref: function () { - self.year = this; - } - }; - } - }, - listeners: [{ - eventName: BI.Tab.EVENT_CHANGE, - action: function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.DynamicYearCombo.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.year.setValue({year: date.getFullYear(), month: date.getMonth()}); - self._setInnerValue(); - break; - case BI.DynamicYearCombo.Dynamic: - default: - if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { - self.dynamicPane.setValue(self.storeValue.value); - }else{ - self.dynamicPane.setValue({ - year: 0 - }); - } - self._setInnerValue(); - break; - } - } - }] - }; - }, - - 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: - this.year.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); - this.textButton.setEnable(true); - break; - } - }, - - getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; - } - -}); -BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.DynamicYearMonthPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_month_popup", BI.DynamicYearMonthPopup);BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") - }, - - props: { - extraCls: "bi-year-month-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }, - - _init: function () { - BI.DynamicYearMonthTrigger.superclass._init.apply(this, arguments); - var o = this.options; - - this.yearEditor = this._createEditor(true); - this.monthEditor = this._createEditor(false); - - BI.createWidget({ - element: this, - type: "bi.htape", - items: [{ - type: "bi.center", - items: [{ - type: "bi.htape", - items: [this.yearEditor, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, - width: o.height - }] - }, { - type: "bi.htape", - items: [this.monthEditor, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Month"), - width: o.height - }, - width: o.height}] - }] - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - }] - }); - this.setValue(o.value); - }, - - _createEditor: function (isYear) { - var self = this, o = this.options, c = this._const; - var editor = BI.createWidget({ - type: "bi.sign_editor", - height: o.height, - validationChecker: function (v) { - if(isYear) { - return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); - } - return v === "" || ((v >= 1 && v <= 12) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); - }, - quitChecker: function () { - return false; - }, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - errorText: function (v) { - return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; - }, - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true - }); - editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_FOCUS); - }); - editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_STOP); - }); - editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = editor.getValue(); - if (BI.isNotNull(value)) { - editor.setValue(value); - } - if (BI.isNotEmptyString(value)) { - var monthValue = self.monthEditor.getValue(); - self.storeValue = { - type: BI.DynamicDateCombo.Static, - value: { - year: self.yearEditor.getValue(), - month: BI.isEmptyString(self.monthEditor.getValue()) ? "" : monthValue - 1 - } - }; - } - - self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_CONFIRM); - }); - editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (editor.isValid()) { - editor.blur(); - } - }); - editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_START); - }); - 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()); - } - }); - - return editor; - }, - - _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; - }, - - _autoSwitch: function (v) { - if (BI.checkDateLegal(v)) { - if (v.length === 4 && this._yearCheck(v)) { - this.monthEditor.focus(); - } - } - }, - - _getText: function (obj) { - var value = ""; - if(BI.isNotNull(obj.year)) { - value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); - } - if(BI.isNotNull(obj.month) && obj.month !== 0) { - value += Math.abs(obj.month) + BI.i18nText("BI-Basic_Year") + (obj.month < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); - } - return value; - }, - - _setInnerValue: function (date, text) { - var dateStr = date.print("%Y-%x"); - this.yearEditor.setValue(date.getFullYear()); - this.monthEditor.setValue(date.getMonth() + 1); - this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); - }, - - setValue: function (v) { - var type, value; - 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: - value = value || {}; - var month = BI.isNull(value.month) ? null : value.month + 1; - this.yearEditor.setValue(value.year); - this.yearEditor.setTitle(value.year); - this.monthEditor.setValue(month); - this.monthEditor.setTitle(month); - break; - } - }, - - 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"; -BI.DynamicYearMonthTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearMonthTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.dynamic_year_month_trigger", BI.DynamicYearMonthTrigger);/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.YearCard - * @extends BI.Trigger - */ -BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-year-month-card" - }, - - render: function () { - var self = this; - return { - type: "bi.vertical", - items: [{ - type: "bi.label", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - textAlign: "left", - height: 24 - }, { - type: "bi.dynamic_date_param_item", - ref: function () { - self.year = this; - }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }, { - type: "bi.dynamic_date_param_item", - dateType: BI.DynamicDateCard.TYPE.QUARTER, - ref: function () { - self.quarter = this; - }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }], - vgap: 10, - hgap: 10 - }; - }, - - _createValue: function (type, v) { - return { - dateType: type, - value: Math.abs(v), - offset: v > 0 ? 1 : 0 - }; - }, - - setValue: function (v) { - v = v || {year: 0, month: 0}; - this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); - this.quarter.setValue(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); - }, - - getValue: function () { - var year = this.year.getValue(); - var quarter = this.quarter.getValue(); - return { - year: (year.offset === 0 ? -year.value : year.value), - quarter: (quarter.offset === 0 ? -quarter.value : quarter.value) - }; - } -}); -BI.DynamicYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_quarter_card", BI.DynamicYearQuarterCard);BI.StaticYearQuarterCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-static-year-quarter-card", - behaviors: {} - }, - - _createQuarter: function () { - - var items = [{ - text: Date._QN[1], - value: 1 - }, { - text: Date._QN[2], - value: 2 - }, { - text: Date._QN[3], - value: 3 - }, { - text: Date._QN[4], - value: 4 - }]; - return BI.map(items, function (j, item) { - return BI.extend(item, { - type: "bi.text_item", - cls: "bi-list-item-active", - textAlign: "center", - whiteSpace: "nowrap", - once: false, - forceSelected: true, - height: 24 - }); - }); - }, - - render: function () { - var self = this, o = this.options; - return { - type: "bi.vertical", - items: [{ - type: "bi.year_picker", - ref: function () { - self.yearPicker = this; - }, - height: 30, - listeners: [{ - eventName: BI.YearPicker.EVENT_CHANGE, - action: function () { - var value = this.getValue(); - self.setValue({ - year: value, - quarter: self.selectedQuarter - }); - } - }] - }, { - type: "bi.button_group", - behaviors: o.behaviors, - ref: function () { - self.quarter = this; - }, - items: this._createQuarter(), - layouts: [{ - type: "bi.vertical", - vgap: 10 - }], - value: o.value, - listeners: [{ - eventName: BI.ButtonGroup.EVENT_CHANGE, - action: function () { - self.selectedYear = self.yearPicker.getValue(); - self.selectedQuarter = this.getValue()[0]; - self.fireEvent(BI.StaticYearQuarterCard.EVENT_CHANGE); - } - }] - }] - }; - }, - - - getValue: function () { - return { - year: this.selectedYear, - quarter: this.selectedQuarter - }; - }, - - setValue: function (obj) { - var o = this.options; - obj = obj || {}; - obj.year = obj.year || 0; - obj.quarter = obj.quarter || 0; - if (BI.checkDateVoid(obj.year, obj.quarter, 1, o.min, o.max)[0]) { - var year = BI.getDate().getFullYear(); - var quarter = BI.getDate().getQuarter(); - this.selectedYear = ""; - this.selectedQuarter = ""; - this.yearPicker.setValue(year); - this.quarter.setValue(quarter); - } else { - this.selectedYear = BI.parseInt(obj.year); - this.selectedQuarter = BI.parseInt(obj.quarter); - this.yearPicker.setValue(this.selectedYear); - this.quarter.setValue(this.selectedQuarter); - } - } -}); -BI.StaticYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-year-quarter-combo bi-border", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }, - - _init: function () { - BI.DynamicYearQuarterCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = o.value; - this.trigger = BI.createWidget({ - type: "bi.dynamic_year_quarter_trigger", - min: o.min, - max: o.max, - value: o.value || "" - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () { - self.combo.showView(); - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; - } - self.storeValue = self.trigger.getValue(); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); - }); - - this.combo = BI.createWidget({ - type: "bi.combo", - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.dynamic_year_quarter_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicYearQuarterPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({year: date.getFullYear()}); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - ref: function () { - self.comboWrapper = this; - }, - 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 - }, this.combo] - }); - this._checkDynamicValue(o.value); - }, - - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.DynamicYearQuarterCombo.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; - } - -}); -BI.DynamicYearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.dynamic_year_quarter_combo", BI.DynamicYearQuarterCombo); - -BI.extend(BI.DynamicYearQuarterCombo, { - Static: 1, - Dynamic: 2 -});BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30 - }, - - props: { - baseCls: "bi-year-quarter-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期, - width: 180, - height: 240 - }, - - render: function () { - var self = this, opts = this.options; - this.storeValue = {type: BI.DynamicYearQuarterCombo.Static}; - return { - type: "bi.vtape", - items: [{ - el: this._getTabJson() - }, { - el: { - type: "bi.grid", - items: [[{ - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_Clear"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearQuarterPopup.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-Basic_Current_Quarter"), - ref: function () { - self.textButton = this; - }, - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE); - } - }] - }, { - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_OK"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE); - } - }] - }]] - }, - height: 24 - }] - }; - }, - - _setInnerValue: function () { - if (this.dateTab.getSelect() === BI.DynamicYearQuarterCombo.Static) { - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); - this.textButton.setEnable(true); - } else { - var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); - date = date.print("%Y-%x"); - this.textButton.setValue(date); - this.textButton.setEnable(false); - } - }, - - _getTabJson: function () { - var self = this, o = this.options; - return { - type: "bi.tab", - 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-Basic_Year_Fen"), - value: BI.DynamicYearQuarterCombo.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicYearQuarterCombo.Dynamic - }], { - textAlign: "center" - }) - }, - cardCreator: function (v) { - switch (v) { - case BI.DynamicYearQuarterCombo.Dynamic: - return { - type: "bi.dynamic_year_quarter_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self._setInnerValue(self.year, v); - } - }], - ref: function () { - self.dynamicPane = this; - } - }; - case BI.DynamicYearQuarterCombo.Static: - default: - return { - type: "bi.static_year_quarter_card", - behaviors: o.behaviors, - min: self.options.min, - max: self.options.max, - listeners: [{ - eventName: BI.YearCard.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearQuarterPopup.EVENT_CHANGE); - } - }], - ref: function () { - self.year = this; - } - }; - } - }, - listeners: [{ - eventName: BI.Tab.EVENT_CHANGE, - action: function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.DynamicYearQuarterCombo.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.year.setValue({year: date.getFullYear(), quarter: date.getQuarter()}); - self._setInnerValue(); - break; - case BI.DynamicYearQuarterCombo.Dynamic: - default: - if(self.storeValue && self.storeValue.type === BI.DynamicYearQuarterCombo.Dynamic) { - self.dynamicPane.setValue(self.storeValue.value); - }else{ - self.dynamicPane.setValue({ - year: 0 - }); - } - self._setInnerValue(); - break; - } - } - }] - }; - }, - - 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: - this.year.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); - this.textButton.setEnable(true); - break; - } - }, - - getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; - } - -}); -BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.DynamicYearQuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_quarter_popup", BI.DynamicYearQuarterPopup);BI.DynamicYearQuarterTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") - }, - - props: { - extraCls: "bi-year-quarter-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }, - - _init: function () { - BI.DynamicYearQuarterTrigger.superclass._init.apply(this, arguments); - var o = this.options; - - this.yearEditor = this._createEditor(true); - this.quarterEditor = this._createEditor(false); - - BI.createWidget({ - element: this, - type: "bi.htape", - items: [{ - type: "bi.center", - items: [{ - type: "bi.htape", - items: [this.yearEditor, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, - width: o.height - }] - }, { - type: "bi.htape", - items: [this.quarterEditor, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Quarter"), - width: o.height - }, - width: o.height}] - }] - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - }] - }); - this.setValue(o.value); - }, - - _createEditor: function (isYear) { - var self = this, o = this.options, c = this._const; - var editor = BI.createWidget({ - type: "bi.sign_editor", - height: o.height, - validationChecker: function (v) { - if(isYear) { - return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); - } - return v === "" || ((v >= 1 && v <= 4) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); - }, - quitChecker: function () { - return false; - }, - errorText: function (v) { - return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; - }, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true - }); - editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_FOCUS); - }); - editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_STOP); - }); - editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = editor.getValue(); - if (BI.isNotNull(value)) { - editor.setValue(value); - } - if (BI.isNotEmptyString(value)) { - var quarterValue = self.quarterEditor.getValue(); - self.storeValue = { - type: BI.DynamicYearQuarterCombo.Static, - value: { - year: self.yearEditor.getValue(), - quarter: BI.isEmptyString(self.quarterEditor.getValue()) ? "" : quarterValue - } - }; - } - - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM); - }); - editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (editor.isValid()) { - editor.blur(); - } - }); - editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_START); - }); - editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_ERROR); - }); - editor.on(BI.SignEditor.EVENT_CHANGE, function () { - if(isYear) { - self._autoSwitch(editor.getValue()); - } - }); - - return editor; - }, - - _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; - }, - - _autoSwitch: function (v) { - if (BI.checkDateLegal(v)) { - if (v.length === 4 && this._yearCheck(v)) { - this.quarterEditor.focus(); - } - } - }, - - _getText: function (obj) { - var value = ""; - if(BI.isNotNull(obj.year)) { - value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); - } - if(BI.isNotNull(obj.quarter) && obj.quarter !== 0) { - value += Math.abs(obj.quarter) + BI.i18nText("BI-Basic_Year") + (obj.quarter < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); - } - return value; - }, - - _setInnerValue: function (date, text) { - var dateStr = date.print("%Y-%x"); - this.yearEditor.setValue(date.getFullYear()); - this.quarterEditor.setValue(date.getQuarter()); - this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); - }, - - setValue: function (v) { - var type, value; - var date = BI.getDate(); - this.storeValue = v; - if (BI.isNotNull(v)) { - type = v.type || BI.DynamicYearQuarterCombo.Static; - value = v.value || v; - } - switch (type) { - case BI.DynamicYearQuarterCombo.Dynamic: - var text = this._getText(value); - date = BI.DynamicDateHelper.getCalculation(value); - this._setInnerValue(date, text); - break; - case BI.DynamicYearQuarterCombo.Static: - default: - value = value || {}; - var quarter = BI.isNull(value.quarter) ? null : value.quarter; - this.yearEditor.setValue(value.year); - this.yearEditor.setTitle(value.year); - this.quarterEditor.setValue(quarter); - this.quarterEditor.setTitle(quarter); - break; - } - }, - - getValue: function () { - return this.storeValue; - } -}); -BI.DynamicYearQuarterTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DynamicYearQuarterTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.DynamicYearQuarterTrigger.EVENT_START = "EVENT_START"; -BI.DynamicYearQuarterTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearQuarterTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.dynamic_year_quarter_trigger", BI.DynamicYearQuarterTrigger);/** - * 汇总表格帮助类 - * Created by Young's on 2017/1/19. - */ -!(function () { - BI.DynamicDateHelper = {}; - BI.extend(BI.DynamicDateHelper, { - getCalculation: function (obj) { - var date = BI.getDate(); - if (BI.isNotNull(obj.year)) { - date = BI.getDate((date.getFullYear() + BI.parseInt(obj.year)), date.getMonth(), date.getDate()); - } - if (BI.isNotNull(obj.quarter)) { - date = date.getAfterMulQuarter(obj.quarter); - } - if (BI.isNotNull(obj.month)) { - date = date.getAfterMultiMonth(obj.month); - } - if (BI.isNotNull(obj.week)) { - date = date.getOffsetDate(obj.week * 7); - } - if (BI.isNotNull(obj.day)) { - date = date.getOffsetDate(obj.day); - } - if (BI.isNotNull(obj.workDay)) { - // todo 根据工作日做偏移 - } - if (BI.isNotNull(obj.position) && obj.position !== BI.DynamicDateCard.OFFSET.CURRENT) { - date = this.getBeginDate(date, obj); - } - return date; - }, - - getBeginDate: function (date, obj) { - if (BI.isNotNull(obj.day)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), date.getMonth(), 1) : BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); - } - if (BI.isNotNull(obj.week)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? date.getWeekStartDate() : date.getWeekEndDate(); - } - if (BI.isNotNull(obj.month)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), date.getMonth(), 1) : BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); - } - if (BI.isNotNull(obj.quarter)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? date.getQuarterStartDate() : date.getQuarterEndDate(); - } - if (BI.isNotNull(obj.year)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), 0, 1) : BI.getDate(date.getFullYear(), 11, 31); - } - } - }); -})();BI.DynamicDateCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-dynamic-date-card" - }, - - render: function () { - var self = this; - this.position = BI.DynamicDateCard.OFFSET.CURRENT; - return { - type: "bi.vertical", - items: [{ - el: { - type: "bi.label", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - textAlign: "left", - height: 24, - lgap: 10 - } - }, { - type: "bi.button_group", - ref: function () { - self.checkgroup = this; - }, - chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, - value: [BI.DynamicDateCard.TYPE.YEAR], - items: BI.createItems([{ - text: BI.i18nText("BI-Basic_Year"), - value: BI.DynamicDateCard.TYPE.YEAR - }, { - text: BI.i18nText("BI-Basic_Single_Quarter"), - value: BI.DynamicDateCard.TYPE.QUARTER - }, { - text: BI.i18nText("BI-Basic_Month"), - value: BI.DynamicDateCard.TYPE.MONTH - }, { - text: BI.i18nText("BI-Basic_Week"), - value: BI.DynamicDateCard.TYPE.WEEK - }, { - text: BI.i18nText("BI-Basic_Day"), - value: BI.DynamicDateCard.TYPE.DAY - }], { - type: "bi.multi_select_item", - logic: { - dynamic: true - } - }), - layouts: [{ - type: "bi.left" - }], - listeners: [{ - eventName: BI.ButtonGroup.EVENT_CHANGE, - action: function () { - var value = self.checkgroup.getValue(); - if(value.length !== 0) { - self.workDayBox.setSelected(false); - } - self.resultPane.populate(self._getParamJson(BI.map(self.checkgroup.getValue(), function (idx, v) { - return { - dateType: v - }; - }))); - self.position = BI.DynamicDateCard.OFFSET.CURRENT; - self.fireEvent("EVENT_CHANGE"); - } - }] - }, { - type: "bi.vertical_adapt", - items: [{ - type: "bi.multi_select_item", - ref: function () { - self.workDayBox = this; - }, - logic: { - dynamic: true - }, - text: BI.i18nText("BI-Basic_Work_Day"), - value: BI.DynamicDateCard.TYPE.WORK_DAY, - listeners: [{ - eventName: BI.MultiSelectItem.EVENT_CHANGE, - action: function () { - if(this.isSelected()) { - self.checkgroup.setValue(); - } - self.resultPane.populate(this.isSelected() ? self._getParamJson([{ - dateType: BI.DynamicDateCard.TYPE.WORK_DAY - }]) : []); - self.position = BI.DynamicDateCard.OFFSET.CURRENT; - self.fireEvent("EVENT_CHANGE"); - } - }] - }], - ref: function () { - self.workDay = this; - } - }, { - type: "bi.button_group", - items: this._getParamJson([{ - dateType: BI.DynamicDateCard.TYPE.YEAR - }]), - ref: function () { - self.resultPane = this; - }, - layouts: [{ - type: "bi.vertical", - vgap: 10, - hgap: 10 - }] - }] - }; - }, - - _getParamJson: function (values, positionValue) { - var self = this; - var items = BI.map(values, function (idx, value) { - return { - type: "bi.dynamic_date_param_item", - dateType: value.dateType, - value: value.value, - offset: value.offset, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }; - }); - - if(values.length === 1 && values[0] === BI.DynamicDateCard.TYPE.DAY) { - items.push = [{ - type: "bi.text_value_combo", - height: 24, - items: this._getText(BI.DynamicDateCard.TYPE.MONTH), - value: positionValue || BI.DynamicDateCard.OFFSET.CURRENT, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.position = this.getValue()[0]; - self.fireEvent("EVENT_CHANGE"); - } - }] - }]; - }else{ - if(values.length !== 0 && BI.last(values).dateType !== BI.DynamicDateCard.TYPE.DAY && BI.last(values).dateType !== BI.DynamicDateCard.TYPE.WORK_DAY) { - items.push({ - type: "bi.text_value_combo", - height: 24, - items: this._getText(BI.last(values).dateType), - value: positionValue || BI.DynamicDateCard.OFFSET.CURRENT, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.position = this.getValue()[0]; - self.fireEvent("EVENT_CHANGE"); - } - }] - }); - - } - } - - return items; - }, - - _getText: function (lastValue) { - switch (lastValue) { - case BI.DynamicDateCard.TYPE.YEAR: - return [{ - text: BI.i18nText("BI-Basic_Current_Day"), - value: BI.DynamicDateCard.OFFSET.CURRENT - }, { - text: BI.i18nText("BI-Basic_Year_Begin"), - value: BI.DynamicDateCard.OFFSET.BEGIN - }, { - text: BI.i18nText("BI-Basic_Year_End"), - value: BI.DynamicDateCard.OFFSET.END - }]; - case BI.DynamicDateCard.TYPE.QUARTER: - return [{ - text: BI.i18nText("BI-Basic_Current_Day"), - value: BI.DynamicDateCard.OFFSET.CURRENT - }, { - text: BI.i18nText("BI-Basic_Quarter_Begin"), - value: BI.DynamicDateCard.OFFSET.BEGIN - }, { - text: BI.i18nText("BI-Basic_Quarter_End"), - value: BI.DynamicDateCard.OFFSET.END - }]; - case BI.DynamicDateCard.TYPE.MONTH: - return [{ - text: BI.i18nText("BI-Basic_Current_Day"), - value: BI.DynamicDateCard.OFFSET.CURRENT - }, { - text: BI.i18nText("BI-Basic_Month_Begin"), - value: BI.DynamicDateCard.OFFSET.BEGIN - }, { - text: BI.i18nText("BI-Basic_Month_End"), - value: BI.DynamicDateCard.OFFSET.END - }]; - case BI.DynamicDateCard.TYPE.WEEK: - default: - return [{ - text: BI.i18nText("BI-Basic_Current_Day"), - value: BI.DynamicDateCard.OFFSET.CURRENT - }, { - text: BI.i18nText("BI-Basic_Week_Begin"), - value: BI.DynamicDateCard.OFFSET.BEGIN - }, { - text: BI.i18nText("BI-Basic_Week_End"), - value: BI.DynamicDateCard.OFFSET.END - }]; - } - }, - - _createValue: function (type, v) { - return { - dateType: type, - value: Math.abs(v), - offset: v > 0 ? 1 : 0 - }; - }, - - setValue: function (v) { - v = v || {}; - var values = []; - var valuesItems = []; - if(BI.isNotNull(v.year)) { - values.push(BI.DynamicDateCard.TYPE.YEAR); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); - } - if(BI.isNotNull(v.quarter)) { - values.push(BI.DynamicDateCard.TYPE.QUARTER); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); - } - if(BI.isNotNull(v.month)) { - values.push(BI.DynamicDateCard.TYPE.MONTH); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); - } - if(BI.isNotNull(v.week)) { - values.push(BI.DynamicDateCard.TYPE.WEEK); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.WEEK, v.week)); - } - if(BI.isNotNull(v.day)) { - values.push(BI.DynamicDateCard.TYPE.DAY); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.DAY, v.day)); - } - if(BI.isNotNull(v.workDay)) { - values.push(BI.DynamicDateCard.TYPE.WORK_DAY); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.WORK_DAY, v.workDay)); - } - this.checkgroup.setValue(values); - this.workDayBox.setSelected(BI.isNotNull(v.workDay)); - this.resultPane.populate(this._getParamJson(valuesItems, v.position)); - }, - - getValue: function () { - var self = this; - var valueMap = {}; - var selectValues = this.checkgroup.getValue(); - var buttons = this.resultPane.getAllButtons(); - if(selectValues.length !== 0) { - BI.each(buttons, function (idx, button) { - var value = button.getValue(); - switch (value.dateType) { - case BI.DynamicDateCard.TYPE.YEAR: - valueMap.year = (value.offset === 0 ? -value.value : value.value); - break; - case BI.DynamicDateCard.TYPE.QUARTER: - valueMap.quarter = (value.offset === 0 ? -value.value : value.value); - break; - case BI.DynamicDateCard.TYPE.MONTH: - valueMap.month = (value.offset === 0 ? -value.value : value.value); - break; - case BI.DynamicDateCard.TYPE.WEEK: - valueMap.week = (value.offset === 0 ? -value.value : value.value); - break; - case BI.DynamicDateCard.TYPE.DAY: - valueMap.day = (value.offset === 0 ? -value.value : value.value); - break; - default: - break; - } - if(BI.isNull(value.dateType)) { - valueMap.position = self.position || BI.DynamicDateCard.OFFSET.CURRENT; - } - }); - } - if(this.workDayBox.isSelected()) { - var value = buttons[0].getValue(); - valueMap.workDay = (value.offset === 0 ? -value.value : value.value); - } - return valueMap; - } - -}); -BI.shortcut("bi.dynamic_date_card", BI.DynamicDateCard); - -BI.extend(BI.DynamicDateCard, { - TYPE: { - YEAR: 1, - QUARTER: 2, - MONTH: 3, - WEEK: 4, - DAY: 5, - WORK_DAY: 6 - }, - OFFSET: { - CURRENT: 1, - BEGIN: 2, - END: 3 - } - -});BI.DynamicDateCombo = 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_trigger", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value, - ref: function () { - self.trigger = this; - }, - listeners: [{ - eventName: BI.DynamicDateTrigger.EVENT_KEY_DOWN, - action: function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_STOP, - action: function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_TRIGGER_CLICK, - action: function () { - self.combo.toggle(); - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_FOCUS, - action: function () { - self.storeTriggerValue = self.trigger.getKey(); - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - self.fireEvent(BI.DynamicDateCombo.EVENT_FOCUS); - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_ERROR, - action: function () { - self.storeValue = { - year: date.getFullYear(), - month: date.getMonth() - }; - self.popup.setValue(); - self.fireEvent(BI.DynamicDateCombo.EVENT_ERROR); - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_VALID, - action: function () { - self.fireEvent(BI.DynamicDateCombo.EVENT_VALID); - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicDateCombo.EVENT_CHANGE); - } - }, { - eventName: BI.DynamicDateTrigger.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.DynamicDateCombo.EVENT_CONFIRM); - } - }] - }, - adjustLength: this.constants.comboAdjustHeight, - popup: { - el: { - type: "bi.dynamic_date_popup", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value, - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicDatePopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }] - }, - stopPropagation: false - }, - listeners: [{ - eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, - action: function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicDateCombo.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.DynamicDateCombo.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.DynamicDateCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicDateCombo.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DynamicDateCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.DynamicDateCombo.EVENT_VALID = "EVENT_VALID"; -BI.DynamicDateCombo.EVENT_ERROR = "EVENT_ERROR"; -BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW = "BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW"; - -BI.shortcut("bi.dynamic_date_combo", BI.DynamicDateCombo); - -BI.extend(BI.DynamicDateCombo, { - Static: 1, - Dynamic: 2 -});BI.DynamicDateParamItem = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-dynamic-date-param-item", - dateType: BI.DynamicDateCard.TYPE.YEAR, - value: 0, - offset: 0, - height: 24 - }, - - render: function () { - var self = this, o = this.options; - return { - type: "bi.htape", - items: [{ - el: { - type: "bi.sign_editor", - cls: "bi-border", - height: 22, - validationChecker: function (v) { - return BI.isNaturalNumber(v); - }, - value: o.value, - ref: function () { - self.editor = this; - }, - errorText: function (v) { - if(BI.isEmptyString(v)) { - return BI.i18nText("BI-Basic_Input_Can_Not_Null"); - } - return BI.i18nText("BI-Please_Input_Positive_Integer"); - }, - allowBlank: false, - listeners: [{ - eventName: BI.SignEditor.EVENT_CONFIRM, - action: function () { - self.fireEvent(BI.DynamicDateParamItem.EVENT_CHANGE); - } - }] - }, - width: 60 - }, { - el: { - type: "bi.label", - height: 24, - text: this._getText() - }, - width: 20 - }, { - type: "bi.text_value_combo", - height: 24, - items: [{ - text: BI.i18nText("BI-Basic_Front"), - value: 0 - }, { - text: BI.i18nText("BI-Basic_Behind"), - value: 1 - }], - ref: function () { - self.offsetCombo = this; - }, - value: o.offset, - listeners: [{ - eventName: BI.TextValueCombo.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicDateParamItem.EVENT_CHANGE); - } - }] - }] - }; - }, - - _getText: function () { - var text = ""; - switch (this.options.dateType) { - case BI.DynamicDateCard.TYPE.YEAR: - text = BI.i18nText("BI-Basic_Year"); - break; - case BI.DynamicDateCard.TYPE.QUARTER: - text = BI.i18nText("BI-Basic_Single_Quarter"); - break; - case BI.DynamicDateCard.TYPE.MONTH: - text = BI.i18nText("BI-Basic_Month"); - break; - case BI.DynamicDateCard.TYPE.WEEK: - text = BI.i18nText("BI-Basic_Week"); - break; - case BI.DynamicDateCard.TYPE.DAY: - default: - text = BI.i18nText("BI-Basic_Day"); - break; - } - return text; - }, - - setValue: function (v) { - v = v || {}; - v.value = v.value || 0; - v.offset = v.offset || 0; - this.editor.setValue(v.value); - this.offsetCombo.setValue(v.offset); - }, - - getValue: function () { - return { - dateType: this.options.dateType, - value: this.editor.getValue(), - offset: this.offsetCombo.getValue()[0] - }; - } - -}); -BI.DynamicDateParamItem.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_date_param_item", BI.DynamicDateParamItem);BI.DynamicDatePopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30 - }, - - props: { - baseCls: "bi-dynamic-date-popup", - width: 248, - height: 344 - }, - - _init: function () { - BI.DynamicDatePopup.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.DynamicDatePopup.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.DynamicDatePopup.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.DynamicDatePopup.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.date_calendar_popup", - min: self.options.min, - max: self.options.max, - listeners: [{ - eventName: BI.DateCalendarPopup.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicDatePopup.EVENT_CHANGE); - } - }], - ref: function () { - self.ymd = this; - } - }; - } - }, - 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._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.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.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 -});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);/** - * Created by roy on 15/9/14. - */ -BI.SearchEditor = BI.inherit(BI.Widget, { - _defaultConfig: function () { - var conf = BI.SearchEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: "bi-search-editor bi-border", - height: 24, - errorText: "", - watermark: BI.i18nText("BI-Basic_Search"), - validationChecker: BI.emptyFn, - quitChecker: BI.emptyFn - }); - }, - _init: function () { - this.options.height -= 2; - BI.SearchEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget({ - type: "bi.editor", - height: o.height, - watermark: o.watermark, - allowBlank: true, - errorText: o.errorText, - validationChecker: o.validationChecker, - quitChecker: o.quitChecker - }); - this.clear = BI.createWidget({ - type: "bi.icon_button", - stopEvent: true, - cls: "search-close-h-font" - }); - this.clear.on(BI.IconButton.EVENT_CHANGE, function () { - self.setValue(""); - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.STOPEDIT); - self.fireEvent(BI.SearchEditor.EVENT_CLEAR); - }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [ - { - el: { - type: "bi.center_adapt", - cls: "search-font", - items: [{ - el: { - type: "bi.icon" - } - }] - }, - width: 25 - }, - { - el: self.editor - }, - { - el: this.clear, - width: 25 - } - ] - }); - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.editor.on(BI.Editor.EVENT_FOCUS, function () { - self.fireEvent(BI.SearchEditor.EVENT_FOCUS); - }); - this.editor.on(BI.Editor.EVENT_BLUR, function () { - self.fireEvent(BI.SearchEditor.EVENT_BLUR); - }); - this.editor.on(BI.Editor.EVENT_CLICK, function () { - self.fireEvent(BI.SearchEditor.EVENT_CLICK); - }); - this.editor.on(BI.Editor.EVENT_CHANGE, function () { - self._checkClear(); - self.fireEvent(BI.SearchEditor.EVENT_CHANGE); - }); - this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { - self.fireEvent(BI.SearchEditor.EVENT_KEY_DOWN, v); - }); - this.editor.on(BI.Editor.EVENT_SPACE, function () { - self.fireEvent(BI.SearchEditor.EVENT_SPACE); - }); - this.editor.on(BI.Editor.EVENT_BACKSPACE, function () { - self.fireEvent(BI.SearchEditor.EVENT_BACKSPACE); - }); - - - this.editor.on(BI.Editor.EVENT_VALID, function () { - self.fireEvent(BI.SearchEditor.EVENT_VALID); - }); - this.editor.on(BI.Editor.EVENT_ERROR, function () { - self.fireEvent(BI.SearchEditor.EVENT_ERROR); - }); - this.editor.on(BI.Editor.EVENT_ENTER, function () { - self.fireEvent(BI.SearchEditor.EVENT_ENTER); - }); - this.editor.on(BI.Editor.EVENT_RESTRICT, function () { - self.fireEvent(BI.SearchEditor.EVENT_RESTRICT); - }); - this.editor.on(BI.Editor.EVENT_EMPTY, function () { - self._checkClear(); - self.fireEvent(BI.SearchEditor.EVENT_EMPTY); - }); - this.editor.on(BI.Editor.EVENT_REMOVE, function () { - self.fireEvent(BI.SearchEditor.EVENT_REMOVE); - }); - this.editor.on(BI.Editor.EVENT_CONFIRM, function () { - self.fireEvent(BI.SearchEditor.EVENT_CONFIRM); - }); - this.editor.on(BI.Editor.EVENT_START, function () { - self.fireEvent(BI.SearchEditor.EVENT_START); - }); - this.editor.on(BI.Editor.EVENT_PAUSE, function () { - self.fireEvent(BI.SearchEditor.EVENT_PAUSE); - }); - this.editor.on(BI.Editor.EVENT_STOP, function () { - self.fireEvent(BI.SearchEditor.EVENT_STOP); - }); - - this.clear.invisible(); - }, - - _checkClear: function () { - if (!this.getValue()) { - this.clear.invisible(); - } else { - this.clear.visible(); - } - }, - - focus: function () { - this.editor.focus(); - }, - - blur: function () { - this.editor.blur(); - }, - - getValue: function () { - if (this.isValid()) { - var res = this.editor.getValue().match(/[\S]+/g); - return BI.isNull(res) ? "" : res[res.length - 1]; - } - }, - - getLastValidValue: function () { - return this.editor.getLastValidValue(); - }, - - setValue: function (v) { - this.editor.setValue(v); - if (BI.isKey(v)) { - this.clear.visible(); - } - }, - - isEditing: function () { - return this.editor.isEditing(); - }, - - isValid: function () { - return this.editor.isValid(); - } -}); -BI.SearchEditor.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SearchEditor.EVENT_FOCUS = "EVENT_FOCUS"; -BI.SearchEditor.EVENT_BLUR = "EVENT_BLUR"; -BI.SearchEditor.EVENT_CLICK = "EVENT_CLICK"; -BI.SearchEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; -BI.SearchEditor.EVENT_SPACE = "EVENT_SPACE"; -BI.SearchEditor.EVENT_BACKSPACE = "EVENT_BACKSPACE"; -BI.SearchEditor.EVENT_CLEAR = "EVENT_CLEAR"; - -BI.SearchEditor.EVENT_START = "EVENT_START"; -BI.SearchEditor.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SearchEditor.EVENT_STOP = "EVENT_STOP"; -BI.SearchEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.SearchEditor.EVENT_VALID = "EVENT_VALID"; -BI.SearchEditor.EVENT_ERROR = "EVENT_ERROR"; -BI.SearchEditor.EVENT_ENTER = "EVENT_ENTER"; -BI.SearchEditor.EVENT_RESTRICT = "EVENT_RESTRICT"; -BI.SearchEditor.EVENT_REMOVE = "EVENT_REMOVE"; -BI.SearchEditor.EVENT_EMPTY = "EVENT_EMPTY"; -BI.shortcut("bi.search_editor", BI.SearchEditor);/** - * 小号搜索框 - * Created by GUY on 2015/9/29. - * @class BI.SmallSearchEditor - * @extends BI.SearchEditor - */ -BI.SmallSearchEditor = BI.inherit(BI.SearchEditor, { - _defaultConfig: function () { - var conf = BI.SmallSearchEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-small-search-editor", - height: 24 - }); - }, - - _init: function () { - BI.SmallSearchEditor.superclass._init.apply(this, arguments); - } -}); -BI.shortcut("bi.small_search_editor", BI.SmallSearchEditor);/** - * guy - * @class BI.TextEditor - * @extends BI.Single - */ -BI.TextEditor = BI.inherit(BI.Widget, { - _defaultConfig: function () { - var conf = BI.TextEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-text-editor bi-border", - hgap: 4, - vgap: 2, - lgap: 0, - rgap: 0, - tgap: 0, - bgap: 0, - validationChecker: BI.emptyFn, - quitChecker: BI.emptyFn, - allowBlank: false, - watermark: "", - errorText: "", - height: 24 - }); - }, - - _init: function () { - BI.TextEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (BI.isNumber(o.height)) { - this.element.css({height: o.height - 2}); - } - if (BI.isNumber(o.width)) { - this.element.css({width: o.width - 2}); - } - this.editor = BI.createWidget({ - type: "bi.editor", - height: o.height - 2, - hgap: o.hgap, - vgap: o.vgap, - lgap: o.lgap, - rgap: o.rgap, - tgap: o.tgap, - bgap: o.bgap, - value: o.value, - title: o.title, - tipType: o.tipType, - validationChecker: o.validationChecker, - quitChecker: o.quitChecker, - allowBlank: o.allowBlank, - watermark: o.watermark, - errorText: o.errorText - }); - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.editor.on(BI.Editor.EVENT_FOCUS, function () { - self.fireEvent(BI.TextEditor.EVENT_FOCUS); - }); - this.editor.on(BI.Editor.EVENT_BLUR, function () { - self.fireEvent(BI.TextEditor.EVENT_BLUR); - }); - this.editor.on(BI.Editor.EVENT_CLICK, function () { - self.fireEvent(BI.TextEditor.EVENT_CLICK); - }); - this.editor.on(BI.Editor.EVENT_CHANGE, function () { - self.fireEvent(BI.TextEditor.EVENT_CHANGE); - }); - this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { - self.fireEvent(BI.TextEditor.EVENT_KEY_DOWN); - }); - this.editor.on(BI.Editor.EVENT_SPACE, function (v) { - self.fireEvent(BI.TextEditor.EVENT_SPACE); - }); - this.editor.on(BI.Editor.EVENT_BACKSPACE, function (v) { - self.fireEvent(BI.TextEditor.EVENT_BACKSPACE); - }); - - - this.editor.on(BI.Editor.EVENT_VALID, function () { - self.fireEvent(BI.TextEditor.EVENT_VALID); - }); - this.editor.on(BI.Editor.EVENT_CONFIRM, function () { - self.fireEvent(BI.TextEditor.EVENT_CONFIRM); - }); - this.editor.on(BI.Editor.EVENT_REMOVE, function (v) { - self.fireEvent(BI.TextEditor.EVENT_REMOVE); - }); - this.editor.on(BI.Editor.EVENT_START, function () { - self.fireEvent(BI.TextEditor.EVENT_START); - }); - this.editor.on(BI.Editor.EVENT_PAUSE, function () { - self.fireEvent(BI.TextEditor.EVENT_PAUSE); - }); - this.editor.on(BI.Editor.EVENT_STOP, function () { - self.fireEvent(BI.TextEditor.EVENT_STOP); - }); - this.editor.on(BI.Editor.EVENT_ERROR, function () { - self.fireEvent(BI.TextEditor.EVENT_ERROR, arguments); - }); - this.editor.on(BI.Editor.EVENT_ENTER, function () { - self.fireEvent(BI.TextEditor.EVENT_ENTER); - }); - this.editor.on(BI.Editor.EVENT_RESTRICT, function () { - self.fireEvent(BI.TextEditor.EVENT_RESTRICT); - }); - this.editor.on(BI.Editor.EVENT_EMPTY, function () { - self.fireEvent(BI.TextEditor.EVENT_EMPTY); - }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, - element: this, - items: [this.editor] - }); - }, - - focus: function () { - this.editor.focus(); - }, - - blur: function () { - this.editor.blur(); - }, - - setErrorText: function (text) { - this.editor.setErrorText(text); - }, - - getErrorText: function () { - return this.editor.getErrorText(); - }, - - isValid: function () { - return this.editor.isValid(); - }, - - setValue: function (v) { - this.editor.setValue(v); - }, - - getValue: function () { - return this.editor.getValue(); - } -}); -BI.TextEditor.EVENT_CHANGE = "EVENT_CHANGE"; -BI.TextEditor.EVENT_FOCUS = "EVENT_FOCUS"; -BI.TextEditor.EVENT_BLUR = "EVENT_BLUR"; -BI.TextEditor.EVENT_CLICK = "EVENT_CLICK"; -BI.TextEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; -BI.TextEditor.EVENT_SPACE = "EVENT_SPACE"; -BI.TextEditor.EVENT_BACKSPACE = "EVENT_BACKSPACE"; - -BI.TextEditor.EVENT_START = "EVENT_START"; -BI.TextEditor.EVENT_PAUSE = "EVENT_PAUSE"; -BI.TextEditor.EVENT_STOP = "EVENT_STOP"; -BI.TextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.TextEditor.EVENT_VALID = "EVENT_VALID"; -BI.TextEditor.EVENT_ERROR = "EVENT_ERROR"; -BI.TextEditor.EVENT_ENTER = "EVENT_ENTER"; -BI.TextEditor.EVENT_RESTRICT = "EVENT_RESTRICT"; -BI.TextEditor.EVENT_REMOVE = "EVENT_REMOVE"; -BI.TextEditor.EVENT_EMPTY = "EVENT_EMPTY"; - -BI.shortcut("bi.text_editor", BI.TextEditor);/** - * 小号搜索框 - * Created by GUY on 2015/9/29. - * @class BI.SmallTextEditor - * @extends BI.SearchEditor - */ -BI.SmallTextEditor = BI.inherit(BI.TextEditor, { - _defaultConfig: function () { - var conf = BI.SmallTextEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-small-text-editor", - height: 25 - }); - }, - - _init: function () { - BI.SmallTextEditor.superclass._init.apply(this, arguments); - } -}); -BI.shortcut("bi.small_text_editor", BI.SmallTextEditor);/** - * 文件管理控件组 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerButtonGroup - * @extends BI.Widget - */ -BI.FileManagerButtonGroup = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.FileManagerButtonGroup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-button_group", - items: [] - }); - }, - - _init: function () { - BI.FileManagerButtonGroup.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.button_group = BI.createWidget({ - type: "bi.button_tree", - element: this, - chooseType: BI.Selection.Multi, - items: this._formatItems(o.items), - layouts: [{ - type: "bi.vertical" - }] - }); - this.button_group.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + }] + }, + 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; + } + }; }, - _formatItems: function (items) { - var self = this, o = this.options; - BI.each(items, function (i, item) { - if (item.children && item.children.length > 0) { - item.type = "bi.file_manager_folder_item"; - } else { - item.type = "bi.file_manager_file_item"; - } - }); - return items; + mounted: function () { + this._checkDynamicValue(this.options.value); }, - setValue: function (v) { - this.button_group.setValue(v); + _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.button_group.getValue(); + return this.storeValue; }, - - getNotSelectedValue: function () { - return this.button_group.getNotSelectedValue(); + getKey: function () { + return this.trigger.getKey(); }, + hidePopupView: function () { + this.combo.hideView(); + } +}); - getAllLeaves: function () { - return this.button_group.getAllLeaves(); - }, +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"; - getAllButtons: function () { - return this.button_group.getAllButtons(); - }, +BI.shortcut("bi.dynamic_date_time_combo", BI.DynamicDateTimeCombo); - getSelectedButtons: function () { - return this.button_group.getSelectedButtons(); +BI.extend(BI.DynamicDateTimeCombo, { + Static: 1, + Dynamic: 2 +});BI.DynamicDateTimePopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 }, - getNotSelectedButtons: function () { - return this.button_group.getNotSelectedButtons(); + props: { + baseCls: "bi-dynamic-date-time-popup", + width: 248, + height: 385 }, - populate: function (items) { - this.button_group.populate(this._formatItems(items)); - } -}); -BI.FileManagerButtonGroup.EVENT_CHANGE = "FileManagerButtonGroup.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_button_group", BI.FileManagerButtonGroup);/** - * 文件管理控件 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManager - * @extends BI.Widget - */ -BI.FileManager = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.FileManager.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager", - el: {}, - items: [] + _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); }, - _init: function () { - BI.FileManager.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.tree = new BI.Tree(); - var items = BI.Tree.transformToTreeFormat(o.items); - this.tree.initTree(items); - this.selectedValues = []; - this.nav = BI.createWidget({ - type: "bi.file_manager_nav", - items: BI.deepClone(items) - }); - this.nav.on(BI.FileManagerNav.EVENT_CHANGE, function (value, obj) { - if (value == "-1") {// 根节点 - self.populate({children: self.tree.toJSON()}); - } else { - var node = self.tree.search(obj.attr("id")); - self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); - } - self.setValue(self.selectedValues); - }); - this.list = BI.createWidget(o.el, { - type: "bi.file_manager_list", - items: items - }); - this.list.on(BI.Controller.EVENT_CHANGE, function (type, selected, obj) { - if (type === BI.Events.CHANGE) { - var node = self.tree.search(obj.attr("id")); - self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); - } else if (type === BI.Events.CLICK) { - var values = []; - if (obj instanceof BI.MultiSelectBar) { - var t = self.list.getValue(); - selected = t.type === BI.Selection.All; - values = BI.concat(t.assist, t.value); - } else { - values = obj.getAllLeaves(); + _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 + }] + }; } - BI.each(values, function (i, v) { - if (selected === true) { - self.selectedValues.pushDistinct(v); - } else { - self.selectedValues.remove(v); + }, + 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; } - }); - } - self.setValue(self.selectedValues); - }); - - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.list, - left: 0, - right: 0, - top: 0, - bottom: 10 - }, { - el: this.nav, - left: 40, - right: 100, - top: 0 + } }] - }); + }; }, - setValue: function (value) { - this.selectedValues = value || []; - this.list.setValue(this.selectedValues); + _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); + } }, - getValue: function () { - var obj = this.list.getValue(); - var res = obj.type === BI.Selection.All ? obj.assist : obj.value; - res.pushDistinctArray(this.selectedValues); - return res; + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, - _populate: function (items) { - this.list.populate(items); + 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; + } }, - getSelectedValue: function () { - return this.nav.getValue()[0]; - }, + 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, { - getSelectedId: function () { - return this.nav.getId()[0]; + props: { + baseCls: "bi-date-time-select bi-border-top" }, - populate: function (node) { - var clone = BI.deepClone(node); - this._populate(node.children); - this.nav.populate(clone); - } -}); -BI.FileManager.EVENT_CHANGE = "FileManager.EVENT_CHANGE"; -BI.shortcut("bi.file_manager", BI.FileManager);/** - * 文件管理控件 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerFileItem - * @extends BI.Single - */ -BI.FileManagerFileItem = BI.inherit(BI.Single, { + 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 + }] + }] + }; + }, - _defaultConfig: function () { - return BI.extend(BI.FileManagerFileItem.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-file-item bi-list-item bi-border-bottom", - height: 30 - }); + _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; }, - _init: function () { - BI.FileManagerFileItem.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.checked = BI.createWidget({ - type: "bi.multi_select_bar", - text: "", - width: 36, - height: o.height - }); - this.checked.on(BI.Controller.EVENT_CHANGE, function () { - arguments[2] = self; - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - items: [{ - el: this.checked, - width: 36 - }, { - el: { - type: "bi.icon_button", - cls: "create-by-me-file-font" - }, - width: 20 - }, { - el: { - type: "bi.label", - textAlign: "left", - height: o.height, - text: o.text, - value: o.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; }, - getAllLeaves: function () { - return [this.options.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; }, - isSelected: function () { - return this.checked.isSelected(); + getValue: function () { + return { + hour: BI.parseInt(this.hour.getValue()), + minute: BI.parseInt(this.minute.getValue()), + second: BI.parseInt(this.second.getValue()) + }; }, - setSelected: function (v) { - this.checked.setSelected(v); + setValue: function (v) { + v = this._assertValue(v); + this.hour.setValue(v.hour); + this.minute.setValue(v.minute); + this.second.setValue(v.second); } + }); -BI.FileManagerFileItem.EVENT_CHANGE = "FileManagerFileItem.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_file_item", BI.FileManagerFileItem);/** - * 文件管理控件 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerFolderItem - * @extends BI.Single - */ -BI.FileManagerFolderItem = BI.inherit(BI.Single, { +BI.DynamicDateTimeSelect.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.shortcut("bi.dynamic_date_time_select", BI.DynamicDateTimeSelect); - _defaultConfig: function () { - return BI.extend(BI.FileManagerFolderItem.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-folder-item bi-list-item bi-border-bottom", - height: 30 - }); +BI.extend(BI.DynamicDateTimeSelect, { + HOUR: 1, + MINUTE: 2 +});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.FileManagerFolderItem.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.checked = BI.createWidget({ - type: "bi.multi_select_bar", - text: "", - width: 36, - height: o.height + 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.checked.on(BI.Controller.EVENT_CHANGE, function () { - arguments[2] = self; - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN); }); - this.button = BI.createWidget({ - type: "bi.text_button", - textAlign: "left", - height: o.height, - text: o.text, - value: o.value + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_FOCUS); }); - this.button.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CHANGE, o.value, self); + 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); + } - this.tree = new BI.Tree(); - this.tree.initTree([{ - id: o.id, - children: o.children - }]); - this.selectValue = []; - + 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.checked, - width: 36 - }, { - el: { - type: "bi.icon_button", - cls: "create-by-me-folder-font" - }, - width: 20 + el: this.editor }, { - el: this.button + 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 || - setAllSelected: function (v) { - this.checked.setSelected(v); - this.selectValue = []; + 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; }, - - setHalfSelected: function (v) { - this.checked.setHalfSelected(v); - if(!v) { - this.selectValue = []; - } + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.options.min, this.options.max)[0]; }, - - setValue: function (v) { - var self = this, o = this.options; - var isHalf = false; - var selectValue = []; - this.tree.traverse(function (node) { - if (node.isLeaf()) { - if (BI.contains(v, node.get("data").value)) { - selectValue.push(node.get("data").value); - } else { - isHalf = true; - } + _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; } - }); - this.setAllSelected(selectValue.length > 0 && !isHalf); - this.setHalfSelected(selectValue.length > 0 && isHalf); - if (this.checked.isHalfSelected()) { - this.selectValue = selectValue; } }, - getAllButtons: function () { - return [this]; + _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; }, - getAllLeaves: function () { - var o = this.options; - var res = []; - this.tree.traverse(function (node) { - if (node.isLeaf()) { - res.push(node.get("data").value); + _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"); } - }); - return res; + } }, - getNotSelectedValue: function () { - var self = this, o = this.options; - var res = []; - var isAllSelected = this.checked.isSelected(); - if (isAllSelected === true) { - return res; + 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; } - var isHalfSelected = this.checked.isHalfSelected(); - this.tree.traverse(function (node) { - if (node.isLeaf()) { - var v = node.get("data").value; - if (isHalfSelected === true) { - if (!BI.contains(self.selectValue, node.get("data").value)) { - res.push(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 { - res.push(v); + 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); } - } - }); - return res; + break; + } }, + getKey: function () { + return this.editor.getValue(); + }, getValue: function () { - var res = []; - if (this.checked.isSelected()) { - this.tree.traverse(function (node) { - if (node.isLeaf()) { - res.push(node.get("data").value); - } - }); - return res; - } - if (this.checked.isHalfSelected()) { - return this.selectValue; - } - return []; + return this.storeValue; } + }); -BI.FileManagerFolderItem.EVENT_CHANGE = "FileManagerFolderItem.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_folder_item", BI.FileManagerFolderItem);/** - * 文件管理控件列表 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerList - * @extends BI.Widget - */ -BI.FileManagerList = BI.inherit(BI.Widget, { +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, { _defaultConfig: function () { - return BI.extend(BI.FileManagerList.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-list", - el: {}, - items: [] + var conf = BI.SearchEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: "bi-search-editor bi-border", + height: 24, + errorText: "", + watermark: BI.i18nText("BI-Basic_Search"), + validationChecker: BI.emptyFn, + quitChecker: BI.emptyFn }); }, - _init: function () { - BI.FileManagerList.superclass._init.apply(this, arguments); + this.options.height -= 2; + BI.SearchEditor.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.list = BI.createWidget({ - type: "bi.select_list", - element: this, - items: o.items, - toolbar: { - type: "bi.multi_select_bar", - height: 40, - text: "" - }, - el: { - type: "bi.list_pane", - el: BI.isWidget(o.el) ? o.el : BI.extend({ - type: "bi.file_manager_button_group" - }, o.el) - } + this.editor = BI.createWidget({ + type: "bi.editor", + height: o.height, + watermark: o.watermark, + allowBlank: true, + errorText: o.errorText, + validationChecker: o.validationChecker, + quitChecker: o.quitChecker }); - this.list.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.clear = BI.createWidget({ + type: "bi.icon_button", + stopEvent: true, + cls: "search-close-h-font" }); - }, - - setValue: function (v) { - this.list.setValue({ - value: v + this.clear.on(BI.IconButton.EVENT_CHANGE, function () { + self.setValue(""); + self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.STOPEDIT); + self.fireEvent(BI.SearchEditor.EVENT_CLEAR); }); - }, - - getValue: function () { - return this.list.getValue(); - }, - - populate: function (items) { - this.list.populate(items); - this.list.setToolBarVisible(true); - } -}); -BI.FileManagerList.EVENT_CHANGE = "FileManagerList.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_list", BI.FileManagerList);/** - * 文件管理导航按钮 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerNavButton - * @extends BI.Widget - */ -BI.FileManagerNavButton = BI.inherit(BI.Widget, { - - _const: { - normal_color: "#ffffff", - select_color: "#eff1f4" - }, - _defaultConfig: function () { - return BI.extend(BI.FileManagerNavButton.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-nav-button", - selected: false, - height: 40 + BI.createWidget({ + element: this, + type: "bi.htape", + items: [ + { + el: { + type: "bi.center_adapt", + cls: "search-font", + items: [{ + el: { + type: "bi.icon" + } + }] + }, + width: 25 + }, + { + el: self.editor + }, + { + el: this.clear, + width: 25 + } + ] + }); + this.editor.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - }, - _init: function () { - BI.FileManagerNavButton.superclass._init.apply(this, arguments); - var self = this, o = this.options, c = this._const; - this.button = BI.createWidget({ - type: "bi.text_button", - cls: "file-manager-nav-button-text bi-card", - once: true, - selected: o.selected, - text: o.text, - title: o.text, - value: o.value, - height: o.height, - lgap: 20, - rgap: 10 + this.editor.on(BI.Editor.EVENT_FOCUS, function () { + self.fireEvent(BI.SearchEditor.EVENT_FOCUS); }); - this.button.on(BI.Controller.EVENT_CHANGE, function () { - arguments[2] = self; - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(BI.Editor.EVENT_BLUR, function () { + self.fireEvent(BI.SearchEditor.EVENT_BLUR); }); - var svg = BI.createWidget({ - type: "bi.svg", - cls: "file-manager-nav-button-triangle", - width: 15, - height: o.height + this.editor.on(BI.Editor.EVENT_CLICK, function () { + self.fireEvent(BI.SearchEditor.EVENT_CLICK); }); - var path = svg.path("M0,0L15,20L0,40").attr({ - stroke: c.select_color, - fill: o.selected ? c.select_color : c.normal_color + this.editor.on(BI.Editor.EVENT_CHANGE, function () { + self._checkClear(); + self.fireEvent(BI.SearchEditor.EVENT_CHANGE); }); - this.button.on(BI.TextButton.EVENT_CHANGE, function () { - if (this.isSelected()) { - path.attr("fill", c.select_color); - } else { - path.attr("fill", c.normal_color); - } + this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { + self.fireEvent(BI.SearchEditor.EVENT_KEY_DOWN, v); }); - BI.createWidget({ - type: "bi.default", - element: this, - items: [this.button] + this.editor.on(BI.Editor.EVENT_SPACE, function () { + self.fireEvent(BI.SearchEditor.EVENT_SPACE); }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: svg, - right: -15, - top: 0, - bottom: 0 - }] + this.editor.on(BI.Editor.EVENT_BACKSPACE, function () { + self.fireEvent(BI.SearchEditor.EVENT_BACKSPACE); }); - }, - - isSelected: function () { - return this.button.isSelected(); - }, - - setValue: function (v) { - this.button.setValue(v); - }, - - getValue: function () { - return this.button.getValue(); - }, - - populate: function (items) { - } -}); -BI.FileManagerNavButton.EVENT_CHANGE = "FileManagerNavButton.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_nav_button", BI.FileManagerNavButton);/** - * 文件管理导航 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerNav - * @extends BI.Widget - */ -BI.FileManagerNav = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.FileManagerNav.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-nav bi-border-left", - height: 40, - items: [] + this.editor.on(BI.Editor.EVENT_VALID, function () { + self.fireEvent(BI.SearchEditor.EVENT_VALID); }); - }, - - _init: function () { - BI.FileManagerNav.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.tree = new BI.Tree(); - this.refreshTreeData(o.items); - this.tree.getRoot().set("data", { - text: BI.i18nText("BI-Created_By_Me"), - value: BI.FileManagerNav.ROOT_CREATE_BY_ME, - id: BI.FileManagerNav.ROOT_CREATE_BY_ME + this.editor.on(BI.Editor.EVENT_ERROR, function () { + self.fireEvent(BI.SearchEditor.EVENT_ERROR); }); - this.button_group = BI.createWidget({ - type: "bi.button_group", - element: this, - items: [{ - type: "bi.file_manager_nav_button", - text: BI.i18nText("BI-Created_By_Me"), - selected: true, - id: BI.FileManagerNav.ROOT_CREATE_BY_ME, - value: BI.FileManagerNav.ROOT_CREATE_BY_ME - }], - layouts: [{ - type: "bi.horizontal" - }] + this.editor.on(BI.Editor.EVENT_ENTER, function () { + self.fireEvent(BI.SearchEditor.EVENT_ENTER); }); - this.button_group.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(BI.Editor.EVENT_RESTRICT, function () { + self.fireEvent(BI.SearchEditor.EVENT_RESTRICT); }); - this.button_group.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) { - self.fireEvent(BI.FileManagerNav.EVENT_CHANGE, arguments); + this.editor.on(BI.Editor.EVENT_EMPTY, function () { + self._checkClear(); + self.fireEvent(BI.SearchEditor.EVENT_EMPTY); + }); + this.editor.on(BI.Editor.EVENT_REMOVE, function () { + self.fireEvent(BI.SearchEditor.EVENT_REMOVE); + }); + this.editor.on(BI.Editor.EVENT_CONFIRM, function () { + self.fireEvent(BI.SearchEditor.EVENT_CONFIRM); + }); + this.editor.on(BI.Editor.EVENT_START, function () { + self.fireEvent(BI.SearchEditor.EVENT_START); + }); + this.editor.on(BI.Editor.EVENT_PAUSE, function () { + self.fireEvent(BI.SearchEditor.EVENT_PAUSE); + }); + this.editor.on(BI.Editor.EVENT_STOP, function () { + self.fireEvent(BI.SearchEditor.EVENT_STOP); }); + + this.clear.invisible(); }, - _getAllParents: function (id) { - var node, res = []; - if (!id) { - node = this.tree.getRoot(); + _checkClear: function () { + if (!this.getValue()) { + this.clear.invisible(); } else { - node = this.tree.search(id); - } - while (node.parent) { - res.push(node); - node = node.parent; + this.clear.visible(); } - res.push(node); - return res.reverse(); }, - _formatNodes: function (nodes) { - var res = []; - BI.each(nodes, function (i, node) { - res.push(BI.extend({ - type: "bi.file_manager_nav_button", - id: node.id - }, node.get("data"))); - }); - BI.last(res).selected = true; - return res; + focus: function () { + this.editor.focus(); + }, + + blur: function () { + this.editor.blur(); }, getValue: function () { - return this.button_group.getValue(); + if (this.isValid()) { + var res = this.editor.getValue().match(/[\S]+/g); + return BI.isNull(res) ? "" : res[res.length - 1]; + } }, - getId: function () { - var ids = []; - BI.each(this.button_group.getSelectedButtons(), function (i, btn) { - ids.push(btn.attr("id")); - }); - return ids; + getLastValidValue: function () { + return this.editor.getLastValidValue(); }, - refreshTreeData: function (items) { - this.tree.initTree(BI.Tree.transformToTreeFormat(items)); - this.tree.getRoot().set("data", { - text: BI.i18nText("BI-Created_By_Me"), - value: BI.FileManagerNav.ROOT_CREATE_BY_ME, - id: BI.FileManagerNav.ROOT_CREATE_BY_ME - }); + setValue: function (v) { + this.editor.setValue(v); + if (BI.isKey(v)) { + this.clear.visible(); + } + }, + + isEditing: function () { + return this.editor.isEditing(); }, - populate: function (node) { - var parents = BI.isNull(node) ? [this.tree.getRoot()] : this._getAllParents(node.id); - this.button_group.populate(this._formatNodes(parents)); + isValid: function () { + return this.editor.isValid(); } }); -BI.extend(BI.FileManagerNav, { - ROOT_CREATE_BY_ME: "-1" -}); -BI.FileManagerNav.EVENT_CHANGE = "FileManagerNav.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_nav", BI.FileManagerNav);/** - * Created by zcf on 2016/9/26. +BI.SearchEditor.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SearchEditor.EVENT_FOCUS = "EVENT_FOCUS"; +BI.SearchEditor.EVENT_BLUR = "EVENT_BLUR"; +BI.SearchEditor.EVENT_CLICK = "EVENT_CLICK"; +BI.SearchEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.SearchEditor.EVENT_SPACE = "EVENT_SPACE"; +BI.SearchEditor.EVENT_BACKSPACE = "EVENT_BACKSPACE"; +BI.SearchEditor.EVENT_CLEAR = "EVENT_CLEAR"; + +BI.SearchEditor.EVENT_START = "EVENT_START"; +BI.SearchEditor.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SearchEditor.EVENT_STOP = "EVENT_STOP"; +BI.SearchEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.SearchEditor.EVENT_VALID = "EVENT_VALID"; +BI.SearchEditor.EVENT_ERROR = "EVENT_ERROR"; +BI.SearchEditor.EVENT_ENTER = "EVENT_ENTER"; +BI.SearchEditor.EVENT_RESTRICT = "EVENT_RESTRICT"; +BI.SearchEditor.EVENT_REMOVE = "EVENT_REMOVE"; +BI.SearchEditor.EVENT_EMPTY = "EVENT_EMPTY"; +BI.shortcut("bi.search_editor", BI.SearchEditor);/** + * 小号搜索框 + * Created by GUY on 2015/9/29. + * @class BI.SmallSearchEditor + * @extends BI.SearchEditor */ -BI.IntervalSlider = BI.inherit(BI.Widget, { - _constant: { - EDITOR_WIDTH: 58, - EDITOR_R_GAP: 60, - EDITOR_HEIGHT: 30, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 +BI.SmallSearchEditor = BI.inherit(BI.SearchEditor, { + _defaultConfig: function () { + var conf = BI.SmallSearchEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-small-search-editor", + height: 24 + }); }, + _init: function () { + BI.SmallSearchEditor.superclass._init.apply(this, arguments); + } +}); +BI.shortcut("bi.small_search_editor", BI.SmallSearchEditor);/** + * guy + * @class BI.TextEditor + * @extends BI.Single + */ +BI.TextEditor = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.IntervalSlider.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-interval-slider bi-slider-track", - digit: false, - unit: "" + var conf = BI.TextEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-text-editor bi-border", + hgap: 4, + vgap: 2, + lgap: 0, + rgap: 0, + tgap: 0, + bgap: 0, + validationChecker: BI.emptyFn, + quitChecker: BI.emptyFn, + allowBlank: false, + watermark: "", + errorText: "", + height: 24 }); }, _init: function () { - BI.IntervalSlider.superclass._init.apply(this, arguments); - - var self = this; - var c = this._constant; - this.enable = false; - this.valueOne = ""; - this.valueTwo = ""; - this.calculation = new BI.AccurateCalculationModel(); - - // this.backgroundTrack = BI.createWidget({ - // type: "bi.layout", - // cls: "background-track", - // height: c.TRACK_HEIGHT - // }); - this.grayTrack = BI.createWidget({ - type: "bi.layout", - cls: "gray-track", - height: 6 + BI.TextEditor.superclass._init.apply(this, arguments); + var self = this, o = this.options; + if (BI.isNumber(o.height)) { + this.element.css({height: o.height - 2}); + } + if (BI.isNumber(o.width)) { + this.element.css({width: o.width - 2}); + } + this.editor = BI.createWidget({ + type: "bi.editor", + height: o.height - 2, + hgap: o.hgap, + vgap: o.vgap, + lgap: o.lgap, + rgap: o.rgap, + tgap: o.tgap, + bgap: o.bgap, + value: o.value, + title: o.title, + tipType: o.tipType, + validationChecker: o.validationChecker, + quitChecker: o.quitChecker, + allowBlank: o.allowBlank, + watermark: o.watermark, + errorText: o.errorText }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 + this.editor.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.track = this._createTrackWrapper(); - this.labelOne = BI.createWidget({ - type: "bi.sign_text_editor", - cls: "slider-editor-button", - text: this.options.unit, - errorText: "", - allowBlank: false, - width: c.EDITOR_WIDTH, - validationChecker: function (v) { - return self._checkValidation(v); - } + this.editor.on(BI.Editor.EVENT_FOCUS, function () { + self.fireEvent(BI.TextEditor.EVENT_FOCUS); }); - this.labelOne.element.hover(function () { - self.labelOne.element.removeClass("bi-border").addClass("bi-border"); - }, function () { - self.labelOne.element.removeClass("bi-border"); + this.editor.on(BI.Editor.EVENT_BLUR, function () { + self.fireEvent(BI.TextEditor.EVENT_BLUR); }); - this.labelOne.on(BI.Editor.EVENT_CONFIRM, function () { - var v = BI.parseFloat(this.getValue()); - self.valueOne = v; - var percent = self._getPercentByValue(v); - var significantPercent = BI.parseFloat(percent.toFixed(1));// 分成1000份 - self._setLabelOnePosition(significantPercent); - self._setSliderOnePosition(significantPercent); - self._setBlueTrack(); - self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); + this.editor.on(BI.Editor.EVENT_CLICK, function () { + self.fireEvent(BI.TextEditor.EVENT_CLICK); }); - - this.labelTwo = BI.createWidget({ - type: "bi.sign_text_editor", - cls: "slider-editor-button", - errorText: "", - text: this.options.unit, - allowBlank: false, - width: c.EDITOR_WIDTH, - validationChecker: function (v) { - return self._checkValidation(v); - } + this.editor.on(BI.Editor.EVENT_CHANGE, function () { + self.fireEvent(BI.TextEditor.EVENT_CHANGE); }); - this.labelTwo.element.hover(function () { - self.labelTwo.element.removeClass("bi-border").addClass("bi-border"); - }, function () { - self.labelTwo.element.removeClass("bi-border"); + this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { + self.fireEvent(BI.TextEditor.EVENT_KEY_DOWN); }); - this.labelTwo.on(BI.Editor.EVENT_CONFIRM, function () { - var v = BI.parseFloat(this.getValue()); - self.valueTwo = v; - var percent = self._getPercentByValue(v); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setLabelTwoPosition(significantPercent); - self._setSliderTwoPosition(significantPercent); - self._setBlueTrack(); - self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); + this.editor.on(BI.Editor.EVENT_SPACE, function (v) { + self.fireEvent(BI.TextEditor.EVENT_SPACE); + }); + this.editor.on(BI.Editor.EVENT_BACKSPACE, function (v) { + self.fireEvent(BI.TextEditor.EVENT_BACKSPACE); }); - this.sliderOne = BI.createWidget({ - type: "bi.single_slider_button" + + this.editor.on(BI.Editor.EVENT_VALID, function () { + self.fireEvent(BI.TextEditor.EVENT_VALID); }); - this.sliderTwo = BI.createWidget({ - type: "bi.single_slider_button" + this.editor.on(BI.Editor.EVENT_CONFIRM, function () { + self.fireEvent(BI.TextEditor.EVENT_CONFIRM); }); - this._draggable(this.sliderOne, true); - this._draggable(this.sliderTwo, false); - this._setVisible(false); - - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.track, - width: "100%", - height: c.TRACK_HEIGHT - }] - }], - hgap: 7, - height: c.TRACK_HEIGHT - }, - top: 23, - left: 0, - width: "100%" - }, - this._createLabelWrapper(), - this._createSliderWrapper() - ] + this.editor.on(BI.Editor.EVENT_REMOVE, function (v) { + self.fireEvent(BI.TextEditor.EVENT_REMOVE); }); - }, - - _rePosBySizeAfterMove: function (size, isLeft) { - var o = this.options; - var percent = size * 100 / (this._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - var v = this._getValueByPercent(significantPercent); - v = this._assertValue(v); - v = o.digit === false ? v : v.toFixed(o.digit); - if(isLeft) { - this._setLabelOnePosition(significantPercent); - this._setSliderOnePosition(significantPercent); - this.labelOne.setValue(v); - this.valueOne = v; - }else{ - this._setLabelTwoPosition(significantPercent); - this._setSliderTwoPosition(significantPercent); - this.labelTwo.setValue(v); - this.valueTwo = v; - } - this._setBlueTrack(); - }, - - _rePosBySizeAfterStop: function (size, isLeft) { - var percent = size * 100 / (this._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - isLeft ? this._setSliderOnePosition(significantPercent) : this._setSliderTwoPosition(significantPercent); - }, - - _draggable: function (widget, isLeft) { - var self = this, o = this.options; - var startDrag = false; - var size = 0, offset = 0, defaultSize = 0; - var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { - if (mouseMoveTracker.isDragging()) { - startDrag = true; - offset += deltaX; - size = optimizeSize(defaultSize + offset); - widget.element.addClass("dragging"); - self._rePosBySizeAfterMove(size, isLeft); - } - }, function () { - if (startDrag === true) { - size = optimizeSize(size); - self._rePosBySizeAfterStop(size, isLeft); - size = 0; - offset = 0; - defaultSize = size; - startDrag = false; - } - widget.element.removeClass("dragging"); - mouseMoveTracker.releaseMouseMoves(); - self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); - }, window); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; - } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); + this.editor.on(BI.Editor.EVENT_START, function () { + self.fireEvent(BI.TextEditor.EVENT_START); + }); + this.editor.on(BI.Editor.EVENT_PAUSE, function () { + self.fireEvent(BI.TextEditor.EVENT_PAUSE); + }); + this.editor.on(BI.Editor.EVENT_STOP, function () { + self.fireEvent(BI.TextEditor.EVENT_STOP); + }); + this.editor.on(BI.Editor.EVENT_ERROR, function () { + self.fireEvent(BI.TextEditor.EVENT_ERROR, arguments); + }); + this.editor.on(BI.Editor.EVENT_ENTER, function () { + self.fireEvent(BI.TextEditor.EVENT_ENTER); + }); + this.editor.on(BI.Editor.EVENT_RESTRICT, function () { + self.fireEvent(BI.TextEditor.EVENT_RESTRICT); + }); + this.editor.on(BI.Editor.EVENT_EMPTY, function () { + self.fireEvent(BI.TextEditor.EVENT_EMPTY); + }); + BI.createWidget({ + type: "bi.vertical", + scrolly: false, + element: this, + items: [this.editor] }); - - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); - } }, - _createLabelWrapper: function () { - var c = this._constant; - return { - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.labelOne, - top: 0, - left: "0%" - }] - }, { - type: "bi.absolute", - items: [{ - el: this.labelTwo, - top: 0, - left: "100%" - }] - }], - rgap: c.EDITOR_R_GAP, - height: 70 - }, - top: 0, - left: 0, - width: "100%" - }; + focus: function () { + this.editor.focus(); }, - _createSliderWrapper: function () { - var c = this._constant; - return { - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.sliderOne, - top: 0, - left: "0%" - }] - }, { - type: "bi.absolute", - items: [{ - el: this.sliderTwo, - top: 0, - left: "100%" - }] - }], - hgap: c.SLIDER_WIDTH_HALF, - height: c.SLIDER_HEIGHT - }, - top: 20, - left: 0, - width: "100%" - }; + blur: function () { + this.editor.blur(); }, - _createTrackWrapper: function () { - return BI.createWidget({ - type: "bi.absolute", - items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.grayTrack, - top: 0, - left: 0, - width: "100%" - }, { - el: this.blueTrack, - top: 0, - left: 0, - width: "0%" - }] - }], - hgap: 8, - height: 8 - }, - top: 8, - left: 0, - width: "100%" - }] - }); + setErrorText: function (text) { + this.editor.setErrorText(text); }, - _checkValidation: function (v) { - var o = this.options; - var valid = false; - // 像90.这样的既不属于整数又不属于小数,是不合法的值 - var dotText = (v + "").split(".")[1]; - if (BI.isEmptyString(dotText)) { - }else{ - if (BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)) { - if(o.digit === false) { - valid = true; - }else{ - dotText = dotText || ""; - valid = (dotText.length === o.digit); - } - } - } - return valid; + getErrorText: function () { + return this.editor.getErrorText(); }, - _checkOverlap: function () { - var labelOneLeft = this.labelOne.element[0].offsetLeft; - var labelTwoLeft = this.labelTwo.element[0].offsetLeft; - if (labelOneLeft <= labelTwoLeft) { - if ((labelTwoLeft - labelOneLeft) < 90) { - this.labelTwo.element.css({top: 40}); - } else { - this.labelTwo.element.css({top: 0}); - } - } else { - if ((labelOneLeft - labelTwoLeft) < 90) { - this.labelTwo.element.css({top: 40}); - } else { - this.labelTwo.element.css({top: 0}); - } - } + isValid: function () { + return this.editor.isValid(); }, - _setLabelOnePosition: function (percent) { - this.labelOne.element.css({left: percent + "%"}); - this._checkOverlap(); + setValue: function (v) { + this.editor.setValue(v); }, - _setLabelTwoPosition: function (percent) { - this.labelTwo.element.css({left: percent + "%"}); - this._checkOverlap(); - }, + getValue: function () { + return this.editor.getValue(); + } +}); +BI.TextEditor.EVENT_CHANGE = "EVENT_CHANGE"; +BI.TextEditor.EVENT_FOCUS = "EVENT_FOCUS"; +BI.TextEditor.EVENT_BLUR = "EVENT_BLUR"; +BI.TextEditor.EVENT_CLICK = "EVENT_CLICK"; +BI.TextEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.TextEditor.EVENT_SPACE = "EVENT_SPACE"; +BI.TextEditor.EVENT_BACKSPACE = "EVENT_BACKSPACE"; - _setSliderOnePosition: function (percent) { - this.sliderOne.element.css({left: percent + "%"}); - }, +BI.TextEditor.EVENT_START = "EVENT_START"; +BI.TextEditor.EVENT_PAUSE = "EVENT_PAUSE"; +BI.TextEditor.EVENT_STOP = "EVENT_STOP"; +BI.TextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.TextEditor.EVENT_VALID = "EVENT_VALID"; +BI.TextEditor.EVENT_ERROR = "EVENT_ERROR"; +BI.TextEditor.EVENT_ENTER = "EVENT_ENTER"; +BI.TextEditor.EVENT_RESTRICT = "EVENT_RESTRICT"; +BI.TextEditor.EVENT_REMOVE = "EVENT_REMOVE"; +BI.TextEditor.EVENT_EMPTY = "EVENT_EMPTY"; - _setSliderTwoPosition: function (percent) { - this.sliderTwo.element.css({left: percent + "%"}); +BI.shortcut("bi.text_editor", BI.TextEditor);/** + * 小号搜索框 + * Created by GUY on 2015/9/29. + * @class BI.SmallTextEditor + * @extends BI.SearchEditor + */ +BI.SmallTextEditor = BI.inherit(BI.TextEditor, { + _defaultConfig: function () { + var conf = BI.SmallTextEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-small-text-editor", + height: 25 + }); }, - _setBlueTrackLeft: function (percent) { - this.blueTrack.element.css({left: percent + "%"}); - }, + _init: function () { + BI.SmallTextEditor.superclass._init.apply(this, arguments); + } +}); +BI.shortcut("bi.small_text_editor", BI.SmallTextEditor);/** + * 文件管理控件组 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerButtonGroup + * @extends BI.Widget + */ +BI.FileManagerButtonGroup = BI.inherit(BI.Widget, { - _setBlueTrackWidth: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); + _defaultConfig: function () { + return BI.extend(BI.FileManagerButtonGroup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-button_group", + items: [] + }); }, - _setBlueTrack: function () { - var percentOne = this._getPercentByValue(this.labelOne.getValue()); - var percentTwo = this._getPercentByValue(this.labelTwo.getValue()); - if (percentOne <= percentTwo) { - this._setBlueTrackLeft(percentOne); - this._setBlueTrackWidth(percentTwo - percentOne); - } else { - this._setBlueTrackLeft(percentTwo); - this._setBlueTrackWidth(percentOne - percentTwo); - } + _init: function () { + BI.FileManagerButtonGroup.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.button_group = BI.createWidget({ + type: "bi.button_tree", + element: this, + chooseType: BI.Selection.Multi, + items: this._formatItems(o.items), + layouts: [{ + type: "bi.vertical" + }] + }); + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); }, - _setAllPosition: function (one, two) { - this._setSliderOnePosition(one); - this._setLabelOnePosition(one); - this._setSliderTwoPosition(two); - this._setLabelTwoPosition(two); - this._setBlueTrack(); + _formatItems: function (items) { + var self = this, o = this.options; + BI.each(items, function (i, item) { + if (item.children && item.children.length > 0) { + item.type = "bi.file_manager_folder_item"; + } else { + item.type = "bi.file_manager_file_item"; + } + }); + return items; }, - _setVisible: function (visible) { - this.sliderOne.setVisible(visible); - this.sliderTwo.setVisible(visible); - this.labelOne.setVisible(visible); - this.labelTwo.setVisible(visible); + setValue: function (v) { + this.button_group.setValue(v); }, - _setErrorText: function () { - var errorText = BI.i18nText("BI-Please_Enter") + this.min + "-" + this.max + BI.i18nText("BI-Basic_De") + BI.i18nText("BI-Basic_Number"); - this.labelOne.setErrorText(errorText); - this.labelTwo.setErrorText(errorText); + getValue: function () { + return this.button_group.getValue(); }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + getNotSelectedValue: function () { + return this.button_group.getNotSelectedValue(); }, - // 其中取max-min后保留4为有效数字后的值的小数位数为最终value的精度 - _getValueByPercent: function (percent) {// return (((max-min)*percent)/100+min) - var sub = this.calculation.accurateSubtraction(this.max, this.min); - var mul = this.calculation.accurateMultiplication(sub, percent); - var div = this.calculation.accurateDivisionTenExponent(mul, 2); - if(this.precision < 0) { - var value = BI.parseFloat(this.calculation.accurateAddition(div, this.min)); - var reduceValue = Math.round(this.calculation.accurateDivisionTenExponent(value, -this.precision)); - return this.calculation.accurateMultiplication(reduceValue, Math.pow(10, -this.precision)); - } - return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision)); + getAllLeaves: function () { + return this.button_group.getAllLeaves(); + }, + getAllButtons: function () { + return this.button_group.getAllButtons(); }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); + getSelectedButtons: function () { + return this.button_group.getSelectedButtons(); }, - _setDraggableEnable: function (enable) { - this.sliderOne.setEnable(enable); - this.sliderTwo.setEnable(enable); + getNotSelectedButtons: function () { + return this.button_group.getNotSelectedButtons(); }, - _getPrecision: function () { - // 计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度) - // 如果差值的整数位数大于4,toPrecision(4)得到的是科学计数法123456 => 1.235e+5 - // 返回非负值: 保留的小数位数 - // 返回负值: 保留的10^n精度中的n - var sub = this.calculation.accurateSubtraction(this.max, this.min); - var pre = sub.toPrecision(4); - // 科学计数法 - var eIndex = pre.indexOf("e"); - var arr = []; - if(eIndex > -1) { - arr = pre.split("e"); - var decimalPartLength = BI.size(arr[0].split(".")[1]); - var sciencePartLength = BI.parseInt(arr[1].substring(1)); - return decimalPartLength - sciencePartLength; - } - arr = pre.split("."); - return arr.length > 1 ? arr[1].length : 0; + populate: function (items) { + this.button_group.populate(this._formatItems(items)); + } +}); +BI.FileManagerButtonGroup.EVENT_CHANGE = "FileManagerButtonGroup.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_button_group", BI.FileManagerButtonGroup);/** + * 文件管理控件 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManager + * @extends BI.Widget + */ +BI.FileManager = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.FileManager.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager", + el: {}, + items: [] + }); }, - _assertValue: function (value) { - if(value <= this.min) { - return this.min; - } - if(value >= this.max) { - return this.max; - } - return value; + _init: function () { + BI.FileManager.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.tree = new BI.Tree(); + var items = BI.Tree.transformToTreeFormat(o.items); + this.tree.initTree(items); + this.selectedValues = []; + this.nav = BI.createWidget({ + type: "bi.file_manager_nav", + items: BI.deepClone(items) + }); + this.nav.on(BI.FileManagerNav.EVENT_CHANGE, function (value, obj) { + if (value == "-1") {// 根节点 + self.populate({children: self.tree.toJSON()}); + } else { + var node = self.tree.search(obj.attr("id")); + self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); + } + self.setValue(self.selectedValues); + }); + this.list = BI.createWidget(o.el, { + type: "bi.file_manager_list", + items: items + }); + this.list.on(BI.Controller.EVENT_CHANGE, function (type, selected, obj) { + if (type === BI.Events.CHANGE) { + var node = self.tree.search(obj.attr("id")); + self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); + } else if (type === BI.Events.CLICK) { + var values = []; + if (obj instanceof BI.MultiSelectBar) { + var t = self.list.getValue(); + selected = t.type === BI.Selection.All; + values = BI.concat(t.assist, t.value); + } else { + values = obj.getAllLeaves(); + } + BI.each(values, function (i, v) { + if (selected === true) { + self.selectedValues.pushDistinct(v); + } else { + self.selectedValues.remove(v); + } + }); + } + self.setValue(self.selectedValues); + }); + + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.list, + left: 0, + right: 0, + top: 0, + bottom: 10 + }, { + el: this.nav, + left: 40, + right: 100, + top: 0 + }] + }); + }, + + setValue: function (value) { + this.selectedValues = value || []; + this.list.setValue(this.selectedValues); }, getValue: function () { - if (this.valueOne <= this.valueTwo) { - return {min: this.valueOne, max: this.valueTwo}; - } - return {min: this.valueTwo, max: this.valueOne}; + var obj = this.list.getValue(); + var res = obj.type === BI.Selection.All ? obj.assist : obj.value; + res.pushDistinctArray(this.selectedValues); + return res; + }, + _populate: function (items) { + this.list.populate(items); }, - setMinAndMax: function (v) { - var minNumber = BI.parseFloat(v.min); - var maxNumber = BI.parseFloat(v.max); - if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber >= minNumber )) { - this.min = minNumber; - this.max = maxNumber; - this.valueOne = minNumber; - this.valueTwo = maxNumber; - this.precision = this._getPrecision(); - this._setDraggableEnable(true); - } - if (maxNumber === minNumber) { - this._setDraggableEnable(false); - } + getSelectedValue: function () { + return this.nav.getValue()[0]; }, - setValue: function (v) { - var o = this.options; - var valueOne = BI.parseFloat(v.min); - var valueTwo = BI.parseFloat(v.max); - valueOne = o.digit === false ? valueOne : valueOne.toFixed(o.digit); - valueTwo = o.digit === false ? valueTwo : valueTwo.toFixed(o.digit); - if (!isNaN(valueOne) && !isNaN(valueTwo)) { - if (this._checkValidation(valueOne)) { - this.valueOne = valueOne; - } - if (this._checkValidation(valueTwo)) { - this.valueTwo = valueTwo; - } - if (valueOne < this.min) { - this.valueOne = this.min; - } - if (valueTwo > this.max) { - this.valueTwo = this.max; - } - } + getSelectedId: function () { + return this.nav.getId()[0]; + }, + + populate: function (node) { + var clone = BI.deepClone(node); + this._populate(node.children); + this.nav.populate(clone); + } +}); +BI.FileManager.EVENT_CHANGE = "FileManager.EVENT_CHANGE"; +BI.shortcut("bi.file_manager", BI.FileManager);/** + * 文件管理控件 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerFileItem + * @extends BI.Single + */ +BI.FileManagerFileItem = BI.inherit(BI.Single, { + + _defaultConfig: function () { + return BI.extend(BI.FileManagerFileItem.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-file-item bi-list-item bi-border-bottom", + height: 30 + }); + }, + + _init: function () { + BI.FileManagerFileItem.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.checked = BI.createWidget({ + type: "bi.multi_select_bar", + text: "", + width: 36, + height: o.height + }); + this.checked.on(BI.Controller.EVENT_CHANGE, function () { + arguments[2] = self; + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + BI.createWidget({ + type: "bi.htape", + element: this, + items: [{ + el: this.checked, + width: 36 + }, { + el: { + type: "bi.icon_button", + cls: "create-by-me-file-font" + }, + width: 20 + }, { + el: { + type: "bi.label", + textAlign: "left", + height: o.height, + text: o.text, + value: o.value + } + }] + }); }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.valueOne = ""; - this.valueTwo = ""; - this.min = NaN; - this.max = NaN; - this._setBlueTrackWidth(0); + getAllLeaves: function () { + return [this.options.value]; }, - populate: function () { - if (!isNaN(this.min) && !isNaN(this.max)) { - this.enable = true; - this._setVisible(true); - this._setErrorText(); - if ((BI.isNumeric(this.valueOne) || BI.isNotEmptyString(this.valueOne)) && (BI.isNumeric(this.valueTwo) || BI.isNotEmptyString(this.valueTwo))) { - this.labelOne.setValue(this.valueOne); - this.labelTwo.setValue(this.valueTwo); - this._setAllPosition(this._getPercentByValue(this.valueOne), this._getPercentByValue(this.valueTwo)); - } else { - this.labelOne.setValue(this.min); - this.labelTwo.setValue(this.max); - this._setAllPosition(0, 100); - } - } + isSelected: function () { + return this.checked.isSelected(); + }, + + setSelected: function (v) { + this.checked.setSelected(v); } }); -BI.IntervalSlider.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.interval_slider", BI.IntervalSlider);/** - * Created by zcf on 2017/3/1. - * 万恶的IEEE-754 - * 使用字符串精确计算含小数加法、减法、乘法和10的指数倍除法,支持负数 +BI.FileManagerFileItem.EVENT_CHANGE = "FileManagerFileItem.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_file_item", BI.FileManagerFileItem);/** + * 文件管理控件 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerFolderItem + * @extends BI.Single */ -BI.AccurateCalculationModel = BI.inherit(BI.Widget, { +BI.FileManagerFolderItem = BI.inherit(BI.Single, { + _defaultConfig: function () { - return BI.extend(BI.AccurateCalculationModel.superclass._defaultConfig.apply(this, arguments), { - baseCls: "" + return BI.extend(BI.FileManagerFolderItem.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-folder-item bi-list-item bi-border-bottom", + height: 30 }); }, _init: function () { - BI.AccurateCalculationModel.superclass._init.apply(this, arguments); + BI.FileManagerFolderItem.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.checked = BI.createWidget({ + type: "bi.multi_select_bar", + text: "", + width: 36, + height: o.height + }); + this.checked.on(BI.Controller.EVENT_CHANGE, function () { + arguments[2] = self; + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + this.button = BI.createWidget({ + type: "bi.text_button", + textAlign: "left", + height: o.height, + text: o.text, + value: o.value + }); + this.button.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CHANGE, o.value, self); + }); + + this.tree = new BI.Tree(); + this.tree.initTree([{ + id: o.id, + children: o.children + }]); + this.selectValue = []; + + BI.createWidget({ + type: "bi.htape", + element: this, + items: [{ + el: this.checked, + width: 36 + }, { + el: { + type: "bi.icon_button", + cls: "create-by-me-folder-font" + }, + width: 20 + }, { + el: this.button + }] + }); }, - _getMagnitude: function (n) { - var magnitude = "1"; - for (var i = 0; i < n; i++) { - magnitude += "0"; - } - return BI.parseInt(magnitude); + setAllSelected: function (v) { + this.checked.setSelected(v); + this.selectValue = []; }, - _formatDecimal: function (stringNumber1, stringNumber2) { - if (stringNumber1.numDecimalLength === stringNumber2.numDecimalLength) { - return; - } - var magnitudeDiff = stringNumber1.numDecimalLength - stringNumber2.numDecimalLength; - if (magnitudeDiff > 0) { - var needAddZero = stringNumber2; - } else { - var needAddZero = stringNumber1; - magnitudeDiff = (0 - magnitudeDiff); + setHalfSelected: function (v) { + this.checked.setHalfSelected(v); + if(!v) { + this.selectValue = []; } - for (var i = 0; i < magnitudeDiff; i++) { - if (needAddZero.numDecimal === "0" && i === 0) { - continue; + }, + + setValue: function (v) { + var self = this, o = this.options; + var isHalf = false; + var selectValue = []; + this.tree.traverse(function (node) { + if (node.isLeaf()) { + if (BI.contains(v, node.get("data").value)) { + selectValue.push(node.get("data").value); + } else { + isHalf = true; + } } - needAddZero.numDecimal += "0"; + }); + this.setAllSelected(selectValue.length > 0 && !isHalf); + this.setHalfSelected(selectValue.length > 0 && isHalf); + if (this.checked.isHalfSelected()) { + this.selectValue = selectValue; } }, - _stringNumberFactory: function (num) { - var strNum = num.toString(); - var numStrArray = strNum.split("."); - var numInteger = numStrArray[0]; - if (numStrArray.length === 1) { - var numDecimal = "0"; - var numDecimalLength = 0; - } else { - var numDecimal = numStrArray[1]; - var numDecimalLength = numStrArray[1].length; - } - return { - numInteger: numInteger, - numDecimal: numDecimal, - numDecimalLength: numDecimalLength - }; + getAllButtons: function () { + return [this]; }, - _accurateSubtraction: function (num1, num2) {// num1-num2 && num1>num2 - var stringNumber1 = this._stringNumberFactory(num1); - var stringNumber2 = this._stringNumberFactory(num2); - // 整数部分计算 - var integerResult = BI.parseInt(stringNumber1.numInteger) - BI.parseInt(stringNumber2.numInteger); - // 小数部分 - this._formatDecimal(stringNumber1, stringNumber2); - var decimalMaxLength = getDecimalMaxLength(stringNumber1, stringNumber2); + getAllLeaves: function () { + var o = this.options; + var res = []; + this.tree.traverse(function (node) { + if (node.isLeaf()) { + res.push(node.get("data").value); + } + }); + return res; + }, - if (BI.parseInt(stringNumber1.numDecimal) >= BI.parseInt(stringNumber2.numDecimal)) { - var decimalResultTemp = (BI.parseInt(stringNumber1.numDecimal) - BI.parseInt(stringNumber2.numDecimal)).toString(); - var decimalResult = addZero(decimalResultTemp, decimalMaxLength); - } else {// 否则借位 - integerResult--; - var borrow = this._getMagnitude(decimalMaxLength); - var decimalResultTemp = (borrow + BI.parseInt(stringNumber1.numDecimal) - BI.parseInt(stringNumber2.numDecimal)).toString(); - var decimalResult = addZero(decimalResultTemp, decimalMaxLength); + getNotSelectedValue: function () { + var self = this, o = this.options; + var res = []; + var isAllSelected = this.checked.isSelected(); + if (isAllSelected === true) { + return res; } - var result = integerResult + "." + decimalResult; - return BI.parseFloat(result); - - function getDecimalMaxLength (num1, num2) { - if (num1.numDecimal.length >= num2.numDecimal.length) { - return num1.numDecimal.length; + var isHalfSelected = this.checked.isHalfSelected(); + this.tree.traverse(function (node) { + if (node.isLeaf()) { + var v = node.get("data").value; + if (isHalfSelected === true) { + if (!BI.contains(self.selectValue, node.get("data").value)) { + res.push(v); + } + } else { + res.push(v); + } } - return num2.numDecimal.length; + }); + return res; + }, + + getValue: function () { + var res = []; + if (this.checked.isSelected()) { + this.tree.traverse(function (node) { + if (node.isLeaf()) { + res.push(node.get("data").value); + } + }); + return res; + } + if (this.checked.isHalfSelected()) { + return this.selectValue; } + return []; + } +}); +BI.FileManagerFolderItem.EVENT_CHANGE = "FileManagerFolderItem.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_folder_item", BI.FileManagerFolderItem);/** + * 文件管理控件列表 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerList + * @extends BI.Widget + */ +BI.FileManagerList = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.FileManagerList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-list", + el: {}, + items: [] + }); + }, - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; + _init: function () { + BI.FileManagerList.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.list = BI.createWidget({ + type: "bi.select_list", + element: this, + items: o.items, + toolbar: { + type: "bi.multi_select_bar", + height: 40, + text: "" + }, + el: { + type: "bi.list_pane", + el: BI.isWidget(o.el) ? o.el : BI.extend({ + type: "bi.file_manager_button_group" + }, o.el) } - return resultTemp; - } + }); + this.list.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); }, - _accurateAddition: function (num1, num2) {// 加法结合律 - var stringNumber1 = this._stringNumberFactory(num1); - var stringNumber2 = this._stringNumberFactory(num2); - // 整数部分计算 - var integerResult = BI.parseInt(stringNumber1.numInteger) + BI.parseInt(stringNumber2.numInteger); - // 小数部分 - this._formatDecimal(stringNumber1, stringNumber2); + setValue: function (v) { + this.list.setValue({ + value: v + }); + }, - var decimalResult = (BI.parseInt(stringNumber1.numDecimal) + BI.parseInt(stringNumber2.numDecimal)).toString(); + getValue: function () { + return this.list.getValue(); + }, - if (decimalResult !== "0") { - if (decimalResult.length <= stringNumber1.numDecimal.length) { - decimalResult = addZero(decimalResult, stringNumber1.numDecimal.length); + populate: function (items) { + this.list.populate(items); + this.list.setToolBarVisible(true); + } +}); +BI.FileManagerList.EVENT_CHANGE = "FileManagerList.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_list", BI.FileManagerList);/** + * 文件管理导航按钮 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerNavButton + * @extends BI.Widget + */ +BI.FileManagerNavButton = BI.inherit(BI.Widget, { + + _const: { + normal_color: "#ffffff", + select_color: "#eff1f4" + }, + _defaultConfig: function () { + return BI.extend(BI.FileManagerNavButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-nav-button", + selected: false, + height: 40 + }); + }, + + _init: function () { + BI.FileManagerNavButton.superclass._init.apply(this, arguments); + var self = this, o = this.options, c = this._const; + this.button = BI.createWidget({ + type: "bi.text_button", + cls: "file-manager-nav-button-text bi-card", + once: true, + selected: o.selected, + text: o.text, + title: o.text, + value: o.value, + height: o.height, + lgap: 20, + rgap: 10 + }); + this.button.on(BI.Controller.EVENT_CHANGE, function () { + arguments[2] = self; + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + var svg = BI.createWidget({ + type: "bi.svg", + cls: "file-manager-nav-button-triangle", + width: 15, + height: o.height + }); + var path = svg.path("M0,0L15,20L0,40").attr({ + stroke: c.select_color, + fill: o.selected ? c.select_color : c.normal_color + }); + this.button.on(BI.TextButton.EVENT_CHANGE, function () { + if (this.isSelected()) { + path.attr("fill", c.select_color); } else { - integerResult++;// 进一 - decimalResult = decimalResult.slice(1); + path.attr("fill", c.normal_color); } - } - var result = integerResult + "." + decimalResult; - return BI.parseFloat(result); + }); + BI.createWidget({ + type: "bi.default", + element: this, + items: [this.button] + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: svg, + right: -15, + top: 0, + bottom: 0 + }] + }); + }, - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; - } - return resultTemp; - } + isSelected: function () { + return this.button.isSelected(); }, - _accurateMultiplication: function (num1, num2) {// 乘法分配律 - var stringNumber1 = this._stringNumberFactory(num1); - var stringNumber2 = this._stringNumberFactory(num2); - // 整数部分计算 - var integerResult = BI.parseInt(stringNumber1.numInteger) * BI.parseInt(stringNumber2.numInteger); - // num1的小数和num2的整数 - var dec1Int2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numDecimal) * BI.parseInt(stringNumber2.numInteger), stringNumber1.numDecimalLength); - // num1的整数和num2的小数 - var int1dec2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numInteger) * BI.parseInt(stringNumber2.numDecimal), stringNumber2.numDecimalLength); - // 小数*小数 - var dec1dec2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numDecimal) * BI.parseInt(stringNumber2.numDecimal), (stringNumber1.numDecimalLength + stringNumber2.numDecimalLength)); + setValue: function (v) { + this.button.setValue(v); + }, - return this._accurateAddition(this._accurateAddition(this._accurateAddition(integerResult, dec1Int2), int1dec2), dec1dec2); + getValue: function () { + return this.button.getValue(); }, - _accurateDivisionTenExponent: function (num, n) {// num/10^n && n>0 - var stringNumber = this._stringNumberFactory(num); - if (stringNumber.numInteger.length > n) { - var integerResult = stringNumber.numInteger.slice(0, (stringNumber.numInteger.length - n)); - var partDecimalResult = stringNumber.numInteger.slice(-n); - } else { - var integerResult = "0"; - var partDecimalResult = addZero(stringNumber.numInteger, n); - } - var result = integerResult + "." + partDecimalResult + stringNumber.numDecimal; - return BI.parseFloat(result); + populate: function (items) { - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; - } - return resultTemp; - } + } +}); +BI.FileManagerNavButton.EVENT_CHANGE = "FileManagerNavButton.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_nav_button", BI.FileManagerNavButton);/** + * 文件管理导航 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerNav + * @extends BI.Widget + */ +BI.FileManagerNav = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.FileManagerNav.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-nav bi-border-left", + height: 40, + items: [] + }); }, - accurateSubtraction: function (num1, num2) { - if (num1 >= 0 && num2 >= 0) { - if (num1 >= num2) { - return this._accurateSubtraction(num1, num2); - } - return -this._accurateSubtraction(num2, num1); - } - if (num1 >= 0 && num2 < 0) { - return this._accurateAddition(num1, -num2); - } - if (num1 < 0 && num2 >= 0) { - return -this._accurateAddition(-num1, num2); - } - if (num1 < 0 && num2 < 0) { - if (num1 >= num2) { - return this._accurateSubtraction(-num2, -num1); - } - return this._accurateSubtraction(-num1, -num2); - } + _init: function () { + BI.FileManagerNav.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.tree = new BI.Tree(); + this.refreshTreeData(o.items); + this.tree.getRoot().set("data", { + text: BI.i18nText("BI-Created_By_Me"), + value: BI.FileManagerNav.ROOT_CREATE_BY_ME, + id: BI.FileManagerNav.ROOT_CREATE_BY_ME + }); + this.button_group = BI.createWidget({ + type: "bi.button_group", + element: this, + items: [{ + type: "bi.file_manager_nav_button", + text: BI.i18nText("BI-Created_By_Me"), + selected: true, + id: BI.FileManagerNav.ROOT_CREATE_BY_ME, + value: BI.FileManagerNav.ROOT_CREATE_BY_ME + }], + layouts: [{ + type: "bi.horizontal" + }] + }); + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + this.button_group.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) { + self.fireEvent(BI.FileManagerNav.EVENT_CHANGE, arguments); + }); }, - accurateAddition: function (num1, num2) { - if (num1 >= 0 && num2 >= 0) { - return this._accurateAddition(num1, num2); - } - if (num1 >= 0 && num2 < 0) { - return this.accurateSubtraction(num1, -num2); - } - if (num1 < 0 && num2 >= 0) { - return this.accurateSubtraction(num2, -num1); + _getAllParents: function (id) { + var node, res = []; + if (!id) { + node = this.tree.getRoot(); + } else { + node = this.tree.search(id); } - if (num1 < 0 && num2 < 0) { - return -this._accurateAddition(-num1, -num2); + while (node.parent) { + res.push(node); + node = node.parent; } + res.push(node); + return res.reverse(); }, - accurateMultiplication: function (num1, num2) { - if (num1 >= 0 && num2 >= 0) { - return this._accurateMultiplication(num1, num2); - } - if (num1 >= 0 && num2 < 0) { - return -this._accurateMultiplication(num1, -num2); - } - if (num1 < 0 && num2 >= 0) { - return -this._accurateMultiplication(-num1, num2); - } - if (num1 < 0 && num2 < 0) { - return this._accurateMultiplication(-num1, -num2); - } + _formatNodes: function (nodes) { + var res = []; + BI.each(nodes, function (i, node) { + res.push(BI.extend({ + type: "bi.file_manager_nav_button", + id: node.id + }, node.get("data"))); + }); + BI.last(res).selected = true; + return res; }, - accurateDivisionTenExponent: function (num1, n) { - if (num1 >= 0) { - return this._accurateDivisionTenExponent(num1, n); - } - return -this._accurateDivisionTenExponent(-num1, n); + getValue: function () { + return this.button_group.getValue(); + }, + + getId: function () { + var ids = []; + BI.each(this.button_group.getSelectedButtons(), function (i, btn) { + ids.push(btn.attr("id")); + }); + return ids; + }, + + refreshTreeData: function (items) { + this.tree.initTree(BI.Tree.transformToTreeFormat(items)); + this.tree.getRoot().set("data", { + text: BI.i18nText("BI-Created_By_Me"), + value: BI.FileManagerNav.ROOT_CREATE_BY_ME, + id: BI.FileManagerNav.ROOT_CREATE_BY_ME + }); + }, + + populate: function (node) { + var parents = BI.isNull(node) ? [this.tree.getRoot()] : this._getAllParents(node.id); + this.button_group.populate(this._formatNodes(parents)); } -});/** - * 月份下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.MonthCombo - * @extends BI.Trigger +}); +BI.extend(BI.FileManagerNav, { + ROOT_CREATE_BY_ME: "-1" +}); +BI.FileManagerNav.EVENT_CHANGE = "FileManagerNav.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_nav", BI.FileManagerNav);/** + * Created by zcf on 2016/9/26. */ -BI.MonthCombo = BI.inherit(BI.Widget, { +BI.IntervalSlider = BI.inherit(BI.Widget, { + _constant: { + EDITOR_WIDTH: 58, + EDITOR_R_GAP: 60, + EDITOR_HEIGHT: 30, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, + _defaultConfig: function () { - return BI.extend(BI.MonthCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-month-combo", - behaviors: {}, - height: 25 + return BI.extend(BI.IntervalSlider.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-interval-slider bi-slider-track", + digit: false, + unit: "" }); }, + _init: function () { - BI.MonthCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.IntervalSlider.superclass._init.apply(this, arguments); - this.trigger = BI.createWidget({ - type: "bi.month_trigger", - value: o.value + var self = this; + var c = this._constant; + this.enable = false; + this.valueOne = ""; + this.valueTwo = ""; + this.calculation = new BI.AccurateCalculationModel(); + + // this.backgroundTrack = BI.createWidget({ + // type: "bi.layout", + // cls: "background-track", + // height: c.TRACK_HEIGHT + // }); + this.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 + }); + this.blueTrack = BI.createWidget({ + type: "bi.layout", + cls: "blue-track bi-high-light-background", + height: 6 }); + this.track = this._createTrackWrapper(); - this.trigger.on(BI.MonthTrigger.EVENT_CONFIRM, function (v) { - if (self.combo.isViewVisible()) { - return; + this.labelOne = BI.createWidget({ + type: "bi.sign_text_editor", + cls: "slider-editor-button", + text: this.options.unit, + errorText: "", + allowBlank: false, + width: c.EDITOR_WIDTH, + validationChecker: function (v) { + return self._checkValidation(v); } - if (this.getKey() && this.getKey() !== self.storeValue) { - self.setValue(this.getValue()); - } else if (!this.getKey()) { - self.setValue(); + }); + this.labelOne.element.hover(function () { + self.labelOne.element.removeClass("bi-border").addClass("bi-border"); + }, function () { + self.labelOne.element.removeClass("bi-border"); + }); + this.labelOne.on(BI.Editor.EVENT_CONFIRM, function () { + var v = BI.parseFloat(this.getValue()); + self.valueOne = v; + var percent = self._getPercentByValue(v); + var significantPercent = BI.parseFloat(percent.toFixed(1));// 分成1000份 + self._setLabelOnePosition(significantPercent); + self._setSliderOnePosition(significantPercent); + self._setBlueTrack(); + self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); + }); + + this.labelTwo = BI.createWidget({ + type: "bi.sign_text_editor", + cls: "slider-editor-button", + errorText: "", + text: this.options.unit, + allowBlank: false, + width: c.EDITOR_WIDTH, + validationChecker: function (v) { + return self._checkValidation(v); + } + }); + this.labelTwo.element.hover(function () { + self.labelTwo.element.removeClass("bi-border").addClass("bi-border"); + }, function () { + self.labelTwo.element.removeClass("bi-border"); + }); + this.labelTwo.on(BI.Editor.EVENT_CONFIRM, function () { + var v = BI.parseFloat(this.getValue()); + self.valueTwo = v; + var percent = self._getPercentByValue(v); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setLabelTwoPosition(significantPercent); + self._setSliderTwoPosition(significantPercent); + self._setBlueTrack(); + self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); + }); + + this.sliderOne = BI.createWidget({ + type: "bi.single_slider_button" + }); + this.sliderTwo = BI.createWidget({ + type: "bi.single_slider_button" + }); + this._draggable(this.sliderOne, true); + this._draggable(this.sliderTwo, false); + this._setVisible(false); + + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.track, + width: "100%", + height: c.TRACK_HEIGHT + }] + }], + hgap: 7, + height: c.TRACK_HEIGHT + }, + top: 23, + left: 0, + width: "100%" + }, + this._createLabelWrapper(), + this._createSliderWrapper() + ] + }); + }, + + _rePosBySizeAfterMove: function (size, isLeft) { + var o = this.options; + var percent = size * 100 / (this._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + var v = this._getValueByPercent(significantPercent); + v = this._assertValue(v); + v = o.digit === false ? v : v.toFixed(o.digit); + if(isLeft) { + this._setLabelOnePosition(significantPercent); + this._setSliderOnePosition(significantPercent); + this.labelOne.setValue(v); + this.valueOne = v; + }else{ + this._setLabelTwoPosition(significantPercent); + this._setSliderTwoPosition(significantPercent); + this.labelTwo.setValue(v); + this.valueTwo = v; + } + this._setBlueTrack(); + }, + + _rePosBySizeAfterStop: function (size, isLeft) { + var percent = size * 100 / (this._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + isLeft ? this._setSliderOnePosition(significantPercent) : this._setSliderTwoPosition(significantPercent); + }, + + _draggable: function (widget, isLeft) { + var self = this, o = this.options; + var startDrag = false; + var size = 0, offset = 0, defaultSize = 0; + var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { + if (mouseMoveTracker.isDragging()) { + startDrag = true; + offset += deltaX; + size = optimizeSize(defaultSize + offset); + widget.element.addClass("dragging"); + self._rePosBySizeAfterMove(size, isLeft); } - self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); - }); - this.trigger.on(BI.MonthTrigger.EVENT_FOCUS, function () { - self.storeValue = this.getKey(); - }); - this.trigger.on(BI.MonthTrigger.EVENT_START, function () { - self.combo.hideView(); - }); - this.trigger.on(BI.MonthTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); + }, function () { + if (startDrag === true) { + size = optimizeSize(size); + self._rePosBySizeAfterStop(size, isLeft); + size = 0; + offset = 0; + defaultSize = size; + startDrag = false; } - }); - - this.popup = BI.createWidget({ - type: "bi.month_popup", - behaviors: o.behaviors, - value: o.value - }); - this.popup.on(BI.MonthPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); - }); - - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - el: this.popup + widget.element.removeClass("dragging"); + mouseMoveTracker.releaseMouseMoves(); + self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); + }, window); + widget.element.on("mousedown", function (event) { + if(!widget.isEnabled()) { + return; } + defaultSize = this.offsetLeft; + optimizeSize(defaultSize); + mouseMoveTracker.captureMouseMoves(event); }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW); - }); - }, - setValue: function (v) { - this.trigger.setValue(v); - this.popup.setValue(v); - }, - - getValue: function () { - if (BI.isNull(this.popup)) { - return this.options.value || ""; - } else { - return this.popup.getValue() || ""; + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); } - } -}); - -BI.MonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.MonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.month_combo", BI.MonthCombo);/** - * 月份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.MonthPopup - * @extends BI.Trigger - */ -BI.MonthPopup = BI.inherit(BI.Widget, { + }, - _defaultConfig: function () { - return BI.extend(BI.MonthPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-month-popup", - behaviors: {} - }); + _createLabelWrapper: function () { + var c = this._constant; + return { + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.labelOne, + top: 0, + left: "0%" + }] + }, { + type: "bi.absolute", + items: [{ + el: this.labelTwo, + top: 0, + left: "100%" + }] + }], + rgap: c.EDITOR_R_GAP, + height: 70 + }, + top: 0, + left: 0, + width: "100%" + }; }, - _init: function () { - BI.MonthPopup.superclass._init.apply(this, arguments); - var self = this, o = this.options; + _createSliderWrapper: function () { + var c = this._constant; + return { + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.sliderOne, + top: 0, + left: "0%" + }] + }, { + type: "bi.absolute", + items: [{ + el: this.sliderTwo, + top: 0, + left: "100%" + }] + }], + hgap: c.SLIDER_WIDTH_HALF, + height: c.SLIDER_HEIGHT + }, + top: 20, + left: 0, + width: "100%" + }; + }, - // 纵向排列月 - var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; - var items = []; - items.push(month.slice(0, 2)); - items.push(month.slice(2, 4)); - items.push(month.slice(4, 6)); - items.push(month.slice(6, 8)); - items.push(month.slice(8, 10)); - items.push(month.slice(10, 12)); - items = BI.map(items, function (i, item) { - return BI.map(item, function (j, td) { - return { - type: "bi.text_item", - cls: "bi-list-item-active", - textAlign: "center", - whiteSpace: "nowrap", - once: false, - forceSelected: true, - height: 23, - width: 38, - value: td, - text: td + 1 - }; - }); + _createTrackWrapper: function () { + return BI.createWidget({ + type: "bi.absolute", + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.grayTrack, + top: 0, + left: 0, + width: "100%" + }, { + el: this.blueTrack, + top: 0, + left: 0, + width: "0%" + }] + }], + hgap: 8, + height: 8 + }, + top: 8, + left: 0, + width: "100%" + }] }); + }, - this.month = BI.createWidget({ - type: "bi.button_group", - element: this, - behaviors: o.behaviors, - items: BI.createItems(items, {}), - layouts: [BI.LogicFactory.createLogic("table", BI.extend({ - dynamic: true - }, { - columns: 2, - rows: 6, - columnSize: [1 / 2, 1 / 2], - rowSize: 25 - })), { - type: "bi.center_adapt", - vgap: 1, - hgap: 2 - }], - value: o.value - }); + _checkValidation: function (v) { + var o = this.options; + var valid = false; + // 像90.这样的既不属于整数又不属于小数,是不合法的值 + var dotText = (v + "").split(".")[1]; + if (BI.isEmptyString(dotText)) { + }else{ + if (BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)) { + if(o.digit === false) { + valid = true; + }else{ + dotText = dotText || ""; + valid = (dotText.length === o.digit); + } + } + } + return valid; + }, - this.month.on(BI.Controller.EVENT_CHANGE, function (type) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if (type === BI.Events.CLICK) { - self.fireEvent(BI.MonthPopup.EVENT_CHANGE); + _checkOverlap: function () { + var labelOneLeft = this.labelOne.element[0].offsetLeft; + var labelTwoLeft = this.labelTwo.element[0].offsetLeft; + if (labelOneLeft <= labelTwoLeft) { + if ((labelTwoLeft - labelOneLeft) < 90) { + this.labelTwo.element.css({top: 40}); + } else { + this.labelTwo.element.css({top: 0}); } - }); + } else { + if ((labelOneLeft - labelTwoLeft) < 90) { + this.labelTwo.element.css({top: 40}); + } else { + this.labelTwo.element.css({top: 0}); + } + } + }, + + _setLabelOnePosition: function (percent) { + this.labelOne.element.css({left: percent + "%"}); + this._checkOverlap(); }, - getValue: function () { - return this.month.getValue()[0]; + _setLabelTwoPosition: function (percent) { + this.labelTwo.element.css({left: percent + "%"}); + this._checkOverlap(); }, - setValue: function (v) { - this.month.setValue([v]); - } -}); -BI.MonthPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.month_popup", BI.MonthPopup);/** - * 月份trigger - * - * Created by GUY on 2015/8/21. - * @class BI.MonthTrigger - * @extends BI.Trigger - */ -BI.MonthTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Month_Trigger_Error_Text") + _setSliderOnePosition: function (percent) { + this.sliderOne.element.css({left: percent + "%"}); }, - _defaultConfig: function () { - return BI.extend(BI.MonthTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-month-trigger bi-border", - height: 24 - }); + _setSliderTwoPosition: function (percent) { + this.sliderTwo.element.css({left: percent + "%"}); }, - _init: function () { - BI.MonthTrigger.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) { - return v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 12); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true, - errorText: c.errorText - }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.MonthTrigger.EVENT_FOCUS); - }); - this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.MonthTrigger.EVENT_CHANGE); - }); - this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - self.editor.setTitle(value); - } - self.fireEvent(BI.MonthTrigger.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.MonthTrigger.EVENT_START); - }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.MonthTrigger.EVENT_STOP); - }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [ - { - el: this.editor - }, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Month"), - baseCls: "bi-trigger-month-text", - width: o.height - }, - width: o.height - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - } - ] - }); - this.setValue(o.value); + + _setBlueTrackLeft: function (percent) { + this.blueTrack.element.css({left: percent + "%"}); }, - setValue: function (v) { - if(BI.isNotNull(v)) { - this.editor.setState(v + 1); - this.editor.setValue(v + 1); - this.editor.setTitle(v + 1); - return; + + _setBlueTrackWidth: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); + }, + + _setBlueTrack: function () { + var percentOne = this._getPercentByValue(this.labelOne.getValue()); + var percentTwo = this._getPercentByValue(this.labelTwo.getValue()); + if (percentOne <= percentTwo) { + this._setBlueTrackLeft(percentOne); + this._setBlueTrackWidth(percentTwo - percentOne); + } else { + this._setBlueTrackLeft(percentTwo); + this._setBlueTrackWidth(percentOne - percentTwo); } - this.editor.setState(""); - this.editor.setValue(""); - this.editor.setTitle(""); }, - getKey: function () { - return this.editor.getValue() | 0; + + _setAllPosition: function (one, two) { + this._setSliderOnePosition(one); + this._setLabelOnePosition(one); + this._setSliderTwoPosition(two); + this._setLabelTwoPosition(two); + this._setBlueTrack(); }, - getValue: function () { - return this.editor.getValue() - 1; - } -}); -BI.MonthTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.MonthTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.MonthTrigger.EVENT_START = "EVENT_START"; -BI.MonthTrigger.EVENT_STOP = "EVENT_STOP"; -BI.MonthTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.month_trigger", BI.MonthTrigger);/** - * 普通控件 - * - * @class BI.MultiDateCard - * @extends BI.Widget - * @abstract - */ -BI.MultiDateCard = BI.inherit(BI.Widget, { - constants: { - lgap: 80, - itemHeight: 35, - defaultEditorValue: "1" + _setVisible: function (visible) { + this.sliderOne.setVisible(visible); + this.sliderTwo.setVisible(visible); + this.labelOne.setVisible(visible); + this.labelTwo.setVisible(visible); }, - _defaultConfig: function () { - return $.extend(BI.MultiDateCard.superclass._defaultConfig.apply(this, arguments), {}); + _setErrorText: function () { + var errorText = BI.i18nText("BI-Please_Enter") + this.min + "-" + this.max + BI.i18nText("BI-Basic_De") + BI.i18nText("BI-Basic_Number"); + this.labelOne.setErrorText(errorText); + this.labelTwo.setErrorText(errorText); }, - dateConfig: function () { + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; + }, + + // 其中取max-min后保留4为有效数字后的值的小数位数为最终value的精度 + _getValueByPercent: function (percent) {// return (((max-min)*percent)/100+min) + var sub = this.calculation.accurateSubtraction(this.max, this.min); + var mul = this.calculation.accurateMultiplication(sub, percent); + var div = this.calculation.accurateDivisionTenExponent(mul, 2); + if(this.precision < 0) { + var value = BI.parseFloat(this.calculation.accurateAddition(div, this.min)); + var reduceValue = Math.round(this.calculation.accurateDivisionTenExponent(value, -this.precision)); + return this.calculation.accurateMultiplication(reduceValue, Math.pow(10, -this.precision)); + } + return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision)); }, - defaultSelectedItem: function () { + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); + }, + _setDraggableEnable: function (enable) { + this.sliderOne.setEnable(enable); + this.sliderTwo.setEnable(enable); }, - _init: function () { - BI.MultiDateCard.superclass._init.apply(this, arguments); - var self = this, opts = this.options; + _getPrecision: function () { + // 计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度) + // 如果差值的整数位数大于4,toPrecision(4)得到的是科学计数法123456 => 1.235e+5 + // 返回非负值: 保留的小数位数 + // 返回负值: 保留的10^n精度中的n + var sub = this.calculation.accurateSubtraction(this.max, this.min); + var pre = sub.toPrecision(4); + // 科学计数法 + var eIndex = pre.indexOf("e"); + var arr = []; + if(eIndex > -1) { + arr = pre.split("e"); + var decimalPartLength = BI.size(arr[0].split(".")[1]); + var sciencePartLength = BI.parseInt(arr[1].substring(1)); + return decimalPartLength - sciencePartLength; + } + arr = pre.split("."); + return arr.length > 1 ? arr[1].length : 0; - this.label = BI.createWidget({ - type: "bi.label", - height: this.constants.itemHeight, - textAlign: "left", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - cls: "bi-multidate-inner-label bi-tips" - }); - this.radioGroup = BI.createWidget({ - type: "bi.button_group", - chooseType: 0, - items: BI.createItems(this.dateConfig(), { - type: "bi.multidate_segment", - height: this.constants.itemHeight - }), - layouts: [{ - type: "bi.vertical" - }] - }); + }, - this.radioGroup.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CONFIRM) { - self.fireEvent(BI.MultiDateCard.EVENT_CHANGE); - } - }); - this.radioGroup.on(BI.ButtonGroup.EVENT_CHANGE, function () { - self.setValue(self.getValue()); - self.fireEvent(BI.MultiDateCard.EVENT_CHANGE); - }); - BI.createWidget({ - element: this, - type: "bi.center_adapt", - lgap: this.constants.lgap, - items: [{ - type: "bi.vertical", - items: [this.label, this.radioGroup] - }] - }); + _assertValue: function (value) { + if(value <= this.min) { + return this.min; + } + if(value >= this.max) { + return this.max; + } + return value; }, getValue: function () { - var button = this.radioGroup.getSelectedButtons()[0]; - var type = button.getValue(), value = button.getInputValue(); - return { - type: type, - value: value - }; + if (this.valueOne <= this.valueTwo) { + return {min: this.valueOne, max: this.valueTwo}; + } + return {min: this.valueTwo, max: this.valueOne}; + + }, + + setMinAndMax: function (v) { + var minNumber = BI.parseFloat(v.min); + var maxNumber = BI.parseFloat(v.max); + if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber >= minNumber )) { + this.min = minNumber; + this.max = maxNumber; + this.valueOne = minNumber; + this.valueTwo = maxNumber; + this.precision = this._getPrecision(); + this._setDraggableEnable(true); + } + if (maxNumber === minNumber) { + this._setDraggableEnable(false); + } }, - _isTypeAvaliable: function (type) { - var res = false; - BI.find(this.dateConfig(), function (i, item) { - if (item.value === type) { - res = true; - return true; + setValue: function (v) { + var o = this.options; + var valueOne = BI.parseFloat(v.min); + var valueTwo = BI.parseFloat(v.max); + valueOne = o.digit === false ? valueOne : valueOne.toFixed(o.digit); + valueTwo = o.digit === false ? valueTwo : valueTwo.toFixed(o.digit); + if (!isNaN(valueOne) && !isNaN(valueTwo)) { + if (this._checkValidation(valueOne)) { + this.valueOne = valueOne; } - }); - return res; + if (this._checkValidation(valueTwo)) { + this.valueTwo = valueTwo; + } + if (valueOne < this.min) { + this.valueOne = this.min; + } + if (valueTwo > this.max) { + this.valueTwo = this.max; + } + } }, - setValue: function (v) { - var self = this; - if (BI.isNotNull(v) && this._isTypeAvaliable(v.type)) { - this.radioGroup.setValue(v.type); - BI.each(this.radioGroup.getAllButtons(), function (i, button) { - if (button.isEditorExist() === true && button.isSelected()) { - button.setInputValue(v.value); - } else { - button.setInputValue(self.constants.defaultEditorValue); - } - }); - } else { - this.radioGroup.setValue(this.defaultSelectedItem()); - BI.each(this.radioGroup.getAllButtons(), function (i, button) { - button.setInputValue(self.constants.defaultEditorValue); - }); - } + reset: function () { + this._setVisible(false); + this.enable = false; + this.valueOne = ""; + this.valueTwo = ""; + this.min = NaN; + this.max = NaN; + this._setBlueTrackWidth(0); }, - getCalculationValue: function () { - var valueObject = this.getValue(); - var type = valueObject.type, value = valueObject.value; - switch (type) { - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - return BI.getDate().getOffsetDate(-1 * value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - return BI.getDate().getOffsetDate(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - return BI.getDate(); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - return BI.getDate().getBeforeMultiMonth(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - return BI.getDate().getAfterMultiMonth(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), 1); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), (BI.getDate().getLastDateOfMonth()).getDate()); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - return BI.getDate().getBeforeMulQuarter(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - return BI.getDate().getAfterMulQuarter(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - return BI.getDate().getQuarterStartDate(); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - return BI.getDate().getQuarterEndDate(); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - return BI.getDate().getOffsetDate(-7 * value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - return BI.getDate().getOffsetDate(7 * value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - return BI.getDate((BI.getDate().getFullYear() - 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - return BI.getDate((BI.getDate().getFullYear() + 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - return BI.getDate(BI.getDate().getFullYear(), 0, 1); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - return BI.getDate(BI.getDate().getFullYear(), 11, 31); + populate: function () { + if (!isNaN(this.min) && !isNaN(this.max)) { + this.enable = true; + this._setVisible(true); + this._setErrorText(); + if ((BI.isNumeric(this.valueOne) || BI.isNotEmptyString(this.valueOne)) && (BI.isNumeric(this.valueTwo) || BI.isNotEmptyString(this.valueTwo))) { + this.labelOne.setValue(this.valueOne); + this.labelTwo.setValue(this.valueTwo); + this._setAllPosition(this._getPercentByValue(this.valueOne), this._getPercentByValue(this.valueTwo)); + } else { + this.labelOne.setValue(this.min); + this.labelTwo.setValue(this.max); + this._setAllPosition(0, 100); + } } } }); -BI.MultiDateCard.EVENT_CHANGE = "EVENT_CHANGE"; -/** - * 日期控件 - * @class BI.MultiDateCombo - * @extends BI.Widget +BI.IntervalSlider.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.interval_slider", BI.IntervalSlider);/** + * Created by zcf on 2017/3/1. + * 万恶的IEEE-754 + * 使用字符串精确计算含小数加法、减法、乘法和10的指数倍除法,支持负数 */ -BI.MultiDateCombo = 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" - }, +BI.AccurateCalculationModel = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiDateCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-combo bi-border", - height: 24 + return BI.extend(BI.AccurateCalculationModel.superclass._defaultConfig.apply(this, arguments), { + baseCls: "" }); }, + _init: function () { - BI.MultiDateCombo.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - this.storeTriggerValue = ""; - var date = BI.getDate(); - this.storeValue = opts.value; - this.trigger = BI.createWidget({ - type: "bi.date_trigger", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value - }); - this.trigger.on(BI.DateTrigger.EVENT_KEY_DOWN, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } - }); - this.trigger.on(BI.DateTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - }); - this.trigger.on(BI.DateTrigger.EVENT_TRIGGER_CLICK, function () { - self.combo.toggle(); - }); - this.trigger.on(BI.DateTrigger.EVENT_FOCUS, function () { - self.storeTriggerValue = self.trigger.getKey(); - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - self.fireEvent(BI.MultiDateCombo.EVENT_FOCUS); - }); - this.trigger.on(BI.DateTrigger.EVENT_ERROR, function () { - self.storeValue = { - year: date.getFullYear(), - month: date.getMonth() - }; - self.popup.setValue(); - self.fireEvent(BI.MultiDateCombo.EVENT_ERROR); - }); - this.trigger.on(BI.DateTrigger.EVENT_VALID, function () { - self.fireEvent(BI.MultiDateCombo.EVENT_VALID); - }); - this.trigger.on(BI.DateTrigger.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDateCombo.EVENT_CHANGE); - }); - this.trigger.on(BI.DateTrigger.EVENT_CONFIRM, 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.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup = BI.createWidget({ - type: "bi.multidate_popup", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value - }); - this.popup.on(BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE, function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup.on(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE, function () { - var date = BI.getDate(); - self.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - self.combo.hideView(); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup.on(BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup.on(BI.MultiDatePopup.CALENDAR_EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - // self.fireEvent(BI.MultiDateCombo.EVENT_CHANGE); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - adjustLength: this.constants.comboAdjustHeight, - popup: { - el: this.popup, - width: this.constants.popupWidth, - stopPropagation: false - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW); - }); + BI.AccurateCalculationModel.superclass._init.apply(this, arguments); + }, - var triggerBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "bi-trigger-icon-button date-font", - width: 24, - height: 24 - }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); + _getMagnitude: function (n) { + var magnitude = "1"; + for (var i = 0; i < n; i++) { + magnitude += "0"; + } + return BI.parseInt(magnitude); + }, + + _formatDecimal: function (stringNumber1, stringNumber2) { + if (stringNumber1.numDecimalLength === stringNumber2.numDecimalLength) { + return; + } + var magnitudeDiff = stringNumber1.numDecimalLength - stringNumber2.numDecimalLength; + if (magnitudeDiff > 0) { + var needAddZero = stringNumber2; + } else { + var needAddZero = stringNumber1; + magnitudeDiff = (0 - magnitudeDiff); + } + for (var i = 0; i < magnitudeDiff; i++) { + if (needAddZero.numDecimal === "0" && i === 0) { + continue; } - }); - this.changeIcon = BI.createWidget({ - type: "bi.icon_button", - cls: "bi-trigger-icon-button date-change-h-font", - width: 24, - height: 24 - }); + needAddZero.numDecimal += "0"; + } + }, + + _stringNumberFactory: function (num) { + var strNum = num.toString(); + var numStrArray = strNum.split("."); + var numInteger = numStrArray[0]; + if (numStrArray.length === 1) { + var numDecimal = "0"; + var numDecimalLength = 0; + } else { + var numDecimal = numStrArray[1]; + var numDecimalLength = numStrArray[1].length; + } + return { + numInteger: numInteger, + numDecimal: numDecimal, + numDecimalLength: numDecimalLength + }; + }, + _accurateSubtraction: function (num1, num2) {// num1-num2 && num1>num2 + var stringNumber1 = this._stringNumberFactory(num1); + var stringNumber2 = this._stringNumberFactory(num2); + // 整数部分计算 + var integerResult = BI.parseInt(stringNumber1.numInteger) - BI.parseInt(stringNumber2.numInteger); + // 小数部分 + this._formatDecimal(stringNumber1, stringNumber2); + var decimalMaxLength = getDecimalMaxLength(stringNumber1, stringNumber2); - var leftPart = BI.createWidget({ - type: "bi.absolute", - items: [{ - el: this.combo, - top: 0, - left: 0, - right: 0, - bottom: 0 - }, { - el: triggerBtn, - top: 0, - left: 0 - }] - }); + if (BI.parseInt(stringNumber1.numDecimal) >= BI.parseInt(stringNumber2.numDecimal)) { + var decimalResultTemp = (BI.parseInt(stringNumber1.numDecimal) - BI.parseInt(stringNumber2.numDecimal)).toString(); + var decimalResult = addZero(decimalResultTemp, decimalMaxLength); + } else {// 否则借位 + integerResult--; + var borrow = this._getMagnitude(decimalMaxLength); + var decimalResultTemp = (borrow + BI.parseInt(stringNumber1.numDecimal) - BI.parseInt(stringNumber2.numDecimal)).toString(); + var decimalResult = addZero(decimalResultTemp, decimalMaxLength); + } + var result = integerResult + "." + decimalResult; + return BI.parseFloat(result); - BI.createWidget({ - type: "bi.htape", - element: this, - items: [leftPart, { - el: this.changeIcon, - width: 30 - }], - ref: function (_ref) { - self.comboWrapper = _ref; + function getDecimalMaxLength (num1, num2) { + if (num1.numDecimal.length >= num2.numDecimal.length) { + return num1.numDecimal.length; } - }); + return num2.numDecimal.length; + } - this._checkDynamicValue(opts.value); + function addZero (resultTemp, length) { + var diff = length - resultTemp.length; + for (var i = 0; i < diff; i++) { + resultTemp = "0" + resultTemp; + } + return resultTemp; + } }, - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[1].width = 30; - this.comboWrapper.resize(); - break; - default: - this.comboWrapper.attr("items")[1].width = 0; - this.comboWrapper.resize(); - this.changeIcon.setVisible(false); - break; + _accurateAddition: function (num1, num2) {// 加法结合律 + var stringNumber1 = this._stringNumberFactory(num1); + var stringNumber2 = this._stringNumberFactory(num2); + // 整数部分计算 + var integerResult = BI.parseInt(stringNumber1.numInteger) + BI.parseInt(stringNumber2.numInteger); + // 小数部分 + this._formatDecimal(stringNumber1, stringNumber2); + + var decimalResult = (BI.parseInt(stringNumber1.numDecimal) + BI.parseInt(stringNumber2.numDecimal)).toString(); + + if (decimalResult !== "0") { + if (decimalResult.length <= stringNumber1.numDecimal.length) { + decimalResult = addZero(decimalResult, stringNumber1.numDecimal.length); + } else { + integerResult++;// 进一 + decimalResult = decimalResult.slice(1); + } } - }, + var result = integerResult + "." + decimalResult; + return BI.parseFloat(result); - setValue: function (v) { - this.storeValue = v; - this.popup.setValue(v); - this.trigger.setValue(v); - this._checkDynamicValue(v); - }, - getValue: function () { - return this.storeValue; - }, - getKey: function () { - return this.trigger.getKey(); + function addZero (resultTemp, length) { + var diff = length - resultTemp.length; + for (var i = 0; i < diff; i++) { + resultTemp = "0" + resultTemp; + } + return resultTemp; + } }, - hidePopupView: function () { - this.combo.hideView(); - } -}); -BI.shortcut("bi.multidate_combo", BI.MultiDateCombo); - -BI.MultiDateCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.MultiDateCombo.EVENT_FOCUS = "EVENT_FOCUS"; -BI.MultiDateCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiDateCombo.EVENT_VALID = "EVENT_VALID"; -BI.MultiDateCombo.EVENT_ERROR = "EVENT_ERROR"; -BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW = "BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW"; - -BI.extend(BI.MultiDateCombo, { - MULTI_DATE_YMD_CARD: 1, - MULTI_DATE_YEAR_CARD: 2, - MULTI_DATE_QUARTER_CARD: 3, - MULTI_DATE_MONTH_CARD: 4, - MULTI_DATE_WEEK_CARD: 5, - MULTI_DATE_DAY_CARD: 6 -}); -BI.extend(BI.MultiDateCombo, { - DATE_TYPE: { - MULTI_DATE_YEAR_PREV: 1, - MULTI_DATE_YEAR_AFTER: 2, - MULTI_DATE_YEAR_BEGIN: 3, - MULTI_DATE_YEAR_END: 4, - MULTI_DATE_MONTH_PREV: 5, - MULTI_DATE_MONTH_AFTER: 6, - MULTI_DATE_MONTH_BEGIN: 7, - MULTI_DATE_MONTH_END: 8, - MULTI_DATE_QUARTER_PREV: 9, - MULTI_DATE_QUARTER_AFTER: 10, - MULTI_DATE_QUARTER_BEGIN: 11, - MULTI_DATE_QUARTER_END: 12, - MULTI_DATE_WEEK_PREV: 13, - MULTI_DATE_WEEK_AFTER: 14, - MULTI_DATE_DAY_PREV: 15, - MULTI_DATE_DAY_AFTER: 16, - MULTI_DATE_DAY_TODAY: 17, - MULTI_DATE_PARAM: 18, - MULTI_DATE_CALENDAR: 19, - YEAR_QUARTER: 20, - YEAR_MONTH: 21, - YEAR_WEEK: 22, - YEAR_DAY: 23, - MONTH_WEEK: 24, - MONTH_DAY: 25, - YEAR: 26, - SAME_PERIOD: 27, - LAST_SAME_PERIOD: 28 - } -}); -/** - * 普通控件 - * - * @class BI.DayCard - * @extends BI.MultiDateCard - */ -BI.DayCard = BI.inherit(BI.MultiDateCard, { + _accurateMultiplication: function (num1, num2) {// 乘法分配律 + var stringNumber1 = this._stringNumberFactory(num1); + var stringNumber2 = this._stringNumberFactory(num2); + // 整数部分计算 + var integerResult = BI.parseInt(stringNumber1.numInteger) * BI.parseInt(stringNumber2.numInteger); + // num1的小数和num2的整数 + var dec1Int2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numDecimal) * BI.parseInt(stringNumber2.numInteger), stringNumber1.numDecimalLength); + // num1的整数和num2的小数 + var int1dec2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numInteger) * BI.parseInt(stringNumber2.numDecimal), stringNumber2.numDecimalLength); + // 小数*小数 + var dec1dec2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numDecimal) * BI.parseInt(stringNumber2.numDecimal), (stringNumber1.numDecimalLength + stringNumber2.numDecimalLength)); - _defaultConfig: function () { - return $.extend(BI.DayCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-daycard" - }); + return this._accurateAddition(this._accurateAddition(this._accurateAddition(integerResult, dec1Int2), int1dec2), dec1dec2); }, - _init: function () { - BI.DayCard.superclass._init.apply(this, arguments); - }, + _accurateDivisionTenExponent: function (num, n) {// num/10^n && n>0 + var stringNumber = this._stringNumberFactory(num); + if (stringNumber.numInteger.length > n) { + var integerResult = stringNumber.numInteger.slice(0, (stringNumber.numInteger.length - n)); + var partDecimalResult = stringNumber.numInteger.slice(-n); + } else { + var integerResult = "0"; + var partDecimalResult = addZero(stringNumber.numInteger, n); + } + var result = integerResult + "." + partDecimalResult + stringNumber.numDecimal; + return BI.parseFloat(result); - dateConfig: function () { - return [{ - isEditorExist: true, - selected: true, - text: BI.i18nText("BI-Multi_Date_Day_Prev"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV - }, - { - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Day_Next"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER - }, - { - isEditorExist: false, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY, - text: BI.i18nText("BI-Multi_Date_Today") - }]; + function addZero (resultTemp, length) { + var diff = length - resultTemp.length; + for (var i = 0; i < diff; i++) { + resultTemp = "0" + resultTemp; + } + return resultTemp; + } }, - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV; - } -}); -BI.DayCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.daycard", BI.DayCard); -/** - * 普通控件 - * - * @class BI.MonthCard - * @extends BI.MultiDateCard - */ -BI.MonthCard = BI.inherit(BI.MultiDateCard, { - _defaultConfig: function () { - return $.extend(BI.MonthCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-monthcard" - }); + accurateSubtraction: function (num1, num2) { + if (num1 >= 0 && num2 >= 0) { + if (num1 >= num2) { + return this._accurateSubtraction(num1, num2); + } + return -this._accurateSubtraction(num2, num1); + } + if (num1 >= 0 && num2 < 0) { + return this._accurateAddition(num1, -num2); + } + if (num1 < 0 && num2 >= 0) { + return -this._accurateAddition(-num1, num2); + } + if (num1 < 0 && num2 < 0) { + if (num1 >= num2) { + return this._accurateSubtraction(-num2, -num1); + } + return this._accurateSubtraction(-num1, -num2); + } }, - _init: function () { - BI.MonthCard.superclass._init.apply(this, arguments); + accurateAddition: function (num1, num2) { + if (num1 >= 0 && num2 >= 0) { + return this._accurateAddition(num1, num2); + } + if (num1 >= 0 && num2 < 0) { + return this.accurateSubtraction(num1, -num2); + } + if (num1 < 0 && num2 >= 0) { + return this.accurateSubtraction(num2, -num1); + } + if (num1 < 0 && num2 < 0) { + return -this._accurateAddition(-num1, -num2); + } }, - dateConfig: function () { - return [{ - selected: true, - isEditorExist: true, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV, - text: BI.i18nText("BI-Multi_Date_Month_Prev") - }, - { - isEditorExist: true, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER, - text: BI.i18nText("BI-Multi_Date_Month_Next") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Month_Begin") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Month_End") - }]; + accurateMultiplication: function (num1, num2) { + if (num1 >= 0 && num2 >= 0) { + return this._accurateMultiplication(num1, num2); + } + if (num1 >= 0 && num2 < 0) { + return -this._accurateMultiplication(num1, -num2); + } + if (num1 < 0 && num2 >= 0) { + return -this._accurateMultiplication(-num1, num2); + } + if (num1 < 0 && num2 < 0) { + return this._accurateMultiplication(-num1, -num2); + } }, - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV; + accurateDivisionTenExponent: function (num1, n) { + if (num1 >= 0) { + return this._accurateDivisionTenExponent(num1, n); + } + return -this._accurateDivisionTenExponent(-num1, n); } -}); -BI.MonthCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.monthcard", BI.MonthCard); -/** - * 日期控件 - * @class BI.MultiDatePopup - * @extends BI.Widget +});/** + * 月份下拉框 + * + * Created by GUY on 2015/8/28. + * @class BI.MonthCombo + * @extends BI.Trigger */ -BI.MultiDatePopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30, - tabWidth: 42, - titleHeight: 27, - itemHeight: 30, - triggerHeight: 24, - buttonWidth: 90, - buttonHeight: 25, - cardHeight: 229, - cardWidth: 270, - popupHeight: 259, - popupWidth: 270, - comboAdjustHeight: 1, - ymdWidth: 58, - lgap: 2, - border: 1 - }, +BI.MonthCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiDatePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-popup", - height: 344 + return BI.extend(BI.MonthCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-month-combo", + behaviors: {}, + height: 25 }); }, _init: function () { - BI.MultiDatePopup.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - this.storeValue = ""; - this.textButton = BI.createWidget({ - type: "bi.text_button", - forceCenter: true, - cls: "bi-multidate-popup-label bi-border-left bi-border-right bi-border-top", - shadow: true, - text: BI.i18nText("BI-Multi_Date_Today") - }); - this.textButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE); - }); - this.clearButton = BI.createWidget({ - type: "bi.text_button", - forceCenter: true, - cls: "bi-multidate-popup-button bi-border-top", - shadow: true, - text: BI.i18nText("BI-Basic_Clear") - }); - this.clearButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE); - }); - this.okButton = BI.createWidget({ - type: "bi.text_button", - forceCenter: true, - cls: "bi-multidate-popup-button bi-border-top", - shadow: true, - text: BI.i18nText("BI-Basic_OK") - }); - this.okButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE); + BI.MonthCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.trigger = BI.createWidget({ + type: "bi.month_trigger", + value: o.value }); - this.dateTab = BI.createWidget({ - type: "bi.tab", - tab: { - cls: "bi-border-bottom", - height: this.constants.tabHeight, - items: BI.createItems([{ - text: BI.i18nText("BI-Multi_Date_YMD"), - value: BI.MultiDateCombo.MULTI_DATE_YMD_CARD, - width: this.constants.ymdWidth - }, { - text: BI.i18nText("BI-Multi_Date_Year"), - value: BI.MultiDateCombo.MULTI_DATE_YEAR_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Quarter"), - value: BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Month"), - value: BI.MultiDateCombo.MULTI_DATE_MONTH_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Week"), - value: BI.MultiDateCombo.MULTI_DATE_WEEK_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Day"), - value: BI.MultiDateCombo.MULTI_DATE_DAY_CARD - }], { - width: this.constants.tabWidth, - textAlign: "center", - height: this.constants.itemHeight, - cls: "bi-multidate-popup-item bi-list-item-active" - }), - layouts: [{ - type: "bi.left" - }] - }, - cardCreator: function (v) { - switch (v) { - case BI.MultiDateCombo.MULTI_DATE_YMD_CARD: - self.ymd = BI.createWidget({ - type: "bi.date_calendar_popup", - min: self.options.min, - max: self.options.max - }); - self.ymd.on(BI.DateCalendarPopup.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.CALENDAR_EVENT_CHANGE); - }); - return self.ymd; - case BI.MultiDateCombo.MULTI_DATE_YEAR_CARD: - self.year = BI.createWidget({ - type: "bi.yearcard" - }); - self.year.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.year, v); - }); - return self.year; - case BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD: - self.quarter = BI.createWidget({ - type: "bi.quartercard" - }); - self.quarter.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.quarter, v); - }); - return self.quarter; - case BI.MultiDateCombo.MULTI_DATE_MONTH_CARD: - self.month = BI.createWidget({ - type: "bi.monthcard" - }); - self.month.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.month, v); - }); - return self.month; - case BI.MultiDateCombo.MULTI_DATE_WEEK_CARD: - self.week = BI.createWidget({ - type: "bi.weekcard" - }); - self.week.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.week, v); - }); - return self.week; - case BI.MultiDateCombo.MULTI_DATE_DAY_CARD: - self.day = BI.createWidget({ - type: "bi.daycard" - }); - self.day.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.day, v); - }); - return self.day; - } + + this.trigger.on(BI.MonthTrigger.EVENT_CONFIRM, function (v) { + if (self.combo.isViewVisible()) { + return; } + if (this.getKey() && this.getKey() !== self.storeValue) { + self.setValue(this.getValue()); + } else if (!this.getKey()) { + self.setValue(); + } + self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); }); - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_YMD_CARD; - this.dateTab.on(BI.Tab.EVENT_CHANGE, function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.MultiDateCombo.MULTI_DATE_YMD_CARD: - var date = this.getTab(self.cur).getCalculationValue(); - self.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - self._setInnerValue(self.ymd); - break; - case BI.MultiDateCombo.MULTI_DATE_YEAR_CARD: - self.year.setValue(self.storeValue); - self._setInnerValue(self.year); - break; - case BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD: - self.quarter.setValue(self.storeValue); - self._setInnerValue(self.quarter); - break; - case BI.MultiDateCombo.MULTI_DATE_MONTH_CARD: - self.month.setValue(self.storeValue); - self._setInnerValue(self.month); - break; - case BI.MultiDateCombo.MULTI_DATE_WEEK_CARD: - self.week.setValue(self.storeValue); - self._setInnerValue(self.week); - break; - case BI.MultiDateCombo.MULTI_DATE_DAY_CARD: - self.day.setValue(self.storeValue); - self._setInnerValue(self.day); - break; + this.trigger.on(BI.MonthTrigger.EVENT_FOCUS, function () { + self.storeValue = this.getKey(); + }); + this.trigger.on(BI.MonthTrigger.EVENT_START, function () { + self.combo.hideView(); + }); + this.trigger.on(BI.MonthTrigger.EVENT_STOP, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); } - self.cur = v; }); - this.dateButton = BI.createWidget({ - type: "bi.grid", - items: [[this.clearButton, this.textButton, this.okButton]] + + this.popup = BI.createWidget({ + type: "bi.month_popup", + behaviors: o.behaviors, + value: o.value }); - BI.createWidget({ - element: this, - type: "bi.vtape", - items: [{ - el: this.dateTab - }, { - el: this.dateButton, - height: 30 - }] + this.popup.on(BI.MonthPopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); }); - this.setValue(opts.value); - }, - _setInnerValue: function (obj) { - if (this.dateTab.getSelect() === BI.MultiDateCombo.MULTI_DATE_YMD_CARD) { - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - this.textButton.setEnable(true); - } else { - var date = obj.getCalculationValue(); - 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); + this.combo = BI.createWidget({ + type: "bi.combo", + element: this, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + el: this.popup + } + }); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW); + }); }, setValue: function (v) { - this.storeValue = v; - var self = this, date; - var type, value; - if (BI.isNotNull(v)) { - type = v.type || BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_CALENDAR; - value = v.value; - if (BI.isNull(value)) { - value = v; - } - } - switch (type) { - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YEAR_CARD); - this.year.setValue({type: type, value: value}); - this.cur = BI.MultiDateCombo.MULTI_DATE_YEAR_CARD; - self._setInnerValue(this.year); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD; - this.quarter.setValue({type: type, value: value}); - self._setInnerValue(this.quarter); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_MONTH_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_MONTH_CARD; - this.month.setValue({type: type, value: value}); - self._setInnerValue(this.month); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_WEEK_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_WEEK_CARD; - this.week.setValue({type: type, value: value}); - self._setInnerValue(this.week); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_DAY_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_DAY_CARD; - this.day.setValue({type: type, value: value}); - self._setInnerValue(this.day); - break; - default: - if (this._checkValueValid(value)) { - var date = BI.getDate(); - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); - this.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } else { - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); - this.ymd.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } - this.textButton.setEnable(true); - break; - } + this.trigger.setValue(v); + this.popup.setValue(v); }, + getValue: function () { - var tab = this.dateTab.getSelect(); - switch (tab) { - case BI.MultiDateCombo.MULTI_DATE_YMD_CARD: - return this.ymd.getValue(); - case BI.MultiDateCombo.MULTI_DATE_YEAR_CARD: - return this.year.getValue(); - case BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD: - return this.quarter.getValue(); - case BI.MultiDateCombo.MULTI_DATE_MONTH_CARD: - return this.month.getValue(); - case BI.MultiDateCombo.MULTI_DATE_WEEK_CARD: - return this.week.getValue(); - case BI.MultiDateCombo.MULTI_DATE_DAY_CARD: - return this.day.getValue(); + if (BI.isNull(this.popup)) { + return this.options.value || ""; + } else { + return this.popup.getValue() || ""; } } }); -BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.MultiDatePopup.CALENDAR_EVENT_CHANGE = "CALENDAR_EVENT_CHANGE"; -BI.shortcut("bi.multidate_popup", BI.MultiDatePopup); -/** - * 普通控件 + +BI.MonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.MonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.month_combo", BI.MonthCombo);/** + * 月份展示面板 * - * @class BI.QuarterCard - * @extends BI.MultiDateCard + * Created by GUY on 2015/9/2. + * @class BI.MonthPopup + * @extends BI.Trigger */ -BI.QuarterCard = BI.inherit(BI.MultiDateCard, { +BI.MonthPopup = BI.inherit(BI.Widget, { _defaultConfig: function () { - return $.extend(BI.QuarterCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-quartercard" + return BI.extend(BI.MonthPopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-month-popup", + behaviors: {} }); }, _init: function () { - BI.QuarterCard.superclass._init.apply(this, arguments); + BI.MonthPopup.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + // 纵向排列月 + var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; + var items = []; + items.push(month.slice(0, 2)); + items.push(month.slice(2, 4)); + items.push(month.slice(4, 6)); + items.push(month.slice(6, 8)); + items.push(month.slice(8, 10)); + items.push(month.slice(10, 12)); + items = BI.map(items, function (i, item) { + return BI.map(item, function (j, td) { + return { + type: "bi.text_item", + cls: "bi-list-item-active", + textAlign: "center", + whiteSpace: "nowrap", + once: false, + forceSelected: true, + height: 23, + width: 38, + value: td, + text: td + 1 + }; + }); + }); + + this.month = BI.createWidget({ + type: "bi.button_group", + element: this, + behaviors: o.behaviors, + items: BI.createItems(items, {}), + layouts: [BI.LogicFactory.createLogic("table", BI.extend({ + dynamic: true + }, { + columns: 2, + rows: 6, + columnSize: [1 / 2, 1 / 2], + rowSize: 25 + })), { + type: "bi.center_adapt", + vgap: 1, + hgap: 2 + }], + value: o.value + }); + + this.month.on(BI.Controller.EVENT_CHANGE, function (type) { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + if (type === BI.Events.CLICK) { + self.fireEvent(BI.MonthPopup.EVENT_CHANGE); + } + }); }, - dateConfig: function () { - return [{ - selected: true, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Quarter_Prev") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Quarter_Next") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Quarter_Begin") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Quarter_End") - }]; + getValue: function () { + return this.month.getValue()[0]; }, - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV; + setValue: function (v) { + this.month.setValue([v]); } }); -BI.QuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.quartercard", BI.QuarterCard); -/** - * 普通控件 +BI.MonthPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.month_popup", BI.MonthPopup);/** + * 月份trigger * - * @class BI.MultiDateSegment - * @extends BI.Single + * Created by GUY on 2015/8/21. + * @class BI.MonthTrigger + * @extends BI.Trigger */ -BI.MultiDateSegment = BI.inherit(BI.Single, { - constants: { - itemHeight: 24, - maxGap: 15, - minGap: 10, - textWidth: 60, - defaultEditorValue: "1" +BI.MonthTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + errorText: BI.i18nText("BI-Month_Trigger_Error_Text") }, _defaultConfig: function () { - return $.extend(BI.MultiDateSegment.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-segment", - text: "", - height: 30, - isEditorExist: true, - selected: false, - defaultEditorValue: "1" + return BI.extend(BI.MonthTrigger.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-month-trigger bi-border", + height: 24 }); }, - _init: function () { - BI.MultiDateSegment.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - this.radio = BI.createWidget({ - type: "bi.radio", - selected: opts.selected + BI.MonthTrigger.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) { + return v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 12); + }, + quitChecker: function (v) { + return false; + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true, + errorText: c.errorText }); - this.radio.on(BI.Controller.EVENT_CHANGE, function (v) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.MonthTrigger.EVENT_FOCUS); }); - this.textEditor = BI.createWidget({ - type: "bi.text_editor", - value: this.constants.defaultEditorValue, - title: function () { - return self.textEditor.getValue(); - }, - tipType: "success", - cls: "bi-multidate-editor", - width: this.constants.textWidth, - height: this.constants.itemHeight + this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.MonthTrigger.EVENT_CHANGE); }); - this.textEditor.on(BI.Controller.EVENT_CHANGE, function (v) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setValue(value); + self.editor.setTitle(value); + } + self.fireEvent(BI.MonthTrigger.EVENT_CONFIRM); }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - cls: "bi-multidate-normal-label", - text: opts.text, - height: this.constants.itemHeight + this.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); + } }); - this._createSegment(); - }, - _createSegment: function () { - if (this.options.isEditorExist === true) { - return BI.createWidget({ - element: this, - type: "bi.left", - items: [{ + this.editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.MonthTrigger.EVENT_START); + }); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.MonthTrigger.EVENT_STOP); + }); + BI.createWidget({ + element: this, + type: "bi.htape", + items: [ + { + el: this.editor + }, { el: { - type: "bi.center_adapt", - items: [this.radio], - height: this.constants.itemHeight + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Month"), + baseCls: "bi-trigger-month-text", + width: o.height }, - lgap: 0 - }, - { + width: o.height + }, { el: { - type: "bi.center_adapt", - items: [this.textEditor], - widgetName: "textEditor" + type: "bi.trigger_icon_button", + width: o.height }, - lgap: this.constants.maxGap - }, - { - el: this.text, - lgap: this.constants.minGap - }] - }); - } - return BI.createWidget({ - element: this, - type: "bi.left", - items: [{ - el: { - type: "bi.center_adapt", - items: [this.radio], - height: this.constants.itemHeight - }, - lgap: 0 - }, - { - el: this.text, - lgap: this.constants.maxGap - }] + width: o.height + } + ] }); + this.setValue(o.value); }, - setSelected: function (v) { - if (BI.isNotNull(this.radio)) { - this.radio.setSelected(v); - this.textEditor.setEnable(v); + setValue: function (v) { + if(BI.isNotNull(v)) { + this.editor.setState(v + 1); + this.editor.setValue(v + 1); + this.editor.setTitle(v + 1); + return; } + this.editor.setState(""); + this.editor.setValue(""); + this.editor.setTitle(""); }, - isSelected: function () { - return this.radio.isSelected(); + getKey: function () { + return this.editor.getValue() | 0; }, getValue: function () { - return this.options.value; - }, - getInputValue: function () { - return this.textEditor.getValue() | 0; - }, - setInputValue: function (v) { - this.textEditor.setValue(v); - }, - isEditorExist: function () { - return this.options.isEditorExist; - } -}); -BI.MultiDateSegment.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multidate_segment", BI.MultiDateSegment);/** - * 普通控件 - * - * @class BI.WeekCard - * @extends BI.MultiDateCard - */ -BI.WeekCard = BI.inherit(BI.MultiDateCard, { - _defaultConfig: function () { - return $.extend(BI.WeekCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-weekcard" - }); - }, - - _init: function () { - BI.WeekCard.superclass._init.apply(this, arguments); - }, - - dateConfig: function () { - return [{ - selected: true, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Week_Prev"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV - }, - { - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Week_Next"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER - }]; - }, - - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV; - } -}); -BI.WeekCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.weekcard", BI.WeekCard); -/** - * 普通控件 - * - * @class BI.YearCard - * @extends BI.MultiDateCard - */ -BI.YearCard = BI.inherit(BI.MultiDateCard, { - _defaultConfig: function () { - return $.extend(BI.YearCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-yearcard" - }); - }, - - _init: function () { - BI.YearCard.superclass._init.apply(this, arguments); - }, - - dateConfig: function () { - return [{ - selected: true, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Year_Prev"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV - }, - { - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Year_Next"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER - }, - { - isEditorExist: false, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN, - text: BI.i18nText("BI-Multi_Date_Year_Begin") - }, - { - isEditorExist: false, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END, - text: BI.i18nText("BI-Multi_Date_Year_End") - }]; - }, - - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV; + return this.editor.getValue() - 1; } }); -BI.YearCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.yearcard", BI.YearCard); -/** +BI.MonthTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.MonthTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.MonthTrigger.EVENT_START = "EVENT_START"; +BI.MonthTrigger.EVENT_STOP = "EVENT_STOP"; +BI.MonthTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.month_trigger", BI.MonthTrigger);/** * Created by roy on 15/8/14. */ BI.DownListCombo = BI.inherit(BI.Widget, { @@ -102030,1567 +98705,2186 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { }); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + _defaultState: function () { + this.trigger.stopEditing(); + this.combo.hideView(); + }, + + setValue: function (v) { + this.storeValue.value = v || {}; + this.combo.setValue({ + value: v || {} + }); + }, + + getValue: function () { + return this.storeValue.value; + }, + + populate: function () { + this.combo.populate.apply(this.combo, arguments); + } +}); + +BI.MultiTreeCombo.EVENT_CONFIRM = "MultiTreeCombo.EVENT_CONFIRM"; + +BI.shortcut("bi.multi_tree_combo", BI.MultiTreeCombo);/** + * 带加载的多选下拉面板 + * @class BI.MultiTreePopup + * @extends BI.Pane + */ +BI.MultiTreePopup = BI.inherit(BI.Pane, { + + _defaultConfig: function () { + return BI.extend(BI.MultiTreePopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-popup", + maxWidth: "auto", + minWidth: 100, + maxHeight: 400, + onLoaded: BI.emptyFn + }); + }, + + _init: function () { + BI.MultiTreePopup.superclass._init.apply(this, arguments); + + var self = this, opts = this.options; + + this.selectedValues = {}; + + this.tree = BI.createWidget({ + type: "bi.async_tree", + height: 400, + cls: "popup-view-tree", + itemsCreator: opts.itemsCreator, + onLoaded: opts.onLoaded, + value: opts.value || {} + }); + + this.popupView = BI.createWidget({ + type: "bi.multi_popup_view", + element: this, + stopPropagation: false, + maxWidth: opts.maxWidth, + minWidth: opts.minWidth, + maxHeight: opts.maxHeight, + buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], + el: this.tree + }); + + this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { + switch (index) { + case 0: + self.fireEvent(BI.MultiTreePopup.EVENT_CLICK_CLEAR); + break; + case 1: + self.fireEvent(BI.MultiTreePopup.EVENT_CLICK_CONFIRM); + break; + } + }); + + this.tree.on(BI.TreeView.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiTreePopup.EVENT_CHANGE); + }); + + this.tree.on(BI.TreeView.EVENT_AFTERINIT, function () { + self.fireEvent(BI.MultiTreePopup.EVENT_AFTERINIT); + }); + + }, + + getValue: function () { + return this.tree.getValue(); + }, + + setValue: function (v) { + v || (v = {}); + this.tree.setSelectedValue(v.value); + }, + + populate: function (config) { + this.tree.stroke(config); + }, + + hasChecked: function () { + return this.tree.hasChecked(); + }, + + resetHeight: function (h) { + this.popupView.resetHeight(h); + }, + + resetWidth: function (w) { + this.popupView.resetWidth(w); + } +}); + +BI.MultiTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.MultiTreePopup.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; +BI.MultiTreePopup.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; +BI.MultiTreePopup.EVENT_AFTERINIT = "EVENT_AFTERINIT"; + + +BI.shortcut("bi.multi_tree_popup_view", BI.MultiTreePopup);/** + * + * 在搜索框中输入文本弹出的面板 + * @class BI.MultiTreeSearchPane + * @extends BI.Pane + */ + +BI.MultiTreeSearchPane = BI.inherit(BI.Pane, { + + _defaultConfig: function () { + return BI.extend(BI.MultiTreeSearchPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-search-pane bi-card", + itemsCreator: BI.emptyFn, + keywordGetter: BI.emptyFn + }); + }, + + _init: function () { + BI.MultiTreeSearchPane.superclass._init.apply(this, arguments); + + var self = this, opts = this.options; + + this.partTree = BI.createWidget({ + type: "bi.part_tree", + element: this, + tipText: BI.i18nText("BI-No_Select"), + itemsCreator: function (op, callback) { + op.keyword = opts.keywordGetter(); + opts.itemsCreator(op, callback); + }, + value: opts.value + }); + + this.partTree.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + this.partTree.on(BI.TreeView.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiTreeSearchPane.EVENT_CHANGE); + }); + }, + + hasChecked: function () { + return this.partTree.hasChecked(); }, setValue: function (v) { - this.storeValue.value = v || {}; - this.combo.setValue({ - value: v || {} - }); + this.setSelectedValue(v.value); + }, + + setSelectedValue: function (v) { + v || (v = {}); + this.partTree.setSelectedValue(v); }, getValue: function () { - return this.storeValue.value; + return this.partTree.getValue(); }, - populate: function () { - this.combo.populate.apply(this.combo, arguments); + empty: function () { + this.partTree.empty(); + }, + + populate: function (op) { + this.partTree.stroke.apply(this.partTree, arguments); } }); -BI.MultiTreeCombo.EVENT_CONFIRM = "MultiTreeCombo.EVENT_CONFIRM"; +BI.MultiTreeSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multi_tree_combo", BI.MultiTreeCombo);/** - * 带加载的多选下拉面板 - * @class BI.MultiTreePopup - * @extends BI.Pane +BI.MultiTreeSearchPane.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; +BI.MultiTreeSearchPane.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; + +BI.shortcut("bi.multi_tree_search_pane", BI.MultiTreeSearchPane);/** + * 查看已选按钮 + * Created by guy on 15/11/3. + * @class BI.MultiTreeCheckSelectedButton + * @extends BI.Single */ -BI.MultiTreePopup = BI.inherit(BI.Pane, { +BI.MultiTreeCheckSelectedButton = BI.inherit(BI.Single, { + + _const: { + checkSelected: BI.i18nText("BI-Check_Selected") + }, _defaultConfig: function () { - return BI.extend(BI.MultiTreePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-popup", - maxWidth: "auto", - minWidth: 100, - maxHeight: 400, - onLoaded: BI.emptyFn + return BI.extend(BI.MultiTreeCheckSelectedButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-check-selected-button", + itemsCreator: BI.emptyFn }); }, _init: function () { - BI.MultiTreePopup.superclass._init.apply(this, arguments); - - var self = this, opts = this.options; + BI.MultiTreeCheckSelectedButton.superclass._init.apply(this, arguments); + var self = this; + this.indicator = BI.createWidget({ + type: "bi.icon_button", + cls: "check-font trigger-check-selected", + width: 15, + height: 15, + stopPropagation: true + }); - this.selectedValues = {}; + this.checkSelected = BI.createWidget({ + type: "bi.text_button", + cls: "trigger-check-selected", + invisible: true, + hgap: 4, + text: this._const.checkSelected, + textAlign: "center", + textHeight: 15 + }); + this.checkSelected.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); - this.tree = BI.createWidget({ - type: "bi.async_tree", - height: 400, - cls: "popup-view-tree", - itemsCreator: opts.itemsCreator, - onLoaded: opts.onLoaded, - value: opts.value || {} + this.checkSelected.on(BI.TextButton.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments); }); - this.popupView = BI.createWidget({ - type: "bi.multi_popup_view", + BI.createWidget({ + type: "bi.horizontal", element: this, - stopPropagation: false, - maxWidth: opts.maxWidth, - minWidth: opts.minWidth, - maxHeight: opts.maxHeight, - buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], - el: this.tree + items: [this.indicator, this.checkSelected] }); - this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { - switch (index) { - case 0: - self.fireEvent(BI.MultiTreePopup.EVENT_CLICK_CLEAR); - break; - case 1: - self.fireEvent(BI.MultiTreePopup.EVENT_CLICK_CONFIRM); - break; + this.element.hover(function () { + self.indicator.setVisible(false); + self.checkSelected.setVisible(true); + }, function () { + self.indicator.setVisible(true); + self.checkSelected.setVisible(false); + }); + this.setVisible(false); + }, + + setValue: function (v) { + v || (v = {}); + this.setVisible(BI.size(v.value) > 0); + } +}); + +BI.MultiTreeCheckSelectedButton.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.multi_tree_check_selected_button", BI.MultiTreeCheckSelectedButton);/** + * searcher + * Created by guy on 15/11/3. + * @class BI.MultiTreeSearcher + * @extends Widget + */ +BI.MultiTreeSearcher = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.MultiTreeSearcher.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-searcher", + itemsCreator: BI.emptyFn, + popup: {}, + + adapter: null, + masker: {} + }); + }, + + _init: function () { + BI.MultiTreeSearcher.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.editor = BI.createWidget({ + type: "bi.multi_select_editor", + height: o.height, + el: { + type: "bi.simple_state_editor", + height: o.height } }); - this.tree.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreePopup.EVENT_CHANGE); + this.searcher = BI.createWidget({ + type: "bi.searcher", + element: this, + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback({ + keyword: self.editor.getValue() + }); + }, + el: this.editor, + + popup: BI.extend({ + type: "bi.multi_tree_search_pane", + keywordGetter: function () { + return self.editor.getValue(); + }, + itemsCreator: function (op, callback) { + op.keyword = self.editor.getValue(); + o.itemsCreator(op, callback); + }, + value: o.value + }, o.popup), + + adapter: o.adapter, + masker: o.masker + }); + this.searcher.on(BI.Searcher.EVENT_START, function () { + self.fireEvent(BI.MultiTreeSearcher.EVENT_START); }); + this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { + if (this.hasMatched()) { - this.tree.on(BI.TreeView.EVENT_AFTERINIT, function () { - self.fireEvent(BI.MultiTreePopup.EVENT_AFTERINIT); + } + self.fireEvent(BI.MultiTreeSearcher.EVENT_PAUSE); + }); + this.searcher.on(BI.Searcher.EVENT_STOP, function () { + self.fireEvent(BI.MultiTreeSearcher.EVENT_STOP); + }); + this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiTreeSearcher.EVENT_CHANGE, arguments); }); + if (BI.isNotNull(o.value)) { + this.setState(o.value); + } + }, + adjustView: function () { + this.searcher.adjustView(); }, - getValue: function () { - return this.tree.getValue(); + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - setValue: function (v) { - v || (v = {}); - this.tree.setSelectedValue(v.value); + isSearching: function () { + return this.searcher.isSearching(); + }, + + stopSearch: function () { + this.searcher.stopSearch(); + }, + + getKeyword: function () { + return this.editor.getValue(); + }, + + hasMatched: function () { + return this.searcher.hasMatched(); + }, + + hasChecked: function () { + return this.searcher.getView() && this.searcher.getView().hasChecked(); + }, + + setState: function (ob) { + ob || (ob = {}); + ob.value || (ob.value = {}); + if (BI.isNumber(ob)) { + this.editor.setState(ob); + } else if (BI.size(ob.value) === 0) { + this.editor.setState(BI.Selection.None); + } else { + var text = ""; + BI.each(ob.value, function (name, children) { + var childNodes = getChildrenNode(children); + text += name + (childNodes === "" ? "" : (":" + childNodes)) + "; "; + }); + this.editor.setState(text); + } + + function getChildrenNode (ob) { + var text = ""; + var index = 0, size = BI.size(ob); + BI.each(ob, function (name, children) { + index++; + var childNodes = getChildrenNode(children); + text += name + (childNodes === "" ? "" : (":" + childNodes)) + (index === size ? "" : ","); + }); + return text; + } }, - populate: function (config) { - this.tree.stroke(config); + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); }, - hasChecked: function () { - return this.tree.hasChecked(); + getKey: function () { + return this.editor.getValue(); }, - resetHeight: function (h) { - this.popupView.resetHeight(h); + getValue: function () { + return this.searcher.getValue(); }, - resetWidth: function (w) { - this.popupView.resetWidth(w); + populate: function (items) { + this.searcher.populate.apply(this.searcher, arguments); } }); -BI.MultiTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiTreePopup.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; -BI.MultiTreePopup.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; -BI.MultiTreePopup.EVENT_AFTERINIT = "EVENT_AFTERINIT"; - - -BI.shortcut("bi.multi_tree_popup_view", BI.MultiTreePopup);/** - * - * 在搜索框中输入文本弹出的面板 - * @class BI.MultiTreeSearchPane - * @extends BI.Pane +BI.MultiTreeSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.MultiTreeSearcher.EVENT_CHANGE = "EVENT_CHANGE"; +BI.MultiTreeSearcher.EVENT_START = "EVENT_START"; +BI.MultiTreeSearcher.EVENT_STOP = "EVENT_STOP"; +BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE"; +BI.shortcut("bi.multi_tree_searcher", BI.MultiTreeSearcher);/** + * Created by windy on 2017/3/13. + * 数值微调器 */ - -BI.MultiTreeSearchPane = BI.inherit(BI.Pane, { - +BI.NumberEditor = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiTreeSearchPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-search-pane bi-card", - itemsCreator: BI.emptyFn, - keywordGetter: BI.emptyFn + return BI.extend(BI.NumberEditor.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-number-editor bi-border", + validationChecker: function () { + return true; + }, + valueFormatter: function (v) { + return v; + }, + value: 0, + allowBlank: false, + errorText: "", + step: 1 }); }, _init: function () { - BI.MultiTreeSearchPane.superclass._init.apply(this, arguments); - - var self = this, opts = this.options; - - this.partTree = BI.createWidget({ - type: "bi.part_tree", - element: this, - tipText: BI.i18nText("BI-No_Select"), - itemsCreator: function (op, callback) { - op.keyword = opts.keywordGetter(); - opts.itemsCreator(op, callback); - }, - value: opts.value + BI.NumberEditor.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.editor = BI.createWidget({ + type: "bi.sign_editor", + height: o.height, + allowBlank: o.allowBlank, + value: o.valueFormatter(o.value), + validationChecker: o.validationChecker, + errorText: o.errorText }); - - this.partTree.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(BI.TextEditor.EVENT_CHANGE, function () { + o.value = this.getValue(); + self.fireEvent(BI.NumberEditor.EVENT_CHANGE); }); - - this.partTree.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreeSearchPane.EVENT_CHANGE); + this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () { + this.setValue(BI.parseFloat(this.getValue())); + self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); + }); + this.topBtn = BI.createWidget({ + type: "bi.icon_button", + trigger: "lclick,", + cls: "column-pre-page-h-font top-button bi-border-left bi-border-bottom" + }); + this.topBtn.on(BI.IconButton.EVENT_CHANGE, function () { + self._finetuning(o.step); + self.fireEvent(BI.NumberEditor.EVENT_CHANGE); + self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); + }); + this.bottomBtn = BI.createWidget({ + type: "bi.icon_button", + trigger: "lclick,", + cls: "column-next-page-h-font bottom-button bi-border-left bi-border-top" + }); + this.bottomBtn.on(BI.IconButton.EVENT_CHANGE, function () { + self._finetuning(-o.step); + self.fireEvent(BI.NumberEditor.EVENT_CHANGE); + self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); + }); + BI.createWidget({ + type: "bi.htape", + element: this, + items: [this.editor, { + el: { + type: "bi.grid", + columns: 1, + rows: 2, + items: [{ + column: 0, + row: 0, + el: this.topBtn + }, { + column: 0, + row: 1, + el: this.bottomBtn + }] + }, + width: 23 + }] }); }, - hasChecked: function () { - return this.partTree.hasChecked(); + focus: function () { + this.editor.focus(); }, - setValue: function (v) { - this.setSelectedValue(v.value); + // 微调 + _finetuning: function (add) { + var v = BI.parseFloat(this.getValue()); + this.setValue(v.add(add)); }, - setSelectedValue: function (v) { - v || (v = {}); - this.partTree.setSelectedValue(v); + setUpEnable: function (v) { + this.topBtn.setEnable(!!v); }, - getValue: function () { - return this.partTree.getValue(); + setDownEnable: function (v) { + this.bottomBtn.setEnable(!!v); }, - empty: function () { - this.partTree.empty(); + getValue: function () { + return this.options.value; }, - populate: function (op) { - this.partTree.stroke.apply(this.partTree, arguments); + setValue: function (v) { + var o = this.options; + o.value = v; + this.editor.setValue(o.valueFormatter(v)); } -}); - -BI.MultiTreeSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.MultiTreeSearchPane.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; -BI.MultiTreeSearchPane.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; -BI.shortcut("bi.multi_tree_search_pane", BI.MultiTreeSearchPane);/** - * 查看已选按钮 - * Created by guy on 15/11/3. - * @class BI.MultiTreeCheckSelectedButton - * @extends BI.Single +}); +BI.NumberEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.NumberEditor.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.number_editor", BI.NumberEditor);// 小于号的值为:0,小于等于号的值为:1 +// closeMIn:最小值的符号,closeMax:最大值的符号 +/** + * Created by roy on 15/9/17. + * */ -BI.MultiTreeCheckSelectedButton = BI.inherit(BI.Single, { - - _const: { - checkSelected: BI.i18nText("BI-Check_Selected") +BI.NumberInterval = BI.inherit(BI.Single, { + constants: { + typeError: "typeBubble", + numberError: "numberBubble", + signalError: "signalBubble", + editorWidth: 114, + columns: 5, + width: 30, + rows: 1, + numberErrorCls: "number-error", + border: 1, + less: 0, + less_equal: 1, + numTip: "" }, - _defaultConfig: function () { - return BI.extend(BI.MultiTreeCheckSelectedButton.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-check-selected-button", - itemsCreator: BI.emptyFn + var conf = BI.NumberInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-number-interval", + height: 25, + validation: "valid" }); }, - _init: function () { - BI.MultiTreeCheckSelectedButton.superclass._init.apply(this, arguments); - var self = this; - this.indicator = BI.createWidget({ - type: "bi.icon_button", - cls: "check-font trigger-check-selected", - width: 15, - height: 15, - stopPropagation: true - }); - - this.checkSelected = BI.createWidget({ - type: "bi.text_button", - cls: "trigger-check-selected", - invisible: true, - hgap: 4, - text: this._const.checkSelected, - textAlign: "center", - textHeight: 15 - }); - this.checkSelected.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + var self = this, c = this.constants, o = this.options; + BI.NumberInterval.superclass._init.apply(this, arguments); + this.smallEditor = BI.createWidget({ + type: "bi.editor", + height: o.height - 2, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + allowBlank: true, + value: o.min, + level: "warning", + tipType: "warning", + quitChecker: function () { + return false; + }, + validationChecker: function (v) { + if (!BI.isNumeric(v)) { + self.smallEditorBubbleType = c.typeError; + return false; + } + return true; + }, + cls: "number-interval-small-editor bi-border-top bi-border-bottom bi-border-left" }); - this.checkSelected.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments); + this.smallTip = BI.createWidget({ + type: "bi.label", + text: o.numTip, + height: o.height - 2, + invisible: true }); - BI.createWidget({ - type: "bi.horizontal", - element: this, - items: [this.indicator, this.checkSelected] + type: "bi.absolute", + element: this.smallEditor.element, + items: [{ + el: this.smallTip, + top: 0, + right: 5 + }] }); - this.element.hover(function () { - self.indicator.setVisible(false); - self.checkSelected.setVisible(true); - }, function () { - self.indicator.setVisible(true); - self.checkSelected.setVisible(false); + this.bigEditor = BI.createWidget({ + type: "bi.editor", + height: o.height - 2, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + allowBlank: true, + value: o.max, + level: "warning", + tipType: "warning", + quitChecker: function () { + return false; + }, + validationChecker: function (v) { + if (!BI.isNumeric(v)) { + self.bigEditorBubbleType = c.typeError; + return false; + } + return true; + }, + cls: "number-interval-big-editor bi-border-top bi-border-bottom bi-border-right" }); - this.setVisible(false); - }, - - setValue: function (v) { - v || (v = {}); - this.setVisible(BI.size(v.value) > 0); - } -}); - -BI.MultiTreeCheckSelectedButton.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multi_tree_check_selected_button", BI.MultiTreeCheckSelectedButton);/** - * searcher - * Created by guy on 15/11/3. - * @class BI.MultiTreeSearcher - * @extends Widget - */ -BI.MultiTreeSearcher = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.MultiTreeSearcher.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-searcher", - itemsCreator: BI.emptyFn, - popup: {}, - adapter: null, - masker: {} + this.bigTip = BI.createWidget({ + type: "bi.label", + text: o.numTip, + height: o.height - 2, + invisible: true }); - }, - - _init: function () { - BI.MultiTreeSearcher.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget({ - type: "bi.multi_select_editor", - height: o.height, - el: { - type: "bi.simple_state_editor", - height: o.height - } + BI.createWidget({ + type: "bi.absolute", + element: this.bigEditor.element, + items: [{ + el: this.bigTip, + top: 0, + right: 5 + }] }); - this.searcher = BI.createWidget({ - type: "bi.searcher", - element: this, - isAutoSearch: false, - isAutoSync: false, - onSearch: function (op, callback) { - callback({ - keyword: self.editor.getValue() - }); - }, - el: this.editor, - - popup: BI.extend({ - type: "bi.multi_tree_search_pane", - keywordGetter: function () { - return self.editor.getValue(); - }, - itemsCreator: function (op, callback) { - op.keyword = self.editor.getValue(); - o.itemsCreator(op, callback); - }, - value: o.value - }, o.popup), - - adapter: o.adapter, - masker: o.masker + // this.smallCombo = BI.createWidget({ + // type: "bi.number_interval_combo", + // cls: "number-interval-small-combo", + // height: o.height, + // value: o.closemin ? 1 : 0, + // offsetStyle: "left" + // }); + // + // this.bigCombo = BI.createWidget({ + // type: "bi.number_interval_combo", + // cls: "number-interval-big-combo", + // height: o.height, + // value: o.closemax ? 1 : 0, + // offsetStyle: "left" + // }); + this.smallCombo = BI.createWidget({ + type: "bi.icon_combo", + cls: "number-interval-small-combo bi-border", + height: o.height - 2, + items: [{ + text: "(" + BI.i18nText("BI-Less_Than") + ")", + iconCls: "less-font", + value: 0 + }, { + text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", + value: 1, + iconCls: "less-equal-font" + }] }); - this.searcher.on(BI.Searcher.EVENT_START, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_START); + if (o.closemin === true) { + this.smallCombo.setValue(1); + } else { + this.smallCombo.setValue(0); + } + this.bigCombo = BI.createWidget({ + type: "bi.icon_combo", + cls: "number-interval-big-combo bi-border", + height: o.height - 2, + items: [{ + text: "(" + BI.i18nText("BI-Less_Than") + ")", + iconCls: "less-font", + value: 0 + }, { + text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", + value: 1, + iconCls: "less-equal-font" + }] }); - this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { - if (this.hasMatched()) { + if (o.closemax === true) { + this.bigCombo.setValue(1); + } else { + this.bigCombo.setValue(0); + } + this.label = BI.createWidget({ + type: "bi.label", + text: BI.i18nText("BI-Basic_Value"), + textHeight: o.height - c.border * 2, + width: c.width - c.border * 2, + height: o.height - c.border * 2, + level: "warning", + tipType: "warning" + }); + this.left = BI.createWidget({ + type: "bi.htape", + items: [{ + el: self.smallEditor + }, { + el: self.smallCombo, + width: c.width - c.border * 2 + }] - } - self.fireEvent(BI.MultiTreeSearcher.EVENT_PAUSE); }); - this.searcher.on(BI.Searcher.EVENT_STOP, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_STOP); + this.right = BI.createWidget({ + type: "bi.htape", + items: [{ + el: self.bigCombo, + width: c.width - c.border * 2 + }, { + el: self.bigEditor + }] }); - this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_CHANGE, arguments); + + + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: o.height, + items: [ + { + type: "bi.absolute", + items: [{ + el: self.left, + left: -15, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: -15, + top: 0, + bottom: 0 + }] + } + ] }); - if (BI.isNotNull(o.value)) { - this.setState(o.value); - } + + BI.createWidget({ + element: self, + type: "bi.horizontal_auto", + items: [ + self.label + ] + }); + + + self._setValidEvent(self.bigEditor, c.bigEditor); + self._setValidEvent(self.smallEditor, c.smallEditor); + self._setErrorEvent(self.bigEditor, c.bigEditor); + self._setErrorEvent(self.smallEditor, c.smallEditor); + self._setBlurEvent(self.bigEditor); + self._setBlurEvent(self.smallEditor); + self._setFocusEvent(self.bigEditor); + self._setFocusEvent(self.smallEditor); + self._setComboValueChangedEvent(self.bigCombo); + self._setComboValueChangedEvent(self.smallCombo); + self._setEditorValueChangedEvent(self.bigEditor); + self._setEditorValueChangedEvent(self.smallEditor); }, - adjustView: function () { - this.searcher.adjustView(); - }, + _checkValidation: function () { + var self = this, c = this.constants, o = this.options; + self._setTitle(""); + BI.Bubbles.hide(c.typeError); + BI.Bubbles.hide(c.numberError); + BI.Bubbles.hide(c.signalError); + if (!self.smallEditor.isValid() || !self.bigEditor.isValid()) { + self.element.removeClass("number-error"); + o.validation = "invalid"; + return c.typeError; + } + if (BI.isEmptyString(self.smallEditor.getValue()) || BI.isEmptyString(self.bigEditor.getValue())) { + self.element.removeClass("number-error"); + o.validation = "valid"; + return ""; + } + var smallValue = parseFloat(self.smallEditor.getValue()), bigValue = parseFloat(self.bigEditor.getValue()), + bigComboValue = self.bigCombo.getValue(), smallComboValue = self.smallCombo.getValue(); + if (bigComboValue[0] === c.less_equal && smallComboValue[0] === c.less_equal) { + if (smallValue > bigValue) { + self.element.addClass("number-error"); + o.validation = "invalid"; + return c.numberError; + } + self.element.removeClass("number-error"); + o.validation = "valid"; + return ""; - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); - }, + } + if (smallValue > bigValue) { + self.element.addClass("number-error"); + o.validation = "invalid"; + return c.numberError; + } else if (smallValue === bigValue) { + self.element.addClass("number-error"); + o.validation = "invalid"; + return c.signalError; + } + self.element.removeClass("number-error"); + o.validation = "valid"; + return ""; - isSearching: function () { - return this.searcher.isSearching(); - }, - stopSearch: function () { - this.searcher.stopSearch(); - }, - getKeyword: function () { - return this.editor.getValue(); - }, - hasMatched: function () { - return this.searcher.hasMatched(); - }, - hasChecked: function () { - return this.searcher.getView() && this.searcher.getView().hasChecked(); }, - setState: function (ob) { - ob || (ob = {}); - ob.value || (ob.value = {}); - if (BI.isNumber(ob)) { - this.editor.setState(ob); - } else if (BI.size(ob.value) === 0) { - this.editor.setState(BI.Selection.None); - } else { - var text = ""; - BI.each(ob.value, function (name, children) { - var childNodes = getChildrenNode(children); - text += name + (childNodes === "" ? "" : (":" + childNodes)) + "; "; - }); - this.editor.setState(text); - } - - function getChildrenNode (ob) { - var text = ""; - var index = 0, size = BI.size(ob); - BI.each(ob, function (name, children) { - index++; - var childNodes = getChildrenNode(children); - text += name + (childNodes === "" ? "" : (":" + childNodes)) + (index === size ? "" : ","); - }); - return text; - } + _setTitle: function (v) { + var self = this; + self.bigEditor.setTitle(v); + self.smallEditor.setTitle(v); + self.label.setTitle(v); }, - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); - }, + _setFocusEvent: function (w) { + var self = this, c = this.constants; + w.on(BI.Editor.EVENT_FOCUS, function () { + self._setTitle(""); + switch (self._checkValidation()) { + case c.typeError: + BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { + offsetStyle: "center" + }); + break; + case c.numberError: + BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { + offsetStyle: "center" + }); + break; + case c.signalError: + BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { + offsetStyle: "center" + }); + break; + default : + return; + } - getKey: function () { - return this.editor.getValue(); + }); + }, + _setBlurEvent: function (w) { + var c = this.constants, self = this; + w.on(BI.Editor.EVENT_BLUR, function () { + BI.Bubbles.hide(c.typeError); + BI.Bubbles.hide(c.numberError); + BI.Bubbles.hide(c.signalError); + switch (self._checkValidation()) { + case c.typeError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Input_Data")); + break; + case c.numberError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Number_Value")); + break; + case c.signalError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Signal_Value")); + break; + default: + self._setTitle(""); + } + }); }, - getValue: function () { - return this.searcher.getValue(); + _setErrorEvent: function (w) { + var c = this.constants, self = this; + w.on(BI.Editor.EVENT_ERROR, function () { + self._checkValidation(); + BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + }); }, - populate: function (items) { - this.searcher.populate.apply(this.searcher, arguments); - } -}); -BI.MultiTreeSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.MultiTreeSearcher.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiTreeSearcher.EVENT_START = "EVENT_START"; -BI.MultiTreeSearcher.EVENT_STOP = "EVENT_STOP"; -BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE"; -BI.shortcut("bi.multi_tree_searcher", BI.MultiTreeSearcher);/** - * Created by windy on 2017/3/13. - * 数值微调器 - */ -BI.NumberEditor = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.NumberEditor.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-number-editor bi-border", - validationChecker: function () { - return true; - }, - valueFormatter: function (v) { - return v; - }, - value: 0, - allowBlank: false, - errorText: "", - step: 1 + _setValidEvent: function (w) { + var self = this, c = this.constants; + w.on(BI.Editor.EVENT_VALID, function () { + switch (self._checkValidation()) { + case c.numberError: + BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + case c.signalError: + BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + default: + self.fireEvent(BI.NumberInterval.EVENT_VALID); + } }); }, - _init: function () { - BI.NumberEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget({ - type: "bi.sign_editor", - height: o.height, - allowBlank: o.allowBlank, - value: o.valueFormatter(o.value), - validationChecker: o.validationChecker, - errorText: o.errorText - }); - this.editor.on(BI.TextEditor.EVENT_CHANGE, function () { - o.value = this.getValue(); - self.fireEvent(BI.NumberEditor.EVENT_CHANGE); - }); - this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () { - this.setValue(BI.parseFloat(this.getValue())); - self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); - }); - this.topBtn = BI.createWidget({ - type: "bi.icon_button", - trigger: "lclick,", - cls: "column-pre-page-h-font top-button bi-border-left bi-border-bottom" - }); - this.topBtn.on(BI.IconButton.EVENT_CHANGE, function () { - self._finetuning(o.step); - self.fireEvent(BI.NumberEditor.EVENT_CHANGE); - self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); - }); - this.bottomBtn = BI.createWidget({ - type: "bi.icon_button", - trigger: "lclick,", - cls: "column-next-page-h-font bottom-button bi-border-left bi-border-top" - }); - this.bottomBtn.on(BI.IconButton.EVENT_CHANGE, function () { - self._finetuning(-o.step); - self.fireEvent(BI.NumberEditor.EVENT_CHANGE); - self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); + + _setEditorValueChangedEvent: function (w) { + var self = this, c = this.constants; + w.on(BI.Editor.EVENT_CHANGE, function () { + switch (self._checkValidation()) { + case c.typeError: + BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { + offsetStyle: "center" + }); + break; + case c.numberError: + BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { + offsetStyle: "center" + }); + break; + case c.signalError: + BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { + offsetStyle: "center" + }); + break; + default : + break; + } + self.fireEvent(BI.NumberInterval.EVENT_CHANGE); }); - BI.createWidget({ - type: "bi.htape", - element: this, - items: [this.editor, { - el: { - type: "bi.grid", - columns: 1, - rows: 2, - items: [{ - column: 0, - row: 0, - el: this.topBtn - }, { - column: 0, - row: 1, - el: this.bottomBtn - }] - }, - width: 23 - }] + }, + + _setComboValueChangedEvent: function (w) { + var self = this, c = this.constants; + w.on(BI.IconCombo.EVENT_CHANGE, function () { + switch (self._checkValidation()) { + case c.typeError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Input_Data")); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + case c.numberError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Number_Value")); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + case c.signalError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Signal_Value")); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + default : + self.fireEvent(BI.NumberInterval.EVENT_CHANGE); + self.fireEvent(BI.NumberInterval.EVENT_VALID); + } }); }, - focus: function () { - this.editor.focus(); + isStateValid: function () { + return this.options.validation === "valid"; }, - // 微调 - _finetuning: function (add) { - var v = BI.parseFloat(this.getValue()); - this.setValue(v.add(add)); + setMinEnable: function (b) { + this.smallEditor.setEnable(b); }, - setUpEnable: function (v) { - this.topBtn.setEnable(!!v); + setCloseMinEnable: function (b) { + this.smallCombo.setEnable(b); }, - setDownEnable: function (v) { - this.bottomBtn.setEnable(!!v); + setMaxEnable: function (b) { + this.bigEditor.setEnable(b); }, - getValue: function () { - return this.options.value; + setCloseMaxEnable: function (b) { + this.bigCombo.setEnable(b); }, - setValue: function (v) { - var o = this.options; - o.value = v; - this.editor.setValue(o.valueFormatter(v)); - } + showNumTip: function () { + this.smallTip.setVisible(true); + this.bigTip.setVisible(true); + }, -}); -BI.NumberEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.NumberEditor.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.number_editor", BI.NumberEditor);// 小于号的值为:0,小于等于号的值为:1 -// closeMIn:最小值的符号,closeMax:最大值的符号 -/** - * Created by roy on 15/9/17. - * - */ -BI.NumberInterval = BI.inherit(BI.Single, { - constants: { - typeError: "typeBubble", - numberError: "numberBubble", - signalError: "signalBubble", - editorWidth: 114, - columns: 5, - width: 30, - rows: 1, - numberErrorCls: "number-error", - border: 1, - less: 0, - less_equal: 1, - numTip: "" + hideNumTip: function () { + this.smallTip.setVisible(false); + this.bigTip.setVisible(false); }, - _defaultConfig: function () { - var conf = BI.NumberInterval.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-number-interval", - height: 25, - validation: "valid" - }); + + setNumTip: function (numTip) { + this.smallTip.setText(numTip); + this.bigTip.setText(numTip); }, - _init: function () { - var self = this, c = this.constants, o = this.options; - BI.NumberInterval.superclass._init.apply(this, arguments); - this.smallEditor = BI.createWidget({ - type: "bi.editor", - height: o.height - 2, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - allowBlank: true, - value: o.min, - level: "warning", - tipType: "warning", - quitChecker: function () { - return false; - }, - validationChecker: function (v) { - if (!BI.isNumeric(v)) { - self.smallEditorBubbleType = c.typeError; - return false; - } - return true; - }, - cls: "number-interval-small-editor bi-border-top bi-border-bottom bi-border-left" - }); - this.smallTip = BI.createWidget({ - type: "bi.label", - text: o.numTip, - height: o.height - 2, - invisible: true - }); - BI.createWidget({ - type: "bi.absolute", - element: this.smallEditor.element, - items: [{ - el: this.smallTip, - top: 0, - right: 5 - }] - }); + getNumTip: function () { + return this.smallTip.getText(); + }, - this.bigEditor = BI.createWidget({ - type: "bi.editor", - height: o.height - 2, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - allowBlank: true, - value: o.max, - level: "warning", - tipType: "warning", - quitChecker: function () { - return false; - }, - validationChecker: function (v) { - if (!BI.isNumeric(v)) { - self.bigEditorBubbleType = c.typeError; - return false; - } - return true; - }, - cls: "number-interval-big-editor bi-border-top bi-border-bottom bi-border-right" - }); + setValue: function (data) { + data = data || {}; + var self = this, combo_value; + if (BI.isNumeric(data.min) || BI.isEmptyString(data.min)) { + self.smallEditor.setValue(data.min); + } - this.bigTip = BI.createWidget({ - type: "bi.label", - text: o.numTip, - height: o.height - 2, - invisible: true - }); - BI.createWidget({ - type: "bi.absolute", - element: this.bigEditor.element, - items: [{ - el: this.bigTip, - top: 0, - right: 5 - }] - }); + if (!BI.isNotNull(data.min)) { + self.smallEditor.setValue(""); + } - // this.smallCombo = BI.createWidget({ - // type: "bi.number_interval_combo", - // cls: "number-interval-small-combo", - // height: o.height, - // value: o.closemin ? 1 : 0, - // offsetStyle: "left" - // }); - // - // this.bigCombo = BI.createWidget({ - // type: "bi.number_interval_combo", - // cls: "number-interval-big-combo", - // height: o.height, - // value: o.closemax ? 1 : 0, - // offsetStyle: "left" - // }); - this.smallCombo = BI.createWidget({ - type: "bi.icon_combo", - cls: "number-interval-small-combo bi-border", - height: o.height - 2, - items: [{ - text: "(" + BI.i18nText("BI-Less_Than") + ")", - iconCls: "less-font", - value: 0 - }, { - text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", - value: 1, - iconCls: "less-equal-font" - }] - }); - if (o.closemin === true) { - this.smallCombo.setValue(1); + if (BI.isNumeric(data.max) || BI.isEmptyString(data.max)) { + self.bigEditor.setValue(data.max); + } + + if (!BI.isNotNull(data.max)) { + self.bigEditor.setValue(""); + } + + if (!BI.isNull(data.closemin)) { + if (data.closemin === true) { + combo_value = 1; + } else { + combo_value = 0; + } + self.smallCombo.setValue(combo_value); + } + + if (!BI.isNull(data.closemax)) { + if (data.closemax === true) { + combo_value = 1; + } else { + combo_value = 0; + } + self.bigCombo.setValue(combo_value); + } + }, + + + getValue: function () { + var self = this, value = {}, minComboValue = self.smallCombo.getValue(), maxComboValue = self.bigCombo.getValue(); + value.min = self.smallEditor.getValue(); + value.max = self.bigEditor.getValue(); + if (minComboValue[0] === 0) { + value.closemin = false; } else { - this.smallCombo.setValue(0); + value.closemin = true; } - this.bigCombo = BI.createWidget({ - type: "bi.icon_combo", - cls: "number-interval-big-combo bi-border", - height: o.height - 2, - items: [{ - text: "(" + BI.i18nText("BI-Less_Than") + ")", - iconCls: "less-font", - value: 0 - }, { - text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", - value: 1, - iconCls: "less-equal-font" - }] - }); - if (o.closemax === true) { - this.bigCombo.setValue(1); + + if (maxComboValue[0] === 0) { + value.closemax = false; } else { - this.bigCombo.setValue(0); + value.closemax = true; } - this.label = BI.createWidget({ - type: "bi.label", - text: BI.i18nText("BI-Basic_Value"), - textHeight: o.height - c.border * 2, - width: c.width - c.border * 2, - height: o.height - c.border * 2, - level: "warning", - tipType: "warning" + return value; + } +}); +BI.NumberInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.NumberInterval.EVENT_VALID = "EVENT_VALID"; +BI.NumberInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.shortcut("bi.number_interval", BI.NumberInterval);/** + * + * 表格 + * + * Created by GUY on 2015/9/22. + * @class BI.PageTableCell + * @extends BI.Single + */ +BI.PageTableCell = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.PageTableCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-page-table-cell", + text: "", + title: "" }); - this.left = BI.createWidget({ - type: "bi.htape", - items: [{ - el: self.smallEditor - }, { - el: self.smallCombo, - width: c.width - c.border * 2 - }] + }, - }); - this.right = BI.createWidget({ - type: "bi.htape", - items: [{ - el: self.bigCombo, - width: c.width - c.border * 2 - }, { - el: self.bigEditor - }] + _init: function () { + BI.PageTableCell.superclass._init.apply(this, arguments); + var label = BI.createWidget({ + type: "bi.label", + element: this, + textAlign: "left", + whiteSpace: "nowrap", + height: this.options.height, + text: this.options.text, + title: this.options.title, + value: this.options.value, + lgap: 5, + rgap: 5 }); + if (BI.isNotNull(this.options.styles) && BI.isObject(this.options.styles)) { + this.element.css(this.options.styles); + } + } +}); - BI.createWidget({ - element: self, - type: "bi.center", - hgap: 15, - height: o.height, - items: [ - { - type: "bi.absolute", - items: [{ - el: self.left, - left: -15, - right: 0, - top: 0, - bottom: 0 - }] - }, { - type: "bi.absolute", - items: [{ - el: self.right, - left: 0, - right: -15, - top: 0, - bottom: 0 - }] +BI.shortcut("bi.page_table_cell", BI.PageTableCell);/** + * 分页表格 + * + * Created by GUY on 2016/2/15. + * @class BI.PageTable + * @extends BI.Widget + */ +BI.PageTable = BI.inherit(BI.Widget, { + + _const: { + scrollWidth: 18, + minScrollWidth: 100 + }, + + _defaultConfig: function () { + return BI.extend(BI.PageTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-page-table", + el: { + type: "bi.sequence_table" + }, + pager: { + horizontal: { + pages: false, // 总页数 + curr: 1, // 初始化当前页, pages为数字时可用 + + hasPrev: BI.emptyFn, + hasNext: BI.emptyFn, + firstPage: 1, + lastPage: BI.emptyFn + }, + vertical: { + pages: false, // 总页数 + curr: 1, // 初始化当前页, pages为数字时可用 + + hasPrev: BI.emptyFn, + hasNext: BI.emptyFn, + firstPage: 1, + lastPage: BI.emptyFn } - ] - }); + }, - BI.createWidget({ - element: self, - type: "bi.horizontal_auto", - items: [ - self.label - ] - }); + itemsCreator: BI.emptyFn, + isNeedFreeze: false, // 是否需要冻结单元格 + freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 - self._setValidEvent(self.bigEditor, c.bigEditor); - self._setValidEvent(self.smallEditor, c.smallEditor); - self._setErrorEvent(self.bigEditor, c.bigEditor); - self._setErrorEvent(self.smallEditor, c.smallEditor); - self._setBlurEvent(self.bigEditor); - self._setBlurEvent(self.smallEditor); - self._setFocusEvent(self.bigEditor); - self._setFocusEvent(self.smallEditor); - self._setComboValueChangedEvent(self.bigCombo); - self._setComboValueChangedEvent(self.smallCombo); - self._setEditorValueChangedEvent(self.bigEditor); - self._setEditorValueChangedEvent(self.smallEditor); - }, + isNeedMerge: false, // 是否需要合并单元格 + mergeCols: [], // 合并的单元格列号 + mergeRule: BI.emptyFn, - _checkValidation: function () { - var self = this, c = this.constants, o = this.options; - self._setTitle(""); - BI.Bubbles.hide(c.typeError); - BI.Bubbles.hide(c.numberError); - BI.Bubbles.hide(c.signalError); - if (!self.smallEditor.isValid() || !self.bigEditor.isValid()) { - self.element.removeClass("number-error"); - o.validation = "invalid"; - return c.typeError; - } - if (BI.isEmptyString(self.smallEditor.getValue()) || BI.isEmptyString(self.bigEditor.getValue())) { - self.element.removeClass("number-error"); - o.validation = "valid"; - return ""; - } - var smallValue = parseFloat(self.smallEditor.getValue()), bigValue = parseFloat(self.bigEditor.getValue()), - bigComboValue = self.bigCombo.getValue(), smallComboValue = self.smallCombo.getValue(); - if (bigComboValue[0] === c.less_equal && smallComboValue[0] === c.less_equal) { - if (smallValue > bigValue) { - self.element.addClass("number-error"); - o.validation = "invalid"; - return c.numberError; - } - self.element.removeClass("number-error"); - o.validation = "valid"; - return ""; + columnSize: [], + minColumnSize: [], + maxColumnSize: [], + headerRowSize: 25, + rowSize: 25, - } - if (smallValue > bigValue) { - self.element.addClass("number-error"); - o.validation = "invalid"; - return c.numberError; - } else if (smallValue === bigValue) { - self.element.addClass("number-error"); - o.validation = "invalid"; - return c.signalError; - } - self.element.removeClass("number-error"); - o.validation = "valid"; - return ""; + regionColumnSize: [], + + headerCellStyleGetter: BI.emptyFn, + summaryCellStyleGetter: BI.emptyFn, + sequenceCellStyleGetter: BI.emptyFn, + + header: [], + items: [], // 二维数组 + + // 交叉表头 + crossHeader: [], + crossItems: [] + }); + }, + + _init: function () { + BI.PageTable.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.hCurr = 1; + this.vCurr = 1; + this.table = BI.createWidget(o.el, { + type: "bi.sequence_table", + width: o.width, + height: o.height && o.height - 30, + isNeedResize: true, + isResizeAdapt: false, + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, + isNeedMerge: o.isNeedMerge, + mergeCols: o.mergeCols, + mergeRule: o.mergeRule, - }, + columnSize: o.columnSize, + minColumnSize: o.minColumnSize, + maxColumnSize: o.maxColumnSize, + headerRowSize: o.headerRowSize, + rowSize: o.rowSize, - _setTitle: function (v) { - var self = this; - self.bigEditor.setTitle(v); - self.smallEditor.setTitle(v); - self.label.setTitle(v); - }, + regionColumnSize: o.regionColumnSize, - _setFocusEvent: function (w) { - var self = this, c = this.constants; - w.on(BI.Editor.EVENT_FOCUS, function () { - self._setTitle(""); - switch (self._checkValidation()) { - case c.typeError: - BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { - offsetStyle: "center" - }); - break; - case c.numberError: - BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { - offsetStyle: "center" - }); - break; - case c.signalError: - BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { - offsetStyle: "center" - }); - break; - default : - return; - } + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter, + header: o.header, + items: o.items, + // 交叉表头 + crossHeader: o.crossHeader, + crossItems: o.crossItems }); - }, - _setBlurEvent: function (w) { - var c = this.constants, self = this; - w.on(BI.Editor.EVENT_BLUR, function () { - BI.Bubbles.hide(c.typeError); - BI.Bubbles.hide(c.numberError); - BI.Bubbles.hide(c.signalError); - switch (self._checkValidation()) { - case c.typeError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Input_Data")); - break; - case c.numberError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Number_Value")); - break; - case c.signalError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Signal_Value")); - break; - default: - self._setTitle(""); - } + + this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { + self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { + o.regionColumnSize = this.getRegionColumnSize(); + o.columnSize = this.getColumnSize(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { + o.regionColumnSize = this.getRegionColumnSize(); + o.columnSize = this.getColumnSize(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); }); - }, - _setErrorEvent: function (w) { - var c = this.constants, self = this; - w.on(BI.Editor.EVENT_ERROR, function () { - self._checkValidation(); - BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { - offsetStyle: "center" + this.pager = BI.createWidget(o.pager, { + type: "bi.direction_pager", + height: 30 + }); + this.pager.on(BI.Pager.EVENT_CHANGE, function () { + var vpage = this.getVPage && this.getVPage(); + if (BI.isNull(vpage)) { + vpage = this.getCurrentPage(); + } + var hpage = this.getHPage && this.getHPage(); + o.itemsCreator({ + vpage: vpage, + hpage: hpage + }, function (items, header, crossItems, crossHeader) { + self.table.setVPage ? self.table.setVPage(vpage) : self.table.setValue(vpage); + self.table.setHPage && self.table.setHPage(hpage); + self.populate.apply(self, arguments); }); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); }); - }, - - _setValidEvent: function (w) { - var self = this, c = this.constants; - w.on(BI.Editor.EVENT_VALID, function () { - switch (self._checkValidation()) { - case c.numberError: - BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { - offsetStyle: "center" - }); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - case c.signalError: - BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { - offsetStyle: "center" - }); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - default: - self.fireEvent(BI.NumberInterval.EVENT_VALID); - } + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.table, + left: 0, + top: 0 + }, { + el: this.pager, + left: 0, + right: 0, + bottom: 0 + }] }); }, + setHPage: function (v) { + this.hCurr = v; + this.pager.setHPage && this.pager.setHPage(v); + this.table.setHPage && this.table.setHPage(v); + }, - _setEditorValueChangedEvent: function (w) { - var self = this, c = this.constants; - w.on(BI.Editor.EVENT_CHANGE, function () { - switch (self._checkValidation()) { - case c.typeError: - BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { - offsetStyle: "center" - }); - break; - case c.numberError: - BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { - offsetStyle: "center" - }); - break; - case c.signalError: - BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { - offsetStyle: "center" - }); - break; - default : - break; - } - self.fireEvent(BI.NumberInterval.EVENT_CHANGE); - }); + setVPage: function (v) { + this.vCurr = v; + this.pager.setVPage && this.pager.setVPage(v); + this.table.setVPage && this.table.setVPage(v); }, - _setComboValueChangedEvent: function (w) { - var self = this, c = this.constants; - w.on(BI.IconCombo.EVENT_CHANGE, function () { - switch (self._checkValidation()) { - case c.typeError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Input_Data")); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - case c.numberError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Number_Value")); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - case c.signalError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Signal_Value")); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - default : - self.fireEvent(BI.NumberInterval.EVENT_CHANGE); - self.fireEvent(BI.NumberInterval.EVENT_VALID); - } - }); + getHPage: function () { + var hpage = this.pager.getHPage && this.pager.getHPage(); + if (BI.isNotNull(hpage)) { + return hpage; + } + hpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); + if (BI.isNotNull(hpage)) { + return hpage; + } + return this.hpage; }, - isStateValid: function () { - return this.options.validation === "valid"; + getVPage: function () { + var vpage = this.pager.getVPage && this.pager.getVPage(); + if (BI.isNotNull(vpage)) { + return vpage; + } + vpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); + if (BI.isNotNull(vpage)) { + return vpage; + } + return this.vpage; }, - setMinEnable: function (b) { - this.smallEditor.setEnable(b); + setWidth: function (width) { + BI.PageTable.superclass.setWidth.apply(this, arguments); + this.table.setWidth(width); }, - setCloseMinEnable: function (b) { - this.smallCombo.setEnable(b); + setHeight: function (height) { + BI.PageTable.superclass.setHeight.apply(this, arguments); + var showPager = false; + if (this.pager.alwaysShowPager) { + showPager = true; + } else if (this.pager.hasHNext && this.pager.hasHNext()) { + showPager = true; + } else if (this.pager.hasHPrev && this.pager.hasHPrev()) { + showPager = true; + } else if (this.pager.hasVNext && this.pager.hasVNext()) { + showPager = true; + } else if (this.pager.hasVPrev && this.pager.hasVPrev()) { + showPager = true; + } else if (this.pager.hasNext && this.pager.hasNext()) { + showPager = true; + } else if (this.pager.hasPrev && this.pager.hasPrev()) { + showPager = true; + } + this.table.setHeight(height - (showPager ? 30 : 0)); + }, + + setColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setColumnSize(columnSize); }, - setMaxEnable: function (b) { - this.bigEditor.setEnable(b); + getColumnSize: function () { + return this.table.getColumnSize(); }, - setCloseMaxEnable: function (b) { - this.bigCombo.setEnable(b); + setRegionColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setRegionColumnSize(columnSize); }, - showNumTip: function () { - this.smallTip.setVisible(true); - this.bigTip.setVisible(true); + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); }, - hideNumTip: function () { - this.smallTip.setVisible(false); - this.bigTip.setVisible(false); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); }, - setNumTip: function (numTip) { - this.smallTip.setText(numTip); - this.bigTip.setText(numTip); + setLeftHorizontalScroll: function (scrollLeft) { + this.table.setLeftHorizontalScroll(scrollLeft); }, - getNumTip: function () { - return this.smallTip.getText(); + setRightHorizontalScroll: function (scrollLeft) { + this.table.setRightHorizontalScroll(scrollLeft); }, - setValue: function (data) { - data = data || {}; - var self = this, combo_value; - if (BI.isNumeric(data.min) || BI.isEmptyString(data.min)) { - self.smallEditor.setValue(data.min); - } + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); + }, - if (!BI.isNotNull(data.min)) { - self.smallEditor.setValue(""); - } + restore: function () { + this.table.restore(); + }, - if (BI.isNumeric(data.max) || BI.isEmptyString(data.max)) { - self.bigEditor.setValue(data.max); - } + attr: function () { + BI.PageTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); + }, - if (!BI.isNotNull(data.max)) { - self.bigEditor.setValue(""); - } + populate: function () { + this.pager.populate(); + this.table.populate.apply(this.table, arguments); + }, - if (!BI.isNull(data.closemin)) { - if (data.closemin === true) { - combo_value = 1; - } else { - combo_value = 0; - } - self.smallCombo.setValue(combo_value); - } + destroy: function () { + this.table.destroy(); + this.pager && this.pager.destroy(); + BI.PageTable.superclass.destroy.apply(this, arguments); + } +}); +BI.shortcut("bi.page_table", BI.PageTable);/** + * 预览表列 + * + * Created by GUY on 2015/12/25. + * @class BI.PreviewTableCell + * @extends BI.Widget + */ +BI.PreviewTableCell = BI.inherit(BI.Widget, { - if (!BI.isNull(data.closemax)) { - if (data.closemax === true) { - combo_value = 1; - } else { - combo_value = 0; - } - self.bigCombo.setValue(combo_value); - } + _defaultConfig: function () { + return BI.extend(BI.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table-cell", + text: "" + }); }, + _init: function () { + BI.PreviewTableCell.superclass._init.apply(this, arguments); + var self = this, o = this.options; - getValue: function () { - var self = this, value = {}, minComboValue = self.smallCombo.getValue(), maxComboValue = self.bigCombo.getValue(); - value.min = self.smallEditor.getValue(); - value.max = self.bigEditor.getValue(); - if (minComboValue[0] === 0) { - value.closemin = false; - } else { - value.closemin = true; - } - - if (maxComboValue[0] === 0) { - value.closemax = false; - } else { - value.closemax = true; - } - return value; + BI.createWidget({ + type: "bi.label", + element: this, + textAlign: "left", + whiteSpace: "normal", + height: this.options.height, + text: this.options.text, + value: this.options.value + }); } }); -BI.NumberInterval.EVENT_CHANGE = "EVENT_CHANGE"; -BI.NumberInterval.EVENT_VALID = "EVENT_VALID"; -BI.NumberInterval.EVENT_ERROR = "EVENT_ERROR"; -BI.shortcut("bi.number_interval", BI.NumberInterval);/** - * - * 表格 +BI.shortcut("bi.preview_table_cell", BI.PreviewTableCell);/** + * 预览表 * - * Created by GUY on 2015/9/22. - * @class BI.PageTableCell - * @extends BI.Single + * Created by GUY on 2015/12/25. + * @class BI.PreviewTableHeaderCell + * @extends BI.Widget */ -BI.PageTableCell = BI.inherit(BI.Widget, { +BI.PreviewTableHeaderCell = BI.inherit(BI.Widget, { + _defaultConfig: function () { - return BI.extend(BI.PageTableCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-page-table-cell", - text: "", - title: "" + return BI.extend(BI.PreviewTableHeaderCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table-header-cell", + text: "" }); }, _init: function () { - BI.PageTableCell.superclass._init.apply(this, arguments); - var label = BI.createWidget({ + BI.PreviewTableHeaderCell.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + BI.createWidget({ type: "bi.label", element: this, textAlign: "left", - whiteSpace: "nowrap", + whiteSpace: "normal", height: this.options.height, text: this.options.text, - title: this.options.title, - value: this.options.value, - lgap: 5, - rgap: 5 + value: this.options.value + }); + } +}); +BI.shortcut("bi.preview_table_header_cell", BI.PreviewTableHeaderCell);/** + * 预览表 + * + * Created by GUY on 2015/12/25. + * @class BI.PreviewTable + * @extends BI.Widget + */ +BI.PreviewTable = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.PreviewTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table", + isNeedFreeze: false, + freezeCols: [], + rowSize: null, + columnSize: [], + headerRowSize: 30, + header: [], + items: [] }); + }, - if (BI.isNotNull(this.options.styles) && BI.isObject(this.options.styles)) { - this.element.css(this.options.styles); + _init: function () { + BI.PreviewTable.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.table = BI.createWidget({ + type: "bi.table_view", + element: this, + isNeedResize: false, + + isResizeAdapt: false, + + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, + + rowSize: o.rowSize, + columnSize: o.columnSize, + headerRowSize: o.headerRowSize, + + header: BI.map(o.header, function (i, items) { + return BI.map(items, function (j, item) { + return BI.extend({ + type: "bi.preview_table_header_cell" + }, item); + }); + }), + items: BI.map(o.items, function (i, items) { + return BI.map(items, function (j, item) { + return BI.extend({ + type: "bi.preview_table_cell" + }, item); + }); + }) + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { + self._adjustColumns(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { + self._adjustColumns(); + }); + }, + + // 是否有自适应调节的列,即列宽为"" + _hasAdaptCol: function (columnSize) { + return BI.any(columnSize, function (i, size) { + return size === ""; + }); + }, + + _isPercentage: function (columnSize) { + return columnSize[0] <= 1; + }, + + _adjustColumns: function () { + var self = this, o = this.options; + if (o.isNeedFreeze === true) { + // 如果存在百分比的情况 + if (this._isPercentage(o.columnSize)) { + if (this._hasAdaptCol(o.columnSize)) { + var findCols = [], remain = 0; + BI.each(o.columnSize, function (i, size) { + if (size === "") { + findCols.push(i); + } else { + remain += size; + } + }); + remain = 1 - remain; + var average = remain / findCols.length; + BI.each(findCols, function (i, col) { + o.columnSize[col] = average; + }); + } + var isRight = BI.first(o.freezeCols) !== 0; + var freezeSize = [], notFreezeSize = []; + BI.each(o.columnSize, function (i, size) { + if (o.freezeCols.contains(i)) { + freezeSize.push(size); + } else { + notFreezeSize.push(size); + } + }); + var sumFreezeSize = BI.sum(freezeSize), sumNotFreezeSize = BI.sum(notFreezeSize); + BI.each(freezeSize, function (i, size) { + freezeSize[i] = size / sumFreezeSize; + }); + BI.each(notFreezeSize, function (i, size) { + notFreezeSize[i] = size / sumNotFreezeSize; + }); + this.table.setRegionColumnSize(isRight ? ["fill", sumFreezeSize] : [sumFreezeSize, "fill"]); + this.table.setColumnSize(isRight ? (notFreezeSize.concat(freezeSize)) : (freezeSize.concat(notFreezeSize))); + } + } else { + // 如果存在自适应宽度的列或者是百分比计算的列,需要将整个表宽设为100% + if (this._hasAdaptCol(o.columnSize) || this._isPercentage(o.columnSize)) { + this.table.setRegionColumnSize(["100%"]); + } } - } -}); - -BI.shortcut("bi.page_table_cell", BI.PageTableCell);/** - * 分页表格 - * - * Created by GUY on 2016/2/15. - * @class BI.PageTable - * @extends BI.Widget - */ -BI.PageTable = BI.inherit(BI.Widget, { - - _const: { - scrollWidth: 18, - minScrollWidth: 100 }, - _defaultConfig: function () { - return BI.extend(BI.PageTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-page-table", - el: { - type: "bi.sequence_table" - }, - pager: { - horizontal: { - pages: false, // 总页数 - curr: 1, // 初始化当前页, pages为数字时可用 + setColumnSize: function (columnSize) { + return this.table.setColumnSize(columnSize); + }, - hasPrev: BI.emptyFn, - hasNext: BI.emptyFn, - firstPage: 1, - lastPage: BI.emptyFn - }, - vertical: { - pages: false, // 总页数 - curr: 1, // 初始化当前页, pages为数字时可用 + getColumnSize: function () { + return this.table.getColumnSize(); + }, - hasPrev: BI.emptyFn, - hasNext: BI.emptyFn, - firstPage: 1, - lastPage: BI.emptyFn - } - }, + getCalculateColumnSize: function () { + return this.table.getCalculateColumnSize(); + }, - itemsCreator: BI.emptyFn, + setHeaderColumnSize: function (columnSize) { + return this.table.setHeaderColumnSize(columnSize); + }, - isNeedFreeze: false, // 是否需要冻结单元格 - freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 + setRegionColumnSize: function (columnSize) { + return this.table.setRegionColumnSize(columnSize); + }, - isNeedMerge: false, // 是否需要合并单元格 - mergeCols: [], // 合并的单元格列号 - mergeRule: BI.emptyFn, + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); + }, - columnSize: [], - minColumnSize: [], - maxColumnSize: [], - headerRowSize: 25, - rowSize: 25, + getCalculateRegionColumnSize: function () { + return this.table.getCalculateRegionColumnSize(); + }, - regionColumnSize: [], + getCalculateRegionRowSize: function () { + return this.table.getCalculateRegionRowSize(); + }, - headerCellStyleGetter: BI.emptyFn, - summaryCellStyleGetter: BI.emptyFn, - sequenceCellStyleGetter: BI.emptyFn, + getClientRegionColumnSize: function () { + return this.table.getClientRegionColumnSize(); + }, - header: [], - items: [], // 二维数组 + getScrollRegionColumnSize: function () { + return this.table.getScrollRegionColumnSize(); + }, - // 交叉表头 - crossHeader: [], - crossItems: [] - }); + getScrollRegionRowSize: function () { + return this.table.getScrollRegionRowSize(); }, - _init: function () { - BI.PageTable.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.hCurr = 1; - this.vCurr = 1; + hasVerticalScroll: function () { + return this.table.hasVerticalScroll(); + }, - this.table = BI.createWidget(o.el, { - type: "bi.sequence_table", - width: o.width, - height: o.height && o.height - 30, + setVerticalScroll: function (scrollTop) { + return this.table.setVerticalScroll(scrollTop); + }, - isNeedResize: true, - isResizeAdapt: false, + setLeftHorizontalScroll: function (scrollLeft) { + return this.table.setLeftHorizontalScroll(scrollLeft); + }, - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, + setRightHorizontalScroll: function (scrollLeft) { + return this.table.setRightHorizontalScroll(scrollLeft); + }, - isNeedMerge: o.isNeedMerge, - mergeCols: o.mergeCols, - mergeRule: o.mergeRule, + getVerticalScroll: function () { + return this.table.getVerticalScroll(); + }, - columnSize: o.columnSize, - minColumnSize: o.minColumnSize, - maxColumnSize: o.maxColumnSize, - headerRowSize: o.headerRowSize, - rowSize: o.rowSize, + getLeftHorizontalScroll: function () { + return this.table.getLeftHorizontalScroll(); + }, - regionColumnSize: o.regionColumnSize, + getRightHorizontalScroll: function () { + return this.table.getRightHorizontalScroll(); + }, - headerCellStyleGetter: o.headerCellStyleGetter, - summaryCellStyleGetter: o.summaryCellStyleGetter, - sequenceCellStyleGetter: o.sequenceCellStyleGetter, + getColumns: function () { + return this.table.getColumns(); + }, - header: o.header, - items: o.items, - // 交叉表头 - crossHeader: o.crossHeader, - crossItems: o.crossItems + populate: function (items, header) { + this.table.populate(items, header); + } +}); +BI.PreviewTable.EVENT_CHANGE = "PreviewTable.EVENT_CHANGE"; +BI.shortcut("bi.preview_table", BI.PreviewTable);/** + * 季度下拉框 + * + * Created by GUY on 2015/8/28. + * @class BI.QuarterCombo + * @extends BI.Widget + */ +BI.QuarterCombo = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.QuarterCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-quarter-combo", + behaviors: {}, + height: 25 }); - - this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { - self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }, + _init: function () { + BI.QuarterCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.storeValue = ""; + this.trigger = BI.createWidget({ + type: "bi.quarter_trigger", + value: o.value }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); + + this.trigger.on(BI.QuarterTrigger.EVENT_FOCUS, function () { + self.storeValue = this.getKey(); }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); + this.trigger.on(BI.QuarterTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - - this.pager = BI.createWidget(o.pager, { - type: "bi.direction_pager", - height: 30 + this.trigger.on(BI.QuarterTrigger.EVENT_STOP, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } }); - this.pager.on(BI.Pager.EVENT_CHANGE, function () { - var vpage = this.getVPage && this.getVPage(); - if (BI.isNull(vpage)) { - vpage = this.getCurrentPage(); + this.trigger.on(BI.QuarterTrigger.EVENT_CONFIRM, function () { + if (self.combo.isViewVisible()) { + return; } - var hpage = this.getHPage && this.getHPage(); - o.itemsCreator({ - vpage: vpage, - hpage: hpage - }, function (items, header, crossItems, crossHeader) { - self.table.setVPage ? self.table.setVPage(vpage) : self.table.setValue(vpage); - self.table.setHPage && self.table.setHPage(hpage); - self.populate.apply(self, arguments); - }); + if (this.getKey() && this.getKey() !== self.storeValue) { + self.setValue(this.getKey()); + } else if (!this.getKey()) { + self.setValue(); + } + self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); }); - - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.table, - left: 0, - top: 0 - }, { - el: this.pager, - left: 0, - right: 0, - bottom: 0 - }] + this.popup = BI.createWidget({ + type: "bi.quarter_popup", + behaviors: o.behaviors, + value: o.value }); - }, - - setHPage: function (v) { - this.hCurr = v; - this.pager.setHPage && this.pager.setHPage(v); - this.table.setHPage && this.table.setHPage(v); - }, - - setVPage: function (v) { - this.vCurr = v; - this.pager.setVPage && this.pager.setVPage(v); - this.table.setVPage && this.table.setVPage(v); - }, - getHPage: function () { - var hpage = this.pager.getHPage && this.pager.getHPage(); - if (BI.isNotNull(hpage)) { - return hpage; - } - hpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); - if (BI.isNotNull(hpage)) { - return hpage; - } - return this.hpage; - }, + this.popup.on(BI.QuarterPopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); + }); - getVPage: function () { - var vpage = this.pager.getVPage && this.pager.getVPage(); - if (BI.isNotNull(vpage)) { - return vpage; - } - vpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); - if (BI.isNotNull(vpage)) { - return vpage; - } - return this.vpage; + this.combo = BI.createWidget({ + type: "bi.combo", + element: this, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + el: this.popup + } + }); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW); + }); }, - setWidth: function (width) { - BI.PageTable.superclass.setWidth.apply(this, arguments); - this.table.setWidth(width); + setValue: function (v) { + this.trigger.setValue(v); + this.popup.setValue(v); }, - setHeight: function (height) { - BI.PageTable.superclass.setHeight.apply(this, arguments); - var showPager = false; - if (this.pager.alwaysShowPager) { - showPager = true; - } else if (this.pager.hasHNext && this.pager.hasHNext()) { - showPager = true; - } else if (this.pager.hasHPrev && this.pager.hasHPrev()) { - showPager = true; - } else if (this.pager.hasVNext && this.pager.hasVNext()) { - showPager = true; - } else if (this.pager.hasVPrev && this.pager.hasVPrev()) { - showPager = true; - } else if (this.pager.hasNext && this.pager.hasNext()) { - showPager = true; - } else if (this.pager.hasPrev && this.pager.hasPrev()) { - showPager = true; + getValue: function () { + if (BI.isNull(this.popup)) { + return this.options.value || ""; + } else { + return this.popup.getValue() || ""; } - this.table.setHeight(height - (showPager ? 30 : 0)); - }, + } +}); - setColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setColumnSize(columnSize); - }, +BI.QuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.quarter_combo", BI.QuarterCombo);/** + * 季度展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.QuarterPopup + * @extends BI.Trigger + */ +BI.QuarterPopup = BI.inherit(BI.Widget, { - getColumnSize: function () { - return this.table.getColumnSize(); + _defaultConfig: function () { + return BI.extend(BI.QuarterPopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-quarter-popup", + behaviors: {} + }); }, - setRegionColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setRegionColumnSize(columnSize); - }, + _init: function () { + BI.QuarterPopup.superclass._init.apply(this, arguments); + var self = this, o = this.options; - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); - }, + var items = [{ + text: Date._QN[1], + value: 1 + }, { + text: Date._QN[2], + value: 2 + }, { + text: Date._QN[3], + value: 3 + }, { + text: Date._QN[4], + value: 4 + }]; + items = BI.map(items, function (j, item) { + return BI.extend(item, { + type: "bi.text_item", + cls: "bi-list-item-active", + textAlign: "left", + whiteSpace: "nowrap", + once: false, + forceSelected: true, + height: 25 + }); + }); - getVerticalScroll: function () { - return this.table.getVerticalScroll(); - }, + this.quarter = BI.createWidget({ + type: "bi.button_group", + element: this, + behaviors: o.behaviors, + items: BI.createItems(items, {}), + layouts: [{ + type: "bi.vertical" + }], + value: o.value + }); - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); + this.quarter.on(BI.Controller.EVENT_CHANGE, function (type) { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + if (type === BI.Events.CLICK) { + self.fireEvent(BI.MonthPopup.EVENT_CHANGE); + } + }); }, - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + getValue: function () { + return this.quarter.getValue()[0]; }, - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); + setValue: function (v) { + this.quarter.setValue([v]); + } +}); +BI.QuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.quarter_popup", BI.QuarterPopup);/** + * 季度trigger + * + * Created by GUY on 2015/8/21. + * @class BI.QuarterTrigger + * @extends BI.Trigger + */ +BI.QuarterTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + textWidth: 40, + errorText: BI.i18nText("BI-Quarter_Trigger_Error_Text") }, - restore: function () { - this.table.restore(); + _defaultConfig: function () { + return BI.extend(BI.QuarterTrigger.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-quarter-trigger bi-border", + height: 24 + }); }, + _init: function () { + BI.QuarterTrigger.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) { + return v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 4); + }, + quitChecker: function (v) { + return false; + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true, + errorText: c.errorText + }); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_FOCUS); + }); + this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_CHANGE); + }); + this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setValue(value); + self.editor.setTitle(value); + } + self.fireEvent(BI.QuarterTrigger.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.QuarterTrigger.EVENT_START); + }); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_STOP); + }); - attr: function () { - BI.PageTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); + BI.createWidget({ + element: this, + type: "bi.htape", + items: [ + { + el: this.editor + }, { + el: { + type: "bi.text_button", + baseCls: "bi-trigger-quarter-text", + text: BI.i18nText("BI-Multi_Date_Quarter"), + width: c.textWidth + }, + width: c.textWidth + }, { + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height + } + ] + }); + this.setValue(o.value); }, - populate: function () { - this.pager.populate(); - this.table.populate.apply(this.table, arguments); + setValue: function (v) { + v = v || ""; + this.editor.setState(v); + this.editor.setValue(v); + this.editor.setTitle(v); }, - destroy: function () { - this.table.destroy(); - this.pager && this.pager.destroy(); - BI.PageTable.superclass.destroy.apply(this, arguments); + getKey: function () { + return this.editor.getValue(); } }); -BI.shortcut("bi.page_table", BI.PageTable);/** - * 预览表列 +BI.QuarterTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.QuarterTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.QuarterTrigger.EVENT_START = "EVENT_START"; +BI.QuarterTrigger.EVENT_STOP = "EVENT_STOP"; +BI.QuarterTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.shortcut("bi.quarter_trigger", BI.QuarterTrigger);/** + * 自适应宽度的表格 * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTableCell + * Created by GUY on 2016/2/3. + * @class BI.ResponisveTable * @extends BI.Widget */ -BI.PreviewTableCell = BI.inherit(BI.Widget, { +BI.ResponisveTable = BI.inherit(BI.Widget, { + + _const: { + perColumnSize: 100 + }, _defaultConfig: function () { - return BI.extend(BI.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table-cell", - text: "" + return BI.extend(BI.ResponisveTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-responsive-table", + isNeedFreeze: false, // 是否需要冻结单元格 + freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 + logic: { // 冻结的页面布局逻辑 + dynamic: false + }, + + isNeedMerge: false, // 是否需要合并单元格 + mergeCols: [], // 合并的单元格列号 + mergeRule: function (row1, row2) { // 合并规则, 默认相等时合并 + return BI.isEqual(row1, row2); + }, + + columnSize: [], + headerRowSize: 25, + footerRowSize: 25, + rowSize: 25, + + regionColumnSize: false, + + header: [], + footer: false, + items: [], // 二维数组 + + // 交叉表头 + crossHeader: [], + crossItems: [] }); }, _init: function () { - BI.PreviewTableCell.superclass._init.apply(this, arguments); + BI.ResponisveTable.superclass._init.apply(this, arguments); var self = this, o = this.options; - BI.createWidget({ - type: "bi.label", + this.table = BI.createWidget({ + type: "bi.table_view", element: this, - textAlign: "left", - whiteSpace: "normal", - height: this.options.height, - text: this.options.text, - value: this.options.value + logic: o.logic, + + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, + + isNeedMerge: o.isNeedMerge, + mergeCols: o.mergeCols, + mergeRule: o.mergeRule, + + columnSize: o.columnSize, + headerRowSize: o.headerRowSize, + footerRowSize: o.footerRowSize, + rowSize: o.rowSize, + + regionColumnSize: o.regionColumnSize, + + header: o.header, + footer: o.footer, + items: o.items, + // 交叉表头 + crossHeader: o.crossHeader, + crossItems: o.crossItems + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { + self._initRegionSize(); + self.table.resize(); + self._resizeHeader(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { + self._resizeRegion(); + self._resizeHeader(); + self.fireEvent(BI.Table.EVENT_TABLE_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { + self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_BEFORE_REGION_RESIZE, function () { + self.fireEvent(BI.Table.EVENT_TABLE_BEFORE_REGION_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_REGION_RESIZE, function () { + // important:在冻结并自适应列宽的情况下要随时变更表头宽度 + if (o.isNeedResize === true && self._isAdaptiveColumn()) { + self._resizeHeader(); + } + self.fireEvent(BI.Table.EVENT_TABLE_REGION_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { + self._resizeHeader(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); }); - } -}); -BI.shortcut("bi.preview_table_cell", BI.PreviewTableCell);/** - * 预览表 - * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTableHeaderCell - * @extends BI.Widget - */ -BI.PreviewTableHeaderCell = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.PreviewTableHeaderCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table-header-cell", - text: "" + this.table.on(BI.Table.EVENT_TABLE_BEFORE_COLUMN_RESIZE, function () { + self._resizeBody(); + self.fireEvent(BI.Table.EVENT_TABLE_BEFORE_COLUMN_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_COLUMN_RESIZE, function () { + self.fireEvent(BI.Table.EVENT_TABLE_COLUMN_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { + self._resizeRegion(); + self._resizeHeader(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); }); }, - _init: function () { - BI.PreviewTableHeaderCell.superclass._init.apply(this, arguments); - var self = this, o = this.options; + _initRegionSize: function () { + var o = this.options; + if (o.isNeedFreeze === true) { + var regionColumnSize = this.table.getRegionColumnSize(); + var maxWidth = this.table.element.width(); + if (!regionColumnSize[0] || (regionColumnSize[0] === "fill") || regionColumnSize[0] > maxWidth || regionColumnSize[1] > maxWidth) { + var freezeCols = o.freezeCols; + if (freezeCols.length === 0) { + this.table.setRegionColumnSize([0, "fill"]); + } else if (freezeCols.length > 0 && freezeCols.length < o.columnSize.length) { + var size = maxWidth / 3; + if (freezeCols.length > o.columnSize.length / 2) { + size = maxWidth * 2 / 3; + } + this.table.setRegionColumnSize([size, "fill"]); + } else { + this.table.setRegionColumnSize(["fill", 0]); + } + } + } + }, - BI.createWidget({ - type: "bi.label", - element: this, - textAlign: "left", - whiteSpace: "normal", - height: this.options.height, - text: this.options.text, - value: this.options.value - }); - } -}); -BI.shortcut("bi.preview_table_header_cell", BI.PreviewTableHeaderCell);/** - * 预览表 - * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTable - * @extends BI.Widget - */ -BI.PreviewTable = BI.inherit(BI.Widget, { + _getBlockSize: function () { + var o = this.options; + var columnSize = this.table.getCalculateColumnSize(); + if (o.isNeedFreeze === true) { + var columnSizeLeft = [], columnSizeRight = []; + BI.each(columnSize, function (i, size) { + if (o.freezeCols.contains(i)) { + columnSizeLeft.push(size); + } else { + columnSizeRight.push(size); + } + }); + // 因为有边框,所以加上数组长度的参数调整 + var sumLeft = BI.sum(columnSizeLeft) + columnSizeLeft.length, + sumRight = BI.sum(columnSizeRight) + columnSizeRight.length; + return { + sumLeft: sumLeft, + sumRight: sumRight, + left: columnSizeLeft, + right: columnSizeRight + }; + } + return { + size: columnSize, + sum: BI.sum(columnSize) + columnSize.length + }; + }, - _defaultConfig: function () { - return BI.extend(BI.PreviewTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table", - isNeedFreeze: false, - freezeCols: [], - rowSize: null, - columnSize: [], - headerRowSize: 30, - header: [], - items: [] - }); + _isAdaptiveColumn: function (columnSize) { + return !(BI.last(columnSize || this.table.getColumnSize()) > 1.05); }, - _init: function () { - BI.PreviewTable.superclass._init.apply(this, arguments); + _resizeHeader: function () { var self = this, o = this.options; + if (o.isNeedFreeze === true) { + // 若是当前处于自适应调节阶段 + if (this._isAdaptiveColumn()) { + var columnSize = this.table.getCalculateColumnSize(); + this.table.setHeaderColumnSize(columnSize); + } else { + var regionColumnSize = this.table.getClientRegionColumnSize(); + var block = this._getBlockSize(); + var sumLeft = block.sumLeft, sumRight = block.sumRight; + var columnSizeLeft = block.left, columnSizeRight = block.right; + columnSizeLeft[columnSizeLeft.length - 1] += regionColumnSize[0] - sumLeft; + columnSizeRight[columnSizeRight.length - 1] += regionColumnSize[1] - sumRight; - this.table = BI.createWidget({ - type: "bi.table_view", - element: this, - isNeedResize: false, + var newLeft = BI.clone(columnSizeLeft), newRight = BI.clone(columnSizeRight); + newLeft[newLeft.length - 1] = ""; + newRight[newRight.length - 1] = ""; + this.table.setColumnSize(newLeft.concat(newRight)); - isResizeAdapt: false, + block = self._getBlockSize(); + if (columnSizeLeft[columnSizeLeft.length - 1] < block.left[block.left.length - 1]) { + columnSizeLeft[columnSizeLeft.length - 1] = block.left[block.left.length - 1]; + } + if (columnSizeRight[columnSizeRight.length - 1] < block.right[block.right.length - 1]) { + columnSizeRight[columnSizeRight.length - 1] = block.right[block.right.length - 1]; + } - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, + self.table.setColumnSize(columnSizeLeft.concat(columnSizeRight)); + } + } else { + if (!this._isAdaptiveColumn()) { + var regionColumnSize = this.table.getClientRegionColumnSize(); + var block = this._getBlockSize(); + var sum = block.sum; + var size = block.size; - rowSize: o.rowSize, - columnSize: o.columnSize, - headerRowSize: o.headerRowSize, + size[size.length - 1] += regionColumnSize[0] - sum; - header: BI.map(o.header, function (i, items) { - return BI.map(items, function (j, item) { - return BI.extend({ - type: "bi.preview_table_header_cell" - }, item); - }); - }), - items: BI.map(o.items, function (i, items) { - return BI.map(items, function (j, item) { - return BI.extend({ - type: "bi.preview_table_cell" - }, item); - }); - }) - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { - self._adjustColumns(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { - self._adjustColumns(); - }); + var newSize = BI.clone(size); + newSize[newSize.length - 1] = ""; + this.table.setColumnSize(newSize); + block = this._getBlockSize(); + + if (size[size.length - 1] < block.size[block.size.length - 1]) { + size[size.length - 1] = block.size[block.size.length - 1]; + } + this.table.setColumnSize(size); + } + } }, - // 是否有自适应调节的列,即列宽为"" - _hasAdaptCol: function (columnSize) { - return BI.any(columnSize, function (i, size) { - return size === ""; - }); + _resizeBody: function () { + if (this._isAdaptiveColumn()) { + var columnSize = this.table.getCalculateColumnSize(); + this.setColumnSize(columnSize); + } }, - _isPercentage: function (columnSize) { - return columnSize[0] <= 1; + _adjustRegion: function () { + var o = this.options; + var regionColumnSize = this.table.getCalculateRegionColumnSize(); + if (o.isNeedFreeze === true && o.freezeCols.length > 0 && o.freezeCols.length < o.columnSize.length) { + var block = this._getBlockSize(); + var sumLeft = block.sumLeft, sumRight = block.sumRight; + if (sumLeft < regionColumnSize[0] || regionColumnSize[0] >= (sumLeft + sumRight)) { + this.table.setRegionColumnSize([sumLeft, "fill"]); + } + this._resizeRegion(); + } }, - _adjustColumns: function () { - var self = this, o = this.options; - if (o.isNeedFreeze === true) { - // 如果存在百分比的情况 - if (this._isPercentage(o.columnSize)) { - if (this._hasAdaptCol(o.columnSize)) { - var findCols = [], remain = 0; - BI.each(o.columnSize, function (i, size) { - if (size === "") { - findCols.push(i); - } else { - remain += size; - } - }); - remain = 1 - remain; - var average = remain / findCols.length; - BI.each(findCols, function (i, col) { - o.columnSize[col] = average; - }); + _resizeRegion: function () { + var o = this.options; + var regionColumnSize = this.table.getCalculateRegionColumnSize(); + if (o.isNeedFreeze === true && o.freezeCols.length > 0 && o.freezeCols.length < o.columnSize.length) { + var maxWidth = this.table.element.width(); + if (regionColumnSize[0] < 15 || regionColumnSize[1] < 15) { + var freezeCols = o.freezeCols; + var size = maxWidth / 3; + if (freezeCols.length > o.columnSize.length / 2) { + size = maxWidth * 2 / 3; } - var isRight = BI.first(o.freezeCols) !== 0; - var freezeSize = [], notFreezeSize = []; - BI.each(o.columnSize, function (i, size) { - if (o.freezeCols.contains(i)) { - freezeSize.push(size); - } else { - notFreezeSize.push(size); - } - }); - var sumFreezeSize = BI.sum(freezeSize), sumNotFreezeSize = BI.sum(notFreezeSize); - BI.each(freezeSize, function (i, size) { - freezeSize[i] = size / sumFreezeSize; - }); - BI.each(notFreezeSize, function (i, size) { - notFreezeSize[i] = size / sumNotFreezeSize; - }); - this.table.setRegionColumnSize(isRight ? ["fill", sumFreezeSize] : [sumFreezeSize, "fill"]); - this.table.setColumnSize(isRight ? (notFreezeSize.concat(freezeSize)) : (freezeSize.concat(notFreezeSize))); - } - } else { - // 如果存在自适应宽度的列或者是百分比计算的列,需要将整个表宽设为100% - if (this._hasAdaptCol(o.columnSize) || this._isPercentage(o.columnSize)) { - this.table.setRegionColumnSize(["100%"]); + this.table.setRegionColumnSize([size, "fill"]); } } }, + + resize: function () { + this.table.resize(); + this._resizeRegion(); + this._resizeHeader(); + }, + setColumnSize: function (columnSize) { - return this.table.setColumnSize(columnSize); + this.table.setColumnSize(columnSize); + this._adjustRegion(); + this._resizeHeader(); }, getColumnSize: function () { @@ -103602,11 +100896,14 @@ BI.PreviewTable = BI.inherit(BI.Widget, { }, setHeaderColumnSize: function (columnSize) { - return this.table.setHeaderColumnSize(columnSize); + this.table.setHeaderColumnSize(columnSize); + this._adjustRegion(); + this._resizeHeader(); }, setRegionColumnSize: function (columnSize) { - return this.table.setRegionColumnSize(columnSize); + this.table.setRegionColumnSize(columnSize); + this._resizeHeader(); }, getRegionColumnSize: function () { @@ -103638,15 +100935,15 @@ BI.PreviewTable = BI.inherit(BI.Widget, { }, setVerticalScroll: function (scrollTop) { - return this.table.setVerticalScroll(scrollTop); + this.table.setVerticalScroll(scrollTop); }, setLeftHorizontalScroll: function (scrollLeft) { - return this.table.setLeftHorizontalScroll(scrollLeft); + this.table.setLeftHorizontalScroll(scrollLeft); }, setRightHorizontalScroll: function (scrollLeft) { - return this.table.setRightHorizontalScroll(scrollLeft); + this.table.setRightHorizontalScroll(scrollLeft); }, getVerticalScroll: function () { @@ -103661,1725 +100958,1844 @@ BI.PreviewTable = BI.inherit(BI.Widget, { return this.table.getRightHorizontalScroll(); }, - getColumns: function () { - return this.table.getColumns(); + getColumns: function () { + return this.table.getColumns(); + }, + + attr: function () { + BI.ResponisveTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); + }, + + populate: function (items) { + var self = this, o = this.options; + this.table.populate.apply(this.table, arguments); + if (o.isNeedFreeze === true) { + BI.nextTick(function () { + self._initRegionSize(); + self.table.resize(); + self._resizeHeader(); + }); + } + } +}); +BI.shortcut("bi.responsive_table", BI.ResponisveTable);/** + * 加号表示的组节点 + * Created by GUY on 2015/9/6. + * @class BI.SelectTreeFirstPlusGroupNode + * @extends BI.NodeButton + */ +BI.SelectTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { + _defaultConfig: function () { + var conf = BI.SelectTreeFirstPlusGroupNode.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-select-tree-first-plus-group-node bi-list-item-active", + logic: { + dynamic: false + }, + id: "", + pId: "", + readonly: true, + open: false, + height: 25 + }); + }, + _init: function () { + BI.SelectTreeFirstPlusGroupNode.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.checkbox = BI.createWidget({ + type: "bi.first_tree_node_checkbox", + stopPropagation: true + }); + this.text = BI.createWidget({ + type: "bi.label", + textAlign: "left", + whiteSpace: "nowrap", + textHeight: o.height, + height: o.height, + hgap: o.hgap, + text: o.text, + value: o.value, + py: o.py + }); + this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + if (this.isSelected()) { + self.triggerExpand(); + } else { + self.triggerCollapse(); + } + } + }); + var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); + var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { + width: 25, + el: this.checkbox + }, this.text); + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { + items: items + })))); + }, + + isOnce: function () { + return true; + }, + + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); + }, + + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); + }, + + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); }, - populate: function (items, header) { - this.table.populate(items, header); + setOpened: function (v) { + BI.SelectTreeFirstPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } } }); -BI.PreviewTable.EVENT_CHANGE = "PreviewTable.EVENT_CHANGE"; -BI.shortcut("bi.preview_table", BI.PreviewTable);/** - * 季度下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.QuarterCombo - * @extends BI.Widget + +BI.shortcut("bi.select_tree_first_plus_group_node", BI.SelectTreeFirstPlusGroupNode);/** + * 加号表示的组节点 + * Created by GUY on 2015/9/6. + * @class BI.SelectTreeLastPlusGroupNode + * @extends BI.NodeButton */ -BI.QuarterCombo = BI.inherit(BI.Widget, { +BI.SelectTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, { _defaultConfig: function () { - return BI.extend(BI.QuarterCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-quarter-combo", - behaviors: {}, + var conf = BI.SelectTreeLastPlusGroupNode.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-select-tree-last-plus-group-node bi-list-item-active", + logic: { + dynamic: false + }, + id: "", + pId: "", + readonly: true, + open: false, height: 25 }); }, _init: function () { - BI.QuarterCombo.superclass._init.apply(this, arguments); + BI.SelectTreeLastPlusGroupNode.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.storeValue = ""; - this.trigger = BI.createWidget({ - type: "bi.quarter_trigger", - value: o.value - }); - - this.trigger.on(BI.QuarterTrigger.EVENT_FOCUS, function () { - self.storeValue = this.getKey(); - }); - this.trigger.on(BI.QuarterTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); + this.checkbox = BI.createWidget({ + type: "bi.last_tree_node_checkbox", + stopPropagation: true }); - this.trigger.on(BI.QuarterTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } + this.text = BI.createWidget({ + type: "bi.label", + textAlign: "left", + whiteSpace: "nowrap", + textHeight: o.height, + height: o.height, + hgap: o.hgap, + text: o.text, + value: o.value, + py: o.py }); - this.trigger.on(BI.QuarterTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; - } - if (this.getKey() && this.getKey() !== self.storeValue) { - self.setValue(this.getKey()); - } else if (!this.getKey()) { - self.setValue(); + this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + if (this.isSelected()) { + self.triggerExpand(); + } else { + self.triggerCollapse(); + } } - self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); - }); - this.popup = BI.createWidget({ - type: "bi.quarter_popup", - behaviors: o.behaviors, - value: o.value }); + var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); + var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { + width: 25, + el: this.checkbox + }, this.text); + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { + items: items + })))); + }, - this.popup.on(BI.QuarterPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); - }); + isOnce: function () { + return true; + }, - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - el: this.popup - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW); - }); + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); }, - setValue: function (v) { - this.trigger.setValue(v); - this.popup.setValue(v); + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - getValue: function () { - if (BI.isNull(this.popup)) { - return this.options.value || ""; - } else { - return this.popup.getValue() || ""; + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); + }, + + setOpened: function (v) { + BI.SelectTreeLastPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); } } }); -BI.QuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.quarter_combo", BI.QuarterCombo);/** - * 季度展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.QuarterPopup - * @extends BI.Trigger +BI.shortcut("bi.select_tree_last_plus_group_node", BI.SelectTreeLastPlusGroupNode);/** + * 加号表示的组节点 + * Created by GUY on 2015/9/6. + * @class BI.SelectTreeMidPlusGroupNode + * @extends BI.NodeButton */ -BI.QuarterPopup = BI.inherit(BI.Widget, { - +BI.SelectTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, { _defaultConfig: function () { - return BI.extend(BI.QuarterPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-quarter-popup", - behaviors: {} + var conf = BI.SelectTreeMidPlusGroupNode.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-select-tree-mid-plus-group-node bi-list-item-active", + logic: { + dynamic: false + }, + id: "", + pId: "", + readonly: true, + open: false, + height: 25 }); }, - _init: function () { - BI.QuarterPopup.superclass._init.apply(this, arguments); + BI.SelectTreeMidPlusGroupNode.superclass._init.apply(this, arguments); var self = this, o = this.options; - - var items = [{ - text: Date._QN[1], - value: 1 - }, { - text: Date._QN[2], - value: 2 - }, { - text: Date._QN[3], - value: 3 - }, { - text: Date._QN[4], - value: 4 - }]; - items = BI.map(items, function (j, item) { - return BI.extend(item, { - type: "bi.text_item", - cls: "bi-list-item-active", - textAlign: "left", - whiteSpace: "nowrap", - once: false, - forceSelected: true, - height: 25 - }); + this.checkbox = BI.createWidget({ + type: "bi.mid_tree_node_checkbox", + stopPropagation: true }); - - this.quarter = BI.createWidget({ - type: "bi.button_group", - element: this, - behaviors: o.behaviors, - items: BI.createItems(items, {}), - layouts: [{ - type: "bi.vertical" - }], - value: o.value + this.text = BI.createWidget({ + type: "bi.label", + textAlign: "left", + whiteSpace: "nowrap", + textHeight: o.height, + height: o.height, + hgap: o.hgap, + text: o.text, + value: o.value, + py: o.py }); - - this.quarter.on(BI.Controller.EVENT_CHANGE, function (type) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) { - self.fireEvent(BI.MonthPopup.EVENT_CHANGE); + if (this.isSelected()) { + self.triggerExpand(); + } else { + self.triggerCollapse(); + } } }); + var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); + var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { + width: 25, + el: this.checkbox + }, this.text); + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { + items: items + })))); + }, + + isOnce: function () { + return true; + }, + + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); + }, + + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - getValue: function () { - return this.quarter.getValue()[0]; + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); }, - setValue: function (v) { - this.quarter.setValue([v]); + setOpened: function (v) { + BI.SelectTreeMidPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } } }); -BI.QuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.quarter_popup", BI.QuarterPopup);/** - * 季度trigger - * - * Created by GUY on 2015/8/21. - * @class BI.QuarterTrigger - * @extends BI.Trigger + +BI.shortcut("bi.select_tree_mid_plus_group_node", BI.SelectTreeMidPlusGroupNode);/** + * @class BI.SelectTreeCombo + * @extends BI.Widget */ -BI.QuarterTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - textWidth: 40, - errorText: BI.i18nText("BI-Quarter_Trigger_Error_Text") - }, +BI.SelectTreeCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.QuarterTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-quarter-trigger bi-border", - height: 24 + return BI.extend(BI.SelectTreeCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-tree-combo", + height: 30, + text: "", + items: [], + value: "" }); }, + _init: function () { - BI.QuarterTrigger.superclass._init.apply(this, arguments); - var self = this, o = this.options, c = this._const; - this.editor = BI.createWidget({ - type: "bi.sign_editor", + BI.SelectTreeCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.trigger = BI.createWidget({ + type: "bi.single_tree_trigger", + text: o.text, height: o.height, - validationChecker: function (v) { - return v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 4); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true, - errorText: c.errorText - }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_FOCUS); - }); - this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_CHANGE); + items: o.items, + value: o.value }); - this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - self.editor.setTitle(value); - } - self.fireEvent(BI.QuarterTrigger.EVENT_CONFIRM); + + this.popup = BI.createWidget({ + type: "bi.select_level_tree", + items: o.items, + value: o.value }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); + + this.combo = BI.createWidget({ + type: "bi.combo", + element: this, + adjustLength: 2, + el: this.trigger, + popup: { + el: this.popup } }); - this.editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_START); - }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_STOP); + + this.combo.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [ - { - el: this.editor - }, { - el: { - type: "bi.text_button", - baseCls: "bi-trigger-quarter-text", - text: BI.i18nText("BI-Multi_Date_Quarter"), - width: c.textWidth - }, - width: c.textWidth - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - } - ] + this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); }); - this.setValue(o.value); }, setValue: function (v) { - v = v || ""; - this.editor.setState(v); - this.editor.setValue(v); - this.editor.setTitle(v); + v = BI.isArray(v) ? v : [v]; + this.trigger.setValue(v); + this.popup.setValue(v); }, - getKey: function () { - return this.editor.getValue(); + getValue: function () { + return this.popup.getValue(); + }, + + populate: function (items) { + this.combo.populate(items); } }); -BI.QuarterTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.QuarterTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.QuarterTrigger.EVENT_START = "EVENT_START"; -BI.QuarterTrigger.EVENT_STOP = "EVENT_STOP"; -BI.QuarterTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.shortcut("bi.quarter_trigger", BI.QuarterTrigger);/** - * 自适应宽度的表格 - * - * Created by GUY on 2016/2/3. - * @class BI.ResponisveTable + + +BI.shortcut("bi.select_tree_combo", BI.SelectTreeCombo);/** + * @class BI.SelectTreeExpander * @extends BI.Widget */ -BI.ResponisveTable = BI.inherit(BI.Widget, { - - _const: { - perColumnSize: 100 - }, +BI.SelectTreeExpander = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.ResponisveTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-responsive-table", - isNeedFreeze: false, // 是否需要冻结单元格 - freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 - logic: { // 冻结的页面布局逻辑 - dynamic: false - }, - - isNeedMerge: false, // 是否需要合并单元格 - mergeCols: [], // 合并的单元格列号 - mergeRule: function (row1, row2) { // 合并规则, 默认相等时合并 - return BI.isEqual(row1, row2); - }, - - columnSize: [], - headerRowSize: 25, - footerRowSize: 25, - rowSize: 25, - - regionColumnSize: false, - - header: [], - footer: false, - items: [], // 二维数组 - - // 交叉表头 - crossHeader: [], - crossItems: [] + return BI.extend(BI.SelectTreeExpander.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-tree-expander", + trigger: "click", + toggle: true, + direction: "bottom", + isDefaultInit: true, + el: {}, + popup: {} }); }, _init: function () { - BI.ResponisveTable.superclass._init.apply(this, arguments); + BI.SelectTreeExpander.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.table = BI.createWidget({ - type: "bi.table_view", - element: this, - logic: o.logic, - - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, - - isNeedMerge: o.isNeedMerge, - mergeCols: o.mergeCols, - mergeRule: o.mergeRule, - - columnSize: o.columnSize, - headerRowSize: o.headerRowSize, - footerRowSize: o.footerRowSize, - rowSize: o.rowSize, - - regionColumnSize: o.regionColumnSize, - - header: o.header, - footer: o.footer, - items: o.items, - // 交叉表头 - crossHeader: o.crossHeader, - crossItems: o.crossItems - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { - self._initRegionSize(); - self.table.resize(); - self._resizeHeader(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { - self._resizeRegion(); - self._resizeHeader(); - self.fireEvent(BI.Table.EVENT_TABLE_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { - self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_BEFORE_REGION_RESIZE, function () { - self.fireEvent(BI.Table.EVENT_TABLE_BEFORE_REGION_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_REGION_RESIZE, function () { - // important:在冻结并自适应列宽的情况下要随时变更表头宽度 - if (o.isNeedResize === true && self._isAdaptiveColumn()) { - self._resizeHeader(); - } - self.fireEvent(BI.Table.EVENT_TABLE_REGION_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { - self._resizeHeader(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); + this.trigger = BI.createWidget(BI.extend({stopPropagation: true}, o.el)); + this.trigger.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + if (this.isSelected()) { + self.expander.setValue([]); + } + } + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.table.on(BI.Table.EVENT_TABLE_BEFORE_COLUMN_RESIZE, function () { - self._resizeBody(); - self.fireEvent(BI.Table.EVENT_TABLE_BEFORE_COLUMN_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_COLUMN_RESIZE, function () { - self.fireEvent(BI.Table.EVENT_TABLE_COLUMN_RESIZE, arguments); + this.expander = BI.createWidget({ + type: "bi.expander", + element: this, + trigger: o.trigger, + toggle: o.toggle, + direction: o.direction, + isDefaultInit: o.isDefaultInit, + el: this.trigger, + popup: o.popup }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { - self._resizeRegion(); - self._resizeHeader(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); + this.expander.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + self.trigger.setSelected(false); + } + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); }, - _initRegionSize: function () { - var o = this.options; - if (o.isNeedFreeze === true) { - var regionColumnSize = this.table.getRegionColumnSize(); - var maxWidth = this.table.element.width(); - if (!regionColumnSize[0] || (regionColumnSize[0] === "fill") || regionColumnSize[0] > maxWidth || regionColumnSize[1] > maxWidth) { - var freezeCols = o.freezeCols; - if (freezeCols.length === 0) { - this.table.setRegionColumnSize([0, "fill"]); - } else if (freezeCols.length > 0 && freezeCols.length < o.columnSize.length) { - var size = maxWidth / 3; - if (freezeCols.length > o.columnSize.length / 2) { - size = maxWidth * 2 / 3; - } - this.table.setRegionColumnSize([size, "fill"]); - } else { - this.table.setRegionColumnSize(["fill", 0]); - } - } + setValue: function (v) { + if (BI.contains(v, this.trigger.getValue())) { + this.trigger.setSelected(true); + this.expander.setValue([]); + } else { + this.trigger.setSelected(false); + this.expander.setValue(v); } }, - _getBlockSize: function () { - var o = this.options; - var columnSize = this.table.getCalculateColumnSize(); - if (o.isNeedFreeze === true) { - var columnSizeLeft = [], columnSizeRight = []; - BI.each(columnSize, function (i, size) { - if (o.freezeCols.contains(i)) { - columnSizeLeft.push(size); - } else { - columnSizeRight.push(size); - } - }); - // 因为有边框,所以加上数组长度的参数调整 - var sumLeft = BI.sum(columnSizeLeft) + columnSizeLeft.length, - sumRight = BI.sum(columnSizeRight) + columnSizeRight.length; - return { - sumLeft: sumLeft, - sumRight: sumRight, - left: columnSizeLeft, - right: columnSizeRight - }; + getValue: function () { + if (this.trigger.isSelected()) { + return [this.trigger.getValue()]; } - return { - size: columnSize, - sum: BI.sum(columnSize) + columnSize.length - }; + return this.expander.getValue(); }, - _isAdaptiveColumn: function (columnSize) { - return !(BI.last(columnSize || this.table.getColumnSize()) > 1.05); - }, + populate: function (items) { + this.expander.populate(items); + } +}); - _resizeHeader: function () { - var self = this, o = this.options; - if (o.isNeedFreeze === true) { - // 若是当前处于自适应调节阶段 - if (this._isAdaptiveColumn()) { - var columnSize = this.table.getCalculateColumnSize(); - this.table.setHeaderColumnSize(columnSize); - } else { - var regionColumnSize = this.table.getClientRegionColumnSize(); - var block = this._getBlockSize(); - var sumLeft = block.sumLeft, sumRight = block.sumRight; - var columnSizeLeft = block.left, columnSizeRight = block.right; - columnSizeLeft[columnSizeLeft.length - 1] += regionColumnSize[0] - sumLeft; - columnSizeRight[columnSizeRight.length - 1] += regionColumnSize[1] - sumRight; +BI.shortcut("bi.select_tree_expander", BI.SelectTreeExpander);/** + * @class BI.SelectTreePopup + * @extends BI.Pane + */ - var newLeft = BI.clone(columnSizeLeft), newRight = BI.clone(columnSizeRight); - newLeft[newLeft.length - 1] = ""; - newRight[newRight.length - 1] = ""; - this.table.setColumnSize(newLeft.concat(newRight)); +BI.SelectTreePopup = BI.inherit(BI.Pane, { - block = self._getBlockSize(); - if (columnSizeLeft[columnSizeLeft.length - 1] < block.left[block.left.length - 1]) { - columnSizeLeft[columnSizeLeft.length - 1] = block.left[block.left.length - 1]; + _defaultConfig: function () { + return BI.extend(BI.SelectTreePopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-level-tree", + tipText: BI.i18nText("BI-No_Selected_Item"), + items: [], + value: "" + }); + }, + + _formatItems: function (nodes, layer) { + var self = this; + BI.each(nodes, function (i, node) { + var extend = {layer: layer}; + node.id = node.id || BI.UUID(); + if (node.isParent === true || BI.isNotEmptyArray(node.children)) { + switch (i) { + case 0 : + extend.type = "bi.select_tree_first_plus_group_node"; + break; + case nodes.length - 1 : + extend.type = "bi.select_tree_last_plus_group_node"; + break; + default : + extend.type = "bi.select_tree_mid_plus_group_node"; + break; } - if (columnSizeRight[columnSizeRight.length - 1] < block.right[block.right.length - 1]) { - columnSizeRight[columnSizeRight.length - 1] = block.right[block.right.length - 1]; + BI.defaults(node, extend); + self._formatItems(node.children); + } else { + switch (i) { + case nodes.length - 1: + extend.type = "bi.last_tree_leaf_item"; + break; + default : + extend.type = "bi.mid_tree_leaf_item"; } - - self.table.setColumnSize(columnSizeLeft.concat(columnSizeRight)); + BI.defaults(node, extend); } - } else { - if (!this._isAdaptiveColumn()) { - var regionColumnSize = this.table.getClientRegionColumnSize(); - var block = this._getBlockSize(); - var sum = block.sum; - var size = block.size; + }); + return nodes; + }, - size[size.length - 1] += regionColumnSize[0] - sum; + _init: function () { + BI.SelectTreePopup.superclass._init.apply(this, arguments); - var newSize = BI.clone(size); - newSize[newSize.length - 1] = ""; - this.table.setColumnSize(newSize); - block = this._getBlockSize(); + var self = this, o = this.options; - if (size[size.length - 1] < block.size[block.size.length - 1]) { - size[size.length - 1] = block.size[block.size.length - 1]; - } - this.table.setColumnSize(size); - } - } + this.tree = BI.createWidget({ + type: "bi.level_tree", + expander: { + type: "bi.select_tree_expander", + isDefaultInit: true + }, + items: this._formatItems(BI.Tree.transformToTreeFormat(o.items)), + value: o.value, + chooseType: BI.Selection.Single + }); + + BI.createWidget({ + type: "bi.vertical", + element: this, + items: [this.tree] + }); + + this.tree.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SelectTreePopup.EVENT_CHANGE); + }); + + this.check(); }, - _resizeBody: function () { - if (this._isAdaptiveColumn()) { - var columnSize = this.table.getCalculateColumnSize(); - this.setColumnSize(columnSize); - } + getValue: function () { + return this.tree.getValue(); }, - _adjustRegion: function () { - var o = this.options; - var regionColumnSize = this.table.getCalculateRegionColumnSize(); - if (o.isNeedFreeze === true && o.freezeCols.length > 0 && o.freezeCols.length < o.columnSize.length) { - var block = this._getBlockSize(); - var sumLeft = block.sumLeft, sumRight = block.sumRight; - if (sumLeft < regionColumnSize[0] || regionColumnSize[0] >= (sumLeft + sumRight)) { - this.table.setRegionColumnSize([sumLeft, "fill"]); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.tree.setValue(v); + }, + + populate: function (items) { + BI.SelectTreePopup.superclass.populate.apply(this, arguments); + this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(items))); + } +}); + +BI.SelectTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.select_level_tree", BI.SelectTreePopup);/** + * + * Created by GUY on 2016/8/10. + * @class BI.SequenceTableDynamicNumber + * @extends BI.SequenceTableTreeNumber + */ +BI.SequenceTableDynamicNumber = BI.inherit(BI.SequenceTableTreeNumber, { + + _defaultConfig: function () { + return BI.extend(BI.SequenceTableDynamicNumber.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-sequence-table-dynamic-number" + }); + }, + + _init: function () { + BI.SequenceTableDynamicNumber.superclass._init.apply(this, arguments); + }, + + _formatNumber: function (nodes) { + var self = this, o = this.options; + var result = []; + var count = this._getStart(nodes); + + function getLeafCount (node) { + var cnt = 0; + if (BI.isNotEmptyArray(node.children)) { + BI.each(node.children, function (index, child) { + cnt += getLeafCount(child); + }); + if (node.children.length > 1 && BI.isNotEmptyArray(node.values)) { + cnt++; + } + } else { + cnt++; } - this._resizeRegion(); + return cnt; } - }, - _resizeRegion: function () { - var o = this.options; - var regionColumnSize = this.table.getCalculateRegionColumnSize(); - if (o.isNeedFreeze === true && o.freezeCols.length > 0 && o.freezeCols.length < o.columnSize.length) { - var maxWidth = this.table.element.width(); - if (regionColumnSize[0] < 15 || regionColumnSize[1] < 15) { - var freezeCols = o.freezeCols; - var size = maxWidth / 3; - if (freezeCols.length > o.columnSize.length / 2) { - size = maxWidth * 2 / 3; + var start = 0, top = 0; + BI.each(nodes, function (i, node) { + if (BI.isArray(node.children)) { + BI.each(node.children, function (index, child) { + var cnt = getLeafCount(child); + result.push({ + text: count++, + start: start, + top: top, + cnt: cnt, + index: index, + height: cnt * o.rowSize + }); + start += cnt; + top += cnt * o.rowSize; + }); + if (BI.isNotEmptyArray(node.values)) { + result.push({ + text: BI.i18nText("BI-Summary_Values"), + start: start++, + top: top, + cnt: 1, + isSummary: true, + height: o.rowSize + }); + top += o.rowSize; } - this.table.setRegionColumnSize([size, "fill"]); } - } - }, + }); + return result; + } +}); +BI.shortcut("bi.sequence_table_dynamic_number", BI.SequenceTableDynamicNumber);/** + * + * Created by GUY on 2016/5/26. + * @class BI.SequenceTableListNumber + * @extends BI.Widget + */ +BI.SequenceTableListNumber = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.SequenceTableListNumber.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-sequence-table-list-number", + isNeedFreeze: false, + scrollTop: 0, + startSequence: 1, // 开始的序号 + headerRowSize: 25, + rowSize: 25, - resize: function () { - this.table.resize(); - this._resizeRegion(); - this._resizeHeader(); - }, + sequenceHeaderCreator: null, - setColumnSize: function (columnSize) { - this.table.setColumnSize(columnSize); - this._adjustRegion(); - this._resizeHeader(); - }, + header: [], + items: [], // 二维数组 - getColumnSize: function () { - return this.table.getColumnSize(); - }, + // 交叉表头 + crossHeader: [], + crossItems: [], - getCalculateColumnSize: function () { - return this.table.getCalculateColumnSize(); + pageSize: 20 + }); }, - setHeaderColumnSize: function (columnSize) { - this.table.setHeaderColumnSize(columnSize); - this._adjustRegion(); - this._resizeHeader(); - }, + _init: function () { + BI.SequenceTableListNumber.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.start = o.startSequence; + this.renderedCells = []; + this.renderedKeys = []; - setRegionColumnSize: function (columnSize) { - this.table.setRegionColumnSize(columnSize); - this._resizeHeader(); - }, + this.container = BI.createWidget({ + type: "bi.absolute", + width: 60, + scrollable: false + }); - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); - }, + this.scrollContainer = BI.createWidget({ + type: "bi.vertical", + scrollable: false, + scrolly: false, + items: [this.container] + }); - getCalculateRegionColumnSize: function () { - return this.table.getCalculateRegionColumnSize(); - }, + this.headerContainer = BI.createWidget({ + type: "bi.absolute", + cls: "bi-border", + width: 58, + scrollable: false + }); - getCalculateRegionRowSize: function () { - return this.table.getCalculateRegionRowSize(); + this.layout = BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.headerContainer, + height: o.headerRowSize * o.header.length - 2 + }, { + el: {type: "bi.layout"}, + height: 2 + }, { + el: this.scrollContainer + }] + }); + this._populate(); }, - getClientRegionColumnSize: function () { - return this.table.getClientRegionColumnSize(); + _layout: function () { + var self = this, o = this.options; + var headerHeight = o.headerRowSize * o.header.length - 2; + var items = this.layout.attr("items"); + if (o.isNeedFreeze === false) { + items[0].height = 0; + items[1].height = 0; + } else if (o.isNeedFreeze === true) { + items[0].height = headerHeight; + items[1].height = 2; + } + this.layout.attr("items", items); + this.layout.resize(); + this.container.setHeight(o.items.length * o.rowSize); + try { + this.scrollContainer.element.scrollTop(o.scrollTop); + } catch (e) { + + } }, - getScrollRegionColumnSize: function () { - return this.table.getScrollRegionColumnSize(); + _createHeader: function () { + var o = this.options; + BI.createWidget({ + type: "bi.absolute", + element: this.headerContainer, + items: [{ + el: o.sequenceHeaderCreator || { + type: "bi.table_style_cell", + cls: "sequence-table-title-cell", + styleGetter: o.headerCellStyleGetter, + text: BI.i18nText("BI-Number_Index") + }, + left: 0, + top: 0, + right: 0, + bottom: 0 + }] + }); }, - getScrollRegionRowSize: function () { - return this.table.getScrollRegionRowSize(); + _calculateChildrenToRender: function () { + var self = this, o = this.options; + var scrollTop = BI.clamp(o.scrollTop, 0, o.rowSize * o.items.length - (o.height - o.header.length * o.headerRowSize) + BI.DOM.getScrollWidth()); + var start = Math.floor(scrollTop / o.rowSize); + var end = start + Math.floor((o.height - o.header.length * o.headerRowSize) / o.rowSize); + var renderedCells = [], renderedKeys = []; + for (var i = start, cnt = 0; i <= end && i < o.items.length; i++, cnt++) { + var index = BI.deepIndexOf(this.renderedKeys, this.start + i); + var top = i * o.rowSize; + if (index > -1) { + if (o.rowSize !== this.renderedCells[index]._height) { + this.renderedCells[index]._height = o.rowSize; + this.renderedCells[index].el.setHeight(o.rowSize); + } + if (this.renderedCells[index].top !== top) { + this.renderedCells[index].top = top; + this.renderedCells[index].el.element.css("top", top + "px"); + } + renderedCells.push(this.renderedCells[index]); + } else { + var child = BI.createWidget(BI.extend({ + type: "bi.table_style_cell", + cls: "sequence-table-number-cell bi-border-left bi-border-right bi-border-bottom", + width: 60, + height: o.rowSize, + text: this.start + i, + styleGetter: function (index) { + return function () { + return o.sequenceCellStyleGetter(self.start + i - 1); + }; + }(cnt) + })); + renderedCells.push({ + el: child, + left: 0, + top: top, + _height: o.rowSize + }); + } + renderedKeys.push(this.start + i); + } + + // 已存在的, 需要添加的和需要删除的 + var existSet = {}, addSet = {}, deleteArray = []; + BI.each(renderedKeys, function (i, key) { + if (BI.deepContains(self.renderedKeys, key)) { + existSet[i] = key; + } else { + addSet[i] = key; + } + }); + BI.each(this.renderedKeys, function (i, key) { + if (BI.deepContains(existSet, key)) { + return; + } + if (BI.deepContains(addSet, key)) { + return; + } + deleteArray.push(i); + }); + BI.each(deleteArray, function (i, index) { + self.renderedCells[index].el.destroy(); + }); + var addedItems = []; + BI.each(addSet, function (index) { + addedItems.push(renderedCells[index]); + }); + BI.createWidget({ + type: "bi.absolute", + element: this.container, + items: addedItems + }); + this.renderedCells = renderedCells; + this.renderedKeys = renderedKeys; }, - hasVerticalScroll: function () { - return this.table.hasVerticalScroll(); + _populate: function () { + this.headerContainer.empty(); + this._createHeader(); + this._layout(); + this._calculateChildrenToRender(); }, setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); - }, - - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); - }, + if (this.options.scrollTop !== scrollTop) { + this.options.scrollTop = scrollTop; + try { + this.scrollContainer.element.scrollTop(scrollTop); + } catch (e) { - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + } + } }, getVerticalScroll: function () { - return this.table.getVerticalScroll(); - }, - - getLeftHorizontalScroll: function () { - return this.table.getLeftHorizontalScroll(); + return this.options.scrollTop; }, - getRightHorizontalScroll: function () { - return this.table.getRightHorizontalScroll(); + setVPage: function (v) { + v = v < 1 ? 1 : v; + var o = this.options; + this.start = (v - 1) * o.pageSize + 1; }, - getColumns: function () { - return this.table.getColumns(); + _restore: function () { + var o = this.options; + BI.each(this.renderedCells, function (i, cell) { + cell.el.destroy(); + }); + this.renderedCells = []; + this.renderedKeys = []; }, - attr: function () { - BI.ResponisveTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); + restore: function () { + this._restore(); }, - populate: function (items) { - var self = this, o = this.options; - this.table.populate.apply(this.table, arguments); - if (o.isNeedFreeze === true) { - BI.nextTick(function () { - self._initRegionSize(); - self.table.resize(); - self._resizeHeader(); - }); + populate: function (items, header) { + var o = this.options; + if (items && items !== this.options.items) { + o.items = items; + this._restore(); + } + if (header && header !== this.options.header) { + o.header = header; } + this._populate(); } }); -BI.shortcut("bi.responsive_table", BI.ResponisveTable);/** - * 加号表示的组节点 - * Created by GUY on 2015/9/6. - * @class BI.SelectTreeFirstPlusGroupNode - * @extends BI.NodeButton +BI.shortcut("bi.sequence_table_list_number", BI.SequenceTableListNumber);/** + * 带有序号的表格 + * + * Created by GUY on 2016/5/26. + * @class BI.SequenceTable + * @extends BI.Widget */ -BI.SelectTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { +BI.SequenceTable = BI.inherit(BI.Widget, { + _defaultConfig: function () { - var conf = BI.SelectTreeFirstPlusGroupNode.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-select-tree-first-plus-group-node bi-list-item-active", - logic: { - dynamic: false + return BI.extend(BI.SequenceTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-sequence-table", + el: { + type: "bi.adaptive_table" }, - id: "", - pId: "", - readonly: true, - open: false, - height: 25 + + sequence: {}, + + isNeedResize: true, + isResizeAdapt: false, + + isNeedFreeze: false, // 是否需要冻结单元格 + freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 + + isNeedMerge: false, // 是否需要合并单元格 + mergeCols: [], // 合并的单元格列号 + mergeRule: BI.emptyFn, + + columnSize: [], + minColumnSize: [], + maxColumnSize: [], + headerRowSize: 25, + rowSize: 25, + + regionColumnSize: [], + + headerCellStyleGetter: BI.emptyFn, + summaryCellStyleGetter: BI.emptyFn, + sequenceCellStyleGetter: BI.emptyFn, + + header: [], + items: [], // 二维数组 + + // 交叉表头 + crossHeader: [], + crossItems: [], + + showSequence: false, + startSequence: 1// 开始的序号 }); }, + _init: function () { - BI.SelectTreeFirstPlusGroupNode.superclass._init.apply(this, arguments); + BI.SequenceTable.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.checkbox = BI.createWidget({ - type: "bi.first_tree_node_checkbox", - stopPropagation: true + + this.sequence = BI.createWidget(o.sequence, { + type: "bi.sequence_table_list_number", + invisible: o.showSequence === false, + startSequence: o.startSequence, + isNeedFreeze: o.isNeedFreeze, + header: o.header, + items: o.items, + crossHeader: o.crossHeader, + crossItems: o.crossItems, + headerRowSize: o.headerRowSize, + rowSize: o.rowSize, + width: 60, + height: o.height && o.height - BI.GridTableScrollbar.SIZE, + + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - whiteSpace: "nowrap", - textHeight: o.height, + this.table = BI.createWidget(o.el, { + type: "bi.adaptive_table", + width: o.showSequence === true ? o.width - 60 : o.width, height: o.height, - hgap: o.hgap, - text: o.text, - value: o.value, - py: o.py - }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); - } - } - }); - var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); - var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { - width: 25, - el: this.checkbox - }, this.text); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { - items: items - })))); - }, + isNeedResize: o.isNeedResize, + isResizeAdapt: o.isResizeAdapt, - isOnce: function () { - return true; - }, + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); - }, + isNeedMerge: o.isNeedMerge, + mergeCols: o.mergeCols, + mergeRule: o.mergeRule, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); - }, + columnSize: o.columnSize, + minColumnSize: o.minColumnSize, + maxColumnSize: o.maxColumnSize, + headerRowSize: o.headerRowSize, + rowSize: o.rowSize, - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); - }, + regionColumnSize: o.regionColumnSize, - setOpened: function (v) { - BI.SelectTreeFirstPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } - } -}); + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter, -BI.shortcut("bi.select_tree_first_plus_group_node", BI.SelectTreeFirstPlusGroupNode);/** - * 加号表示的组节点 - * Created by GUY on 2015/9/6. - * @class BI.SelectTreeLastPlusGroupNode - * @extends BI.NodeButton - */ -BI.SelectTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, { - _defaultConfig: function () { - var conf = BI.SelectTreeLastPlusGroupNode.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-select-tree-last-plus-group-node bi-list-item-active", - logic: { - dynamic: false - }, - id: "", - pId: "", - readonly: true, - open: false, - height: 25 + header: o.header, + items: o.items, + // 交叉表头 + crossHeader: o.crossHeader, + crossItems: o.crossItems + }); + + this.table.on(BI.Table.EVENT_TABLE_SCROLL, function (scroll) { + if (self.sequence.getVerticalScroll() !== this.getVerticalScroll()) { + self.sequence.setVerticalScroll(this.getVerticalScroll()); + self.sequence.populate(); + } + self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }); - }, - _init: function () { - BI.SelectTreeLastPlusGroupNode.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.checkbox = BI.createWidget({ - type: "bi.last_tree_node_checkbox", - stopPropagation: true + this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { + o.regionColumnSize = this.getRegionColumnSize(); + o.columnSize = this.getColumnSize(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - whiteSpace: "nowrap", - textHeight: o.height, - height: o.height, - hgap: o.hgap, - text: o.text, - value: o.value, - py: o.py + this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { + o.regionColumnSize = this.getRegionColumnSize(); + o.columnSize = this.getColumnSize(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); - } - } + + this.htape = BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.sequence, + left: 0, + top: 0 + }, { + el: this.table, + top: 0, + left: o.showSequence === true ? 60 : 0 + }] }); - var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); - var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { - width: 25, - el: this.checkbox - }, this.text); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { - items: items - })))); + this._populate(); }, - isOnce: function () { - return true; + _populate: function () { + var o = this.options; + if (o.showSequence === true) { + this.sequence.setVisible(true); + this.table.element.css("left", "60px"); + this.table.setWidth(o.width - 60); + } else { + this.sequence.setVisible(false); + this.table.element.css("left", "0px"); + this.table.setWidth(o.width); + } }, - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); + setWidth: function (width) { + BI.PageTable.superclass.setWidth.apply(this, arguments); + this.table.setWidth(this.options.showSequence ? width - 60 : width); }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); + setHeight: function (height) { + BI.PageTable.superclass.setHeight.apply(this, arguments); + this.table.setHeight(height); + this.sequence.setHeight(height - BI.GridTableScrollbar.SIZE); }, - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); + setColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setColumnSize(columnSize); }, - setOpened: function (v) { - BI.SelectTreeLastPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } - } -}); - -BI.shortcut("bi.select_tree_last_plus_group_node", BI.SelectTreeLastPlusGroupNode);/** - * 加号表示的组节点 - * Created by GUY on 2015/9/6. - * @class BI.SelectTreeMidPlusGroupNode - * @extends BI.NodeButton - */ -BI.SelectTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, { - _defaultConfig: function () { - var conf = BI.SelectTreeMidPlusGroupNode.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-select-tree-mid-plus-group-node bi-list-item-active", - logic: { - dynamic: false - }, - id: "", - pId: "", - readonly: true, - open: false, - height: 25 - }); - }, - _init: function () { - BI.SelectTreeMidPlusGroupNode.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.checkbox = BI.createWidget({ - type: "bi.mid_tree_node_checkbox", - stopPropagation: true - }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - whiteSpace: "nowrap", - textHeight: o.height, - height: o.height, - hgap: o.hgap, - text: o.text, - value: o.value, - py: o.py - }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); - } - } - }); - var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); - var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { - width: 25, - el: this.checkbox - }, this.text); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { - items: items - })))); + getColumnSize: function () { + return this.table.getColumnSize(); }, - isOnce: function () { - return true; + setRegionColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setRegionColumnSize(columnSize); }, - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); + hasLeftHorizontalScroll: function () { + return this.table.hasLeftHorizontalScroll(); }, - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); + hasRightHorizontalScroll: function () { + return this.table.hasRightHorizontalScroll(); }, - setOpened: function (v) { - BI.SelectTreeMidPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } - } -}); - -BI.shortcut("bi.select_tree_mid_plus_group_node", BI.SelectTreeMidPlusGroupNode);/** - * @class BI.SelectTreeCombo - * @extends BI.Widget - */ -BI.SelectTreeCombo = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.SelectTreeCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-select-tree-combo", - height: 30, - text: "", - items: [], - value: "" - }); + setLeftHorizontalScroll: function (scrollLeft) { + this.table.setLeftHorizontalScroll(scrollLeft); }, - _init: function () { - BI.SelectTreeCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; + setRightHorizontalScroll: function (scrollLeft) { + this.table.setRightHorizontalScroll(scrollLeft); + }, - this.trigger = BI.createWidget({ - type: "bi.single_tree_trigger", - text: o.text, - height: o.height, - items: o.items, - value: o.value - }); + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); + this.sequence.setVerticalScroll(scrollTop); + }, - this.popup = BI.createWidget({ - type: "bi.select_level_tree", - items: o.items, - value: o.value - }); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); + }, - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - adjustLength: 2, - el: this.trigger, - popup: { - el: this.popup - } - }); + setVPage: function (page) { + this.sequence.setVPage && this.sequence.setVPage(page); + }, - this.combo.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + setHPage: function (page) { + this.sequence.setHPage && this.sequence.setHPage(page); + }, - this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - }); + attr: function () { + BI.SequenceTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); + this.sequence.attr.apply(this.sequence, arguments); }, - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.trigger.setValue(v); - this.popup.setValue(v); + restore: function () { + this.table.restore(); + this.sequence.restore(); }, - getValue: function () { - return this.popup.getValue(); + populate: function (items, header, crossItems, crossHeader) { + var o = this.options; + if (items) { + o.items = items; + } + if (header) { + o.header = header; + } + if (crossItems) { + o.crossItems = crossItems; + } + if (crossHeader) { + o.crossHeader = crossHeader; + } + this._populate(); + this.table.populate.apply(this.table, arguments); + this.sequence.populate.apply(this.sequence, arguments); + this.sequence.setVerticalScroll(this.table.getVerticalScroll()); }, - populate: function (items) { - this.combo.populate(items); + destroy: function () { + this.table.destroy(); + BI.SequenceTable.superclass.destroy.apply(this, arguments); } }); - - -BI.shortcut("bi.select_tree_combo", BI.SelectTreeCombo);/** - * @class BI.SelectTreeExpander - * @extends BI.Widget +BI.shortcut("bi.sequence_table", BI.SequenceTable);/** + * 单选加载数据搜索loader面板 + * Created by guy on 15/11/4. + * @class BI.SingleSelectSearchLoader + * @extends Widget */ -BI.SelectTreeExpander = BI.inherit(BI.Widget, { +BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SelectTreeExpander.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-select-tree-expander", - trigger: "click", - toggle: true, - direction: "bottom", - isDefaultInit: true, - el: {}, - popup: {} + return BI.extend(BI.SingleSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-search-loader", + itemsCreator: BI.emptyFn, + keywordGetter: BI.emptyFn, + valueFormatter: BI.emptyFn }); }, _init: function () { - BI.SelectTreeExpander.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); - this.trigger = BI.createWidget(BI.extend({stopPropagation: true}, o.el)); - this.trigger.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.expander.setValue([]); + var self = this, opts = this.options; + var hasNext = false; + + this.button_group = BI.createWidget({ + type: "bi.single_select_list", + element: this, + logic: { + dynamic: false + }, + el: { + tipText: BI.i18nText("BI-No_Select"), + el: { + type: "bi.loader", + isDefaultInit: false, + logic: { + dynamic: true, + scrolly: true + }, + el: { + chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, + behaviors: { + redmark: function () { + return true; + } + }, + layouts: [{ + type: "bi.vertical" + }] + } } + }, + itemsCreator: function (op, callback) { + self.storeValue && (op = BI.extend(op || {}, { + selectedValues: [self.storeValue] + })); + opts.itemsCreator(op, function (ob) { + var keyword = ob.keyword = opts.keywordGetter(); + hasNext = ob.hasNext; + var firstItems = []; + if (op.times === 1 && self.storeValue) { + var json = BI.map([self.storeValue], function (i, v) { + var txt = opts.valueFormatter(v) || v; + return { + text: txt, + value: v, + title: txt, + selected: false + }; + }); + firstItems = self._createItems(json); + } + callback(firstItems.concat(self._createItems(ob.items)), keyword); + if (op.times === 1 && self.storeValue) { + self.setValue(self.storeValue); + } + }); + }, + hasNext: function () { + return hasNext; } + }); + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); + this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); + }); + }, - this.expander = BI.createWidget({ - type: "bi.expander", - element: this, - trigger: o.trigger, - toggle: o.toggle, - direction: o.direction, - isDefaultInit: o.isDefaultInit, - el: this.trigger, - popup: o.popup + _createItems: function (items) { + return BI.createItems(items, { + type: "bi.single_select_radio_item", + logic: { + dynamic: false + }, + height: 25, + selected: false }); - this.expander.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - self.trigger.setSelected(false); - } - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }, + + _filterValues: function (src) { + var o = this.options; + var keyword = o.keywordGetter(); + var values = BI.deepClone(src.value) || []; + var newValues = BI.map(values, function (i, v) { + return { + text: o.valueFormatter(v) || v, + value: v + }; + }); + if (BI.isKey(keyword)) { + var search = BI.Func.getSearchResult(newValues, keyword); + values = search.match.concat(search.find); + } + return BI.map(values, function (i, v) { + return { + text: v.text, + title: v.text, + value: v.value, + selected: false + }; }); }, setValue: function (v) { - if (BI.contains(v, this.trigger.getValue())) { - this.trigger.setSelected(true); - this.expander.setValue([]); - } else { - this.trigger.setSelected(false); - this.expander.setValue(v); - } + // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = v; + this.button_group.setValue(v); }, getValue: function () { - if (this.trigger.isSelected()) { - return [this.trigger.getValue()]; - } - return this.expander.getValue(); + return this.button_group.getValue(); + }, + + getAllButtons: function () { + return this.button_group.getAllButtons(); + }, + + empty: function () { + this.button_group.empty(); }, populate: function (items) { - this.expander.populate(items); + this.button_group.populate.apply(this.button_group, arguments); + }, + + resetHeight: function (h) { + this.button_group.resetHeight(h); + }, + + resetWidth: function (w) { + this.button_group.resetWidth(w); } }); -BI.shortcut("bi.select_tree_expander", BI.SelectTreeExpander);/** - * @class BI.SelectTreePopup - * @extends BI.Pane +BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_search_loader", BI.SingleSelectSearchLoader);/** + * + * 在搜索框中输入文本弹出的面板 + * @class BI.SingleSelectSearchPane + * @extends Widget */ -BI.SelectTreePopup = BI.inherit(BI.Pane, { +BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.SelectTreePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-select-level-tree", - tipText: BI.i18nText("BI-No_Selected_Item"), - items: [], - value: "" - }); + constants: { + height: 25, + lgap: 10, + tgap: 5 }, - _formatItems: function (nodes, layer) { - var self = this; - BI.each(nodes, function (i, node) { - var extend = {layer: layer}; - node.id = node.id || BI.UUID(); - if (node.isParent === true || BI.isNotEmptyArray(node.children)) { - switch (i) { - case 0 : - extend.type = "bi.select_tree_first_plus_group_node"; - break; - case nodes.length - 1 : - extend.type = "bi.select_tree_last_plus_group_node"; - break; - default : - extend.type = "bi.select_tree_mid_plus_group_node"; - break; - } - BI.defaults(node, extend); - self._formatItems(node.children); - } else { - switch (i) { - case nodes.length - 1: - extend.type = "bi.last_tree_leaf_item"; - break; - default : - extend.type = "bi.mid_tree_leaf_item"; - } - BI.defaults(node, extend); - } + _defaultConfig: function () { + return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-search-pane bi-card", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + keywordGetter: BI.emptyFn }); - return nodes; }, _init: function () { - BI.SelectTreePopup.superclass._init.apply(this, arguments); - + BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.tree = BI.createWidget({ - type: "bi.level_tree", - expander: { - type: "bi.select_tree_expander", - isDefaultInit: true - }, - items: this._formatItems(BI.Tree.transformToTreeFormat(o.items)), - value: o.value, - chooseType: BI.Selection.Single + this.tooltipClick = BI.createWidget({ + type: "bi.label", + invisible: true, + text: BI.i18nText("BI-Click_Blank_To_Select"), + cls: "single-select-toolbar", + height: this.constants.height }); - BI.createWidget({ - type: "bi.vertical", - element: this, - items: [this.tree] + this.loader = BI.createWidget({ + type: "bi.single_select_search_loader", + keywordGetter: o.keywordGetter, + valueFormatter: o.valueFormatter, + itemsCreator: function (op, callback) { + o.itemsCreator.apply(self, [op, function (res) { + callback(res); + self.setKeyword(o.keywordGetter()); + }]); + } }); - - this.tree.on(BI.Controller.EVENT_CHANGE, function () { + this.loader.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { - self.fireEvent(BI.SelectTreePopup.EVENT_CHANGE); + this.resizer = BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.tooltipClick, + height: 0 + }, { + el: this.loader + }] }); + this.tooltipClick.setVisible(false); + }, - this.check(); + setKeyword: function (keyword) { + var btn; + var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === btn.getValue()); + if (isVisible !== this.tooltipClick.isVisible()) { + this.tooltipClick.setVisible(isVisible); + this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); + this.resizer.resize(); + } }, - getValue: function () { - return this.tree.getValue(); + hasMatched: function () { + return this.tooltipClick.isVisible(); }, setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.tree.setValue(v); + this.loader.setValue(v); + }, + + getValue: function () { + return this.loader.getValue(); + }, + + empty: function () { + this.loader.empty(); }, populate: function (items) { - BI.SelectTreePopup.superclass.populate.apply(this, arguments); - this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(items))); + this.loader.populate.apply(this.loader, arguments); } }); -BI.SelectTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.select_level_tree", BI.SelectTreePopup);/** +BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; + +BI.shortcut("bi.single_select_search_pane", BI.SingleSelectSearchPane);/** * - * Created by GUY on 2016/8/10. - * @class BI.SequenceTableDynamicNumber - * @extends BI.SequenceTableTreeNumber + * @class BI.SingleSelectCombo + * @extends BI.Single */ -BI.SequenceTableDynamicNumber = BI.inherit(BI.SequenceTableTreeNumber, { +BI.SingleSelectCombo = BI.inherit(BI.Single, { _defaultConfig: function () { - return BI.extend(BI.SequenceTableDynamicNumber.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-sequence-table-dynamic-number" + return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-combo", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + height: 28 }); }, _init: function () { - BI.SequenceTableDynamicNumber.superclass._init.apply(this, arguments); - }, - - _formatNumber: function (nodes) { + BI.SingleSelectCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - var result = []; - var count = this._getStart(nodes); - function getLeafCount (node) { - var cnt = 0; - if (BI.isNotEmptyArray(node.children)) { - BI.each(node.children, function (index, child) { - cnt += getLeafCount(child); - }); - if (node.children.length > 1 && BI.isNotEmptyArray(node.values)) { - cnt++; + var assertShowValue = function () { + BI.isKey(self._startValue) && (self.storeValue = self._startValue); + self.trigger.getSearcher().setState(self.storeValue); + }; + this.storeValue = ""; + // 标记正在请求数据 + this.requesting = false; + + this.trigger = BI.createWidget({ + type: "bi.single_select_trigger", + height: o.height, + // adapter: this.popup, + masker: { + offset: { + left: 1, + top: 1, + right: 2, + bottom: 33 } - } else { - cnt++; + }, + valueFormatter: o.valueFormatter, + itemsCreator: function (op, callback) { + o.itemsCreator(op, function (res) { + if (op.times === 1 && BI.isNotNull(op.keywords)) { + // 预防trigger内部把当前的storeValue改掉 + self.trigger.setValue(self.getValue()); + } + callback.apply(self, arguments); + }); } - return cnt; - } + }); - var start = 0, top = 0; - BI.each(nodes, function (i, node) { - if (BI.isArray(node.children)) { - BI.each(node.children, function (index, child) { - var cnt = getLeafCount(child); - result.push({ - text: count++, - start: start, - top: top, - cnt: cnt, - index: index, - height: cnt * o.rowSize - }); - start += cnt; - top += cnt * o.rowSize; + this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { + self._setStartValue(""); + this.getSearcher().setValue(self.storeValue); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { + self._setStartValue(""); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { + if (this.getSearcher().hasMatched()) { + var keyword = this.getSearcher().getKeyword(); + self._join({ + type: BI.Selection.Multi, + value: [keyword] + }, function () { + self.combo.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self.populate(); + self._setStartValue(""); }); - if (BI.isNotEmptyArray(node.values)) { - result.push({ - text: BI.i18nText("BI-Summary_Values"), - start: start++, - top: top, - cnt: 1, - isSummary: true, - height: o.rowSize + } + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) { + var last = BI.last(keywords); + keywords = BI.initial(keywords || []); + if (keywords.length > 0) { + self._joinKeywords(keywords, function () { + if (BI.isEndWithBlank(last)) { + self.combo.setValue(self.storeValue); + assertShowValue(); + self.combo.populate(); + self._setStartValue(""); + } else { + self.combo.setValue(self.storeValue); + assertShowValue(); + } + }); + } + }); + + this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { + self.storeValue = this.getValue(); + assertShowValue(); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + }); + + this.combo = BI.createWidget({ + type: "bi.combo", + toggle: false, + el: this.trigger, + adjustLength: 1, + popup: { + type: "bi.single_select_popup_view", + ref: function () { + self.popup = this; + self.trigger.setAdapter(this); + }, + listeners: [{ + eventName: BI.SingleSelectPopupView.EVENT_CHANGE, + action: function () { + self.storeValue = this.getValue(); + self._adjust(function () { + assertShowValue(); + }); + } + }, { + eventName: BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM, + action: function () { + self._defaultState(); + } + }, { + eventName: BI.SingleSelectPopupView.EVENT_CLICK_CLEAR, + action: function () { + self.setValue(); + self._defaultState(); + } + }], + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, + onLoaded: function () { + BI.nextTick(function () { + self.combo.adjustWidth(); + self.combo.adjustHeight(); + self.trigger.getSearcher().adjustView(); }); - top += o.rowSize; } + }, + hideChecker: function (e) { + return triggerBtn.element.find(e.target).length === 0; } }); - return result; - } -}); -BI.shortcut("bi.sequence_table_dynamic_number", BI.SequenceTableDynamicNumber);/** - * - * Created by GUY on 2016/5/26. - * @class BI.SequenceTableListNumber - * @extends BI.Widget - */ -BI.SequenceTableListNumber = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.SequenceTableListNumber.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-sequence-table-list-number", - isNeedFreeze: false, - scrollTop: 0, - startSequence: 1, // 开始的序号 - headerRowSize: 25, - rowSize: 25, - - sequenceHeaderCreator: null, - - header: [], - items: [], // 二维数组 - - // 交叉表头 - crossHeader: [], - crossItems: [], - pageSize: 20 + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + this.setValue(self.storeValue); + BI.nextTick(function () { + self.populate(); + }); }); - }, - - _init: function () { - BI.SequenceTableListNumber.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.start = o.startSequence; - this.renderedCells = []; - this.renderedKeys = []; - - this.container = BI.createWidget({ - type: "bi.absolute", - width: 60, - scrollable: false + // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 + this.wants2Quit = false; + this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { + // important:关闭弹出时又可能没有退出编辑状态 + self.trigger.stopEditing(); + if (self.requesting === true) { + self.wants2Quit = true; + } else { + self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + } }); - this.scrollContainer = BI.createWidget({ - type: "bi.vertical", - scrollable: false, - scrolly: false, - items: [this.container] + var triggerBtn = BI.createWidget({ + type: "bi.trigger_icon_button", + width: o.height, + height: o.height, + cls: "single-select-trigger-icon-button" }); - - this.headerContainer = BI.createWidget({ - type: "bi.absolute", - cls: "bi-border", - width: 58, - scrollable: false + triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } else { + self.combo.showView(); + } }); - - this.layout = BI.createWidget({ - type: "bi.vtape", + BI.createWidget({ + type: "bi.absolute", element: this, items: [{ - el: this.headerContainer, - height: o.headerRowSize * o.header.length - 2 - }, { - el: {type: "bi.layout"}, - height: 2 + el: this.combo, + left: 0, + right: 0, + top: 0, + bottom: 0 }, { - el: this.scrollContainer + el: triggerBtn, + right: 0, + top: 0, + bottom: 0 }] }); - this._populate(); }, - _layout: function () { - var self = this, o = this.options; - var headerHeight = o.headerRowSize * o.header.length - 2; - var items = this.layout.attr("items"); - if (o.isNeedFreeze === false) { - items[0].height = 0; - items[1].height = 0; - } else if (o.isNeedFreeze === true) { - items[0].height = headerHeight; - items[1].height = 2; - } - this.layout.attr("items", items); - this.layout.resize(); - this.container.setHeight(o.items.length * o.rowSize); - try { - this.scrollContainer.element.scrollTop(o.scrollTop); - } catch (e) { + _defaultState: function () { + this.trigger.stopEditing(); + this.combo.hideView(); + }, - } + _assertValue: function (val) { + val || (val = ""); }, - _createHeader: function () { - var o = this.options; - BI.createWidget({ - type: "bi.absolute", - element: this.headerContainer, - items: [{ - el: o.sequenceHeaderCreator || { - type: "bi.table_style_cell", - cls: "sequence-table-title-cell", - styleGetter: o.headerCellStyleGetter, - text: BI.i18nText("BI-Number_Index") - }, - left: 0, - top: 0, - right: 0, - bottom: 0 - }] - }); + _makeMap: function (values) { + return BI.makeObject(values || []); }, - _calculateChildrenToRender: function () { + _joinKeywords: function (keywords, callback) { var self = this, o = this.options; - var scrollTop = BI.clamp(o.scrollTop, 0, o.rowSize * o.items.length - (o.height - o.header.length * o.headerRowSize) + BI.DOM.getScrollWidth()); - var start = Math.floor(scrollTop / o.rowSize); - var end = start + Math.floor((o.height - o.header.length * o.headerRowSize) / o.rowSize); - var renderedCells = [], renderedKeys = []; - for (var i = start, cnt = 0; i <= end && i < o.items.length; i++, cnt++) { - var index = BI.deepIndexOf(this.renderedKeys, this.start + i); - var top = i * o.rowSize; - if (index > -1) { - if (o.rowSize !== this.renderedCells[index]._height) { - this.renderedCells[index]._height = o.rowSize; - this.renderedCells[index].el.setHeight(o.rowSize); - } - if (this.renderedCells[index].top !== top) { - this.renderedCells[index].top = top; - this.renderedCells[index].el.element.css("top", top + "px"); + this._assertValue(this.storeValue); + this.requesting = true; + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + keywords: keywords + }, function (ob) { + var values = BI.map(ob.items, "value"); + digest(values); + }); + + function digest (items) { + var selectedMap = self._makeMap(items); + BI.each(keywords, function (i, val) { + if (BI.isNotNull(selectedMap[val])) { + self.storeValue.value["remove"](val); } - renderedCells.push(this.renderedCells[index]); - } else { - var child = BI.createWidget(BI.extend({ - type: "bi.table_style_cell", - cls: "sequence-table-number-cell bi-border-left bi-border-right bi-border-bottom", - width: 60, - height: o.rowSize, - text: this.start + i, - styleGetter: function (index) { - return function () { - return o.sequenceCellStyleGetter(self.start + i - 1); - }; - }(cnt) - })); - renderedCells.push({ - el: child, - left: 0, - top: top, - _height: o.rowSize - }); - } - renderedKeys.push(this.start + i); + }); + self._adjust(callback); } + }, - // 已存在的, 需要添加的和需要删除的 - var existSet = {}, addSet = {}, deleteArray = []; - BI.each(renderedKeys, function (i, key) { - if (BI.deepContains(self.renderedKeys, key)) { - existSet[i] = key; - } else { - addSet[i] = key; - } - }); - BI.each(this.renderedKeys, function (i, key) { - if (BI.deepContains(existSet, key)) { - return; - } - if (BI.deepContains(addSet, key)) { + _joinAll: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + this.requesting = true; + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + keywords: [this.trigger.getKey()] + }, function (ob) { + var items = BI.map(ob.items, "value"); + if (self.storeValue.type === res.type) { + var change = false; + var map = self._makeMap(self.storeValue.value); + BI.each(items, function (i, v) { + if (BI.isNotNull(map[v])) { + change = true; + delete map[v]; + } + }); + change && (self.storeValue.value = BI.values(map)); + self._adjust(callback); return; } - deleteArray.push(i); - }); - BI.each(deleteArray, function (i, index) { - self.renderedCells[index].el.destroy(); - }); - var addedItems = []; - BI.each(addSet, function (index) { - addedItems.push(renderedCells[index]); - }); - BI.createWidget({ - type: "bi.absolute", - element: this.container, - items: addedItems + var selectedMap = self._makeMap(self.storeValue.value); + var notSelectedMap = self._makeMap(res.value); + var newItems = []; + BI.each(items, function (i, item) { + if (BI.isNotNull(selectedMap[items[i]])) { + delete selectedMap[items[i]]; + } + if (BI.isNull(notSelectedMap[items[i]])) { + newItems.push(item); + } + }); + self.storeValue.value = newItems.concat(BI.values(selectedMap)); + self._adjust(callback); }); - this.renderedCells = renderedCells; - this.renderedKeys = renderedKeys; }, - _populate: function () { - this.headerContainer.empty(); - this._createHeader(); - this._layout(); - this._calculateChildrenToRender(); - }, + _adjust: function (callback) { + var self = this, o = this.options; + if (!this._count) { + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH + }, function (res) { + self._count = res.count; + adjust(); + callback(); + }); + } else { + adjust(); + callback(); - setVerticalScroll: function (scrollTop) { - if (this.options.scrollTop !== scrollTop) { - this.options.scrollTop = scrollTop; - try { - this.scrollContainer.element.scrollTop(scrollTop); - } catch (e) { + } + function adjust () { + if (self.wants2Quit === true) { + self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + self.wants2Quit = false; } + self.requesting = false; } }, - getVerticalScroll: function () { - return this.options.scrollTop; + _join: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + this._assertValue(this.storeValue); + if (this.storeValue.type === res.type) { + var map = this._makeMap(this.storeValue.value); + BI.each(res.value, function (i, v) { + if (!map[v]) { + self.storeValue.value.push(v); + map[v] = v; + } + }); + var change = false; + BI.each(res.assist, function (i, v) { + if (BI.isNotNull(map[v])) { + change = true; + delete map[v]; + } + }); + change && (this.storeValue.value = BI.values(map)); + self._adjust(callback); + return; + } + this._joinAll(res, callback); }, - setVPage: function (v) { - v = v < 1 ? 1 : v; - var o = this.options; - this.start = (v - 1) * o.pageSize + 1; + _setStartValue: function (value) { + this._startValue = value; + this.popup.setStartValue(value); }, - _restore: function () { - var o = this.options; - BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); - }); - this.renderedCells = []; - this.renderedKeys = []; + setValue: function (v) { + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.combo.setValue(this.storeValue); }, - restore: function () { - this._restore(); + getValue: function () { + return this.storeValue; }, - populate: function (items, header) { - var o = this.options; - if (items && items !== this.options.items) { - o.items = items; - this._restore(); - } - if (header && header !== this.options.header) { - o.header = header; - } - this._populate(); + populate: function () { + this._count = null; + this.combo.populate.apply(this.combo, arguments); } }); -BI.shortcut("bi.sequence_table_list_number", BI.SequenceTableListNumber);/** - * 带有序号的表格 + +BI.extend(BI.SingleSelectCombo, { + REQ_GET_DATA_LENGTH: 0, + REQ_GET_ALL_DATA: -1 +}); + +BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; + +BI.shortcut("bi.single_select_combo", BI.SingleSelectCombo);/** + * 选择列表 * - * Created by GUY on 2016/5/26. - * @class BI.SequenceTable + * Created by GUY on 2015/11/1. + * @class BI.SingleSelectList * @extends BI.Widget */ -BI.SequenceTable = BI.inherit(BI.Widget, { - +BI.SingleSelectList = BI.inherit(BI.Widget, { + _defaultConfig: function () { - return BI.extend(BI.SequenceTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-sequence-table", - el: { - type: "bi.adaptive_table" + return BI.extend(BI.SingleSelectList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-list", + direction: BI.Direction.Top, // toolbar的位置 + logic: { + dynamic: true }, - - sequence: {}, - - isNeedResize: true, - isResizeAdapt: false, - - isNeedFreeze: false, // 是否需要冻结单元格 - freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 - - isNeedMerge: false, // 是否需要合并单元格 - mergeCols: [], // 合并的单元格列号 - mergeRule: BI.emptyFn, - - columnSize: [], - minColumnSize: [], - maxColumnSize: [], - headerRowSize: 25, - rowSize: 25, - - regionColumnSize: [], - - headerCellStyleGetter: BI.emptyFn, - summaryCellStyleGetter: BI.emptyFn, - sequenceCellStyleGetter: BI.emptyFn, - - header: [], - items: [], // 二维数组 - - // 交叉表头 - crossHeader: [], - crossItems: [], - - showSequence: false, - startSequence: 1// 开始的序号 + items: [], + itemsCreator: BI.emptyFn, + hasNext: BI.emptyFn, + onLoaded: BI.emptyFn, + el: { + type: "bi.list_pane" + } }); }, - _init: function () { - BI.SequenceTable.superclass._init.apply(this, arguments); + BI.SingleSelectList.superclass._init.apply(this, arguments); var self = this, o = this.options; - - this.sequence = BI.createWidget(o.sequence, { - type: "bi.sequence_table_list_number", - invisible: o.showSequence === false, - startSequence: o.startSequence, - isNeedFreeze: o.isNeedFreeze, - header: o.header, - items: o.items, - crossHeader: o.crossHeader, - crossItems: o.crossItems, - headerRowSize: o.headerRowSize, - rowSize: o.rowSize, - width: 60, - height: o.height && o.height - BI.GridTableScrollbar.SIZE, - - headerCellStyleGetter: o.headerCellStyleGetter, - summaryCellStyleGetter: o.summaryCellStyleGetter, - sequenceCellStyleGetter: o.sequenceCellStyleGetter - }); - this.table = BI.createWidget(o.el, { - type: "bi.adaptive_table", - width: o.showSequence === true ? o.width - 60 : o.width, - height: o.height, - isNeedResize: o.isNeedResize, - isResizeAdapt: o.isResizeAdapt, - - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, - - isNeedMerge: o.isNeedMerge, - mergeCols: o.mergeCols, - mergeRule: o.mergeRule, - - columnSize: o.columnSize, - minColumnSize: o.minColumnSize, - maxColumnSize: o.maxColumnSize, - headerRowSize: o.headerRowSize, - rowSize: o.rowSize, - - regionColumnSize: o.regionColumnSize, - - headerCellStyleGetter: o.headerCellStyleGetter, - summaryCellStyleGetter: o.summaryCellStyleGetter, - sequenceCellStyleGetter: o.sequenceCellStyleGetter, - - header: o.header, - items: o.items, - // 交叉表头 - crossHeader: o.crossHeader, - crossItems: o.crossItems - }); - - this.table.on(BI.Table.EVENT_TABLE_SCROLL, function (scroll) { - if (self.sequence.getVerticalScroll() !== this.getVerticalScroll()) { - self.sequence.setVerticalScroll(this.getVerticalScroll()); - self.sequence.populate(); - } - self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); - }); - - this.htape = BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.sequence, - left: 0, - top: 0 - }, { - el: this.table, - top: 0, - left: o.showSequence === true ? 60 : 0 - }] + + this.list = BI.createWidget(o.el, { + type: "bi.list_pane", + items: o.items, + itemsCreator: function (op, callback) { + o.itemsCreator(op, function (items) { + callback.apply(self, arguments); + }); + }, + onLoaded: o.onLoaded, + hasNext: o.hasNext + }); + + this.list.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { + if (type === BI.Events.CLICK) { + self.fireEvent(BI.SingleSelectList.EVENT_CHANGE, value, obj); + } + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this._populate(); - }, - _populate: function () { - var o = this.options; - if (o.showSequence === true) { - this.sequence.setVisible(true); - this.table.element.css("left", "60px"); - this.table.setWidth(o.width - 60); - } else { - this.sequence.setVisible(false); - this.table.element.css("left", "0px"); - this.table.setWidth(o.width); - } + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ + scrolly: true + }, o.logic, { + items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.list) + })))); + }, - - setWidth: function (width) { - BI.PageTable.superclass.setWidth.apply(this, arguments); - this.table.setWidth(this.options.showSequence ? width - 60 : width); + + hasPrev: function () { + return this.list.hasPrev(); }, - - setHeight: function (height) { - BI.PageTable.superclass.setHeight.apply(this, arguments); - this.table.setHeight(height); - this.sequence.setHeight(height - BI.GridTableScrollbar.SIZE); + + hasNext: function () { + return this.list.hasNext(); }, - - setColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setColumnSize(columnSize); + + prependItems: function (items) { + this.list.prependItems.apply(this.list, arguments); }, - - getColumnSize: function () { - return this.table.getColumnSize(); + + addItems: function (items) { + this.list.addItems.apply(this.list, arguments); }, - - setRegionColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setRegionColumnSize(columnSize); + + setValue: function (v) { + this.list.setValue([v]); }, - - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); + + getValue: function () { + return this.list.getValue()[0]; }, - - hasLeftHorizontalScroll: function () { - return this.table.hasLeftHorizontalScroll(); + + empty: function () { + this.list.empty(); }, - - hasRightHorizontalScroll: function () { - return this.table.hasRightHorizontalScroll(); + + populate: function (items) { + this.list.populate.apply(this.list, arguments); }, - - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); + + resetHeight: function (h) { + this.list.resetHeight ? this.list.resetHeight(h) : + this.list.element.css({"max-height": h + "px"}); }, - - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + + setNotSelectedValue: function () { + this.list.setNotSelectedValue.apply(this.list, arguments); }, - - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); - this.sequence.setVerticalScroll(scrollTop); + + getNotSelectedValue: function () { + return this.list.getNotSelectedValue(); }, - - getVerticalScroll: function () { - return this.table.getVerticalScroll(); + + getAllButtons: function () { + return this.list.getAllButtons(); }, - - setVPage: function (page) { - this.sequence.setVPage && this.sequence.setVPage(page); + + getAllLeaves: function () { + return this.list.getAllLeaves(); }, - - setHPage: function (page) { - this.sequence.setHPage && this.sequence.setHPage(page); + + getSelectedButtons: function () { + return this.list.getSelectedButtons(); }, - - attr: function () { - BI.SequenceTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); - this.sequence.attr.apply(this.sequence, arguments); + + getNotSelectedButtons: function () { + return this.list.getNotSelectedButtons(); }, - - restore: function () { - this.table.restore(); - this.sequence.restore(); + + getIndexByValue: function (value) { + return this.list.getIndexByValue(value); }, - - populate: function (items, header, crossItems, crossHeader) { - var o = this.options; - if (items) { - o.items = items; - } - if (header) { - o.header = header; - } - if (crossItems) { - o.crossItems = crossItems; - } - if (crossHeader) { - o.crossHeader = crossHeader; - } - this._populate(); - this.table.populate.apply(this.table, arguments); - this.sequence.populate.apply(this.sequence, arguments); - this.sequence.setVerticalScroll(this.table.getVerticalScroll()); + + getNodeById: function (id) { + return this.list.getNodeById(id); }, - - destroy: function () { - this.table.destroy(); - BI.SequenceTable.superclass.destroy.apply(this, arguments); + + getNodeByValue: function (value) { + return this.list.getNodeByValue(value); } }); -BI.shortcut("bi.sequence_table", BI.SequenceTable);/** - * 单选加载数据搜索loader面板 - * Created by guy on 15/11/4. - * @class BI.SingleSelectSearchLoader +BI.SingleSelectList.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_list", BI.SingleSelectList);/** + * 单选加载数据面板 + * Created by guy on 15/11/2. + * @class BI.SingleSelectLoader * @extends Widget */ -BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { +BI.SingleSelectLoader = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-search-loader", + return BI.extend(BI.SingleSelectLoader.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-loader", + logic: { + dynamic: true + }, + el: { + height: 400 + }, + valueFormatter: BI.emptyFn, itemsCreator: BI.emptyFn, - keywordGetter: BI.emptyFn, - valueFormatter: BI.emptyFn + onLoaded: BI.emptyFn }); }, _init: function () { - BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); + BI.SingleSelectLoader.superclass._init.apply(this, arguments); var self = this, opts = this.options; var hasNext = false; @@ -105387,11 +102803,9 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { this.button_group = BI.createWidget({ type: "bi.single_select_list", element: this, - logic: { - dynamic: false - }, - el: { - tipText: BI.i18nText("BI-No_Select"), + logic: opts.logic, + el: BI.extend({ + onLoaded: opts.onLoaded, el: { type: "bi.loader", isDefaultInit: false, @@ -105411,13 +102825,13 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { }] } } - }, + }, opts.el), itemsCreator: function (op, callback) { + var startValue = self._startValue; self.storeValue && (op = BI.extend(op || {}, { selectedValues: [self.storeValue] })); opts.itemsCreator(op, function (ob) { - var keyword = ob.keyword = opts.keywordGetter(); hasNext = ob.hasNext; var firstItems = []; if (op.times === 1 && self.storeValue) { @@ -105432,10 +102846,12 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { }); firstItems = self._createItems(json); } - callback(firstItems.concat(self._createItems(ob.items)), keyword); + callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); if (op.times === 1 && self.storeValue) { + BI.isKey(startValue) && (self.storeValue = startValue); self.setValue(self.storeValue); } + (op.times === 1) && self._scrollToTop(); }); }, hasNext: function () { @@ -105446,49 +102862,38 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); + self.fireEvent(BI.SingleSelectLoader.EVENT_CHANGE, arguments); }); }, _createItems: function (items) { return BI.createItems(items, { type: "bi.single_select_radio_item", - logic: { - dynamic: false - }, + logic: this.options.logic, height: 25, selected: false }); }, - _filterValues: function (src) { - var o = this.options; - var keyword = o.keywordGetter(); - var values = BI.deepClone(src.value) || []; - var newValues = BI.map(values, function (i, v) { - return { - text: o.valueFormatter(v) || v, - value: v - }; - }); - if (BI.isKey(keyword)) { - var search = BI.Func.getSearchResult(newValues, keyword); - values = search.match.concat(search.find); - } - return BI.map(values, function (i, v) { - return { - text: v.text, - title: v.text, - value: v.value, - selected: false - }; - }); + _scrollToTop: function () { + var self = this; + BI.delay(function () { + self.button_group.element.scrollTop(0); + }, 30); + }, + + _assertValue: function (val) { + val || (val = ""); + }, + + setStartValue: function (v) { + this._startValue = v; }, setValue: function (v) { - // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 - this.storeValue = v; - this.button_group.setValue(v); + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.button_group.setValue(this.storeValue); }, getValue: function () { @@ -105516,611 +102921,440 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { } }); -BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_search_loader", BI.SingleSelectSearchLoader);/** - * - * 在搜索框中输入文本弹出的面板 - * @class BI.SingleSelectSearchPane +BI.SingleSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_loader", BI.SingleSelectLoader);/** + * 带加载的单选下拉面板 + * @class BI.SingleSelectPopupView * @extends Widget */ - -BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { - - constants: { - height: 25, - lgap: 10, - tgap: 5 - }, +BI.SingleSelectPopupView = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-search-pane bi-card", - itemsCreator: BI.emptyFn, + return BI.extend(BI.SingleSelectPopupView.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-popup-view", + maxWidth: "auto", + minWidth: 135, + maxHeight: 400, valueFormatter: BI.emptyFn, - keywordGetter: BI.emptyFn - }); - }, - - _init: function () { - BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.tooltipClick = BI.createWidget({ - type: "bi.label", - invisible: true, - text: BI.i18nText("BI-Click_Blank_To_Select"), - cls: "single-select-toolbar", - height: this.constants.height - }); - - this.loader = BI.createWidget({ - type: "bi.single_select_search_loader", - keywordGetter: o.keywordGetter, - valueFormatter: o.valueFormatter, - itemsCreator: function (op, callback) { - o.itemsCreator.apply(self, [op, function (res) { - callback(res); - self.setKeyword(o.keywordGetter()); - }]); - } - }); - this.loader.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.resizer = BI.createWidget({ - type: "bi.vtape", - element: this, - items: [{ - el: this.tooltipClick, - height: 0 - }, { - el: this.loader - }] - }); - this.tooltipClick.setVisible(false); - }, - - setKeyword: function (keyword) { - var btn; - var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === btn.getValue()); - if (isVisible !== this.tooltipClick.isVisible()) { - this.tooltipClick.setVisible(isVisible); - this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); - this.resizer.resize(); - } - }, - - hasMatched: function () { - return this.tooltipClick.isVisible(); - }, - - setValue: function (v) { - this.loader.setValue(v); - }, - - getValue: function () { - return this.loader.getValue(); - }, - - empty: function () { - this.loader.empty(); - }, - - populate: function (items) { - this.loader.populate.apply(this.loader, arguments); - } -}); - -BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.single_select_search_pane", BI.SingleSelectSearchPane);/** - * - * @class BI.SingleSelectCombo - * @extends BI.Single - */ -BI.SingleSelectCombo = BI.inherit(BI.Single, { - - _defaultConfig: function () { - return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-combo", itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - height: 28 + onLoaded: BI.emptyFn }); }, _init: function () { - BI.SingleSelectCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - var assertShowValue = function () { - BI.isKey(self._startValue) && (self.storeValue = self._startValue); - self.trigger.getSearcher().setState(self.storeValue); - }; - this.storeValue = ""; - // 标记正在请求数据 - this.requesting = false; - - this.trigger = BI.createWidget({ - type: "bi.single_select_trigger", - height: o.height, - // adapter: this.popup, - masker: { - offset: { - left: 1, - top: 1, - right: 2, - bottom: 33 - } - }, - valueFormatter: o.valueFormatter, - itemsCreator: function (op, callback) { - o.itemsCreator(op, function (res) { - if (op.times === 1 && BI.isNotNull(op.keywords)) { - // 预防trigger内部把当前的storeValue改掉 - self.trigger.setValue(self.getValue()); - } - callback.apply(self, arguments); - }); - } - }); - - this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { - self._setStartValue(""); - this.getSearcher().setValue(self.storeValue); - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { - self._setStartValue(""); - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { - if (this.getSearcher().hasMatched()) { - var keyword = this.getSearcher().getKeyword(); - self._join({ - type: BI.Selection.Multi, - value: [keyword] - }, function () { - self.combo.setValue(self.storeValue); - self._setStartValue(keyword); - assertShowValue(); - self.populate(); - self._setStartValue(""); - }); - } - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) { - var last = BI.last(keywords); - keywords = BI.initial(keywords || []); - if (keywords.length > 0) { - self._joinKeywords(keywords, function () { - if (BI.isEndWithBlank(last)) { - self.combo.setValue(self.storeValue); - assertShowValue(); - self.combo.populate(); - self._setStartValue(""); - } else { - self.combo.setValue(self.storeValue); - assertShowValue(); - } - }); - } - }); - - this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { - self.storeValue = this.getValue(); - assertShowValue(); - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - }); + BI.SingleSelectPopupView.superclass._init.apply(this, arguments); + var self = this, opts = this.options; - this.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - el: this.trigger, - adjustLength: 1, - popup: { - type: "bi.single_select_popup_view", - ref: function () { - self.popup = this; - self.trigger.setAdapter(this); - }, - listeners: [{ - eventName: BI.SingleSelectPopupView.EVENT_CHANGE, - action: function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - }); - } - }, { - eventName: BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM, - action: function () { - self._defaultState(); - } - }, { - eventName: BI.SingleSelectPopupView.EVENT_CLICK_CLEAR, - action: function () { - self.setValue(); - self._defaultState(); - } - }], - itemsCreator: o.itemsCreator, - valueFormatter: o.valueFormatter, - onLoaded: function () { - BI.nextTick(function () { - self.combo.adjustWidth(); - self.combo.adjustHeight(); - self.trigger.getSearcher().adjustView(); - }); - } - }, - hideChecker: function (e) { - return triggerBtn.element.find(e.target).length === 0; - } + this.loader = BI.createWidget({ + type: "bi.single_select_loader", + itemsCreator: opts.itemsCreator, + valueFormatter: opts.valueFormatter, + onLoaded: opts.onLoaded }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - this.setValue(self.storeValue); - BI.nextTick(function () { - self.populate(); - }); - }); - // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 - this.wants2Quit = false; - this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { - // important:关闭弹出时又可能没有退出编辑状态 - self.trigger.stopEditing(); - if (self.requesting === true) { - self.wants2Quit = true; - } else { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); - } + this.popupView = BI.createWidget({ + type: "bi.multi_popup_view", + stopPropagation: false, + maxWidth: opts.maxWidth, + minWidth: opts.minWidth, + maxHeight: opts.maxHeight, + element: this, + buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], + el: this.loader }); - var triggerBtn = BI.createWidget({ - type: "bi.trigger_icon_button", - width: o.height, - height: o.height, - cls: "single-select-trigger-icon-button" + this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleSelectPopupView.EVENT_CHANGE); }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); + this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { + switch (index) { + case 0: + self.fireEvent(BI.SingleSelectPopupView.EVENT_CLICK_CLEAR); + break; + case 1: + self.fireEvent(BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM); + break; } }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.combo, - left: 0, - right: 0, - top: 0, - bottom: 0 - }, { - el: triggerBtn, - right: 0, - top: 0, - bottom: 0 - }] - }); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + setStartValue: function (v) { + this.loader.setStartValue(v); }, - _assertValue: function (val) { - val || (val = ""); + setValue: function (v) { + this.popupView.setValue(v); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + getValue: function () { + return this.popupView.getValue(); }, - _joinKeywords: function (keywords, callback) { - var self = this, o = this.options; - this._assertValue(this.storeValue); - this.requesting = true; - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, - keywords: keywords - }, function (ob) { - var values = BI.map(ob.items, "value"); - digest(values); - }); - - function digest (items) { - var selectedMap = self._makeMap(items); - BI.each(keywords, function (i, val) { - if (BI.isNotNull(selectedMap[val])) { - self.storeValue.value["remove"](val); - } - }); - self._adjust(callback); - } + populate: function (items) { + this.popupView.populate.apply(this.popupView, arguments); }, - _joinAll: function (res, callback) { - var self = this, o = this.options; - this._assertValue(res); - this.requesting = true; - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, - keywords: [this.trigger.getKey()] - }, function (ob) { - var items = BI.map(ob.items, "value"); - if (self.storeValue.type === res.type) { - var change = false; - var map = self._makeMap(self.storeValue.value); - BI.each(items, function (i, v) { - if (BI.isNotNull(map[v])) { - change = true; - delete map[v]; - } - }); - change && (self.storeValue.value = BI.values(map)); - self._adjust(callback); - return; - } - var selectedMap = self._makeMap(self.storeValue.value); - var notSelectedMap = self._makeMap(res.value); - var newItems = []; - BI.each(items, function (i, item) { - if (BI.isNotNull(selectedMap[items[i]])) { - delete selectedMap[items[i]]; - } - if (BI.isNull(notSelectedMap[items[i]])) { - newItems.push(item); - } - }); - self.storeValue.value = newItems.concat(BI.values(selectedMap)); - self._adjust(callback); - }); + resetHeight: function (h) { + this.popupView.resetHeight(h); }, - _adjust: function (callback) { - var self = this, o = this.options; - if (!this._count) { - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH - }, function (res) { - self._count = res.count; - adjust(); - callback(); - }); - } else { - adjust(); - callback(); + resetWidth: function (w) { + this.popupView.resetWidth(w); + } +}); - } +BI.SingleSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; +BI.SingleSelectPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; - function adjust () { - if (self.wants2Quit === true) { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); - self.wants2Quit = false; - } - self.requesting = false; - } + +BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView);/** + * + * 单选下拉框 + * @class BI.SingleSelectTrigger + * @extends BI.Trigger + */ + +BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { + + constants: { + height: 14, + rgap: 4, + lgap: 4 }, - _join: function (res, callback) { + _defaultConfig: function () { + return BI.extend(BI.SingleSelectTrigger.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-trigger bi-border", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + searcher: {}, + switcher: {}, + + adapter: null, + masker: {} + }); + }, + + _init: function () { + BI.SingleSelectTrigger.superclass._init.apply(this, arguments); + var self = this, o = this.options; - this._assertValue(res); - this._assertValue(this.storeValue); - if (this.storeValue.type === res.type) { - var map = this._makeMap(this.storeValue.value); - BI.each(res.value, function (i, v) { - if (!map[v]) { - self.storeValue.value.push(v); - map[v] = v; - } - }); - var change = false; - BI.each(res.assist, function (i, v) { - if (BI.isNotNull(map[v])) { - change = true; - delete map[v]; - } - }); - change && (this.storeValue.value = BI.values(map)); - self._adjust(callback); - return; + if (o.height) { + this.setHeight(o.height - 2); } - this._joinAll(res, callback); + + this.searcher = BI.createWidget(o.searcher, { + type: "bi.single_select_searcher", + height: o.height, + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, + popup: {}, + adapter: o.adapter, + masker: o.masker + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_START, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_START); + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_PAUSE, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_PAUSE); + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_SEARCHING, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_SEARCHING, arguments); + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_STOP, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_STOP); + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_CHANGE, arguments); + }); + + var wrapper = BI.createWidget({ + type: "bi.htape", + element: this, + items: [ + { + el: this.searcher, + width: "fill" + }, { + el: BI.createWidget(), + width: 30 + }] + }); }, - _setStartValue: function (value) { - this._startValue = value; - this.popup.setStartValue(value); + getSearcher: function () { + return this.searcher; + }, + + stopEditing: function () { + this.searcher.stopSearch(); + }, + + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, setValue: function (v) { - this.storeValue = v || ""; - this._assertValue(this.storeValue); - this.combo.setValue(this.storeValue); + this.searcher.setValue(v); }, - getValue: function () { - return this.storeValue; + getKey: function () { + return this.searcher.getKey(); }, - populate: function () { - this._count = null; - this.combo.populate.apply(this.combo, arguments); + getValue: function () { + return this.searcher.getValue(); } }); -BI.extend(BI.SingleSelectCombo, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 -}); - -BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.SingleSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.SingleSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; +BI.SingleSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectTrigger.EVENT_START = "EVENT_START"; +BI.SingleSelectTrigger.EVENT_STOP = "EVENT_STOP"; +BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; -BI.shortcut("bi.single_select_combo", BI.SingleSelectCombo);/** - * 选择列表 - * - * Created by GUY on 2015/11/1. - * @class BI.SingleSelectList - * @extends BI.Widget +BI.shortcut("bi.single_select_trigger", BI.SingleSelectTrigger);/** + * 单选输入框 + * Created by guy on 15/11/3. + * @class BI.SingleSelectEditor + * @extends Widget */ -BI.SingleSelectList = BI.inherit(BI.Widget, { - +BI.SingleSelectEditor = BI.inherit(BI.Widget, { + + _const: { + checkSelected: BI.i18nText("BI-Check_Selected") + }, + _defaultConfig: function () { - return BI.extend(BI.SingleSelectList.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-select-list", - direction: BI.Direction.Top, // toolbar的位置 - logic: { - dynamic: true - }, - items: [], - itemsCreator: BI.emptyFn, - hasNext: BI.emptyFn, - onLoaded: BI.emptyFn, - el: { - type: "bi.list_pane" - } + return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-editor", + el: {} }); }, + _init: function () { - BI.SingleSelectList.superclass._init.apply(this, arguments); + BI.SingleSelectEditor.superclass._init.apply(this, arguments); var self = this, o = this.options; - - this.list = BI.createWidget(o.el, { - type: "bi.list_pane", - items: o.items, - itemsCreator: function (op, callback) { - o.itemsCreator(op, function (items) { - callback.apply(self, arguments); - }); - }, - onLoaded: o.onLoaded, - hasNext: o.hasNext + this.editor = BI.createWidget(o.el, { + type: "bi.state_editor", + element: this, + height: o.height, + watermark: BI.i18nText("BI-Basic_Search"), + allowBlank: true }); - - this.list.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - if (type === BI.Events.CLICK) { - self.fireEvent(BI.SingleSelectList.EVENT_CHANGE, value, obj); - } + + this.editor.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ - scrolly: true - }, o.logic, { - items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.list) - })))); - - }, - - hasPrev: function () { - return this.list.hasPrev(); + this.editor.on(BI.StateEditor.EVENT_PAUSE, function () { + self.fireEvent(BI.SingleSelectEditor.EVENT_PAUSE); + }); + this.editor.on(BI.StateEditor.EVENT_CLICK_LABEL, function () { + + }); }, - - hasNext: function () { - return this.list.hasNext(); + + focus: function () { + this.editor.focus(); }, - - prependItems: function (items) { - this.list.prependItems.apply(this.list, arguments); + + blur: function () { + this.editor.blur(); }, - - addItems: function (items) { - this.list.addItems.apply(this.list, arguments); + + setState: function (state) { + this.editor.setState(state); }, - + setValue: function (v) { - this.list.setValue([v]); + this.editor.setValue(v); }, - + getValue: function () { - return this.list.getValue()[0]; + var v = this.editor.getState(); + if (BI.isArray(v) && v.length > 0) { + return v[v.length - 1]; + } + return ""; + }, - - empty: function () { - this.list.empty(); + + getKeywords: function () { + var val = this.editor.getLastValidValue(); + var keywords = val.match(/[\S]+/g); + if (BI.isEndWithBlank(val)) { + return keywords.concat([" "]); + } + return keywords; }, - + populate: function (items) { - this.list.populate.apply(this.list, arguments); + + } +}); +BI.SingleSelectEditor.EVENT_PAUSE = "SingleSelectEditor.EVENT_PAUSE"; +BI.shortcut("bi.single_select_editor", BI.SingleSelectEditor);/** + * searcher + * Created by guy on 15/11/3. + * @class BI.SingleSelectSearcher + * @extends Widget + */ +BI.SingleSelectSearcher = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.SingleSelectSearcher.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-searcher", + itemsCreator: BI.emptyFn, + el: {}, + popup: {}, + valueFormatter: BI.emptyFn, + adapter: null, + masker: {} + }); }, - - resetHeight: function (h) { - this.list.resetHeight ? this.list.resetHeight(h) : - this.list.element.css({"max-height": h + "px"}); + + _init: function () { + BI.SingleSelectSearcher.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.editor = BI.createWidget(o.el, { + type: "bi.single_select_editor", + height: o.height + }); + + this.searcher = BI.createWidget({ + type: "bi.searcher", + element: this, + height: o.height, + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback(); + }, + el: this.editor, + + popup: BI.extend({ + type: "bi.single_select_search_pane", + valueFormatter: o.valueFormatter, + keywordGetter: function () { + return self.editor.getValue(); + }, + itemsCreator: function (op, callback) { + op.keyword = self.editor.getValue(); + this.setKeyword(op.keyword); + o.itemsCreator(op, callback); + } + }, o.popup), + + adapter: o.adapter, + masker: o.masker + }); + this.searcher.on(BI.Searcher.EVENT_START, function () { + self.fireEvent(BI.SingleSelectSearcher.EVENT_START); + }); + this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { + if (this.hasMatched()) { + + } + self.fireEvent(BI.SingleSelectSearcher.EVENT_PAUSE); + }); + this.searcher.on(BI.Searcher.EVENT_STOP, function () { + self.fireEvent(BI.SingleSelectSearcher.EVENT_STOP); + }); + this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleSelectSearcher.EVENT_CHANGE, arguments); + }); + this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { + var keywords = this.getKeywords(); + self.fireEvent(BI.SingleSelectSearcher.EVENT_SEARCHING, keywords); + }); + }, + + adjustView: function () { + this.searcher.adjustView(); + }, + + isSearching: function () { + return this.searcher.isSearching(); }, - - setNotSelectedValue: function () { - this.list.setNotSelectedValue.apply(this.list, arguments); + + stopSearch: function () { + this.searcher.stopSearch(); }, - - getNotSelectedValue: function () { - return this.list.getNotSelectedValue(); + + getKeyword: function () { + return this.editor.getValue(); }, - - getAllButtons: function () { - return this.list.getAllButtons(); + + hasMatched: function () { + return this.searcher.hasMatched(); }, - - getAllLeaves: function () { - return this.list.getAllLeaves(); + + hasChecked: function () { + return this.searcher.getView() && this.searcher.getView().hasChecked(); }, - - getSelectedButtons: function () { - return this.list.getSelectedButtons(); + + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - - getNotSelectedButtons: function () { - return this.list.getNotSelectedButtons(); + + setState: function (v) { + var o = this.options; + v || (v = ""); + if (v === "") { + this.editor.setState(BI.Selection.None); + } else { + this.editor.setState(o.valueFormatter(v + "") || (v + "")); + } }, - - getIndexByValue: function (value) { - return this.list.getIndexByValue(value); + + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); }, - - getNodeById: function (id) { - return this.list.getNodeById(id); + + getKey: function () { + return this.editor.getValue(); }, - - getNodeByValue: function (value) { - return this.list.getNodeByValue(value); + + getValue: function () { + return this.searcher.getValue(); + }, + + populate: function (items) { + this.searcher.populate.apply(this.searcher, arguments); } }); -BI.SingleSelectList.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_list", BI.SingleSelectList);/** - * 单选加载数据面板 - * Created by guy on 15/11/2. - * @class BI.SingleSelectLoader + +BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectSearcher.EVENT_START = "EVENT_START"; +BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP"; +BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.shortcut("bi.single_select_searcher", BI.SingleSelectSearcher);/** + * 单选加载数据搜索loader面板 + * Created by guy on 15/11/4. + * @class BI.SingleSelectSearchLoader * @extends Widget */ -BI.SingleSelectLoader = BI.inherit(BI.Widget, { +BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectLoader.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-loader", - logic: { - dynamic: true - }, - el: { - height: 400 - }, - valueFormatter: BI.emptyFn, + return BI.extend(BI.SingleSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-search-loader", itemsCreator: BI.emptyFn, - onLoaded: BI.emptyFn + keywordGetter: BI.emptyFn, + valueFormatter: BI.emptyFn }); }, _init: function () { - BI.SingleSelectLoader.superclass._init.apply(this, arguments); + BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); var self = this, opts = this.options; var hasNext = false; @@ -106128,9 +103362,11 @@ BI.SingleSelectLoader = BI.inherit(BI.Widget, { this.button_group = BI.createWidget({ type: "bi.single_select_list", element: this, - logic: opts.logic, - el: BI.extend({ - onLoaded: opts.onLoaded, + logic: { + dynamic: false + }, + el: { + tipText: BI.i18nText("BI-No_Select"), el: { type: "bi.loader", isDefaultInit: false, @@ -106150,13 +103386,13 @@ BI.SingleSelectLoader = BI.inherit(BI.Widget, { }] } } - }, opts.el), + }, itemsCreator: function (op, callback) { - var startValue = self._startValue; self.storeValue && (op = BI.extend(op || {}, { selectedValues: [self.storeValue] })); opts.itemsCreator(op, function (ob) { + var keyword = ob.keyword = opts.keywordGetter(); hasNext = ob.hasNext; var firstItems = []; if (op.times === 1 && self.storeValue) { @@ -106171,12 +103407,27 @@ BI.SingleSelectLoader = BI.inherit(BI.Widget, { }); firstItems = self._createItems(json); } - callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); + if(keyword) { + var flag = false; + for(var i = 0; i < ob.items.length; i++) { + if(BI.contains(ob.items[i], keyword)) { + flag = true; + } + } + if(!flag) { + var preItems = self._createItems([{ + text: keyword, + value: keyword, + title: keyword, + selected: false + }]); + firstItems = firstItems.concat(preItems); + } + } + callback(firstItems.concat(self._createItems(ob.items)), keyword); if (op.times === 1 && self.storeValue) { - BI.isKey(startValue) && (self.storeValue = startValue); self.setValue(self.storeValue); } - (op.times === 1) && self._scrollToTop(); }); }, hasNext: function () { @@ -106187,153 +103438,525 @@ BI.SingleSelectLoader = BI.inherit(BI.Widget, { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectLoader.EVENT_CHANGE, arguments); + self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); }); }, _createItems: function (items) { return BI.createItems(items, { type: "bi.single_select_radio_item", - logic: this.options.logic, + logic: { + dynamic: false + }, height: 25, selected: false }); }, - _scrollToTop: function () { - var self = this; - BI.delay(function () { - self.button_group.element.scrollTop(0); - }, 30); + _filterValues: function (src) { + var o = this.options; + var keyword = o.keywordGetter(); + var values = BI.deepClone(src.value) || []; + var newValues = BI.map(values, function (i, v) { + return { + text: o.valueFormatter(v) || v, + value: v + }; + }); + if (BI.isKey(keyword)) { + var search = BI.Func.getSearchResult(newValues, keyword); + values = search.match.concat(search.find); + } + return BI.map(values, function (i, v) { + return { + text: v.text, + title: v.text, + value: v.value, + selected: false + }; + }); + }, + + setValue: function (v) { + // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = v; + this.button_group.setValue(v); + }, + + getValue: function () { + return this.button_group.getValue(); + }, + + getAllButtons: function () { + return this.button_group.getAllButtons(); + }, + + empty: function () { + this.button_group.empty(); + }, + + populate: function (items) { + this.button_group.populate.apply(this.button_group, arguments); + }, + + resetHeight: function (h) { + this.button_group.resetHeight(h); + }, + + resetWidth: function (w) { + this.button_group.resetWidth(w); + } +}); + +BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_search_add_loader", BI.SingleSelectSearchLoader);/** + * + * 在搜索框中输入文本弹出的面板 + * @class BI.SingleSelectSearchPane + * @extends Widget + */ + +BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { + + constants: { + height: 25, + lgap: 10, + tgap: 5 + }, + + _defaultConfig: function () { + return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-search-pane bi-card", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + keywordGetter: BI.emptyFn + }); + }, + + _init: function () { + BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.tooltipClick = BI.createWidget({ + type: "bi.label", + invisible: true, + text: BI.i18nText("BI-Click_Blank_To_Select"), + cls: "single-select-toolbar", + height: this.constants.height + }); + + this.loader = BI.createWidget({ + type: "bi.single_select_search_add_loader", + keywordGetter: o.keywordGetter, + valueFormatter: o.valueFormatter, + itemsCreator: function (op, callback) { + o.itemsCreator.apply(self, [op, function (res) { + callback(res); + self.setKeyword(o.keywordGetter()); + }]); + } + }); + this.loader.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + this.resizer = BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.tooltipClick, + height: 0 + }, { + el: this.loader + }] + }); + this.tooltipClick.setVisible(false); }, - _assertValue: function (val) { - val || (val = ""); + setKeyword: function (keyword) { + var btn; + var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === btn.getValue()); + if (isVisible !== this.tooltipClick.isVisible()) { + this.tooltipClick.setVisible(isVisible); + this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); + this.resizer.resize(); + } }, - setStartValue: function (v) { - this._startValue = v; + hasMatched: function () { + return this.tooltipClick.isVisible(); }, setValue: function (v) { - this.storeValue = v || ""; - this._assertValue(this.storeValue); - this.button_group.setValue(this.storeValue); + this.loader.setValue(v); }, getValue: function () { - return this.button_group.getValue(); - }, - - getAllButtons: function () { - return this.button_group.getAllButtons(); + return this.loader.getValue(); }, empty: function () { - this.button_group.empty(); + this.loader.empty(); }, populate: function (items) { - this.button_group.populate.apply(this.button_group, arguments); - }, - - resetHeight: function (h) { - this.button_group.resetHeight(h); - }, - - resetWidth: function (w) { - this.button_group.resetWidth(w); + this.loader.populate.apply(this.loader, arguments); } }); -BI.SingleSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_loader", BI.SingleSelectLoader);/** - * 带加载的单选下拉面板 - * @class BI.SingleSelectPopupView - * @extends Widget +BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; + +BI.shortcut("bi.single_select_search_add_pane", BI.SingleSelectSearchPane);/** + * + * @class BI.SingleSelectCombo + * @extends BI.Single */ -BI.SingleSelectPopupView = BI.inherit(BI.Widget, { +BI.SingleSelectCombo = BI.inherit(BI.Single, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectPopupView.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-popup-view", - maxWidth: "auto", - minWidth: 135, - maxHeight: 400, - valueFormatter: BI.emptyFn, + return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-combo", itemsCreator: BI.emptyFn, - onLoaded: BI.emptyFn + valueFormatter: BI.emptyFn, + height: 28 }); }, _init: function () { - BI.SingleSelectPopupView.superclass._init.apply(this, arguments); - var self = this, opts = this.options; + BI.SingleSelectCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + var assertShowValue = function () { + BI.isKey(self._startValue) && (self.storeValue = self._startValue); + self.trigger.getSearcher().setState(self.storeValue); + }; + this.storeValue = ""; + // 标记正在请求数据 + this.requesting = false; + + this.trigger = BI.createWidget({ + type: "bi.single_select_add_trigger", + height: o.height, + // adapter: this.popup, + masker: { + offset: { + left: 1, + top: 1, + right: 2, + bottom: 33 + } + }, + valueFormatter: o.valueFormatter, + itemsCreator: function (op, callback) { + o.itemsCreator(op, function (res) { + if (op.times === 1 && BI.isNotNull(op.keywords)) { + // 预防trigger内部把当前的storeValue改掉 + self.trigger.setValue(self.getValue()); + } + callback.apply(self, arguments); + }); + } + }); + + this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { + self._setStartValue(""); + this.getSearcher().setValue(self.storeValue); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { + self._setStartValue(""); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { + if (this.getSearcher().hasMatched()) { + var keyword = this.getSearcher().getKeyword(); + self._join({ + type: BI.Selection.Multi, + value: [keyword] + }, function () { + self.combo.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self.populate(); + self._setStartValue(""); + }); + } + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) { + var last = BI.last(keywords); + keywords = BI.initial(keywords || []); + if (keywords.length > 0) { + self._joinKeywords(keywords, function () { + if (BI.isEndWithBlank(last)) { + self.combo.setValue(self.storeValue); + assertShowValue(); + self.combo.populate(); + self._setStartValue(""); + } else { + self.combo.setValue(self.storeValue); + assertShowValue(); + } + }); + } + }); + + this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { + self.storeValue = this.getValue(); + assertShowValue(); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + }); + + this.combo = BI.createWidget({ + type: "bi.combo", + toggle: false, + el: this.trigger, + adjustLength: 1, + popup: { + type: "bi.single_select_popup_view", + ref: function () { + self.popup = this; + self.trigger.setAdapter(this); + }, + listeners: [{ + eventName: BI.SingleSelectPopupView.EVENT_CHANGE, + action: function () { + self.storeValue = this.getValue(); + self._adjust(function () { + assertShowValue(); + }); + } + }, { + eventName: BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM, + action: function () { + self._defaultState(); + } + }, { + eventName: BI.SingleSelectPopupView.EVENT_CLICK_CLEAR, + action: function () { + self.setValue(); + self._defaultState(); + } + }], + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, + onLoaded: function () { + BI.nextTick(function () { + self.combo.adjustWidth(); + self.combo.adjustHeight(); + self.trigger.getSearcher().adjustView(); + }); + } + }, + hideChecker: function (e) { + return triggerBtn.element.find(e.target).length === 0; + } + }); + + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + this.setValue(self.storeValue); + BI.nextTick(function () { + self.populate(); + }); + }); + // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 + this.wants2Quit = false; + this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { + // important:关闭弹出时又可能没有退出编辑状态 + self.trigger.stopEditing(); + if (self.requesting === true) { + self.wants2Quit = true; + } else { + self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + } + }); + + var triggerBtn = BI.createWidget({ + type: "bi.trigger_icon_button", + width: o.height, + height: o.height, + cls: "single-select-trigger-icon-button" + }); + triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } else { + self.combo.showView(); + } + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.combo, + left: 0, + right: 0, + top: 0, + bottom: 0 + }, { + el: triggerBtn, + right: 0, + top: 0, + bottom: 0 + }] + }); + }, + + _defaultState: function () { + this.trigger.stopEditing(); + this.combo.hideView(); + }, + + _assertValue: function (val) { + val || (val = ""); + }, + + _makeMap: function (values) { + return BI.makeObject(values || []); + }, - this.loader = BI.createWidget({ - type: "bi.single_select_loader", - itemsCreator: opts.itemsCreator, - valueFormatter: opts.valueFormatter, - onLoaded: opts.onLoaded + _joinKeywords: function (keywords, callback) { + var self = this, o = this.options; + this._assertValue(this.storeValue); + this.requesting = true; + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + keywords: keywords + }, function (ob) { + var values = BI.map(ob.items, "value"); + digest(values); }); - this.popupView = BI.createWidget({ - type: "bi.multi_popup_view", - stopPropagation: false, - maxWidth: opts.maxWidth, - minWidth: opts.minWidth, - maxHeight: opts.maxHeight, - element: this, - buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], - el: this.loader - }); + function digest (items) { + var selectedMap = self._makeMap(items); + BI.each(keywords, function (i, val) { + if (BI.isNotNull(selectedMap[val])) { + self.storeValue.value["remove"](val); + } + }); + self._adjust(callback); + } + }, - this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectPopupView.EVENT_CHANGE); - }); - this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { - switch (index) { - case 0: - self.fireEvent(BI.SingleSelectPopupView.EVENT_CLICK_CLEAR); - break; - case 1: - self.fireEvent(BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM); - break; + _joinAll: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + this.requesting = true; + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + keywords: [this.trigger.getKey()] + }, function (ob) { + var items = BI.map(ob.items, "value"); + if (self.storeValue.type === res.type) { + var change = false; + var map = self._makeMap(self.storeValue.value); + BI.each(items, function (i, v) { + if (BI.isNotNull(map[v])) { + change = true; + delete map[v]; + } + }); + change && (self.storeValue.value = BI.values(map)); + self._adjust(callback); + return; } + var selectedMap = self._makeMap(self.storeValue.value); + var notSelectedMap = self._makeMap(res.value); + var newItems = []; + BI.each(items, function (i, item) { + if (BI.isNotNull(selectedMap[items[i]])) { + delete selectedMap[items[i]]; + } + if (BI.isNull(notSelectedMap[items[i]])) { + newItems.push(item); + } + }); + self.storeValue.value = newItems.concat(BI.values(selectedMap)); + self._adjust(callback); }); }, - setStartValue: function (v) { - this.loader.setStartValue(v); + _adjust: function (callback) { + var self = this, o = this.options; + if (!this._count) { + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH + }, function (res) { + self._count = res.count; + adjust(); + callback(); + }); + } else { + adjust(); + callback(); + + } + + function adjust () { + if (self.wants2Quit === true) { + self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + self.wants2Quit = false; + } + self.requesting = false; + } }, - setValue: function (v) { - this.popupView.setValue(v); + _join: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + this._assertValue(this.storeValue); + if (this.storeValue.type === res.type) { + var map = this._makeMap(this.storeValue.value); + BI.each(res.value, function (i, v) { + if (!map[v]) { + self.storeValue.value.push(v); + map[v] = v; + } + }); + var change = false; + BI.each(res.assist, function (i, v) { + if (BI.isNotNull(map[v])) { + change = true; + delete map[v]; + } + }); + change && (this.storeValue.value = BI.values(map)); + self._adjust(callback); + return; + } + this._joinAll(res, callback); }, - getValue: function () { - return this.popupView.getValue(); + _setStartValue: function (value) { + this._startValue = value; + this.popup.setStartValue(value); }, - populate: function (items) { - this.popupView.populate.apply(this.popupView, arguments); + setValue: function (v) { + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.combo.setValue(this.storeValue); }, - resetHeight: function (h) { - this.popupView.resetHeight(h); + getValue: function () { + return this.storeValue; }, - resetWidth: function (w) { - this.popupView.resetWidth(w); + populate: function () { + this._count = null; + this.combo.populate.apply(this.combo, arguments); } }); -BI.SingleSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; -BI.SingleSelectPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; +BI.extend(BI.SingleSelectCombo, { + REQ_GET_DATA_LENGTH: 0, + REQ_GET_ALL_DATA: -1 +}); +BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView);/** +BI.shortcut("bi.single_select_add_combo", BI.SingleSelectCombo);/** * * 单选下拉框 * @class BI.SingleSelectTrigger @@ -106370,7 +103993,7 @@ BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { } this.searcher = BI.createWidget(o.searcher, { - type: "bi.single_select_searcher", + type: "bi.single_select_add_searcher", height: o.height, itemsCreator: o.itemsCreator, valueFormatter: o.valueFormatter, @@ -106432,98 +104055,17 @@ BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { return this.searcher.getValue(); } }); - -BI.SingleSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; -BI.SingleSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; -BI.SingleSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectTrigger.EVENT_START = "EVENT_START"; -BI.SingleSelectTrigger.EVENT_STOP = "EVENT_STOP"; -BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; - -BI.shortcut("bi.single_select_trigger", BI.SingleSelectTrigger);/** - * 单选输入框 - * Created by guy on 15/11/3. - * @class BI.SingleSelectEditor - * @extends Widget - */ -BI.SingleSelectEditor = BI.inherit(BI.Widget, { - - _const: { - checkSelected: BI.i18nText("BI-Check_Selected") - }, - - _defaultConfig: function () { - return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-editor", - el: {} - }); - }, - - _init: function () { - BI.SingleSelectEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget(o.el, { - type: "bi.state_editor", - element: this, - height: o.height, - watermark: BI.i18nText("BI-Basic_Search"), - allowBlank: true - }); - - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.editor.on(BI.StateEditor.EVENT_PAUSE, function () { - self.fireEvent(BI.SingleSelectEditor.EVENT_PAUSE); - }); - this.editor.on(BI.StateEditor.EVENT_CLICK_LABEL, function () { - - }); - }, - - focus: function () { - this.editor.focus(); - }, - - blur: function () { - this.editor.blur(); - }, - - setState: function (state) { - this.editor.setState(state); - }, - - setValue: function (v) { - this.editor.setValue(v); - }, - - getValue: function () { - var v = this.editor.getState(); - if (BI.isArray(v) && v.length > 0) { - return v[v.length - 1]; - } - return ""; - - }, - - getKeywords: function () { - var val = this.editor.getLastValidValue(); - var keywords = val.match(/[\S]+/g); - if (BI.isEndWithBlank(val)) { - return keywords.concat([" "]); - } - return keywords; - }, - - populate: function (items) { - - } -}); -BI.SingleSelectEditor.EVENT_PAUSE = "SingleSelectEditor.EVENT_PAUSE"; -BI.shortcut("bi.single_select_editor", BI.SingleSelectEditor);/** + +BI.SingleSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.SingleSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; +BI.SingleSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectTrigger.EVENT_START = "EVENT_START"; +BI.SingleSelectTrigger.EVENT_STOP = "EVENT_STOP"; +BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; + +BI.shortcut("bi.single_select_add_trigger", BI.SingleSelectTrigger);/** * searcher * Created by guy on 15/11/3. * @class BI.SingleSelectSearcher @@ -106563,7 +104105,7 @@ BI.SingleSelectSearcher = BI.inherit(BI.Widget, { el: this.editor, popup: BI.extend({ - type: "bi.single_select_search_pane", + type: "bi.single_select_search_add_pane", valueFormatter: o.valueFormatter, keywordGetter: function () { return self.editor.getValue(); @@ -106654,2513 +104196,3336 @@ BI.SingleSelectSearcher = BI.inherit(BI.Widget, { this.searcher.populate.apply(this.searcher, arguments); } }); - -BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectSearcher.EVENT_START = "EVENT_START"; -BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP"; -BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.shortcut("bi.single_select_searcher", BI.SingleSelectSearcher);/** - * 单选加载数据搜索loader面板 - * Created by guy on 15/11/4. - * @class BI.SingleSelectSearchLoader - * @extends Widget + +BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectSearcher.EVENT_START = "EVENT_START"; +BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP"; +BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.shortcut("bi.single_select_add_searcher", BI.SingleSelectSearcher);/** + * Created by User on 2017/11/16. + */ +BI.SignTextEditor = BI.inherit(BI.Widget, { + _defaultConfig: function () { + var conf = BI.SignTextEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-sign-initial-editor", + hgap: 4, + vgap: 2, + lgap: 0, + rgap: 0, + tgap: 0, + bgap: 0, + validationChecker: BI.emptyFn, + quitChecker: BI.emptyFn, + allowBlank: true, + watermark: "", + errorText: "", + text: "", + height: 24 + }); + }, + + _init: function () { + BI.SignTextEditor.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.editor = BI.createWidget({ + type: "bi.editor", + height: o.height, + hgap: o.hgap, + vgap: o.vgap, + lgap: o.lgap, + rgap: o.rgap, + tgap: o.tgap, + bgap: o.bgap, + value: o.value, + validationChecker: o.validationChecker, + quitChecker: o.quitChecker, + allowBlank: o.allowBlank, + watermark: o.watermark, + errorText: o.errorText + }); + this.text = BI.createWidget({ + type: "bi.text_button", + cls: "sign-editor-text", + title: o.title, + warningTitle: o.warningTitle, + tipType: o.tipType, + textAlign: "left", + height: o.height, + hgap: 4, + handler: function () { + self._showInput(); + self.editor.focus(); + self.editor.selectAll(); + } + }); + this.text.on(BI.TextButton.EVENT_CHANGE, function () { + BI.nextTick(function () { + self.fireEvent(BI.SignTextEditor.EVENT_CLICK_LABEL); + }); + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.text, + left: 0, + right: 0, + top: 0, + bottom: 0 + }] + }); + this.editor.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + this.editor.on(BI.Editor.EVENT_CONFIRM, function () { + self._showHint(); + self._checkText(); + self.fireEvent(BI.SignTextEditor.EVENT_CONFIRM, arguments); + }); + this.editor.on(BI.Editor.EVENT_ERROR, function () { + self._checkText(); + }); + BI.createWidget({ + type: "bi.vertical", + scrolly: false, + element: this, + items: [this.editor] + }); + this._showHint(); + self._checkText(); + }, + + _checkText: function () { + var o = this.options; + BI.nextTick(BI.bind(function () { + if (this.editor.getValue() === "") { + this.text.setValue(o.watermark || ""); + this.text.element.addClass("bi-water-mark"); + } else { + var v = this.editor.getValue(); + v = (BI.isEmpty(v) || v == o.text) ? o.text : v + o.text; + this.text.setValue(v); + this.text.element.removeClass("bi-water-mark"); + } + }, this)); + }, + + _showInput: function () { + this.editor.visible(); + this.text.invisible(); + }, + + _showHint: function () { + this.editor.invisible(); + this.text.visible(); + }, + + setTitle: function (title) { + this.text.setTitle(title); + }, + + setWarningTitle: function (title) { + this.text.setWarningTitle(title); + }, + + focus: function () { + this._showInput(); + this.editor.focus(); + }, + + blur: function () { + this.editor.blur(); + this._showHint(); + this._checkText(); + }, + + doRedMark: function () { + if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { + return; + } + this.text.doRedMark.apply(this.text, arguments); + }, + + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); + }, + + doHighLight: function () { + if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { + return; + } + this.text.doHighLight.apply(this.text, arguments); + }, + + unHighLight: function () { + this.text.unHighLight.apply(this.text, arguments); + }, + + isValid: function () { + return this.editor.isValid(); + }, + + setErrorText: function (text) { + this.editor.setErrorText(text); + }, + + getErrorText: function () { + return this.editor.getErrorText(); + }, + + isEditing: function () { + return this.editor.isEditing(); + }, + + getLastValidValue: function () { + return this.editor.getLastValidValue(); + }, + + setValue: function (v) { + this.editor.setValue(v); + this._checkText(); + }, + + getValue: function () { + return this.editor.getValue(); + }, + + getState: function () { + return this.text.getValue(); + }, + + setState: function (v) { + var o = this.options; + this._showHint(); + v = (BI.isEmpty(v) || v == o.text) ? o.text : v + o.text; + this.text.setValue(v); + } +}); +BI.SignTextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.SignTextEditor.EVENT_CLICK_LABEL = "EVENT_CLICK_LABEL"; + +BI.shortcut("bi.sign_text_editor", BI.SignTextEditor);/** + * Created by zcf on 2016/9/22. + */ +BI.SliderIconButton = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.SliderIconButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-slider-button" + }); + }, + _init: function () { + BI.extend(BI.SliderIconButton.superclass._init.apply(this, arguments)); + this.slider = BI.createWidget({ + type: "bi.icon_button", + cls: "slider-icon slider-button", + iconWidth: 14, + iconHeight: 14, + height: 14, + width: 14 + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.slider, + top: 7, + left: -7 + }], + width: 0, + height: 14 + }); + } +}); +BI.shortcut("bi.single_slider_button", BI.SliderIconButton);/** + * Created by zcf on 2016/9/22. */ -BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { - +BI.SingleSlider = BI.inherit(BI.Widget, { + _constant: { + EDITOR_WIDTH: 90, + EDITOR_HEIGHT: 30, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-search-loader", - itemsCreator: BI.emptyFn, - keywordGetter: BI.emptyFn, - valueFormatter: BI.emptyFn + return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-slider bi-slider-track", + digit: false, + unit: "" }); }, - _init: function () { - BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); + BI.SingleSlider.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - var hasNext = false; + var self = this, o = this.options; + var c = this._constant; + this.enable = false; + this.value = ""; - this.button_group = BI.createWidget({ - type: "bi.single_select_list", + this.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 + }); + this.blueTrack = BI.createWidget({ + type: "bi.layout", + cls: "blue-track bi-high-light-background", + height: 6 + }); + this.track = this._createTrackWrapper(); + + this.slider = BI.createWidget({ + type: "bi.single_slider_button" + }); + this._draggable(this.slider); + var sliderVertical = BI.createWidget({ + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.slider] + }], + hgap: c.SLIDER_WIDTH_HALF, + height: c.SLIDER_HEIGHT + }); + sliderVertical.element.click(function (e) { + if (self.enable) { + var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; + var trackLength = self.track.element[0].scrollWidth; + var percent = 0; + if (offset < 0) { + percent = 0; + } + if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { + percent = offset * 100 / self._getGrayTrackLength(); + } + if (offset > (trackLength - c.SLIDER_WIDTH)) { + percent = 100; + } + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setAllPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.label.setValue(v); + self.value = v; + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + } + }); + this.label = BI.createWidget({ + type: "bi.sign_text_editor", + cls: "slider-editor-button", + errorText: "", + text: o.unit, + width: c.EDITOR_WIDTH - 2, + allowBlank: false, + validationChecker: function (v) { + return self._checkValidation(v); + } + }); + this.label.element.hover(function () { + self.label.element.removeClass("bi-border").addClass("bi-border"); + }, function () { + self.label.element.removeClass("bi-border"); + }); + this.label.on(BI.SignEditor.EVENT_CONFIRM, function () { + var v = BI.parseFloat(this.getValue()); + var percent = self._getPercentByValue(v); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setAllPosition(significantPercent); + this.setValue(v); + self.value = v; + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + }); + this._setVisible(false); + BI.createWidget({ + type: "bi.absolute", element: this, - logic: { - dynamic: false - }, - el: { - tipText: BI.i18nText("BI-No_Select"), + items: [{ el: { - type: "bi.loader", - isDefaultInit: false, - logic: { - dynamic: true, - scrolly: true - }, - el: { - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, - behaviors: { - redmark: function () { - return true; - } - }, - layouts: [{ - type: "bi.vertical" + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.track, + width: "100%", + height: c.TRACK_HEIGHT }] - } - } - }, - itemsCreator: function (op, callback) { - self.storeValue && (op = BI.extend(op || {}, { - selectedValues: [self.storeValue] - })); - opts.itemsCreator(op, function (ob) { - var keyword = ob.keyword = opts.keywordGetter(); - hasNext = ob.hasNext; - var firstItems = []; - if (op.times === 1 && self.storeValue) { - var json = BI.map([self.storeValue], function (i, v) { - var txt = opts.valueFormatter(v) || v; - return { - text: txt, - value: v, - title: txt, - selected: false - }; - }); - firstItems = self._createItems(json); - } - if(keyword) { - var flag = false; - for(var i = 0; i < ob.items.length; i++) { - if(BI.contains(ob.items[i], keyword)) { - flag = true; - } - } - if(!flag) { - var preItems = self._createItems([{ - text: keyword, - value: keyword, - title: keyword, - selected: false - }]); - firstItems = firstItems.concat(preItems); - } - } - callback(firstItems.concat(self._createItems(ob.items)), keyword); - if (op.times === 1 && self.storeValue) { - self.setValue(self.storeValue); - } - }); - }, - hasNext: function () { - return hasNext; + }], + hgap: 7, + height: c.TRACK_HEIGHT + }, + top: 23, + left: 0, + width: "100%" + }, { + el: sliderVertical, + top: 20, + left: 0, + width: "100%" + }, { + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.label] + }], + rgap: c.EDITOR_WIDTH, + height: c.EDITOR_HEIGHT + }, + top: 0, + left: 0, + width: "100%" + }] + }); + }, + + _draggable: function (widget) { + var self = this, o = this.options; + var startDrag = false; + var size = 0, offset = 0, defaultSize = 0; + var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { + if (mouseMoveTracker.isDragging()) { + startDrag = true; + offset += deltaX; + size = optimizeSize(defaultSize + offset); + widget.element.addClass("dragging"); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 + self._setBlueTrack(significantPercent); + self._setLabelPosition(significantPercent); + self._setSliderPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.label.setValue(v); + self.value = v; + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + } + }, function () { + if (startDrag === true) { + size = optimizeSize(size); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setSliderPosition(significantPercent); + size = 0; + offset = 0; + defaultSize = size; + startDrag = false; } + widget.element.removeClass("dragging"); + mouseMoveTracker.releaseMouseMoves(); + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + }, window); + widget.element.on("mousedown", function (event) { + if(!widget.isEnabled()) { + return; + } + defaultSize = this.offsetLeft; + optimizeSize(defaultSize); + mouseMoveTracker.captureMouseMoves(event); }); - this.button_group.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); - }); + + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); + } }, - _createItems: function (items) { - return BI.createItems(items, { - type: "bi.single_select_radio_item", - logic: { - dynamic: false - }, - height: 25, - selected: false + _createTrackWrapper: function () { + return BI.createWidget({ + type: "bi.absolute", + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.grayTrack, + top: 0, + left: 0, + width: "100%" + }, { + el: this.blueTrack, + top: 0, + left: 0, + width: "0%" + }] + }], + hgap: 8, + height: 8 + }, + top: 8, + left: 0, + width: "100%" + }] }); }, - _filterValues: function (src) { + _checkValidation: function (v) { var o = this.options; - var keyword = o.keywordGetter(); - var values = BI.deepClone(src.value) || []; - var newValues = BI.map(values, function (i, v) { - return { - text: o.valueFormatter(v) || v, - value: v - }; - }); - if (BI.isKey(keyword)) { - var search = BI.Func.getSearchResult(newValues, keyword); - values = search.match.concat(search.find); + var valid = false; + if (BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)) { + if(o.digit === false) { + valid = true; + }else{ + var dotText = (v + "").split(".")[1] || ""; + valid = (dotText.length === o.digit); + } } - return BI.map(values, function (i, v) { - return { - text: v.text, - title: v.text, - value: v.value, - selected: false - }; - }); + return valid; }, - setValue: function (v) { - // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 - this.storeValue = v; - this.button_group.setValue(v); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - getValue: function () { - return this.button_group.getValue(); + _setLabelPosition: function (percent) { + this.label.element.css({left: percent + "%"}); }, - getAllButtons: function () { - return this.button_group.getAllButtons(); + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); }, - empty: function () { - this.button_group.empty(); + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setLabelPosition(percent); + this._setBlueTrack(percent); }, - populate: function (items) { - this.button_group.populate.apply(this.button_group, arguments); + _setVisible: function (visible) { + this.slider.setVisible(visible); + this.label.setVisible(visible); }, - resetHeight: function (h) { - this.button_group.resetHeight(h); + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - resetWidth: function (w) { - this.button_group.resetWidth(w); - } -}); - -BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_search_add_loader", BI.SingleSelectSearchLoader);/** - * - * 在搜索框中输入文本弹出的面板 - * @class BI.SingleSelectSearchPane - * @extends Widget - */ - -BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { - - constants: { - height: 25, - lgap: 10, - tgap: 5 + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-search-pane bi-card", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - keywordGetter: BI.emptyFn - }); + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, - _init: function () { - BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.tooltipClick = BI.createWidget({ - type: "bi.label", - invisible: true, - text: BI.i18nText("BI-Click_Blank_To_Select"), - cls: "single-select-toolbar", - height: this.constants.height - }); - - this.loader = BI.createWidget({ - type: "bi.single_select_search_add_loader", - keywordGetter: o.keywordGetter, - valueFormatter: o.valueFormatter, - itemsCreator: function (op, callback) { - o.itemsCreator.apply(self, [op, function (res) { - callback(res); - self.setKeyword(o.keywordGetter()); - }]); - } - }); - this.loader.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.resizer = BI.createWidget({ - type: "bi.vtape", - element: this, - items: [{ - el: this.tooltipClick, - height: 0 - }, { - el: this.loader - }] - }); - this.tooltipClick.setVisible(false); + getValue: function () { + return this.value; }, - setKeyword: function (keyword) { - var btn; - var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === btn.getValue()); - if (isVisible !== this.tooltipClick.isVisible()) { - this.tooltipClick.setVisible(isVisible); - this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); - this.resizer.resize(); + setValue: function (v) { + var o = this.options; + v = BI.parseFloat(v); + v = o.digit === false ? v : v.toFixed(o.digit); + if ((!isNaN(v))) { + if (this._checkValidation(v)) { + this.value = v; + } + if (v > this.max) { + this.value = this.max; + } + if (v < this.min) { + this.value = this.min; + } } }, - hasMatched: function () { - return this.tooltipClick.isVisible(); - }, - - setValue: function (v) { - this.loader.setValue(v); + setMinAndMax: function (v) { + var minNumber = BI.parseFloat(v.min); + var maxNumber = BI.parseFloat(v.max); + if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { + this.min = minNumber; + this.max = maxNumber; + } }, - getValue: function () { - return this.loader.getValue(); - }, + reset: function () { + this._setVisible(false); + this.enable = false; + this.value = ""; + this.min = 0; + this.max = 0; + this._setBlueTrack(0); - empty: function () { - this.loader.empty(); }, - populate: function (items) { - this.loader.populate.apply(this.loader, arguments); - } -}); - -BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.single_select_search_add_pane", BI.SingleSelectSearchPane);/** - * - * @class BI.SingleSelectCombo - * @extends BI.Single + populate: function () { + if (!isNaN(this.min) && !isNaN(this.max)) { + this._setVisible(true); + this.enable = true; + this.label.setErrorText(BI.i18nText("BI-Please_Enter") + this.min + "-" + this.max + BI.i18nText("BI-Basic_De") + BI.i18nText("BI-Basic_Number")); + if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { + this.label.setValue(this.value); + this._setAllPosition(this._getPercentByValue(this.value)); + } else { + this.label.setValue(this.max); + this._setAllPosition(100); + } + } + } +}); +BI.SingleSlider.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_slider", BI.SingleSlider);/** + * Created by Urthur on 2017/9/12. */ -BI.SingleSelectCombo = BI.inherit(BI.Single, { - +BI.SingleSliderLabel = BI.inherit(BI.Widget, { + _constant: { + EDITOR_WIDTH: 90, + EDITOR_HEIGHT: 20, + HEIGHT: 20, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, _defaultConfig: function () { - return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-combo", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - height: 28 + return BI.extend(BI.SingleSliderLabel.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-slider-label bi-slider-track", + digit: false, + unit: "" }); }, - _init: function () { - BI.SingleSelectCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.SingleSliderLabel.superclass._init.apply(this, arguments); - var assertShowValue = function () { - BI.isKey(self._startValue) && (self.storeValue = self._startValue); - self.trigger.getSearcher().setState(self.storeValue); - }; - this.storeValue = ""; - // 标记正在请求数据 - this.requesting = false; + var self = this, o = this.options; + var c = this._constant; + this.enable = false; + this.value = ""; - this.trigger = BI.createWidget({ - type: "bi.single_select_add_trigger", - height: o.height, - // adapter: this.popup, - masker: { - offset: { - left: 1, - top: 1, - right: 2, - bottom: 33 - } - }, - valueFormatter: o.valueFormatter, - itemsCreator: function (op, callback) { - o.itemsCreator(op, function (res) { - if (op.times === 1 && BI.isNotNull(op.keywords)) { - // 预防trigger内部把当前的storeValue改掉 - self.trigger.setValue(self.getValue()); - } - callback.apply(self, arguments); - }); - } + this.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 + }); + this.blueTrack = BI.createWidget({ + type: "bi.layout", + cls: "blue-track bi-high-light-background", + height: 6 }); + this.track = this._createTrackWrapper(); - this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { - self._setStartValue(""); - this.getSearcher().setValue(self.storeValue); + this.slider = BI.createWidget({ + type: "bi.single_slider_button" }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { - self._setStartValue(""); + this._draggable(this.slider); + var sliderVertical = BI.createWidget({ + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.slider] + }], + hgap: c.SLIDER_WIDTH_HALF, + height: c.SLIDER_HEIGHT }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { - if (this.getSearcher().hasMatched()) { - var keyword = this.getSearcher().getKeyword(); - self._join({ - type: BI.Selection.Multi, - value: [keyword] - }, function () { - self.combo.setValue(self.storeValue); - self._setStartValue(keyword); - assertShowValue(); - self.populate(); - self._setStartValue(""); - }); + sliderVertical.element.click(function (e) { + if (self.enable) { + var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; + var trackLength = self.track.element[0].scrollWidth; + var percent = 0; + if (offset < 0) { + percent = 0; + } + if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { + percent = offset * 100 / self._getGrayTrackLength(); + } + if (offset > (trackLength - c.SLIDER_WIDTH)) { + percent = 100; + } + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setAllPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.label.setText(v + o.unit); + self.value = v; + self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); } }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) { - var last = BI.last(keywords); - keywords = BI.initial(keywords || []); - if (keywords.length > 0) { - self._joinKeywords(keywords, function () { - if (BI.isEndWithBlank(last)) { - self.combo.setValue(self.storeValue); - assertShowValue(); - self.combo.populate(); - self._setStartValue(""); - } else { - self.combo.setValue(self.storeValue); - assertShowValue(); - } - }); - } + this.label = BI.createWidget({ + type: "bi.label", + height: c.HEIGHT, + width: c.EDITOR_WIDTH - 2 }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { - self.storeValue = this.getValue(); - assertShowValue(); - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } + this._setVisible(false); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.track, + width: "100%", + height: c.TRACK_HEIGHT + }] + }], + hgap: 7, + height: c.TRACK_HEIGHT + }, + top: 13, + left: 0, + width: "100%" + }, { + el: sliderVertical, + top: 10, + left: 0, + width: "100%" + }, { + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.label] + }], + rgap: c.EDITOR_WIDTH, + height: c.EDITOR_HEIGHT + }, + top: 0, + left: 0, + width: "100%" + }] }); + }, - this.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - el: this.trigger, - adjustLength: 1, - popup: { - type: "bi.single_select_popup_view", - ref: function () { - self.popup = this; - self.trigger.setAdapter(this); - }, - listeners: [{ - eventName: BI.SingleSelectPopupView.EVENT_CHANGE, - action: function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - }); - } - }, { - eventName: BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM, - action: function () { - self._defaultState(); - } - }, { - eventName: BI.SingleSelectPopupView.EVENT_CLICK_CLEAR, - action: function () { - self.setValue(); - self._defaultState(); - } - }], - itemsCreator: o.itemsCreator, - valueFormatter: o.valueFormatter, - onLoaded: function () { - BI.nextTick(function () { - self.combo.adjustWidth(); - self.combo.adjustHeight(); - self.trigger.getSearcher().adjustView(); - }); - } - }, - hideChecker: function (e) { - return triggerBtn.element.find(e.target).length === 0; + _draggable: function (widget) { + var self = this, o = this.options; + var startDrag = false; + var size = 0, offset = 0, defaultSize = 0; + var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { + if (mouseMoveTracker.isDragging()) { + startDrag = true; + offset += deltaX; + size = optimizeSize(defaultSize + offset); + widget.element.addClass("dragging"); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 + self._setBlueTrack(significantPercent); + self._setLabelPosition(significantPercent); + self._setSliderPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.label.setValue(v); + self.value = v; + self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); } - }); - - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - this.setValue(self.storeValue); - BI.nextTick(function () { - self.populate(); - }); - }); - // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 - this.wants2Quit = false; - this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { - // important:关闭弹出时又可能没有退出编辑状态 - self.trigger.stopEditing(); - if (self.requesting === true) { - self.wants2Quit = true; - } else { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + }, function () { + if (startDrag === true) { + size = optimizeSize(size); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setSliderPosition(significantPercent); + size = 0; + offset = 0; + defaultSize = size; + startDrag = false; } - }); - - var triggerBtn = BI.createWidget({ - type: "bi.trigger_icon_button", - width: o.height, - height: o.height, - cls: "single-select-trigger-icon-button" - }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); + widget.element.removeClass("dragging"); + mouseMoveTracker.releaseMouseMoves(); + self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); + }, window); + widget.element.on("mousedown", function (event) { + if(!widget.isEnabled()) { + return; } + defaultSize = this.offsetLeft; + optimizeSize(defaultSize); + mouseMoveTracker.captureMouseMoves(event); }); - BI.createWidget({ + + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); + } + }, + + _createTrackWrapper: function () { + return BI.createWidget({ type: "bi.absolute", - element: this, items: [{ - el: this.combo, + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.grayTrack, + top: 0, + left: 0, + width: "100%" + }, { + el: this.blueTrack, + top: 0, + left: 0, + width: "0%" + }] + }], + hgap: 8, + height: 8 + }, + top: 8, left: 0, - right: 0, - top: 0, - bottom: 0 - }, { - el: triggerBtn, - right: 0, - top: 0, - bottom: 0 + width: "100%" }] }); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + _checkValidation: function (v) { + return BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max); }, - _assertValue: function (val) { - val || (val = ""); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + _setLabelPosition: function (percent) { + this.label.element.css({left: percent + "%"}); }, - _joinKeywords: function (keywords, callback) { - var self = this, o = this.options; - this._assertValue(this.storeValue); - this.requesting = true; - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, - keywords: keywords - }, function (ob) { - var values = BI.map(ob.items, "value"); - digest(values); - }); - - function digest (items) { - var selectedMap = self._makeMap(items); - BI.each(keywords, function (i, val) { - if (BI.isNotNull(selectedMap[val])) { - self.storeValue.value["remove"](val); - } - }); - self._adjust(callback); - } + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); }, - _joinAll: function (res, callback) { - var self = this, o = this.options; - this._assertValue(res); - this.requesting = true; - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, - keywords: [this.trigger.getKey()] - }, function (ob) { - var items = BI.map(ob.items, "value"); - if (self.storeValue.type === res.type) { - var change = false; - var map = self._makeMap(self.storeValue.value); - BI.each(items, function (i, v) { - if (BI.isNotNull(map[v])) { - change = true; - delete map[v]; - } - }); - change && (self.storeValue.value = BI.values(map)); - self._adjust(callback); - return; - } - var selectedMap = self._makeMap(self.storeValue.value); - var notSelectedMap = self._makeMap(res.value); - var newItems = []; - BI.each(items, function (i, item) { - if (BI.isNotNull(selectedMap[items[i]])) { - delete selectedMap[items[i]]; - } - if (BI.isNull(notSelectedMap[items[i]])) { - newItems.push(item); - } - }); - self.storeValue.value = newItems.concat(BI.values(selectedMap)); - self._adjust(callback); - }); + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setLabelPosition(percent); + this._setBlueTrack(percent); }, - _adjust: function (callback) { - var self = this, o = this.options; - if (!this._count) { - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH - }, function (res) { - self._count = res.count; - adjust(); - callback(); - }); - } else { - adjust(); - callback(); + _setVisible: function (visible) { + this.slider.setVisible(visible); + this.label.setVisible(visible); + }, - } + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; + }, - function adjust () { - if (self.wants2Quit === true) { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); - self.wants2Quit = false; - } - self.requesting = false; - } + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - _join: function (res, callback) { - var self = this, o = this.options; - this._assertValue(res); - this._assertValue(this.storeValue); - if (this.storeValue.type === res.type) { - var map = this._makeMap(this.storeValue.value); - BI.each(res.value, function (i, v) { - if (!map[v]) { - self.storeValue.value.push(v); - map[v] = v; - } - }); - var change = false; - BI.each(res.assist, function (i, v) { - if (BI.isNotNull(map[v])) { - change = true; - delete map[v]; - } - }); - change && (this.storeValue.value = BI.values(map)); - self._adjust(callback); - return; - } - this._joinAll(res, callback); + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, - _setStartValue: function (value) { - this._startValue = value; - this.popup.setStartValue(value); + getValue: function () { + return this.value; }, setValue: function (v) { - this.storeValue = v || ""; - this._assertValue(this.storeValue); - this.combo.setValue(this.storeValue); + var o = this.options; + v = BI.parseFloat(v); + v = o.digit === false ? v : v.toFixed(o.digit); + if ((!isNaN(v))) { + if (this._checkValidation(v)) { + this.value = v; + } + if (v > this.max) { + this.value = this.max; + } + if (v < this.min) { + this.value = this.min; + } + } + }, + + setMinAndMax: function (v) { + var minNumber = BI.parseFloat(v.min); + var maxNumber = BI.parseFloat(v.max); + if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { + this.min = minNumber; + this.max = maxNumber; + } }, - getValue: function () { - return this.storeValue; + reset: function () { + this._setVisible(false); + this.enable = false; + this.value = ""; + this.min = 0; + this.max = 0; + this._setBlueTrack(0); }, populate: function () { - this._count = null; - this.combo.populate.apply(this.combo, arguments); + var o = this.options; + if (!isNaN(this.min) && !isNaN(this.max)) { + this._setVisible(true); + this.enable = true; + if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { + this.label.setValue(this.value + o.unit); + this._setAllPosition(this._getPercentByValue(this.value)); + } else { + this.label.setValue(this.max + o.unit); + this._setAllPosition(100); + } + } } }); - -BI.extend(BI.SingleSelectCombo, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 -}); - -BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; - -BI.shortcut("bi.single_select_add_combo", BI.SingleSelectCombo);/** - * - * 单选下拉框 - * @class BI.SingleSelectTrigger - * @extends BI.Trigger +BI.SingleSliderLabel.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_slider_label", BI.SingleSliderLabel);/** + * normal single slider + * Created by Young on 2017/6/21. */ +BI.SingleSliderNormal = BI.inherit(BI.Widget, { -BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { + _constant: { + HEIGHT: 28, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, - constants: { - height: 14, - rgap: 4, - lgap: 4 + props: { + baseCls: "bi-single-slider-normal bi-slider-track", + minMax: { + min: 0, + max: 100 + } + // color: "#3f8ce8" }, - _defaultConfig: function () { - return BI.extend(BI.SingleSelectTrigger.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-trigger bi-border", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - searcher: {}, - switcher: {}, + render: function () { + var self = this; + var c = this._constant; + var track = this._createTrack(); + this.slider = BI.createWidget({ + type: "bi.single_slider_button" + }); + this._draggable(this.slider); - adapter: null, - masker: {} + var sliderVertical = BI.createWidget({ + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.slider] + }], + hgap: c.SLIDER_WIDTH_HALF, + height: c.SLIDER_HEIGHT + }); + sliderVertical.element.click(function (e) { + if (self.enable) { + var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; + var trackLength = self.track.element[0].scrollWidth; + var percent = 0; + if (offset < 0) { + percent = 0; + } + if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { + percent = offset * 100 / self._getGrayTrackLength(); + } + if (offset > (trackLength - c.SLIDER_WIDTH)) { + percent = 100; + } + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setAllPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + self.value = v; + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + } }); - }, - _init: function () { - BI.SingleSelectTrigger.superclass._init.apply(this, arguments); + return { + type: "bi.absolute", + element: this, + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: track, + width: "100%", + height: c.TRACK_HEIGHT + }] + }], + hgap: 7, + height: c.TRACK_HEIGHT + }, + top: 3, + left: 0, + width: "100%" + }, { + el: sliderVertical, + top: 0, + left: 0, + width: "100%" + }] + }; + }, + _draggable: function (widget) { var self = this, o = this.options; - if (o.height) { - this.setHeight(o.height - 2); + var startDrag = false; + var size = 0, offset = 0, defaultSize = 0; + var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { + if (mouseMoveTracker.isDragging()) { + startDrag = true; + offset += deltaX; + size = optimizeSize(defaultSize + offset); + widget.element.addClass("dragging"); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 + self._setBlueTrack(significantPercent); + self._setSliderPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.value = v; + self.fireEvent(BI.SingleSliderNormal.EVENT_DRAG, v); + } + }, function () { + if (startDrag === true) { + size = optimizeSize(size); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setSliderPosition(significantPercent); + size = 0; + offset = 0; + defaultSize = size; + startDrag = false; + } + widget.element.removeClass("dragging"); + mouseMoveTracker.releaseMouseMoves(); + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + }, window); + widget.element.on("mousedown", function (event) { + if(!widget.isEnabled()) { + return; + } + defaultSize = this.offsetLeft; + optimizeSize(defaultSize); + mouseMoveTracker.captureMouseMoves(event); + }); + + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); } + }, - this.searcher = BI.createWidget(o.searcher, { - type: "bi.single_select_add_searcher", - height: o.height, - itemsCreator: o.itemsCreator, - valueFormatter: o.valueFormatter, - popup: {}, - adapter: o.adapter, - masker: o.masker - }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_START, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_START); - }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_PAUSE, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_PAUSE); - }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_SEARCHING, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_SEARCHING, arguments); - }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_STOP, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_STOP); + _createTrack: function () { + var self = this; + var c = this._constant; + this.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_CHANGE, arguments); + this.blueTrack = BI.createWidget({ + type: "bi.layout", + cls: "blue-track bi-high-light-background", + height: 6 }); + if (this.options.color) { + this.blueTrack.element.css({"background-color": this.options.color}); + } + + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.grayTrack, + top: 0, + left: 0, + width: "100%" + }, { + el: this.blueTrack, + top: 0, + left: 0, + width: "0%" + }] + }], + hgap: 8, + height: 8 + }, + top: 8, + left: 0, + width: "100%" + }], + ref: function (ref) { + self.track = ref; + } + }; + }, + + _checkValidation: function (v) { + return !(BI.isNull(v) || v < this.min || v > this.max); + }, - var wrapper = BI.createWidget({ - type: "bi.htape", - element: this, - items: [ - { - el: this.searcher, - width: "fill" - }, { - el: BI.createWidget(), - width: 30 - }] - }); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - getSearcher: function () { - return this.searcher; + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); }, - stopEditing: function () { - this.searcher.stopSearch(); + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setBlueTrack(percent); }, - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + _setVisible: function (visible) { + this.slider.setVisible(visible); }, - setValue: function (v) { - this.searcher.setValue(v); + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - getKey: function () { - return this.searcher.getKey(); + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); + }, + + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, getValue: function () { - return this.searcher.getValue(); - } -}); + return this.value; + }, -BI.SingleSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; -BI.SingleSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; -BI.SingleSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectTrigger.EVENT_START = "EVENT_START"; -BI.SingleSelectTrigger.EVENT_STOP = "EVENT_STOP"; -BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; + setValue: function (v) { + var value = BI.parseFloat(v); + if ((!isNaN(value))) { + if (this._checkValidation(value)) { + this.value = value; + } + if (value > this.max) { + this.value = this.max; + } + if (value < this.min) { + this.value = this.min; + } + } + }, -BI.shortcut("bi.single_select_add_trigger", BI.SingleSelectTrigger);/** - * searcher - * Created by guy on 15/11/3. - * @class BI.SingleSelectSearcher - * @extends Widget + setMinAndMax: function (v) { + var minNumber = BI.parseFloat(v.min); + var maxNumber = BI.parseFloat(v.max); + if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { + this.min = minNumber; + this.max = maxNumber; + } + }, + + reset: function () { + this._setVisible(false); + this.enable = false; + this.value = ""; + this.min = 0; + this.max = 0; + this._setBlueTrack(0); + }, + + populate: function () { + if (!isNaN(this.min) && !isNaN(this.max)) { + this._setVisible(true); + this.enable = true; + if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { + this._setAllPosition(this._getPercentByValue(this.value)); + } else { + this._setAllPosition(100); + } + } + } +}); +BI.SingleSliderNormal.EVENT_DRAG = "EVENT_DRAG"; +BI.shortcut("bi.single_slider_normal", BI.SingleSliderNormal);/** + * @class BI.SingleTreeCombo + * @extends BI.Widget */ -BI.SingleSelectSearcher = BI.inherit(BI.Widget, { +BI.SingleTreeCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearcher.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-searcher", - itemsCreator: BI.emptyFn, - el: {}, - popup: {}, - valueFormatter: BI.emptyFn, - adapter: null, - masker: {} + return BI.extend(BI.SingleTreeCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-tree-combo", + trigger: {}, + height: 24, + text: "", + items: [], + value: "" }); }, _init: function () { - BI.SingleSelectSearcher.superclass._init.apply(this, arguments); + BI.SingleTreeCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.editor = BI.createWidget(o.el, { - type: "bi.single_select_editor", - height: o.height - }); - this.searcher = BI.createWidget({ - type: "bi.searcher", - element: this, + this.trigger = BI.createWidget(BI.extend({ + type: "bi.single_tree_trigger", + text: o.text, height: o.height, - isAutoSearch: false, - isAutoSync: false, - onSearch: function (op, callback) { - callback(); - }, - el: this.editor, - - popup: BI.extend({ - type: "bi.single_select_search_add_pane", - valueFormatter: o.valueFormatter, - keywordGetter: function () { - return self.editor.getValue(); - }, - itemsCreator: function (op, callback) { - op.keyword = self.editor.getValue(); - this.setKeyword(op.keyword); - o.itemsCreator(op, callback); - } - }, o.popup), + items: o.items, + value: o.value + }, o.trigger)); - adapter: o.adapter, - masker: o.masker - }); - this.searcher.on(BI.Searcher.EVENT_START, function () { - self.fireEvent(BI.SingleSelectSearcher.EVENT_START); + this.popup = BI.createWidget({ + type: "bi.single_level_tree", + items: o.items, + value: o.value }); - this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { - if (this.hasMatched()) { + this.combo = BI.createWidget({ + type: "bi.combo", + element: this, + adjustLength: 2, + el: this.trigger, + popup: { + el: this.popup } - self.fireEvent(BI.SingleSelectSearcher.EVENT_PAUSE); }); - this.searcher.on(BI.Searcher.EVENT_STOP, function () { - self.fireEvent(BI.SingleSelectSearcher.EVENT_STOP); + + this.combo.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectSearcher.EVENT_CHANGE, arguments); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW, arguments); }); - this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { - var keywords = this.getKeywords(); - self.fireEvent(BI.SingleSelectSearcher.EVENT_SEARCHING, keywords); + + this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.SingleTreeCombo.EVENT_CHANGE); }); }, - adjustView: function () { - this.searcher.adjustView(); + populate: function (items) { + this.combo.populate(items); }, - isSearching: function () { - return this.searcher.isSearching(); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.trigger.setValue(v); + this.popup.setValue(v); }, - stopSearch: function () { - this.searcher.stopSearch(); - }, + getValue: function () { + return this.popup.getValue(); + } +}); - getKeyword: function () { - return this.editor.getValue(); - }, +BI.SingleTreeCombo.EVENT_CHANGE = "SingleTreeCombo.EVENT_CHANGE"; +BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.single_tree_combo", BI.SingleTreeCombo);/** + * @class BI.SingleTreePopup + * @extends BI.Pane + */ - hasMatched: function () { - return this.searcher.hasMatched(); - }, +BI.SingleTreePopup = BI.inherit(BI.Pane, { - hasChecked: function () { - return this.searcher.getView() && this.searcher.getView().hasChecked(); + _defaultConfig: function () { + return BI.extend(BI.SingleTreePopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-level-tree", + tipText: BI.i18nText("BI-No_Selected_Item"), + items: [], + value: "" + }); }, - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); - }, + _init: function () { + BI.SingleTreePopup.superclass._init.apply(this, arguments); + + var self = this, o = this.options; + + this.tree = BI.createWidget({ + type: "bi.level_tree", + expander: { + isDefaultInit: true + }, + items: o.items, + value: o.value, + chooseType: BI.Selection.Single + }); + + BI.createWidget({ + type: "bi.vertical", + element: this, + items: [this.tree] + }); + + this.tree.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); - setState: function (v) { - var o = this.options; - v || (v = ""); - if (v === "") { - this.editor.setState(BI.Selection.None); - } else { - this.editor.setState(o.valueFormatter(v + "") || (v + "")); - } - }, + this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleTreePopup.EVENT_CHANGE); + }); - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); + this.check(); }, - getKey: function () { - return this.editor.getValue(); + getValue: function () { + return this.tree.getValue(); }, - getValue: function () { - return this.searcher.getValue(); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.tree.setValue(v); }, populate: function (items) { - this.searcher.populate.apply(this.searcher, arguments); + BI.SingleTreePopup.superclass.populate.apply(this, arguments); + this.tree.populate(items); } }); -BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectSearcher.EVENT_START = "EVENT_START"; -BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP"; -BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.shortcut("bi.single_select_add_searcher", BI.SingleSelectSearcher);/** - * Created by User on 2017/11/16. +BI.SingleTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_level_tree", BI.SingleTreePopup);/** + * @class BI.SingleTreeTrigger + * @extends BI.Trigger */ -BI.SignTextEditor = BI.inherit(BI.Widget, { + +BI.SingleTreeTrigger = BI.inherit(BI.Trigger, { + _defaultConfig: function () { - var conf = BI.SignTextEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-sign-initial-editor", - hgap: 4, - vgap: 2, - lgap: 0, - rgap: 0, - tgap: 0, - bgap: 0, - validationChecker: BI.emptyFn, - quitChecker: BI.emptyFn, - allowBlank: true, - watermark: "", - errorText: "", + return BI.extend(BI.SingleTreeTrigger.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-tree-trigger", + height: 24, text: "", - height: 24 + items: [], + value: "" }); }, _init: function () { - BI.SignTextEditor.superclass._init.apply(this, arguments); + BI.SingleTreeTrigger.superclass._init.apply(this, arguments); + var self = this, o = this.options; - this.editor = BI.createWidget({ - type: "bi.editor", - height: o.height, - hgap: o.hgap, - vgap: o.vgap, - lgap: o.lgap, - rgap: o.rgap, - tgap: o.tgap, - bgap: o.bgap, - value: o.value, - validationChecker: o.validationChecker, - quitChecker: o.quitChecker, - allowBlank: o.allowBlank, - watermark: o.watermark, - errorText: o.errorText - }); - this.text = BI.createWidget({ - type: "bi.text_button", - cls: "sign-editor-text", - title: o.title, - warningTitle: o.warningTitle, - tipType: o.tipType, - textAlign: "left", - height: o.height, - hgap: 4, - handler: function () { - self._showInput(); - self.editor.focus(); - self.editor.selectAll(); - } - }); - this.text.on(BI.TextButton.EVENT_CHANGE, function () { - BI.nextTick(function () { - self.fireEvent(BI.SignTextEditor.EVENT_CLICK_LABEL); - }); - }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.text, - left: 0, - right: 0, - top: 0, - bottom: 0 - }] - }); - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.editor.on(BI.Editor.EVENT_CONFIRM, function () { - self._showHint(); - self._checkText(); - self.fireEvent(BI.SignTextEditor.EVENT_CONFIRM, arguments); - }); - this.editor.on(BI.Editor.EVENT_ERROR, function () { - self._checkText(); - }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, + + this.trigger = BI.createWidget({ + type: "bi.select_text_trigger", element: this, - items: [this.editor] + text: o.text, + items: o.items, + height: o.height, + value: o.value }); - this._showHint(); - self._checkText(); }, - _checkText: function () { - var o = this.options; - BI.nextTick(BI.bind(function () { - if (this.editor.getValue() === "") { - this.text.setValue(o.watermark || ""); - this.text.element.addClass("bi-water-mark"); - } else { - var v = this.editor.getValue(); - v = (BI.isEmpty(v) || v == o.text) ? o.text : v + o.text; - this.text.setValue(v); - this.text.element.removeClass("bi-water-mark"); + _checkTitle: function () { + var self = this, val = this.getValue(); + BI.any(this.options.items, function (i, item) { + if (val.contains(item.value)) { + self.trigger.setTitle(item.text || item.value); + return true; } - }, this)); - }, - - _showInput: function () { - this.editor.visible(); - this.text.invisible(); - }, - - _showHint: function () { - this.editor.invisible(); - this.text.visible(); - }, - - setTitle: function (title) { - this.text.setTitle(title); + }); }, - setWarningTitle: function (title) { - this.text.setWarningTitle(title); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.options.value = v; + this.trigger.setValue(v); + this._checkTitle(); }, - focus: function () { - this._showInput(); - this.editor.focus(); + getValue: function () { + return this.options.value || []; }, - blur: function () { - this.editor.blur(); - this._showHint(); - this._checkText(); - }, + populate: function (items) { + BI.SingleTreeTrigger.superclass.populate.apply(this, arguments); + this.trigger.populate(items); + } - doRedMark: function () { - if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { - return; - } - this.text.doRedMark.apply(this.text, arguments); - }, +}); - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); - }, +BI.shortcut("bi.single_tree_trigger", BI.SingleTreeTrigger);/** + * 可以单选多选切换的树 + * + * Created by GUY on 2015/12/21. + * @class BI.SwitchTree + * @extends BI.Widget + */ +BI.SwitchTree = BI.inherit(BI.Widget, { - doHighLight: function () { - if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { - return; - } - this.text.doHighLight.apply(this.text, arguments); + _defaultConfig: function () { + return BI.extend(BI.SwitchTree.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-switch-tree", + items: [] + }); }, - unHighLight: function () { - this.text.unHighLight.apply(this.text, arguments); + _init: function () { + BI.SwitchTree.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.tab = BI.createWidget({ + type: "bi.tab", + element: this, + tab: null, + showIndex: BI.SwitchTree.SelectType.SingleSelect, + cardCreator: BI.bind(this._createTree, this) + }); }, - isValid: function () { - return this.editor.isValid(); + _createTree: function (type) { + var self = this, o = this.options; + switch (type) { + case BI.SwitchTree.SelectType.SingleSelect: + this.levelTree = BI.createWidget({ + type: "bi.multilayer_single_level_tree", + isDefaultInit: true, + items: BI.deepClone(o.items), + value: o.value + }); + this.levelTree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SwitchTree.EVENT_CHANGE, arguments); + }); + return this.levelTree; + case BI.SwitchTree.SelectType.MultiSelect: + this.tree = BI.createWidget({ + type: "bi.simple_tree", + items: this._removeIsParent(BI.deepClone(o.items)), + value: o.value + }); + this.tree.on(BI.SimpleTreeView.EVENT_CHANGE, function () { + self.fireEvent(BI.SwitchTree.EVENT_CHANGE, arguments); + }); + return this.tree; + } }, - setErrorText: function (text) { - this.editor.setErrorText(text); + _removeIsParent: function (items) { + BI.each(items, function (i, item) { + BI.isNotNull(item.isParent) && delete item.isParent; + }); + return items; }, - getErrorText: function () { - return this.editor.getErrorText(); + switchSelect: function () { + switch (this.getSelect()) { + case BI.SwitchTree.SelectType.SingleSelect: + this.setSelect(BI.SwitchTree.SelectType.MultiSelect); + break; + case BI.SwitchTree.SelectType.MultiSelect: + this.setSelect(BI.SwitchTree.SelectType.SingleSelect); + break; + } }, - isEditing: function () { - return this.editor.isEditing(); + setSelect: function (v) { + this.tab.setSelect(v); }, - getLastValidValue: function () { - return this.editor.getLastValidValue(); + getSelect: function () { + return this.tab.getSelect(); }, setValue: function (v) { - this.editor.setValue(v); - this._checkText(); + this.storeValue = v; + switch (this.getSelect()) { + case BI.SwitchTree.SelectType.SingleSelect: + this.levelTree.setValue(v); + break; + case BI.SwitchTree.SelectType.MultiSelect: + this.tree.setValue(v); + break; + } }, getValue: function () { - return this.editor.getValue(); - }, - - getState: function () { - return this.text.getValue(); + return this.tab.getValue(); }, - setState: function (v) { - var o = this.options; - this._showHint(); - v = (BI.isEmpty(v) || v == o.text) ? o.text : v + o.text; - this.text.setValue(v); + populate: function (items) { + this.options.items = items; + if (BI.isNotNull(this.levelTree)) { + this.levelTree.populate(BI.deepClone(items)); + } + if (BI.isNotNull(this.tree)) { + this.tree.populate(this._removeIsParent(BI.deepClone(items))); + } } }); -BI.SignTextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.SignTextEditor.EVENT_CLICK_LABEL = "EVENT_CLICK_LABEL"; - -BI.shortcut("bi.sign_text_editor", BI.SignTextEditor);/** - * Created by zcf on 2016/9/22. +BI.SwitchTree.EVENT_CHANGE = "SwitchTree.EVENT_CHANGE"; +BI.SwitchTree.SelectType = { + SingleSelect: BI.Selection.Single, + MultiSelect: BI.Selection.Multi +}; +BI.shortcut("bi.switch_tree", BI.SwitchTree); +/** + * Created by Baron on 2015/10/19. */ -BI.SliderIconButton = BI.inherit(BI.Widget, { +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 () { - return BI.extend(BI.SliderIconButton.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-slider-button" + var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-date-interval" }); }, _init: function () { - BI.extend(BI.SliderIconButton.superclass._init.apply(this, arguments)); - this.slider = BI.createWidget({ - type: "bi.icon_button", - cls: "slider-icon slider-button", - iconWidth: 14, - iconHeight: 14, - height: 14, - width: 14 + 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({ - type: "bi.absolute", - element: this, + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, items: [{ - el: this.slider, - top: 7, - left: -7 - }], - width: 0, - height: 14 + 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.shortcut("bi.single_slider_button", BI.SliderIconButton);/** - * Created by zcf on 2016/9/22. +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.SingleSlider = BI.inherit(BI.Widget, { - _constant: { - EDITOR_WIDTH: 90, - EDITOR_HEIGHT: 30, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 +BI.TimeInterval = 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 () { - return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-slider bi-slider-track", - digit: false, - unit: "" + var conf = BI.TimeInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-time-interval" }); }, _init: function () { - BI.SingleSlider.superclass._init.apply(this, arguments); - var self = this, o = this.options; - var c = this._constant; - this.enable = false; - this.value = ""; - - this.grayTrack = BI.createWidget({ - type: "bi.layout", - cls: "gray-track", - height: 6 - }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 - }); - this.track = this._createTrackWrapper(); + BI.TimeInterval.superclass._init.apply(this, arguments); - this.slider = BI.createWidget({ - type: "bi.single_slider_button" - }); - this._draggable(this.slider); - var sliderVertical = BI.createWidget({ - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.slider] - }], - hgap: c.SLIDER_WIDTH_HALF, - height: c.SLIDER_HEIGHT - }); - sliderVertical.element.click(function (e) { - if (self.enable) { - var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; - var trackLength = self.track.element[0].scrollWidth; - var percent = 0; - if (offset < 0) { - percent = 0; - } - if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { - percent = offset * 100 / self._getGrayTrackLength(); - } - if (offset > (trackLength - c.SLIDER_WIDTH)) { - percent = 100; - } - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setAllPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.label.setValue(v); - self.value = v; - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); - } - }); + o.value = o.value || {}; + this.left = this._createCombo(o.value.start); + this.right = this._createCombo(o.value.end); this.label = BI.createWidget({ - type: "bi.sign_text_editor", - cls: "slider-editor-button", - errorText: "", - text: o.unit, - width: c.EDITOR_WIDTH - 2, - allowBlank: false, - validationChecker: function (v) { - return self._checkValidation(v); - } - }); - this.label.element.hover(function () { - self.label.element.removeClass("bi-border").addClass("bi-border"); - }, function () { - self.label.element.removeClass("bi-border"); - }); - this.label.on(BI.SignEditor.EVENT_CONFIRM, function () { - var v = BI.parseFloat(this.getValue()); - var percent = self._getPercentByValue(v); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setAllPosition(significantPercent); - this.setValue(v); - self.value = v; - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + type: "bi.label", + height: this.constants.height, + width: this.constants.width, + text: "-" }); - this._setVisible(false); BI.createWidget({ - type: "bi.absolute", - element: this, + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.track, - width: "100%", - height: c.TRACK_HEIGHT - }] - }], - hgap: 7, - height: c.TRACK_HEIGHT - }, - top: 23, - left: 0, - width: "100%" - }, { - el: sliderVertical, - top: 20, - left: 0, - width: "100%" + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] }, { - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.label] - }], - rgap: c.EDITOR_WIDTH, - height: c.EDITOR_HEIGHT - }, - top: 0, - left: 0, - width: "100%" + 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 + ] + }); }, - _draggable: function (widget) { - var self = this, o = this.options; - var startDrag = false; - var size = 0, offset = 0, defaultSize = 0; - var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { - if (mouseMoveTracker.isDragging()) { - startDrag = true; - offset += deltaX; - size = optimizeSize(defaultSize + offset); - widget.element.addClass("dragging"); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 - self._setBlueTrack(significantPercent); - self._setLabelPosition(significantPercent); - self._setSliderPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.label.setValue(v); - self.value = v; - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); - } - }, function () { - if (startDrag === true) { - size = optimizeSize(size); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setSliderPosition(significantPercent); - size = 0; - offset = 0; - defaultSize = size; - startDrag = false; + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_date_time_combo", + value: v + }); + combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.TimeInterval.EVENT_ERROR); + }); + + 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)) { + 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.TimeInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); } - widget.element.removeClass("dragging"); - mouseMoveTracker.releaseMouseMoves(); - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); - }, window); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; + }); + + 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)) { + 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.TimeInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); }); - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); - } - }, - - _createTrackWrapper: function () { - return BI.createWidget({ - type: "bi.absolute", - items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.grayTrack, - top: 0, - left: 0, - width: "100%" - }, { - el: this.blueTrack, - top: 0, - left: 0, - width: "0%" - }] - }], - hgap: 8, - height: 8 - }, - top: 8, - left: 0, - width: "100%" - }] + combo.on(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hidePopupView(); + self.right.hidePopupView(); }); - }, + // 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)) { + // 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.TimeInterval.EVENT_ERROR); + // } else { + // self._clearTitle(); + // self.element.removeClass(self.constants.timeErrorCls); + // } + // }); - _checkValidation: function (v) { - var o = this.options; - var valid = false; - if (BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)) { - if(o.digit === false) { - valid = true; + 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)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + self.fireEvent(BI.TimeInterval.EVENT_ERROR); }else{ - var dotText = (v + "").split(".")[1] || ""; - valid = (dotText.length === o.digit); + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.TimeInterval.EVENT_CHANGE); } - } - return valid; + }); + return combo; + }, + _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; + }, + _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 %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) { + 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.TimeInterval.EVENT_VALID = "EVENT_VALID"; +BI.TimeInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.TimeInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.time_interval", BI.TimeInterval);/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.YearCard + * @extends BI.Trigger + */ +BI.DynamicYearCard = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-year-card" }, - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); + render: function () { + var self = this; + return { + type: "bi.vertical", + items: [{ + type: "bi.label", + text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), + textAlign: "left", + height: 24 + }, { + type: "bi.dynamic_date_param_item", + ref: function () { + self.item = this; + }, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }], + vgap: 10, + hgap: 10 + }; }, - _setLabelPosition: function (percent) { - this.label.element.css({left: percent + "%"}); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); + setValue: function (v) { + v = v || {year: 0}; + this.item.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); }, - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setLabelPosition(percent); - this._setBlueTrack(percent); + getValue: function () { + var value = this.item.getValue(); + return { + year: (value.offset === 0 ? -value.value : value.value) + }; + } +}); +BI.DynamicYearCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_card", BI.DynamicYearCard);/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.StaticYearCard + * @extends BI.Trigger + */ +BI.StaticYearCard = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.StaticYearCard.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-year-card", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31" // 最大日期 + }); }, - _setVisible: function (visible) { - this.slider.setVisible(visible); - this.label.setVisible(visible); + _createYearCalendar: function (v) { + var o = this.options, y = this._year; + + var calendar = BI.createWidget({ + type: "bi.year_calendar", + behaviors: o.behaviors, + min: o.min, + max: o.max, + logic: { + dynamic: true + }, + year: y + v * 12 + }); + calendar.setValue(this._year); + return calendar; }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; - }, + _init: function () { + BI.StaticYearCard.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.selectedYear = this._year = BI.getDate().getFullYear(); + + this.backBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "pre-page-h-font", + width: 25, + height: 25, + value: -1, + listeners: [{ + eventName: BI.IconButton.EVENT_CHANGE, + action: function () { + self.navigation.setSelect(self.navigation.getSelect() - 1); + self._checkLeftValid(); + self._checkRightValid(); + } + }] + }); + + this.preBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "next-page-h-font", + width: 25, + height: 25, + value: 1, + listeners: [{ + eventName: BI.IconButton.EVENT_CHANGE, + action: function () { + self.navigation.setSelect(self.navigation.getSelect() + 1); + self._checkLeftValid(); + self._checkRightValid(); + } + }] + }); + + this.navigation = BI.createWidget({ + type: "bi.navigation", + direction: "top", + element: this, + single: true, + logic: { + dynamic: true + }, + tab: { + type: "bi.htape", + cls: "bi-border-top bi-border-bottom", + height: 30, + items: [{ + el: { + type: "bi.center_adapt", + items: [self.backBtn] + }, + width: 25 + }, { + type: "bi.layout" + }, { + el: { + type: "bi.center_adapt", + items: [self.preBtn] + }, + width: 25 + }] + }, + cardCreator: BI.bind(this._createYearCalendar, this), - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); - }, + afterCardShow: function () { + this.setValue(self.selectedYear); + var calendar = this.getSelectedCard(); + self.backBtn.setEnable(!calendar.isFrontYear()); + self.preBtn.setEnable(!calendar.isFinalYear()); + } + }); - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); - }, + this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { + self.selectedYear = this.getValue(); + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + self.fireEvent(BI.StaticYearCard.EVENT_CHANGE, self.selectedYear); + }); - getValue: function () { - return this.value; + if(BI.isKey(o.value)){ + this.setValue(o.value); + } }, - setValue: function (v) { + _checkLeftValid: function () { var o = this.options; - v = BI.parseFloat(v); - v = o.digit === false ? v : v.toFixed(o.digit); - if ((!isNaN(v))) { - if (this._checkValidation(v)) { - this.value = v; - } - if (v > this.max) { - this.value = this.max; - } - if (v < this.min) { - this.value = this.min; - } - } + var valid = true; + this.backBtn.setEnable(valid); + return valid; }, - setMinAndMax: function (v) { - var minNumber = BI.parseFloat(v.min); - var maxNumber = BI.parseFloat(v.max); - if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { - this.min = minNumber; - this.max = maxNumber; - } + _checkRightValid: function () { + var o = this.options; + var valid = true; + this.preBtn.setEnable(valid); + return valid; }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.value = ""; - this.min = 0; - this.max = 0; - this._setBlueTrack(0); - + getValue: function () { + return { + year: this.selectedYear + }; }, - populate: function () { - if (!isNaN(this.min) && !isNaN(this.max)) { - this._setVisible(true); - this.enable = true; - this.label.setErrorText(BI.i18nText("BI-Please_Enter") + this.min + "-" + this.max + BI.i18nText("BI-Basic_De") + BI.i18nText("BI-Basic_Number")); - if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { - this.label.setValue(this.value); - this._setAllPosition(this._getPercentByValue(this.value)); - } else { - this.label.setValue(this.max); - this._setAllPosition(100); - } + setValue: function (obj) { + var o = this.options; + obj = obj || {}; + var v = obj.year; + if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { + v = BI.getDate().getFullYear(); + this.selectedYear = ""; + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(""); + } else { + this.selectedYear = BI.parseInt(v); + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(this.selectedYear); } + this._checkLeftValid(); + this._checkRightValid(); } }); -BI.SingleSlider.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_slider", BI.SingleSlider);/** - * Created by Urthur on 2017/9/12. - */ -BI.SingleSliderLabel = BI.inherit(BI.Widget, { - _constant: { - EDITOR_WIDTH: 90, - EDITOR_HEIGHT: 20, - HEIGHT: 20, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 - }, - _defaultConfig: function () { - return BI.extend(BI.SingleSliderLabel.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-slider-label bi-slider-track", - digit: false, - unit: "" - }); +BI.StaticYearCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-year-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, - _init: function () { - BI.SingleSliderLabel.superclass._init.apply(this, arguments); + _init: function () { + BI.DynamicYearCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - var c = this._constant; - this.enable = false; - this.value = ""; - - this.grayTrack = BI.createWidget({ - type: "bi.layout", - cls: "gray-track", - height: 6 + this.storeValue = o.value; + this.trigger = BI.createWidget({ + type: "bi.dynamic_year_trigger", + min: o.min, + max: o.max, + value: o.value || "" }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 + this.trigger.on(BI.DynamicYearTrigger.EVENT_FOCUS, function () { + self.storeTriggerValue = this.getKey(); }); - this.track = this._createTrackWrapper(); - - this.slider = BI.createWidget({ - type: "bi.single_slider_button" + this.trigger.on(BI.DynamicYearTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - this._draggable(this.slider); - var sliderVertical = BI.createWidget({ - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.slider] - }], - hgap: c.SLIDER_WIDTH_HALF, - height: c.SLIDER_HEIGHT + this.trigger.on(BI.DynamicYearTrigger.EVENT_STOP, function () { + self.combo.showView(); }); - sliderVertical.element.click(function (e) { - if (self.enable) { - var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; - var trackLength = self.track.element[0].scrollWidth; - var percent = 0; - if (offset < 0) { - percent = 0; - } - if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { - percent = offset * 100 / self._getGrayTrackLength(); - } - if (offset > (trackLength - c.SLIDER_WIDTH)) { - percent = 100; - } - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setAllPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.label.setText(v + o.unit); - self.value = v; - self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); + this.trigger.on(BI.DynamicYearTrigger.EVENT_ERROR, function () { + self.combo.isViewVisible() && self.combo.hideView(); + }); + this.trigger.on(BI.DynamicYearTrigger.EVENT_CONFIRM, function () { + if (self.combo.isViewVisible()) { + return; + } + if (this.getKey() && this.getKey() !== self.storeTriggerValue) { + self.storeValue = self.trigger.getValue(); + self.setValue(self.storeValue); + } else if (!this.getKey()) { + self.storeValue = null; + self.setValue(); + } + self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); + }); + + this.combo = BI.createWidget({ + type: "bi.combo", + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + stopPropagation: false, + el: { + type: "bi.dynamic_year_popup", + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicYearPopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({year: date.getFullYear()}); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }], + behaviors: o.behaviors, + min: o.min, + max: o.max + }, + value: o.value || "" } }); - this.label = BI.createWidget({ - type: "bi.label", - height: c.HEIGHT, - width: c.EDITOR_WIDTH - 2 + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW); }); - this._setVisible(false); BI.createWidget({ - type: "bi.absolute", + type: "bi.htape", element: this, + ref: function () { + self.comboWrapper = this; + }, items: [{ el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.track, - width: "100%", - height: c.TRACK_HEIGHT - }] - }], - hgap: 7, - height: c.TRACK_HEIGHT - }, - top: 13, - left: 0, - width: "100%" - }, { - el: sliderVertical, - top: 10, - left: 0, - width: "100%" - }, { - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.label] - }], - rgap: c.EDITOR_WIDTH, - height: c.EDITOR_HEIGHT + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, + ref: function () { + self.changeIcon = this; + } }, - top: 0, - left: 0, - width: "100%" - }] + width: 24 + }, this.combo] }); + this._checkDynamicValue(o.value); }, - _draggable: function (widget) { - var self = this, o = this.options; - var startDrag = false; - var size = 0, offset = 0, defaultSize = 0; - var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { - if (mouseMoveTracker.isDragging()) { - startDrag = true; - offset += deltaX; - size = optimizeSize(defaultSize + offset); - widget.element.addClass("dragging"); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 - self._setBlueTrack(significantPercent); - self._setLabelPosition(significantPercent); - self._setSliderPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.label.setValue(v); - self.value = v; - self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); - } - }, function () { - if (startDrag === true) { - size = optimizeSize(size); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setSliderPosition(significantPercent); - size = 0; - offset = 0; - defaultSize = size; - startDrag = false; - } - widget.element.removeClass("dragging"); - mouseMoveTracker.releaseMouseMoves(); - self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); - }, window); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; - } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); - }); - - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicYearCombo.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; } }, - _createTrackWrapper: function () { - return BI.createWidget({ - type: "bi.absolute", + setValue: function (v) { + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); + }, + + getValue: function () { + return this.storeValue; + } + +}); +BI.DynamicYearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.dynamic_year_combo", BI.DynamicYearCombo); + +BI.extend(BI.DynamicYearCombo, { + Static: 1, + Dynamic: 2 +});/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.DynamicYearPopup + * @extends BI.Trigger + */ +BI.DynamicYearPopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 + }, + + props: { + baseCls: "bi-year-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 + }, + + render: function () { + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicYearCombo.Static}; + return { + type: "bi.vtape", items: [{ + el: this._getTabJson() + }, { el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.grayTrack, - top: 0, - left: 0, - width: "100%" - }, { - el: this.blueTrack, - top: 0, - left: 0, - width: "0%" + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE); + } }] - }], - hgap: 8, - height: 8 + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-left bi-border-right bi-border-top", + shadow: true, + text: BI.i18nText("BI-Basic_Current_Year"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] }, - top: 8, - left: 0, - width: "100%" + height: 24 }] - }); - }, - - _checkValidation: function (v) { - return BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max); - }, - - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); - }, - - _setLabelPosition: function (percent) { - this.label.element.css({left: percent + "%"}); - }, - - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); - }, - - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setLabelPosition(percent); - this._setBlueTrack(percent); - }, - - _setVisible: function (visible) { - this.slider.setVisible(visible); - this.label.setVisible(visible); - }, - - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; - }, - - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); + }; }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y"); + this.textButton.setValue(date); + this.textButton.setEnable(false); + } }, - getValue: function () { - return this.value; + _getTabJson: function () { + var self = this, o = this.options; + return { + type: "bi.tab", + 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-Basic_Year_Fen"), + value: BI.DynamicYearCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicYearCombo.Dynamic + }], { + textAlign: "center" + }) + }, + cardCreator: function (v) { + switch (v) { + case BI.DynamicYearCombo.Dynamic: + return { + type: "bi.dynamic_year_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicYearCombo.Static: + default: + return { + type: "bi.static_year_card", + behaviors: o.behaviors, + min: self.options.min, + max: self.options.max, + listeners: [{ + eventName: BI.StaticYearCard.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.EVENT_CHANGE); + } + }], + ref: function () { + self.year = this; + } + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicYearCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.year.setValue({year: date.getFullYear()}); + self._setInnerValue(); + break; + case BI.DynamicYearCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; }, setValue: function (v) { - var o = this.options; - v = BI.parseFloat(v); - v = o.digit === false ? v : v.toFixed(o.digit); - if ((!isNaN(v))) { - if (this._checkValidation(v)) { - this.value = v; - } - if (v > this.max) { - this.value = this.max; - } - if (v < this.min) { - this.value = this.min; - } - } - }, - - setMinAndMax: function (v) { - var minNumber = BI.parseFloat(v.min); - var maxNumber = BI.parseFloat(v.max); - if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { - this.min = minNumber; - this.max = maxNumber; + 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: + this.year.setValue(value); + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); + this.textButton.setEnable(true); + break; } }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.value = ""; - this.min = 0; - this.max = 0; - this._setBlueTrack(0); - }, - - populate: function () { - var o = this.options; - if (!isNaN(this.min) && !isNaN(this.max)) { - this._setVisible(true); - this.enable = true; - if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { - this.label.setValue(this.value + o.unit); - this._setAllPosition(this._getPercentByValue(this.value)); - } else { - this.label.setValue(this.max + o.unit); - this._setAllPosition(100); - } - } + getValue: function () { + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; } -}); -BI.SingleSliderLabel.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_slider_label", BI.SingleSliderLabel);/** - * normal single slider - * Created by Young on 2017/6/21. - */ -BI.SingleSliderNormal = BI.inherit(BI.Widget, { - _constant: { - HEIGHT: 28, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 +}); +BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicYearPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_popup", BI.DynamicYearPopup);BI.DynamicYearTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), + errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") }, - props: { - baseCls: "bi-single-slider-normal bi-slider-track", - minMax: { - min: 0, - max: 100 - } - // color: "#3f8ce8" + _defaultConfig: function () { + return BI.extend(BI.DynamicYearTrigger.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-year-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 + }); }, - - render: function () { - var self = this; - var c = this._constant; - var track = this._createTrack(); - this.slider = BI.createWidget({ - type: "bi.single_slider_button" + _init: function () { + BI.DynamicYearTrigger.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) { + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); + }, + quitChecker: function (v) { + return false; + }, + hgap: c.hgap, + vgap: c.vgap, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + allowBlank: true, + errorText: function (v) { + return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; + } }); - this._draggable(this.slider); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_FOCUS); + }); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_STOP); + }); + this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setValue(value); + } + if (BI.isNotEmptyString(value)) { + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: value + } + }; + } - var sliderVertical = BI.createWidget({ - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.slider] - }], - hgap: c.SLIDER_WIDTH_HALF, - height: c.SLIDER_HEIGHT + self.fireEvent(BI.DynamicYearTrigger.EVENT_CONFIRM); }); - sliderVertical.element.click(function (e) { - if (self.enable) { - var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; - var trackLength = self.track.element[0].scrollWidth; - var percent = 0; - if (offset < 0) { - percent = 0; - } - if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { - percent = offset * 100 / self._getGrayTrackLength(); - } - if (offset > (trackLength - c.SLIDER_WIDTH)) { - percent = 100; - } - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setAllPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - self.value = v; - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + this.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); } }); - - return { - type: "bi.absolute", + this.editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_START); + }); + this.editor.on(BI.SignEditor.EVENT_ERROR, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_ERROR); + }); + BI.createWidget({ element: this, + type: "bi.htape", items: [{ + el: this.editor + }, { el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: track, - width: "100%", - height: c.TRACK_HEIGHT - }] - }], - hgap: 7, - height: c.TRACK_HEIGHT + type: "bi.text_button", + baseCls: "bi-trigger-year-text", + text: BI.i18nText("BI-Multi_Date_Year"), + width: o.height }, - top: 3, - left: 0, - width: "100%" + width: o.height }, { - el: sliderVertical, - top: 0, - left: 0, - width: "100%" + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height }] - }; - }, - - _draggable: function (widget) { - var self = this, o = this.options; - var startDrag = false; - var size = 0, offset = 0, defaultSize = 0; - var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { - if (mouseMoveTracker.isDragging()) { - startDrag = true; - offset += deltaX; - size = optimizeSize(defaultSize + offset); - widget.element.addClass("dragging"); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 - self._setBlueTrack(significantPercent); - self._setSliderPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.value = v; - self.fireEvent(BI.SingleSliderNormal.EVENT_DRAG, v); - } - }, function () { - if (startDrag === true) { - size = optimizeSize(size); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setSliderPosition(significantPercent); - size = 0; - offset = 0; - defaultSize = size; - startDrag = false; - } - widget.element.removeClass("dragging"); - mouseMoveTracker.releaseMouseMoves(); - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); - }, window); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; - } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); }); + this.setValue(o.value); + }, - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); + _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")); } + return value; }, - _createTrack: function () { - var self = this; - var c = this._constant; - this.grayTrack = BI.createWidget({ - type: "bi.layout", - cls: "gray-track", - height: 6 - }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 - }); - if (this.options.color) { - this.blueTrack.element.css({"background-color": this.options.color}); + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); + }, + + setValue: function (v) { + var type, value; + 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: + value = value || {}; + this.editor.setState(value.year); + this.editor.setValue(value.year); + this.editor.setTitle(value.year); + break; } + }, + + getValue: function () { + return this.storeValue; + }, + + getKey: function () { + return this.editor.getValue() | 0; + } +}); +BI.DynamicYearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicYearTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearTrigger.EVENT_START = "EVENT_START"; +BI.DynamicYearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearTrigger.EVENT_STOP = "EVENT_STOP"; +BI.shortcut("bi.dynamic_year_trigger", BI.DynamicYearTrigger);/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.YearCard + * @extends BI.Trigger + */ +BI.DynamicYearMonthCard = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-year-month-card" + }, + render: function () { + var self = this; return { - type: "bi.absolute", + type: "bi.vertical", items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.grayTrack, - top: 0, - left: 0, - width: "100%" - }, { - el: this.blueTrack, - top: 0, - left: 0, - width: "0%" - }] - }], - hgap: 8, - height: 8 + type: "bi.label", + text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), + textAlign: "left", + height: 24 + }, { + type: "bi.dynamic_date_param_item", + ref: function () { + self.year = this; + }, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }, { + type: "bi.dynamic_date_param_item", + dateType: BI.DynamicDateCard.TYPE.MONTH, + ref: function () { + self.month = this; }, - top: 8, - left: 0, - width: "100%" + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] }], - ref: function (ref) { - self.track = ref; - } + vgap: 10, + hgap: 10 }; }, - _checkValidation: function (v) { - return !(BI.isNull(v) || v < this.min || v > this.max); - }, - - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); + setValue: function (v) { + v = v || {year: 0, month: 0}; + this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); + this.month.setValue(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); }, - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setBlueTrack(percent); - }, + getValue: function () { + var year = this.year.getValue(); + var month = this.month.getValue(); + return { + year: (year.offset === 0 ? -year.value : year.value), + month: (month.offset === 0 ? -month.value : month.value) + }; + } +}); +BI.DynamicYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_month_card", BI.DynamicYearMonthCard);BI.StaticYearMonthCard = BI.inherit(BI.Widget, { - _setVisible: function (visible) { - this.slider.setVisible(visible); + props: { + baseCls: "bi-static-year-month-card", + behaviors: {} }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + _createMonths: function () { + // 纵向排列月 + var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; + var items = []; + items.push(month.slice(0, 2)); + items.push(month.slice(2, 4)); + items.push(month.slice(4, 6)); + items.push(month.slice(6, 8)); + items.push(month.slice(8, 10)); + items.push(month.slice(10, 12)); + return BI.map(items, function (i, item) { + return BI.map(item, function (j, td) { + return { + type: "bi.text_item", + cls: "bi-list-item-active", + textAlign: "center", + whiteSpace: "nowrap", + once: false, + forceSelected: true, + height: 23, + width: 38, + value: td, + text: td + 1 + }; + }); + }); }, - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); + render: function () { + var self = this, o = this.options; + return { + type: "bi.vertical", + items: [{ + type: "bi.year_picker", + ref: function () { + self.yearPicker = this; + }, + height: 30, + listeners: [{ + eventName: BI.YearPicker.EVENT_CHANGE, + action: function () { + var value = this.getValue(); + self.setValue({ + year: value, + month: self.selectedMonth + }); + } + }] + }, { + type: "bi.button_group", + behaviors: o.behaviors, + ref: function () { + self.month = this; + }, + items: this._createMonths(), + layouts: [BI.LogicFactory.createLogic("table", BI.extend({ + dynamic: true + }, { + columns: 2, + rows: 6, + columnSize: [1 / 2, 1 / 2], + rowSize: 25 + })), { + type: "bi.center_adapt", + vgap: 1, + hgap: 2 + }], + value: o.value, + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + self.selectedYear = self.yearPicker.getValue(); + self.selectedMonth = this.getValue()[0]; + self.fireEvent(BI.StaticYearMonthCard.EVENT_CHANGE); + } + }] + }] + }; }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); - }, getValue: function () { - return this.value; - }, - - setValue: function (v) { - var value = BI.parseFloat(v); - if ((!isNaN(value))) { - if (this._checkValidation(value)) { - this.value = value; - } - if (value > this.max) { - this.value = this.max; - } - if (value < this.min) { - this.value = this.min; - } - } - }, - - setMinAndMax: function (v) { - var minNumber = BI.parseFloat(v.min); - var maxNumber = BI.parseFloat(v.max); - if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { - this.min = minNumber; - this.max = maxNumber; - } - }, - - reset: function () { - this._setVisible(false); - this.enable = false; - this.value = ""; - this.min = 0; - this.max = 0; - this._setBlueTrack(0); + return { + year: this.selectedYear, + month: this.selectedMonth + }; }, - populate: function () { - if (!isNaN(this.min) && !isNaN(this.max)) { - this._setVisible(true); - this.enable = true; - if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { - this._setAllPosition(this._getPercentByValue(this.value)); - } else { - this._setAllPosition(100); - } + setValue: function (obj) { + var o = this.options; + obj = obj || {}; + obj.year = obj.year || 0; + obj.month = obj.month || 0; + if (BI.checkDateVoid(obj.year, obj.month, 1, o.min, o.max)[0]) { + var year = BI.getDate().getFullYear(); + var month = BI.getDate().getMonth(); + this.selectedYear = ""; + this.selectedMonth = ""; + this.yearPicker.setValue(year); + this.month.setValue(month); + } else { + this.selectedYear = BI.parseInt(obj.year); + this.selectedMonth = BI.parseInt(obj.month); + this.yearPicker.setValue(this.selectedYear); + this.month.setValue(this.selectedMonth); } } }); -BI.SingleSliderNormal.EVENT_DRAG = "EVENT_DRAG"; -BI.shortcut("bi.single_slider_normal", BI.SingleSliderNormal);/** - * @class BI.SingleTreeCombo - * @extends BI.Widget - */ -BI.SingleTreeCombo = BI.inherit(BI.Widget, { +BI.StaticYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearMonthCombo = BI.inherit(BI.Single, { - _defaultConfig: function () { - return BI.extend(BI.SingleTreeCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-tree-combo", - trigger: {}, - height: 24, - text: "", - items: [], - value: "" + props: { + baseCls: "bi-year-month-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 + }, + + _init: function () { + BI.DynamicYearMonthCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.storeValue = o.value; + this.trigger = BI.createWidget({ + type: "bi.dynamic_year_month_trigger", + min: o.min, + max: o.max, + value: o.value || "" + }); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); + }); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_STOP, function () { + self.combo.showView(); + }); + 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()) { + return; + } + self.storeValue = self.trigger.getValue(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); }); - }, - - _init: function () { - BI.SingleTreeCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.trigger = BI.createWidget(BI.extend({ - type: "bi.single_tree_trigger", - text: o.text, - height: o.height, - items: o.items, - value: o.value - }, o.trigger)); - - this.popup = BI.createWidget({ - type: "bi.single_level_tree", - items: o.items, - value: o.value + this.trigger.on(BI.DynamicYearMonthCombo.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_FOCUS); }); this.combo = BI.createWidget({ type: "bi.combo", - element: this, - adjustLength: 2, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, el: this.trigger, popup: { - el: this.popup + minWidth: 85, + stopPropagation: false, + el: { + type: "bi.dynamic_year_month_popup", + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicYearMonthPopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({year: date.getFullYear()}); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }], + behaviors: o.behaviors, + min: o.min, + max: o.max + }, + value: o.value || "" } }); - - this.combo.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW, arguments); - }); - - this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.SingleTreeCombo.EVENT_CHANGE); - }); - }, - - populate: function (items) { - this.combo.populate(items); - }, - - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.trigger.setValue(v); - this.popup.setValue(v); - }, - - getValue: function () { - return this.popup.getValue(); - } -}); - -BI.SingleTreeCombo.EVENT_CHANGE = "SingleTreeCombo.EVENT_CHANGE"; -BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.single_tree_combo", BI.SingleTreeCombo);/** - * @class BI.SingleTreePopup - * @extends BI.Pane - */ - -BI.SingleTreePopup = BI.inherit(BI.Pane, { - - _defaultConfig: function () { - return BI.extend(BI.SingleTreePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-level-tree", - tipText: BI.i18nText("BI-No_Selected_Item"), - items: [], - value: "" - }); - }, - - _init: function () { - BI.SingleTreePopup.superclass._init.apply(this, arguments); - - var self = this, o = this.options; - - this.tree = BI.createWidget({ - type: "bi.level_tree", - expander: { - isDefaultInit: true - }, - items: o.items, - value: o.value, - chooseType: BI.Selection.Single + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW); }); BI.createWidget({ - type: "bi.vertical", + type: "bi.htape", element: this, - items: [this.tree] - }); - - this.tree.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleTreePopup.EVENT_CHANGE); - }); - - this.check(); - }, - - getValue: function () { - return this.tree.getValue(); - }, - - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.tree.setValue(v); - }, - - populate: function (items) { - BI.SingleTreePopup.superclass.populate.apply(this, arguments); - this.tree.populate(items); - } -}); - -BI.SingleTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_level_tree", BI.SingleTreePopup);/** - * @class BI.SingleTreeTrigger - * @extends BI.Trigger - */ - -BI.SingleTreeTrigger = BI.inherit(BI.Trigger, { - - _defaultConfig: function () { - return BI.extend(BI.SingleTreeTrigger.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-tree-trigger", - height: 24, - text: "", - items: [], - value: "" + ref: function () { + self.comboWrapper = this; + }, + 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 + }, this.combo] }); + this._checkDynamicValue(o.value); }, - _init: function () { - BI.SingleTreeTrigger.superclass._init.apply(this, arguments); - - var self = this, o = this.options; - - this.trigger = BI.createWidget({ - type: "bi.select_text_trigger", - element: this, - text: o.text, - items: o.items, - height: o.height, - value: o.value - }); + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicYearMonthCombo.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; + } }, - _checkTitle: function () { - var self = this, val = this.getValue(); - BI.any(this.options.items, function (i, item) { - if (val.contains(item.value)) { - self.trigger.setTitle(item.text || item.value); - return true; - } - }); + hideView: function () { + this.combo.hideView(); }, setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.options.value = v; + this.storeValue = v; this.trigger.setValue(v); - this._checkTitle(); + this._checkDynamicValue(v); }, getValue: function () { - return this.options.value || []; + return this.storeValue; }, - populate: function (items) { - BI.SingleTreeTrigger.superclass.populate.apply(this, arguments); - this.trigger.populate(items); + 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); -BI.shortcut("bi.single_tree_trigger", BI.SingleTreeTrigger);/** - * 可以单选多选切换的树 +BI.extend(BI.DynamicYearMonthCombo, { + Static: 1, + Dynamic: 2 +});/** + * 年月 * - * Created by GUY on 2015/12/21. - * @class BI.SwitchTree - * @extends BI.Widget + * Created by GUY on 2015/9/2. + * @class BI.DynamicYearMonthPopup + * @extends BI.Trigger */ -BI.SwitchTree = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.SwitchTree.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-switch-tree", - items: [] - }); - }, - - _init: function () { - BI.SwitchTree.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.tab = BI.createWidget({ - type: "bi.tab", - element: this, - tab: null, - showIndex: BI.SwitchTree.SelectType.SingleSelect, - cardCreator: BI.bind(this._createTree, this) - }); +BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 }, - _createTree: function (type) { - var self = this, o = this.options; - switch (type) { - case BI.SwitchTree.SelectType.SingleSelect: - this.levelTree = BI.createWidget({ - type: "bi.multilayer_single_level_tree", - isDefaultInit: true, - items: BI.deepClone(o.items), - value: o.value - }); - this.levelTree.on(BI.LevelTree.EVENT_CHANGE, function () { - self.fireEvent(BI.SwitchTree.EVENT_CHANGE, arguments); - }); - return this.levelTree; - case BI.SwitchTree.SelectType.MultiSelect: - this.tree = BI.createWidget({ - type: "bi.simple_tree", - items: this._removeIsParent(BI.deepClone(o.items)), - value: o.value - }); - this.tree.on(BI.SimpleTreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.SwitchTree.EVENT_CHANGE, arguments); - }); - return this.tree; - } + props: { + baseCls: "bi-year-month-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 }, - _removeIsParent: function (items) { - BI.each(items, function (i, item) { - BI.isNotNull(item.isParent) && delete item.isParent; - }); - return items; + render: function () { + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicYearMonthCombo.Static}; + return { + type: "bi.vtape", + items: [{ + el: this._getTabJson() + }, { + el: { + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearMonthPopup.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-Basic_Current_Month"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 + }] + }; }, - switchSelect: function () { - switch (this.getSelect()) { - case BI.SwitchTree.SelectType.SingleSelect: - this.setSelect(BI.SwitchTree.SelectType.MultiSelect); - break; - case BI.SwitchTree.SelectType.MultiSelect: - this.setSelect(BI.SwitchTree.SelectType.SingleSelect); - break; + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y-%x"); + this.textButton.setValue(date); + this.textButton.setEnable(false); } }, - setSelect: function (v) { - this.tab.setSelect(v); - }, - - getSelect: function () { - return this.tab.getSelect(); + _getTabJson: function () { + var self = this, o = this.options; + return { + type: "bi.tab", + 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-Basic_Year_Fen"), + value: BI.DynamicYearCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicYearCombo.Dynamic + }], { + textAlign: "center" + }) + }, + cardCreator: function (v) { + switch (v) { + case BI.DynamicYearCombo.Dynamic: + return { + type: "bi.dynamic_year_month_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicYearCombo.Static: + default: + return { + type: "bi.static_year_month_card", + behaviors: o.behaviors, + min: self.options.min, + max: self.options.max, + listeners: [{ + eventName: BI.StaticYearMonthCard.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearMonthPopup.EVENT_CHANGE); + } + }], + ref: function () { + self.year = this; + } + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicYearCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.year.setValue({year: date.getFullYear(), month: date.getMonth()}); + self._setInnerValue(); + break; + case BI.DynamicYearCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; }, setValue: function (v) { this.storeValue = v; - switch (this.getSelect()) { - case BI.SwitchTree.SelectType.SingleSelect: - this.levelTree.setValue(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.SwitchTree.SelectType.MultiSelect: - this.tree.setValue(v); + case BI.DynamicDateCombo.Static: + default: + this.year.setValue(value); + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); + this.textButton.setEnable(true); break; } }, getValue: function () { - return this.tab.getValue(); - }, - - populate: function (items) { - this.options.items = items; - if (BI.isNotNull(this.levelTree)) { - this.levelTree.populate(BI.deepClone(items)); - } - if (BI.isNotNull(this.tree)) { - this.tree.populate(this._removeIsParent(BI.deepClone(items))); - } + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; } + }); -BI.SwitchTree.EVENT_CHANGE = "SwitchTree.EVENT_CHANGE"; -BI.SwitchTree.SelectType = { - SingleSelect: BI.Selection.Single, - MultiSelect: BI.Selection.Multi -}; -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" +BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicYearMonthPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_month_popup", BI.DynamicYearMonthPopup);BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), + errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") }, - _defaultConfig: function () { - var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-date-interval" - }); + + props: { + extraCls: "bi-year-month-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, + _init: function () { - var self = this, o = this.options; - BI.DateInterval.superclass._init.apply(this, arguments); + BI.DynamicYearMonthTrigger.superclass._init.apply(this, arguments); + var o = this.options; + + this.yearEditor = this._createEditor(true); + this.monthEditor = this._createEditor(false); - 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, + element: this, + type: "bi.htape", items: [{ - type: "bi.absolute", + type: "bi.center", items: [{ - el: self.left, - left: this.constants.offset, - right: 0, - top: 0, - bottom: 0 + type: "bi.htape", + items: [this.yearEditor, { + el: { + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Year"), + width: o.height + }, + width: o.height + }] + }, { + type: "bi.htape", + items: [this.monthEditor, { + el: { + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Month"), + width: o.height + }, + width: o.height}] }] }, { - type: "bi.absolute", - items: [{ - el: self.right, - left: 0, - right: this.constants.offset, - top: 0, - bottom: 0 - }] + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height }] }); - BI.createWidget({ - type: "bi.horizontal_auto", - element: this, - items: [ - self.label - ] - }); + this.setValue(o.value); }, - _createCombo: function (v) { - var self = this; - var combo = BI.createWidget({ - type: "bi.dynamic_date_combo", - value: v + _createEditor: function (isYear) { + var self = this, o = this.options, c = this._const; + var editor = BI.createWidget({ + type: "bi.sign_editor", + height: o.height, + validationChecker: function (v) { + if(isYear) { + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); + } + return v === "" || ((v >= 1 && v <= 12) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); + }, + quitChecker: function () { + return false; + }, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + errorText: function (v) { + return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true }); - combo.on(BI.DynamicDateCombo.EVENT_ERROR, function () { - self._clearTitle(); - self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.DateInterval.EVENT_ERROR); + editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_FOCUS); }); - - 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); - } + editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_STOP); }); + editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = editor.getValue(); + if (BI.isNotNull(value)) { + editor.setValue(value); + } + if (BI.isNotEmptyString(value)) { + var monthValue = self.monthEditor.getValue(); + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: self.yearEditor.getValue(), + month: BI.isEmptyString(self.monthEditor.getValue()) ? "" : monthValue - 1 + } + }; + } - 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); + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_CONFIRM); + }); + editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (editor.isValid()) { + editor.blur(); } }); - - combo.on(BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.left.hidePopupView(); - self.right.hidePopupView(); + editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_START); }); - - 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); + 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); + } } }); - 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] + editor.on(BI.SignEditor.EVENT_CHANGE, function () { + if(isYear) { + self._autoSwitch(editor.getValue()); + } }); + + return editor; }, - _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; + + _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; }, - _setTitle: function (v) { - this.left.setTitle(v); - this.right.setTitle(v); - this.label.setTitle(v); + + _autoSwitch: function (v) { + if (BI.checkDateLegal(v)) { + if (v.length === 4 && this._yearCheck(v)) { + this.monthEditor.focus(); + } + } }, - _clearTitle: function () { - this.left.setTitle(""); - this.right.setTitle(""); - this.label.setTitle(""); + + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year)) { + value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + if(BI.isNotNull(obj.month) && obj.month !== 0) { + value += Math.abs(obj.month) + BI.i18nText("BI-Basic_Year") + (obj.month < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + return value; }, - setValue: function (date) { - date = date || {}; - this.left.setValue(date.start); - this.right.setValue(date.end); + + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y-%x"); + this.yearEditor.setValue(date.getFullYear()); + this.monthEditor.setValue(date.getMonth() + 1); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); + }, + + setValue: function (v) { + var type, value; + 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: + value = value || {}; + var month = BI.isNull(value.month) ? null : value.month + 1; + this.yearEditor.setValue(value.year); + this.yearEditor.setTitle(value.year); + this.monthEditor.setValue(month); + this.monthEditor.setTitle(month); + break; + } }, + getValue: function () { - return {start: this.left.getValue(), end: this.right.getValue()}; + return this.storeValue; + }, + + getKey: function () { + return this.yearEditor.getValue() + "-" + this.monthEditor.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, { +BI.DynamicYearMonthTrigger.EVENT_VALID = "EVENT_FOCUS"; +BI.DynamicYearMonthTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicYearMonthTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearMonthTrigger.EVENT_START = "EVENT_START"; +BI.DynamicYearMonthTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearMonthTrigger.EVENT_STOP = "EVENT_STOP"; +BI.shortcut("bi.dynamic_year_month_trigger", BI.DynamicYearMonthTrigger);BI.YearMonthInterval = BI.inherit(BI.Single, { constants: { height: 25, width: 25, @@ -109170,15 +107535,14 @@ BI.TimeInterval = BI.inherit(BI.Single, { DATE_MIN_VALUE: "1900-01-01", DATE_MAX_VALUE: "2099-12-31" }, - _defaultConfig: function () { - var conf = BI.TimeInterval.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-time-interval" - }); + + props: { + extraCls: "bi-year-month-interval" }, + _init: function () { var self = this, o = this.options; - BI.TimeInterval.superclass._init.apply(this, arguments); + BI.YearMonthInterval.superclass._init.apply(this, arguments); o.value = o.value || {}; this.left = this._createCombo(o.value.start); @@ -109226,16 +107590,16 @@ BI.TimeInterval = BI.inherit(BI.Single, { _createCombo: function (v) { var self = this; var combo = BI.createWidget({ - type: "bi.dynamic_date_time_combo", + type: "bi.dynamic_year_month_combo", value: v }); - combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { + combo.on(BI.DynamicYearMonthCombo.EVENT_ERROR, function () { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.TimeInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); }); - combo.on(BI.DynamicDateTimeCombo.EVENT_VALID, function () { + 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)) { @@ -109244,14 +107608,14 @@ BI.TimeInterval = BI.inherit(BI.Single, { BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { offsetStyle: "center" }); - self.fireEvent(BI.TimeInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); } else { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); } }); - combo.on(BI.DynamicDateTimeCombo.EVENT_FOCUS, function () { + 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)) { @@ -109260,741 +107624,809 @@ BI.TimeInterval = BI.inherit(BI.Single, { BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { offsetStyle: "center" }); - self.fireEvent(BI.TimeInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); } else { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); } }); - combo.on(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.left.hidePopupView(); - self.right.hidePopupView(); + combo.on(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hideView(); + self.right.hideView(); }); - // 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)) { - // 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.TimeInterval.EVENT_ERROR); - // } else { - // self._clearTitle(); - // self.element.removeClass(self.constants.timeErrorCls); - // } - // }); - combo.on(BI.DynamicDateTimeCombo.EVENT_CONFIRM, function () { + 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.TimeInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); }else{ self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.TimeInterval.EVENT_CHANGE); + self.fireEvent(BI.YearMonthInterval.EVENT_CHANGE); } }); return combo; }, + + _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; + 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, 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 %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) { - 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.TimeInterval.EVENT_VALID = "EVENT_VALID"; -BI.TimeInterval.EVENT_ERROR = "EVENT_ERROR"; -BI.TimeInterval.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.time_interval", BI.TimeInterval);/** - * 年份下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.YearCombo - * @extends BI.Widget - */ -BI.YearCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-combo", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 25 - }); + return !BI.checkDateVoid(obj.year, obj.month, 1, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, - _init: function () { - BI.YearCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = ""; - this.trigger = BI.createWidget({ - type: "bi.year_trigger", - min: o.min, - max: o.max, - value: o.value || "" - }); - this.trigger.on(BI.YearTrigger.EVENT_FOCUS, function () { - self.storeValue = this.getKey(); - }); - this.trigger.on(BI.YearTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.YearTrigger.EVENT_STOP, function () { - self.combo.showView(); - }); - this.trigger.on(BI.YearTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.YearTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; - } - if (this.getKey() && this.getKey() !== self.storeValue) { - self.setValue(this.getKey()); - } else if (!this.getKey()) { - self.setValue(); - } - self.fireEvent(BI.YearCombo.EVENT_CONFIRM); - }); - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - destroyWhenHide: true, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.year_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.YearPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.YearCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - var value = self.trigger.getKey(); - if (BI.isNotNull(value)) { - self.popup.setValue(value); - } else if (!value && value !== self.storeValue) { - self.popup.setValue(self.storeValue); - } else { - self.setValue(); - } - self.fireEvent(BI.YearCombo.EVENT_BEFORE_POPUPVIEW); + // 判格式合法 + _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 }); }, - setValue: function (v) { - this.combo.setValue(v || ""); + _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 () { - if (BI.isNull(this.popup)) { - return this.options.value; - } else { - return this.popup.getValue(); - } + return {start: this.left.getValue(), end: this.right.getValue()}; } }); -BI.YearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_combo", BI.YearCombo);/** +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);/** * 年份展示面板 * * Created by GUY on 2015/9/2. - * @class BI.YearPopup + * @class BI.YearCard * @extends BI.Trigger */ -BI.YearPopup = BI.inherit(BI.Widget, { +BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31" // 最大日期 - }); + props: { + baseCls: "bi-year-month-card" }, - _createYearCalendar: function (v) { - var o = this.options, y = this._year; - - var calendar = BI.createWidget({ - type: "bi.year_calendar", - behaviors: o.behaviors, - min: o.min, - max: o.max, - logic: { - dynamic: true - }, - year: y + v * 12 - }); - calendar.setValue(this._year); - return calendar; + render: function () { + var self = this; + return { + type: "bi.vertical", + items: [{ + type: "bi.label", + text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), + textAlign: "left", + height: 24 + }, { + type: "bi.dynamic_date_param_item", + ref: function () { + self.year = this; + }, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }, { + type: "bi.dynamic_date_param_item", + dateType: BI.DynamicDateCard.TYPE.QUARTER, + ref: function () { + self.quarter = this; + }, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }], + vgap: 10, + hgap: 10 + }; }, - _init: function () { - BI.YearPopup.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.selectedYear = this._year = BI.getDate().getFullYear(); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; + }, - var backBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "pre-page-h-font", - width: 25, - height: 25, - value: -1 - }); + setValue: function (v) { + v = v || {year: 0, month: 0}; + this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); + this.quarter.setValue(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); + }, - var preBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "next-page-h-font", - width: 25, - height: 25, - value: 1 - }); + getValue: function () { + var year = this.year.getValue(); + var quarter = this.quarter.getValue(); + return { + year: (year.offset === 0 ? -year.value : year.value), + quarter: (quarter.offset === 0 ? -quarter.value : quarter.value) + }; + } +}); +BI.DynamicYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_quarter_card", BI.DynamicYearQuarterCard);BI.StaticYearQuarterCard = BI.inherit(BI.Widget, { - this.navigation = BI.createWidget({ - type: "bi.navigation", - element: this, - single: true, - logic: { - dynamic: true - }, - tab: { - cls: "year-popup-navigation bi-high-light bi-border-top", - height: 25, - items: [backBtn, preBtn] - }, - cardCreator: BI.bind(this._createYearCalendar, this), + props: { + baseCls: "bi-static-year-quarter-card", + behaviors: {} + }, - afterCardShow: function () { - this.setValue(self.selectedYear); - var calendar = this.getSelectedCard(); - backBtn.setEnable(!calendar.isFrontYear()); - preBtn.setEnable(!calendar.isFinalYear()); - } - }); + _createQuarter: function () { - this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { - self.selectedYear = this.getValue(); - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.YearPopup.EVENT_CHANGE, self.selectedYear); + var items = [{ + text: Date._QN[1], + value: 1 + }, { + text: Date._QN[2], + value: 2 + }, { + text: Date._QN[3], + value: 3 + }, { + text: Date._QN[4], + value: 4 + }]; + return BI.map(items, function (j, item) { + return BI.extend(item, { + type: "bi.text_item", + cls: "bi-list-item-active", + textAlign: "center", + whiteSpace: "nowrap", + once: false, + forceSelected: true, + height: 24 + }); }); + }, - if(BI.isKey(o.value)){ - this.setValue(o.value); - } + render: function () { + var self = this, o = this.options; + return { + type: "bi.vertical", + items: [{ + type: "bi.year_picker", + ref: function () { + self.yearPicker = this; + }, + height: 30, + listeners: [{ + eventName: BI.YearPicker.EVENT_CHANGE, + action: function () { + var value = this.getValue(); + self.setValue({ + year: value, + quarter: self.selectedQuarter + }); + } + }] + }, { + type: "bi.button_group", + behaviors: o.behaviors, + ref: function () { + self.quarter = this; + }, + items: this._createQuarter(), + layouts: [{ + type: "bi.vertical", + vgap: 10 + }], + value: o.value, + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + self.selectedYear = self.yearPicker.getValue(); + self.selectedQuarter = this.getValue()[0]; + self.fireEvent(BI.StaticYearQuarterCard.EVENT_CHANGE); + } + }] + }] + }; }, + getValue: function () { - return this.selectedYear; + return { + year: this.selectedYear, + quarter: this.selectedQuarter + }; }, - setValue: function (v) { + setValue: function (obj) { var o = this.options; - if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { - v = BI.getDate().getFullYear(); + obj = obj || {}; + obj.year = obj.year || 0; + obj.quarter = obj.quarter || 0; + if (BI.checkDateVoid(obj.year, obj.quarter, 1, o.min, o.max)[0]) { + var year = BI.getDate().getFullYear(); + var quarter = BI.getDate().getQuarter(); this.selectedYear = ""; - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(""); + this.selectedQuarter = ""; + this.yearPicker.setValue(year); + this.quarter.setValue(quarter); } else { - this.selectedYear = v; - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(v); + this.selectedYear = BI.parseInt(obj.year); + this.selectedQuarter = BI.parseInt(obj.quarter); + this.yearPicker.setValue(this.selectedYear); + this.quarter.setValue(this.selectedQuarter); } } }); -BI.YearPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.year_popup", BI.YearPopup);/** - * 年份trigger - * - * Created by GUY on 2015/8/21. - * @class BI.YearTrigger - * @extends BI.Trigger - */ -BI.YearTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") - }, +BI.StaticYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-year-trigger bi-border", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }); + props: { + baseCls: "bi-year-quarter-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, + _init: function () { - BI.YearTrigger.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) { - self.editor.setErrorText(!BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid); - return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true, - errorText: c.errorText, - value: o.value + BI.DynamicYearQuarterCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.storeValue = o.value; + this.trigger = BI.createWidget({ + type: "bi.dynamic_year_quarter_trigger", + min: o.min, + max: o.max, + value: o.value || "" }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.YearTrigger.EVENT_FOCUS); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.YearTrigger.EVENT_STOP); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () { + self.combo.showView(); }); - this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - self.editor.setTitle(value); - } - self.fireEvent(BI.YearTrigger.EVENT_CONFIRM); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_ERROR, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM, function () { + if (self.combo.isViewVisible()) { + return; } + self.storeValue = self.trigger.getValue(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); }); - this.editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.YearTrigger.EVENT_START); + + this.combo = BI.createWidget({ + type: "bi.combo", + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + stopPropagation: false, + el: { + type: "bi.dynamic_year_quarter_popup", + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicYearQuarterPopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({year: date.getFullYear()}); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }], + behaviors: o.behaviors, + min: o.min, + max: o.max + }, + value: o.value || "" + } }); - this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.YearTrigger.EVENT_ERROR); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW); }); + BI.createWidget({ - element: this, type: "bi.htape", - items: [ - { - el: this.editor - }, { - el: { + element: this, + ref: function () { + self.comboWrapper = this; + }, + 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 + }, this.combo] + }); + this._checkDynamicValue(o.value); + }, + + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicYearQuarterCombo.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; + } + +}); +BI.DynamicYearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.dynamic_year_quarter_combo", BI.DynamicYearQuarterCombo); + +BI.extend(BI.DynamicYearQuarterCombo, { + Static: 1, + Dynamic: 2 +});BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 + }, + + props: { + baseCls: "bi-year-quarter-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 + }, + + render: function () { + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicYearQuarterCombo.Static}; + return { + type: "bi.vtape", + items: [{ + el: this._getTabJson() + }, { + el: { + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearQuarterPopup.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-Basic_Current_Quarter"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { type: "bi.text_button", - baseCls: "bi-trigger-year-text", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, - width: o.height - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - } - ] - }); - }, - setValue: function (v) { - this.editor.setState(v); - this.editor.setValue(v); - this.editor.setTitle(v); - }, - getKey: function () { - return this.editor.getValue() | 0; - } -}); -BI.YearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.YearTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.YearTrigger.EVENT_START = "EVENT_START"; -BI.YearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.year_trigger", BI.YearTrigger);/** - * 年份 + 月份下拉框 - * - * @class BI.YearMonthCombo - * @extends BI.Widget - */ -BI.YearMonthCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearMonthCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-month-combo", - yearBehaviors: {}, - monthBehaviors: {}, - height: 25 - }); + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 + }] + }; }, - _init: function () { - BI.YearMonthCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - o.value = o.value || {}; - this.year = BI.createWidget({ - type: "bi.year_combo", - behaviors: o.yearBehaviors, - value: o.value.year - }); - - this.month = BI.createWidget({ - type: "bi.month_combo", - behaviors: o.monthBehaviors, - value: o.value.month - }); - - this.year.on(BI.YearCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_CONFIRM); - }); - this.year.on(BI.YearCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW); - }); - - this.month.on(BI.MonthCombo.EVENT_CONFIRM, function () { - self.getValue(); - self.fireEvent(BI.YearMonthCombo.EVENT_CONFIRM); - }); - this.month.on(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.center", - element: this, - hgap: 5, - items: [this.year, this.month] - }); + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicYearQuarterCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y-%x"); + this.textButton.setValue(date); + this.textButton.setEnable(false); + } + }, + _getTabJson: function () { + var self = this, o = this.options; + return { + type: "bi.tab", + 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-Basic_Year_Fen"), + value: BI.DynamicYearQuarterCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicYearQuarterCombo.Dynamic + }], { + textAlign: "center" + }) + }, + cardCreator: function (v) { + switch (v) { + case BI.DynamicYearQuarterCombo.Dynamic: + return { + type: "bi.dynamic_year_quarter_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicYearQuarterCombo.Static: + default: + return { + type: "bi.static_year_quarter_card", + behaviors: o.behaviors, + min: self.options.min, + max: self.options.max, + listeners: [{ + eventName: BI.DynamicYearCard.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearQuarterPopup.EVENT_CHANGE); + } + }], + ref: function () { + self.year = this; + } + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicYearQuarterCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.year.setValue({year: date.getFullYear(), quarter: date.getQuarter()}); + self._setInnerValue(); + break; + case BI.DynamicYearQuarterCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicYearQuarterCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; }, setValue: function (v) { + this.storeValue = v; + var self = this; + var type, value; v = v || {}; - this.month.setValue(v.month); - this.year.setValue(v.year); + 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: + this.year.setValue(value); + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); + this.textButton.setEnable(true); + break; + } }, getValue: function () { return { - year: this.year.getValue(), - month: this.month.getValue() + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() }; } + }); -BI.YearMonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -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" +BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicYearQuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_quarter_popup", BI.DynamicYearQuarterPopup);BI.DynamicYearQuarterTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), + errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") }, props: { - extraCls: "bi-year-month-interval" + extraCls: "bi-year-quarter-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, _init: function () { - var self = this, o = this.options; - BI.YearMonthInterval.superclass._init.apply(this, arguments); + BI.DynamicYearQuarterTrigger.superclass._init.apply(this, arguments); + var o = this.options; + + this.yearEditor = this._createEditor(true); + this.quarterEditor = this._createEditor(false); - 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, + element: this, + type: "bi.htape", items: [{ - type: "bi.absolute", - items: [{ - el: self.left, - left: this.constants.offset, - right: 0, - top: 0, - bottom: 0 - }] - }, { - type: "bi.absolute", + type: "bi.center", items: [{ - el: self.right, - left: 0, - right: this.constants.offset, - top: 0, - bottom: 0 + type: "bi.htape", + items: [this.yearEditor, { + el: { + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Year"), + width: o.height + }, + width: o.height + }] + }, { + type: "bi.htape", + items: [this.quarterEditor, { + el: { + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Quarter"), + width: o.height + }, + width: o.height}] }] + }, { + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height }] }); - BI.createWidget({ - type: "bi.horizontal_auto", - element: this, - items: [ - self.label - ] - }); + this.setValue(o.value); }, - _createCombo: function (v) { - var self = this; - var combo = BI.createWidget({ - type: "bi.dynamic_year_month_combo", - value: v + _createEditor: function (isYear) { + var self = this, o = this.options, c = this._const; + var editor = BI.createWidget({ + type: "bi.sign_editor", + height: o.height, + validationChecker: function (v) { + if(isYear) { + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); + } + return v === "" || ((v >= 1 && v <= 4) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); + }, + quitChecker: function () { + return false; + }, + errorText: function (v) { + return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; + }, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true }); - combo.on(BI.DynamicYearMonthCombo.EVENT_ERROR, function () { - self._clearTitle(); - self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_FOCUS); }); - - 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); - } + editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_STOP); }); + editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = editor.getValue(); + if (BI.isNotNull(value)) { + editor.setValue(value); + } + if (BI.isNotEmptyString(value)) { + var quarterValue = self.quarterEditor.getValue(); + self.storeValue = { + type: BI.DynamicYearQuarterCombo.Static, + value: { + year: self.yearEditor.getValue(), + quarter: BI.isEmptyString(self.quarterEditor.getValue()) ? "" : quarterValue + } + }; + } - 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); + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM); + }); + editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (editor.isValid()) { + editor.blur(); } }); - - combo.on(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.left.hideView(); - self.right.hideView(); + editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_START); }); - - 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); + editor.on(BI.SignEditor.EVENT_ERROR, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_ERROR); + }); + editor.on(BI.SignEditor.EVENT_CHANGE, function () { + if(isYear) { + self._autoSwitch(editor.getValue()); } }); - return combo; - }, - - _dateCheck: function (date) { - return BI.parseDateTime(date, "%Y-%x").print("%Y-%x") === date || BI.parseDateTime(date, "%Y-%X").print("%Y-%X") === date; + return editor; }, - - // 判是否在最大最小之间 - _checkVoid: function (obj) { - return !BI.checkDateVoid(obj.year, obj.month, 1, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + _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; }, - // 判格式合法 - _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 - }); + _autoSwitch: function (v) { + if (BI.checkDateLegal(v)) { + if (v.length === 4 && this._yearCheck(v)) { + this.quarterEditor.focus(); + } + } }, - _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 - * @extends BI.Widget - */ -BI.YearQuarterCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearQuarterCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-quarter-combo", - yearBehaviors: {}, - quarterBehaviors: {}, - height: 25 - }); + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year)) { + value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + if(BI.isNotNull(obj.quarter) && obj.quarter !== 0) { + value += Math.abs(obj.quarter) + BI.i18nText("BI-Basic_Year") + (obj.quarter < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + return value; }, - _init: function () { - BI.YearQuarterCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - o.value = o.value || {}; - - this.year = BI.createWidget({ - type: "bi.year_combo", - behaviors: o.yearBehaviors, - value: o.value.year - }); - - this.quarter = BI.createWidget({ - type: "bi.quarter_combo", - behaviors: o.quarterBehaviors, - value: o.value.quarter - }); - - this.year.on(BI.YearCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_CONFIRM); - }); - this.year.on(BI.YearCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_BEFORE_POPUPVIEW); - }); - - this.quarter.on(BI.QuarterCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_CONFIRM); - }); - this.quarter.on(BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.center", - element: this, - hgap: 5, - items: [this.year, this.quarter] - }); + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y-%x"); + this.yearEditor.setValue(date.getFullYear()); + this.quarterEditor.setValue(date.getQuarter()); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); }, setValue: function (v) { - v = v || {}; - this.quarter.setValue(v.quarter); - this.year.setValue(v.year); + var type, value; + var date = BI.getDate(); + this.storeValue = v; + if (BI.isNotNull(v)) { + type = v.type || BI.DynamicYearQuarterCombo.Static; + value = v.value || v; + } + switch (type) { + case BI.DynamicYearQuarterCombo.Dynamic: + var text = this._getText(value); + date = BI.DynamicDateHelper.getCalculation(value); + this._setInnerValue(date, text); + break; + case BI.DynamicYearQuarterCombo.Static: + default: + value = value || {}; + var quarter = BI.isNull(value.quarter) ? null : value.quarter; + this.yearEditor.setValue(value.year); + this.yearEditor.setTitle(value.year); + this.quarterEditor.setValue(quarter); + this.quarterEditor.setTitle(quarter); + break; + } }, getValue: function () { - return { - year: this.year.getValue(), - quarter: this.quarter.getValue() - }; + return this.storeValue; } }); -BI.YearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_quarter_combo", BI.YearQuarterCombo);/** +BI.DynamicYearQuarterTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicYearQuarterTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearQuarterTrigger.EVENT_START = "EVENT_START"; +BI.DynamicYearQuarterTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearQuarterTrigger.EVENT_STOP = "EVENT_STOP"; +BI.shortcut("bi.dynamic_year_quarter_trigger", BI.DynamicYearQuarterTrigger);/** * 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 * 封装了字段处理逻辑 * diff --git a/dist/widget.js b/dist/widget.js index b24093c2d..abbacfcd2 100644 --- a/dist/widget.js +++ b/dist/widget.js @@ -903,6 +903,115 @@ BI.DateCalendarPopup = BI.inherit(BI.Widget, { }); BI.DateCalendarPopup.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.date_calendar_popup", BI.DateCalendarPopup);/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.YearPopup + * @extends BI.Trigger + */ +BI.YearPopup = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.YearPopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-year-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31" // 最大日期 + }); + }, + + _createYearCalendar: function (v) { + var o = this.options, y = this._year; + + var calendar = BI.createWidget({ + type: "bi.year_calendar", + behaviors: o.behaviors, + min: o.min, + max: o.max, + logic: { + dynamic: true + }, + year: y + v * 12 + }); + calendar.setValue(this._year); + return calendar; + }, + + _init: function () { + BI.YearPopup.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.selectedYear = this._year = BI.getDate().getFullYear(); + + var backBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "pre-page-h-font", + width: 25, + height: 25, + value: -1 + }); + + var preBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "next-page-h-font", + width: 25, + height: 25, + value: 1 + }); + + this.navigation = BI.createWidget({ + type: "bi.navigation", + element: this, + single: true, + logic: { + dynamic: true + }, + tab: { + cls: "year-popup-navigation bi-high-light bi-border-top", + height: 25, + items: [backBtn, preBtn] + }, + cardCreator: BI.bind(this._createYearCalendar, this), + + afterCardShow: function () { + this.setValue(self.selectedYear); + var calendar = this.getSelectedCard(); + backBtn.setEnable(!calendar.isFrontYear()); + preBtn.setEnable(!calendar.isFinalYear()); + } + }); + + this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { + self.selectedYear = this.getValue(); + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + self.fireEvent(BI.YearPopup.EVENT_CHANGE, self.selectedYear); + }); + + if(BI.isKey(o.value)){ + this.setValue(o.value); + } + }, + + getValue: function () { + return this.selectedYear; + }, + + setValue: function (v) { + var o = this.options; + if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { + v = BI.getDate().getFullYear(); + this.selectedYear = ""; + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(""); + } else { + this.selectedYear = v; + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(v); + } + } +}); +BI.YearPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.year_popup", BI.YearPopup);/** * 日期控件中的年份或月份trigger * * Created by GUY on 2015/9/7. @@ -1349,9 +1458,9 @@ BI.DateTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; BI.shortcut("bi.date_trigger", BI.DateTrigger);/** * Created by zcf on 2017/2/20. */ -BI.DatePaneWidget = BI.inherit(BI.Widget, { +BI.StaticDatePaneCard = BI.inherit(BI.Widget, { _defaultConfig: function () { - var conf = BI.DatePaneWidget.superclass._defaultConfig.apply(this, arguments); + var conf = BI.StaticDatePaneCard.superclass._defaultConfig.apply(this, arguments); return BI.extend(conf, { baseCls: "bi-date-pane", min: "1900-01-01", // 最小日期 @@ -1360,7 +1469,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { }); }, _init: function () { - BI.DatePaneWidget.superclass._init.apply(this, arguments); + BI.StaticDatePaneCard.superclass._init.apply(this, arguments); var self = this, o = this.options; this.today = BI.getDate(); @@ -1459,7 +1568,146 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { } }); -BI.shortcut("bi.date_pane", BI.DatePaneWidget);/** +BI.shortcut("bi.static_date_pane_card", BI.StaticDatePaneCard);BI.DynamicDatePane = 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.DynamicDatePane.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDatePane.Dynamic + }], { + textAlign: "center" + }), + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + var value = this.getValue()[0]; + self.dateTab.setSelect(value); + switch (value) { + case BI.DynamicDatePane.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + break; + case BI.DynamicDatePane.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.DynamicDatePane.Static, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDatePane.Static: + return { + type: "bi.static_date_pane_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.ymd = this; + } + }; + case BI.DynamicDatePane.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.DynamicDateCombo.Static; + var value = v.value || v; + this.switch.setValue(type); + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateCombo.Dynamic: + this.dynamicPane.setValue(value); + break; + case BI.DynamicDateCombo.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_pane", BI.DynamicDatePane); + +BI.extend(BI.DynamicDatePane, { + Static: 1, + Dynamic: 2 +});/** * Created by Urthur on 2017/7/14. */ BI.DateTimeCombo = BI.inherit(BI.Single, { @@ -1926,309 +2174,577 @@ BI.DateTimeTrigger = BI.inherit(BI.Trigger, { } }); -BI.shortcut("bi.date_time_trigger", BI.DateTimeTrigger);/** - * Created by roy on 15/8/14. - */ -BI.DownListCombo = BI.inherit(BI.Widget, { +BI.shortcut("bi.date_time_trigger", BI.DateTimeTrigger);BI.StaticDateTimePaneCard = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.DownListCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-down-list-combo", - height: 24, - items: [], - adjustLength: 0, - direction: "bottom", - trigger: "click", - container: null, - stopPropagation: false, - el: {} + 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.DownListCombo.superclass._init.apply(this, arguments); + BI.StaticDateTimePaneCard.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.popupview = BI.createWidget({ - type: "bi.down_list_popup", - items: o.items, - chooseType: o.chooseType, - value: o.value - }); - this.popupview.on(BI.DownListPopup.EVENT_CHANGE, function (value) { - self.fireEvent(BI.DownListCombo.EVENT_CHANGE, value); - self.downlistcombo.hideView(); - }); + this.today = BI.getDate(); + this._year = this.today.getFullYear(); + this._month = this.today.getMonth(); - this.popupview.on(BI.DownListPopup.EVENT_SON_VALUE_CHANGE, function (value, fatherValue) { - self.fireEvent(BI.DownListCombo.EVENT_SON_VALUE_CHANGE, value, fatherValue); - self.downlistcombo.hideView(); + 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); + }); - this.downlistcombo = BI.createWidget({ + BI.createWidget({ + type: "bi.vtape", element: this, - type: "bi.combo", - trigger: o.trigger, - isNeedAdjustWidth: false, - container: o.container, - adjustLength: o.adjustLength, - direction: o.direction, - stopPropagation: o.stopPropagation, - el: BI.createWidget(o.el, { - type: "bi.icon_trigger", - extraCls: o.iconCls ? o.iconCls : "pull-down-font", - width: o.width, - height: o.height - }), - popup: { - el: this.popupview, - stopPropagation: true, - maxHeight: 1000 - } + items: [this.calendar, { + el: { + type: "bi.dynamic_date_time_select", + ref: function () { + self.timeSelect = this; + } + }, + height: 40 + }] }); + this.setValue(o.selectedTime); - this.downlistcombo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.DownListCombo.EVENT_BEFORE_POPUPVIEW); - }); }, - hideView: function () { - this.downlistcombo.hideView(); + _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; }, - showView: function () { - this.downlistcombo.showView(); + _getNewCurrentDate: function () { + var today = BI.getDate(); + return { + year: today.getFullYear(), + month: today.getMonth() + }; }, - populate: function (items) { - this.popupview.populate(items); + _setCalenderValue: function (date) { + this.calendar.setSelect(BI.Calendar.getPageByDateJSON(date)); + this.calendar.setValue(date); + this.selectedTime = BI.extend(date, this.timeSelect.getValue()); }, - setValue: function (v) { - this.popupview.setValue(v); + _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); + } }, - getValue: function () { - return this.popupview.getValue(); - } -}); -BI.DownListCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.DownListCombo.EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE"; -BI.DownListCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.down_list_combo", BI.DownListCombo);/** - * Created by roy on 15/9/6. - */ -BI.DownListGroup = BI.inherit(BI.Widget, { - constants: { - iconCls: "check-mark-ha-font" - }, - _defaultConfig: function () { - return BI.extend(BI.DownListGroup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-down-list-group", - items: [ - { - el: {} - } - ] - }); + _setCalendar: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { + this.calendar.empty(); + this._setCalenderValue(this._getNewCurrentDate()); + } else { + this._setCalenderValue(timeOb); + } }, - _init: function () { - BI.DownListGroup.superclass._init.apply(this, arguments); - var o = this.options, self = this; - this.downlistgroup = BI.createWidget({ - element: this, - type: "bi.button_tree", - items: o.items, - chooseType: 0, // 0单选,1多选 - layouts: [{ - type: "bi.vertical", - hgap: 0, - vgap: 0 - }], - value: o.value - }); - this.downlistgroup.on(BI.Controller.EVENT_CHANGE, function (type) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if(type === BI.Events.CLICK) { - self.fireEvent(BI.DownListGroup.EVENT_CHANGE, arguments); - } + 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.downlistgroup.getValue(); - }, - setValue: function (v) { - this.downlistgroup.setValue(v); + return this.selectedTime; } - }); -BI.DownListGroup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.down_list_group", BI.DownListGroup);BI.DownListItem = BI.inherit(BI.Single, { - _defaultConfig: function () { - var conf = BI.DownListItem.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: "bi-down-list-item bi-list-item-active", - cls: "", - height: 25, - logic: { - dynamic: true - }, - selected: false, - iconHeight: null, - iconWidth: null, - textHgap: 0, - textVgap: 0, - textLgap: 0, - textRgap: 0 - }); - }, - _init: function () { - BI.DownListItem.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.text = BI.createWidget({ - type: "bi.icon_text_item", - element: this, - height: o.height, - text: o.text, - value: o.value, - logic: o.logic, - selected: o.selected, - disabled: o.disabled, - iconHeight: o.iconHeight, - iconWidth: o.iconWidth, - textHgap: o.textHgap, - textVgap: o.textVgap, - textLgap: o.textLgap, - textRgap: o.textRgap, - father: o.father, - bubble: o.bubble - }); - this.text.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.text.on(BI.IconTextItem.EVENT_CHANGE, function () { - self.fireEvent(BI.DownListItem.EVENT_CHANGE); - }); - // this.setSelected(o.selected); - }, +BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.DynamicDateTimePane = BI.inherit(BI.Widget, { - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); + props: { + baseCls: "bi-dynamic-date-pane" }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); - }, + 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; + } + }; + } + } + }] + }; + }, - isSelected: function () { - return this.text.isSelected(); + mounted: function () { + this.setValue(this.options.value); }, - setSelected: function (b) { - this.text.setSelected(b); - // if (b === true) { - // this.element.addClass("dot-e-font"); - // } else { - // this.element.removeClass("dot-e-font"); - // } + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, setValue: function (v) { - this.text.setValue(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 this.text.getValue(); + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; } }); -BI.DownListItem.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.down_list_item", BI.DownListItem);BI.DownListGroupItem = BI.inherit(BI.BasicButton, { +BI.shortcut("bi.dynamic_date_time_pane", BI.DynamicDateTimePane); + +BI.extend(BI.DynamicDateTimePane, { + Static: 1, + Dynamic: 2 +});/** + * Created by roy on 15/8/14. + */ +BI.DownListCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { - var conf = BI.DownListGroupItem.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-down-list-group-item", - logic: { - dynamic: false - }, - // invalid: true, - iconCls1: "dot-e-font", - iconCls2: "pull-right-e-font" + return BI.extend(BI.DownListCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-down-list-combo", + height: 24, + items: [], + adjustLength: 0, + direction: "bottom", + trigger: "click", + container: null, + stopPropagation: false, + el: {} }); }, - _init: function () { - BI.DownListGroupItem.superclass._init.apply(this, arguments); - var o = this.options; - var self = this; - this.text = BI.createWidget({ - type: "bi.label", - cls: "list-group-item-text", - textAlign: "left", - text: o.text, - value: o.value, - height: o.height - }); - this.icon1 = BI.createWidget({ - type: "bi.icon_button", - cls: o.iconCls1, - width: 25, - forceNotSelected: true, - selected: this._digest(o.value) + _init: function () { + BI.DownListCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.popupview = BI.createWidget({ + type: "bi.down_list_popup", + items: o.items, + chooseType: o.chooseType, + value: o.value }); - this.icon2 = BI.createWidget({ - type: "bi.icon_button", - cls: o.iconCls2, - width: 25, - forceNotSelected: true + this.popupview.on(BI.DownListPopup.EVENT_CHANGE, function (value) { + self.fireEvent(BI.DownListCombo.EVENT_CHANGE, value); + self.downlistcombo.hideView(); }); - var blank = BI.createWidget({ - type: "bi.layout", - width: 25 - }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.icon2, - top: 0, - bottom: 0, - right: 0 - }] + this.popupview.on(BI.DownListPopup.EVENT_SON_VALUE_CHANGE, function (value, fatherValue) { + self.fireEvent(BI.DownListCombo.EVENT_SON_VALUE_CHANGE, value, fatherValue); + self.downlistcombo.hideView(); }); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { - items: BI.LogicFactory.createLogicItemsByDirection("left", this.icon1, this.text, blank) - })))); - this.element.hover(function () { - if (self.isEnabled()) { - self.hover(); - } - }, function () { - if (self.isEnabled()) { - self.dishover(); + this.downlistcombo = BI.createWidget({ + element: this, + type: "bi.combo", + trigger: o.trigger, + isNeedAdjustWidth: false, + container: o.container, + adjustLength: o.adjustLength, + direction: o.direction, + stopPropagation: o.stopPropagation, + el: BI.createWidget(o.el, { + type: "bi.icon_trigger", + extraCls: o.iconCls ? o.iconCls : "pull-down-font", + width: o.width, + height: o.height + }), + popup: { + el: this.popupview, + stopPropagation: true, + maxHeight: 1000 } }); - }, - _digest: function (v) { - var self = this, o = this.options; - v = BI.isArray(v) ? v : [v]; - return BI.any(v, function (idx, value) { - return BI.contains(o.childValues, value); + this.downlistcombo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.DownListCombo.EVENT_BEFORE_POPUPVIEW); }); }, - hover: function () { - BI.DownListGroupItem.superclass.hover.apply(this, arguments); - this.icon1.element.addClass("hover"); - this.icon2.element.addClass("hover"); + hideView: function () { + this.downlistcombo.hideView(); + }, + + showView: function () { + this.downlistcombo.showView(); + }, + + populate: function (items) { + this.popupview.populate(items); + }, + + setValue: function (v) { + this.popupview.setValue(v); + }, + getValue: function () { + return this.popupview.getValue(); + } +}); +BI.DownListCombo.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DownListCombo.EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE"; +BI.DownListCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; + +BI.shortcut("bi.down_list_combo", BI.DownListCombo);/** + * Created by roy on 15/9/6. + */ +BI.DownListGroup = BI.inherit(BI.Widget, { + constants: { + iconCls: "check-mark-ha-font" + }, + _defaultConfig: function () { + return BI.extend(BI.DownListGroup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-down-list-group", + items: [ + { + el: {} + } + ] + }); + }, + _init: function () { + BI.DownListGroup.superclass._init.apply(this, arguments); + var o = this.options, self = this; + + this.downlistgroup = BI.createWidget({ + element: this, + type: "bi.button_tree", + items: o.items, + chooseType: 0, // 0单选,1多选 + layouts: [{ + type: "bi.vertical", + hgap: 0, + vgap: 0 + }], + value: o.value + }); + this.downlistgroup.on(BI.Controller.EVENT_CHANGE, function (type) { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + if(type === BI.Events.CLICK) { + self.fireEvent(BI.DownListGroup.EVENT_CHANGE, arguments); + } + }); + }, + getValue: function () { + return this.downlistgroup.getValue(); + }, + setValue: function (v) { + this.downlistgroup.setValue(v); + } + + +}); +BI.DownListGroup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.down_list_group", BI.DownListGroup);BI.DownListItem = BI.inherit(BI.Single, { + _defaultConfig: function () { + var conf = BI.DownListItem.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: "bi-down-list-item bi-list-item-active", + cls: "", + height: 25, + logic: { + dynamic: true + }, + selected: false, + iconHeight: null, + iconWidth: null, + textHgap: 0, + textVgap: 0, + textLgap: 0, + textRgap: 0 + }); + }, + _init: function () { + BI.DownListItem.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.text = BI.createWidget({ + type: "bi.icon_text_item", + element: this, + height: o.height, + text: o.text, + value: o.value, + logic: o.logic, + selected: o.selected, + disabled: o.disabled, + iconHeight: o.iconHeight, + iconWidth: o.iconWidth, + textHgap: o.textHgap, + textVgap: o.textVgap, + textLgap: o.textLgap, + textRgap: o.textRgap, + father: o.father, + bubble: o.bubble + }); + this.text.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + this.text.on(BI.IconTextItem.EVENT_CHANGE, function () { + self.fireEvent(BI.DownListItem.EVENT_CHANGE); + }); + // this.setSelected(o.selected); + }, + + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); + }, + + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); + }, + + isSelected: function () { + return this.text.isSelected(); + }, + + setSelected: function (b) { + this.text.setSelected(b); + // if (b === true) { + // this.element.addClass("dot-e-font"); + // } else { + // this.element.removeClass("dot-e-font"); + // } + }, + + setValue: function (v) { + this.text.setValue(v); + }, + + getValue: function () { + return this.text.getValue(); + } +}); +BI.DownListItem.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.down_list_item", BI.DownListItem);BI.DownListGroupItem = BI.inherit(BI.BasicButton, { + _defaultConfig: function () { + var conf = BI.DownListGroupItem.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-down-list-group-item", + logic: { + dynamic: false + }, + // invalid: true, + iconCls1: "dot-e-font", + iconCls2: "pull-right-e-font" + }); + }, + _init: function () { + BI.DownListGroupItem.superclass._init.apply(this, arguments); + var o = this.options; + var self = this; + this.text = BI.createWidget({ + type: "bi.label", + cls: "list-group-item-text", + textAlign: "left", + text: o.text, + value: o.value, + height: o.height + }); + + this.icon1 = BI.createWidget({ + type: "bi.icon_button", + cls: o.iconCls1, + width: 25, + forceNotSelected: true, + selected: this._digest(o.value) + }); + + this.icon2 = BI.createWidget({ + type: "bi.icon_button", + cls: o.iconCls2, + width: 25, + forceNotSelected: true + }); + + var blank = BI.createWidget({ + type: "bi.layout", + width: 25 + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.icon2, + top: 0, + bottom: 0, + right: 0 + }] + }); + + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { + items: BI.LogicFactory.createLogicItemsByDirection("left", this.icon1, this.text, blank) + })))); + + this.element.hover(function () { + if (self.isEnabled()) { + self.hover(); + } + }, function () { + if (self.isEnabled()) { + self.dishover(); + } + }); + }, + + _digest: function (v) { + var self = this, o = this.options; + v = BI.isArray(v) ? v : [v]; + return BI.any(v, function (idx, value) { + return BI.contains(o.childValues, value); + }); + }, + + hover: function () { + BI.DownListGroupItem.superclass.hover.apply(this, arguments); + this.icon1.element.addClass("hover"); + this.icon2.element.addClass("hover"); }, @@ -2537,7991 +3053,4150 @@ BI.DownListPopup = BI.inherit(BI.Pane, { BI.DownListPopup.EVENT_CHANGE = "EVENT_CHANGE"; BI.DownListPopup.EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE"; BI.shortcut("bi.down_list_popup", BI.DownListPopup);/** - * Created by zcf on 2017/2/20. + * 汇总表格帮助类 + * Created by Young's on 2017/1/19. */ -BI.StaticDatePaneCard = BI.inherit(BI.Widget, { - _defaultConfig: function () { - var conf = BI.StaticDatePaneCard.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: "bi-date-pane", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - selectedTime: null - }); - }, - _init: function () { - BI.StaticDatePaneCard.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 = self.datePicker.getValue(); - self.calendar.setSelect(BI.Calendar.getPageByDateJSON(self.selectedTime)); - }); - - this.calendar = BI.createWidget({ - direction: "top", - element: this, - 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 = self.calendar.getValue(); - self.calendar.empty(); - self.setValue(self.selectedTime); - self.fireEvent(BI.DateCalendarPopup.EVENT_CHANGE); - }); - 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 = date; - }, - - _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); - } - }, +!(function () { + BI.DynamicDateHelper = {}; + BI.extend(BI.DynamicDateHelper, { + getCalculation: function (obj) { + var date = BI.getDate(); + if (BI.isNotNull(obj.year)) { + date = BI.getDate((date.getFullYear() + BI.parseInt(obj.year)), date.getMonth(), date.getDate()); + } + if (BI.isNotNull(obj.quarter)) { + date = date.getAfterMulQuarter(obj.quarter); + } + if (BI.isNotNull(obj.month)) { + date = date.getAfterMultiMonth(obj.month); + } + if (BI.isNotNull(obj.week)) { + date = date.getOffsetDate(obj.week * 7); + } + if (BI.isNotNull(obj.day)) { + date = date.getOffsetDate(obj.day); + } + if (BI.isNotNull(obj.workDay)) { + // todo 根据工作日做偏移 + } + if (BI.isNotNull(obj.position) && obj.position !== BI.DynamicDateCard.OFFSET.CURRENT) { + date = this.getBeginDate(date, obj); + } + return date; + }, - _setCalendar: function (timeOb) { - if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { - this.calendar.empty(); - this._setCalenderValue(this._getNewCurrentDate()); - } else { - this._setCalenderValue(timeOb); + getBeginDate: function (date, obj) { + if (BI.isNotNull(obj.day)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), date.getMonth(), 1) : BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); + } + if (BI.isNotNull(obj.week)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? date.getWeekStartDate() : date.getWeekEndDate(); + } + if (BI.isNotNull(obj.month)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), date.getMonth(), 1) : BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); + } + if (BI.isNotNull(obj.quarter)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? date.getQuarterStartDate() : date.getQuarterEndDate(); + } + if (BI.isNotNull(obj.year)) { + return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), 0, 1) : BI.getDate(date.getFullYear(), 11, 31); + } } - }, - - setValue: function (timeOb) { - this._setDatePicker(timeOb); - this._setCalendar(timeOb); - }, - - getValue: function () { - return this.selectedTime; - } - -}); -BI.shortcut("bi.static_date_pane_card", BI.StaticDatePaneCard);BI.DynamicDatePane = BI.inherit(BI.Widget, { + }); +})();BI.DynamicDateCard = BI.inherit(BI.Widget, { props: { - baseCls: "bi-dynamic-date-pane" + baseCls: "bi-dynamic-date-card" }, render: function () { var self = this; + this.position = BI.DynamicDateCard.OFFSET.CURRENT; return { - type: "bi.vtape", + type: "bi.vertical", items: [{ el: { - type: "bi.linear_segment", - cls: "bi-border-bottom", - height: 30, - items: BI.createItems([{ - text: BI.i18nText("BI-Multi_Date_YMD"), - value: BI.DynamicDatePane.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicDatePane.Dynamic - }], { - textAlign: "center" - }), - listeners: [{ - eventName: BI.ButtonGroup.EVENT_CHANGE, - action: function () { - var value = this.getValue()[0]; - self.dateTab.setSelect(value); - switch (value) { - case BI.DynamicDatePane.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - break; - case BI.DynamicDatePane.Dynamic: - self.dynamicPane.setValue({ - year: 0 - }); - break; - default: - break; - } - } - }], - ref: function () { - self.switch = this; - } - }, - height: 30 + type: "bi.label", + text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), + textAlign: "left", + height: 24, + lgap: 10 + } }, { - type: "bi.tab", + type: "bi.button_group", ref: function () { - self.dateTab = this; + self.checkgroup = this; }, - showIndex: BI.DynamicDatePane.Static, - cardCreator: function (v) { - switch (v) { - case BI.DynamicDatePane.Static: - return { - type: "bi.static_date_pane_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }], - ref: function () { - self.ymd = this; - } - }; - case BI.DynamicDatePane.Dynamic: - default: + chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, + value: [BI.DynamicDateCard.TYPE.YEAR], + items: BI.createItems([{ + text: BI.i18nText("BI-Basic_Year"), + value: BI.DynamicDateCard.TYPE.YEAR + }, { + text: BI.i18nText("BI-Basic_Single_Quarter"), + value: BI.DynamicDateCard.TYPE.QUARTER + }, { + text: BI.i18nText("BI-Basic_Month"), + value: BI.DynamicDateCard.TYPE.MONTH + }, { + text: BI.i18nText("BI-Basic_Week"), + value: BI.DynamicDateCard.TYPE.WEEK + }, { + text: BI.i18nText("BI-Basic_Day"), + value: BI.DynamicDateCard.TYPE.DAY + }], { + type: "bi.multi_select_item", + logic: { + dynamic: true + } + }), + layouts: [{ + type: "bi.left" + }], + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + var value = self.checkgroup.getValue(); + if(value.length !== 0) { + self.workDayBox.setSelected(false); + } + self.resultPane.populate(self._getParamJson(BI.map(self.checkgroup.getValue(), function (idx, v) { return { - type: "bi.dynamic_date_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }], - ref: function () { - self.dynamicPane = this; - } + dateType: v }; + }))); + self.position = BI.DynamicDateCard.OFFSET.CURRENT; + self.fireEvent("EVENT_CHANGE"); } + }] + }, { + type: "bi.vertical_adapt", + items: [{ + type: "bi.multi_select_item", + ref: function () { + self.workDayBox = this; + }, + logic: { + dynamic: true + }, + text: BI.i18nText("BI-Basic_Work_Day"), + value: BI.DynamicDateCard.TYPE.WORK_DAY, + listeners: [{ + eventName: BI.MultiSelectItem.EVENT_CHANGE, + action: function () { + if(this.isSelected()) { + self.checkgroup.setValue(); + } + self.resultPane.populate(this.isSelected() ? self._getParamJson([{ + dateType: BI.DynamicDateCard.TYPE.WORK_DAY + }]) : []); + self.position = BI.DynamicDateCard.OFFSET.CURRENT; + self.fireEvent("EVENT_CHANGE"); + } + }] + }], + ref: function () { + self.workDay = this; } + }, { + type: "bi.button_group", + items: this._getParamJson([{ + dateType: BI.DynamicDateCard.TYPE.YEAR + }]), + ref: function () { + self.resultPane = this; + }, + layouts: [{ + type: "bi.vertical", + vgap: 10, + hgap: 10 + }] }] }; }, - mounted: function () { - this.setValue(this.options.value); + _getParamJson: function (values, positionValue) { + var self = this; + var items = BI.map(values, function (idx, value) { + return { + type: "bi.dynamic_date_param_item", + dateType: value.dateType, + value: value.value, + offset: value.offset, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }; + }); + + if(values.length === 1 && values[0] === BI.DynamicDateCard.TYPE.DAY) { + items.push = [{ + type: "bi.text_value_combo", + height: 24, + items: this._getText(BI.DynamicDateCard.TYPE.MONTH), + value: positionValue || BI.DynamicDateCard.OFFSET.CURRENT, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.position = this.getValue()[0]; + self.fireEvent("EVENT_CHANGE"); + } + }] + }]; + }else{ + if(values.length !== 0 && BI.last(values).dateType !== BI.DynamicDateCard.TYPE.DAY && BI.last(values).dateType !== BI.DynamicDateCard.TYPE.WORK_DAY) { + items.push({ + type: "bi.text_value_combo", + height: 24, + items: this._getText(BI.last(values).dateType), + value: positionValue || BI.DynamicDateCard.OFFSET.CURRENT, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.position = this.getValue()[0]; + self.fireEvent("EVENT_CHANGE"); + } + }] + }); + + } + } + + return items; }, - _checkValueValid: function (value) { - return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + _getText: function (lastValue) { + switch (lastValue) { + case BI.DynamicDateCard.TYPE.YEAR: + return [{ + text: BI.i18nText("BI-Basic_Current_Day"), + value: BI.DynamicDateCard.OFFSET.CURRENT + }, { + text: BI.i18nText("BI-Basic_Year_Begin"), + value: BI.DynamicDateCard.OFFSET.BEGIN + }, { + text: BI.i18nText("BI-Basic_Year_End"), + value: BI.DynamicDateCard.OFFSET.END + }]; + case BI.DynamicDateCard.TYPE.QUARTER: + return [{ + text: BI.i18nText("BI-Basic_Current_Day"), + value: BI.DynamicDateCard.OFFSET.CURRENT + }, { + text: BI.i18nText("BI-Basic_Quarter_Begin"), + value: BI.DynamicDateCard.OFFSET.BEGIN + }, { + text: BI.i18nText("BI-Basic_Quarter_End"), + value: BI.DynamicDateCard.OFFSET.END + }]; + case BI.DynamicDateCard.TYPE.MONTH: + return [{ + text: BI.i18nText("BI-Basic_Current_Day"), + value: BI.DynamicDateCard.OFFSET.CURRENT + }, { + text: BI.i18nText("BI-Basic_Month_Begin"), + value: BI.DynamicDateCard.OFFSET.BEGIN + }, { + text: BI.i18nText("BI-Basic_Month_End"), + value: BI.DynamicDateCard.OFFSET.END + }]; + case BI.DynamicDateCard.TYPE.WEEK: + default: + return [{ + text: BI.i18nText("BI-Basic_Current_Day"), + value: BI.DynamicDateCard.OFFSET.CURRENT + }, { + text: BI.i18nText("BI-Basic_Week_Begin"), + value: BI.DynamicDateCard.OFFSET.BEGIN + }, { + text: BI.i18nText("BI-Basic_Week_End"), + value: BI.DynamicDateCard.OFFSET.END + }]; + } + }, + + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, setValue: function (v) { v = v || {}; - var type = v.type || BI.DynamicDateCombo.Static; - var value = v.value || v; - this.switch.setValue(type); - this.dateTab.setSelect(type); - switch (type) { - case BI.DynamicDateCombo.Dynamic: - this.dynamicPane.setValue(value); - break; - case BI.DynamicDateCombo.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; + var values = []; + var valuesItems = []; + if(BI.isNotNull(v.year)) { + values.push(BI.DynamicDateCard.TYPE.YEAR); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); + } + if(BI.isNotNull(v.quarter)) { + values.push(BI.DynamicDateCard.TYPE.QUARTER); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); + } + if(BI.isNotNull(v.month)) { + values.push(BI.DynamicDateCard.TYPE.MONTH); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); + } + if(BI.isNotNull(v.week)) { + values.push(BI.DynamicDateCard.TYPE.WEEK); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.WEEK, v.week)); + } + if(BI.isNotNull(v.day)) { + values.push(BI.DynamicDateCard.TYPE.DAY); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.DAY, v.day)); + } + if(BI.isNotNull(v.workDay)) { + values.push(BI.DynamicDateCard.TYPE.WORK_DAY); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.WORK_DAY, v.workDay)); } + this.checkgroup.setValue(values); + this.workDayBox.setSelected(BI.isNotNull(v.workDay)); + this.resultPane.populate(this._getParamJson(valuesItems, v.position)); }, getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; + var self = this; + var valueMap = {}; + var selectValues = this.checkgroup.getValue(); + var buttons = this.resultPane.getAllButtons(); + if(selectValues.length !== 0) { + BI.each(buttons, function (idx, button) { + var value = button.getValue(); + switch (value.dateType) { + case BI.DynamicDateCard.TYPE.YEAR: + valueMap.year = (value.offset === 0 ? -value.value : value.value); + break; + case BI.DynamicDateCard.TYPE.QUARTER: + valueMap.quarter = (value.offset === 0 ? -value.value : value.value); + break; + case BI.DynamicDateCard.TYPE.MONTH: + valueMap.month = (value.offset === 0 ? -value.value : value.value); + break; + case BI.DynamicDateCard.TYPE.WEEK: + valueMap.week = (value.offset === 0 ? -value.value : value.value); + break; + case BI.DynamicDateCard.TYPE.DAY: + valueMap.day = (value.offset === 0 ? -value.value : value.value); + break; + default: + break; + } + if(BI.isNull(value.dateType)) { + valueMap.position = self.position || BI.DynamicDateCard.OFFSET.CURRENT; + } + }); + } + if(this.workDayBox.isSelected()) { + var value = buttons[0].getValue(); + valueMap.workDay = (value.offset === 0 ? -value.value : value.value); + } + return valueMap; } + }); -BI.shortcut("bi.dynamic_date_pane", BI.DynamicDatePane); +BI.shortcut("bi.dynamic_date_card", BI.DynamicDateCard); -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 - }); +BI.extend(BI.DynamicDateCard, { + TYPE: { + YEAR: 1, + QUARTER: 2, + MONTH: 3, + WEEK: 4, + DAY: 5, + WORK_DAY: 6 }, - - getValue: function () { - return this.selectedTime; + OFFSET: { + CURRENT: 1, + BEGIN: 2, + END: 3 } -}); -BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.DynamicDateTimePane = BI.inherit(BI.Widget, { +});BI.DynamicDateCombo = 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-pane" + baseCls: "bi-dynamic-date-combo bi-border", + height: 24 }, + render: function () { - var self = this; + var self = this, opts = this.options; + this.storeTriggerValue = ""; + var date = BI.getDate(); + this.storeValue = opts.value; return { - type: "bi.vtape", + type: "bi.htape", 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; - } - } - }], + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, ref: function () { - self.switch = this; + self.changeIcon = this; } }, - height: 30 + width: 24 }, { - 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"); + type: "bi.absolute", + items: [{ + el: { + type: "bi.combo", + ref: function () { + self.combo = this; + }, + toggle: false, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: { + type: "bi.dynamic_date_trigger", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.trigger = this; + }, + listeners: [{ + eventName: BI.DynamicDateTrigger.EVENT_KEY_DOWN, + action: function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); } - }], - 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"); + }, { + eventName: BI.DynamicDateTrigger.EVENT_STOP, + action: function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); } - }], - ref: function () { - self.dynamicPane = this; } - }; - } - } - }] - }; - }, - - mounted: function () { - this.setValue(this.options.value); + }, { + eventName: BI.DynamicDateTrigger.EVENT_TRIGGER_CLICK, + action: function () { + self.combo.toggle(); + } + }, { + eventName: BI.DynamicDateTrigger.EVENT_FOCUS, + action: function () { + self.storeTriggerValue = self.trigger.getKey(); + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + self.fireEvent(BI.DynamicDateCombo.EVENT_FOCUS); + } + }, { + eventName: BI.DynamicDateTrigger.EVENT_ERROR, + action: function () { + self.storeValue = { + year: date.getFullYear(), + month: date.getMonth() + }; + self.popup.setValue(); + self.fireEvent(BI.DynamicDateCombo.EVENT_ERROR); + } + }, { + eventName: BI.DynamicDateTrigger.EVENT_VALID, + action: function () { + self.fireEvent(BI.DynamicDateCombo.EVENT_VALID); + } + }, { + eventName: BI.DynamicDateTrigger.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateCombo.EVENT_CHANGE); + } + }, { + eventName: BI.DynamicDateTrigger.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.DynamicDateCombo.EVENT_CONFIRM); + } + }] + }, + adjustLength: this.constants.comboAdjustHeight, + popup: { + el: { + type: "bi.dynamic_date_popup", + min: this.constants.DATE_MIN_VALUE, + max: this.constants.DATE_MAX_VALUE, + value: opts.value, + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicDatePopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }] + }, + stopPropagation: false + }, + listeners: [{ + eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, + action: function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicDateCombo.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; + } + }; }, - _checkValueValid: function (value) { - return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + mounted: function () { + this._checkDynamicValue(this.options.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); + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } switch (type) { - case BI.DynamicDateTimePane.Dynamic: - this.dynamicPane.setValue(value); + case BI.DynamicDateCombo.Dynamic: + this.changeIcon.setVisible(true); + this.comboWrapper.attr("items")[0].width = 24; + this.comboWrapper.resize(); 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); - } + 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 { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; + return this.storeValue; + }, + getKey: function () { + return this.trigger.getKey(); + }, + hidePopupView: function () { + this.combo.hideView(); } }); -BI.shortcut("bi.dynamic_date_time_pane", BI.DynamicDateTimePane); -BI.extend(BI.DynamicDateTimePane, { +BI.DynamicDateCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicDateCombo.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicDateCombo.EVENT_CHANGE = "EVENT_CHANGE"; +BI.DynamicDateCombo.EVENT_VALID = "EVENT_VALID"; +BI.DynamicDateCombo.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW = "BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW"; + +BI.shortcut("bi.dynamic_date_combo", BI.DynamicDateCombo); + +BI.extend(BI.DynamicDateCombo, { Static: 1, Dynamic: 2 -});/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.YearCard - * @extends BI.Trigger - */ -BI.DynamicYearCard = BI.inherit(BI.Widget, { +});BI.DynamicDateParamItem = BI.inherit(BI.Widget, { props: { - baseCls: "bi-year-card" + baseCls: "bi-dynamic-date-param-item", + dateType: BI.DynamicDateCard.TYPE.YEAR, + value: 0, + offset: 0, + height: 24 }, render: function () { - var self = this; + var self = this, o = this.options; return { - type: "bi.vertical", + type: "bi.htape", items: [{ - type: "bi.label", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - textAlign: "left", - height: 24 - }, { - type: "bi.dynamic_date_param_item", - ref: function () { - self.item = this; + el: { + type: "bi.sign_editor", + cls: "bi-border", + height: 22, + validationChecker: function (v) { + return BI.isNaturalNumber(v); + }, + value: o.value, + ref: function () { + self.editor = this; + }, + errorText: function (v) { + if(BI.isEmptyString(v)) { + return BI.i18nText("BI-Basic_Input_Can_Not_Null"); + } + return BI.i18nText("BI-Please_Input_Positive_Integer"); + }, + allowBlank: false, + listeners: [{ + eventName: BI.SignEditor.EVENT_CONFIRM, + action: function () { + self.fireEvent(BI.DynamicDateParamItem.EVENT_CHANGE); + } + }] }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); + width: 60 + }, { + el: { + type: "bi.label", + height: 24, + text: this._getText() + }, + width: 20 + }, { + type: "bi.text_value_combo", + height: 24, + items: [{ + text: BI.i18nText("BI-Basic_Front"), + value: 0 + }, { + text: BI.i18nText("BI-Basic_Behind"), + value: 1 + }], + ref: function () { + self.offsetCombo = this; + }, + value: o.offset, + listeners: [{ + eventName: BI.TextValueCombo.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDateParamItem.EVENT_CHANGE); } }] - }], - vgap: 10, - hgap: 10 + }] }; }, - _createValue: function (type, v) { - return { - dateType: type, - value: Math.abs(v), - offset: v > 0 ? 1 : 0 - }; + _getText: function () { + var text = ""; + switch (this.options.dateType) { + case BI.DynamicDateCard.TYPE.YEAR: + text = BI.i18nText("BI-Basic_Year"); + break; + case BI.DynamicDateCard.TYPE.QUARTER: + text = BI.i18nText("BI-Basic_Single_Quarter"); + break; + case BI.DynamicDateCard.TYPE.MONTH: + text = BI.i18nText("BI-Basic_Month"); + break; + case BI.DynamicDateCard.TYPE.WEEK: + text = BI.i18nText("BI-Basic_Week"); + break; + case BI.DynamicDateCard.TYPE.DAY: + default: + text = BI.i18nText("BI-Basic_Day"); + break; + } + return text; }, setValue: function (v) { - v = v || {year: 0}; - this.item.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); + v = v || {}; + v.value = v.value || 0; + v.offset = v.offset || 0; + this.editor.setValue(v.value); + this.offsetCombo.setValue(v.offset); }, getValue: function () { - var value = this.item.getValue(); return { - year: (value.offset === 0 ? -value.value : value.value) + dateType: this.options.dateType, + value: this.editor.getValue(), + offset: this.offsetCombo.getValue()[0] }; } -}); -BI.DynamicYearCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_card", BI.DynamicYearCard);/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.StaticYearCard - * @extends BI.Trigger - */ -BI.StaticYearCard = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.StaticYearCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-card", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31" // 最大日期 - }); +}); +BI.DynamicDateParamItem.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_date_param_item", BI.DynamicDateParamItem);BI.DynamicDatePopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 }, - - _createYearCalendar: function (v) { - var o = this.options, y = this._year; - - var calendar = BI.createWidget({ - type: "bi.year_calendar", - behaviors: o.behaviors, - min: o.min, - max: o.max, - logic: { - dynamic: true - }, - year: y + v * 12 - }); - calendar.setValue(this._year); - return calendar; + + props: { + baseCls: "bi-dynamic-date-popup", + width: 248, + height: 344 }, - + _init: function () { - BI.StaticYearCard.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.selectedYear = this._year = BI.getDate().getFullYear(); - - this.backBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "pre-page-h-font", - width: 25, - height: 25, - value: -1, - listeners: [{ - eventName: BI.IconButton.EVENT_CHANGE, - action: function () { - self.navigation.setSelect(self.navigation.getSelect() - 1); - self._checkLeftValid(); - self._checkRightValid(); - } - }] - }); - - this.preBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "next-page-h-font", - width: 25, - height: 25, - value: 1, - listeners: [{ - eventName: BI.IconButton.EVENT_CHANGE, - action: function () { - self.navigation.setSelect(self.navigation.getSelect() + 1); - self._checkLeftValid(); - self._checkRightValid(); - } + BI.DynamicDatePopup.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.DynamicDatePopup.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.DynamicDatePopup.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.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 }] }); + this.setValue(opts.value); + }, - this.navigation = BI.createWidget({ - type: "bi.navigation", - direction: "top", - element: this, - single: true, - logic: { - dynamic: true + _getTabJson: function () { + var self = this; + return { + type: "bi.tab", + showIndex: BI.DynamicDateCombo.Static, + ref: function () { + self.dateTab = this; }, tab: { - type: "bi.htape", - cls: "bi-border-top bi-border-bottom", - height: 30, - items: [{ - el: { - type: "bi.center_adapt", - items: [self.backBtn] - }, - width: 25 - }, { - type: "bi.layout" + 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 }, { - el: { - type: "bi.center_adapt", - items: [self.preBtn] - }, - width: 25 - }] + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDateCombo.Dynamic + }], { + textAlign: "center" + }) }, - cardCreator: BI.bind(this._createYearCalendar, this), - - afterCardShow: function () { - this.setValue(self.selectedYear); - var calendar = this.getSelectedCard(); - self.backBtn.setEnable(!calendar.isFrontYear()); - self.preBtn.setEnable(!calendar.isFinalYear()); - } - }); - - this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { - self.selectedYear = this.getValue(); - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.StaticYearCard.EVENT_CHANGE, self.selectedYear); - }); + 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.date_calendar_popup", + min: self.options.min, + max: self.options.max, + listeners: [{ + eventName: BI.DateCalendarPopup.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicDatePopup.EVENT_CHANGE); + } + }], + ref: function () { + self.ymd = this; + } + }; + } + }, + 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._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; + } + } + }] + }; + }, - if(BI.isKey(o.value)){ - this.setValue(o.value); + _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); } }, - _checkLeftValid: function () { - var o = this.options; - var valid = true; - this.backBtn.setEnable(valid); - return valid; + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, - _checkRightValid: function () { - var o = this.options; - var valid = true; - this.preBtn.setEnable(valid); - return valid; + 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 { - year: this.selectedYear + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() }; - }, - - setValue: function (obj) { - var o = this.options; - obj = obj || {}; - var v = obj.year; - if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { - v = BI.getDate().getFullYear(); - this.selectedYear = ""; - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(""); - } else { - this.selectedYear = BI.parseInt(v); - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(this.selectedYear); - } - this._checkLeftValid(); - this._checkRightValid(); } }); -BI.StaticYearCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.inherit(BI.Widget, { +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: { - baseCls: "bi-year-combo bi-border", - behaviors: {}, + extraCls: "bi-date-trigger", min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24 }, _init: function () { - BI.DynamicYearCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = o.value; - this.trigger = BI.createWidget({ - type: "bi.dynamic_year_trigger", - min: o.min, - max: o.max, - value: o.value || "" + 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.trigger.on(BI.DynamicYearTrigger.EVENT_FOCUS, function () { - self.storeTriggerValue = this.getKey(); + this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_FOCUS); }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_STOP, function () { - self.combo.showView(); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_STOP); }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); + this.editor.on(BI.SignEditor.EVENT_VALID, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_VALID); }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; + 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 (this.getKey() && this.getKey() !== self.storeTriggerValue) { - self.storeValue = self.trigger.getValue(); - self.setValue(self.storeValue); - } else if (!this.getKey()) { - self.storeValue = null; - self.setValue(); + + 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.DynamicYearCombo.EVENT_CONFIRM); + self.fireEvent(BI.DynamicDateTrigger.EVENT_CONFIRM); }); - - this.combo = BI.createWidget({ - type: "bi.combo", - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.dynamic_year_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicYearPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({year: date.getFullYear()}); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" + this.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); } }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW); + 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, - ref: function () { - self.comboWrapper = this; - }, 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 - }, this.combo] + el: this.editor + }, { + el: BI.createWidget(), + width: 30 + }] }); - this._checkDynamicValue(o.value); + 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; + } + } }, - _checkDynamicValue: function (v) { - var type = null; + _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; + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; } switch (type) { - case BI.DynamicYearCombo.Dynamic: - this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[0].width = 24; - this.comboWrapper.resize(); + case BI.DynamicDateCombo.Dynamic: + var text = this._getText(value); + date = BI.DynamicDateHelper.getCalculation(value); + this._setInnerValue(date, text); break; + case BI.DynamicDateCombo.Static: default: - this.comboWrapper.attr("items")[0].width = 0; - this.comboWrapper.resize(); - this.changeIcon.setVisible(false); + 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; } }, - setValue: function (v) { - this.storeValue = v; - this.trigger.setValue(v); - this._checkDynamicValue(v); + getKey: function () { + return this.editor.getValue(); }, - getValue: function () { return this.storeValue; } }); -BI.DynamicYearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.dynamic_year_combo", BI.DynamicYearCombo); -BI.extend(BI.DynamicYearCombo, { - Static: 1, - Dynamic: 2 -});/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.DynamicYearPopup - * @extends BI.Trigger - */ -BI.DynamicYearPopup = BI.inherit(BI.Widget, { +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: { - tabHeight: 30 + popupHeight: 259, + popupWidth: 270, + comboAdjustHeight: 1, + border: 1, + DATE_MIN_VALUE: "1900-01-01", + DATE_MAX_VALUE: "2099-12-31" }, props: { - baseCls: "bi-year-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期, - width: 180, - height: 240 + baseCls: "bi-dynamic-date-combo bi-border", + height: 24 }, + render: function () { var self = this, opts = this.options; - this.storeValue = {type: BI.DynamicYearCombo.Static}; + this.storeTriggerValue = ""; + var date = BI.getDate(); + this.storeValue = opts.value; return { - type: "bi.vtape", + type: "bi.htape", items: [{ - el: this._getTabJson() - }, { el: { - type: "bi.grid", - items: [[{ - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_Clear"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.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-Basic_Current_Year"), - ref: function () { - self.textButton = this; - }, - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE); - } - }] - }, { - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_OK"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE); - } - }] - }]] + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, + ref: function () { + self.changeIcon = this; + } }, - height: 24 - }] - }; - }, - - _setInnerValue: function () { - if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); - this.textButton.setEnable(true); - } else { - var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); - date = date.print("%Y"); - this.textButton.setValue(date); - this.textButton.setEnable(false); - } - }, - - _getTabJson: function () { - var self = this, o = this.options; - return { - type: "bi.tab", - 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-Basic_Year_Fen"), - value: BI.DynamicYearCombo.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicYearCombo.Dynamic - }], { - textAlign: "center" - }) - }, - cardCreator: function (v) { - switch (v) { - case BI.DynamicYearCombo.Dynamic: - return { - type: "bi.dynamic_year_card", + 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: "EVENT_CHANGE", + eventName: BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN, action: function () { - self._setInnerValue(self.year, v); + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } } - }], - ref: function () { - self.dynamicPane = this; - } - }; - case BI.DynamicYearCombo.Static: - default: - return { - type: "bi.static_year_card", - behaviors: o.behaviors, - min: self.options.min, - max: self.options.max, - listeners: [{ - eventName: BI.YearCard.EVENT_CHANGE, + }, { + eventName: BI.DynamicDateTimeTrigger.EVENT_STOP, action: function () { - self.fireEvent(BI.DynamicYearPopup.EVENT_CHANGE); + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } } - }], - ref: function () { - self.year = this; - } - }; - } - }, - listeners: [{ - eventName: BI.Tab.EVENT_CHANGE, - action: function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.DynamicYearCombo.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.year.setValue({year: date.getFullYear()}); - self._setInnerValue(); - break; - case BI.DynamicYearCombo.Dynamic: - default: - if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { - self.dynamicPane.setValue(self.storeValue.value); - }else{ - self.dynamicPane.setValue({ - year: 0 - }); - } - self._setInnerValue(); - break; - } - } - }] - }; - }, - - 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: - this.year.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); - this.textButton.setEnable(true); - break; - } - }, - - getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; - } - -}); -BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.DynamicYearPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_popup", BI.DynamicYearPopup);BI.DynamicYearTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") - }, - - _defaultConfig: function () { - return BI.extend(BI.DynamicYearTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-year-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }); - }, - _init: function () { - BI.DynamicYearTrigger.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) { - return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - allowBlank: true, - errorText: function (v) { - return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; - } - }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_FOCUS); - }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_STOP); - }); - this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - } - if (BI.isNotEmptyString(value)) { - self.storeValue = { - type: BI.DynamicDateCombo.Static, - value: { - year: value - } - }; - } - - self.fireEvent(BI.DynamicYearTrigger.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.DynamicYearTrigger.EVENT_START); - }); - this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_ERROR); - }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [{ - el: this.editor - }, { - el: { - type: "bi.text_button", - baseCls: "bi-trigger-year-text", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, - width: o.height - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - }] - }); - this.setValue(o.value); - }, - - _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")); - } - return value; - }, - - _setInnerValue: function (date, text) { - var dateStr = date.print("%Y"); - this.editor.setState(dateStr); - this.editor.setValue(dateStr); - this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); - }, - - setValue: function (v) { - var type, value; - 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: - value = value || {}; - this.editor.setState(value.year); - this.editor.setValue(value.year); - this.editor.setTitle(value.year); - break; - } - }, - - getValue: function () { - return this.storeValue; - }, - - getKey: function () { - return this.editor.getValue() | 0; - } -}); -BI.DynamicYearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DynamicYearTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.DynamicYearTrigger.EVENT_START = "EVENT_START"; -BI.DynamicYearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.dynamic_year_trigger", BI.DynamicYearTrigger);/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.YearCard - * @extends BI.Trigger - */ -BI.DynamicYearMonthCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-year-month-card" - }, - - render: function () { - var self = this; - return { - type: "bi.vertical", - items: [{ - type: "bi.label", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - textAlign: "left", - height: 24 - }, { - type: "bi.dynamic_date_param_item", - ref: function () { - self.year = this; - }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }, { - type: "bi.dynamic_date_param_item", - dateType: BI.DynamicDateCard.TYPE.MONTH, - ref: function () { - self.month = this; - }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }], - vgap: 10, - hgap: 10 - }; - }, - - _createValue: function (type, v) { - return { - dateType: type, - value: Math.abs(v), - offset: v > 0 ? 1 : 0 - }; - }, - - setValue: function (v) { - v = v || {year: 0, month: 0}; - this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); - this.month.setValue(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); - }, - - getValue: function () { - var year = this.year.getValue(); - var month = this.month.getValue(); - return { - year: (year.offset === 0 ? -year.value : year.value), - month: (month.offset === 0 ? -month.value : month.value) - }; - } -}); -BI.DynamicYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_month_card", BI.DynamicYearMonthCard);BI.StaticYearMonthCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-static-year-month-card", - behaviors: {} - }, - - _createMonths: function () { - // 纵向排列月 - var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; - var items = []; - items.push(month.slice(0, 2)); - items.push(month.slice(2, 4)); - items.push(month.slice(4, 6)); - items.push(month.slice(6, 8)); - items.push(month.slice(8, 10)); - items.push(month.slice(10, 12)); - return BI.map(items, function (i, item) { - return BI.map(item, function (j, td) { - return { - type: "bi.text_item", - cls: "bi-list-item-active", - textAlign: "center", - whiteSpace: "nowrap", - once: false, - forceSelected: true, - height: 23, - width: 38, - value: td, - text: td + 1 - }; - }); - }); - }, - - render: function () { - var self = this, o = this.options; - return { - type: "bi.vertical", - items: [{ - type: "bi.year_picker", - ref: function () { - self.yearPicker = this; - }, - height: 30, - listeners: [{ - eventName: BI.YearPicker.EVENT_CHANGE, - action: function () { - var value = this.getValue(); - self.setValue({ - year: value, - month: self.selectedMonth - }); - } - }] - }, { - type: "bi.button_group", - behaviors: o.behaviors, - ref: function () { - self.month = this; - }, - items: this._createMonths(), - layouts: [BI.LogicFactory.createLogic("table", BI.extend({ - dynamic: true - }, { - columns: 2, - rows: 6, - columnSize: [1 / 2, 1 / 2], - rowSize: 25 - })), { - type: "bi.center_adapt", - vgap: 1, - hgap: 2 - }], - value: o.value, - listeners: [{ - eventName: BI.ButtonGroup.EVENT_CHANGE, - action: function () { - self.selectedYear = self.yearPicker.getValue(); - self.selectedMonth = this.getValue()[0]; - self.fireEvent(BI.StaticYearMonthCard.EVENT_CHANGE); - } - }] - }] - }; - }, - - - getValue: function () { - return { - year: this.selectedYear, - month: this.selectedMonth - }; - }, - - setValue: function (obj) { - var o = this.options; - obj = obj || {}; - obj.year = obj.year || 0; - obj.month = obj.month || 0; - if (BI.checkDateVoid(obj.year, obj.month, 1, o.min, o.max)[0]) { - var year = BI.getDate().getFullYear(); - var month = BI.getDate().getMonth(); - this.selectedYear = ""; - this.selectedMonth = ""; - this.yearPicker.setValue(year); - this.month.setValue(month); - } else { - this.selectedYear = BI.parseInt(obj.year); - this.selectedMonth = BI.parseInt(obj.month); - this.yearPicker.setValue(this.selectedYear); - this.month.setValue(this.selectedMonth); - } - } -}); -BI.StaticYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; -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: 24 - }, - - _init: function () { - BI.DynamicYearMonthCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = o.value; - this.trigger = BI.createWidget({ - type: "bi.dynamic_year_month_trigger", - min: o.min, - max: o.max, - value: o.value || "" - }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_STOP, function () { - self.combo.showView(); - }); - 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()) { - return; - } - 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", - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.dynamic_year_month_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicYearMonthPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({year: date.getFullYear()}); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - ref: function () { - self.comboWrapper = this; - }, - 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 - }, this.combo] - }); - this._checkDynamicValue(o.value); - }, - - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.DynamicYearMonthCombo.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; - } - }, - - hideView: function () { - this.combo.hideView(); - }, - - setValue: function (v) { - this.storeValue = v; - this.trigger.setValue(v); - this._checkDynamicValue(v); - }, - - 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); - -BI.extend(BI.DynamicYearMonthCombo, { - Static: 1, - Dynamic: 2 -});/** - * 年月 - * - * Created by GUY on 2015/9/2. - * @class BI.DynamicYearMonthPopup - * @extends BI.Trigger - */ -BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30 - }, - - props: { - baseCls: "bi-year-month-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期, - width: 180, - height: 240 - }, - - render: function () { - var self = this, opts = this.options; - this.storeValue = {type: BI.DynamicYearMonthCombo.Static}; - return { - type: "bi.vtape", - items: [{ - el: this._getTabJson() - }, { - el: { - type: "bi.grid", - items: [[{ - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_Clear"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearMonthPopup.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-Basic_Current_Month"), - ref: function () { - self.textButton = this; - }, - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE); - } - }] - }, { - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_OK"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE); - } - }] - }]] - }, - height: 24 - }] - }; - }, - - _setInnerValue: function () { - if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); - this.textButton.setEnable(true); - } else { - var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); - date = date.print("%Y-%x"); - this.textButton.setValue(date); - this.textButton.setEnable(false); - } - }, - - _getTabJson: function () { - var self = this, o = this.options; - return { - type: "bi.tab", - 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-Basic_Year_Fen"), - value: BI.DynamicYearCombo.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicYearCombo.Dynamic - }], { - textAlign: "center" - }) - }, - cardCreator: function (v) { - switch (v) { - case BI.DynamicYearCombo.Dynamic: - return { - type: "bi.dynamic_year_month_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self._setInnerValue(self.year, v); - } - }], - ref: function () { - self.dynamicPane = this; - } - }; - case BI.DynamicYearCombo.Static: - default: - return { - type: "bi.static_year_month_card", - behaviors: o.behaviors, - min: self.options.min, - max: self.options.max, - listeners: [{ - eventName: BI.YearCard.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearMonthPopup.EVENT_CHANGE); - } - }], - ref: function () { - self.year = this; - } - }; - } - }, - listeners: [{ - eventName: BI.Tab.EVENT_CHANGE, - action: function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.DynamicYearCombo.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.year.setValue({year: date.getFullYear(), month: date.getMonth()}); - self._setInnerValue(); - break; - case BI.DynamicYearCombo.Dynamic: - default: - if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { - self.dynamicPane.setValue(self.storeValue.value); - }else{ - self.dynamicPane.setValue({ - year: 0 - }); - } - self._setInnerValue(); - break; - } - } - }] - }; - }, - - 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: - this.year.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); - this.textButton.setEnable(true); - break; - } - }, - - getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; - } - -}); -BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.DynamicYearMonthPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_month_popup", BI.DynamicYearMonthPopup);BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") - }, - - props: { - extraCls: "bi-year-month-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }, - - _init: function () { - BI.DynamicYearMonthTrigger.superclass._init.apply(this, arguments); - var o = this.options; - - this.yearEditor = this._createEditor(true); - this.monthEditor = this._createEditor(false); - - BI.createWidget({ - element: this, - type: "bi.htape", - items: [{ - type: "bi.center", - items: [{ - type: "bi.htape", - items: [this.yearEditor, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, - width: o.height - }] - }, { - type: "bi.htape", - items: [this.monthEditor, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Month"), - width: o.height - }, - width: o.height}] - }] - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - }] - }); - this.setValue(o.value); - }, - - _createEditor: function (isYear) { - var self = this, o = this.options, c = this._const; - var editor = BI.createWidget({ - type: "bi.sign_editor", - height: o.height, - validationChecker: function (v) { - if(isYear) { - return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); - } - return v === "" || ((v >= 1 && v <= 12) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); - }, - quitChecker: function () { - return false; - }, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - errorText: function (v) { - return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; - }, - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true - }); - editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_FOCUS); - }); - editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_STOP); - }); - editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = editor.getValue(); - if (BI.isNotNull(value)) { - editor.setValue(value); - } - if (BI.isNotEmptyString(value)) { - var monthValue = self.monthEditor.getValue(); - self.storeValue = { - type: BI.DynamicDateCombo.Static, - value: { - year: self.yearEditor.getValue(), - month: BI.isEmptyString(self.monthEditor.getValue()) ? "" : monthValue - 1 - } - }; - } - - self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_CONFIRM); - }); - editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (editor.isValid()) { - editor.blur(); - } - }); - editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_START); - }); - 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()); - } - }); - - return editor; - }, - - _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; - }, - - _autoSwitch: function (v) { - if (BI.checkDateLegal(v)) { - if (v.length === 4 && this._yearCheck(v)) { - this.monthEditor.focus(); - } - } - }, - - _getText: function (obj) { - var value = ""; - if(BI.isNotNull(obj.year)) { - value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); - } - if(BI.isNotNull(obj.month) && obj.month !== 0) { - value += Math.abs(obj.month) + BI.i18nText("BI-Basic_Year") + (obj.month < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); - } - return value; - }, - - _setInnerValue: function (date, text) { - var dateStr = date.print("%Y-%x"); - this.yearEditor.setValue(date.getFullYear()); - this.monthEditor.setValue(date.getMonth() + 1); - this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); - }, - - setValue: function (v) { - var type, value; - 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: - value = value || {}; - var month = BI.isNull(value.month) ? null : value.month + 1; - this.yearEditor.setValue(value.year); - this.yearEditor.setTitle(value.year); - this.monthEditor.setValue(month); - this.monthEditor.setTitle(month); - break; - } - }, - - 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"; -BI.DynamicYearMonthTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearMonthTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.dynamic_year_month_trigger", BI.DynamicYearMonthTrigger);/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.YearCard - * @extends BI.Trigger - */ -BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-year-month-card" - }, - - render: function () { - var self = this; - return { - type: "bi.vertical", - items: [{ - type: "bi.label", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - textAlign: "left", - height: 24 - }, { - type: "bi.dynamic_date_param_item", - ref: function () { - self.year = this; - }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }, { - type: "bi.dynamic_date_param_item", - dateType: BI.DynamicDateCard.TYPE.QUARTER, - ref: function () { - self.quarter = this; - }, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }], - vgap: 10, - hgap: 10 - }; - }, - - _createValue: function (type, v) { - return { - dateType: type, - value: Math.abs(v), - offset: v > 0 ? 1 : 0 - }; - }, - - setValue: function (v) { - v = v || {year: 0, month: 0}; - this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); - this.quarter.setValue(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); - }, - - getValue: function () { - var year = this.year.getValue(); - var quarter = this.quarter.getValue(); - return { - year: (year.offset === 0 ? -year.value : year.value), - quarter: (quarter.offset === 0 ? -quarter.value : quarter.value) - }; - } -}); -BI.DynamicYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_quarter_card", BI.DynamicYearQuarterCard);BI.StaticYearQuarterCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-static-year-quarter-card", - behaviors: {} - }, - - _createQuarter: function () { - - var items = [{ - text: Date._QN[1], - value: 1 - }, { - text: Date._QN[2], - value: 2 - }, { - text: Date._QN[3], - value: 3 - }, { - text: Date._QN[4], - value: 4 - }]; - return BI.map(items, function (j, item) { - return BI.extend(item, { - type: "bi.text_item", - cls: "bi-list-item-active", - textAlign: "center", - whiteSpace: "nowrap", - once: false, - forceSelected: true, - height: 24 - }); - }); - }, - - render: function () { - var self = this, o = this.options; - return { - type: "bi.vertical", - items: [{ - type: "bi.year_picker", - ref: function () { - self.yearPicker = this; - }, - height: 30, - listeners: [{ - eventName: BI.YearPicker.EVENT_CHANGE, - action: function () { - var value = this.getValue(); - self.setValue({ - year: value, - quarter: self.selectedQuarter - }); - } - }] - }, { - type: "bi.button_group", - behaviors: o.behaviors, - ref: function () { - self.quarter = this; - }, - items: this._createQuarter(), - layouts: [{ - type: "bi.vertical", - vgap: 10 - }], - value: o.value, - listeners: [{ - eventName: BI.ButtonGroup.EVENT_CHANGE, - action: function () { - self.selectedYear = self.yearPicker.getValue(); - self.selectedQuarter = this.getValue()[0]; - self.fireEvent(BI.StaticYearQuarterCard.EVENT_CHANGE); - } - }] - }] - }; - }, - - - getValue: function () { - return { - year: this.selectedYear, - quarter: this.selectedQuarter - }; - }, - - setValue: function (obj) { - var o = this.options; - obj = obj || {}; - obj.year = obj.year || 0; - obj.quarter = obj.quarter || 0; - if (BI.checkDateVoid(obj.year, obj.quarter, 1, o.min, o.max)[0]) { - var year = BI.getDate().getFullYear(); - var quarter = BI.getDate().getQuarter(); - this.selectedYear = ""; - this.selectedQuarter = ""; - this.yearPicker.setValue(year); - this.quarter.setValue(quarter); - } else { - this.selectedYear = BI.parseInt(obj.year); - this.selectedQuarter = BI.parseInt(obj.quarter); - this.yearPicker.setValue(this.selectedYear); - this.quarter.setValue(this.selectedQuarter); - } - } -}); -BI.StaticYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-year-quarter-combo bi-border", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }, - - _init: function () { - BI.DynamicYearQuarterCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = o.value; - this.trigger = BI.createWidget({ - type: "bi.dynamic_year_quarter_trigger", - min: o.min, - max: o.max, - value: o.value || "" - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () { - self.combo.showView(); - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; - } - self.storeValue = self.trigger.getValue(); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); - }); - - this.combo = BI.createWidget({ - type: "bi.combo", - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.dynamic_year_quarter_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicYearQuarterPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({year: date.getFullYear()}); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - ref: function () { - self.comboWrapper = this; - }, - 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 - }, this.combo] - }); - this._checkDynamicValue(o.value); - }, - - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.DynamicYearQuarterCombo.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; - } - -}); -BI.DynamicYearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.dynamic_year_quarter_combo", BI.DynamicYearQuarterCombo); - -BI.extend(BI.DynamicYearQuarterCombo, { - Static: 1, - Dynamic: 2 -});BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30 - }, - - props: { - baseCls: "bi-year-quarter-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期, - width: 180, - height: 240 - }, - - render: function () { - var self = this, opts = this.options; - this.storeValue = {type: BI.DynamicYearQuarterCombo.Static}; - return { - type: "bi.vtape", - items: [{ - el: this._getTabJson() - }, { - el: { - type: "bi.grid", - items: [[{ - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_Clear"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearQuarterPopup.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-Basic_Current_Quarter"), - ref: function () { - self.textButton = this; - }, - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE); - } - }] - }, { - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_OK"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE); - } - }] - }]] - }, - height: 24 - }] - }; - }, - - _setInnerValue: function () { - if (this.dateTab.getSelect() === BI.DynamicYearQuarterCombo.Static) { - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); - this.textButton.setEnable(true); - } else { - var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); - date = date.print("%Y-%x"); - this.textButton.setValue(date); - this.textButton.setEnable(false); - } - }, - - _getTabJson: function () { - var self = this, o = this.options; - return { - type: "bi.tab", - 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-Basic_Year_Fen"), - value: BI.DynamicYearQuarterCombo.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicYearQuarterCombo.Dynamic - }], { - textAlign: "center" - }) - }, - cardCreator: function (v) { - switch (v) { - case BI.DynamicYearQuarterCombo.Dynamic: - return { - type: "bi.dynamic_year_quarter_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self._setInnerValue(self.year, v); - } - }], - ref: function () { - self.dynamicPane = this; - } - }; - case BI.DynamicYearQuarterCombo.Static: - default: - return { - type: "bi.static_year_quarter_card", - behaviors: o.behaviors, - min: self.options.min, - max: self.options.max, - listeners: [{ - eventName: BI.YearCard.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearQuarterPopup.EVENT_CHANGE); - } - }], - ref: function () { - self.year = this; - } - }; - } - }, - listeners: [{ - eventName: BI.Tab.EVENT_CHANGE, - action: function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.DynamicYearQuarterCombo.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.year.setValue({year: date.getFullYear(), quarter: date.getQuarter()}); - self._setInnerValue(); - break; - case BI.DynamicYearQuarterCombo.Dynamic: - default: - if(self.storeValue && self.storeValue.type === BI.DynamicYearQuarterCombo.Dynamic) { - self.dynamicPane.setValue(self.storeValue.value); - }else{ - self.dynamicPane.setValue({ - year: 0 - }); - } - self._setInnerValue(); - break; - } - } - }] - }; - }, - - 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: - this.year.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); - this.textButton.setEnable(true); - break; - } - }, - - getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; - } - -}); -BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.DynamicYearQuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_quarter_popup", BI.DynamicYearQuarterPopup);BI.DynamicYearQuarterTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") - }, - - props: { - extraCls: "bi-year-quarter-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }, - - _init: function () { - BI.DynamicYearQuarterTrigger.superclass._init.apply(this, arguments); - var o = this.options; - - this.yearEditor = this._createEditor(true); - this.quarterEditor = this._createEditor(false); - - BI.createWidget({ - element: this, - type: "bi.htape", - items: [{ - type: "bi.center", - items: [{ - type: "bi.htape", - items: [this.yearEditor, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, - width: o.height - }] - }, { - type: "bi.htape", - items: [this.quarterEditor, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Quarter"), - width: o.height - }, - width: o.height}] - }] - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - }] - }); - this.setValue(o.value); - }, - - _createEditor: function (isYear) { - var self = this, o = this.options, c = this._const; - var editor = BI.createWidget({ - type: "bi.sign_editor", - height: o.height, - validationChecker: function (v) { - if(isYear) { - return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); - } - return v === "" || ((v >= 1 && v <= 4) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); - }, - quitChecker: function () { - return false; - }, - errorText: function (v) { - return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; - }, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true - }); - editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_FOCUS); - }); - editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_STOP); - }); - editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = editor.getValue(); - if (BI.isNotNull(value)) { - editor.setValue(value); - } - if (BI.isNotEmptyString(value)) { - var quarterValue = self.quarterEditor.getValue(); - self.storeValue = { - type: BI.DynamicYearQuarterCombo.Static, - value: { - year: self.yearEditor.getValue(), - quarter: BI.isEmptyString(self.quarterEditor.getValue()) ? "" : quarterValue - } - }; - } - - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM); - }); - editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (editor.isValid()) { - editor.blur(); - } - }); - editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_START); - }); - editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_ERROR); - }); - editor.on(BI.SignEditor.EVENT_CHANGE, function () { - if(isYear) { - self._autoSwitch(editor.getValue()); - } - }); - - return editor; - }, - - _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; - }, - - _autoSwitch: function (v) { - if (BI.checkDateLegal(v)) { - if (v.length === 4 && this._yearCheck(v)) { - this.quarterEditor.focus(); - } - } - }, - - _getText: function (obj) { - var value = ""; - if(BI.isNotNull(obj.year)) { - value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); - } - if(BI.isNotNull(obj.quarter) && obj.quarter !== 0) { - value += Math.abs(obj.quarter) + BI.i18nText("BI-Basic_Year") + (obj.quarter < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); - } - return value; - }, - - _setInnerValue: function (date, text) { - var dateStr = date.print("%Y-%x"); - this.yearEditor.setValue(date.getFullYear()); - this.quarterEditor.setValue(date.getQuarter()); - this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); - }, - - setValue: function (v) { - var type, value; - var date = BI.getDate(); - this.storeValue = v; - if (BI.isNotNull(v)) { - type = v.type || BI.DynamicYearQuarterCombo.Static; - value = v.value || v; - } - switch (type) { - case BI.DynamicYearQuarterCombo.Dynamic: - var text = this._getText(value); - date = BI.DynamicDateHelper.getCalculation(value); - this._setInnerValue(date, text); - break; - case BI.DynamicYearQuarterCombo.Static: - default: - value = value || {}; - var quarter = BI.isNull(value.quarter) ? null : value.quarter; - this.yearEditor.setValue(value.year); - this.yearEditor.setTitle(value.year); - this.quarterEditor.setValue(quarter); - this.quarterEditor.setTitle(quarter); - break; - } - }, - - getValue: function () { - return this.storeValue; - } -}); -BI.DynamicYearQuarterTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DynamicYearQuarterTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.DynamicYearQuarterTrigger.EVENT_START = "EVENT_START"; -BI.DynamicYearQuarterTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearQuarterTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.dynamic_year_quarter_trigger", BI.DynamicYearQuarterTrigger);/** - * 汇总表格帮助类 - * Created by Young's on 2017/1/19. - */ -!(function () { - BI.DynamicDateHelper = {}; - BI.extend(BI.DynamicDateHelper, { - getCalculation: function (obj) { - var date = BI.getDate(); - if (BI.isNotNull(obj.year)) { - date = BI.getDate((date.getFullYear() + BI.parseInt(obj.year)), date.getMonth(), date.getDate()); - } - if (BI.isNotNull(obj.quarter)) { - date = date.getAfterMulQuarter(obj.quarter); - } - if (BI.isNotNull(obj.month)) { - date = date.getAfterMultiMonth(obj.month); - } - if (BI.isNotNull(obj.week)) { - date = date.getOffsetDate(obj.week * 7); - } - if (BI.isNotNull(obj.day)) { - date = date.getOffsetDate(obj.day); - } - if (BI.isNotNull(obj.workDay)) { - // todo 根据工作日做偏移 - } - if (BI.isNotNull(obj.position) && obj.position !== BI.DynamicDateCard.OFFSET.CURRENT) { - date = this.getBeginDate(date, obj); - } - return date; - }, - - getBeginDate: function (date, obj) { - if (BI.isNotNull(obj.day)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), date.getMonth(), 1) : BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); - } - if (BI.isNotNull(obj.week)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? date.getWeekStartDate() : date.getWeekEndDate(); - } - if (BI.isNotNull(obj.month)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), date.getMonth(), 1) : BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); - } - if (BI.isNotNull(obj.quarter)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? date.getQuarterStartDate() : date.getQuarterEndDate(); - } - if (BI.isNotNull(obj.year)) { - return obj.position === BI.DynamicDateCard.OFFSET.BEGIN ? BI.getDate(date.getFullYear(), 0, 1) : BI.getDate(date.getFullYear(), 11, 31); - } - } - }); -})();BI.DynamicDateCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-dynamic-date-card" - }, - - render: function () { - var self = this; - this.position = BI.DynamicDateCard.OFFSET.CURRENT; - return { - type: "bi.vertical", - items: [{ - el: { - type: "bi.label", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - textAlign: "left", - height: 24, - lgap: 10 - } - }, { - type: "bi.button_group", - ref: function () { - self.checkgroup = this; - }, - chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, - value: [BI.DynamicDateCard.TYPE.YEAR], - items: BI.createItems([{ - text: BI.i18nText("BI-Basic_Year"), - value: BI.DynamicDateCard.TYPE.YEAR - }, { - text: BI.i18nText("BI-Basic_Single_Quarter"), - value: BI.DynamicDateCard.TYPE.QUARTER - }, { - text: BI.i18nText("BI-Basic_Month"), - value: BI.DynamicDateCard.TYPE.MONTH - }, { - text: BI.i18nText("BI-Basic_Week"), - value: BI.DynamicDateCard.TYPE.WEEK - }, { - text: BI.i18nText("BI-Basic_Day"), - value: BI.DynamicDateCard.TYPE.DAY - }], { - type: "bi.multi_select_item", - logic: { - dynamic: true - } - }), - layouts: [{ - type: "bi.left" - }], - listeners: [{ - eventName: BI.ButtonGroup.EVENT_CHANGE, - action: function () { - var value = self.checkgroup.getValue(); - if(value.length !== 0) { - self.workDayBox.setSelected(false); - } - self.resultPane.populate(self._getParamJson(BI.map(self.checkgroup.getValue(), function (idx, v) { - return { - dateType: v - }; - }))); - self.position = BI.DynamicDateCard.OFFSET.CURRENT; - self.fireEvent("EVENT_CHANGE"); - } - }] - }, { - type: "bi.vertical_adapt", - items: [{ - type: "bi.multi_select_item", - ref: function () { - self.workDayBox = this; - }, - logic: { - dynamic: true - }, - text: BI.i18nText("BI-Basic_Work_Day"), - value: BI.DynamicDateCard.TYPE.WORK_DAY, - listeners: [{ - eventName: BI.MultiSelectItem.EVENT_CHANGE, - action: function () { - if(this.isSelected()) { - self.checkgroup.setValue(); - } - self.resultPane.populate(this.isSelected() ? self._getParamJson([{ - dateType: BI.DynamicDateCard.TYPE.WORK_DAY - }]) : []); - self.position = BI.DynamicDateCard.OFFSET.CURRENT; - self.fireEvent("EVENT_CHANGE"); - } - }] - }], - ref: function () { - self.workDay = this; - } - }, { - type: "bi.button_group", - items: this._getParamJson([{ - dateType: BI.DynamicDateCard.TYPE.YEAR - }]), - ref: function () { - self.resultPane = this; - }, - layouts: [{ - type: "bi.vertical", - vgap: 10, - hgap: 10 - }] - }] - }; - }, - - _getParamJson: function (values, positionValue) { - var self = this; - var items = BI.map(values, function (idx, value) { - return { - type: "bi.dynamic_date_param_item", - dateType: value.dateType, - value: value.value, - offset: value.offset, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }] - }; - }); - - if(values.length === 1 && values[0] === BI.DynamicDateCard.TYPE.DAY) { - items.push = [{ - type: "bi.text_value_combo", - height: 24, - items: this._getText(BI.DynamicDateCard.TYPE.MONTH), - value: positionValue || BI.DynamicDateCard.OFFSET.CURRENT, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.position = this.getValue()[0]; - self.fireEvent("EVENT_CHANGE"); - } - }] - }]; - }else{ - if(values.length !== 0 && BI.last(values).dateType !== BI.DynamicDateCard.TYPE.DAY && BI.last(values).dateType !== BI.DynamicDateCard.TYPE.WORK_DAY) { - items.push({ - type: "bi.text_value_combo", - height: 24, - items: this._getText(BI.last(values).dateType), - value: positionValue || BI.DynamicDateCard.OFFSET.CURRENT, - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.position = this.getValue()[0]; - self.fireEvent("EVENT_CHANGE"); - } - }] - }); - - } - } - - return items; - }, - - _getText: function (lastValue) { - switch (lastValue) { - case BI.DynamicDateCard.TYPE.YEAR: - return [{ - text: BI.i18nText("BI-Basic_Current_Day"), - value: BI.DynamicDateCard.OFFSET.CURRENT - }, { - text: BI.i18nText("BI-Basic_Year_Begin"), - value: BI.DynamicDateCard.OFFSET.BEGIN - }, { - text: BI.i18nText("BI-Basic_Year_End"), - value: BI.DynamicDateCard.OFFSET.END - }]; - case BI.DynamicDateCard.TYPE.QUARTER: - return [{ - text: BI.i18nText("BI-Basic_Current_Day"), - value: BI.DynamicDateCard.OFFSET.CURRENT - }, { - text: BI.i18nText("BI-Basic_Quarter_Begin"), - value: BI.DynamicDateCard.OFFSET.BEGIN - }, { - text: BI.i18nText("BI-Basic_Quarter_End"), - value: BI.DynamicDateCard.OFFSET.END - }]; - case BI.DynamicDateCard.TYPE.MONTH: - return [{ - text: BI.i18nText("BI-Basic_Current_Day"), - value: BI.DynamicDateCard.OFFSET.CURRENT - }, { - text: BI.i18nText("BI-Basic_Month_Begin"), - value: BI.DynamicDateCard.OFFSET.BEGIN - }, { - text: BI.i18nText("BI-Basic_Month_End"), - value: BI.DynamicDateCard.OFFSET.END - }]; - case BI.DynamicDateCard.TYPE.WEEK: - default: - return [{ - text: BI.i18nText("BI-Basic_Current_Day"), - value: BI.DynamicDateCard.OFFSET.CURRENT - }, { - text: BI.i18nText("BI-Basic_Week_Begin"), - value: BI.DynamicDateCard.OFFSET.BEGIN - }, { - text: BI.i18nText("BI-Basic_Week_End"), - value: BI.DynamicDateCard.OFFSET.END - }]; - } - }, - - _createValue: function (type, v) { - return { - dateType: type, - value: Math.abs(v), - offset: v > 0 ? 1 : 0 - }; - }, - - setValue: function (v) { - v = v || {}; - var values = []; - var valuesItems = []; - if(BI.isNotNull(v.year)) { - values.push(BI.DynamicDateCard.TYPE.YEAR); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); - } - if(BI.isNotNull(v.quarter)) { - values.push(BI.DynamicDateCard.TYPE.QUARTER); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); - } - if(BI.isNotNull(v.month)) { - values.push(BI.DynamicDateCard.TYPE.MONTH); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); - } - if(BI.isNotNull(v.week)) { - values.push(BI.DynamicDateCard.TYPE.WEEK); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.WEEK, v.week)); - } - if(BI.isNotNull(v.day)) { - values.push(BI.DynamicDateCard.TYPE.DAY); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.DAY, v.day)); - } - if(BI.isNotNull(v.workDay)) { - values.push(BI.DynamicDateCard.TYPE.WORK_DAY); - valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.WORK_DAY, v.workDay)); - } - this.checkgroup.setValue(values); - this.workDayBox.setSelected(BI.isNotNull(v.workDay)); - this.resultPane.populate(this._getParamJson(valuesItems, v.position)); - }, - - getValue: function () { - var self = this; - var valueMap = {}; - var selectValues = this.checkgroup.getValue(); - var buttons = this.resultPane.getAllButtons(); - if(selectValues.length !== 0) { - BI.each(buttons, function (idx, button) { - var value = button.getValue(); - switch (value.dateType) { - case BI.DynamicDateCard.TYPE.YEAR: - valueMap.year = (value.offset === 0 ? -value.value : value.value); - break; - case BI.DynamicDateCard.TYPE.QUARTER: - valueMap.quarter = (value.offset === 0 ? -value.value : value.value); - break; - case BI.DynamicDateCard.TYPE.MONTH: - valueMap.month = (value.offset === 0 ? -value.value : value.value); - break; - case BI.DynamicDateCard.TYPE.WEEK: - valueMap.week = (value.offset === 0 ? -value.value : value.value); - break; - case BI.DynamicDateCard.TYPE.DAY: - valueMap.day = (value.offset === 0 ? -value.value : value.value); - break; - default: - break; - } - if(BI.isNull(value.dateType)) { - valueMap.position = self.position || BI.DynamicDateCard.OFFSET.CURRENT; - } - }); - } - if(this.workDayBox.isSelected()) { - var value = buttons[0].getValue(); - valueMap.workDay = (value.offset === 0 ? -value.value : value.value); - } - return valueMap; - } - -}); -BI.shortcut("bi.dynamic_date_card", BI.DynamicDateCard); - -BI.extend(BI.DynamicDateCard, { - TYPE: { - YEAR: 1, - QUARTER: 2, - MONTH: 3, - WEEK: 4, - DAY: 5, - WORK_DAY: 6 - }, - OFFSET: { - CURRENT: 1, - BEGIN: 2, - END: 3 - } - -});BI.DynamicDateCombo = 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_trigger", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value, - ref: function () { - self.trigger = this; - }, - listeners: [{ - eventName: BI.DynamicDateTrigger.EVENT_KEY_DOWN, - action: function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_STOP, - action: function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_TRIGGER_CLICK, - action: function () { - self.combo.toggle(); - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_FOCUS, - action: function () { - self.storeTriggerValue = self.trigger.getKey(); - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - self.fireEvent(BI.DynamicDateCombo.EVENT_FOCUS); - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_ERROR, - action: function () { - self.storeValue = { - year: date.getFullYear(), - month: date.getMonth() - }; - self.popup.setValue(); - self.fireEvent(BI.DynamicDateCombo.EVENT_ERROR); - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_VALID, - action: function () { - self.fireEvent(BI.DynamicDateCombo.EVENT_VALID); - } - }, { - eventName: BI.DynamicDateTrigger.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicDateCombo.EVENT_CHANGE); - } - }, { - eventName: BI.DynamicDateTrigger.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.DynamicDateCombo.EVENT_CONFIRM); - } - }] - }, - adjustLength: this.constants.comboAdjustHeight, - popup: { - el: { - type: "bi.dynamic_date_popup", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value, - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicDatePopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicDatePopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicDatePopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }] - }, - stopPropagation: false - }, - listeners: [{ - eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, - action: function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicDateCombo.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.DynamicDateCombo.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.DynamicDateCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicDateCombo.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DynamicDateCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.DynamicDateCombo.EVENT_VALID = "EVENT_VALID"; -BI.DynamicDateCombo.EVENT_ERROR = "EVENT_ERROR"; -BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW = "BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW"; - -BI.shortcut("bi.dynamic_date_combo", BI.DynamicDateCombo); - -BI.extend(BI.DynamicDateCombo, { - Static: 1, - Dynamic: 2 -});BI.DynamicDateParamItem = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-dynamic-date-param-item", - dateType: BI.DynamicDateCard.TYPE.YEAR, - value: 0, - offset: 0, - height: 24 - }, - - render: function () { - var self = this, o = this.options; - return { - type: "bi.htape", - items: [{ - el: { - type: "bi.sign_editor", - cls: "bi-border", - height: 22, - validationChecker: function (v) { - return BI.isNaturalNumber(v); - }, - value: o.value, - ref: function () { - self.editor = this; - }, - errorText: function (v) { - if(BI.isEmptyString(v)) { - return BI.i18nText("BI-Basic_Input_Can_Not_Null"); - } - return BI.i18nText("BI-Please_Input_Positive_Integer"); - }, - allowBlank: false, - listeners: [{ - eventName: BI.SignEditor.EVENT_CONFIRM, - action: function () { - self.fireEvent(BI.DynamicDateParamItem.EVENT_CHANGE); - } - }] - }, - width: 60 - }, { - el: { - type: "bi.label", - height: 24, - text: this._getText() - }, - width: 20 - }, { - type: "bi.text_value_combo", - height: 24, - items: [{ - text: BI.i18nText("BI-Basic_Front"), - value: 0 - }, { - text: BI.i18nText("BI-Basic_Behind"), - value: 1 - }], - ref: function () { - self.offsetCombo = this; - }, - value: o.offset, - listeners: [{ - eventName: BI.TextValueCombo.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicDateParamItem.EVENT_CHANGE); - } - }] - }] - }; - }, - - _getText: function () { - var text = ""; - switch (this.options.dateType) { - case BI.DynamicDateCard.TYPE.YEAR: - text = BI.i18nText("BI-Basic_Year"); - break; - case BI.DynamicDateCard.TYPE.QUARTER: - text = BI.i18nText("BI-Basic_Single_Quarter"); - break; - case BI.DynamicDateCard.TYPE.MONTH: - text = BI.i18nText("BI-Basic_Month"); - break; - case BI.DynamicDateCard.TYPE.WEEK: - text = BI.i18nText("BI-Basic_Week"); - break; - case BI.DynamicDateCard.TYPE.DAY: - default: - text = BI.i18nText("BI-Basic_Day"); - break; - } - return text; - }, - - setValue: function (v) { - v = v || {}; - v.value = v.value || 0; - v.offset = v.offset || 0; - this.editor.setValue(v.value); - this.offsetCombo.setValue(v.offset); - }, - - getValue: function () { - return { - dateType: this.options.dateType, - value: this.editor.getValue(), - offset: this.offsetCombo.getValue()[0] - }; - } - -}); -BI.DynamicDateParamItem.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_date_param_item", BI.DynamicDateParamItem);BI.DynamicDatePopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30 - }, - - props: { - baseCls: "bi-dynamic-date-popup", - width: 248, - height: 344 - }, - - _init: function () { - BI.DynamicDatePopup.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.DynamicDatePopup.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.DynamicDatePopup.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.DynamicDatePopup.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.date_calendar_popup", - min: self.options.min, - max: self.options.max, - listeners: [{ - eventName: BI.DateCalendarPopup.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicDatePopup.EVENT_CHANGE); - } - }], - ref: function () { - self.ymd = this; - } - }; - } - }, - 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._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.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.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 -});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);/** - * Created by roy on 15/9/14. - */ -BI.SearchEditor = BI.inherit(BI.Widget, { - _defaultConfig: function () { - var conf = BI.SearchEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: "bi-search-editor bi-border", - height: 24, - errorText: "", - watermark: BI.i18nText("BI-Basic_Search"), - validationChecker: BI.emptyFn, - quitChecker: BI.emptyFn - }); - }, - _init: function () { - this.options.height -= 2; - BI.SearchEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget({ - type: "bi.editor", - height: o.height, - watermark: o.watermark, - allowBlank: true, - errorText: o.errorText, - validationChecker: o.validationChecker, - quitChecker: o.quitChecker - }); - this.clear = BI.createWidget({ - type: "bi.icon_button", - stopEvent: true, - cls: "search-close-h-font" - }); - this.clear.on(BI.IconButton.EVENT_CHANGE, function () { - self.setValue(""); - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.STOPEDIT); - self.fireEvent(BI.SearchEditor.EVENT_CLEAR); - }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [ - { - el: { - type: "bi.center_adapt", - cls: "search-font", - items: [{ + }, { + 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.icon" - } - }] - }, - width: 25 - }, - { - el: self.editor - }, - { - el: this.clear, - width: 25 - } - ] - }); - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.editor.on(BI.Editor.EVENT_FOCUS, function () { - self.fireEvent(BI.SearchEditor.EVENT_FOCUS); - }); - this.editor.on(BI.Editor.EVENT_BLUR, function () { - self.fireEvent(BI.SearchEditor.EVENT_BLUR); - }); - this.editor.on(BI.Editor.EVENT_CLICK, function () { - self.fireEvent(BI.SearchEditor.EVENT_CLICK); - }); - this.editor.on(BI.Editor.EVENT_CHANGE, function () { - self._checkClear(); - self.fireEvent(BI.SearchEditor.EVENT_CHANGE); - }); - this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { - self.fireEvent(BI.SearchEditor.EVENT_KEY_DOWN, v); - }); - this.editor.on(BI.Editor.EVENT_SPACE, function () { - self.fireEvent(BI.SearchEditor.EVENT_SPACE); - }); - this.editor.on(BI.Editor.EVENT_BACKSPACE, function () { - self.fireEvent(BI.SearchEditor.EVENT_BACKSPACE); - }); - - - this.editor.on(BI.Editor.EVENT_VALID, function () { - self.fireEvent(BI.SearchEditor.EVENT_VALID); - }); - this.editor.on(BI.Editor.EVENT_ERROR, function () { - self.fireEvent(BI.SearchEditor.EVENT_ERROR); - }); - this.editor.on(BI.Editor.EVENT_ENTER, function () { - self.fireEvent(BI.SearchEditor.EVENT_ENTER); - }); - this.editor.on(BI.Editor.EVENT_RESTRICT, function () { - self.fireEvent(BI.SearchEditor.EVENT_RESTRICT); - }); - this.editor.on(BI.Editor.EVENT_EMPTY, function () { - self._checkClear(); - self.fireEvent(BI.SearchEditor.EVENT_EMPTY); - }); - this.editor.on(BI.Editor.EVENT_REMOVE, function () { - self.fireEvent(BI.SearchEditor.EVENT_REMOVE); - }); - this.editor.on(BI.Editor.EVENT_CONFIRM, function () { - self.fireEvent(BI.SearchEditor.EVENT_CONFIRM); - }); - this.editor.on(BI.Editor.EVENT_START, function () { - self.fireEvent(BI.SearchEditor.EVENT_START); - }); - this.editor.on(BI.Editor.EVENT_PAUSE, function () { - self.fireEvent(BI.SearchEditor.EVENT_PAUSE); - }); - this.editor.on(BI.Editor.EVENT_STOP, function () { - self.fireEvent(BI.SearchEditor.EVENT_STOP); - }); - - this.clear.invisible(); - }, - - _checkClear: function () { - if (!this.getValue()) { - this.clear.invisible(); - } else { - this.clear.visible(); - } - }, - - focus: function () { - this.editor.focus(); + 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; + } + }; }, - blur: function () { - this.editor.blur(); + mounted: function () { + this._checkDynamicValue(this.options.value); }, - getValue: function () { - if (this.isValid()) { - var res = this.editor.getValue().match(/[\S]+/g); - return BI.isNull(res) ? "" : res[res.length - 1]; + _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; } - }, - - getLastValidValue: function () { - return this.editor.getLastValidValue(); }, setValue: function (v) { - this.editor.setValue(v); - if (BI.isKey(v)) { - this.clear.visible(); - } + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); }, - - isEditing: function () { - return this.editor.isEditing(); + getValue: function () { + return this.storeValue; }, - - isValid: function () { - return this.editor.isValid(); + getKey: function () { + return this.trigger.getKey(); + }, + hidePopupView: function () { + this.combo.hideView(); } }); -BI.SearchEditor.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SearchEditor.EVENT_FOCUS = "EVENT_FOCUS"; -BI.SearchEditor.EVENT_BLUR = "EVENT_BLUR"; -BI.SearchEditor.EVENT_CLICK = "EVENT_CLICK"; -BI.SearchEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; -BI.SearchEditor.EVENT_SPACE = "EVENT_SPACE"; -BI.SearchEditor.EVENT_BACKSPACE = "EVENT_BACKSPACE"; -BI.SearchEditor.EVENT_CLEAR = "EVENT_CLEAR"; -BI.SearchEditor.EVENT_START = "EVENT_START"; -BI.SearchEditor.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SearchEditor.EVENT_STOP = "EVENT_STOP"; -BI.SearchEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.SearchEditor.EVENT_VALID = "EVENT_VALID"; -BI.SearchEditor.EVENT_ERROR = "EVENT_ERROR"; -BI.SearchEditor.EVENT_ENTER = "EVENT_ENTER"; -BI.SearchEditor.EVENT_RESTRICT = "EVENT_RESTRICT"; -BI.SearchEditor.EVENT_REMOVE = "EVENT_REMOVE"; -BI.SearchEditor.EVENT_EMPTY = "EVENT_EMPTY"; -BI.shortcut("bi.search_editor", BI.SearchEditor);/** - * 小号搜索框 - * Created by GUY on 2015/9/29. - * @class BI.SmallSearchEditor - * @extends BI.SearchEditor - */ -BI.SmallSearchEditor = BI.inherit(BI.SearchEditor, { - _defaultConfig: function () { - var conf = BI.SmallSearchEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-small-search-editor", - height: 24 - }); +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 }, - _init: function () { - BI.SmallSearchEditor.superclass._init.apply(this, arguments); - } -}); -BI.shortcut("bi.small_search_editor", BI.SmallSearchEditor);/** - * guy - * @class BI.TextEditor - * @extends BI.Single - */ -BI.TextEditor = BI.inherit(BI.Widget, { - _defaultConfig: function () { - var conf = BI.TextEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-text-editor bi-border", - hgap: 4, - vgap: 2, - lgap: 0, - rgap: 0, - tgap: 0, - bgap: 0, - validationChecker: BI.emptyFn, - quitChecker: BI.emptyFn, - allowBlank: false, - watermark: "", - errorText: "", - height: 24 - }); + props: { + baseCls: "bi-dynamic-date-time-popup", + width: 248, + height: 385 }, _init: function () { - BI.TextEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (BI.isNumber(o.height)) { - this.element.css({height: o.height - 2}); - } - if (BI.isNumber(o.width)) { - this.element.css({width: o.width - 2}); - } - this.editor = BI.createWidget({ - type: "bi.editor", - height: o.height - 2, - hgap: o.hgap, - vgap: o.vgap, - lgap: o.lgap, - rgap: o.rgap, - tgap: o.tgap, - bgap: o.bgap, - value: o.value, - title: o.title, - tipType: o.tipType, - validationChecker: o.validationChecker, - quitChecker: o.quitChecker, - allowBlank: o.allowBlank, - watermark: o.watermark, - errorText: o.errorText - }); - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.editor.on(BI.Editor.EVENT_FOCUS, function () { - self.fireEvent(BI.TextEditor.EVENT_FOCUS); - }); - this.editor.on(BI.Editor.EVENT_BLUR, function () { - self.fireEvent(BI.TextEditor.EVENT_BLUR); - }); - this.editor.on(BI.Editor.EVENT_CLICK, function () { - self.fireEvent(BI.TextEditor.EVENT_CLICK); - }); - this.editor.on(BI.Editor.EVENT_CHANGE, function () { - self.fireEvent(BI.TextEditor.EVENT_CHANGE); - }); - this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { - self.fireEvent(BI.TextEditor.EVENT_KEY_DOWN); - }); - this.editor.on(BI.Editor.EVENT_SPACE, function (v) { - self.fireEvent(BI.TextEditor.EVENT_SPACE); - }); - this.editor.on(BI.Editor.EVENT_BACKSPACE, function (v) { - self.fireEvent(BI.TextEditor.EVENT_BACKSPACE); - }); - - - this.editor.on(BI.Editor.EVENT_VALID, function () { - self.fireEvent(BI.TextEditor.EVENT_VALID); - }); - this.editor.on(BI.Editor.EVENT_CONFIRM, function () { - self.fireEvent(BI.TextEditor.EVENT_CONFIRM); - }); - this.editor.on(BI.Editor.EVENT_REMOVE, function (v) { - self.fireEvent(BI.TextEditor.EVENT_REMOVE); - }); - this.editor.on(BI.Editor.EVENT_START, function () { - self.fireEvent(BI.TextEditor.EVENT_START); - }); - this.editor.on(BI.Editor.EVENT_PAUSE, function () { - self.fireEvent(BI.TextEditor.EVENT_PAUSE); - }); - this.editor.on(BI.Editor.EVENT_STOP, function () { - self.fireEvent(BI.TextEditor.EVENT_STOP); - }); - this.editor.on(BI.Editor.EVENT_ERROR, function () { - self.fireEvent(BI.TextEditor.EVENT_ERROR, arguments); - }); - this.editor.on(BI.Editor.EVENT_ENTER, function () { - self.fireEvent(BI.TextEditor.EVENT_ENTER); - }); - this.editor.on(BI.Editor.EVENT_RESTRICT, function () { - self.fireEvent(BI.TextEditor.EVENT_RESTRICT); - }); - this.editor.on(BI.Editor.EVENT_EMPTY, function () { - self.fireEvent(BI.TextEditor.EVENT_EMPTY); - }); + BI.DynamicDateTimePopup.superclass._init.apply(this, arguments); + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicDateCombo.Static}; BI.createWidget({ - type: "bi.vertical", - scrolly: false, element: this, - items: [this.editor] + 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); }, - focus: function () { - this.editor.focus(); - }, - - blur: function () { - this.editor.blur(); - }, + _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 () { - setErrorText: function (text) { - this.editor.setErrorText(text); + } + }] + }, + 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; + } + } + }] + }; }, - getErrorText: function () { - return this.editor.getErrorText(); + _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); + } }, - isValid: function () { - return this.editor.isValid(); + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, setValue: function (v) { - this.editor.setValue(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 () { - return this.editor.getValue(); - } -}); -BI.TextEditor.EVENT_CHANGE = "EVENT_CHANGE"; -BI.TextEditor.EVENT_FOCUS = "EVENT_FOCUS"; -BI.TextEditor.EVENT_BLUR = "EVENT_BLUR"; -BI.TextEditor.EVENT_CLICK = "EVENT_CLICK"; -BI.TextEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; -BI.TextEditor.EVENT_SPACE = "EVENT_SPACE"; -BI.TextEditor.EVENT_BACKSPACE = "EVENT_BACKSPACE"; - -BI.TextEditor.EVENT_START = "EVENT_START"; -BI.TextEditor.EVENT_PAUSE = "EVENT_PAUSE"; -BI.TextEditor.EVENT_STOP = "EVENT_STOP"; -BI.TextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.TextEditor.EVENT_VALID = "EVENT_VALID"; -BI.TextEditor.EVENT_ERROR = "EVENT_ERROR"; -BI.TextEditor.EVENT_ENTER = "EVENT_ENTER"; -BI.TextEditor.EVENT_RESTRICT = "EVENT_RESTRICT"; -BI.TextEditor.EVENT_REMOVE = "EVENT_REMOVE"; -BI.TextEditor.EVENT_EMPTY = "EVENT_EMPTY"; - -BI.shortcut("bi.text_editor", BI.TextEditor);/** - * 小号搜索框 - * Created by GUY on 2015/9/29. - * @class BI.SmallTextEditor - * @extends BI.SearchEditor - */ -BI.SmallTextEditor = BI.inherit(BI.TextEditor, { - _defaultConfig: function () { - var conf = BI.SmallTextEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-small-text-editor", - height: 25 - }); - }, - - _init: function () { - BI.SmallTextEditor.superclass._init.apply(this, arguments); - } -}); -BI.shortcut("bi.small_text_editor", BI.SmallTextEditor);/** - * 文件管理控件组 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerButtonGroup - * @extends BI.Widget - */ -BI.FileManagerButtonGroup = BI.inherit(BI.Widget, { + 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, { - _defaultConfig: function () { - return BI.extend(BI.FileManagerButtonGroup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-button_group", - items: [] - }); + props: { + baseCls: "bi-date-time-select bi-border-top" }, - _init: function () { - BI.FileManagerButtonGroup.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.button_group = BI.createWidget({ - type: "bi.button_tree", - element: this, - chooseType: BI.Selection.Multi, - items: this._formatItems(o.items), - layouts: [{ - type: "bi.vertical" + 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 + }] }] - }); - this.button_group.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + }; }, - _formatItems: function (items) { - var self = this, o = this.options; - BI.each(items, function (i, item) { - if (item.children && item.children.length > 0) { - item.type = "bi.file_manager_folder_item"; - } else { - item.type = "bi.file_manager_file_item"; - } - }); - return items; + _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; }, - setValue: function (v) { - this.button_group.setValue(v); + _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; }, - getValue: function () { - return this.button_group.getValue(); + _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; }, - getNotSelectedValue: function () { - return this.button_group.getNotSelectedValue(); + getValue: function () { + return { + hour: BI.parseInt(this.hour.getValue()), + minute: BI.parseInt(this.minute.getValue()), + second: BI.parseInt(this.second.getValue()) + }; }, - getAllLeaves: function () { - return this.button_group.getAllLeaves(); - }, + setValue: function (v) { + v = this._assertValue(v); + this.hour.setValue(v.hour); + this.minute.setValue(v.minute); + this.second.setValue(v.second); + } - getAllButtons: function () { - return this.button_group.getAllButtons(); - }, +}); +BI.DynamicDateTimeSelect.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.shortcut("bi.dynamic_date_time_select", BI.DynamicDateTimeSelect); - getSelectedButtons: function () { - return this.button_group.getSelectedButtons(); +BI.extend(BI.DynamicDateTimeSelect, { + HOUR: 1, + MINUTE: 2 +});BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + yearLength: 4, + yearMonthLength: 7 }, - getNotSelectedButtons: function () { - return this.button_group.getNotSelectedButtons(); + props: { + extraCls: "bi-date-time-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, - populate: function (items) { - this.button_group.populate(this._formatItems(items)); - } -}); -BI.FileManagerButtonGroup.EVENT_CHANGE = "FileManagerButtonGroup.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_button_group", BI.FileManagerButtonGroup);/** - * 文件管理控件 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManager - * @extends BI.Widget - */ -BI.FileManager = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.FileManager.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager", - el: {}, - items: [] + _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"); + } }); - }, - - _init: function () { - BI.FileManager.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.tree = new BI.Tree(); - var items = BI.Tree.transformToTreeFormat(o.items); - this.tree.initTree(items); - this.selectedValues = []; - this.nav = BI.createWidget({ - type: "bi.file_manager_nav", - items: BI.deepClone(items) + this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_KEY_DOWN); }); - this.nav.on(BI.FileManagerNav.EVENT_CHANGE, function (value, obj) { - if (value == "-1") {// 根节点 - self.populate({children: self.tree.toJSON()}); - } else { - var node = self.tree.search(obj.attr("id")); - self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); - } - self.setValue(self.selectedValues); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_FOCUS); }); - this.list = BI.createWidget(o.el, { - type: "bi.file_manager_list", - items: items + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_STOP); }); - this.list.on(BI.Controller.EVENT_CHANGE, function (type, selected, obj) { - if (type === BI.Events.CHANGE) { - var node = self.tree.search(obj.attr("id")); - self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); - } else if (type === BI.Events.CLICK) { - var values = []; - if (obj instanceof BI.MultiSelectBar) { - var t = self.list.getValue(); - selected = t.type === BI.Selection.All; - values = BI.concat(t.assist, t.value); - } else { - values = obj.getAllLeaves(); - } - BI.each(values, function (i, v) { - if (selected === true) { - self.selectedValues.pushDistinct(v); - } else { - self.selectedValues.remove(v); + 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.setValue(self.selectedValues); + 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.absolute", + type: "bi.htape", element: this, items: [{ - el: this.list, - left: 0, - right: 0, - top: 0, - bottom: 10 + el: this.editor }, { - el: this.nav, - left: 40, - right: 100, - top: 0 + 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 || - setValue: function (value) { - this.selectedValues = value || []; - this.list.setValue(this.selectedValues); + 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; }, - - getValue: function () { - var obj = this.list.getValue(); - var res = obj.type === BI.Selection.All ? obj.assist : obj.value; - res.pushDistinctArray(this.selectedValues); - return res; + _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; + } + } }, - _populate: function (items) { - this.list.populate(items); + _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; }, - getSelectedValue: function () { - return this.nav.getValue()[0]; + _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; }, - getSelectedId: function () { - return this.nav.getId()[0]; + _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)); }, - populate: function (node) { - var clone = BI.deepClone(node); - this._populate(node.children); - this.nav.populate(clone); - } -}); -BI.FileManager.EVENT_CHANGE = "FileManager.EVENT_CHANGE"; -BI.shortcut("bi.file_manager", BI.FileManager);/** - * 文件管理控件 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerFileItem - * @extends BI.Single - */ -BI.FileManagerFileItem = BI.inherit(BI.Single, { + _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; - _defaultConfig: function () { - return BI.extend(BI.FileManagerFileItem.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-file-item bi-list-item bi-border-bottom", - height: 30 - }); + 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"); + } + } }, - _init: function () { - BI.FileManagerFileItem.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.checked = BI.createWidget({ - type: "bi.multi_select_bar", - text: "", - width: 36, - height: o.height - }); - this.checked.on(BI.Controller.EVENT_CHANGE, function () { - arguments[2] = self; - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - items: [{ - el: this.checked, - width: 36 - }, { - el: { - type: "bi.icon_button", - cls: "create-by-me-file-font" - }, - width: 20 - }, { - el: { - type: "bi.label", - textAlign: "left", - height: o.height, - text: o.text, - value: o.value + 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); } - }] - }); - }, - - getAllLeaves: function () { - return [this.options.value]; + break; + } }, - isSelected: function () { - return this.checked.isSelected(); + getKey: function () { + return this.editor.getValue(); }, - - setSelected: function (v) { - this.checked.setSelected(v); + getValue: function () { + return this.storeValue; } + }); -BI.FileManagerFileItem.EVENT_CHANGE = "FileManagerFileItem.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_file_item", BI.FileManagerFileItem);/** - * 文件管理控件 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerFolderItem - * @extends BI.Single - */ -BI.FileManagerFolderItem = BI.inherit(BI.Single, { +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, { _defaultConfig: function () { - return BI.extend(BI.FileManagerFolderItem.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-folder-item bi-list-item bi-border-bottom", - height: 30 + var conf = BI.SearchEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: "bi-search-editor bi-border", + height: 24, + errorText: "", + watermark: BI.i18nText("BI-Basic_Search"), + validationChecker: BI.emptyFn, + quitChecker: BI.emptyFn }); }, - _init: function () { - BI.FileManagerFolderItem.superclass._init.apply(this, arguments); + this.options.height -= 2; + BI.SearchEditor.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.checked = BI.createWidget({ - type: "bi.multi_select_bar", - text: "", - width: 36, - height: o.height - }); - this.checked.on(BI.Controller.EVENT_CHANGE, function () { - arguments[2] = self; - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.button = BI.createWidget({ - type: "bi.text_button", - textAlign: "left", + this.editor = BI.createWidget({ + type: "bi.editor", height: o.height, - text: o.text, - value: o.value + watermark: o.watermark, + allowBlank: true, + errorText: o.errorText, + validationChecker: o.validationChecker, + quitChecker: o.quitChecker }); - this.button.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CHANGE, o.value, self); + this.clear = BI.createWidget({ + type: "bi.icon_button", + stopEvent: true, + cls: "search-close-h-font" + }); + this.clear.on(BI.IconButton.EVENT_CHANGE, function () { + self.setValue(""); + self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.STOPEDIT); + self.fireEvent(BI.SearchEditor.EVENT_CLEAR); }); - - this.tree = new BI.Tree(); - this.tree.initTree([{ - id: o.id, - children: o.children - }]); - this.selectValue = []; - BI.createWidget({ - type: "bi.htape", element: this, - items: [{ - el: this.checked, - width: 36 - }, { - el: { - type: "bi.icon_button", - cls: "create-by-me-folder-font" + type: "bi.htape", + items: [ + { + el: { + type: "bi.center_adapt", + cls: "search-font", + items: [{ + el: { + type: "bi.icon" + } + }] + }, + width: 25 }, - width: 20 - }, { - el: this.button - }] + { + el: self.editor + }, + { + el: this.clear, + width: 25 + } + ] + }); + this.editor.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - }, - - setAllSelected: function (v) { - this.checked.setSelected(v); - this.selectValue = []; - }, - - setHalfSelected: function (v) { - this.checked.setHalfSelected(v); - if(!v) { - this.selectValue = []; - } - }, - setValue: function (v) { - var self = this, o = this.options; - var isHalf = false; - var selectValue = []; - this.tree.traverse(function (node) { - if (node.isLeaf()) { - if (BI.contains(v, node.get("data").value)) { - selectValue.push(node.get("data").value); - } else { - isHalf = true; - } - } + this.editor.on(BI.Editor.EVENT_FOCUS, function () { + self.fireEvent(BI.SearchEditor.EVENT_FOCUS); + }); + this.editor.on(BI.Editor.EVENT_BLUR, function () { + self.fireEvent(BI.SearchEditor.EVENT_BLUR); + }); + this.editor.on(BI.Editor.EVENT_CLICK, function () { + self.fireEvent(BI.SearchEditor.EVENT_CLICK); + }); + this.editor.on(BI.Editor.EVENT_CHANGE, function () { + self._checkClear(); + self.fireEvent(BI.SearchEditor.EVENT_CHANGE); + }); + this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { + self.fireEvent(BI.SearchEditor.EVENT_KEY_DOWN, v); + }); + this.editor.on(BI.Editor.EVENT_SPACE, function () { + self.fireEvent(BI.SearchEditor.EVENT_SPACE); + }); + this.editor.on(BI.Editor.EVENT_BACKSPACE, function () { + self.fireEvent(BI.SearchEditor.EVENT_BACKSPACE); }); - this.setAllSelected(selectValue.length > 0 && !isHalf); - this.setHalfSelected(selectValue.length > 0 && isHalf); - if (this.checked.isHalfSelected()) { - this.selectValue = selectValue; - } - }, - getAllButtons: function () { - return [this]; - }, - getAllLeaves: function () { - var o = this.options; - var res = []; - this.tree.traverse(function (node) { - if (node.isLeaf()) { - res.push(node.get("data").value); - } + this.editor.on(BI.Editor.EVENT_VALID, function () { + self.fireEvent(BI.SearchEditor.EVENT_VALID); }); - return res; - }, - - getNotSelectedValue: function () { - var self = this, o = this.options; - var res = []; - var isAllSelected = this.checked.isSelected(); - if (isAllSelected === true) { - return res; - } - var isHalfSelected = this.checked.isHalfSelected(); - this.tree.traverse(function (node) { - if (node.isLeaf()) { - var v = node.get("data").value; - if (isHalfSelected === true) { - if (!BI.contains(self.selectValue, node.get("data").value)) { - res.push(v); - } - } else { - res.push(v); - } - } + this.editor.on(BI.Editor.EVENT_ERROR, function () { + self.fireEvent(BI.SearchEditor.EVENT_ERROR); }); - return res; + this.editor.on(BI.Editor.EVENT_ENTER, function () { + self.fireEvent(BI.SearchEditor.EVENT_ENTER); + }); + this.editor.on(BI.Editor.EVENT_RESTRICT, function () { + self.fireEvent(BI.SearchEditor.EVENT_RESTRICT); + }); + this.editor.on(BI.Editor.EVENT_EMPTY, function () { + self._checkClear(); + self.fireEvent(BI.SearchEditor.EVENT_EMPTY); + }); + this.editor.on(BI.Editor.EVENT_REMOVE, function () { + self.fireEvent(BI.SearchEditor.EVENT_REMOVE); + }); + this.editor.on(BI.Editor.EVENT_CONFIRM, function () { + self.fireEvent(BI.SearchEditor.EVENT_CONFIRM); + }); + this.editor.on(BI.Editor.EVENT_START, function () { + self.fireEvent(BI.SearchEditor.EVENT_START); + }); + this.editor.on(BI.Editor.EVENT_PAUSE, function () { + self.fireEvent(BI.SearchEditor.EVENT_PAUSE); + }); + this.editor.on(BI.Editor.EVENT_STOP, function () { + self.fireEvent(BI.SearchEditor.EVENT_STOP); + }); + + this.clear.invisible(); + }, + + _checkClear: function () { + if (!this.getValue()) { + this.clear.invisible(); + } else { + this.clear.visible(); + } + }, + + focus: function () { + this.editor.focus(); + }, + + blur: function () { + this.editor.blur(); }, getValue: function () { - var res = []; - if (this.checked.isSelected()) { - this.tree.traverse(function (node) { - if (node.isLeaf()) { - res.push(node.get("data").value); - } - }); - return res; - } - if (this.checked.isHalfSelected()) { - return this.selectValue; + if (this.isValid()) { + var res = this.editor.getValue().match(/[\S]+/g); + return BI.isNull(res) ? "" : res[res.length - 1]; } - return []; - } -}); -BI.FileManagerFolderItem.EVENT_CHANGE = "FileManagerFolderItem.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_folder_item", BI.FileManagerFolderItem);/** - * 文件管理控件列表 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerList - * @extends BI.Widget - */ -BI.FileManagerList = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.FileManagerList.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-list", - el: {}, - items: [] - }); }, - _init: function () { - BI.FileManagerList.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.list = BI.createWidget({ - type: "bi.select_list", - element: this, - items: o.items, - toolbar: { - type: "bi.multi_select_bar", - height: 40, - text: "" - }, - el: { - type: "bi.list_pane", - el: BI.isWidget(o.el) ? o.el : BI.extend({ - type: "bi.file_manager_button_group" - }, o.el) - } - }); - this.list.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + getLastValidValue: function () { + return this.editor.getLastValidValue(); }, setValue: function (v) { - this.list.setValue({ - value: v - }); + this.editor.setValue(v); + if (BI.isKey(v)) { + this.clear.visible(); + } }, - - getValue: function () { - return this.list.getValue(); + + isEditing: function () { + return this.editor.isEditing(); }, - populate: function (items) { - this.list.populate(items); - this.list.setToolBarVisible(true); + isValid: function () { + return this.editor.isValid(); } }); -BI.FileManagerList.EVENT_CHANGE = "FileManagerList.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_list", BI.FileManagerList);/** - * 文件管理导航按钮 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerNavButton - * @extends BI.Widget - */ -BI.FileManagerNavButton = BI.inherit(BI.Widget, { +BI.SearchEditor.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SearchEditor.EVENT_FOCUS = "EVENT_FOCUS"; +BI.SearchEditor.EVENT_BLUR = "EVENT_BLUR"; +BI.SearchEditor.EVENT_CLICK = "EVENT_CLICK"; +BI.SearchEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.SearchEditor.EVENT_SPACE = "EVENT_SPACE"; +BI.SearchEditor.EVENT_BACKSPACE = "EVENT_BACKSPACE"; +BI.SearchEditor.EVENT_CLEAR = "EVENT_CLEAR"; - _const: { - normal_color: "#ffffff", - select_color: "#eff1f4" +BI.SearchEditor.EVENT_START = "EVENT_START"; +BI.SearchEditor.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SearchEditor.EVENT_STOP = "EVENT_STOP"; +BI.SearchEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.SearchEditor.EVENT_VALID = "EVENT_VALID"; +BI.SearchEditor.EVENT_ERROR = "EVENT_ERROR"; +BI.SearchEditor.EVENT_ENTER = "EVENT_ENTER"; +BI.SearchEditor.EVENT_RESTRICT = "EVENT_RESTRICT"; +BI.SearchEditor.EVENT_REMOVE = "EVENT_REMOVE"; +BI.SearchEditor.EVENT_EMPTY = "EVENT_EMPTY"; +BI.shortcut("bi.search_editor", BI.SearchEditor);/** + * 小号搜索框 + * Created by GUY on 2015/9/29. + * @class BI.SmallSearchEditor + * @extends BI.SearchEditor + */ +BI.SmallSearchEditor = BI.inherit(BI.SearchEditor, { + _defaultConfig: function () { + var conf = BI.SmallSearchEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-small-search-editor", + height: 24 + }); }, + + _init: function () { + BI.SmallSearchEditor.superclass._init.apply(this, arguments); + } +}); +BI.shortcut("bi.small_search_editor", BI.SmallSearchEditor);/** + * guy + * @class BI.TextEditor + * @extends BI.Single + */ +BI.TextEditor = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.FileManagerNavButton.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-nav-button", - selected: false, - height: 40 + var conf = BI.TextEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-text-editor bi-border", + hgap: 4, + vgap: 2, + lgap: 0, + rgap: 0, + tgap: 0, + bgap: 0, + validationChecker: BI.emptyFn, + quitChecker: BI.emptyFn, + allowBlank: false, + watermark: "", + errorText: "", + height: 24 }); }, _init: function () { - BI.FileManagerNavButton.superclass._init.apply(this, arguments); - var self = this, o = this.options, c = this._const; - this.button = BI.createWidget({ - type: "bi.text_button", - cls: "file-manager-nav-button-text bi-card", - once: true, - selected: o.selected, - text: o.text, - title: o.text, + BI.TextEditor.superclass._init.apply(this, arguments); + var self = this, o = this.options; + if (BI.isNumber(o.height)) { + this.element.css({height: o.height - 2}); + } + if (BI.isNumber(o.width)) { + this.element.css({width: o.width - 2}); + } + this.editor = BI.createWidget({ + type: "bi.editor", + height: o.height - 2, + hgap: o.hgap, + vgap: o.vgap, + lgap: o.lgap, + rgap: o.rgap, + tgap: o.tgap, + bgap: o.bgap, value: o.value, - height: o.height, - lgap: 20, - rgap: 10 + title: o.title, + tipType: o.tipType, + validationChecker: o.validationChecker, + quitChecker: o.quitChecker, + allowBlank: o.allowBlank, + watermark: o.watermark, + errorText: o.errorText }); - this.button.on(BI.Controller.EVENT_CHANGE, function () { - arguments[2] = self; + this.editor.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - var svg = BI.createWidget({ - type: "bi.svg", - cls: "file-manager-nav-button-triangle", - width: 15, - height: o.height + + this.editor.on(BI.Editor.EVENT_FOCUS, function () { + self.fireEvent(BI.TextEditor.EVENT_FOCUS); }); - var path = svg.path("M0,0L15,20L0,40").attr({ - stroke: c.select_color, - fill: o.selected ? c.select_color : c.normal_color + this.editor.on(BI.Editor.EVENT_BLUR, function () { + self.fireEvent(BI.TextEditor.EVENT_BLUR); + }); + this.editor.on(BI.Editor.EVENT_CLICK, function () { + self.fireEvent(BI.TextEditor.EVENT_CLICK); + }); + this.editor.on(BI.Editor.EVENT_CHANGE, function () { + self.fireEvent(BI.TextEditor.EVENT_CHANGE); + }); + this.editor.on(BI.Editor.EVENT_KEY_DOWN, function (v) { + self.fireEvent(BI.TextEditor.EVENT_KEY_DOWN); + }); + this.editor.on(BI.Editor.EVENT_SPACE, function (v) { + self.fireEvent(BI.TextEditor.EVENT_SPACE); + }); + this.editor.on(BI.Editor.EVENT_BACKSPACE, function (v) { + self.fireEvent(BI.TextEditor.EVENT_BACKSPACE); + }); + + + this.editor.on(BI.Editor.EVENT_VALID, function () { + self.fireEvent(BI.TextEditor.EVENT_VALID); + }); + this.editor.on(BI.Editor.EVENT_CONFIRM, function () { + self.fireEvent(BI.TextEditor.EVENT_CONFIRM); + }); + this.editor.on(BI.Editor.EVENT_REMOVE, function (v) { + self.fireEvent(BI.TextEditor.EVENT_REMOVE); + }); + this.editor.on(BI.Editor.EVENT_START, function () { + self.fireEvent(BI.TextEditor.EVENT_START); + }); + this.editor.on(BI.Editor.EVENT_PAUSE, function () { + self.fireEvent(BI.TextEditor.EVENT_PAUSE); + }); + this.editor.on(BI.Editor.EVENT_STOP, function () { + self.fireEvent(BI.TextEditor.EVENT_STOP); + }); + this.editor.on(BI.Editor.EVENT_ERROR, function () { + self.fireEvent(BI.TextEditor.EVENT_ERROR, arguments); + }); + this.editor.on(BI.Editor.EVENT_ENTER, function () { + self.fireEvent(BI.TextEditor.EVENT_ENTER); }); - this.button.on(BI.TextButton.EVENT_CHANGE, function () { - if (this.isSelected()) { - path.attr("fill", c.select_color); - } else { - path.attr("fill", c.normal_color); - } + this.editor.on(BI.Editor.EVENT_RESTRICT, function () { + self.fireEvent(BI.TextEditor.EVENT_RESTRICT); }); - BI.createWidget({ - type: "bi.default", - element: this, - items: [this.button] + this.editor.on(BI.Editor.EVENT_EMPTY, function () { + self.fireEvent(BI.TextEditor.EVENT_EMPTY); }); BI.createWidget({ - type: "bi.absolute", + type: "bi.vertical", + scrolly: false, element: this, - items: [{ - el: svg, - right: -15, - top: 0, - bottom: 0 - }] + items: [this.editor] }); }, - isSelected: function () { - return this.button.isSelected(); - }, - - setValue: function (v) { - this.button.setValue(v); + focus: function () { + this.editor.focus(); }, - getValue: function () { - return this.button.getValue(); + blur: function () { + this.editor.blur(); }, - populate: function (items) { - - } -}); -BI.FileManagerNavButton.EVENT_CHANGE = "FileManagerNavButton.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_nav_button", BI.FileManagerNavButton);/** - * 文件管理导航 - * - * Created by GUY on 2015/12/11. - * @class BI.FileManagerNav - * @extends BI.Widget - */ -BI.FileManagerNav = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.FileManagerNav.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-nav bi-border-left", - height: 40, - items: [] - }); + setErrorText: function (text) { + this.editor.setErrorText(text); }, - _init: function () { - BI.FileManagerNav.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.tree = new BI.Tree(); - this.refreshTreeData(o.items); - this.tree.getRoot().set("data", { - text: BI.i18nText("BI-Created_By_Me"), - value: BI.FileManagerNav.ROOT_CREATE_BY_ME, - id: BI.FileManagerNav.ROOT_CREATE_BY_ME - }); - this.button_group = BI.createWidget({ - type: "bi.button_group", - element: this, - items: [{ - type: "bi.file_manager_nav_button", - text: BI.i18nText("BI-Created_By_Me"), - selected: true, - id: BI.FileManagerNav.ROOT_CREATE_BY_ME, - value: BI.FileManagerNav.ROOT_CREATE_BY_ME - }], - layouts: [{ - type: "bi.horizontal" - }] - }); - this.button_group.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.button_group.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) { - self.fireEvent(BI.FileManagerNav.EVENT_CHANGE, arguments); - }); + getErrorText: function () { + return this.editor.getErrorText(); }, - _getAllParents: function (id) { - var node, res = []; - if (!id) { - node = this.tree.getRoot(); - } else { - node = this.tree.search(id); - } - while (node.parent) { - res.push(node); - node = node.parent; - } - res.push(node); - return res.reverse(); + isValid: function () { + return this.editor.isValid(); }, - _formatNodes: function (nodes) { - var res = []; - BI.each(nodes, function (i, node) { - res.push(BI.extend({ - type: "bi.file_manager_nav_button", - id: node.id - }, node.get("data"))); - }); - BI.last(res).selected = true; - return res; + setValue: function (v) { + this.editor.setValue(v); }, getValue: function () { - return this.button_group.getValue(); - }, - - getId: function () { - var ids = []; - BI.each(this.button_group.getSelectedButtons(), function (i, btn) { - ids.push(btn.attr("id")); - }); - return ids; - }, - - refreshTreeData: function (items) { - this.tree.initTree(BI.Tree.transformToTreeFormat(items)); - this.tree.getRoot().set("data", { - text: BI.i18nText("BI-Created_By_Me"), - value: BI.FileManagerNav.ROOT_CREATE_BY_ME, - id: BI.FileManagerNav.ROOT_CREATE_BY_ME - }); - }, - - populate: function (node) { - var parents = BI.isNull(node) ? [this.tree.getRoot()] : this._getAllParents(node.id); - this.button_group.populate(this._formatNodes(parents)); + return this.editor.getValue(); } }); -BI.extend(BI.FileManagerNav, { - ROOT_CREATE_BY_ME: "-1" -}); -BI.FileManagerNav.EVENT_CHANGE = "FileManagerNav.EVENT_CHANGE"; -BI.shortcut("bi.file_manager_nav", BI.FileManagerNav);/** - * Created by zcf on 2016/9/26. - */ -BI.IntervalSlider = BI.inherit(BI.Widget, { - _constant: { - EDITOR_WIDTH: 58, - EDITOR_R_GAP: 60, - EDITOR_HEIGHT: 30, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 - }, - - _defaultConfig: function () { - return BI.extend(BI.IntervalSlider.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-interval-slider bi-slider-track", - digit: false, - unit: "" - }); - }, - - _init: function () { - BI.IntervalSlider.superclass._init.apply(this, arguments); - - var self = this; - var c = this._constant; - this.enable = false; - this.valueOne = ""; - this.valueTwo = ""; - this.calculation = new BI.AccurateCalculationModel(); - - // this.backgroundTrack = BI.createWidget({ - // type: "bi.layout", - // cls: "background-track", - // height: c.TRACK_HEIGHT - // }); - this.grayTrack = BI.createWidget({ - type: "bi.layout", - cls: "gray-track", - height: 6 - }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 - }); - this.track = this._createTrackWrapper(); +BI.TextEditor.EVENT_CHANGE = "EVENT_CHANGE"; +BI.TextEditor.EVENT_FOCUS = "EVENT_FOCUS"; +BI.TextEditor.EVENT_BLUR = "EVENT_BLUR"; +BI.TextEditor.EVENT_CLICK = "EVENT_CLICK"; +BI.TextEditor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.TextEditor.EVENT_SPACE = "EVENT_SPACE"; +BI.TextEditor.EVENT_BACKSPACE = "EVENT_BACKSPACE"; - this.labelOne = BI.createWidget({ - type: "bi.sign_text_editor", - cls: "slider-editor-button", - text: this.options.unit, - errorText: "", - allowBlank: false, - width: c.EDITOR_WIDTH, - validationChecker: function (v) { - return self._checkValidation(v); - } - }); - this.labelOne.element.hover(function () { - self.labelOne.element.removeClass("bi-border").addClass("bi-border"); - }, function () { - self.labelOne.element.removeClass("bi-border"); - }); - this.labelOne.on(BI.Editor.EVENT_CONFIRM, function () { - var v = BI.parseFloat(this.getValue()); - self.valueOne = v; - var percent = self._getPercentByValue(v); - var significantPercent = BI.parseFloat(percent.toFixed(1));// 分成1000份 - self._setLabelOnePosition(significantPercent); - self._setSliderOnePosition(significantPercent); - self._setBlueTrack(); - self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); - }); +BI.TextEditor.EVENT_START = "EVENT_START"; +BI.TextEditor.EVENT_PAUSE = "EVENT_PAUSE"; +BI.TextEditor.EVENT_STOP = "EVENT_STOP"; +BI.TextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.TextEditor.EVENT_VALID = "EVENT_VALID"; +BI.TextEditor.EVENT_ERROR = "EVENT_ERROR"; +BI.TextEditor.EVENT_ENTER = "EVENT_ENTER"; +BI.TextEditor.EVENT_RESTRICT = "EVENT_RESTRICT"; +BI.TextEditor.EVENT_REMOVE = "EVENT_REMOVE"; +BI.TextEditor.EVENT_EMPTY = "EVENT_EMPTY"; - this.labelTwo = BI.createWidget({ - type: "bi.sign_text_editor", - cls: "slider-editor-button", - errorText: "", - text: this.options.unit, - allowBlank: false, - width: c.EDITOR_WIDTH, - validationChecker: function (v) { - return self._checkValidation(v); - } - }); - this.labelTwo.element.hover(function () { - self.labelTwo.element.removeClass("bi-border").addClass("bi-border"); - }, function () { - self.labelTwo.element.removeClass("bi-border"); +BI.shortcut("bi.text_editor", BI.TextEditor);/** + * 小号搜索框 + * Created by GUY on 2015/9/29. + * @class BI.SmallTextEditor + * @extends BI.SearchEditor + */ +BI.SmallTextEditor = BI.inherit(BI.TextEditor, { + _defaultConfig: function () { + var conf = BI.SmallTextEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-small-text-editor", + height: 25 }); - this.labelTwo.on(BI.Editor.EVENT_CONFIRM, function () { - var v = BI.parseFloat(this.getValue()); - self.valueTwo = v; - var percent = self._getPercentByValue(v); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setLabelTwoPosition(significantPercent); - self._setSliderTwoPosition(significantPercent); - self._setBlueTrack(); - self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); + }, + + _init: function () { + BI.SmallTextEditor.superclass._init.apply(this, arguments); + } +}); +BI.shortcut("bi.small_text_editor", BI.SmallTextEditor);/** + * 文件管理控件组 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerButtonGroup + * @extends BI.Widget + */ +BI.FileManagerButtonGroup = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.FileManagerButtonGroup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-button_group", + items: [] }); + }, - this.sliderOne = BI.createWidget({ - type: "bi.single_slider_button" + _init: function () { + BI.FileManagerButtonGroup.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.button_group = BI.createWidget({ + type: "bi.button_tree", + element: this, + chooseType: BI.Selection.Multi, + items: this._formatItems(o.items), + layouts: [{ + type: "bi.vertical" + }] }); - this.sliderTwo = BI.createWidget({ - type: "bi.single_slider_button" + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this._draggable(this.sliderOne, true); - this._draggable(this.sliderTwo, false); - this._setVisible(false); + }, - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.track, - width: "100%", - height: c.TRACK_HEIGHT - }] - }], - hgap: 7, - height: c.TRACK_HEIGHT - }, - top: 23, - left: 0, - width: "100%" - }, - this._createLabelWrapper(), - this._createSliderWrapper() - ] + _formatItems: function (items) { + var self = this, o = this.options; + BI.each(items, function (i, item) { + if (item.children && item.children.length > 0) { + item.type = "bi.file_manager_folder_item"; + } else { + item.type = "bi.file_manager_file_item"; + } }); + return items; }, - _rePosBySizeAfterMove: function (size, isLeft) { - var o = this.options; - var percent = size * 100 / (this._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - var v = this._getValueByPercent(significantPercent); - v = this._assertValue(v); - v = o.digit === false ? v : v.toFixed(o.digit); - if(isLeft) { - this._setLabelOnePosition(significantPercent); - this._setSliderOnePosition(significantPercent); - this.labelOne.setValue(v); - this.valueOne = v; - }else{ - this._setLabelTwoPosition(significantPercent); - this._setSliderTwoPosition(significantPercent); - this.labelTwo.setValue(v); - this.valueTwo = v; - } - this._setBlueTrack(); + setValue: function (v) { + this.button_group.setValue(v); }, - _rePosBySizeAfterStop: function (size, isLeft) { - var percent = size * 100 / (this._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - isLeft ? this._setSliderOnePosition(significantPercent) : this._setSliderTwoPosition(significantPercent); + getValue: function () { + return this.button_group.getValue(); }, - _draggable: function (widget, isLeft) { - var self = this, o = this.options; - var startDrag = false; - var size = 0, offset = 0, defaultSize = 0; - var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { - if (mouseMoveTracker.isDragging()) { - startDrag = true; - offset += deltaX; - size = optimizeSize(defaultSize + offset); - widget.element.addClass("dragging"); - self._rePosBySizeAfterMove(size, isLeft); - } - }, function () { - if (startDrag === true) { - size = optimizeSize(size); - self._rePosBySizeAfterStop(size, isLeft); - size = 0; - offset = 0; - defaultSize = size; - startDrag = false; - } - widget.element.removeClass("dragging"); - mouseMoveTracker.releaseMouseMoves(); - self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); - }, window); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; - } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); - }); + getNotSelectedValue: function () { + return this.button_group.getNotSelectedValue(); + }, - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); - } + getAllLeaves: function () { + return this.button_group.getAllLeaves(); }, - _createLabelWrapper: function () { - var c = this._constant; - return { - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.labelOne, - top: 0, - left: "0%" - }] - }, { - type: "bi.absolute", - items: [{ - el: this.labelTwo, - top: 0, - left: "100%" - }] - }], - rgap: c.EDITOR_R_GAP, - height: 70 - }, - top: 0, - left: 0, - width: "100%" - }; + getAllButtons: function () { + return this.button_group.getAllButtons(); }, - _createSliderWrapper: function () { - var c = this._constant; - return { - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.sliderOne, - top: 0, - left: "0%" - }] - }, { - type: "bi.absolute", - items: [{ - el: this.sliderTwo, - top: 0, - left: "100%" - }] - }], - hgap: c.SLIDER_WIDTH_HALF, - height: c.SLIDER_HEIGHT - }, - top: 20, - left: 0, - width: "100%" - }; + getSelectedButtons: function () { + return this.button_group.getSelectedButtons(); + }, + + getNotSelectedButtons: function () { + return this.button_group.getNotSelectedButtons(); + }, + + populate: function (items) { + this.button_group.populate(this._formatItems(items)); + } +}); +BI.FileManagerButtonGroup.EVENT_CHANGE = "FileManagerButtonGroup.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_button_group", BI.FileManagerButtonGroup);/** + * 文件管理控件 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManager + * @extends BI.Widget + */ +BI.FileManager = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.FileManager.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager", + el: {}, + items: [] + }); }, - _createTrackWrapper: function () { - return BI.createWidget({ + _init: function () { + BI.FileManager.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.tree = new BI.Tree(); + var items = BI.Tree.transformToTreeFormat(o.items); + this.tree.initTree(items); + this.selectedValues = []; + this.nav = BI.createWidget({ + type: "bi.file_manager_nav", + items: BI.deepClone(items) + }); + this.nav.on(BI.FileManagerNav.EVENT_CHANGE, function (value, obj) { + if (value == "-1") {// 根节点 + self.populate({children: self.tree.toJSON()}); + } else { + var node = self.tree.search(obj.attr("id")); + self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); + } + self.setValue(self.selectedValues); + }); + this.list = BI.createWidget(o.el, { + type: "bi.file_manager_list", + items: items + }); + this.list.on(BI.Controller.EVENT_CHANGE, function (type, selected, obj) { + if (type === BI.Events.CHANGE) { + var node = self.tree.search(obj.attr("id")); + self.populate(BI.extend({id: node.id}, node.get("data"), {children: self.tree.toJSON(node)})); + } else if (type === BI.Events.CLICK) { + var values = []; + if (obj instanceof BI.MultiSelectBar) { + var t = self.list.getValue(); + selected = t.type === BI.Selection.All; + values = BI.concat(t.assist, t.value); + } else { + values = obj.getAllLeaves(); + } + BI.each(values, function (i, v) { + if (selected === true) { + self.selectedValues.pushDistinct(v); + } else { + self.selectedValues.remove(v); + } + }); + } + self.setValue(self.selectedValues); + }); + + BI.createWidget({ type: "bi.absolute", + element: this, items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.grayTrack, - top: 0, - left: 0, - width: "100%" - }, { - el: this.blueTrack, - top: 0, - left: 0, - width: "0%" - }] - }], - hgap: 8, - height: 8 - }, - top: 8, + el: this.list, left: 0, - width: "100%" + right: 0, + top: 0, + bottom: 10 + }, { + el: this.nav, + left: 40, + right: 100, + top: 0 }] }); }, - _checkValidation: function (v) { - var o = this.options; - var valid = false; - // 像90.这样的既不属于整数又不属于小数,是不合法的值 - var dotText = (v + "").split(".")[1]; - if (BI.isEmptyString(dotText)) { - }else{ - if (BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)) { - if(o.digit === false) { - valid = true; - }else{ - dotText = dotText || ""; - valid = (dotText.length === o.digit); - } - } - } - return valid; + setValue: function (value) { + this.selectedValues = value || []; + this.list.setValue(this.selectedValues); }, - _checkOverlap: function () { - var labelOneLeft = this.labelOne.element[0].offsetLeft; - var labelTwoLeft = this.labelTwo.element[0].offsetLeft; - if (labelOneLeft <= labelTwoLeft) { - if ((labelTwoLeft - labelOneLeft) < 90) { - this.labelTwo.element.css({top: 40}); - } else { - this.labelTwo.element.css({top: 0}); - } - } else { - if ((labelOneLeft - labelTwoLeft) < 90) { - this.labelTwo.element.css({top: 40}); - } else { - this.labelTwo.element.css({top: 0}); - } - } + getValue: function () { + var obj = this.list.getValue(); + var res = obj.type === BI.Selection.All ? obj.assist : obj.value; + res.pushDistinctArray(this.selectedValues); + return res; }, - _setLabelOnePosition: function (percent) { - this.labelOne.element.css({left: percent + "%"}); - this._checkOverlap(); + _populate: function (items) { + this.list.populate(items); }, - _setLabelTwoPosition: function (percent) { - this.labelTwo.element.css({left: percent + "%"}); - this._checkOverlap(); + getSelectedValue: function () { + return this.nav.getValue()[0]; }, - _setSliderOnePosition: function (percent) { - this.sliderOne.element.css({left: percent + "%"}); + getSelectedId: function () { + return this.nav.getId()[0]; }, - _setSliderTwoPosition: function (percent) { - this.sliderTwo.element.css({left: percent + "%"}); - }, + populate: function (node) { + var clone = BI.deepClone(node); + this._populate(node.children); + this.nav.populate(clone); + } +}); +BI.FileManager.EVENT_CHANGE = "FileManager.EVENT_CHANGE"; +BI.shortcut("bi.file_manager", BI.FileManager);/** + * 文件管理控件 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerFileItem + * @extends BI.Single + */ +BI.FileManagerFileItem = BI.inherit(BI.Single, { - _setBlueTrackLeft: function (percent) { - this.blueTrack.element.css({left: percent + "%"}); + _defaultConfig: function () { + return BI.extend(BI.FileManagerFileItem.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-file-item bi-list-item bi-border-bottom", + height: 30 + }); }, - _setBlueTrackWidth: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); + _init: function () { + BI.FileManagerFileItem.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.checked = BI.createWidget({ + type: "bi.multi_select_bar", + text: "", + width: 36, + height: o.height + }); + this.checked.on(BI.Controller.EVENT_CHANGE, function () { + arguments[2] = self; + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + BI.createWidget({ + type: "bi.htape", + element: this, + items: [{ + el: this.checked, + width: 36 + }, { + el: { + type: "bi.icon_button", + cls: "create-by-me-file-font" + }, + width: 20 + }, { + el: { + type: "bi.label", + textAlign: "left", + height: o.height, + text: o.text, + value: o.value + } + }] + }); }, - _setBlueTrack: function () { - var percentOne = this._getPercentByValue(this.labelOne.getValue()); - var percentTwo = this._getPercentByValue(this.labelTwo.getValue()); - if (percentOne <= percentTwo) { - this._setBlueTrackLeft(percentOne); - this._setBlueTrackWidth(percentTwo - percentOne); - } else { - this._setBlueTrackLeft(percentTwo); - this._setBlueTrackWidth(percentOne - percentTwo); - } + getAllLeaves: function () { + return [this.options.value]; }, - _setAllPosition: function (one, two) { - this._setSliderOnePosition(one); - this._setLabelOnePosition(one); - this._setSliderTwoPosition(two); - this._setLabelTwoPosition(two); - this._setBlueTrack(); + isSelected: function () { + return this.checked.isSelected(); }, - _setVisible: function (visible) { - this.sliderOne.setVisible(visible); - this.sliderTwo.setVisible(visible); - this.labelOne.setVisible(visible); - this.labelTwo.setVisible(visible); + setSelected: function (v) { + this.checked.setSelected(v); + } +}); +BI.FileManagerFileItem.EVENT_CHANGE = "FileManagerFileItem.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_file_item", BI.FileManagerFileItem);/** + * 文件管理控件 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerFolderItem + * @extends BI.Single + */ +BI.FileManagerFolderItem = BI.inherit(BI.Single, { + + _defaultConfig: function () { + return BI.extend(BI.FileManagerFolderItem.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-folder-item bi-list-item bi-border-bottom", + height: 30 + }); }, - _setErrorText: function () { - var errorText = BI.i18nText("BI-Please_Enter") + this.min + "-" + this.max + BI.i18nText("BI-Basic_De") + BI.i18nText("BI-Basic_Number"); - this.labelOne.setErrorText(errorText); - this.labelTwo.setErrorText(errorText); + _init: function () { + BI.FileManagerFolderItem.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.checked = BI.createWidget({ + type: "bi.multi_select_bar", + text: "", + width: 36, + height: o.height + }); + this.checked.on(BI.Controller.EVENT_CHANGE, function () { + arguments[2] = self; + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + this.button = BI.createWidget({ + type: "bi.text_button", + textAlign: "left", + height: o.height, + text: o.text, + value: o.value + }); + this.button.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CHANGE, o.value, self); + }); + + this.tree = new BI.Tree(); + this.tree.initTree([{ + id: o.id, + children: o.children + }]); + this.selectValue = []; + + BI.createWidget({ + type: "bi.htape", + element: this, + items: [{ + el: this.checked, + width: 36 + }, { + el: { + type: "bi.icon_button", + cls: "create-by-me-folder-font" + }, + width: 20 + }, { + el: this.button + }] + }); }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + setAllSelected: function (v) { + this.checked.setSelected(v); + this.selectValue = []; }, - // 其中取max-min后保留4为有效数字后的值的小数位数为最终value的精度 - _getValueByPercent: function (percent) {// return (((max-min)*percent)/100+min) - var sub = this.calculation.accurateSubtraction(this.max, this.min); - var mul = this.calculation.accurateMultiplication(sub, percent); - var div = this.calculation.accurateDivisionTenExponent(mul, 2); - if(this.precision < 0) { - var value = BI.parseFloat(this.calculation.accurateAddition(div, this.min)); - var reduceValue = Math.round(this.calculation.accurateDivisionTenExponent(value, -this.precision)); - return this.calculation.accurateMultiplication(reduceValue, Math.pow(10, -this.precision)); + setHalfSelected: function (v) { + this.checked.setHalfSelected(v); + if(!v) { + this.selectValue = []; } - return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision)); - }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); + setValue: function (v) { + var self = this, o = this.options; + var isHalf = false; + var selectValue = []; + this.tree.traverse(function (node) { + if (node.isLeaf()) { + if (BI.contains(v, node.get("data").value)) { + selectValue.push(node.get("data").value); + } else { + isHalf = true; + } + } + }); + this.setAllSelected(selectValue.length > 0 && !isHalf); + this.setHalfSelected(selectValue.length > 0 && isHalf); + if (this.checked.isHalfSelected()) { + this.selectValue = selectValue; + } }, - _setDraggableEnable: function (enable) { - this.sliderOne.setEnable(enable); - this.sliderTwo.setEnable(enable); + getAllButtons: function () { + return [this]; }, - _getPrecision: function () { - // 计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度) - // 如果差值的整数位数大于4,toPrecision(4)得到的是科学计数法123456 => 1.235e+5 - // 返回非负值: 保留的小数位数 - // 返回负值: 保留的10^n精度中的n - var sub = this.calculation.accurateSubtraction(this.max, this.min); - var pre = sub.toPrecision(4); - // 科学计数法 - var eIndex = pre.indexOf("e"); - var arr = []; - if(eIndex > -1) { - arr = pre.split("e"); - var decimalPartLength = BI.size(arr[0].split(".")[1]); - var sciencePartLength = BI.parseInt(arr[1].substring(1)); - return decimalPartLength - sciencePartLength; - } - arr = pre.split("."); - return arr.length > 1 ? arr[1].length : 0; - + getAllLeaves: function () { + var o = this.options; + var res = []; + this.tree.traverse(function (node) { + if (node.isLeaf()) { + res.push(node.get("data").value); + } + }); + return res; }, - _assertValue: function (value) { - if(value <= this.min) { - return this.min; - } - if(value >= this.max) { - return this.max; + getNotSelectedValue: function () { + var self = this, o = this.options; + var res = []; + var isAllSelected = this.checked.isSelected(); + if (isAllSelected === true) { + return res; } - return value; + var isHalfSelected = this.checked.isHalfSelected(); + this.tree.traverse(function (node) { + if (node.isLeaf()) { + var v = node.get("data").value; + if (isHalfSelected === true) { + if (!BI.contains(self.selectValue, node.get("data").value)) { + res.push(v); + } + } else { + res.push(v); + } + } + }); + return res; }, getValue: function () { - if (this.valueOne <= this.valueTwo) { - return {min: this.valueOne, max: this.valueTwo}; + var res = []; + if (this.checked.isSelected()) { + this.tree.traverse(function (node) { + if (node.isLeaf()) { + res.push(node.get("data").value); + } + }); + return res; } - return {min: this.valueTwo, max: this.valueOne}; + if (this.checked.isHalfSelected()) { + return this.selectValue; + } + return []; + } +}); +BI.FileManagerFolderItem.EVENT_CHANGE = "FileManagerFolderItem.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_folder_item", BI.FileManagerFolderItem);/** + * 文件管理控件列表 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerList + * @extends BI.Widget + */ +BI.FileManagerList = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.FileManagerList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-list", + el: {}, + items: [] + }); }, - setMinAndMax: function (v) { - var minNumber = BI.parseFloat(v.min); - var maxNumber = BI.parseFloat(v.max); - if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber >= minNumber )) { - this.min = minNumber; - this.max = maxNumber; - this.valueOne = minNumber; - this.valueTwo = maxNumber; - this.precision = this._getPrecision(); - this._setDraggableEnable(true); - } - if (maxNumber === minNumber) { - this._setDraggableEnable(false); - } + _init: function () { + BI.FileManagerList.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.list = BI.createWidget({ + type: "bi.select_list", + element: this, + items: o.items, + toolbar: { + type: "bi.multi_select_bar", + height: 40, + text: "" + }, + el: { + type: "bi.list_pane", + el: BI.isWidget(o.el) ? o.el : BI.extend({ + type: "bi.file_manager_button_group" + }, o.el) + } + }); + this.list.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); }, setValue: function (v) { - var o = this.options; - var valueOne = BI.parseFloat(v.min); - var valueTwo = BI.parseFloat(v.max); - valueOne = o.digit === false ? valueOne : valueOne.toFixed(o.digit); - valueTwo = o.digit === false ? valueTwo : valueTwo.toFixed(o.digit); - if (!isNaN(valueOne) && !isNaN(valueTwo)) { - if (this._checkValidation(valueOne)) { - this.valueOne = valueOne; - } - if (this._checkValidation(valueTwo)) { - this.valueTwo = valueTwo; - } - if (valueOne < this.min) { - this.valueOne = this.min; - } - if (valueTwo > this.max) { - this.valueTwo = this.max; - } - } + this.list.setValue({ + value: v + }); }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.valueOne = ""; - this.valueTwo = ""; - this.min = NaN; - this.max = NaN; - this._setBlueTrackWidth(0); + getValue: function () { + return this.list.getValue(); }, - populate: function () { - if (!isNaN(this.min) && !isNaN(this.max)) { - this.enable = true; - this._setVisible(true); - this._setErrorText(); - if ((BI.isNumeric(this.valueOne) || BI.isNotEmptyString(this.valueOne)) && (BI.isNumeric(this.valueTwo) || BI.isNotEmptyString(this.valueTwo))) { - this.labelOne.setValue(this.valueOne); - this.labelTwo.setValue(this.valueTwo); - this._setAllPosition(this._getPercentByValue(this.valueOne), this._getPercentByValue(this.valueTwo)); - } else { - this.labelOne.setValue(this.min); - this.labelTwo.setValue(this.max); - this._setAllPosition(0, 100); - } - } + populate: function (items) { + this.list.populate(items); + this.list.setToolBarVisible(true); } }); -BI.IntervalSlider.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.interval_slider", BI.IntervalSlider);/** - * Created by zcf on 2017/3/1. - * 万恶的IEEE-754 - * 使用字符串精确计算含小数加法、减法、乘法和10的指数倍除法,支持负数 +BI.FileManagerList.EVENT_CHANGE = "FileManagerList.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_list", BI.FileManagerList);/** + * 文件管理导航按钮 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerNavButton + * @extends BI.Widget */ -BI.AccurateCalculationModel = BI.inherit(BI.Widget, { +BI.FileManagerNavButton = BI.inherit(BI.Widget, { + + _const: { + normal_color: "#ffffff", + select_color: "#eff1f4" + }, _defaultConfig: function () { - return BI.extend(BI.AccurateCalculationModel.superclass._defaultConfig.apply(this, arguments), { - baseCls: "" + return BI.extend(BI.FileManagerNavButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-nav-button", + selected: false, + height: 40 }); }, _init: function () { - BI.AccurateCalculationModel.superclass._init.apply(this, arguments); - }, - - _getMagnitude: function (n) { - var magnitude = "1"; - for (var i = 0; i < n; i++) { - magnitude += "0"; - } - return BI.parseInt(magnitude); - }, - - _formatDecimal: function (stringNumber1, stringNumber2) { - if (stringNumber1.numDecimalLength === stringNumber2.numDecimalLength) { - return; - } - var magnitudeDiff = stringNumber1.numDecimalLength - stringNumber2.numDecimalLength; - if (magnitudeDiff > 0) { - var needAddZero = stringNumber2; - } else { - var needAddZero = stringNumber1; - magnitudeDiff = (0 - magnitudeDiff); - } - for (var i = 0; i < magnitudeDiff; i++) { - if (needAddZero.numDecimal === "0" && i === 0) { - continue; + BI.FileManagerNavButton.superclass._init.apply(this, arguments); + var self = this, o = this.options, c = this._const; + this.button = BI.createWidget({ + type: "bi.text_button", + cls: "file-manager-nav-button-text bi-card", + once: true, + selected: o.selected, + text: o.text, + title: o.text, + value: o.value, + height: o.height, + lgap: 20, + rgap: 10 + }); + this.button.on(BI.Controller.EVENT_CHANGE, function () { + arguments[2] = self; + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + var svg = BI.createWidget({ + type: "bi.svg", + cls: "file-manager-nav-button-triangle", + width: 15, + height: o.height + }); + var path = svg.path("M0,0L15,20L0,40").attr({ + stroke: c.select_color, + fill: o.selected ? c.select_color : c.normal_color + }); + this.button.on(BI.TextButton.EVENT_CHANGE, function () { + if (this.isSelected()) { + path.attr("fill", c.select_color); + } else { + path.attr("fill", c.normal_color); } - needAddZero.numDecimal += "0"; - } + }); + BI.createWidget({ + type: "bi.default", + element: this, + items: [this.button] + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: svg, + right: -15, + top: 0, + bottom: 0 + }] + }); }, - _stringNumberFactory: function (num) { - var strNum = num.toString(); - var numStrArray = strNum.split("."); - var numInteger = numStrArray[0]; - if (numStrArray.length === 1) { - var numDecimal = "0"; - var numDecimalLength = 0; - } else { - var numDecimal = numStrArray[1]; - var numDecimalLength = numStrArray[1].length; - } - return { - numInteger: numInteger, - numDecimal: numDecimal, - numDecimalLength: numDecimalLength - }; + isSelected: function () { + return this.button.isSelected(); }, - _accurateSubtraction: function (num1, num2) {// num1-num2 && num1>num2 - var stringNumber1 = this._stringNumberFactory(num1); - var stringNumber2 = this._stringNumberFactory(num2); - // 整数部分计算 - var integerResult = BI.parseInt(stringNumber1.numInteger) - BI.parseInt(stringNumber2.numInteger); - // 小数部分 - this._formatDecimal(stringNumber1, stringNumber2); - var decimalMaxLength = getDecimalMaxLength(stringNumber1, stringNumber2); - - if (BI.parseInt(stringNumber1.numDecimal) >= BI.parseInt(stringNumber2.numDecimal)) { - var decimalResultTemp = (BI.parseInt(stringNumber1.numDecimal) - BI.parseInt(stringNumber2.numDecimal)).toString(); - var decimalResult = addZero(decimalResultTemp, decimalMaxLength); - } else {// 否则借位 - integerResult--; - var borrow = this._getMagnitude(decimalMaxLength); - var decimalResultTemp = (borrow + BI.parseInt(stringNumber1.numDecimal) - BI.parseInt(stringNumber2.numDecimal)).toString(); - var decimalResult = addZero(decimalResultTemp, decimalMaxLength); - } - var result = integerResult + "." + decimalResult; - return BI.parseFloat(result); - - function getDecimalMaxLength (num1, num2) { - if (num1.numDecimal.length >= num2.numDecimal.length) { - return num1.numDecimal.length; - } - return num2.numDecimal.length; - } - - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; - } - return resultTemp; - } + setValue: function (v) { + this.button.setValue(v); }, - _accurateAddition: function (num1, num2) {// 加法结合律 - var stringNumber1 = this._stringNumberFactory(num1); - var stringNumber2 = this._stringNumberFactory(num2); - // 整数部分计算 - var integerResult = BI.parseInt(stringNumber1.numInteger) + BI.parseInt(stringNumber2.numInteger); - // 小数部分 - this._formatDecimal(stringNumber1, stringNumber2); + getValue: function () { + return this.button.getValue(); + }, - var decimalResult = (BI.parseInt(stringNumber1.numDecimal) + BI.parseInt(stringNumber2.numDecimal)).toString(); + populate: function (items) { - if (decimalResult !== "0") { - if (decimalResult.length <= stringNumber1.numDecimal.length) { - decimalResult = addZero(decimalResult, stringNumber1.numDecimal.length); - } else { - integerResult++;// 进一 - decimalResult = decimalResult.slice(1); - } - } - var result = integerResult + "." + decimalResult; - return BI.parseFloat(result); + } +}); +BI.FileManagerNavButton.EVENT_CHANGE = "FileManagerNavButton.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_nav_button", BI.FileManagerNavButton);/** + * 文件管理导航 + * + * Created by GUY on 2015/12/11. + * @class BI.FileManagerNav + * @extends BI.Widget + */ +BI.FileManagerNav = BI.inherit(BI.Widget, { - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; - } - return resultTemp; - } + _defaultConfig: function () { + return BI.extend(BI.FileManagerNav.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-nav bi-border-left", + height: 40, + items: [] + }); }, - _accurateMultiplication: function (num1, num2) {// 乘法分配律 - var stringNumber1 = this._stringNumberFactory(num1); - var stringNumber2 = this._stringNumberFactory(num2); - // 整数部分计算 - var integerResult = BI.parseInt(stringNumber1.numInteger) * BI.parseInt(stringNumber2.numInteger); - // num1的小数和num2的整数 - var dec1Int2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numDecimal) * BI.parseInt(stringNumber2.numInteger), stringNumber1.numDecimalLength); - // num1的整数和num2的小数 - var int1dec2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numInteger) * BI.parseInt(stringNumber2.numDecimal), stringNumber2.numDecimalLength); - // 小数*小数 - var dec1dec2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numDecimal) * BI.parseInt(stringNumber2.numDecimal), (stringNumber1.numDecimalLength + stringNumber2.numDecimalLength)); - - return this._accurateAddition(this._accurateAddition(this._accurateAddition(integerResult, dec1Int2), int1dec2), dec1dec2); + _init: function () { + BI.FileManagerNav.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.tree = new BI.Tree(); + this.refreshTreeData(o.items); + this.tree.getRoot().set("data", { + text: BI.i18nText("BI-Created_By_Me"), + value: BI.FileManagerNav.ROOT_CREATE_BY_ME, + id: BI.FileManagerNav.ROOT_CREATE_BY_ME + }); + this.button_group = BI.createWidget({ + type: "bi.button_group", + element: this, + items: [{ + type: "bi.file_manager_nav_button", + text: BI.i18nText("BI-Created_By_Me"), + selected: true, + id: BI.FileManagerNav.ROOT_CREATE_BY_ME, + value: BI.FileManagerNav.ROOT_CREATE_BY_ME + }], + layouts: [{ + type: "bi.horizontal" + }] + }); + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + this.button_group.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) { + self.fireEvent(BI.FileManagerNav.EVENT_CHANGE, arguments); + }); }, - _accurateDivisionTenExponent: function (num, n) {// num/10^n && n>0 - var stringNumber = this._stringNumberFactory(num); - if (stringNumber.numInteger.length > n) { - var integerResult = stringNumber.numInteger.slice(0, (stringNumber.numInteger.length - n)); - var partDecimalResult = stringNumber.numInteger.slice(-n); + _getAllParents: function (id) { + var node, res = []; + if (!id) { + node = this.tree.getRoot(); } else { - var integerResult = "0"; - var partDecimalResult = addZero(stringNumber.numInteger, n); + node = this.tree.search(id); } - var result = integerResult + "." + partDecimalResult + stringNumber.numDecimal; - return BI.parseFloat(result); - - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; - } - return resultTemp; + while (node.parent) { + res.push(node); + node = node.parent; } + res.push(node); + return res.reverse(); }, - accurateSubtraction: function (num1, num2) { - if (num1 >= 0 && num2 >= 0) { - if (num1 >= num2) { - return this._accurateSubtraction(num1, num2); - } - return -this._accurateSubtraction(num2, num1); - } - if (num1 >= 0 && num2 < 0) { - return this._accurateAddition(num1, -num2); - } - if (num1 < 0 && num2 >= 0) { - return -this._accurateAddition(-num1, num2); - } - if (num1 < 0 && num2 < 0) { - if (num1 >= num2) { - return this._accurateSubtraction(-num2, -num1); - } - return this._accurateSubtraction(-num1, -num2); - } + _formatNodes: function (nodes) { + var res = []; + BI.each(nodes, function (i, node) { + res.push(BI.extend({ + type: "bi.file_manager_nav_button", + id: node.id + }, node.get("data"))); + }); + BI.last(res).selected = true; + return res; }, - accurateAddition: function (num1, num2) { - if (num1 >= 0 && num2 >= 0) { - return this._accurateAddition(num1, num2); - } - if (num1 >= 0 && num2 < 0) { - return this.accurateSubtraction(num1, -num2); - } - if (num1 < 0 && num2 >= 0) { - return this.accurateSubtraction(num2, -num1); - } - if (num1 < 0 && num2 < 0) { - return -this._accurateAddition(-num1, -num2); - } + getValue: function () { + return this.button_group.getValue(); }, - accurateMultiplication: function (num1, num2) { - if (num1 >= 0 && num2 >= 0) { - return this._accurateMultiplication(num1, num2); - } - if (num1 >= 0 && num2 < 0) { - return -this._accurateMultiplication(num1, -num2); - } - if (num1 < 0 && num2 >= 0) { - return -this._accurateMultiplication(-num1, num2); - } - if (num1 < 0 && num2 < 0) { - return this._accurateMultiplication(-num1, -num2); - } + getId: function () { + var ids = []; + BI.each(this.button_group.getSelectedButtons(), function (i, btn) { + ids.push(btn.attr("id")); + }); + return ids; }, - accurateDivisionTenExponent: function (num1, n) { - if (num1 >= 0) { - return this._accurateDivisionTenExponent(num1, n); - } - return -this._accurateDivisionTenExponent(-num1, n); + refreshTreeData: function (items) { + this.tree.initTree(BI.Tree.transformToTreeFormat(items)); + this.tree.getRoot().set("data", { + text: BI.i18nText("BI-Created_By_Me"), + value: BI.FileManagerNav.ROOT_CREATE_BY_ME, + id: BI.FileManagerNav.ROOT_CREATE_BY_ME + }); + }, + + populate: function (node) { + var parents = BI.isNull(node) ? [this.tree.getRoot()] : this._getAllParents(node.id); + this.button_group.populate(this._formatNodes(parents)); } -});/** - * 月份下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.MonthCombo - * @extends BI.Trigger +}); +BI.extend(BI.FileManagerNav, { + ROOT_CREATE_BY_ME: "-1" +}); +BI.FileManagerNav.EVENT_CHANGE = "FileManagerNav.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_nav", BI.FileManagerNav);/** + * Created by zcf on 2016/9/26. */ -BI.MonthCombo = BI.inherit(BI.Widget, { +BI.IntervalSlider = BI.inherit(BI.Widget, { + _constant: { + EDITOR_WIDTH: 58, + EDITOR_R_GAP: 60, + EDITOR_HEIGHT: 30, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, + _defaultConfig: function () { - return BI.extend(BI.MonthCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-month-combo", - behaviors: {}, - height: 25 + return BI.extend(BI.IntervalSlider.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-interval-slider bi-slider-track", + digit: false, + unit: "" }); }, + _init: function () { - BI.MonthCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.IntervalSlider.superclass._init.apply(this, arguments); - this.trigger = BI.createWidget({ - type: "bi.month_trigger", - value: o.value + var self = this; + var c = this._constant; + this.enable = false; + this.valueOne = ""; + this.valueTwo = ""; + this.calculation = new BI.AccurateCalculationModel(); + + // this.backgroundTrack = BI.createWidget({ + // type: "bi.layout", + // cls: "background-track", + // height: c.TRACK_HEIGHT + // }); + this.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 + }); + this.blueTrack = BI.createWidget({ + type: "bi.layout", + cls: "blue-track bi-high-light-background", + height: 6 + }); + this.track = this._createTrackWrapper(); + + this.labelOne = BI.createWidget({ + type: "bi.sign_text_editor", + cls: "slider-editor-button", + text: this.options.unit, + errorText: "", + allowBlank: false, + width: c.EDITOR_WIDTH, + validationChecker: function (v) { + return self._checkValidation(v); + } + }); + this.labelOne.element.hover(function () { + self.labelOne.element.removeClass("bi-border").addClass("bi-border"); + }, function () { + self.labelOne.element.removeClass("bi-border"); + }); + this.labelOne.on(BI.Editor.EVENT_CONFIRM, function () { + var v = BI.parseFloat(this.getValue()); + self.valueOne = v; + var percent = self._getPercentByValue(v); + var significantPercent = BI.parseFloat(percent.toFixed(1));// 分成1000份 + self._setLabelOnePosition(significantPercent); + self._setSliderOnePosition(significantPercent); + self._setBlueTrack(); + self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); + }); + + this.labelTwo = BI.createWidget({ + type: "bi.sign_text_editor", + cls: "slider-editor-button", + errorText: "", + text: this.options.unit, + allowBlank: false, + width: c.EDITOR_WIDTH, + validationChecker: function (v) { + return self._checkValidation(v); + } + }); + this.labelTwo.element.hover(function () { + self.labelTwo.element.removeClass("bi-border").addClass("bi-border"); + }, function () { + self.labelTwo.element.removeClass("bi-border"); + }); + this.labelTwo.on(BI.Editor.EVENT_CONFIRM, function () { + var v = BI.parseFloat(this.getValue()); + self.valueTwo = v; + var percent = self._getPercentByValue(v); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setLabelTwoPosition(significantPercent); + self._setSliderTwoPosition(significantPercent); + self._setBlueTrack(); + self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); + }); + + this.sliderOne = BI.createWidget({ + type: "bi.single_slider_button" + }); + this.sliderTwo = BI.createWidget({ + type: "bi.single_slider_button" + }); + this._draggable(this.sliderOne, true); + this._draggable(this.sliderTwo, false); + this._setVisible(false); + + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.track, + width: "100%", + height: c.TRACK_HEIGHT + }] + }], + hgap: 7, + height: c.TRACK_HEIGHT + }, + top: 23, + left: 0, + width: "100%" + }, + this._createLabelWrapper(), + this._createSliderWrapper() + ] }); + }, + + _rePosBySizeAfterMove: function (size, isLeft) { + var o = this.options; + var percent = size * 100 / (this._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + var v = this._getValueByPercent(significantPercent); + v = this._assertValue(v); + v = o.digit === false ? v : v.toFixed(o.digit); + if(isLeft) { + this._setLabelOnePosition(significantPercent); + this._setSliderOnePosition(significantPercent); + this.labelOne.setValue(v); + this.valueOne = v; + }else{ + this._setLabelTwoPosition(significantPercent); + this._setSliderTwoPosition(significantPercent); + this.labelTwo.setValue(v); + this.valueTwo = v; + } + this._setBlueTrack(); + }, - this.trigger.on(BI.MonthTrigger.EVENT_CONFIRM, function (v) { - if (self.combo.isViewVisible()) { - return; + _rePosBySizeAfterStop: function (size, isLeft) { + var percent = size * 100 / (this._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + isLeft ? this._setSliderOnePosition(significantPercent) : this._setSliderTwoPosition(significantPercent); + }, + + _draggable: function (widget, isLeft) { + var self = this, o = this.options; + var startDrag = false; + var size = 0, offset = 0, defaultSize = 0; + var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { + if (mouseMoveTracker.isDragging()) { + startDrag = true; + offset += deltaX; + size = optimizeSize(defaultSize + offset); + widget.element.addClass("dragging"); + self._rePosBySizeAfterMove(size, isLeft); } - if (this.getKey() && this.getKey() !== self.storeValue) { - self.setValue(this.getValue()); - } else if (!this.getKey()) { - self.setValue(); + }, function () { + if (startDrag === true) { + size = optimizeSize(size); + self._rePosBySizeAfterStop(size, isLeft); + size = 0; + offset = 0; + defaultSize = size; + startDrag = false; } - self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); - }); - this.trigger.on(BI.MonthTrigger.EVENT_FOCUS, function () { - self.storeValue = this.getKey(); - }); - this.trigger.on(BI.MonthTrigger.EVENT_START, function () { - self.combo.hideView(); - }); - this.trigger.on(BI.MonthTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); + widget.element.removeClass("dragging"); + mouseMoveTracker.releaseMouseMoves(); + self.fireEvent(BI.IntervalSlider.EVENT_CHANGE); + }, window); + widget.element.on("mousedown", function (event) { + if(!widget.isEnabled()) { + return; } + defaultSize = this.offsetLeft; + optimizeSize(defaultSize); + mouseMoveTracker.captureMouseMoves(event); }); - this.popup = BI.createWidget({ - type: "bi.month_popup", - behaviors: o.behaviors, - value: o.value - }); - this.popup.on(BI.MonthPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); - }); - - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - el: this.popup - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW); - }); + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); + } }, - setValue: function (v) { - this.trigger.setValue(v); - this.popup.setValue(v); + _createLabelWrapper: function () { + var c = this._constant; + return { + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.labelOne, + top: 0, + left: "0%" + }] + }, { + type: "bi.absolute", + items: [{ + el: this.labelTwo, + top: 0, + left: "100%" + }] + }], + rgap: c.EDITOR_R_GAP, + height: 70 + }, + top: 0, + left: 0, + width: "100%" + }; }, - getValue: function () { - if (BI.isNull(this.popup)) { - return this.options.value || ""; - } else { - return this.popup.getValue() || ""; - } - } -}); - -BI.MonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.MonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.month_combo", BI.MonthCombo);/** - * 月份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.MonthPopup - * @extends BI.Trigger - */ -BI.MonthPopup = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.MonthPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-month-popup", - behaviors: {} - }); + _createSliderWrapper: function () { + var c = this._constant; + return { + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.sliderOne, + top: 0, + left: "0%" + }] + }, { + type: "bi.absolute", + items: [{ + el: this.sliderTwo, + top: 0, + left: "100%" + }] + }], + hgap: c.SLIDER_WIDTH_HALF, + height: c.SLIDER_HEIGHT + }, + top: 20, + left: 0, + width: "100%" + }; }, - _init: function () { - BI.MonthPopup.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - // 纵向排列月 - var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; - var items = []; - items.push(month.slice(0, 2)); - items.push(month.slice(2, 4)); - items.push(month.slice(4, 6)); - items.push(month.slice(6, 8)); - items.push(month.slice(8, 10)); - items.push(month.slice(10, 12)); - items = BI.map(items, function (i, item) { - return BI.map(item, function (j, td) { - return { - type: "bi.text_item", - cls: "bi-list-item-active", - textAlign: "center", - whiteSpace: "nowrap", - once: false, - forceSelected: true, - height: 23, - width: 38, - value: td, - text: td + 1 - }; - }); + _createTrackWrapper: function () { + return BI.createWidget({ + type: "bi.absolute", + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.grayTrack, + top: 0, + left: 0, + width: "100%" + }, { + el: this.blueTrack, + top: 0, + left: 0, + width: "0%" + }] + }], + hgap: 8, + height: 8 + }, + top: 8, + left: 0, + width: "100%" + }] }); + }, - this.month = BI.createWidget({ - type: "bi.button_group", - element: this, - behaviors: o.behaviors, - items: BI.createItems(items, {}), - layouts: [BI.LogicFactory.createLogic("table", BI.extend({ - dynamic: true - }, { - columns: 2, - rows: 6, - columnSize: [1 / 2, 1 / 2], - rowSize: 25 - })), { - type: "bi.center_adapt", - vgap: 1, - hgap: 2 - }], - value: o.value - }); + _checkValidation: function (v) { + var o = this.options; + var valid = false; + // 像90.这样的既不属于整数又不属于小数,是不合法的值 + var dotText = (v + "").split(".")[1]; + if (BI.isEmptyString(dotText)) { + }else{ + if (BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)) { + if(o.digit === false) { + valid = true; + }else{ + dotText = dotText || ""; + valid = (dotText.length === o.digit); + } + } + } + return valid; + }, - this.month.on(BI.Controller.EVENT_CHANGE, function (type) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if (type === BI.Events.CLICK) { - self.fireEvent(BI.MonthPopup.EVENT_CHANGE); + _checkOverlap: function () { + var labelOneLeft = this.labelOne.element[0].offsetLeft; + var labelTwoLeft = this.labelTwo.element[0].offsetLeft; + if (labelOneLeft <= labelTwoLeft) { + if ((labelTwoLeft - labelOneLeft) < 90) { + this.labelTwo.element.css({top: 40}); + } else { + this.labelTwo.element.css({top: 0}); } - }); + } else { + if ((labelOneLeft - labelTwoLeft) < 90) { + this.labelTwo.element.css({top: 40}); + } else { + this.labelTwo.element.css({top: 0}); + } + } }, - getValue: function () { - return this.month.getValue()[0]; + _setLabelOnePosition: function (percent) { + this.labelOne.element.css({left: percent + "%"}); + this._checkOverlap(); }, - setValue: function (v) { - this.month.setValue([v]); - } -}); -BI.MonthPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.month_popup", BI.MonthPopup);/** - * 月份trigger - * - * Created by GUY on 2015/8/21. - * @class BI.MonthTrigger - * @extends BI.Trigger - */ -BI.MonthTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Month_Trigger_Error_Text") + _setLabelTwoPosition: function (percent) { + this.labelTwo.element.css({left: percent + "%"}); + this._checkOverlap(); }, - _defaultConfig: function () { - return BI.extend(BI.MonthTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-month-trigger bi-border", - height: 24 - }); + _setSliderOnePosition: function (percent) { + this.sliderOne.element.css({left: percent + "%"}); }, - _init: function () { - BI.MonthTrigger.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) { - return v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 12); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true, - errorText: c.errorText - }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.MonthTrigger.EVENT_FOCUS); - }); - this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.MonthTrigger.EVENT_CHANGE); - }); - this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - self.editor.setTitle(value); - } - self.fireEvent(BI.MonthTrigger.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.MonthTrigger.EVENT_START); - }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.MonthTrigger.EVENT_STOP); - }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [ - { - el: this.editor - }, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Month"), - baseCls: "bi-trigger-month-text", - width: o.height - }, - width: o.height - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - } - ] - }); - this.setValue(o.value); + + _setSliderTwoPosition: function (percent) { + this.sliderTwo.element.css({left: percent + "%"}); }, - setValue: function (v) { - if(BI.isNotNull(v)) { - this.editor.setState(v + 1); - this.editor.setValue(v + 1); - this.editor.setTitle(v + 1); - return; + + _setBlueTrackLeft: function (percent) { + this.blueTrack.element.css({left: percent + "%"}); + }, + + _setBlueTrackWidth: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); + }, + + _setBlueTrack: function () { + var percentOne = this._getPercentByValue(this.labelOne.getValue()); + var percentTwo = this._getPercentByValue(this.labelTwo.getValue()); + if (percentOne <= percentTwo) { + this._setBlueTrackLeft(percentOne); + this._setBlueTrackWidth(percentTwo - percentOne); + } else { + this._setBlueTrackLeft(percentTwo); + this._setBlueTrackWidth(percentOne - percentTwo); } - this.editor.setState(""); - this.editor.setValue(""); - this.editor.setTitle(""); }, - getKey: function () { - return this.editor.getValue() | 0; + + _setAllPosition: function (one, two) { + this._setSliderOnePosition(one); + this._setLabelOnePosition(one); + this._setSliderTwoPosition(two); + this._setLabelTwoPosition(two); + this._setBlueTrack(); }, - getValue: function () { - return this.editor.getValue() - 1; - } -}); -BI.MonthTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.MonthTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.MonthTrigger.EVENT_START = "EVENT_START"; -BI.MonthTrigger.EVENT_STOP = "EVENT_STOP"; -BI.MonthTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.month_trigger", BI.MonthTrigger);/** - * 普通控件 - * - * @class BI.MultiDateCard - * @extends BI.Widget - * @abstract - */ -BI.MultiDateCard = BI.inherit(BI.Widget, { - constants: { - lgap: 80, - itemHeight: 35, - defaultEditorValue: "1" + _setVisible: function (visible) { + this.sliderOne.setVisible(visible); + this.sliderTwo.setVisible(visible); + this.labelOne.setVisible(visible); + this.labelTwo.setVisible(visible); }, - _defaultConfig: function () { - return $.extend(BI.MultiDateCard.superclass._defaultConfig.apply(this, arguments), {}); + _setErrorText: function () { + var errorText = BI.i18nText("BI-Please_Enter") + this.min + "-" + this.max + BI.i18nText("BI-Basic_De") + BI.i18nText("BI-Basic_Number"); + this.labelOne.setErrorText(errorText); + this.labelTwo.setErrorText(errorText); + }, + + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - dateConfig: function () { + // 其中取max-min后保留4为有效数字后的值的小数位数为最终value的精度 + _getValueByPercent: function (percent) {// return (((max-min)*percent)/100+min) + var sub = this.calculation.accurateSubtraction(this.max, this.min); + var mul = this.calculation.accurateMultiplication(sub, percent); + var div = this.calculation.accurateDivisionTenExponent(mul, 2); + if(this.precision < 0) { + var value = BI.parseFloat(this.calculation.accurateAddition(div, this.min)); + var reduceValue = Math.round(this.calculation.accurateDivisionTenExponent(value, -this.precision)); + return this.calculation.accurateMultiplication(reduceValue, Math.pow(10, -this.precision)); + } + return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision)); }, - defaultSelectedItem: function () { + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); + }, + _setDraggableEnable: function (enable) { + this.sliderOne.setEnable(enable); + this.sliderTwo.setEnable(enable); }, - _init: function () { - BI.MultiDateCard.superclass._init.apply(this, arguments); - var self = this, opts = this.options; + _getPrecision: function () { + // 计算每一份值的精度(最大值和最小值的差值保留4为有效数字后的精度) + // 如果差值的整数位数大于4,toPrecision(4)得到的是科学计数法123456 => 1.235e+5 + // 返回非负值: 保留的小数位数 + // 返回负值: 保留的10^n精度中的n + var sub = this.calculation.accurateSubtraction(this.max, this.min); + var pre = sub.toPrecision(4); + // 科学计数法 + var eIndex = pre.indexOf("e"); + var arr = []; + if(eIndex > -1) { + arr = pre.split("e"); + var decimalPartLength = BI.size(arr[0].split(".")[1]); + var sciencePartLength = BI.parseInt(arr[1].substring(1)); + return decimalPartLength - sciencePartLength; + } + arr = pre.split("."); + return arr.length > 1 ? arr[1].length : 0; - this.label = BI.createWidget({ - type: "bi.label", - height: this.constants.itemHeight, - textAlign: "left", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - cls: "bi-multidate-inner-label bi-tips" - }); - this.radioGroup = BI.createWidget({ - type: "bi.button_group", - chooseType: 0, - items: BI.createItems(this.dateConfig(), { - type: "bi.multidate_segment", - height: this.constants.itemHeight - }), - layouts: [{ - type: "bi.vertical" - }] - }); + }, - this.radioGroup.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CONFIRM) { - self.fireEvent(BI.MultiDateCard.EVENT_CHANGE); - } - }); - this.radioGroup.on(BI.ButtonGroup.EVENT_CHANGE, function () { - self.setValue(self.getValue()); - self.fireEvent(BI.MultiDateCard.EVENT_CHANGE); - }); - BI.createWidget({ - element: this, - type: "bi.center_adapt", - lgap: this.constants.lgap, - items: [{ - type: "bi.vertical", - items: [this.label, this.radioGroup] - }] - }); + _assertValue: function (value) { + if(value <= this.min) { + return this.min; + } + if(value >= this.max) { + return this.max; + } + return value; }, getValue: function () { - var button = this.radioGroup.getSelectedButtons()[0]; - var type = button.getValue(), value = button.getInputValue(); - return { - type: type, - value: value - }; + if (this.valueOne <= this.valueTwo) { + return {min: this.valueOne, max: this.valueTwo}; + } + return {min: this.valueTwo, max: this.valueOne}; + }, - _isTypeAvaliable: function (type) { - var res = false; - BI.find(this.dateConfig(), function (i, item) { - if (item.value === type) { - res = true; - return true; - } - }); - return res; + setMinAndMax: function (v) { + var minNumber = BI.parseFloat(v.min); + var maxNumber = BI.parseFloat(v.max); + if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber >= minNumber )) { + this.min = minNumber; + this.max = maxNumber; + this.valueOne = minNumber; + this.valueTwo = maxNumber; + this.precision = this._getPrecision(); + this._setDraggableEnable(true); + } + if (maxNumber === minNumber) { + this._setDraggableEnable(false); + } }, setValue: function (v) { - var self = this; - if (BI.isNotNull(v) && this._isTypeAvaliable(v.type)) { - this.radioGroup.setValue(v.type); - BI.each(this.radioGroup.getAllButtons(), function (i, button) { - if (button.isEditorExist() === true && button.isSelected()) { - button.setInputValue(v.value); - } else { - button.setInputValue(self.constants.defaultEditorValue); - } - }); - } else { - this.radioGroup.setValue(this.defaultSelectedItem()); - BI.each(this.radioGroup.getAllButtons(), function (i, button) { - button.setInputValue(self.constants.defaultEditorValue); - }); + var o = this.options; + var valueOne = BI.parseFloat(v.min); + var valueTwo = BI.parseFloat(v.max); + valueOne = o.digit === false ? valueOne : valueOne.toFixed(o.digit); + valueTwo = o.digit === false ? valueTwo : valueTwo.toFixed(o.digit); + if (!isNaN(valueOne) && !isNaN(valueTwo)) { + if (this._checkValidation(valueOne)) { + this.valueOne = valueOne; + } + if (this._checkValidation(valueTwo)) { + this.valueTwo = valueTwo; + } + if (valueOne < this.min) { + this.valueOne = this.min; + } + if (valueTwo > this.max) { + this.valueTwo = this.max; + } } }, - getCalculationValue: function () { - var valueObject = this.getValue(); - var type = valueObject.type, value = valueObject.value; - switch (type) { - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - return BI.getDate().getOffsetDate(-1 * value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - return BI.getDate().getOffsetDate(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - return BI.getDate(); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - return BI.getDate().getBeforeMultiMonth(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - return BI.getDate().getAfterMultiMonth(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), 1); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), (BI.getDate().getLastDateOfMonth()).getDate()); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - return BI.getDate().getBeforeMulQuarter(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - return BI.getDate().getAfterMulQuarter(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - return BI.getDate().getQuarterStartDate(); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - return BI.getDate().getQuarterEndDate(); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - return BI.getDate().getOffsetDate(-7 * value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - return BI.getDate().getOffsetDate(7 * value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - return BI.getDate((BI.getDate().getFullYear() - 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - return BI.getDate((BI.getDate().getFullYear() + 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - return BI.getDate(BI.getDate().getFullYear(), 0, 1); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - return BI.getDate(BI.getDate().getFullYear(), 11, 31); + reset: function () { + this._setVisible(false); + this.enable = false; + this.valueOne = ""; + this.valueTwo = ""; + this.min = NaN; + this.max = NaN; + this._setBlueTrackWidth(0); + }, + + populate: function () { + if (!isNaN(this.min) && !isNaN(this.max)) { + this.enable = true; + this._setVisible(true); + this._setErrorText(); + if ((BI.isNumeric(this.valueOne) || BI.isNotEmptyString(this.valueOne)) && (BI.isNumeric(this.valueTwo) || BI.isNotEmptyString(this.valueTwo))) { + this.labelOne.setValue(this.valueOne); + this.labelTwo.setValue(this.valueTwo); + this._setAllPosition(this._getPercentByValue(this.valueOne), this._getPercentByValue(this.valueTwo)); + } else { + this.labelOne.setValue(this.min); + this.labelTwo.setValue(this.max); + this._setAllPosition(0, 100); + } } } }); -BI.MultiDateCard.EVENT_CHANGE = "EVENT_CHANGE"; -/** - * 日期控件 - * @class BI.MultiDateCombo - * @extends BI.Widget +BI.IntervalSlider.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.interval_slider", BI.IntervalSlider);/** + * Created by zcf on 2017/3/1. + * 万恶的IEEE-754 + * 使用字符串精确计算含小数加法、减法、乘法和10的指数倍除法,支持负数 */ -BI.MultiDateCombo = 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" - }, +BI.AccurateCalculationModel = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiDateCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-combo bi-border", - height: 24 + return BI.extend(BI.AccurateCalculationModel.superclass._defaultConfig.apply(this, arguments), { + baseCls: "" }); }, + _init: function () { - BI.MultiDateCombo.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - this.storeTriggerValue = ""; - var date = BI.getDate(); - this.storeValue = opts.value; - this.trigger = BI.createWidget({ - type: "bi.date_trigger", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value - }); - this.trigger.on(BI.DateTrigger.EVENT_KEY_DOWN, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } - }); - this.trigger.on(BI.DateTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - }); - this.trigger.on(BI.DateTrigger.EVENT_TRIGGER_CLICK, function () { - self.combo.toggle(); - }); - this.trigger.on(BI.DateTrigger.EVENT_FOCUS, function () { - self.storeTriggerValue = self.trigger.getKey(); - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - self.fireEvent(BI.MultiDateCombo.EVENT_FOCUS); - }); - this.trigger.on(BI.DateTrigger.EVENT_ERROR, function () { - self.storeValue = { - year: date.getFullYear(), - month: date.getMonth() - }; - self.popup.setValue(); - self.fireEvent(BI.MultiDateCombo.EVENT_ERROR); - }); - this.trigger.on(BI.DateTrigger.EVENT_VALID, function () { - self.fireEvent(BI.MultiDateCombo.EVENT_VALID); - }); - this.trigger.on(BI.DateTrigger.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDateCombo.EVENT_CHANGE); - }); - this.trigger.on(BI.DateTrigger.EVENT_CONFIRM, 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.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup = BI.createWidget({ - type: "bi.multidate_popup", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value - }); - this.popup.on(BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE, function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup.on(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE, function () { - var date = BI.getDate(); - self.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - self.combo.hideView(); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup.on(BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup.on(BI.MultiDatePopup.CALENDAR_EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - // self.fireEvent(BI.MultiDateCombo.EVENT_CHANGE); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - adjustLength: this.constants.comboAdjustHeight, - popup: { - el: this.popup, - width: this.constants.popupWidth, - stopPropagation: false - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW); - }); + BI.AccurateCalculationModel.superclass._init.apply(this, arguments); + }, - var triggerBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "bi-trigger-icon-button date-font", - width: 24, - height: 24 - }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); + _getMagnitude: function (n) { + var magnitude = "1"; + for (var i = 0; i < n; i++) { + magnitude += "0"; + } + return BI.parseInt(magnitude); + }, + + _formatDecimal: function (stringNumber1, stringNumber2) { + if (stringNumber1.numDecimalLength === stringNumber2.numDecimalLength) { + return; + } + var magnitudeDiff = stringNumber1.numDecimalLength - stringNumber2.numDecimalLength; + if (magnitudeDiff > 0) { + var needAddZero = stringNumber2; + } else { + var needAddZero = stringNumber1; + magnitudeDiff = (0 - magnitudeDiff); + } + for (var i = 0; i < magnitudeDiff; i++) { + if (needAddZero.numDecimal === "0" && i === 0) { + continue; } - }); - this.changeIcon = BI.createWidget({ - type: "bi.icon_button", - cls: "bi-trigger-icon-button date-change-h-font", - width: 24, - height: 24 - }); + needAddZero.numDecimal += "0"; + } + }, + _stringNumberFactory: function (num) { + var strNum = num.toString(); + var numStrArray = strNum.split("."); + var numInteger = numStrArray[0]; + if (numStrArray.length === 1) { + var numDecimal = "0"; + var numDecimalLength = 0; + } else { + var numDecimal = numStrArray[1]; + var numDecimalLength = numStrArray[1].length; + } + return { + numInteger: numInteger, + numDecimal: numDecimal, + numDecimalLength: numDecimalLength + }; + }, - var leftPart = BI.createWidget({ - type: "bi.absolute", - items: [{ - el: this.combo, - top: 0, - left: 0, - right: 0, - bottom: 0 - }, { - el: triggerBtn, - top: 0, - left: 0 - }] - }); + _accurateSubtraction: function (num1, num2) {// num1-num2 && num1>num2 + var stringNumber1 = this._stringNumberFactory(num1); + var stringNumber2 = this._stringNumberFactory(num2); + // 整数部分计算 + var integerResult = BI.parseInt(stringNumber1.numInteger) - BI.parseInt(stringNumber2.numInteger); + // 小数部分 + this._formatDecimal(stringNumber1, stringNumber2); + var decimalMaxLength = getDecimalMaxLength(stringNumber1, stringNumber2); - BI.createWidget({ - type: "bi.htape", - element: this, - items: [leftPart, { - el: this.changeIcon, - width: 30 - }], - ref: function (_ref) { - self.comboWrapper = _ref; + if (BI.parseInt(stringNumber1.numDecimal) >= BI.parseInt(stringNumber2.numDecimal)) { + var decimalResultTemp = (BI.parseInt(stringNumber1.numDecimal) - BI.parseInt(stringNumber2.numDecimal)).toString(); + var decimalResult = addZero(decimalResultTemp, decimalMaxLength); + } else {// 否则借位 + integerResult--; + var borrow = this._getMagnitude(decimalMaxLength); + var decimalResultTemp = (borrow + BI.parseInt(stringNumber1.numDecimal) - BI.parseInt(stringNumber2.numDecimal)).toString(); + var decimalResult = addZero(decimalResultTemp, decimalMaxLength); + } + var result = integerResult + "." + decimalResult; + return BI.parseFloat(result); + + function getDecimalMaxLength (num1, num2) { + if (num1.numDecimal.length >= num2.numDecimal.length) { + return num1.numDecimal.length; } - }); + return num2.numDecimal.length; + } - this._checkDynamicValue(opts.value); + function addZero (resultTemp, length) { + var diff = length - resultTemp.length; + for (var i = 0; i < diff; i++) { + resultTemp = "0" + resultTemp; + } + return resultTemp; + } }, - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[1].width = 30; - this.comboWrapper.resize(); - break; - default: - this.comboWrapper.attr("items")[1].width = 0; - this.comboWrapper.resize(); - this.changeIcon.setVisible(false); - break; + _accurateAddition: function (num1, num2) {// 加法结合律 + var stringNumber1 = this._stringNumberFactory(num1); + var stringNumber2 = this._stringNumberFactory(num2); + // 整数部分计算 + var integerResult = BI.parseInt(stringNumber1.numInteger) + BI.parseInt(stringNumber2.numInteger); + // 小数部分 + this._formatDecimal(stringNumber1, stringNumber2); + + var decimalResult = (BI.parseInt(stringNumber1.numDecimal) + BI.parseInt(stringNumber2.numDecimal)).toString(); + + if (decimalResult !== "0") { + if (decimalResult.length <= stringNumber1.numDecimal.length) { + decimalResult = addZero(decimalResult, stringNumber1.numDecimal.length); + } else { + integerResult++;// 进一 + decimalResult = decimalResult.slice(1); + } } - }, + var result = integerResult + "." + decimalResult; + return BI.parseFloat(result); - setValue: function (v) { - this.storeValue = v; - this.popup.setValue(v); - this.trigger.setValue(v); - this._checkDynamicValue(v); - }, - getValue: function () { - return this.storeValue; - }, - getKey: function () { - return this.trigger.getKey(); + function addZero (resultTemp, length) { + var diff = length - resultTemp.length; + for (var i = 0; i < diff; i++) { + resultTemp = "0" + resultTemp; + } + return resultTemp; + } }, - hidePopupView: function () { - this.combo.hideView(); - } -}); -BI.shortcut("bi.multidate_combo", BI.MultiDateCombo); - -BI.MultiDateCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.MultiDateCombo.EVENT_FOCUS = "EVENT_FOCUS"; -BI.MultiDateCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiDateCombo.EVENT_VALID = "EVENT_VALID"; -BI.MultiDateCombo.EVENT_ERROR = "EVENT_ERROR"; -BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW = "BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW"; - -BI.extend(BI.MultiDateCombo, { - MULTI_DATE_YMD_CARD: 1, - MULTI_DATE_YEAR_CARD: 2, - MULTI_DATE_QUARTER_CARD: 3, - MULTI_DATE_MONTH_CARD: 4, - MULTI_DATE_WEEK_CARD: 5, - MULTI_DATE_DAY_CARD: 6 -}); -BI.extend(BI.MultiDateCombo, { - DATE_TYPE: { - MULTI_DATE_YEAR_PREV: 1, - MULTI_DATE_YEAR_AFTER: 2, - MULTI_DATE_YEAR_BEGIN: 3, - MULTI_DATE_YEAR_END: 4, - MULTI_DATE_MONTH_PREV: 5, - MULTI_DATE_MONTH_AFTER: 6, - MULTI_DATE_MONTH_BEGIN: 7, - MULTI_DATE_MONTH_END: 8, - MULTI_DATE_QUARTER_PREV: 9, - MULTI_DATE_QUARTER_AFTER: 10, - MULTI_DATE_QUARTER_BEGIN: 11, - MULTI_DATE_QUARTER_END: 12, - MULTI_DATE_WEEK_PREV: 13, - MULTI_DATE_WEEK_AFTER: 14, - MULTI_DATE_DAY_PREV: 15, - MULTI_DATE_DAY_AFTER: 16, - MULTI_DATE_DAY_TODAY: 17, - MULTI_DATE_PARAM: 18, - MULTI_DATE_CALENDAR: 19, - YEAR_QUARTER: 20, - YEAR_MONTH: 21, - YEAR_WEEK: 22, - YEAR_DAY: 23, - MONTH_WEEK: 24, - MONTH_DAY: 25, - YEAR: 26, - SAME_PERIOD: 27, - LAST_SAME_PERIOD: 28 - } -}); -/** - * 普通控件 - * - * @class BI.DayCard - * @extends BI.MultiDateCard - */ -BI.DayCard = BI.inherit(BI.MultiDateCard, { + _accurateMultiplication: function (num1, num2) {// 乘法分配律 + var stringNumber1 = this._stringNumberFactory(num1); + var stringNumber2 = this._stringNumberFactory(num2); + // 整数部分计算 + var integerResult = BI.parseInt(stringNumber1.numInteger) * BI.parseInt(stringNumber2.numInteger); + // num1的小数和num2的整数 + var dec1Int2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numDecimal) * BI.parseInt(stringNumber2.numInteger), stringNumber1.numDecimalLength); + // num1的整数和num2的小数 + var int1dec2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numInteger) * BI.parseInt(stringNumber2.numDecimal), stringNumber2.numDecimalLength); + // 小数*小数 + var dec1dec2 = this._accurateDivisionTenExponent(BI.parseInt(stringNumber1.numDecimal) * BI.parseInt(stringNumber2.numDecimal), (stringNumber1.numDecimalLength + stringNumber2.numDecimalLength)); - _defaultConfig: function () { - return $.extend(BI.DayCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-daycard" - }); + return this._accurateAddition(this._accurateAddition(this._accurateAddition(integerResult, dec1Int2), int1dec2), dec1dec2); }, - _init: function () { - BI.DayCard.superclass._init.apply(this, arguments); - }, + _accurateDivisionTenExponent: function (num, n) {// num/10^n && n>0 + var stringNumber = this._stringNumberFactory(num); + if (stringNumber.numInteger.length > n) { + var integerResult = stringNumber.numInteger.slice(0, (stringNumber.numInteger.length - n)); + var partDecimalResult = stringNumber.numInteger.slice(-n); + } else { + var integerResult = "0"; + var partDecimalResult = addZero(stringNumber.numInteger, n); + } + var result = integerResult + "." + partDecimalResult + stringNumber.numDecimal; + return BI.parseFloat(result); - dateConfig: function () { - return [{ - isEditorExist: true, - selected: true, - text: BI.i18nText("BI-Multi_Date_Day_Prev"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV - }, - { - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Day_Next"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER - }, - { - isEditorExist: false, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY, - text: BI.i18nText("BI-Multi_Date_Today") - }]; + function addZero (resultTemp, length) { + var diff = length - resultTemp.length; + for (var i = 0; i < diff; i++) { + resultTemp = "0" + resultTemp; + } + return resultTemp; + } }, - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV; - } -}); -BI.DayCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.daycard", BI.DayCard); -/** - * 普通控件 - * - * @class BI.MonthCard - * @extends BI.MultiDateCard - */ -BI.MonthCard = BI.inherit(BI.MultiDateCard, { - _defaultConfig: function () { - return $.extend(BI.MonthCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-monthcard" - }); + accurateSubtraction: function (num1, num2) { + if (num1 >= 0 && num2 >= 0) { + if (num1 >= num2) { + return this._accurateSubtraction(num1, num2); + } + return -this._accurateSubtraction(num2, num1); + } + if (num1 >= 0 && num2 < 0) { + return this._accurateAddition(num1, -num2); + } + if (num1 < 0 && num2 >= 0) { + return -this._accurateAddition(-num1, num2); + } + if (num1 < 0 && num2 < 0) { + if (num1 >= num2) { + return this._accurateSubtraction(-num2, -num1); + } + return this._accurateSubtraction(-num1, -num2); + } }, - _init: function () { - BI.MonthCard.superclass._init.apply(this, arguments); + accurateAddition: function (num1, num2) { + if (num1 >= 0 && num2 >= 0) { + return this._accurateAddition(num1, num2); + } + if (num1 >= 0 && num2 < 0) { + return this.accurateSubtraction(num1, -num2); + } + if (num1 < 0 && num2 >= 0) { + return this.accurateSubtraction(num2, -num1); + } + if (num1 < 0 && num2 < 0) { + return -this._accurateAddition(-num1, -num2); + } }, - dateConfig: function () { - return [{ - selected: true, - isEditorExist: true, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV, - text: BI.i18nText("BI-Multi_Date_Month_Prev") - }, - { - isEditorExist: true, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER, - text: BI.i18nText("BI-Multi_Date_Month_Next") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Month_Begin") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Month_End") - }]; + accurateMultiplication: function (num1, num2) { + if (num1 >= 0 && num2 >= 0) { + return this._accurateMultiplication(num1, num2); + } + if (num1 >= 0 && num2 < 0) { + return -this._accurateMultiplication(num1, -num2); + } + if (num1 < 0 && num2 >= 0) { + return -this._accurateMultiplication(-num1, num2); + } + if (num1 < 0 && num2 < 0) { + return this._accurateMultiplication(-num1, -num2); + } }, - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV; + accurateDivisionTenExponent: function (num1, n) { + if (num1 >= 0) { + return this._accurateDivisionTenExponent(num1, n); + } + return -this._accurateDivisionTenExponent(-num1, n); } -}); -BI.MonthCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.monthcard", BI.MonthCard); -/** - * 日期控件 - * @class BI.MultiDatePopup - * @extends BI.Widget +});/** + * 月份下拉框 + * + * Created by GUY on 2015/8/28. + * @class BI.MonthCombo + * @extends BI.Trigger */ -BI.MultiDatePopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30, - tabWidth: 42, - titleHeight: 27, - itemHeight: 30, - triggerHeight: 24, - buttonWidth: 90, - buttonHeight: 25, - cardHeight: 229, - cardWidth: 270, - popupHeight: 259, - popupWidth: 270, - comboAdjustHeight: 1, - ymdWidth: 58, - lgap: 2, - border: 1 - }, +BI.MonthCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiDatePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-popup", - height: 344 - }); - }, - _init: function () { - BI.MultiDatePopup.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - this.storeValue = ""; - this.textButton = BI.createWidget({ - type: "bi.text_button", - forceCenter: true, - cls: "bi-multidate-popup-label bi-border-left bi-border-right bi-border-top", - shadow: true, - text: BI.i18nText("BI-Multi_Date_Today") - }); - this.textButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE); - }); - this.clearButton = BI.createWidget({ - type: "bi.text_button", - forceCenter: true, - cls: "bi-multidate-popup-button bi-border-top", - shadow: true, - text: BI.i18nText("BI-Basic_Clear") - }); - this.clearButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE); - }); - this.okButton = BI.createWidget({ - type: "bi.text_button", - forceCenter: true, - cls: "bi-multidate-popup-button bi-border-top", - shadow: true, - text: BI.i18nText("BI-Basic_OK") - }); - this.okButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE); - }); - this.dateTab = BI.createWidget({ - type: "bi.tab", - tab: { - cls: "bi-border-bottom", - height: this.constants.tabHeight, - items: BI.createItems([{ - text: BI.i18nText("BI-Multi_Date_YMD"), - value: BI.MultiDateCombo.MULTI_DATE_YMD_CARD, - width: this.constants.ymdWidth - }, { - text: BI.i18nText("BI-Multi_Date_Year"), - value: BI.MultiDateCombo.MULTI_DATE_YEAR_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Quarter"), - value: BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Month"), - value: BI.MultiDateCombo.MULTI_DATE_MONTH_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Week"), - value: BI.MultiDateCombo.MULTI_DATE_WEEK_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Day"), - value: BI.MultiDateCombo.MULTI_DATE_DAY_CARD - }], { - width: this.constants.tabWidth, - textAlign: "center", - height: this.constants.itemHeight, - cls: "bi-multidate-popup-item bi-list-item-active" - }), - layouts: [{ - type: "bi.left" - }] - }, - cardCreator: function (v) { - switch (v) { - case BI.MultiDateCombo.MULTI_DATE_YMD_CARD: - self.ymd = BI.createWidget({ - type: "bi.date_calendar_popup", - min: self.options.min, - max: self.options.max - }); - self.ymd.on(BI.DateCalendarPopup.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.CALENDAR_EVENT_CHANGE); - }); - return self.ymd; - case BI.MultiDateCombo.MULTI_DATE_YEAR_CARD: - self.year = BI.createWidget({ - type: "bi.yearcard" - }); - self.year.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.year, v); - }); - return self.year; - case BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD: - self.quarter = BI.createWidget({ - type: "bi.quartercard" - }); - self.quarter.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.quarter, v); - }); - return self.quarter; - case BI.MultiDateCombo.MULTI_DATE_MONTH_CARD: - self.month = BI.createWidget({ - type: "bi.monthcard" - }); - self.month.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.month, v); - }); - return self.month; - case BI.MultiDateCombo.MULTI_DATE_WEEK_CARD: - self.week = BI.createWidget({ - type: "bi.weekcard" - }); - self.week.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.week, v); - }); - return self.week; - case BI.MultiDateCombo.MULTI_DATE_DAY_CARD: - self.day = BI.createWidget({ - type: "bi.daycard" - }); - self.day.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.day, v); - }); - return self.day; - } + return BI.extend(BI.MonthCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-month-combo", + behaviors: {}, + height: 25 + }); + }, + _init: function () { + BI.MonthCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.trigger = BI.createWidget({ + type: "bi.month_trigger", + value: o.value + }); + + this.trigger.on(BI.MonthTrigger.EVENT_CONFIRM, function (v) { + if (self.combo.isViewVisible()) { + return; + } + if (this.getKey() && this.getKey() !== self.storeValue) { + self.setValue(this.getValue()); + } else if (!this.getKey()) { + self.setValue(); } + self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); }); - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_YMD_CARD; - this.dateTab.on(BI.Tab.EVENT_CHANGE, function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.MultiDateCombo.MULTI_DATE_YMD_CARD: - var date = this.getTab(self.cur).getCalculationValue(); - self.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - self._setInnerValue(self.ymd); - break; - case BI.MultiDateCombo.MULTI_DATE_YEAR_CARD: - self.year.setValue(self.storeValue); - self._setInnerValue(self.year); - break; - case BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD: - self.quarter.setValue(self.storeValue); - self._setInnerValue(self.quarter); - break; - case BI.MultiDateCombo.MULTI_DATE_MONTH_CARD: - self.month.setValue(self.storeValue); - self._setInnerValue(self.month); - break; - case BI.MultiDateCombo.MULTI_DATE_WEEK_CARD: - self.week.setValue(self.storeValue); - self._setInnerValue(self.week); - break; - case BI.MultiDateCombo.MULTI_DATE_DAY_CARD: - self.day.setValue(self.storeValue); - self._setInnerValue(self.day); - break; + this.trigger.on(BI.MonthTrigger.EVENT_FOCUS, function () { + self.storeValue = this.getKey(); + }); + this.trigger.on(BI.MonthTrigger.EVENT_START, function () { + self.combo.hideView(); + }); + this.trigger.on(BI.MonthTrigger.EVENT_STOP, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); } - self.cur = v; }); - this.dateButton = BI.createWidget({ - type: "bi.grid", - items: [[this.clearButton, this.textButton, this.okButton]] + + this.popup = BI.createWidget({ + type: "bi.month_popup", + behaviors: o.behaviors, + value: o.value }); - BI.createWidget({ - element: this, - type: "bi.vtape", - items: [{ - el: this.dateTab - }, { - el: this.dateButton, - height: 30 - }] + this.popup.on(BI.MonthPopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); }); - this.setValue(opts.value); - }, - _setInnerValue: function (obj) { - if (this.dateTab.getSelect() === BI.MultiDateCombo.MULTI_DATE_YMD_CARD) { - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - this.textButton.setEnable(true); - } else { - var date = obj.getCalculationValue(); - 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); + this.combo = BI.createWidget({ + type: "bi.combo", + element: this, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + el: this.popup + } + }); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW); + }); }, setValue: function (v) { - this.storeValue = v; - var self = this, date; - var type, value; - if (BI.isNotNull(v)) { - type = v.type || BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_CALENDAR; - value = v.value; - if (BI.isNull(value)) { - value = v; - } - } - switch (type) { - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YEAR_CARD); - this.year.setValue({type: type, value: value}); - this.cur = BI.MultiDateCombo.MULTI_DATE_YEAR_CARD; - self._setInnerValue(this.year); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD; - this.quarter.setValue({type: type, value: value}); - self._setInnerValue(this.quarter); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_MONTH_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_MONTH_CARD; - this.month.setValue({type: type, value: value}); - self._setInnerValue(this.month); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_WEEK_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_WEEK_CARD; - this.week.setValue({type: type, value: value}); - self._setInnerValue(this.week); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_DAY_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_DAY_CARD; - this.day.setValue({type: type, value: value}); - self._setInnerValue(this.day); - break; - default: - if (this._checkValueValid(value)) { - var date = BI.getDate(); - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); - this.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } else { - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); - this.ymd.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } - this.textButton.setEnable(true); - break; - } + this.trigger.setValue(v); + this.popup.setValue(v); }, + getValue: function () { - var tab = this.dateTab.getSelect(); - switch (tab) { - case BI.MultiDateCombo.MULTI_DATE_YMD_CARD: - return this.ymd.getValue(); - case BI.MultiDateCombo.MULTI_DATE_YEAR_CARD: - return this.year.getValue(); - case BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD: - return this.quarter.getValue(); - case BI.MultiDateCombo.MULTI_DATE_MONTH_CARD: - return this.month.getValue(); - case BI.MultiDateCombo.MULTI_DATE_WEEK_CARD: - return this.week.getValue(); - case BI.MultiDateCombo.MULTI_DATE_DAY_CARD: - return this.day.getValue(); + if (BI.isNull(this.popup)) { + return this.options.value || ""; + } else { + return this.popup.getValue() || ""; } } }); -BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.MultiDatePopup.CALENDAR_EVENT_CHANGE = "CALENDAR_EVENT_CHANGE"; -BI.shortcut("bi.multidate_popup", BI.MultiDatePopup); -/** - * 普通控件 + +BI.MonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.MonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.month_combo", BI.MonthCombo);/** + * 月份展示面板 * - * @class BI.QuarterCard - * @extends BI.MultiDateCard + * Created by GUY on 2015/9/2. + * @class BI.MonthPopup + * @extends BI.Trigger */ -BI.QuarterCard = BI.inherit(BI.MultiDateCard, { +BI.MonthPopup = BI.inherit(BI.Widget, { _defaultConfig: function () { - return $.extend(BI.QuarterCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-quartercard" + return BI.extend(BI.MonthPopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-month-popup", + behaviors: {} }); }, _init: function () { - BI.QuarterCard.superclass._init.apply(this, arguments); + BI.MonthPopup.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + // 纵向排列月 + var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; + var items = []; + items.push(month.slice(0, 2)); + items.push(month.slice(2, 4)); + items.push(month.slice(4, 6)); + items.push(month.slice(6, 8)); + items.push(month.slice(8, 10)); + items.push(month.slice(10, 12)); + items = BI.map(items, function (i, item) { + return BI.map(item, function (j, td) { + return { + type: "bi.text_item", + cls: "bi-list-item-active", + textAlign: "center", + whiteSpace: "nowrap", + once: false, + forceSelected: true, + height: 23, + width: 38, + value: td, + text: td + 1 + }; + }); + }); + + this.month = BI.createWidget({ + type: "bi.button_group", + element: this, + behaviors: o.behaviors, + items: BI.createItems(items, {}), + layouts: [BI.LogicFactory.createLogic("table", BI.extend({ + dynamic: true + }, { + columns: 2, + rows: 6, + columnSize: [1 / 2, 1 / 2], + rowSize: 25 + })), { + type: "bi.center_adapt", + vgap: 1, + hgap: 2 + }], + value: o.value + }); + + this.month.on(BI.Controller.EVENT_CHANGE, function (type) { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + if (type === BI.Events.CLICK) { + self.fireEvent(BI.MonthPopup.EVENT_CHANGE); + } + }); }, - dateConfig: function () { - return [{ - selected: true, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Quarter_Prev") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Quarter_Next") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Quarter_Begin") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Quarter_End") - }]; + getValue: function () { + return this.month.getValue()[0]; }, - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV; + setValue: function (v) { + this.month.setValue([v]); } }); -BI.QuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.quartercard", BI.QuarterCard); -/** - * 普通控件 +BI.MonthPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.month_popup", BI.MonthPopup);/** + * 月份trigger * - * @class BI.MultiDateSegment - * @extends BI.Single + * Created by GUY on 2015/8/21. + * @class BI.MonthTrigger + * @extends BI.Trigger */ -BI.MultiDateSegment = BI.inherit(BI.Single, { - constants: { - itemHeight: 24, - maxGap: 15, - minGap: 10, - textWidth: 60, - defaultEditorValue: "1" +BI.MonthTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + errorText: BI.i18nText("BI-Month_Trigger_Error_Text") }, _defaultConfig: function () { - return $.extend(BI.MultiDateSegment.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-segment", - text: "", - height: 30, - isEditorExist: true, - selected: false, - defaultEditorValue: "1" + return BI.extend(BI.MonthTrigger.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-month-trigger bi-border", + height: 24 }); }, - _init: function () { - BI.MultiDateSegment.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - this.radio = BI.createWidget({ - type: "bi.radio", - selected: opts.selected + BI.MonthTrigger.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) { + return v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 12); + }, + quitChecker: function (v) { + return false; + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true, + errorText: c.errorText }); - this.radio.on(BI.Controller.EVENT_CHANGE, function (v) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.MonthTrigger.EVENT_FOCUS); }); - this.textEditor = BI.createWidget({ - type: "bi.text_editor", - value: this.constants.defaultEditorValue, - title: function () { - return self.textEditor.getValue(); - }, - tipType: "success", - cls: "bi-multidate-editor", - width: this.constants.textWidth, - height: this.constants.itemHeight + this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.MonthTrigger.EVENT_CHANGE); }); - this.textEditor.on(BI.Controller.EVENT_CHANGE, function (v) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setValue(value); + self.editor.setTitle(value); + } + self.fireEvent(BI.MonthTrigger.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.MonthTrigger.EVENT_START); }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - cls: "bi-multidate-normal-label", - text: opts.text, - height: this.constants.itemHeight + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.MonthTrigger.EVENT_STOP); }); - this._createSegment(); - }, - _createSegment: function () { - if (this.options.isEditorExist === true) { - return BI.createWidget({ - element: this, - type: "bi.left", - items: [{ + BI.createWidget({ + element: this, + type: "bi.htape", + items: [ + { + el: this.editor + }, { el: { - type: "bi.center_adapt", - items: [this.radio], - height: this.constants.itemHeight + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Month"), + baseCls: "bi-trigger-month-text", + width: o.height }, - lgap: 0 - }, - { + width: o.height + }, { el: { - type: "bi.center_adapt", - items: [this.textEditor], - widgetName: "textEditor" + type: "bi.trigger_icon_button", + width: o.height }, - lgap: this.constants.maxGap - }, - { - el: this.text, - lgap: this.constants.minGap - }] - }); - } - return BI.createWidget({ - element: this, - type: "bi.left", - items: [{ - el: { - type: "bi.center_adapt", - items: [this.radio], - height: this.constants.itemHeight - }, - lgap: 0 - }, - { - el: this.text, - lgap: this.constants.maxGap - }] + width: o.height + } + ] }); + this.setValue(o.value); }, - setSelected: function (v) { - if (BI.isNotNull(this.radio)) { - this.radio.setSelected(v); - this.textEditor.setEnable(v); + setValue: function (v) { + if(BI.isNotNull(v)) { + this.editor.setState(v + 1); + this.editor.setValue(v + 1); + this.editor.setTitle(v + 1); + return; } + this.editor.setState(""); + this.editor.setValue(""); + this.editor.setTitle(""); }, - isSelected: function () { - return this.radio.isSelected(); + getKey: function () { + return this.editor.getValue() | 0; }, getValue: function () { - return this.options.value; - }, - getInputValue: function () { - return this.textEditor.getValue() | 0; - }, - setInputValue: function (v) { - this.textEditor.setValue(v); - }, - isEditorExist: function () { - return this.options.isEditorExist; - } -}); -BI.MultiDateSegment.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multidate_segment", BI.MultiDateSegment);/** - * 普通控件 - * - * @class BI.WeekCard - * @extends BI.MultiDateCard - */ -BI.WeekCard = BI.inherit(BI.MultiDateCard, { - _defaultConfig: function () { - return $.extend(BI.WeekCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-weekcard" - }); - }, - - _init: function () { - BI.WeekCard.superclass._init.apply(this, arguments); - }, - - dateConfig: function () { - return [{ - selected: true, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Week_Prev"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV - }, - { - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Week_Next"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER - }]; - }, - - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV; - } -}); -BI.WeekCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.weekcard", BI.WeekCard); -/** - * 普通控件 - * - * @class BI.YearCard - * @extends BI.MultiDateCard - */ -BI.YearCard = BI.inherit(BI.MultiDateCard, { - _defaultConfig: function () { - return $.extend(BI.YearCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-yearcard" - }); - }, - - _init: function () { - BI.YearCard.superclass._init.apply(this, arguments); - }, - - dateConfig: function () { - return [{ - selected: true, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Year_Prev"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV - }, - { - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Year_Next"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER - }, - { - isEditorExist: false, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN, - text: BI.i18nText("BI-Multi_Date_Year_Begin") - }, - { - isEditorExist: false, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END, - text: BI.i18nText("BI-Multi_Date_Year_End") - }]; - }, - - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV; + return this.editor.getValue() - 1; } }); -BI.YearCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.yearcard", BI.YearCard); -/** +BI.MonthTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.MonthTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.MonthTrigger.EVENT_START = "EVENT_START"; +BI.MonthTrigger.EVENT_STOP = "EVENT_STOP"; +BI.MonthTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.month_trigger", BI.MonthTrigger);/** * Created by roy on 15/8/14. */ BI.DownListCombo = BI.inherit(BI.Widget, { @@ -15555,1567 +12230,2186 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { }); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + _defaultState: function () { + this.trigger.stopEditing(); + this.combo.hideView(); + }, + + setValue: function (v) { + this.storeValue.value = v || {}; + this.combo.setValue({ + value: v || {} + }); + }, + + getValue: function () { + return this.storeValue.value; + }, + + populate: function () { + this.combo.populate.apply(this.combo, arguments); + } +}); + +BI.MultiTreeCombo.EVENT_CONFIRM = "MultiTreeCombo.EVENT_CONFIRM"; + +BI.shortcut("bi.multi_tree_combo", BI.MultiTreeCombo);/** + * 带加载的多选下拉面板 + * @class BI.MultiTreePopup + * @extends BI.Pane + */ +BI.MultiTreePopup = BI.inherit(BI.Pane, { + + _defaultConfig: function () { + return BI.extend(BI.MultiTreePopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-popup", + maxWidth: "auto", + minWidth: 100, + maxHeight: 400, + onLoaded: BI.emptyFn + }); + }, + + _init: function () { + BI.MultiTreePopup.superclass._init.apply(this, arguments); + + var self = this, opts = this.options; + + this.selectedValues = {}; + + this.tree = BI.createWidget({ + type: "bi.async_tree", + height: 400, + cls: "popup-view-tree", + itemsCreator: opts.itemsCreator, + onLoaded: opts.onLoaded, + value: opts.value || {} + }); + + this.popupView = BI.createWidget({ + type: "bi.multi_popup_view", + element: this, + stopPropagation: false, + maxWidth: opts.maxWidth, + minWidth: opts.minWidth, + maxHeight: opts.maxHeight, + buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], + el: this.tree + }); + + this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { + switch (index) { + case 0: + self.fireEvent(BI.MultiTreePopup.EVENT_CLICK_CLEAR); + break; + case 1: + self.fireEvent(BI.MultiTreePopup.EVENT_CLICK_CONFIRM); + break; + } + }); + + this.tree.on(BI.TreeView.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiTreePopup.EVENT_CHANGE); + }); + + this.tree.on(BI.TreeView.EVENT_AFTERINIT, function () { + self.fireEvent(BI.MultiTreePopup.EVENT_AFTERINIT); + }); + + }, + + getValue: function () { + return this.tree.getValue(); + }, + + setValue: function (v) { + v || (v = {}); + this.tree.setSelectedValue(v.value); + }, + + populate: function (config) { + this.tree.stroke(config); + }, + + hasChecked: function () { + return this.tree.hasChecked(); + }, + + resetHeight: function (h) { + this.popupView.resetHeight(h); + }, + + resetWidth: function (w) { + this.popupView.resetWidth(w); + } +}); + +BI.MultiTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.MultiTreePopup.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; +BI.MultiTreePopup.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; +BI.MultiTreePopup.EVENT_AFTERINIT = "EVENT_AFTERINIT"; + + +BI.shortcut("bi.multi_tree_popup_view", BI.MultiTreePopup);/** + * + * 在搜索框中输入文本弹出的面板 + * @class BI.MultiTreeSearchPane + * @extends BI.Pane + */ + +BI.MultiTreeSearchPane = BI.inherit(BI.Pane, { + + _defaultConfig: function () { + return BI.extend(BI.MultiTreeSearchPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-search-pane bi-card", + itemsCreator: BI.emptyFn, + keywordGetter: BI.emptyFn + }); + }, + + _init: function () { + BI.MultiTreeSearchPane.superclass._init.apply(this, arguments); + + var self = this, opts = this.options; + + this.partTree = BI.createWidget({ + type: "bi.part_tree", + element: this, + tipText: BI.i18nText("BI-No_Select"), + itemsCreator: function (op, callback) { + op.keyword = opts.keywordGetter(); + opts.itemsCreator(op, callback); + }, + value: opts.value + }); + + this.partTree.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + this.partTree.on(BI.TreeView.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiTreeSearchPane.EVENT_CHANGE); + }); + }, + + hasChecked: function () { + return this.partTree.hasChecked(); }, setValue: function (v) { - this.storeValue.value = v || {}; - this.combo.setValue({ - value: v || {} - }); + this.setSelectedValue(v.value); + }, + + setSelectedValue: function (v) { + v || (v = {}); + this.partTree.setSelectedValue(v); }, getValue: function () { - return this.storeValue.value; + return this.partTree.getValue(); }, - populate: function () { - this.combo.populate.apply(this.combo, arguments); + empty: function () { + this.partTree.empty(); + }, + + populate: function (op) { + this.partTree.stroke.apply(this.partTree, arguments); } }); -BI.MultiTreeCombo.EVENT_CONFIRM = "MultiTreeCombo.EVENT_CONFIRM"; +BI.MultiTreeSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multi_tree_combo", BI.MultiTreeCombo);/** - * 带加载的多选下拉面板 - * @class BI.MultiTreePopup - * @extends BI.Pane +BI.MultiTreeSearchPane.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; +BI.MultiTreeSearchPane.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; + +BI.shortcut("bi.multi_tree_search_pane", BI.MultiTreeSearchPane);/** + * 查看已选按钮 + * Created by guy on 15/11/3. + * @class BI.MultiTreeCheckSelectedButton + * @extends BI.Single */ -BI.MultiTreePopup = BI.inherit(BI.Pane, { +BI.MultiTreeCheckSelectedButton = BI.inherit(BI.Single, { + + _const: { + checkSelected: BI.i18nText("BI-Check_Selected") + }, _defaultConfig: function () { - return BI.extend(BI.MultiTreePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-popup", - maxWidth: "auto", - minWidth: 100, - maxHeight: 400, - onLoaded: BI.emptyFn + return BI.extend(BI.MultiTreeCheckSelectedButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-check-selected-button", + itemsCreator: BI.emptyFn }); }, _init: function () { - BI.MultiTreePopup.superclass._init.apply(this, arguments); - - var self = this, opts = this.options; + BI.MultiTreeCheckSelectedButton.superclass._init.apply(this, arguments); + var self = this; + this.indicator = BI.createWidget({ + type: "bi.icon_button", + cls: "check-font trigger-check-selected", + width: 15, + height: 15, + stopPropagation: true + }); - this.selectedValues = {}; + this.checkSelected = BI.createWidget({ + type: "bi.text_button", + cls: "trigger-check-selected", + invisible: true, + hgap: 4, + text: this._const.checkSelected, + textAlign: "center", + textHeight: 15 + }); + this.checkSelected.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); - this.tree = BI.createWidget({ - type: "bi.async_tree", - height: 400, - cls: "popup-view-tree", - itemsCreator: opts.itemsCreator, - onLoaded: opts.onLoaded, - value: opts.value || {} + this.checkSelected.on(BI.TextButton.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments); }); - this.popupView = BI.createWidget({ - type: "bi.multi_popup_view", + BI.createWidget({ + type: "bi.horizontal", element: this, - stopPropagation: false, - maxWidth: opts.maxWidth, - minWidth: opts.minWidth, - maxHeight: opts.maxHeight, - buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], - el: this.tree + items: [this.indicator, this.checkSelected] }); - this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { - switch (index) { - case 0: - self.fireEvent(BI.MultiTreePopup.EVENT_CLICK_CLEAR); - break; - case 1: - self.fireEvent(BI.MultiTreePopup.EVENT_CLICK_CONFIRM); - break; + this.element.hover(function () { + self.indicator.setVisible(false); + self.checkSelected.setVisible(true); + }, function () { + self.indicator.setVisible(true); + self.checkSelected.setVisible(false); + }); + this.setVisible(false); + }, + + setValue: function (v) { + v || (v = {}); + this.setVisible(BI.size(v.value) > 0); + } +}); + +BI.MultiTreeCheckSelectedButton.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.multi_tree_check_selected_button", BI.MultiTreeCheckSelectedButton);/** + * searcher + * Created by guy on 15/11/3. + * @class BI.MultiTreeSearcher + * @extends Widget + */ +BI.MultiTreeSearcher = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.MultiTreeSearcher.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-searcher", + itemsCreator: BI.emptyFn, + popup: {}, + + adapter: null, + masker: {} + }); + }, + + _init: function () { + BI.MultiTreeSearcher.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.editor = BI.createWidget({ + type: "bi.multi_select_editor", + height: o.height, + el: { + type: "bi.simple_state_editor", + height: o.height } }); - this.tree.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreePopup.EVENT_CHANGE); + this.searcher = BI.createWidget({ + type: "bi.searcher", + element: this, + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback({ + keyword: self.editor.getValue() + }); + }, + el: this.editor, + + popup: BI.extend({ + type: "bi.multi_tree_search_pane", + keywordGetter: function () { + return self.editor.getValue(); + }, + itemsCreator: function (op, callback) { + op.keyword = self.editor.getValue(); + o.itemsCreator(op, callback); + }, + value: o.value + }, o.popup), + + adapter: o.adapter, + masker: o.masker + }); + this.searcher.on(BI.Searcher.EVENT_START, function () { + self.fireEvent(BI.MultiTreeSearcher.EVENT_START); }); + this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { + if (this.hasMatched()) { - this.tree.on(BI.TreeView.EVENT_AFTERINIT, function () { - self.fireEvent(BI.MultiTreePopup.EVENT_AFTERINIT); + } + self.fireEvent(BI.MultiTreeSearcher.EVENT_PAUSE); + }); + this.searcher.on(BI.Searcher.EVENT_STOP, function () { + self.fireEvent(BI.MultiTreeSearcher.EVENT_STOP); + }); + this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiTreeSearcher.EVENT_CHANGE, arguments); }); + if (BI.isNotNull(o.value)) { + this.setState(o.value); + } + }, + adjustView: function () { + this.searcher.adjustView(); }, - getValue: function () { - return this.tree.getValue(); + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - setValue: function (v) { - v || (v = {}); - this.tree.setSelectedValue(v.value); + isSearching: function () { + return this.searcher.isSearching(); + }, + + stopSearch: function () { + this.searcher.stopSearch(); + }, + + getKeyword: function () { + return this.editor.getValue(); + }, + + hasMatched: function () { + return this.searcher.hasMatched(); + }, + + hasChecked: function () { + return this.searcher.getView() && this.searcher.getView().hasChecked(); + }, + + setState: function (ob) { + ob || (ob = {}); + ob.value || (ob.value = {}); + if (BI.isNumber(ob)) { + this.editor.setState(ob); + } else if (BI.size(ob.value) === 0) { + this.editor.setState(BI.Selection.None); + } else { + var text = ""; + BI.each(ob.value, function (name, children) { + var childNodes = getChildrenNode(children); + text += name + (childNodes === "" ? "" : (":" + childNodes)) + "; "; + }); + this.editor.setState(text); + } + + function getChildrenNode (ob) { + var text = ""; + var index = 0, size = BI.size(ob); + BI.each(ob, function (name, children) { + index++; + var childNodes = getChildrenNode(children); + text += name + (childNodes === "" ? "" : (":" + childNodes)) + (index === size ? "" : ","); + }); + return text; + } }, - populate: function (config) { - this.tree.stroke(config); + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); }, - hasChecked: function () { - return this.tree.hasChecked(); + getKey: function () { + return this.editor.getValue(); }, - resetHeight: function (h) { - this.popupView.resetHeight(h); + getValue: function () { + return this.searcher.getValue(); }, - resetWidth: function (w) { - this.popupView.resetWidth(w); + populate: function (items) { + this.searcher.populate.apply(this.searcher, arguments); } }); -BI.MultiTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiTreePopup.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; -BI.MultiTreePopup.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; -BI.MultiTreePopup.EVENT_AFTERINIT = "EVENT_AFTERINIT"; - - -BI.shortcut("bi.multi_tree_popup_view", BI.MultiTreePopup);/** - * - * 在搜索框中输入文本弹出的面板 - * @class BI.MultiTreeSearchPane - * @extends BI.Pane +BI.MultiTreeSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.MultiTreeSearcher.EVENT_CHANGE = "EVENT_CHANGE"; +BI.MultiTreeSearcher.EVENT_START = "EVENT_START"; +BI.MultiTreeSearcher.EVENT_STOP = "EVENT_STOP"; +BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE"; +BI.shortcut("bi.multi_tree_searcher", BI.MultiTreeSearcher);/** + * Created by windy on 2017/3/13. + * 数值微调器 */ - -BI.MultiTreeSearchPane = BI.inherit(BI.Pane, { - +BI.NumberEditor = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiTreeSearchPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-search-pane bi-card", - itemsCreator: BI.emptyFn, - keywordGetter: BI.emptyFn + return BI.extend(BI.NumberEditor.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-number-editor bi-border", + validationChecker: function () { + return true; + }, + valueFormatter: function (v) { + return v; + }, + value: 0, + allowBlank: false, + errorText: "", + step: 1 }); }, _init: function () { - BI.MultiTreeSearchPane.superclass._init.apply(this, arguments); - - var self = this, opts = this.options; - - this.partTree = BI.createWidget({ - type: "bi.part_tree", - element: this, - tipText: BI.i18nText("BI-No_Select"), - itemsCreator: function (op, callback) { - op.keyword = opts.keywordGetter(); - opts.itemsCreator(op, callback); - }, - value: opts.value + BI.NumberEditor.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.editor = BI.createWidget({ + type: "bi.sign_editor", + height: o.height, + allowBlank: o.allowBlank, + value: o.valueFormatter(o.value), + validationChecker: o.validationChecker, + errorText: o.errorText }); - - this.partTree.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.editor.on(BI.TextEditor.EVENT_CHANGE, function () { + o.value = this.getValue(); + self.fireEvent(BI.NumberEditor.EVENT_CHANGE); }); - - this.partTree.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreeSearchPane.EVENT_CHANGE); + this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () { + this.setValue(BI.parseFloat(this.getValue())); + self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); + }); + this.topBtn = BI.createWidget({ + type: "bi.icon_button", + trigger: "lclick,", + cls: "column-pre-page-h-font top-button bi-border-left bi-border-bottom" + }); + this.topBtn.on(BI.IconButton.EVENT_CHANGE, function () { + self._finetuning(o.step); + self.fireEvent(BI.NumberEditor.EVENT_CHANGE); + self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); + }); + this.bottomBtn = BI.createWidget({ + type: "bi.icon_button", + trigger: "lclick,", + cls: "column-next-page-h-font bottom-button bi-border-left bi-border-top" + }); + this.bottomBtn.on(BI.IconButton.EVENT_CHANGE, function () { + self._finetuning(-o.step); + self.fireEvent(BI.NumberEditor.EVENT_CHANGE); + self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); + }); + BI.createWidget({ + type: "bi.htape", + element: this, + items: [this.editor, { + el: { + type: "bi.grid", + columns: 1, + rows: 2, + items: [{ + column: 0, + row: 0, + el: this.topBtn + }, { + column: 0, + row: 1, + el: this.bottomBtn + }] + }, + width: 23 + }] }); }, - hasChecked: function () { - return this.partTree.hasChecked(); + focus: function () { + this.editor.focus(); }, - setValue: function (v) { - this.setSelectedValue(v.value); + // 微调 + _finetuning: function (add) { + var v = BI.parseFloat(this.getValue()); + this.setValue(v.add(add)); }, - setSelectedValue: function (v) { - v || (v = {}); - this.partTree.setSelectedValue(v); + setUpEnable: function (v) { + this.topBtn.setEnable(!!v); }, - getValue: function () { - return this.partTree.getValue(); + setDownEnable: function (v) { + this.bottomBtn.setEnable(!!v); }, - empty: function () { - this.partTree.empty(); + getValue: function () { + return this.options.value; }, - populate: function (op) { - this.partTree.stroke.apply(this.partTree, arguments); + setValue: function (v) { + var o = this.options; + o.value = v; + this.editor.setValue(o.valueFormatter(v)); } -}); - -BI.MultiTreeSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.MultiTreeSearchPane.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; -BI.MultiTreeSearchPane.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; -BI.shortcut("bi.multi_tree_search_pane", BI.MultiTreeSearchPane);/** - * 查看已选按钮 - * Created by guy on 15/11/3. - * @class BI.MultiTreeCheckSelectedButton - * @extends BI.Single +}); +BI.NumberEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.NumberEditor.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.number_editor", BI.NumberEditor);// 小于号的值为:0,小于等于号的值为:1 +// closeMIn:最小值的符号,closeMax:最大值的符号 +/** + * Created by roy on 15/9/17. + * */ -BI.MultiTreeCheckSelectedButton = BI.inherit(BI.Single, { - - _const: { - checkSelected: BI.i18nText("BI-Check_Selected") +BI.NumberInterval = BI.inherit(BI.Single, { + constants: { + typeError: "typeBubble", + numberError: "numberBubble", + signalError: "signalBubble", + editorWidth: 114, + columns: 5, + width: 30, + rows: 1, + numberErrorCls: "number-error", + border: 1, + less: 0, + less_equal: 1, + numTip: "" }, - _defaultConfig: function () { - return BI.extend(BI.MultiTreeCheckSelectedButton.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-check-selected-button", - itemsCreator: BI.emptyFn + var conf = BI.NumberInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-number-interval", + height: 25, + validation: "valid" }); }, - _init: function () { - BI.MultiTreeCheckSelectedButton.superclass._init.apply(this, arguments); - var self = this; - this.indicator = BI.createWidget({ - type: "bi.icon_button", - cls: "check-font trigger-check-selected", - width: 15, - height: 15, - stopPropagation: true - }); - - this.checkSelected = BI.createWidget({ - type: "bi.text_button", - cls: "trigger-check-selected", - invisible: true, - hgap: 4, - text: this._const.checkSelected, - textAlign: "center", - textHeight: 15 - }); - this.checkSelected.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + var self = this, c = this.constants, o = this.options; + BI.NumberInterval.superclass._init.apply(this, arguments); + this.smallEditor = BI.createWidget({ + type: "bi.editor", + height: o.height - 2, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + allowBlank: true, + value: o.min, + level: "warning", + tipType: "warning", + quitChecker: function () { + return false; + }, + validationChecker: function (v) { + if (!BI.isNumeric(v)) { + self.smallEditorBubbleType = c.typeError; + return false; + } + return true; + }, + cls: "number-interval-small-editor bi-border-top bi-border-bottom bi-border-left" }); - this.checkSelected.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments); + this.smallTip = BI.createWidget({ + type: "bi.label", + text: o.numTip, + height: o.height - 2, + invisible: true }); - BI.createWidget({ - type: "bi.horizontal", - element: this, - items: [this.indicator, this.checkSelected] + type: "bi.absolute", + element: this.smallEditor.element, + items: [{ + el: this.smallTip, + top: 0, + right: 5 + }] }); - this.element.hover(function () { - self.indicator.setVisible(false); - self.checkSelected.setVisible(true); - }, function () { - self.indicator.setVisible(true); - self.checkSelected.setVisible(false); + this.bigEditor = BI.createWidget({ + type: "bi.editor", + height: o.height - 2, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + allowBlank: true, + value: o.max, + level: "warning", + tipType: "warning", + quitChecker: function () { + return false; + }, + validationChecker: function (v) { + if (!BI.isNumeric(v)) { + self.bigEditorBubbleType = c.typeError; + return false; + } + return true; + }, + cls: "number-interval-big-editor bi-border-top bi-border-bottom bi-border-right" }); - this.setVisible(false); - }, - - setValue: function (v) { - v || (v = {}); - this.setVisible(BI.size(v.value) > 0); - } -}); - -BI.MultiTreeCheckSelectedButton.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multi_tree_check_selected_button", BI.MultiTreeCheckSelectedButton);/** - * searcher - * Created by guy on 15/11/3. - * @class BI.MultiTreeSearcher - * @extends Widget - */ -BI.MultiTreeSearcher = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.MultiTreeSearcher.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-searcher", - itemsCreator: BI.emptyFn, - popup: {}, - adapter: null, - masker: {} + this.bigTip = BI.createWidget({ + type: "bi.label", + text: o.numTip, + height: o.height - 2, + invisible: true }); - }, - - _init: function () { - BI.MultiTreeSearcher.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget({ - type: "bi.multi_select_editor", - height: o.height, - el: { - type: "bi.simple_state_editor", - height: o.height - } + BI.createWidget({ + type: "bi.absolute", + element: this.bigEditor.element, + items: [{ + el: this.bigTip, + top: 0, + right: 5 + }] }); - this.searcher = BI.createWidget({ - type: "bi.searcher", - element: this, - isAutoSearch: false, - isAutoSync: false, - onSearch: function (op, callback) { - callback({ - keyword: self.editor.getValue() - }); - }, - el: this.editor, - - popup: BI.extend({ - type: "bi.multi_tree_search_pane", - keywordGetter: function () { - return self.editor.getValue(); - }, - itemsCreator: function (op, callback) { - op.keyword = self.editor.getValue(); - o.itemsCreator(op, callback); - }, - value: o.value - }, o.popup), - - adapter: o.adapter, - masker: o.masker + // this.smallCombo = BI.createWidget({ + // type: "bi.number_interval_combo", + // cls: "number-interval-small-combo", + // height: o.height, + // value: o.closemin ? 1 : 0, + // offsetStyle: "left" + // }); + // + // this.bigCombo = BI.createWidget({ + // type: "bi.number_interval_combo", + // cls: "number-interval-big-combo", + // height: o.height, + // value: o.closemax ? 1 : 0, + // offsetStyle: "left" + // }); + this.smallCombo = BI.createWidget({ + type: "bi.icon_combo", + cls: "number-interval-small-combo bi-border", + height: o.height - 2, + items: [{ + text: "(" + BI.i18nText("BI-Less_Than") + ")", + iconCls: "less-font", + value: 0 + }, { + text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", + value: 1, + iconCls: "less-equal-font" + }] }); - this.searcher.on(BI.Searcher.EVENT_START, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_START); + if (o.closemin === true) { + this.smallCombo.setValue(1); + } else { + this.smallCombo.setValue(0); + } + this.bigCombo = BI.createWidget({ + type: "bi.icon_combo", + cls: "number-interval-big-combo bi-border", + height: o.height - 2, + items: [{ + text: "(" + BI.i18nText("BI-Less_Than") + ")", + iconCls: "less-font", + value: 0 + }, { + text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", + value: 1, + iconCls: "less-equal-font" + }] }); - this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { - if (this.hasMatched()) { + if (o.closemax === true) { + this.bigCombo.setValue(1); + } else { + this.bigCombo.setValue(0); + } + this.label = BI.createWidget({ + type: "bi.label", + text: BI.i18nText("BI-Basic_Value"), + textHeight: o.height - c.border * 2, + width: c.width - c.border * 2, + height: o.height - c.border * 2, + level: "warning", + tipType: "warning" + }); + this.left = BI.createWidget({ + type: "bi.htape", + items: [{ + el: self.smallEditor + }, { + el: self.smallCombo, + width: c.width - c.border * 2 + }] - } - self.fireEvent(BI.MultiTreeSearcher.EVENT_PAUSE); }); - this.searcher.on(BI.Searcher.EVENT_STOP, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_STOP); + this.right = BI.createWidget({ + type: "bi.htape", + items: [{ + el: self.bigCombo, + width: c.width - c.border * 2 + }, { + el: self.bigEditor + }] }); - this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_CHANGE, arguments); + + + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: o.height, + items: [ + { + type: "bi.absolute", + items: [{ + el: self.left, + left: -15, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: -15, + top: 0, + bottom: 0 + }] + } + ] }); - if (BI.isNotNull(o.value)) { - this.setState(o.value); - } + + BI.createWidget({ + element: self, + type: "bi.horizontal_auto", + items: [ + self.label + ] + }); + + + self._setValidEvent(self.bigEditor, c.bigEditor); + self._setValidEvent(self.smallEditor, c.smallEditor); + self._setErrorEvent(self.bigEditor, c.bigEditor); + self._setErrorEvent(self.smallEditor, c.smallEditor); + self._setBlurEvent(self.bigEditor); + self._setBlurEvent(self.smallEditor); + self._setFocusEvent(self.bigEditor); + self._setFocusEvent(self.smallEditor); + self._setComboValueChangedEvent(self.bigCombo); + self._setComboValueChangedEvent(self.smallCombo); + self._setEditorValueChangedEvent(self.bigEditor); + self._setEditorValueChangedEvent(self.smallEditor); }, - adjustView: function () { - this.searcher.adjustView(); - }, + _checkValidation: function () { + var self = this, c = this.constants, o = this.options; + self._setTitle(""); + BI.Bubbles.hide(c.typeError); + BI.Bubbles.hide(c.numberError); + BI.Bubbles.hide(c.signalError); + if (!self.smallEditor.isValid() || !self.bigEditor.isValid()) { + self.element.removeClass("number-error"); + o.validation = "invalid"; + return c.typeError; + } + if (BI.isEmptyString(self.smallEditor.getValue()) || BI.isEmptyString(self.bigEditor.getValue())) { + self.element.removeClass("number-error"); + o.validation = "valid"; + return ""; + } + var smallValue = parseFloat(self.smallEditor.getValue()), bigValue = parseFloat(self.bigEditor.getValue()), + bigComboValue = self.bigCombo.getValue(), smallComboValue = self.smallCombo.getValue(); + if (bigComboValue[0] === c.less_equal && smallComboValue[0] === c.less_equal) { + if (smallValue > bigValue) { + self.element.addClass("number-error"); + o.validation = "invalid"; + return c.numberError; + } + self.element.removeClass("number-error"); + o.validation = "valid"; + return ""; - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); - }, + } + if (smallValue > bigValue) { + self.element.addClass("number-error"); + o.validation = "invalid"; + return c.numberError; + } else if (smallValue === bigValue) { + self.element.addClass("number-error"); + o.validation = "invalid"; + return c.signalError; + } + self.element.removeClass("number-error"); + o.validation = "valid"; + return ""; - isSearching: function () { - return this.searcher.isSearching(); - }, - stopSearch: function () { - this.searcher.stopSearch(); - }, - getKeyword: function () { - return this.editor.getValue(); - }, - hasMatched: function () { - return this.searcher.hasMatched(); - }, - hasChecked: function () { - return this.searcher.getView() && this.searcher.getView().hasChecked(); }, - setState: function (ob) { - ob || (ob = {}); - ob.value || (ob.value = {}); - if (BI.isNumber(ob)) { - this.editor.setState(ob); - } else if (BI.size(ob.value) === 0) { - this.editor.setState(BI.Selection.None); - } else { - var text = ""; - BI.each(ob.value, function (name, children) { - var childNodes = getChildrenNode(children); - text += name + (childNodes === "" ? "" : (":" + childNodes)) + "; "; - }); - this.editor.setState(text); - } - - function getChildrenNode (ob) { - var text = ""; - var index = 0, size = BI.size(ob); - BI.each(ob, function (name, children) { - index++; - var childNodes = getChildrenNode(children); - text += name + (childNodes === "" ? "" : (":" + childNodes)) + (index === size ? "" : ","); - }); - return text; - } + _setTitle: function (v) { + var self = this; + self.bigEditor.setTitle(v); + self.smallEditor.setTitle(v); + self.label.setTitle(v); }, - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); - }, + _setFocusEvent: function (w) { + var self = this, c = this.constants; + w.on(BI.Editor.EVENT_FOCUS, function () { + self._setTitle(""); + switch (self._checkValidation()) { + case c.typeError: + BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { + offsetStyle: "center" + }); + break; + case c.numberError: + BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { + offsetStyle: "center" + }); + break; + case c.signalError: + BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { + offsetStyle: "center" + }); + break; + default : + return; + } - getKey: function () { - return this.editor.getValue(); + }); + }, + _setBlurEvent: function (w) { + var c = this.constants, self = this; + w.on(BI.Editor.EVENT_BLUR, function () { + BI.Bubbles.hide(c.typeError); + BI.Bubbles.hide(c.numberError); + BI.Bubbles.hide(c.signalError); + switch (self._checkValidation()) { + case c.typeError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Input_Data")); + break; + case c.numberError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Number_Value")); + break; + case c.signalError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Signal_Value")); + break; + default: + self._setTitle(""); + } + }); }, - getValue: function () { - return this.searcher.getValue(); + _setErrorEvent: function (w) { + var c = this.constants, self = this; + w.on(BI.Editor.EVENT_ERROR, function () { + self._checkValidation(); + BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + }); }, - populate: function (items) { - this.searcher.populate.apply(this.searcher, arguments); - } -}); -BI.MultiTreeSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.MultiTreeSearcher.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiTreeSearcher.EVENT_START = "EVENT_START"; -BI.MultiTreeSearcher.EVENT_STOP = "EVENT_STOP"; -BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE"; -BI.shortcut("bi.multi_tree_searcher", BI.MultiTreeSearcher);/** - * Created by windy on 2017/3/13. - * 数值微调器 - */ -BI.NumberEditor = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.NumberEditor.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-number-editor bi-border", - validationChecker: function () { - return true; - }, - valueFormatter: function (v) { - return v; - }, - value: 0, - allowBlank: false, - errorText: "", - step: 1 + _setValidEvent: function (w) { + var self = this, c = this.constants; + w.on(BI.Editor.EVENT_VALID, function () { + switch (self._checkValidation()) { + case c.numberError: + BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + case c.signalError: + BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { + offsetStyle: "center" + }); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + default: + self.fireEvent(BI.NumberInterval.EVENT_VALID); + } }); }, - _init: function () { - BI.NumberEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget({ - type: "bi.sign_editor", - height: o.height, - allowBlank: o.allowBlank, - value: o.valueFormatter(o.value), - validationChecker: o.validationChecker, - errorText: o.errorText - }); - this.editor.on(BI.TextEditor.EVENT_CHANGE, function () { - o.value = this.getValue(); - self.fireEvent(BI.NumberEditor.EVENT_CHANGE); - }); - this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () { - this.setValue(BI.parseFloat(this.getValue())); - self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); - }); - this.topBtn = BI.createWidget({ - type: "bi.icon_button", - trigger: "lclick,", - cls: "column-pre-page-h-font top-button bi-border-left bi-border-bottom" - }); - this.topBtn.on(BI.IconButton.EVENT_CHANGE, function () { - self._finetuning(o.step); - self.fireEvent(BI.NumberEditor.EVENT_CHANGE); - self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); - }); - this.bottomBtn = BI.createWidget({ - type: "bi.icon_button", - trigger: "lclick,", - cls: "column-next-page-h-font bottom-button bi-border-left bi-border-top" - }); - this.bottomBtn.on(BI.IconButton.EVENT_CHANGE, function () { - self._finetuning(-o.step); - self.fireEvent(BI.NumberEditor.EVENT_CHANGE); - self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); + + _setEditorValueChangedEvent: function (w) { + var self = this, c = this.constants; + w.on(BI.Editor.EVENT_CHANGE, function () { + switch (self._checkValidation()) { + case c.typeError: + BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { + offsetStyle: "center" + }); + break; + case c.numberError: + BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { + offsetStyle: "center" + }); + break; + case c.signalError: + BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { + offsetStyle: "center" + }); + break; + default : + break; + } + self.fireEvent(BI.NumberInterval.EVENT_CHANGE); }); - BI.createWidget({ - type: "bi.htape", - element: this, - items: [this.editor, { - el: { - type: "bi.grid", - columns: 1, - rows: 2, - items: [{ - column: 0, - row: 0, - el: this.topBtn - }, { - column: 0, - row: 1, - el: this.bottomBtn - }] - }, - width: 23 - }] + }, + + _setComboValueChangedEvent: function (w) { + var self = this, c = this.constants; + w.on(BI.IconCombo.EVENT_CHANGE, function () { + switch (self._checkValidation()) { + case c.typeError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Input_Data")); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + case c.numberError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Number_Value")); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + case c.signalError: + self._setTitle(BI.i18nText("BI-Numerical_Interval_Signal_Value")); + self.fireEvent(BI.NumberInterval.EVENT_ERROR); + break; + default : + self.fireEvent(BI.NumberInterval.EVENT_CHANGE); + self.fireEvent(BI.NumberInterval.EVENT_VALID); + } }); }, - focus: function () { - this.editor.focus(); + isStateValid: function () { + return this.options.validation === "valid"; }, - // 微调 - _finetuning: function (add) { - var v = BI.parseFloat(this.getValue()); - this.setValue(v.add(add)); + setMinEnable: function (b) { + this.smallEditor.setEnable(b); }, - setUpEnable: function (v) { - this.topBtn.setEnable(!!v); + setCloseMinEnable: function (b) { + this.smallCombo.setEnable(b); }, - setDownEnable: function (v) { - this.bottomBtn.setEnable(!!v); + setMaxEnable: function (b) { + this.bigEditor.setEnable(b); }, - getValue: function () { - return this.options.value; + setCloseMaxEnable: function (b) { + this.bigCombo.setEnable(b); }, - setValue: function (v) { - var o = this.options; - o.value = v; - this.editor.setValue(o.valueFormatter(v)); - } + showNumTip: function () { + this.smallTip.setVisible(true); + this.bigTip.setVisible(true); + }, -}); -BI.NumberEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.NumberEditor.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.number_editor", BI.NumberEditor);// 小于号的值为:0,小于等于号的值为:1 -// closeMIn:最小值的符号,closeMax:最大值的符号 -/** - * Created by roy on 15/9/17. - * - */ -BI.NumberInterval = BI.inherit(BI.Single, { - constants: { - typeError: "typeBubble", - numberError: "numberBubble", - signalError: "signalBubble", - editorWidth: 114, - columns: 5, - width: 30, - rows: 1, - numberErrorCls: "number-error", - border: 1, - less: 0, - less_equal: 1, - numTip: "" + hideNumTip: function () { + this.smallTip.setVisible(false); + this.bigTip.setVisible(false); }, - _defaultConfig: function () { - var conf = BI.NumberInterval.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-number-interval", - height: 25, - validation: "valid" - }); + + setNumTip: function (numTip) { + this.smallTip.setText(numTip); + this.bigTip.setText(numTip); }, - _init: function () { - var self = this, c = this.constants, o = this.options; - BI.NumberInterval.superclass._init.apply(this, arguments); - this.smallEditor = BI.createWidget({ - type: "bi.editor", - height: o.height - 2, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - allowBlank: true, - value: o.min, - level: "warning", - tipType: "warning", - quitChecker: function () { - return false; - }, - validationChecker: function (v) { - if (!BI.isNumeric(v)) { - self.smallEditorBubbleType = c.typeError; - return false; - } - return true; - }, - cls: "number-interval-small-editor bi-border-top bi-border-bottom bi-border-left" - }); - this.smallTip = BI.createWidget({ - type: "bi.label", - text: o.numTip, - height: o.height - 2, - invisible: true - }); - BI.createWidget({ - type: "bi.absolute", - element: this.smallEditor.element, - items: [{ - el: this.smallTip, - top: 0, - right: 5 - }] - }); + getNumTip: function () { + return this.smallTip.getText(); + }, - this.bigEditor = BI.createWidget({ - type: "bi.editor", - height: o.height - 2, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - allowBlank: true, - value: o.max, - level: "warning", - tipType: "warning", - quitChecker: function () { - return false; - }, - validationChecker: function (v) { - if (!BI.isNumeric(v)) { - self.bigEditorBubbleType = c.typeError; - return false; - } - return true; - }, - cls: "number-interval-big-editor bi-border-top bi-border-bottom bi-border-right" - }); + setValue: function (data) { + data = data || {}; + var self = this, combo_value; + if (BI.isNumeric(data.min) || BI.isEmptyString(data.min)) { + self.smallEditor.setValue(data.min); + } - this.bigTip = BI.createWidget({ - type: "bi.label", - text: o.numTip, - height: o.height - 2, - invisible: true - }); - BI.createWidget({ - type: "bi.absolute", - element: this.bigEditor.element, - items: [{ - el: this.bigTip, - top: 0, - right: 5 - }] - }); + if (!BI.isNotNull(data.min)) { + self.smallEditor.setValue(""); + } - // this.smallCombo = BI.createWidget({ - // type: "bi.number_interval_combo", - // cls: "number-interval-small-combo", - // height: o.height, - // value: o.closemin ? 1 : 0, - // offsetStyle: "left" - // }); - // - // this.bigCombo = BI.createWidget({ - // type: "bi.number_interval_combo", - // cls: "number-interval-big-combo", - // height: o.height, - // value: o.closemax ? 1 : 0, - // offsetStyle: "left" - // }); - this.smallCombo = BI.createWidget({ - type: "bi.icon_combo", - cls: "number-interval-small-combo bi-border", - height: o.height - 2, - items: [{ - text: "(" + BI.i18nText("BI-Less_Than") + ")", - iconCls: "less-font", - value: 0 - }, { - text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", - value: 1, - iconCls: "less-equal-font" - }] - }); - if (o.closemin === true) { - this.smallCombo.setValue(1); + if (BI.isNumeric(data.max) || BI.isEmptyString(data.max)) { + self.bigEditor.setValue(data.max); + } + + if (!BI.isNotNull(data.max)) { + self.bigEditor.setValue(""); + } + + if (!BI.isNull(data.closemin)) { + if (data.closemin === true) { + combo_value = 1; + } else { + combo_value = 0; + } + self.smallCombo.setValue(combo_value); + } + + if (!BI.isNull(data.closemax)) { + if (data.closemax === true) { + combo_value = 1; + } else { + combo_value = 0; + } + self.bigCombo.setValue(combo_value); + } + }, + + + getValue: function () { + var self = this, value = {}, minComboValue = self.smallCombo.getValue(), maxComboValue = self.bigCombo.getValue(); + value.min = self.smallEditor.getValue(); + value.max = self.bigEditor.getValue(); + if (minComboValue[0] === 0) { + value.closemin = false; } else { - this.smallCombo.setValue(0); + value.closemin = true; } - this.bigCombo = BI.createWidget({ - type: "bi.icon_combo", - cls: "number-interval-big-combo bi-border", - height: o.height - 2, - items: [{ - text: "(" + BI.i18nText("BI-Less_Than") + ")", - iconCls: "less-font", - value: 0 - }, { - text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", - value: 1, - iconCls: "less-equal-font" - }] - }); - if (o.closemax === true) { - this.bigCombo.setValue(1); + + if (maxComboValue[0] === 0) { + value.closemax = false; } else { - this.bigCombo.setValue(0); + value.closemax = true; } - this.label = BI.createWidget({ - type: "bi.label", - text: BI.i18nText("BI-Basic_Value"), - textHeight: o.height - c.border * 2, - width: c.width - c.border * 2, - height: o.height - c.border * 2, - level: "warning", - tipType: "warning" + return value; + } +}); +BI.NumberInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.NumberInterval.EVENT_VALID = "EVENT_VALID"; +BI.NumberInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.shortcut("bi.number_interval", BI.NumberInterval);/** + * + * 表格 + * + * Created by GUY on 2015/9/22. + * @class BI.PageTableCell + * @extends BI.Single + */ +BI.PageTableCell = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.PageTableCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-page-table-cell", + text: "", + title: "" }); - this.left = BI.createWidget({ - type: "bi.htape", - items: [{ - el: self.smallEditor - }, { - el: self.smallCombo, - width: c.width - c.border * 2 - }] + }, - }); - this.right = BI.createWidget({ - type: "bi.htape", - items: [{ - el: self.bigCombo, - width: c.width - c.border * 2 - }, { - el: self.bigEditor - }] + _init: function () { + BI.PageTableCell.superclass._init.apply(this, arguments); + var label = BI.createWidget({ + type: "bi.label", + element: this, + textAlign: "left", + whiteSpace: "nowrap", + height: this.options.height, + text: this.options.text, + title: this.options.title, + value: this.options.value, + lgap: 5, + rgap: 5 }); + if (BI.isNotNull(this.options.styles) && BI.isObject(this.options.styles)) { + this.element.css(this.options.styles); + } + } +}); - BI.createWidget({ - element: self, - type: "bi.center", - hgap: 15, - height: o.height, - items: [ - { - type: "bi.absolute", - items: [{ - el: self.left, - left: -15, - right: 0, - top: 0, - bottom: 0 - }] - }, { - type: "bi.absolute", - items: [{ - el: self.right, - left: 0, - right: -15, - top: 0, - bottom: 0 - }] +BI.shortcut("bi.page_table_cell", BI.PageTableCell);/** + * 分页表格 + * + * Created by GUY on 2016/2/15. + * @class BI.PageTable + * @extends BI.Widget + */ +BI.PageTable = BI.inherit(BI.Widget, { + + _const: { + scrollWidth: 18, + minScrollWidth: 100 + }, + + _defaultConfig: function () { + return BI.extend(BI.PageTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-page-table", + el: { + type: "bi.sequence_table" + }, + pager: { + horizontal: { + pages: false, // 总页数 + curr: 1, // 初始化当前页, pages为数字时可用 + + hasPrev: BI.emptyFn, + hasNext: BI.emptyFn, + firstPage: 1, + lastPage: BI.emptyFn + }, + vertical: { + pages: false, // 总页数 + curr: 1, // 初始化当前页, pages为数字时可用 + + hasPrev: BI.emptyFn, + hasNext: BI.emptyFn, + firstPage: 1, + lastPage: BI.emptyFn } - ] - }); + }, - BI.createWidget({ - element: self, - type: "bi.horizontal_auto", - items: [ - self.label - ] - }); + itemsCreator: BI.emptyFn, + isNeedFreeze: false, // 是否需要冻结单元格 + freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 - self._setValidEvent(self.bigEditor, c.bigEditor); - self._setValidEvent(self.smallEditor, c.smallEditor); - self._setErrorEvent(self.bigEditor, c.bigEditor); - self._setErrorEvent(self.smallEditor, c.smallEditor); - self._setBlurEvent(self.bigEditor); - self._setBlurEvent(self.smallEditor); - self._setFocusEvent(self.bigEditor); - self._setFocusEvent(self.smallEditor); - self._setComboValueChangedEvent(self.bigCombo); - self._setComboValueChangedEvent(self.smallCombo); - self._setEditorValueChangedEvent(self.bigEditor); - self._setEditorValueChangedEvent(self.smallEditor); - }, + isNeedMerge: false, // 是否需要合并单元格 + mergeCols: [], // 合并的单元格列号 + mergeRule: BI.emptyFn, - _checkValidation: function () { - var self = this, c = this.constants, o = this.options; - self._setTitle(""); - BI.Bubbles.hide(c.typeError); - BI.Bubbles.hide(c.numberError); - BI.Bubbles.hide(c.signalError); - if (!self.smallEditor.isValid() || !self.bigEditor.isValid()) { - self.element.removeClass("number-error"); - o.validation = "invalid"; - return c.typeError; - } - if (BI.isEmptyString(self.smallEditor.getValue()) || BI.isEmptyString(self.bigEditor.getValue())) { - self.element.removeClass("number-error"); - o.validation = "valid"; - return ""; - } - var smallValue = parseFloat(self.smallEditor.getValue()), bigValue = parseFloat(self.bigEditor.getValue()), - bigComboValue = self.bigCombo.getValue(), smallComboValue = self.smallCombo.getValue(); - if (bigComboValue[0] === c.less_equal && smallComboValue[0] === c.less_equal) { - if (smallValue > bigValue) { - self.element.addClass("number-error"); - o.validation = "invalid"; - return c.numberError; - } - self.element.removeClass("number-error"); - o.validation = "valid"; - return ""; + columnSize: [], + minColumnSize: [], + maxColumnSize: [], + headerRowSize: 25, + rowSize: 25, - } - if (smallValue > bigValue) { - self.element.addClass("number-error"); - o.validation = "invalid"; - return c.numberError; - } else if (smallValue === bigValue) { - self.element.addClass("number-error"); - o.validation = "invalid"; - return c.signalError; - } - self.element.removeClass("number-error"); - o.validation = "valid"; - return ""; + regionColumnSize: [], + + headerCellStyleGetter: BI.emptyFn, + summaryCellStyleGetter: BI.emptyFn, + sequenceCellStyleGetter: BI.emptyFn, + + header: [], + items: [], // 二维数组 + + // 交叉表头 + crossHeader: [], + crossItems: [] + }); + }, + + _init: function () { + BI.PageTable.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.hCurr = 1; + this.vCurr = 1; + this.table = BI.createWidget(o.el, { + type: "bi.sequence_table", + width: o.width, + height: o.height && o.height - 30, + isNeedResize: true, + isResizeAdapt: false, + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, + isNeedMerge: o.isNeedMerge, + mergeCols: o.mergeCols, + mergeRule: o.mergeRule, - }, + columnSize: o.columnSize, + minColumnSize: o.minColumnSize, + maxColumnSize: o.maxColumnSize, + headerRowSize: o.headerRowSize, + rowSize: o.rowSize, - _setTitle: function (v) { - var self = this; - self.bigEditor.setTitle(v); - self.smallEditor.setTitle(v); - self.label.setTitle(v); - }, + regionColumnSize: o.regionColumnSize, - _setFocusEvent: function (w) { - var self = this, c = this.constants; - w.on(BI.Editor.EVENT_FOCUS, function () { - self._setTitle(""); - switch (self._checkValidation()) { - case c.typeError: - BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { - offsetStyle: "center" - }); - break; - case c.numberError: - BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { - offsetStyle: "center" - }); - break; - case c.signalError: - BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { - offsetStyle: "center" - }); - break; - default : - return; - } + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter, + header: o.header, + items: o.items, + // 交叉表头 + crossHeader: o.crossHeader, + crossItems: o.crossItems }); - }, - _setBlurEvent: function (w) { - var c = this.constants, self = this; - w.on(BI.Editor.EVENT_BLUR, function () { - BI.Bubbles.hide(c.typeError); - BI.Bubbles.hide(c.numberError); - BI.Bubbles.hide(c.signalError); - switch (self._checkValidation()) { - case c.typeError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Input_Data")); - break; - case c.numberError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Number_Value")); - break; - case c.signalError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Signal_Value")); - break; - default: - self._setTitle(""); - } + + this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { + self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { + o.regionColumnSize = this.getRegionColumnSize(); + o.columnSize = this.getColumnSize(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { + o.regionColumnSize = this.getRegionColumnSize(); + o.columnSize = this.getColumnSize(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); }); - }, - _setErrorEvent: function (w) { - var c = this.constants, self = this; - w.on(BI.Editor.EVENT_ERROR, function () { - self._checkValidation(); - BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { - offsetStyle: "center" + this.pager = BI.createWidget(o.pager, { + type: "bi.direction_pager", + height: 30 + }); + this.pager.on(BI.Pager.EVENT_CHANGE, function () { + var vpage = this.getVPage && this.getVPage(); + if (BI.isNull(vpage)) { + vpage = this.getCurrentPage(); + } + var hpage = this.getHPage && this.getHPage(); + o.itemsCreator({ + vpage: vpage, + hpage: hpage + }, function (items, header, crossItems, crossHeader) { + self.table.setVPage ? self.table.setVPage(vpage) : self.table.setValue(vpage); + self.table.setHPage && self.table.setHPage(hpage); + self.populate.apply(self, arguments); }); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); }); - }, - - _setValidEvent: function (w) { - var self = this, c = this.constants; - w.on(BI.Editor.EVENT_VALID, function () { - switch (self._checkValidation()) { - case c.numberError: - BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { - offsetStyle: "center" - }); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - case c.signalError: - BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { - offsetStyle: "center" - }); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - default: - self.fireEvent(BI.NumberInterval.EVENT_VALID); - } + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.table, + left: 0, + top: 0 + }, { + el: this.pager, + left: 0, + right: 0, + bottom: 0 + }] }); }, + setHPage: function (v) { + this.hCurr = v; + this.pager.setHPage && this.pager.setHPage(v); + this.table.setHPage && this.table.setHPage(v); + }, - _setEditorValueChangedEvent: function (w) { - var self = this, c = this.constants; - w.on(BI.Editor.EVENT_CHANGE, function () { - switch (self._checkValidation()) { - case c.typeError: - BI.Bubbles.show(c.typeError, BI.i18nText("BI-Numerical_Interval_Input_Data"), self, { - offsetStyle: "center" - }); - break; - case c.numberError: - BI.Bubbles.show(c.numberError, BI.i18nText("BI-Numerical_Interval_Number_Value"), self, { - offsetStyle: "center" - }); - break; - case c.signalError: - BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { - offsetStyle: "center" - }); - break; - default : - break; - } - self.fireEvent(BI.NumberInterval.EVENT_CHANGE); - }); + setVPage: function (v) { + this.vCurr = v; + this.pager.setVPage && this.pager.setVPage(v); + this.table.setVPage && this.table.setVPage(v); }, - _setComboValueChangedEvent: function (w) { - var self = this, c = this.constants; - w.on(BI.IconCombo.EVENT_CHANGE, function () { - switch (self._checkValidation()) { - case c.typeError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Input_Data")); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - case c.numberError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Number_Value")); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - case c.signalError: - self._setTitle(BI.i18nText("BI-Numerical_Interval_Signal_Value")); - self.fireEvent(BI.NumberInterval.EVENT_ERROR); - break; - default : - self.fireEvent(BI.NumberInterval.EVENT_CHANGE); - self.fireEvent(BI.NumberInterval.EVENT_VALID); - } - }); + getHPage: function () { + var hpage = this.pager.getHPage && this.pager.getHPage(); + if (BI.isNotNull(hpage)) { + return hpage; + } + hpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); + if (BI.isNotNull(hpage)) { + return hpage; + } + return this.hpage; }, - isStateValid: function () { - return this.options.validation === "valid"; + getVPage: function () { + var vpage = this.pager.getVPage && this.pager.getVPage(); + if (BI.isNotNull(vpage)) { + return vpage; + } + vpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); + if (BI.isNotNull(vpage)) { + return vpage; + } + return this.vpage; }, - setMinEnable: function (b) { - this.smallEditor.setEnable(b); + setWidth: function (width) { + BI.PageTable.superclass.setWidth.apply(this, arguments); + this.table.setWidth(width); }, - setCloseMinEnable: function (b) { - this.smallCombo.setEnable(b); + setHeight: function (height) { + BI.PageTable.superclass.setHeight.apply(this, arguments); + var showPager = false; + if (this.pager.alwaysShowPager) { + showPager = true; + } else if (this.pager.hasHNext && this.pager.hasHNext()) { + showPager = true; + } else if (this.pager.hasHPrev && this.pager.hasHPrev()) { + showPager = true; + } else if (this.pager.hasVNext && this.pager.hasVNext()) { + showPager = true; + } else if (this.pager.hasVPrev && this.pager.hasVPrev()) { + showPager = true; + } else if (this.pager.hasNext && this.pager.hasNext()) { + showPager = true; + } else if (this.pager.hasPrev && this.pager.hasPrev()) { + showPager = true; + } + this.table.setHeight(height - (showPager ? 30 : 0)); + }, + + setColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setColumnSize(columnSize); }, - setMaxEnable: function (b) { - this.bigEditor.setEnable(b); + getColumnSize: function () { + return this.table.getColumnSize(); }, - setCloseMaxEnable: function (b) { - this.bigCombo.setEnable(b); + setRegionColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setRegionColumnSize(columnSize); }, - showNumTip: function () { - this.smallTip.setVisible(true); - this.bigTip.setVisible(true); + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); }, - hideNumTip: function () { - this.smallTip.setVisible(false); - this.bigTip.setVisible(false); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); }, - setNumTip: function (numTip) { - this.smallTip.setText(numTip); - this.bigTip.setText(numTip); + setLeftHorizontalScroll: function (scrollLeft) { + this.table.setLeftHorizontalScroll(scrollLeft); }, - getNumTip: function () { - return this.smallTip.getText(); + setRightHorizontalScroll: function (scrollLeft) { + this.table.setRightHorizontalScroll(scrollLeft); }, - setValue: function (data) { - data = data || {}; - var self = this, combo_value; - if (BI.isNumeric(data.min) || BI.isEmptyString(data.min)) { - self.smallEditor.setValue(data.min); - } + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); + }, - if (!BI.isNotNull(data.min)) { - self.smallEditor.setValue(""); - } + restore: function () { + this.table.restore(); + }, - if (BI.isNumeric(data.max) || BI.isEmptyString(data.max)) { - self.bigEditor.setValue(data.max); - } + attr: function () { + BI.PageTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); + }, - if (!BI.isNotNull(data.max)) { - self.bigEditor.setValue(""); - } + populate: function () { + this.pager.populate(); + this.table.populate.apply(this.table, arguments); + }, - if (!BI.isNull(data.closemin)) { - if (data.closemin === true) { - combo_value = 1; - } else { - combo_value = 0; - } - self.smallCombo.setValue(combo_value); - } + destroy: function () { + this.table.destroy(); + this.pager && this.pager.destroy(); + BI.PageTable.superclass.destroy.apply(this, arguments); + } +}); +BI.shortcut("bi.page_table", BI.PageTable);/** + * 预览表列 + * + * Created by GUY on 2015/12/25. + * @class BI.PreviewTableCell + * @extends BI.Widget + */ +BI.PreviewTableCell = BI.inherit(BI.Widget, { - if (!BI.isNull(data.closemax)) { - if (data.closemax === true) { - combo_value = 1; - } else { - combo_value = 0; - } - self.bigCombo.setValue(combo_value); - } + _defaultConfig: function () { + return BI.extend(BI.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table-cell", + text: "" + }); }, + _init: function () { + BI.PreviewTableCell.superclass._init.apply(this, arguments); + var self = this, o = this.options; - getValue: function () { - var self = this, value = {}, minComboValue = self.smallCombo.getValue(), maxComboValue = self.bigCombo.getValue(); - value.min = self.smallEditor.getValue(); - value.max = self.bigEditor.getValue(); - if (minComboValue[0] === 0) { - value.closemin = false; - } else { - value.closemin = true; - } - - if (maxComboValue[0] === 0) { - value.closemax = false; - } else { - value.closemax = true; - } - return value; + BI.createWidget({ + type: "bi.label", + element: this, + textAlign: "left", + whiteSpace: "normal", + height: this.options.height, + text: this.options.text, + value: this.options.value + }); } }); -BI.NumberInterval.EVENT_CHANGE = "EVENT_CHANGE"; -BI.NumberInterval.EVENT_VALID = "EVENT_VALID"; -BI.NumberInterval.EVENT_ERROR = "EVENT_ERROR"; -BI.shortcut("bi.number_interval", BI.NumberInterval);/** - * - * 表格 +BI.shortcut("bi.preview_table_cell", BI.PreviewTableCell);/** + * 预览表 * - * Created by GUY on 2015/9/22. - * @class BI.PageTableCell - * @extends BI.Single + * Created by GUY on 2015/12/25. + * @class BI.PreviewTableHeaderCell + * @extends BI.Widget */ -BI.PageTableCell = BI.inherit(BI.Widget, { +BI.PreviewTableHeaderCell = BI.inherit(BI.Widget, { + _defaultConfig: function () { - return BI.extend(BI.PageTableCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-page-table-cell", - text: "", - title: "" + return BI.extend(BI.PreviewTableHeaderCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table-header-cell", + text: "" }); }, _init: function () { - BI.PageTableCell.superclass._init.apply(this, arguments); - var label = BI.createWidget({ + BI.PreviewTableHeaderCell.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + BI.createWidget({ type: "bi.label", element: this, textAlign: "left", - whiteSpace: "nowrap", + whiteSpace: "normal", height: this.options.height, text: this.options.text, - title: this.options.title, - value: this.options.value, - lgap: 5, - rgap: 5 + value: this.options.value + }); + } +}); +BI.shortcut("bi.preview_table_header_cell", BI.PreviewTableHeaderCell);/** + * 预览表 + * + * Created by GUY on 2015/12/25. + * @class BI.PreviewTable + * @extends BI.Widget + */ +BI.PreviewTable = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.PreviewTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table", + isNeedFreeze: false, + freezeCols: [], + rowSize: null, + columnSize: [], + headerRowSize: 30, + header: [], + items: [] }); + }, - if (BI.isNotNull(this.options.styles) && BI.isObject(this.options.styles)) { - this.element.css(this.options.styles); + _init: function () { + BI.PreviewTable.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.table = BI.createWidget({ + type: "bi.table_view", + element: this, + isNeedResize: false, + + isResizeAdapt: false, + + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, + + rowSize: o.rowSize, + columnSize: o.columnSize, + headerRowSize: o.headerRowSize, + + header: BI.map(o.header, function (i, items) { + return BI.map(items, function (j, item) { + return BI.extend({ + type: "bi.preview_table_header_cell" + }, item); + }); + }), + items: BI.map(o.items, function (i, items) { + return BI.map(items, function (j, item) { + return BI.extend({ + type: "bi.preview_table_cell" + }, item); + }); + }) + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { + self._adjustColumns(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { + self._adjustColumns(); + }); + }, + + // 是否有自适应调节的列,即列宽为"" + _hasAdaptCol: function (columnSize) { + return BI.any(columnSize, function (i, size) { + return size === ""; + }); + }, + + _isPercentage: function (columnSize) { + return columnSize[0] <= 1; + }, + + _adjustColumns: function () { + var self = this, o = this.options; + if (o.isNeedFreeze === true) { + // 如果存在百分比的情况 + if (this._isPercentage(o.columnSize)) { + if (this._hasAdaptCol(o.columnSize)) { + var findCols = [], remain = 0; + BI.each(o.columnSize, function (i, size) { + if (size === "") { + findCols.push(i); + } else { + remain += size; + } + }); + remain = 1 - remain; + var average = remain / findCols.length; + BI.each(findCols, function (i, col) { + o.columnSize[col] = average; + }); + } + var isRight = BI.first(o.freezeCols) !== 0; + var freezeSize = [], notFreezeSize = []; + BI.each(o.columnSize, function (i, size) { + if (o.freezeCols.contains(i)) { + freezeSize.push(size); + } else { + notFreezeSize.push(size); + } + }); + var sumFreezeSize = BI.sum(freezeSize), sumNotFreezeSize = BI.sum(notFreezeSize); + BI.each(freezeSize, function (i, size) { + freezeSize[i] = size / sumFreezeSize; + }); + BI.each(notFreezeSize, function (i, size) { + notFreezeSize[i] = size / sumNotFreezeSize; + }); + this.table.setRegionColumnSize(isRight ? ["fill", sumFreezeSize] : [sumFreezeSize, "fill"]); + this.table.setColumnSize(isRight ? (notFreezeSize.concat(freezeSize)) : (freezeSize.concat(notFreezeSize))); + } + } else { + // 如果存在自适应宽度的列或者是百分比计算的列,需要将整个表宽设为100% + if (this._hasAdaptCol(o.columnSize) || this._isPercentage(o.columnSize)) { + this.table.setRegionColumnSize(["100%"]); + } } - } -}); - -BI.shortcut("bi.page_table_cell", BI.PageTableCell);/** - * 分页表格 - * - * Created by GUY on 2016/2/15. - * @class BI.PageTable - * @extends BI.Widget - */ -BI.PageTable = BI.inherit(BI.Widget, { - - _const: { - scrollWidth: 18, - minScrollWidth: 100 }, - _defaultConfig: function () { - return BI.extend(BI.PageTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-page-table", - el: { - type: "bi.sequence_table" - }, - pager: { - horizontal: { - pages: false, // 总页数 - curr: 1, // 初始化当前页, pages为数字时可用 + setColumnSize: function (columnSize) { + return this.table.setColumnSize(columnSize); + }, - hasPrev: BI.emptyFn, - hasNext: BI.emptyFn, - firstPage: 1, - lastPage: BI.emptyFn - }, - vertical: { - pages: false, // 总页数 - curr: 1, // 初始化当前页, pages为数字时可用 + getColumnSize: function () { + return this.table.getColumnSize(); + }, - hasPrev: BI.emptyFn, - hasNext: BI.emptyFn, - firstPage: 1, - lastPage: BI.emptyFn - } - }, + getCalculateColumnSize: function () { + return this.table.getCalculateColumnSize(); + }, - itemsCreator: BI.emptyFn, + setHeaderColumnSize: function (columnSize) { + return this.table.setHeaderColumnSize(columnSize); + }, - isNeedFreeze: false, // 是否需要冻结单元格 - freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 + setRegionColumnSize: function (columnSize) { + return this.table.setRegionColumnSize(columnSize); + }, - isNeedMerge: false, // 是否需要合并单元格 - mergeCols: [], // 合并的单元格列号 - mergeRule: BI.emptyFn, + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); + }, - columnSize: [], - minColumnSize: [], - maxColumnSize: [], - headerRowSize: 25, - rowSize: 25, + getCalculateRegionColumnSize: function () { + return this.table.getCalculateRegionColumnSize(); + }, - regionColumnSize: [], + getCalculateRegionRowSize: function () { + return this.table.getCalculateRegionRowSize(); + }, - headerCellStyleGetter: BI.emptyFn, - summaryCellStyleGetter: BI.emptyFn, - sequenceCellStyleGetter: BI.emptyFn, + getClientRegionColumnSize: function () { + return this.table.getClientRegionColumnSize(); + }, - header: [], - items: [], // 二维数组 + getScrollRegionColumnSize: function () { + return this.table.getScrollRegionColumnSize(); + }, - // 交叉表头 - crossHeader: [], - crossItems: [] - }); + getScrollRegionRowSize: function () { + return this.table.getScrollRegionRowSize(); }, - _init: function () { - BI.PageTable.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.hCurr = 1; - this.vCurr = 1; + hasVerticalScroll: function () { + return this.table.hasVerticalScroll(); + }, - this.table = BI.createWidget(o.el, { - type: "bi.sequence_table", - width: o.width, - height: o.height && o.height - 30, + setVerticalScroll: function (scrollTop) { + return this.table.setVerticalScroll(scrollTop); + }, - isNeedResize: true, - isResizeAdapt: false, + setLeftHorizontalScroll: function (scrollLeft) { + return this.table.setLeftHorizontalScroll(scrollLeft); + }, - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, + setRightHorizontalScroll: function (scrollLeft) { + return this.table.setRightHorizontalScroll(scrollLeft); + }, - isNeedMerge: o.isNeedMerge, - mergeCols: o.mergeCols, - mergeRule: o.mergeRule, + getVerticalScroll: function () { + return this.table.getVerticalScroll(); + }, - columnSize: o.columnSize, - minColumnSize: o.minColumnSize, - maxColumnSize: o.maxColumnSize, - headerRowSize: o.headerRowSize, - rowSize: o.rowSize, + getLeftHorizontalScroll: function () { + return this.table.getLeftHorizontalScroll(); + }, - regionColumnSize: o.regionColumnSize, + getRightHorizontalScroll: function () { + return this.table.getRightHorizontalScroll(); + }, - headerCellStyleGetter: o.headerCellStyleGetter, - summaryCellStyleGetter: o.summaryCellStyleGetter, - sequenceCellStyleGetter: o.sequenceCellStyleGetter, + getColumns: function () { + return this.table.getColumns(); + }, - header: o.header, - items: o.items, - // 交叉表头 - crossHeader: o.crossHeader, - crossItems: o.crossItems + populate: function (items, header) { + this.table.populate(items, header); + } +}); +BI.PreviewTable.EVENT_CHANGE = "PreviewTable.EVENT_CHANGE"; +BI.shortcut("bi.preview_table", BI.PreviewTable);/** + * 季度下拉框 + * + * Created by GUY on 2015/8/28. + * @class BI.QuarterCombo + * @extends BI.Widget + */ +BI.QuarterCombo = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.QuarterCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-quarter-combo", + behaviors: {}, + height: 25 }); - - this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { - self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }, + _init: function () { + BI.QuarterCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.storeValue = ""; + this.trigger = BI.createWidget({ + type: "bi.quarter_trigger", + value: o.value }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); + + this.trigger.on(BI.QuarterTrigger.EVENT_FOCUS, function () { + self.storeValue = this.getKey(); }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); + this.trigger.on(BI.QuarterTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - - this.pager = BI.createWidget(o.pager, { - type: "bi.direction_pager", - height: 30 + this.trigger.on(BI.QuarterTrigger.EVENT_STOP, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } }); - this.pager.on(BI.Pager.EVENT_CHANGE, function () { - var vpage = this.getVPage && this.getVPage(); - if (BI.isNull(vpage)) { - vpage = this.getCurrentPage(); + this.trigger.on(BI.QuarterTrigger.EVENT_CONFIRM, function () { + if (self.combo.isViewVisible()) { + return; } - var hpage = this.getHPage && this.getHPage(); - o.itemsCreator({ - vpage: vpage, - hpage: hpage - }, function (items, header, crossItems, crossHeader) { - self.table.setVPage ? self.table.setVPage(vpage) : self.table.setValue(vpage); - self.table.setHPage && self.table.setHPage(hpage); - self.populate.apply(self, arguments); - }); + if (this.getKey() && this.getKey() !== self.storeValue) { + self.setValue(this.getKey()); + } else if (!this.getKey()) { + self.setValue(); + } + self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); }); - - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.table, - left: 0, - top: 0 - }, { - el: this.pager, - left: 0, - right: 0, - bottom: 0 - }] + this.popup = BI.createWidget({ + type: "bi.quarter_popup", + behaviors: o.behaviors, + value: o.value }); - }, - - setHPage: function (v) { - this.hCurr = v; - this.pager.setHPage && this.pager.setHPage(v); - this.table.setHPage && this.table.setHPage(v); - }, - - setVPage: function (v) { - this.vCurr = v; - this.pager.setVPage && this.pager.setVPage(v); - this.table.setVPage && this.table.setVPage(v); - }, - getHPage: function () { - var hpage = this.pager.getHPage && this.pager.getHPage(); - if (BI.isNotNull(hpage)) { - return hpage; - } - hpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); - if (BI.isNotNull(hpage)) { - return hpage; - } - return this.hpage; - }, + this.popup.on(BI.QuarterPopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); + }); - getVPage: function () { - var vpage = this.pager.getVPage && this.pager.getVPage(); - if (BI.isNotNull(vpage)) { - return vpage; - } - vpage = this.pager.getCurrentPage && this.pager.getCurrentPage(); - if (BI.isNotNull(vpage)) { - return vpage; - } - return this.vpage; + this.combo = BI.createWidget({ + type: "bi.combo", + element: this, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + el: this.popup + } + }); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW); + }); }, - setWidth: function (width) { - BI.PageTable.superclass.setWidth.apply(this, arguments); - this.table.setWidth(width); + setValue: function (v) { + this.trigger.setValue(v); + this.popup.setValue(v); }, - setHeight: function (height) { - BI.PageTable.superclass.setHeight.apply(this, arguments); - var showPager = false; - if (this.pager.alwaysShowPager) { - showPager = true; - } else if (this.pager.hasHNext && this.pager.hasHNext()) { - showPager = true; - } else if (this.pager.hasHPrev && this.pager.hasHPrev()) { - showPager = true; - } else if (this.pager.hasVNext && this.pager.hasVNext()) { - showPager = true; - } else if (this.pager.hasVPrev && this.pager.hasVPrev()) { - showPager = true; - } else if (this.pager.hasNext && this.pager.hasNext()) { - showPager = true; - } else if (this.pager.hasPrev && this.pager.hasPrev()) { - showPager = true; + getValue: function () { + if (BI.isNull(this.popup)) { + return this.options.value || ""; + } else { + return this.popup.getValue() || ""; } - this.table.setHeight(height - (showPager ? 30 : 0)); - }, + } +}); - setColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setColumnSize(columnSize); - }, +BI.QuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.quarter_combo", BI.QuarterCombo);/** + * 季度展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.QuarterPopup + * @extends BI.Trigger + */ +BI.QuarterPopup = BI.inherit(BI.Widget, { - getColumnSize: function () { - return this.table.getColumnSize(); + _defaultConfig: function () { + return BI.extend(BI.QuarterPopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-quarter-popup", + behaviors: {} + }); }, - setRegionColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setRegionColumnSize(columnSize); - }, + _init: function () { + BI.QuarterPopup.superclass._init.apply(this, arguments); + var self = this, o = this.options; - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); - }, + var items = [{ + text: Date._QN[1], + value: 1 + }, { + text: Date._QN[2], + value: 2 + }, { + text: Date._QN[3], + value: 3 + }, { + text: Date._QN[4], + value: 4 + }]; + items = BI.map(items, function (j, item) { + return BI.extend(item, { + type: "bi.text_item", + cls: "bi-list-item-active", + textAlign: "left", + whiteSpace: "nowrap", + once: false, + forceSelected: true, + height: 25 + }); + }); - getVerticalScroll: function () { - return this.table.getVerticalScroll(); - }, + this.quarter = BI.createWidget({ + type: "bi.button_group", + element: this, + behaviors: o.behaviors, + items: BI.createItems(items, {}), + layouts: [{ + type: "bi.vertical" + }], + value: o.value + }); - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); + this.quarter.on(BI.Controller.EVENT_CHANGE, function (type) { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + if (type === BI.Events.CLICK) { + self.fireEvent(BI.MonthPopup.EVENT_CHANGE); + } + }); }, - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + getValue: function () { + return this.quarter.getValue()[0]; }, - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); + setValue: function (v) { + this.quarter.setValue([v]); + } +}); +BI.QuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.quarter_popup", BI.QuarterPopup);/** + * 季度trigger + * + * Created by GUY on 2015/8/21. + * @class BI.QuarterTrigger + * @extends BI.Trigger + */ +BI.QuarterTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + textWidth: 40, + errorText: BI.i18nText("BI-Quarter_Trigger_Error_Text") }, - restore: function () { - this.table.restore(); + _defaultConfig: function () { + return BI.extend(BI.QuarterTrigger.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-quarter-trigger bi-border", + height: 24 + }); }, + _init: function () { + BI.QuarterTrigger.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) { + return v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 4); + }, + quitChecker: function (v) { + return false; + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true, + errorText: c.errorText + }); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_FOCUS); + }); + this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_CHANGE); + }); + this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setValue(value); + self.editor.setTitle(value); + } + self.fireEvent(BI.QuarterTrigger.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.QuarterTrigger.EVENT_START); + }); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_STOP); + }); - attr: function () { - BI.PageTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); + BI.createWidget({ + element: this, + type: "bi.htape", + items: [ + { + el: this.editor + }, { + el: { + type: "bi.text_button", + baseCls: "bi-trigger-quarter-text", + text: BI.i18nText("BI-Multi_Date_Quarter"), + width: c.textWidth + }, + width: c.textWidth + }, { + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height + } + ] + }); + this.setValue(o.value); }, - populate: function () { - this.pager.populate(); - this.table.populate.apply(this.table, arguments); + setValue: function (v) { + v = v || ""; + this.editor.setState(v); + this.editor.setValue(v); + this.editor.setTitle(v); }, - destroy: function () { - this.table.destroy(); - this.pager && this.pager.destroy(); - BI.PageTable.superclass.destroy.apply(this, arguments); + getKey: function () { + return this.editor.getValue(); } }); -BI.shortcut("bi.page_table", BI.PageTable);/** - * 预览表列 +BI.QuarterTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.QuarterTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.QuarterTrigger.EVENT_START = "EVENT_START"; +BI.QuarterTrigger.EVENT_STOP = "EVENT_STOP"; +BI.QuarterTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.shortcut("bi.quarter_trigger", BI.QuarterTrigger);/** + * 自适应宽度的表格 * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTableCell + * Created by GUY on 2016/2/3. + * @class BI.ResponisveTable * @extends BI.Widget */ -BI.PreviewTableCell = BI.inherit(BI.Widget, { +BI.ResponisveTable = BI.inherit(BI.Widget, { + + _const: { + perColumnSize: 100 + }, _defaultConfig: function () { - return BI.extend(BI.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table-cell", - text: "" + return BI.extend(BI.ResponisveTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-responsive-table", + isNeedFreeze: false, // 是否需要冻结单元格 + freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 + logic: { // 冻结的页面布局逻辑 + dynamic: false + }, + + isNeedMerge: false, // 是否需要合并单元格 + mergeCols: [], // 合并的单元格列号 + mergeRule: function (row1, row2) { // 合并规则, 默认相等时合并 + return BI.isEqual(row1, row2); + }, + + columnSize: [], + headerRowSize: 25, + footerRowSize: 25, + rowSize: 25, + + regionColumnSize: false, + + header: [], + footer: false, + items: [], // 二维数组 + + // 交叉表头 + crossHeader: [], + crossItems: [] }); }, _init: function () { - BI.PreviewTableCell.superclass._init.apply(this, arguments); + BI.ResponisveTable.superclass._init.apply(this, arguments); var self = this, o = this.options; - BI.createWidget({ - type: "bi.label", + this.table = BI.createWidget({ + type: "bi.table_view", element: this, - textAlign: "left", - whiteSpace: "normal", - height: this.options.height, - text: this.options.text, - value: this.options.value + logic: o.logic, + + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, + + isNeedMerge: o.isNeedMerge, + mergeCols: o.mergeCols, + mergeRule: o.mergeRule, + + columnSize: o.columnSize, + headerRowSize: o.headerRowSize, + footerRowSize: o.footerRowSize, + rowSize: o.rowSize, + + regionColumnSize: o.regionColumnSize, + + header: o.header, + footer: o.footer, + items: o.items, + // 交叉表头 + crossHeader: o.crossHeader, + crossItems: o.crossItems + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { + self._initRegionSize(); + self.table.resize(); + self._resizeHeader(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { + self._resizeRegion(); + self._resizeHeader(); + self.fireEvent(BI.Table.EVENT_TABLE_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { + self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_BEFORE_REGION_RESIZE, function () { + self.fireEvent(BI.Table.EVENT_TABLE_BEFORE_REGION_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_REGION_RESIZE, function () { + // important:在冻结并自适应列宽的情况下要随时变更表头宽度 + if (o.isNeedResize === true && self._isAdaptiveColumn()) { + self._resizeHeader(); + } + self.fireEvent(BI.Table.EVENT_TABLE_REGION_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { + self._resizeHeader(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); }); - } -}); -BI.shortcut("bi.preview_table_cell", BI.PreviewTableCell);/** - * 预览表 - * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTableHeaderCell - * @extends BI.Widget - */ -BI.PreviewTableHeaderCell = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.PreviewTableHeaderCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table-header-cell", - text: "" + this.table.on(BI.Table.EVENT_TABLE_BEFORE_COLUMN_RESIZE, function () { + self._resizeBody(); + self.fireEvent(BI.Table.EVENT_TABLE_BEFORE_COLUMN_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_COLUMN_RESIZE, function () { + self.fireEvent(BI.Table.EVENT_TABLE_COLUMN_RESIZE, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { + self._resizeRegion(); + self._resizeHeader(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); }); }, - _init: function () { - BI.PreviewTableHeaderCell.superclass._init.apply(this, arguments); - var self = this, o = this.options; + _initRegionSize: function () { + var o = this.options; + if (o.isNeedFreeze === true) { + var regionColumnSize = this.table.getRegionColumnSize(); + var maxWidth = this.table.element.width(); + if (!regionColumnSize[0] || (regionColumnSize[0] === "fill") || regionColumnSize[0] > maxWidth || regionColumnSize[1] > maxWidth) { + var freezeCols = o.freezeCols; + if (freezeCols.length === 0) { + this.table.setRegionColumnSize([0, "fill"]); + } else if (freezeCols.length > 0 && freezeCols.length < o.columnSize.length) { + var size = maxWidth / 3; + if (freezeCols.length > o.columnSize.length / 2) { + size = maxWidth * 2 / 3; + } + this.table.setRegionColumnSize([size, "fill"]); + } else { + this.table.setRegionColumnSize(["fill", 0]); + } + } + } + }, - BI.createWidget({ - type: "bi.label", - element: this, - textAlign: "left", - whiteSpace: "normal", - height: this.options.height, - text: this.options.text, - value: this.options.value - }); - } -}); -BI.shortcut("bi.preview_table_header_cell", BI.PreviewTableHeaderCell);/** - * 预览表 - * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTable - * @extends BI.Widget - */ -BI.PreviewTable = BI.inherit(BI.Widget, { + _getBlockSize: function () { + var o = this.options; + var columnSize = this.table.getCalculateColumnSize(); + if (o.isNeedFreeze === true) { + var columnSizeLeft = [], columnSizeRight = []; + BI.each(columnSize, function (i, size) { + if (o.freezeCols.contains(i)) { + columnSizeLeft.push(size); + } else { + columnSizeRight.push(size); + } + }); + // 因为有边框,所以加上数组长度的参数调整 + var sumLeft = BI.sum(columnSizeLeft) + columnSizeLeft.length, + sumRight = BI.sum(columnSizeRight) + columnSizeRight.length; + return { + sumLeft: sumLeft, + sumRight: sumRight, + left: columnSizeLeft, + right: columnSizeRight + }; + } + return { + size: columnSize, + sum: BI.sum(columnSize) + columnSize.length + }; + }, - _defaultConfig: function () { - return BI.extend(BI.PreviewTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table", - isNeedFreeze: false, - freezeCols: [], - rowSize: null, - columnSize: [], - headerRowSize: 30, - header: [], - items: [] - }); + _isAdaptiveColumn: function (columnSize) { + return !(BI.last(columnSize || this.table.getColumnSize()) > 1.05); }, - _init: function () { - BI.PreviewTable.superclass._init.apply(this, arguments); + _resizeHeader: function () { var self = this, o = this.options; + if (o.isNeedFreeze === true) { + // 若是当前处于自适应调节阶段 + if (this._isAdaptiveColumn()) { + var columnSize = this.table.getCalculateColumnSize(); + this.table.setHeaderColumnSize(columnSize); + } else { + var regionColumnSize = this.table.getClientRegionColumnSize(); + var block = this._getBlockSize(); + var sumLeft = block.sumLeft, sumRight = block.sumRight; + var columnSizeLeft = block.left, columnSizeRight = block.right; + columnSizeLeft[columnSizeLeft.length - 1] += regionColumnSize[0] - sumLeft; + columnSizeRight[columnSizeRight.length - 1] += regionColumnSize[1] - sumRight; - this.table = BI.createWidget({ - type: "bi.table_view", - element: this, - isNeedResize: false, + var newLeft = BI.clone(columnSizeLeft), newRight = BI.clone(columnSizeRight); + newLeft[newLeft.length - 1] = ""; + newRight[newRight.length - 1] = ""; + this.table.setColumnSize(newLeft.concat(newRight)); - isResizeAdapt: false, + block = self._getBlockSize(); + if (columnSizeLeft[columnSizeLeft.length - 1] < block.left[block.left.length - 1]) { + columnSizeLeft[columnSizeLeft.length - 1] = block.left[block.left.length - 1]; + } + if (columnSizeRight[columnSizeRight.length - 1] < block.right[block.right.length - 1]) { + columnSizeRight[columnSizeRight.length - 1] = block.right[block.right.length - 1]; + } - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, + self.table.setColumnSize(columnSizeLeft.concat(columnSizeRight)); + } + } else { + if (!this._isAdaptiveColumn()) { + var regionColumnSize = this.table.getClientRegionColumnSize(); + var block = this._getBlockSize(); + var sum = block.sum; + var size = block.size; - rowSize: o.rowSize, - columnSize: o.columnSize, - headerRowSize: o.headerRowSize, + size[size.length - 1] += regionColumnSize[0] - sum; - header: BI.map(o.header, function (i, items) { - return BI.map(items, function (j, item) { - return BI.extend({ - type: "bi.preview_table_header_cell" - }, item); - }); - }), - items: BI.map(o.items, function (i, items) { - return BI.map(items, function (j, item) { - return BI.extend({ - type: "bi.preview_table_cell" - }, item); - }); - }) - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { - self._adjustColumns(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { - self._adjustColumns(); - }); + var newSize = BI.clone(size); + newSize[newSize.length - 1] = ""; + this.table.setColumnSize(newSize); + block = this._getBlockSize(); + + if (size[size.length - 1] < block.size[block.size.length - 1]) { + size[size.length - 1] = block.size[block.size.length - 1]; + } + this.table.setColumnSize(size); + } + } }, - // 是否有自适应调节的列,即列宽为"" - _hasAdaptCol: function (columnSize) { - return BI.any(columnSize, function (i, size) { - return size === ""; - }); + _resizeBody: function () { + if (this._isAdaptiveColumn()) { + var columnSize = this.table.getCalculateColumnSize(); + this.setColumnSize(columnSize); + } }, - _isPercentage: function (columnSize) { - return columnSize[0] <= 1; + _adjustRegion: function () { + var o = this.options; + var regionColumnSize = this.table.getCalculateRegionColumnSize(); + if (o.isNeedFreeze === true && o.freezeCols.length > 0 && o.freezeCols.length < o.columnSize.length) { + var block = this._getBlockSize(); + var sumLeft = block.sumLeft, sumRight = block.sumRight; + if (sumLeft < regionColumnSize[0] || regionColumnSize[0] >= (sumLeft + sumRight)) { + this.table.setRegionColumnSize([sumLeft, "fill"]); + } + this._resizeRegion(); + } }, - _adjustColumns: function () { - var self = this, o = this.options; - if (o.isNeedFreeze === true) { - // 如果存在百分比的情况 - if (this._isPercentage(o.columnSize)) { - if (this._hasAdaptCol(o.columnSize)) { - var findCols = [], remain = 0; - BI.each(o.columnSize, function (i, size) { - if (size === "") { - findCols.push(i); - } else { - remain += size; - } - }); - remain = 1 - remain; - var average = remain / findCols.length; - BI.each(findCols, function (i, col) { - o.columnSize[col] = average; - }); + _resizeRegion: function () { + var o = this.options; + var regionColumnSize = this.table.getCalculateRegionColumnSize(); + if (o.isNeedFreeze === true && o.freezeCols.length > 0 && o.freezeCols.length < o.columnSize.length) { + var maxWidth = this.table.element.width(); + if (regionColumnSize[0] < 15 || regionColumnSize[1] < 15) { + var freezeCols = o.freezeCols; + var size = maxWidth / 3; + if (freezeCols.length > o.columnSize.length / 2) { + size = maxWidth * 2 / 3; } - var isRight = BI.first(o.freezeCols) !== 0; - var freezeSize = [], notFreezeSize = []; - BI.each(o.columnSize, function (i, size) { - if (o.freezeCols.contains(i)) { - freezeSize.push(size); - } else { - notFreezeSize.push(size); - } - }); - var sumFreezeSize = BI.sum(freezeSize), sumNotFreezeSize = BI.sum(notFreezeSize); - BI.each(freezeSize, function (i, size) { - freezeSize[i] = size / sumFreezeSize; - }); - BI.each(notFreezeSize, function (i, size) { - notFreezeSize[i] = size / sumNotFreezeSize; - }); - this.table.setRegionColumnSize(isRight ? ["fill", sumFreezeSize] : [sumFreezeSize, "fill"]); - this.table.setColumnSize(isRight ? (notFreezeSize.concat(freezeSize)) : (freezeSize.concat(notFreezeSize))); - } - } else { - // 如果存在自适应宽度的列或者是百分比计算的列,需要将整个表宽设为100% - if (this._hasAdaptCol(o.columnSize) || this._isPercentage(o.columnSize)) { - this.table.setRegionColumnSize(["100%"]); + this.table.setRegionColumnSize([size, "fill"]); } } }, + + resize: function () { + this.table.resize(); + this._resizeRegion(); + this._resizeHeader(); + }, + setColumnSize: function (columnSize) { - return this.table.setColumnSize(columnSize); + this.table.setColumnSize(columnSize); + this._adjustRegion(); + this._resizeHeader(); }, getColumnSize: function () { @@ -17127,11 +14421,14 @@ BI.PreviewTable = BI.inherit(BI.Widget, { }, setHeaderColumnSize: function (columnSize) { - return this.table.setHeaderColumnSize(columnSize); + this.table.setHeaderColumnSize(columnSize); + this._adjustRegion(); + this._resizeHeader(); }, setRegionColumnSize: function (columnSize) { - return this.table.setRegionColumnSize(columnSize); + this.table.setRegionColumnSize(columnSize); + this._resizeHeader(); }, getRegionColumnSize: function () { @@ -17163,15 +14460,15 @@ BI.PreviewTable = BI.inherit(BI.Widget, { }, setVerticalScroll: function (scrollTop) { - return this.table.setVerticalScroll(scrollTop); + this.table.setVerticalScroll(scrollTop); }, setLeftHorizontalScroll: function (scrollLeft) { - return this.table.setLeftHorizontalScroll(scrollLeft); + this.table.setLeftHorizontalScroll(scrollLeft); }, setRightHorizontalScroll: function (scrollLeft) { - return this.table.setRightHorizontalScroll(scrollLeft); + this.table.setRightHorizontalScroll(scrollLeft); }, getVerticalScroll: function () { @@ -17186,1725 +14483,1844 @@ BI.PreviewTable = BI.inherit(BI.Widget, { return this.table.getRightHorizontalScroll(); }, - getColumns: function () { - return this.table.getColumns(); + getColumns: function () { + return this.table.getColumns(); + }, + + attr: function () { + BI.ResponisveTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); + }, + + populate: function (items) { + var self = this, o = this.options; + this.table.populate.apply(this.table, arguments); + if (o.isNeedFreeze === true) { + BI.nextTick(function () { + self._initRegionSize(); + self.table.resize(); + self._resizeHeader(); + }); + } + } +}); +BI.shortcut("bi.responsive_table", BI.ResponisveTable);/** + * 加号表示的组节点 + * Created by GUY on 2015/9/6. + * @class BI.SelectTreeFirstPlusGroupNode + * @extends BI.NodeButton + */ +BI.SelectTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { + _defaultConfig: function () { + var conf = BI.SelectTreeFirstPlusGroupNode.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-select-tree-first-plus-group-node bi-list-item-active", + logic: { + dynamic: false + }, + id: "", + pId: "", + readonly: true, + open: false, + height: 25 + }); + }, + _init: function () { + BI.SelectTreeFirstPlusGroupNode.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.checkbox = BI.createWidget({ + type: "bi.first_tree_node_checkbox", + stopPropagation: true + }); + this.text = BI.createWidget({ + type: "bi.label", + textAlign: "left", + whiteSpace: "nowrap", + textHeight: o.height, + height: o.height, + hgap: o.hgap, + text: o.text, + value: o.value, + py: o.py + }); + this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + if (this.isSelected()) { + self.triggerExpand(); + } else { + self.triggerCollapse(); + } + } + }); + var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); + var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { + width: 25, + el: this.checkbox + }, this.text); + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { + items: items + })))); + }, + + isOnce: function () { + return true; + }, + + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); + }, + + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); + }, + + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); }, - populate: function (items, header) { - this.table.populate(items, header); + setOpened: function (v) { + BI.SelectTreeFirstPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } } }); -BI.PreviewTable.EVENT_CHANGE = "PreviewTable.EVENT_CHANGE"; -BI.shortcut("bi.preview_table", BI.PreviewTable);/** - * 季度下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.QuarterCombo - * @extends BI.Widget + +BI.shortcut("bi.select_tree_first_plus_group_node", BI.SelectTreeFirstPlusGroupNode);/** + * 加号表示的组节点 + * Created by GUY on 2015/9/6. + * @class BI.SelectTreeLastPlusGroupNode + * @extends BI.NodeButton */ -BI.QuarterCombo = BI.inherit(BI.Widget, { +BI.SelectTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, { _defaultConfig: function () { - return BI.extend(BI.QuarterCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-quarter-combo", - behaviors: {}, + var conf = BI.SelectTreeLastPlusGroupNode.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-select-tree-last-plus-group-node bi-list-item-active", + logic: { + dynamic: false + }, + id: "", + pId: "", + readonly: true, + open: false, height: 25 }); }, _init: function () { - BI.QuarterCombo.superclass._init.apply(this, arguments); + BI.SelectTreeLastPlusGroupNode.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.storeValue = ""; - this.trigger = BI.createWidget({ - type: "bi.quarter_trigger", - value: o.value - }); - - this.trigger.on(BI.QuarterTrigger.EVENT_FOCUS, function () { - self.storeValue = this.getKey(); - }); - this.trigger.on(BI.QuarterTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); + this.checkbox = BI.createWidget({ + type: "bi.last_tree_node_checkbox", + stopPropagation: true }); - this.trigger.on(BI.QuarterTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } + this.text = BI.createWidget({ + type: "bi.label", + textAlign: "left", + whiteSpace: "nowrap", + textHeight: o.height, + height: o.height, + hgap: o.hgap, + text: o.text, + value: o.value, + py: o.py }); - this.trigger.on(BI.QuarterTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; - } - if (this.getKey() && this.getKey() !== self.storeValue) { - self.setValue(this.getKey()); - } else if (!this.getKey()) { - self.setValue(); + this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + if (this.isSelected()) { + self.triggerExpand(); + } else { + self.triggerCollapse(); + } } - self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); - }); - this.popup = BI.createWidget({ - type: "bi.quarter_popup", - behaviors: o.behaviors, - value: o.value }); + var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); + var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { + width: 25, + el: this.checkbox + }, this.text); + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { + items: items + })))); + }, - this.popup.on(BI.QuarterPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); - }); + isOnce: function () { + return true; + }, - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - el: this.popup - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW); - }); + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); }, - setValue: function (v) { - this.trigger.setValue(v); - this.popup.setValue(v); + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - getValue: function () { - if (BI.isNull(this.popup)) { - return this.options.value || ""; - } else { - return this.popup.getValue() || ""; + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); + }, + + setOpened: function (v) { + BI.SelectTreeLastPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); } } }); -BI.QuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.quarter_combo", BI.QuarterCombo);/** - * 季度展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.QuarterPopup - * @extends BI.Trigger +BI.shortcut("bi.select_tree_last_plus_group_node", BI.SelectTreeLastPlusGroupNode);/** + * 加号表示的组节点 + * Created by GUY on 2015/9/6. + * @class BI.SelectTreeMidPlusGroupNode + * @extends BI.NodeButton */ -BI.QuarterPopup = BI.inherit(BI.Widget, { - +BI.SelectTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, { _defaultConfig: function () { - return BI.extend(BI.QuarterPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-quarter-popup", - behaviors: {} + var conf = BI.SelectTreeMidPlusGroupNode.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-select-tree-mid-plus-group-node bi-list-item-active", + logic: { + dynamic: false + }, + id: "", + pId: "", + readonly: true, + open: false, + height: 25 }); }, - _init: function () { - BI.QuarterPopup.superclass._init.apply(this, arguments); + BI.SelectTreeMidPlusGroupNode.superclass._init.apply(this, arguments); var self = this, o = this.options; - - var items = [{ - text: Date._QN[1], - value: 1 - }, { - text: Date._QN[2], - value: 2 - }, { - text: Date._QN[3], - value: 3 - }, { - text: Date._QN[4], - value: 4 - }]; - items = BI.map(items, function (j, item) { - return BI.extend(item, { - type: "bi.text_item", - cls: "bi-list-item-active", - textAlign: "left", - whiteSpace: "nowrap", - once: false, - forceSelected: true, - height: 25 - }); + this.checkbox = BI.createWidget({ + type: "bi.mid_tree_node_checkbox", + stopPropagation: true }); - - this.quarter = BI.createWidget({ - type: "bi.button_group", - element: this, - behaviors: o.behaviors, - items: BI.createItems(items, {}), - layouts: [{ - type: "bi.vertical" - }], - value: o.value + this.text = BI.createWidget({ + type: "bi.label", + textAlign: "left", + whiteSpace: "nowrap", + textHeight: o.height, + height: o.height, + hgap: o.hgap, + text: o.text, + value: o.value, + py: o.py }); - - this.quarter.on(BI.Controller.EVENT_CHANGE, function (type) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) { - self.fireEvent(BI.MonthPopup.EVENT_CHANGE); + if (this.isSelected()) { + self.triggerExpand(); + } else { + self.triggerCollapse(); + } } }); + var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); + var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { + width: 25, + el: this.checkbox + }, this.text); + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { + items: items + })))); + }, + + isOnce: function () { + return true; + }, + + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); + }, + + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - getValue: function () { - return this.quarter.getValue()[0]; + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); }, - setValue: function (v) { - this.quarter.setValue([v]); + setOpened: function (v) { + BI.SelectTreeMidPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } } }); -BI.QuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.quarter_popup", BI.QuarterPopup);/** - * 季度trigger - * - * Created by GUY on 2015/8/21. - * @class BI.QuarterTrigger - * @extends BI.Trigger + +BI.shortcut("bi.select_tree_mid_plus_group_node", BI.SelectTreeMidPlusGroupNode);/** + * @class BI.SelectTreeCombo + * @extends BI.Widget */ -BI.QuarterTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - textWidth: 40, - errorText: BI.i18nText("BI-Quarter_Trigger_Error_Text") - }, +BI.SelectTreeCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.QuarterTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-quarter-trigger bi-border", - height: 24 + return BI.extend(BI.SelectTreeCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-tree-combo", + height: 30, + text: "", + items: [], + value: "" }); }, + _init: function () { - BI.QuarterTrigger.superclass._init.apply(this, arguments); - var self = this, o = this.options, c = this._const; - this.editor = BI.createWidget({ - type: "bi.sign_editor", + BI.SelectTreeCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.trigger = BI.createWidget({ + type: "bi.single_tree_trigger", + text: o.text, height: o.height, - validationChecker: function (v) { - return v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 4); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true, - errorText: c.errorText - }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_FOCUS); - }); - this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_CHANGE); + items: o.items, + value: o.value }); - this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - self.editor.setTitle(value); - } - self.fireEvent(BI.QuarterTrigger.EVENT_CONFIRM); + + this.popup = BI.createWidget({ + type: "bi.select_level_tree", + items: o.items, + value: o.value }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); + + this.combo = BI.createWidget({ + type: "bi.combo", + element: this, + adjustLength: 2, + el: this.trigger, + popup: { + el: this.popup } }); - this.editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_START); - }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_STOP); + + this.combo.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [ - { - el: this.editor - }, { - el: { - type: "bi.text_button", - baseCls: "bi-trigger-quarter-text", - text: BI.i18nText("BI-Multi_Date_Quarter"), - width: c.textWidth - }, - width: c.textWidth - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - } - ] + this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); }); - this.setValue(o.value); }, setValue: function (v) { - v = v || ""; - this.editor.setState(v); - this.editor.setValue(v); - this.editor.setTitle(v); + v = BI.isArray(v) ? v : [v]; + this.trigger.setValue(v); + this.popup.setValue(v); }, - getKey: function () { - return this.editor.getValue(); + getValue: function () { + return this.popup.getValue(); + }, + + populate: function (items) { + this.combo.populate(items); } }); -BI.QuarterTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.QuarterTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.QuarterTrigger.EVENT_START = "EVENT_START"; -BI.QuarterTrigger.EVENT_STOP = "EVENT_STOP"; -BI.QuarterTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.shortcut("bi.quarter_trigger", BI.QuarterTrigger);/** - * 自适应宽度的表格 - * - * Created by GUY on 2016/2/3. - * @class BI.ResponisveTable + + +BI.shortcut("bi.select_tree_combo", BI.SelectTreeCombo);/** + * @class BI.SelectTreeExpander * @extends BI.Widget */ -BI.ResponisveTable = BI.inherit(BI.Widget, { - - _const: { - perColumnSize: 100 - }, +BI.SelectTreeExpander = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.ResponisveTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-responsive-table", - isNeedFreeze: false, // 是否需要冻结单元格 - freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 - logic: { // 冻结的页面布局逻辑 - dynamic: false - }, - - isNeedMerge: false, // 是否需要合并单元格 - mergeCols: [], // 合并的单元格列号 - mergeRule: function (row1, row2) { // 合并规则, 默认相等时合并 - return BI.isEqual(row1, row2); - }, - - columnSize: [], - headerRowSize: 25, - footerRowSize: 25, - rowSize: 25, - - regionColumnSize: false, - - header: [], - footer: false, - items: [], // 二维数组 - - // 交叉表头 - crossHeader: [], - crossItems: [] + return BI.extend(BI.SelectTreeExpander.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-tree-expander", + trigger: "click", + toggle: true, + direction: "bottom", + isDefaultInit: true, + el: {}, + popup: {} }); }, _init: function () { - BI.ResponisveTable.superclass._init.apply(this, arguments); + BI.SelectTreeExpander.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.table = BI.createWidget({ - type: "bi.table_view", - element: this, - logic: o.logic, - - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, - - isNeedMerge: o.isNeedMerge, - mergeCols: o.mergeCols, - mergeRule: o.mergeRule, - - columnSize: o.columnSize, - headerRowSize: o.headerRowSize, - footerRowSize: o.footerRowSize, - rowSize: o.rowSize, - - regionColumnSize: o.regionColumnSize, - - header: o.header, - footer: o.footer, - items: o.items, - // 交叉表头 - crossHeader: o.crossHeader, - crossItems: o.crossItems - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { - self._initRegionSize(); - self.table.resize(); - self._resizeHeader(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { - self._resizeRegion(); - self._resizeHeader(); - self.fireEvent(BI.Table.EVENT_TABLE_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { - self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_BEFORE_REGION_RESIZE, function () { - self.fireEvent(BI.Table.EVENT_TABLE_BEFORE_REGION_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_REGION_RESIZE, function () { - // important:在冻结并自适应列宽的情况下要随时变更表头宽度 - if (o.isNeedResize === true && self._isAdaptiveColumn()) { - self._resizeHeader(); - } - self.fireEvent(BI.Table.EVENT_TABLE_REGION_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { - self._resizeHeader(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); + this.trigger = BI.createWidget(BI.extend({stopPropagation: true}, o.el)); + this.trigger.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + if (this.isSelected()) { + self.expander.setValue([]); + } + } + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.table.on(BI.Table.EVENT_TABLE_BEFORE_COLUMN_RESIZE, function () { - self._resizeBody(); - self.fireEvent(BI.Table.EVENT_TABLE_BEFORE_COLUMN_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_COLUMN_RESIZE, function () { - self.fireEvent(BI.Table.EVENT_TABLE_COLUMN_RESIZE, arguments); + this.expander = BI.createWidget({ + type: "bi.expander", + element: this, + trigger: o.trigger, + toggle: o.toggle, + direction: o.direction, + isDefaultInit: o.isDefaultInit, + el: this.trigger, + popup: o.popup }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { - self._resizeRegion(); - self._resizeHeader(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); + this.expander.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + self.trigger.setSelected(false); + } + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); }, - _initRegionSize: function () { - var o = this.options; - if (o.isNeedFreeze === true) { - var regionColumnSize = this.table.getRegionColumnSize(); - var maxWidth = this.table.element.width(); - if (!regionColumnSize[0] || (regionColumnSize[0] === "fill") || regionColumnSize[0] > maxWidth || regionColumnSize[1] > maxWidth) { - var freezeCols = o.freezeCols; - if (freezeCols.length === 0) { - this.table.setRegionColumnSize([0, "fill"]); - } else if (freezeCols.length > 0 && freezeCols.length < o.columnSize.length) { - var size = maxWidth / 3; - if (freezeCols.length > o.columnSize.length / 2) { - size = maxWidth * 2 / 3; - } - this.table.setRegionColumnSize([size, "fill"]); - } else { - this.table.setRegionColumnSize(["fill", 0]); - } - } + setValue: function (v) { + if (BI.contains(v, this.trigger.getValue())) { + this.trigger.setSelected(true); + this.expander.setValue([]); + } else { + this.trigger.setSelected(false); + this.expander.setValue(v); } }, - _getBlockSize: function () { - var o = this.options; - var columnSize = this.table.getCalculateColumnSize(); - if (o.isNeedFreeze === true) { - var columnSizeLeft = [], columnSizeRight = []; - BI.each(columnSize, function (i, size) { - if (o.freezeCols.contains(i)) { - columnSizeLeft.push(size); - } else { - columnSizeRight.push(size); - } - }); - // 因为有边框,所以加上数组长度的参数调整 - var sumLeft = BI.sum(columnSizeLeft) + columnSizeLeft.length, - sumRight = BI.sum(columnSizeRight) + columnSizeRight.length; - return { - sumLeft: sumLeft, - sumRight: sumRight, - left: columnSizeLeft, - right: columnSizeRight - }; + getValue: function () { + if (this.trigger.isSelected()) { + return [this.trigger.getValue()]; } - return { - size: columnSize, - sum: BI.sum(columnSize) + columnSize.length - }; + return this.expander.getValue(); }, - _isAdaptiveColumn: function (columnSize) { - return !(BI.last(columnSize || this.table.getColumnSize()) > 1.05); - }, + populate: function (items) { + this.expander.populate(items); + } +}); - _resizeHeader: function () { - var self = this, o = this.options; - if (o.isNeedFreeze === true) { - // 若是当前处于自适应调节阶段 - if (this._isAdaptiveColumn()) { - var columnSize = this.table.getCalculateColumnSize(); - this.table.setHeaderColumnSize(columnSize); - } else { - var regionColumnSize = this.table.getClientRegionColumnSize(); - var block = this._getBlockSize(); - var sumLeft = block.sumLeft, sumRight = block.sumRight; - var columnSizeLeft = block.left, columnSizeRight = block.right; - columnSizeLeft[columnSizeLeft.length - 1] += regionColumnSize[0] - sumLeft; - columnSizeRight[columnSizeRight.length - 1] += regionColumnSize[1] - sumRight; +BI.shortcut("bi.select_tree_expander", BI.SelectTreeExpander);/** + * @class BI.SelectTreePopup + * @extends BI.Pane + */ - var newLeft = BI.clone(columnSizeLeft), newRight = BI.clone(columnSizeRight); - newLeft[newLeft.length - 1] = ""; - newRight[newRight.length - 1] = ""; - this.table.setColumnSize(newLeft.concat(newRight)); +BI.SelectTreePopup = BI.inherit(BI.Pane, { - block = self._getBlockSize(); - if (columnSizeLeft[columnSizeLeft.length - 1] < block.left[block.left.length - 1]) { - columnSizeLeft[columnSizeLeft.length - 1] = block.left[block.left.length - 1]; + _defaultConfig: function () { + return BI.extend(BI.SelectTreePopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-level-tree", + tipText: BI.i18nText("BI-No_Selected_Item"), + items: [], + value: "" + }); + }, + + _formatItems: function (nodes, layer) { + var self = this; + BI.each(nodes, function (i, node) { + var extend = {layer: layer}; + node.id = node.id || BI.UUID(); + if (node.isParent === true || BI.isNotEmptyArray(node.children)) { + switch (i) { + case 0 : + extend.type = "bi.select_tree_first_plus_group_node"; + break; + case nodes.length - 1 : + extend.type = "bi.select_tree_last_plus_group_node"; + break; + default : + extend.type = "bi.select_tree_mid_plus_group_node"; + break; } - if (columnSizeRight[columnSizeRight.length - 1] < block.right[block.right.length - 1]) { - columnSizeRight[columnSizeRight.length - 1] = block.right[block.right.length - 1]; + BI.defaults(node, extend); + self._formatItems(node.children); + } else { + switch (i) { + case nodes.length - 1: + extend.type = "bi.last_tree_leaf_item"; + break; + default : + extend.type = "bi.mid_tree_leaf_item"; } - - self.table.setColumnSize(columnSizeLeft.concat(columnSizeRight)); + BI.defaults(node, extend); } - } else { - if (!this._isAdaptiveColumn()) { - var regionColumnSize = this.table.getClientRegionColumnSize(); - var block = this._getBlockSize(); - var sum = block.sum; - var size = block.size; + }); + return nodes; + }, - size[size.length - 1] += regionColumnSize[0] - sum; + _init: function () { + BI.SelectTreePopup.superclass._init.apply(this, arguments); - var newSize = BI.clone(size); - newSize[newSize.length - 1] = ""; - this.table.setColumnSize(newSize); - block = this._getBlockSize(); + var self = this, o = this.options; - if (size[size.length - 1] < block.size[block.size.length - 1]) { - size[size.length - 1] = block.size[block.size.length - 1]; - } - this.table.setColumnSize(size); - } - } + this.tree = BI.createWidget({ + type: "bi.level_tree", + expander: { + type: "bi.select_tree_expander", + isDefaultInit: true + }, + items: this._formatItems(BI.Tree.transformToTreeFormat(o.items)), + value: o.value, + chooseType: BI.Selection.Single + }); + + BI.createWidget({ + type: "bi.vertical", + element: this, + items: [this.tree] + }); + + this.tree.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SelectTreePopup.EVENT_CHANGE); + }); + + this.check(); }, - _resizeBody: function () { - if (this._isAdaptiveColumn()) { - var columnSize = this.table.getCalculateColumnSize(); - this.setColumnSize(columnSize); - } + getValue: function () { + return this.tree.getValue(); }, - _adjustRegion: function () { - var o = this.options; - var regionColumnSize = this.table.getCalculateRegionColumnSize(); - if (o.isNeedFreeze === true && o.freezeCols.length > 0 && o.freezeCols.length < o.columnSize.length) { - var block = this._getBlockSize(); - var sumLeft = block.sumLeft, sumRight = block.sumRight; - if (sumLeft < regionColumnSize[0] || regionColumnSize[0] >= (sumLeft + sumRight)) { - this.table.setRegionColumnSize([sumLeft, "fill"]); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.tree.setValue(v); + }, + + populate: function (items) { + BI.SelectTreePopup.superclass.populate.apply(this, arguments); + this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(items))); + } +}); + +BI.SelectTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.select_level_tree", BI.SelectTreePopup);/** + * + * Created by GUY on 2016/8/10. + * @class BI.SequenceTableDynamicNumber + * @extends BI.SequenceTableTreeNumber + */ +BI.SequenceTableDynamicNumber = BI.inherit(BI.SequenceTableTreeNumber, { + + _defaultConfig: function () { + return BI.extend(BI.SequenceTableDynamicNumber.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-sequence-table-dynamic-number" + }); + }, + + _init: function () { + BI.SequenceTableDynamicNumber.superclass._init.apply(this, arguments); + }, + + _formatNumber: function (nodes) { + var self = this, o = this.options; + var result = []; + var count = this._getStart(nodes); + + function getLeafCount (node) { + var cnt = 0; + if (BI.isNotEmptyArray(node.children)) { + BI.each(node.children, function (index, child) { + cnt += getLeafCount(child); + }); + if (node.children.length > 1 && BI.isNotEmptyArray(node.values)) { + cnt++; + } + } else { + cnt++; } - this._resizeRegion(); + return cnt; } - }, - _resizeRegion: function () { - var o = this.options; - var regionColumnSize = this.table.getCalculateRegionColumnSize(); - if (o.isNeedFreeze === true && o.freezeCols.length > 0 && o.freezeCols.length < o.columnSize.length) { - var maxWidth = this.table.element.width(); - if (regionColumnSize[0] < 15 || regionColumnSize[1] < 15) { - var freezeCols = o.freezeCols; - var size = maxWidth / 3; - if (freezeCols.length > o.columnSize.length / 2) { - size = maxWidth * 2 / 3; + var start = 0, top = 0; + BI.each(nodes, function (i, node) { + if (BI.isArray(node.children)) { + BI.each(node.children, function (index, child) { + var cnt = getLeafCount(child); + result.push({ + text: count++, + start: start, + top: top, + cnt: cnt, + index: index, + height: cnt * o.rowSize + }); + start += cnt; + top += cnt * o.rowSize; + }); + if (BI.isNotEmptyArray(node.values)) { + result.push({ + text: BI.i18nText("BI-Summary_Values"), + start: start++, + top: top, + cnt: 1, + isSummary: true, + height: o.rowSize + }); + top += o.rowSize; } - this.table.setRegionColumnSize([size, "fill"]); } - } - }, + }); + return result; + } +}); +BI.shortcut("bi.sequence_table_dynamic_number", BI.SequenceTableDynamicNumber);/** + * + * Created by GUY on 2016/5/26. + * @class BI.SequenceTableListNumber + * @extends BI.Widget + */ +BI.SequenceTableListNumber = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.SequenceTableListNumber.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-sequence-table-list-number", + isNeedFreeze: false, + scrollTop: 0, + startSequence: 1, // 开始的序号 + headerRowSize: 25, + rowSize: 25, - resize: function () { - this.table.resize(); - this._resizeRegion(); - this._resizeHeader(); - }, + sequenceHeaderCreator: null, - setColumnSize: function (columnSize) { - this.table.setColumnSize(columnSize); - this._adjustRegion(); - this._resizeHeader(); - }, + header: [], + items: [], // 二维数组 - getColumnSize: function () { - return this.table.getColumnSize(); - }, + // 交叉表头 + crossHeader: [], + crossItems: [], - getCalculateColumnSize: function () { - return this.table.getCalculateColumnSize(); + pageSize: 20 + }); }, - setHeaderColumnSize: function (columnSize) { - this.table.setHeaderColumnSize(columnSize); - this._adjustRegion(); - this._resizeHeader(); - }, + _init: function () { + BI.SequenceTableListNumber.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.start = o.startSequence; + this.renderedCells = []; + this.renderedKeys = []; - setRegionColumnSize: function (columnSize) { - this.table.setRegionColumnSize(columnSize); - this._resizeHeader(); - }, + this.container = BI.createWidget({ + type: "bi.absolute", + width: 60, + scrollable: false + }); - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); - }, + this.scrollContainer = BI.createWidget({ + type: "bi.vertical", + scrollable: false, + scrolly: false, + items: [this.container] + }); - getCalculateRegionColumnSize: function () { - return this.table.getCalculateRegionColumnSize(); - }, + this.headerContainer = BI.createWidget({ + type: "bi.absolute", + cls: "bi-border", + width: 58, + scrollable: false + }); - getCalculateRegionRowSize: function () { - return this.table.getCalculateRegionRowSize(); + this.layout = BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.headerContainer, + height: o.headerRowSize * o.header.length - 2 + }, { + el: {type: "bi.layout"}, + height: 2 + }, { + el: this.scrollContainer + }] + }); + this._populate(); }, - getClientRegionColumnSize: function () { - return this.table.getClientRegionColumnSize(); + _layout: function () { + var self = this, o = this.options; + var headerHeight = o.headerRowSize * o.header.length - 2; + var items = this.layout.attr("items"); + if (o.isNeedFreeze === false) { + items[0].height = 0; + items[1].height = 0; + } else if (o.isNeedFreeze === true) { + items[0].height = headerHeight; + items[1].height = 2; + } + this.layout.attr("items", items); + this.layout.resize(); + this.container.setHeight(o.items.length * o.rowSize); + try { + this.scrollContainer.element.scrollTop(o.scrollTop); + } catch (e) { + + } }, - getScrollRegionColumnSize: function () { - return this.table.getScrollRegionColumnSize(); + _createHeader: function () { + var o = this.options; + BI.createWidget({ + type: "bi.absolute", + element: this.headerContainer, + items: [{ + el: o.sequenceHeaderCreator || { + type: "bi.table_style_cell", + cls: "sequence-table-title-cell", + styleGetter: o.headerCellStyleGetter, + text: BI.i18nText("BI-Number_Index") + }, + left: 0, + top: 0, + right: 0, + bottom: 0 + }] + }); }, - getScrollRegionRowSize: function () { - return this.table.getScrollRegionRowSize(); + _calculateChildrenToRender: function () { + var self = this, o = this.options; + var scrollTop = BI.clamp(o.scrollTop, 0, o.rowSize * o.items.length - (o.height - o.header.length * o.headerRowSize) + BI.DOM.getScrollWidth()); + var start = Math.floor(scrollTop / o.rowSize); + var end = start + Math.floor((o.height - o.header.length * o.headerRowSize) / o.rowSize); + var renderedCells = [], renderedKeys = []; + for (var i = start, cnt = 0; i <= end && i < o.items.length; i++, cnt++) { + var index = BI.deepIndexOf(this.renderedKeys, this.start + i); + var top = i * o.rowSize; + if (index > -1) { + if (o.rowSize !== this.renderedCells[index]._height) { + this.renderedCells[index]._height = o.rowSize; + this.renderedCells[index].el.setHeight(o.rowSize); + } + if (this.renderedCells[index].top !== top) { + this.renderedCells[index].top = top; + this.renderedCells[index].el.element.css("top", top + "px"); + } + renderedCells.push(this.renderedCells[index]); + } else { + var child = BI.createWidget(BI.extend({ + type: "bi.table_style_cell", + cls: "sequence-table-number-cell bi-border-left bi-border-right bi-border-bottom", + width: 60, + height: o.rowSize, + text: this.start + i, + styleGetter: function (index) { + return function () { + return o.sequenceCellStyleGetter(self.start + i - 1); + }; + }(cnt) + })); + renderedCells.push({ + el: child, + left: 0, + top: top, + _height: o.rowSize + }); + } + renderedKeys.push(this.start + i); + } + + // 已存在的, 需要添加的和需要删除的 + var existSet = {}, addSet = {}, deleteArray = []; + BI.each(renderedKeys, function (i, key) { + if (BI.deepContains(self.renderedKeys, key)) { + existSet[i] = key; + } else { + addSet[i] = key; + } + }); + BI.each(this.renderedKeys, function (i, key) { + if (BI.deepContains(existSet, key)) { + return; + } + if (BI.deepContains(addSet, key)) { + return; + } + deleteArray.push(i); + }); + BI.each(deleteArray, function (i, index) { + self.renderedCells[index].el.destroy(); + }); + var addedItems = []; + BI.each(addSet, function (index) { + addedItems.push(renderedCells[index]); + }); + BI.createWidget({ + type: "bi.absolute", + element: this.container, + items: addedItems + }); + this.renderedCells = renderedCells; + this.renderedKeys = renderedKeys; }, - hasVerticalScroll: function () { - return this.table.hasVerticalScroll(); + _populate: function () { + this.headerContainer.empty(); + this._createHeader(); + this._layout(); + this._calculateChildrenToRender(); }, setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); - }, - - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); - }, + if (this.options.scrollTop !== scrollTop) { + this.options.scrollTop = scrollTop; + try { + this.scrollContainer.element.scrollTop(scrollTop); + } catch (e) { - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + } + } }, getVerticalScroll: function () { - return this.table.getVerticalScroll(); - }, - - getLeftHorizontalScroll: function () { - return this.table.getLeftHorizontalScroll(); + return this.options.scrollTop; }, - getRightHorizontalScroll: function () { - return this.table.getRightHorizontalScroll(); + setVPage: function (v) { + v = v < 1 ? 1 : v; + var o = this.options; + this.start = (v - 1) * o.pageSize + 1; }, - getColumns: function () { - return this.table.getColumns(); + _restore: function () { + var o = this.options; + BI.each(this.renderedCells, function (i, cell) { + cell.el.destroy(); + }); + this.renderedCells = []; + this.renderedKeys = []; }, - attr: function () { - BI.ResponisveTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); + restore: function () { + this._restore(); }, - populate: function (items) { - var self = this, o = this.options; - this.table.populate.apply(this.table, arguments); - if (o.isNeedFreeze === true) { - BI.nextTick(function () { - self._initRegionSize(); - self.table.resize(); - self._resizeHeader(); - }); + populate: function (items, header) { + var o = this.options; + if (items && items !== this.options.items) { + o.items = items; + this._restore(); + } + if (header && header !== this.options.header) { + o.header = header; } + this._populate(); } }); -BI.shortcut("bi.responsive_table", BI.ResponisveTable);/** - * 加号表示的组节点 - * Created by GUY on 2015/9/6. - * @class BI.SelectTreeFirstPlusGroupNode - * @extends BI.NodeButton +BI.shortcut("bi.sequence_table_list_number", BI.SequenceTableListNumber);/** + * 带有序号的表格 + * + * Created by GUY on 2016/5/26. + * @class BI.SequenceTable + * @extends BI.Widget */ -BI.SelectTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { +BI.SequenceTable = BI.inherit(BI.Widget, { + _defaultConfig: function () { - var conf = BI.SelectTreeFirstPlusGroupNode.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-select-tree-first-plus-group-node bi-list-item-active", - logic: { - dynamic: false + return BI.extend(BI.SequenceTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-sequence-table", + el: { + type: "bi.adaptive_table" }, - id: "", - pId: "", - readonly: true, - open: false, - height: 25 + + sequence: {}, + + isNeedResize: true, + isResizeAdapt: false, + + isNeedFreeze: false, // 是否需要冻结单元格 + freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 + + isNeedMerge: false, // 是否需要合并单元格 + mergeCols: [], // 合并的单元格列号 + mergeRule: BI.emptyFn, + + columnSize: [], + minColumnSize: [], + maxColumnSize: [], + headerRowSize: 25, + rowSize: 25, + + regionColumnSize: [], + + headerCellStyleGetter: BI.emptyFn, + summaryCellStyleGetter: BI.emptyFn, + sequenceCellStyleGetter: BI.emptyFn, + + header: [], + items: [], // 二维数组 + + // 交叉表头 + crossHeader: [], + crossItems: [], + + showSequence: false, + startSequence: 1// 开始的序号 }); }, + _init: function () { - BI.SelectTreeFirstPlusGroupNode.superclass._init.apply(this, arguments); + BI.SequenceTable.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.checkbox = BI.createWidget({ - type: "bi.first_tree_node_checkbox", - stopPropagation: true + + this.sequence = BI.createWidget(o.sequence, { + type: "bi.sequence_table_list_number", + invisible: o.showSequence === false, + startSequence: o.startSequence, + isNeedFreeze: o.isNeedFreeze, + header: o.header, + items: o.items, + crossHeader: o.crossHeader, + crossItems: o.crossItems, + headerRowSize: o.headerRowSize, + rowSize: o.rowSize, + width: 60, + height: o.height && o.height - BI.GridTableScrollbar.SIZE, + + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - whiteSpace: "nowrap", - textHeight: o.height, + this.table = BI.createWidget(o.el, { + type: "bi.adaptive_table", + width: o.showSequence === true ? o.width - 60 : o.width, height: o.height, - hgap: o.hgap, - text: o.text, - value: o.value, - py: o.py - }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); - } - } - }); - var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); - var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { - width: 25, - el: this.checkbox - }, this.text); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { - items: items - })))); - }, + isNeedResize: o.isNeedResize, + isResizeAdapt: o.isResizeAdapt, - isOnce: function () { - return true; - }, + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); - }, + isNeedMerge: o.isNeedMerge, + mergeCols: o.mergeCols, + mergeRule: o.mergeRule, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); - }, + columnSize: o.columnSize, + minColumnSize: o.minColumnSize, + maxColumnSize: o.maxColumnSize, + headerRowSize: o.headerRowSize, + rowSize: o.rowSize, - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); - }, + regionColumnSize: o.regionColumnSize, - setOpened: function (v) { - BI.SelectTreeFirstPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } - } -}); + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter, -BI.shortcut("bi.select_tree_first_plus_group_node", BI.SelectTreeFirstPlusGroupNode);/** - * 加号表示的组节点 - * Created by GUY on 2015/9/6. - * @class BI.SelectTreeLastPlusGroupNode - * @extends BI.NodeButton - */ -BI.SelectTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, { - _defaultConfig: function () { - var conf = BI.SelectTreeLastPlusGroupNode.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-select-tree-last-plus-group-node bi-list-item-active", - logic: { - dynamic: false - }, - id: "", - pId: "", - readonly: true, - open: false, - height: 25 + header: o.header, + items: o.items, + // 交叉表头 + crossHeader: o.crossHeader, + crossItems: o.crossItems + }); + + this.table.on(BI.Table.EVENT_TABLE_SCROLL, function (scroll) { + if (self.sequence.getVerticalScroll() !== this.getVerticalScroll()) { + self.sequence.setVerticalScroll(this.getVerticalScroll()); + self.sequence.populate(); + } + self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }); - }, - _init: function () { - BI.SelectTreeLastPlusGroupNode.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.checkbox = BI.createWidget({ - type: "bi.last_tree_node_checkbox", - stopPropagation: true + this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { + o.regionColumnSize = this.getRegionColumnSize(); + o.columnSize = this.getColumnSize(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - whiteSpace: "nowrap", - textHeight: o.height, - height: o.height, - hgap: o.hgap, - text: o.text, - value: o.value, - py: o.py + this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { + o.regionColumnSize = this.getRegionColumnSize(); + o.columnSize = this.getColumnSize(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); - } - } + + this.htape = BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.sequence, + left: 0, + top: 0 + }, { + el: this.table, + top: 0, + left: o.showSequence === true ? 60 : 0 + }] }); - var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); - var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { - width: 25, - el: this.checkbox - }, this.text); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { - items: items - })))); + this._populate(); }, - isOnce: function () { - return true; + _populate: function () { + var o = this.options; + if (o.showSequence === true) { + this.sequence.setVisible(true); + this.table.element.css("left", "60px"); + this.table.setWidth(o.width - 60); + } else { + this.sequence.setVisible(false); + this.table.element.css("left", "0px"); + this.table.setWidth(o.width); + } }, - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); + setWidth: function (width) { + BI.PageTable.superclass.setWidth.apply(this, arguments); + this.table.setWidth(this.options.showSequence ? width - 60 : width); }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); + setHeight: function (height) { + BI.PageTable.superclass.setHeight.apply(this, arguments); + this.table.setHeight(height); + this.sequence.setHeight(height - BI.GridTableScrollbar.SIZE); }, - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); + setColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setColumnSize(columnSize); }, - setOpened: function (v) { - BI.SelectTreeLastPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } - } -}); - -BI.shortcut("bi.select_tree_last_plus_group_node", BI.SelectTreeLastPlusGroupNode);/** - * 加号表示的组节点 - * Created by GUY on 2015/9/6. - * @class BI.SelectTreeMidPlusGroupNode - * @extends BI.NodeButton - */ -BI.SelectTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, { - _defaultConfig: function () { - var conf = BI.SelectTreeMidPlusGroupNode.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-select-tree-mid-plus-group-node bi-list-item-active", - logic: { - dynamic: false - }, - id: "", - pId: "", - readonly: true, - open: false, - height: 25 - }); - }, - _init: function () { - BI.SelectTreeMidPlusGroupNode.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.checkbox = BI.createWidget({ - type: "bi.mid_tree_node_checkbox", - stopPropagation: true - }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - whiteSpace: "nowrap", - textHeight: o.height, - height: o.height, - hgap: o.hgap, - text: o.text, - value: o.value, - py: o.py - }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); - } - } - }); - var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); - var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { - width: 25, - el: this.checkbox - }, this.text); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { - items: items - })))); + getColumnSize: function () { + return this.table.getColumnSize(); }, - isOnce: function () { - return true; + setRegionColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setRegionColumnSize(columnSize); }, - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); + hasLeftHorizontalScroll: function () { + return this.table.hasLeftHorizontalScroll(); }, - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); + hasRightHorizontalScroll: function () { + return this.table.hasRightHorizontalScroll(); }, - setOpened: function (v) { - BI.SelectTreeMidPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } - } -}); - -BI.shortcut("bi.select_tree_mid_plus_group_node", BI.SelectTreeMidPlusGroupNode);/** - * @class BI.SelectTreeCombo - * @extends BI.Widget - */ -BI.SelectTreeCombo = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.SelectTreeCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-select-tree-combo", - height: 30, - text: "", - items: [], - value: "" - }); + setLeftHorizontalScroll: function (scrollLeft) { + this.table.setLeftHorizontalScroll(scrollLeft); }, - _init: function () { - BI.SelectTreeCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; + setRightHorizontalScroll: function (scrollLeft) { + this.table.setRightHorizontalScroll(scrollLeft); + }, - this.trigger = BI.createWidget({ - type: "bi.single_tree_trigger", - text: o.text, - height: o.height, - items: o.items, - value: o.value - }); + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); + this.sequence.setVerticalScroll(scrollTop); + }, - this.popup = BI.createWidget({ - type: "bi.select_level_tree", - items: o.items, - value: o.value - }); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); + }, - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - adjustLength: 2, - el: this.trigger, - popup: { - el: this.popup - } - }); + setVPage: function (page) { + this.sequence.setVPage && this.sequence.setVPage(page); + }, - this.combo.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + setHPage: function (page) { + this.sequence.setHPage && this.sequence.setHPage(page); + }, - this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - }); + attr: function () { + BI.SequenceTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); + this.sequence.attr.apply(this.sequence, arguments); }, - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.trigger.setValue(v); - this.popup.setValue(v); + restore: function () { + this.table.restore(); + this.sequence.restore(); }, - getValue: function () { - return this.popup.getValue(); + populate: function (items, header, crossItems, crossHeader) { + var o = this.options; + if (items) { + o.items = items; + } + if (header) { + o.header = header; + } + if (crossItems) { + o.crossItems = crossItems; + } + if (crossHeader) { + o.crossHeader = crossHeader; + } + this._populate(); + this.table.populate.apply(this.table, arguments); + this.sequence.populate.apply(this.sequence, arguments); + this.sequence.setVerticalScroll(this.table.getVerticalScroll()); }, - populate: function (items) { - this.combo.populate(items); + destroy: function () { + this.table.destroy(); + BI.SequenceTable.superclass.destroy.apply(this, arguments); } }); - - -BI.shortcut("bi.select_tree_combo", BI.SelectTreeCombo);/** - * @class BI.SelectTreeExpander - * @extends BI.Widget +BI.shortcut("bi.sequence_table", BI.SequenceTable);/** + * 单选加载数据搜索loader面板 + * Created by guy on 15/11/4. + * @class BI.SingleSelectSearchLoader + * @extends Widget */ -BI.SelectTreeExpander = BI.inherit(BI.Widget, { +BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SelectTreeExpander.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-select-tree-expander", - trigger: "click", - toggle: true, - direction: "bottom", - isDefaultInit: true, - el: {}, - popup: {} + return BI.extend(BI.SingleSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-search-loader", + itemsCreator: BI.emptyFn, + keywordGetter: BI.emptyFn, + valueFormatter: BI.emptyFn }); }, _init: function () { - BI.SelectTreeExpander.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); - this.trigger = BI.createWidget(BI.extend({stopPropagation: true}, o.el)); - this.trigger.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.expander.setValue([]); + var self = this, opts = this.options; + var hasNext = false; + + this.button_group = BI.createWidget({ + type: "bi.single_select_list", + element: this, + logic: { + dynamic: false + }, + el: { + tipText: BI.i18nText("BI-No_Select"), + el: { + type: "bi.loader", + isDefaultInit: false, + logic: { + dynamic: true, + scrolly: true + }, + el: { + chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, + behaviors: { + redmark: function () { + return true; + } + }, + layouts: [{ + type: "bi.vertical" + }] + } } + }, + itemsCreator: function (op, callback) { + self.storeValue && (op = BI.extend(op || {}, { + selectedValues: [self.storeValue] + })); + opts.itemsCreator(op, function (ob) { + var keyword = ob.keyword = opts.keywordGetter(); + hasNext = ob.hasNext; + var firstItems = []; + if (op.times === 1 && self.storeValue) { + var json = BI.map([self.storeValue], function (i, v) { + var txt = opts.valueFormatter(v) || v; + return { + text: txt, + value: v, + title: txt, + selected: false + }; + }); + firstItems = self._createItems(json); + } + callback(firstItems.concat(self._createItems(ob.items)), keyword); + if (op.times === 1 && self.storeValue) { + self.setValue(self.storeValue); + } + }); + }, + hasNext: function () { + return hasNext; } + }); + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); + this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); + }); + }, - this.expander = BI.createWidget({ - type: "bi.expander", - element: this, - trigger: o.trigger, - toggle: o.toggle, - direction: o.direction, - isDefaultInit: o.isDefaultInit, - el: this.trigger, - popup: o.popup + _createItems: function (items) { + return BI.createItems(items, { + type: "bi.single_select_radio_item", + logic: { + dynamic: false + }, + height: 25, + selected: false }); - this.expander.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - self.trigger.setSelected(false); - } - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }, + + _filterValues: function (src) { + var o = this.options; + var keyword = o.keywordGetter(); + var values = BI.deepClone(src.value) || []; + var newValues = BI.map(values, function (i, v) { + return { + text: o.valueFormatter(v) || v, + value: v + }; + }); + if (BI.isKey(keyword)) { + var search = BI.Func.getSearchResult(newValues, keyword); + values = search.match.concat(search.find); + } + return BI.map(values, function (i, v) { + return { + text: v.text, + title: v.text, + value: v.value, + selected: false + }; }); }, setValue: function (v) { - if (BI.contains(v, this.trigger.getValue())) { - this.trigger.setSelected(true); - this.expander.setValue([]); - } else { - this.trigger.setSelected(false); - this.expander.setValue(v); - } + // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = v; + this.button_group.setValue(v); }, getValue: function () { - if (this.trigger.isSelected()) { - return [this.trigger.getValue()]; - } - return this.expander.getValue(); + return this.button_group.getValue(); + }, + + getAllButtons: function () { + return this.button_group.getAllButtons(); + }, + + empty: function () { + this.button_group.empty(); }, populate: function (items) { - this.expander.populate(items); + this.button_group.populate.apply(this.button_group, arguments); + }, + + resetHeight: function (h) { + this.button_group.resetHeight(h); + }, + + resetWidth: function (w) { + this.button_group.resetWidth(w); } }); -BI.shortcut("bi.select_tree_expander", BI.SelectTreeExpander);/** - * @class BI.SelectTreePopup - * @extends BI.Pane +BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_search_loader", BI.SingleSelectSearchLoader);/** + * + * 在搜索框中输入文本弹出的面板 + * @class BI.SingleSelectSearchPane + * @extends Widget */ -BI.SelectTreePopup = BI.inherit(BI.Pane, { +BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.SelectTreePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-select-level-tree", - tipText: BI.i18nText("BI-No_Selected_Item"), - items: [], - value: "" - }); + constants: { + height: 25, + lgap: 10, + tgap: 5 }, - _formatItems: function (nodes, layer) { - var self = this; - BI.each(nodes, function (i, node) { - var extend = {layer: layer}; - node.id = node.id || BI.UUID(); - if (node.isParent === true || BI.isNotEmptyArray(node.children)) { - switch (i) { - case 0 : - extend.type = "bi.select_tree_first_plus_group_node"; - break; - case nodes.length - 1 : - extend.type = "bi.select_tree_last_plus_group_node"; - break; - default : - extend.type = "bi.select_tree_mid_plus_group_node"; - break; - } - BI.defaults(node, extend); - self._formatItems(node.children); - } else { - switch (i) { - case nodes.length - 1: - extend.type = "bi.last_tree_leaf_item"; - break; - default : - extend.type = "bi.mid_tree_leaf_item"; - } - BI.defaults(node, extend); - } + _defaultConfig: function () { + return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-search-pane bi-card", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + keywordGetter: BI.emptyFn }); - return nodes; }, _init: function () { - BI.SelectTreePopup.superclass._init.apply(this, arguments); - + BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.tree = BI.createWidget({ - type: "bi.level_tree", - expander: { - type: "bi.select_tree_expander", - isDefaultInit: true - }, - items: this._formatItems(BI.Tree.transformToTreeFormat(o.items)), - value: o.value, - chooseType: BI.Selection.Single + this.tooltipClick = BI.createWidget({ + type: "bi.label", + invisible: true, + text: BI.i18nText("BI-Click_Blank_To_Select"), + cls: "single-select-toolbar", + height: this.constants.height }); - BI.createWidget({ - type: "bi.vertical", - element: this, - items: [this.tree] + this.loader = BI.createWidget({ + type: "bi.single_select_search_loader", + keywordGetter: o.keywordGetter, + valueFormatter: o.valueFormatter, + itemsCreator: function (op, callback) { + o.itemsCreator.apply(self, [op, function (res) { + callback(res); + self.setKeyword(o.keywordGetter()); + }]); + } }); - - this.tree.on(BI.Controller.EVENT_CHANGE, function () { + this.loader.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { - self.fireEvent(BI.SelectTreePopup.EVENT_CHANGE); + this.resizer = BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.tooltipClick, + height: 0 + }, { + el: this.loader + }] }); + this.tooltipClick.setVisible(false); + }, - this.check(); + setKeyword: function (keyword) { + var btn; + var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === btn.getValue()); + if (isVisible !== this.tooltipClick.isVisible()) { + this.tooltipClick.setVisible(isVisible); + this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); + this.resizer.resize(); + } }, - getValue: function () { - return this.tree.getValue(); + hasMatched: function () { + return this.tooltipClick.isVisible(); }, setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.tree.setValue(v); + this.loader.setValue(v); + }, + + getValue: function () { + return this.loader.getValue(); + }, + + empty: function () { + this.loader.empty(); }, populate: function (items) { - BI.SelectTreePopup.superclass.populate.apply(this, arguments); - this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(items))); + this.loader.populate.apply(this.loader, arguments); } }); -BI.SelectTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.select_level_tree", BI.SelectTreePopup);/** +BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; + +BI.shortcut("bi.single_select_search_pane", BI.SingleSelectSearchPane);/** * - * Created by GUY on 2016/8/10. - * @class BI.SequenceTableDynamicNumber - * @extends BI.SequenceTableTreeNumber + * @class BI.SingleSelectCombo + * @extends BI.Single */ -BI.SequenceTableDynamicNumber = BI.inherit(BI.SequenceTableTreeNumber, { +BI.SingleSelectCombo = BI.inherit(BI.Single, { _defaultConfig: function () { - return BI.extend(BI.SequenceTableDynamicNumber.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-sequence-table-dynamic-number" + return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-combo", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + height: 28 }); }, _init: function () { - BI.SequenceTableDynamicNumber.superclass._init.apply(this, arguments); - }, - - _formatNumber: function (nodes) { + BI.SingleSelectCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - var result = []; - var count = this._getStart(nodes); - function getLeafCount (node) { - var cnt = 0; - if (BI.isNotEmptyArray(node.children)) { - BI.each(node.children, function (index, child) { - cnt += getLeafCount(child); - }); - if (node.children.length > 1 && BI.isNotEmptyArray(node.values)) { - cnt++; + var assertShowValue = function () { + BI.isKey(self._startValue) && (self.storeValue = self._startValue); + self.trigger.getSearcher().setState(self.storeValue); + }; + this.storeValue = ""; + // 标记正在请求数据 + this.requesting = false; + + this.trigger = BI.createWidget({ + type: "bi.single_select_trigger", + height: o.height, + // adapter: this.popup, + masker: { + offset: { + left: 1, + top: 1, + right: 2, + bottom: 33 } - } else { - cnt++; + }, + valueFormatter: o.valueFormatter, + itemsCreator: function (op, callback) { + o.itemsCreator(op, function (res) { + if (op.times === 1 && BI.isNotNull(op.keywords)) { + // 预防trigger内部把当前的storeValue改掉 + self.trigger.setValue(self.getValue()); + } + callback.apply(self, arguments); + }); } - return cnt; - } + }); - var start = 0, top = 0; - BI.each(nodes, function (i, node) { - if (BI.isArray(node.children)) { - BI.each(node.children, function (index, child) { - var cnt = getLeafCount(child); - result.push({ - text: count++, - start: start, - top: top, - cnt: cnt, - index: index, - height: cnt * o.rowSize - }); - start += cnt; - top += cnt * o.rowSize; + this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { + self._setStartValue(""); + this.getSearcher().setValue(self.storeValue); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { + self._setStartValue(""); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { + if (this.getSearcher().hasMatched()) { + var keyword = this.getSearcher().getKeyword(); + self._join({ + type: BI.Selection.Multi, + value: [keyword] + }, function () { + self.combo.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self.populate(); + self._setStartValue(""); }); - if (BI.isNotEmptyArray(node.values)) { - result.push({ - text: BI.i18nText("BI-Summary_Values"), - start: start++, - top: top, - cnt: 1, - isSummary: true, - height: o.rowSize + } + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) { + var last = BI.last(keywords); + keywords = BI.initial(keywords || []); + if (keywords.length > 0) { + self._joinKeywords(keywords, function () { + if (BI.isEndWithBlank(last)) { + self.combo.setValue(self.storeValue); + assertShowValue(); + self.combo.populate(); + self._setStartValue(""); + } else { + self.combo.setValue(self.storeValue); + assertShowValue(); + } + }); + } + }); + + this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { + self.storeValue = this.getValue(); + assertShowValue(); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + }); + + this.combo = BI.createWidget({ + type: "bi.combo", + toggle: false, + el: this.trigger, + adjustLength: 1, + popup: { + type: "bi.single_select_popup_view", + ref: function () { + self.popup = this; + self.trigger.setAdapter(this); + }, + listeners: [{ + eventName: BI.SingleSelectPopupView.EVENT_CHANGE, + action: function () { + self.storeValue = this.getValue(); + self._adjust(function () { + assertShowValue(); + }); + } + }, { + eventName: BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM, + action: function () { + self._defaultState(); + } + }, { + eventName: BI.SingleSelectPopupView.EVENT_CLICK_CLEAR, + action: function () { + self.setValue(); + self._defaultState(); + } + }], + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, + onLoaded: function () { + BI.nextTick(function () { + self.combo.adjustWidth(); + self.combo.adjustHeight(); + self.trigger.getSearcher().adjustView(); }); - top += o.rowSize; } + }, + hideChecker: function (e) { + return triggerBtn.element.find(e.target).length === 0; } }); - return result; - } -}); -BI.shortcut("bi.sequence_table_dynamic_number", BI.SequenceTableDynamicNumber);/** - * - * Created by GUY on 2016/5/26. - * @class BI.SequenceTableListNumber - * @extends BI.Widget - */ -BI.SequenceTableListNumber = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.SequenceTableListNumber.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-sequence-table-list-number", - isNeedFreeze: false, - scrollTop: 0, - startSequence: 1, // 开始的序号 - headerRowSize: 25, - rowSize: 25, - - sequenceHeaderCreator: null, - - header: [], - items: [], // 二维数组 - - // 交叉表头 - crossHeader: [], - crossItems: [], - pageSize: 20 + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + this.setValue(self.storeValue); + BI.nextTick(function () { + self.populate(); + }); }); - }, - - _init: function () { - BI.SequenceTableListNumber.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.start = o.startSequence; - this.renderedCells = []; - this.renderedKeys = []; - - this.container = BI.createWidget({ - type: "bi.absolute", - width: 60, - scrollable: false + // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 + this.wants2Quit = false; + this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { + // important:关闭弹出时又可能没有退出编辑状态 + self.trigger.stopEditing(); + if (self.requesting === true) { + self.wants2Quit = true; + } else { + self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + } }); - this.scrollContainer = BI.createWidget({ - type: "bi.vertical", - scrollable: false, - scrolly: false, - items: [this.container] + var triggerBtn = BI.createWidget({ + type: "bi.trigger_icon_button", + width: o.height, + height: o.height, + cls: "single-select-trigger-icon-button" }); - - this.headerContainer = BI.createWidget({ - type: "bi.absolute", - cls: "bi-border", - width: 58, - scrollable: false + triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } else { + self.combo.showView(); + } }); - - this.layout = BI.createWidget({ - type: "bi.vtape", + BI.createWidget({ + type: "bi.absolute", element: this, items: [{ - el: this.headerContainer, - height: o.headerRowSize * o.header.length - 2 - }, { - el: {type: "bi.layout"}, - height: 2 + el: this.combo, + left: 0, + right: 0, + top: 0, + bottom: 0 }, { - el: this.scrollContainer + el: triggerBtn, + right: 0, + top: 0, + bottom: 0 }] }); - this._populate(); }, - _layout: function () { - var self = this, o = this.options; - var headerHeight = o.headerRowSize * o.header.length - 2; - var items = this.layout.attr("items"); - if (o.isNeedFreeze === false) { - items[0].height = 0; - items[1].height = 0; - } else if (o.isNeedFreeze === true) { - items[0].height = headerHeight; - items[1].height = 2; - } - this.layout.attr("items", items); - this.layout.resize(); - this.container.setHeight(o.items.length * o.rowSize); - try { - this.scrollContainer.element.scrollTop(o.scrollTop); - } catch (e) { + _defaultState: function () { + this.trigger.stopEditing(); + this.combo.hideView(); + }, - } + _assertValue: function (val) { + val || (val = ""); }, - _createHeader: function () { - var o = this.options; - BI.createWidget({ - type: "bi.absolute", - element: this.headerContainer, - items: [{ - el: o.sequenceHeaderCreator || { - type: "bi.table_style_cell", - cls: "sequence-table-title-cell", - styleGetter: o.headerCellStyleGetter, - text: BI.i18nText("BI-Number_Index") - }, - left: 0, - top: 0, - right: 0, - bottom: 0 - }] - }); + _makeMap: function (values) { + return BI.makeObject(values || []); }, - _calculateChildrenToRender: function () { + _joinKeywords: function (keywords, callback) { var self = this, o = this.options; - var scrollTop = BI.clamp(o.scrollTop, 0, o.rowSize * o.items.length - (o.height - o.header.length * o.headerRowSize) + BI.DOM.getScrollWidth()); - var start = Math.floor(scrollTop / o.rowSize); - var end = start + Math.floor((o.height - o.header.length * o.headerRowSize) / o.rowSize); - var renderedCells = [], renderedKeys = []; - for (var i = start, cnt = 0; i <= end && i < o.items.length; i++, cnt++) { - var index = BI.deepIndexOf(this.renderedKeys, this.start + i); - var top = i * o.rowSize; - if (index > -1) { - if (o.rowSize !== this.renderedCells[index]._height) { - this.renderedCells[index]._height = o.rowSize; - this.renderedCells[index].el.setHeight(o.rowSize); - } - if (this.renderedCells[index].top !== top) { - this.renderedCells[index].top = top; - this.renderedCells[index].el.element.css("top", top + "px"); + this._assertValue(this.storeValue); + this.requesting = true; + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + keywords: keywords + }, function (ob) { + var values = BI.map(ob.items, "value"); + digest(values); + }); + + function digest (items) { + var selectedMap = self._makeMap(items); + BI.each(keywords, function (i, val) { + if (BI.isNotNull(selectedMap[val])) { + self.storeValue.value["remove"](val); } - renderedCells.push(this.renderedCells[index]); - } else { - var child = BI.createWidget(BI.extend({ - type: "bi.table_style_cell", - cls: "sequence-table-number-cell bi-border-left bi-border-right bi-border-bottom", - width: 60, - height: o.rowSize, - text: this.start + i, - styleGetter: function (index) { - return function () { - return o.sequenceCellStyleGetter(self.start + i - 1); - }; - }(cnt) - })); - renderedCells.push({ - el: child, - left: 0, - top: top, - _height: o.rowSize - }); - } - renderedKeys.push(this.start + i); + }); + self._adjust(callback); } + }, - // 已存在的, 需要添加的和需要删除的 - var existSet = {}, addSet = {}, deleteArray = []; - BI.each(renderedKeys, function (i, key) { - if (BI.deepContains(self.renderedKeys, key)) { - existSet[i] = key; - } else { - addSet[i] = key; - } - }); - BI.each(this.renderedKeys, function (i, key) { - if (BI.deepContains(existSet, key)) { - return; - } - if (BI.deepContains(addSet, key)) { + _joinAll: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + this.requesting = true; + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + keywords: [this.trigger.getKey()] + }, function (ob) { + var items = BI.map(ob.items, "value"); + if (self.storeValue.type === res.type) { + var change = false; + var map = self._makeMap(self.storeValue.value); + BI.each(items, function (i, v) { + if (BI.isNotNull(map[v])) { + change = true; + delete map[v]; + } + }); + change && (self.storeValue.value = BI.values(map)); + self._adjust(callback); return; } - deleteArray.push(i); - }); - BI.each(deleteArray, function (i, index) { - self.renderedCells[index].el.destroy(); - }); - var addedItems = []; - BI.each(addSet, function (index) { - addedItems.push(renderedCells[index]); - }); - BI.createWidget({ - type: "bi.absolute", - element: this.container, - items: addedItems + var selectedMap = self._makeMap(self.storeValue.value); + var notSelectedMap = self._makeMap(res.value); + var newItems = []; + BI.each(items, function (i, item) { + if (BI.isNotNull(selectedMap[items[i]])) { + delete selectedMap[items[i]]; + } + if (BI.isNull(notSelectedMap[items[i]])) { + newItems.push(item); + } + }); + self.storeValue.value = newItems.concat(BI.values(selectedMap)); + self._adjust(callback); }); - this.renderedCells = renderedCells; - this.renderedKeys = renderedKeys; }, - _populate: function () { - this.headerContainer.empty(); - this._createHeader(); - this._layout(); - this._calculateChildrenToRender(); - }, + _adjust: function (callback) { + var self = this, o = this.options; + if (!this._count) { + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH + }, function (res) { + self._count = res.count; + adjust(); + callback(); + }); + } else { + adjust(); + callback(); - setVerticalScroll: function (scrollTop) { - if (this.options.scrollTop !== scrollTop) { - this.options.scrollTop = scrollTop; - try { - this.scrollContainer.element.scrollTop(scrollTop); - } catch (e) { + } + function adjust () { + if (self.wants2Quit === true) { + self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + self.wants2Quit = false; } + self.requesting = false; } }, - getVerticalScroll: function () { - return this.options.scrollTop; + _join: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + this._assertValue(this.storeValue); + if (this.storeValue.type === res.type) { + var map = this._makeMap(this.storeValue.value); + BI.each(res.value, function (i, v) { + if (!map[v]) { + self.storeValue.value.push(v); + map[v] = v; + } + }); + var change = false; + BI.each(res.assist, function (i, v) { + if (BI.isNotNull(map[v])) { + change = true; + delete map[v]; + } + }); + change && (this.storeValue.value = BI.values(map)); + self._adjust(callback); + return; + } + this._joinAll(res, callback); }, - setVPage: function (v) { - v = v < 1 ? 1 : v; - var o = this.options; - this.start = (v - 1) * o.pageSize + 1; + _setStartValue: function (value) { + this._startValue = value; + this.popup.setStartValue(value); }, - _restore: function () { - var o = this.options; - BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); - }); - this.renderedCells = []; - this.renderedKeys = []; + setValue: function (v) { + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.combo.setValue(this.storeValue); }, - restore: function () { - this._restore(); + getValue: function () { + return this.storeValue; }, - populate: function (items, header) { - var o = this.options; - if (items && items !== this.options.items) { - o.items = items; - this._restore(); - } - if (header && header !== this.options.header) { - o.header = header; - } - this._populate(); + populate: function () { + this._count = null; + this.combo.populate.apply(this.combo, arguments); } }); -BI.shortcut("bi.sequence_table_list_number", BI.SequenceTableListNumber);/** - * 带有序号的表格 + +BI.extend(BI.SingleSelectCombo, { + REQ_GET_DATA_LENGTH: 0, + REQ_GET_ALL_DATA: -1 +}); + +BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; + +BI.shortcut("bi.single_select_combo", BI.SingleSelectCombo);/** + * 选择列表 * - * Created by GUY on 2016/5/26. - * @class BI.SequenceTable + * Created by GUY on 2015/11/1. + * @class BI.SingleSelectList * @extends BI.Widget */ -BI.SequenceTable = BI.inherit(BI.Widget, { - +BI.SingleSelectList = BI.inherit(BI.Widget, { + _defaultConfig: function () { - return BI.extend(BI.SequenceTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-sequence-table", - el: { - type: "bi.adaptive_table" + return BI.extend(BI.SingleSelectList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-list", + direction: BI.Direction.Top, // toolbar的位置 + logic: { + dynamic: true }, - - sequence: {}, - - isNeedResize: true, - isResizeAdapt: false, - - isNeedFreeze: false, // 是否需要冻结单元格 - freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 - - isNeedMerge: false, // 是否需要合并单元格 - mergeCols: [], // 合并的单元格列号 - mergeRule: BI.emptyFn, - - columnSize: [], - minColumnSize: [], - maxColumnSize: [], - headerRowSize: 25, - rowSize: 25, - - regionColumnSize: [], - - headerCellStyleGetter: BI.emptyFn, - summaryCellStyleGetter: BI.emptyFn, - sequenceCellStyleGetter: BI.emptyFn, - - header: [], - items: [], // 二维数组 - - // 交叉表头 - crossHeader: [], - crossItems: [], - - showSequence: false, - startSequence: 1// 开始的序号 + items: [], + itemsCreator: BI.emptyFn, + hasNext: BI.emptyFn, + onLoaded: BI.emptyFn, + el: { + type: "bi.list_pane" + } }); }, - _init: function () { - BI.SequenceTable.superclass._init.apply(this, arguments); + BI.SingleSelectList.superclass._init.apply(this, arguments); var self = this, o = this.options; - - this.sequence = BI.createWidget(o.sequence, { - type: "bi.sequence_table_list_number", - invisible: o.showSequence === false, - startSequence: o.startSequence, - isNeedFreeze: o.isNeedFreeze, - header: o.header, - items: o.items, - crossHeader: o.crossHeader, - crossItems: o.crossItems, - headerRowSize: o.headerRowSize, - rowSize: o.rowSize, - width: 60, - height: o.height && o.height - BI.GridTableScrollbar.SIZE, - - headerCellStyleGetter: o.headerCellStyleGetter, - summaryCellStyleGetter: o.summaryCellStyleGetter, - sequenceCellStyleGetter: o.sequenceCellStyleGetter - }); - this.table = BI.createWidget(o.el, { - type: "bi.adaptive_table", - width: o.showSequence === true ? o.width - 60 : o.width, - height: o.height, - isNeedResize: o.isNeedResize, - isResizeAdapt: o.isResizeAdapt, - - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, - - isNeedMerge: o.isNeedMerge, - mergeCols: o.mergeCols, - mergeRule: o.mergeRule, - - columnSize: o.columnSize, - minColumnSize: o.minColumnSize, - maxColumnSize: o.maxColumnSize, - headerRowSize: o.headerRowSize, - rowSize: o.rowSize, - - regionColumnSize: o.regionColumnSize, - - headerCellStyleGetter: o.headerCellStyleGetter, - summaryCellStyleGetter: o.summaryCellStyleGetter, - sequenceCellStyleGetter: o.sequenceCellStyleGetter, - - header: o.header, - items: o.items, - // 交叉表头 - crossHeader: o.crossHeader, - crossItems: o.crossItems - }); - - this.table.on(BI.Table.EVENT_TABLE_SCROLL, function (scroll) { - if (self.sequence.getVerticalScroll() !== this.getVerticalScroll()) { - self.sequence.setVerticalScroll(this.getVerticalScroll()); - self.sequence.populate(); - } - self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, arguments); - }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); - }); - - this.htape = BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.sequence, - left: 0, - top: 0 - }, { - el: this.table, - top: 0, - left: o.showSequence === true ? 60 : 0 - }] + + this.list = BI.createWidget(o.el, { + type: "bi.list_pane", + items: o.items, + itemsCreator: function (op, callback) { + o.itemsCreator(op, function (items) { + callback.apply(self, arguments); + }); + }, + onLoaded: o.onLoaded, + hasNext: o.hasNext + }); + + this.list.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { + if (type === BI.Events.CLICK) { + self.fireEvent(BI.SingleSelectList.EVENT_CHANGE, value, obj); + } + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this._populate(); - }, - _populate: function () { - var o = this.options; - if (o.showSequence === true) { - this.sequence.setVisible(true); - this.table.element.css("left", "60px"); - this.table.setWidth(o.width - 60); - } else { - this.sequence.setVisible(false); - this.table.element.css("left", "0px"); - this.table.setWidth(o.width); - } + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ + scrolly: true + }, o.logic, { + items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.list) + })))); + }, - - setWidth: function (width) { - BI.PageTable.superclass.setWidth.apply(this, arguments); - this.table.setWidth(this.options.showSequence ? width - 60 : width); + + hasPrev: function () { + return this.list.hasPrev(); }, - - setHeight: function (height) { - BI.PageTable.superclass.setHeight.apply(this, arguments); - this.table.setHeight(height); - this.sequence.setHeight(height - BI.GridTableScrollbar.SIZE); + + hasNext: function () { + return this.list.hasNext(); }, - - setColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setColumnSize(columnSize); + + prependItems: function (items) { + this.list.prependItems.apply(this.list, arguments); }, - - getColumnSize: function () { - return this.table.getColumnSize(); + + addItems: function (items) { + this.list.addItems.apply(this.list, arguments); }, - - setRegionColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setRegionColumnSize(columnSize); + + setValue: function (v) { + this.list.setValue([v]); }, - - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); + + getValue: function () { + return this.list.getValue()[0]; }, - - hasLeftHorizontalScroll: function () { - return this.table.hasLeftHorizontalScroll(); + + empty: function () { + this.list.empty(); }, - - hasRightHorizontalScroll: function () { - return this.table.hasRightHorizontalScroll(); + + populate: function (items) { + this.list.populate.apply(this.list, arguments); }, - - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); + + resetHeight: function (h) { + this.list.resetHeight ? this.list.resetHeight(h) : + this.list.element.css({"max-height": h + "px"}); }, - - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + + setNotSelectedValue: function () { + this.list.setNotSelectedValue.apply(this.list, arguments); }, - - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); - this.sequence.setVerticalScroll(scrollTop); + + getNotSelectedValue: function () { + return this.list.getNotSelectedValue(); }, - - getVerticalScroll: function () { - return this.table.getVerticalScroll(); + + getAllButtons: function () { + return this.list.getAllButtons(); }, - - setVPage: function (page) { - this.sequence.setVPage && this.sequence.setVPage(page); + + getAllLeaves: function () { + return this.list.getAllLeaves(); }, - - setHPage: function (page) { - this.sequence.setHPage && this.sequence.setHPage(page); + + getSelectedButtons: function () { + return this.list.getSelectedButtons(); }, - - attr: function () { - BI.SequenceTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); - this.sequence.attr.apply(this.sequence, arguments); + + getNotSelectedButtons: function () { + return this.list.getNotSelectedButtons(); }, - - restore: function () { - this.table.restore(); - this.sequence.restore(); + + getIndexByValue: function (value) { + return this.list.getIndexByValue(value); }, - - populate: function (items, header, crossItems, crossHeader) { - var o = this.options; - if (items) { - o.items = items; - } - if (header) { - o.header = header; - } - if (crossItems) { - o.crossItems = crossItems; - } - if (crossHeader) { - o.crossHeader = crossHeader; - } - this._populate(); - this.table.populate.apply(this.table, arguments); - this.sequence.populate.apply(this.sequence, arguments); - this.sequence.setVerticalScroll(this.table.getVerticalScroll()); + + getNodeById: function (id) { + return this.list.getNodeById(id); }, - - destroy: function () { - this.table.destroy(); - BI.SequenceTable.superclass.destroy.apply(this, arguments); + + getNodeByValue: function (value) { + return this.list.getNodeByValue(value); } }); -BI.shortcut("bi.sequence_table", BI.SequenceTable);/** - * 单选加载数据搜索loader面板 - * Created by guy on 15/11/4. - * @class BI.SingleSelectSearchLoader +BI.SingleSelectList.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_list", BI.SingleSelectList);/** + * 单选加载数据面板 + * Created by guy on 15/11/2. + * @class BI.SingleSelectLoader * @extends Widget */ -BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { +BI.SingleSelectLoader = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-search-loader", + return BI.extend(BI.SingleSelectLoader.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-loader", + logic: { + dynamic: true + }, + el: { + height: 400 + }, + valueFormatter: BI.emptyFn, itemsCreator: BI.emptyFn, - keywordGetter: BI.emptyFn, - valueFormatter: BI.emptyFn + onLoaded: BI.emptyFn }); }, _init: function () { - BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); + BI.SingleSelectLoader.superclass._init.apply(this, arguments); var self = this, opts = this.options; var hasNext = false; @@ -18912,11 +16328,9 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { this.button_group = BI.createWidget({ type: "bi.single_select_list", element: this, - logic: { - dynamic: false - }, - el: { - tipText: BI.i18nText("BI-No_Select"), + logic: opts.logic, + el: BI.extend({ + onLoaded: opts.onLoaded, el: { type: "bi.loader", isDefaultInit: false, @@ -18936,13 +16350,13 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { }] } } - }, + }, opts.el), itemsCreator: function (op, callback) { + var startValue = self._startValue; self.storeValue && (op = BI.extend(op || {}, { selectedValues: [self.storeValue] })); opts.itemsCreator(op, function (ob) { - var keyword = ob.keyword = opts.keywordGetter(); hasNext = ob.hasNext; var firstItems = []; if (op.times === 1 && self.storeValue) { @@ -18957,10 +16371,12 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { }); firstItems = self._createItems(json); } - callback(firstItems.concat(self._createItems(ob.items)), keyword); + callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); if (op.times === 1 && self.storeValue) { + BI.isKey(startValue) && (self.storeValue = startValue); self.setValue(self.storeValue); } + (op.times === 1) && self._scrollToTop(); }); }, hasNext: function () { @@ -18971,49 +16387,38 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); + self.fireEvent(BI.SingleSelectLoader.EVENT_CHANGE, arguments); }); }, _createItems: function (items) { return BI.createItems(items, { type: "bi.single_select_radio_item", - logic: { - dynamic: false - }, + logic: this.options.logic, height: 25, selected: false }); }, - _filterValues: function (src) { - var o = this.options; - var keyword = o.keywordGetter(); - var values = BI.deepClone(src.value) || []; - var newValues = BI.map(values, function (i, v) { - return { - text: o.valueFormatter(v) || v, - value: v - }; - }); - if (BI.isKey(keyword)) { - var search = BI.Func.getSearchResult(newValues, keyword); - values = search.match.concat(search.find); - } - return BI.map(values, function (i, v) { - return { - text: v.text, - title: v.text, - value: v.value, - selected: false - }; - }); + _scrollToTop: function () { + var self = this; + BI.delay(function () { + self.button_group.element.scrollTop(0); + }, 30); + }, + + _assertValue: function (val) { + val || (val = ""); + }, + + setStartValue: function (v) { + this._startValue = v; }, setValue: function (v) { - // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 - this.storeValue = v; - this.button_group.setValue(v); + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.button_group.setValue(this.storeValue); }, getValue: function () { @@ -19041,611 +16446,440 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { } }); -BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_search_loader", BI.SingleSelectSearchLoader);/** - * - * 在搜索框中输入文本弹出的面板 - * @class BI.SingleSelectSearchPane +BI.SingleSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_loader", BI.SingleSelectLoader);/** + * 带加载的单选下拉面板 + * @class BI.SingleSelectPopupView * @extends Widget */ - -BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { - - constants: { - height: 25, - lgap: 10, - tgap: 5 - }, +BI.SingleSelectPopupView = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-search-pane bi-card", - itemsCreator: BI.emptyFn, + return BI.extend(BI.SingleSelectPopupView.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-popup-view", + maxWidth: "auto", + minWidth: 135, + maxHeight: 400, valueFormatter: BI.emptyFn, - keywordGetter: BI.emptyFn - }); - }, - - _init: function () { - BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.tooltipClick = BI.createWidget({ - type: "bi.label", - invisible: true, - text: BI.i18nText("BI-Click_Blank_To_Select"), - cls: "single-select-toolbar", - height: this.constants.height - }); - - this.loader = BI.createWidget({ - type: "bi.single_select_search_loader", - keywordGetter: o.keywordGetter, - valueFormatter: o.valueFormatter, - itemsCreator: function (op, callback) { - o.itemsCreator.apply(self, [op, function (res) { - callback(res); - self.setKeyword(o.keywordGetter()); - }]); - } - }); - this.loader.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.resizer = BI.createWidget({ - type: "bi.vtape", - element: this, - items: [{ - el: this.tooltipClick, - height: 0 - }, { - el: this.loader - }] - }); - this.tooltipClick.setVisible(false); - }, - - setKeyword: function (keyword) { - var btn; - var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === btn.getValue()); - if (isVisible !== this.tooltipClick.isVisible()) { - this.tooltipClick.setVisible(isVisible); - this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); - this.resizer.resize(); - } - }, - - hasMatched: function () { - return this.tooltipClick.isVisible(); - }, - - setValue: function (v) { - this.loader.setValue(v); - }, - - getValue: function () { - return this.loader.getValue(); - }, - - empty: function () { - this.loader.empty(); - }, - - populate: function (items) { - this.loader.populate.apply(this.loader, arguments); - } -}); - -BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.single_select_search_pane", BI.SingleSelectSearchPane);/** - * - * @class BI.SingleSelectCombo - * @extends BI.Single - */ -BI.SingleSelectCombo = BI.inherit(BI.Single, { - - _defaultConfig: function () { - return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-combo", itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - height: 28 + onLoaded: BI.emptyFn }); }, _init: function () { - BI.SingleSelectCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - var assertShowValue = function () { - BI.isKey(self._startValue) && (self.storeValue = self._startValue); - self.trigger.getSearcher().setState(self.storeValue); - }; - this.storeValue = ""; - // 标记正在请求数据 - this.requesting = false; - - this.trigger = BI.createWidget({ - type: "bi.single_select_trigger", - height: o.height, - // adapter: this.popup, - masker: { - offset: { - left: 1, - top: 1, - right: 2, - bottom: 33 - } - }, - valueFormatter: o.valueFormatter, - itemsCreator: function (op, callback) { - o.itemsCreator(op, function (res) { - if (op.times === 1 && BI.isNotNull(op.keywords)) { - // 预防trigger内部把当前的storeValue改掉 - self.trigger.setValue(self.getValue()); - } - callback.apply(self, arguments); - }); - } - }); - - this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { - self._setStartValue(""); - this.getSearcher().setValue(self.storeValue); - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { - self._setStartValue(""); - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { - if (this.getSearcher().hasMatched()) { - var keyword = this.getSearcher().getKeyword(); - self._join({ - type: BI.Selection.Multi, - value: [keyword] - }, function () { - self.combo.setValue(self.storeValue); - self._setStartValue(keyword); - assertShowValue(); - self.populate(); - self._setStartValue(""); - }); - } - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) { - var last = BI.last(keywords); - keywords = BI.initial(keywords || []); - if (keywords.length > 0) { - self._joinKeywords(keywords, function () { - if (BI.isEndWithBlank(last)) { - self.combo.setValue(self.storeValue); - assertShowValue(); - self.combo.populate(); - self._setStartValue(""); - } else { - self.combo.setValue(self.storeValue); - assertShowValue(); - } - }); - } - }); - - this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { - self.storeValue = this.getValue(); - assertShowValue(); - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - }); + BI.SingleSelectPopupView.superclass._init.apply(this, arguments); + var self = this, opts = this.options; - this.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - el: this.trigger, - adjustLength: 1, - popup: { - type: "bi.single_select_popup_view", - ref: function () { - self.popup = this; - self.trigger.setAdapter(this); - }, - listeners: [{ - eventName: BI.SingleSelectPopupView.EVENT_CHANGE, - action: function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - }); - } - }, { - eventName: BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM, - action: function () { - self._defaultState(); - } - }, { - eventName: BI.SingleSelectPopupView.EVENT_CLICK_CLEAR, - action: function () { - self.setValue(); - self._defaultState(); - } - }], - itemsCreator: o.itemsCreator, - valueFormatter: o.valueFormatter, - onLoaded: function () { - BI.nextTick(function () { - self.combo.adjustWidth(); - self.combo.adjustHeight(); - self.trigger.getSearcher().adjustView(); - }); - } - }, - hideChecker: function (e) { - return triggerBtn.element.find(e.target).length === 0; - } + this.loader = BI.createWidget({ + type: "bi.single_select_loader", + itemsCreator: opts.itemsCreator, + valueFormatter: opts.valueFormatter, + onLoaded: opts.onLoaded }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - this.setValue(self.storeValue); - BI.nextTick(function () { - self.populate(); - }); - }); - // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 - this.wants2Quit = false; - this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { - // important:关闭弹出时又可能没有退出编辑状态 - self.trigger.stopEditing(); - if (self.requesting === true) { - self.wants2Quit = true; - } else { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); - } + this.popupView = BI.createWidget({ + type: "bi.multi_popup_view", + stopPropagation: false, + maxWidth: opts.maxWidth, + minWidth: opts.minWidth, + maxHeight: opts.maxHeight, + element: this, + buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], + el: this.loader }); - var triggerBtn = BI.createWidget({ - type: "bi.trigger_icon_button", - width: o.height, - height: o.height, - cls: "single-select-trigger-icon-button" + this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleSelectPopupView.EVENT_CHANGE); }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); + this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { + switch (index) { + case 0: + self.fireEvent(BI.SingleSelectPopupView.EVENT_CLICK_CLEAR); + break; + case 1: + self.fireEvent(BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM); + break; } }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.combo, - left: 0, - right: 0, - top: 0, - bottom: 0 - }, { - el: triggerBtn, - right: 0, - top: 0, - bottom: 0 - }] - }); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + setStartValue: function (v) { + this.loader.setStartValue(v); }, - _assertValue: function (val) { - val || (val = ""); + setValue: function (v) { + this.popupView.setValue(v); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + getValue: function () { + return this.popupView.getValue(); }, - _joinKeywords: function (keywords, callback) { - var self = this, o = this.options; - this._assertValue(this.storeValue); - this.requesting = true; - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, - keywords: keywords - }, function (ob) { - var values = BI.map(ob.items, "value"); - digest(values); - }); - - function digest (items) { - var selectedMap = self._makeMap(items); - BI.each(keywords, function (i, val) { - if (BI.isNotNull(selectedMap[val])) { - self.storeValue.value["remove"](val); - } - }); - self._adjust(callback); - } + populate: function (items) { + this.popupView.populate.apply(this.popupView, arguments); }, - _joinAll: function (res, callback) { - var self = this, o = this.options; - this._assertValue(res); - this.requesting = true; - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, - keywords: [this.trigger.getKey()] - }, function (ob) { - var items = BI.map(ob.items, "value"); - if (self.storeValue.type === res.type) { - var change = false; - var map = self._makeMap(self.storeValue.value); - BI.each(items, function (i, v) { - if (BI.isNotNull(map[v])) { - change = true; - delete map[v]; - } - }); - change && (self.storeValue.value = BI.values(map)); - self._adjust(callback); - return; - } - var selectedMap = self._makeMap(self.storeValue.value); - var notSelectedMap = self._makeMap(res.value); - var newItems = []; - BI.each(items, function (i, item) { - if (BI.isNotNull(selectedMap[items[i]])) { - delete selectedMap[items[i]]; - } - if (BI.isNull(notSelectedMap[items[i]])) { - newItems.push(item); - } - }); - self.storeValue.value = newItems.concat(BI.values(selectedMap)); - self._adjust(callback); - }); + resetHeight: function (h) { + this.popupView.resetHeight(h); }, - _adjust: function (callback) { - var self = this, o = this.options; - if (!this._count) { - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH - }, function (res) { - self._count = res.count; - adjust(); - callback(); - }); - } else { - adjust(); - callback(); + resetWidth: function (w) { + this.popupView.resetWidth(w); + } +}); - } +BI.SingleSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; +BI.SingleSelectPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; - function adjust () { - if (self.wants2Quit === true) { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); - self.wants2Quit = false; - } - self.requesting = false; - } + +BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView);/** + * + * 单选下拉框 + * @class BI.SingleSelectTrigger + * @extends BI.Trigger + */ + +BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { + + constants: { + height: 14, + rgap: 4, + lgap: 4 }, - _join: function (res, callback) { + _defaultConfig: function () { + return BI.extend(BI.SingleSelectTrigger.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-trigger bi-border", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + searcher: {}, + switcher: {}, + + adapter: null, + masker: {} + }); + }, + + _init: function () { + BI.SingleSelectTrigger.superclass._init.apply(this, arguments); + var self = this, o = this.options; - this._assertValue(res); - this._assertValue(this.storeValue); - if (this.storeValue.type === res.type) { - var map = this._makeMap(this.storeValue.value); - BI.each(res.value, function (i, v) { - if (!map[v]) { - self.storeValue.value.push(v); - map[v] = v; - } - }); - var change = false; - BI.each(res.assist, function (i, v) { - if (BI.isNotNull(map[v])) { - change = true; - delete map[v]; - } - }); - change && (this.storeValue.value = BI.values(map)); - self._adjust(callback); - return; + if (o.height) { + this.setHeight(o.height - 2); } - this._joinAll(res, callback); + + this.searcher = BI.createWidget(o.searcher, { + type: "bi.single_select_searcher", + height: o.height, + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, + popup: {}, + adapter: o.adapter, + masker: o.masker + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_START, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_START); + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_PAUSE, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_PAUSE); + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_SEARCHING, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_SEARCHING, arguments); + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_STOP, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_STOP); + }); + this.searcher.on(BI.SingleSelectSearcher.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_CHANGE, arguments); + }); + + var wrapper = BI.createWidget({ + type: "bi.htape", + element: this, + items: [ + { + el: this.searcher, + width: "fill" + }, { + el: BI.createWidget(), + width: 30 + }] + }); }, - _setStartValue: function (value) { - this._startValue = value; - this.popup.setStartValue(value); + getSearcher: function () { + return this.searcher; + }, + + stopEditing: function () { + this.searcher.stopSearch(); + }, + + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, setValue: function (v) { - this.storeValue = v || ""; - this._assertValue(this.storeValue); - this.combo.setValue(this.storeValue); + this.searcher.setValue(v); }, - getValue: function () { - return this.storeValue; + getKey: function () { + return this.searcher.getKey(); }, - populate: function () { - this._count = null; - this.combo.populate.apply(this.combo, arguments); + getValue: function () { + return this.searcher.getValue(); } }); -BI.extend(BI.SingleSelectCombo, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 -}); - -BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.SingleSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.SingleSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; +BI.SingleSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectTrigger.EVENT_START = "EVENT_START"; +BI.SingleSelectTrigger.EVENT_STOP = "EVENT_STOP"; +BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; -BI.shortcut("bi.single_select_combo", BI.SingleSelectCombo);/** - * 选择列表 - * - * Created by GUY on 2015/11/1. - * @class BI.SingleSelectList - * @extends BI.Widget +BI.shortcut("bi.single_select_trigger", BI.SingleSelectTrigger);/** + * 单选输入框 + * Created by guy on 15/11/3. + * @class BI.SingleSelectEditor + * @extends Widget */ -BI.SingleSelectList = BI.inherit(BI.Widget, { - +BI.SingleSelectEditor = BI.inherit(BI.Widget, { + + _const: { + checkSelected: BI.i18nText("BI-Check_Selected") + }, + _defaultConfig: function () { - return BI.extend(BI.SingleSelectList.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-select-list", - direction: BI.Direction.Top, // toolbar的位置 - logic: { - dynamic: true - }, - items: [], - itemsCreator: BI.emptyFn, - hasNext: BI.emptyFn, - onLoaded: BI.emptyFn, - el: { - type: "bi.list_pane" - } + return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-editor", + el: {} }); }, + _init: function () { - BI.SingleSelectList.superclass._init.apply(this, arguments); + BI.SingleSelectEditor.superclass._init.apply(this, arguments); var self = this, o = this.options; - - this.list = BI.createWidget(o.el, { - type: "bi.list_pane", - items: o.items, - itemsCreator: function (op, callback) { - o.itemsCreator(op, function (items) { - callback.apply(self, arguments); - }); - }, - onLoaded: o.onLoaded, - hasNext: o.hasNext + this.editor = BI.createWidget(o.el, { + type: "bi.state_editor", + element: this, + height: o.height, + watermark: BI.i18nText("BI-Basic_Search"), + allowBlank: true }); - - this.list.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { - if (type === BI.Events.CLICK) { - self.fireEvent(BI.SingleSelectList.EVENT_CHANGE, value, obj); - } + + this.editor.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - BI.createWidget(BI.extend({ - element: this - }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ - scrolly: true - }, o.logic, { - items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.list) - })))); - - }, - - hasPrev: function () { - return this.list.hasPrev(); + this.editor.on(BI.StateEditor.EVENT_PAUSE, function () { + self.fireEvent(BI.SingleSelectEditor.EVENT_PAUSE); + }); + this.editor.on(BI.StateEditor.EVENT_CLICK_LABEL, function () { + + }); }, - - hasNext: function () { - return this.list.hasNext(); + + focus: function () { + this.editor.focus(); }, - - prependItems: function (items) { - this.list.prependItems.apply(this.list, arguments); + + blur: function () { + this.editor.blur(); }, - - addItems: function (items) { - this.list.addItems.apply(this.list, arguments); + + setState: function (state) { + this.editor.setState(state); }, - + setValue: function (v) { - this.list.setValue([v]); + this.editor.setValue(v); }, - + getValue: function () { - return this.list.getValue()[0]; + var v = this.editor.getState(); + if (BI.isArray(v) && v.length > 0) { + return v[v.length - 1]; + } + return ""; + }, - - empty: function () { - this.list.empty(); + + getKeywords: function () { + var val = this.editor.getLastValidValue(); + var keywords = val.match(/[\S]+/g); + if (BI.isEndWithBlank(val)) { + return keywords.concat([" "]); + } + return keywords; }, - + populate: function (items) { - this.list.populate.apply(this.list, arguments); + + } +}); +BI.SingleSelectEditor.EVENT_PAUSE = "SingleSelectEditor.EVENT_PAUSE"; +BI.shortcut("bi.single_select_editor", BI.SingleSelectEditor);/** + * searcher + * Created by guy on 15/11/3. + * @class BI.SingleSelectSearcher + * @extends Widget + */ +BI.SingleSelectSearcher = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.SingleSelectSearcher.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-searcher", + itemsCreator: BI.emptyFn, + el: {}, + popup: {}, + valueFormatter: BI.emptyFn, + adapter: null, + masker: {} + }); }, - - resetHeight: function (h) { - this.list.resetHeight ? this.list.resetHeight(h) : - this.list.element.css({"max-height": h + "px"}); + + _init: function () { + BI.SingleSelectSearcher.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.editor = BI.createWidget(o.el, { + type: "bi.single_select_editor", + height: o.height + }); + + this.searcher = BI.createWidget({ + type: "bi.searcher", + element: this, + height: o.height, + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback(); + }, + el: this.editor, + + popup: BI.extend({ + type: "bi.single_select_search_pane", + valueFormatter: o.valueFormatter, + keywordGetter: function () { + return self.editor.getValue(); + }, + itemsCreator: function (op, callback) { + op.keyword = self.editor.getValue(); + this.setKeyword(op.keyword); + o.itemsCreator(op, callback); + } + }, o.popup), + + adapter: o.adapter, + masker: o.masker + }); + this.searcher.on(BI.Searcher.EVENT_START, function () { + self.fireEvent(BI.SingleSelectSearcher.EVENT_START); + }); + this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { + if (this.hasMatched()) { + + } + self.fireEvent(BI.SingleSelectSearcher.EVENT_PAUSE); + }); + this.searcher.on(BI.Searcher.EVENT_STOP, function () { + self.fireEvent(BI.SingleSelectSearcher.EVENT_STOP); + }); + this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleSelectSearcher.EVENT_CHANGE, arguments); + }); + this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { + var keywords = this.getKeywords(); + self.fireEvent(BI.SingleSelectSearcher.EVENT_SEARCHING, keywords); + }); + }, + + adjustView: function () { + this.searcher.adjustView(); + }, + + isSearching: function () { + return this.searcher.isSearching(); }, - - setNotSelectedValue: function () { - this.list.setNotSelectedValue.apply(this.list, arguments); + + stopSearch: function () { + this.searcher.stopSearch(); }, - - getNotSelectedValue: function () { - return this.list.getNotSelectedValue(); + + getKeyword: function () { + return this.editor.getValue(); }, - - getAllButtons: function () { - return this.list.getAllButtons(); + + hasMatched: function () { + return this.searcher.hasMatched(); }, - - getAllLeaves: function () { - return this.list.getAllLeaves(); + + hasChecked: function () { + return this.searcher.getView() && this.searcher.getView().hasChecked(); }, - - getSelectedButtons: function () { - return this.list.getSelectedButtons(); + + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - - getNotSelectedButtons: function () { - return this.list.getNotSelectedButtons(); + + setState: function (v) { + var o = this.options; + v || (v = ""); + if (v === "") { + this.editor.setState(BI.Selection.None); + } else { + this.editor.setState(o.valueFormatter(v + "") || (v + "")); + } }, - - getIndexByValue: function (value) { - return this.list.getIndexByValue(value); + + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); }, - - getNodeById: function (id) { - return this.list.getNodeById(id); + + getKey: function () { + return this.editor.getValue(); }, - - getNodeByValue: function (value) { - return this.list.getNodeByValue(value); + + getValue: function () { + return this.searcher.getValue(); + }, + + populate: function (items) { + this.searcher.populate.apply(this.searcher, arguments); } }); -BI.SingleSelectList.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_list", BI.SingleSelectList);/** - * 单选加载数据面板 - * Created by guy on 15/11/2. - * @class BI.SingleSelectLoader + +BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectSearcher.EVENT_START = "EVENT_START"; +BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP"; +BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.shortcut("bi.single_select_searcher", BI.SingleSelectSearcher);/** + * 单选加载数据搜索loader面板 + * Created by guy on 15/11/4. + * @class BI.SingleSelectSearchLoader * @extends Widget */ -BI.SingleSelectLoader = BI.inherit(BI.Widget, { +BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectLoader.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-loader", - logic: { - dynamic: true - }, - el: { - height: 400 - }, - valueFormatter: BI.emptyFn, + return BI.extend(BI.SingleSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-search-loader", itemsCreator: BI.emptyFn, - onLoaded: BI.emptyFn + keywordGetter: BI.emptyFn, + valueFormatter: BI.emptyFn }); }, _init: function () { - BI.SingleSelectLoader.superclass._init.apply(this, arguments); + BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); var self = this, opts = this.options; var hasNext = false; @@ -19653,9 +16887,11 @@ BI.SingleSelectLoader = BI.inherit(BI.Widget, { this.button_group = BI.createWidget({ type: "bi.single_select_list", element: this, - logic: opts.logic, - el: BI.extend({ - onLoaded: opts.onLoaded, + logic: { + dynamic: false + }, + el: { + tipText: BI.i18nText("BI-No_Select"), el: { type: "bi.loader", isDefaultInit: false, @@ -19675,13 +16911,13 @@ BI.SingleSelectLoader = BI.inherit(BI.Widget, { }] } } - }, opts.el), + }, itemsCreator: function (op, callback) { - var startValue = self._startValue; self.storeValue && (op = BI.extend(op || {}, { selectedValues: [self.storeValue] })); opts.itemsCreator(op, function (ob) { + var keyword = ob.keyword = opts.keywordGetter(); hasNext = ob.hasNext; var firstItems = []; if (op.times === 1 && self.storeValue) { @@ -19696,12 +16932,27 @@ BI.SingleSelectLoader = BI.inherit(BI.Widget, { }); firstItems = self._createItems(json); } - callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); + if(keyword) { + var flag = false; + for(var i = 0; i < ob.items.length; i++) { + if(BI.contains(ob.items[i], keyword)) { + flag = true; + } + } + if(!flag) { + var preItems = self._createItems([{ + text: keyword, + value: keyword, + title: keyword, + selected: false + }]); + firstItems = firstItems.concat(preItems); + } + } + callback(firstItems.concat(self._createItems(ob.items)), keyword); if (op.times === 1 && self.storeValue) { - BI.isKey(startValue) && (self.storeValue = startValue); self.setValue(self.storeValue); } - (op.times === 1) && self._scrollToTop(); }); }, hasNext: function () { @@ -19712,153 +16963,525 @@ BI.SingleSelectLoader = BI.inherit(BI.Widget, { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectLoader.EVENT_CHANGE, arguments); + self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); }); }, _createItems: function (items) { return BI.createItems(items, { type: "bi.single_select_radio_item", - logic: this.options.logic, + logic: { + dynamic: false + }, height: 25, selected: false }); }, - _scrollToTop: function () { - var self = this; - BI.delay(function () { - self.button_group.element.scrollTop(0); - }, 30); + _filterValues: function (src) { + var o = this.options; + var keyword = o.keywordGetter(); + var values = BI.deepClone(src.value) || []; + var newValues = BI.map(values, function (i, v) { + return { + text: o.valueFormatter(v) || v, + value: v + }; + }); + if (BI.isKey(keyword)) { + var search = BI.Func.getSearchResult(newValues, keyword); + values = search.match.concat(search.find); + } + return BI.map(values, function (i, v) { + return { + text: v.text, + title: v.text, + value: v.value, + selected: false + }; + }); + }, + + setValue: function (v) { + // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = v; + this.button_group.setValue(v); + }, + + getValue: function () { + return this.button_group.getValue(); + }, + + getAllButtons: function () { + return this.button_group.getAllButtons(); + }, + + empty: function () { + this.button_group.empty(); + }, + + populate: function (items) { + this.button_group.populate.apply(this.button_group, arguments); + }, + + resetHeight: function (h) { + this.button_group.resetHeight(h); + }, + + resetWidth: function (w) { + this.button_group.resetWidth(w); + } +}); + +BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_search_add_loader", BI.SingleSelectSearchLoader);/** + * + * 在搜索框中输入文本弹出的面板 + * @class BI.SingleSelectSearchPane + * @extends Widget + */ + +BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { + + constants: { + height: 25, + lgap: 10, + tgap: 5 + }, + + _defaultConfig: function () { + return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-search-pane bi-card", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + keywordGetter: BI.emptyFn + }); + }, + + _init: function () { + BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.tooltipClick = BI.createWidget({ + type: "bi.label", + invisible: true, + text: BI.i18nText("BI-Click_Blank_To_Select"), + cls: "single-select-toolbar", + height: this.constants.height + }); + + this.loader = BI.createWidget({ + type: "bi.single_select_search_add_loader", + keywordGetter: o.keywordGetter, + valueFormatter: o.valueFormatter, + itemsCreator: function (op, callback) { + o.itemsCreator.apply(self, [op, function (res) { + callback(res); + self.setKeyword(o.keywordGetter()); + }]); + } + }); + this.loader.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + this.resizer = BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.tooltipClick, + height: 0 + }, { + el: this.loader + }] + }); + this.tooltipClick.setVisible(false); }, - _assertValue: function (val) { - val || (val = ""); + setKeyword: function (keyword) { + var btn; + var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === btn.getValue()); + if (isVisible !== this.tooltipClick.isVisible()) { + this.tooltipClick.setVisible(isVisible); + this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); + this.resizer.resize(); + } }, - setStartValue: function (v) { - this._startValue = v; + hasMatched: function () { + return this.tooltipClick.isVisible(); }, setValue: function (v) { - this.storeValue = v || ""; - this._assertValue(this.storeValue); - this.button_group.setValue(this.storeValue); + this.loader.setValue(v); }, getValue: function () { - return this.button_group.getValue(); - }, - - getAllButtons: function () { - return this.button_group.getAllButtons(); + return this.loader.getValue(); }, empty: function () { - this.button_group.empty(); + this.loader.empty(); }, populate: function (items) { - this.button_group.populate.apply(this.button_group, arguments); - }, - - resetHeight: function (h) { - this.button_group.resetHeight(h); - }, - - resetWidth: function (w) { - this.button_group.resetWidth(w); + this.loader.populate.apply(this.loader, arguments); } }); -BI.SingleSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_loader", BI.SingleSelectLoader);/** - * 带加载的单选下拉面板 - * @class BI.SingleSelectPopupView - * @extends Widget +BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; + +BI.shortcut("bi.single_select_search_add_pane", BI.SingleSelectSearchPane);/** + * + * @class BI.SingleSelectCombo + * @extends BI.Single */ -BI.SingleSelectPopupView = BI.inherit(BI.Widget, { +BI.SingleSelectCombo = BI.inherit(BI.Single, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectPopupView.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-popup-view", - maxWidth: "auto", - minWidth: 135, - maxHeight: 400, - valueFormatter: BI.emptyFn, + return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-combo", itemsCreator: BI.emptyFn, - onLoaded: BI.emptyFn + valueFormatter: BI.emptyFn, + height: 28 }); }, _init: function () { - BI.SingleSelectPopupView.superclass._init.apply(this, arguments); - var self = this, opts = this.options; + BI.SingleSelectCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + var assertShowValue = function () { + BI.isKey(self._startValue) && (self.storeValue = self._startValue); + self.trigger.getSearcher().setState(self.storeValue); + }; + this.storeValue = ""; + // 标记正在请求数据 + this.requesting = false; + + this.trigger = BI.createWidget({ + type: "bi.single_select_add_trigger", + height: o.height, + // adapter: this.popup, + masker: { + offset: { + left: 1, + top: 1, + right: 2, + bottom: 33 + } + }, + valueFormatter: o.valueFormatter, + itemsCreator: function (op, callback) { + o.itemsCreator(op, function (res) { + if (op.times === 1 && BI.isNotNull(op.keywords)) { + // 预防trigger内部把当前的storeValue改掉 + self.trigger.setValue(self.getValue()); + } + callback.apply(self, arguments); + }); + } + }); + + this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { + self._setStartValue(""); + this.getSearcher().setValue(self.storeValue); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { + self._setStartValue(""); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { + if (this.getSearcher().hasMatched()) { + var keyword = this.getSearcher().getKeyword(); + self._join({ + type: BI.Selection.Multi, + value: [keyword] + }, function () { + self.combo.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self.populate(); + self._setStartValue(""); + }); + } + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) { + var last = BI.last(keywords); + keywords = BI.initial(keywords || []); + if (keywords.length > 0) { + self._joinKeywords(keywords, function () { + if (BI.isEndWithBlank(last)) { + self.combo.setValue(self.storeValue); + assertShowValue(); + self.combo.populate(); + self._setStartValue(""); + } else { + self.combo.setValue(self.storeValue); + assertShowValue(); + } + }); + } + }); + + this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { + self.storeValue = this.getValue(); + assertShowValue(); + }); + this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + }); + + this.combo = BI.createWidget({ + type: "bi.combo", + toggle: false, + el: this.trigger, + adjustLength: 1, + popup: { + type: "bi.single_select_popup_view", + ref: function () { + self.popup = this; + self.trigger.setAdapter(this); + }, + listeners: [{ + eventName: BI.SingleSelectPopupView.EVENT_CHANGE, + action: function () { + self.storeValue = this.getValue(); + self._adjust(function () { + assertShowValue(); + }); + } + }, { + eventName: BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM, + action: function () { + self._defaultState(); + } + }, { + eventName: BI.SingleSelectPopupView.EVENT_CLICK_CLEAR, + action: function () { + self.setValue(); + self._defaultState(); + } + }], + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, + onLoaded: function () { + BI.nextTick(function () { + self.combo.adjustWidth(); + self.combo.adjustHeight(); + self.trigger.getSearcher().adjustView(); + }); + } + }, + hideChecker: function (e) { + return triggerBtn.element.find(e.target).length === 0; + } + }); + + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + this.setValue(self.storeValue); + BI.nextTick(function () { + self.populate(); + }); + }); + // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 + this.wants2Quit = false; + this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { + // important:关闭弹出时又可能没有退出编辑状态 + self.trigger.stopEditing(); + if (self.requesting === true) { + self.wants2Quit = true; + } else { + self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + } + }); + + var triggerBtn = BI.createWidget({ + type: "bi.trigger_icon_button", + width: o.height, + height: o.height, + cls: "single-select-trigger-icon-button" + }); + triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } else { + self.combo.showView(); + } + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.combo, + left: 0, + right: 0, + top: 0, + bottom: 0 + }, { + el: triggerBtn, + right: 0, + top: 0, + bottom: 0 + }] + }); + }, + + _defaultState: function () { + this.trigger.stopEditing(); + this.combo.hideView(); + }, + + _assertValue: function (val) { + val || (val = ""); + }, + + _makeMap: function (values) { + return BI.makeObject(values || []); + }, - this.loader = BI.createWidget({ - type: "bi.single_select_loader", - itemsCreator: opts.itemsCreator, - valueFormatter: opts.valueFormatter, - onLoaded: opts.onLoaded + _joinKeywords: function (keywords, callback) { + var self = this, o = this.options; + this._assertValue(this.storeValue); + this.requesting = true; + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + keywords: keywords + }, function (ob) { + var values = BI.map(ob.items, "value"); + digest(values); }); - this.popupView = BI.createWidget({ - type: "bi.multi_popup_view", - stopPropagation: false, - maxWidth: opts.maxWidth, - minWidth: opts.minWidth, - maxHeight: opts.maxHeight, - element: this, - buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], - el: this.loader - }); + function digest (items) { + var selectedMap = self._makeMap(items); + BI.each(keywords, function (i, val) { + if (BI.isNotNull(selectedMap[val])) { + self.storeValue.value["remove"](val); + } + }); + self._adjust(callback); + } + }, - this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectPopupView.EVENT_CHANGE); - }); - this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { - switch (index) { - case 0: - self.fireEvent(BI.SingleSelectPopupView.EVENT_CLICK_CLEAR); - break; - case 1: - self.fireEvent(BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM); - break; + _joinAll: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + this.requesting = true; + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + keywords: [this.trigger.getKey()] + }, function (ob) { + var items = BI.map(ob.items, "value"); + if (self.storeValue.type === res.type) { + var change = false; + var map = self._makeMap(self.storeValue.value); + BI.each(items, function (i, v) { + if (BI.isNotNull(map[v])) { + change = true; + delete map[v]; + } + }); + change && (self.storeValue.value = BI.values(map)); + self._adjust(callback); + return; } + var selectedMap = self._makeMap(self.storeValue.value); + var notSelectedMap = self._makeMap(res.value); + var newItems = []; + BI.each(items, function (i, item) { + if (BI.isNotNull(selectedMap[items[i]])) { + delete selectedMap[items[i]]; + } + if (BI.isNull(notSelectedMap[items[i]])) { + newItems.push(item); + } + }); + self.storeValue.value = newItems.concat(BI.values(selectedMap)); + self._adjust(callback); }); }, - setStartValue: function (v) { - this.loader.setStartValue(v); + _adjust: function (callback) { + var self = this, o = this.options; + if (!this._count) { + o.itemsCreator({ + type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH + }, function (res) { + self._count = res.count; + adjust(); + callback(); + }); + } else { + adjust(); + callback(); + + } + + function adjust () { + if (self.wants2Quit === true) { + self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + self.wants2Quit = false; + } + self.requesting = false; + } }, - setValue: function (v) { - this.popupView.setValue(v); + _join: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + this._assertValue(this.storeValue); + if (this.storeValue.type === res.type) { + var map = this._makeMap(this.storeValue.value); + BI.each(res.value, function (i, v) { + if (!map[v]) { + self.storeValue.value.push(v); + map[v] = v; + } + }); + var change = false; + BI.each(res.assist, function (i, v) { + if (BI.isNotNull(map[v])) { + change = true; + delete map[v]; + } + }); + change && (this.storeValue.value = BI.values(map)); + self._adjust(callback); + return; + } + this._joinAll(res, callback); }, - getValue: function () { - return this.popupView.getValue(); + _setStartValue: function (value) { + this._startValue = value; + this.popup.setStartValue(value); }, - populate: function (items) { - this.popupView.populate.apply(this.popupView, arguments); + setValue: function (v) { + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.combo.setValue(this.storeValue); }, - resetHeight: function (h) { - this.popupView.resetHeight(h); + getValue: function () { + return this.storeValue; }, - resetWidth: function (w) { - this.popupView.resetWidth(w); + populate: function () { + this._count = null; + this.combo.populate.apply(this.combo, arguments); } }); -BI.SingleSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; -BI.SingleSelectPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; +BI.extend(BI.SingleSelectCombo, { + REQ_GET_DATA_LENGTH: 0, + REQ_GET_ALL_DATA: -1 +}); +BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView);/** +BI.shortcut("bi.single_select_add_combo", BI.SingleSelectCombo);/** * * 单选下拉框 * @class BI.SingleSelectTrigger @@ -19895,7 +17518,7 @@ BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { } this.searcher = BI.createWidget(o.searcher, { - type: "bi.single_select_searcher", + type: "bi.single_select_add_searcher", height: o.height, itemsCreator: o.itemsCreator, valueFormatter: o.valueFormatter, @@ -19957,98 +17580,17 @@ BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { return this.searcher.getValue(); } }); - -BI.SingleSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; -BI.SingleSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; -BI.SingleSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectTrigger.EVENT_START = "EVENT_START"; -BI.SingleSelectTrigger.EVENT_STOP = "EVENT_STOP"; -BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; - -BI.shortcut("bi.single_select_trigger", BI.SingleSelectTrigger);/** - * 单选输入框 - * Created by guy on 15/11/3. - * @class BI.SingleSelectEditor - * @extends Widget - */ -BI.SingleSelectEditor = BI.inherit(BI.Widget, { - - _const: { - checkSelected: BI.i18nText("BI-Check_Selected") - }, - - _defaultConfig: function () { - return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-editor", - el: {} - }); - }, - - _init: function () { - BI.SingleSelectEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget(o.el, { - type: "bi.state_editor", - element: this, - height: o.height, - watermark: BI.i18nText("BI-Basic_Search"), - allowBlank: true - }); - - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.editor.on(BI.StateEditor.EVENT_PAUSE, function () { - self.fireEvent(BI.SingleSelectEditor.EVENT_PAUSE); - }); - this.editor.on(BI.StateEditor.EVENT_CLICK_LABEL, function () { - - }); - }, - - focus: function () { - this.editor.focus(); - }, - - blur: function () { - this.editor.blur(); - }, - - setState: function (state) { - this.editor.setState(state); - }, - - setValue: function (v) { - this.editor.setValue(v); - }, - - getValue: function () { - var v = this.editor.getState(); - if (BI.isArray(v) && v.length > 0) { - return v[v.length - 1]; - } - return ""; - - }, - - getKeywords: function () { - var val = this.editor.getLastValidValue(); - var keywords = val.match(/[\S]+/g); - if (BI.isEndWithBlank(val)) { - return keywords.concat([" "]); - } - return keywords; - }, - - populate: function (items) { - - } -}); -BI.SingleSelectEditor.EVENT_PAUSE = "SingleSelectEditor.EVENT_PAUSE"; -BI.shortcut("bi.single_select_editor", BI.SingleSelectEditor);/** + +BI.SingleSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.SingleSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; +BI.SingleSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectTrigger.EVENT_START = "EVENT_START"; +BI.SingleSelectTrigger.EVENT_STOP = "EVENT_STOP"; +BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; + +BI.shortcut("bi.single_select_add_trigger", BI.SingleSelectTrigger);/** * searcher * Created by guy on 15/11/3. * @class BI.SingleSelectSearcher @@ -20088,7 +17630,7 @@ BI.SingleSelectSearcher = BI.inherit(BI.Widget, { el: this.editor, popup: BI.extend({ - type: "bi.single_select_search_pane", + type: "bi.single_select_search_add_pane", valueFormatter: o.valueFormatter, keywordGetter: function () { return self.editor.getValue(); @@ -20179,2513 +17721,3336 @@ BI.SingleSelectSearcher = BI.inherit(BI.Widget, { this.searcher.populate.apply(this.searcher, arguments); } }); - -BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectSearcher.EVENT_START = "EVENT_START"; -BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP"; -BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.shortcut("bi.single_select_searcher", BI.SingleSelectSearcher);/** - * 单选加载数据搜索loader面板 - * Created by guy on 15/11/4. - * @class BI.SingleSelectSearchLoader - * @extends Widget + +BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectSearcher.EVENT_START = "EVENT_START"; +BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP"; +BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; +BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.shortcut("bi.single_select_add_searcher", BI.SingleSelectSearcher);/** + * Created by User on 2017/11/16. + */ +BI.SignTextEditor = BI.inherit(BI.Widget, { + _defaultConfig: function () { + var conf = BI.SignTextEditor.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-sign-initial-editor", + hgap: 4, + vgap: 2, + lgap: 0, + rgap: 0, + tgap: 0, + bgap: 0, + validationChecker: BI.emptyFn, + quitChecker: BI.emptyFn, + allowBlank: true, + watermark: "", + errorText: "", + text: "", + height: 24 + }); + }, + + _init: function () { + BI.SignTextEditor.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.editor = BI.createWidget({ + type: "bi.editor", + height: o.height, + hgap: o.hgap, + vgap: o.vgap, + lgap: o.lgap, + rgap: o.rgap, + tgap: o.tgap, + bgap: o.bgap, + value: o.value, + validationChecker: o.validationChecker, + quitChecker: o.quitChecker, + allowBlank: o.allowBlank, + watermark: o.watermark, + errorText: o.errorText + }); + this.text = BI.createWidget({ + type: "bi.text_button", + cls: "sign-editor-text", + title: o.title, + warningTitle: o.warningTitle, + tipType: o.tipType, + textAlign: "left", + height: o.height, + hgap: 4, + handler: function () { + self._showInput(); + self.editor.focus(); + self.editor.selectAll(); + } + }); + this.text.on(BI.TextButton.EVENT_CHANGE, function () { + BI.nextTick(function () { + self.fireEvent(BI.SignTextEditor.EVENT_CLICK_LABEL); + }); + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.text, + left: 0, + right: 0, + top: 0, + bottom: 0 + }] + }); + this.editor.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + this.editor.on(BI.Editor.EVENT_CONFIRM, function () { + self._showHint(); + self._checkText(); + self.fireEvent(BI.SignTextEditor.EVENT_CONFIRM, arguments); + }); + this.editor.on(BI.Editor.EVENT_ERROR, function () { + self._checkText(); + }); + BI.createWidget({ + type: "bi.vertical", + scrolly: false, + element: this, + items: [this.editor] + }); + this._showHint(); + self._checkText(); + }, + + _checkText: function () { + var o = this.options; + BI.nextTick(BI.bind(function () { + if (this.editor.getValue() === "") { + this.text.setValue(o.watermark || ""); + this.text.element.addClass("bi-water-mark"); + } else { + var v = this.editor.getValue(); + v = (BI.isEmpty(v) || v == o.text) ? o.text : v + o.text; + this.text.setValue(v); + this.text.element.removeClass("bi-water-mark"); + } + }, this)); + }, + + _showInput: function () { + this.editor.visible(); + this.text.invisible(); + }, + + _showHint: function () { + this.editor.invisible(); + this.text.visible(); + }, + + setTitle: function (title) { + this.text.setTitle(title); + }, + + setWarningTitle: function (title) { + this.text.setWarningTitle(title); + }, + + focus: function () { + this._showInput(); + this.editor.focus(); + }, + + blur: function () { + this.editor.blur(); + this._showHint(); + this._checkText(); + }, + + doRedMark: function () { + if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { + return; + } + this.text.doRedMark.apply(this.text, arguments); + }, + + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); + }, + + doHighLight: function () { + if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { + return; + } + this.text.doHighLight.apply(this.text, arguments); + }, + + unHighLight: function () { + this.text.unHighLight.apply(this.text, arguments); + }, + + isValid: function () { + return this.editor.isValid(); + }, + + setErrorText: function (text) { + this.editor.setErrorText(text); + }, + + getErrorText: function () { + return this.editor.getErrorText(); + }, + + isEditing: function () { + return this.editor.isEditing(); + }, + + getLastValidValue: function () { + return this.editor.getLastValidValue(); + }, + + setValue: function (v) { + this.editor.setValue(v); + this._checkText(); + }, + + getValue: function () { + return this.editor.getValue(); + }, + + getState: function () { + return this.text.getValue(); + }, + + setState: function (v) { + var o = this.options; + this._showHint(); + v = (BI.isEmpty(v) || v == o.text) ? o.text : v + o.text; + this.text.setValue(v); + } +}); +BI.SignTextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.SignTextEditor.EVENT_CLICK_LABEL = "EVENT_CLICK_LABEL"; + +BI.shortcut("bi.sign_text_editor", BI.SignTextEditor);/** + * Created by zcf on 2016/9/22. + */ +BI.SliderIconButton = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.SliderIconButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-slider-button" + }); + }, + _init: function () { + BI.extend(BI.SliderIconButton.superclass._init.apply(this, arguments)); + this.slider = BI.createWidget({ + type: "bi.icon_button", + cls: "slider-icon slider-button", + iconWidth: 14, + iconHeight: 14, + height: 14, + width: 14 + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.slider, + top: 7, + left: -7 + }], + width: 0, + height: 14 + }); + } +}); +BI.shortcut("bi.single_slider_button", BI.SliderIconButton);/** + * Created by zcf on 2016/9/22. */ -BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { - +BI.SingleSlider = BI.inherit(BI.Widget, { + _constant: { + EDITOR_WIDTH: 90, + EDITOR_HEIGHT: 30, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-search-loader", - itemsCreator: BI.emptyFn, - keywordGetter: BI.emptyFn, - valueFormatter: BI.emptyFn + return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-slider bi-slider-track", + digit: false, + unit: "" }); }, - _init: function () { - BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); + BI.SingleSlider.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - var hasNext = false; + var self = this, o = this.options; + var c = this._constant; + this.enable = false; + this.value = ""; - this.button_group = BI.createWidget({ - type: "bi.single_select_list", + this.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 + }); + this.blueTrack = BI.createWidget({ + type: "bi.layout", + cls: "blue-track bi-high-light-background", + height: 6 + }); + this.track = this._createTrackWrapper(); + + this.slider = BI.createWidget({ + type: "bi.single_slider_button" + }); + this._draggable(this.slider); + var sliderVertical = BI.createWidget({ + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.slider] + }], + hgap: c.SLIDER_WIDTH_HALF, + height: c.SLIDER_HEIGHT + }); + sliderVertical.element.click(function (e) { + if (self.enable) { + var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; + var trackLength = self.track.element[0].scrollWidth; + var percent = 0; + if (offset < 0) { + percent = 0; + } + if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { + percent = offset * 100 / self._getGrayTrackLength(); + } + if (offset > (trackLength - c.SLIDER_WIDTH)) { + percent = 100; + } + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setAllPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.label.setValue(v); + self.value = v; + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + } + }); + this.label = BI.createWidget({ + type: "bi.sign_text_editor", + cls: "slider-editor-button", + errorText: "", + text: o.unit, + width: c.EDITOR_WIDTH - 2, + allowBlank: false, + validationChecker: function (v) { + return self._checkValidation(v); + } + }); + this.label.element.hover(function () { + self.label.element.removeClass("bi-border").addClass("bi-border"); + }, function () { + self.label.element.removeClass("bi-border"); + }); + this.label.on(BI.SignEditor.EVENT_CONFIRM, function () { + var v = BI.parseFloat(this.getValue()); + var percent = self._getPercentByValue(v); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setAllPosition(significantPercent); + this.setValue(v); + self.value = v; + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + }); + this._setVisible(false); + BI.createWidget({ + type: "bi.absolute", element: this, - logic: { - dynamic: false - }, - el: { - tipText: BI.i18nText("BI-No_Select"), + items: [{ el: { - type: "bi.loader", - isDefaultInit: false, - logic: { - dynamic: true, - scrolly: true - }, - el: { - chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, - behaviors: { - redmark: function () { - return true; - } - }, - layouts: [{ - type: "bi.vertical" + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.track, + width: "100%", + height: c.TRACK_HEIGHT }] - } - } - }, - itemsCreator: function (op, callback) { - self.storeValue && (op = BI.extend(op || {}, { - selectedValues: [self.storeValue] - })); - opts.itemsCreator(op, function (ob) { - var keyword = ob.keyword = opts.keywordGetter(); - hasNext = ob.hasNext; - var firstItems = []; - if (op.times === 1 && self.storeValue) { - var json = BI.map([self.storeValue], function (i, v) { - var txt = opts.valueFormatter(v) || v; - return { - text: txt, - value: v, - title: txt, - selected: false - }; - }); - firstItems = self._createItems(json); - } - if(keyword) { - var flag = false; - for(var i = 0; i < ob.items.length; i++) { - if(BI.contains(ob.items[i], keyword)) { - flag = true; - } - } - if(!flag) { - var preItems = self._createItems([{ - text: keyword, - value: keyword, - title: keyword, - selected: false - }]); - firstItems = firstItems.concat(preItems); - } - } - callback(firstItems.concat(self._createItems(ob.items)), keyword); - if (op.times === 1 && self.storeValue) { - self.setValue(self.storeValue); - } - }); - }, - hasNext: function () { - return hasNext; + }], + hgap: 7, + height: c.TRACK_HEIGHT + }, + top: 23, + left: 0, + width: "100%" + }, { + el: sliderVertical, + top: 20, + left: 0, + width: "100%" + }, { + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.label] + }], + rgap: c.EDITOR_WIDTH, + height: c.EDITOR_HEIGHT + }, + top: 0, + left: 0, + width: "100%" + }] + }); + }, + + _draggable: function (widget) { + var self = this, o = this.options; + var startDrag = false; + var size = 0, offset = 0, defaultSize = 0; + var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { + if (mouseMoveTracker.isDragging()) { + startDrag = true; + offset += deltaX; + size = optimizeSize(defaultSize + offset); + widget.element.addClass("dragging"); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 + self._setBlueTrack(significantPercent); + self._setLabelPosition(significantPercent); + self._setSliderPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.label.setValue(v); + self.value = v; + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + } + }, function () { + if (startDrag === true) { + size = optimizeSize(size); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setSliderPosition(significantPercent); + size = 0; + offset = 0; + defaultSize = size; + startDrag = false; } + widget.element.removeClass("dragging"); + mouseMoveTracker.releaseMouseMoves(); + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + }, window); + widget.element.on("mousedown", function (event) { + if(!widget.isEnabled()) { + return; + } + defaultSize = this.offsetLeft; + optimizeSize(defaultSize); + mouseMoveTracker.captureMouseMoves(event); }); - this.button_group.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); - }); + + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); + } }, - _createItems: function (items) { - return BI.createItems(items, { - type: "bi.single_select_radio_item", - logic: { - dynamic: false - }, - height: 25, - selected: false + _createTrackWrapper: function () { + return BI.createWidget({ + type: "bi.absolute", + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.grayTrack, + top: 0, + left: 0, + width: "100%" + }, { + el: this.blueTrack, + top: 0, + left: 0, + width: "0%" + }] + }], + hgap: 8, + height: 8 + }, + top: 8, + left: 0, + width: "100%" + }] }); }, - _filterValues: function (src) { + _checkValidation: function (v) { var o = this.options; - var keyword = o.keywordGetter(); - var values = BI.deepClone(src.value) || []; - var newValues = BI.map(values, function (i, v) { - return { - text: o.valueFormatter(v) || v, - value: v - }; - }); - if (BI.isKey(keyword)) { - var search = BI.Func.getSearchResult(newValues, keyword); - values = search.match.concat(search.find); + var valid = false; + if (BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)) { + if(o.digit === false) { + valid = true; + }else{ + var dotText = (v + "").split(".")[1] || ""; + valid = (dotText.length === o.digit); + } } - return BI.map(values, function (i, v) { - return { - text: v.text, - title: v.text, - value: v.value, - selected: false - }; - }); + return valid; }, - setValue: function (v) { - // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 - this.storeValue = v; - this.button_group.setValue(v); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - getValue: function () { - return this.button_group.getValue(); + _setLabelPosition: function (percent) { + this.label.element.css({left: percent + "%"}); }, - getAllButtons: function () { - return this.button_group.getAllButtons(); + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); }, - empty: function () { - this.button_group.empty(); + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setLabelPosition(percent); + this._setBlueTrack(percent); }, - populate: function (items) { - this.button_group.populate.apply(this.button_group, arguments); + _setVisible: function (visible) { + this.slider.setVisible(visible); + this.label.setVisible(visible); }, - resetHeight: function (h) { - this.button_group.resetHeight(h); + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - resetWidth: function (w) { - this.button_group.resetWidth(w); - } -}); - -BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_search_add_loader", BI.SingleSelectSearchLoader);/** - * - * 在搜索框中输入文本弹出的面板 - * @class BI.SingleSelectSearchPane - * @extends Widget - */ - -BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { - - constants: { - height: 25, - lgap: 10, - tgap: 5 + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-search-pane bi-card", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - keywordGetter: BI.emptyFn - }); + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, - _init: function () { - BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.tooltipClick = BI.createWidget({ - type: "bi.label", - invisible: true, - text: BI.i18nText("BI-Click_Blank_To_Select"), - cls: "single-select-toolbar", - height: this.constants.height - }); - - this.loader = BI.createWidget({ - type: "bi.single_select_search_add_loader", - keywordGetter: o.keywordGetter, - valueFormatter: o.valueFormatter, - itemsCreator: function (op, callback) { - o.itemsCreator.apply(self, [op, function (res) { - callback(res); - self.setKeyword(o.keywordGetter()); - }]); - } - }); - this.loader.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.resizer = BI.createWidget({ - type: "bi.vtape", - element: this, - items: [{ - el: this.tooltipClick, - height: 0 - }, { - el: this.loader - }] - }); - this.tooltipClick.setVisible(false); + getValue: function () { + return this.value; }, - setKeyword: function (keyword) { - var btn; - var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === btn.getValue()); - if (isVisible !== this.tooltipClick.isVisible()) { - this.tooltipClick.setVisible(isVisible); - this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); - this.resizer.resize(); + setValue: function (v) { + var o = this.options; + v = BI.parseFloat(v); + v = o.digit === false ? v : v.toFixed(o.digit); + if ((!isNaN(v))) { + if (this._checkValidation(v)) { + this.value = v; + } + if (v > this.max) { + this.value = this.max; + } + if (v < this.min) { + this.value = this.min; + } } }, - hasMatched: function () { - return this.tooltipClick.isVisible(); - }, - - setValue: function (v) { - this.loader.setValue(v); + setMinAndMax: function (v) { + var minNumber = BI.parseFloat(v.min); + var maxNumber = BI.parseFloat(v.max); + if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { + this.min = minNumber; + this.max = maxNumber; + } }, - getValue: function () { - return this.loader.getValue(); - }, + reset: function () { + this._setVisible(false); + this.enable = false; + this.value = ""; + this.min = 0; + this.max = 0; + this._setBlueTrack(0); - empty: function () { - this.loader.empty(); }, - populate: function (items) { - this.loader.populate.apply(this.loader, arguments); - } -}); - -BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.single_select_search_add_pane", BI.SingleSelectSearchPane);/** - * - * @class BI.SingleSelectCombo - * @extends BI.Single + populate: function () { + if (!isNaN(this.min) && !isNaN(this.max)) { + this._setVisible(true); + this.enable = true; + this.label.setErrorText(BI.i18nText("BI-Please_Enter") + this.min + "-" + this.max + BI.i18nText("BI-Basic_De") + BI.i18nText("BI-Basic_Number")); + if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { + this.label.setValue(this.value); + this._setAllPosition(this._getPercentByValue(this.value)); + } else { + this.label.setValue(this.max); + this._setAllPosition(100); + } + } + } +}); +BI.SingleSlider.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_slider", BI.SingleSlider);/** + * Created by Urthur on 2017/9/12. */ -BI.SingleSelectCombo = BI.inherit(BI.Single, { - +BI.SingleSliderLabel = BI.inherit(BI.Widget, { + _constant: { + EDITOR_WIDTH: 90, + EDITOR_HEIGHT: 20, + HEIGHT: 20, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, _defaultConfig: function () { - return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-combo", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - height: 28 + return BI.extend(BI.SingleSliderLabel.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-slider-label bi-slider-track", + digit: false, + unit: "" }); }, - _init: function () { - BI.SingleSelectCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.SingleSliderLabel.superclass._init.apply(this, arguments); - var assertShowValue = function () { - BI.isKey(self._startValue) && (self.storeValue = self._startValue); - self.trigger.getSearcher().setState(self.storeValue); - }; - this.storeValue = ""; - // 标记正在请求数据 - this.requesting = false; + var self = this, o = this.options; + var c = this._constant; + this.enable = false; + this.value = ""; - this.trigger = BI.createWidget({ - type: "bi.single_select_add_trigger", - height: o.height, - // adapter: this.popup, - masker: { - offset: { - left: 1, - top: 1, - right: 2, - bottom: 33 - } - }, - valueFormatter: o.valueFormatter, - itemsCreator: function (op, callback) { - o.itemsCreator(op, function (res) { - if (op.times === 1 && BI.isNotNull(op.keywords)) { - // 预防trigger内部把当前的storeValue改掉 - self.trigger.setValue(self.getValue()); - } - callback.apply(self, arguments); - }); - } + this.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 + }); + this.blueTrack = BI.createWidget({ + type: "bi.layout", + cls: "blue-track bi-high-light-background", + height: 6 }); + this.track = this._createTrackWrapper(); - this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { - self._setStartValue(""); - this.getSearcher().setValue(self.storeValue); + this.slider = BI.createWidget({ + type: "bi.single_slider_button" }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { - self._setStartValue(""); + this._draggable(this.slider); + var sliderVertical = BI.createWidget({ + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.slider] + }], + hgap: c.SLIDER_WIDTH_HALF, + height: c.SLIDER_HEIGHT }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { - if (this.getSearcher().hasMatched()) { - var keyword = this.getSearcher().getKeyword(); - self._join({ - type: BI.Selection.Multi, - value: [keyword] - }, function () { - self.combo.setValue(self.storeValue); - self._setStartValue(keyword); - assertShowValue(); - self.populate(); - self._setStartValue(""); - }); + sliderVertical.element.click(function (e) { + if (self.enable) { + var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; + var trackLength = self.track.element[0].scrollWidth; + var percent = 0; + if (offset < 0) { + percent = 0; + } + if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { + percent = offset * 100 / self._getGrayTrackLength(); + } + if (offset > (trackLength - c.SLIDER_WIDTH)) { + percent = 100; + } + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setAllPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.label.setText(v + o.unit); + self.value = v; + self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); } }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function (keywords) { - var last = BI.last(keywords); - keywords = BI.initial(keywords || []); - if (keywords.length > 0) { - self._joinKeywords(keywords, function () { - if (BI.isEndWithBlank(last)) { - self.combo.setValue(self.storeValue); - assertShowValue(); - self.combo.populate(); - self._setStartValue(""); - } else { - self.combo.setValue(self.storeValue); - assertShowValue(); - } - }); - } + this.label = BI.createWidget({ + type: "bi.label", + height: c.HEIGHT, + width: c.EDITOR_WIDTH - 2 }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { - self.storeValue = this.getValue(); - assertShowValue(); - }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } + this._setVisible(false); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.track, + width: "100%", + height: c.TRACK_HEIGHT + }] + }], + hgap: 7, + height: c.TRACK_HEIGHT + }, + top: 13, + left: 0, + width: "100%" + }, { + el: sliderVertical, + top: 10, + left: 0, + width: "100%" + }, { + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.label] + }], + rgap: c.EDITOR_WIDTH, + height: c.EDITOR_HEIGHT + }, + top: 0, + left: 0, + width: "100%" + }] }); + }, - this.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - el: this.trigger, - adjustLength: 1, - popup: { - type: "bi.single_select_popup_view", - ref: function () { - self.popup = this; - self.trigger.setAdapter(this); - }, - listeners: [{ - eventName: BI.SingleSelectPopupView.EVENT_CHANGE, - action: function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - }); - } - }, { - eventName: BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM, - action: function () { - self._defaultState(); - } - }, { - eventName: BI.SingleSelectPopupView.EVENT_CLICK_CLEAR, - action: function () { - self.setValue(); - self._defaultState(); - } - }], - itemsCreator: o.itemsCreator, - valueFormatter: o.valueFormatter, - onLoaded: function () { - BI.nextTick(function () { - self.combo.adjustWidth(); - self.combo.adjustHeight(); - self.trigger.getSearcher().adjustView(); - }); - } - }, - hideChecker: function (e) { - return triggerBtn.element.find(e.target).length === 0; + _draggable: function (widget) { + var self = this, o = this.options; + var startDrag = false; + var size = 0, offset = 0, defaultSize = 0; + var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { + if (mouseMoveTracker.isDragging()) { + startDrag = true; + offset += deltaX; + size = optimizeSize(defaultSize + offset); + widget.element.addClass("dragging"); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 + self._setBlueTrack(significantPercent); + self._setLabelPosition(significantPercent); + self._setSliderPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.label.setValue(v); + self.value = v; + self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); } - }); - - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - this.setValue(self.storeValue); - BI.nextTick(function () { - self.populate(); - }); - }); - // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 - this.wants2Quit = false; - this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { - // important:关闭弹出时又可能没有退出编辑状态 - self.trigger.stopEditing(); - if (self.requesting === true) { - self.wants2Quit = true; - } else { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + }, function () { + if (startDrag === true) { + size = optimizeSize(size); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setSliderPosition(significantPercent); + size = 0; + offset = 0; + defaultSize = size; + startDrag = false; } - }); - - var triggerBtn = BI.createWidget({ - type: "bi.trigger_icon_button", - width: o.height, - height: o.height, - cls: "single-select-trigger-icon-button" - }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); + widget.element.removeClass("dragging"); + mouseMoveTracker.releaseMouseMoves(); + self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); + }, window); + widget.element.on("mousedown", function (event) { + if(!widget.isEnabled()) { + return; } + defaultSize = this.offsetLeft; + optimizeSize(defaultSize); + mouseMoveTracker.captureMouseMoves(event); }); - BI.createWidget({ + + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); + } + }, + + _createTrackWrapper: function () { + return BI.createWidget({ type: "bi.absolute", - element: this, items: [{ - el: this.combo, + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.grayTrack, + top: 0, + left: 0, + width: "100%" + }, { + el: this.blueTrack, + top: 0, + left: 0, + width: "0%" + }] + }], + hgap: 8, + height: 8 + }, + top: 8, left: 0, - right: 0, - top: 0, - bottom: 0 - }, { - el: triggerBtn, - right: 0, - top: 0, - bottom: 0 + width: "100%" }] }); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + _checkValidation: function (v) { + return BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max); }, - _assertValue: function (val) { - val || (val = ""); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + _setLabelPosition: function (percent) { + this.label.element.css({left: percent + "%"}); }, - _joinKeywords: function (keywords, callback) { - var self = this, o = this.options; - this._assertValue(this.storeValue); - this.requesting = true; - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, - keywords: keywords - }, function (ob) { - var values = BI.map(ob.items, "value"); - digest(values); - }); - - function digest (items) { - var selectedMap = self._makeMap(items); - BI.each(keywords, function (i, val) { - if (BI.isNotNull(selectedMap[val])) { - self.storeValue.value["remove"](val); - } - }); - self._adjust(callback); - } + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); }, - _joinAll: function (res, callback) { - var self = this, o = this.options; - this._assertValue(res); - this.requesting = true; - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, - keywords: [this.trigger.getKey()] - }, function (ob) { - var items = BI.map(ob.items, "value"); - if (self.storeValue.type === res.type) { - var change = false; - var map = self._makeMap(self.storeValue.value); - BI.each(items, function (i, v) { - if (BI.isNotNull(map[v])) { - change = true; - delete map[v]; - } - }); - change && (self.storeValue.value = BI.values(map)); - self._adjust(callback); - return; - } - var selectedMap = self._makeMap(self.storeValue.value); - var notSelectedMap = self._makeMap(res.value); - var newItems = []; - BI.each(items, function (i, item) { - if (BI.isNotNull(selectedMap[items[i]])) { - delete selectedMap[items[i]]; - } - if (BI.isNull(notSelectedMap[items[i]])) { - newItems.push(item); - } - }); - self.storeValue.value = newItems.concat(BI.values(selectedMap)); - self._adjust(callback); - }); + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setLabelPosition(percent); + this._setBlueTrack(percent); }, - _adjust: function (callback) { - var self = this, o = this.options; - if (!this._count) { - o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH - }, function (res) { - self._count = res.count; - adjust(); - callback(); - }); - } else { - adjust(); - callback(); + _setVisible: function (visible) { + this.slider.setVisible(visible); + this.label.setVisible(visible); + }, - } + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; + }, - function adjust () { - if (self.wants2Quit === true) { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); - self.wants2Quit = false; - } - self.requesting = false; - } + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - _join: function (res, callback) { - var self = this, o = this.options; - this._assertValue(res); - this._assertValue(this.storeValue); - if (this.storeValue.type === res.type) { - var map = this._makeMap(this.storeValue.value); - BI.each(res.value, function (i, v) { - if (!map[v]) { - self.storeValue.value.push(v); - map[v] = v; - } - }); - var change = false; - BI.each(res.assist, function (i, v) { - if (BI.isNotNull(map[v])) { - change = true; - delete map[v]; - } - }); - change && (this.storeValue.value = BI.values(map)); - self._adjust(callback); - return; - } - this._joinAll(res, callback); + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, - _setStartValue: function (value) { - this._startValue = value; - this.popup.setStartValue(value); + getValue: function () { + return this.value; }, setValue: function (v) { - this.storeValue = v || ""; - this._assertValue(this.storeValue); - this.combo.setValue(this.storeValue); + var o = this.options; + v = BI.parseFloat(v); + v = o.digit === false ? v : v.toFixed(o.digit); + if ((!isNaN(v))) { + if (this._checkValidation(v)) { + this.value = v; + } + if (v > this.max) { + this.value = this.max; + } + if (v < this.min) { + this.value = this.min; + } + } + }, + + setMinAndMax: function (v) { + var minNumber = BI.parseFloat(v.min); + var maxNumber = BI.parseFloat(v.max); + if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { + this.min = minNumber; + this.max = maxNumber; + } }, - getValue: function () { - return this.storeValue; + reset: function () { + this._setVisible(false); + this.enable = false; + this.value = ""; + this.min = 0; + this.max = 0; + this._setBlueTrack(0); }, populate: function () { - this._count = null; - this.combo.populate.apply(this.combo, arguments); + var o = this.options; + if (!isNaN(this.min) && !isNaN(this.max)) { + this._setVisible(true); + this.enable = true; + if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { + this.label.setValue(this.value + o.unit); + this._setAllPosition(this._getPercentByValue(this.value)); + } else { + this.label.setValue(this.max + o.unit); + this._setAllPosition(100); + } + } } }); - -BI.extend(BI.SingleSelectCombo, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 -}); - -BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; - -BI.shortcut("bi.single_select_add_combo", BI.SingleSelectCombo);/** - * - * 单选下拉框 - * @class BI.SingleSelectTrigger - * @extends BI.Trigger +BI.SingleSliderLabel.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_slider_label", BI.SingleSliderLabel);/** + * normal single slider + * Created by Young on 2017/6/21. */ +BI.SingleSliderNormal = BI.inherit(BI.Widget, { -BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { + _constant: { + HEIGHT: 28, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, - constants: { - height: 14, - rgap: 4, - lgap: 4 + props: { + baseCls: "bi-single-slider-normal bi-slider-track", + minMax: { + min: 0, + max: 100 + } + // color: "#3f8ce8" }, - _defaultConfig: function () { - return BI.extend(BI.SingleSelectTrigger.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-trigger bi-border", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - searcher: {}, - switcher: {}, + render: function () { + var self = this; + var c = this._constant; + var track = this._createTrack(); + this.slider = BI.createWidget({ + type: "bi.single_slider_button" + }); + this._draggable(this.slider); - adapter: null, - masker: {} + var sliderVertical = BI.createWidget({ + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.slider] + }], + hgap: c.SLIDER_WIDTH_HALF, + height: c.SLIDER_HEIGHT + }); + sliderVertical.element.click(function (e) { + if (self.enable) { + var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; + var trackLength = self.track.element[0].scrollWidth; + var percent = 0; + if (offset < 0) { + percent = 0; + } + if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { + percent = offset * 100 / self._getGrayTrackLength(); + } + if (offset > (trackLength - c.SLIDER_WIDTH)) { + percent = 100; + } + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setAllPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + self.value = v; + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + } }); - }, - _init: function () { - BI.SingleSelectTrigger.superclass._init.apply(this, arguments); + return { + type: "bi.absolute", + element: this, + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: track, + width: "100%", + height: c.TRACK_HEIGHT + }] + }], + hgap: 7, + height: c.TRACK_HEIGHT + }, + top: 3, + left: 0, + width: "100%" + }, { + el: sliderVertical, + top: 0, + left: 0, + width: "100%" + }] + }; + }, + _draggable: function (widget) { var self = this, o = this.options; - if (o.height) { - this.setHeight(o.height - 2); + var startDrag = false; + var size = 0, offset = 0, defaultSize = 0; + var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { + if (mouseMoveTracker.isDragging()) { + startDrag = true; + offset += deltaX; + size = optimizeSize(defaultSize + offset); + widget.element.addClass("dragging"); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 + self._setBlueTrack(significantPercent); + self._setSliderPosition(significantPercent); + var v = self._getValueByPercent(significantPercent); + v = o.digit === false ? v : v.toFixed(o.digit); + self.value = v; + self.fireEvent(BI.SingleSliderNormal.EVENT_DRAG, v); + } + }, function () { + if (startDrag === true) { + size = optimizeSize(size); + var percent = size * 100 / (self._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + self._setSliderPosition(significantPercent); + size = 0; + offset = 0; + defaultSize = size; + startDrag = false; + } + widget.element.removeClass("dragging"); + mouseMoveTracker.releaseMouseMoves(); + self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + }, window); + widget.element.on("mousedown", function (event) { + if(!widget.isEnabled()) { + return; + } + defaultSize = this.offsetLeft; + optimizeSize(defaultSize); + mouseMoveTracker.captureMouseMoves(event); + }); + + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); } + }, - this.searcher = BI.createWidget(o.searcher, { - type: "bi.single_select_add_searcher", - height: o.height, - itemsCreator: o.itemsCreator, - valueFormatter: o.valueFormatter, - popup: {}, - adapter: o.adapter, - masker: o.masker - }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_START, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_START); - }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_PAUSE, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_PAUSE); - }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_SEARCHING, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_SEARCHING, arguments); - }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_STOP, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_STOP); + _createTrack: function () { + var self = this; + var c = this._constant; + this.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_CHANGE, arguments); + this.blueTrack = BI.createWidget({ + type: "bi.layout", + cls: "blue-track bi-high-light-background", + height: 6 }); + if (this.options.color) { + this.blueTrack.element.css({"background-color": this.options.color}); + } + + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.grayTrack, + top: 0, + left: 0, + width: "100%" + }, { + el: this.blueTrack, + top: 0, + left: 0, + width: "0%" + }] + }], + hgap: 8, + height: 8 + }, + top: 8, + left: 0, + width: "100%" + }], + ref: function (ref) { + self.track = ref; + } + }; + }, + + _checkValidation: function (v) { + return !(BI.isNull(v) || v < this.min || v > this.max); + }, - var wrapper = BI.createWidget({ - type: "bi.htape", - element: this, - items: [ - { - el: this.searcher, - width: "fill" - }, { - el: BI.createWidget(), - width: 30 - }] - }); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - getSearcher: function () { - return this.searcher; + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); }, - stopEditing: function () { - this.searcher.stopSearch(); + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setBlueTrack(percent); }, - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + _setVisible: function (visible) { + this.slider.setVisible(visible); }, - setValue: function (v) { - this.searcher.setValue(v); + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - getKey: function () { - return this.searcher.getKey(); + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); + }, + + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, getValue: function () { - return this.searcher.getValue(); - } -}); + return this.value; + }, -BI.SingleSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; -BI.SingleSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; -BI.SingleSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectTrigger.EVENT_START = "EVENT_START"; -BI.SingleSelectTrigger.EVENT_STOP = "EVENT_STOP"; -BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; + setValue: function (v) { + var value = BI.parseFloat(v); + if ((!isNaN(value))) { + if (this._checkValidation(value)) { + this.value = value; + } + if (value > this.max) { + this.value = this.max; + } + if (value < this.min) { + this.value = this.min; + } + } + }, -BI.shortcut("bi.single_select_add_trigger", BI.SingleSelectTrigger);/** - * searcher - * Created by guy on 15/11/3. - * @class BI.SingleSelectSearcher - * @extends Widget + setMinAndMax: function (v) { + var minNumber = BI.parseFloat(v.min); + var maxNumber = BI.parseFloat(v.max); + if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { + this.min = minNumber; + this.max = maxNumber; + } + }, + + reset: function () { + this._setVisible(false); + this.enable = false; + this.value = ""; + this.min = 0; + this.max = 0; + this._setBlueTrack(0); + }, + + populate: function () { + if (!isNaN(this.min) && !isNaN(this.max)) { + this._setVisible(true); + this.enable = true; + if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { + this._setAllPosition(this._getPercentByValue(this.value)); + } else { + this._setAllPosition(100); + } + } + } +}); +BI.SingleSliderNormal.EVENT_DRAG = "EVENT_DRAG"; +BI.shortcut("bi.single_slider_normal", BI.SingleSliderNormal);/** + * @class BI.SingleTreeCombo + * @extends BI.Widget */ -BI.SingleSelectSearcher = BI.inherit(BI.Widget, { +BI.SingleTreeCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectSearcher.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-searcher", - itemsCreator: BI.emptyFn, - el: {}, - popup: {}, - valueFormatter: BI.emptyFn, - adapter: null, - masker: {} + return BI.extend(BI.SingleTreeCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-tree-combo", + trigger: {}, + height: 24, + text: "", + items: [], + value: "" }); }, _init: function () { - BI.SingleSelectSearcher.superclass._init.apply(this, arguments); + BI.SingleTreeCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.editor = BI.createWidget(o.el, { - type: "bi.single_select_editor", - height: o.height - }); - this.searcher = BI.createWidget({ - type: "bi.searcher", - element: this, + this.trigger = BI.createWidget(BI.extend({ + type: "bi.single_tree_trigger", + text: o.text, height: o.height, - isAutoSearch: false, - isAutoSync: false, - onSearch: function (op, callback) { - callback(); - }, - el: this.editor, - - popup: BI.extend({ - type: "bi.single_select_search_add_pane", - valueFormatter: o.valueFormatter, - keywordGetter: function () { - return self.editor.getValue(); - }, - itemsCreator: function (op, callback) { - op.keyword = self.editor.getValue(); - this.setKeyword(op.keyword); - o.itemsCreator(op, callback); - } - }, o.popup), + items: o.items, + value: o.value + }, o.trigger)); - adapter: o.adapter, - masker: o.masker - }); - this.searcher.on(BI.Searcher.EVENT_START, function () { - self.fireEvent(BI.SingleSelectSearcher.EVENT_START); + this.popup = BI.createWidget({ + type: "bi.single_level_tree", + items: o.items, + value: o.value }); - this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { - if (this.hasMatched()) { + this.combo = BI.createWidget({ + type: "bi.combo", + element: this, + adjustLength: 2, + el: this.trigger, + popup: { + el: this.popup } - self.fireEvent(BI.SingleSelectSearcher.EVENT_PAUSE); }); - this.searcher.on(BI.Searcher.EVENT_STOP, function () { - self.fireEvent(BI.SingleSelectSearcher.EVENT_STOP); + + this.combo.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectSearcher.EVENT_CHANGE, arguments); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW, arguments); }); - this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { - var keywords = this.getKeywords(); - self.fireEvent(BI.SingleSelectSearcher.EVENT_SEARCHING, keywords); + + this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.SingleTreeCombo.EVENT_CHANGE); }); }, - adjustView: function () { - this.searcher.adjustView(); + populate: function (items) { + this.combo.populate(items); }, - isSearching: function () { - return this.searcher.isSearching(); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.trigger.setValue(v); + this.popup.setValue(v); }, - stopSearch: function () { - this.searcher.stopSearch(); - }, + getValue: function () { + return this.popup.getValue(); + } +}); - getKeyword: function () { - return this.editor.getValue(); - }, +BI.SingleTreeCombo.EVENT_CHANGE = "SingleTreeCombo.EVENT_CHANGE"; +BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.single_tree_combo", BI.SingleTreeCombo);/** + * @class BI.SingleTreePopup + * @extends BI.Pane + */ - hasMatched: function () { - return this.searcher.hasMatched(); - }, +BI.SingleTreePopup = BI.inherit(BI.Pane, { - hasChecked: function () { - return this.searcher.getView() && this.searcher.getView().hasChecked(); + _defaultConfig: function () { + return BI.extend(BI.SingleTreePopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-level-tree", + tipText: BI.i18nText("BI-No_Selected_Item"), + items: [], + value: "" + }); }, - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); - }, + _init: function () { + BI.SingleTreePopup.superclass._init.apply(this, arguments); + + var self = this, o = this.options; + + this.tree = BI.createWidget({ + type: "bi.level_tree", + expander: { + isDefaultInit: true + }, + items: o.items, + value: o.value, + chooseType: BI.Selection.Single + }); + + BI.createWidget({ + type: "bi.vertical", + element: this, + items: [this.tree] + }); + + this.tree.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); - setState: function (v) { - var o = this.options; - v || (v = ""); - if (v === "") { - this.editor.setState(BI.Selection.None); - } else { - this.editor.setState(o.valueFormatter(v + "") || (v + "")); - } - }, + this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleTreePopup.EVENT_CHANGE); + }); - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); + this.check(); }, - getKey: function () { - return this.editor.getValue(); + getValue: function () { + return this.tree.getValue(); }, - getValue: function () { - return this.searcher.getValue(); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.tree.setValue(v); }, populate: function (items) { - this.searcher.populate.apply(this.searcher, arguments); + BI.SingleTreePopup.superclass.populate.apply(this, arguments); + this.tree.populate(items); } }); -BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectSearcher.EVENT_START = "EVENT_START"; -BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP"; -BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; -BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.shortcut("bi.single_select_add_searcher", BI.SingleSelectSearcher);/** - * Created by User on 2017/11/16. +BI.SingleTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_level_tree", BI.SingleTreePopup);/** + * @class BI.SingleTreeTrigger + * @extends BI.Trigger */ -BI.SignTextEditor = BI.inherit(BI.Widget, { + +BI.SingleTreeTrigger = BI.inherit(BI.Trigger, { + _defaultConfig: function () { - var conf = BI.SignTextEditor.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-sign-initial-editor", - hgap: 4, - vgap: 2, - lgap: 0, - rgap: 0, - tgap: 0, - bgap: 0, - validationChecker: BI.emptyFn, - quitChecker: BI.emptyFn, - allowBlank: true, - watermark: "", - errorText: "", + return BI.extend(BI.SingleTreeTrigger.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-tree-trigger", + height: 24, text: "", - height: 24 + items: [], + value: "" }); }, _init: function () { - BI.SignTextEditor.superclass._init.apply(this, arguments); + BI.SingleTreeTrigger.superclass._init.apply(this, arguments); + var self = this, o = this.options; - this.editor = BI.createWidget({ - type: "bi.editor", - height: o.height, - hgap: o.hgap, - vgap: o.vgap, - lgap: o.lgap, - rgap: o.rgap, - tgap: o.tgap, - bgap: o.bgap, - value: o.value, - validationChecker: o.validationChecker, - quitChecker: o.quitChecker, - allowBlank: o.allowBlank, - watermark: o.watermark, - errorText: o.errorText - }); - this.text = BI.createWidget({ - type: "bi.text_button", - cls: "sign-editor-text", - title: o.title, - warningTitle: o.warningTitle, - tipType: o.tipType, - textAlign: "left", - height: o.height, - hgap: 4, - handler: function () { - self._showInput(); - self.editor.focus(); - self.editor.selectAll(); - } - }); - this.text.on(BI.TextButton.EVENT_CHANGE, function () { - BI.nextTick(function () { - self.fireEvent(BI.SignTextEditor.EVENT_CLICK_LABEL); - }); - }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.text, - left: 0, - right: 0, - top: 0, - bottom: 0 - }] - }); - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.editor.on(BI.Editor.EVENT_CONFIRM, function () { - self._showHint(); - self._checkText(); - self.fireEvent(BI.SignTextEditor.EVENT_CONFIRM, arguments); - }); - this.editor.on(BI.Editor.EVENT_ERROR, function () { - self._checkText(); - }); - BI.createWidget({ - type: "bi.vertical", - scrolly: false, + + this.trigger = BI.createWidget({ + type: "bi.select_text_trigger", element: this, - items: [this.editor] + text: o.text, + items: o.items, + height: o.height, + value: o.value }); - this._showHint(); - self._checkText(); }, - _checkText: function () { - var o = this.options; - BI.nextTick(BI.bind(function () { - if (this.editor.getValue() === "") { - this.text.setValue(o.watermark || ""); - this.text.element.addClass("bi-water-mark"); - } else { - var v = this.editor.getValue(); - v = (BI.isEmpty(v) || v == o.text) ? o.text : v + o.text; - this.text.setValue(v); - this.text.element.removeClass("bi-water-mark"); + _checkTitle: function () { + var self = this, val = this.getValue(); + BI.any(this.options.items, function (i, item) { + if (val.contains(item.value)) { + self.trigger.setTitle(item.text || item.value); + return true; } - }, this)); - }, - - _showInput: function () { - this.editor.visible(); - this.text.invisible(); - }, - - _showHint: function () { - this.editor.invisible(); - this.text.visible(); - }, - - setTitle: function (title) { - this.text.setTitle(title); + }); }, - setWarningTitle: function (title) { - this.text.setWarningTitle(title); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.options.value = v; + this.trigger.setValue(v); + this._checkTitle(); }, - focus: function () { - this._showInput(); - this.editor.focus(); + getValue: function () { + return this.options.value || []; }, - blur: function () { - this.editor.blur(); - this._showHint(); - this._checkText(); - }, + populate: function (items) { + BI.SingleTreeTrigger.superclass.populate.apply(this, arguments); + this.trigger.populate(items); + } - doRedMark: function () { - if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { - return; - } - this.text.doRedMark.apply(this.text, arguments); - }, +}); - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); - }, +BI.shortcut("bi.single_tree_trigger", BI.SingleTreeTrigger);/** + * 可以单选多选切换的树 + * + * Created by GUY on 2015/12/21. + * @class BI.SwitchTree + * @extends BI.Widget + */ +BI.SwitchTree = BI.inherit(BI.Widget, { - doHighLight: function () { - if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { - return; - } - this.text.doHighLight.apply(this.text, arguments); + _defaultConfig: function () { + return BI.extend(BI.SwitchTree.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-switch-tree", + items: [] + }); }, - unHighLight: function () { - this.text.unHighLight.apply(this.text, arguments); + _init: function () { + BI.SwitchTree.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.tab = BI.createWidget({ + type: "bi.tab", + element: this, + tab: null, + showIndex: BI.SwitchTree.SelectType.SingleSelect, + cardCreator: BI.bind(this._createTree, this) + }); }, - isValid: function () { - return this.editor.isValid(); + _createTree: function (type) { + var self = this, o = this.options; + switch (type) { + case BI.SwitchTree.SelectType.SingleSelect: + this.levelTree = BI.createWidget({ + type: "bi.multilayer_single_level_tree", + isDefaultInit: true, + items: BI.deepClone(o.items), + value: o.value + }); + this.levelTree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SwitchTree.EVENT_CHANGE, arguments); + }); + return this.levelTree; + case BI.SwitchTree.SelectType.MultiSelect: + this.tree = BI.createWidget({ + type: "bi.simple_tree", + items: this._removeIsParent(BI.deepClone(o.items)), + value: o.value + }); + this.tree.on(BI.SimpleTreeView.EVENT_CHANGE, function () { + self.fireEvent(BI.SwitchTree.EVENT_CHANGE, arguments); + }); + return this.tree; + } }, - setErrorText: function (text) { - this.editor.setErrorText(text); + _removeIsParent: function (items) { + BI.each(items, function (i, item) { + BI.isNotNull(item.isParent) && delete item.isParent; + }); + return items; }, - getErrorText: function () { - return this.editor.getErrorText(); + switchSelect: function () { + switch (this.getSelect()) { + case BI.SwitchTree.SelectType.SingleSelect: + this.setSelect(BI.SwitchTree.SelectType.MultiSelect); + break; + case BI.SwitchTree.SelectType.MultiSelect: + this.setSelect(BI.SwitchTree.SelectType.SingleSelect); + break; + } }, - isEditing: function () { - return this.editor.isEditing(); + setSelect: function (v) { + this.tab.setSelect(v); }, - getLastValidValue: function () { - return this.editor.getLastValidValue(); + getSelect: function () { + return this.tab.getSelect(); }, setValue: function (v) { - this.editor.setValue(v); - this._checkText(); + this.storeValue = v; + switch (this.getSelect()) { + case BI.SwitchTree.SelectType.SingleSelect: + this.levelTree.setValue(v); + break; + case BI.SwitchTree.SelectType.MultiSelect: + this.tree.setValue(v); + break; + } }, getValue: function () { - return this.editor.getValue(); - }, - - getState: function () { - return this.text.getValue(); + return this.tab.getValue(); }, - setState: function (v) { - var o = this.options; - this._showHint(); - v = (BI.isEmpty(v) || v == o.text) ? o.text : v + o.text; - this.text.setValue(v); + populate: function (items) { + this.options.items = items; + if (BI.isNotNull(this.levelTree)) { + this.levelTree.populate(BI.deepClone(items)); + } + if (BI.isNotNull(this.tree)) { + this.tree.populate(this._removeIsParent(BI.deepClone(items))); + } } }); -BI.SignTextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.SignTextEditor.EVENT_CLICK_LABEL = "EVENT_CLICK_LABEL"; - -BI.shortcut("bi.sign_text_editor", BI.SignTextEditor);/** - * Created by zcf on 2016/9/22. +BI.SwitchTree.EVENT_CHANGE = "SwitchTree.EVENT_CHANGE"; +BI.SwitchTree.SelectType = { + SingleSelect: BI.Selection.Single, + MultiSelect: BI.Selection.Multi +}; +BI.shortcut("bi.switch_tree", BI.SwitchTree); +/** + * Created by Baron on 2015/10/19. */ -BI.SliderIconButton = BI.inherit(BI.Widget, { +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 () { - return BI.extend(BI.SliderIconButton.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-slider-button" + var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-date-interval" }); }, _init: function () { - BI.extend(BI.SliderIconButton.superclass._init.apply(this, arguments)); - this.slider = BI.createWidget({ - type: "bi.icon_button", - cls: "slider-icon slider-button", - iconWidth: 14, - iconHeight: 14, - height: 14, - width: 14 + 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({ - type: "bi.absolute", - element: this, + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, items: [{ - el: this.slider, - top: 7, - left: -7 - }], - width: 0, - height: 14 + 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.shortcut("bi.single_slider_button", BI.SliderIconButton);/** - * Created by zcf on 2016/9/22. +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.SingleSlider = BI.inherit(BI.Widget, { - _constant: { - EDITOR_WIDTH: 90, - EDITOR_HEIGHT: 30, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 +BI.TimeInterval = 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 () { - return BI.extend(BI.SingleSlider.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-slider bi-slider-track", - digit: false, - unit: "" + var conf = BI.TimeInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-time-interval" }); }, _init: function () { - BI.SingleSlider.superclass._init.apply(this, arguments); - var self = this, o = this.options; - var c = this._constant; - this.enable = false; - this.value = ""; - - this.grayTrack = BI.createWidget({ - type: "bi.layout", - cls: "gray-track", - height: 6 - }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 - }); - this.track = this._createTrackWrapper(); + BI.TimeInterval.superclass._init.apply(this, arguments); - this.slider = BI.createWidget({ - type: "bi.single_slider_button" - }); - this._draggable(this.slider); - var sliderVertical = BI.createWidget({ - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.slider] - }], - hgap: c.SLIDER_WIDTH_HALF, - height: c.SLIDER_HEIGHT - }); - sliderVertical.element.click(function (e) { - if (self.enable) { - var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; - var trackLength = self.track.element[0].scrollWidth; - var percent = 0; - if (offset < 0) { - percent = 0; - } - if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { - percent = offset * 100 / self._getGrayTrackLength(); - } - if (offset > (trackLength - c.SLIDER_WIDTH)) { - percent = 100; - } - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setAllPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.label.setValue(v); - self.value = v; - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); - } - }); + o.value = o.value || {}; + this.left = this._createCombo(o.value.start); + this.right = this._createCombo(o.value.end); this.label = BI.createWidget({ - type: "bi.sign_text_editor", - cls: "slider-editor-button", - errorText: "", - text: o.unit, - width: c.EDITOR_WIDTH - 2, - allowBlank: false, - validationChecker: function (v) { - return self._checkValidation(v); - } - }); - this.label.element.hover(function () { - self.label.element.removeClass("bi-border").addClass("bi-border"); - }, function () { - self.label.element.removeClass("bi-border"); - }); - this.label.on(BI.SignEditor.EVENT_CONFIRM, function () { - var v = BI.parseFloat(this.getValue()); - var percent = self._getPercentByValue(v); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setAllPosition(significantPercent); - this.setValue(v); - self.value = v; - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + type: "bi.label", + height: this.constants.height, + width: this.constants.width, + text: "-" }); - this._setVisible(false); BI.createWidget({ - type: "bi.absolute", - element: this, + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.track, - width: "100%", - height: c.TRACK_HEIGHT - }] - }], - hgap: 7, - height: c.TRACK_HEIGHT - }, - top: 23, - left: 0, - width: "100%" - }, { - el: sliderVertical, - top: 20, - left: 0, - width: "100%" + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] }, { - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.label] - }], - rgap: c.EDITOR_WIDTH, - height: c.EDITOR_HEIGHT - }, - top: 0, - left: 0, - width: "100%" + 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 + ] + }); }, - _draggable: function (widget) { - var self = this, o = this.options; - var startDrag = false; - var size = 0, offset = 0, defaultSize = 0; - var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { - if (mouseMoveTracker.isDragging()) { - startDrag = true; - offset += deltaX; - size = optimizeSize(defaultSize + offset); - widget.element.addClass("dragging"); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 - self._setBlueTrack(significantPercent); - self._setLabelPosition(significantPercent); - self._setSliderPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.label.setValue(v); - self.value = v; - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); - } - }, function () { - if (startDrag === true) { - size = optimizeSize(size); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setSliderPosition(significantPercent); - size = 0; - offset = 0; - defaultSize = size; - startDrag = false; + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_date_time_combo", + value: v + }); + combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.TimeInterval.EVENT_ERROR); + }); + + 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)) { + 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.TimeInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); } - widget.element.removeClass("dragging"); - mouseMoveTracker.releaseMouseMoves(); - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); - }, window); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; + }); + + 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)) { + 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.TimeInterval.EVENT_ERROR); + } else { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); }); - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); - } - }, - - _createTrackWrapper: function () { - return BI.createWidget({ - type: "bi.absolute", - items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.grayTrack, - top: 0, - left: 0, - width: "100%" - }, { - el: this.blueTrack, - top: 0, - left: 0, - width: "0%" - }] - }], - hgap: 8, - height: 8 - }, - top: 8, - left: 0, - width: "100%" - }] + combo.on(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hidePopupView(); + self.right.hidePopupView(); }); - }, + // 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)) { + // 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.TimeInterval.EVENT_ERROR); + // } else { + // self._clearTitle(); + // self.element.removeClass(self.constants.timeErrorCls); + // } + // }); - _checkValidation: function (v) { - var o = this.options; - var valid = false; - if (BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max)) { - if(o.digit === false) { - valid = true; + 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)) { + self._setTitle(BI.i18nText("BI-Time_Interval_Error_Text")); + self.element.addClass(self.constants.timeErrorCls); + self.fireEvent(BI.TimeInterval.EVENT_ERROR); }else{ - var dotText = (v + "").split(".")[1] || ""; - valid = (dotText.length === o.digit); + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.TimeInterval.EVENT_CHANGE); } - } - return valid; + }); + return combo; + }, + _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; + }, + _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 %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) { + 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.TimeInterval.EVENT_VALID = "EVENT_VALID"; +BI.TimeInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.TimeInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.time_interval", BI.TimeInterval);/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.YearCard + * @extends BI.Trigger + */ +BI.DynamicYearCard = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-year-card" }, - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); + render: function () { + var self = this; + return { + type: "bi.vertical", + items: [{ + type: "bi.label", + text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), + textAlign: "left", + height: 24 + }, { + type: "bi.dynamic_date_param_item", + ref: function () { + self.item = this; + }, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }], + vgap: 10, + hgap: 10 + }; }, - _setLabelPosition: function (percent) { - this.label.element.css({left: percent + "%"}); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); + setValue: function (v) { + v = v || {year: 0}; + this.item.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); }, - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setLabelPosition(percent); - this._setBlueTrack(percent); + getValue: function () { + var value = this.item.getValue(); + return { + year: (value.offset === 0 ? -value.value : value.value) + }; + } +}); +BI.DynamicYearCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_card", BI.DynamicYearCard);/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.StaticYearCard + * @extends BI.Trigger + */ +BI.StaticYearCard = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.StaticYearCard.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-year-card", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31" // 最大日期 + }); }, - _setVisible: function (visible) { - this.slider.setVisible(visible); - this.label.setVisible(visible); + _createYearCalendar: function (v) { + var o = this.options, y = this._year; + + var calendar = BI.createWidget({ + type: "bi.year_calendar", + behaviors: o.behaviors, + min: o.min, + max: o.max, + logic: { + dynamic: true + }, + year: y + v * 12 + }); + calendar.setValue(this._year); + return calendar; }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; - }, + _init: function () { + BI.StaticYearCard.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.selectedYear = this._year = BI.getDate().getFullYear(); + + this.backBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "pre-page-h-font", + width: 25, + height: 25, + value: -1, + listeners: [{ + eventName: BI.IconButton.EVENT_CHANGE, + action: function () { + self.navigation.setSelect(self.navigation.getSelect() - 1); + self._checkLeftValid(); + self._checkRightValid(); + } + }] + }); + + this.preBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "next-page-h-font", + width: 25, + height: 25, + value: 1, + listeners: [{ + eventName: BI.IconButton.EVENT_CHANGE, + action: function () { + self.navigation.setSelect(self.navigation.getSelect() + 1); + self._checkLeftValid(); + self._checkRightValid(); + } + }] + }); + + this.navigation = BI.createWidget({ + type: "bi.navigation", + direction: "top", + element: this, + single: true, + logic: { + dynamic: true + }, + tab: { + type: "bi.htape", + cls: "bi-border-top bi-border-bottom", + height: 30, + items: [{ + el: { + type: "bi.center_adapt", + items: [self.backBtn] + }, + width: 25 + }, { + type: "bi.layout" + }, { + el: { + type: "bi.center_adapt", + items: [self.preBtn] + }, + width: 25 + }] + }, + cardCreator: BI.bind(this._createYearCalendar, this), - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); - }, + afterCardShow: function () { + this.setValue(self.selectedYear); + var calendar = this.getSelectedCard(); + self.backBtn.setEnable(!calendar.isFrontYear()); + self.preBtn.setEnable(!calendar.isFinalYear()); + } + }); - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); - }, + this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { + self.selectedYear = this.getValue(); + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + self.fireEvent(BI.StaticYearCard.EVENT_CHANGE, self.selectedYear); + }); - getValue: function () { - return this.value; + if(BI.isKey(o.value)){ + this.setValue(o.value); + } }, - setValue: function (v) { + _checkLeftValid: function () { var o = this.options; - v = BI.parseFloat(v); - v = o.digit === false ? v : v.toFixed(o.digit); - if ((!isNaN(v))) { - if (this._checkValidation(v)) { - this.value = v; - } - if (v > this.max) { - this.value = this.max; - } - if (v < this.min) { - this.value = this.min; - } - } + var valid = true; + this.backBtn.setEnable(valid); + return valid; }, - setMinAndMax: function (v) { - var minNumber = BI.parseFloat(v.min); - var maxNumber = BI.parseFloat(v.max); - if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { - this.min = minNumber; - this.max = maxNumber; - } + _checkRightValid: function () { + var o = this.options; + var valid = true; + this.preBtn.setEnable(valid); + return valid; }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.value = ""; - this.min = 0; - this.max = 0; - this._setBlueTrack(0); - + getValue: function () { + return { + year: this.selectedYear + }; }, - populate: function () { - if (!isNaN(this.min) && !isNaN(this.max)) { - this._setVisible(true); - this.enable = true; - this.label.setErrorText(BI.i18nText("BI-Please_Enter") + this.min + "-" + this.max + BI.i18nText("BI-Basic_De") + BI.i18nText("BI-Basic_Number")); - if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { - this.label.setValue(this.value); - this._setAllPosition(this._getPercentByValue(this.value)); - } else { - this.label.setValue(this.max); - this._setAllPosition(100); - } + setValue: function (obj) { + var o = this.options; + obj = obj || {}; + var v = obj.year; + if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { + v = BI.getDate().getFullYear(); + this.selectedYear = ""; + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(""); + } else { + this.selectedYear = BI.parseInt(v); + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(this.selectedYear); } + this._checkLeftValid(); + this._checkRightValid(); } }); -BI.SingleSlider.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_slider", BI.SingleSlider);/** - * Created by Urthur on 2017/9/12. - */ -BI.SingleSliderLabel = BI.inherit(BI.Widget, { - _constant: { - EDITOR_WIDTH: 90, - EDITOR_HEIGHT: 20, - HEIGHT: 20, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 - }, - _defaultConfig: function () { - return BI.extend(BI.SingleSliderLabel.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-slider-label bi-slider-track", - digit: false, - unit: "" - }); +BI.StaticYearCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-year-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, - _init: function () { - BI.SingleSliderLabel.superclass._init.apply(this, arguments); + _init: function () { + BI.DynamicYearCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - var c = this._constant; - this.enable = false; - this.value = ""; - - this.grayTrack = BI.createWidget({ - type: "bi.layout", - cls: "gray-track", - height: 6 + this.storeValue = o.value; + this.trigger = BI.createWidget({ + type: "bi.dynamic_year_trigger", + min: o.min, + max: o.max, + value: o.value || "" }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 + this.trigger.on(BI.DynamicYearTrigger.EVENT_FOCUS, function () { + self.storeTriggerValue = this.getKey(); }); - this.track = this._createTrackWrapper(); - - this.slider = BI.createWidget({ - type: "bi.single_slider_button" + this.trigger.on(BI.DynamicYearTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - this._draggable(this.slider); - var sliderVertical = BI.createWidget({ - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.slider] - }], - hgap: c.SLIDER_WIDTH_HALF, - height: c.SLIDER_HEIGHT + this.trigger.on(BI.DynamicYearTrigger.EVENT_STOP, function () { + self.combo.showView(); }); - sliderVertical.element.click(function (e) { - if (self.enable) { - var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; - var trackLength = self.track.element[0].scrollWidth; - var percent = 0; - if (offset < 0) { - percent = 0; - } - if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { - percent = offset * 100 / self._getGrayTrackLength(); - } - if (offset > (trackLength - c.SLIDER_WIDTH)) { - percent = 100; - } - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setAllPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.label.setText(v + o.unit); - self.value = v; - self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); + this.trigger.on(BI.DynamicYearTrigger.EVENT_ERROR, function () { + self.combo.isViewVisible() && self.combo.hideView(); + }); + this.trigger.on(BI.DynamicYearTrigger.EVENT_CONFIRM, function () { + if (self.combo.isViewVisible()) { + return; + } + if (this.getKey() && this.getKey() !== self.storeTriggerValue) { + self.storeValue = self.trigger.getValue(); + self.setValue(self.storeValue); + } else if (!this.getKey()) { + self.storeValue = null; + self.setValue(); + } + self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); + }); + + this.combo = BI.createWidget({ + type: "bi.combo", + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + stopPropagation: false, + el: { + type: "bi.dynamic_year_popup", + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicYearPopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({year: date.getFullYear()}); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }], + behaviors: o.behaviors, + min: o.min, + max: o.max + }, + value: o.value || "" } }); - this.label = BI.createWidget({ - type: "bi.label", - height: c.HEIGHT, - width: c.EDITOR_WIDTH - 2 + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW); }); - this._setVisible(false); BI.createWidget({ - type: "bi.absolute", + type: "bi.htape", element: this, + ref: function () { + self.comboWrapper = this; + }, items: [{ el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.track, - width: "100%", - height: c.TRACK_HEIGHT - }] - }], - hgap: 7, - height: c.TRACK_HEIGHT - }, - top: 13, - left: 0, - width: "100%" - }, { - el: sliderVertical, - top: 10, - left: 0, - width: "100%" - }, { - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.label] - }], - rgap: c.EDITOR_WIDTH, - height: c.EDITOR_HEIGHT + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, + ref: function () { + self.changeIcon = this; + } }, - top: 0, - left: 0, - width: "100%" - }] + width: 24 + }, this.combo] }); + this._checkDynamicValue(o.value); }, - _draggable: function (widget) { - var self = this, o = this.options; - var startDrag = false; - var size = 0, offset = 0, defaultSize = 0; - var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { - if (mouseMoveTracker.isDragging()) { - startDrag = true; - offset += deltaX; - size = optimizeSize(defaultSize + offset); - widget.element.addClass("dragging"); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 - self._setBlueTrack(significantPercent); - self._setLabelPosition(significantPercent); - self._setSliderPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.label.setValue(v); - self.value = v; - self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); - } - }, function () { - if (startDrag === true) { - size = optimizeSize(size); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setSliderPosition(significantPercent); - size = 0; - offset = 0; - defaultSize = size; - startDrag = false; - } - widget.element.removeClass("dragging"); - mouseMoveTracker.releaseMouseMoves(); - self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); - }, window); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; - } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); - }); - - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicYearCombo.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; } }, - _createTrackWrapper: function () { - return BI.createWidget({ - type: "bi.absolute", + setValue: function (v) { + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); + }, + + getValue: function () { + return this.storeValue; + } + +}); +BI.DynamicYearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.dynamic_year_combo", BI.DynamicYearCombo); + +BI.extend(BI.DynamicYearCombo, { + Static: 1, + Dynamic: 2 +});/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.DynamicYearPopup + * @extends BI.Trigger + */ +BI.DynamicYearPopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 + }, + + props: { + baseCls: "bi-year-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 + }, + + render: function () { + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicYearCombo.Static}; + return { + type: "bi.vtape", items: [{ + el: this._getTabJson() + }, { el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.grayTrack, - top: 0, - left: 0, - width: "100%" - }, { - el: this.blueTrack, - top: 0, - left: 0, - width: "0%" + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE); + } }] - }], - hgap: 8, - height: 8 + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-left bi-border-right bi-border-top", + shadow: true, + text: BI.i18nText("BI-Basic_Current_Year"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] }, - top: 8, - left: 0, - width: "100%" + height: 24 }] - }); - }, - - _checkValidation: function (v) { - return BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max); - }, - - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); - }, - - _setLabelPosition: function (percent) { - this.label.element.css({left: percent + "%"}); - }, - - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); - }, - - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setLabelPosition(percent); - this._setBlueTrack(percent); - }, - - _setVisible: function (visible) { - this.slider.setVisible(visible); - this.label.setVisible(visible); - }, - - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; - }, - - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); + }; }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y"); + this.textButton.setValue(date); + this.textButton.setEnable(false); + } }, - getValue: function () { - return this.value; + _getTabJson: function () { + var self = this, o = this.options; + return { + type: "bi.tab", + 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-Basic_Year_Fen"), + value: BI.DynamicYearCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicYearCombo.Dynamic + }], { + textAlign: "center" + }) + }, + cardCreator: function (v) { + switch (v) { + case BI.DynamicYearCombo.Dynamic: + return { + type: "bi.dynamic_year_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicYearCombo.Static: + default: + return { + type: "bi.static_year_card", + behaviors: o.behaviors, + min: self.options.min, + max: self.options.max, + listeners: [{ + eventName: BI.StaticYearCard.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.EVENT_CHANGE); + } + }], + ref: function () { + self.year = this; + } + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicYearCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.year.setValue({year: date.getFullYear()}); + self._setInnerValue(); + break; + case BI.DynamicYearCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; }, setValue: function (v) { - var o = this.options; - v = BI.parseFloat(v); - v = o.digit === false ? v : v.toFixed(o.digit); - if ((!isNaN(v))) { - if (this._checkValidation(v)) { - this.value = v; - } - if (v > this.max) { - this.value = this.max; - } - if (v < this.min) { - this.value = this.min; - } - } - }, - - setMinAndMax: function (v) { - var minNumber = BI.parseFloat(v.min); - var maxNumber = BI.parseFloat(v.max); - if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { - this.min = minNumber; - this.max = maxNumber; + 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: + this.year.setValue(value); + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); + this.textButton.setEnable(true); + break; } }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.value = ""; - this.min = 0; - this.max = 0; - this._setBlueTrack(0); - }, - - populate: function () { - var o = this.options; - if (!isNaN(this.min) && !isNaN(this.max)) { - this._setVisible(true); - this.enable = true; - if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { - this.label.setValue(this.value + o.unit); - this._setAllPosition(this._getPercentByValue(this.value)); - } else { - this.label.setValue(this.max + o.unit); - this._setAllPosition(100); - } - } + getValue: function () { + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; } -}); -BI.SingleSliderLabel.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_slider_label", BI.SingleSliderLabel);/** - * normal single slider - * Created by Young on 2017/6/21. - */ -BI.SingleSliderNormal = BI.inherit(BI.Widget, { - _constant: { - HEIGHT: 28, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 +}); +BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicYearPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_popup", BI.DynamicYearPopup);BI.DynamicYearTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), + errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") }, - props: { - baseCls: "bi-single-slider-normal bi-slider-track", - minMax: { - min: 0, - max: 100 - } - // color: "#3f8ce8" + _defaultConfig: function () { + return BI.extend(BI.DynamicYearTrigger.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-year-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 + }); }, - - render: function () { - var self = this; - var c = this._constant; - var track = this._createTrack(); - this.slider = BI.createWidget({ - type: "bi.single_slider_button" + _init: function () { + BI.DynamicYearTrigger.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) { + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); + }, + quitChecker: function (v) { + return false; + }, + hgap: c.hgap, + vgap: c.vgap, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + allowBlank: true, + errorText: function (v) { + return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; + } }); - this._draggable(this.slider); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_FOCUS); + }); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_STOP); + }); + this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setValue(value); + } + if (BI.isNotEmptyString(value)) { + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: value + } + }; + } - var sliderVertical = BI.createWidget({ - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.slider] - }], - hgap: c.SLIDER_WIDTH_HALF, - height: c.SLIDER_HEIGHT + self.fireEvent(BI.DynamicYearTrigger.EVENT_CONFIRM); }); - sliderVertical.element.click(function (e) { - if (self.enable) { - var offset = e.clientX - self.element.offset().left - c.SLIDER_WIDTH_HALF; - var trackLength = self.track.element[0].scrollWidth; - var percent = 0; - if (offset < 0) { - percent = 0; - } - if (offset > 0 && offset < (trackLength - c.SLIDER_WIDTH)) { - percent = offset * 100 / self._getGrayTrackLength(); - } - if (offset > (trackLength - c.SLIDER_WIDTH)) { - percent = 100; - } - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setAllPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - self.value = v; - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); + this.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); } }); - - return { - type: "bi.absolute", + this.editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_START); + }); + this.editor.on(BI.SignEditor.EVENT_ERROR, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_ERROR); + }); + BI.createWidget({ element: this, + type: "bi.htape", items: [{ + el: this.editor + }, { el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: track, - width: "100%", - height: c.TRACK_HEIGHT - }] - }], - hgap: 7, - height: c.TRACK_HEIGHT + type: "bi.text_button", + baseCls: "bi-trigger-year-text", + text: BI.i18nText("BI-Multi_Date_Year"), + width: o.height }, - top: 3, - left: 0, - width: "100%" + width: o.height }, { - el: sliderVertical, - top: 0, - left: 0, - width: "100%" + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height }] - }; - }, - - _draggable: function (widget) { - var self = this, o = this.options; - var startDrag = false; - var size = 0, offset = 0, defaultSize = 0; - var mouseMoveTracker = new BI.MouseMoveTracker(function (deltaX) { - if (mouseMoveTracker.isDragging()) { - startDrag = true; - offset += deltaX; - size = optimizeSize(defaultSize + offset); - widget.element.addClass("dragging"); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1));// 直接对计算出来的百分数保留到小数点后一位,相当于分成了1000份。 - self._setBlueTrack(significantPercent); - self._setSliderPosition(significantPercent); - var v = self._getValueByPercent(significantPercent); - v = o.digit === false ? v : v.toFixed(o.digit); - self.value = v; - self.fireEvent(BI.SingleSliderNormal.EVENT_DRAG, v); - } - }, function () { - if (startDrag === true) { - size = optimizeSize(size); - var percent = size * 100 / (self._getGrayTrackLength()); - var significantPercent = BI.parseFloat(percent.toFixed(1)); - self._setSliderPosition(significantPercent); - size = 0; - offset = 0; - defaultSize = size; - startDrag = false; - } - widget.element.removeClass("dragging"); - mouseMoveTracker.releaseMouseMoves(); - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); - }, window); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; - } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); }); + this.setValue(o.value); + }, - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); + _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")); } + return value; }, - _createTrack: function () { - var self = this; - var c = this._constant; - this.grayTrack = BI.createWidget({ - type: "bi.layout", - cls: "gray-track", - height: 6 - }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 - }); - if (this.options.color) { - this.blueTrack.element.css({"background-color": this.options.color}); + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); + }, + + setValue: function (v) { + var type, value; + 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: + value = value || {}; + this.editor.setState(value.year); + this.editor.setValue(value.year); + this.editor.setTitle(value.year); + break; } + }, + + getValue: function () { + return this.storeValue; + }, + + getKey: function () { + return this.editor.getValue() | 0; + } +}); +BI.DynamicYearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicYearTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearTrigger.EVENT_START = "EVENT_START"; +BI.DynamicYearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearTrigger.EVENT_STOP = "EVENT_STOP"; +BI.shortcut("bi.dynamic_year_trigger", BI.DynamicYearTrigger);/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.YearCard + * @extends BI.Trigger + */ +BI.DynamicYearMonthCard = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-year-month-card" + }, + render: function () { + var self = this; return { - type: "bi.absolute", + type: "bi.vertical", items: [{ - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.grayTrack, - top: 0, - left: 0, - width: "100%" - }, { - el: this.blueTrack, - top: 0, - left: 0, - width: "0%" - }] - }], - hgap: 8, - height: 8 + type: "bi.label", + text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), + textAlign: "left", + height: 24 + }, { + type: "bi.dynamic_date_param_item", + ref: function () { + self.year = this; + }, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }, { + type: "bi.dynamic_date_param_item", + dateType: BI.DynamicDateCard.TYPE.MONTH, + ref: function () { + self.month = this; }, - top: 8, - left: 0, - width: "100%" + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] }], - ref: function (ref) { - self.track = ref; - } + vgap: 10, + hgap: 10 }; }, - _checkValidation: function (v) { - return !(BI.isNull(v) || v < this.min || v > this.max); - }, - - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); + setValue: function (v) { + v = v || {year: 0, month: 0}; + this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); + this.month.setValue(this._createValue(BI.DynamicDateCard.TYPE.MONTH, v.month)); }, - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setBlueTrack(percent); - }, + getValue: function () { + var year = this.year.getValue(); + var month = this.month.getValue(); + return { + year: (year.offset === 0 ? -year.value : year.value), + month: (month.offset === 0 ? -month.value : month.value) + }; + } +}); +BI.DynamicYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_month_card", BI.DynamicYearMonthCard);BI.StaticYearMonthCard = BI.inherit(BI.Widget, { - _setVisible: function (visible) { - this.slider.setVisible(visible); + props: { + baseCls: "bi-static-year-month-card", + behaviors: {} }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + _createMonths: function () { + // 纵向排列月 + var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; + var items = []; + items.push(month.slice(0, 2)); + items.push(month.slice(2, 4)); + items.push(month.slice(4, 6)); + items.push(month.slice(6, 8)); + items.push(month.slice(8, 10)); + items.push(month.slice(10, 12)); + return BI.map(items, function (i, item) { + return BI.map(item, function (j, td) { + return { + type: "bi.text_item", + cls: "bi-list-item-active", + textAlign: "center", + whiteSpace: "nowrap", + once: false, + forceSelected: true, + height: 23, + width: 38, + value: td, + text: td + 1 + }; + }); + }); }, - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); + render: function () { + var self = this, o = this.options; + return { + type: "bi.vertical", + items: [{ + type: "bi.year_picker", + ref: function () { + self.yearPicker = this; + }, + height: 30, + listeners: [{ + eventName: BI.YearPicker.EVENT_CHANGE, + action: function () { + var value = this.getValue(); + self.setValue({ + year: value, + month: self.selectedMonth + }); + } + }] + }, { + type: "bi.button_group", + behaviors: o.behaviors, + ref: function () { + self.month = this; + }, + items: this._createMonths(), + layouts: [BI.LogicFactory.createLogic("table", BI.extend({ + dynamic: true + }, { + columns: 2, + rows: 6, + columnSize: [1 / 2, 1 / 2], + rowSize: 25 + })), { + type: "bi.center_adapt", + vgap: 1, + hgap: 2 + }], + value: o.value, + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + self.selectedYear = self.yearPicker.getValue(); + self.selectedMonth = this.getValue()[0]; + self.fireEvent(BI.StaticYearMonthCard.EVENT_CHANGE); + } + }] + }] + }; }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); - }, getValue: function () { - return this.value; - }, - - setValue: function (v) { - var value = BI.parseFloat(v); - if ((!isNaN(value))) { - if (this._checkValidation(value)) { - this.value = value; - } - if (value > this.max) { - this.value = this.max; - } - if (value < this.min) { - this.value = this.min; - } - } + return { + year: this.selectedYear, + month: this.selectedMonth + }; }, - setMinAndMax: function (v) { - var minNumber = BI.parseFloat(v.min); - var maxNumber = BI.parseFloat(v.max); - if ((!isNaN(minNumber)) && (!isNaN(maxNumber)) && (maxNumber > minNumber )) { - this.min = minNumber; - this.max = maxNumber; + setValue: function (obj) { + var o = this.options; + obj = obj || {}; + obj.year = obj.year || 0; + obj.month = obj.month || 0; + if (BI.checkDateVoid(obj.year, obj.month, 1, o.min, o.max)[0]) { + var year = BI.getDate().getFullYear(); + var month = BI.getDate().getMonth(); + this.selectedYear = ""; + this.selectedMonth = ""; + this.yearPicker.setValue(year); + this.month.setValue(month); + } else { + this.selectedYear = BI.parseInt(obj.year); + this.selectedMonth = BI.parseInt(obj.month); + this.yearPicker.setValue(this.selectedYear); + this.month.setValue(this.selectedMonth); } - }, + } +}); +BI.StaticYearMonthCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.static_year_month_card", BI.StaticYearMonthCard);BI.DynamicYearMonthCombo = BI.inherit(BI.Single, { - reset: function () { - this._setVisible(false); - this.enable = false; - this.value = ""; - this.min = 0; - this.max = 0; - this._setBlueTrack(0); + props: { + baseCls: "bi-year-month-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, - populate: function () { - if (!isNaN(this.min) && !isNaN(this.max)) { - this._setVisible(true); - this.enable = true; - if (BI.isNumeric(this.value) || BI.isNotEmptyString(this.value)) { - this._setAllPosition(this._getPercentByValue(this.value)); - } else { - this._setAllPosition(100); + _init: function () { + BI.DynamicYearMonthCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.storeValue = o.value; + this.trigger = BI.createWidget({ + type: "bi.dynamic_year_month_trigger", + min: o.min, + max: o.max, + value: o.value || "" + }); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); + }); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_STOP, function () { + self.combo.showView(); + }); + 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()) { + return; } - } - } -}); -BI.SingleSliderNormal.EVENT_DRAG = "EVENT_DRAG"; -BI.shortcut("bi.single_slider_normal", BI.SingleSliderNormal);/** - * @class BI.SingleTreeCombo - * @extends BI.Widget - */ -BI.SingleTreeCombo = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.SingleTreeCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-tree-combo", - trigger: {}, - height: 24, - text: "", - items: [], - value: "" + self.storeValue = self.trigger.getValue(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); }); - }, - - _init: function () { - BI.SingleTreeCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.trigger = BI.createWidget(BI.extend({ - type: "bi.single_tree_trigger", - text: o.text, - height: o.height, - items: o.items, - value: o.value - }, o.trigger)); - - this.popup = BI.createWidget({ - type: "bi.single_level_tree", - items: o.items, - value: o.value + this.trigger.on(BI.DynamicYearMonthCombo.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_FOCUS); }); this.combo = BI.createWidget({ type: "bi.combo", - element: this, - adjustLength: 2, + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, el: this.trigger, popup: { - el: this.popup + minWidth: 85, + stopPropagation: false, + el: { + type: "bi.dynamic_year_month_popup", + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicYearMonthPopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({year: date.getFullYear()}); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }], + behaviors: o.behaviors, + min: o.min, + max: o.max + }, + value: o.value || "" } }); - - this.combo.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW, arguments); - }); - - this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.SingleTreeCombo.EVENT_CHANGE); - }); - }, - - populate: function (items) { - this.combo.populate(items); - }, - - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.trigger.setValue(v); - this.popup.setValue(v); - }, - - getValue: function () { - return this.popup.getValue(); - } -}); - -BI.SingleTreeCombo.EVENT_CHANGE = "SingleTreeCombo.EVENT_CHANGE"; -BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.single_tree_combo", BI.SingleTreeCombo);/** - * @class BI.SingleTreePopup - * @extends BI.Pane - */ - -BI.SingleTreePopup = BI.inherit(BI.Pane, { - - _defaultConfig: function () { - return BI.extend(BI.SingleTreePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-level-tree", - tipText: BI.i18nText("BI-No_Selected_Item"), - items: [], - value: "" - }); - }, - - _init: function () { - BI.SingleTreePopup.superclass._init.apply(this, arguments); - - var self = this, o = this.options; - - this.tree = BI.createWidget({ - type: "bi.level_tree", - expander: { - isDefaultInit: true - }, - items: o.items, - value: o.value, - chooseType: BI.Selection.Single + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW); }); BI.createWidget({ - type: "bi.vertical", + type: "bi.htape", element: this, - items: [this.tree] - }); - - this.tree.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleTreePopup.EVENT_CHANGE); - }); - - this.check(); - }, - - getValue: function () { - return this.tree.getValue(); - }, - - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.tree.setValue(v); - }, - - populate: function (items) { - BI.SingleTreePopup.superclass.populate.apply(this, arguments); - this.tree.populate(items); - } -}); - -BI.SingleTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_level_tree", BI.SingleTreePopup);/** - * @class BI.SingleTreeTrigger - * @extends BI.Trigger - */ - -BI.SingleTreeTrigger = BI.inherit(BI.Trigger, { - - _defaultConfig: function () { - return BI.extend(BI.SingleTreeTrigger.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-tree-trigger", - height: 24, - text: "", - items: [], - value: "" + ref: function () { + self.comboWrapper = this; + }, + 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 + }, this.combo] }); + this._checkDynamicValue(o.value); }, - _init: function () { - BI.SingleTreeTrigger.superclass._init.apply(this, arguments); - - var self = this, o = this.options; - - this.trigger = BI.createWidget({ - type: "bi.select_text_trigger", - element: this, - text: o.text, - items: o.items, - height: o.height, - value: o.value - }); + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicYearMonthCombo.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; + } }, - _checkTitle: function () { - var self = this, val = this.getValue(); - BI.any(this.options.items, function (i, item) { - if (val.contains(item.value)) { - self.trigger.setTitle(item.text || item.value); - return true; - } - }); + hideView: function () { + this.combo.hideView(); }, setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.options.value = v; + this.storeValue = v; this.trigger.setValue(v); - this._checkTitle(); + this._checkDynamicValue(v); }, getValue: function () { - return this.options.value || []; + return this.storeValue; }, - populate: function (items) { - BI.SingleTreeTrigger.superclass.populate.apply(this, arguments); - this.trigger.populate(items); + 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); -BI.shortcut("bi.single_tree_trigger", BI.SingleTreeTrigger);/** - * 可以单选多选切换的树 +BI.extend(BI.DynamicYearMonthCombo, { + Static: 1, + Dynamic: 2 +});/** + * 年月 * - * Created by GUY on 2015/12/21. - * @class BI.SwitchTree - * @extends BI.Widget + * Created by GUY on 2015/9/2. + * @class BI.DynamicYearMonthPopup + * @extends BI.Trigger */ -BI.SwitchTree = BI.inherit(BI.Widget, { - - _defaultConfig: function () { - return BI.extend(BI.SwitchTree.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-switch-tree", - items: [] - }); - }, - - _init: function () { - BI.SwitchTree.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.tab = BI.createWidget({ - type: "bi.tab", - element: this, - tab: null, - showIndex: BI.SwitchTree.SelectType.SingleSelect, - cardCreator: BI.bind(this._createTree, this) - }); +BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 }, - _createTree: function (type) { - var self = this, o = this.options; - switch (type) { - case BI.SwitchTree.SelectType.SingleSelect: - this.levelTree = BI.createWidget({ - type: "bi.multilayer_single_level_tree", - isDefaultInit: true, - items: BI.deepClone(o.items), - value: o.value - }); - this.levelTree.on(BI.LevelTree.EVENT_CHANGE, function () { - self.fireEvent(BI.SwitchTree.EVENT_CHANGE, arguments); - }); - return this.levelTree; - case BI.SwitchTree.SelectType.MultiSelect: - this.tree = BI.createWidget({ - type: "bi.simple_tree", - items: this._removeIsParent(BI.deepClone(o.items)), - value: o.value - }); - this.tree.on(BI.SimpleTreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.SwitchTree.EVENT_CHANGE, arguments); - }); - return this.tree; - } + props: { + baseCls: "bi-year-month-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 }, - _removeIsParent: function (items) { - BI.each(items, function (i, item) { - BI.isNotNull(item.isParent) && delete item.isParent; - }); - return items; + render: function () { + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicYearMonthCombo.Static}; + return { + type: "bi.vtape", + items: [{ + el: this._getTabJson() + }, { + el: { + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearMonthPopup.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-Basic_Current_Month"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 + }] + }; }, - switchSelect: function () { - switch (this.getSelect()) { - case BI.SwitchTree.SelectType.SingleSelect: - this.setSelect(BI.SwitchTree.SelectType.MultiSelect); - break; - case BI.SwitchTree.SelectType.MultiSelect: - this.setSelect(BI.SwitchTree.SelectType.SingleSelect); - break; + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y-%x"); + this.textButton.setValue(date); + this.textButton.setEnable(false); } }, - setSelect: function (v) { - this.tab.setSelect(v); - }, - - getSelect: function () { - return this.tab.getSelect(); + _getTabJson: function () { + var self = this, o = this.options; + return { + type: "bi.tab", + 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-Basic_Year_Fen"), + value: BI.DynamicYearCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicYearCombo.Dynamic + }], { + textAlign: "center" + }) + }, + cardCreator: function (v) { + switch (v) { + case BI.DynamicYearCombo.Dynamic: + return { + type: "bi.dynamic_year_month_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicYearCombo.Static: + default: + return { + type: "bi.static_year_month_card", + behaviors: o.behaviors, + min: self.options.min, + max: self.options.max, + listeners: [{ + eventName: BI.StaticYearMonthCard.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearMonthPopup.EVENT_CHANGE); + } + }], + ref: function () { + self.year = this; + } + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicYearCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.year.setValue({year: date.getFullYear(), month: date.getMonth()}); + self._setInnerValue(); + break; + case BI.DynamicYearCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; }, setValue: function (v) { this.storeValue = v; - switch (this.getSelect()) { - case BI.SwitchTree.SelectType.SingleSelect: - this.levelTree.setValue(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.SwitchTree.SelectType.MultiSelect: - this.tree.setValue(v); + case BI.DynamicDateCombo.Static: + default: + this.year.setValue(value); + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Month")); + this.textButton.setEnable(true); break; } }, getValue: function () { - return this.tab.getValue(); - }, - - populate: function (items) { - this.options.items = items; - if (BI.isNotNull(this.levelTree)) { - this.levelTree.populate(BI.deepClone(items)); - } - if (BI.isNotNull(this.tree)) { - this.tree.populate(this._removeIsParent(BI.deepClone(items))); - } + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; } + }); -BI.SwitchTree.EVENT_CHANGE = "SwitchTree.EVENT_CHANGE"; -BI.SwitchTree.SelectType = { - SingleSelect: BI.Selection.Single, - MultiSelect: BI.Selection.Multi -}; -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" +BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicYearMonthPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_month_popup", BI.DynamicYearMonthPopup);BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), + errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") }, - _defaultConfig: function () { - var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-date-interval" - }); + + props: { + extraCls: "bi-year-month-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, + _init: function () { - var self = this, o = this.options; - BI.DateInterval.superclass._init.apply(this, arguments); + BI.DynamicYearMonthTrigger.superclass._init.apply(this, arguments); + var o = this.options; + + this.yearEditor = this._createEditor(true); + this.monthEditor = this._createEditor(false); - 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, + element: this, + type: "bi.htape", items: [{ - type: "bi.absolute", + type: "bi.center", items: [{ - el: self.left, - left: this.constants.offset, - right: 0, - top: 0, - bottom: 0 + type: "bi.htape", + items: [this.yearEditor, { + el: { + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Year"), + width: o.height + }, + width: o.height + }] + }, { + type: "bi.htape", + items: [this.monthEditor, { + el: { + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Month"), + width: o.height + }, + width: o.height}] }] }, { - type: "bi.absolute", - items: [{ - el: self.right, - left: 0, - right: this.constants.offset, - top: 0, - bottom: 0 - }] + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height }] }); - BI.createWidget({ - type: "bi.horizontal_auto", - element: this, - items: [ - self.label - ] - }); + this.setValue(o.value); }, - _createCombo: function (v) { - var self = this; - var combo = BI.createWidget({ - type: "bi.dynamic_date_combo", - value: v + _createEditor: function (isYear) { + var self = this, o = this.options, c = this._const; + var editor = BI.createWidget({ + type: "bi.sign_editor", + height: o.height, + validationChecker: function (v) { + if(isYear) { + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); + } + return v === "" || ((v >= 1 && v <= 12) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); + }, + quitChecker: function () { + return false; + }, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + errorText: function (v) { + return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true }); - combo.on(BI.DynamicDateCombo.EVENT_ERROR, function () { - self._clearTitle(); - self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.DateInterval.EVENT_ERROR); + editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_FOCUS); }); - - 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); - } + editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_STOP); }); + editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = editor.getValue(); + if (BI.isNotNull(value)) { + editor.setValue(value); + } + if (BI.isNotEmptyString(value)) { + var monthValue = self.monthEditor.getValue(); + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: self.yearEditor.getValue(), + month: BI.isEmptyString(self.monthEditor.getValue()) ? "" : monthValue - 1 + } + }; + } - 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); + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_CONFIRM); + }); + editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (editor.isValid()) { + editor.blur(); } }); - - combo.on(BI.DynamicDateCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.left.hidePopupView(); - self.right.hidePopupView(); + editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_START); }); - - 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); + 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); + } } }); - 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] + editor.on(BI.SignEditor.EVENT_CHANGE, function () { + if(isYear) { + self._autoSwitch(editor.getValue()); + } }); + + return editor; }, - _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; + + _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; }, - _setTitle: function (v) { - this.left.setTitle(v); - this.right.setTitle(v); - this.label.setTitle(v); + + _autoSwitch: function (v) { + if (BI.checkDateLegal(v)) { + if (v.length === 4 && this._yearCheck(v)) { + this.monthEditor.focus(); + } + } }, - _clearTitle: function () { - this.left.setTitle(""); - this.right.setTitle(""); - this.label.setTitle(""); + + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year)) { + value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + if(BI.isNotNull(obj.month) && obj.month !== 0) { + value += Math.abs(obj.month) + BI.i18nText("BI-Basic_Year") + (obj.month < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + return value; }, - setValue: function (date) { - date = date || {}; - this.left.setValue(date.start); - this.right.setValue(date.end); + + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y-%x"); + this.yearEditor.setValue(date.getFullYear()); + this.monthEditor.setValue(date.getMonth() + 1); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); + }, + + setValue: function (v) { + var type, value; + 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: + value = value || {}; + var month = BI.isNull(value.month) ? null : value.month + 1; + this.yearEditor.setValue(value.year); + this.yearEditor.setTitle(value.year); + this.monthEditor.setValue(month); + this.monthEditor.setTitle(month); + break; + } }, + getValue: function () { - return {start: this.left.getValue(), end: this.right.getValue()}; + return this.storeValue; + }, + + getKey: function () { + return this.yearEditor.getValue() + "-" + this.monthEditor.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, { +BI.DynamicYearMonthTrigger.EVENT_VALID = "EVENT_FOCUS"; +BI.DynamicYearMonthTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicYearMonthTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearMonthTrigger.EVENT_START = "EVENT_START"; +BI.DynamicYearMonthTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearMonthTrigger.EVENT_STOP = "EVENT_STOP"; +BI.shortcut("bi.dynamic_year_month_trigger", BI.DynamicYearMonthTrigger);BI.YearMonthInterval = BI.inherit(BI.Single, { constants: { height: 25, width: 25, @@ -22695,15 +21060,14 @@ BI.TimeInterval = BI.inherit(BI.Single, { DATE_MIN_VALUE: "1900-01-01", DATE_MAX_VALUE: "2099-12-31" }, - _defaultConfig: function () { - var conf = BI.TimeInterval.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-time-interval" - }); + + props: { + extraCls: "bi-year-month-interval" }, + _init: function () { var self = this, o = this.options; - BI.TimeInterval.superclass._init.apply(this, arguments); + BI.YearMonthInterval.superclass._init.apply(this, arguments); o.value = o.value || {}; this.left = this._createCombo(o.value.start); @@ -22751,16 +21115,16 @@ BI.TimeInterval = BI.inherit(BI.Single, { _createCombo: function (v) { var self = this; var combo = BI.createWidget({ - type: "bi.dynamic_date_time_combo", + type: "bi.dynamic_year_month_combo", value: v }); - combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { + combo.on(BI.DynamicYearMonthCombo.EVENT_ERROR, function () { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.TimeInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); }); - combo.on(BI.DynamicDateTimeCombo.EVENT_VALID, function () { + 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)) { @@ -22769,14 +21133,14 @@ BI.TimeInterval = BI.inherit(BI.Single, { BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { offsetStyle: "center" }); - self.fireEvent(BI.TimeInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); } else { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); } }); - combo.on(BI.DynamicDateTimeCombo.EVENT_FOCUS, function () { + 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)) { @@ -22785,741 +21149,809 @@ BI.TimeInterval = BI.inherit(BI.Single, { BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { offsetStyle: "center" }); - self.fireEvent(BI.TimeInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); } else { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); } }); - combo.on(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.left.hidePopupView(); - self.right.hidePopupView(); + combo.on(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hideView(); + self.right.hideView(); }); - // 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)) { - // 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.TimeInterval.EVENT_ERROR); - // } else { - // self._clearTitle(); - // self.element.removeClass(self.constants.timeErrorCls); - // } - // }); - combo.on(BI.DynamicDateTimeCombo.EVENT_CONFIRM, function () { + 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.TimeInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); }else{ self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.TimeInterval.EVENT_CHANGE); + self.fireEvent(BI.YearMonthInterval.EVENT_CHANGE); } }); return combo; }, + + _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; - }, - _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 %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) { - 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.TimeInterval.EVENT_VALID = "EVENT_VALID"; -BI.TimeInterval.EVENT_ERROR = "EVENT_ERROR"; -BI.TimeInterval.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.time_interval", BI.TimeInterval);/** - * 年份下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.YearCombo - * @extends BI.Widget - */ -BI.YearCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-combo", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 25 - }); + return BI.parseDateTime(date, "%Y-%x").print("%Y-%x") === date || BI.parseDateTime(date, "%Y-%X").print("%Y-%X") === date; }, - _init: function () { - BI.YearCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = ""; - this.trigger = BI.createWidget({ - type: "bi.year_trigger", - min: o.min, - max: o.max, - value: o.value || "" - }); - this.trigger.on(BI.YearTrigger.EVENT_FOCUS, function () { - self.storeValue = this.getKey(); - }); - this.trigger.on(BI.YearTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.YearTrigger.EVENT_STOP, function () { - self.combo.showView(); - }); - this.trigger.on(BI.YearTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.YearTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; - } - if (this.getKey() && this.getKey() !== self.storeValue) { - self.setValue(this.getKey()); - } else if (!this.getKey()) { - self.setValue(); - } - self.fireEvent(BI.YearCombo.EVENT_CONFIRM); - }); - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - destroyWhenHide: true, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.year_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.YearPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.YearCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - var value = self.trigger.getKey(); - if (BI.isNotNull(value)) { - self.popup.setValue(value); - } else if (!value && value !== self.storeValue) { - self.popup.setValue(self.storeValue); - } else { - self.setValue(); - } - self.fireEvent(BI.YearCombo.EVENT_BEFORE_POPUPVIEW); - }); + + // 判是否在最大最小之间 + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, 1, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, - setValue: function (v) { - this.combo.setValue(v || ""); + // 判格式合法 + _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 () { - if (BI.isNull(this.popup)) { - return this.options.value; - } else { - return this.popup.getValue(); - } + return {start: this.left.getValue(), end: this.right.getValue()}; } }); -BI.YearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_combo", BI.YearCombo);/** +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);/** * 年份展示面板 * * Created by GUY on 2015/9/2. - * @class BI.YearPopup + * @class BI.YearCard * @extends BI.Trigger */ -BI.YearPopup = BI.inherit(BI.Widget, { +BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31" // 最大日期 - }); + props: { + baseCls: "bi-year-month-card" }, - _createYearCalendar: function (v) { - var o = this.options, y = this._year; - - var calendar = BI.createWidget({ - type: "bi.year_calendar", - behaviors: o.behaviors, - min: o.min, - max: o.max, - logic: { - dynamic: true - }, - year: y + v * 12 - }); - calendar.setValue(this._year); - return calendar; + render: function () { + var self = this; + return { + type: "bi.vertical", + items: [{ + type: "bi.label", + text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), + textAlign: "left", + height: 24 + }, { + type: "bi.dynamic_date_param_item", + ref: function () { + self.year = this; + }, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }, { + type: "bi.dynamic_date_param_item", + dateType: BI.DynamicDateCard.TYPE.QUARTER, + ref: function () { + self.quarter = this; + }, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }], + vgap: 10, + hgap: 10 + }; }, - _init: function () { - BI.YearPopup.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - this.selectedYear = this._year = BI.getDate().getFullYear(); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; + }, - var backBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "pre-page-h-font", - width: 25, - height: 25, - value: -1 - }); + setValue: function (v) { + v = v || {year: 0, month: 0}; + this.year.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); + this.quarter.setValue(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); + }, - var preBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "next-page-h-font", - width: 25, - height: 25, - value: 1 - }); + getValue: function () { + var year = this.year.getValue(); + var quarter = this.quarter.getValue(); + return { + year: (year.offset === 0 ? -year.value : year.value), + quarter: (quarter.offset === 0 ? -quarter.value : quarter.value) + }; + } +}); +BI.DynamicYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_quarter_card", BI.DynamicYearQuarterCard);BI.StaticYearQuarterCard = BI.inherit(BI.Widget, { - this.navigation = BI.createWidget({ - type: "bi.navigation", - element: this, - single: true, - logic: { - dynamic: true - }, - tab: { - cls: "year-popup-navigation bi-high-light bi-border-top", - height: 25, - items: [backBtn, preBtn] - }, - cardCreator: BI.bind(this._createYearCalendar, this), + props: { + baseCls: "bi-static-year-quarter-card", + behaviors: {} + }, - afterCardShow: function () { - this.setValue(self.selectedYear); - var calendar = this.getSelectedCard(); - backBtn.setEnable(!calendar.isFrontYear()); - preBtn.setEnable(!calendar.isFinalYear()); - } - }); + _createQuarter: function () { - this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { - self.selectedYear = this.getValue(); - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.YearPopup.EVENT_CHANGE, self.selectedYear); + var items = [{ + text: Date._QN[1], + value: 1 + }, { + text: Date._QN[2], + value: 2 + }, { + text: Date._QN[3], + value: 3 + }, { + text: Date._QN[4], + value: 4 + }]; + return BI.map(items, function (j, item) { + return BI.extend(item, { + type: "bi.text_item", + cls: "bi-list-item-active", + textAlign: "center", + whiteSpace: "nowrap", + once: false, + forceSelected: true, + height: 24 + }); }); + }, - if(BI.isKey(o.value)){ - this.setValue(o.value); - } + render: function () { + var self = this, o = this.options; + return { + type: "bi.vertical", + items: [{ + type: "bi.year_picker", + ref: function () { + self.yearPicker = this; + }, + height: 30, + listeners: [{ + eventName: BI.YearPicker.EVENT_CHANGE, + action: function () { + var value = this.getValue(); + self.setValue({ + year: value, + quarter: self.selectedQuarter + }); + } + }] + }, { + type: "bi.button_group", + behaviors: o.behaviors, + ref: function () { + self.quarter = this; + }, + items: this._createQuarter(), + layouts: [{ + type: "bi.vertical", + vgap: 10 + }], + value: o.value, + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + self.selectedYear = self.yearPicker.getValue(); + self.selectedQuarter = this.getValue()[0]; + self.fireEvent(BI.StaticYearQuarterCard.EVENT_CHANGE); + } + }] + }] + }; }, + getValue: function () { - return this.selectedYear; + return { + year: this.selectedYear, + quarter: this.selectedQuarter + }; }, - setValue: function (v) { + setValue: function (obj) { var o = this.options; - if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { - v = BI.getDate().getFullYear(); + obj = obj || {}; + obj.year = obj.year || 0; + obj.quarter = obj.quarter || 0; + if (BI.checkDateVoid(obj.year, obj.quarter, 1, o.min, o.max)[0]) { + var year = BI.getDate().getFullYear(); + var quarter = BI.getDate().getQuarter(); this.selectedYear = ""; - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(""); + this.selectedQuarter = ""; + this.yearPicker.setValue(year); + this.quarter.setValue(quarter); } else { - this.selectedYear = v; - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(v); + this.selectedYear = BI.parseInt(obj.year); + this.selectedQuarter = BI.parseInt(obj.quarter); + this.yearPicker.setValue(this.selectedYear); + this.quarter.setValue(this.selectedQuarter); } } }); -BI.YearPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.year_popup", BI.YearPopup);/** - * 年份trigger - * - * Created by GUY on 2015/8/21. - * @class BI.YearTrigger - * @extends BI.Trigger - */ -BI.YearTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") - }, +BI.StaticYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-year-trigger bi-border", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }); + props: { + baseCls: "bi-year-quarter-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, + _init: function () { - BI.YearTrigger.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) { - self.editor.setErrorText(!BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid); - return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true, - errorText: c.errorText, - value: o.value + BI.DynamicYearQuarterCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.storeValue = o.value; + this.trigger = BI.createWidget({ + type: "bi.dynamic_year_quarter_trigger", + min: o.min, + max: o.max, + value: o.value || "" }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.YearTrigger.EVENT_FOCUS); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.YearTrigger.EVENT_STOP); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () { + self.combo.showView(); }); - this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - self.editor.setTitle(value); - } - self.fireEvent(BI.YearTrigger.EVENT_CONFIRM); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_ERROR, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM, function () { + if (self.combo.isViewVisible()) { + return; } + self.storeValue = self.trigger.getValue(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); }); - this.editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.YearTrigger.EVENT_START); + + this.combo = BI.createWidget({ + type: "bi.combo", + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + stopPropagation: false, + el: { + type: "bi.dynamic_year_quarter_popup", + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicYearQuarterPopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({year: date.getFullYear()}); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }], + behaviors: o.behaviors, + min: o.min, + max: o.max + }, + value: o.value || "" + } }); - this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.YearTrigger.EVENT_ERROR); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW); }); + BI.createWidget({ - element: this, type: "bi.htape", - items: [ - { - el: this.editor - }, { - el: { + element: this, + ref: function () { + self.comboWrapper = this; + }, + 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 + }, this.combo] + }); + this._checkDynamicValue(o.value); + }, + + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicYearQuarterCombo.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; + } + +}); +BI.DynamicYearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.dynamic_year_quarter_combo", BI.DynamicYearQuarterCombo); + +BI.extend(BI.DynamicYearQuarterCombo, { + Static: 1, + Dynamic: 2 +});BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 + }, + + props: { + baseCls: "bi-year-quarter-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 + }, + + render: function () { + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicYearQuarterCombo.Static}; + return { + type: "bi.vtape", + items: [{ + el: this._getTabJson() + }, { + el: { + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearQuarterPopup.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-Basic_Current_Quarter"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { type: "bi.text_button", - baseCls: "bi-trigger-year-text", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, - width: o.height - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - } - ] - }); - }, - setValue: function (v) { - this.editor.setState(v); - this.editor.setValue(v); - this.editor.setTitle(v); - }, - getKey: function () { - return this.editor.getValue() | 0; - } -}); -BI.YearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.YearTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.YearTrigger.EVENT_START = "EVENT_START"; -BI.YearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.year_trigger", BI.YearTrigger);/** - * 年份 + 月份下拉框 - * - * @class BI.YearMonthCombo - * @extends BI.Widget - */ -BI.YearMonthCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearMonthCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-month-combo", - yearBehaviors: {}, - monthBehaviors: {}, - height: 25 - }); + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 + }] + }; }, - _init: function () { - BI.YearMonthCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - o.value = o.value || {}; - - this.year = BI.createWidget({ - type: "bi.year_combo", - behaviors: o.yearBehaviors, - value: o.value.year - }); - - this.month = BI.createWidget({ - type: "bi.month_combo", - behaviors: o.monthBehaviors, - value: o.value.month - }); - - this.year.on(BI.YearCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_CONFIRM); - }); - this.year.on(BI.YearCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW); - }); - - this.month.on(BI.MonthCombo.EVENT_CONFIRM, function () { - self.getValue(); - self.fireEvent(BI.YearMonthCombo.EVENT_CONFIRM); - }); - this.month.on(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.center", - element: this, - hgap: 5, - items: [this.year, this.month] - }); + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicYearQuarterCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y-%x"); + this.textButton.setValue(date); + this.textButton.setEnable(false); + } + }, + _getTabJson: function () { + var self = this, o = this.options; + return { + type: "bi.tab", + 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-Basic_Year_Fen"), + value: BI.DynamicYearQuarterCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicYearQuarterCombo.Dynamic + }], { + textAlign: "center" + }) + }, + cardCreator: function (v) { + switch (v) { + case BI.DynamicYearQuarterCombo.Dynamic: + return { + type: "bi.dynamic_year_quarter_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicYearQuarterCombo.Static: + default: + return { + type: "bi.static_year_quarter_card", + behaviors: o.behaviors, + min: self.options.min, + max: self.options.max, + listeners: [{ + eventName: BI.DynamicYearCard.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearQuarterPopup.EVENT_CHANGE); + } + }], + ref: function () { + self.year = this; + } + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicYearQuarterCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.year.setValue({year: date.getFullYear(), quarter: date.getQuarter()}); + self._setInnerValue(); + break; + case BI.DynamicYearQuarterCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicYearQuarterCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; }, setValue: function (v) { + this.storeValue = v; + var self = this; + var type, value; v = v || {}; - this.month.setValue(v.month); - this.year.setValue(v.year); + 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: + this.year.setValue(value); + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Quarter")); + this.textButton.setEnable(true); + break; + } }, getValue: function () { return { - year: this.year.getValue(), - month: this.month.getValue() + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() }; } + }); -BI.YearMonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -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" +BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicYearQuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_quarter_popup", BI.DynamicYearQuarterPopup);BI.DynamicYearQuarterTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), + errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") }, props: { - extraCls: "bi-year-month-interval" + extraCls: "bi-year-quarter-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, _init: function () { - var self = this, o = this.options; - BI.YearMonthInterval.superclass._init.apply(this, arguments); + BI.DynamicYearQuarterTrigger.superclass._init.apply(this, arguments); + var o = this.options; + + this.yearEditor = this._createEditor(true); + this.quarterEditor = this._createEditor(false); - 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, + element: this, + type: "bi.htape", items: [{ - type: "bi.absolute", - items: [{ - el: self.left, - left: this.constants.offset, - right: 0, - top: 0, - bottom: 0 - }] - }, { - type: "bi.absolute", + type: "bi.center", items: [{ - el: self.right, - left: 0, - right: this.constants.offset, - top: 0, - bottom: 0 + type: "bi.htape", + items: [this.yearEditor, { + el: { + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Year"), + width: o.height + }, + width: o.height + }] + }, { + type: "bi.htape", + items: [this.quarterEditor, { + el: { + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Quarter"), + width: o.height + }, + width: o.height}] }] + }, { + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height }] }); - BI.createWidget({ - type: "bi.horizontal_auto", - element: this, - items: [ - self.label - ] - }); + this.setValue(o.value); }, - _createCombo: function (v) { - var self = this; - var combo = BI.createWidget({ - type: "bi.dynamic_year_month_combo", - value: v + _createEditor: function (isYear) { + var self = this, o = this.options, c = this._const; + var editor = BI.createWidget({ + type: "bi.sign_editor", + height: o.height, + validationChecker: function (v) { + if(isYear) { + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); + } + return v === "" || ((v >= 1 && v <= 4) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); + }, + quitChecker: function () { + return false; + }, + errorText: function (v) { + return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; + }, + watermark: BI.i18nText("BI-Basic_Unrestricted"), + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true }); - combo.on(BI.DynamicYearMonthCombo.EVENT_ERROR, function () { - self._clearTitle(); - self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); + editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_FOCUS); }); - - 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); - } + editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_STOP); }); + editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = editor.getValue(); + if (BI.isNotNull(value)) { + editor.setValue(value); + } + if (BI.isNotEmptyString(value)) { + var quarterValue = self.quarterEditor.getValue(); + self.storeValue = { + type: BI.DynamicYearQuarterCombo.Static, + value: { + year: self.yearEditor.getValue(), + quarter: BI.isEmptyString(self.quarterEditor.getValue()) ? "" : quarterValue + } + }; + } - 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); + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM); + }); + editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (editor.isValid()) { + editor.blur(); } }); - - combo.on(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.left.hideView(); - self.right.hideView(); + editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_START); }); - - 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); + editor.on(BI.SignEditor.EVENT_ERROR, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_ERROR); + }); + editor.on(BI.SignEditor.EVENT_CHANGE, function () { + if(isYear) { + self._autoSwitch(editor.getValue()); } }); - return combo; - }, - - _dateCheck: function (date) { - return BI.parseDateTime(date, "%Y-%x").print("%Y-%x") === date || BI.parseDateTime(date, "%Y-%X").print("%Y-%X") === date; + return editor; }, - - // 判是否在最大最小之间 - _checkVoid: function (obj) { - return !BI.checkDateVoid(obj.year, obj.month, 1, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + _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; }, - // 判格式合法 - _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 - }); + _autoSwitch: function (v) { + if (BI.checkDateLegal(v)) { + if (v.length === 4 && this._yearCheck(v)) { + this.quarterEditor.focus(); + } + } }, - _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 - * @extends BI.Widget - */ -BI.YearQuarterCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearQuarterCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-quarter-combo", - yearBehaviors: {}, - quarterBehaviors: {}, - height: 25 - }); + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year)) { + value += Math.abs(obj.year) + BI.i18nText("BI-Basic_Year") + (obj.year < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + if(BI.isNotNull(obj.quarter) && obj.quarter !== 0) { + value += Math.abs(obj.quarter) + BI.i18nText("BI-Basic_Year") + (obj.quarter < 0 ? BI.i18nText("BI-Basic_Front") : BI.i18nText("BI-Basic_Behind")); + } + return value; }, - _init: function () { - BI.YearQuarterCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - - o.value = o.value || {}; - - this.year = BI.createWidget({ - type: "bi.year_combo", - behaviors: o.yearBehaviors, - value: o.value.year - }); - - this.quarter = BI.createWidget({ - type: "bi.quarter_combo", - behaviors: o.quarterBehaviors, - value: o.value.quarter - }); - - this.year.on(BI.YearCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_CONFIRM); - }); - this.year.on(BI.YearCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_BEFORE_POPUPVIEW); - }); - - this.quarter.on(BI.QuarterCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_CONFIRM); - }); - this.quarter.on(BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.center", - element: this, - hgap: 5, - items: [this.year, this.quarter] - }); + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y-%x"); + this.yearEditor.setValue(date.getFullYear()); + this.quarterEditor.setValue(date.getQuarter()); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); }, setValue: function (v) { - v = v || {}; - this.quarter.setValue(v.quarter); - this.year.setValue(v.year); + var type, value; + var date = BI.getDate(); + this.storeValue = v; + if (BI.isNotNull(v)) { + type = v.type || BI.DynamicYearQuarterCombo.Static; + value = v.value || v; + } + switch (type) { + case BI.DynamicYearQuarterCombo.Dynamic: + var text = this._getText(value); + date = BI.DynamicDateHelper.getCalculation(value); + this._setInnerValue(date, text); + break; + case BI.DynamicYearQuarterCombo.Static: + default: + value = value || {}; + var quarter = BI.isNull(value.quarter) ? null : value.quarter; + this.yearEditor.setValue(value.year); + this.yearEditor.setTitle(value.year); + this.quarterEditor.setValue(quarter); + this.quarterEditor.setTitle(quarter); + break; + } }, getValue: function () { - return { - year: this.year.getValue(), - quarter: this.quarter.getValue() - }; + return this.storeValue; } }); -BI.YearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_quarter_combo", BI.YearQuarterCombo);/** +BI.DynamicYearQuarterTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicYearQuarterTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearQuarterTrigger.EVENT_START = "EVENT_START"; +BI.DynamicYearQuarterTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearQuarterTrigger.EVENT_STOP = "EVENT_STOP"; +BI.shortcut("bi.dynamic_year_quarter_trigger", BI.DynamicYearQuarterTrigger);/** * 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 * 封装了字段处理逻辑 * diff --git a/src/widget/date/calendar/popup.year.js b/src/widget/date/calendar/popup.year.js new file mode 100644 index 000000000..16e542f48 --- /dev/null +++ b/src/widget/date/calendar/popup.year.js @@ -0,0 +1,110 @@ +/** + * 年份展示面板 + * + * Created by GUY on 2015/9/2. + * @class BI.YearPopup + * @extends BI.Trigger + */ +BI.YearPopup = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.YearPopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-year-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31" // 最大日期 + }); + }, + + _createYearCalendar: function (v) { + var o = this.options, y = this._year; + + var calendar = BI.createWidget({ + type: "bi.year_calendar", + behaviors: o.behaviors, + min: o.min, + max: o.max, + logic: { + dynamic: true + }, + year: y + v * 12 + }); + calendar.setValue(this._year); + return calendar; + }, + + _init: function () { + BI.YearPopup.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.selectedYear = this._year = BI.getDate().getFullYear(); + + var backBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "pre-page-h-font", + width: 25, + height: 25, + value: -1 + }); + + var preBtn = BI.createWidget({ + type: "bi.icon_button", + cls: "next-page-h-font", + width: 25, + height: 25, + value: 1 + }); + + this.navigation = BI.createWidget({ + type: "bi.navigation", + element: this, + single: true, + logic: { + dynamic: true + }, + tab: { + cls: "year-popup-navigation bi-high-light bi-border-top", + height: 25, + items: [backBtn, preBtn] + }, + cardCreator: BI.bind(this._createYearCalendar, this), + + afterCardShow: function () { + this.setValue(self.selectedYear); + var calendar = this.getSelectedCard(); + backBtn.setEnable(!calendar.isFrontYear()); + preBtn.setEnable(!calendar.isFinalYear()); + } + }); + + this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { + self.selectedYear = this.getValue(); + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + self.fireEvent(BI.YearPopup.EVENT_CHANGE, self.selectedYear); + }); + + if(BI.isKey(o.value)){ + this.setValue(o.value); + } + }, + + getValue: function () { + return this.selectedYear; + }, + + setValue: function (v) { + var o = this.options; + if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { + v = BI.getDate().getFullYear(); + this.selectedYear = ""; + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(""); + } else { + this.selectedYear = v; + this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); + this.navigation.setValue(v); + } + } +}); +BI.YearPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.year_popup", BI.YearPopup); \ No newline at end of file diff --git a/src/widget/dynamic/datepane/card.static.datepane.js b/src/widget/datepane/card.static.datepane.js similarity index 100% rename from src/widget/dynamic/datepane/card.static.datepane.js rename to src/widget/datepane/card.static.datepane.js diff --git a/src/widget/datepane/datepane.js b/src/widget/datepane/datepane.js index 591c6549d..f559cb8c8 100644 --- a/src/widget/datepane/datepane.js +++ b/src/widget/datepane/datepane.js @@ -1,114 +1,140 @@ -/** - * Created by zcf on 2017/2/20. - */ -BI.DatePaneWidget = BI.inherit(BI.Widget, { - _defaultConfig: function () { - var conf = BI.DatePaneWidget.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: "bi-date-pane", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - selectedTime: null - }); - }, - _init: function () { - BI.DatePaneWidget.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 = self.datePicker.getValue(); - self.calendar.setSelect(BI.Calendar.getPageByDateJSON(self.selectedTime)); - }); - - this.calendar = BI.createWidget({ - direction: "top", - element: this, - 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 = self.calendar.getValue(); - self.calendar.empty(); - self.setValue(self.selectedTime); - self.fireEvent(BI.DateCalendarPopup.EVENT_CHANGE); - }); - this.setValue(o.selectedTime); - - }, +BI.DynamicDatePane = BI.inherit(BI.Widget, { - _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; + props: { + baseCls: "bi-dynamic-date-pane" }, - _getNewCurrentDate: function () { - var today = BI.getDate(); + render: function () { + var self = this; return { - year: today.getFullYear(), - month: today.getMonth() + 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.DynamicDatePane.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDatePane.Dynamic + }], { + textAlign: "center" + }), + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + var value = this.getValue()[0]; + self.dateTab.setSelect(value); + switch (value) { + case BI.DynamicDatePane.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + break; + case BI.DynamicDatePane.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.DynamicDatePane.Static, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDatePane.Static: + return { + type: "bi.static_date_pane_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.ymd = this; + } + }; + case BI.DynamicDatePane.Dynamic: + default: + return { + type: "bi.dynamic_date_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + } + } + }] }; }, - _setCalenderValue: function (date) { - this.calendar.setSelect(BI.Calendar.getPageByDateJSON(date)); - this.calendar.setValue(date); - this.selectedTime = date; + mounted: function () { + this.setValue(this.options.value); }, - _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); - } + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, - _setCalendar: function (timeOb) { - if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { - this.calendar.empty(); - this._setCalenderValue(this._getNewCurrentDate()); - } else { - this._setCalenderValue(timeOb); + setValue: function (v) { + v = v || {}; + var type = v.type || BI.DynamicDateCombo.Static; + var value = v.value || v; + this.switch.setValue(type); + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateCombo.Dynamic: + this.dynamicPane.setValue(value); + break; + case BI.DynamicDateCombo.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; } }, - setValue: function (timeOb) { - this._setDatePicker(timeOb); - this._setCalendar(timeOb); - }, - getValue: function () { - return this.selectedTime; + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; } - }); -BI.shortcut("bi.date_pane", BI.DatePaneWidget); \ No newline at end of file +BI.shortcut("bi.dynamic_date_pane", BI.DynamicDatePane); + +BI.extend(BI.DynamicDatePane, { + Static: 1, + Dynamic: 2 +}); \ No newline at end of file diff --git a/src/widget/dynamic/datetimepane/card.static.datetimepane.js b/src/widget/datetimepane/card.static.datetimepane.js similarity index 100% rename from src/widget/dynamic/datetimepane/card.static.datetimepane.js rename to src/widget/datetimepane/card.static.datetimepane.js diff --git a/src/widget/dynamic/datetimepane/datetimepane.js b/src/widget/datetimepane/datetimepane.js similarity index 100% rename from src/widget/dynamic/datetimepane/datetimepane.js rename to src/widget/datetimepane/datetimepane.js diff --git a/src/widget/dynamic/datepane/datepane.js b/src/widget/dynamic/datepane/datepane.js deleted file mode 100644 index f559cb8c8..000000000 --- a/src/widget/dynamic/datepane/datepane.js +++ /dev/null @@ -1,140 +0,0 @@ -BI.DynamicDatePane = 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.DynamicDatePane.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicDatePane.Dynamic - }], { - textAlign: "center" - }), - listeners: [{ - eventName: BI.ButtonGroup.EVENT_CHANGE, - action: function () { - var value = this.getValue()[0]; - self.dateTab.setSelect(value); - switch (value) { - case BI.DynamicDatePane.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - break; - case BI.DynamicDatePane.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.DynamicDatePane.Static, - cardCreator: function (v) { - switch (v) { - case BI.DynamicDatePane.Static: - return { - type: "bi.static_date_pane_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self.fireEvent("EVENT_CHANGE"); - } - }], - ref: function () { - self.ymd = this; - } - }; - case BI.DynamicDatePane.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.DynamicDateCombo.Static; - var value = v.value || v; - this.switch.setValue(type); - this.dateTab.setSelect(type); - switch (type) { - case BI.DynamicDateCombo.Dynamic: - this.dynamicPane.setValue(value); - break; - case BI.DynamicDateCombo.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_pane", BI.DynamicDatePane); - -BI.extend(BI.DynamicDatePane, { - Static: 1, - Dynamic: 2 -}); \ No newline at end of file diff --git a/src/widget/dynamic/year/combo.year.js b/src/widget/dynamic/year/combo.year.js deleted file mode 100644 index 9f140d6a6..000000000 --- a/src/widget/dynamic/year/combo.year.js +++ /dev/null @@ -1,161 +0,0 @@ -BI.DynamicYearCombo = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-year-combo bi-border", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }, - - _init: function () { - BI.DynamicYearCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = o.value; - this.trigger = BI.createWidget({ - type: "bi.dynamic_year_trigger", - min: o.min, - max: o.max, - value: o.value || "" - }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_FOCUS, function () { - self.storeTriggerValue = this.getKey(); - }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_STOP, function () { - self.combo.showView(); - }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; - } - if (this.getKey() && this.getKey() !== self.storeTriggerValue) { - self.storeValue = self.trigger.getValue(); - self.setValue(self.storeValue); - } else if (!this.getKey()) { - self.storeValue = null; - self.setValue(); - } - self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); - }); - - this.combo = BI.createWidget({ - type: "bi.combo", - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.dynamic_year_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicYearPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({year: date.getFullYear()}); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - ref: function () { - self.comboWrapper = this; - }, - 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 - }, this.combo] - }); - this._checkDynamicValue(o.value); - }, - - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.DynamicYearCombo.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; - } - -}); -BI.DynamicYearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.dynamic_year_combo", BI.DynamicYearCombo); - -BI.extend(BI.DynamicYearCombo, { - Static: 1, - Dynamic: 2 -}); \ No newline at end of file diff --git a/src/widget/dynamic/year/popup.year.js b/src/widget/dynamic/year/popup.year.js deleted file mode 100644 index 313816222..000000000 --- a/src/widget/dynamic/year/popup.year.js +++ /dev/null @@ -1,206 +0,0 @@ -/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.DynamicYearPopup - * @extends BI.Trigger - */ -BI.DynamicYearPopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30 - }, - - props: { - baseCls: "bi-year-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期, - width: 180, - height: 240 - }, - - render: function () { - var self = this, opts = this.options; - this.storeValue = {type: BI.DynamicYearCombo.Static}; - return { - type: "bi.vtape", - items: [{ - el: this._getTabJson() - }, { - el: { - type: "bi.grid", - items: [[{ - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_Clear"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.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-Basic_Current_Year"), - ref: function () { - self.textButton = this; - }, - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE); - } - }] - }, { - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_OK"), - listeners: [{ - eventName: BI.TextButton.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE); - } - }] - }]] - }, - height: 24 - }] - }; - }, - - _setInnerValue: function () { - if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); - this.textButton.setEnable(true); - } else { - var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); - date = date.print("%Y"); - this.textButton.setValue(date); - this.textButton.setEnable(false); - } - }, - - _getTabJson: function () { - var self = this, o = this.options; - return { - type: "bi.tab", - 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-Basic_Year_Fen"), - value: BI.DynamicYearCombo.Static - }, { - text: BI.i18nText("BI-Basic_Dynamic_Title"), - value: BI.DynamicYearCombo.Dynamic - }], { - textAlign: "center" - }) - }, - cardCreator: function (v) { - switch (v) { - case BI.DynamicYearCombo.Dynamic: - return { - type: "bi.dynamic_year_card", - listeners: [{ - eventName: "EVENT_CHANGE", - action: function () { - self._setInnerValue(self.year, v); - } - }], - ref: function () { - self.dynamicPane = this; - } - }; - case BI.DynamicYearCombo.Static: - default: - return { - type: "bi.static_year_card", - behaviors: o.behaviors, - min: self.options.min, - max: self.options.max, - listeners: [{ - eventName: BI.YearCard.EVENT_CHANGE, - action: function () { - self.fireEvent(BI.DynamicYearPopup.EVENT_CHANGE); - } - }], - ref: function () { - self.year = this; - } - }; - } - }, - listeners: [{ - eventName: BI.Tab.EVENT_CHANGE, - action: function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.DynamicYearCombo.Static: - var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.year.setValue({year: date.getFullYear()}); - self._setInnerValue(); - break; - case BI.DynamicYearCombo.Dynamic: - default: - if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { - self.dynamicPane.setValue(self.storeValue.value); - }else{ - self.dynamicPane.setValue({ - year: 0 - }); - } - self._setInnerValue(); - break; - } - } - }] - }; - }, - - 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: - this.year.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); - this.textButton.setEnable(true); - break; - } - }, - - getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; - } - -}); -BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.DynamicYearPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.dynamic_year_popup", BI.DynamicYearPopup); \ No newline at end of file diff --git a/src/widget/dynamic/year/trigger.year.js b/src/widget/dynamic/year/trigger.year.js deleted file mode 100644 index 6c49685e2..000000000 --- a/src/widget/dynamic/year/trigger.year.js +++ /dev/null @@ -1,146 +0,0 @@ -BI.DynamicYearTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") - }, - - _defaultConfig: function () { - return BI.extend(BI.DynamicYearTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-year-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }); - }, - _init: function () { - BI.DynamicYearTrigger.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) { - return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - watermark: BI.i18nText("BI-Basic_Unrestricted"), - allowBlank: true, - errorText: function (v) { - return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; - } - }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_FOCUS); - }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_STOP); - }); - this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - } - if (BI.isNotEmptyString(value)) { - self.storeValue = { - type: BI.DynamicDateCombo.Static, - value: { - year: value - } - }; - } - - self.fireEvent(BI.DynamicYearTrigger.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.DynamicYearTrigger.EVENT_START); - }); - this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_ERROR); - }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [{ - el: this.editor - }, { - el: { - type: "bi.text_button", - baseCls: "bi-trigger-year-text", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, - width: o.height - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - }] - }); - this.setValue(o.value); - }, - - _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")); - } - return value; - }, - - _setInnerValue: function (date, text) { - var dateStr = date.print("%Y"); - this.editor.setState(dateStr); - this.editor.setValue(dateStr); - this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); - }, - - setValue: function (v) { - var type, value; - 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: - value = value || {}; - this.editor.setState(value.year); - this.editor.setValue(value.year); - this.editor.setTitle(value.year); - break; - } - }, - - getValue: function () { - return this.storeValue; - }, - - getKey: function () { - return this.editor.getValue() | 0; - } -}); -BI.DynamicYearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DynamicYearTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.DynamicYearTrigger.EVENT_START = "EVENT_START"; -BI.DynamicYearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.dynamic_year_trigger", BI.DynamicYearTrigger); \ No newline at end of file diff --git a/src/widget/dynamic/yearmonth/combo.yearmonth.js b/src/widget/dynamic/yearmonth/combo.yearmonth.js deleted file mode 100644 index b1dddfcef..000000000 --- a/src/widget/dynamic/yearmonth/combo.yearmonth.js +++ /dev/null @@ -1,170 +0,0 @@ -BI.DynamicYearMonthCombo = BI.inherit(BI.Single, { - - props: { - baseCls: "bi-year-month-combo bi-border", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }, - - _init: function () { - BI.DynamicYearMonthCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = o.value; - this.trigger = BI.createWidget({ - type: "bi.dynamic_year_month_trigger", - min: o.min, - max: o.max, - value: o.value || "" - }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_STOP, function () { - self.combo.showView(); - }); - 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()) { - return; - } - 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", - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.dynamic_year_month_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicYearMonthPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({year: date.getFullYear()}); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - ref: function () { - self.comboWrapper = this; - }, - 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 - }, this.combo] - }); - this._checkDynamicValue(o.value); - }, - - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.DynamicYearMonthCombo.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; - } - }, - - hideView: function () { - this.combo.hideView(); - }, - - setValue: function (v) { - this.storeValue = v; - this.trigger.setValue(v); - this._checkDynamicValue(v); - }, - - 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); - -BI.extend(BI.DynamicYearMonthCombo, { - Static: 1, - Dynamic: 2 -}); \ No newline at end of file diff --git a/src/widget/dynamic/yearquarter/combo.yearquarter.js b/src/widget/dynamic/yearquarter/combo.yearquarter.js deleted file mode 100644 index ee489b8cc..000000000 --- a/src/widget/dynamic/yearquarter/combo.yearquarter.js +++ /dev/null @@ -1,152 +0,0 @@ -BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-year-quarter-combo bi-border", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }, - - _init: function () { - BI.DynamicYearQuarterCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = o.value; - this.trigger = BI.createWidget({ - type: "bi.dynamic_year_quarter_trigger", - min: o.min, - max: o.max, - value: o.value || "" - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () { - self.combo.showView(); - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); - }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { - return; - } - self.storeValue = self.trigger.getValue(); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); - }); - - this.combo = BI.createWidget({ - type: "bi.combo", - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - stopPropagation: false, - el: { - type: "bi.dynamic_year_quarter_popup", - ref: function () { - self.popup = this; - }, - listeners: [{ - eventName: BI.DynamicYearQuarterPopup.EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE, - action: function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE, - action: function () { - var date = BI.getDate(); - self.setValue({year: date.getFullYear()}); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }, { - eventName: BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE, - action: function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); - } - }], - behaviors: o.behaviors, - min: o.min, - max: o.max - }, - value: o.value || "" - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW); - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - ref: function () { - self.comboWrapper = this; - }, - 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 - }, this.combo] - }); - this._checkDynamicValue(o.value); - }, - - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.DynamicYearQuarterCombo.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; - } - -}); -BI.DynamicYearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.dynamic_year_quarter_combo", BI.DynamicYearQuarterCombo); - -BI.extend(BI.DynamicYearQuarterCombo, { - Static: 1, - Dynamic: 2 -}); \ No newline at end of file diff --git a/src/widget/multidate/abstract.multidate.datepane.js b/src/widget/multidate/abstract.multidate.datepane.js deleted file mode 100644 index 4d4d5ac55..000000000 --- a/src/widget/multidate/abstract.multidate.datepane.js +++ /dev/null @@ -1,151 +0,0 @@ -/** - * 普通控件 - * - * @class BI.MultiDateCard - * @extends BI.Widget - * @abstract - */ -BI.MultiDateCard = BI.inherit(BI.Widget, { - - constants: { - lgap: 80, - itemHeight: 35, - defaultEditorValue: "1" - }, - - _defaultConfig: function () { - return $.extend(BI.MultiDateCard.superclass._defaultConfig.apply(this, arguments), {}); - }, - - dateConfig: function () { - - }, - - defaultSelectedItem: function () { - - }, - - _init: function () { - BI.MultiDateCard.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - - this.label = BI.createWidget({ - type: "bi.label", - height: this.constants.itemHeight, - textAlign: "left", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - cls: "bi-multidate-inner-label bi-tips" - }); - this.radioGroup = BI.createWidget({ - type: "bi.button_group", - chooseType: 0, - items: BI.createItems(this.dateConfig(), { - type: "bi.multidate_segment", - height: this.constants.itemHeight - }), - layouts: [{ - type: "bi.vertical" - }] - }); - - this.radioGroup.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CONFIRM) { - self.fireEvent(BI.MultiDateCard.EVENT_CHANGE); - } - }); - this.radioGroup.on(BI.ButtonGroup.EVENT_CHANGE, function () { - self.setValue(self.getValue()); - self.fireEvent(BI.MultiDateCard.EVENT_CHANGE); - }); - BI.createWidget({ - element: this, - type: "bi.center_adapt", - lgap: this.constants.lgap, - items: [{ - type: "bi.vertical", - items: [this.label, this.radioGroup] - }] - }); - }, - - getValue: function () { - var button = this.radioGroup.getSelectedButtons()[0]; - var type = button.getValue(), value = button.getInputValue(); - return { - type: type, - value: value - }; - }, - - _isTypeAvaliable: function (type) { - var res = false; - BI.find(this.dateConfig(), function (i, item) { - if (item.value === type) { - res = true; - return true; - } - }); - return res; - }, - - setValue: function (v) { - var self = this; - if (BI.isNotNull(v) && this._isTypeAvaliable(v.type)) { - this.radioGroup.setValue(v.type); - BI.each(this.radioGroup.getAllButtons(), function (i, button) { - if (button.isEditorExist() === true && button.isSelected()) { - button.setInputValue(v.value); - } else { - button.setInputValue(self.constants.defaultEditorValue); - } - }); - } else { - this.radioGroup.setValue(this.defaultSelectedItem()); - BI.each(this.radioGroup.getAllButtons(), function (i, button) { - button.setInputValue(self.constants.defaultEditorValue); - }); - } - }, - - getCalculationValue: function () { - var valueObject = this.getValue(); - var type = valueObject.type, value = valueObject.value; - switch (type) { - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - return BI.getDate().getOffsetDate(-1 * value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - return BI.getDate().getOffsetDate(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - return BI.getDate(); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - return BI.getDate().getBeforeMultiMonth(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - return BI.getDate().getAfterMultiMonth(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), 1); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - return BI.getDate(BI.getDate().getFullYear(), BI.getDate().getMonth(), (BI.getDate().getLastDateOfMonth()).getDate()); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - return BI.getDate().getBeforeMulQuarter(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - return BI.getDate().getAfterMulQuarter(value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - return BI.getDate().getQuarterStartDate(); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - return BI.getDate().getQuarterEndDate(); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - return BI.getDate().getOffsetDate(-7 * value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - return BI.getDate().getOffsetDate(7 * value); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - return BI.getDate((BI.getDate().getFullYear() - 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - return BI.getDate((BI.getDate().getFullYear() + 1 * value), BI.getDate().getMonth(), BI.getDate().getDate()); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - return BI.getDate(BI.getDate().getFullYear(), 0, 1); - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - return BI.getDate(BI.getDate().getFullYear(), 11, 31); - } - } -}); -BI.MultiDateCard.EVENT_CHANGE = "EVENT_CHANGE"; diff --git a/src/widget/multidate/multidate.combo.js b/src/widget/multidate/multidate.combo.js deleted file mode 100644 index 8c2ac9789..000000000 --- a/src/widget/multidate/multidate.combo.js +++ /dev/null @@ -1,283 +0,0 @@ -/** - * 日期控件 - * @class BI.MultiDateCombo - * @extends BI.Widget - */ -BI.MultiDateCombo = 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" - }, - _defaultConfig: function () { - return BI.extend(BI.MultiDateCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-combo bi-border", - height: 24 - }); - }, - _init: function () { - BI.MultiDateCombo.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - this.storeTriggerValue = ""; - var date = BI.getDate(); - this.storeValue = opts.value; - this.trigger = BI.createWidget({ - type: "bi.date_trigger", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value - }); - this.trigger.on(BI.DateTrigger.EVENT_KEY_DOWN, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } - }); - this.trigger.on(BI.DateTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - }); - this.trigger.on(BI.DateTrigger.EVENT_TRIGGER_CLICK, function () { - self.combo.toggle(); - }); - this.trigger.on(BI.DateTrigger.EVENT_FOCUS, function () { - self.storeTriggerValue = self.trigger.getKey(); - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } - self.fireEvent(BI.MultiDateCombo.EVENT_FOCUS); - }); - this.trigger.on(BI.DateTrigger.EVENT_ERROR, function () { - self.storeValue = { - year: date.getFullYear(), - month: date.getMonth() - }; - self.popup.setValue(); - self.fireEvent(BI.MultiDateCombo.EVENT_ERROR); - }); - this.trigger.on(BI.DateTrigger.EVENT_VALID, function () { - self.fireEvent(BI.MultiDateCombo.EVENT_VALID); - }); - this.trigger.on(BI.DateTrigger.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDateCombo.EVENT_CHANGE); - }); - this.trigger.on(BI.DateTrigger.EVENT_CONFIRM, 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.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup = BI.createWidget({ - type: "bi.multidate_popup", - min: this.constants.DATE_MIN_VALUE, - max: this.constants.DATE_MAX_VALUE, - value: opts.value - }); - this.popup.on(BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE, function () { - self.setValue(); - self.combo.hideView(); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup.on(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE, function () { - var date = BI.getDate(); - self.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - self.combo.hideView(); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup.on(BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.popup.on(BI.MultiDatePopup.CALENDAR_EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - // self.fireEvent(BI.MultiDateCombo.EVENT_CHANGE); - self.fireEvent(BI.MultiDateCombo.EVENT_CONFIRM); - }); - this.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - adjustLength: this.constants.comboAdjustHeight, - popup: { - el: this.popup, - width: this.constants.popupWidth, - stopPropagation: false - } - }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW); - }); - - var triggerBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "bi-trigger-icon-button date-font", - width: 24, - height: 24 - }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); - } - }); - this.changeIcon = BI.createWidget({ - type: "bi.icon_button", - cls: "bi-trigger-icon-button date-change-h-font", - width: 24, - height: 24 - }); - - - var leftPart = BI.createWidget({ - type: "bi.absolute", - items: [{ - el: this.combo, - top: 0, - left: 0, - right: 0, - bottom: 0 - }, { - el: triggerBtn, - top: 0, - left: 0 - }] - }); - - BI.createWidget({ - type: "bi.htape", - element: this, - items: [leftPart, { - el: this.changeIcon, - width: 30 - }], - ref: function (_ref) { - self.comboWrapper = _ref; - } - }); - - this._checkDynamicValue(opts.value); - }, - - _checkDynamicValue: function (v) { - var type = null; - if (BI.isNotNull(v)) { - type = v.type; - } - switch (type) { - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - this.changeIcon.setVisible(true); - this.comboWrapper.attr("items")[1].width = 30; - this.comboWrapper.resize(); - break; - default: - this.comboWrapper.attr("items")[1].width = 0; - this.comboWrapper.resize(); - this.changeIcon.setVisible(false); - break; - } - }, - - setValue: function (v) { - this.storeValue = v; - this.popup.setValue(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.shortcut("bi.multidate_combo", BI.MultiDateCombo); - -BI.MultiDateCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.MultiDateCombo.EVENT_FOCUS = "EVENT_FOCUS"; -BI.MultiDateCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiDateCombo.EVENT_VALID = "EVENT_VALID"; -BI.MultiDateCombo.EVENT_ERROR = "EVENT_ERROR"; -BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW = "BI.MultiDateCombo.EVENT_BEFORE_POPUPVIEW"; - -BI.extend(BI.MultiDateCombo, { - MULTI_DATE_YMD_CARD: 1, - MULTI_DATE_YEAR_CARD: 2, - MULTI_DATE_QUARTER_CARD: 3, - MULTI_DATE_MONTH_CARD: 4, - MULTI_DATE_WEEK_CARD: 5, - MULTI_DATE_DAY_CARD: 6 -}); - -BI.extend(BI.MultiDateCombo, { - DATE_TYPE: { - MULTI_DATE_YEAR_PREV: 1, - MULTI_DATE_YEAR_AFTER: 2, - MULTI_DATE_YEAR_BEGIN: 3, - MULTI_DATE_YEAR_END: 4, - MULTI_DATE_MONTH_PREV: 5, - MULTI_DATE_MONTH_AFTER: 6, - MULTI_DATE_MONTH_BEGIN: 7, - MULTI_DATE_MONTH_END: 8, - MULTI_DATE_QUARTER_PREV: 9, - MULTI_DATE_QUARTER_AFTER: 10, - MULTI_DATE_QUARTER_BEGIN: 11, - MULTI_DATE_QUARTER_END: 12, - MULTI_DATE_WEEK_PREV: 13, - MULTI_DATE_WEEK_AFTER: 14, - MULTI_DATE_DAY_PREV: 15, - MULTI_DATE_DAY_AFTER: 16, - MULTI_DATE_DAY_TODAY: 17, - MULTI_DATE_PARAM: 18, - MULTI_DATE_CALENDAR: 19, - YEAR_QUARTER: 20, - YEAR_MONTH: 21, - YEAR_WEEK: 22, - YEAR_DAY: 23, - MONTH_WEEK: 24, - MONTH_DAY: 25, - YEAR: 26, - SAME_PERIOD: 27, - LAST_SAME_PERIOD: 28 - } -}); diff --git a/src/widget/multidate/multidate.day.js b/src/widget/multidate/multidate.day.js deleted file mode 100644 index 403679c72..000000000 --- a/src/widget/multidate/multidate.day.js +++ /dev/null @@ -1,43 +0,0 @@ -/** - * 普通控件 - * - * @class BI.DayCard - * @extends BI.MultiDateCard - */ -BI.DayCard = BI.inherit(BI.MultiDateCard, { - - _defaultConfig: function () { - return $.extend(BI.DayCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-daycard" - }); - }, - - _init: function () { - BI.DayCard.superclass._init.apply(this, arguments); - }, - - dateConfig: function () { - return [{ - isEditorExist: true, - selected: true, - text: BI.i18nText("BI-Multi_Date_Day_Prev"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV - }, - { - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Day_Next"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER - }, - { - isEditorExist: false, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY, - text: BI.i18nText("BI-Multi_Date_Today") - }]; - }, - - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV; - } -}); -BI.DayCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.daycard", BI.DayCard); diff --git a/src/widget/multidate/multidate.month.js b/src/widget/multidate/multidate.month.js deleted file mode 100644 index 731f43b70..000000000 --- a/src/widget/multidate/multidate.month.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 普通控件 - * - * @class BI.MonthCard - * @extends BI.MultiDateCard - */ -BI.MonthCard = BI.inherit(BI.MultiDateCard, { - _defaultConfig: function () { - return $.extend(BI.MonthCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-monthcard" - }); - }, - - _init: function () { - BI.MonthCard.superclass._init.apply(this, arguments); - }, - - dateConfig: function () { - return [{ - selected: true, - isEditorExist: true, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV, - text: BI.i18nText("BI-Multi_Date_Month_Prev") - }, - { - isEditorExist: true, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER, - text: BI.i18nText("BI-Multi_Date_Month_Next") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Month_Begin") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Month_End") - }]; - }, - - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV; - } -}); -BI.MonthCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.monthcard", BI.MonthCard); diff --git a/src/widget/multidate/multidate.popup.js b/src/widget/multidate/multidate.popup.js deleted file mode 100644 index 3f9f99790..000000000 --- a/src/widget/multidate/multidate.popup.js +++ /dev/null @@ -1,317 +0,0 @@ -/** - * 日期控件 - * @class BI.MultiDatePopup - * @extends BI.Widget - */ -BI.MultiDatePopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30, - tabWidth: 42, - titleHeight: 27, - itemHeight: 30, - triggerHeight: 24, - buttonWidth: 90, - buttonHeight: 25, - cardHeight: 229, - cardWidth: 270, - popupHeight: 259, - popupWidth: 270, - comboAdjustHeight: 1, - ymdWidth: 58, - lgap: 2, - border: 1 - }, - _defaultConfig: function () { - return BI.extend(BI.MultiDatePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-popup", - height: 344 - }); - }, - _init: function () { - BI.MultiDatePopup.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - this.storeValue = ""; - this.textButton = BI.createWidget({ - type: "bi.text_button", - forceCenter: true, - cls: "bi-multidate-popup-label bi-border-left bi-border-right bi-border-top", - shadow: true, - text: BI.i18nText("BI-Multi_Date_Today") - }); - this.textButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE); - }); - this.clearButton = BI.createWidget({ - type: "bi.text_button", - forceCenter: true, - cls: "bi-multidate-popup-button bi-border-top", - shadow: true, - text: BI.i18nText("BI-Basic_Clear") - }); - this.clearButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE); - }); - this.okButton = BI.createWidget({ - type: "bi.text_button", - forceCenter: true, - cls: "bi-multidate-popup-button bi-border-top", - shadow: true, - text: BI.i18nText("BI-Basic_OK") - }); - this.okButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE); - }); - this.dateTab = BI.createWidget({ - type: "bi.tab", - tab: { - cls: "bi-border-bottom", - height: this.constants.tabHeight, - items: BI.createItems([{ - text: BI.i18nText("BI-Multi_Date_YMD"), - value: BI.MultiDateCombo.MULTI_DATE_YMD_CARD, - width: this.constants.ymdWidth - }, { - text: BI.i18nText("BI-Multi_Date_Year"), - value: BI.MultiDateCombo.MULTI_DATE_YEAR_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Quarter"), - value: BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Month"), - value: BI.MultiDateCombo.MULTI_DATE_MONTH_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Week"), - value: BI.MultiDateCombo.MULTI_DATE_WEEK_CARD - }, { - text: BI.i18nText("BI-Multi_Date_Day"), - value: BI.MultiDateCombo.MULTI_DATE_DAY_CARD - }], { - width: this.constants.tabWidth, - textAlign: "center", - height: this.constants.itemHeight, - cls: "bi-multidate-popup-item bi-list-item-active" - }), - layouts: [{ - type: "bi.left" - }] - }, - cardCreator: function (v) { - switch (v) { - case BI.MultiDateCombo.MULTI_DATE_YMD_CARD: - self.ymd = BI.createWidget({ - type: "bi.date_calendar_popup", - min: self.options.min, - max: self.options.max - }); - self.ymd.on(BI.DateCalendarPopup.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.CALENDAR_EVENT_CHANGE); - }); - return self.ymd; - case BI.MultiDateCombo.MULTI_DATE_YEAR_CARD: - self.year = BI.createWidget({ - type: "bi.yearcard" - }); - self.year.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.year, v); - }); - return self.year; - case BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD: - self.quarter = BI.createWidget({ - type: "bi.quartercard" - }); - self.quarter.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.quarter, v); - }); - return self.quarter; - case BI.MultiDateCombo.MULTI_DATE_MONTH_CARD: - self.month = BI.createWidget({ - type: "bi.monthcard" - }); - self.month.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.month, v); - }); - return self.month; - case BI.MultiDateCombo.MULTI_DATE_WEEK_CARD: - self.week = BI.createWidget({ - type: "bi.weekcard" - }); - self.week.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.week, v); - }); - return self.week; - case BI.MultiDateCombo.MULTI_DATE_DAY_CARD: - self.day = BI.createWidget({ - type: "bi.daycard" - }); - self.day.on(BI.MultiDateCard.EVENT_CHANGE, function (v) { - self._setInnerValue(self.day, v); - }); - return self.day; - } - } - }); - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_YMD_CARD; - this.dateTab.on(BI.Tab.EVENT_CHANGE, function () { - var v = self.dateTab.getSelect(); - switch (v) { - case BI.MultiDateCombo.MULTI_DATE_YMD_CARD: - var date = this.getTab(self.cur).getCalculationValue(); - self.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - self._setInnerValue(self.ymd); - break; - case BI.MultiDateCombo.MULTI_DATE_YEAR_CARD: - self.year.setValue(self.storeValue); - self._setInnerValue(self.year); - break; - case BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD: - self.quarter.setValue(self.storeValue); - self._setInnerValue(self.quarter); - break; - case BI.MultiDateCombo.MULTI_DATE_MONTH_CARD: - self.month.setValue(self.storeValue); - self._setInnerValue(self.month); - break; - case BI.MultiDateCombo.MULTI_DATE_WEEK_CARD: - self.week.setValue(self.storeValue); - self._setInnerValue(self.week); - break; - case BI.MultiDateCombo.MULTI_DATE_DAY_CARD: - self.day.setValue(self.storeValue); - self._setInnerValue(self.day); - break; - } - self.cur = v; - }); - this.dateButton = BI.createWidget({ - type: "bi.grid", - items: [[this.clearButton, this.textButton, this.okButton]] - }); - BI.createWidget({ - element: this, - type: "bi.vtape", - items: [{ - el: this.dateTab - }, { - el: this.dateButton, - height: 30 - }] - }); - this.setValue(opts.value); - }, - _setInnerValue: function (obj) { - if (this.dateTab.getSelect() === BI.MultiDateCombo.MULTI_DATE_YMD_CARD) { - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - this.textButton.setEnable(true); - } else { - var date = obj.getCalculationValue(); - 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, date; - var type, value; - if (BI.isNotNull(v)) { - type = v.type || BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_CALENDAR; - value = v.value; - if (BI.isNull(value)) { - value = v; - } - } - switch (type) { - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YEAR_CARD); - this.year.setValue({type: type, value: value}); - this.cur = BI.MultiDateCombo.MULTI_DATE_YEAR_CARD; - self._setInnerValue(this.year); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD; - this.quarter.setValue({type: type, value: value}); - self._setInnerValue(this.quarter); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_BEGIN: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_MONTH_END: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_MONTH_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_MONTH_CARD; - this.month.setValue({type: type, value: value}); - self._setInnerValue(this.month); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_WEEK_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_WEEK_CARD; - this.week.setValue({type: type, value: value}); - self._setInnerValue(this.week); - break; - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_PREV: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_AFTER: - case BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_DAY_TODAY: - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_DAY_CARD); - this.cur = BI.MultiDateCombo.MULTI_DATE_DAY_CARD; - this.day.setValue({type: type, value: value}); - self._setInnerValue(this.day); - break; - default: - if (this._checkValueValid(value)) { - var date = BI.getDate(); - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); - this.ymd.setValue({ - year: date.getFullYear(), - month: date.getMonth(), - day: date.getDate() - }); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } else { - this.dateTab.setSelect(BI.MultiDateCombo.MULTI_DATE_YMD_CARD); - this.ymd.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); - } - this.textButton.setEnable(true); - break; - } - }, - getValue: function () { - var tab = this.dateTab.getSelect(); - switch (tab) { - case BI.MultiDateCombo.MULTI_DATE_YMD_CARD: - return this.ymd.getValue(); - case BI.MultiDateCombo.MULTI_DATE_YEAR_CARD: - return this.year.getValue(); - case BI.MultiDateCombo.MULTI_DATE_QUARTER_CARD: - return this.quarter.getValue(); - case BI.MultiDateCombo.MULTI_DATE_MONTH_CARD: - return this.month.getValue(); - case BI.MultiDateCombo.MULTI_DATE_WEEK_CARD: - return this.week.getValue(); - case BI.MultiDateCombo.MULTI_DATE_DAY_CARD: - return this.day.getValue(); - } - } -}); -BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; -BI.MultiDatePopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; -BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; -BI.MultiDatePopup.CALENDAR_EVENT_CHANGE = "CALENDAR_EVENT_CHANGE"; -BI.shortcut("bi.multidate_popup", BI.MultiDatePopup); diff --git a/src/widget/multidate/multidate.quarter.js b/src/widget/multidate/multidate.quarter.js deleted file mode 100644 index ab137edeb..000000000 --- a/src/widget/multidate/multidate.quarter.js +++ /dev/null @@ -1,48 +0,0 @@ -/** - * 普通控件 - * - * @class BI.QuarterCard - * @extends BI.MultiDateCard - */ -BI.QuarterCard = BI.inherit(BI.MultiDateCard, { - - _defaultConfig: function () { - return $.extend(BI.QuarterCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-quartercard" - }); - }, - - _init: function () { - BI.QuarterCard.superclass._init.apply(this, arguments); - }, - - dateConfig: function () { - return [{ - selected: true, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Quarter_Prev") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_AFTER, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Quarter_Next") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_BEGIN, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Quarter_Begin") - }, - { - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_END, - isEditorExist: false, - text: BI.i18nText("BI-Multi_Date_Quarter_End") - }]; - }, - - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_QUARTER_PREV; - } -}); -BI.QuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.quartercard", BI.QuarterCard); diff --git a/src/widget/multidate/multidate.segment.js b/src/widget/multidate/multidate.segment.js deleted file mode 100644 index 0021b9a1b..000000000 --- a/src/widget/multidate/multidate.segment.js +++ /dev/null @@ -1,127 +0,0 @@ -/** - * 普通控件 - * - * @class BI.MultiDateSegment - * @extends BI.Single - */ -BI.MultiDateSegment = BI.inherit(BI.Single, { - constants: { - itemHeight: 24, - maxGap: 15, - minGap: 10, - textWidth: 60, - defaultEditorValue: "1" - }, - - _defaultConfig: function () { - return $.extend(BI.MultiDateSegment.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-segment", - text: "", - height: 30, - isEditorExist: true, - selected: false, - defaultEditorValue: "1" - }); - }, - - _init: function () { - BI.MultiDateSegment.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - this.radio = BI.createWidget({ - type: "bi.radio", - selected: opts.selected - }); - this.radio.on(BI.Controller.EVENT_CHANGE, function (v) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.textEditor = BI.createWidget({ - type: "bi.text_editor", - value: this.constants.defaultEditorValue, - title: function () { - return self.textEditor.getValue(); - }, - tipType: "success", - cls: "bi-multidate-editor", - width: this.constants.textWidth, - height: this.constants.itemHeight - }); - this.textEditor.on(BI.Controller.EVENT_CHANGE, function (v) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - cls: "bi-multidate-normal-label", - text: opts.text, - height: this.constants.itemHeight - }); - this._createSegment(); - }, - _createSegment: function () { - if (this.options.isEditorExist === true) { - return BI.createWidget({ - element: this, - type: "bi.left", - items: [{ - el: { - type: "bi.center_adapt", - items: [this.radio], - height: this.constants.itemHeight - }, - lgap: 0 - }, - { - el: { - type: "bi.center_adapt", - items: [this.textEditor], - widgetName: "textEditor" - }, - lgap: this.constants.maxGap - }, - { - el: this.text, - lgap: this.constants.minGap - }] - }); - } - return BI.createWidget({ - element: this, - type: "bi.left", - items: [{ - el: { - type: "bi.center_adapt", - items: [this.radio], - height: this.constants.itemHeight - }, - lgap: 0 - }, - { - el: this.text, - lgap: this.constants.maxGap - }] - }); - }, - setSelected: function (v) { - if (BI.isNotNull(this.radio)) { - this.radio.setSelected(v); - this.textEditor.setEnable(v); - } - }, - isSelected: function () { - return this.radio.isSelected(); - }, - getValue: function () { - return this.options.value; - }, - getInputValue: function () { - return this.textEditor.getValue() | 0; - }, - setInputValue: function (v) { - this.textEditor.setValue(v); - }, - isEditorExist: function () { - return this.options.isEditorExist; - } -}); -BI.MultiDateSegment.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multidate_segment", BI.MultiDateSegment); \ No newline at end of file diff --git a/src/widget/multidate/multidate.week.js b/src/widget/multidate/multidate.week.js deleted file mode 100644 index 9eb6708c8..000000000 --- a/src/widget/multidate/multidate.week.js +++ /dev/null @@ -1,37 +0,0 @@ -/** - * 普通控件 - * - * @class BI.WeekCard - * @extends BI.MultiDateCard - */ -BI.WeekCard = BI.inherit(BI.MultiDateCard, { - _defaultConfig: function () { - return $.extend(BI.WeekCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-weekcard" - }); - }, - - _init: function () { - BI.WeekCard.superclass._init.apply(this, arguments); - }, - - dateConfig: function () { - return [{ - selected: true, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Week_Prev"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV - }, - { - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Week_Next"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_AFTER - }]; - }, - - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_WEEK_PREV; - } -}); -BI.WeekCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.weekcard", BI.WeekCard); diff --git a/src/widget/multidate/multidate.year.js b/src/widget/multidate/multidate.year.js deleted file mode 100644 index 272db0e7c..000000000 --- a/src/widget/multidate/multidate.year.js +++ /dev/null @@ -1,47 +0,0 @@ -/** - * 普通控件 - * - * @class BI.YearCard - * @extends BI.MultiDateCard - */ -BI.YearCard = BI.inherit(BI.MultiDateCard, { - _defaultConfig: function () { - return $.extend(BI.YearCard.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multidate-yearcard" - }); - }, - - _init: function () { - BI.YearCard.superclass._init.apply(this, arguments); - }, - - dateConfig: function () { - return [{ - selected: true, - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Year_Prev"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV - }, - { - isEditorExist: true, - text: BI.i18nText("BI-Multi_Date_Year_Next"), - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_AFTER - }, - { - isEditorExist: false, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_BEGIN, - text: BI.i18nText("BI-Multi_Date_Year_Begin") - }, - { - isEditorExist: false, - value: BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_END, - text: BI.i18nText("BI-Multi_Date_Year_End") - }]; - }, - - defaultSelectedItem: function () { - return BI.MultiDateCombo.DATE_TYPE.MULTI_DATE_YEAR_PREV; - } -}); -BI.YearCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.yearcard", BI.YearCard); diff --git a/src/widget/dynamic/year/card.dynamic.year.js b/src/widget/year/card.dynamic.year.js similarity index 100% rename from src/widget/dynamic/year/card.dynamic.year.js rename to src/widget/year/card.dynamic.year.js diff --git a/src/widget/dynamic/year/card.year.js b/src/widget/year/card.year.js similarity index 100% rename from src/widget/dynamic/year/card.year.js rename to src/widget/year/card.year.js diff --git a/src/widget/year/combo.year.js b/src/widget/year/combo.year.js index 94d82e5ee..9f140d6a6 100644 --- a/src/widget/year/combo.year.js +++ b/src/widget/year/combo.year.js @@ -1,58 +1,51 @@ -/** - * 年份下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.YearCombo - * @extends BI.Widget - */ -BI.YearCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-combo", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 25 - }); +BI.DynamicYearCombo = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-year-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, + _init: function () { - BI.YearCombo.superclass._init.apply(this, arguments); + BI.DynamicYearCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.storeValue = ""; + this.storeValue = o.value; this.trigger = BI.createWidget({ - type: "bi.year_trigger", + type: "bi.dynamic_year_trigger", min: o.min, max: o.max, value: o.value || "" }); - this.trigger.on(BI.YearTrigger.EVENT_FOCUS, function () { - self.storeValue = this.getKey(); + this.trigger.on(BI.DynamicYearTrigger.EVENT_FOCUS, function () { + self.storeTriggerValue = this.getKey(); }); - this.trigger.on(BI.YearTrigger.EVENT_START, function () { + this.trigger.on(BI.DynamicYearTrigger.EVENT_START, function () { self.combo.isViewVisible() && self.combo.hideView(); }); - this.trigger.on(BI.YearTrigger.EVENT_STOP, function () { + this.trigger.on(BI.DynamicYearTrigger.EVENT_STOP, function () { self.combo.showView(); }); - this.trigger.on(BI.YearTrigger.EVENT_ERROR, function () { + this.trigger.on(BI.DynamicYearTrigger.EVENT_ERROR, function () { self.combo.isViewVisible() && self.combo.hideView(); }); - this.trigger.on(BI.YearTrigger.EVENT_CONFIRM, function () { + this.trigger.on(BI.DynamicYearTrigger.EVENT_CONFIRM, function () { if (self.combo.isViewVisible()) { return; } - if (this.getKey() && this.getKey() !== self.storeValue) { - self.setValue(this.getKey()); + if (this.getKey() && this.getKey() !== self.storeTriggerValue) { + self.storeValue = self.trigger.getValue(); + self.setValue(self.storeValue); } else if (!this.getKey()) { + self.storeValue = null; self.setValue(); } - self.fireEvent(BI.YearCombo.EVENT_CONFIRM); + self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); }); this.combo = BI.createWidget({ type: "bi.combo", - element: this, - destroyWhenHide: true, isNeedAdjustHeight: false, isNeedAdjustWidth: false, el: this.trigger, @@ -60,16 +53,38 @@ BI.YearCombo = BI.inherit(BI.Widget, { minWidth: 85, stopPropagation: false, el: { - type: "bi.year_popup", + type: "bi.dynamic_year_popup", ref: function () { self.popup = this; }, listeners: [{ - eventName: BI.YearPopup.EVENT_CHANGE, + eventName: BI.DynamicYearPopup.EVENT_CHANGE, action: function () { self.setValue(self.popup.getValue()); self.combo.hideView(); - self.fireEvent(BI.YearCombo.EVENT_CONFIRM); + self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({year: date.getFullYear()}); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); } }], behaviors: o.behaviors, @@ -80,30 +95,67 @@ BI.YearCombo = BI.inherit(BI.Widget, { } }); this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - var value = self.trigger.getKey(); - if (BI.isNotNull(value)) { - self.popup.setValue(value); - } else if (!value && value !== self.storeValue) { - self.popup.setValue(self.storeValue); - } else { - self.setValue(); - } - self.fireEvent(BI.YearCombo.EVENT_BEFORE_POPUPVIEW); + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW); + }); + + BI.createWidget({ + type: "bi.htape", + element: this, + ref: function () { + self.comboWrapper = this; + }, + 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 + }, this.combo] }); + this._checkDynamicValue(o.value); + }, + + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicYearCombo.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.combo.setValue(v || ""); + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); }, getValue: function () { - if (BI.isNull(this.popup)) { - return this.options.value; - } else { - return this.popup.getValue(); - } + return this.storeValue; } + }); -BI.YearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_combo", BI.YearCombo); \ No newline at end of file +BI.DynamicYearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.dynamic_year_combo", BI.DynamicYearCombo); + +BI.extend(BI.DynamicYearCombo, { + Static: 1, + Dynamic: 2 +}); \ No newline at end of file diff --git a/src/widget/year/popup.year.js b/src/widget/year/popup.year.js index 16e542f48..cb05ed305 100644 --- a/src/widget/year/popup.year.js +++ b/src/widget/year/popup.year.js @@ -2,109 +2,205 @@ * 年份展示面板 * * Created by GUY on 2015/9/2. - * @class BI.YearPopup + * @class BI.DynamicYearPopup * @extends BI.Trigger */ -BI.YearPopup = BI.inherit(BI.Widget, { +BI.DynamicYearPopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 + }, - _defaultConfig: function () { - return BI.extend(BI.YearPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-popup", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31" // 最大日期 - }); + props: { + baseCls: "bi-year-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 }, - _createYearCalendar: function (v) { - var o = this.options, y = this._year; + render: function () { + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicYearCombo.Static}; + return { + type: "bi.vtape", + items: [{ + el: this._getTabJson() + }, { + el: { + type: "bi.grid", + items: [[{ + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_Clear"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.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-Basic_Current_Year"), + ref: function () { + self.textButton = this; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE); + } + }] + }, { + type: "bi.text_button", + forceCenter: true, + cls: "bi-border-top bi-high-light", + shadow: true, + text: BI.i18nText("BI-Basic_OK"), + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE); + } + }] + }]] + }, + height: 24 + }] + }; + }, - var calendar = BI.createWidget({ - type: "bi.year_calendar", - behaviors: o.behaviors, - min: o.min, - max: o.max, - logic: { - dynamic: true - }, - year: y + v * 12 - }); - calendar.setValue(this._year); - return calendar; + _setInnerValue: function () { + if (this.dateTab.getSelect() === BI.DynamicDateCombo.Static) { + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); + this.textButton.setEnable(true); + } else { + var date = BI.DynamicDateHelper.getCalculation(this.dynamicPane.getValue()); + date = date.print("%Y"); + this.textButton.setValue(date); + this.textButton.setEnable(false); + } }, - _init: function () { - BI.YearPopup.superclass._init.apply(this, arguments); + _getTabJson: function () { var self = this, o = this.options; - - this.selectedYear = this._year = BI.getDate().getFullYear(); - - var backBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "pre-page-h-font", - width: 25, - height: 25, - value: -1 - }); - - var preBtn = BI.createWidget({ - type: "bi.icon_button", - cls: "next-page-h-font", - width: 25, - height: 25, - value: 1 - }); - - this.navigation = BI.createWidget({ - type: "bi.navigation", - element: this, - single: true, - logic: { - dynamic: true + return { + type: "bi.tab", + ref: function () { + self.dateTab = this; }, tab: { - cls: "year-popup-navigation bi-high-light bi-border-top", - height: 25, - items: [backBtn, preBtn] + type: "bi.linear_segment", + cls: "bi-border-bottom", + height: this.constants.tabHeight, + items: BI.createItems([{ + text: BI.i18nText("BI-Basic_Year_Fen"), + value: BI.DynamicYearCombo.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicYearCombo.Dynamic + }], { + textAlign: "center" + }) }, - cardCreator: BI.bind(this._createYearCalendar, this), - - afterCardShow: function () { - this.setValue(self.selectedYear); - var calendar = this.getSelectedCard(); - backBtn.setEnable(!calendar.isFrontYear()); - preBtn.setEnable(!calendar.isFinalYear()); - } - }); - - this.navigation.on(BI.Navigation.EVENT_CHANGE, function () { - self.selectedYear = this.getValue(); - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - self.fireEvent(BI.YearPopup.EVENT_CHANGE, self.selectedYear); - }); + cardCreator: function (v) { + switch (v) { + case BI.DynamicYearCombo.Dynamic: + return { + type: "bi.dynamic_year_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self._setInnerValue(self.year, v); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + case BI.DynamicYearCombo.Static: + default: + return { + type: "bi.static_year_card", + behaviors: o.behaviors, + min: self.options.min, + max: self.options.max, + listeners: [{ + eventName: BI.StaticYearCard.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.DynamicYearPopup.EVENT_CHANGE); + } + }], + ref: function () { + self.year = this; + } + }; + } + }, + listeners: [{ + eventName: BI.Tab.EVENT_CHANGE, + action: function () { + var v = self.dateTab.getSelect(); + switch (v) { + case BI.DynamicYearCombo.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.year.setValue({year: date.getFullYear()}); + self._setInnerValue(); + break; + case BI.DynamicYearCombo.Dynamic: + default: + if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { + self.dynamicPane.setValue(self.storeValue.value); + }else{ + self.dynamicPane.setValue({ + year: 0 + }); + } + self._setInnerValue(); + break; + } + } + }] + }; + }, - if(BI.isKey(o.value)){ - this.setValue(o.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: + this.year.setValue(value); + this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); + this.textButton.setEnable(true); + break; } }, getValue: function () { - return this.selectedYear; - }, - - setValue: function (v) { - var o = this.options; - if (BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]) { - v = BI.getDate().getFullYear(); - this.selectedYear = ""; - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(""); - } else { - this.selectedYear = v; - this.navigation.setSelect(BI.YearCalendar.getPageByYear(v)); - this.navigation.setValue(v); - } + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; } + }); -BI.YearPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.year_popup", BI.YearPopup); \ No newline at end of file +BI.DynamicYearPopup.BUTTON_CLEAR_EVENT_CHANGE = "BUTTON_CLEAR_EVENT_CHANGE"; +BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE = "BUTTON_lABEL_EVENT_CHANGE"; +BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE = "BUTTON_OK_EVENT_CHANGE"; +BI.DynamicYearPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.dynamic_year_popup", BI.DynamicYearPopup); \ No newline at end of file diff --git a/src/widget/year/trigger.year.js b/src/widget/year/trigger.year.js index da6140337..6c49685e2 100644 --- a/src/widget/year/trigger.year.js +++ b/src/widget/year/trigger.year.js @@ -1,11 +1,4 @@ -/** - * 年份trigger - * - * Created by GUY on 2015/8/21. - * @class BI.YearTrigger - * @extends BI.Trigger - */ -BI.YearTrigger = BI.inherit(BI.Trigger, { +BI.DynamicYearTrigger = BI.inherit(BI.Trigger, { _const: { hgap: 4, vgap: 2, @@ -14,21 +7,20 @@ BI.YearTrigger = BI.inherit(BI.Trigger, { }, _defaultConfig: function () { - return BI.extend(BI.YearTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-year-trigger bi-border", + return BI.extend(BI.DynamicYearTrigger.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-year-trigger", min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 height: 24 }); }, _init: function () { - BI.YearTrigger.superclass._init.apply(this, arguments); + BI.DynamicYearTrigger.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) { - self.editor.setErrorText(!BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid); return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); }, quitChecker: function (v) { @@ -36,23 +28,33 @@ BI.YearTrigger = BI.inherit(BI.Trigger, { }, hgap: c.hgap, vgap: c.vgap, + watermark: BI.i18nText("BI-Basic_Unrestricted"), allowBlank: true, - errorText: c.errorText, - value: o.value + errorText: function (v) { + return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; + } }); this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.YearTrigger.EVENT_FOCUS); + self.fireEvent(BI.DynamicYearTrigger.EVENT_FOCUS); }); this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.YearTrigger.EVENT_STOP); + self.fireEvent(BI.DynamicYearTrigger.EVENT_STOP); }); this.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { var value = self.editor.getValue(); if (BI.isNotNull(value)) { self.editor.setValue(value); - self.editor.setTitle(value); } - self.fireEvent(BI.YearTrigger.EVENT_CONFIRM); + if (BI.isNotEmptyString(value)) { + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: value + } + }; + } + + self.fireEvent(BI.DynamicYearTrigger.EVENT_CONFIRM); }); this.editor.on(BI.SignEditor.EVENT_SPACE, function () { if (self.editor.isValid()) { @@ -60,47 +62,85 @@ BI.YearTrigger = BI.inherit(BI.Trigger, { } }); this.editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.YearTrigger.EVENT_START); + self.fireEvent(BI.DynamicYearTrigger.EVENT_START); }); this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.YearTrigger.EVENT_ERROR); + self.fireEvent(BI.DynamicYearTrigger.EVENT_ERROR); }); BI.createWidget({ element: this, type: "bi.htape", - items: [ - { - el: this.editor - }, { - el: { - type: "bi.text_button", - baseCls: "bi-trigger-year-text", - text: BI.i18nText("BI-Multi_Date_Year"), - width: o.height - }, + items: [{ + el: this.editor + }, { + el: { + type: "bi.text_button", + baseCls: "bi-trigger-year-text", + text: BI.i18nText("BI-Multi_Date_Year"), width: o.height - }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, + }, + width: o.height + }, { + el: { + type: "bi.trigger_icon_button", width: o.height - } - ] + }, + width: o.height + }] }); + this.setValue(o.value); + }, + + _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")); + } + return value; }, + + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr)); + }, + setValue: function (v) { - this.editor.setState(v); - this.editor.setValue(v); - this.editor.setTitle(v); + var type, value; + 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: + value = value || {}; + this.editor.setState(value.year); + this.editor.setValue(value.year); + this.editor.setTitle(value.year); + break; + } }, + + getValue: function () { + return this.storeValue; + }, + getKey: function () { return this.editor.getValue() | 0; } }); -BI.YearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.YearTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.YearTrigger.EVENT_START = "EVENT_START"; -BI.YearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearTrigger.EVENT_STOP = "EVENT_STOP"; -BI.shortcut("bi.year_trigger", BI.YearTrigger); \ No newline at end of file +BI.DynamicYearTrigger.EVENT_FOCUS = "EVENT_FOCUS"; +BI.DynamicYearTrigger.EVENT_ERROR = "EVENT_ERROR"; +BI.DynamicYearTrigger.EVENT_START = "EVENT_START"; +BI.DynamicYearTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearTrigger.EVENT_STOP = "EVENT_STOP"; +BI.shortcut("bi.dynamic_year_trigger", BI.DynamicYearTrigger); \ No newline at end of file diff --git a/src/widget/dynamic/yearmonth/card.dynamic.yearmonth.js b/src/widget/yearmonth/card.dynamic.yearmonth.js similarity index 100% rename from src/widget/dynamic/yearmonth/card.dynamic.yearmonth.js rename to src/widget/yearmonth/card.dynamic.yearmonth.js diff --git a/src/widget/dynamic/yearmonth/card.static.yearmonth.js b/src/widget/yearmonth/card.static.yearmonth.js similarity index 100% rename from src/widget/dynamic/yearmonth/card.static.yearmonth.js rename to src/widget/yearmonth/card.static.yearmonth.js diff --git a/src/widget/yearmonth/combo.yearmonth.js b/src/widget/yearmonth/combo.yearmonth.js index e69fa0736..b1dddfcef 100644 --- a/src/widget/yearmonth/combo.yearmonth.js +++ b/src/widget/yearmonth/combo.yearmonth.js @@ -1,73 +1,170 @@ -/** - * 年份 + 月份下拉框 - * - * @class BI.YearMonthCombo - * @extends BI.Widget - */ -BI.YearMonthCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearMonthCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-month-combo", - yearBehaviors: {}, - monthBehaviors: {}, - height: 25 - }); +BI.DynamicYearMonthCombo = BI.inherit(BI.Single, { + + props: { + baseCls: "bi-year-month-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, + _init: function () { - BI.YearMonthCombo.superclass._init.apply(this, arguments); + BI.DynamicYearMonthCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - - o.value = o.value || {}; - - this.year = BI.createWidget({ - type: "bi.year_combo", - behaviors: o.yearBehaviors, - value: o.value.year + this.storeValue = o.value; + this.trigger = BI.createWidget({ + type: "bi.dynamic_year_month_trigger", + min: o.min, + max: o.max, + value: o.value || "" }); - - this.month = BI.createWidget({ - type: "bi.month_combo", - behaviors: o.monthBehaviors, - value: o.value.month + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - - this.year.on(BI.YearCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_CONFIRM); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_STOP, function () { + self.combo.showView(); + }); + 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.year.on(BI.YearCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_CONFIRM, function () { + if (self.combo.isViewVisible()) { + return; + } + 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.month.on(BI.MonthCombo.EVENT_CONFIRM, function () { - self.getValue(); - self.fireEvent(BI.YearMonthCombo.EVENT_CONFIRM); + this.combo = BI.createWidget({ + type: "bi.combo", + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + stopPropagation: false, + el: { + type: "bi.dynamic_year_month_popup", + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicYearMonthPopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearMonthPopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearMonthPopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({year: date.getFullYear()}); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearMonthPopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }], + behaviors: o.behaviors, + min: o.min, + max: o.max + }, + value: o.value || "" + } }); - this.month.on(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW); }); BI.createWidget({ - type: "bi.center", + type: "bi.htape", element: this, - hgap: 5, - items: [this.year, this.month] + ref: function () { + self.comboWrapper = this; + }, + 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 + }, this.combo] }); + this._checkDynamicValue(o.value); + }, + + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicYearMonthCombo.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; + } + }, + hideView: function () { + this.combo.hideView(); }, setValue: function (v) { - v = v || {}; - this.month.setValue(v.month); - this.year.setValue(v.year); + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); }, getValue: function () { - return { - year: this.year.getValue(), - month: this.month.getValue() - }; + return this.storeValue; + }, + + getKey: function () { + return this.trigger.getKey(); } + }); -BI.YearMonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_month_combo", BI.YearMonthCombo); \ No newline at end of file +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); + +BI.extend(BI.DynamicYearMonthCombo, { + Static: 1, + Dynamic: 2 +}); \ No newline at end of file diff --git a/src/widget/dynamic/yearmonth/popup.yearmonth.js b/src/widget/yearmonth/popup.yearmonth.js similarity index 98% rename from src/widget/dynamic/yearmonth/popup.yearmonth.js rename to src/widget/yearmonth/popup.yearmonth.js index 893ea58a1..d9280737a 100644 --- a/src/widget/dynamic/yearmonth/popup.yearmonth.js +++ b/src/widget/yearmonth/popup.yearmonth.js @@ -131,7 +131,7 @@ BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { min: self.options.min, max: self.options.max, listeners: [{ - eventName: BI.YearCard.EVENT_CHANGE, + eventName: BI.StaticYearMonthCard.EVENT_CHANGE, action: function () { self.fireEvent(BI.DynamicYearMonthPopup.EVENT_CHANGE); } diff --git a/src/widget/dynamic/yearmonth/trigger.yearmonth.js b/src/widget/yearmonth/trigger.yearmonth.js similarity index 100% rename from src/widget/dynamic/yearmonth/trigger.yearmonth.js rename to src/widget/yearmonth/trigger.yearmonth.js diff --git a/src/widget/dynamic/yearquarter/card.dynamic.yearquarter.js b/src/widget/yearquarter/card.dynamic.yearquarter.js similarity index 100% rename from src/widget/dynamic/yearquarter/card.dynamic.yearquarter.js rename to src/widget/yearquarter/card.dynamic.yearquarter.js diff --git a/src/widget/dynamic/yearquarter/card.static.yearquarter.js b/src/widget/yearquarter/card.static.yearquarter.js similarity index 100% rename from src/widget/dynamic/yearquarter/card.static.yearquarter.js rename to src/widget/yearquarter/card.static.yearquarter.js diff --git a/src/widget/yearquarter/combo.yearquarter.js b/src/widget/yearquarter/combo.yearquarter.js index fae8db001..ee489b8cc 100644 --- a/src/widget/yearquarter/combo.yearquarter.js +++ b/src/widget/yearquarter/combo.yearquarter.js @@ -1,72 +1,152 @@ -/** - * 年份 + 月份下拉框 - * - * @class BI.YearQuarterCombo - * @extends BI.Widget - */ -BI.YearQuarterCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.YearQuarterCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-year-quarter-combo", - yearBehaviors: {}, - quarterBehaviors: {}, - height: 25 - }); +BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-year-quarter-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, + _init: function () { - BI.YearQuarterCombo.superclass._init.apply(this, arguments); + BI.DynamicYearQuarterCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - - o.value = o.value || {}; - - this.year = BI.createWidget({ - type: "bi.year_combo", - behaviors: o.yearBehaviors, - value: o.value.year + this.storeValue = o.value; + this.trigger = BI.createWidget({ + type: "bi.dynamic_year_quarter_trigger", + min: o.min, + max: o.max, + value: o.value || "" }); - - this.quarter = BI.createWidget({ - type: "bi.quarter_combo", - behaviors: o.quarterBehaviors, - value: o.value.quarter + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_START, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - - this.year.on(BI.YearCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_CONFIRM); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () { + self.combo.showView(); + }); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_ERROR, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - this.year.on(BI.YearCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_BEFORE_POPUPVIEW); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM, function () { + if (self.combo.isViewVisible()) { + return; + } + self.storeValue = self.trigger.getValue(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); }); - this.quarter.on(BI.QuarterCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_CONFIRM); + this.combo = BI.createWidget({ + type: "bi.combo", + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + stopPropagation: false, + el: { + type: "bi.dynamic_year_quarter_popup", + ref: function () { + self.popup = this; + }, + listeners: [{ + eventName: BI.DynamicYearQuarterPopup.EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearQuarterPopup.BUTTON_CLEAR_EVENT_CHANGE, + action: function () { + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearQuarterPopup.BUTTON_lABEL_EVENT_CHANGE, + action: function () { + var date = BI.getDate(); + self.setValue({year: date.getFullYear()}); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }, { + eventName: BI.DynamicYearQuarterPopup.BUTTON_OK_EVENT_CHANGE, + action: function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); + } + }], + behaviors: o.behaviors, + min: o.min, + max: o.max + }, + value: o.value || "" + } }); - this.quarter.on(BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearQuarterCombo.EVENT_BEFORE_POPUPVIEW); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW); }); BI.createWidget({ - type: "bi.center", + type: "bi.htape", element: this, - hgap: 5, - items: [this.year, this.quarter] + ref: function () { + self.comboWrapper = this; + }, + 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 + }, this.combo] }); + this._checkDynamicValue(o.value); + }, + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } + switch (type) { + case BI.DynamicYearQuarterCombo.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) { - v = v || {}; - this.quarter.setValue(v.quarter); - this.year.setValue(v.year); + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); }, getValue: function () { - return { - year: this.year.getValue(), - quarter: this.quarter.getValue() - }; + return this.storeValue; } + }); -BI.YearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_quarter_combo", BI.YearQuarterCombo); \ No newline at end of file +BI.DynamicYearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.dynamic_year_quarter_combo", BI.DynamicYearQuarterCombo); + +BI.extend(BI.DynamicYearQuarterCombo, { + Static: 1, + Dynamic: 2 +}); \ No newline at end of file diff --git a/src/widget/dynamic/yearquarter/popup.yearquarter.js b/src/widget/yearquarter/popup.yearquarter.js similarity index 98% rename from src/widget/dynamic/yearquarter/popup.yearquarter.js rename to src/widget/yearquarter/popup.yearquarter.js index df767b5f9..dca8e246e 100644 --- a/src/widget/dynamic/yearquarter/popup.yearquarter.js +++ b/src/widget/yearquarter/popup.yearquarter.js @@ -124,7 +124,7 @@ BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, { min: self.options.min, max: self.options.max, listeners: [{ - eventName: BI.YearCard.EVENT_CHANGE, + eventName: BI.DynamicYearCard.EVENT_CHANGE, action: function () { self.fireEvent(BI.DynamicYearQuarterPopup.EVENT_CHANGE); } diff --git a/src/widget/dynamic/yearquarter/trigger.yearquarter.js b/src/widget/yearquarter/trigger.yearquarter.js similarity index 100% rename from src/widget/dynamic/yearquarter/trigger.yearquarter.js rename to src/widget/yearquarter/trigger.yearquarter.js