diff --git a/demo/js/case/editor/demo.clear_editor.js b/demo/js/case/editor/demo.clear_editor.js index 0e1e9519b..6ad9b4283 100644 --- a/demo/js/case/editor/demo.clear_editor.js +++ b/demo/js/case/editor/demo.clear_editor.js @@ -12,7 +12,8 @@ Demo.ClearEditor = BI.inherit(BI.Widget, { type: "bi.clear_editor", cls: "bi-border", width: 300, - watermark: "这个是带清除按钮的" + watermark: "这个是带清除按钮的", + value: 123 }], vgap: 20 }; diff --git a/demo/js/widget/date/demo.datepane.js b/demo/js/widget/date/demo.datepane.js index 5f687de49..025026a1d 100644 --- a/demo/js/widget/date/demo.datepane.js +++ b/demo/js/widget/date/demo.datepane.js @@ -19,7 +19,7 @@ Demo.DatePane = BI.inherit(BI.Widget, { type: 1, value: { year: 2017, - month: 11, + month: 12, day: 11 } }, @@ -39,7 +39,7 @@ Demo.DatePane = BI.inherit(BI.Widget, { type: 1, value: { year: 2017, - month: 11, + month: 12, day: 11, hour: 12, minute: 12, @@ -62,7 +62,7 @@ Demo.DatePane = BI.inherit(BI.Widget, { handler: function () { self.datepane.setValue({ year: 2017, - month: 11, + month: 12, day: 31 }); } diff --git a/demo/js/widget/date/demo.multidate_combo.js b/demo/js/widget/date/demo.multidate_combo.js index 0177e32f8..7573a4f6b 100644 --- a/demo/js/widget/date/demo.multidate_combo.js +++ b/demo/js/widget/date/demo.multidate_combo.js @@ -25,7 +25,7 @@ Demo.Date = BI.inherit(BI.Widget, { type: 1, value: { year: 2018, - month: 1, + month: 2, day: 23 } } @@ -46,7 +46,7 @@ Demo.Date = BI.inherit(BI.Widget, { type: 1, value: { year: 2018, - month: 1, + month: 2, day: 23 } } diff --git a/demo/js/widget/yearmonth/demo.year_month_combo.js b/demo/js/widget/yearmonth/demo.year_month_combo.js index b4044a590..1eafab451 100644 --- a/demo/js/widget/yearmonth/demo.year_month_combo.js +++ b/demo/js/widget/yearmonth/demo.year_month_combo.js @@ -20,7 +20,7 @@ Demo.YearMonthCombo = BI.inherit(BI.Widget, { type: 1, value: { year: 2018, - month: 0 + month: 1 } } }, { @@ -32,12 +32,12 @@ Demo.YearMonthCombo = BI.inherit(BI.Widget, { width: 300 }, { type: "bi.button", - text: "setVlaue '2017-12'", + text: "setValue '2017-12'", width: 300, handler: function () { self.widget.setValue({ year: 2017, - month: 11 + month: 12 }); } }], diff --git a/demo/js/widget/yearmonthinterval/demo.year_month_interval.js b/demo/js/widget/yearmonthinterval/demo.year_month_interval.js index a87de534c..b0958b50d 100644 --- a/demo/js/widget/yearmonthinterval/demo.year_month_interval.js +++ b/demo/js/widget/yearmonthinterval/demo.year_month_interval.js @@ -24,7 +24,7 @@ Demo.YearMonthInterval = BI.inherit(BI.Widget, { type: 1, value: { year: 2018, - month: 0 + month: 1 } } }, diff --git a/dist/bundle.js b/dist/bundle.js index e133390ba..4252e40de 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -73547,7 +73547,7 @@ BI.Calendar = BI.inherit(BI.Widget, { min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 year: 2015, - month: 7, // 7表示八月 + month: 8, day: 25 }); }, @@ -73565,18 +73565,23 @@ BI.Calendar = BI.inherit(BI.Widget, { var MD = Date._MD.slice(0); MD[1] = BI.isLeapYear(log.ymd[0]) ? 29 : 28; + // 日期所在月第一天 De.setFullYear(log.ymd[0], log.ymd[1], 1); + // 是周几 log.FDay = De.getDay(); + // 当前月页第一天是几号 log.PDay = MD[M === 0 ? 11 : M - 1] - log.FDay + 1; log.NDay = 1; var items = []; BI.each(BI.range(42), function (i) { var td = {}, YY = log.ymd[0], MM = log.ymd[1] + 1, DD; + // 上个月的日期 if (i < log.FDay) { td.lastMonth = true; DD = i + log.PDay; + // 上一年 MM === 1 && (YY -= 1); MM = MM === 1 ? 12 : MM - 1; } else if (i >= log.FDay && i < log.FDay + MD[log.ymd[1]]) { @@ -73619,7 +73624,7 @@ BI.Calendar = BI.inherit(BI.Widget, { vgap: 10 }] }); - var days = this._dateCreator(o.year, o.month, o.day); + var days = this._dateCreator(o.year, o.month - 1, o.day); items = []; items.push(days.slice(0, 7)); items.push(days.slice(7, 14)); @@ -78523,7 +78528,8 @@ BI.ClearEditor = BI.inherit(BI.Widget, { allowBlank: true, errorText: o.errorText, validationChecker: o.validationChecker, - quitChecker: o.quitChecker + quitChecker: o.quitChecker, + value: o.value }); this.clear = BI.createWidget({ type: "bi.icon_button", @@ -78607,7 +78613,11 @@ BI.ClearEditor = BI.inherit(BI.Widget, { self.fireEvent(BI.ClearEditor.EVENT_STOP); }); - this.clear.invisible(); + if (BI.isKey(o.value)) { + this.clear.visible(); + } else { + this.clear.invisible(); + } }, _checkClear: function () { @@ -86938,7 +86948,7 @@ BI.MonthDateCombo = BI.inherit(BI.Trigger, { }, setValue: function (v) { - this.trigger.setValue(v + 1); + this.trigger.setValue(v); this.popup.setValue(v); }, @@ -87043,7 +87053,7 @@ BI.DatePicker = BI.inherit(BI.Widget, { if (self._month === 0) { self.setValue({ year: self.year.getValue() - 1, - month: 11 + month: 12 }); } else { self.setValue({ @@ -87135,14 +87145,14 @@ BI.DatePicker = BI.inherit(BI.Widget, { _checkLeftValid: function () { var o = this.options; - var valid = !(this._month === 0 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 1 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); this.left.setEnable(valid); return valid; }, _checkRightValid: function () { var o = this.options; - var valid = !(this._month === 11 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 12 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); this.right.setEnable(valid); return valid; }, @@ -87373,6 +87383,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. @@ -87819,9 +87938,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", // 最小日期 @@ -87830,7 +87949,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(); @@ -87929,7 +88048,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, { @@ -88396,7 +88654,275 @@ BI.DateTimeTrigger = BI.inherit(BI.Trigger, { } }); -BI.shortcut("bi.date_time_trigger", BI.DateTimeTrigger);/** +BI.shortcut("bi.date_time_trigger", BI.DateTimeTrigger);BI.StaticDateTimePaneCard = BI.inherit(BI.Widget, { + _defaultConfig: function () { + var conf = BI.StaticDateTimePaneCard.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: "bi-date-time-pane", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + selectedTime: null + }); + }, + _init: function () { + BI.StaticDateTimePaneCard.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.today = BI.getDate(); + this._year = this.today.getFullYear(); + this._month = this.today.getMonth(); + + this.selectedTime = o.selectedTime || { + year: this._year, + month: this._month + }; + + this.datePicker = BI.createWidget({ + type: "bi.date_picker", + min: o.min, + max: o.max + }); + this.datePicker.on(BI.DatePicker.EVENT_CHANGE, function () { + self.selectedTime = BI.extend(self.datePicker.getValue(), self.timeSelect.getValue()); + self.calendar.setSelect(BI.Calendar.getPageByDateJSON(self.selectedTime)); + }); + + this.calendar = BI.createWidget({ + direction: "top", + logic: { + dynamic: false + }, + type: "bi.navigation", + tab: this.datePicker, + cardCreator: BI.bind(this._createNav, this) + }); + this.calendar.on(BI.Navigation.EVENT_CHANGE, function () { + self.selectedTime = BI.extend(self.calendar.getValue(), self.timeSelect.getValue()); + self.calendar.empty(); + self.setValue(self.selectedTime); + self.fireEvent(BI.DateCalendarPopup.EVENT_CHANGE); + }); + + BI.createWidget({ + type: "bi.vtape", + element: this, + items: [this.calendar, { + el: { + type: "bi.dynamic_date_time_select", + ref: function () { + self.timeSelect = this; + } + }, + height: 40 + }] + }); + this.setValue(o.selectedTime); + + }, + + _createNav: function (v) { + var date = BI.Calendar.getDateJSONByPage(v); + var calendar = BI.createWidget({ + type: "bi.calendar", + logic: { + dynamic: false + }, + min: this.options.min, + max: this.options.max, + year: date.year, + month: date.month, + day: this.selectedTime.day + }); + return calendar; + }, + + _getNewCurrentDate: function () { + var today = BI.getDate(); + return { + year: today.getFullYear(), + month: today.getMonth() + }; + }, + + _setCalenderValue: function (date) { + this.calendar.setSelect(BI.Calendar.getPageByDateJSON(date)); + this.calendar.setValue(date); + this.selectedTime = BI.extend(date, this.timeSelect.getValue()); + }, + + _setDatePicker: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.year) || BI.isNull(timeOb.month)) { + this.datePicker.setValue(this._getNewCurrentDate()); + } else { + this.datePicker.setValue(timeOb); + } + }, + + _setCalendar: function (timeOb) { + if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { + this.calendar.empty(); + this._setCalenderValue(this._getNewCurrentDate()); + } else { + this._setCalenderValue(timeOb); + } + }, + + setValue: function (timeOb) { + timeOb = timeOb || {}; + this._setDatePicker(timeOb); + this._setCalendar(timeOb); + this.timeSelect.setValue({ + hour: timeOb.hour, + minute: timeOb.minute, + second: timeOb.second + }); + }, + + getValue: function () { + return this.selectedTime; + } + +}); +BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.DynamicDateTimePane = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-dynamic-date-pane" + }, + + render: function () { + var self = this; + return { + type: "bi.vtape", + items: [{ + el: { + type: "bi.linear_segment", + cls: "bi-border-bottom", + height: 30, + items: BI.createItems([{ + text: BI.i18nText("BI-Multi_Date_YMD"), + value: BI.DynamicDateTimePane.Static + }, { + text: BI.i18nText("BI-Basic_Dynamic_Title"), + value: BI.DynamicDateTimePane.Dynamic + }], { + textAlign: "center" + }), + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function () { + var value = this.getValue()[0]; + self.dateTab.setSelect(value); + switch (value) { + case BI.DynamicDateTimePane.Static: + var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + break; + case BI.DynamicDateTimePane.Dynamic: + self.dynamicPane.setValue({ + year: 0 + }); + break; + default: + break; + } + } + }], + ref: function () { + self.switch = this; + } + }, + height: 30 + }, { + type: "bi.tab", + ref: function () { + self.dateTab = this; + }, + showIndex: BI.DynamicDateTimePane.Static, + cardCreator: function (v) { + switch (v) { + case BI.DynamicDateTimePane.Static: + return { + type: "bi.static_date_time_pane_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.ymd = this; + } + }; + case BI.DynamicDateTimePane.Dynamic: + default: + return { + type: "bi.dynamic_date_card", + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.dynamicPane = this; + } + }; + } + } + }] + }; + }, + + mounted: function () { + this.setValue(this.options.value); + }, + + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + }, + + setValue: function (v) { + v = v || {}; + var type = v.type || BI.DynamicDateTimePane.Static; + var value = v.value || v; + this.switch.setValue(type); + this.dateTab.setSelect(type); + switch (type) { + case BI.DynamicDateTimePane.Dynamic: + this.dynamicPane.setValue(value); + break; + case BI.DynamicDateTimePane.Static: + default: + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth() + }); + } else { + this.ymd.setValue(value); + } + break; + } + }, + + getValue: function () { + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; + } +}); +BI.shortcut("bi.dynamic_date_time_pane", BI.DynamicDateTimePane); + +BI.extend(BI.DynamicDateTimePane, { + Static: 1, + Dynamic: 2 +});/** * Created by roy on 15/8/14. */ BI.DownListCombo = BI.inherit(BI.Widget, { @@ -89007,482 +89533,905 @@ 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; +!(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; + }, - this.today = BI.getDate(); - this._year = this.today.getFullYear(); - this._month = this.today.getMonth(); + 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, { - this.selectedTime = o.selectedTime || { - year: this._year, - month: this._month + 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 + }] + }] }; + }, - 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)); + _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"); + } + }] + }; }); - 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); + 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; }, - _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; + _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 + }]; + } }, - _getNewCurrentDate: function () { - var today = BI.getDate(); + _createValue: function (type, v) { return { - year: today.getFullYear(), - month: today.getMonth() + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 }; }, - _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); + 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)); } - }, - - _setCalendar: function (timeOb) { - if (BI.isNull(timeOb) || BI.isNull(timeOb.day)) { - this.calendar.empty(); - this._setCalenderValue(this._getNewCurrentDate()); - } else { - this._setCalenderValue(timeOb); + if(BI.isNotNull(v.quarter)) { + values.push(BI.DynamicDateCard.TYPE.QUARTER); + valuesItems.push(this._createValue(BI.DynamicDateCard.TYPE.QUARTER, v.quarter)); } - }, - - setValue: function (timeOb) { - this._setDatePicker(timeOb); - this._setCalendar(timeOb); + 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 this.selectedTime; + 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.static_date_pane_card", BI.StaticDatePaneCard);BI.DynamicDatePane = BI.inherit(BI.Widget, { +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-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.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; - } - } - }], + 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.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", + 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: "EVENT_CHANGE", + eventName: BI.DynamicDatePopup.BUTTON_CLEAR_EVENT_CHANGE, action: function () { - self.fireEvent("EVENT_CHANGE"); + self.setValue(); + self.combo.hideView(); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); } - }], - ref: function () { - self.dynamicPane = this; + }, { + 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.setValue(this.options.value); - }, - - _checkValueValid: function (value) { - return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + this._checkDynamicValue(this.options.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); + _checkDynamicValue: function (v) { + var type = null; + if (BI.isNotNull(v)) { + type = v.type; + } switch (type) { case BI.DynamicDateCombo.Dynamic: - this.dynamicPane.setValue(value); + this.changeIcon.setVisible(true); + this.comboWrapper.attr("items")[0].width = 24; + this.comboWrapper.resize(); 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); - } + 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_pane", BI.DynamicDatePane); - -BI.extend(BI.DynamicDatePane, { - Static: 1, - Dynamic: 2 -});BI.StaticDateTimePaneCard = BI.inherit(BI.Widget, { - _defaultConfig: function () { - var conf = BI.StaticDateTimePaneCard.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - baseCls: "bi-date-time-pane", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - selectedTime: null - }); - }, - _init: function () { - BI.StaticDateTimePaneCard.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.today = BI.getDate(); - this._year = this.today.getFullYear(); - this._month = this.today.getMonth(); +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"; - this.selectedTime = o.selectedTime || { - year: this._year, - month: this._month - }; +BI.shortcut("bi.dynamic_date_combo", BI.DynamicDateCombo); - 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)); - }); +BI.extend(BI.DynamicDateCombo, { + Static: 1, + Dynamic: 2 +});BI.DynamicDateParamItem = BI.inherit(BI.Widget, { - 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); - }); + props: { + baseCls: "bi-dynamic-date-param-item", + dateType: BI.DynamicDateCard.TYPE.YEAR, + value: 0, + offset: 0, + height: 24 + }, - BI.createWidget({ - type: "bi.vtape", - element: this, - items: [this.calendar, { + render: function () { + var self = this, o = this.options; + return { + type: "bi.htape", + items: [{ el: { - type: "bi.dynamic_date_time_select", + type: "bi.sign_editor", + cls: "bi-border", + height: 22, + validationChecker: function (v) { + return BI.isNaturalNumber(v); + }, + value: o.value, ref: function () { - self.timeSelect = this; - } + 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); + } + }] }, - height: 40 + 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); + } + }] }] - }); - 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); + _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 (timeOb) { - timeOb = timeOb || {}; - this._setDatePicker(timeOb); - this._setCalendar(timeOb); - this.timeSelect.setValue({ - hour: timeOb.hour, - minute: timeOb.minute, - second: timeOb.second - }); + 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 this.selectedTime; + return { + dateType: this.options.dateType, + value: this.editor.getValue(), + offset: this.offsetCombo.getValue()[0] + }; } }); -BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.DynamicDateTimePane = BI.inherit(BI.Widget, { - +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-pane" + baseCls: "bi-dynamic-date-popup", + width: 248, + height: 344 }, - - render: function () { - var self = this; - return { + + _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.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.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); } - } - }], - ref: function () { - self.switch = this; - } - }, - height: 30 - }, { - type: "bi.tab", - ref: function () { - self.dateTab = this; + }] + }, { + 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); + } + }] + }]] }, - 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; + 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); } - }; - 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; + }], + 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; } } }] }; }, - mounted: function () { - this.setValue(this.options.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); + } }, _checkValueValid: function (value) { @@ -89490,26 +90439,33 @@ BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.Dynam }, setValue: function (v) { + this.storeValue = v; + var self = this; + var type, value; v = v || {}; - var type = v.type || BI.DynamicDateTimePane.Static; - var value = v.value || v; - this.switch.setValue(type); + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || v; this.dateTab.setSelect(type); switch (type) { - case BI.DynamicDateTimePane.Dynamic: + case BI.DynamicDateCombo.Dynamic: this.dynamicPane.setValue(value); + self._setInnerValue(); break; - case BI.DynamicDateTimePane.Static: + case BI.DynamicDateCombo.Static: default: if (this._checkValueValid(value)) { var date = BI.getDate(); this.ymd.setValue({ year: date.getFullYear(), - month: date.getMonth() + month: date.getMonth() + 1, + 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; } }, @@ -89521,7477 +90477,3206 @@ BI.shortcut("bi.static_date_time_pane_card", BI.StaticDateTimePaneCard);BI.Dynam }; } }); -BI.shortcut("bi.dynamic_date_time_pane", BI.DynamicDateTimePane); - -BI.extend(BI.DynamicDateTimePane, { - Static: 1, - Dynamic: 2 -});/** - * 年份展示面板 - * - * Created by GUY on 2015/9/2. - * @class BI.YearCard - * @extends BI.Trigger - */ -BI.DynamicYearCard = BI.inherit(BI.Widget, { - - props: { - baseCls: "bi-year-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.item = 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}; - this.item.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); - }, - - 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" // 最大日期 - }); - }, - - _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.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), - - 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); - }); - - if(BI.isKey(o.value)){ - this.setValue(o.value); - } - }, - - _checkLeftValid: function () { - var o = this.options; - var valid = true; - this.backBtn.setEnable(valid); - return valid; - }, - - _checkRightValid: function () { - var o = this.options; - var valid = true; - this.preBtn.setEnable(valid); - return valid; - }, - - getValue: function () { - return { - year: this.selectedYear - }; - }, - - 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, { - - 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 -});/** - * 年份展示面板 - * - * 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);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); - }); +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 + }, - this.editor.on(BI.Editor.EVENT_VALID, function () { - self.fireEvent(BI.TextEditor.EVENT_VALID); + _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.Editor.EVENT_CONFIRM, function () { - self.fireEvent(BI.TextEditor.EVENT_CONFIRM); + this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_KEY_DOWN); }); - this.editor.on(BI.Editor.EVENT_REMOVE, function (v) { - self.fireEvent(BI.TextEditor.EVENT_REMOVE); + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_FOCUS); }); - this.editor.on(BI.Editor.EVENT_START, function () { - self.fireEvent(BI.TextEditor.EVENT_START); + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_STOP); }); - this.editor.on(BI.Editor.EVENT_PAUSE, function () { - self.fireEvent(BI.TextEditor.EVENT_PAUSE); + this.editor.on(BI.SignEditor.EVENT_VALID, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_VALID); }); - this.editor.on(BI.Editor.EVENT_STOP, function () { - self.fireEvent(BI.TextEditor.EVENT_STOP); + this.editor.on(BI.SignEditor.EVENT_ERROR, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_ERROR); }); - this.editor.on(BI.Editor.EVENT_ERROR, function () { - self.fireEvent(BI.TextEditor.EVENT_ERROR, arguments); + 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], + day: date[2] | 0 + } + }; + } + self.fireEvent(BI.DynamicDateTrigger.EVENT_CONFIRM); }); - this.editor.on(BI.Editor.EVENT_ENTER, function () { - self.fireEvent(BI.TextEditor.EVENT_ENTER); + this.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); + } }); - this.editor.on(BI.Editor.EVENT_RESTRICT, function () { - self.fireEvent(BI.TextEditor.EVENT_RESTRICT); + this.editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_START); }); - this.editor.on(BI.Editor.EVENT_EMPTY, function () { - self.fireEvent(BI.TextEditor.EVENT_EMPTY); + this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.DynamicDateTrigger.EVENT_CHANGE); }); BI.createWidget({ - type: "bi.vertical", - scrolly: false, + type: "bi.htape", element: this, - items: [this.editor] + items: [{ + el: this.editor + }, { + el: BI.createWidget(), + width: 30 + }] }); + this.setValue(o.value); }, - - focus: function () { - this.editor.focus(); + _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; + } + } }, - blur: function () { - this.editor.blur(); + _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; }, - setErrorText: function (text) { - this.editor.setErrorText(text); + _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; }, - getErrorText: function () { - return this.editor.getErrorText(); + _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)); }, - isValid: function () { - return this.editor.isValid(); + _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) { - this.editor.setValue(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) + "-" + value.day; + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(dateStr); + } + break; + } }, - getValue: function () { + getKey: function () { return this.editor.getValue(); + }, + getValue: function () { + return this.storeValue; } + }); -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.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" + }, -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 - }); + props: { + baseCls: "bi-dynamic-date-combo bi-border", + height: 24 }, - _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: [] - }); + 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; + } + }; }, - _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); - }); + mounted: function () { + this._checkDynamicValue(this.options.value); }, - _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; + _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.button_group.setValue(v); + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); }, - getValue: function () { - return this.button_group.getValue(); - }, - - getNotSelectedValue: function () { - return this.button_group.getNotSelectedValue(); + return this.storeValue; }, - - getAllLeaves: function () { - return this.button_group.getAllLeaves(); + getKey: function () { + return this.trigger.getKey(); }, + hidePopupView: function () { + this.combo.hideView(); + } +}); - getAllButtons: function () { - return this.button_group.getAllButtons(); - }, +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"; - getSelectedButtons: function () { - return this.button_group.getSelectedButtons(); - }, +BI.shortcut("bi.dynamic_date_time_combo", BI.DynamicDateTimeCombo); - getNotSelectedButtons: function () { - return this.button_group.getNotSelectedButtons(); +BI.extend(BI.DynamicDateTimeCombo, { + Static: 1, + Dynamic: 2 +});BI.DynamicDateTimePopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 }, - 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: [] - }); + props: { + baseCls: "bi-dynamic-date-time-popup", + width: 248, + height: 385 }, _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.DynamicDateTimePopup.superclass._init.apply(this, arguments); + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicDateCombo.Static}; BI.createWidget({ - type: "bi.absolute", element: this, + type: "bi.vtape", items: [{ - el: this.list, - left: 0, - right: 0, - top: 0, - bottom: 10 + el: this._getTabJson() }, { - el: this.nav, - left: 40, - right: 100, - top: 0 + 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); }, - setValue: function (value) { - this.selectedValues = value || []; - this.list.setValue(this.selectedValues); - }, + _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 () { - getValue: function () { - var obj = this.list.getValue(); - var res = obj.type === BI.Selection.All ? obj.assist : obj.value; - res.pushDistinctArray(this.selectedValues); - return res; + } + }] + }, + 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; + } + } + }] + }; }, - _populate: function (items) { - this.list.populate(items); + _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); + } }, - getSelectedValue: function () { - return this.nav.getValue()[0]; + _checkValueValid: function (value) { + return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); }, - getSelectedId: function () { - return this.nav.getId()[0]; + 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() + 1, + 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; + } }, - populate: function (node) { - var clone = BI.deepClone(node); - this._populate(node.children); - this.nav.populate(clone); + 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.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, { +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.FileManagerFileItem.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-file-item bi-list-item bi-border-bottom", - height: 30 - }); + props: { + baseCls: "bi-date-time-select bi-border-top" }, - _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, + render: function () { + var self = this; + return { + type: "bi.center_adapt", items: [{ - el: this.checked, - width: 36 - }, { - el: { - type: "bi.icon_button", - cls: "create-by-me-file-font" - }, - width: 20 - }, { - el: { + 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", - textAlign: "left", - height: o.height, - text: o.text, - value: o.value - } + 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; }, - getAllLeaves: function () { - return [this.options.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; }, - isSelected: function () { - return this.checked.isSelected(); + _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; }, - setSelected: function (v) { - this.checked.setSelected(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.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], + 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); - } - }); - return res; + _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; }, - 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); - } - } - }); - return res; + _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)); }, - getValue: function () { - var res = []; - if (this.checked.isSelected()) { - this.tree.traverse(function (node) { - if (node.isLeaf()) { - res.push(node.get("data").value); - } - }); - return res; + _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 (this.checked.isHalfSelected()) { - return this.selectValue; + 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); } - 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: [] - }); - }, + 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; - _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) + 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"); } - }); - this.list.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + } }, setValue: function (v) { - this.list.setValue({ - value: 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) + "-" + value.day + " " + + (value.hour || "00") + ":" + (value.minute || "00") + ":" + (value.second || "00"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(dateStr); + } + break; + } }, - getValue: function () { - return this.list.getValue(); + getKey: function () { + return this.editor.getValue(); }, - - populate: function (items) { - this.list.populate(items); - this.list.setToolBarVisible(true); + getValue: function () { + return this.storeValue; } + }); -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" - }, +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.FileManagerNavButton.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-file-manager-nav-button", - selected: false, - height: 40 + 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.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, + 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, - lgap: 20, - rgap: 10 + watermark: o.watermark, + allowBlank: true, + errorText: o.errorText, + validationChecker: o.validationChecker, + quitChecker: o.quitChecker }); - this.button.on(BI.Controller.EVENT_CHANGE, function () { - arguments[2] = 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); + }); + 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); }); - 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.SearchEditor.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.SearchEditor.EVENT_BLUR); }); - 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_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); }); - 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%" - }; }, - _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%" - }; + focus: function () { + this.editor.focus(); }, - _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%" - }] - }); + blur: function () { + this.editor.blur(); }, - _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; + setErrorText: function (text) { + this.editor.setErrorText(text); }, - _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}); - } - } + getErrorText: function () { + return this.editor.getErrorText(); }, - _setLabelOnePosition: function (percent) { - this.labelOne.element.css({left: percent + "%"}); - this._checkOverlap(); + isValid: function () { + return this.editor.isValid(); }, - _setLabelTwoPosition: function (percent) { - this.labelTwo.element.css({left: percent + "%"}); - this._checkOverlap(); + setValue: function (v) { + this.editor.setValue(v); }, - _setSliderOnePosition: function (percent) { - this.sliderOne.element.css({left: percent + "%"}); - }, + 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"; - _setSliderTwoPosition: function (percent) { - this.sliderTwo.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"; + +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, { + + _defaultConfig: function () { + return BI.extend(BI.FileManagerButtonGroup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-button_group", + items: [] + }); }, - _setBlueTrackWidth: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); + _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); + }); }, - _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); - } + _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; }, - _setAllPosition: function (one, two) { - this._setSliderOnePosition(one); - this._setLabelOnePosition(one); - this._setSliderTwoPosition(two); - this._setLabelTwoPosition(two); - this._setBlueTrack(); + setValue: function (v) { + this.button_group.setValue(v); }, - _setVisible: function (visible) { - this.sliderOne.setVisible(visible); - this.sliderTwo.setVisible(visible); - this.labelOne.setVisible(visible); - this.labelTwo.setVisible(visible); + getValue: function () { + return this.button_group.getValue(); }, - _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); + getNotSelectedValue: function () { + return this.button_group.getNotSelectedValue(); }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + getAllLeaves: function () { + return this.button_group.getAllLeaves(); }, - // 其中取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)); + getAllButtons: function () { + return this.button_group.getAllButtons(); + }, + getSelectedButtons: function () { + return this.button_group.getSelectedButtons(); }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); + getNotSelectedButtons: function () { + return this.button_group.getNotSelectedButtons(); }, - _setDraggableEnable: function (enable) { - this.sliderOne.setEnable(enable); - this.sliderTwo.setEnable(enable); + 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: [] + }); }, - _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; + _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 + }] + }); }, - _assertValue: function (value) { - if(value <= this.min) { - return this.min; - } - if(value >= this.max) { - return this.max; - } - return value; + 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; }, - 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); - } + _populate: function (items) { + this.list.populate(items); }, - 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; - } - } + getSelectedValue: function () { + return this.nav.getValue()[0]; }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.valueOne = ""; - this.valueTwo = ""; - this.min = NaN; - this.max = NaN; - this._setBlueTrackWidth(0); + getSelectedId: function () { + return this.nav.getId()[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); - } - } + populate: function (node) { + var clone = BI.deepClone(node); + this._populate(node.children); + this.nav.populate(clone); } }); -BI.IntervalSlider.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.interval_slider", BI.IntervalSlider);/** - * Created by zcf on 2017/3/1. - * 万恶的IEEE-754 - * 使用字符串精确计算含小数加法、减法、乘法和10的指数倍除法,支持负数 +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 + } + }] + }); + }, + + getAllLeaves: function () { + return [this.options.value]; + }, + + isSelected: function () { + return this.checked.isSelected(); + }, + + 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.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); + }); - _getMagnitude: function (n) { - var magnitude = "1"; - for (var i = 0; i < n; i++) { - magnitude += "0"; - } - return BI.parseInt(magnitude); - }, + this.tree = new BI.Tree(); + this.tree.initTree([{ + id: o.id, + children: o.children + }]); + 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); - } - for (var i = 0; i < magnitudeDiff; i++) { - if (needAddZero.numDecimal === "0" && i === 0) { - continue; - } - needAddZero.numDecimal += "0"; - } + 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 + }] + }); }, - _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 - }; + setAllSelected: function (v) { + this.checked.setSelected(v); + this.selectValue = []; }, - _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; + setHalfSelected: function (v) { + this.checked.setHalfSelected(v); + if(!v) { + this.selectValue = []; } }, - _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); - - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; + 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; + } } - return resultTemp; + }); + this.setAllSelected(selectValue.length > 0 && !isHalf); + this.setHalfSelected(selectValue.length > 0 && isHalf); + if (this.checked.isHalfSelected()) { + this.selectValue = selectValue; } }, - _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)); + getAllButtons: function () { + return [this]; + }, - return this._accurateAddition(this._accurateAddition(this._accurateAddition(integerResult, dec1Int2), int1dec2), dec1dec2); + getAllLeaves: function () { + var o = this.options; + var res = []; + this.tree.traverse(function (node) { + if (node.isLeaf()) { + res.push(node.get("data").value); + } + }); + return res; }, - _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); + getNotSelectedValue: function () { + var self = this, o = this.options; + var res = []; + var isAllSelected = this.checked.isSelected(); + if (isAllSelected === true) { + return res; } - 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; + 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 resultTemp; - } + }); + return res; }, - 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); + 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 (num1 < 0 && num2 >= 0) { - return -this._accurateAddition(-num1, num2); + if (this.checked.isHalfSelected()) { + return this.selectValue; } - if (num1 < 0 && num2 < 0) { - if (num1 >= num2) { - return this._accurateSubtraction(-num2, -num1); + 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) } - return this._accurateSubtraction(-num1, -num2); - } + }); + this.list.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.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); - } - if (num1 < 0 && num2 < 0) { - return -this._accurateAddition(-num1, -num2); - } + setValue: function (v) { + this.list.setValue({ + value: v + }); }, - 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); - } + getValue: function () { + return this.list.getValue(); }, - accurateDivisionTenExponent: function (num1, n) { - if (num1 >= 0) { - return this._accurateDivisionTenExponent(num1, n); - } - return -this._accurateDivisionTenExponent(-num1, n); + 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/8/28. - * @class BI.MonthCombo - * @extends BI.Trigger + * Created by GUY on 2015/12/11. + * @class BI.FileManagerNavButton + * @extends BI.Widget */ -BI.MonthCombo = BI.inherit(BI.Widget, { +BI.FileManagerNavButton = BI.inherit(BI.Widget, { + + _const: { + normal_color: "#ffffff", + select_color: "#eff1f4" + }, _defaultConfig: function () { - return BI.extend(BI.MonthCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-month-combo", - behaviors: {}, - height: 25 + return BI.extend(BI.FileManagerNavButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-nav-button", + selected: false, + height: 40 }); }, - _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 + _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.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.button.on(BI.Controller.EVENT_CHANGE, function () { + arguments[2] = self; + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.trigger.on(BI.MonthTrigger.EVENT_FOCUS, function () { - self.storeValue = this.getKey(); + var svg = BI.createWidget({ + type: "bi.svg", + cls: "file-manager-nav-button-triangle", + width: 15, + height: o.height }); - this.trigger.on(BI.MonthTrigger.EVENT_START, function () { - self.combo.hideView(); + var path = svg.path("M0,0L15,20L0,40").attr({ + stroke: c.select_color, + fill: o.selected ? c.select_color : c.normal_color }); - this.trigger.on(BI.MonthTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); + 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.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", + BI.createWidget({ + type: "bi.default", element: this, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - el: this.popup - } + items: [this.button] }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: svg, + right: -15, + top: 0, + bottom: 0 + }] }); }, + isSelected: function () { + return this.button.isSelected(); + }, + setValue: function (v) { - this.trigger.setValue(v); - this.popup.setValue(v); + this.button.setValue(v); }, getValue: function () { - if (BI.isNull(this.popup)) { - return this.options.value || ""; - } else { - return this.popup.getValue() || ""; - } + return this.button.getValue(); + }, + + populate: function (items) { + } }); - -BI.MonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.MonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.month_combo", BI.MonthCombo);/** - * 月份展示面板 +BI.FileManagerNavButton.EVENT_CHANGE = "FileManagerNavButton.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_nav_button", BI.FileManagerNavButton);/** + * 文件管理导航 * - * Created by GUY on 2015/9/2. - * @class BI.MonthPopup - * @extends BI.Trigger + * Created by GUY on 2015/12/11. + * @class BI.FileManagerNav + * @extends BI.Widget */ -BI.MonthPopup = BI.inherit(BI.Widget, { +BI.FileManagerNav = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MonthPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-month-popup", - behaviors: {} + return BI.extend(BI.FileManagerNav.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-nav bi-border-left", + height: 40, + items: [] }); }, _init: function () { - BI.MonthPopup.superclass._init.apply(this, arguments); + BI.FileManagerNav.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.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.month = BI.createWidget({ + this.button_group = 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 + 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 }], - value: o.value + layouts: [{ + type: "bi.horizontal" + }] }); - - this.month.on(BI.Controller.EVENT_CHANGE, function (type) { + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - if (type === BI.Events.CLICK) { - self.fireEvent(BI.MonthPopup.EVENT_CHANGE); - } }); + this.button_group.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) { + self.fireEvent(BI.FileManagerNav.EVENT_CHANGE, arguments); + }); + }, + + _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(); + }, + + _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; }, getValue: function () { - return this.month.getValue()[0]; + return this.button_group.getValue(); }, - setValue: function (v) { - this.month.setValue([v]); + 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)); } }); -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.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.MonthTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Month_Trigger_Error_Text") +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.MonthTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-month-trigger bi-border", - height: 24 + return BI.extend(BI.IntervalSlider.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-interval-slider bi-slider-track", + digit: false, + unit: "" }); }, + _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, + 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(); + + 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 v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 12); - }, - quitChecker: function (v) { - return false; - }, - hgap: c.hgap, - vgap: c.vgap, - allowBlank: true, - errorText: c.errorText + return self._checkValidation(v); + } }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.MonthTrigger.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.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.MonthTrigger.EVENT_CHANGE); + 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.SignEditor.EVENT_CONFIRM, function () { - var value = self.editor.getValue(); - if (BI.isNotNull(value)) { - self.editor.setValue(value); - self.editor.setTitle(value); + + 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); } - self.fireEvent(BI.MonthTrigger.EVENT_CONFIRM); }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); - } + 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.SignEditor.EVENT_START, function () { - self.fireEvent(BI.MonthTrigger.EVENT_START); + 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.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.MonthTrigger.EVENT_STOP); + + 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, - type: "bi.htape", - items: [ - { - el: this.editor + 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); + } + }, 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); + }); + + 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%" + }] }, { - el: { - type: "bi.text_button", - text: BI.i18nText("BI-Multi_Date_Month"), - baseCls: "bi-trigger-month-text", - width: o.height - }, - width: o.height + type: "bi.absolute", + items: [{ + el: this.labelTwo, + top: 0, + left: "100%" + }] + }], + rgap: c.EDITOR_R_GAP, + height: 70 + }, + top: 0, + left: 0, + width: "100%" + }; + }, + + _createSliderWrapper: function () { + var c = this._constant; + return { + el: { + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [{ + el: this.sliderOne, + top: 0, + left: "0%" + }] }, { - el: { - type: "bi.trigger_icon_button", - width: o.height - }, - width: o.height - } - ] + 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%" + }; + }, + + _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.setValue(o.value); }, - setValue: function (v) { - if(BI.isNotNull(v)) { - this.editor.setState(v + 1); - this.editor.setValue(v + 1); - this.editor.setTitle(v + 1); - return; + + _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; + }, + + _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(); + }, + + _setLabelTwoPosition: function (percent) { + this.labelTwo.element.css({left: percent + "%"}); + this._checkOverlap(); + }, + + _setSliderOnePosition: function (percent) { + this.sliderOne.element.css({left: percent + "%"}); + }, + + _setSliderTwoPosition: function (percent) { + this.sliderTwo.element.css({left: percent + "%"}); + }, + + _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 + 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") + 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.clearButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_CLEAR_EVENT_CHANGE); + + 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.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.trigger.on(BI.MonthTrigger.EVENT_FOCUS, function () { + self.storeValue = this.getKey(); }); - this.okButton.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiDatePopup.BUTTON_OK_EVENT_CHANGE); + this.trigger.on(BI.MonthTrigger.EVENT_START, function () { + self.combo.hideView(); }); - 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_STOP, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); } }); - 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.popup = BI.createWidget({ + type: "bi.month_popup", + behaviors: o.behaviors, + value: o.value }); - this.dateButton = BI.createWidget({ - type: "bi.grid", - items: [[this.clearButton, this.textButton, this.okButton]] + this.popup.on(BI.MonthPopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); }); - BI.createWidget({ + + this.combo = BI.createWidget({ + type: "bi.combo", element: this, - type: "bi.vtape", - items: [{ - el: this.dateTab - }, { - el: this.dateButton, - height: 30 - }] + 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); }); - 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; - } + 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 = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; + 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 + }; + }); + }); + + 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, { @@ -99661,61 +96346,473 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { this.combo.setValue(this.storeValue); }, - getValue: function () { - return BI.deepClone(this.storeValue); + getValue: function () { + return BI.deepClone(this.storeValue); + }, + + populate: function () { + this._count = null; + this.combo.populate.apply(this.combo, arguments); + } +}); + +BI.extend(BI.MultiSelectCombo, { + REQ_GET_DATA_LENGTH: 0, + REQ_GET_ALL_DATA: -1 +}); + +BI.MultiSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; + +BI.shortcut("bi.multi_select_combo", BI.MultiSelectCombo);/** + * 多选加载数据面板 + * Created by guy on 15/11/2. + * @class BI.MultiSelectLoader + * @extends Widget + */ +BI.MultiSelectLoader = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.MultiSelectLoader.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-loader", + logic: { + dynamic: true + }, + el: { + height: 400 + }, + valueFormatter: BI.emptyFn, + itemsCreator: BI.emptyFn, + onLoaded: BI.emptyFn + }); + }, + + _init: function () { + BI.MultiSelectLoader.superclass._init.apply(this, arguments); + + var self = this, opts = this.options; + var hasNext = false; + + this.storeValue = opts.value || {}; + this._assertValue(this.storeValue); + + this.button_group = BI.createWidget({ + type: "bi.select_list", + element: this, + logic: opts.logic, + el: BI.extend({ + onLoaded: opts.onLoaded, + el: { + type: "bi.loader", + isDefaultInit: false, + logic: { + dynamic: true, + scrolly: true + }, + el: { + chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, + behaviors: { + redmark: function () { + return true; + } + }, + layouts: [{ + type: "bi.vertical" + }] + } + } + }, opts.el), + itemsCreator: function (op, callback) { + var startValue = self._startValue; + self.storeValue && (op = BI.extend(op || {}, { + selectedValues: BI.isKey(startValue) && self.storeValue.type === BI.Selection.Multi + ? self.storeValue.value.concat(startValue) : self.storeValue.value + })); + opts.itemsCreator(op, function (ob) { + hasNext = ob.hasNext; + var firstItems = []; + if (op.times === 1 && self.storeValue) { + var json = BI.map(self.storeValue.value, function (i, v) { + var txt = opts.valueFormatter(v) || v; + return { + text: txt, + value: v, + title: txt, + selected: self.storeValue.type === BI.Selection.Multi + }; + }); + if (BI.isKey(self._startValue) && !self.storeValue.value.contains(self._startValue)) { + var txt = opts.valueFormatter(startValue) || startValue; + json.unshift({ + text: txt, + value: startValue, + title: txt, + selected: true + }); + } + firstItems = self._createItems(json); + } + callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); + if (op.times === 1 && self.storeValue) { + BI.isKey(startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](startValue); + self.setValue(self.storeValue); + } + (op.times === 1) && self._scrollToTop(); + }); + }, + hasNext: function () { + return hasNext; + }, + value: this.storeValue + }); + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + this.button_group.on(BI.SelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectLoader.EVENT_CHANGE, arguments); + }); + }, + + _createItems: function (items) { + return BI.createItems(items, { + type: "bi.multi_select_item", + logic: this.options.logic, + height: 25, + selected: this.isAllSelected() + }); + }, + + _scrollToTop: function () { + var self = this; + BI.delay(function () { + self.button_group.element.scrollTop(0); + }, 30); + }, + + isAllSelected: function () { + return this.button_group.isAllSelected(); + }, + + _assertValue: function (val) { + val || (val = {}); + val.type || (val.type = BI.Selection.Multi); + val.value || (val.value = []); + }, + + setStartValue: function (v) { + this._startValue = v; + }, + + setValue: function (v) { + this.storeValue = v || {}; + this._assertValue(this.storeValue); + this.button_group.setValue(this.storeValue); + }, + + 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.MultiSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.multi_select_loader", BI.MultiSelectLoader);/** + * 带加载的多选下拉面板 + * @class BI.MultiSelectPopupView + * @extends Widget + */ +BI.MultiSelectPopupView = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.MultiSelectPopupView.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-popup-view", + maxWidth: "auto", + minWidth: 135, + maxHeight: 400, + valueFormatter: BI.emptyFn, + itemsCreator: BI.emptyFn, + onLoaded: BI.emptyFn + }); + }, + + _init: function () { + BI.MultiSelectPopupView.superclass._init.apply(this, arguments); + var self = this, opts = this.options; + + this.loader = BI.createWidget({ + type: "bi.multi_select_loader", + itemsCreator: opts.itemsCreator, + valueFormatter: opts.valueFormatter, + onLoaded: opts.onLoaded, + value: opts.value + }); + + 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, + value: opts.value + }); + + this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectPopupView.EVENT_CHANGE); + }); + this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { + switch (index) { + case 0: + self.fireEvent(BI.MultiSelectPopupView.EVENT_CLICK_CLEAR); + break; + case 1: + self.fireEvent(BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM); + break; + } + }); + }, + + isAllSelected: function () { + return this.loader.isAllSelected(); + }, + + setStartValue: function (v) { + this.loader.setStartValue(v); + }, + + setValue: function (v) { + this.popupView.setValue(v); + }, + + getValue: function () { + return this.popupView.getValue(); + }, + + populate: function (items) { + this.popupView.populate.apply(this.popupView, arguments); + }, + + resetHeight: function (h) { + this.popupView.resetHeight(h); + }, + + resetWidth: function (w) { + this.popupView.resetWidth(w); + } +}); + +BI.MultiSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; +BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; +BI.MultiSelectPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; + + +BI.shortcut("bi.multi_select_popup_view", BI.MultiSelectPopupView);/** + * + * 复选下拉框 + * @class BI.MultiSelectTrigger + * @extends BI.Trigger + */ + +BI.MultiSelectTrigger = BI.inherit(BI.Trigger, { + + constants: { + height: 14, + rgap: 4, + lgap: 4 + }, + + _defaultConfig: function () { + return BI.extend(BI.MultiSelectTrigger.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-trigger bi-border", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + searcher: {}, + switcher: {}, + + adapter: null, + masker: {} + }); + }, + + _init: function () { + BI.MultiSelectTrigger.superclass._init.apply(this, arguments); + + var self = this, o = this.options; + if (o.height) { + this.setHeight(o.height - 2); + } + + this.searcher = BI.createWidget(o.searcher, { + type: "bi.multi_select_searcher", + height: o.height, + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, + popup: {}, + adapter: o.adapter, + masker: o.masker, + value: o.value + }); + this.searcher.on(BI.MultiSelectSearcher.EVENT_START, function () { + self.fireEvent(BI.MultiSelectTrigger.EVENT_START); + }); + this.searcher.on(BI.MultiSelectSearcher.EVENT_PAUSE, function () { + self.fireEvent(BI.MultiSelectTrigger.EVENT_PAUSE); + }); + this.searcher.on(BI.MultiSelectSearcher.EVENT_SEARCHING, function () { + self.fireEvent(BI.MultiSelectTrigger.EVENT_SEARCHING, arguments); + }); + this.searcher.on(BI.MultiSelectSearcher.EVENT_STOP, function () { + self.fireEvent(BI.MultiSelectTrigger.EVENT_STOP); + }); + this.searcher.on(BI.MultiSelectSearcher.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectTrigger.EVENT_CHANGE, arguments); + }); + this.numberCounter = BI.createWidget(o.switcher, { + type: "bi.multi_select_check_selected_switcher", + valueFormatter: o.valueFormatter, + itemsCreator: o.itemsCreator, + adapter: o.adapter, + masker: o.masker, + value: o.value + }); + this.numberCounter.on(BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, function () { + self.fireEvent(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK); + }); + this.numberCounter.on(BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW); + }); + + var wrapNumberCounter = BI.createWidget({ + type: "bi.right_vertical_adapt", + hgap: 4, + items: [{ + el: this.numberCounter + }] + }); + + var wrapper = BI.createWidget({ + type: "bi.htape", + element: this, + items: [ + { + el: this.searcher, + width: "fill" + }, { + el: wrapNumberCounter, + width: 0 + }, { + el: BI.createWidget(), + width: 30 + }] + }); + + this.numberCounter.on(BI.Events.VIEW, function (b) { + BI.nextTick(function () {// 自动调整宽度 + wrapper.attr("items")[1].width = (b === true ? self.numberCounter.element.outerWidth() + 8 : 0); + wrapper.resize(); + }); + }); + + this.element.click(function (e) { + if (self.element.__isMouseInBounds__(e) && !self.numberCounter.element.__isMouseInBounds__(e)) { + self.numberCounter.hideView(); + } + }); + }, + + getCounter: function () { + return this.numberCounter; + }, + + getSearcher: function () { + return this.searcher; + }, + + stopEditing: function () { + this.searcher.stopSearch(); + this.numberCounter.hideView(); + }, + + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + this.numberCounter.setAdapter(adapter); + }, + + setValue: function (ob) { + this.searcher.setValue(ob); + this.numberCounter.setValue(ob); + }, + + 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.MultiSelectCombo, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 -}); - -BI.MultiSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.MultiSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; +BI.MultiSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; +BI.MultiSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; +BI.MultiSelectTrigger.EVENT_START = "EVENT_START"; +BI.MultiSelectTrigger.EVENT_STOP = "EVENT_STOP"; +BI.MultiSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; +BI.MultiSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; -BI.shortcut("bi.multi_select_combo", BI.MultiSelectCombo);/** - * 多选加载数据面板 - * Created by guy on 15/11/2. - * @class BI.MultiSelectLoader +BI.shortcut("bi.multi_select_trigger", BI.MultiSelectTrigger);/** + * 多选加载数据搜索loader面板 + * Created by guy on 15/11/4. + * @class BI.MultiSelectSearchLoader * @extends Widget */ -BI.MultiSelectLoader = BI.inherit(BI.Widget, { +BI.MultiSelectSearchLoader = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectLoader.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-loader", - logic: { - dynamic: true - }, - el: { - height: 400 - }, - valueFormatter: BI.emptyFn, + return BI.extend(BI.MultiSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-search-loader", itemsCreator: BI.emptyFn, - onLoaded: BI.emptyFn + keywordGetter: BI.emptyFn, + valueFormatter: BI.emptyFn }); }, _init: function () { - BI.MultiSelectLoader.superclass._init.apply(this, arguments); + BI.MultiSelectSearchLoader.superclass._init.apply(this, arguments); var self = this, opts = this.options; var hasNext = false; - - this.storeValue = opts.value || {}; - this._assertValue(this.storeValue); - + this.storeValue = BI.deepClone(opts.value); this.button_group = BI.createWidget({ type: "bi.select_list", element: this, - logic: opts.logic, - el: BI.extend({ - onLoaded: opts.onLoaded, + logic: { + dynamic: false + }, + value: opts.value, + el: { + tipText: BI.i18nText("BI-No_Select"), el: { type: "bi.loader", isDefaultInit: false, @@ -99735,4527 +96832,5152 @@ BI.MultiSelectLoader = BI.inherit(BI.Widget, { }] } } - }, opts.el), + }, itemsCreator: function (op, callback) { - var startValue = self._startValue; self.storeValue && (op = BI.extend(op || {}, { - selectedValues: BI.isKey(startValue) && self.storeValue.type === BI.Selection.Multi - ? self.storeValue.value.concat(startValue) : self.storeValue.value + selectedValues: self.storeValue.value })); 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.value, function (i, v) { - var txt = opts.valueFormatter(v) || v; - return { - text: txt, - value: v, - title: txt, - selected: self.storeValue.type === BI.Selection.Multi - }; - }); - if (BI.isKey(self._startValue) && !self.storeValue.value.contains(self._startValue)) { - var txt = opts.valueFormatter(startValue) || startValue; - json.unshift({ - text: txt, - value: startValue, - title: txt, - selected: true - }); - } + var json = self._filterValues(self.storeValue); firstItems = self._createItems(json); } - callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); + callback(firstItems.concat(self._createItems(ob.items)), keyword); if (op.times === 1 && self.storeValue) { - BI.isKey(startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](startValue); self.setValue(self.storeValue); } - (op.times === 1) && self._scrollToTop(); }); }, hasNext: function () { return hasNext; - }, - value: this.storeValue + } }); this.button_group.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); this.button_group.on(BI.SelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectLoader.EVENT_CHANGE, arguments); + self.fireEvent(BI.MultiSelectSearchLoader.EVENT_CHANGE, arguments); }); }, _createItems: function (items) { return BI.createItems(items, { type: "bi.multi_select_item", - logic: this.options.logic, + logic: { + dynamic: false + }, height: 25, selected: this.isAllSelected() }); }, - _scrollToTop: function () { - var self = this; - BI.delay(function () { - self.button_group.element.scrollTop(0); - }, 30); + isAllSelected: function () { + return this.button_group.isAllSelected(); + }, + + _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: src.type === BI.Selection.All + }; + }); + }, + + setValue: function (v) { + // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = BI.deepClone(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.MultiSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.multi_select_search_loader", BI.MultiSelectSearchLoader);/** + * + * 在搜索框中输入文本弹出的面板 + * @class BI.MultiSelectSearchPane + * @extends Widget + */ + +BI.MultiSelectSearchPane = BI.inherit(BI.Widget, { + + constants: { + height: 25, + lgap: 10, + tgap: 5 + }, + + _defaultConfig: function () { + return BI.extend(BI.MultiSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-search-pane bi-card", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + keywordGetter: BI.emptyFn + }); + }, + + _init: function () { + BI.MultiSelectSearchPane.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: "multi-select-toolbar", + height: this.constants.height + }); + + this.loader = BI.createWidget({ + type: "bi.multi_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()); + }]); + }, + value: o.value + }); + 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(); + } + }, + + isAllSelected: function () { + return this.loader.isAllSelected(); + }, + + 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.MultiSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; + +BI.shortcut("bi.multi_select_search_pane", BI.MultiSelectSearchPane);/** + * 查看已选按钮 + * Created by guy on 15/11/3. + * @class BI.MultiSelectCheckSelectedButton + * @extends BI.Single + */ +BI.MultiSelectCheckSelectedButton = BI.inherit(BI.Single, { + + _const: { + checkSelected: BI.i18nText("BI-Check_Selected") + }, + + _defaultConfig: function () { + return BI.extend(BI.MultiSelectCheckSelectedButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-check-selected-button bi-high-light", + itemsCreator: BI.emptyFn + }); + }, + + _init: function () { + BI.MultiSelectCheckSelectedButton.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.numberCounter = BI.createWidget({ + type: "bi.text_button", + element: this, + hgap: 4, + text: "0", + textAlign: "center", + textHeight: 15 + }); + this.numberCounter.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + this.numberCounter.on(BI.TextButton.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments); + }); + + this.numberCounter.element.hover(function () { + self.numberCounter.setTag(self.numberCounter.getText()); + self.numberCounter.setText(self._const.checkSelected); + }, function () { + self.numberCounter.setText(self.numberCounter.getTag()); + }); + this.setVisible(false); + if(BI.isNotNull(o.value)){ + this.setValue(o.value); + } + }, + + setValue: function (ob) { + var self = this, o = this.options; + ob || (ob = {}); + ob.type || (ob.type = BI.Selection.Multi); + ob.value || (ob.value = []); + if (ob.type === BI.Selection.All) { + o.itemsCreator({ + type: BI.MultiSelectCombo.REQ_GET_DATA_LENGTH + }, function (res) { + var length = res.count - ob.value.length; + BI.nextTick(function () { + self.numberCounter.setText(length); + self.setVisible(length > 0); + }); + }); + return; + } + BI.nextTick(function () { + self.numberCounter.setText(ob.value.length); + self.setVisible(ob.value.length > 0); + }); + }, + + getValue: function () { + + } +}); + +BI.MultiSelectCheckSelectedButton.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.multi_select_check_selected_button", BI.MultiSelectCheckSelectedButton);/** + * 多选输入框 + * Created by guy on 15/11/3. + * @class BI.MultiSelectEditor + * @extends Widget + */ +BI.MultiSelectEditor = BI.inherit(BI.Widget, { + + _const: { + checkSelected: BI.i18nText("BI-Check_Selected") + }, + + _defaultConfig: function () { + return BI.extend(BI.MultiSelectEditor.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-editor", + el: {} + }); + }, + + _init: function () { + BI.MultiSelectEditor.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, + value: o.value + }); + + 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.MultiSelectEditor.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.MultiSelectEditor.EVENT_PAUSE = "MultiSelectEditor.EVENT_PAUSE"; +BI.shortcut("bi.multi_select_editor", BI.MultiSelectEditor);/** + * searcher + * Created by guy on 15/11/3. + * @class BI.MultiSelectSearcher + * @extends Widget + */ +BI.MultiSelectSearcher = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.MultiSelectSearcher.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-searcher", + itemsCreator: BI.emptyFn, + el: {}, + popup: {}, + valueFormatter: BI.emptyFn, + adapter: null, + masker: {} + }); + }, + + _init: function () { + BI.MultiSelectSearcher.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.editor = BI.createWidget(o.el, { + type: "bi.multi_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.multi_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); + }, + value: o.value + }, o.popup), + + adapter: o.adapter, + masker: o.masker + }); + this.searcher.on(BI.Searcher.EVENT_START, function () { + self.fireEvent(BI.MultiSelectSearcher.EVENT_START); + }); + this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { + if (this.hasMatched()) { + + } + self.fireEvent(BI.MultiSelectSearcher.EVENT_PAUSE); + }); + this.searcher.on(BI.Searcher.EVENT_STOP, function () { + self.fireEvent(BI.MultiSelectSearcher.EVENT_STOP); + }); + this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectSearcher.EVENT_CHANGE, arguments); + }); + this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { + var keywords = this.getKeywords(); + self.fireEvent(BI.MultiSelectSearcher.EVENT_SEARCHING, keywords); + }); + if(BI.isNotNull(o.value)){ + this.setState(o.value); + } + }, + + adjustView: function () { + this.searcher.adjustView(); }, - isAllSelected: function () { - return this.button_group.isAllSelected(); + isSearching: function () { + return this.searcher.isSearching(); }, - _assertValue: function (val) { - val || (val = {}); - val.type || (val.type = BI.Selection.Multi); - val.value || (val.value = []); + stopSearch: function () { + this.searcher.stopSearch(); }, - setStartValue: function (v) { - this._startValue = v; + getKeyword: function () { + return this.editor.getValue(); }, - setValue: function (v) { - this.storeValue = v || {}; - this._assertValue(this.storeValue); - this.button_group.setValue(this.storeValue); + hasMatched: function () { + return this.searcher.hasMatched(); }, - getValue: function () { - return this.button_group.getValue(); + hasChecked: function () { + return this.searcher.getView() && this.searcher.getView().hasChecked(); }, - getAllButtons: function () { - return this.button_group.getAllButtons(); + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - empty: function () { - this.button_group.empty(); + setState: function (ob) { + var o = this.options; + ob || (ob = {}); + ob.value || (ob.value = []); + if (ob.type === BI.Selection.All) { + if (ob.value.length === 0) { + this.editor.setState(BI.Selection.All); + } else if (BI.size(ob.assist) <= 20) { + var state = ""; + BI.each(ob.assist, function (i, v) { + if (i === 0) { + state += "" + (o.valueFormatter(v + "") || v); + } else { + state += "," + (o.valueFormatter(v + "") || v); + } + }); + this.editor.setState(state); + } else { + this.editor.setState(BI.Selection.Multi); + } + } else { + if (ob.value.length === 0) { + this.editor.setState(BI.Selection.None); + } else if (BI.size(ob.value) <= 20) { + var state = ""; + BI.each(ob.value, function (i, v) { + if (i === 0) { + state += "" + (o.valueFormatter(v + "") || v); + } else { + state += "," + (o.valueFormatter(v + "") || v); + } + }); + this.editor.setState(state); + } else { + this.editor.setState(BI.Selection.Multi); + } + } }, - populate: function (items) { - this.button_group.populate.apply(this.button_group, arguments); + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); }, - resetHeight: function (h) { - this.button_group.resetHeight(h); + getKey: function () { + return this.editor.getValue(); }, - resetWidth: function (w) { - this.button_group.resetWidth(w); + getValue: function () { + return this.searcher.getValue(); + }, + + populate: function (items) { + this.searcher.populate.apply(this.searcher, arguments); } }); -BI.MultiSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multi_select_loader", BI.MultiSelectLoader);/** - * 带加载的多选下拉面板 - * @class BI.MultiSelectPopupView +BI.MultiSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.MultiSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; +BI.MultiSelectSearcher.EVENT_START = "EVENT_START"; +BI.MultiSelectSearcher.EVENT_STOP = "EVENT_STOP"; +BI.MultiSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; +BI.MultiSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; +BI.shortcut("bi.multi_select_searcher", BI.MultiSelectSearcher);/** + * 查看已选switcher + * Created by guy on 15/11/3. + * @class BI.MultiSelectCheckSelectedSwitcher * @extends Widget */ -BI.MultiSelectPopupView = BI.inherit(BI.Widget, { +BI.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectPopupView.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-popup-view", - maxWidth: "auto", - minWidth: 135, - maxHeight: 400, - valueFormatter: BI.emptyFn, + return BI.extend(BI.MultiSelectCheckSelectedSwitcher.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-check-selected-switcher", itemsCreator: BI.emptyFn, - onLoaded: BI.emptyFn + valueFormatter: BI.emptyFn, + el: {}, + popup: {}, + adapter: null, + masker: {} }); }, _init: function () { - BI.MultiSelectPopupView.superclass._init.apply(this, arguments); - var self = this, opts = this.options; + BI.MultiSelectCheckSelectedSwitcher.superclass._init.apply(this, arguments); + var self = this, o = this.options; - this.loader = BI.createWidget({ - type: "bi.multi_select_loader", - itemsCreator: opts.itemsCreator, - valueFormatter: opts.valueFormatter, - onLoaded: opts.onLoaded, - value: opts.value + this.button = BI.createWidget(o.el, { + type: "bi.multi_select_check_selected_button", + itemsCreator: o.itemsCreator, + value: o.value }); - - this.popupView = BI.createWidget({ - type: "bi.multi_popup_view", - stopPropagation: false, - maxWidth: opts.maxWidth, - minWidth: opts.minWidth, - maxHeight: opts.maxHeight, + this.button.on(BI.Events.VIEW, function () { + self.fireEvent(BI.Events.VIEW, arguments); + }); + this.switcher = BI.createWidget({ + type: "bi.switcher", + toggle: false, element: this, - buttons: [BI.i18nText("BI-Basic_Clears"), BI.i18nText("BI-Basic_Sure")], - el: this.loader, - value: opts.value + el: this.button, + popup: BI.extend({ + type: "bi.multi_select_check_pane", + valueFormatter: o.valueFormatter, + itemsCreator: o.itemsCreator, + onClickContinueSelect: function () { + self.switcher.hideView(); + }, + value: o.value + }, o.popup), + adapter: o.adapter, + masker: o.masker }); - - this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectPopupView.EVENT_CHANGE); + this.switcher.on(BI.Switcher.EVENT_TRIGGER_CHANGE, function () { + self.fireEvent(BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE); }); - this.popupView.on(BI.MultiPopupView.EVENT_CLICK_TOOLBAR_BUTTON, function (index) { - switch (index) { - case 0: - self.fireEvent(BI.MultiSelectPopupView.EVENT_CLICK_CLEAR); - break; - case 1: - self.fireEvent(BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM); - break; - } + this.switcher.on(BI.Switcher.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW); + }); + this.switcher.on(BI.Switcher.EVENT_AFTER_POPUPVIEW, function () { + var me = this; + BI.nextTick(function () { + me.populate(); + }); + }); + + this.switcher.element.click(function (e) { + e.stopPropagation(); }); }, - isAllSelected: function () { - return this.loader.isAllSelected(); + adjustView: function () { + this.switcher.adjustView(); }, - setStartValue: function (v) { - this.loader.setStartValue(v); + hideView: function () { + this.switcher.empty(); + this.switcher.hideView(); }, - setValue: function (v) { - this.popupView.setValue(v); + setAdapter: function (adapter) { + this.switcher.setAdapter(adapter); }, - getValue: function () { - return this.popupView.getValue(); + setValue: function (v) { + this.switcher.setValue(v); }, - populate: function (items) { - this.popupView.populate.apply(this.popupView, arguments); + setButtonChecked: function (v) { + this.button.setValue(v); }, - resetHeight: function (h) { - this.popupView.resetHeight(h); + getValue: function () { + }, - resetWidth: function (w) { - this.popupView.resetWidth(w); + populate: function (items) { + this.switcher.populate.apply(this.switcher, arguments); } }); -BI.MultiSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; -BI.MultiSelectPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; - - -BI.shortcut("bi.multi_select_popup_view", BI.MultiSelectPopupView);/** - * - * 复选下拉框 - * @class BI.MultiSelectTrigger - * @extends BI.Trigger +BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE = "MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE"; +BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.multi_select_check_selected_switcher", BI.MultiSelectCheckSelectedSwitcher);/** + * Created by zcf_1 on 2017/5/2. */ - -BI.MultiSelectTrigger = BI.inherit(BI.Trigger, { - - constants: { - height: 14, - rgap: 4, - lgap: 4 - }, - +BI.MultiSelectInsertList = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectTrigger.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-trigger bi-border", + return BI.extend(BI.MultiSelectInsertList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-insert-list", itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - searcher: {}, - switcher: {}, - - adapter: null, - masker: {} + valueFormatter: BI.emptyFn }); }, - _init: function () { - BI.MultiSelectTrigger.superclass._init.apply(this, arguments); + BI.MultiSelectInsertList.superclass._init.apply(this, arguments); var self = this, o = this.options; - if (o.height) { - this.setHeight(o.height - 2); - } + this.storeValue = {}; - this.searcher = BI.createWidget(o.searcher, { - type: "bi.multi_select_searcher", - height: o.height, + var assertShowValue = function () { + BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); + // self.trigger.setValue(self.storeValue); + }; + + this.adapter = BI.createWidget({ + type: "bi.multi_select_loader", + cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom", itemsCreator: o.itemsCreator, valueFormatter: o.valueFormatter, - popup: {}, - adapter: o.adapter, - masker: o.masker, - value: o.value - }); - this.searcher.on(BI.MultiSelectSearcher.EVENT_START, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_START); - }); - this.searcher.on(BI.MultiSelectSearcher.EVENT_PAUSE, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_PAUSE); - }); - this.searcher.on(BI.MultiSelectSearcher.EVENT_SEARCHING, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_SEARCHING, arguments); - }); - this.searcher.on(BI.MultiSelectSearcher.EVENT_STOP, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_STOP); + logic: { + dynamic: false + }, + // onLoaded: o.onLoaded, + el: {} }); - this.searcher.on(BI.MultiSelectSearcher.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_CHANGE, arguments); + this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { + self.storeValue = this.getValue(); + assertShowValue(); + self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); }); - this.numberCounter = BI.createWidget(o.switcher, { - type: "bi.multi_select_check_selected_switcher", + + this.searcherPane = BI.createWidget({ + type: "bi.multi_select_search_pane", + cls: "bi-border-left bi-border-right bi-border-bottom", valueFormatter: o.valueFormatter, - itemsCreator: o.itemsCreator, - adapter: o.adapter, - masker: o.masker, - value: o.value - }); - this.numberCounter.on(BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK); + keywordGetter: function () { + return self.trigger.getKeyword(); + }, + itemsCreator: function (op, callback) { + op.keyword = self.trigger.getKeyword(); + this.setKeyword(op.keyword); + o.itemsCreator(op, callback); + } }); - this.numberCounter.on(BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW); + this.searcherPane.setVisible(false); + + this.trigger = BI.createWidget({ + type: "bi.searcher", + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback(); + }, + adapter: this.adapter, + popup: this.searcherPane, + height: 200, + masker: false, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); + self._setStartValue(""); + this.setValue(BI.deepClone(self.storeValue)); + } + }, { + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + self._setStartValue(""); + self.adapter.setValue(self.storeValue); + // 需要刷新回到初始界面,否则搜索的结果不能放在最前面 + self.adapter.populate(); + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + var keyword = this.getKeyword(); + if (this.hasMatched()) { + self._join({ + type: BI.Selection.Multi, + value: [keyword] + }, function () { + if (self.storeValue.type === BI.Selection.Multi) { + self.storeValue.value.pushDistinct(keyword); + } + self._showAdapter(); + self.adapter.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self.adapter.populate(); + self._setStartValue(""); + self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); + }); + } else { + if (self.storeValue.type === BI.Selection.Multi) { + self.storeValue.value.pushDistinct(keyword); + } + self._showAdapter(); + self.adapter.setValue(self.storeValue); + self.adapter.populate(); + if (self.storeValue.type === BI.Selection.Multi) { + self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); + } + } + } + }, { + eventName: BI.Searcher.EVENT_SEARCHING, + action: function () { + var keywords = this.getKeyword(); + var last = BI.last(keywords); + keywords = BI.initial(keywords || []); + if (keywords.length > 0) { + self._joinKeywords(keywords, function () { + if (BI.isEndWithBlank(last)) { + self.adapter.setValue(self.storeValue); + assertShowValue(); + self.adapter.populate(); + self._setStartValue(""); + } else { + self.adapter.setValue(self.storeValue); + assertShowValue(); + } + }); + } + } + }, { + eventName: BI.Searcher.EVENT_CHANGE, + action: function (value, obj) { + if (obj instanceof BI.MultiSelectBar) { + self._joinAll(this.getValue(), function () { + assertShowValue(); + self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); + }); + } else { + self._join(this.getValue(), function () { + assertShowValue(); + self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); + }); + } + } + }] }); - var wrapNumberCounter = BI.createWidget({ - type: "bi.right_vertical_adapt", - hgap: 4, + BI.createWidget({ + type: "bi.vtape", + element: this, items: [{ - el: this.numberCounter + el: this.trigger, + height: 24 + }, { + el: this.adapter, + height: "fill" }] }); - - var wrapper = BI.createWidget({ - type: "bi.htape", + BI.createWidget({ + type: "bi.absolute", element: this, - items: [ - { - el: this.searcher, - width: "fill" - }, { - el: wrapNumberCounter, - width: 0 - }, { - el: BI.createWidget(), - width: 30 - }] + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] }); + }, - this.numberCounter.on(BI.Events.VIEW, function (b) { - BI.nextTick(function () {// 自动调整宽度 - wrapper.attr("items")[1].width = (b === true ? self.numberCounter.element.outerWidth() + 8 : 0); - wrapper.resize(); + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); + }, + + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); + }, + + _defaultState: function () { + this.trigger.stopEditing(); + }, + + _assertValue: function (val) { + val || (val = {}); + val.type || (val.type = BI.Selection.Multi); + val.value || (val.value = []); + }, + + _makeMap: function (values) { + return BI.makeObject(values || []); + }, + + _joinKeywords: function (keywords, callback) { + var self = this, o = this.options; + this._assertValue(this.storeValue); + if (!this._allData) { + o.itemsCreator({ + type: BI.MultiSelectInsertList.REQ_GET_ALL_DATA + }, function (ob) { + self._allData = BI.map(ob.items, "value"); + digest(self._allData); }); - }); + } else { + digest(this._allData); + } - this.element.click(function (e) { - if (self.element.__isMouseInBounds__(e) && !self.numberCounter.element.__isMouseInBounds__(e)) { - self.numberCounter.hideView(); + function digest (items) { + var selectedMap = self._makeMap(items); + BI.each(keywords, function (i, val) { + if (BI.isNotNull(selectedMap[val])) { + self.storeValue.value[self.storeValue.type === BI.Selection.Multi ? "pushDistinct" : "remove"](val); + } + }); + callback(); + } + }, + + _joinAll: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + o.itemsCreator({ + type: BI.MultiSelectInsertList.REQ_GET_ALL_DATA, + keyword: self.trigger.getKeyword() + }, 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)); + 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)); + callback(); }); }, - getCounter: function () { - return this.numberCounter; + _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)); + callback(); + return; + } + this._joinAll(res, callback); }, - getSearcher: function () { - return this.searcher; + _setStartValue: function (value) { + this._startValue = value; + this.adapter.setStartValue(value); }, - stopEditing: function () { - this.searcher.stopSearch(); - this.numberCounter.hideView(); + isAllSelected: function () { + return this.adapter.isAllSelected(); }, - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); - this.numberCounter.setAdapter(adapter); + resize: function () { + // this.trigger.getCounter().adjustView(); + // this.trigger.adjustView(); }, - - setValue: function (ob) { - this.searcher.setValue(ob); - this.numberCounter.setValue(ob); + setValue: function (v) { + this.storeValue = v || {}; + this._assertValue(this.storeValue); + this.adapter.setValue(this.storeValue); + this.trigger.setValue(this.storeValue); }, - getKey: function () { - return this.searcher.getKey(); + getValue: function () { + return BI.deepClone(this.storeValue); }, - getValue: function () { - return this.searcher.getValue(); + populate: function () { + this._count = null; + this._allData = null; + this.adapter.populate.apply(this.adapter, arguments); + this.trigger.populate.apply(this.trigger, arguments); } }); -BI.MultiSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; -BI.MultiSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK"; -BI.MultiSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiSelectTrigger.EVENT_START = "EVENT_START"; -BI.MultiSelectTrigger.EVENT_STOP = "EVENT_STOP"; -BI.MultiSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; -BI.MultiSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; +BI.extend(BI.MultiSelectInsertList, { + REQ_GET_DATA_LENGTH: 0, + REQ_GET_ALL_DATA: -1 +}); -BI.shortcut("bi.multi_select_trigger", BI.MultiSelectTrigger);/** - * 多选加载数据搜索loader面板 - * Created by guy on 15/11/4. - * @class BI.MultiSelectSearchLoader - * @extends Widget +BI.MultiSelectInsertList.EVENT_CHANGE = "BI.MultiSelectInsertList.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_insert_list", BI.MultiSelectInsertList);/** + * Created by zcf_1 on 2017/5/2. */ -BI.MultiSelectSearchLoader = BI.inherit(BI.Widget, { - +BI.MultiSelectList = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-search-loader", + return BI.extend(BI.MultiSelectList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-list", itemsCreator: BI.emptyFn, - keywordGetter: BI.emptyFn, valueFormatter: BI.emptyFn }); }, - _init: function () { - BI.MultiSelectSearchLoader.superclass._init.apply(this, arguments); + BI.MultiSelectList.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - var hasNext = false; - this.storeValue = BI.deepClone(opts.value); - this.button_group = BI.createWidget({ - type: "bi.select_list", - element: this, + var self = this, o = this.options; + this.storeValue = {}; + + var assertShowValue = function () { + BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); + // self.trigger.setValue(self.storeValue); + }; + + this.adapter = BI.createWidget({ + type: "bi.multi_select_loader", + cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom", + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, logic: { dynamic: false }, - value: opts.value, - el: { - tipText: BI.i18nText("BI-No_Select"), - el: { - type: "bi.loader", - isDefaultInit: false, - logic: { - dynamic: true, - scrolly: true - }, - el: { - chooseType: BI.ButtonGroup.CHOOSE_TYPE_MULTI, - behaviors: { - redmark: function () { - return true; - } - }, - layouts: [{ - type: "bi.vertical" - }] - } - } + // onLoaded: o.onLoaded, + el: {} + }); + this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { + self.storeValue = this.getValue(); + self._adjust(function () { + assertShowValue(); + self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); + }); + }); + + this.searcherPane = BI.createWidget({ + type: "bi.multi_select_search_pane", + cls: "bi-border-left bi-border-right bi-border-bottom", + valueFormatter: o.valueFormatter, + keywordGetter: function () { + return self.trigger.getKeyword(); }, itemsCreator: function (op, callback) { - self.storeValue && (op = BI.extend(op || {}, { - selectedValues: self.storeValue.value - })); - opts.itemsCreator(op, function (ob) { - var keyword = ob.keyword = opts.keywordGetter(); - hasNext = ob.hasNext; - var firstItems = []; - if (op.times === 1 && self.storeValue) { - var json = self._filterValues(self.storeValue); - 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; + op.keyword = self.trigger.getKeyword(); + this.setKeyword(op.keyword); + o.itemsCreator(op, callback); } }); - this.button_group.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.button_group.on(BI.SelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectSearchLoader.EVENT_CHANGE, arguments); - }); - }, + this.searcherPane.setVisible(false); - _createItems: function (items) { - return BI.createItems(items, { - type: "bi.multi_select_item", - logic: { - dynamic: false + this.trigger = BI.createWidget({ + type: "bi.searcher", + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback(); }, - height: 25, - selected: this.isAllSelected() + adapter: this.adapter, + popup: this.searcherPane, + height: 200, + masker: false, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); + self._setStartValue(""); + this.setValue(BI.deepClone(self.storeValue)); + } + }, { + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + self._setStartValue(""); + self.adapter.setValue(self.storeValue); + // 需要刷新回到初始界面,否则搜索的结果不能放在最前面 + self.adapter.populate(); + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + var keyword = this.getKeyword(); + if (this.hasMatched()) { + self._join({ + type: BI.Selection.Multi, + value: [keyword] + }, function () { + self._showAdapter(); + self.adapter.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self.adapter.populate(); + self._setStartValue(""); + self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); + }); + } + } + }, { + eventName: BI.Searcher.EVENT_SEARCHING, + action: function () { + var keywords = this.getKeyword(); + var last = BI.last(keywords); + keywords = BI.initial(keywords || []); + if (keywords.length > 0) { + self._joinKeywords(keywords, function () { + if (BI.isEndWithBlank(last)) { + self.adapter.setValue(self.storeValue); + assertShowValue(); + self.adapter.populate(); + self._setStartValue(""); + } else { + self.adapter.setValue(self.storeValue); + assertShowValue(); + } + }); + } + } + }, { + eventName: BI.Searcher.EVENT_CHANGE, + action: function (value, obj) { + if (obj instanceof BI.MultiSelectBar) { + self._joinAll(this.getValue(), function () { + assertShowValue(); + self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); + }); + } else { + self._join(this.getValue(), function () { + assertShowValue(); + self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); + }); + } + } + }] }); - }, - - isAllSelected: function () { - return this.button_group.isAllSelected(); - }, - _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 - }; + BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.trigger, + height: 24 + }, { + el: this.adapter, + height: "fill" + }] }); - 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: src.type === BI.Selection.All - }; + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] }); }, - setValue: function (v) { - // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 - this.storeValue = BI.deepClone(v); - this.button_group.setValue(v); - }, - - getValue: function () { - return this.button_group.getValue(); + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); }, - getAllButtons: function () { - return this.button_group.getAllButtons(); + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); }, - empty: function () { - this.button_group.empty(); + _defaultState: function () { + this.trigger.stopEditing(); }, - populate: function (items) { - this.button_group.populate.apply(this.button_group, arguments); + _assertValue: function (val) { + val || (val = {}); + val.type || (val.type = BI.Selection.Multi); + val.value || (val.value = []); }, - resetHeight: function (h) { - this.button_group.resetHeight(h); + _makeMap: function (values) { + return BI.makeObject(values || []); }, - resetWidth: function (w) { - this.button_group.resetWidth(w); - } -}); - -BI.MultiSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multi_select_search_loader", BI.MultiSelectSearchLoader);/** - * - * 在搜索框中输入文本弹出的面板 - * @class BI.MultiSelectSearchPane - * @extends Widget - */ - -BI.MultiSelectSearchPane = BI.inherit(BI.Widget, { + _joinKeywords: function (keywords, callback) { + var self = this, o = this.options; + this._assertValue(this.storeValue); + if (!this._allData) { + o.itemsCreator({ + type: BI.MultiSelectList.REQ_GET_ALL_DATA + }, function (ob) { + self._allData = BI.map(ob.items, "value"); + digest(self._allData); + }); + } else { + digest(this._allData); + } - constants: { - height: 25, - lgap: 10, - tgap: 5 + function digest (items) { + var selectedMap = self._makeMap(items); + BI.each(keywords, function (i, val) { + if (BI.isNotNull(selectedMap[val])) { + self.storeValue.value[self.storeValue.type === BI.Selection.Multi ? "pushDistinct" : "remove"](val); + } + }); + self._adjust(callback); + } }, - _defaultConfig: function () { - return BI.extend(BI.MultiSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-search-pane bi-card", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - keywordGetter: BI.emptyFn + _joinAll: function (res, callback) { + var self = this, o = this.options; + this._assertValue(res); + o.itemsCreator({ + type: BI.MultiSelectList.REQ_GET_ALL_DATA, + keyword: self.trigger.getKeyword() + }, 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); }); }, - _init: function () { - BI.MultiSelectSearchPane.superclass._init.apply(this, arguments); + _adjust: function (callback) { var self = this, o = this.options; + if (!this._count) { + o.itemsCreator({ + type: BI.MultiSelectList.REQ_GET_DATA_LENGTH + }, function (res) { + self._count = res.count; + adjust(); + callback(); + }); + } else { + adjust(); + callback(); + } - this.tooltipClick = BI.createWidget({ - type: "bi.label", - invisible: true, - text: BI.i18nText("BI-Click_Blank_To_Select"), - cls: "multi-select-toolbar", - height: this.constants.height - }); - - this.loader = BI.createWidget({ - type: "bi.multi_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()); - }]); - }, - value: o.value - }); - 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); + function adjust () { + if (self.storeValue.type === BI.Selection.All && self.storeValue.value.length >= self._count) { + self.storeValue = { + type: BI.Selection.Multi, + value: [] + }; + } else if (self.storeValue.type === BI.Selection.Multi && self.storeValue.value.length >= self._count) { + self.storeValue = { + type: BI.Selection.All, + 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(); + _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); }, - isAllSelected: function () { - return this.loader.isAllSelected(); + _setStartValue: function (value) { + this._startValue = value; + this.adapter.setStartValue(value); }, - hasMatched: function () { - return this.tooltipClick.isVisible(); + isAllSelected: function () { + return this.adapter.isAllSelected(); }, + resize: function () { + // this.trigger.getCounter().adjustView(); + // this.trigger.adjustView(); + }, setValue: function (v) { - this.loader.setValue(v); + this.storeValue = v || {}; + this._assertValue(this.storeValue); + this.adapter.setValue(this.storeValue); + this.trigger.setValue(this.storeValue); }, getValue: function () { - return this.loader.getValue(); - }, - - empty: function () { - this.loader.empty(); + return BI.deepClone(this.storeValue); }, - populate: function (items) { - this.loader.populate.apply(this.loader, arguments); + populate: function () { + this._count = null; + this._allData = null; + this.adapter.populate.apply(this.adapter, arguments); + this.trigger.populate.apply(this.trigger, arguments); } }); -BI.MultiSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; +BI.extend(BI.MultiSelectList, { + REQ_GET_DATA_LENGTH: 0, + REQ_GET_ALL_DATA: -1 +}); -BI.shortcut("bi.multi_select_search_pane", BI.MultiSelectSearchPane);/** - * 查看已选按钮 - * Created by guy on 15/11/3. - * @class BI.MultiSelectCheckSelectedButton - * @extends BI.Single +BI.MultiSelectList.EVENT_CHANGE = "BI.MultiSelectList.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_list", BI.MultiSelectList);/** + * Created by zcf_1 on 2017/5/11. */ -BI.MultiSelectCheckSelectedButton = BI.inherit(BI.Single, { - - _const: { - checkSelected: BI.i18nText("BI-Check_Selected") - }, - +BI.MultiSelectTree = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectCheckSelectedButton.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-check-selected-button bi-high-light", + return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-tree", itemsCreator: BI.emptyFn }); }, _init: function () { - BI.MultiSelectCheckSelectedButton.superclass._init.apply(this, arguments); + BI.MultiSelectTree.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.numberCounter = BI.createWidget({ - type: "bi.text_button", - element: this, - hgap: 4, - text: "0", - textAlign: "center", - textHeight: 15 - }); - this.numberCounter.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + this.storeValue = {value: {}}; - this.numberCounter.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments); + this.adapter = BI.createWidget({ + type: "bi.multi_select_tree_popup", + itemsCreator: o.itemsCreator }); - - this.numberCounter.element.hover(function () { - self.numberCounter.setTag(self.numberCounter.getText()); - self.numberCounter.setText(self._const.checkSelected); - }, function () { - self.numberCounter.setText(self.numberCounter.getTag()); + this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () { + if (self.searcher.isSearching()) { + self.storeValue = {value: self.searcherPane.getValue()}; + } else { + self.storeValue = {value: self.adapter.getValue()}; + } + self.setSelectedValue(self.storeValue.value); + self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); }); - this.setVisible(false); - if(BI.isNotNull(o.value)){ - this.setValue(o.value); - } - }, - setValue: function (ob) { - var self = this, o = this.options; - ob || (ob = {}); - ob.type || (ob.type = BI.Selection.Multi); - ob.value || (ob.value = []); - if (ob.type === BI.Selection.All) { - o.itemsCreator({ - type: BI.MultiSelectCombo.REQ_GET_DATA_LENGTH - }, function (res) { - var length = res.count - ob.value.length; - BI.nextTick(function () { - self.numberCounter.setText(length); - self.setVisible(length > 0); - }); - }); - return; - } - BI.nextTick(function () { - self.numberCounter.setText(ob.value.length); - self.setVisible(ob.value.length > 0); + // 搜索中的时候用的是parttree,同adapter中的synctree不一样 + this.searcherPane = BI.createWidget({ + type: "bi.multi_tree_search_pane", + cls: "bi-border-left bi-border-right bi-border-bottom", + keywordGetter: function () { + return self.searcher.getKeyword(); + }, + itemsCreator: function (op, callback) { + op.keyword = self.searcher.getKeyword(); + o.itemsCreator(op, callback); + } }); - }, - - getValue: function () { - - } -}); - -BI.MultiSelectCheckSelectedButton.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multi_select_check_selected_button", BI.MultiSelectCheckSelectedButton);/** - * 多选输入框 - * Created by guy on 15/11/3. - * @class BI.MultiSelectEditor - * @extends Widget - */ -BI.MultiSelectEditor = BI.inherit(BI.Widget, { - - _const: { - checkSelected: BI.i18nText("BI-Check_Selected") - }, + this.searcherPane.setVisible(false); - _defaultConfig: function () { - return BI.extend(BI.MultiSelectEditor.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-editor", - el: {} + this.searcher = BI.createWidget({ + type: "bi.searcher", + isAutoSearch: false, + isAutoSync: false, + onSearch: function (op, callback) { + callback({ + keyword: self.searcher.getKeyword() + }); + }, + adapter: this.adapter, + popup: this.searcherPane, + masker: false, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); + // self.storeValue = {value: self.adapter.getValue()}; + // self.searcherPane.setSelectedValue(self.storeValue.value); + } + }, { + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + // self.storeValue = {value: self.searcherPane.getValue()}; + // self.adapter.setSelectedValue(self.storeValue.value); + BI.nextTick(function () { + self.adapter.populate(); + }); + } + }, { + eventName: BI.Searcher.EVENT_CHANGE, + action: function () { + if (self.searcher.isSearching()) { + self.storeValue = {value: self.searcherPane.getValue()}; + } else { + self.storeValue = {value: self.adapter.getValue()}; + } + self.setSelectedValue(self.storeValue.value); + self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + self._showAdapter(); + } + }] }); - }, - _init: function () { - BI.MultiSelectEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget(o.el, { - type: "bi.state_editor", + BI.createWidget({ + type: "bi.vtape", element: this, - height: o.height, - watermark: BI.i18nText("BI-Basic_Search"), - allowBlank: true, - value: o.value + items: [{ + el: this.searcher, + height: 24 + }, { + el: this.adapter, + height: "fill" + }] }); - - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] }); - this.editor.on(BI.StateEditor.EVENT_PAUSE, function () { - self.fireEvent(BI.MultiSelectEditor.EVENT_PAUSE); - }); - this.editor.on(BI.StateEditor.EVENT_CLICK_LABEL, function () { + }, - }); + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); }, - focus: function () { - this.editor.focus(); + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); }, - blur: function () { - this.editor.blur(); + resize: function () { + }, - setState: function (state) { - this.editor.setState(state); + setSelectedValue: function (v) { + this.storeValue.value = v || {}; + this.adapter.setSelectedValue(v); + this.searcherPane.setSelectedValue(v); + this.searcher.setValue({ + value: v || {} + }); }, setValue: function (v) { - this.editor.setValue(v); + this.adapter.setValue(v); }, - getValue: function () { - var v = this.editor.getState(); - if (BI.isArray(v) && v.length > 0) { - return v[v.length - 1]; - } - return ""; - + stopSearch: function () { + this.searcher.stopSearch(); }, - getKeywords: function () { - var val = this.editor.getLastValidValue(); - var keywords = val.match(/[\S]+/g); - if (BI.isEndWithBlank(val)) { - return keywords.concat([" "]); - } - return keywords; + updateValue: function (v) { + this.adapter.updateValue(v); }, - populate: function (items) { + getValue: function () { + return this.storeValue.value; + }, + populate: function () { + this.searcher.populate.apply(this.searcher, arguments); + this.adapter.populate.apply(this.adapter, arguments); } }); -BI.MultiSelectEditor.EVENT_PAUSE = "MultiSelectEditor.EVENT_PAUSE"; -BI.shortcut("bi.multi_select_editor", BI.MultiSelectEditor);/** - * searcher - * Created by guy on 15/11/3. - * @class BI.MultiSelectSearcher - * @extends Widget +BI.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree);/** + * Created by zcf on 2016/12/21. */ -BI.MultiSelectSearcher = BI.inherit(BI.Widget, { - +BI.MultiSelectTreePopup = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectSearcher.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-searcher", - itemsCreator: BI.emptyFn, - el: {}, - popup: {}, - valueFormatter: BI.emptyFn, - adapter: null, - masker: {} + return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-tree-popup bi-border-left bi-border-right bi-border-bottom", + itemsCreator: BI.emptyFn }); }, - _init: function () { - BI.MultiSelectSearcher.superclass._init.apply(this, arguments); + BI.MultiSelectTreePopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.editor = BI.createWidget(o.el, { - type: "bi.multi_select_editor", - height: o.height - }); - - this.searcher = BI.createWidget({ - type: "bi.searcher", + this.popup = BI.createWidget({ + type: "bi.async_tree", element: this, - height: o.height, - isAutoSearch: false, - isAutoSync: false, - onSearch: function (op, callback) { - callback(); - }, - el: this.editor, - - popup: BI.extend({ - type: "bi.multi_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); - }, - value: o.value - }, o.popup), - - adapter: o.adapter, - masker: o.masker - }); - this.searcher.on(BI.Searcher.EVENT_START, function () { - self.fireEvent(BI.MultiSelectSearcher.EVENT_START); - }); - this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { - if (this.hasMatched()) { - - } - self.fireEvent(BI.MultiSelectSearcher.EVENT_PAUSE); - }); - this.searcher.on(BI.Searcher.EVENT_STOP, function () { - self.fireEvent(BI.MultiSelectSearcher.EVENT_STOP); + itemsCreator: o.itemsCreator }); - this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectSearcher.EVENT_CHANGE, arguments); + this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () { + self.fireEvent(BI.MultiSelectTreePopup.EVENT_AFTER_INIT); }); - this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { - var keywords = this.getKeywords(); - self.fireEvent(BI.MultiSelectSearcher.EVENT_SEARCHING, keywords); + this.popup.on(BI.TreeView.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectTreePopup.EVENT_CHANGE); }); - if(BI.isNotNull(o.value)){ - this.setState(o.value); - } - }, - - adjustView: function () { - this.searcher.adjustView(); - }, - - 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(); - }, - - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + return this.popup.hasChecked(); }, - setState: function (ob) { - var o = this.options; - ob || (ob = {}); - ob.value || (ob.value = []); - if (ob.type === BI.Selection.All) { - if (ob.value.length === 0) { - this.editor.setState(BI.Selection.All); - } else if (BI.size(ob.assist) <= 20) { - var state = ""; - BI.each(ob.assist, function (i, v) { - if (i === 0) { - state += "" + (o.valueFormatter(v + "") || v); - } else { - state += "," + (o.valueFormatter(v + "") || v); - } - }); - this.editor.setState(state); - } else { - this.editor.setState(BI.Selection.Multi); - } - } else { - if (ob.value.length === 0) { - this.editor.setState(BI.Selection.None); - } else if (BI.size(ob.value) <= 20) { - var state = ""; - BI.each(ob.value, function (i, v) { - if (i === 0) { - state += "" + (o.valueFormatter(v + "") || v); - } else { - state += "," + (o.valueFormatter(v + "") || v); - } - }); - this.editor.setState(state); - } else { - this.editor.setState(BI.Selection.Multi); - } - } + getValue: function () { + return this.popup.getValue(); }, - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); + setValue: function (v) { + v || (v = {}); + this.popup.setValue(v); }, - getKey: function () { - return this.editor.getValue(); + setSelectedValue: function (v) { + v || (v = {}); + this.popup.setSelectedValue(v); }, - getValue: function () { - return this.searcher.getValue(); + updateValue: function (v) { + this.popup.updateValue(v); + this.popup.refresh(); }, - populate: function (items) { - this.searcher.populate.apply(this.searcher, arguments); + populate: function (config) { + this.popup.stroke(config); } -}); -BI.MultiSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.MultiSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiSelectSearcher.EVENT_START = "EVENT_START"; -BI.MultiSelectSearcher.EVENT_STOP = "EVENT_STOP"; -BI.MultiSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE"; -BI.MultiSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING"; -BI.shortcut("bi.multi_select_searcher", BI.MultiSelectSearcher);/** - * 查看已选switcher - * Created by guy on 15/11/3. - * @class BI.MultiSelectCheckSelectedSwitcher - * @extends Widget +}); +BI.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT"; +BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE"; +BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);/** + * + * @class BI.MultiTreeCheckPane + * @extends BI.Pane */ -BI.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, { +BI.MultiTreeCheckPane = BI.inherit(BI.Pane, { - _defaultConfig: function () { - return BI.extend(BI.MultiSelectCheckSelectedSwitcher.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-check-selected-switcher", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - el: {}, - popup: {}, - adapter: null, - masker: {} + constants: { + height: 25, + lgap: 10, + tgap: 5 + }, + + _defaultConfig: function () { + return BI.extend(BI.MultiTreeCheckPane.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-check-pane bi-background", + onClickContinueSelect: BI.emptyFn }); }, _init: function () { - BI.MultiSelectCheckSelectedSwitcher.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.MultiTreeCheckPane.superclass._init.apply(this, arguments); - this.button = BI.createWidget(o.el, { - type: "bi.multi_select_check_selected_button", - itemsCreator: o.itemsCreator, - value: o.value + var self = this, opts = this.options; + + this.selectedValues = {}; + + var continueSelect = BI.createWidget({ + type: "bi.text_button", + text: BI.i18nText("BI-Continue_Select"), + cls: "multi-tree-check-selected" }); - this.button.on(BI.Events.VIEW, function () { - self.fireEvent(BI.Events.VIEW, arguments); + continueSelect.on(BI.TextButton.EVENT_CHANGE, function () { + opts.onClickContinueSelect(); + BI.nextTick(function () { + self.empty(); + }); }); - this.switcher = BI.createWidget({ - type: "bi.switcher", - toggle: false, - element: this, - el: this.button, - popup: BI.extend({ - type: "bi.multi_select_check_pane", - valueFormatter: o.valueFormatter, - itemsCreator: o.itemsCreator, - onClickContinueSelect: function () { - self.switcher.hideView(); + + var backToPopup = BI.createWidget({ + type: "bi.left", + cls: "multi-tree-continue-select", + items: [ + { + el: { + type: "bi.label", + text: BI.i18nText("BI-Selected_Data") + }, + lgap: this.constants.lgap, + tgap: this.constants.tgap }, - value: o.value - }, o.popup), - adapter: o.adapter, - masker: o.masker + { + el: continueSelect, + lgap: this.constants.lgap, + tgap: this.constants.tgap + }] }); - this.switcher.on(BI.Switcher.EVENT_TRIGGER_CHANGE, function () { - self.fireEvent(BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE); + + this.display = BI.createWidget({ + type: "bi.display_tree", + cls: "bi-multi-tree-display", + itemsCreator: function (op, callback) { + op.type = BI.TreeView.REQ_TYPE_GET_SELECTED_DATA; + opts.itemsCreator(op, callback); + }, + value: (opts.value || {}).value }); - this.switcher.on(BI.Switcher.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW); + + this.display.on(BI.Events.AFTERINIT, function () { + self.fireEvent(BI.Events.AFTERINIT); }); - this.switcher.on(BI.Switcher.EVENT_AFTER_POPUPVIEW, function () { - var me = this; - BI.nextTick(function () { - me.populate(); - }); + + this.display.on(BI.TreeView.EVENT_INIT, function () { + backToPopup.setVisible(false); }); - this.switcher.element.click(function (e) { - e.stopPropagation(); + this.display.on(BI.TreeView.EVENT_AFTERINIT, function () { + backToPopup.setVisible(true); }); - }, - adjustView: function () { - this.switcher.adjustView(); - }, + BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + height: this.constants.height, + el: backToPopup + }, { + height: "fill", + el: this.display + }] + }); - hideView: function () { - this.switcher.empty(); - this.switcher.hideView(); }, - setAdapter: function (adapter) { - this.switcher.setAdapter(adapter); + empty: function () { + this.display.empty(); }, - setValue: function (v) { - this.switcher.setValue(v); + populate: function (configs) { + this.display.stroke(configs); }, - setButtonChecked: function (v) { - this.button.setValue(v); + setValue: function (v) { + v || (v = {}); + this.display.setSelectedValue(v.value); }, getValue: function () { - }, - - populate: function (items) { - this.switcher.populate.apply(this.switcher, arguments); } }); -BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE = "MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE"; -BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.multi_select_check_selected_switcher", BI.MultiSelectCheckSelectedSwitcher);/** - * Created by zcf_1 on 2017/5/2. +BI.MultiTreeCheckPane.EVENT_CONTINUE_CLICK = "EVENT_CONTINUE_CLICK"; + + +BI.shortcut("bi.multi_tree_check_pane", BI.MultiTreeCheckPane);/** + * + * @class BI.MultiTreeCombo + * @extends BI.Single */ -BI.MultiSelectInsertList = BI.inherit(BI.Widget, { + +BI.MultiTreeCombo = BI.inherit(BI.Single, { + + constants: { + offset: { + top: 1, + left: 1, + right: 2, + bottom: 33 + } + }, + _defaultConfig: function () { - return BI.extend(BI.MultiSelectInsertList.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-insert-list", + return BI.extend(BI.MultiTreeCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-combo", itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn + height: 25 }); }, + _init: function () { - BI.MultiSelectInsertList.superclass._init.apply(this, arguments); + BI.MultiTreeCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.storeValue = {}; - var assertShowValue = function () { - BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); - // self.trigger.setValue(self.storeValue); - }; + var isInit = false; + var want2showCounter = false; - this.adapter = BI.createWidget({ - type: "bi.multi_select_loader", - cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom", - itemsCreator: o.itemsCreator, - valueFormatter: o.valueFormatter, - logic: { - dynamic: false + this.storeValue = {value: o.value || {}}; + + this.trigger = BI.createWidget({ + type: "bi.multi_select_trigger", + height: o.height, + // adapter: this.popup, + masker: { + offset: this.constants.offset }, - // onLoaded: o.onLoaded, - el: {} - }); - this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { - self.storeValue = this.getValue(); - assertShowValue(); - self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); + searcher: { + type: "bi.multi_tree_searcher", + itemsCreator: o.itemsCreator + }, + switcher: { + el: { + type: "bi.multi_tree_check_selected_button" + }, + popup: { + type: "bi.multi_tree_check_pane", + itemsCreator: o.itemsCreator + } + }, + value: {value: o.value || {}} + }); - this.searcherPane = BI.createWidget({ - type: "bi.multi_select_search_pane", - cls: "bi-border-left bi-border-right bi-border-bottom", - valueFormatter: o.valueFormatter, - keywordGetter: function () { - return self.trigger.getKeyword(); + this.combo = BI.createWidget({ + type: "bi.combo", + toggle: false, + el: this.trigger, + adjustLength: 1, + popup: { + type: "bi.multi_tree_popup_view", + ref: function () { + self.popup = this; + self.trigger.setAdapter(this); + }, + listeners: [{ + eventName: BI.MultiTreePopup.EVENT_AFTERINIT, + action: function () { + self.trigger.getCounter().adjustView(); + isInit = true; + if (want2showCounter === true) { + showCounter(); + } + } + }, { + eventName: BI.MultiTreePopup.EVENT_CHANGE, + action: function () { + change = true; + var val = { + type: BI.Selection.Multi, + value: this.hasChecked() ? this.getValue() : {} + }; + self.trigger.getSearcher().setState(val); + self.trigger.getCounter().setButtonChecked(val); + } + }, { + eventName: BI.MultiTreePopup.EVENT_CLICK_CONFIRM, + action: function () { + self.combo.hideView(); + } + }, { + eventName: BI.MultiTreePopup.EVENT_CLICK_CLEAR, + action: function () { + clear = true; + self.setValue(); + self._defaultState(); + } + }], + itemsCreator: o.itemsCreator, + onLoaded: function () { + BI.nextTick(function () { + self.trigger.getCounter().adjustView(); + self.trigger.getSearcher().adjustView(); + }); + } }, - itemsCreator: function (op, callback) { - op.keyword = self.trigger.getKeyword(); - this.setKeyword(op.keyword); - o.itemsCreator(op, callback); + value: {value: o.value || {}}, + hideChecker: function (e) { + return triggerBtn.element.find(e.target).length === 0; } }); - this.searcherPane.setVisible(false); + + var change = false; + var clear = false; // 标识当前是否点击了清空 - this.trigger = BI.createWidget({ - type: "bi.searcher", - isAutoSearch: false, - isAutoSync: false, - onSearch: function (op, callback) { - callback(); - }, - adapter: this.adapter, - popup: this.searcherPane, - height: 200, - masker: false, - listeners: [{ - eventName: BI.Searcher.EVENT_START, - action: function () { - self._showSearcherPane(); - self._setStartValue(""); - this.setValue(BI.deepClone(self.storeValue)); - } - }, { - eventName: BI.Searcher.EVENT_STOP, - action: function () { - self._showAdapter(); - self._setStartValue(""); - self.adapter.setValue(self.storeValue); - // 需要刷新回到初始界面,否则搜索的结果不能放在最前面 - self.adapter.populate(); - } - }, { - eventName: BI.Searcher.EVENT_PAUSE, - action: function () { - var keyword = this.getKeyword(); - if (this.hasMatched()) { - self._join({ - type: BI.Selection.Multi, - value: [keyword] - }, function () { - if (self.storeValue.type === BI.Selection.Multi) { - self.storeValue.value.pushDistinct(keyword); - } - self._showAdapter(); - self.adapter.setValue(self.storeValue); - self._setStartValue(keyword); - assertShowValue(); - self.adapter.populate(); - self._setStartValue(""); - self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); - }); - } else { - if (self.storeValue.type === BI.Selection.Multi) { - self.storeValue.value.pushDistinct(keyword); - } - self._showAdapter(); - self.adapter.setValue(self.storeValue); - self.adapter.populate(); - if (self.storeValue.type === BI.Selection.Multi) { - self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); - } - } + var isSearching = function () { + return self.trigger.getSearcher().isSearching(); + }; + + var isPopupView = function () { + return self.combo.isViewVisible(); + }; + + this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { + self.storeValue = {value: self.combo.getValue()}; + this.setValue(self.storeValue); + }); + this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { + self.storeValue = {value: this.getValue()}; + self.combo.setValue(self.storeValue); + BI.nextTick(function () { + if (isPopupView()) { + self.combo.populate(); } - }, { - eventName: BI.Searcher.EVENT_SEARCHING, - action: function () { - var keywords = this.getKeyword(); - var last = BI.last(keywords); - keywords = BI.initial(keywords || []); - if (keywords.length > 0) { - self._joinKeywords(keywords, function () { - if (BI.isEndWithBlank(last)) { - self.adapter.setValue(self.storeValue); - assertShowValue(); - self.adapter.populate(); - self._setStartValue(""); - } else { - self.adapter.setValue(self.storeValue); - assertShowValue(); - } - }); + }); + }); + + function showCounter () { + if (isSearching()) { + self.storeValue = {value: self.trigger.getValue()}; + } else if (isPopupView()) { + self.storeValue = {value: self.combo.getValue()}; + } + self.trigger.setValue(self.storeValue); + } + + this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { + if (want2showCounter === false) { + want2showCounter = true; + } + if (isInit === true) { + want2showCounter = null; + showCounter(); + } + }); + this.trigger.on(BI.MultiSelectTrigger.EVENT_TRIGGER_CLICK, function () { + self.combo.toggle(); + }); + this.trigger.on(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + }); + + this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () { + var checked = this.getSearcher().hasChecked(); + var val = { + type: BI.Selection.Multi, + value: checked ? {1: 1} : {} + }; + this.getSearcher().setState(checked ? BI.Selection.Multi : BI.Selection.None); + this.getCounter().setButtonChecked(val); + }); + + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + if (isSearching()) { + return; + } + if (change === true) { + self.storeValue = {value: self.combo.getValue()}; + change = false; + } + self.combo.setValue(self.storeValue); + self.populate(); + + }); + this.combo.on(BI.Combo.EVENT_BEFORE_HIDEVIEW, function () { + if (isSearching()) { + self.trigger.stopEditing(); + self.fireEvent(BI.MultiTreeCombo.EVENT_CONFIRM); + } else { + if (isPopupView()) { + self.trigger.stopEditing(); + self.storeValue = {value: self.combo.getValue()}; + if (clear === true) { + self.storeValue = {value: {}}; } + self.fireEvent(BI.MultiTreeCombo.EVENT_CONFIRM); } + } + clear = false; + change = false; + }); + + var triggerBtn = BI.createWidget({ + type: "bi.trigger_icon_button", + width: o.height, + height: o.height, + cls: "multi-select-trigger-icon-button" + }); + triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { + self.trigger.getCounter().hideView(); + 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 }, { - eventName: BI.Searcher.EVENT_CHANGE, - action: function (value, obj) { - if (obj instanceof BI.MultiSelectBar) { - self._joinAll(this.getValue(), function () { - assertShowValue(); - self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); - }); - } else { - self._join(this.getValue(), function () { - assertShowValue(); - self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); - }); - } - } + el: triggerBtn, + right: 0, + top: 0, + bottom: 0 }] }); + }, + + _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 + }); + }, - BI.createWidget({ - type: "bi.vtape", - element: this, - items: [{ - el: this.trigger, - height: 24 - }, { - el: this.adapter, - height: "fill" - }] + _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 || {} }); - BI.createWidget({ - type: "bi.absolute", + + this.popupView = BI.createWidget({ + type: "bi.multi_popup_view", element: this, - items: [{ - el: this.searcherPane, - top: 30, - bottom: 0, - left: 0, - right: 0 - }] + 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); }); + }, - _showAdapter: function () { - this.adapter.setVisible(true); - this.searcherPane.setVisible(false); + getValue: function () { + return this.tree.getValue(); }, - _showSearcherPane: function () { - this.searcherPane.setVisible(true); - this.adapter.setVisible(false); + setValue: function (v) { + v || (v = {}); + this.tree.setSelectedValue(v.value); }, - _defaultState: function () { - this.trigger.stopEditing(); + populate: function (config) { + this.tree.stroke(config); }, - _assertValue: function (val) { - val || (val = {}); - val.type || (val.type = BI.Selection.Multi); - val.value || (val.value = []); + hasChecked: function () { + return this.tree.hasChecked(); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + resetHeight: function (h) { + this.popupView.resetHeight(h); }, - _joinKeywords: function (keywords, callback) { - var self = this, o = this.options; - this._assertValue(this.storeValue); - if (!this._allData) { - o.itemsCreator({ - type: BI.MultiSelectInsertList.REQ_GET_ALL_DATA - }, function (ob) { - self._allData = BI.map(ob.items, "value"); - digest(self._allData); - }); - } else { - digest(this._allData); - } + resetWidth: function (w) { + this.popupView.resetWidth(w); + } +}); - function digest (items) { - var selectedMap = self._makeMap(items); - BI.each(keywords, function (i, val) { - if (BI.isNotNull(selectedMap[val])) { - self.storeValue.value[self.storeValue.type === BI.Selection.Multi ? "pushDistinct" : "remove"](val); - } - }); - callback(); - } - }, +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"; - _joinAll: function (res, callback) { - var self = this, o = this.options; - this._assertValue(res); - o.itemsCreator({ - type: BI.MultiSelectInsertList.REQ_GET_ALL_DATA, - keyword: self.trigger.getKeyword() - }, 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)); - 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)); - callback(); + +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 }); }, - _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)); - callback(); - return; - } - this._joinAll(res, callback); - }, + _init: function () { + BI.MultiTreeSearchPane.superclass._init.apply(this, arguments); - _setStartValue: function (value) { - this._startValue = value; - this.adapter.setStartValue(value); - }, + var self = this, opts = this.options; - isAllSelected: function () { - return this.adapter.isAllSelected(); + 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); + }); }, - resize: function () { - // this.trigger.getCounter().adjustView(); - // this.trigger.adjustView(); + hasChecked: function () { + return this.partTree.hasChecked(); }, + setValue: function (v) { - this.storeValue = v || {}; - this._assertValue(this.storeValue); - this.adapter.setValue(this.storeValue); - this.trigger.setValue(this.storeValue); + this.setSelectedValue(v.value); + }, + + setSelectedValue: function (v) { + v || (v = {}); + this.partTree.setSelectedValue(v); }, getValue: function () { - return BI.deepClone(this.storeValue); + return this.partTree.getValue(); }, - populate: function () { - this._count = null; - this._allData = null; - this.adapter.populate.apply(this.adapter, arguments); - this.trigger.populate.apply(this.trigger, arguments); + empty: function () { + this.partTree.empty(); + }, + + populate: function (op) { + this.partTree.stroke.apply(this.partTree, arguments); } }); -BI.extend(BI.MultiSelectInsertList, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 -}); +BI.MultiTreeSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; -BI.MultiSelectInsertList.EVENT_CHANGE = "BI.MultiSelectInsertList.EVENT_CHANGE"; -BI.shortcut("bi.multi_select_insert_list", BI.MultiSelectInsertList);/** - * Created by zcf_1 on 2017/5/2. +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.MultiSelectList = BI.inherit(BI.Widget, { +BI.MultiTreeCheckSelectedButton = BI.inherit(BI.Single, { + + _const: { + checkSelected: BI.i18nText("BI-Check_Selected") + }, + _defaultConfig: function () { - return BI.extend(BI.MultiSelectList.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-list", - itemsCreator: BI.emptyFn, - valueFormatter: 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.MultiSelectList.superclass._init.apply(this, arguments); + 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 + }); - var self = this, o = this.options; - this.storeValue = {}; + 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 assertShowValue = function () { - BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); - // self.trigger.setValue(self.storeValue); - }; + this.checkSelected.on(BI.TextButton.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments); + }); - this.adapter = BI.createWidget({ - type: "bi.multi_select_loader", - cls: "popup-multi-select-list bi-border-left bi-border-right bi-border-bottom", - itemsCreator: o.itemsCreator, - valueFormatter: o.valueFormatter, - logic: { - dynamic: false - }, - // onLoaded: o.onLoaded, - el: {} + BI.createWidget({ + type: "bi.horizontal", + element: this, + items: [this.indicator, this.checkSelected] }); - this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); - }); + + this.element.hover(function () { + self.indicator.setVisible(false); + self.checkSelected.setVisible(true); + }, function () { + self.indicator.setVisible(true); + self.checkSelected.setVisible(false); }); + this.setVisible(false); + }, - this.searcherPane = BI.createWidget({ - type: "bi.multi_select_search_pane", - cls: "bi-border-left bi-border-right bi-border-bottom", - valueFormatter: o.valueFormatter, - keywordGetter: function () { - return self.trigger.getKeyword(); - }, - itemsCreator: function (op, callback) { - op.keyword = self.trigger.getKeyword(); - this.setKeyword(op.keyword); - o.itemsCreator(op, callback); + 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.searcherPane.setVisible(false); - this.trigger = BI.createWidget({ + this.searcher = BI.createWidget({ type: "bi.searcher", + element: this, isAutoSearch: false, isAutoSync: false, onSearch: function (op, callback) { - callback(); + callback({ + keyword: self.editor.getValue() + }); }, - adapter: this.adapter, - popup: this.searcherPane, - height: 200, - masker: false, - listeners: [{ - eventName: BI.Searcher.EVENT_START, - action: function () { - self._showSearcherPane(); - self._setStartValue(""); - this.setValue(BI.deepClone(self.storeValue)); - } - }, { - eventName: BI.Searcher.EVENT_STOP, - action: function () { - self._showAdapter(); - self._setStartValue(""); - self.adapter.setValue(self.storeValue); - // 需要刷新回到初始界面,否则搜索的结果不能放在最前面 - self.adapter.populate(); - } - }, { - eventName: BI.Searcher.EVENT_PAUSE, - action: function () { - var keyword = this.getKeyword(); - if (this.hasMatched()) { - self._join({ - type: BI.Selection.Multi, - value: [keyword] - }, function () { - self._showAdapter(); - self.adapter.setValue(self.storeValue); - self._setStartValue(keyword); - assertShowValue(); - self.adapter.populate(); - self._setStartValue(""); - self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); - }); - } - } - }, { - eventName: BI.Searcher.EVENT_SEARCHING, - action: function () { - var keywords = this.getKeyword(); - var last = BI.last(keywords); - keywords = BI.initial(keywords || []); - if (keywords.length > 0) { - self._joinKeywords(keywords, function () { - if (BI.isEndWithBlank(last)) { - self.adapter.setValue(self.storeValue); - assertShowValue(); - self.adapter.populate(); - self._setStartValue(""); - } else { - self.adapter.setValue(self.storeValue); - assertShowValue(); - } - }); - } - } - }, { - eventName: BI.Searcher.EVENT_CHANGE, - action: function (value, obj) { - if (obj instanceof BI.MultiSelectBar) { - self._joinAll(this.getValue(), function () { - assertShowValue(); - self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); - }); - } else { - self._join(this.getValue(), function () { - assertShowValue(); - self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); - }); - } - } - }] - }); + el: this.editor, - BI.createWidget({ - type: "bi.vtape", - element: this, - items: [{ - el: this.trigger, - height: 24 - }, { - el: this.adapter, - height: "fill" - }] + 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 }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.searcherPane, - top: 30, - bottom: 0, - left: 0, - right: 0 - }] + 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()) { + + } + 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); + } }, - _showAdapter: function () { - this.adapter.setVisible(true); - this.searcherPane.setVisible(false); + adjustView: function () { + this.searcher.adjustView(); }, - _showSearcherPane: function () { - this.searcherPane.setVisible(true); - this.adapter.setVisible(false); + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - _defaultState: function () { - this.trigger.stopEditing(); + isSearching: function () { + return this.searcher.isSearching(); }, - _assertValue: function (val) { - val || (val = {}); - val.type || (val.type = BI.Selection.Multi); - val.value || (val.value = []); + stopSearch: function () { + this.searcher.stopSearch(); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + getKeyword: function () { + return this.editor.getValue(); }, - _joinKeywords: function (keywords, callback) { - var self = this, o = this.options; - this._assertValue(this.storeValue); - if (!this._allData) { - o.itemsCreator({ - type: BI.MultiSelectList.REQ_GET_ALL_DATA - }, function (ob) { - self._allData = BI.map(ob.items, "value"); - digest(self._allData); - }); + 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 { - digest(this._allData); + var text = ""; + BI.each(ob.value, function (name, children) { + var childNodes = getChildrenNode(children); + text += name + (childNodes === "" ? "" : (":" + childNodes)) + "; "; + }); + this.editor.setState(text); } - function digest (items) { - var selectedMap = self._makeMap(items); - BI.each(keywords, function (i, val) { - if (BI.isNotNull(selectedMap[val])) { - self.storeValue.value[self.storeValue.type === BI.Selection.Multi ? "pushDistinct" : "remove"](val); - } + 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 ? "" : ","); }); - self._adjust(callback); + return text; } }, - _joinAll: function (res, callback) { - var self = this, o = this.options; - this._assertValue(res); - o.itemsCreator({ - type: BI.MultiSelectList.REQ_GET_ALL_DATA, - keyword: self.trigger.getKeyword() - }, 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); - }); + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); }, - _adjust: function (callback) { - var self = this, o = this.options; - if (!this._count) { - o.itemsCreator({ - type: BI.MultiSelectList.REQ_GET_DATA_LENGTH - }, function (res) { - self._count = res.count; - adjust(); - callback(); - }); - } else { - adjust(); - callback(); - } + getKey: function () { + return this.editor.getValue(); + }, - function adjust () { - if (self.storeValue.type === BI.Selection.All && self.storeValue.value.length >= self._count) { - self.storeValue = { - type: BI.Selection.Multi, - value: [] - }; - } else if (self.storeValue.type === BI.Selection.Multi && self.storeValue.value.length >= self._count) { - self.storeValue = { - type: BI.Selection.All, - value: [] - }; - } - } + getValue: function () { + return this.searcher.getValue(); }, - _join: function (res, callback) { + 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 + }); + }, + + _init: function () { + BI.NumberEditor.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; - } - this._joinAll(res, callback); + 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); + }); + 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 + }] + }); }, - _setStartValue: function (value) { - this._startValue = value; - this.adapter.setStartValue(value); + focus: function () { + this.editor.focus(); }, - isAllSelected: function () { - return this.adapter.isAllSelected(); + // 微调 + _finetuning: function (add) { + var v = BI.parseFloat(this.getValue()); + this.setValue(v.add(add)); }, - resize: function () { - // this.trigger.getCounter().adjustView(); - // this.trigger.adjustView(); + setUpEnable: function (v) { + this.topBtn.setEnable(!!v); }, - setValue: function (v) { - this.storeValue = v || {}; - this._assertValue(this.storeValue); - this.adapter.setValue(this.storeValue); - this.trigger.setValue(this.storeValue); + + setDownEnable: function (v) { + this.bottomBtn.setEnable(!!v); }, getValue: function () { - return BI.deepClone(this.storeValue); + return this.options.value; }, - populate: function () { - this._count = null; - this._allData = null; - this.adapter.populate.apply(this.adapter, arguments); - this.trigger.populate.apply(this.trigger, arguments); + setValue: function (v) { + var o = this.options; + o.value = v; + this.editor.setValue(o.valueFormatter(v)); } -}); -BI.extend(BI.MultiSelectList, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 }); - -BI.MultiSelectList.EVENT_CHANGE = "BI.MultiSelectList.EVENT_CHANGE"; -BI.shortcut("bi.multi_select_list", BI.MultiSelectList);/** - * Created by zcf_1 on 2017/5/11. +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.MultiSelectTree = BI.inherit(BI.Widget, { +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.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-tree", - 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.MultiSelectTree.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = {value: {}}; + 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.adapter = BI.createWidget({ - type: "bi.multi_select_tree_popup", - itemsCreator: o.itemsCreator + this.smallTip = BI.createWidget({ + type: "bi.label", + text: o.numTip, + height: o.height - 2, + invisible: true }); - this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () { - if (self.searcher.isSearching()) { - self.storeValue = {value: self.searcherPane.getValue()}; - } else { - self.storeValue = {value: self.adapter.getValue()}; - } - self.setSelectedValue(self.storeValue.value); - self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); + BI.createWidget({ + type: "bi.absolute", + element: this.smallEditor.element, + items: [{ + el: this.smallTip, + top: 0, + right: 5 + }] }); - // 搜索中的时候用的是parttree,同adapter中的synctree不一样 - this.searcherPane = BI.createWidget({ - type: "bi.multi_tree_search_pane", - cls: "bi-border-left bi-border-right bi-border-bottom", - keywordGetter: function () { - return self.searcher.getKeyword(); + 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; }, - itemsCreator: function (op, callback) { - op.keyword = self.searcher.getKeyword(); - o.itemsCreator(op, callback); - } + 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.searcherPane.setVisible(false); - this.searcher = BI.createWidget({ - type: "bi.searcher", - isAutoSearch: false, - isAutoSync: false, - onSearch: function (op, callback) { - callback({ - keyword: self.searcher.getKeyword() - }); - }, - adapter: this.adapter, - popup: this.searcherPane, - masker: false, - listeners: [{ - eventName: BI.Searcher.EVENT_START, - action: function () { - self._showSearcherPane(); - // self.storeValue = {value: self.adapter.getValue()}; - // self.searcherPane.setSelectedValue(self.storeValue.value); - } - }, { - eventName: BI.Searcher.EVENT_STOP, - action: function () { - self._showAdapter(); - // self.storeValue = {value: self.searcherPane.getValue()}; - // self.adapter.setSelectedValue(self.storeValue.value); - BI.nextTick(function () { - self.adapter.populate(); - }); - } + 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 + }] + }); + + // 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 }, { - eventName: BI.Searcher.EVENT_CHANGE, - action: function () { - if (self.searcher.isSearching()) { - self.storeValue = {value: self.searcherPane.getValue()}; - } else { - self.storeValue = {value: self.adapter.getValue()}; - } - self.setSelectedValue(self.storeValue.value); - self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); - } + text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", + value: 1, + iconCls: "less-equal-font" + }] + }); + 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 }, { - eventName: BI.Searcher.EVENT_PAUSE, - action: function () { - self._showAdapter(); - } + text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", + value: 1, + iconCls: "less-equal-font" }] }); - - BI.createWidget({ - type: "bi.vtape", - element: this, + 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: this.searcher, - height: 24 + el: self.smallEditor }, { - el: this.adapter, - height: "fill" + el: self.smallCombo, + width: c.width - c.border * 2 }] + }); - BI.createWidget({ - type: "bi.absolute", - element: this, + this.right = BI.createWidget({ + type: "bi.htape", items: [{ - el: this.searcherPane, - top: 30, - bottom: 0, - left: 0, - right: 0 + el: self.bigCombo, + width: c.width - c.border * 2 + }, { + el: self.bigEditor }] }); + + 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.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); }, - _showAdapter: function () { - this.adapter.setVisible(true); - this.searcherPane.setVisible(false); + _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 ""; + + } + 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 ""; + + + + + }, - _showSearcherPane: function () { - this.searcherPane.setVisible(true); - this.adapter.setVisible(false); + _setTitle: function (v) { + var self = this; + self.bigEditor.setTitle(v); + self.smallEditor.setTitle(v); + self.label.setTitle(v); }, - resize: function () { + _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; + } + }); }, - - setSelectedValue: function (v) { - this.storeValue.value = v || {}; - this.adapter.setSelectedValue(v); - this.searcherPane.setSelectedValue(v); - this.searcher.setValue({ - value: v || {} + _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(""); + } }); }, - setValue: function (v) { - this.adapter.setValue(v); + _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); + }); }, - stopSearch: function () { - this.searcher.stopSearch(); - }, - updateValue: function (v) { - this.adapter.updateValue(v); + _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); + } + }); }, - getValue: function () { - return this.storeValue.value; - }, - populate: function () { - this.searcher.populate.apply(this.searcher, arguments); - this.adapter.populate.apply(this.adapter, arguments); - } -}); -BI.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE"; -BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree);/** - * Created by zcf on 2016/12/21. - */ -BI.MultiSelectTreePopup = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-tree-popup bi-border-left bi-border-right bi-border-bottom", - itemsCreator: BI.emptyFn + _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); }); }, - _init: function () { - BI.MultiSelectTreePopup.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.popup = BI.createWidget({ - type: "bi.async_tree", - element: this, - itemsCreator: o.itemsCreator - }); - this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () { - self.fireEvent(BI.MultiSelectTreePopup.EVENT_AFTER_INIT); - }); - this.popup.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectTreePopup.EVENT_CHANGE); + + _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); + } }); }, - hasChecked: function () { - return this.popup.hasChecked(); + isStateValid: function () { + return this.options.validation === "valid"; }, - getValue: function () { - return this.popup.getValue(); + setMinEnable: function (b) { + this.smallEditor.setEnable(b); }, - setValue: function (v) { - v || (v = {}); - this.popup.setValue(v); + setCloseMinEnable: function (b) { + this.smallCombo.setEnable(b); }, - setSelectedValue: function (v) { - v || (v = {}); - this.popup.setSelectedValue(v); + setMaxEnable: function (b) { + this.bigEditor.setEnable(b); }, - updateValue: function (v) { - this.popup.updateValue(v); - this.popup.refresh(); + setCloseMaxEnable: function (b) { + this.bigCombo.setEnable(b); }, - populate: function (config) { - this.popup.stroke(config); - } + showNumTip: function () { + this.smallTip.setVisible(true); + this.bigTip.setVisible(true); + }, -}); -BI.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT"; -BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE"; -BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);/** - * - * @class BI.MultiTreeCheckPane - * @extends BI.Pane - */ -BI.MultiTreeCheckPane = BI.inherit(BI.Pane, { + hideNumTip: function () { + this.smallTip.setVisible(false); + this.bigTip.setVisible(false); + }, - constants: { - height: 25, - lgap: 10, - tgap: 5 + setNumTip: function (numTip) { + this.smallTip.setText(numTip); + this.bigTip.setText(numTip); }, - _defaultConfig: function () { - return BI.extend(BI.MultiTreeCheckPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-check-pane bi-background", - onClickContinueSelect: BI.emptyFn - }); + getNumTip: function () { + return this.smallTip.getText(); }, - _init: function () { - BI.MultiTreeCheckPane.superclass._init.apply(this, arguments); + setValue: function (data) { + data = data || {}; + var self = this, combo_value; + if (BI.isNumeric(data.min) || BI.isEmptyString(data.min)) { + self.smallEditor.setValue(data.min); + } - var self = this, opts = this.options; + if (!BI.isNotNull(data.min)) { + self.smallEditor.setValue(""); + } - this.selectedValues = {}; + if (BI.isNumeric(data.max) || BI.isEmptyString(data.max)) { + self.bigEditor.setValue(data.max); + } - var continueSelect = BI.createWidget({ - type: "bi.text_button", - text: BI.i18nText("BI-Continue_Select"), - cls: "multi-tree-check-selected" - }); - continueSelect.on(BI.TextButton.EVENT_CHANGE, function () { - opts.onClickContinueSelect(); - BI.nextTick(function () { - self.empty(); - }); - }); + if (!BI.isNotNull(data.max)) { + self.bigEditor.setValue(""); + } - var backToPopup = BI.createWidget({ - type: "bi.left", - cls: "multi-tree-continue-select", - items: [ - { - el: { - type: "bi.label", - text: BI.i18nText("BI-Selected_Data") - }, - lgap: this.constants.lgap, - tgap: this.constants.tgap - }, - { - el: continueSelect, - lgap: this.constants.lgap, - tgap: this.constants.tgap - }] - }); + if (!BI.isNull(data.closemin)) { + if (data.closemin === true) { + combo_value = 1; + } else { + combo_value = 0; + } + self.smallCombo.setValue(combo_value); + } - this.display = BI.createWidget({ - type: "bi.display_tree", - cls: "bi-multi-tree-display", - itemsCreator: function (op, callback) { - op.type = BI.TreeView.REQ_TYPE_GET_SELECTED_DATA; - opts.itemsCreator(op, callback); - }, - value: (opts.value || {}).value - }); + if (!BI.isNull(data.closemax)) { + if (data.closemax === true) { + combo_value = 1; + } else { + combo_value = 0; + } + self.bigCombo.setValue(combo_value); + } + }, - this.display.on(BI.Events.AFTERINIT, function () { - self.fireEvent(BI.Events.AFTERINIT); - }); - this.display.on(BI.TreeView.EVENT_INIT, function () { - backToPopup.setVisible(false); - }); + 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; + } - this.display.on(BI.TreeView.EVENT_AFTERINIT, function () { - backToPopup.setVisible(true); + if (maxComboValue[0] === 0) { + value.closemax = false; + } else { + value.closemax = true; + } + 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: "" }); + }, - BI.createWidget({ - type: "bi.vtape", + _init: function () { + BI.PageTableCell.superclass._init.apply(this, arguments); + var label = BI.createWidget({ + type: "bi.label", element: this, - items: [{ - height: this.constants.height, - el: backToPopup - }, { - height: "fill", - el: this.display - }] + 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); + } + } +}); - empty: function () { - this.display.empty(); - }, +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, { - populate: function (configs) { - this.display.stroke(configs); + _const: { + scrollWidth: 18, + minScrollWidth: 100 }, - setValue: function (v) { - v || (v = {}); - this.display.setSelectedValue(v.value); - }, + _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为数字时可用 - getValue: function () { + 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.MultiTreeCheckPane.EVENT_CONTINUE_CLICK = "EVENT_CONTINUE_CLICK"; + itemsCreator: BI.emptyFn, + isNeedFreeze: false, // 是否需要冻结单元格 + freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 -BI.shortcut("bi.multi_tree_check_pane", BI.MultiTreeCheckPane);/** - * - * @class BI.MultiTreeCombo - * @extends BI.Single - */ + isNeedMerge: false, // 是否需要合并单元格 + mergeCols: [], // 合并的单元格列号 + mergeRule: BI.emptyFn, -BI.MultiTreeCombo = BI.inherit(BI.Single, { + columnSize: [], + minColumnSize: [], + maxColumnSize: [], + headerRowSize: 25, + rowSize: 25, - constants: { - offset: { - top: 1, - left: 1, - right: 2, - bottom: 33 - } - }, + regionColumnSize: [], - _defaultConfig: function () { - return BI.extend(BI.MultiTreeCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-combo", - itemsCreator: BI.emptyFn, - height: 25 + headerCellStyleGetter: BI.emptyFn, + summaryCellStyleGetter: BI.emptyFn, + sequenceCellStyleGetter: BI.emptyFn, + + header: [], + items: [], // 二维数组 + + // 交叉表头 + crossHeader: [], + crossItems: [] }); }, _init: function () { - BI.MultiTreeCombo.superclass._init.apply(this, arguments); - + BI.PageTable.superclass._init.apply(this, arguments); var self = this, o = this.options; + this.hCurr = 1; + this.vCurr = 1; - var isInit = false; - var want2showCounter = false; + this.table = BI.createWidget(o.el, { + type: "bi.sequence_table", + width: o.width, + height: o.height && o.height - 30, - this.storeValue = {value: o.value || {}}; + isNeedResize: true, + isResizeAdapt: false, - this.trigger = BI.createWidget({ - type: "bi.multi_select_trigger", - height: o.height, - // adapter: this.popup, - masker: { - offset: this.constants.offset - }, - searcher: { - type: "bi.multi_tree_searcher", - itemsCreator: o.itemsCreator - }, - switcher: { - el: { - type: "bi.multi_tree_check_selected_button" - }, - popup: { - type: "bi.multi_tree_check_pane", - itemsCreator: o.itemsCreator - } - }, - value: {value: o.value || {}} + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, - }); + isNeedMerge: o.isNeedMerge, + mergeCols: o.mergeCols, + mergeRule: o.mergeRule, - this.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - el: this.trigger, - adjustLength: 1, - popup: { - type: "bi.multi_tree_popup_view", - ref: function () { - self.popup = this; - self.trigger.setAdapter(this); - }, - listeners: [{ - eventName: BI.MultiTreePopup.EVENT_AFTERINIT, - action: function () { - self.trigger.getCounter().adjustView(); - isInit = true; - if (want2showCounter === true) { - showCounter(); - } - } - }, { - eventName: BI.MultiTreePopup.EVENT_CHANGE, - action: function () { - change = true; - var val = { - type: BI.Selection.Multi, - value: this.hasChecked() ? this.getValue() : {} - }; - self.trigger.getSearcher().setState(val); - self.trigger.getCounter().setButtonChecked(val); - } - }, { - eventName: BI.MultiTreePopup.EVENT_CLICK_CONFIRM, - action: function () { - self.combo.hideView(); - } - }, { - eventName: BI.MultiTreePopup.EVENT_CLICK_CLEAR, - action: function () { - clear = true; - self.setValue(); - self._defaultState(); - } - }], - itemsCreator: o.itemsCreator, - onLoaded: function () { - BI.nextTick(function () { - self.trigger.getCounter().adjustView(); - self.trigger.getSearcher().adjustView(); - }); - } - }, - value: {value: o.value || {}}, - hideChecker: function (e) { - return triggerBtn.element.find(e.target).length === 0; - } - }); - - var change = false; - var clear = false; // 标识当前是否点击了清空 + columnSize: o.columnSize, + minColumnSize: o.minColumnSize, + maxColumnSize: o.maxColumnSize, + headerRowSize: o.headerRowSize, + rowSize: o.rowSize, - var isSearching = function () { - return self.trigger.getSearcher().isSearching(); - }; + regionColumnSize: o.regionColumnSize, - var isPopupView = function () { - return self.combo.isViewVisible(); - }; + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter, - this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { - self.storeValue = {value: self.combo.getValue()}; - this.setValue(self.storeValue); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { - self.storeValue = {value: this.getValue()}; - self.combo.setValue(self.storeValue); - BI.nextTick(function () { - if (isPopupView()) { - self.combo.populate(); - } - }); + header: o.header, + items: o.items, + // 交叉表头 + crossHeader: o.crossHeader, + crossItems: o.crossItems }); - function showCounter () { - if (isSearching()) { - self.storeValue = {value: self.trigger.getValue()}; - } else if (isPopupView()) { - self.storeValue = {value: self.combo.getValue()}; - } - self.trigger.setValue(self.storeValue); - } - - this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { - if (want2showCounter === false) { - want2showCounter = true; - } - if (isInit === true) { - want2showCounter = null; - showCounter(); - } - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_TRIGGER_CLICK, function () { - self.combo.toggle(); + this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { + self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } + 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.MultiSelectTrigger.EVENT_CHANGE, function () { - var checked = this.getSearcher().hasChecked(); - var val = { - type: BI.Selection.Multi, - value: checked ? {1: 1} : {} - }; - this.getSearcher().setState(checked ? BI.Selection.Multi : BI.Selection.None); - this.getCounter().setButtonChecked(val); + 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.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - if (isSearching()) { - return; - } - if (change === true) { - self.storeValue = {value: self.combo.getValue()}; - change = false; - } - self.combo.setValue(self.storeValue); - self.populate(); - + this.pager = BI.createWidget(o.pager, { + type: "bi.direction_pager", + height: 30 }); - this.combo.on(BI.Combo.EVENT_BEFORE_HIDEVIEW, function () { - if (isSearching()) { - self.trigger.stopEditing(); - self.fireEvent(BI.MultiTreeCombo.EVENT_CONFIRM); - } else { - if (isPopupView()) { - self.trigger.stopEditing(); - self.storeValue = {value: self.combo.getValue()}; - if (clear === true) { - self.storeValue = {value: {}}; - } - self.fireEvent(BI.MultiTreeCombo.EVENT_CONFIRM); - } + this.pager.on(BI.Pager.EVENT_CHANGE, function () { + var vpage = this.getVPage && this.getVPage(); + if (BI.isNull(vpage)) { + vpage = this.getCurrentPage(); } - clear = false; - change = false; + 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); + }); }); - var triggerBtn = BI.createWidget({ - type: "bi.trigger_icon_button", - width: o.height, - height: o.height, - cls: "multi-select-trigger-icon-button" - }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - self.trigger.getCounter().hideView(); - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); - } - }); BI.createWidget({ type: "bi.absolute", element: this, items: [{ - el: this.combo, + el: this.table, left: 0, - right: 0, - top: 0, - bottom: 0 + top: 0 }, { - el: triggerBtn, + el: this.pager, + left: 0, right: 0, - top: 0, bottom: 0 }] }); }, - _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); - }); - + setHPage: function (v) { + this.hCurr = v; + this.pager.setHPage && this.pager.setHPage(v); + this.table.setHPage && this.table.setHPage(v); }, - getValue: function () { - return this.tree.getValue(); + setVPage: function (v) { + this.vCurr = v; + this.pager.setVPage && this.pager.setVPage(v); + this.table.setVPage && this.table.setVPage(v); }, - setValue: function (v) { - v || (v = {}); - this.tree.setSelectedValue(v.value); + 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; }, - populate: function (config) { - this.tree.stroke(config); + 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; }, - hasChecked: function () { - return this.tree.hasChecked(); + setWidth: function (width) { + BI.PageTable.superclass.setWidth.apply(this, arguments); + this.table.setWidth(width); }, - resetHeight: function (h) { - this.popupView.resetHeight(h); + 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)); }, - 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 - }); + setColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setColumnSize(columnSize); }, - _init: function () { - BI.MultiTreeSearchPane.superclass._init.apply(this, arguments); + getColumnSize: function () { + return this.table.getColumnSize(); + }, - var self = this, opts = this.options; + setRegionColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setRegionColumnSize(columnSize); + }, - 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 - }); + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); + }, - this.partTree.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); + }, - this.partTree.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreeSearchPane.EVENT_CHANGE); - }); + setLeftHorizontalScroll: function (scrollLeft) { + this.table.setLeftHorizontalScroll(scrollLeft); }, - hasChecked: function () { - return this.partTree.hasChecked(); + setRightHorizontalScroll: function (scrollLeft) { + this.table.setRightHorizontalScroll(scrollLeft); }, - setValue: function (v) { - this.setSelectedValue(v.value); + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); }, - setSelectedValue: function (v) { - v || (v = {}); - this.partTree.setSelectedValue(v); + restore: function () { + this.table.restore(); }, - getValue: function () { - return this.partTree.getValue(); + attr: function () { + BI.PageTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); }, - empty: function () { - this.partTree.empty(); + populate: function () { + this.pager.populate(); + this.table.populate.apply(this.table, arguments); }, - populate: function (op) { - this.partTree.stroke.apply(this.partTree, arguments); + destroy: function () { + this.table.destroy(); + this.pager && this.pager.destroy(); + BI.PageTable.superclass.destroy.apply(this, arguments); } }); - -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.shortcut("bi.page_table", BI.PageTable);/** + * 预览表列 + * + * Created by GUY on 2015/12/25. + * @class BI.PreviewTableCell + * @extends BI.Widget */ -BI.MultiTreeCheckSelectedButton = BI.inherit(BI.Single, { - - _const: { - checkSelected: BI.i18nText("BI-Check_Selected") - }, +BI.PreviewTableCell = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiTreeCheckSelectedButton.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-check-selected-button", - itemsCreator: BI.emptyFn + return BI.extend(BI.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table-cell", + text: "" }); }, _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); - }); - - this.checkSelected.on(BI.TextButton.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments); - }); + BI.PreviewTableCell.superclass._init.apply(this, arguments); + var self = this, o = this.options; BI.createWidget({ - type: "bi.horizontal", + type: "bi.label", element: this, - items: [this.indicator, this.checkSelected] + textAlign: "left", + whiteSpace: "normal", + height: this.options.height, + text: this.options.text, + value: this.options.value }); + } +}); +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, { - this.element.hover(function () { - self.indicator.setVisible(false); - self.checkSelected.setVisible(true); - }, function () { - self.indicator.setVisible(true); - self.checkSelected.setVisible(false); + _defaultConfig: function () { + return BI.extend(BI.PreviewTableHeaderCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table-header-cell", + text: "" }); - this.setVisible(false); }, - setValue: function (v) { - v || (v = {}); - this.setVisible(BI.size(v.value) > 0); + _init: function () { + BI.PreviewTableHeaderCell.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + BI.createWidget({ + type: "bi.label", + element: this, + textAlign: "left", + whiteSpace: "normal", + height: this.options.height, + text: this.options.text, + value: this.options.value + }); } }); - -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.shortcut("bi.preview_table_header_cell", BI.PreviewTableHeaderCell);/** + * 预览表 + * + * Created by GUY on 2015/12/25. + * @class BI.PreviewTable + * @extends BI.Widget */ -BI.MultiTreeSearcher = BI.inherit(BI.Widget, { +BI.PreviewTable = 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: {} + return BI.extend(BI.PreviewTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table", + isNeedFreeze: false, + freezeCols: [], + rowSize: null, + columnSize: [], + headerRowSize: 30, + header: [], + items: [] }); }, _init: function () { - BI.MultiTreeSearcher.superclass._init.apply(this, arguments); + BI.PreviewTable.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.searcher = BI.createWidget({ - type: "bi.searcher", + this.table = BI.createWidget({ + type: "bi.table_view", element: this, - isAutoSearch: false, - isAutoSync: false, - onSearch: function (op, callback) { - callback({ - keyword: self.editor.getValue() - }); - }, - el: this.editor, + isNeedResize: false, - 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), + isResizeAdapt: false, - 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()) { + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, - } - self.fireEvent(BI.MultiTreeSearcher.EVENT_PAUSE); + 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.searcher.on(BI.Searcher.EVENT_STOP, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_STOP); + this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { + self._adjustColumns(); + self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); }); - this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_CHANGE, arguments); + this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { + self._adjustColumns(); }); - if (BI.isNotNull(o.value)) { - this.setState(o.value); + }, + + // 是否有自适应调节的列,即列宽为"" + _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%"]); + } } }, - adjustView: function () { - this.searcher.adjustView(); + setColumnSize: function (columnSize) { + return this.table.setColumnSize(columnSize); }, - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + getColumnSize: function () { + return this.table.getColumnSize(); }, - isSearching: function () { - return this.searcher.isSearching(); + getCalculateColumnSize: function () { + return this.table.getCalculateColumnSize(); }, - stopSearch: function () { - this.searcher.stopSearch(); + setHeaderColumnSize: function (columnSize) { + return this.table.setHeaderColumnSize(columnSize); }, - getKeyword: function () { - return this.editor.getValue(); + setRegionColumnSize: function (columnSize) { + return this.table.setRegionColumnSize(columnSize); }, - hasMatched: function () { - return this.searcher.hasMatched(); + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); }, - hasChecked: function () { - return this.searcher.getView() && this.searcher.getView().hasChecked(); + getCalculateRegionColumnSize: function () { + return this.table.getCalculateRegionColumnSize(); }, - 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); - } + getCalculateRegionRowSize: function () { + return this.table.getCalculateRegionRowSize(); + }, - 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; - } + getClientRegionColumnSize: function () { + return this.table.getClientRegionColumnSize(); }, - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); + getScrollRegionColumnSize: function () { + return this.table.getScrollRegionColumnSize(); }, - getKey: function () { - return this.editor.getValue(); + getScrollRegionRowSize: function () { + return this.table.getScrollRegionRowSize(); + }, + + hasVerticalScroll: function () { + return this.table.hasVerticalScroll(); + }, + + setVerticalScroll: function (scrollTop) { + return this.table.setVerticalScroll(scrollTop); + }, + + setLeftHorizontalScroll: function (scrollLeft) { + return this.table.setLeftHorizontalScroll(scrollLeft); + }, + + setRightHorizontalScroll: function (scrollLeft) { + return this.table.setRightHorizontalScroll(scrollLeft); + }, + + getVerticalScroll: function () { + return this.table.getVerticalScroll(); + }, + + getLeftHorizontalScroll: function () { + return this.table.getLeftHorizontalScroll(); + }, + + getRightHorizontalScroll: function () { + return this.table.getRightHorizontalScroll(); + }, + + getColumns: function () { + return this.table.getColumns(); + }, + + 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 + }); + }, + _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.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.trigger.on(BI.QuarterTrigger.EVENT_STOP, function () { + if (!self.combo.isViewVisible()) { + self.combo.showView(); + } + }); + 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(); + } + self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); + }); + this.popup = BI.createWidget({ + type: "bi.quarter_popup", + behaviors: o.behaviors, + value: o.value + }); + + this.popup.on(BI.QuarterPopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.QuarterCombo.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.QuarterCombo.EVENT_BEFORE_POPUPVIEW); + }); + }, + + setValue: function (v) { + this.trigger.setValue(v); + this.popup.setValue(v); }, getValue: function () { - return this.searcher.getValue(); - }, - - populate: function (items) { - this.searcher.populate.apply(this.searcher, arguments); + if (BI.isNull(this.popup)) { + return this.options.value || ""; + } else { + return this.popup.getValue() || ""; + } } }); -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.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.NumberEditor = BI.inherit(BI.Widget, { +BI.QuarterPopup = 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 + return BI.extend(BI.QuarterPopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-quarter-popup", + behaviors: {} }); }, _init: function () { - BI.NumberEditor.superclass._init.apply(this, arguments); + BI.QuarterPopup.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); + + 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 + }); }); - BI.createWidget({ - type: "bi.htape", + + this.quarter = BI.createWidget({ + type: "bi.button_group", 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 - }] + behaviors: o.behaviors, + items: BI.createItems(items, {}), + layouts: [{ + type: "bi.vertical" + }], + value: o.value }); - }, - - focus: function () { - this.editor.focus(); - }, - - // 微调 - _finetuning: function (add) { - var v = BI.parseFloat(this.getValue()); - this.setValue(v.add(add)); - }, - - setUpEnable: function (v) { - this.topBtn.setEnable(!!v); - }, - setDownEnable: function (v) { - this.bottomBtn.setEnable(!!v); + 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); + } + }); }, getValue: function () { - return this.options.value; + return this.quarter.getValue()[0]; }, setValue: function (v) { - var o = this.options; - o.value = v; - this.editor.setValue(o.valueFormatter(v)); + this.quarter.setValue([v]); } - }); -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.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.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: "" +BI.QuarterTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + textWidth: 40, + errorText: BI.i18nText("BI-Quarter_Trigger_Error_Text") }, + _defaultConfig: function () { - var conf = BI.NumberInterval.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-number-interval", - height: 25, - validation: "valid" + return BI.extend(BI.QuarterTrigger.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-quarter-trigger bi-border", + height: 24 }); }, _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; - }, + 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) { - if (!BI.isNumeric(v)) { - self.smallEditorBubbleType = c.typeError; - return false; - } - return true; + return v === "" || (BI.isPositiveInteger(v) && v >= 1 && v <= 4); }, - 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 - }] - }); - - 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 () { + quitChecker: function (v) { 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.bigTip = BI.createWidget({ - type: "bi.label", - text: o.numTip, - height: o.height - 2, - invisible: true + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true, + errorText: c.errorText }); - BI.createWidget({ - type: "bi.absolute", - element: this.bigEditor.element, - items: [{ - el: this.bigTip, - top: 0, - right: 5 - }] + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_FOCUS); }); - - // 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.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_CHANGE); }); - 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.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); }); - 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.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); + } }); - this.left = BI.createWidget({ - type: "bi.htape", - items: [{ - el: self.smallEditor - }, { - el: self.smallCombo, - width: c.width - c.border * 2 - }] - + this.editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_START); }); - this.right = BI.createWidget({ - type: "bi.htape", - items: [{ - el: self.bigCombo, - width: c.width - c.border * 2 - }, { - el: self.bigEditor - }] + this.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.QuarterTrigger.EVENT_STOP); }); - BI.createWidget({ - element: self, - type: "bi.center", - hgap: 15, - height: o.height, + element: this, + type: "bi.htape", items: [ { - type: "bi.absolute", - items: [{ - el: self.left, - left: -15, - right: 0, - top: 0, - bottom: 0 - }] + el: this.editor }, { - type: "bi.absolute", - items: [{ - el: self.right, - left: 0, - right: -15, - top: 0, - bottom: 0 - }] + 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); + }, - 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); + setValue: function (v) { + v = v || ""; + this.editor.setState(v); + this.editor.setValue(v); + this.editor.setTitle(v); }, - _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 ""; + getKey: function () { + return this.editor.getValue(); + } +}); +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 + * @extends BI.Widget + */ +BI.ResponisveTable = BI.inherit(BI.Widget, { - } - 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 ""; + _const: { + perColumnSize: 100 + }, + _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: [], // 二维数组 - _setTitle: function (v) { - var self = this; - self.bigEditor.setTitle(v); - self.smallEditor.setTitle(v); - self.label.setTitle(v); + // 交叉表头 + crossHeader: [], + crossItems: [] + }); }, - _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; - } + _init: function () { + BI.ResponisveTable.superclass._init.apply(this, arguments); + var self = this, o = this.options; - }); - }, - _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 = BI.createWidget({ + type: "bi.table_view", + element: this, + logic: o.logic, - _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); - }); - }, + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, + isNeedMerge: o.isNeedMerge, + mergeCols: o.mergeCols, + mergeRule: o.mergeRule, - _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); - } - }); - }, + columnSize: o.columnSize, + headerRowSize: o.headerRowSize, + footerRowSize: o.footerRowSize, + rowSize: o.rowSize, + regionColumnSize: o.regionColumnSize, - _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); + header: o.header, + footer: o.footer, + items: o.items, + // 交叉表头 + crossHeader: o.crossHeader, + crossItems: o.crossItems }); - }, - - _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); + 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); }); - }, - - isStateValid: function () { - return this.options.validation === "valid"; - }, - setMinEnable: function (b) { - this.smallEditor.setEnable(b); + 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); + }); }, - setCloseMinEnable: function (b) { - this.smallCombo.setEnable(b); + _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]); + } + } + } }, - setMaxEnable: function (b) { - this.bigEditor.setEnable(b); + _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 + }; }, - setCloseMaxEnable: function (b) { - this.bigCombo.setEnable(b); + _isAdaptiveColumn: function (columnSize) { + return !(BI.last(columnSize || this.table.getColumnSize()) > 1.05); }, - showNumTip: function () { - this.smallTip.setVisible(true); - this.bigTip.setVisible(true); - }, + _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; - hideNumTip: function () { - this.smallTip.setVisible(false); - this.bigTip.setVisible(false); - }, + var newLeft = BI.clone(columnSizeLeft), newRight = BI.clone(columnSizeRight); + newLeft[newLeft.length - 1] = ""; + newRight[newRight.length - 1] = ""; + this.table.setColumnSize(newLeft.concat(newRight)); - setNumTip: function (numTip) { - this.smallTip.setText(numTip); - this.bigTip.setText(numTip); - }, + 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]; + } - getNumTip: function () { - return this.smallTip.getText(); - }, + 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; - setValue: function (data) { - data = data || {}; - var self = this, combo_value; - if (BI.isNumeric(data.min) || BI.isEmptyString(data.min)) { - self.smallEditor.setValue(data.min); - } + size[size.length - 1] += regionColumnSize[0] - sum; - if (!BI.isNotNull(data.min)) { - self.smallEditor.setValue(""); - } + var newSize = BI.clone(size); + newSize[newSize.length - 1] = ""; + this.table.setColumnSize(newSize); + block = this._getBlockSize(); - if (BI.isNumeric(data.max) || BI.isEmptyString(data.max)) { - self.bigEditor.setValue(data.max); + 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); + } } + }, - if (!BI.isNotNull(data.max)) { - self.bigEditor.setValue(""); + _resizeBody: function () { + if (this._isAdaptiveColumn()) { + var columnSize = this.table.getCalculateColumnSize(); + this.setColumnSize(columnSize); } + }, - if (!BI.isNull(data.closemin)) { - if (data.closemin === true) { - combo_value = 1; - } else { - combo_value = 0; + _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"]); } - self.smallCombo.setValue(combo_value); + this._resizeRegion(); } + }, - if (!BI.isNull(data.closemax)) { - if (data.closemax === true) { - combo_value = 1; - } else { - combo_value = 0; + _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; + } + this.table.setRegionColumnSize([size, "fill"]); } - 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 { - value.closemin = true; - } - - if (maxComboValue[0] === 0) { - value.closemax = false; - } else { - value.closemax = true; - } - 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: "" - }); + resize: function () { + this.table.resize(); + this._resizeRegion(); + this._resizeHeader(); }, - _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.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 + setColumnSize: function (columnSize) { + this.table.setColumnSize(columnSize); + this._adjustRegion(); + this._resizeHeader(); }, - _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 - } - }, + getColumnSize: function () { + return this.table.getColumnSize(); + }, - itemsCreator: BI.emptyFn, + getCalculateColumnSize: function () { + return this.table.getCalculateColumnSize(); + }, - isNeedFreeze: false, // 是否需要冻结单元格 - freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 + setHeaderColumnSize: function (columnSize) { + this.table.setHeaderColumnSize(columnSize); + this._adjustRegion(); + this._resizeHeader(); + }, - isNeedMerge: false, // 是否需要合并单元格 - mergeCols: [], // 合并的单元格列号 - mergeRule: BI.emptyFn, + setRegionColumnSize: function (columnSize) { + this.table.setRegionColumnSize(columnSize); + this._resizeHeader(); + }, - columnSize: [], - minColumnSize: [], - maxColumnSize: [], - headerRowSize: 25, - rowSize: 25, + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); + }, - regionColumnSize: [], + getCalculateRegionColumnSize: function () { + return this.table.getCalculateRegionColumnSize(); + }, - headerCellStyleGetter: BI.emptyFn, - summaryCellStyleGetter: BI.emptyFn, - sequenceCellStyleGetter: BI.emptyFn, + getCalculateRegionRowSize: function () { + return this.table.getCalculateRegionRowSize(); + }, - header: [], - items: [], // 二维数组 + getClientRegionColumnSize: function () { + return this.table.getClientRegionColumnSize(); + }, - // 交叉表头 - crossHeader: [], - crossItems: [] - }); + getScrollRegionColumnSize: function () { + return this.table.getScrollRegionColumnSize(); }, - _init: function () { - BI.PageTable.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.hCurr = 1; - this.vCurr = 1; + getScrollRegionRowSize: function () { + return this.table.getScrollRegionRowSize(); + }, - this.table = BI.createWidget(o.el, { - type: "bi.sequence_table", - width: o.width, - height: o.height && o.height - 30, + hasVerticalScroll: function () { + return this.table.hasVerticalScroll(); + }, - isNeedResize: true, - isResizeAdapt: false, + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); + }, - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, + setLeftHorizontalScroll: function (scrollLeft) { + this.table.setLeftHorizontalScroll(scrollLeft); + }, - isNeedMerge: o.isNeedMerge, - mergeCols: o.mergeCols, - mergeRule: o.mergeRule, + setRightHorizontalScroll: function (scrollLeft) { + this.table.setRightHorizontalScroll(scrollLeft); + }, - columnSize: o.columnSize, - minColumnSize: o.minColumnSize, - maxColumnSize: o.maxColumnSize, - headerRowSize: o.headerRowSize, - rowSize: o.rowSize, + getVerticalScroll: function () { + return this.table.getVerticalScroll(); + }, - regionColumnSize: o.regionColumnSize, + getLeftHorizontalScroll: function () { + return this.table.getLeftHorizontalScroll(); + }, - headerCellStyleGetter: o.headerCellStyleGetter, - summaryCellStyleGetter: o.summaryCellStyleGetter, - sequenceCellStyleGetter: o.sequenceCellStyleGetter, + getRightHorizontalScroll: function () { + return this.table.getRightHorizontalScroll(); + }, - header: o.header, - items: o.items, - // 交叉表头 - crossHeader: o.crossHeader, - crossItems: o.crossItems - }); + getColumns: function () { + return this.table.getColumns(); + }, - 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); + 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 }); - 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); + }, + _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.pager = BI.createWidget(o.pager, { - type: "bi.direction_pager", - height: 30 + 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.pager.on(BI.Pager.EVENT_CHANGE, function () { - var vpage = this.getVPage && this.getVPage(); - if (BI.isNull(vpage)) { - vpage = this.getCurrentPage(); + this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + if (this.isSelected()) { + self.triggerExpand(); + } else { + self.triggerCollapse(); + } } - 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); - }); }); + 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 + })))); + }, - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.table, - left: 0, - top: 0 - }, { - el: this.pager, - left: 0, - right: 0, - bottom: 0 - }] - }); + isOnce: function () { + return true; }, - setHPage: function (v) { - this.hCurr = v; - this.pager.setHPage && this.pager.setHPage(v); - this.table.setHPage && this.table.setHPage(v); + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); }, - setVPage: function (v) { - this.vCurr = v; - this.pager.setVPage && this.pager.setVPage(v); - this.table.setVPage && this.table.setVPage(v); + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - 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; + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); }, - 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; + setOpened: function (v) { + BI.SelectTreeFirstPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); } - return this.vpage; - }, + } +}); - setWidth: function (width) { - BI.PageTable.superclass.setWidth.apply(this, arguments); - this.table.setWidth(width); +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 + }); }, - - 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)); + _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.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 + })))); }, - setColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setColumnSize(columnSize); + isOnce: function () { + return true; }, - getColumnSize: function () { - return this.table.getColumnSize(); + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); }, - setRegionColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setRegionColumnSize(columnSize); + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); }, - getVerticalScroll: function () { - return this.table.getVerticalScroll(); - }, + setOpened: function (v) { + BI.SelectTreeLastPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } + } +}); - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); +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 + }); }, - - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + _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 + })))); }, - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); + isOnce: function () { + return true; }, - restore: function () { - this.table.restore(); + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); }, - attr: function () { - BI.PageTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - populate: function () { - this.pager.populate(); - this.table.populate.apply(this.table, arguments); + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); }, - destroy: function () { - this.table.destroy(); - this.pager && this.pager.destroy(); - BI.PageTable.superclass.destroy.apply(this, arguments); + setOpened: function (v) { + BI.SelectTreeMidPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } } }); -BI.shortcut("bi.page_table", BI.PageTable);/** - * 预览表列 - * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTableCell + +BI.shortcut("bi.select_tree_mid_plus_group_node", BI.SelectTreeMidPlusGroupNode);/** + * @class BI.SelectTreeCombo * @extends BI.Widget */ -BI.PreviewTableCell = BI.inherit(BI.Widget, { +BI.SelectTreeCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table-cell", - text: "" + return BI.extend(BI.SelectTreeCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-tree-combo", + height: 30, + text: "", + items: [], + value: "" }); }, _init: function () { - BI.PreviewTableCell.superclass._init.apply(this, arguments); + BI.SelectTreeCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - BI.createWidget({ - type: "bi.label", + this.trigger = BI.createWidget({ + type: "bi.single_tree_trigger", + text: o.text, + height: o.height, + items: o.items, + value: o.value + }); + + this.popup = BI.createWidget({ + type: "bi.select_level_tree", + items: o.items, + value: o.value + }); + + this.combo = BI.createWidget({ + type: "bi.combo", element: this, - textAlign: "left", - whiteSpace: "normal", - height: this.options.height, - text: this.options.text, - value: this.options.value + adjustLength: 2, + el: this.trigger, + popup: { + el: this.popup + } }); + + this.combo.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + }); + }, + + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.trigger.setValue(v); + this.popup.setValue(v); + }, + + getValue: function () { + return this.popup.getValue(); + }, + + populate: function (items) { + this.combo.populate(items); } }); -BI.shortcut("bi.preview_table_cell", BI.PreviewTableCell);/** - * 预览表 - * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTableHeaderCell + + +BI.shortcut("bi.select_tree_combo", BI.SelectTreeCombo);/** + * @class BI.SelectTreeExpander * @extends BI.Widget */ -BI.PreviewTableHeaderCell = BI.inherit(BI.Widget, { +BI.SelectTreeExpander = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.PreviewTableHeaderCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table-header-cell", - text: "" + 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.PreviewTableHeaderCell.superclass._init.apply(this, arguments); + BI.SelectTreeExpander.superclass._init.apply(this, arguments); var self = this, o = this.options; - BI.createWidget({ - type: "bi.label", + 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.expander = BI.createWidget({ + type: "bi.expander", element: this, - textAlign: "left", - whiteSpace: "normal", - height: this.options.height, - text: this.options.text, - value: this.options.value + trigger: o.trigger, + toggle: o.toggle, + direction: o.direction, + isDefaultInit: o.isDefaultInit, + el: this.trigger, + popup: o.popup }); + 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); + }); + }, + + 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); + } + }, + + getValue: function () { + if (this.trigger.isSelected()) { + return [this.trigger.getValue()]; + } + return this.expander.getValue(); + }, + + populate: function (items) { + this.expander.populate(items); } }); -BI.shortcut("bi.preview_table_header_cell", BI.PreviewTableHeaderCell);/** - * 预览表 - * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTable - * @extends BI.Widget + +BI.shortcut("bi.select_tree_expander", BI.SelectTreeExpander);/** + * @class BI.SelectTreePopup + * @extends BI.Pane */ -BI.PreviewTable = BI.inherit(BI.Widget, { + +BI.SelectTreePopup = BI.inherit(BI.Pane, { _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: [] + return BI.extend(BI.SelectTreePopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-level-tree", + tipText: BI.i18nText("BI-No_Selected_Item"), + items: [], + value: "" }); }, - _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, + _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); + } + }); + return nodes; + }, - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, + _init: function () { + BI.SelectTreePopup.superclass._init.apply(this, arguments); - rowSize: o.rowSize, - columnSize: o.columnSize, - headerRowSize: o.headerRowSize, + var self = this, o = this.options; - 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.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.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { - self._adjustColumns(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); + + BI.createWidget({ + type: "bi.vertical", + element: this, + items: [this.tree] }); - this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { - self._adjustColumns(); + + this.tree.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - }, - // 是否有自适应调节的列,即列宽为"" - _hasAdaptCol: function (columnSize) { - return BI.any(columnSize, function (i, size) { - return size === ""; + this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SelectTreePopup.EVENT_CHANGE); }); - }, - _isPercentage: function (columnSize) { - return columnSize[0] <= 1; + this.check(); }, - _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%"]); - } - } + getValue: function () { + return this.tree.getValue(); }, - setColumnSize: function (columnSize) { - return this.table.setColumnSize(columnSize); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.tree.setValue(v); }, - getColumnSize: function () { - return this.table.getColumnSize(); - }, + populate: function (items) { + BI.SelectTreePopup.superclass.populate.apply(this, arguments); + this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(items))); + } +}); - getCalculateColumnSize: function () { - return this.table.getCalculateColumnSize(); - }, +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, { - setHeaderColumnSize: function (columnSize) { - return this.table.setHeaderColumnSize(columnSize); + _defaultConfig: function () { + return BI.extend(BI.SequenceTableDynamicNumber.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-sequence-table-dynamic-number" + }); }, - setRegionColumnSize: function (columnSize) { - return this.table.setRegionColumnSize(columnSize); + _init: function () { + BI.SequenceTableDynamicNumber.superclass._init.apply(this, arguments); }, - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); - }, + _formatNumber: function (nodes) { + var self = this, o = this.options; + var result = []; + var count = this._getStart(nodes); - getCalculateRegionColumnSize: function () { - return this.table.getCalculateRegionColumnSize(); - }, + 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++; + } + return cnt; + } - getCalculateRegionRowSize: function () { - return this.table.getCalculateRegionRowSize(); - }, + 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; + } + } + }); + 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, { - getClientRegionColumnSize: function () { - return this.table.getClientRegionColumnSize(); - }, + _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, - getScrollRegionColumnSize: function () { - return this.table.getScrollRegionColumnSize(); - }, + sequenceHeaderCreator: null, - getScrollRegionRowSize: function () { - return this.table.getScrollRegionRowSize(); - }, + header: [], + items: [], // 二维数组 - hasVerticalScroll: function () { - return this.table.hasVerticalScroll(); - }, + // 交叉表头 + crossHeader: [], + crossItems: [], - setVerticalScroll: function (scrollTop) { - return this.table.setVerticalScroll(scrollTop); + pageSize: 20 + }); }, - setLeftHorizontalScroll: function (scrollLeft) { - return this.table.setLeftHorizontalScroll(scrollLeft); - }, + _init: function () { + BI.SequenceTableListNumber.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.start = o.startSequence; + this.renderedCells = []; + this.renderedKeys = []; - setRightHorizontalScroll: function (scrollLeft) { - return this.table.setRightHorizontalScroll(scrollLeft); - }, + this.container = BI.createWidget({ + type: "bi.absolute", + width: 60, + scrollable: false + }); - getVerticalScroll: function () { - return this.table.getVerticalScroll(); - }, + this.scrollContainer = BI.createWidget({ + type: "bi.vertical", + scrollable: false, + scrolly: false, + items: [this.container] + }); - getLeftHorizontalScroll: function () { - return this.table.getLeftHorizontalScroll(); - }, + this.headerContainer = BI.createWidget({ + type: "bi.absolute", + cls: "bi-border", + width: 58, + scrollable: false + }); - getRightHorizontalScroll: function () { - return this.table.getRightHorizontalScroll(); + 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(); }, - getColumns: function () { - return this.table.getColumns(); + _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) { + + } }, - 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 + _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 + }] }); }, - _init: function () { - BI.QuarterCombo.superclass._init.apply(this, arguments); + + _calculateChildrenToRender: function () { var self = this, o = this.options; - this.storeValue = ""; - this.trigger = BI.createWidget({ - type: "bi.quarter_trigger", - value: o.value - }); + 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); + } - 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.trigger.on(BI.QuarterTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); + // 已存在的, 需要添加的和需要删除的 + var existSet = {}, addSet = {}, deleteArray = []; + BI.each(renderedKeys, function (i, key) { + if (BI.deepContains(self.renderedKeys, key)) { + existSet[i] = key; + } else { + addSet[i] = key; } }); - this.trigger.on(BI.QuarterTrigger.EVENT_CONFIRM, function () { - if (self.combo.isViewVisible()) { + BI.each(this.renderedKeys, function (i, key) { + if (BI.deepContains(existSet, key)) { return; } - if (this.getKey() && this.getKey() !== self.storeValue) { - self.setValue(this.getKey()); - } else if (!this.getKey()) { - self.setValue(); + if (BI.deepContains(addSet, key)) { + return; } - self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); - }); - this.popup = BI.createWidget({ - type: "bi.quarter_popup", - behaviors: o.behaviors, - value: o.value + deleteArray.push(i); }); - - this.popup.on(BI.QuarterPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.QuarterCombo.EVENT_CONFIRM); + BI.each(deleteArray, function (i, index) { + self.renderedCells[index].el.destroy(); }); - - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - el: this.popup - } + var addedItems = []; + BI.each(addSet, function (index) { + addedItems.push(renderedCells[index]); }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW); + BI.createWidget({ + type: "bi.absolute", + element: this.container, + items: addedItems }); + this.renderedCells = renderedCells; + this.renderedKeys = renderedKeys; }, - 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() || ""; - } - } -}); - -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, { - - _defaultConfig: function () { - return BI.extend(BI.QuarterPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-quarter-popup", - behaviors: {} - }); + _populate: function () { + this.headerContainer.empty(); + this._createHeader(); + this._layout(); + this._calculateChildrenToRender(); }, - _init: function () { - BI.QuarterPopup.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.quarter = BI.createWidget({ - type: "bi.button_group", - element: this, - behaviors: o.behaviors, - items: BI.createItems(items, {}), - layouts: [{ - type: "bi.vertical" - }], - value: o.value - }); + setVerticalScroll: function (scrollTop) { + if (this.options.scrollTop !== scrollTop) { + this.options.scrollTop = scrollTop; + try { + this.scrollContainer.element.scrollTop(scrollTop); + } catch (e) { - 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); } - }); - }, - - getValue: function () { - return this.quarter.getValue()[0]; + } }, - 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") + getVerticalScroll: function () { + return this.options.scrollTop; }, - _defaultConfig: function () { - return BI.extend(BI.QuarterTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-quarter-trigger bi-border", - height: 24 - }); + setVPage: function (v) { + v = v < 1 ? 1 : v; + var o = this.options; + this.start = (v - 1) * o.pageSize + 1; }, - _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); - }); - 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 - } - ] + _restore: function () { + var o = this.options; + BI.each(this.renderedCells, function (i, cell) { + cell.el.destroy(); }); - this.setValue(o.value); + this.renderedCells = []; + this.renderedKeys = []; }, - setValue: function (v) { - v = v || ""; - this.editor.setState(v); - this.editor.setValue(v); - this.editor.setTitle(v); + restore: function () { + this._restore(); }, - getKey: function () { - return this.editor.getValue(); + 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.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);/** - * 自适应宽度的表格 +BI.shortcut("bi.sequence_table_list_number", BI.SequenceTableListNumber);/** + * 带有序号的表格 * - * Created by GUY on 2016/2/3. - * @class BI.ResponisveTable + * Created by GUY on 2016/5/26. + * @class BI.SequenceTable * @extends BI.Widget */ -BI.ResponisveTable = BI.inherit(BI.Widget, { - - _const: { - perColumnSize: 100 - }, +BI.SequenceTable = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.ResponisveTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-responsive-table", + return BI.extend(BI.SequenceTable.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-sequence-table", + el: { + type: "bi.adaptive_table" + }, + + sequence: {}, + + isNeedResize: true, + isResizeAdapt: false, + isNeedFreeze: false, // 是否需要冻结单元格 freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 - logic: { // 冻结的页面布局逻辑 - dynamic: false - }, isNeedMerge: false, // 是否需要合并单元格 mergeCols: [], // 合并的单元格列号 - mergeRule: function (row1, row2) { // 合并规则, 默认相等时合并 - return BI.isEqual(row1, row2); - }, + mergeRule: BI.emptyFn, columnSize: [], + minColumnSize: [], + maxColumnSize: [], headerRowSize: 25, - footerRowSize: 25, rowSize: 25, - regionColumnSize: false, + regionColumnSize: [], + + headerCellStyleGetter: BI.emptyFn, + summaryCellStyleGetter: BI.emptyFn, + sequenceCellStyleGetter: BI.emptyFn, header: [], - footer: false, items: [], // 二维数组 // 交叉表头 crossHeader: [], - crossItems: [] + crossItems: [], + + showSequence: false, + startSequence: 1// 开始的序号 }); }, _init: function () { - BI.ResponisveTable.superclass._init.apply(this, arguments); + BI.SequenceTable.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.table = BI.createWidget({ - type: "bi.table_view", - element: this, - logic: o.logic, - + this.sequence = BI.createWidget(o.sequence, { + type: "bi.sequence_table_list_number", + invisible: o.showSequence === false, + startSequence: o.startSequence, 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); - }); + crossItems: o.crossItems, + headerRowSize: o.headerRowSize, + rowSize: o.rowSize, + width: 60, + height: o.height && o.height - BI.GridTableScrollbar.SIZE, - 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); + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter }); - }, - - _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]); - } - } - } - }, - - _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 - }; - }, - - _isAdaptiveColumn: function (columnSize) { - return !(BI.last(columnSize || this.table.getColumnSize()) > 1.05); - }, - - _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(o.el, { + type: "bi.adaptive_table", + width: o.showSequence === true ? o.width - 60 : o.width, + height: o.height, + isNeedResize: o.isNeedResize, + isResizeAdapt: o.isResizeAdapt, - var newLeft = BI.clone(columnSizeLeft), newRight = BI.clone(columnSizeRight); - newLeft[newLeft.length - 1] = ""; - newRight[newRight.length - 1] = ""; - this.table.setColumnSize(newLeft.concat(newRight)); + isNeedFreeze: o.isNeedFreeze, + freezeCols: o.freezeCols, - 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]; - } + isNeedMerge: o.isNeedMerge, + mergeCols: o.mergeCols, + mergeRule: o.mergeRule, - 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; + columnSize: o.columnSize, + minColumnSize: o.minColumnSize, + maxColumnSize: o.maxColumnSize, + headerRowSize: o.headerRowSize, + rowSize: o.rowSize, - size[size.length - 1] += regionColumnSize[0] - sum; + regionColumnSize: o.regionColumnSize, - var newSize = BI.clone(size); - newSize[newSize.length - 1] = ""; - this.table.setColumnSize(newSize); - block = this._getBlockSize(); + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter, - 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); + 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); + }); - _resizeBody: function () { - if (this._isAdaptiveColumn()) { - var columnSize = this.table.getCalculateColumnSize(); - this.setColumnSize(columnSize); - } + 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._populate(); }, - _adjustRegion: function () { + _populate: 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(); + 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); } }, - _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; - } - this.table.setRegionColumnSize([size, "fill"]); - } - } + setWidth: function (width) { + BI.PageTable.superclass.setWidth.apply(this, arguments); + this.table.setWidth(this.options.showSequence ? width - 60 : width); }, - - resize: function () { - this.table.resize(); - this._resizeRegion(); - this._resizeHeader(); + setHeight: function (height) { + BI.PageTable.superclass.setHeight.apply(this, arguments); + this.table.setHeight(height); + this.sequence.setHeight(height - BI.GridTableScrollbar.SIZE); }, setColumnSize: function (columnSize) { + this.options.columnSize = columnSize; this.table.setColumnSize(columnSize); - this._adjustRegion(); - this._resizeHeader(); }, getColumnSize: function () { return this.table.getColumnSize(); }, - getCalculateColumnSize: function () { - return this.table.getCalculateColumnSize(); - }, - - setHeaderColumnSize: function (columnSize) { - this.table.setHeaderColumnSize(columnSize); - this._adjustRegion(); - this._resizeHeader(); - }, - setRegionColumnSize: function (columnSize) { + this.options.columnSize = columnSize; this.table.setRegionColumnSize(columnSize); - this._resizeHeader(); }, getRegionColumnSize: function () { return this.table.getRegionColumnSize(); }, - getCalculateRegionColumnSize: function () { - return this.table.getCalculateRegionColumnSize(); - }, - - getCalculateRegionRowSize: function () { - return this.table.getCalculateRegionRowSize(); - }, - - getClientRegionColumnSize: function () { - return this.table.getClientRegionColumnSize(); - }, - - getScrollRegionColumnSize: function () { - return this.table.getScrollRegionColumnSize(); - }, - - getScrollRegionRowSize: function () { - return this.table.getScrollRegionRowSize(); - }, - - hasVerticalScroll: function () { - return this.table.hasVerticalScroll(); + hasLeftHorizontalScroll: function () { + return this.table.hasLeftHorizontalScroll(); }, - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); + hasRightHorizontalScroll: function () { + return this.table.hasRightHorizontalScroll(); }, setLeftHorizontalScroll: function (scrollLeft) { @@ -104266,1097 +101988,1360 @@ BI.ResponisveTable = BI.inherit(BI.Widget, { this.table.setRightHorizontalScroll(scrollLeft); }, - getVerticalScroll: function () { - return this.table.getVerticalScroll(); + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); + this.sequence.setVerticalScroll(scrollTop); }, - getLeftHorizontalScroll: function () { - return this.table.getLeftHorizontalScroll(); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); }, - getRightHorizontalScroll: function () { - return this.table.getRightHorizontalScroll(); + setVPage: function (page) { + this.sequence.setVPage && this.sequence.setVPage(page); }, - getColumns: function () { - return this.table.getColumns(); + setHPage: function (page) { + this.sequence.setHPage && this.sequence.setHPage(page); }, attr: function () { - BI.ResponisveTable.superclass.attr.apply(this, arguments); + BI.SequenceTable.superclass.attr.apply(this, arguments); this.table.attr.apply(this.table, arguments); + this.sequence.attr.apply(this.sequence, 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(); - }); + restore: function () { + this.table.restore(); + this.sequence.restore(); + }, + + 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()); + }, + + destroy: function () { + this.table.destroy(); + BI.SequenceTable.superclass.destroy.apply(this, arguments); } }); -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", BI.SequenceTable);/** + * 单选加载数据搜索loader面板 + * Created by guy on 15/11/4. + * @class BI.SingleSelectSearchLoader + * @extends Widget */ -BI.SelectTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { +BI.SingleSelectSearchLoader = 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 - }, - id: "", - pId: "", - readonly: true, - open: false, - height: 25 + 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.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(); + BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); + + 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; } }); - 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); + 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); + }); }, - setOpened: function (v) { - BI.SelectTreeFirstPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } - } -}); - -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", + _createItems: function (items) { + return BI.createItems(items, { + type: "bi.single_select_radio_item", logic: { dynamic: false }, - id: "", - pId: "", - readonly: true, - open: false, - height: 25 + height: 25, + selected: false }); }, - _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.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 + + _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 + }; }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); - } - } + 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 + }; }); - 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; + setValue: function (v) { + // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = v; + this.button_group.setValue(v); }, - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); + getValue: function () { + return this.button_group.getValue(); }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); + getAllButtons: function () { + return this.button_group.getAllButtons(); }, - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); + empty: function () { + this.button_group.empty(); }, - setOpened: function (v) { - BI.SelectTreeLastPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } + 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.shortcut("bi.select_tree_last_plus_group_node", BI.SelectTreeLastPlusGroupNode);/** - * 加号表示的组节点 - * Created by GUY on 2015/9/6. - * @class BI.SelectTreeMidPlusGroupNode - * @extends BI.NodeButton +BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_search_loader", BI.SingleSelectSearchLoader);/** + * + * 在搜索框中输入文本弹出的面板 + * @class BI.SingleSelectSearchPane + * @extends Widget */ -BI.SelectTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, { + +BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { + + constants: { + height: 25, + lgap: 10, + tgap: 5 + }, + _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 + 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.SelectTreeMidPlusGroupNode.superclass._init.apply(this, arguments); + BI.SingleSelectSearchPane.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({ + + this.tooltipClick = 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 + invisible: true, + text: BI.i18nText("BI-Click_Blank_To_Select"), + cls: "single-select-toolbar", + height: this.constants.height }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); - } + + 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()); + }]); } }); - 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.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); }, - isOnce: function () { - return true; + 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(); + } }, - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); + hasMatched: function () { + return this.tooltipClick.isVisible(); }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); + setValue: function (v) { + this.loader.setValue(v); }, - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); + getValue: function () { + return this.loader.getValue(); }, - setOpened: function (v) { - BI.SelectTreeMidPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } + empty: function () { + this.loader.empty(); + }, + + populate: function (items) { + this.loader.populate.apply(this.loader, arguments); } }); -BI.shortcut("bi.select_tree_mid_plus_group_node", BI.SelectTreeMidPlusGroupNode);/** - * @class BI.SelectTreeCombo - * @extends BI.Widget +BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; + +BI.shortcut("bi.single_select_search_pane", BI.SingleSelectSearchPane);/** + * + * @class BI.SingleSelectCombo + * @extends BI.Single */ -BI.SelectTreeCombo = BI.inherit(BI.Widget, { +BI.SingleSelectCombo = BI.inherit(BI.Single, { _defaultConfig: function () { - return BI.extend(BI.SelectTreeCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-select-tree-combo", - height: 30, - text: "", - items: [], - value: "" + 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.SelectTreeCombo.superclass._init.apply(this, arguments); + 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_tree_trigger", - text: o.text, + type: "bi.single_select_trigger", height: o.height, - items: o.items, - value: o.value + // 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.popup = BI.createWidget({ - type: "bi.select_level_tree", - items: o.items, - value: o.value + 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", - element: this, - adjustLength: 2, + toggle: false, el: this.trigger, + adjustLength: 1, popup: { - el: this.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.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + 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.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); + 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 + }] }); }, - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.trigger.setValue(v); - this.popup.setValue(v); + _defaultState: function () { + this.trigger.stopEditing(); + this.combo.hideView(); }, - getValue: function () { - return this.popup.getValue(); + _assertValue: function (val) { + val || (val = ""); }, - populate: function (items) { - this.combo.populate(items); - } -}); - - -BI.shortcut("bi.select_tree_combo", BI.SelectTreeCombo);/** - * @class BI.SelectTreeExpander - * @extends BI.Widget - */ -BI.SelectTreeExpander = 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: {} - }); + _makeMap: function (values) { + return BI.makeObject(values || []); }, - _init: function () { - BI.SelectTreeExpander.superclass._init.apply(this, arguments); + _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.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([]); + 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.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + }); + self._adjust(callback); + } + }, - 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.expander.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - self.trigger.setSelected(false); + _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; } - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + 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); }); }, - setValue: function (v) { - if (BI.contains(v, this.trigger.getValue())) { - this.trigger.setSelected(true); - this.expander.setValue([]); + _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 { - this.trigger.setSelected(false); - this.expander.setValue(v); + adjust(); + callback(); + } - }, - getValue: function () { - if (this.trigger.isSelected()) { - return [this.trigger.getValue()]; + function adjust () { + if (self.wants2Quit === true) { + self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + self.wants2Quit = false; + } + self.requesting = false; } - return this.expander.getValue(); }, - populate: function (items) { - this.expander.populate(items); - } -}); + _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); + }, -BI.shortcut("bi.select_tree_expander", BI.SelectTreeExpander);/** - * @class BI.SelectTreePopup - * @extends BI.Pane - */ + _setStartValue: function (value) { + this._startValue = value; + this.popup.setStartValue(value); + }, -BI.SelectTreePopup = BI.inherit(BI.Pane, { + setValue: function (v) { + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.combo.setValue(this.storeValue); + }, - _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: "" - }); + getValue: function () { + return this.storeValue; }, - _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); + populate: function () { + this._count = null; + this.combo.populate.apply(this.combo, arguments); + } +}); + +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 2015/11/1. + * @class BI.SingleSelectList + * @extends BI.Widget + */ +BI.SingleSelectList = BI.inherit(BI.Widget, { + + _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 nodes; }, - _init: function () { - BI.SelectTreePopup.superclass._init.apply(this, arguments); - + BI.SingleSelectList.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 + + 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); + }); }, - 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] + onLoaded: o.onLoaded, + hasNext: o.hasNext }); - - this.tree.on(BI.Controller.EVENT_CHANGE, function () { + + 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.tree.on(BI.LevelTree.EVENT_CHANGE, function () { - self.fireEvent(BI.SelectTreePopup.EVENT_CHANGE); - }); - - this.check(); + 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) + })))); + }, - - getValue: function () { - return this.tree.getValue(); + + hasPrev: function () { + return this.list.hasPrev(); }, - + + hasNext: function () { + return this.list.hasNext(); + }, + + prependItems: function (items) { + this.list.prependItems.apply(this.list, arguments); + }, + + addItems: function (items) { + this.list.addItems.apply(this.list, arguments); + }, + setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.tree.setValue(v); + this.list.setValue([v]); }, - + + getValue: function () { + return this.list.getValue()[0]; + }, + + empty: function () { + this.list.empty(); + }, + populate: function (items) { - BI.SelectTreePopup.superclass.populate.apply(this, arguments); - this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(items))); + this.list.populate.apply(this.list, arguments); + }, + + resetHeight: function (h) { + this.list.resetHeight ? this.list.resetHeight(h) : + this.list.element.css({"max-height": h + "px"}); + }, + + setNotSelectedValue: function () { + this.list.setNotSelectedValue.apply(this.list, arguments); + }, + + getNotSelectedValue: function () { + return this.list.getNotSelectedValue(); + }, + + getAllButtons: function () { + return this.list.getAllButtons(); + }, + + getAllLeaves: function () { + return this.list.getAllLeaves(); + }, + + getSelectedButtons: function () { + return this.list.getSelectedButtons(); + }, + + getNotSelectedButtons: function () { + return this.list.getNotSelectedButtons(); + }, + + getIndexByValue: function (value) { + return this.list.getIndexByValue(value); + }, + + getNodeById: function (id) { + return this.list.getNodeById(id); + }, + + getNodeByValue: function (value) { + return this.list.getNodeByValue(value); } }); - -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.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.SequenceTableDynamicNumber = BI.inherit(BI.SequenceTableTreeNumber, { +BI.SingleSelectLoader = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.SequenceTableDynamicNumber.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-sequence-table-dynamic-number" + 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, + onLoaded: BI.emptyFn }); }, _init: function () { - BI.SequenceTableDynamicNumber.superclass._init.apply(this, arguments); - }, + BI.SingleSelectLoader.superclass._init.apply(this, arguments); - _formatNumber: function (nodes) { - var self = this, o = this.options; - var result = []; - var count = this._getStart(nodes); + var self = this, opts = this.options; + var hasNext = false; - 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++; + this.button_group = BI.createWidget({ + type: "bi.single_select_list", + element: this, + logic: opts.logic, + el: BI.extend({ + onLoaded: opts.onLoaded, + 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" + }] + } } - } else { - cnt++; - } - 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; + }, opts.el), + itemsCreator: function (op, callback) { + var startValue = self._startValue; + self.storeValue && (op = BI.extend(op || {}, { + selectedValues: [self.storeValue] + })); + opts.itemsCreator(op, function (ob) { + 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)), ob.keyword || ""); + if (op.times === 1 && self.storeValue) { + BI.isKey(startValue) && (self.storeValue = startValue); + self.setValue(self.storeValue); + } + (op.times === 1) && self._scrollToTop(); }); - 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; - } + }, + hasNext: function () { + return hasNext; } }); - 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: [], + 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.SingleSelectLoader.EVENT_CHANGE, arguments); + }); + }, - pageSize: 20 + _createItems: function (items) { + return BI.createItems(items, { + type: "bi.single_select_radio_item", + logic: this.options.logic, + height: 25, + selected: false }); }, - _init: function () { - BI.SequenceTableListNumber.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.start = o.startSequence; - this.renderedCells = []; - this.renderedKeys = []; + _scrollToTop: function () { + var self = this; + BI.delay(function () { + self.button_group.element.scrollTop(0); + }, 30); + }, - this.container = BI.createWidget({ - type: "bi.absolute", - width: 60, - scrollable: false - }); + _assertValue: function (val) { + val || (val = ""); + }, - this.scrollContainer = BI.createWidget({ - type: "bi.vertical", - scrollable: false, - scrolly: false, - items: [this.container] - }); + setStartValue: function (v) { + this._startValue = v; + }, - this.headerContainer = BI.createWidget({ - type: "bi.absolute", - cls: "bi-border", - width: 58, - scrollable: false - }); + setValue: function (v) { + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.button_group.setValue(this.storeValue); + }, - 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(); + getValue: function () { + return this.button_group.getValue(); }, - _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) { + getAllButtons: function () { + return this.button_group.getAllButtons(); + }, - } + empty: function () { + this.button_group.empty(); }, - _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 - }] - }); + populate: function (items) { + this.button_group.populate.apply(this.button_group, arguments); }, - _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); - } + resetHeight: function (h) { + this.button_group.resetHeight(h); + }, - // 已存在的, 需要添加的和需要删除的 - 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 + resetWidth: function (w) { + this.button_group.resetWidth(w); + } +}); + +BI.SingleSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_loader", BI.SingleSelectLoader);/** + * 带加载的单选下拉面板 + * @class BI.SingleSelectPopupView + * @extends Widget + */ +BI.SingleSelectPopupView = BI.inherit(BI.Widget, { + + _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, + itemsCreator: BI.emptyFn, + onLoaded: BI.emptyFn }); - this.renderedCells = renderedCells; - this.renderedKeys = renderedKeys; }, - _populate: function () { - this.headerContainer.empty(); - this._createHeader(); - this._layout(); - this._calculateChildrenToRender(); - }, + _init: function () { + BI.SingleSelectPopupView.superclass._init.apply(this, arguments); + var self = this, opts = this.options; - setVerticalScroll: function (scrollTop) { - if (this.options.scrollTop !== scrollTop) { - this.options.scrollTop = scrollTop; - try { - this.scrollContainer.element.scrollTop(scrollTop); - } catch (e) { + this.loader = BI.createWidget({ + type: "bi.single_select_loader", + itemsCreator: opts.itemsCreator, + valueFormatter: opts.valueFormatter, + onLoaded: opts.onLoaded + }); + + 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 + }); + 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; } - } + }); }, - getVerticalScroll: function () { - return this.options.scrollTop; + setStartValue: function (v) { + this.loader.setStartValue(v); }, - setVPage: function (v) { - v = v < 1 ? 1 : v; - var o = this.options; - this.start = (v - 1) * o.pageSize + 1; + setValue: function (v) { + this.popupView.setValue(v); }, - _restore: function () { - var o = this.options; - BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); - }); - this.renderedCells = []; - this.renderedKeys = []; + getValue: function () { + return this.popupView.getValue(); }, - restore: function () { - this._restore(); + populate: function (items) { + this.popupView.populate.apply(this.popupView, arguments); }, - 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(); + resetHeight: function (h) { + this.popupView.resetHeight(h); + }, + + resetWidth: function (w) { + this.popupView.resetWidth(w); } }); -BI.shortcut("bi.sequence_table_list_number", BI.SequenceTableListNumber);/** - * 带有序号的表格 - * - * Created by GUY on 2016/5/26. - * @class BI.SequenceTable - * @extends BI.Widget - */ -BI.SequenceTable = 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" - }, +BI.SingleSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; +BI.SingleSelectPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; - sequence: {}, - isNeedResize: true, - isResizeAdapt: false, +BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView);/** + * + * 单选下拉框 + * @class BI.SingleSelectTrigger + * @extends BI.Trigger + */ - isNeedFreeze: false, // 是否需要冻结单元格 - freezeCols: [], // 冻结的列号,从0开始,isNeedFreeze为true时生效 +BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { - isNeedMerge: false, // 是否需要合并单元格 - mergeCols: [], // 合并的单元格列号 - mergeRule: BI.emptyFn, + constants: { + height: 14, + rgap: 4, + lgap: 4 + }, - columnSize: [], - minColumnSize: [], - maxColumnSize: [], - headerRowSize: 25, - rowSize: 25, + _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: {}, - regionColumnSize: [], + adapter: null, + masker: {} + }); + }, - headerCellStyleGetter: BI.emptyFn, - summaryCellStyleGetter: BI.emptyFn, - sequenceCellStyleGetter: BI.emptyFn, + _init: function () { + BI.SingleSelectTrigger.superclass._init.apply(this, arguments); - header: [], - items: [], // 二维数组 + var self = this, o = this.options; + if (o.height) { + this.setHeight(o.height - 2); + } - // 交叉表头 - crossHeader: [], - crossItems: [], + 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); + }); - showSequence: false, - startSequence: 1// 开始的序号 + var wrapper = BI.createWidget({ + type: "bi.htape", + element: this, + items: [ + { + el: this.searcher, + width: "fill" + }, { + el: BI.createWidget(), + width: 30 + }] }); }, - _init: function () { - BI.SequenceTable.superclass._init.apply(this, arguments); - var self = this, o = this.options; + getSearcher: function () { + return this.searcher; + }, - 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, + stopEditing: function () { + this.searcher.stopSearch(); + }, - 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, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + }, - isNeedFreeze: o.isNeedFreeze, - freezeCols: o.freezeCols, + setValue: function (v) { + this.searcher.setValue(v); + }, - isNeedMerge: o.isNeedMerge, - mergeCols: o.mergeCols, - mergeRule: o.mergeRule, + getKey: function () { + return this.searcher.getKey(); + }, - columnSize: o.columnSize, - minColumnSize: o.minColumnSize, - maxColumnSize: o.maxColumnSize, - headerRowSize: o.headerRowSize, - rowSize: o.rowSize, + getValue: function () { + return this.searcher.getValue(); + } +}); - regionColumnSize: o.regionColumnSize, +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"; - headerCellStyleGetter: o.headerCellStyleGetter, - summaryCellStyleGetter: o.summaryCellStyleGetter, - sequenceCellStyleGetter: o.sequenceCellStyleGetter, +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, { - header: o.header, - items: o.items, - // 交叉表头 - crossHeader: o.crossHeader, - crossItems: o.crossItems + _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: {} }); + }, - 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.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.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.editor.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, 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.editor.on(BI.StateEditor.EVENT_PAUSE, function () { + self.fireEvent(BI.SingleSelectEditor.EVENT_PAUSE); }); + this.editor.on(BI.StateEditor.EVENT_CLICK_LABEL, function () { - 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._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); - } + focus: function () { + this.editor.focus(); }, - setWidth: function (width) { - BI.PageTable.superclass.setWidth.apply(this, arguments); - this.table.setWidth(this.options.showSequence ? width - 60 : width); + blur: function () { + this.editor.blur(); }, - setHeight: function (height) { - BI.PageTable.superclass.setHeight.apply(this, arguments); - this.table.setHeight(height); - this.sequence.setHeight(height - BI.GridTableScrollbar.SIZE); + setState: function (state) { + this.editor.setState(state); }, - setColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setColumnSize(columnSize); + setValue: function (v) { + this.editor.setValue(v); }, - getColumnSize: function () { - return this.table.getColumnSize(); + getValue: function () { + var v = this.editor.getState(); + if (BI.isArray(v) && v.length > 0) { + return v[v.length - 1]; + } + return ""; + }, - setRegionColumnSize: function (columnSize) { - this.options.columnSize = columnSize; - this.table.setRegionColumnSize(columnSize); + getKeywords: function () { + var val = this.editor.getLastValidValue(); + var keywords = val.match(/[\S]+/g); + if (BI.isEndWithBlank(val)) { + return keywords.concat([" "]); + } + return keywords; }, - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); + populate: function (items) { + + } +}); +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: {} + }); }, - hasLeftHorizontalScroll: function () { - return this.table.hasLeftHorizontalScroll(); + _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); + }); }, - hasRightHorizontalScroll: function () { - return this.table.hasRightHorizontalScroll(); + adjustView: function () { + this.searcher.adjustView(); }, - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); + isSearching: function () { + return this.searcher.isSearching(); }, - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + stopSearch: function () { + this.searcher.stopSearch(); }, - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); - this.sequence.setVerticalScroll(scrollTop); + getKeyword: function () { + return this.editor.getValue(); }, - getVerticalScroll: function () { - return this.table.getVerticalScroll(); + hasMatched: function () { + return this.searcher.hasMatched(); }, - setVPage: function (page) { - this.sequence.setVPage && this.sequence.setVPage(page); + hasChecked: function () { + return this.searcher.getView() && this.searcher.getView().hasChecked(); }, - setHPage: function (page) { - this.sequence.setHPage && this.sequence.setHPage(page); + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - attr: function () { - BI.SequenceTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); - this.sequence.attr.apply(this.sequence, 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 + "")); + } + }, + + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); }, - restore: function () { - this.table.restore(); - this.sequence.restore(); + getKey: function () { + return this.editor.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()); + getValue: function () { + return this.searcher.getValue(); }, - destroy: function () { - this.table.destroy(); - BI.SequenceTable.superclass.destroy.apply(this, arguments); + populate: function (items) { + this.searcher.populate.apply(this.searcher, arguments); } }); -BI.shortcut("bi.sequence_table", BI.SequenceTable);/** + +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 @@ -105427,6 +103412,23 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { }); 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); @@ -105512,7 +103514,7 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { }); BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_search_loader", BI.SingleSelectSearchLoader);/** +BI.shortcut("bi.single_select_search_add_loader", BI.SingleSelectSearchLoader);/** * * 在搜索框中输入文本弹出的面板 * @class BI.SingleSelectSearchPane @@ -105549,7 +103551,7 @@ BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { }); this.loader = BI.createWidget({ - type: "bi.single_select_search_loader", + type: "bi.single_select_search_add_loader", keywordGetter: o.keywordGetter, valueFormatter: o.valueFormatter, itemsCreator: function (op, callback) { @@ -105609,7 +103611,7 @@ BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_search_pane", BI.SingleSelectSearchPane);/** +BI.shortcut("bi.single_select_search_add_pane", BI.SingleSelectSearchPane);/** * * @class BI.SingleSelectCombo * @extends BI.Single @@ -105638,7 +103640,7 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { this.requesting = false; this.trigger = BI.createWidget({ - type: "bi.single_select_trigger", + type: "bi.single_select_add_trigger", height: o.height, // adapter: this.popup, masker: { @@ -105775,3209 +103777,3760 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { } }); - var triggerBtn = BI.createWidget({ - type: "bi.trigger_icon_button", - width: o.height, + 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 || []); + }, + + _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); + } + }, + + _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); + }); + }, + + _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; + } + }, + + _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); + }, + + _setStartValue: function (value) { + this._startValue = value; + this.popup.setStartValue(value); + }, + + setValue: function (v) { + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.combo.setValue(this.storeValue); + }, + + getValue: function () { + return this.storeValue; + }, + + populate: function () { + this._count = null; + this.combo.populate.apply(this.combo, arguments); + } +}); + +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.SingleSelectTrigger = BI.inherit(BI.Trigger, { + + constants: { + height: 14, + rgap: 4, + lgap: 4 + }, + + _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; + if (o.height) { + this.setHeight(o.height - 2); + } + + 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); + }); + 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 + }] + }); + }, + + getSearcher: function () { + return this.searcher; + }, + + stopEditing: function () { + this.searcher.stopSearch(); + }, + + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + }, + + setValue: function (v) { + this.searcher.setValue(v); + }, + + getKey: function () { + return this.searcher.getKey(); + }, + + getValue: function () { + 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_add_trigger", BI.SingleSelectTrigger);/** + * 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: {} + }); + }, + + _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_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), + + 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(); + }, + + 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(); + }, + + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + }, + + 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 + "")); + } + }, + + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); + }, + + getKey: function () { + return this.editor.getValue(); + }, + + getValue: function () { + return this.searcher.getValue(); + }, + + populate: function (items) { + 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_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, - cls: "single-select-trigger-icon-button" + 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 }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); + 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.combo, + el: this.text, left: 0, right: 0, top: 0, bottom: 0 - }, { - el: triggerBtn, - 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(); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + _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)); }, - _assertValue: function (val) { - val || (val = ""); + _showInput: function () { + this.editor.visible(); + this.text.invisible(); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + _showHint: function () { + this.editor.invisible(); + this.text.visible(); }, - _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); - }); + setTitle: function (title) { + this.text.setTitle(title); + }, - 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); - } + setWarningTitle: function (title) { + this.text.setWarningTitle(title); }, - _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); - }); + focus: function () { + this._showInput(); + this.editor.focus(); }, - _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(); + 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); + }, - function adjust () { - if (self.wants2Quit === true) { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); - self.wants2Quit = false; - } - self.requesting = false; - } + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - _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); + doHighLight: function () { + if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { return; } - this._joinAll(res, callback); + this.text.doHighLight.apply(this.text, arguments); }, - _setStartValue: function (value) { - this._startValue = value; - this.popup.setStartValue(value); + 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.storeValue = v || ""; - this._assertValue(this.storeValue); - this.combo.setValue(this.storeValue); + this.editor.setValue(v); + this._checkText(); }, getValue: function () { - return this.storeValue; + return this.editor.getValue(); }, - populate: function () { - this._count = null; - this.combo.populate.apply(this.combo, arguments); - } -}); + getState: function () { + return this.text.getValue(); + }, -BI.extend(BI.SingleSelectCombo, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 + 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.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; - -BI.shortcut("bi.single_select_combo", BI.SingleSelectCombo);/** - * 选择列表 - * - * Created by GUY on 2015/11/1. - * @class BI.SingleSelectList - * @extends BI.Widget +BI.shortcut("bi.sign_text_editor", BI.SignTextEditor);/** + * Created by zcf on 2016/9/22. */ -BI.SingleSelectList = BI.inherit(BI.Widget, { - +BI.SliderIconButton = BI.inherit(BI.Widget, { _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.SliderIconButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-slider-button" }); }, _init: function () { - BI.SingleSelectList.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 + 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 }); - - 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); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.slider, + top: 7, + left: -7 + }], + width: 0, + height: 14 }); - - 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(); - }, - - hasNext: function () { - return this.list.hasNext(); - }, - - prependItems: function (items) { - this.list.prependItems.apply(this.list, arguments); - }, - - addItems: function (items) { - this.list.addItems.apply(this.list, arguments); - }, - - setValue: function (v) { - this.list.setValue([v]); - }, - - getValue: function () { - return this.list.getValue()[0]; - }, - - empty: function () { - this.list.empty(); - }, - - populate: function (items) { - this.list.populate.apply(this.list, arguments); - }, - - resetHeight: function (h) { - this.list.resetHeight ? this.list.resetHeight(h) : - this.list.element.css({"max-height": h + "px"}); - }, - - setNotSelectedValue: function () { - this.list.setNotSelectedValue.apply(this.list, arguments); - }, - - getNotSelectedValue: function () { - return this.list.getNotSelectedValue(); - }, - - getAllButtons: function () { - return this.list.getAllButtons(); - }, - - getAllLeaves: function () { - return this.list.getAllLeaves(); - }, - - getSelectedButtons: function () { - return this.list.getSelectedButtons(); - }, - - getNotSelectedButtons: function () { - return this.list.getNotSelectedButtons(); - }, - - getIndexByValue: function (value) { - return this.list.getIndexByValue(value); - }, - - getNodeById: function (id) { - return this.list.getNodeById(id); - }, - - getNodeByValue: function (value) { - return this.list.getNodeByValue(value); } }); -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.shortcut("bi.single_slider_button", BI.SliderIconButton);/** + * Created by zcf on 2016/9/22. */ -BI.SingleSelectLoader = 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.SingleSelectLoader.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-loader", - logic: { - dynamic: true - }, - el: { - height: 400 - }, - valueFormatter: BI.emptyFn, - itemsCreator: BI.emptyFn, - onLoaded: 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.SingleSelectLoader.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", - element: this, - logic: opts.logic, - el: BI.extend({ - onLoaded: opts.onLoaded, - 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" - }] - } + 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; } - }, opts.el), - itemsCreator: function (op, callback) { - var startValue = self._startValue; - self.storeValue && (op = BI.extend(op || {}, { - selectedValues: [self.storeValue] - })); - opts.itemsCreator(op, function (ob) { - 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)), 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 () { - return hasNext; + 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.button_group.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + 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.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectLoader.EVENT_CHANGE, arguments); + 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, + 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%" + }, { + 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%" + }] }); }, - _createItems: function (items) { - return BI.createItems(items, { - type: "bi.single_select_radio_item", - logic: this.options.logic, - height: 25, - selected: false + _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); }); - }, - _scrollToTop: function () { - var self = this; - BI.delay(function () { - self.button_group.element.scrollTop(0); - }, 30); + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); + } }, - _assertValue: function (val) { - val || (val = ""); + _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%" + }] + }); }, - setStartValue: function (v) { - this._startValue = v; + _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; + }else{ + var dotText = (v + "").split(".")[1] || ""; + valid = (dotText.length === o.digit); + } + } + return valid; }, - setValue: function (v) { - this.storeValue = v || ""; - this._assertValue(this.storeValue); - this.button_group.setValue(this.storeValue); + _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.SingleSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_loader", BI.SingleSelectLoader);/** - * 带加载的单选下拉面板 - * @class BI.SingleSelectPopupView - * @extends Widget - */ -BI.SingleSelectPopupView = BI.inherit(BI.Widget, { - - _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, - itemsCreator: BI.emptyFn, - onLoaded: BI.emptyFn - }); + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - _init: function () { - BI.SingleSelectPopupView.superclass._init.apply(this, arguments); - var self = this, opts = this.options; - - this.loader = BI.createWidget({ - type: "bi.single_select_loader", - itemsCreator: opts.itemsCreator, - valueFormatter: opts.valueFormatter, - onLoaded: opts.onLoaded - }); - - 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 - }); - - 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; - } - }); + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, - setStartValue: function (v) { - this.loader.setStartValue(v); + getValue: function () { + return this.value; }, setValue: function (v) { - this.popupView.setValue(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; + } + } }, - getValue: function () { - return this.popupView.getValue(); + 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; + } }, - populate: function (items) { - this.popupView.populate.apply(this.popupView, arguments); - }, + reset: function () { + this._setVisible(false); + this.enable = false; + this.value = ""; + this.min = 0; + this.max = 0; + this._setBlueTrack(0); - resetHeight: function (h) { - this.popupView.resetHeight(h); }, - resetWidth: function (w) { - this.popupView.resetWidth(w); + 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.SingleSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; -BI.SingleSelectPopupView.EVENT_CLICK_CONFIRM = "EVENT_CLICK_CONFIRM"; -BI.SingleSelectPopupView.EVENT_CLICK_CLEAR = "EVENT_CLICK_CLEAR"; - - -BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView);/** - * - * 单选下拉框 - * @class BI.SingleSelectTrigger - * @extends BI.Trigger +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: "" + }); + }, + _init: function () { + BI.SingleSliderLabel.superclass._init.apply(this, arguments); -BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { + var self = this, o = this.options; + var c = this._constant; + this.enable = false; + this.value = ""; - constants: { - height: 14, - rgap: 4, - lgap: 4 - }, + 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(); - _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: {}, + 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.setText(v + o.unit); + self.value = v; + self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); + } + }); + this.label = BI.createWidget({ + type: "bi.label", + height: c.HEIGHT, + width: c.EDITOR_WIDTH - 2 + }); - adapter: null, - masker: {} + 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%" + }] }); }, - _init: function () { - BI.SingleSelectTrigger.superclass._init.apply(this, arguments); - + _draggable: function (widget) { var self = this, o = this.options; - if (o.height) { - this.setHeight(o.height - 2); - } - - 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 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); }); - var wrapper = BI.createWidget({ - type: "bi.htape", - element: this, - items: [ - { - el: this.searcher, - width: "fill" - }, { - el: BI.createWidget(), - width: 30 - }] - }); + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); + } }, - getSearcher: function () { - return this.searcher; + _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%" + }] + }); }, - stopEditing: function () { - this.searcher.stopSearch(); + _checkValidation: function (v) { + return BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max); }, - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - setValue: function (v) { - this.searcher.setValue(v); + _setLabelPosition: function (percent) { + this.label.element.css({left: percent + "%"}); }, - getKey: function () { - return this.searcher.getKey(); + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); }, - getValue: function () { - 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") + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setLabelPosition(percent); + this._setBlueTrack(percent); }, - _defaultConfig: function () { - return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-editor", - el: {} - }); + _setVisible: function (visible) { + this.slider.setVisible(visible); + this.label.setVisible(visible); }, - _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 () { - - }); + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - focus: function () { - this.editor.focus(); + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - blur: function () { - this.editor.blur(); + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, - setState: function (state) { - this.editor.setState(state); + getValue: function () { + return this.value; }, 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]; + 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; + } } - return ""; - }, - getKeywords: function () { - var val = this.editor.getLastValidValue(); - var keywords = val.match(/[\S]+/g); - if (BI.isEndWithBlank(val)) { - return keywords.concat([" "]); + 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; } - return keywords; }, - populate: function (items) { + 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); + } + } } }); -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.SingleSliderLabel.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_slider_label", BI.SingleSliderLabel);/** + * normal single slider + * Created by Young on 2017/6/21. */ -BI.SingleSelectSearcher = BI.inherit(BI.Widget, { +BI.SingleSliderNormal = 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: {} - }); + _constant: { + HEIGHT: 28, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 }, - _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), + props: { + baseCls: "bi-single-slider-normal bi-slider-track", + minMax: { + min: 0, + max: 100 + } + // color: "#3f8ce8" + }, - adapter: o.adapter, - masker: o.masker - }); - this.searcher.on(BI.Searcher.EVENT_START, function () { - self.fireEvent(BI.SingleSelectSearcher.EVENT_START); + render: function () { + var self = this; + var c = this._constant; + var track = this._createTrack(); + this.slider = BI.createWidget({ + type: "bi.single_slider_button" }); - this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { - if (this.hasMatched()) { + this._draggable(this.slider); - } - 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); + var sliderVertical = BI.createWidget({ + type: "bi.vertical", + items: [{ + type: "bi.absolute", + items: [this.slider] + }], + hgap: c.SLIDER_WIDTH_HALF, + height: c.SLIDER_HEIGHT }); - this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { - var keywords = this.getKeywords(); - self.fireEvent(BI.SingleSelectSearcher.EVENT_SEARCHING, keywords); + 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); + } }); - }, - adjustView: function () { - this.searcher.adjustView(); - }, - - isSearching: function () { - return this.searcher.isSearching(); - }, - - stopSearch: function () { - this.searcher.stopSearch(); - }, - - getKeyword: function () { - return this.editor.getValue(); - }, - - hasMatched: function () { - return this.searcher.hasMatched(); + 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%" + }] + }; }, - hasChecked: function () { - return this.searcher.getView() && this.searcher.getView().hasChecked(); - }, + _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); + }); - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); + } }, - 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 + "")); + _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}); } + + 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; + } + }; }, - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); + _checkValidation: function (v) { + return !(BI.isNull(v) || v < this.min || v > this.max); }, - getKey: function () { - return this.editor.getValue(); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - getValue: function () { - return this.searcher.getValue(); + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); }, - populate: function (items) { - 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.SingleSelectSearchLoader = BI.inherit(BI.Widget, { - - _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 - }); + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setBlueTrack(percent); }, - _init: function () { - BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); - - 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); - } - 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; - } - }); - 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); - }); + _setVisible: function (visible) { + this.slider.setVisible(visible); }, - _createItems: function (items) { - return BI.createItems(items, { - type: "bi.single_select_radio_item", - logic: { - dynamic: false - }, - height: 25, - selected: false - }); + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - _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 - }; - }); + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - setValue: function (v) { - // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 - this.storeValue = v; - this.button_group.setValue(v); + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, getValue: function () { - return this.button_group.getValue(); - }, - - getAllButtons: function () { - return this.button_group.getAllButtons(); + return this.value; }, - empty: function () { - this.button_group.empty(); + 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; + } + } }, - populate: function (items) { - this.button_group.populate.apply(this.button_group, arguments); + 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; + } }, - resetHeight: function (h) { - this.button_group.resetHeight(h); + reset: function () { + this._setVisible(false); + this.enable = false; + this.value = ""; + this.min = 0; + this.max = 0; + this._setBlueTrack(0); }, - resetWidth: function (w) { - this.button_group.resetWidth(w); + 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.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_select_search_add_loader", BI.SingleSelectSearchLoader);/** - * - * 在搜索框中输入文本弹出的面板 - * @class BI.SingleSelectSearchPane - * @extends Widget +BI.SingleSliderNormal.EVENT_DRAG = "EVENT_DRAG"; +BI.shortcut("bi.single_slider_normal", BI.SingleSliderNormal);/** + * @class BI.SingleTreeCombo + * @extends BI.Widget */ - -BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { - - constants: { - height: 25, - lgap: 10, - tgap: 5 - }, +BI.SingleTreeCombo = 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, - valueFormatter: BI.emptyFn, - keywordGetter: BI.emptyFn + return BI.extend(BI.SingleTreeCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-tree-combo", + trigger: {}, + height: 24, + text: "", + items: [], + value: "" }); }, _init: function () { - BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); + BI.SingleTreeCombo.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.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.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.combo = BI.createWidget({ + type: "bi.combo", + element: this, + adjustLength: 2, + el: this.trigger, + popup: { + el: this.popup } }); - this.loader.on(BI.Controller.EVENT_CHANGE, function () { + + this.combo.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.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW, arguments); }); - 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(); - } + this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.SingleTreeCombo.EVENT_CHANGE); + }); }, - hasMatched: function () { - return this.tooltipClick.isVisible(); + populate: function (items) { + this.combo.populate(items); }, setValue: function (v) { - this.loader.setValue(v); + v = BI.isArray(v) ? v : [v]; + this.trigger.setValue(v); + this.popup.setValue(v); }, getValue: function () { - return this.loader.getValue(); - }, - - empty: function () { - this.loader.empty(); - }, - - populate: function (items) { - this.loader.populate.apply(this.loader, arguments); + return this.popup.getValue(); } }); -BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.single_select_search_add_pane", BI.SingleSelectSearchPane);/** - * - * @class BI.SingleSelectCombo - * @extends BI.Single +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.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 - }); - }, - - _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_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(); - } - }); +BI.SingleTreePopup = BI.inherit(BI.Pane, { - 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(); - }); - } + _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 }, - hideChecker: function (e) { - return triggerBtn.element.find(e.target).length === 0; - } + items: o.items, + value: o.value, + chooseType: BI.Selection.Single }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - this.setValue(self.storeValue); - BI.nextTick(function () { - self.populate(); - }); + BI.createWidget({ + type: "bi.vertical", + element: this, + items: [this.tree] }); - // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 - 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.tree.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - var triggerBtn = BI.createWidget({ - type: "bi.trigger_icon_button", - width: o.height, - height: o.height, - cls: "single-select-trigger-icon-button" + this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleTreePopup.EVENT_CHANGE); }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); - } + + 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: "" }); - BI.createWidget({ - type: "bi.absolute", + }, + + _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, - items: [{ - el: this.combo, - left: 0, - right: 0, - top: 0, - bottom: 0 - }, { - el: triggerBtn, - right: 0, - top: 0, - bottom: 0 - }] + text: o.text, + items: o.items, + height: o.height, + value: o.value }); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + _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; + } + }); }, - _assertValue: function (val) { - val || (val = ""); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.options.value = v; + this.trigger.setValue(v); + this._checkTitle(); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + getValue: function () { + return this.options.value || []; }, - _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); - }); + populate: function (items) { + BI.SingleTreeTrigger.superclass.populate.apply(this, arguments); + this.trigger.populate(items); + } - 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); - } +}); + +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, { + + _defaultConfig: function () { + return BI.extend(BI.SwitchTree.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-switch-tree", + items: [] + }); }, - _joinAll: function (res, callback) { + _init: function () { + BI.SwitchTree.superclass._init.apply(this, arguments); 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); + this.tab = BI.createWidget({ + type: "bi.tab", + element: this, + tab: null, + showIndex: BI.SwitchTree.SelectType.SingleSelect, + cardCreator: BI.bind(this._createTree, this) }); }, - _adjust: function (callback) { + _createTree: function (type) { 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(); - + 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; } + }, - function adjust () { - if (self.wants2Quit === true) { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); - self.wants2Quit = false; - } - self.requesting = false; - } + _removeIsParent: function (items) { + BI.each(items, function (i, item) { + BI.isNotNull(item.isParent) && delete item.isParent; + }); + return items; }, - _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; + 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; } - this._joinAll(res, callback); }, - _setStartValue: function (value) { - this._startValue = value; - this.popup.setStartValue(value); + setSelect: function (v) { + this.tab.setSelect(v); + }, + + getSelect: function () { + return this.tab.getSelect(); }, setValue: function (v) { - this.storeValue = v || ""; - this._assertValue(this.storeValue); - this.combo.setValue(this.storeValue); + 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.storeValue; + return this.tab.getValue(); }, - populate: function () { - this._count = null; - this.combo.populate.apply(this.combo, arguments); + 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.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.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.SingleSelectTrigger = BI.inherit(BI.Trigger, { - +BI.DateInterval = BI.inherit(BI.Single, { constants: { - height: 14, - rgap: 4, - lgap: 4 + 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.SingleSelectTrigger.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-trigger bi-border", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - searcher: {}, - switcher: {}, - - adapter: null, - masker: {} + var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-date-interval" }); }, - _init: function () { - BI.SingleSelectTrigger.superclass._init.apply(this, arguments); - var self = this, o = this.options; - if (o.height) { - this.setHeight(o.height - 2); - } + BI.DateInterval.superclass._init.apply(this, arguments); - 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 + 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: "-" }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_START, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_START); + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, + items: [{ + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: this.constants.offset, + top: 0, + bottom: 0 + }] + }] }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_PAUSE, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_PAUSE); + BI.createWidget({ + type: "bi.horizontal_auto", + element: this, + items: [ + self.label + ] }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_SEARCHING, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_SEARCHING, arguments); + }, + + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_date_combo", + value: v }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_STOP, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_STOP); + combo.on(BI.DynamicDateCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_ERROR); }); - this.searcher.on(BI.SingleSelectSearcher.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectTrigger.EVENT_CHANGE, arguments); + + 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); + } }); - var wrapper = BI.createWidget({ - type: "bi.htape", - element: this, - items: [ - { - el: this.searcher, - width: "fill" - }, { - el: BI.createWidget(), - width: 30 - }] + 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; }, - - getSearcher: function () { - return this.searcher; + _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; }, - - stopEditing: function () { - this.searcher.stopSearch(); + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, - - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + _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] + }); }, - - setValue: function (v) { - this.searcher.setValue(v); + _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; }, - - getKey: function () { - return this.searcher.getKey(); + _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 this.searcher.getValue(); + return {start: this.left.getValue(), end: this.right.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_add_trigger", BI.SingleSelectTrigger);/** - * searcher - * Created by guy on 15/11/3. - * @class BI.SingleSelectSearcher - * @extends Widget +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.SingleSelectSearcher = BI.inherit(BI.Widget, { - +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.SingleSelectSearcher.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-searcher", - itemsCreator: BI.emptyFn, - el: {}, - popup: {}, - valueFormatter: BI.emptyFn, - adapter: null, - masker: {} + var conf = BI.TimeInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-time-interval" }); }, - _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 - }); + BI.TimeInterval.superclass._init.apply(this, arguments); - this.searcher = BI.createWidget({ - type: "bi.searcher", + o.value = o.value || {}; + this.left = this._createCombo(o.value.start); + this.right = this._createCombo(o.value.end); + this.label = BI.createWidget({ + type: "bi.label", + height: this.constants.height, + width: this.constants.width, + text: "-" + }); + BI.createWidget({ + element: self, + type: "bi.center", + hgap: 15, + height: this.constants.height, + items: [{ + type: "bi.absolute", + items: [{ + el: self.left, + left: this.constants.offset, + right: 0, + top: 0, + bottom: 0 + }] + }, { + type: "bi.absolute", + items: [{ + el: self.right, + left: 0, + right: this.constants.offset, + top: 0, + bottom: 0 + }] + }] + }); + BI.createWidget({ + type: "bi.horizontal_auto", element: this, - 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: [ + self.label + ] + }); + }, - adapter: o.adapter, - masker: o.masker + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_date_time_combo", + value: v }); - this.searcher.on(BI.Searcher.EVENT_START, function () { - self.fireEvent(BI.SingleSelectSearcher.EVENT_START); + combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.TimeInterval.EVENT_ERROR); }); - this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { - if (this.hasMatched()) { + 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); } - 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(); - }, + 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); + } + }); - isSearching: function () { - return this.searcher.isSearching(); - }, + 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); + // } + // }); - stopSearch: function () { - this.searcher.stopSearch(); + 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{ + self._clearTitle(); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.TimeInterval.EVENT_CHANGE); + } + }); + return combo; }, - - getKeyword: function () { - return this.editor.getValue(); + _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; }, - - hasMatched: function () { - return this.searcher.hasMatched(); + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, - - hasChecked: function () { - return this.searcher.getView() && this.searcher.getView().hasChecked(); + _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] + }); }, - - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + _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; }, - - 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 + "")); - } + _setTitle: function (v) { + this.left.setTitle(v); + this.right.setTitle(v); + this.label.setTitle(v); }, - - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); + _clearTitle: function () { + this.left.setTitle(""); + this.right.setTitle(""); + this.label.setTitle(""); }, - - getKey: function () { - return this.editor.getValue(); + setValue: function (date) { + date = date || {}; + this.left.setValue(date.start); + this.right.setValue(date.end); }, - getValue: function () { - return this.searcher.getValue(); - }, - - populate: function (items) { - this.searcher.populate.apply(this.searcher, arguments); + return {start: this.left.getValue(), end: this.right.getValue()}; } }); - -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.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.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 - }); - }, +BI.DynamicYearCard = BI.inherit(BI.Widget, { - _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(); + props: { + baseCls: "bi-year-card" }, - _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)); + 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 + }; }, - _showInput: function () { - this.editor.visible(); - this.text.invisible(); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - _showHint: function () { - this.editor.invisible(); - this.text.visible(); + setValue: function (v) { + v = v || {year: 0}; + this.item.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); }, - setTitle: function (title) { - this.text.setTitle(title); - }, + 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, { - setWarningTitle: function (title) { - this.text.setWarningTitle(title); + _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" // 最大日期 + }); }, - focus: function () { - this._showInput(); - this.editor.focus(); - }, + _createYearCalendar: function (v) { + var o = this.options, y = this._year; - blur: function () { - this.editor.blur(); - this._showHint(); - this._checkText(); + 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; }, - doRedMark: function () { - if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { - return; - } - this.text.doRedMark.apply(this.text, arguments); - }, + _init: function () { + BI.StaticYearCard.superclass._init.apply(this, arguments); + var self = this, o = this.options; - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); - }, + this.selectedYear = this._year = BI.getDate().getFullYear(); - doHighLight: function () { - if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { - return; - } - this.text.doHighLight.apply(this.text, arguments); - }, + 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(); + } + }] + }); - unHighLight: function () { - this.text.unHighLight.apply(this.text, arguments); - }, + 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(); + } + }] + }); - isValid: function () { - return this.editor.isValid(); - }, + 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), - setErrorText: function (text) { - this.editor.setErrorText(text); - }, + afterCardShow: function () { + this.setValue(self.selectedYear); + var calendar = this.getSelectedCard(); + self.backBtn.setEnable(!calendar.isFrontYear()); + self.preBtn.setEnable(!calendar.isFinalYear()); + } + }); - getErrorText: function () { - return this.editor.getErrorText(); - }, + 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); + }); - isEditing: function () { - return this.editor.isEditing(); + if(BI.isKey(o.value)){ + this.setValue(o.value); + } }, - getLastValidValue: function () { - return this.editor.getLastValidValue(); + _checkLeftValid: function () { + var o = this.options; + var valid = true; + this.backBtn.setEnable(valid); + return valid; }, - setValue: function (v) { - this.editor.setValue(v); - this._checkText(); + _checkRightValid: function () { + var o = this.options; + var valid = true; + this.preBtn.setEnable(valid); + return valid; }, getValue: function () { - return this.editor.getValue(); - }, - - getState: function () { - return this.text.getValue(); + return { + year: this.selectedYear + }; }, - setState: function (v) { + setValue: function (obj) { var o = this.options; - this._showHint(); - v = (BI.isEmpty(v) || v == o.text) ? o.text : v + o.text; - this.text.setValue(v); + 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.SignTextEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.SignTextEditor.EVENT_CLICK_LABEL = "EVENT_CLICK_LABEL"; +BI.StaticYearCard.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.static_year_card", BI.StaticYearCard);BI.DynamicYearCombo = BI.inherit(BI.Widget, { -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.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.SingleSlider.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-slider bi-slider-track", - digit: false, - unit: "" - }); + props: { + baseCls: "bi-year-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, - _init: function () { - BI.SingleSlider.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.setValue(v); - self.value = v; - self.fireEvent(BI.SingleSlider.EVENT_CHANGE); - } + this.trigger.on(BI.DynamicYearTrigger.EVENT_ERROR, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - 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.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.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, - 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%" - }, { + + this.combo = BI.createWidget({ + type: "bi.combo", + isNeedAdjustHeight: false, + isNeedAdjustWidth: false, + el: this.trigger, + popup: { + minWidth: 85, + stopPropagation: false, el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [this.label] + 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); + } }], - rgap: c.EDITOR_WIDTH, - height: c.EDITOR_HEIGHT + behaviors: o.behaviors, + min: o.min, + max: o.max }, - 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; + value: o.value || "" } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); + }); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW); }); - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); - } - }, - - _createTrackWrapper: function () { - return BI.createWidget({ - type: "bi.absolute", + BI.createWidget({ + type: "bi.htape", + element: this, + ref: function () { + self.comboWrapper = 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 + type: "bi.icon_button", + cls: "bi-trigger-icon-button date-change-h-font", + width: 24, + height: 24, + ref: function () { + self.changeIcon = this; + } }, - top: 8, - left: 0, - width: "100%" - }] + width: 24 + }, this.combo] }); + this._checkDynamicValue(o.value); }, - _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; - }else{ - var dotText = (v + "").split(".")[1] || ""; - valid = (dotText.length === o.digit); - } + _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; } - return valid; - }, - - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); }, - _setLabelPosition: function (percent) { - this.label.element.css({left: percent + "%"}); + setValue: function (v) { + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); }, - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); - }, + getValue: function () { + return this.storeValue; + } - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setLabelPosition(percent); - this._setBlueTrack(percent); - }, +}); +BI.DynamicYearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.dynamic_year_combo", BI.DynamicYearCombo); - _setVisible: function (visible) { - this.slider.setVisible(visible); - this.label.setVisible(visible); +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 }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + props: { + baseCls: "bi-year-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 }, - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); + 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 + }] + }; }, - _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 () { - 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); - } - } + getValue: function () { + return { + type: this.dateTab.getSelect(), + value: this.dateTab.getValue() + }; } + }); -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 +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.SingleSliderLabel.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-slider-label bi-slider-track", - digit: false, - unit: "" + 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.SingleSliderLabel.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(); - - 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.setText(v + o.unit); - self.value = v; - self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); + 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.label = BI.createWidget({ - type: "bi.label", - height: c.HEIGHT, - width: c.EDITOR_WIDTH - 2 + this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_FOCUS); }); - - 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.editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicYearTrigger.EVENT_STOP); }); - }, - - _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.editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = self.editor.getValue(); + if (BI.isNotNull(value)) { + self.editor.setValue(value); } - }, 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; + if (BI.isNotEmptyString(value)) { + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: value + } + }; } - widget.element.removeClass("dragging"); - mouseMoveTracker.releaseMouseMoves(); - self.fireEvent(BI.SingleSliderLabel.EVENT_CHANGE); - }, window); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; + + self.fireEvent(BI.DynamicYearTrigger.EVENT_CONFIRM); + }); + this.editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (self.editor.isValid()) { + self.editor.blur(); } - 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", + 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: this.grayTrack, - top: 0, - left: 0, - width: "100%" - }, { - el: this.blueTrack, - top: 0, - left: 0, - width: "0%" - }] - }], - hgap: 8, - height: 8 + type: "bi.text_button", + baseCls: "bi-trigger-year-text", + text: BI.i18nText("BI-Multi_Date_Year"), + width: o.height }, - top: 8, - left: 0, - width: "100%" + width: o.height + }, { + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height }] }); + this.setValue(o.value); }, - _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); + _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; }, - getValue: function () { - return this.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 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 type, value; + var date = BI.getDate(); + this.storeValue = v; + if (BI.isNotNull(v)) { + type = v.type || BI.DynamicDateCombo.Static; + value = v.value || 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; + 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; } }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.value = ""; - this.min = 0; - this.max = 0; - this._setBlueTrack(0); + getValue: function () { + return this.storeValue; }, - 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); - } - } + getKey: function () { + return this.editor.getValue() | 0; } }); -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.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.SingleSliderNormal = BI.inherit(BI.Widget, { - - _constant: { - HEIGHT: 28, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 - }, +BI.DynamicYearMonthCard = BI.inherit(BI.Widget, { props: { - baseCls: "bi-single-slider-normal bi-slider-track", - minMax: { - min: 0, - max: 100 - } - // color: "#3f8ce8" + baseCls: "bi-year-month-card" }, 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); - - 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); - } - }); - return { - type: "bi.absolute", - element: this, + type: "bi.vertical", items: [{ - 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.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; }, - top: 3, - left: 0, - width: "100%" + listeners: [{ + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] }, { - el: sliderVertical, - 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._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()); - } - }, - - _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}); - } - - 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 + 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 + "%"}); - }, - - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); - }, - - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setBlueTrack(percent); - }, - - _setVisible: function (visible) { - this.slider.setVisible(visible); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + 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)); }, - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); - }, + 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, { - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); + props: { + baseCls: "bi-static-year-month-card", + behaviors: {} }, - getValue: function () { - return this.value; + _createMonths: function () { + // 纵向排列月 + var month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; + 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 + }; + }); + }); }, - 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; - } - } + 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); + } + }] + }] + }; }, - 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); + getValue: function () { + 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.SingleTreeCombo.superclass._init.apply(this, arguments); + BI.DynamicYearMonthCombo.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.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", - 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); + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW); }); - this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.SingleTreeCombo.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] }); + this._checkDynamicValue(o.value); }, - populate: function (items) { - this.combo.populate(items); - }, - - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.trigger.setValue(v); - this.popup.setValue(v); + _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; + } }, - 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: "" - }); + hideView: function () { + this.combo.hideView(); }, - _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); - }); - - this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleTreePopup.EVENT_CHANGE); - }); - - this.check(); + setValue: function (v) { + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); }, getValue: function () { - return this.tree.getValue(); - }, - - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.tree.setValue(v); + return this.storeValue; }, - populate: function (items) { - BI.SingleTreePopup.superclass.populate.apply(this, arguments); - this.tree.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.SingleTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_level_tree", BI.SingleTreePopup);/** - * @class BI.SingleTreeTrigger +BI.extend(BI.DynamicYearMonthCombo, { + Static: 1, + Dynamic: 2 +});/** + * 年月 + * + * Created by GUY on 2015/9/2. + * @class BI.DynamicYearMonthPopup * @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: "" - }); +BI.DynamicYearMonthPopup = BI.inherit(BI.Widget, { + constants: { + tabHeight: 30 }, - _init: function () { - BI.SingleTreeTrigger.superclass._init.apply(this, arguments); + props: { + baseCls: "bi-year-month-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 + }, - var self = this, o = this.options; + 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 + }] + }; + }, - this.trigger = BI.createWidget({ - type: "bi.select_text_trigger", - element: this, - text: o.text, - items: o.items, - height: o.height, - value: o.value - }); + _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); + } }, - _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; - } - }); + _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) { - v = BI.isArray(v) ? v : [v]; - this.options.value = v; - this.trigger.setValue(v); - this._checkTitle(); + 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 this.options.value || []; - }, - - populate: function (items) { - BI.SingleTreeTrigger.superclass.populate.apply(this, arguments); - this.trigger.populate(items); + 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") + }, -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, { - - _defaultConfig: function () { - return BI.extend(BI.SwitchTree.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-switch-tree", - items: [] - }); + props: { + extraCls: "bi-year-month-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, _init: function () { - BI.SwitchTree.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.tab = BI.createWidget({ - type: "bi.tab", + 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, - tab: null, - showIndex: BI.SwitchTree.SelectType.SingleSelect, - cardCreator: BI.bind(this._createTree, 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); }, - _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; - } - }, + _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 + } + }; + } - _removeIsParent: function (items) { - BI.each(items, function (i, item) { - BI.isNotNull(item.isParent) && delete item.isParent; + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_CONFIRM); }); - return items; + 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; }, - 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; + _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(); + } } }, - setSelect: function (v) { - this.tab.setSelect(v); + _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; }, - getSelect: function () { - return this.tab.getSelect(); + _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; - switch (this.getSelect()) { - case BI.SwitchTree.SelectType.SingleSelect: - this.levelTree.setValue(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.SwitchTree.SelectType.MultiSelect: - this.tree.setValue(v); + case BI.DynamicDateCombo.Static: + default: + value = value || {}; + var month = BI.isNull(value.month) ? null : value.month; + this.yearEditor.setValue(value.year); + this.yearEditor.setTitle(value.year); + this.monthEditor.setValue(month); + this.monthEditor.setTitle(month); break; } }, getValue: function () { - return this.tab.getValue(); + return this.storeValue; }, - 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))); - } + getKey: function () { + return this.yearEditor.getValue() + "-" + this.monthEditor.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, { +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, @@ -108987,15 +107540,14 @@ BI.DateInterval = BI.inherit(BI.Single, { DATE_MIN_VALUE: "1900-01-01", DATE_MAX_VALUE: "2099-12-31" }, - _defaultConfig: function () { - var conf = BI.DateInterval.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-date-interval" - }); + + props: { + extraCls: "bi-year-month-interval" }, + _init: function () { var self = this, o = this.options; - BI.DateInterval.superclass._init.apply(this, arguments); + BI.YearMonthInterval.superclass._init.apply(this, arguments); o.value = o.value || {}; this.left = this._createCombo(o.value.start); @@ -109043,16 +107595,16 @@ BI.DateInterval = BI.inherit(BI.Single, { _createCombo: function (v) { var self = this; var combo = BI.createWidget({ - type: "bi.dynamic_date_combo", + type: "bi.dynamic_year_month_combo", value: v }); - combo.on(BI.DynamicDateCombo.EVENT_ERROR, function () { + combo.on(BI.DynamicYearMonthCombo.EVENT_ERROR, function () { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.DateInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); }); - combo.on(BI.DynamicDateCombo.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)) { @@ -109061,14 +107613,14 @@ BI.DateInterval = BI.inherit(BI.Single, { BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { offsetStyle: "center" }); - self.fireEvent(BI.DateInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); } else { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); } }); - combo.on(BI.DynamicDateCombo.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)) { @@ -109077,57 +107629,62 @@ BI.DateInterval = BI.inherit(BI.Single, { BI.Bubbles.show("error", BI.i18nText("BI-Time_Interval_Error_Text"), self, { offsetStyle: "center" }); - self.fireEvent(BI.DateInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.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.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW, function () { + self.left.hideView(); + self.right.hideView(); }); - combo.on(BI.DynamicDateCombo.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.DateInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); }else{ self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.DateInterval.EVENT_CHANGE); + self.fireEvent(BI.YearMonthInterval.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; + 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]; + return !BI.checkDateVoid(obj.year, obj.month, 1, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, + + // 判格式合法 _check: function (smallDate, bigDate) { var smallObj = smallDate.match(/\d+/g), bigObj = bigDate.match(/\d+/g); return this._dateCheck(smallDate) && BI.checkDateLegal(smallDate) && this._checkVoid({ year: smallObj[0], month: smallObj[1], - day: smallObj[2] + day: 1 }) && this._dateCheck(bigDate) && BI.checkDateLegal(bigDate) && this._checkVoid({ year: bigObj[0], month: bigObj[1], - day: bigObj[2] + day: 1 }); }, + _compare: function (smallDate, bigDate) { - smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); - bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + smallDate = BI.parseDateTime(smallDate, "%Y-%X").print("%Y-%X"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X").print("%Y-%X"); return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; }, _setTitle: function (v) { @@ -109149,257 +107706,231 @@ BI.DateInterval = BI.inherit(BI.Single, { return {start: this.left.getValue(), end: this.right.getValue()}; } }); -BI.DateInterval.EVENT_VALID = "EVENT_VALID"; -BI.DateInterval.EVENT_ERROR = "EVENT_ERROR"; -BI.DateInterval.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.date_interval", BI.DateInterval);/** - * Created by Baron on 2015/10/19. +BI.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.YearCard + * @extends BI.Trigger */ -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 () { - var conf = BI.TimeInterval.superclass._defaultConfig.apply(this, arguments); - return BI.extend(conf, { - extraCls: "bi-time-interval" - }); +BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-year-month-card" }, - _init: function () { - var self = this, o = this.options; - BI.TimeInterval.superclass._init.apply(this, arguments); - o.value = o.value || {}; - this.left = this._createCombo(o.value.start); - this.right = this._createCombo(o.value.end); - this.label = BI.createWidget({ - type: "bi.label", - height: this.constants.height, - width: this.constants.width, - text: "-" - }); - BI.createWidget({ - element: self, - type: "bi.center", - hgap: 15, - height: this.constants.height, + render: function () { + var self = this; + return { + type: "bi.vertical", items: [{ - type: "bi.absolute", - items: [{ - el: self.left, - left: this.constants.offset, - right: 0, - top: 0, - bottom: 0 + 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.absolute", - items: [{ - el: self.right, - left: 0, - right: this.constants.offset, - top: 0, - bottom: 0 + 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"); + } }] - }] - }); - 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_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); - } - }); - - 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); - } - }); - - 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); - // } - // }); + }], + vgap: 10, + hgap: 10 + }; + }, - 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{ - self._clearTitle(); - self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.TimeInterval.EVENT_CHANGE); - } - }); - return combo; + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - _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 (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)); }, - _checkVoid: function (obj) { - return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; + + 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: {} }, - _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] + + _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 + }); }); }, - _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); + + 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 {start: this.left.getValue(), end: this.right.getValue()}; + 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.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 - }); +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.YearCombo.superclass._init.apply(this, arguments); + BI.DynamicYearQuarterCombo.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_quarter_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 () { + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_START, function () { self.combo.isViewVisible() && self.combo.hideView(); }); - this.trigger.on(BI.YearTrigger.EVENT_STOP, function () { + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () { self.combo.showView(); }); - this.trigger.on(BI.YearTrigger.EVENT_ERROR, function () { + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_ERROR, function () { self.combo.isViewVisible() && self.combo.hideView(); }); - this.trigger.on(BI.YearTrigger.EVENT_CONFIRM, function () { + this.trigger.on(BI.DynamicYearQuarterTrigger.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); + self.storeValue = self.trigger.getValue(); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); }); this.combo = BI.createWidget({ type: "bi.combo", - element: this, - destroyWhenHide: true, isNeedAdjustHeight: false, isNeedAdjustWidth: false, el: this.trigger, @@ -109407,16 +107938,38 @@ BI.YearCombo = BI.inherit(BI.Widget, { minWidth: 85, stopPropagation: false, el: { - type: "bi.year_popup", + type: "bi.dynamic_year_quarter_popup", ref: function () { self.popup = this; }, listeners: [{ - eventName: BI.YearPopup.EVENT_CHANGE, + 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.YearCombo.EVENT_CONFIRM); + self.fireEvent(BI.DynamicDateCombo.EVENT_CONFIRM); } }], behaviors: o.behaviors, @@ -109427,569 +107980,458 @@ 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); - }); - }, - - setValue: function (v) { - this.combo.setValue(v || ""); - }, - - getValue: function () { - if (BI.isNull(this.popup)) { - return this.options.value; - } else { - return this.popup.getValue(); - } - } -}); -BI.YearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_combo", BI.YearCombo);/** - * 年份展示面板 - * - * 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 + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW); }); - this.navigation = BI.createWidget({ - type: "bi.navigation", + BI.createWidget({ + type: "bi.htape", element: this, - single: true, - logic: { - dynamic: true - }, - tab: { - cls: "year-popup-navigation bi-high-light bi-border-top", - height: 25, - items: [backBtn, preBtn] + ref: function () { + self.comboWrapper = this; }, - 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); + 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); + }, - if(BI.isKey(o.value)){ - this.setValue(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; } }, - getValue: function () { - return this.selectedYear; + setValue: function (v) { + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); }, - 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); - } + getValue: function () { + return this.storeValue; } + }); -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.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 }, - _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-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 }, - _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 - }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.YearTrigger.EVENT_FOCUS); - }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.YearTrigger.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); - }); - 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.YearTrigger.EVENT_START); - }); - this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.YearTrigger.EVENT_ERROR); - }); - BI.createWidget({ - element: this, - type: "bi.htape", - items: [ - { - el: this.editor - }, { - el: { + + 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", + 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.quarterEditor, { + el: { + type: "bi.text_button", + text: BI.i18nText("BI-Multi_Date_Quarter"), + 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_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/case.js b/dist/case.js index c129cb255..5582e2b01 100644 --- a/dist/case.js +++ b/dist/case.js @@ -1605,7 +1605,7 @@ BI.Calendar = BI.inherit(BI.Widget, { min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 year: 2015, - month: 7, // 7表示八月 + month: 8, day: 25 }); }, @@ -1623,18 +1623,23 @@ BI.Calendar = BI.inherit(BI.Widget, { var MD = Date._MD.slice(0); MD[1] = BI.isLeapYear(log.ymd[0]) ? 29 : 28; + // 日期所在月第一天 De.setFullYear(log.ymd[0], log.ymd[1], 1); + // 是周几 log.FDay = De.getDay(); + // 当前月页第一天是几号 log.PDay = MD[M === 0 ? 11 : M - 1] - log.FDay + 1; log.NDay = 1; var items = []; BI.each(BI.range(42), function (i) { var td = {}, YY = log.ymd[0], MM = log.ymd[1] + 1, DD; + // 上个月的日期 if (i < log.FDay) { td.lastMonth = true; DD = i + log.PDay; + // 上一年 MM === 1 && (YY -= 1); MM = MM === 1 ? 12 : MM - 1; } else if (i >= log.FDay && i < log.FDay + MD[log.ymd[1]]) { @@ -1677,7 +1682,7 @@ BI.Calendar = BI.inherit(BI.Widget, { vgap: 10 }] }); - var days = this._dateCreator(o.year, o.month, o.day); + var days = this._dateCreator(o.year, o.month - 1, o.day); items = []; items.push(days.slice(0, 7)); items.push(days.slice(7, 14)); @@ -6581,7 +6586,8 @@ BI.ClearEditor = BI.inherit(BI.Widget, { allowBlank: true, errorText: o.errorText, validationChecker: o.validationChecker, - quitChecker: o.quitChecker + quitChecker: o.quitChecker, + value: o.value }); this.clear = BI.createWidget({ type: "bi.icon_button", @@ -6665,7 +6671,11 @@ BI.ClearEditor = BI.inherit(BI.Widget, { self.fireEvent(BI.ClearEditor.EVENT_STOP); }); - this.clear.invisible(); + if (BI.isKey(o.value)) { + this.clear.visible(); + } else { + this.clear.invisible(); + } }, _checkClear: function () { diff --git a/dist/demo.js b/dist/demo.js index 3933fd8ca..5f3ec7afb 100644 --- a/dist/demo.js +++ b/dist/demo.js @@ -2471,7 +2471,8 @@ Demo.ClearEditor = BI.inherit(BI.Widget, { type: "bi.clear_editor", cls: "bi-border", width: 300, - watermark: "这个是带清除按钮的" + watermark: "这个是带清除按钮的", + value: 123 }], vgap: 20 }; @@ -12096,7 +12097,7 @@ BI.shortcut("demo.tips", Demo.Tips);Demo.DatePane = BI.inherit(BI.Widget, { type: 1, value: { year: 2017, - month: 11, + month: 12, day: 11 } }, @@ -12116,7 +12117,7 @@ BI.shortcut("demo.tips", Demo.Tips);Demo.DatePane = BI.inherit(BI.Widget, { type: 1, value: { year: 2017, - month: 11, + month: 12, day: 11, hour: 12, minute: 12, @@ -12139,7 +12140,7 @@ BI.shortcut("demo.tips", Demo.Tips);Demo.DatePane = BI.inherit(BI.Widget, { handler: function () { self.datepane.setValue({ year: 2017, - month: 11, + month: 12, day: 31 }); } @@ -12182,7 +12183,7 @@ Demo.Date = BI.inherit(BI.Widget, { type: 1, value: { year: 2018, - month: 1, + month: 2, day: 23 } } @@ -12203,7 +12204,7 @@ Demo.Date = BI.inherit(BI.Widget, { type: 1, value: { year: 2018, - month: 1, + month: 2, day: 23 } } @@ -14556,7 +14557,7 @@ Demo.YearMonthCombo = BI.inherit(BI.Widget, { type: 1, value: { year: 2018, - month: 0 + month: 1 } } }, { @@ -14568,12 +14569,12 @@ Demo.YearMonthCombo = BI.inherit(BI.Widget, { width: 300 }, { type: "bi.button", - text: "setVlaue '2017-12'", + text: "setValue '2017-12'", width: 300, handler: function () { self.widget.setValue({ year: 2017, - month: 11 + month: 12 }); } }], @@ -14608,7 +14609,7 @@ BI.shortcut("demo.year_month_combo", Demo.YearMonthCombo);Demo.YearMonthInterval type: 1, value: { year: 2018, - month: 0 + month: 1 } } }, diff --git a/dist/widget.js b/dist/widget.js index b24093c2d..f57e2623c 100644 --- a/dist/widget.js +++ b/dist/widget.js @@ -468,7 +468,7 @@ BI.MonthDateCombo = BI.inherit(BI.Trigger, { }, setValue: function (v) { - this.trigger.setValue(v + 1); + this.trigger.setValue(v); this.popup.setValue(v); }, @@ -573,7 +573,7 @@ BI.DatePicker = BI.inherit(BI.Widget, { if (self._month === 0) { self.setValue({ year: self.year.getValue() - 1, - month: 11 + month: 12 }); } else { self.setValue({ @@ -665,14 +665,14 @@ BI.DatePicker = BI.inherit(BI.Widget, { _checkLeftValid: function () { var o = this.options; - var valid = !(this._month === 0 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 1 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); this.left.setEnable(valid); return valid; }, _checkRightValid: function () { var o = this.options; - var valid = !(this._month === 11 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 12 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); this.right.setEnable(valid); return valid; }, @@ -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,313 +2174,581 @@ 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(); }, - dishover: function () { + 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"); + + }, + + dishover: function () { BI.DownListGroupItem.superclass.dishover.apply(this, arguments); this.icon1.element.removeClass("hover"); this.icon2.element.removeClass("hover"); @@ -2537,1063 +3053,1595 @@ 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; } - }; - } - } - }] + }, { + 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.setValue(this.options.value); - }, - - _checkValueValid: function (value) { - return BI.isNull(value) || BI.isEmptyObject(value) || BI.isEmptyString(value); + 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", + 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("EVENT_CHANGE"); + 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() + 1, + 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], + 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) + "-" + 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"), + 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.textButton = this; + 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.TextButton.EVENT_CHANGE, + eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, action: function () { - self.fireEvent(BI.DynamicYearPopup.BUTTON_lABEL_EVENT_CHANGE); + self.popup.setValue(self.storeValue); + self.fireEvent(BI.DynamicDateTimeCombo.EVENT_BEFORE_POPUPVIEW); } }] - }, { - type: "bi.text_button", - forceCenter: true, - cls: "bi-border-top bi-high-light", - shadow: true, - text: BI.i18nText("BI-Basic_OK"), + }, + 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.TextButton.EVENT_CHANGE, + eventName: BI.IconButton.EVENT_CHANGE, action: function () { - self.fireEvent(BI.DynamicYearPopup.BUTTON_OK_EVENT_CHANGE); + if (self.combo.isViewVisible()) { + self.combo.hideView(); + } else { + self.combo.showView(); + } } }] - }]] - }, - height: 24 - }] + }, + top: 0, + right: 0 + }] + }], + ref: function (_ref) { + self.comboWrapper = _ref; + } }; }, - _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); + 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; } }, - _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: [{ + 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.DynamicYearCombo.Static: + case BI.DynamicDateCombo.Static: var date = BI.DynamicDateHelper.getCalculation(self.dynamicPane.getValue()); - self.year.setValue({year: date.getFullYear()}); + self.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth(), + day: date.getDate() + }); + self.timeSelect.setValue(); self._setInnerValue(); break; - case BI.DynamicYearCombo.Dynamic: + case BI.DynamicDateCombo.Dynamic: default: - if(self.storeValue && self.storeValue.type === BI.DynamicYearCombo.Dynamic) { + if(self.storeValue && self.storeValue.type === BI.DynamicDateCombo.Dynamic) { self.dynamicPane.setValue(self.storeValue.value); }else{ self.dynamicPane.setValue({ @@ -3608,6 +4656,22 @@ BI.DynamicYearPopup = BI.inherit(BI.Widget, { }; }, + _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; @@ -3623,135 +4687,388 @@ BI.DynamicYearPopup = BI.inherit(BI.Widget, { break; case BI.DynamicDateCombo.Static: default: - this.year.setValue(value); - this.textButton.setValue(BI.i18nText("BI-Basic_Current_Year")); + if (this._checkValueValid(value)) { + var date = BI.getDate(); + this.ymd.setValue({ + year: date.getFullYear(), + month: date.getMonth() + 1, + 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: this.dateTab.getSelect(), - value: this.dateTab.getValue() + type: type, + value: type === BI.DynamicDateTimeCombo.Static ? BI.extend(this.ymd.getValue(), this.timeSelect.getValue()) : this.dynamicPane.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") - }, +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.DynamicYearTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-year-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }); + props: { + baseCls: "bi-date-time-select bi-border-top" }, - _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; - }, + + 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, - watermark: BI.i18nText("BI-Basic_Unrestricted"), allowBlank: true, - errorText: function (v) { - return !BI.isPositiveInteger(v) ? c.errorText : c.errorTextInvalid; + 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.DynamicYearTrigger.EVENT_FOCUS); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_FOCUS); }); this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_STOP); + 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.setValue(value); + self.editor.setState(value); } + if (BI.isNotEmptyString(value)) { + var date = value.split(/-|\s|:/); self.storeValue = { type: BI.DynamicDateCombo.Static, value: { - year: value + year: date[0] | 0, + month: date[1], + day: date[2] | 0, + hour: date[3] | 0, + minute: date[4] | 0, + second: date[5] | 0 } }; } - - self.fireEvent(BI.DynamicYearTrigger.EVENT_CONFIRM); - }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); - } + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_CONFIRM); }); this.editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_START); + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_START); }); - this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DynamicYearTrigger.EVENT_ERROR); + this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { + self.fireEvent(BI.DynamicDateTimeTrigger.EVENT_CHANGE); }); BI.createWidget({ - element: this, type: "bi.htape", + element: this, 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 + el: BI.createWidget(), + width: 30 }] }); 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")); + _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; + } } - return value; + }, + + _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"); + 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; + var type, value, self = this; var date = BI.getDate(); this.storeValue = v; if (BI.isNotNull(v)) { @@ -3766,6762 +5083,2120 @@ BI.shortcut("bi.dynamic_year_popup", BI.DynamicYearPopup);BI.DynamicYearTrigger break; case BI.DynamicDateCombo.Static: default: - value = value || {}; - this.editor.setState(value.year); - this.editor.setValue(value.year); - this.editor.setTitle(value.year); + if (BI.isNull(value) || BI.isNull(value.day)) { + this.editor.setState(""); + this.editor.setValue(""); + this.setTitle(""); + } else { + var dateStr = value.year + "-" + (value.month) + "-" + value.day + " " + + (value.hour || "00") + ":" + (value.minute || "00") + ":" + (value.second || "00"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + this.setTitle(dateStr); + } 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)); + return this.editor.getValue(); }, - 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) - }; + return this.storeValue; } -}); -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 - }; - }); +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 }); }, - - render: function () { + _init: function () { + this.options.height -= 2; + BI.SearchEditor.superclass._init.apply(this, arguments); 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; + 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 }, - 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 - }; - }, + { + el: self.editor + }, + { + el: this.clear, + width: 25 + } + ] + }); + this.editor.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); - 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, { + 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); + }); - 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.editor.on(BI.Editor.EVENT_VALID, function () { + self.fireEvent(BI.SearchEditor.EVENT_VALID); }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_START, function () { - self.combo.isViewVisible() && self.combo.hideView(); + this.editor.on(BI.Editor.EVENT_ERROR, function () { + self.fireEvent(BI.SearchEditor.EVENT_ERROR); }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_STOP, function () { - self.combo.showView(); + this.editor.on(BI.Editor.EVENT_ENTER, function () { + self.fireEvent(BI.SearchEditor.EVENT_ENTER); }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_ERROR); + this.editor.on(BI.Editor.EVENT_RESTRICT, function () { + self.fireEvent(BI.SearchEditor.EVENT_RESTRICT); }); - this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_VALID, function () { - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_VALID); + this.editor.on(BI.Editor.EVENT_EMPTY, function () { + self._checkClear(); + self.fireEvent(BI.SearchEditor.EVENT_EMPTY); }); - 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.editor.on(BI.Editor.EVENT_REMOVE, function () { + self.fireEvent(BI.SearchEditor.EVENT_REMOVE); }); - this.trigger.on(BI.DynamicYearMonthCombo.EVENT_FOCUS, function () { - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_FOCUS); + this.editor.on(BI.Editor.EVENT_CONFIRM, function () { + self.fireEvent(BI.SearchEditor.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.editor.on(BI.Editor.EVENT_START, function () { + self.fireEvent(BI.SearchEditor.EVENT_START); }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.popup.setValue(self.storeValue); - self.fireEvent(BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW); + this.editor.on(BI.Editor.EVENT_PAUSE, function () { + self.fireEvent(BI.SearchEditor.EVENT_PAUSE); }); - - 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.editor.on(BI.Editor.EVENT_STOP, function () { + self.fireEvent(BI.SearchEditor.EVENT_STOP); }); - this._checkDynamicValue(o.value); + + this.clear.invisible(); }, - _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; + _checkClear: function () { + if (!this.getValue()) { + this.clear.invisible(); + } else { + this.clear.visible(); } }, - hideView: function () { - this.combo.hideView(); + focus: function () { + this.editor.focus(); }, - setValue: function (v) { - this.storeValue = v; - this.trigger.setValue(v); - this._checkDynamicValue(v); + blur: function () { + this.editor.blur(); }, getValue: function () { - return this.storeValue; + if (this.isValid()) { + var res = this.editor.getValue().match(/[\S]+/g); + return BI.isNull(res) ? "" : res[res.length - 1]; + } }, - getKey: function () { - return this.trigger.getKey(); - } + 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.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.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.extend(BI.DynamicYearMonthCombo, { - Static: 1, - Dynamic: 2 -});/** - * 年月 - * - * Created by GUY on 2015/9/2. - * @class BI.DynamicYearMonthPopup - * @extends BI.Trigger +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.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 +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 + }); }, - 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 - }] - }; + _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 + }); }, - _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); + _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); + }); - _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; - } - } - }] - }; + 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.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; - } + this.editor.setValue(v); }, getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; + return this.editor.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") - }, +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"; - props: { - extraCls: "bi-year-month-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 +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.DynamicYearMonthTrigger.superclass._init.apply(this, arguments); - var o = this.options; + 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, { - this.yearEditor = this._createEditor(true); - this.monthEditor = this._createEditor(false); + _defaultConfig: function () { + return BI.extend(BI.FileManagerButtonGroup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-button_group", + items: [] + }); + }, - BI.createWidget({ + _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, - 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 + chooseType: BI.Selection.Multi, + items: this._formatItems(o.items), + layouts: [{ + type: "bi.vertical" }] }); - 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); + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - 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()); + _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; + }, - return editor; + setValue: function (v) { + this.button_group.setValue(v); }, - _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; + getValue: function () { + return this.button_group.getValue(); }, - _autoSwitch: function (v) { - if (BI.checkDateLegal(v)) { - if (v.length === 4 && this._yearCheck(v)) { - this.monthEditor.focus(); - } - } + getNotSelectedValue: function () { + return this.button_group.getNotSelectedValue(); }, - _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; + getAllLeaves: function () { + return this.button_group.getAllLeaves(); }, - _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)); + getAllButtons: function () { + return this.button_group.getAllButtons(); }, - 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; - } + getSelectedButtons: function () { + return this.button_group.getSelectedButtons(); }, - getValue: function () { - return this.storeValue; + getNotSelectedButtons: function () { + return this.button_group.getNotSelectedButtons(); }, - getKey: function () { - return this.yearEditor.getValue() + "-" + this.monthEditor.getValue(); + populate: function (items) { + this.button_group.populate(this._formatItems(items)); } }); -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.FileManagerButtonGroup.EVENT_CHANGE = "FileManagerButtonGroup.EVENT_CHANGE"; +BI.shortcut("bi.file_manager_button_group", BI.FileManagerButtonGroup);/** + * 文件管理控件 * - * Created by GUY on 2015/9/2. - * @class BI.YearCard - * @extends BI.Trigger + * Created by GUY on 2015/12/11. + * @class BI.FileManager + * @extends BI.Widget */ -BI.DynamicYearQuarterCard = BI.inherit(BI.Widget, { +BI.FileManager = BI.inherit(BI.Widget, { - props: { - baseCls: "bi-year-month-card" + _defaultConfig: function () { + return BI.extend(BI.FileManager.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager", + el: {}, + items: [] + }); }, - render: function () { - var self = this; - return { - type: "bi.vertical", + _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: [{ - type: "bi.label", - text: BI.i18nText("BI-Multi_Date_Relative_Current_Time"), - textAlign: "left", - height: 24 + el: this.list, + left: 0, + right: 0, + top: 0, + bottom: 10 }, { - 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 - }; + el: this.nav, + left: 40, + right: 100, + top: 0 + }] + }); }, - _createValue: function (type, v) { - return { - dateType: type, - value: Math.abs(v), - offset: v > 0 ? 1 : 0 - }; + setValue: function (value) { + this.selectedValues = value || []; + this.list.setValue(this.selectedValues); }, - 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 obj = this.list.getValue(); + var res = obj.type === BI.Selection.All ? obj.assist : obj.value; + res.pushDistinctArray(this.selectedValues); + return res; }, - 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, { + _populate: function (items) { + this.list.populate(items); + }, - props: { - baseCls: "bi-static-year-quarter-card", - behaviors: {} + getSelectedValue: function () { + return this.nav.getValue()[0]; }, - _createQuarter: function () { + getSelectedId: function () { + return this.nav.getId()[0]; + }, - 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 - }); + 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 }); }, - render: function () { + _init: function () { + BI.FileManagerFileItem.superclass._init.apply(this, arguments); var self = this, o = this.options; - return { - type: "bi.vertical", + 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: [{ - 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 - }); - } - }] + el: this.checked, + width: 36 }, { - type: "bi.button_group", - behaviors: o.behaviors, - ref: function () { - self.quarter = this; + el: { + type: "bi.icon_button", + cls: "create-by-me-file-font" }, - 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); - } - }] + width: 20 + }, { + el: { + type: "bi.label", + textAlign: "left", + height: o.height, + text: o.text, + value: o.value + } }] - }; + }); }, + getAllLeaves: function () { + return [this.options.value]; + }, - getValue: function () { - return { - year: this.selectedYear, - quarter: this.selectedQuarter - }; + isSelected: function () { + return this.checked.isSelected(); }, - 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); - } + setSelected: function (v) { + this.checked.setSelected(v); } }); -BI.StaticYearQuarterCard.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.static_year_quarter_card", BI.StaticYearQuarterCard);BI.DynamicYearQuarterCombo = BI.inherit(BI.Widget, { +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, { - props: { - baseCls: "bi-year-quarter-combo bi-border", - behaviors: {}, - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 + _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 + }); }, _init: function () { - BI.DynamicYearQuarterCombo.superclass._init.apply(this, arguments); + BI.FileManagerFolderItem.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.checked = BI.createWidget({ + type: "bi.multi_select_bar", + text: "", + width: 36, + height: o.height }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_STOP, function () { - self.combo.showView(); + this.checked.on(BI.Controller.EVENT_CHANGE, function () { + arguments[2] = self; + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_ERROR, function () { - self.combo.isViewVisible() && self.combo.hideView(); + this.button = BI.createWidget({ + type: "bi.text_button", + textAlign: "left", + height: o.height, + text: o.text, + value: o.value }); - 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.button.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CHANGE, o.value, self); }); - 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); - }); + this.tree = new BI.Tree(); + this.tree.initTree([{ + id: o.id, + children: o.children + }]); + this.selectValue = []; BI.createWidget({ type: "bi.htape", element: this, - ref: function () { - self.comboWrapper = this; - }, items: [{ + el: this.checked, + width: 36 + }, { el: { type: "bi.icon_button", - cls: "bi-trigger-icon-button date-change-h-font", - width: 24, - height: 24, - ref: function () { - self.changeIcon = this; - } + cls: "create-by-me-folder-font" }, - width: 24 - }, this.combo] + width: 20 + }, { + el: this.button + }] }); - 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; + setAllSelected: function (v) { + this.checked.setSelected(v); + this.selectValue = []; + }, + + setHalfSelected: function (v) { + this.checked.setHalfSelected(v); + if(!v) { + this.selectValue = []; } }, setValue: function (v) { - this.storeValue = v; - this.trigger.setValue(v); - this._checkDynamicValue(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; + } + }, + + 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); + } + }); + 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); + } + } + }); + return res; }, getValue: function () { - return this.storeValue; + 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.DynamicYearQuarterCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DynamicYearQuarterCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.dynamic_year_quarter_combo", BI.DynamicYearQuarterCombo); +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.extend(BI.DynamicYearQuarterCombo, { - Static: 1, - Dynamic: 2 -});BI.DynamicYearQuarterPopup = BI.inherit(BI.Widget, { - constants: { - tabHeight: 30 + _defaultConfig: function () { + return BI.extend(BI.FileManagerList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-file-manager-list", + el: {}, + items: [] + }); }, - 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; - } - } - }] - }; + _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) { - 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; - } + this.list.setValue({ + value: v + }); }, getValue: function () { - return { - type: this.dateTab.getSelect(), - value: this.dateTab.getValue() - }; - } + return this.list.getValue(); + }, + populate: function (items) { + this.list.populate(items); + this.list.setToolBarVisible(true); + } }); -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, { +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: { - hgap: 4, - vgap: 2, - errorText: BI.i18nText("BI-Please_Input_Positive_Integer"), - errorTextInvalid: BI.i18nText("BI-Year_Trigger_Invalid_Text") + normal_color: "#ffffff", + select_color: "#eff1f4" }, - - props: { - extraCls: "bi-year-quarter-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 + _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.DynamicYearQuarterTrigger.superclass._init.apply(this, arguments); - var o = this.options; - - this.yearEditor = this._createEditor(true); - this.quarterEditor = this._createEditor(false); - + 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); + } + }); BI.createWidget({ + type: "bi.default", + element: this, + items: [this.button] + }); + BI.createWidget({ + type: "bi.absolute", 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 + el: svg, + right: -15, + top: 0, + bottom: 0 }] }); - 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 - } - }; - } + isSelected: function () { + return this.button.isSelected(); + }, - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM); + 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: [] }); - editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (editor.isValid()) { - editor.blur(); - } + }, + + _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 }); - editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_START); + 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" + }] }); - editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_ERROR); + this.button_group.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - editor.on(BI.SignEditor.EVENT_CHANGE, function () { - if(isYear) { - self._autoSwitch(editor.getValue()); - } + this.button_group.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) { + self.fireEvent(BI.FileManagerNav.EVENT_CHANGE, arguments); }); - - 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; + _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(); }, - _autoSwitch: function (v) { - if (BI.checkDateLegal(v)) { - if (v.length === 4 && this._yearCheck(v)) { - this.quarterEditor.focus(); - } - } + _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; }, - _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; + getValue: function () { + return this.button_group.getValue(); }, - _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)); + getId: function () { + var ids = []; + BI.each(this.button_group.getSelectedButtons(), function (i, btn) { + ids.push(btn.attr("id")); + }); + return ids; }, - 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; - } + 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 + }); }, - getValue: function () { - return this.storeValue; + populate: function (node) { + var parents = BI.isNull(node) ? [this.tree.getRoot()] : this._getAllParents(node.id); + this.button_group.populate(this._formatNodes(parents)); } }); -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. +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. */ -!(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); - }); - }, - - _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; - }, - - setValue: function (v) { - this.button_group.setValue(v); - }, - - getValue: function () { - return this.button_group.getValue(); - }, - - getNotSelectedValue: function () { - return this.button_group.getNotSelectedValue(); - }, - - getAllLeaves: function () { - return this.button_group.getAllLeaves(); - }, - - getAllButtons: function () { - return this.button_group.getAllButtons(); - }, - - 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: [] - }); - }, - - _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 () { - 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); - }, - - getSelectedValue: function () { - return this.nav.getValue()[0]; - }, - - 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 - } - }] - }); - }, - - getAllLeaves: function () { - return [this.options.value]; - }, - - isSelected: function () { - return this.checked.isSelected(); - }, - - 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 - }); - }, - - _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 - }] - }); - }, - - 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.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); - } - }); - 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); - } - } - }); - 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: [] - }); - }, - - _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) { - this.list.setValue({ - value: v - }); - }, - - 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 - }); - }, - - _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 { - path.attr("fill", c.normal_color); - } - }); - 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 - }] - }); - }, - - 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: [] - }); - }, - - _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); - }); - }, - - _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(); - }, - - _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; - }, - - 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)); - } -}); -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(); - - 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(); - }, - - _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); - }); - - 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%" - }; - }, - - _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%" - }; - }, - - _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%" - }] - }); - }, - - _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; - }, - - _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(); - }, - - _setLabelTwoPosition: function (percent) { - this.labelTwo.element.css({left: percent + "%"}); - this._checkOverlap(); - }, - - _setSliderOnePosition: function (percent) { - this.sliderOne.element.css({left: percent + "%"}); - }, - - _setSliderTwoPosition: function (percent) { - this.sliderTwo.element.css({left: percent + "%"}); - }, - - _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); - } - }, - - _setAllPosition: function (one, two) { - this._setSliderOnePosition(one); - this._setLabelOnePosition(one); - this._setSliderTwoPosition(two); - this._setLabelTwoPosition(two); - this._setBlueTrack(); - }, - - _setVisible: function (visible) { - this.sliderOne.setVisible(visible); - this.sliderTwo.setVisible(visible); - this.labelOne.setVisible(visible); - this.labelTwo.setVisible(visible); - }, - - _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; - }, - - // 其中取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)); - - }, - - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); - }, - - _setDraggableEnable: function (enable) { - this.sliderOne.setEnable(enable); - this.sliderTwo.setEnable(enable); - }, - - _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; - - }, - - _assertValue: function (value) { - if(value <= this.min) { - return this.min; - } - if(value >= this.max) { - return this.max; - } - return value; - }, - - getValue: function () { - 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); - } - }, - - 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; - } - } - }, - - 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.IntervalSlider.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.interval_slider", BI.IntervalSlider);/** - * Created by zcf on 2017/3/1. - * 万恶的IEEE-754 - * 使用字符串精确计算含小数加法、减法、乘法和10的指数倍除法,支持负数 - */ -BI.AccurateCalculationModel = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.AccurateCalculationModel.superclass._defaultConfig.apply(this, arguments), { - baseCls: "" - }); - }, - - _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; - } - 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); - - 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; - } - }, - - _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); +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 + }, - 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.IntervalSlider.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-interval-slider bi-slider-track", + digit: false, + unit: "" + }); }, - _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)); + _init: function () { + BI.IntervalSlider.superclass._init.apply(this, arguments); - return this._accurateAddition(this._accurateAddition(this._accurateAddition(integerResult, dec1Int2), int1dec2), dec1dec2); - }, + var self = this; + var c = this._constant; + this.enable = false; + this.valueOne = ""; + this.valueTwo = ""; + this.calculation = new BI.AccurateCalculationModel(); - _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); + // 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(); - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; + 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); } - return resultTemp; - } - }, + }); + 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); + }); - 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); + 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); } - return this._accurateSubtraction(-num1, -num2); - } - }, + }); + 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); + }); - 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); - } - }, + 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); - 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); - } + 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() + ] + }); }, - accurateDivisionTenExponent: function (num1, n) { - if (num1 >= 0) { - return this._accurateDivisionTenExponent(num1, n); + _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; } - return -this._accurateDivisionTenExponent(-num1, n); - } -});/** - * 月份下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.MonthCombo - * @extends BI.Trigger - */ -BI.MonthCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.MonthCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-month-combo", - behaviors: {}, - height: 25 - }); + this._setBlueTrack(); }, - _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 - }); + _rePosBySizeAfterStop: function (size, isLeft) { + var percent = size * 100 / (this._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + isLeft ? this._setSliderOnePosition(significantPercent) : this._setSliderTwoPosition(significantPercent); + }, - this.trigger.on(BI.MonthTrigger.EVENT_CONFIRM, function (v) { - if (self.combo.isViewVisible()) { - return; + _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 - }; - }); - }); - - 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 + _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.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); + _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; + }, + + _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 - }; + getValue: function () { + 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 - }, - _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; - } +BI.MonthCombo = BI.inherit(BI.Widget, { + _defaultConfig: function () { + 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 = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; + 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 + }; + }); + }); + + 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 + })))); }, - getValue: function () { - return this.quarter.getValue()[0]; + 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); }, - 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(); + 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.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); + 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; - - this.trigger = BI.createWidget({ - type: "bi.single_tree_trigger", - text: o.text, - height: o.height, - items: o.items, - value: o.value - }); + setRightHorizontalScroll: function (scrollLeft) { + this.table.setRightHorizontalScroll(scrollLeft); + }, - this.popup = BI.createWidget({ - type: "bi.select_level_tree", - items: o.items, - value: o.value - }); + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); + this.sequence.setVerticalScroll(scrollTop); + }, - this.combo = BI.createWidget({ - type: "bi.combo", - element: this, - adjustLength: 2, - el: this.trigger, - popup: { - el: this.popup - } - }); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); + }, - this.combo.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + setVPage: function (page) { + this.sequence.setVPage && this.sequence.setVPage(page); + }, - this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - }); + setHPage: function (page) { + this.sequence.setHPage && this.sequence.setHPage(page); }, - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.trigger.setValue(v); - this.popup.setValue(v); + attr: function () { + BI.SequenceTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); + this.sequence.attr.apply(this.sequence, arguments); }, - getValue: function () { - return this.popup.getValue(); + restore: function () { + this.table.restore(); + this.sequence.restore(); + }, + + 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(); + }, + + stopSearch: function () { + this.searcher.stopSearch(); }, - - setNotSelectedValue: function () { - this.list.setNotSelectedValue.apply(this.list, arguments); + + getKeyword: function () { + return this.editor.getValue(); }, - - getNotSelectedValue: function () { - return this.list.getNotSelectedValue(); + + hasMatched: function () { + return this.searcher.hasMatched(); }, - - getAllButtons: function () { - return this.list.getAllButtons(); + + hasChecked: function () { + return this.searcher.getView() && this.searcher.getView().hasChecked(); }, - - getAllLeaves: function () { - return this.list.getAllLeaves(); + + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - - getSelectedButtons: function () { - return this.list.getSelectedButtons(); + + 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 + "")); + } }, - - getNotSelectedButtons: function () { - return this.list.getNotSelectedButtons(); + + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); }, - - getIndexByValue: function (value) { - return this.list.getIndexByValue(value); + + getKey: function () { + return this.editor.getValue(); }, - - getNodeById: function (id) { - return this.list.getNodeById(id); + + getValue: function () { + return this.searcher.getValue(); }, - - getNodeByValue: function (value) { - return this.list.getNodeByValue(value); + + 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, @@ -19954,101 +17577,20 @@ BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { }, getValue: function () { - 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) { - + return this.searcher.getValue(); } }); -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] + }); - 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.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); - }, + this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleTreePopup.EVENT_CHANGE); + }); - getKey: function () { - return this.editor.getValue(); + this.check(); }, getValue: function () { - return this.searcher.getValue(); + return this.tree.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 = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; + 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 + }; + }); + }); }, - _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; + 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/case/calendar/calendar.js b/src/case/calendar/calendar.js index 747a3097c..f755fa4e0 100644 --- a/src/case/calendar/calendar.js +++ b/src/case/calendar/calendar.js @@ -14,7 +14,7 @@ BI.Calendar = BI.inherit(BI.Widget, { min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 year: 2015, - month: 7, // 7表示八月 + month: 8, day: 25 }); }, @@ -32,18 +32,23 @@ BI.Calendar = BI.inherit(BI.Widget, { var MD = Date._MD.slice(0); MD[1] = BI.isLeapYear(log.ymd[0]) ? 29 : 28; + // 日期所在月第一天 De.setFullYear(log.ymd[0], log.ymd[1], 1); + // 是周几 log.FDay = De.getDay(); + // 当前月页第一天是几号 log.PDay = MD[M === 0 ? 11 : M - 1] - log.FDay + 1; log.NDay = 1; var items = []; BI.each(BI.range(42), function (i) { var td = {}, YY = log.ymd[0], MM = log.ymd[1] + 1, DD; + // 上个月的日期 if (i < log.FDay) { td.lastMonth = true; DD = i + log.PDay; + // 上一年 MM === 1 && (YY -= 1); MM = MM === 1 ? 12 : MM - 1; } else if (i >= log.FDay && i < log.FDay + MD[log.ymd[1]]) { @@ -86,7 +91,7 @@ BI.Calendar = BI.inherit(BI.Widget, { vgap: 10 }] }); - var days = this._dateCreator(o.year, o.month, o.day); + var days = this._dateCreator(o.year, o.month - 1, o.day); items = []; items.push(days.slice(0, 7)); items.push(days.slice(7, 14)); diff --git a/src/case/editor/editor.clear.js b/src/case/editor/editor.clear.js index c784a862e..0657837da 100644 --- a/src/case/editor/editor.clear.js +++ b/src/case/editor/editor.clear.js @@ -26,7 +26,8 @@ BI.ClearEditor = BI.inherit(BI.Widget, { allowBlank: true, errorText: o.errorText, validationChecker: o.validationChecker, - quitChecker: o.quitChecker + quitChecker: o.quitChecker, + value: o.value }); this.clear = BI.createWidget({ type: "bi.icon_button", @@ -110,7 +111,11 @@ BI.ClearEditor = BI.inherit(BI.Widget, { self.fireEvent(BI.ClearEditor.EVENT_STOP); }); - this.clear.invisible(); + if (BI.isKey(o.value)) { + this.clear.visible(); + } else { + this.clear.invisible(); + } }, _checkClear: function () { diff --git a/src/widget/date/calendar/combo.month.date.js b/src/widget/date/calendar/combo.month.date.js index 07466cba9..eca405f84 100644 --- a/src/widget/date/calendar/combo.month.date.js +++ b/src/widget/date/calendar/combo.month.date.js @@ -49,7 +49,7 @@ BI.MonthDateCombo = BI.inherit(BI.Trigger, { }, setValue: function (v) { - this.trigger.setValue(v + 1); + this.trigger.setValue(v); this.popup.setValue(v); }, diff --git a/src/widget/date/calendar/picker.date.js b/src/widget/date/calendar/picker.date.js index f420e8493..5268224f7 100644 --- a/src/widget/date/calendar/picker.date.js +++ b/src/widget/date/calendar/picker.date.js @@ -29,7 +29,7 @@ BI.DatePicker = BI.inherit(BI.Widget, { if (self._month === 0) { self.setValue({ year: self.year.getValue() - 1, - month: 11 + month: 12 }); } else { self.setValue({ @@ -121,14 +121,14 @@ BI.DatePicker = BI.inherit(BI.Widget, { _checkLeftValid: function () { var o = this.options; - var valid = !(this._month === 0 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 1 && this._year === BI.parseDateTime(o.min, "%Y-%X-%d").getFullYear()); this.left.setEnable(valid); return valid; }, _checkRightValid: function () { var o = this.options; - var valid = !(this._month === 11 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); + var valid = !(this._month === 12 && this._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); this.right.setEnable(valid); return valid; }, 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/dynamicdate/dynamicdate.popup.js b/src/widget/dynamicdate/dynamicdate.popup.js index 90ffc8003..0efc24f10 100644 --- a/src/widget/dynamicdate/dynamicdate.popup.js +++ b/src/widget/dynamicdate/dynamicdate.popup.js @@ -189,7 +189,7 @@ BI.DynamicDatePopup = BI.inherit(BI.Widget, { var date = BI.getDate(); this.ymd.setValue({ year: date.getFullYear(), - month: date.getMonth(), + month: date.getMonth() + 1, day: date.getDate() }); this.textButton.setValue(BI.i18nText("BI-Multi_Date_Today")); diff --git a/src/widget/dynamicdate/dynamicdate.trigger.js b/src/widget/dynamicdate/dynamicdate.trigger.js index a770148c5..c48070870 100644 --- a/src/widget/dynamicdate/dynamicdate.trigger.js +++ b/src/widget/dynamicdate/dynamicdate.trigger.js @@ -69,7 +69,7 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { type: BI.DynamicDateCombo.Static, value: { year: date[0] | 0, - month: date[1] - 1, + month: date[1], day: date[2] | 0 } }; @@ -198,7 +198,7 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { this.editor.setValue(""); this.setTitle(""); } else { - var dateStr = value.year + "-" + (value.month + 1) + "-" + value.day; + var dateStr = value.year + "-" + (value.month) + "-" + value.day; this.editor.setState(dateStr); this.editor.setValue(dateStr); this.setTitle(dateStr); diff --git a/src/widget/dynamicdatetime/dynamicdatetime.popup.js b/src/widget/dynamicdatetime/dynamicdatetime.popup.js index 340794cfb..8342ac6b8 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.popup.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.popup.js @@ -201,7 +201,7 @@ BI.DynamicDateTimePopup = BI.inherit(BI.Widget, { var date = BI.getDate(); this.ymd.setValue({ year: date.getFullYear(), - month: date.getMonth(), + month: date.getMonth() + 1, day: date.getDate() }); this.timeSelect.setValue(); diff --git a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js index b24772d56..99f76ddfc 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js @@ -69,7 +69,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { type: BI.DynamicDateCombo.Static, value: { year: date[0] | 0, - month: date[1] - 1, + month: date[1], day: date[2] | 0, hour: date[3] | 0, minute: date[4] | 0, @@ -201,7 +201,7 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { this.editor.setValue(""); this.setTitle(""); } else { - var dateStr = value.year + "-" + (value.month + 1) + "-" + value.day + " " + + var dateStr = value.year + "-" + (value.month) + "-" + value.day + " " + (value.hour || "00") + ":" + (value.minute || "00") + ":" + (value.second || "00"); this.editor.setState(dateStr); this.editor.setValue(dateStr); diff --git a/src/widget/month/popup.month.js b/src/widget/month/popup.month.js index 8811b65f8..2fe941bfb 100644 --- a/src/widget/month/popup.month.js +++ b/src/widget/month/popup.month.js @@ -19,7 +19,7 @@ BI.MonthPopup = BI.inherit(BI.Widget, { var self = this, o = this.options; // 纵向排列月 - var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; + var month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; var items = []; items.push(month.slice(0, 2)); items.push(month.slice(2, 4)); @@ -39,7 +39,7 @@ BI.MonthPopup = BI.inherit(BI.Widget, { height: 23, width: 38, value: td, - text: td + 1 + text: td }; }); }); 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 97% rename from src/widget/dynamic/yearmonth/card.static.yearmonth.js rename to src/widget/yearmonth/card.static.yearmonth.js index e1a6c34ce..65749d8a3 100644 --- a/src/widget/dynamic/yearmonth/card.static.yearmonth.js +++ b/src/widget/yearmonth/card.static.yearmonth.js @@ -7,7 +7,7 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, { _createMonths: function () { // 纵向排列月 - var month = [0, 6, 1, 7, 2, 8, 3, 9, 4, 10, 5, 11]; + var month = [1, 7, 2, 8, 3, 9, 4, 10, 5, 11, 6, 12]; var items = []; items.push(month.slice(0, 2)); items.push(month.slice(2, 4)); @@ -27,7 +27,7 @@ BI.StaticYearMonthCard = BI.inherit(BI.Widget, { height: 23, width: 38, value: td, - text: td + 1 + text: td }; }); }); 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 99% rename from src/widget/dynamic/yearmonth/trigger.yearmonth.js rename to src/widget/yearmonth/trigger.yearmonth.js index 5e2e35ca8..6e0c428d6 100644 --- a/src/widget/dynamic/yearmonth/trigger.yearmonth.js +++ b/src/widget/yearmonth/trigger.yearmonth.js @@ -179,7 +179,7 @@ BI.DynamicYearMonthTrigger = BI.inherit(BI.Trigger, { case BI.DynamicDateCombo.Static: default: value = value || {}; - var month = BI.isNull(value.month) ? null : value.month + 1; + var month = BI.isNull(value.month) ? null : value.month; this.yearEditor.setValue(value.year); this.yearEditor.setTitle(value.year); this.monthEditor.setValue(month); 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