From 32e17f5164b63e085a7a97d0ac43094bf2fe4b4b Mon Sep 17 00:00:00 2001 From: windy <1374721899@qq.com> Date: Wed, 2 May 2018 09:09:19 +0800 Subject: [PATCH] BI-18672 && BI-19143 --- dist/bundle.js | 48 +- dist/fineui.js | 26928 ++++++++++------ dist/widget.js | 48 +- src/widget/dynamicdate/dynamicdate.trigger.js | 24 +- .../dynamicdatetime.trigger.js | 24 +- 5 files changed, 16619 insertions(+), 10453 deletions(-) diff --git a/dist/bundle.js b/dist/bundle.js index 789bd066c..89c3d9553 100644 --- a/dist/bundle.js +++ b/dist/bundle.js @@ -91179,6 +91179,25 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger return BI.i18nText("BI-Date_Trigger_Error_Text"); } return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + }, + title: function () { + var storeValue = self.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = self._getText(value); + var date = BI.getDate(); + date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = date.print("%Y-%x-%e"); + return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + return ""; + } + return BI.getDate(value.year, (value.month - 1), value.day).print("%Y-%X-%d"); + } } }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { @@ -91278,11 +91297,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger BI.parseDateTime(v, "%Y-%x").print("%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; }, - _setInnerValue: function (date, text) { + _setInnerValue: function (date) { 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) { @@ -91355,12 +91373,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger if (BI.isNull(value) || BI.isNull(value.day)) { this.editor.setState(""); this.editor.setValue(""); - this.setTitle(""); } else { var dateStr = BI.getDate(value.year, (value.month - 1), value.day).print("%Y-%X-%d"); this.editor.setState(dateStr); this.editor.setValue(dateStr); - this.setTitle(dateStr); } break; } @@ -92117,6 +92133,25 @@ BI.extend(BI.DynamicDateTimeSelect, { return BI.i18nText("BI-Basic_Date_Time_Error_Text"); } return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + }, + title: function () { + var storeValue = self.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = self._getText(value); + var date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = date.print("%Y-%x-%e %H:%M:%S"); + return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + return ""; + } + return BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, + value.second || 0).print("%Y-%X-%d %H:%M:%S"); + } } }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { @@ -92219,11 +92254,10 @@ BI.extend(BI.DynamicDateTimeSelect, { BI.parseDateTime(v, "%Y-%x").print("%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; }, - _setInnerValue: function (date, text) { + _setInnerValue: function (date) { 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) { @@ -92296,13 +92330,11 @@ BI.extend(BI.DynamicDateTimeSelect, { if (BI.isNull(value) || BI.isNull(value.day)) { this.editor.setState(""); this.editor.setValue(""); - this.setTitle(""); } else { var dateStr = BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, value.second || 0).print("%Y-%X-%d %H:%M:%S"); this.editor.setState(dateStr); this.editor.setValue(dateStr); - this.setTitle(dateStr); } break; } diff --git a/dist/fineui.js b/dist/fineui.js index 74800d029..b4f8bbddb 100644 --- a/dist/fineui.js +++ b/dist/fineui.js @@ -9842,7 +9842,7 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { })( window );/** * @license * Lodash (Custom Build) - * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject,initial,cloneDeep,clamp,isPlainObject,take,takeRight,without"` + * Build: `lodash core plus="debounce,throttle,get,findIndex,findLastIndex,findKey,findLastKey,isArrayLike,invert,invertBy,uniq,uniqBy,omit,omitBy,zip,unzip,rest,range,random,reject,intersection,drop,countBy,union,zipObject,initial,cloneDeep,clamp,isPlainObject,take,takeRight,without,difference,defaultsDeep"` * Copyright JS Foundation and other contributors * Released under MIT license * Based on Underscore.js 1.8.3 @@ -10687,6 +10687,20 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return result; } + /** + * Gets the value at `key`, unless `key` is "__proto__". + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. + */ + function safeGet(object, key) { + return key == '__proto__' + ? undefined + : object[key]; + } + /** * Converts `set` to an array of its values. * @@ -11702,6 +11716,22 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return result; } + /** + * This function is like `assignValue` except that it doesn't assign + * `undefined` values. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ + function assignMergeValue(object, key, value) { + if ((value !== undefined && !eq(object[key], value)) || + (value === undefined && !(key in object))) { + baseAssignValue(object, key, value); + } + } + /** * Assigns `value` to `key` of `object` if the existing value is not equivalent * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) @@ -12730,6 +12760,116 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { }; } + /** + * The base implementation of `_.merge` without support for multiple sources. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {number} srcIndex The index of `source`. + * @param {Function} [customizer] The function to customize merged values. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + */ + function baseMerge(object, source, srcIndex, customizer, stack) { + if (object === source) { + return; + } + baseFor(source, function(srcValue, key) { + if (isObject(srcValue)) { + stack || (stack = new Stack); + baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); + } + else { + var newValue = customizer + ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack) + : undefined; + + if (newValue === undefined) { + newValue = srcValue; + } + assignMergeValue(object, key, newValue); + } + }, keysIn); + } + + /** + * A specialized version of `baseMerge` for arrays and objects which performs + * deep merges and tracks traversed objects enabling objects with circular + * references to be merged. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {string} key The key of the value to merge. + * @param {number} srcIndex The index of `source`. + * @param {Function} mergeFunc The function to merge values. + * @param {Function} [customizer] The function to customize assigned values. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + */ + function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { + var objValue = safeGet(object, key), + srcValue = safeGet(source, key), + stacked = stack.get(srcValue); + + if (stacked) { + assignMergeValue(object, key, stacked); + return; + } + var newValue = customizer + ? customizer(objValue, srcValue, (key + ''), object, source, stack) + : undefined; + + var isCommon = newValue === undefined; + + if (isCommon) { + var isArr = isArray(srcValue), + isBuff = !isArr && isBuffer(srcValue), + isTyped = !isArr && !isBuff && isTypedArray(srcValue); + + newValue = srcValue; + if (isArr || isBuff || isTyped) { + if (isArray(objValue)) { + newValue = objValue; + } + else if (isArrayLikeObject(objValue)) { + newValue = copyArray(objValue); + } + else if (isBuff) { + isCommon = false; + newValue = cloneBuffer(srcValue, true); + } + else if (isTyped) { + isCommon = false; + newValue = cloneTypedArray(srcValue, true); + } + else { + newValue = []; + } + } + else if (isPlainObject(srcValue) || isArguments(srcValue)) { + newValue = objValue; + if (isArguments(objValue)) { + newValue = toPlainObject(objValue); + } + else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) { + newValue = initCloneObject(srcValue); + } + } + else { + isCommon = false; + } + } + if (isCommon) { + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, newValue); + mergeFunc(newValue, srcValue, srcIndex, customizer, stack); + stack['delete'](srcValue); + } + assignMergeValue(object, key, newValue); + } + /** * The base implementation of `_.orderBy` without param guards. * @@ -13949,6 +14089,30 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return setWrapToString(setter(result, newData), func, bitmask); } + /** + * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source + * objects into destination objects that are passed thru. + * + * @private + * @param {*} objValue The destination value. + * @param {*} srcValue The source value. + * @param {string} key The key of the property to merge. + * @param {Object} object The parent object of `objValue`. + * @param {Object} source The parent object of `srcValue`. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + * @returns {*} Returns the value to assign. + */ + function customDefaultsMerge(objValue, srcValue, key, object, source, stack) { + if (isObject(objValue) && isObject(srcValue)) { + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, objValue); + baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack); + stack['delete'](srcValue); + } + return objValue; + } + /** * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain * objects. @@ -15164,6 +15328,33 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); } + /** + * Creates an array of `array` values not included in the other given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * **Note:** Unlike `_.pullAll`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @returns {Array} Returns the new array of filtered values. + * @see _.without, _.xor + * @example + * + * _.difference([2, 1], [2, 3]); + * // => [1] + */ + var difference = baseRest(function(array, values) { + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) + : []; + }); + /** * Creates a slice of `array` with `n` elements dropped from the beginning. * @@ -17997,6 +18188,34 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { : (reIsBadHex.test(value) ? NAN : +value); } + /** + * Converts `value` to a plain object flattening inherited enumerable string + * keyed properties of `value` to own properties of the plain object. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {Object} Returns the converted plain object. + * @example + * + * function Foo() { + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.assign({ 'a': 1 }, new Foo); + * // => { 'a': 1, 'b': 2 } + * + * _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); + * // => { 'a': 1, 'b': 2, 'c': 3 } + */ + function toPlainObject(value) { + return copyObject(value, keysIn(value)); + } + /** * Converts `value` to a string. An empty string is returned for `null` * and `undefined` values. The sign of `-0` is preserved. @@ -18150,6 +18369,30 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return object; }); + /** + * This method is like `_.defaults` except that it recursively assigns + * default properties. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 3.10.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see _.defaults + * @example + * + * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }); + * // => { 'a': { 'b': 2, 'c': 3 } } + */ + var defaultsDeep = baseRest(function(args) { + args.push(undefined, customDefaultsMerge); + return apply(mergeWith, undefined, args); + }); + /** * This method is like `_.find` except that it returns the key of the first * element `predicate` returns truthy for instead of the element itself. @@ -18444,6 +18687,41 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object); } + /** + * This method is like `_.merge` except that it accepts `customizer` which + * is invoked to produce the merged values of the destination and source + * properties. If `customizer` returns `undefined`, merging is handled by the + * method instead. The `customizer` is invoked with six arguments: + * (objValue, srcValue, key, object, source, stack). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} sources The source objects. + * @param {Function} customizer The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * function customizer(objValue, srcValue) { + * if (_.isArray(objValue)) { + * return objValue.concat(srcValue); + * } + * } + * + * var object = { 'a': [1], 'b': [2] }; + * var other = { 'a': [3], 'b': [4] }; + * + * _.mergeWith(object, other, customizer); + * // => { 'a': [1, 3], 'b': [2, 4] } + */ + var mergeWith = createAssigner(function(object, source, srcIndex, customizer) { + baseMerge(object, source, srcIndex, customizer); + }); + /** * The opposite of `_.pick`; this method creates an object composed of the * own and inherited enumerable property paths of `object` that are not omitted. @@ -19213,8 +19491,10 @@ if ( typeof define === "function" && define.amd && define.amd.jQuery ) { lodash.create = create; lodash.debounce = debounce; lodash.defaults = defaults; + lodash.defaultsDeep = defaultsDeep; lodash.defer = defer; lodash.delay = delay; + lodash.difference = difference; lodash.drop = drop; lodash.filter = filter; lodash.flatten = flatten; @@ -19650,10 +19930,16 @@ if (!window.BI) { return widget instanceof BI.Widget || (BI.View && widget instanceof BI.View); }, - createWidgets: function (items, options) { + createWidgets: function (items, options, context) { if (!BI.isArray(items)) { throw new Error("cannot create Widgets"); } + if (BI.isWidget(options)) { + context = options; + options = {}; + } else { + options || (options = {}); + } return BI.map(BI.flatten(items), function (i, item) { return BI.createWidget(item, BI.deepClone(options)); }); @@ -19731,7 +20017,7 @@ if (!window.BI) { }); // 集合相关方法 - _.each(["where", "findWhere", "contains", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], function (name) { + _.each(["where", "findWhere", "invoke", "pluck", "shuffle", "sample", "toArray", "size"], function (name) { BI[name] = _apply(name); }); _.each(["get", "each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", @@ -21663,7 +21949,7 @@ BI.Widget = BI.inherit(BI.OB, { var kv = {}; BI.shortcut = function (xtype, cls) { if (kv[xtype] != null) { - throw ("shortcut:[" + xtype + "] has been registed"); + console.error("shortcut:[" + xtype + "] has been registed"); } kv[xtype] = cls; }; @@ -23450,28 +23736,7 @@ BI.IntegerBufferSet.prototype = { return array; } }; -})();window.BI = window.BI || {}; - -_.extend(BI, { - $defaultImport: function (options, type) { - var config; - if (BI.isObject(options)) { - config = $.extend({ - op: "resource", - path: null, - type: null, - must: false - }, options); - config.url = BI.servletURL + "?op=" + config.op + "&resource=" + config.path; - } else { - config = { - url: BI.servletURL + "?op=resource&resource=" + options, - type: arguments[1], - must: arguments[2] - }; - } - this.$import(config.url, config.type, config.must); - }, +})();_.extend(BI, { $import: function () { var _LOADED = {}; // alex:保存加载过的 function loadReady (src, must) { @@ -25511,9 +25776,13 @@ BI.shortcut("bi.layout", BI.Layout);BI.Plugin = BI.Plugin || {}; var _WidgetsPlugin = {}; var _ObjectPlugin = {}; var _ConfigPlugin = {}; + var _GlobalWidgetConfigFn, _GlobalObjectConfigFn; BI.extend(BI.Plugin, { getWidget: function (type, options) { + if (_GlobalWidgetConfigFn) { + _GlobalWidgetConfigFn(type, options); + } if (_ConfigPlugin[type]) { for (var i = _ConfigPlugin[type].length - 1; i >= 0; i--) { _ConfigPlugin[type][i](options); @@ -25530,6 +25799,11 @@ BI.shortcut("bi.layout", BI.Layout);BI.Plugin = BI.Plugin || {}; return options; }, + config: function (widgetConfigFn, objectConfigFn) { + _GlobalWidgetConfigFn = widgetConfigFn; + _GlobalObjectConfigFn = objectConfigFn; + }, + configWidget: function (type, fn) { if (!_ConfigPlugin[type]) { _ConfigPlugin[type] = []; @@ -25552,6 +25826,9 @@ BI.shortcut("bi.layout", BI.Layout);BI.Plugin = BI.Plugin || {}; }, getObject: function (type, object) { + if (_GlobalObjectConfigFn) { + _GlobalObjectConfigFn(type, object); + } if (_ObjectPlugin[type]) { var res; for (var i = 0, len = _ObjectPlugin[type].length; i < len; i++) { @@ -25643,6 +25920,7 @@ BI.ShowAction = BI.inherit(BI.Action, { if (!window.BI) { window.BI = {}; } + function isEmpty (value) { // 判断是否为空值 var result = value === "" || value === null || value === undefined; @@ -25932,7 +26210,7 @@ BI.ShowAction = BI.inherit(BI.Action, { // replace the html special tags BI.htmlEncode = function (text) { - return (text == null) ? '' : String(text).replace(/&/g, '&').replace(/\"/g, '"').replace(//g, '>').replace(/\s/g, ' '); + return (text == null) ? "" : String(text).replace(/&/g, "&").replace(/\"/g, """).replace(//g, ">").replace(/\s/g, " "); }; // html decode BI.htmlDecode = function (text) { @@ -25981,8 +26259,8 @@ BI.ShowAction = BI.inherit(BI.Action, { } c = b.charCodeAt(); return "\\u00" + - Math.floor(c / 16).toString(16) + - (c % 16).toString(16); + Math.floor(c / 16).toString(16) + + (c % 16).toString(16); }) + "\""; } return "\"" + s + "\""; @@ -26058,7 +26336,7 @@ BI.ShowAction = BI.inherit(BI.Action, { try { // 注意0啊 // var jo = $.parseJSON(text) || {}; - var jo = $ ? $.parseJSON(text): window.JSON.parse(text); + var jo = $ ? $.parseJSON(text) : window.JSON.parse(text); if (jo == null) { jo = {}; } @@ -26147,6 +26425,70 @@ BI.ShowAction = BI.inherit(BI.Action, { return text; }; + /** + * 将Java提供的日期格式字符串装换为JS识别的日期格式字符串 + * @class FR.parseFmt + * @param fmt 日期格式 + * @returns {String} + */ + BI.parseFmt = function (fmt) { + if (!fmt) { + return ""; + } + //日期 + fmt = String(fmt) + //年 + .replace(/y{4,}/g, "%Y")//yyyy的时候替换为Y + .replace(/y{2}/g, "%y")//yy的时候替换为y + //月 + .replace(/M{4,}/g, "%b")//MMMM的时候替换为b,八 + .replace(/M{3}/g, "%B")//MMM的时候替换为M,八月 + .replace(/M{2}/g, "%X")//MM的时候替换为X,08 + .replace(/M{1}/g, "%x")//M的时候替换为x,8 + .replace(/a{1}/g, "%p"); + //天 + if (new RegExp("d{2,}", "g").test(fmt)) { + fmt = fmt.replace(/d{2,}/g, "%d");//dd的时候替换为d + } else { + fmt = fmt.replace(/d{1}/g, "%e");//d的时候替换为j + } + //时 + if (new RegExp("h{2,}", "g").test(fmt)) {//12小时制 + fmt = fmt.replace(/h{2,}/g, "%I"); + } else { + fmt = fmt.replace(/h{1}/g, "%I"); + } + if (new RegExp("H{2,}", "g").test(fmt)) {//24小时制 + fmt = fmt.replace(/H{2,}/g, "%H"); + } else { + fmt = fmt.replace(/H{1}/g, "%H"); + } + fmt = fmt.replace(/m{2,}/g, "%M")//分 + //秒 + .replace(/s{2,}/g, "%S"); + + return fmt; + }; + + /** + * 把字符串按照对应的格式转化成日期对象 + * + * @example + * var result = FR.str2Date('2013-12-12', 'yyyy-MM-dd');//Thu Dec 12 2013 00:00:00 GMT+0800 + * + * @class FR.str2Date + * @param str 字符串 + * @param format 日期格式 + * @returns {*} + */ + BI.str2Date = function (str, format) { + if (typeof str != "string" || typeof format != "string") { + return null; + } + var fmt = BI.parseFmt(format); + return BI.parseDateTime(str, fmt); + }; + /** * 把日期对象按照指定格式转化成字符串 * @@ -26277,8 +26619,6 @@ BI.ShowAction = BI.inherit(BI.Action, { return parseInt(str); } return parseFloat(str); - - }; BI.object2Date = function (obj) { @@ -26320,7 +26660,7 @@ BI.ShowAction = BI.inherit(BI.Action, { return dt; } } - dt = BI.str2Date(str, "HH:mm:ss"); + dt = BI.parseDateTime(str, "HH:mm:ss"); if (!isInvalidDate(dt)) { return dt; } @@ -26353,9 +26693,9 @@ BI.HighlightBehavior = BI.inherit(BI.Behavior, { function doBe (run) { if (run === true) { - item.doHighLight.apply(item, args); + item.doHighLight && item.doHighLight.apply(item, args); } else { - item.unHighLight.apply(item, args); + item.unHighLight && item.unHighLight.apply(item, args); } } @@ -26365,7 +26705,7 @@ BI.HighlightBehavior = BI.inherit(BI.Behavior, { doBe(rule); } } else { - item.doBehavior.apply(item, args); + item.doBehavior && item.doBehavior.apply(item, args); } }); } @@ -26393,12 +26733,12 @@ BI.RedMarkBehavior = BI.inherit(BI.Behavior, { BI.each(items, function (i, item) { if(item instanceof BI.Single) { if (o.rule(item.getValue(), item)) { - item.doRedMark.apply(item, args); + item.doRedMark && item.doRedMark.apply(item, args); } else { - item.unRedMark.apply(item, args); + item.doRedMark && item.unRedMark.apply(item, args); } } else { - item.doBehavior.apply(item, args); + item.doBehavior && item.doBehavior.apply(item, args); } }); } @@ -26407,56 +26747,47 @@ BI.RedMarkBehavior = BI.inherit(BI.Behavior, { // 注册布局 var isSupportFlex = BI.isSupportCss3("flex"); BI.Plugin.registerWidget("bi.horizontal", function (ob) { - if (isSupportFlex) { + if (!BI.isIE() && isSupportFlex) { return BI.extend(ob, {type: "bi.flex_horizontal"}); } return ob; - + }); BI.Plugin.registerWidget("bi.center_adapt", function (ob) { - if (isSupportFlex && ob.items && ob.items.length <= 1) { + if (!BI.isIE() && isSupportFlex && ob.items && ob.items.length <= 1) { // 有滚动条的情况下需要用到flex_wrapper_center布局 if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) { // 不是IE用flex_wrapper_center布局 - if (!BI.isIE()) { - return BI.extend(ob, {type: "bi.flex_wrapper_center"}); - } - return ob; + return BI.extend(ob, {type: "bi.flex_wrapper_center"}); } return BI.extend(ob, {type: "bi.flex_center"}); } return ob; - + }); BI.Plugin.registerWidget("bi.vertical_adapt", function (ob) { - if (isSupportFlex) { + if (!BI.isIE() && isSupportFlex) { // 有滚动条的情况下需要用到flex_wrapper_center布局 if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) { // 不是IE用flex_wrapper_center布局 - if (!BI.isIE()) { - return BI.extend({}, ob, {type: "bi.flex_wrapper_vertical_center"}); - } - return ob; + return BI.extend({}, ob, {type: "bi.flex_wrapper_vertical_center"}); } return BI.extend(ob, {type: "bi.flex_vertical_center"}); } return ob; - + }); BI.Plugin.registerWidget("bi.float_center_adapt", function (ob) { - if (isSupportFlex) { + if (!BI.isIE() && isSupportFlex) { // 有滚动条的情况下需要用到flex_wrapper_center布局 if (ob.scrollable === true || ob.scrollx === true || ob.scrolly === true) { // 不是IE用flex_wrapper_center布局 - if (!BI.isIE()) { - return BI.extend({}, ob, {type: "bi.flex_wrapper_center"}); - } - return ob; + return BI.extend({}, ob, {type: "bi.flex_wrapper_center"}); } return BI.extend(ob, {type: "bi.flex_center"}); } return ob; - + }); // 注册滚动条 BI.Plugin.registerWidget("bi.grid_table_scrollbar", function (ob) { @@ -26464,14 +26795,14 @@ BI.RedMarkBehavior = BI.inherit(BI.Behavior, { return BI.extend(ob, {type: "bi.native_table_scrollbar"}); } return ob; - + }); BI.Plugin.registerWidget("bi.grid_table_horizontal_scrollbar", function (ob) { if (BI.isIE9Below()) { return BI.extend(ob, {type: "bi.native_table_horizontal_scrollbar"}); } return ob; - + }); // 注册控件 @@ -26481,7 +26812,7 @@ BI.RedMarkBehavior = BI.inherit(BI.Behavior, { return BI.extend(ob, {type: "bi.quick_grid_table"}); } return ob; - + }); BI.Plugin.registerWidget("bi.collection_table", function (ob) { // 非chrome下滚动条滑动效果不好,禁止掉 @@ -26489,7 +26820,7 @@ BI.RedMarkBehavior = BI.inherit(BI.Behavior, { return BI.extend(ob, {type: "bi.quick_collection_table"}); } return ob; - + }); // IE8下滚动条用原生的 $(function () { @@ -28626,31 +28957,33 @@ BI.extend(BI.DOM, { return this._scrollWidth; }, - getImage: function (param) { - var image = new Image(); + getImage: function (param, fillStyle, backgroundColor) { var canvas = document.createElement("canvas"); $("body").append(canvas); var w = BI.DOM.getTextSizeWidth(param, 14) + 6; canvas.width = w; - canvas.height = 16; + canvas.height = 24; var ctx = canvas.getContext("2d"); - ctx.font = "14px Georgia"; - ctx.fillStyle = "#ffffff"; - ctx.fillText(param, 3, 14); + // ctx.fillStyle = "#EAF2FD"; + ctx.font = "12px Georgia"; + ctx.fillStyle = fillStyle || "#3D4D66"; + ctx.textBaseline = "middle"; + ctx.fillText(param, 6, 12); $(canvas).destroy(); + var backColor = backgroundColor || "#EAF2FD"; return { width: w, - height: 16, + height: 24, src: canvas.toDataURL("image/png"), - style: "background-color: #3f8ce8; vertical-align: sub; margin: 0 3px;", - alt: param + style: "background-color: " + backColor + ";vertical-align: middle; margin: 0 3px;", + param: param }; } });(function () { var constantInjection = {}; BI.constant = function (xtype, cls) { if (constantInjection[xtype] != null) { - throw ("constant:[" + xtype + "] has been registed"); + console.error("constant:[" + xtype + "] has been registed"); } constantInjection[xtype] = cls; }; @@ -28658,7 +28991,7 @@ BI.extend(BI.DOM, { var modelInjection = {}; BI.model = function (xtype, cls) { if (modelInjection[xtype] != null) { - throw ("model:[" + xtype + "] has been registed"); + console.error("model:[" + xtype + "] has been registed"); } modelInjection[xtype] = cls; }; @@ -28666,7 +28999,7 @@ BI.extend(BI.DOM, { var storeInjection = {}; BI.store = function (xtype, cls) { if (storeInjection[xtype] != null) { - throw ("store:[" + xtype + "] has been registed"); + console.error("store:[" + xtype + "] has been registed"); } storeInjection[xtype] = cls; }; @@ -28674,7 +29007,7 @@ BI.extend(BI.DOM, { var serviceInjection = {}; BI.service = function (xtype, cls) { if (serviceInjection[xtype] != null) { - throw ("service:[" + xtype + "] has been registed"); + console.error("service:[" + xtype + "] has been registed"); } serviceInjection[xtype] = cls; }; @@ -28682,7 +29015,7 @@ BI.extend(BI.DOM, { var providerInjection = {}; BI.provider = function (xtype, cls) { if (providerInjection[xtype] != null) { - throw ("provider:[" + xtype + "] has been registed"); + console.error("provider:[" + xtype + "] has been registed"); } providerInjection[xtype] = cls; }; @@ -28701,7 +29034,14 @@ BI.extend(BI.DOM, { }; var actions = {}; + var globalAction = []; BI.action = function (type, actionFn) { + if (BI.isFunction(type)) { + globalAction.push(type); + return function () { + BI.remove(globalAction, actionFn); + }; + } if (!actions[type]) { actions[type] = []; } @@ -28762,7 +29102,7 @@ BI.extend(BI.DOM, { console.error(e); } } - } + }; }(afns)); } } @@ -28820,7 +29160,21 @@ BI.extend(BI.DOM, { BI.Actions = { runAction: function (type, config) { BI.each(actions[type], function (i, act) { - act(config); + try { + act(config); + } catch (e) { + console.error(e); + } + }); + }, + runGlobalAction: function () { + var args = [].slice.call(arguments); + BI.each(globalAction, function (i, act) { + try { + act.apply(null, args); + } catch (e) { + console.error(e); + } }); } }; @@ -29381,17 +29735,18 @@ Date.prototype.getOffsetDate = function (offset) { return BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds()) + offset * 864e5); }; -Date.prototype.getAfterMulQuarter = function (n) { +Date.prototype.getOffsetQuarter = function (n) { var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); - dt.setMonth(dt.getMonth() + n * 3); - return dt; -}; -// 获得n个季度前的日期 -Date.prototype.getBeforeMulQuarter = function (n) { - var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); - dt.setMonth(dt.getMonth() - n * 3); + var day = dt.getDate(); + var monthDay = BI.getDate(dt.getFullYear(), dt.getMonth() + BI.parseInt(n) * 3, 1).getMonthDays(); + if (day > monthDay) { + day = monthDay; + } + dt.setDate(day); + dt.setMonth(dt.getMonth() + parseInt(n) * 3); return dt; }; + // 得到本季度的起始月份 Date.prototype.getQuarterStartMonth = function () { var quarterStartMonth = 0; @@ -29419,16 +29774,6 @@ Date.prototype.getQuarterEndDate = function () { var quarterEndMonth = this.getQuarterStartMonth() + 2; return BI.getDate(this.getFullYear(), quarterEndMonth, this.getMonthDays(quarterEndMonth)); }; -Date.prototype.getAfterMultiMonth = function (n) { - var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); - dt.setMonth(dt.getMonth() + n | 0); - return dt; -}; -Date.prototype.getBeforeMultiMonth = function (n) { - var dt = BI.getDate(BI.getTime(this.getFullYear(), this.getMonth(), this.getDate(), this.getHours(), this.getMinutes(), this.getSeconds())); - dt.setMonth(dt.getMonth() - n | 0); - return dt; -}; // 指定日期n个月之前或之后的日期 Date.prototype.getOffsetMonth = function (n) { @@ -31310,53 +31655,19 @@ BI.FloatHorizontalLayout = BI.inherit(BI.Layout, { } }); BI.shortcut("bi.horizontal_float", BI.FloatHorizontalLayout);/** - *自适应水平和垂直方向都居中容器 - * Created by GUY on 2016/12/2. - * - * @class BI.FlexCenterLayout + * 内联布局 + * @class BI.InlineCenterAdaptLayout * @extends BI.Layout - */ -BI.FlexCenterLayout = BI.inherit(BI.Layout, { - props: function () { - return BI.extend(BI.FlexCenterLayout.superclass.props.apply(this, arguments), { - baseCls: "bi-flex-center-layout" - }); - }, - render: function () { - BI.FlexCenterLayout.superclass.render.apply(this, arguments); - this.populate(this.options.items); - }, - - _addElement: function (i, item) { - var o = this.options; - var w = BI.FlexCenterLayout.superclass._addElement.apply(this, arguments); - w.element.css({position: "relative", "flex-shrink": "0"}); - return w; - }, - - resize: function () { - // console.log("flex_center布局不需要resize"); - }, - - populate: function (items) { - BI.FlexCenterLayout.superclass.populate.apply(this, arguments); - this._mount(); - } -}); -BI.shortcut("bi.flex_center", BI.FlexCenterLayout);/** - *自适应水平和垂直方向都居中容器 - * Created by GUY on 2016/12/2. * - * @class BI.FlexHorizontalLayout - * @extends BI.Layout + * @cfg {JSON} options 配置属性 + * @cfg {Number} [hgap=0] 水平间隙 + * @cfg {Number} [vgap=0] 垂直间隙 */ -BI.FlexHorizontalLayout = BI.inherit(BI.Layout, { +BI.InlineCenterAdaptLayout = BI.inherit(BI.Layout, { + props: function () { - return BI.extend(BI.FlexHorizontalLayout.superclass.props.apply(this, arguments), { - baseCls: "bi-flex-horizontal-layout", - verticalAlign: BI.VerticalAlign.Top, - columnSize: [], - scrollx: true, + return BI.extend(BI.InlineLayout.superclass.props.apply(this, arguments), { + baseCls: "bi-inline-center-adapt-layout", hgap: 0, vgap: 0, lgap: 0, @@ -31365,17 +31676,223 @@ BI.FlexHorizontalLayout = BI.inherit(BI.Layout, { bgap: 0 }); }, + render: function () { - BI.FlexHorizontalLayout.superclass.render.apply(this, arguments); - var o = this.options; - this.element.addClass(o.verticalAlign); + BI.InlineCenterAdaptLayout.superclass.render.apply(this, arguments); + this.element.css({ + whiteSpace: "nowrap" + }); this.populate(this.options.items); }, - _addElement: function (i, item) { + _addElement: function (i, item, length) { var o = this.options; - var w = BI.FlexHorizontalLayout.superclass._addElement.apply(this, arguments); - w.element.css({position: "relative", "flex-shrink": "0"}); + if (!this.hasWidget(this.getName() + i)) { + var t = BI.createWidget(item); + t.element.css({ + position: "relative" + }); + var w = BI.createWidget({ + type: "bi.horizontal_auto", + items: [t] + }); + this.addWidget(this.getName() + i, w); + } else { + var w = this.getWidgetByName(this.getName() + i); + } + w.element.css({ + position: "relative", + display: "inline-block", + "vertical-align": "middle", + "*display": "inline", + "*zoom": 1, + "min-width": 100 / length + "%" + }); + if (o.vgap + o.tgap + (item.tgap || 0) + (item.vgap || 0) !== 0) { + w.element.css({ + "margin-top": o.vgap + o.tgap + (item.tgap || 0) + (item.vgap || 0) + "px" + }); + } + if (o.hgap + o.lgap + (item.lgap || 0) + (item.hgap || 0) !== 0) { + w.element.css({ + "margin-left": (i === 0 ? o.hgap : 0) + o.lgap + (item.lgap || 0) + (item.hgap || 0) +"px" + }); + } + if (o.hgap + o.rgap + (item.rgap || 0) + (item.hgap || 0) !== 0) { + w.element.css({ + "margin-right": o.hgap + o.rgap + (item.rgap || 0) + (item.hgap || 0) + "px" + }); + } + if (o.vgap + o.bgap + (item.bgap || 0) + (item.vgap || 0) !== 0) { + w.element.css({ + "margin-bottom": o.vgap + o.bgap + (item.bgap || 0) + (item.vgap || 0) + "px" + }); + } + return w; + }, + + resize: function () { + this.stroke(this.options.items); + }, + + addItem: function (item) { + throw new Error("不能添加元素"); + }, + + stroke: function (items) { + var self = this; + BI.each(items, function (i, item) { + if (item) { + self._addElement(i, item, items.length); + } + }); + }, + + populate: function (items) { + BI.InlineCenterAdaptLayout.superclass.populate.apply(this, arguments); + this._mount(); + } +}); +BI.shortcut("bi.inline_center_adapt", BI.InlineCenterAdaptLayout);/** + * 内联布局 + * @class BI.InlineVerticalAdaptLayout + * @extends BI.Layout + * + * @cfg {JSON} options 配置属性 + * @cfg {Number} [hgap=0] 水平间隙 + * @cfg {Number} [vgap=0] 垂直间隙 + */ +BI.InlineVerticalAdaptLayout = BI.inherit(BI.Layout, { + + props: function () { + return BI.extend(BI.InlineLayout.superclass.props.apply(this, arguments), { + baseCls: "bi-inline-vertical-adapt-layout", + hgap: 0, + vgap: 0, + lgap: 0, + rgap: 0, + tgap: 0, + bgap: 0 + }); + }, + + render: function () { + BI.InlineVerticalAdaptLayout.superclass.render.apply(this, arguments); + this.element.css({ + whiteSpace: "nowrap" + }); + this.populate(this.options.items); + }, + + _addElement: function (i, item) { + var o = this.options; + var w = BI.InlineVerticalAdaptLayout.superclass._addElement.apply(this, arguments); + w.element.css({ + position: "relative", + display: "inline-block", + "vertical-align": "middle", + "*display": "inline", + "*zoom": 1 + }); + if (o.vgap + o.tgap + (item.tgap || 0) + (item.vgap || 0) !== 0) { + w.element.css({ + "margin-top": o.vgap + o.tgap + (item.tgap || 0) + (item.vgap || 0) + "px" + }); + } + if (o.hgap + o.lgap + (item.lgap || 0) + (item.hgap || 0) !== 0) { + w.element.css({ + "margin-left": (i === 0 ? o.hgap : 0) + o.lgap + (item.lgap || 0) + (item.hgap || 0) +"px" + }); + } + if (o.hgap + o.rgap + (item.rgap || 0) + (item.hgap || 0) !== 0) { + w.element.css({ + "margin-right": o.hgap + o.rgap + (item.rgap || 0) + (item.hgap || 0) + "px" + }); + } + if (o.vgap + o.bgap + (item.bgap || 0) + (item.vgap || 0) !== 0) { + w.element.css({ + "margin-bottom": o.vgap + o.bgap + (item.bgap || 0) + (item.vgap || 0) + "px" + }); + } + return w; + }, + + resize: function () { + this.stroke(this.options.items); + }, + + populate: function (items) { + BI.InlineVerticalAdaptLayout.superclass.populate.apply(this, arguments); + this._mount(); + } +}); +BI.shortcut("bi.inline_vertical_adapt", BI.InlineVerticalAdaptLayout);/** + *自适应水平和垂直方向都居中容器 + * Created by GUY on 2016/12/2. + * + * @class BI.FlexCenterLayout + * @extends BI.Layout + */ +BI.FlexCenterLayout = BI.inherit(BI.Layout, { + props: function () { + return BI.extend(BI.FlexCenterLayout.superclass.props.apply(this, arguments), { + baseCls: "bi-flex-center-layout" + }); + }, + render: function () { + BI.FlexCenterLayout.superclass.render.apply(this, arguments); + this.populate(this.options.items); + }, + + _addElement: function (i, item) { + var o = this.options; + var w = BI.FlexCenterLayout.superclass._addElement.apply(this, arguments); + w.element.css({position: "relative", "flex-shrink": "0"}); + return w; + }, + + resize: function () { + // console.log("flex_center布局不需要resize"); + }, + + populate: function (items) { + BI.FlexCenterLayout.superclass.populate.apply(this, arguments); + this._mount(); + } +}); +BI.shortcut("bi.flex_center", BI.FlexCenterLayout);/** + *自适应水平和垂直方向都居中容器 + * Created by GUY on 2016/12/2. + * + * @class BI.FlexHorizontalLayout + * @extends BI.Layout + */ +BI.FlexHorizontalLayout = BI.inherit(BI.Layout, { + props: function () { + return BI.extend(BI.FlexHorizontalLayout.superclass.props.apply(this, arguments), { + baseCls: "bi-flex-horizontal-layout", + verticalAlign: BI.VerticalAlign.Top, + columnSize: [], + scrollx: true, + hgap: 0, + vgap: 0, + lgap: 0, + rgap: 0, + tgap: 0, + bgap: 0 + }); + }, + render: function () { + BI.FlexHorizontalLayout.superclass.render.apply(this, arguments); + var o = this.options; + this.element.addClass(o.verticalAlign); + this.populate(this.options.items); + }, + + _addElement: function (i, item) { + var o = this.options; + var w = BI.FlexHorizontalLayout.superclass._addElement.apply(this, arguments); + w.element.css({position: "relative", "flex-shrink": "0"}); if (o.vgap + o.tgap + (item.tgap || 0) + (item.vgap || 0) !== 0) { w.element.css({ "margin-top": o.vgap + o.tgap + (item.tgap || 0) + (item.vgap || 0) + "px" @@ -32125,7 +32642,7 @@ BI.CardLayout = BI.inherit(BI.Layout, { if (this.isCardExisted(cardName)) { throw new Error("cardName is already exist"); } - var widget = BI.createWidget(cardItem); + var widget = BI.createWidget(cardItem, this); widget.element.css({ position: "relative", top: "0", @@ -32904,6 +33421,70 @@ BI.HorizontalCellLayout = BI.inherit(BI.Layout, { } }); BI.shortcut("bi.horizontal_cell", BI.HorizontalCellLayout);/** + * 内联布局 + * @class BI.InlineLayout + * @extends BI.Layout + * + * @cfg {JSON} options 配置属性 + * @cfg {Number} [hgap=0] 水平间隙 + * @cfg {Number} [vgap=0] 垂直间隙 + */ +BI.InlineLayout = BI.inherit(BI.Layout, { + + props: function () { + return BI.extend(BI.InlineLayout.superclass.props.apply(this, arguments), { + baseCls: "bi-inline-layout", + hgap: 0, + vgap: 0, + lgap: 0, + rgap: 0, + tgap: 0, + bgap: 0 + }); + }, + + render: function () { + BI.InlineLayout.superclass.render.apply(this, arguments); + this.populate(this.options.items); + }, + + _addElement: function (i, item) { + var o = this.options; + var w = BI.InlineLayout.superclass._addElement.apply(this, arguments); + w.element.css({"position": "relative", display: "inline-block", "*display": "inline", "*zoom": 1}); + if (o.vgap + o.tgap + (item.tgap || 0) + (item.vgap || 0) !== 0) { + w.element.css({ + "margin-top": o.vgap + o.tgap + (item.tgap || 0) + (item.vgap || 0) + "px" + }); + } + if (o.hgap + o.lgap + (item.lgap || 0) + (item.hgap || 0) !== 0) { + w.element.css({ + "margin-left": (i === 0 ? o.hgap : 0) + o.lgap + (item.lgap || 0) + (item.hgap || 0) +"px" + }); + } + if (o.hgap + o.rgap + (item.rgap || 0) + (item.hgap || 0) !== 0) { + w.element.css({ + "margin-right": o.hgap + o.rgap + (item.rgap || 0) + (item.hgap || 0) + "px" + }); + } + if (o.vgap + o.bgap + (item.bgap || 0) + (item.vgap || 0) !== 0) { + w.element.css({ + "margin-bottom": o.vgap + o.bgap + (item.bgap || 0) + (item.vgap || 0) + "px" + }); + } + return w; + }, + + resize: function () { + this.stroke(this.options.items); + }, + + populate: function (items) { + BI.InlineLayout.superclass.populate.apply(this, arguments); + this._mount(); + } +}); +BI.shortcut("bi.inline", BI.InlineLayout);/** * 靠左对齐的自由浮动布局 * @class BI.LatticeLayout * @extends BI.Layout @@ -34002,17 +34583,6 @@ BI.VerticalCenterLayout = BI.inherit(BI.Layout, { } }); BI.shortcut("bi.vertical_center", BI.VerticalCenterLayout);/** - * 保存数据,将js里面用到的常量数据都分离 - * - */ -BI.Data = Data = {}; - -/** - * 存放bi里面通用的一些常量 - * @type {{}} - */ -Data.Constant = BICst = {}; -/** * 缓冲池 * @type {{Buffer: {}}} */ @@ -34021,7 +34591,7 @@ Data.Constant = BICst = {}; var Buffer = {}; var MODE = false;// 设置缓存模式为关闭 - Data.BufferPool = { + BI.BufferPool = { put: function (name, cache) { if (BI.isNotNull(Buffer[name])) { throw new Error("Buffer Pool has the key already!"); @@ -34040,7 +34610,7 @@ Data.Constant = BICst = {}; (function () { var _Shared = {}; - Data.SharingPool = { + BI.SharingPool = { _Shared: _Shared, put: function (name, shared) { _Shared[name] = shared; @@ -34063,12 +34633,10 @@ Data.Constant = BICst = {}; delete _Shared[key]; } }; -})();Data.Req = { +})();BI.Req = { }; -Data.Source = BISource = { - -};function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } (function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : typeof define === 'function' && define.amd ? define(['exports'], factory) : factory(global.Fix = global.Fix || {}); @@ -34202,10 +34770,11 @@ Data.Source = BISource = { var _resolve = void 0; callbacks.push(function () { if (cb) { - // try { - cb.call(ctx); - // } catch (e) { - // } + try { + cb.call(ctx); + } catch (e) { + console.error(e); + } } else if (_resolve) { _resolve(ctx); } @@ -34260,11 +34829,11 @@ Data.Source = BISource = { } }; - Dep.prototype.notify = function notify() { + Dep.prototype.notify = function notify(options) { // stabilize the subscriber list first var subs = this.subs.slice(); for (var i = 0, l = subs.length; i < l; i++) { - subs[i].update(); + subs[i].update(options); } }; @@ -34528,11 +35097,11 @@ Data.Source = BISource = { } function notify(observer, key, dep) { - dep.notify(); + dep.notify({ observer: observer, key: key }); if (observer) { //触发a.*绑定的依赖 _.each(observer._deps, function (dep) { - dep.notify(); + dep.notify({ observer: observer, key: key }); }); //触发a.**绑定的依赖 var parent = observer, @@ -34540,7 +35109,7 @@ Data.Source = BISource = { route = key || ""; while (parent) { _.each(parent._scopeDeps, function (dep) { - dep.notify(); + dep.notify({ observer: observer, key: key }); }); if (parent.parentKey != null) { route = parent.parentKey + '.' + route; @@ -34551,7 +35120,7 @@ Data.Source = BISource = { for (var _key2 in root._globalDeps) { var reg = new RegExp(_key2); if (reg.test(route)) { - root._globalDeps[_key2].notify(); + root._globalDeps[_key2].notify({ observer: observer, key: _key2 }); } } } @@ -34618,7 +35187,7 @@ Data.Source = BISource = { enumerable: true, configurable: true, get: function reactiveGetter() { - var value = val; + var value = childOb ? childOb.model : val; if (Dep.target) { dep.depend(); if (childOb) { @@ -34631,7 +35200,7 @@ Data.Source = BISource = { return value; }, set: function reactiveSetter(newVal) { - var value = val; + var value = childOb ? childOb.model : val; if (newVal === value || newVal !== newVal && value !== value) { return; } @@ -34723,7 +35292,8 @@ Data.Source = BISource = { function flushSchedulerQueue() { flushing = true; var watcher = void 0, - id = void 0; + id = void 0, + options = void 0; // Sort queue before flush. // This ensures that: @@ -34740,29 +35310,30 @@ Data.Source = BISource = { // do not cache length because more watchers might be pushed // as we run existing watchers for (index = 0; index < queue.length; index++) { - watcher = queue[index]; + watcher = queue[index].watcher; + options = queue[index].options; id = watcher.id; has[id] = null; - watcher.run(); + watcher.run(options); } resetSchedulerState(); } - function queueWatcher(watcher) { + function queueWatcher(watcher, options) { var id = watcher.id; if (has[id] == null) { has[id] = true; if (!flushing) { - queue.push(watcher); + queue.push({ watcher: watcher, options: options }); } else { // if already flushing, splice the watcher based on its id // if already past its id, it will be run next immediately. var i = queue.length - 1; - while (i > index && queue[i].id > watcher.id) { + while (i > index && queue[i].watcher.id > watcher.id) { i--; } - queue.splice(i + 1, 0, watcher); + queue.splice(i + 1, 0, { watcher: watcher, options: options }); } // queue the flush if (!waiting) { @@ -34820,7 +35391,7 @@ Data.Source = BISource = { } catch (e) { // if (this.user) { // } else { - throw e; + console.error(e); // } } finally { // "touch" every property so they are all tracked as @@ -34863,18 +35434,18 @@ Data.Source = BISource = { this.newDeps.length = 0; }; - Watcher.prototype.update = function update() { + Watcher.prototype.update = function update(options) { /* istanbul ignore else */ if (this.lazy) { this.dirty = true; } else if (this.sync) { - this.run(); + this.run(options); } else { - queueWatcher(this); + queueWatcher(this, options); } }; - Watcher.prototype.run = function run() { + Watcher.prototype.run = function run(options) { if (this.active) { var value = this.get(); if (value !== this.value || @@ -34886,12 +35457,17 @@ Data.Source = BISource = { var oldValue = this.value; this.value = value; if (this.user) { - // try { - this.cb.call(this.vm, value, oldValue); - // } catch (e) { - // } + try { + this.cb.call(this.vm, value, oldValue, options); + } catch (e) { + console.log(e); + } } else { - this.cb.call(this.vm, value, oldValue); + try { + this.cb.call(this.vm, value, oldValue, options); + } catch (e) { + console.log(e); + } } } } @@ -35010,14 +35586,14 @@ Data.Source = BISource = { var fns = exps.slice(); var complete = false, running = false; - var callback = function callback(index, newValue, oldValue) { + var callback = function callback(index, newValue, oldValue, options) { if (complete === true) { return; } fns[index] = true; if (runBinaryFunction(fns)) { complete = true; - cb(newValue, oldValue, index); + cb(newValue, oldValue, options); } if (!running) { running = true; @@ -35055,9 +35631,9 @@ Data.Source = BISource = { var w = new Watcher(model, function () { dep.depend(); return NaN; - }, function (newValue, oldValue) { - callback(i, newValue, oldValue); - }); + }, function (newValue, oldValue, opt) { + callback(i, newValue, oldValue, _.extend({ index: i }, opt)); + }, options); watchers.push(function unwatchFn() { w.teardown(); v.__ob__._scopeDeps && remove(v.__ob__._scopeDeps, dep); @@ -35096,17 +35672,17 @@ Data.Source = BISource = { var _w = new Watcher(currentModel, function () { _dep.depend(); return NaN; - }, function (newValue, oldValue) { - callback(i, newValue, oldValue); - }); + }, function (newValue, oldValue, opt) { + callback(i, newValue, oldValue, _.extend({ index: i }, opt)); + }, options); watchers.push(function unwatchFn() { _w.teardown(); root._globalDeps && delete root._globalDeps[regStr]; }); return; } - var watcher = new Watcher(model, exp, function (newValue, oldValue) { - callback(i, newValue, oldValue); + var watcher = new Watcher(model, exp, function (newValue, oldValue, opt) { + callback(i, newValue, oldValue, _.extend({ index: i }, opt)); }, options); watchers.push(function unwatchFn() { watcher.teardown(); @@ -35210,9 +35786,7 @@ Data.Source = BISource = { if (typeof cb === 'string') { cb = vm[cb]; } - return watch(vm.model, keyOrFn, _.bind(cb, vm.$$model ? vm.model : vm), _.extend({ - sync: true - }, options)); + return watch(vm.model, keyOrFn, _.bind(cb, vm.$$model ? vm.model : vm), options); } function initMethods(vm, methods) { @@ -35356,6 +35930,7 @@ Data.Source = BISource = { initComputed(this, computed); initWatch(this, watch$$1); initMethods(this, actions); + this.created && this.created(); if (this.$$model) { return this.model; } @@ -35390,7 +35965,7 @@ Data.Source = BISource = { for (var i = 0, len = model.length; i < len; i++) { result[i] = toJSON(model[i]); } - } else if (isPlainObject(model)) { + } else if (model && isPlainObject(model)) { result = {}; for (var _key4 in model) { if (!_.has($$skipArray, _key4)) { @@ -35426,212 +36001,7 @@ Data.Source = BISource = { exports.toJSON = toJSON; exports.__esModule = true; -});;(function () { - function initWatch (vm, watch) { - vm._watchers || (vm._watchers = []); - for (var key in watch) { - var handler = watch[key]; - if (BI.isArray(handler)) { - for (var i = 0; i < handler.length; i++) { - vm._watchers.push(createWatcher(vm, key, handler[i])); - } - } else { - vm._watchers.push(createWatcher(vm, key, handler)); - } - } - } - - function createWatcher (vm, keyOrFn, handler) { - return Fix.watch(vm.model, keyOrFn, _.bind(handler, vm), { - store: vm.store - }); - } - - var target = null; - var targetStack = []; - - function pushTarget (_target) { - if (target) targetStack.push(target) - Fix.Model.target = target = _target; - } - - function popTarget () { - Fix.Model.target = target = targetStack.pop(); - } - - var context = null; - var contextStack = []; - - function pushContext (_context) { - if (context) contextStack.push(context) - Fix.Model.context = context = _context; - } - - function popContext () { - Fix.Model.context = context = contextStack.pop(); - } - - var oldWatch = Fix.watch; - Fix.watch = function (model, expOrFn, cb, options) { - if (BI.isPlainObject(cb)) { - options = cb; - cb = cb.handler; - } - if (typeof cb === "string") { - cb = model[cb]; - } - return oldWatch.call(this, model, expOrFn, function () { - options && options.store && pushTarget(options.store); - var res = cb.apply(this, arguments); - options && options.store && popTarget(); - return res; - }, options); - }; - - function findStore (widget) { - var p = widget; - while (p) { - if (p.store || p.__cacheStore) { - break; - } - p = p._parent || (p.options && p.options.element); - } - if (p) { - widget.__cacheStore = p.store; - return p.__cacheStore || p.store; - } - } - - var _create = BI.createWidget; - BI.createWidget = function (item, options, context) { - var pushed = false; - if (BI.isWidget(options)) { - pushContext(options); - pushed = true; - } else if (context != null) { - pushContext(context); - pushed = true; - } - var result = _create.apply(this, arguments); - pushed && popContext(); - return result; - }; - - var _init = BI.Widget.prototype._init; - BI.Widget.prototype._init = function () { - var self = this; - var needPop = false; - if (window.Fix && this._store) { - var store = findStore(this.options.element || context); - if (store) { - pushTarget(store); - needPop = true; - } - this.store = this._store(); - needPop && popTarget(); - needPop = false; - pushTarget(this.store); - if (this.store instanceof Fix.Model) { - this.model = this.store.model; - } else { - this.model = this.store; - } - needPop = true; - } - _init.apply(this, arguments); - needPop && popTarget(); - }; - - var _render = BI.Widget.prototype._render; - BI.Widget.prototype._render = function () { - var needPop = false; - if (window.Fix && this._store) { - needPop = true; - pushTarget(this.store); - initWatch(this, this.watch); - } - _render.apply(this, arguments); - needPop && popTarget(); - }; - - var unMount = BI.Widget.prototype.__d; - BI.Widget.prototype.__d = function () { - unMount.apply(this, arguments); - this.store && BI.isFunction(this.store.destroy) && this.store.destroy(); - BI.each(this._watchers, function (i, unwatches) { - unwatches = BI.isArray(unwatches) ? unwatches : [unwatches]; - BI.each(unwatches, function (j, unwatch) { - unwatch(); - }); - }); - this._watchers && (this._watchers = []); - if (this.store) { - this.store._parent && (this.store._parent = null); - this.store = null; - } - }; - - _.each(["_mount"], function (name) { - var old = BI.Widget.prototype[name]; - old && (BI.Widget.prototype[name] = function () { - this.store && pushTarget(this.store); - var res = old.apply(this, arguments); - this.store && popTarget(); - return res; - }); - }); - - if (BI.isIE9Below()) { - _.each(["each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", - "sortBy", "groupBy", "indexBy", "countBy", "partition", - "keys", "allKeys", "values", "pairs", "invert", - "mapObject", "findKey", "pick", "omit", "tap"], function (name) { - var old = BI[name]; - BI[name] = function (obj, fn) { - return typeof fn === "function" ? old(obj, function (key, value) { - if (!(key in Fix.$$skipArray)) { - return fn.apply(this, arguments); - } - }) : old.apply(this, arguments); - }; - }); - BI.isEmpty = function (ob) { - if (BI.isPlainObject(ob) && ob.__ob__) { - return BI.keys(ob).length === 0; - } - return _.isEmpty(ob); - }; - BI.keys = function (ob) { - var keys = _.keys(ob); - var nKeys = []; - for (var i = 0; i < keys.length; i++) { - if (!(keys[i] in Fix.$$skipArray)) { - nKeys.push(keys[i]); - } - } - return nKeys; - }; - BI.values = function (ob) { - var keys = BI.keys(obj); - var length = keys.length; - var values = []; - for (var i = 0; i < length; i++) { - values[i] = obj[keys[i]]; - } - return values; - }; - BI.size = function (ob) { - if (BI.isPlainObject(ob) && ob.__ob__) { - return BI.keys(ob).length; - } - return _.size(ob); - }; - BI.isEmptyObject = function (ob) { - return BI.size(ob) === 0; - }; - } - BI.watch = Fix.watch; -}());/* ! +});/* ! * jQuery Mousewheel 3.1.13 * * Copyright jQuery Foundation and other contributors @@ -36537,6 +36907,7 @@ BI.BasicButton = BI.inherit(BI.Single, { if (o.action) { BI.Actions.runAction(o.action, o); } + BI.Actions.runGlobalAction(o); } }, @@ -37344,7 +37715,7 @@ BI.TreeView = BI.inherit(BI.Pane, { + "&parentValues= " + window.encodeURIComponent(BI.jsonEncode(parentNode)) + "&checkState=" + window.encodeURIComponent(BI.jsonEncode(treeNode.getCheckStatus())); - return BI.servletURL + "?op=" + self.options.op + "&cmd=" + self.options.cmd + "&" + param; + return "&" + param; } function beforeExpand (treeId, treeNode) { @@ -37357,7 +37728,7 @@ BI.TreeView = BI.inherit(BI.Pane, { } BI.Msg.toast("Please Wait。", "warning"); return false; - + } function onAsyncSuccess (event, treeId, treeNode, msg) { @@ -37393,7 +37764,6 @@ BI.TreeView = BI.inherit(BI.Pane, { function ajaxGetNodes (treeNode, reloadType) { var zTree = self.nodes; if (reloadType == "refresh") { - // treeNode.icon = BI.servletURL +"?op=resource&resource=/com/fr/bi/web/css/base/third/ztree/img/loading.gif"; zTree.updateNode(treeNode); } zTree.reAsyncChildNodes(treeNode, reloadType, true); @@ -39249,9 +39619,7 @@ BI.Expander = BI.inherit(BI.Widget, { }, _initExpander: function () { - this.expander = BI.createWidget(this.options.el, { - value: this.options.value - }); + this.expander = BI.createWidget(this.options.el); }, _assertPopupView: function () { @@ -50160,7 +50528,7 @@ BI.shortcut("bi.el", BI.EL);// CodeMirror, copyright (c) by Marijn Haverbeke and BI.FormulaEditor = BI.inherit(BI.Single, { _defaultConfig: function () { return $.extend(BI.FormulaEditor.superclass._defaultConfig.apply(), { - baseCls: "bi-formula-editor bi-card", + baseCls: "bi-formula-editor", watermark: "", value: "", fieldTextValueMap: {}, @@ -50199,11 +50567,6 @@ BI.FormulaEditor = BI.inherit(BI.Single, { self.fireEvent(BI.FormulaEditor.EVENT_BLUR); }); - - if (BI.isKey(o.value)) { - self.setValue(o.value); - } - if (BI.isKey(this.options.watermark)) { var self = this; this.watermark = BI.createWidget({ @@ -50242,6 +50605,14 @@ BI.FormulaEditor = BI.inherit(BI.Single, { bottom: 0 }); } + + }, + + mounted: function () { + var o = this.options; + if(BI.isNotNull(o.value)) { + this.setValue(o.value); + } }, _checkWaterMark: function () { @@ -50940,11 +51311,20 @@ BI.shortcut("bi.grid_view", BI.GridView);/** * @extends BI.Widget */ BI.Popover = BI.inherit(BI.Widget, { + _constant: { + SIZE: { + SMALL: "small", + NORMAL: "normal", + BIG: "big" + } + }, + _defaultConfig: function () { return BI.extend(BI.Popover.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-popover bi-card", - width: 600, - height: 500, + // width: 600, + // height: 500, + size: "normal", // small, normal, big header: null, body: null, footer: null @@ -50952,37 +51332,41 @@ BI.Popover = BI.inherit(BI.Widget, { }, render: function () { var self = this, o = this.options; - this.element.draggable && this.element.draggable({ - handle: ".bi-message-title", - drag: function (e, ui) { - var W = $("body").width(), H = $("body").height(); - if (ui.position.left + o.width > W) { - ui.position.left = W - o.width; - } - if (ui.position.top + o.height > H) { - ui.position.top = H - o.height; - } - if (ui.position.left < 0) { - ui.position.left = 0; - } - if (ui.position.top < 0) { - ui.position.top = 0; - } - // BI-12134 没有什么特别好的方法 - BI.Resizers._resize(); - } - }); + this.startX = 0; + this.startY = 0; + this.tracker = new BI.MouseMoveTracker(function (deltaX, deltaY) { + var size = self._calculateSize(); + var W = $("body").width(), H = $("body").height(); + self.startX += deltaX; + self.startY += deltaY; + self.element.css({ + left: BI.clamp(self.startX, 0, W - size.width) + "px", + top: BI.clamp(self.startY, 0, H - size.height) + "px" + }); + // BI-12134 没有什么特别好的方法 + BI.Resizers._resize(); + }, function () { + self.tracker.releaseMouseMoves(); + }, window); var items = { north: { el: { type: "bi.border", cls: "bi-message-title bi-background", + ref: function (_ref) { + self.dragger = _ref; + }, items: { center: { el: { type: "bi.absolute", items: [{ - el: BI.createWidget(o.header), + el: BI.isPlainObject(o.header) ? BI.createWidget(o.header) : { + type: "bi.label", + height: 36, + text: o.header, + textAlign: "left" + }, left: 10, top: 0, right: 0, @@ -51034,15 +51418,48 @@ BI.Popover = BI.inherit(BI.Widget, { }; } - BI.createWidget({ + var size = this._calculateSize(); + + return { type: "bi.border", - element: this, - items: items - }); + items: items, + width: size.width, + height: size.height + }; }, - show: function () { + mounted: function () { + var self = this; + this.dragger.element.mousedown(function (e) { + var pos = self.element.offset(); + self.startX = pos.left; + self.startY = pos.top; + self.tracker.captureMouseMoves(e); + }); + }, + _calculateSize: function () { + var o = this.options; + var size = {}; + if (BI.isNotNull(o.size)) { + switch (o.size) { + case this._constant.SIZE.SMALL: + size.width = 450; + size.height = 220; + break; + case this._constant.SIZE.BIG: + size.width = 900; + size.height = 500; + break; + default: + size.width = 550; + size.height = 500; + } + } + return { + width: o.width || size.width, + height: o.height || size.height + }; }, hide: function () { @@ -52013,7 +52430,7 @@ BI.A = BI.inherit(BI.Text, { href: "", target: "_blank", el: null, - element: "" + tagName: "a" }); }, _init: function () { @@ -53689,6 +54106,7 @@ BI.CodeEditor = BI.inherit(BI.Single, { watermark: "", lineHeight: 2, readOnly: false, + lineNumbers: false, // 参数显示值构造函数 paramFormatter: function (v) { return v; @@ -53701,7 +54119,7 @@ BI.CodeEditor = BI.inherit(BI.Single, { this.editor = CodeMirror(this.element[0], { textWrapping: true, lineWrapping: true, - lineNumbers: false, + lineNumbers: o.lineNumbers, readOnly: o.readOnly, // 解决插入字段由括号或其他特殊字符包围时分裂的bug specialChars: /[\u0000-\u001f\u007f\u00ad\u200c-\u200f\u2028\u2029\ufeff]/ @@ -53760,14 +54178,19 @@ BI.CodeEditor = BI.inherit(BI.Single, { items: [{ el: this.watermark, top: 0, - left: 5 + left: o.lineNumbers ? 30 + 5 : 5 }] }); + }, - if (BI.isKey(o.value)) { - BI.nextTick(function () { - self.setValue(o.value); - }); + mounted: function () { + var o = this.options; + if (BI.isNumber(o.value) || BI.isString(o.value)) { + this.setValue(o.value); + } + + if (BI.isNotNull(o.style)) { + this.setStyle(o.style); } }, @@ -53854,7 +54277,7 @@ BI.CodeEditor = BI.inherit(BI.Single, { focus: function () { this.editor.focus(); }, - + blur: function () { this.editor.getInputField().blur(); }, @@ -53987,7 +54410,7 @@ BI.Editor = BI.inherit(BI.Single, { self.fireEvent(BI.Editor.EVENT_FOCUS, arguments); }); this.editor.on(BI.Input.EVENT_BLUR, function () { - self.setErrorVisible(false); + self._setErrorVisible(false); self.element.removeClass("bi-editor-focus"); self.fireEvent(BI.Editor.EVENT_BLUR, arguments); }); @@ -54006,17 +54429,17 @@ BI.Editor = BI.inherit(BI.Single, { this.editor.on(BI.Input.EVENT_VALID, function () { self._checkWaterMark(); - self.setErrorVisible(false); + self._setErrorVisible(false); self.fireEvent(BI.Editor.EVENT_VALID, arguments); }); this.editor.on(BI.Input.EVENT_ERROR, function () { self._checkWaterMark(); self.fireEvent(BI.Editor.EVENT_ERROR, arguments); - self.setErrorVisible(self.isEditing()); + self._setErrorVisible(self.isEditing()); }); this.editor.on(BI.Input.EVENT_RESTRICT, function () { self._checkWaterMark(); - var tip = self.setErrorVisible(true); + var tip = self._setErrorVisible(true); tip && tip.element.fadeOut(100, function () { tip.element.fadeIn(100); }); @@ -54078,7 +54501,7 @@ BI.Editor = BI.inherit(BI.Single, { }, _checkError: function () { - this.setErrorVisible(this.isEnabled() && !this.isValid()); + this._setErrorVisible(this.isEnabled() && !this.isValid()); this._checkToolTip(); }, @@ -54099,7 +54522,7 @@ BI.Editor = BI.inherit(BI.Single, { return this.options.errorText; }, - setErrorVisible: function (b) { + _setErrorVisible: function (b) { var o = this.options; var errorText = o.errorText; if (BI.isFunction(errorText)) { @@ -54296,7 +54719,7 @@ BI.shortcut("bi.multifile_editor", BI.MultifileEditor);/** BI.TextAreaEditor = BI.inherit(BI.Single, { _defaultConfig: function () { return $.extend(BI.TextAreaEditor.superclass._defaultConfig.apply(), { - baseCls: "bi-textarea-editor bi-card", + baseCls: "bi-textarea-editor", value: "" }); }, @@ -54354,7 +54777,7 @@ BI.TextAreaEditor = BI.inherit(BI.Single, { self.setValue(o.value); } if (BI.isNotNull(o.style)) { - self.setValue(o.style); + self.setStyle(o.style); } this._checkWaterMark(); }, @@ -54803,7 +55226,9 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/** break; } }; - upload.onloadstart(); + if (isFunction(upload.onloadstart)) { + upload.onloadstart(); + } } var boundary = "AjaxUploadBoundary" + (new Date).getTime(); xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); @@ -55060,8 +55485,7 @@ BI.shortcut("bi.checkbox", BI.Checkbox);/** // enable again the submit button/element }, 1000); }; - _wrap.url = o.url ? o.url : BI.servletURL - + "?op=fr_attach&cmd=ah_upload"; + _wrap.url = o.url; _wrap.fileType = o.accept; // 文件类型限制 _wrap.attach_array = []; _wrap.attach_names = []; @@ -55300,6 +55724,7 @@ BI.Input = BI.inherit(BI.Single, { self._isEditing = false; self._start = false; if (self.isValid()) { + self._lastValidValue = self.getValue(); self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CONFIRM, self.getValue(), self); self.fireEvent(BI.Input.EVENT_CONFIRM); } @@ -55439,7 +55864,7 @@ BI.Input = BI.inherit(BI.Single, { this._checkValidationOnValueChange(); this._defaultState(); if (this.isValid()) { - this._lastSubmitValue = this.getValue(); + this._lastValidValue = this._lastSubmitValue = this.getValue(); } }, this)); }, @@ -55459,7 +55884,6 @@ BI.Input = BI.inherit(BI.Single, { _setValid: function () { BI.Input.superclass._setValid.apply(this, arguments); if (this.isValid()) { - this._lastValidValue = this.getValue(); this.element.removeClass("bi-input-error"); this.fireEvent(BI.Input.EVENT_VALID, BI.trim(this.getValue()), this); } else { @@ -56007,7 +56431,8 @@ BI.Link = BI.inherit(BI.Label, { _defaultConfig: function () { var conf = BI.Link.superclass._defaultConfig.apply(this, arguments); return BI.extend(conf, { - baseCls: (conf.baseCls || "") + " bi-link", + baseCls: (conf.baseCls || "") + " bi-link display-block", + tagName: "a", href: "", target: "_blank" }); @@ -68387,7 +68812,9 @@ BI.Table = BI.inherit(BI.Widget, { }, render: function () { - this.populate(this.options.items); + if (this.options.items.length > 0 || this.options.header.length > 0) { + this.populate(this.options.items); + } }, setColumnSize: function (columnSize) { @@ -69821,12 +70248,13 @@ BI.CustomTree = BI.inherit(BI.Widget, { if (BI.isNotEmptyArray(node.children) || node.isParent === true) { var item = BI.extend({ type: "bi.expander", - el: {}, + el: { + value: node.value + }, popup: {type: "bi.custom_tree"} }, BI.deepClone(o.expander), { id: node.id, - pId: node.pId, - value: node.value + pId: node.pId }); var el = BI.stripEL(node); if (!BI.isWidget(el)) { @@ -72592,7 +73020,7 @@ BI.shortcut("bi.single_select_item", BI.SingleSelectItem);/** BI.SingleSelectRadioItem = BI.inherit(BI.BasicButton, { _defaultConfig: function () { return BI.extend(BI.SingleSelectRadioItem.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-single-select-radio-item bi-list-item-active", + extraCls: "bi-single-select-radio-item", logic: { dynamic: false }, @@ -72606,9 +73034,6 @@ BI.SingleSelectRadioItem = BI.inherit(BI.BasicButton, { this.radio = BI.createWidget({ type: "bi.radio" }); - this.radio.on(BI.Controller.EVENT_CHANGE, function (type) { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); this.text = BI.createWidget({ type: "bi.label", cls: "list-item-text", @@ -72629,7 +73054,7 @@ BI.SingleSelectRadioItem = BI.inherit(BI.BasicButton, { items: BI.LogicFactory.createLogicItemsByDirection("left", { type: "bi.center_adapt", items: [this.radio], - width: 36 + width: 16 }, this.text) })))); }, @@ -72771,7 +73196,8 @@ BI.FirstPlusGroupNode = BI.inherit(BI.NodeButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) { @@ -72952,7 +73378,8 @@ BI.LastPlusGroupNode = BI.inherit(BI.NodeButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { if(type === BI.Events.CLICK) { @@ -73032,7 +73459,8 @@ BI.MidPlusGroupNode = BI.inherit(BI.NodeButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) { @@ -73320,7 +73748,8 @@ BI.FirstTreeLeafItem = BI.inherit(BI.BasicButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) { @@ -73510,7 +73939,8 @@ BI.LastTreeLeafItem = BI.inherit(BI.BasicButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) { @@ -73613,7 +74043,8 @@ BI.MidTreeLeafItem = BI.inherit(BI.BasicButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) { @@ -73863,7 +74294,7 @@ BI.Calendar = BI.inherit(BI.Widget, { min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 year: 2015, - month: 7, // 7表示八月 + month: 8, day: 25 }); }, @@ -73881,18 +74312,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]]) { @@ -73921,16 +74357,21 @@ BI.Calendar = BI.inherit(BI.Widget, { var items = BI.map(Date._SDN.slice(0, 7), function (i, value) { return { type: "bi.label", - height: 25, + height: 24, text: value }; }); var title = BI.createWidget({ type: "bi.button_group", - height: 25, - items: items + height: 44, + items: items, + layouts: [{ + type: "bi.center", + hgap: 10, + 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)); @@ -73948,7 +74389,7 @@ BI.Calendar = BI.inherit(BI.Widget, { whiteSpace: "normal", once: false, forceSelected: true, - height: 25, + height: 24, value: o.year + "-" + o.month + "-" + td.text, disabled: td.lastMonth || td.nextMonth || td.disabled // selected: td.currentDay @@ -73963,7 +74404,9 @@ BI.Calendar = BI.inherit(BI.Widget, { columns: 7, rows: 6, columnSize: [1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7, 1 / 7], - rowSize: 25 + rowSize: 24, + hgap: 10, + vgap: 10 }))] }); this.days.on(BI.Controller.EVENT_CHANGE, function () { @@ -74014,7 +74457,7 @@ BI.extend(BI.Calendar, { var year = BI.getDate().getFullYear(); var month = BI.getDate().getMonth(); var page = (json.year - year) * 12; - page += json.month - month; + page += json.month - 1 - month; return page; }, getDateJSONByPage: function (v) { @@ -74031,7 +74474,7 @@ BI.extend(BI.Calendar, { var month = page >= 0 ? (page % 12) : ((12 + page % 12) % 12); return { year: BI.getDate().getFullYear() + year, - month: month + month: month + 1 }; } }); @@ -74168,7 +74611,7 @@ BI.extend(BI.YearCalendar, { }, getEndYear: function (year) { - return BI.YearCalendar.getStartYear(year) + BI.YearCalendar.INTERVAL; + return BI.YearCalendar.getStartYear(year) + BI.YearCalendar.INTERVAL - 1; }, getPageByYear: function (year) { @@ -75801,8 +76244,8 @@ BI.CustomColorChooser = BI.inherit(BI.Widget, { _init: function () { BI.CustomColorChooser.superclass._init.apply(this, arguments); - var self = this; - this.editor = BI.createWidget({ + var self = this, o = this.options; + this.editor = BI.createWidget(o.editor, { type: "bi.color_picker_editor" }); this.editor.on(BI.ColorPickerEditor.EVENT_CHANGE, function () { @@ -75862,7 +76305,7 @@ BI.ColorChooser = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.ColorChooser.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-color-chooser", - el: {} + value: "" }); }, @@ -75874,8 +76317,10 @@ BI.ColorChooser = BI.inherit(BI.Widget, { type: "bi.combo", element: this, adjustLength: 1, + isNeedAdjustWidth: false, + isNeedAdjustHeight: false, el: BI.extend({ - type: "bi.color_chooser_trigger", + type: o.width <= 30 ? "bi.color_chooser_trigger" : "bi.long_color_chooser_trigger", ref: function (_ref) { self.trigger = _ref; }, @@ -75883,7 +76328,7 @@ BI.ColorChooser = BI.inherit(BI.Widget, { height: o.height }, o.el), popup: { - el: { + el: BI.extend({ type: "bi.color_chooser_popup", ref: function (_ref) { self.colorPicker = _ref; @@ -75900,10 +76345,9 @@ BI.ColorChooser = BI.inherit(BI.Widget, { self.combo.hideView(); } }] - }, + }, o.popup), stopPropagation: false, - minWidth: 202, - minWidth: 202 + width: 202 }, value: o.value }); @@ -75968,7 +76412,7 @@ BI.ColorChooserPopup = BI.inherit(BI.Widget, { _init: function () { BI.ColorChooserPopup.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.colorEditor = BI.createWidget({ + this.colorEditor = BI.createWidget(o.editor, { type: "bi.color_picker_editor", value: o.value }); @@ -76027,7 +76471,8 @@ BI.ColorChooserPopup = BI.inherit(BI.Widget, { }); this.customColorChooser = BI.createWidget({ - type: "bi.custom_color_chooser" + type: "bi.custom_color_chooser", + editor: o.editor }); var panel = BI.createWidget({ @@ -76149,6 +76594,108 @@ BI.ColorChooserPopup = BI.inherit(BI.Widget, { BI.ColorChooserPopup.EVENT_VALUE_CHANGE = "ColorChooserPopup.EVENT_VALUE_CHANGE"; BI.ColorChooserPopup.EVENT_CHANGE = "ColorChooserPopup.EVENT_CHANGE"; BI.shortcut("bi.color_chooser_popup", BI.ColorChooserPopup);/** + * 选色控件 + * + * Created by GUY on 2015/11/17. + * @class BI.SimpleColorChooserPopup + * @extends BI.Widget + */ +BI.SimpleColorChooserPopup = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.SimpleColorChooserPopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-color-chooser-popup" + }); + }, + + _init: function () { + BI.SimpleColorChooserPopup.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.popup = BI.createWidget({ + type: "bi.color_chooser_popup", + value: o.value, + element: this, + editor: { + type: "bi.simple_color_picker_editor" + } + }); + this.popup.on(BI.ColorChooserPopup.EVENT_CHANGE, function () { + self.fireEvent(BI.SimpleColorChooserPopup.EVENT_CHANGE, arguments); + }); + this.popup.on(BI.ColorChooserPopup.EVENT_VALUE_CHANGE, function () { + self.fireEvent(BI.SimpleColorChooserPopup.EVENT_VALUE_CHANGE, arguments); + }); + }, + + setStoreColors: function (colors) { + this.popup.setStoreColors(colors); + }, + + setValue: function (color) { + this.popup.setValue(color); + }, + + getValue: function () { + return this.popup.getValue(); + } +}); +BI.SimpleColorChooserPopup.EVENT_VALUE_CHANGE = "ColorChooserPopup.EVENT_VALUE_CHANGE"; +BI.SimpleColorChooserPopup.EVENT_CHANGE = "ColorChooserPopup.EVENT_CHANGE"; +BI.shortcut("bi.simple_color_chooser_popup", BI.SimpleColorChooserPopup);/** + * 简单选色控件,没有自动和透明 + * + * Created by GUY on 2015/11/17. + * @class BI.SimpleColorChooser + * @extends BI.Widget + */ +BI.SimpleColorChooser = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.SimpleColorChooser.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-simple-color-chooser", + value: "#ffffff" + }); + }, + + _init: function () { + BI.SimpleColorChooser.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + this.combo = BI.createWidget({ + type: "bi.color_chooser", + element: this, + value: o.value, + popup: { + type: "bi.simple_color_chooser_popup" + } + }); + this.combo.on(BI.ColorChooser.EVENT_CHANGE, function () { + self.fireEvent(BI.SimpleColorChooser.EVENT_CHANGE, arguments); + }); + }, + + isViewVisible: function () { + return this.combo.isViewVisible(); + }, + + hideView: function () { + this.combo.hideView(); + }, + + showView: function () { + this.combo.showView(); + }, + + setValue: function (color) { + this.combo.setValue(color); + }, + + getValue: function () { + return this.combo.getValue(); + } +}); +BI.SimpleColorChooser.EVENT_CHANGE = "ColorChooser.EVENT_CHANGE"; +BI.shortcut("bi.simple_color_chooser", BI.SimpleColorChooser);/** * 选色控件 * * Created by GUY on 2015/11/17. @@ -76195,7 +76742,7 @@ BI.ColorChooserTrigger = BI.inherit(BI.Trigger, { bottom: 3 }] }); - if (this.options.value) { + if (BI.isNotNull(this.options.value)) { this.setValue(this.options.value); } }, @@ -76213,6 +76760,102 @@ BI.ColorChooserTrigger = BI.inherit(BI.Trigger, { }); BI.ColorChooserTrigger.EVENT_CHANGE = "ColorChooserTrigger.EVENT_CHANGE"; BI.shortcut("bi.color_chooser_trigger", BI.ColorChooserTrigger);/** + * 选色控件 + * + * Created by GUY on 2015/11/17. + * @class BI.LongColorChooserTrigger + * @extends BI.Trigger + */ +BI.LongColorChooserTrigger = BI.inherit(BI.Trigger, { + + _defaultConfig: function () { + var conf = BI.LongColorChooserTrigger.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-color-chooser-trigger", + height: 30 + }); + }, + + _init: function () { + BI.LongColorChooserTrigger.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.colorContainer = BI.createWidget({ + type: "bi.htape", + cls: "bi-card color-chooser-trigger-content", + items: [{ + type: "bi.icon_change_button", + ref: function (_ref) { + self.changeIcon = _ref; + }, + iconCls: "auto-color-icon", + width: 24, + iconWidth: 16, + iconHeight: 16 + }, { + el: { + type: "bi.label", + ref: function (_ref) { + self.label = _ref; + }, + textAlign: "left", + hgap: 5, + height: 24, + text: BI.i18nText("BI-Basic_Auto") + } + }] + }); + + var down = BI.createWidget({ + type: "bi.icon_button", + disableSelected: true, + cls: "icon-combo-down-icon trigger-triangle-font", + width: 12, + height: 8 + }); + + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.colorContainer, + left: 3, + right: 3, + top: 3, + bottom: 3 + }, { + el: down, + right: 3, + bottom: 3 + }] + }); + if (this.options.value) { + this.setValue(this.options.value); + } + }, + + setValue: function (color) { + BI.LongColorChooserTrigger.superclass.setValue.apply(this, arguments); + if (color === "") { + this.colorContainer.element.css("background-color", ""); + this.changeIcon.setVisible(true); + this.label.setVisible(true); + this.changeIcon.setIcon("auto-color-icon"); + this.label.setText(BI.i18nText("BI-Basic_Auto")); + } else if (color === "transparent") { + this.colorContainer.element.css("background-color", ""); + this.changeIcon.setVisible(true); + this.label.setVisible(true); + this.changeIcon.setIcon("trans-color-icon"); + this.label.setText(BI.i18nText("BI-Transparent_Color")); + } else { + this.colorContainer.element.css({"background-color": color}); + this.changeIcon.setVisible(false); + this.label.setVisible(false); + } + } +}); +BI.LongColorChooserTrigger.EVENT_CHANGE = "ColorChooserTrigger.EVENT_CHANGE"; +BI.shortcut("bi.long_color_chooser_trigger", BI.LongColorChooserTrigger);/** * 简单选色控件按钮 * * Created by GUY on 2015/11/16. @@ -76518,15 +77161,20 @@ BI.ColorPickerEditor = BI.inherit(BI.Widget, { this.B = Ws[2]; this.none = BI.createWidget({ - type: "bi.checkbox", + type: "bi.icon_button", + cls: "auto-color-icon", + width: 16, + height: 16, + iconWidth: 16, + iconHeight: 16, title: BI.i18nText("BI-Basic_Auto") }); - this.none.on(BI.Checkbox.EVENT_CHANGE, function () { + this.none.on(BI.IconButton.EVENT_CHANGE, function () { if (this.isSelected()) { self.lastColor = self.getValue(); self.setValue(""); } else { - self.setValue(self.lastColor || "#000000"); + self.setValue(self.lastColor || "#ffffff"); } if (self.R.isValid() && self.G.isValid() && self.B.isValid()) { self.colorShow.element.css("background-color", self.getValue()); @@ -76535,15 +77183,23 @@ BI.ColorPickerEditor = BI.inherit(BI.Widget, { }); this.transparent = BI.createWidget({ - type: "bi.checkbox", + type: "bi.icon_button", + cls: "trans-color-icon", + width: 16, + height: 16, + iconWidth: 16, + iconHeight: 16, title: BI.i18nText("BI-Transparent_Color") }); - this.transparent.on(BI.Checkbox.EVENT_CHANGE, function () { + this.transparent.on(BI.IconButton.EVENT_CHANGE, function () { if (this.isSelected()) { self.lastColor = self.getValue(); self.setValue("transparent"); } else { - self.setValue(self.lastColor || "#000000"); + if (self.lastColor === "transparent") { + self.lastColor = ""; + } + self.setValue(self.lastColor || "#ffffff"); } if (self.R.isValid() && self.G.isValid() && self.B.isValid()) { self.colorShow.element.css("background-color", self.getValue()); @@ -76594,10 +77250,21 @@ BI.ColorPickerEditor = BI.inherit(BI.Widget, { }); }, + _showPreColor: function (color) { + if (color === "") { + this.colorShow.element.css("background-color", "").removeClass("trans-color-background").addClass("auto-color-background"); + } else if (color === "transparent") { + this.colorShow.element.css("background-color", "").removeClass("auto-color-background").addClass("trans-color-background"); + } else { + this.colorShow.element.css({"background-color": color}).removeClass("auto-color-background").removeClass("trans-color-background"); + } + }, + setValue: function (color) { if (color === "transparent") { this.transparent.setSelected(true); this.none.setSelected(false); + this._showPreColor("transparent"); this.R.setValue(""); this.G.setValue(""); this.B.setValue(""); @@ -76610,7 +77277,7 @@ BI.ColorPickerEditor = BI.inherit(BI.Widget, { this.none.setSelected(false); } this.transparent.setSelected(false); - this.colorShow.element.css("background-color", color); + this._showPreColor(color); var json = BI.DOM.rgb2json(BI.DOM.hex2rgb(color)); this.R.setValue(BI.isNull(json.r) ? "" : json.r); this.G.setValue(BI.isNull(json.g) ? "" : json.g); @@ -76630,6 +77297,113 @@ BI.ColorPickerEditor = BI.inherit(BI.Widget, { }); BI.ColorPickerEditor.EVENT_CHANGE = "ColorPickerEditor.EVENT_CHANGE"; BI.shortcut("bi.color_picker_editor", BI.ColorPickerEditor);/** + * 简单选色控件 + * + * Created by GUY on 2015/11/16. + * @class BI.SimpleColorPickerEditor + * @extends BI.Widget + */ +BI.SimpleColorPickerEditor = BI.inherit(BI.Widget, { + + _defaultConfig: function () { + return BI.extend(BI.SimpleColorPickerEditor.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-color-picker-editor", + // width: 200, + height: 20 + }); + }, + + _init: function () { + BI.SimpleColorPickerEditor.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.colorShow = BI.createWidget({ + type: "bi.layout", + cls: "color-picker-editor-display bi-card", + height: 20 + }); + var RGB = BI.createWidgets(BI.createItems([{text: "R"}, {text: "G"}, {text: "B"}], { + type: "bi.label", + cls: "color-picker-editor-label", + width: 10, + height: 20 + })); + + var checker = function (v) { + return BI.isNumeric(v) && (v | 0) >= 0 && (v | 0) <= 255; + }; + var Ws = BI.createWidgets([{}, {}, {}], { + type: "bi.small_text_editor", + cls: "color-picker-editor-input", + validationChecker: checker, + errorText: BI.i18nText("BI-Color_Picker_Error_Text"), + allowBlank: true, + value: 255, + width: 32, + height: 20 + }); + BI.each(Ws, function (i, w) { + w.on(BI.TextEditor.EVENT_CHANGE, function () { + if (self.R.isValid() && self.G.isValid() && self.B.isValid()) { + self.colorShow.element.css("background-color", self.getValue()); + self.fireEvent(BI.SimpleColorPickerEditor.EVENT_CHANGE); + } + }); + }); + this.R = Ws[0]; + this.G = Ws[1]; + this.B = Ws[2]; + + BI.createWidget({ + type: "bi.htape", + element: this, + items: [{ + el: this.colorShow, + lgap: 5, + rgap: 5 + }, { + el: RGB[0], + lgap: 10, + width: 16 + }, { + el: this.R, + width: 36 + }, { + el: RGB[1], + lgap: 10, + width: 16 + }, { + el: this.G, + width: 36 + }, { + el: RGB[2], + lgap: 10, + width: 16 + }, { + el: this.B, + width: 36, + rgap: 10 + }] + }); + }, + + setValue: function (color) { + this.colorShow.element.css({"background-color": color}); + var json = BI.DOM.rgb2json(BI.DOM.hex2rgb(color)); + this.R.setValue(BI.isNull(json.r) ? "" : json.r); + this.G.setValue(BI.isNull(json.g) ? "" : json.g); + this.B.setValue(BI.isNull(json.b) ? "" : json.b); + }, + + getValue: function () { + return BI.DOM.rgb2hex(BI.DOM.json2rgb({ + r: this.R.getValue(), + g: this.G.getValue(), + b: this.B.getValue() + })); + } +}); +BI.SimpleColorPickerEditor.EVENT_CHANGE = "SimpleColorPickerEditor.EVENT_CHANGE"; +BI.shortcut("bi.simple_color_picker_editor", BI.SimpleColorPickerEditor);/** * 选色控件 * * Created by GUY on 2015/11/16. @@ -77310,7 +78084,7 @@ BI.BubblePopupBarView = BI.inherit(BI.BubblePopupView, { _defaultConfig: function () { return BI.extend(BI.BubblePopupBarView.superclass._defaultConfig.apply(this, arguments), { extraCls: "bi-bubble-bar-popup-view", - buttons: [{value: BI.i18nText(BI.i18nText("BI-Basic_Sure"))}, {value: BI.i18nText("BI-Basic_Cancel"), level: "ignore"}] + buttons: [{value: BI.i18nText("BI-Basic_Cancel"), level: "ignore"}, {value: BI.i18nText(BI.i18nText("BI-Basic_Sure"))}] }); }, _init: function () { @@ -77320,7 +78094,7 @@ BI.BubblePopupBarView = BI.inherit(BI.BubblePopupView, { var o = this.options, self = this; var items = []; - BI.each(o.buttons.reverse(), function (i, buttonOpt) { + BI.each(o.buttons, function (i, buttonOpt) { if(BI.isWidget(buttonOpt)) { items.push(buttonOpt); }else{ @@ -77682,7 +78456,7 @@ BI.IconComboTrigger = BI.inherit(BI.Trigger, { cls: "icon-combo-trigger-icon", iconCls: iconCls, disableSelected: true, - width: o.width - 12, + width: o.isShowDown ? o.width - 12 : o.width, height: o.height, iconWidth: o.iconWidth, iconHeight: o.iconHeight, @@ -77693,7 +78467,7 @@ BI.IconComboTrigger = BI.inherit(BI.Trigger, { disableSelected: true, cls: "icon-combo-down-icon trigger-triangle-font", width: 12, - height: o.height, + height: 8, selected: BI.isNotEmptyString(iconCls) }); this.down.setVisible(o.isShowDown); @@ -77950,9 +78724,14 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, { }, listeners: [{ eventName: BI.Combo.EVENT_AFTER_HIDEVIEW, - action: function(){ + action: function () { self.trigger.stopEditing(); } + }, { + eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, + action: function () { + self.fireEvent(BI.SearchTextValueCombo.EVENT_BEFORE_POPUPVIEW); + } }], hideChecker: function (e) { return self.triggerBtn.element.find(e.target).length === 0; @@ -77983,6 +78762,27 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, { bottom: 0, top: 0 }] + }; + }, + + mounted: function () { + var o = this.options; + if(BI.isKey(o.value)) { + this._checkError(o.value); + } + }, + + _checkError: function (v) { + if(BI.isNotNull(v)) { + v = BI.isArray(v) ? v : [v]; + var result = BI.find(this.options.items, function (idx, item) { + return BI.contains(v, item.value); + }); + if (BI.isNull(result)) { + this.element.removeClass("combo-error").addClass("combo-error"); + } else { + this.element.removeClass("combo-error"); + } } }, @@ -77992,6 +78792,7 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, { setValue: function (v) { this.combo.setValue(v); + this._checkError(v); }, getValue: function () { @@ -78000,6 +78801,7 @@ BI.SearchTextValueCombo = BI.inherit(BI.Widget, { } }); BI.SearchTextValueCombo.EVENT_CHANGE = "EVENT_CHANGE"; +BI.SearchTextValueCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; BI.shortcut("bi.search_text_value_combo", BI.SearchTextValueCombo);/** * Created by Windy on 2018/2/5. */ @@ -78454,7 +79256,7 @@ BI.shortcut("bi.text_value_check_combo_popup", BI.TextValueCheckComboPopup);/** BI.TextValueCombo = BI.inherit(BI.Widget, { _defaultConfig: function () { return BI.extend(BI.TextValueCombo.superclass._defaultConfig.apply(this, arguments), { - baseClass: "bi-text-value-combo", + baseCls: "bi-text-value-combo", height: 30, chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, text: "", @@ -78496,11 +79298,29 @@ BI.TextValueCombo = BI.inherit(BI.Widget, { maxHeight: 300 } }); + if(BI.isKey(o.value)) { + this._checkError(o.value); + } + }, + + _checkError: function (v) { + if(BI.isNotNull(v)) { + v = BI.isArray(v) ? v : [v]; + var result = BI.find(this.options.items, function (idx, item) { + return BI.contains(v, item.value); + }); + if (BI.isNull(result)) { + this.element.removeClass("combo-error").addClass("combo-error"); + } else { + this.element.removeClass("combo-error"); + } + } }, setValue: function (v) { this.trigger.setValue(v); this.popup.setValue(v); + this._checkError(v); }, getValue: function () { @@ -78808,7 +79628,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", @@ -78892,7 +79713,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 () { @@ -80635,7 +81460,109 @@ BI.Panel = BI.inherit(BI.Widget, { }); BI.Panel.EVENT_CHANGE = "Panel.EVENT_CHANGE"; -BI.shortcut("bi.panel", BI.Panel);/** +BI.shortcut("bi.panel", BI.Panel);BI.LinearSegmentButton = BI.inherit(BI.BasicButton, { + + props: { + extraCls: "bi-line-segment-button bi-list-item-effect", + once: true, + readonly: true, + hgap: 10, + height: 25 + }, + + render: function () { + var self = this, o = this.options; + + return [{ + type: "bi.label", + text: o.text, + height: o.height, + value: o.value, + hgap: o.hgap, + ref: function () { + self.text = this; + } + }, { + type: "bi.absolute", + items: [{ + el: { + type: "bi.layout", + cls: "line-segment-button-line", + height: 3, + ref: function () { + self.line = this; + } + }, + left: 0, + right: 0, + bottom: 0 + }] + }]; + }, + + setSelected: function (v) { + BI.LinearSegmentButton.superclass.setSelected.apply(this, arguments); + if (v) { + this.line.element.addClass("bi-high-light-background"); + } else { + this.line.element.removeClass("bi-high-light-background"); + } + }, + + setText: function (text) { + this.text.setText(text); + } +}); +BI.shortcut("bi.linear_segment_button", BI.LinearSegmentButton);BI.LinearSegment = BI.inherit(BI.Widget, { + + props: { + baseCls: "bi-linear-segment bi-border-bottom", + items: [], + height: 29 + }, + + render: function () { + var self = this, o = this.options; + return { + type: "bi.button_group", + items: BI.createItems(o.items, { + type: "bi.linear_segment_button", + height: o.height - 1 + }), + layout: [{ + type: "bi.center" + }], + listeners: [{ + eventName: "__EVENT_CHANGE__", + action: function () { + self.fireEvent("__EVENT_CHANGE__", arguments); + } + }, { + eventName: "EVENT_CHANGE", + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }], + ref: function () { + self.buttonGroup = this; + } + }; + }, + + setValue: function (v) { + this.buttonGroup.setValue(v); + }, + + setEnabledValue: function (v) { + this.buttonGroup.setEnabledValue(v); + }, + + + getValue: function () { + return this.buttonGroup.getValue(); + } +}); +BI.shortcut("bi.linear_segment", BI.LinearSegment);/** * 选择列表 * * Created by GUY on 2015/11/1. @@ -82150,7 +83077,11 @@ BI.RichEditorAction = BI.inherit(BI.Widget, { */ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, { _defaultConfig: function () { - return BI.extend(BI.RichEditorParamAction.superclass._defaultConfig.apply(this, arguments), {}); + return BI.extend(BI.RichEditorParamAction.superclass._defaultConfig.apply(this, arguments), { + paramFormatter: function (v) { + return v; + } + }); }, _init: function () { @@ -82185,11 +83116,11 @@ BI.RichEditorParamAction = BI.inherit(BI.RichEditorAction, { var o = this.options; var instance = o.editor.instance; var image = new Image(); - var attrs = BI.DOM.getImage(param); + var attrs = BI.DOM.getImage(o.paramFormatter(param)); image.src = attrs.src; image.alt = param; image.style = attrs.style; - + $(image).addClass("rich-editor-param"); var sel = this._get$Sel(); var wrapper = o.editor.instance.getElm().element; if (wrapper.find(sel).length <= 0) { @@ -82316,6 +83247,7 @@ BI.RichEditorTextToolbar = BI.inherit(BI.Widget, { return BI.extend(BI.RichEditorTextToolbar.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-rich-editor-text-toolbar bi-background", buttons: [ + {type: "bi.rich_editor_font_chooser"}, {type: "bi.rich_editor_size_chooser"}, {type: "bi.rich_editor_bold_button"}, {type: "bi.rich_editor_italic_button"}, @@ -82393,10 +83325,7 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** BI.createWidget({ type: "bi.vertical", element: this, - items: [{ - type: "bi.layout", - height: 1 - }, this.instance = this.addInstance()] + items: [this.instance = this.addInstance()] }); }, @@ -82404,7 +83333,7 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** var o = this.options; var conf = { ne: this, - height: o.height - 1, + height: o.height, maxHeight: o.maxHeight ? o.maxHeight : null }; if (this.element[0].contentEditable || !!window.opera) { @@ -82412,6 +83341,9 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** } else { console.error("不支持此浏览器"); } + if(o.readOnly) { + newInstance.disable(); + } return newInstance; }, @@ -82436,6 +83368,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** // return false; }, + focus: function () { + this.instance.focus(); + }, + setValue: function (v) { this.instance.setContent(v); }, @@ -82450,6 +83386,7 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** }); BI.NicEditor.EVENT_SELECTED = "selected"; BI.NicEditor.EVENT_BLUR = "blur"; + BI.NicEditor.EVENT_FOCUS = "focus"; BI.NicEditor.EVENT_KEYDOWN = "keydown"; BI.shortcut("bi.nic_editor", BI.NicEditor); @@ -82467,8 +83404,7 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** scrollable: false }); this.elm.element.css({ - margin: "4px", - minHeight: (o.height - 8) + "px", + minHeight: BI.isNumber(o.height) ? (o.height - 8) + "px" : o.height, outline: "none" }).html(o.value); @@ -82621,6 +83557,10 @@ BI.shortcut("bi.rich_editor_text_toolbar", BI.RichEditorTextToolbar);/** // return false; }, + focus: function () { + this.setFocus(this.elm.element[0]); + }, + blur: function () { this.isFocused = false; this.elm.element.removeClass(prefix + "selected"); @@ -82672,31 +83612,32 @@ BI.RichEditorBackgroundChooserTrigger = BI.inherit(BI.Widget, { BI.RichEditorBackgroundChooserTrigger.superclass._init.apply(this, arguments); this.font = BI.createWidget({ type: "bi.icon_button", + element: this, cls: "text-background-font" }); - this.underline = BI.createWidget({ - type: "bi.icon_button", - cls: "text-color-underline-font" - }); + // this.underline = BI.createWidget({ + // type: "bi.icon_button", + // cls: "text-color-underline-font" + // }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.font, - top: 2, - left: 2 - }, { - el: this.underline, - top: 7, - left: 2 - }] - }); + // BI.createWidget({ + // type: "bi.absolute", + // element: this, + // items: [{ + // el: this.font, + // top: 2, + // left: 2 + // }, { + // el: this.underline, + // top: 7, + // left: 2 + // }] + // }); }, setValue: function (color) { - this.underline.element.css("color", color); + this.font.element.css("color", color); }, getValue: function () { @@ -82990,31 +83931,32 @@ BI.RichEditorColorChooserTrigger = BI.inherit(BI.Widget, { BI.RichEditorColorChooserTrigger.superclass._init.apply(this, arguments); this.font = BI.createWidget({ type: "bi.icon_button", + element: this, cls: "text-color-font" }); - this.underline = BI.createWidget({ - type: "bi.icon_button", - cls: "text-color-underline-font" - }); + // this.underline = BI.createWidget({ + // type: "bi.icon_button", + // cls: "text-color-underline-font" + // }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.font, - top: 2, - left: 2 - }, { - el: this.underline, - top: 7, - left: 2 - }] - }); + // BI.createWidget({ + // type: "bi.absolute", + // element: this, + // items: [{ + // el: this.font, + // top: 2, + // left: 2 + // }, { + // el: this.underline, + // top: 7, + // left: 2 + // }] + // }); }, setValue: function (color) { - this.underline.element.css("color", color); + this.font.element.css("color", color); }, getValue: function () { @@ -83052,11 +83994,7 @@ BI.RichEditorBackgroundColorChooser = BI.inherit(BI.RichEditorAction, { }); this.colorchooser.on(BI.ColorChooser.EVENT_CHANGE, function () { var backgroundColor = this.getValue(); - o.editor.element.css({ - backgroundColor: backgroundColor, - color: BI.DOM.getContrastColor(backgroundColor) - }); - this.setValue(""); + self.fireEvent("EVENT_CHANGE", backgroundColor); }); }, @@ -83120,7 +84058,73 @@ BI.RichEditorColorChooser = BI.inherit(BI.RichEditorAction, { this.colorchooser.setValue(""); } }); -BI.shortcut("bi.rich_editor_color_chooser", BI.RichEditorColorChooser);/** +BI.shortcut("bi.rich_editor_color_chooser", BI.RichEditorColorChooser);BI.RichEditorFontChooser = BI.inherit(BI.RichEditorAction, { + _defaultConfig: function () { + return BI.extend(BI.RichEditorFontChooser.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-rich-editor-font-chooser bi-border bi-card", + command: "FontName", + width: 50, + height: 20 + }); + }, + + _init: function () { + BI.RichEditorSizeChooser.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.trigger = BI.createWidget({ + type: "bi.text_trigger", + readonly: true, + height: o.height, + triggerWidth: 16, + text: BI.i18nText("BI-Font_Family") + }); + + this.combo = BI.createWidget({ + type: "bi.combo", + element: this, + el: this.trigger, + adjustLength: 1, + popup: { + maxWidth: 70, + minWidth: 70, + el: { + type: "bi.button_group", + items: BI.createItems([{ + value: "Microsoft YaHei", + text: BI.i18nText("BI-Microsoft_YaHei") + }, { + value: "PingFangSC-Light !important", + text: BI.i18nText("BI-Apple_Light") + }, { + value: "arial", + text: "Arial" + }, { + value: "Verdana", + text: "Verdana" + }], { + type: "bi.single_select_item" + }), + layouts: [{ + type: "bi.vertical" + }] + } + } + }); + this.combo.on(BI.Combo.EVENT_CHANGE, function () { + var val = this.getValue()[0]; + self.doCommand(val); + this.hideView(); + this.setValue([]); + }); + }, + + hideIf: function (e) { + if(!this.combo.element.find(e.target).length > 0) { + this.combo.hideView(); + } + } +}); +BI.shortcut("bi.rich_editor_font_chooser", BI.RichEditorFontChooser);/** * 字体大小选择 * * Created by GUY on 2015/11/26. @@ -83209,33 +84213,53 @@ BI.shortcut("bi.rich_editor_size_chooser", BI.RichEditorSizeChooser);/** * @extends BI.Widget */ BI.RichEditor = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.RichEditor.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-rich-editor bi-card", - toolbar: {} - }); + + props: { + baseCls: "bi-rich-editor", + toolbar: {}, + readOnly: false }, - _init: function () { - BI.RichEditor.superclass._init.apply(this, arguments); + + render: function () { var self = this, o = this.options; - this.editor = BI.createWidget({ + var editor = { type: "bi.nic_editor", width: o.width, - height: o.height - }); - - this.editor.on(BI.NicEditor.EVENT_BLUR, function () { - self.fireEvent(BI.RichEditor.EVENT_CONFIRM); - }); - - this.combo = BI.createWidget({ + height: o.height, + readOnly: o.readOnly, + ref: function () { + self.editor = this; + }, + listeners: [{ + eventName: BI.NicEditor.EVENT_BLUR, + action: function () { + self.fireEvent(BI.RichEditor.EVENT_CONFIRM); + } + }, { + eventName: BI.NicEditor.EVENT_FOCUS, + action: function () { + if (!o.readOnly && !self.combo.isViewVisible()) { + self.combo.showView(); + } + self.fireEvent(BI.RichEditor.EVENT_FOCUS); + } + }] + }; + if(o.readOnly) { + return editor; + } + this.editor = BI.createWidget(editor); + return { type: "bi.combo", - element: this, toggle: false, - direction: "top,left", + trigger: "click", + direction: "top,right", isNeedAdjustWidth: false, isNeedAdjustHeight: false, adjustLength: 1, + ref: function () { + self.combo = this; + }, el: this.editor, popup: { el: BI.extend({ @@ -83245,11 +84269,25 @@ BI.RichEditor = BI.inherit(BI.Widget, { height: 30, stopPropagation: true, stopEvent: true - } - }); + }, + listeners: [{ + eventName: BI.Combo.EVENT_AFTER_HIDEVIEW, + action: function () { + self.fireEvent(BI.RichEditor.EVENT_AFTER_HIDEVIEW); + } + }] + }; + }, - this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { - }); + mounted: function () { + var o = this.options; + if(BI.isNull(o.value)) { + this.editor.setValue(o.value); + } + }, + + focus: function () { + this.editor.focus(); }, setValue: function (v) { @@ -83260,7 +84298,9 @@ BI.RichEditor = BI.inherit(BI.Widget, { return this.editor.getValue(); } }); +BI.RichEditor.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW"; BI.RichEditor.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.RichEditor.EVENT_FOCUS = "EVENT_FOCUS"; BI.shortcut("bi.rich_editor", BI.RichEditor);/** * 分段控件使用的button * @@ -83331,6 +84371,7 @@ BI.Segment = BI.inherit(BI.Widget, { this.buttonGroup = BI.createWidget({ element: this, type: "bi.button_group", + value: o.value, items: BI.createItems(o.items, { type: "bi.segment_button", height: o.height - 2, @@ -85048,6 +86089,9 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, { this.checkbox.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, self.isSelected(), self); }); + this.checkbox.on(BI.Checkbox.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectBar.EVENT_CHANGE, self.isSelected(), self); + }); this.half.on(BI.Controller.EVENT_CHANGE, function () { self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, self.isSelected(), self); }); @@ -85128,6 +86172,13 @@ BI.MultiSelectBar = BI.inherit(BI.BasicButton, { var isAllChecked = this.options.isAllCheckedBySelectedValue.apply(this, arguments); this._setSelected(isAllChecked); !isAllChecked && this.setHalfSelected(this.options.isHalfCheckedBySelectedValue.apply(this, arguments)); + }, + + doClick: function () { + BI.MultiSelectBar.superclass.doClick.apply(this, arguments); + if(this.isValid()) { + this.fireEvent(BI.MultiSelectBar.EVENT_CHANGE); + } } }); BI.MultiSelectBar.EVENT_CHANGE = "MultiSelectBar.EVENT_CHANGE"; @@ -86586,7 +87637,9 @@ BI.SmallSelectTextTrigger = BI.inherit(BI.Trigger, { }, setValue: function (vals) { - this.trigger.setText(this._digest(vals, this.options.items)); + var formatValue = this._digest(vals, this.options.items); + this.trigger.element.removeClass("bi-water-mark").addClass(formatValue.cls); + this.trigger.setText(formatValue.text); }, populate: function (items) { @@ -87119,7 +88172,7 @@ BI.MonthDateCombo = BI.inherit(BI.Trigger, { }, setValue: function (v) { - this.trigger.setValue(v + 1); + this.trigger.setValue(v); this.popup.setValue(v); }, @@ -87141,6 +88194,7 @@ BI.YearDateCombo = BI.inherit(BI.Trigger, { baseCls: "bi-year-combo", min: "1900-01-01", // 最小日期 max: "2099-12-31", // 最大日期 + behaviors: {}, height: 25 }); }, @@ -87154,6 +88208,7 @@ BI.YearDateCombo = BI.inherit(BI.Trigger, { this.popup = BI.createWidget({ type: "bi.year_popup", + behaviors: o.behaviors, min: o.min, max: o.max }); @@ -87193,7 +88248,8 @@ BI.YearDateCombo = BI.inherit(BI.Trigger, { } }); BI.YearDateCombo.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.year_date_combo", BI.YearDateCombo);/** +BI.shortcut("bi.year_date_combo", BI.YearDateCombo); +/** * Created by GUY on 2015/9/7. * @class BI.DatePicker * @extends BI.Widget @@ -87203,7 +88259,7 @@ BI.DatePicker = BI.inherit(BI.Widget, { var conf = BI.DatePicker.superclass._defaultConfig.apply(this, arguments); return BI.extend(conf, { baseCls: "bi-date-picker bi-background", - height: 25, + height: 40, min: "1900-01-01", // 最小日期 max: "2099-12-31" // 最大日期 }); @@ -87213,7 +88269,7 @@ BI.DatePicker = BI.inherit(BI.Widget, { BI.DatePicker.superclass._init.apply(this, arguments); var self = this, o = this.options; this._year = BI.getDate().getFullYear(); - this._month = BI.getDate().getMonth(); + this._month = BI.getDate().getMonth() + 1; this.left = BI.createWidget({ type: "bi.icon_button", cls: "pre-page-h-font", @@ -87221,10 +88277,10 @@ BI.DatePicker = BI.inherit(BI.Widget, { height: 25 }); this.left.on(BI.IconButton.EVENT_CHANGE, function () { - if (self._month === 0) { + if (self._month === 1) { self.setValue({ year: self.year.getValue() - 1, - month: 11 + month: 12 }); } else { self.setValue({ @@ -87245,10 +88301,10 @@ BI.DatePicker = BI.inherit(BI.Widget, { }); this.right.on(BI.IconButton.EVENT_CHANGE, function () { - if (self._month === 11) { + if (self._month === 12) { self.setValue({ year: self.year.getValue() + 1, - month: 0 + month: 1 }); } else { self.setValue({ @@ -87288,7 +88344,10 @@ BI.DatePicker = BI.inherit(BI.Widget, { type: "bi.htape", element: this, items: [{ - el: this.left, + el: { + type: "bi.center_adapt", + items: [this.left] + }, width: 25 }, { type: "bi.center_adapt", @@ -87298,7 +88357,10 @@ BI.DatePicker = BI.inherit(BI.Widget, { items: [this.year, this.month] }] }, { - el: this.right, + el: { + type: "bi.center_adapt", + items: [this.right] + }, width: 25 }] }); @@ -87310,14 +88372,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; }, @@ -87342,6 +88404,119 @@ BI.DatePicker = BI.inherit(BI.Widget, { }); BI.DatePicker.EVENT_CHANGE = "EVENT_CHANGE"; BI.shortcut("bi.date_picker", BI.DatePicker);/** + * Created by GUY on 2015/9/7. + * @class BI.YearPicker + * @extends BI.Widget + */ +BI.YearPicker = BI.inherit(BI.Widget, { + _defaultConfig: function () { + var conf = BI.YearPicker.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: "bi-year-picker bi-background", + behaviors: {}, + height: 40, + min: "1900-01-01", // 最小日期 + max: "2099-12-31" // 最大日期 + }); + }, + + _init: function () { + BI.YearPicker.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this._year = BI.getDate().getFullYear(); + this.left = BI.createWidget({ + type: "bi.icon_button", + cls: "pre-page-h-font", + width: 25, + height: 25 + }); + this.left.on(BI.IconButton.EVENT_CHANGE, function () { + self.setValue(self.year.getValue() - 1); + self.fireEvent(BI.YearPicker.EVENT_CHANGE); + self._checkLeftValid(); + self._checkRightValid(); + }); + + this.right = BI.createWidget({ + type: "bi.icon_button", + cls: "next-page-h-font", + width: 25, + height: 25 + }); + + this.right.on(BI.IconButton.EVENT_CHANGE, function () { + self.setValue(self.year.getValue() + 1); + self.fireEvent(BI.YearPicker.EVENT_CHANGE); + self._checkLeftValid(); + self._checkRightValid(); + }); + + this.year = BI.createWidget({ + type: "bi.year_date_combo", + min: o.min, + behaviors: o.behaviors, + max: o.max + }); + this.year.on(BI.YearDateCombo.EVENT_CHANGE, function () { + self.setValue(self.year.getValue()); + self.fireEvent(BI.YearPicker.EVENT_CHANGE); + }); + + BI.createWidget({ + type: "bi.htape", + element: this, + items: [{ + el: { + type: "bi.center_adapt", + items: [this.left] + }, + width: 25 + }, { + type: "bi.center_adapt", + items: [this.year] + }, { + el: { + type: "bi.center_adapt", + items: [this.right] + }, + width: 25 + }] + }); + this.setValue({ + year: this._year + }); + }, + + _checkLeftValid: function () { + var o = this.options; + var valid = !(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._year === BI.parseDateTime(o.max, "%Y-%X-%d").getFullYear()); + this.right.setEnable(valid); + return valid; + }, + + + + setValue: function (v) { + this._year = v; + this.year.setValue(v); + this._checkLeftValid(); + this._checkRightValid(); + }, + + getValue: function () { + return this.year.getValue(); + } +}); +BI.YearPicker.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.year_picker", BI.YearPicker); +/** * Created by GUY on 2015/9/7. * @class BI.DateCalendarPopup * @extends BI.Widget @@ -87379,7 +88554,7 @@ BI.DateCalendarPopup = BI.inherit(BI.Widget, { o = this.options; this.today = BI.getDate(); this._year = this.today.getFullYear(); - this._month = this.today.getMonth(); + this._month = this.today.getMonth() + 1; this._day = this.today.getDate(); this.selectedTime = o.selectedTime || { @@ -87438,6 +88613,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. @@ -87507,386 +88791,11 @@ BI.DateTriangleTrigger = BI.inherit(BI.Trigger, { } }); BI.shortcut("bi.date_triangle_trigger", BI.DateTriangleTrigger);/** - * 日期下拉框 - * - * Created by GUY on 2015/9/7. - * @class BI.DateCombo - * @extends BI.Widget - */ -BI.DateCombo = BI.inherit(BI.Widget, { - _defaultConfig: function () { - return BI.extend(BI.DateCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-date-combo bi-border", - height: 25 - }); - }, - _init: function () { - BI.DateCombo.superclass._init.apply(this, arguments); - var self = this, - o = this.options; - - this.trigger = BI.createWidget({ - type: "bi.date_trigger" - }); - - this.trigger.on(BI.DateTrigger.EVENT_TRIGGER_CLICK, function () { - self.combo.toggle(); - }); - - this.popup = BI.createWidget({ - type: "bi.date_calendar_popup" - }); - - this.popup.on(BI.DateCalendarPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - }); - - this.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - element: this, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - width: 270, - el: this.popup, - stopPropagation: false - } - }); - }, - - setValue: function (v) { - this.trigger.setValue(v); - this.popup.setValue(v); - }, - - getValue: function () { - return this.popup.getValue(); - } -}); -BI.shortcut("bi.date_combo", BI.DateCombo);BI.DateTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - yearLength: 4, - yearMonthLength: 7 - }, - - _defaultConfig: function () { - return BI.extend(BI.DateTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-date-trigger", - min: "1900-01-01", // 最小日期 - max: "2099-12-31", // 最大日期 - height: 24 - }); - }, - _init: function () { - BI.DateTrigger.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.DateTrigger.EVENT_KEY_DOWN); - }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.DateTrigger.EVENT_FOCUS); - }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.DateTrigger.EVENT_STOP); - }); - this.editor.on(BI.SignEditor.EVENT_VALID, function () { - self.fireEvent(BI.DateTrigger.EVENT_VALID); - }); - this.editor.on(BI.SignEditor.EVENT_ERROR, function () { - self.fireEvent(BI.DateTrigger.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.store_value = { - type: BI.DateTrigger.MULTI_DATE_CALENDAR, - value: { - year: date[0] | 0, - month: date[1] - 1, - day: date[2] | 0 - } - }; - } - self.fireEvent(BI.DateTrigger.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.DateTrigger.EVENT_START); - }); - this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.DateTrigger.EVENT_CHANGE); - }); - BI.createWidget({ - type: "bi.htape", - element: this, - items: [{ - el: BI.createWidget(), - width: 30 - }, { - el: this.editor - }] - }); - 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) { - var self = this; - var date = BI.parseDateTime(v, "%Y-%X-%d").print("%Y-%X-%d"); - var yearCheck = function (v) { - return BI.parseDateTime(v, "%Y").print("%Y") == v && date >= self.options.min && date <= self.options.max; - }; - var monthCheck = function (v) { - return BI.parseDateTime(v, "%Y-%X").print("%Y-%X") == v && date >= self.options.min && date <= self.options.max; - }; - if (BI.isNotNull(dateObj) && BI.checkDateLegal(v)) { - switch (v.length) { - case this._const.yearLength: - if (yearCheck(v)) { - this.editor.setValue(v + "-"); - } - break; - case this._const.yearMonthLength: - if (monthCheck(v)) { - this.editor.setValue(v + "-"); - } - break; - } - } - }, - - setValue: function (v) { - var type, value, self = this; - var date = BI.getDate(); - this.store_value = v; - if (BI.isNotNull(v)) { - type = v.type || BI.DateTrigger.MULTI_DATE_CALENDAR; value = v.value; - if(BI.isNull(value)) { - value = v; - } - } - var _setInnerValue = function (date, text) { - var dateStr = date.print("%Y-%x-%e"); - self.editor.setState(dateStr); - self.editor.setValue(dateStr); - self.setTitle(text + ":" + dateStr); - }; - switch (type) { - case BI.DateTrigger.MULTI_DATE_YEAR_PREV: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_PREV]; - date = BI.getDate((date.getFullYear() - 1 * value), date.getMonth(), date.getDate()); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_YEAR_AFTER: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_AFTER]; - date = BI.getDate((date.getFullYear() + 1 * value), date.getMonth(), date.getDate()); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_YEAR_BEGIN: - var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_BEGIN]; - date = BI.getDate(date.getFullYear(), 0, 1); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_YEAR_END: - var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_END]; - date = BI.getDate(date.getFullYear(), 11, 31); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_QUARTER_PREV: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_PREV]; - date = BI.getDate().getBeforeMulQuarter(value); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_QUARTER_AFTER: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_AFTER]; - date = BI.getDate().getAfterMulQuarter(value); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN: - var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN]; - date = BI.getDate().getQuarterStartDate(); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_QUARTER_END: - var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_END]; - date = BI.getDate().getQuarterEndDate(); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_MONTH_PREV: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_PREV]; - date = BI.getDate().getBeforeMultiMonth(value); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_MONTH_AFTER: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_AFTER]; - date = BI.getDate().getAfterMultiMonth(value); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_MONTH_BEGIN: - var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_BEGIN]; - date = BI.getDate(date.getFullYear(), date.getMonth(), 1); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_MONTH_END: - var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_END]; - date = BI.getDate(date.getFullYear(), date.getMonth(), (date.getLastDateOfMonth()).getDate()); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_WEEK_PREV: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_WEEK_PREV]; - date = date.getOffsetDate(-7 * value); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_WEEK_AFTER: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_WEEK_AFTER]; - date = date.getOffsetDate(7 * value); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_DAY_PREV: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_PREV]; - date = date.getOffsetDate(-1 * value); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_DAY_AFTER: - var text = value + BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_AFTER]; - date = date.getOffsetDate(1 * value); - _setInnerValue(date, text); - break; - case BI.DateTrigger.MULTI_DATE_DAY_TODAY: - var text = BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_TODAY]; - date = BI.getDate(); - _setInnerValue(date, text); - break; - 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.store_value; - } - -}); - -BI.DateTrigger.MULTI_DATE_YEAR_PREV = 1; -BI.DateTrigger.MULTI_DATE_YEAR_AFTER = 2; -BI.DateTrigger.MULTI_DATE_YEAR_BEGIN = 3; -BI.DateTrigger.MULTI_DATE_YEAR_END = 4; - -BI.DateTrigger.MULTI_DATE_MONTH_PREV = 5; -BI.DateTrigger.MULTI_DATE_MONTH_AFTER = 6; -BI.DateTrigger.MULTI_DATE_MONTH_BEGIN = 7; -BI.DateTrigger.MULTI_DATE_MONTH_END = 8; - -BI.DateTrigger.MULTI_DATE_QUARTER_PREV = 9; -BI.DateTrigger.MULTI_DATE_QUARTER_AFTER = 10; -BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN = 11; -BI.DateTrigger.MULTI_DATE_QUARTER_END = 12; - -BI.DateTrigger.MULTI_DATE_WEEK_PREV = 13; -BI.DateTrigger.MULTI_DATE_WEEK_AFTER = 14; - -BI.DateTrigger.MULTI_DATE_DAY_PREV = 15; -BI.DateTrigger.MULTI_DATE_DAY_AFTER = 16; -BI.DateTrigger.MULTI_DATE_DAY_TODAY = 17; - -BI.DateTrigger.MULTI_DATE_PARAM = 18; -BI.DateTrigger.MULTI_DATE_CALENDAR = 19; - -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM = {}; -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_PREV] = BI.i18nText("BI-Multi_Date_Year_Prev"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_AFTER] = BI.i18nText("BI-Multi_Date_Year_Next"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_BEGIN] = BI.i18nText("BI-Multi_Date_Year_Begin"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_YEAR_END] = BI.i18nText("BI-Multi_Date_Year_End"); - -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_PREV] = BI.i18nText("BI-Multi_Date_Quarter_Prev"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_AFTER] = BI.i18nText("BI-Multi_Date_Quarter_Next"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_BEGIN] = BI.i18nText("BI-Multi_Date_Quarter_Begin"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_QUARTER_END] = BI.i18nText("BI-Multi_Date_Quarter_End"); - -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_PREV] = BI.i18nText("BI-Multi_Date_Month_Prev"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_AFTER] = BI.i18nText("BI-Multi_Date_Month_Next"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_BEGIN] = BI.i18nText("BI-Multi_Date_Month_Begin"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_MONTH_END] = BI.i18nText("BI-Multi_Date_Month_End"); - -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_WEEK_PREV] = BI.i18nText("BI-Multi_Date_Week_Prev"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_WEEK_AFTER] = BI.i18nText("BI-Multi_Date_Week_Next"); - -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_PREV] = BI.i18nText("BI-Multi_Date_Day_Prev"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_AFTER] = BI.i18nText("BI-Multi_Date_Day_Next"); -BI.DateTrigger.MULTI_DATE_SEGMENT_NUM[BI.DateTrigger.MULTI_DATE_DAY_TODAY] = BI.i18nText("BI-Multi_Date_Today"); - -BI.DateTrigger.EVENT_FOCUS = "EVENT_FOCUS"; -BI.DateTrigger.EVENT_START = "EVENT_START"; -BI.DateTrigger.EVENT_STOP = "EVENT_STOP"; -BI.DateTrigger.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.DateTrigger.EVENT_CHANGE = "EVENT_CHANGE"; -BI.DateTrigger.EVENT_VALID = "EVENT_VALID"; -BI.DateTrigger.EVENT_ERROR = "EVENT_ERROR"; -BI.DateTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK"; -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", // 最小日期 @@ -87895,12 +88804,12 @@ 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(); this._year = this.today.getFullYear(); - this._month = this.today.getMonth(); + this._month = this.today.getMonth() + 1; this.selectedTime = o.selectedTime || { year: this._year, @@ -87913,9 +88822,19 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { max: o.max }); this.datePicker.on(BI.DatePicker.EVENT_CHANGE, function () { - self.selectedTime = self.datePicker.getValue(); - // self.selectedTime.day = 1; + var value = self.datePicker.getValue(); + var monthDay = BI.getDate(value.year, value.month - 1, 1).getMonthDays(); + var day = self.selectedTime.day || 0; + if (day > monthDay) { + day = monthDay; + } + self.selectedTime = { + year: value.year, + month: value.month, + day: day + }; self.calendar.setSelect(BI.Calendar.getPageByDateJSON(self.selectedTime)); + self.calendar.setValue(self.selectedTime); }); this.calendar = BI.createWidget({ @@ -87927,14 +88846,6 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { type: "bi.navigation", tab: this.datePicker, cardCreator: BI.bind(this._createNav, this) - - // afterCardCreated: function () { - // - // }, - // - // afterCardShow: function () { - // // this.setValue(self.selectedTime); - // } }); this.calendar.on(BI.Navigation.EVENT_CHANGE, function () { self.selectedTime = self.calendar.getValue(); @@ -87966,7 +88877,7 @@ BI.DatePaneWidget = BI.inherit(BI.Widget, { var today = BI.getDate(); return { year: today.getFullYear(), - month: today.getMonth() + month: today.getMonth() + 1 }; }, @@ -88003,7 +88914,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() + 1, + day: date.getDate() + }); + break; + case BI.DynamicDatePane.Dynamic: + self.dynamicPane.setValue({ + year: 0 + }); + break; + default: + break; + } + } + }], + ref: function () { + self.switcher = 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.switcher.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() + 1 + }); + } 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, { @@ -88028,7 +89078,7 @@ BI.DateTimeCombo = BI.inherit(BI.Single, { var date = BI.getDate(); this.storeValue = BI.isNotNull(opts.value) ? opts.value : { year: date.getFullYear(), - month: date.getMonth(), + month: date.getMonth() + 1, day: date.getDate(), hour: date.getHours(), minute: date.getMinutes(), @@ -88060,10 +89110,6 @@ BI.DateTimeCombo = BI.inherit(BI.Single, { self.hidePopupView(); self.fireEvent(BI.DateTimeCombo.EVENT_CONFIRM); }); - this.popup.on(BI.DateTimePopup.CALENDAR_EVENT_CHANGE, function () { - self.trigger.setValue(self.popup.getValue()); - self.fireEvent(BI.DateTimeCombo.EVENT_CHANGE); - }); this.combo = BI.createWidget({ type: "bi.combo", toggle: false, @@ -88073,7 +89119,6 @@ BI.DateTimeCombo = BI.inherit(BI.Single, { adjustLength: this.constants.comboAdjustHeight, popup: { el: this.popup, - maxHeight: this.constants.popupHeight, width: this.constants.popupWidth, stopPropagation: false } @@ -88144,7 +89189,7 @@ BI.DateTimePopup = BI.inherit(BI.Widget, { return BI.extend(BI.DateTimePopup.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-date-time-popup", width: 268, - height: 290 + height: 374 }); }, _init: function () { @@ -88271,7 +89316,7 @@ BI.DateTimePopup = BI.inherit(BI.Widget, { date = BI.getDate(); this.dateCombo.setValue({ year: date.getFullYear(), - month: date.getMonth(), + month: date.getMonth() + 1, day: date.getDate() }); this.hour.setValue(date.getHours()); @@ -88462,7 +89507,7 @@ BI.DateTimeTrigger = BI.inherit(BI.Trigger, { value = BI.getDate(); dateStr = value.print("%Y-%X-%d %H:%M:%S"); } else { - var date = BI.getDate(value.year, value.month, value.day, value.hour, value.minute, value.second); + var date = BI.getDate(value.year, value.month - 1, value.day, value.hour, value.minute, value.second); dateStr = date.print("%Y-%X-%d %H:%M:%S"); } @@ -88471,7 +89516,293 @@ 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() + 1; + + 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 () { + var value = self.datePicker.getValue(); + var monthDay = BI.getDate(value.year, value.month - 1, 1).getMonthDays(); + var day = self.selectedTime.day || 0; + if (day > monthDay) { + day = monthDay; + } + self.selectedTime = BI.extend(self.selectedTime, { + year: value.year, + month: value.month, + day: day + }); + self.calendar.setSelect(BI.Calendar.getPageByDateJSON(self.selectedTime)); + self.calendar.setValue(self.selectedTime); + self.fireEvent("EVENT_CHANGE"); + }); + + 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; + }, + listeners: [{ + eventName: BI.DynamicDateTimeSelect.EVENT_CONFIRM, + action: function () { + self.fireEvent("EVENT_CHANGE"); + } + }] + }, + 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() + 1 + }; + }, + + _setCalenderValue: function (date) { + this.calendar.setSelect(BI.Calendar.getPageByDateJSON(date)); + this.calendar.setValue(date); + this.selectedTime = BI.extend({}, this.timeSelect.getValue(), 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); + } + }, + + _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() + 1, + day: date.getDate() + }); + break; + case BI.DynamicDateTimePane.Dynamic: + self.dynamicPane.setValue({ + year: 0 + }); + break; + default: + break; + } + } + }], + ref: function () { + self.switcher = 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.switcher.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() + 1 + }); + } 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, { @@ -88831,7 +90162,8 @@ BI.DownListPopup = BI.inherit(BI.Pane, { this.singleValues = []; this.childValueMap = {}; this.fatherValueMap = {}; - var self = this, o = this.options, children = this._createChildren(o.items); + this.items = BI.deepClone(this.options.items); + var self = this, o = this.options, children = this._createChildren(this.items); this.popup = BI.createWidget({ type: "bi.button_tree", items: BI.createItems(children, @@ -88880,6 +90212,7 @@ BI.DownListPopup = BI.inherit(BI.Pane, { }, _createChildren: function (items) { var self = this, result = []; + // 不能修改populate进来的item的引用 BI.each(items, function (i, it) { var item_done = { type: "bi.down_list_group", @@ -88999,9 +90332,8 @@ BI.DownListPopup = BI.inherit(BI.Pane, { }, _checkValues: function (values) { - var self = this, o = this.options; var value = []; - BI.each(o.items, function (idx, itemGroup) { + BI.each(this.items, function (idx, itemGroup) { BI.each(itemGroup, function (id, item) { if(BI.isNotNull(item.children)) { var childValues = BI.map(item.children, "value"); @@ -89034,17 +90366,17 @@ BI.DownListPopup = BI.inherit(BI.Pane, { populate: function (items) { BI.DownListPopup.superclass.populate.apply(this, arguments); - var self = this; - self.childValueMap = {}; - self.fatherValueMap = {}; - self.singleValues = []; - var children = self._createChildren(items); + this.items = BI.deepClone(items); + this.childValueMap = {}; + this.fatherValueMap = {}; + this.singleValues = []; + var children = this._createChildren(this.items); var popupItem = BI.createItems(children, {}, { adjustLength: -2 } ); - self.popup.populate(popupItem); + this.popup.populate(popupItem); }, setValue: function (valueItem) { @@ -89082,184 +90414,2385 @@ 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 roy on 15/9/14. + * 汇总表格帮助类 + * Created by Young's on 2017/1/19. */ -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 - }); +!(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.getOffsetQuarter(BI.parseInt(obj.quarter)); + } + if (BI.isNotNull(obj.month)) { + date = date.getOffsetMonth(BI.parseInt(obj.month)); + } + if (BI.isNotNull(obj.week)) { + date = date.getOffsetDate(BI.parseInt(obj.week) * 7); + } + if (BI.isNotNull(obj.day)) { + date = date.getOffsetDate(BI.parseInt(obj.day)); + } + if (BI.isNotNull(obj.workDay)) { + // todo 根据工作日做偏移 暂时按天偏移 + date = date.getOffsetDate(BI.parseInt(obj.workDay)); + } + 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" }, - _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" + + 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); + } + + var plainValue = {}; + BI.each(self.resultPane.getAllButtons(), function (idx, button) { + var value = button.getValue(); + if(BI.isNotNull(value.dateType)) { + plainValue[value.dateType] = { + value: value.value, + offset: value.offset + }; } - }] + }); + self.resultPane.populate(self._getParamJson(BI.map(self.checkgroup.getValue(), function (idx, v) { + var obj = { + dateType: v + }; + if(BI.has(plainValue, v)) { + obj.value = plainValue[v].value; + obj.offset = plainValue[v].offset; + } + return obj; + }))); + 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; }, - width: 25 - }, - { - el: self.editor - }, - { - el: this.clear, - width: 25 + 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; } - ] - }); - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + }, { + 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.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); + _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"); + } + }] + }); - 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(); + return items; }, - _checkClear: function () { - if (!this.getValue()) { - this.clear.invisible(); - } else { - this.clear.visible(); + _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 + }]; } }, - focus: function () { - this.editor.focus(); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - blur: function () { - this.editor.blur(); + 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 () { - if (this.isValid()) { - var res = this.editor.getValue().match(/[\S]+/g); - return BI.isNull(res) ? "" : res[res.length - 1]; + 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; + } - getLastValidValue: function () { - return this.editor.getLastValidValue(); +}); +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 + } - setValue: function (v) { - this.editor.setValue(v); - if (BI.isKey(v)) { - this.clear.visible(); - } +});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" }, - - isEditing: function () { - return this.editor.isEditing(); + + props: { + baseCls: "bi-dynamic-date-combo bi-border", + height: 24 }, - 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"; + 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() + 1 + }; + 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._checkDynamicValue(self.storeValue); + 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() + 1, + 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_Please_Input_Content"); + } + 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() + 1, + 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() + 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 { + 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: 6, + yearFullMonthLength: 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] | 0, + month: date[1] | 0, + day: date[2] | 0 + }); + }, + 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"); + }, + title: function () { + var storeValue = self.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = self._getText(value); + var date = BI.getDate(); + date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = date.print("%Y-%x-%e"); + return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + return ""; + } + return BI.getDate(value.year, (value.month - 1), value.day).print("%Y-%X-%d"); + } + } + }); + 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] | 0, + 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: + case this._const.yearFullMonthLength: + var splitMonth = v.split("-")[1]; + if ((BI.isNotNull(splitMonth) && splitMonth.length === 2) || 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"); + var dateStr = date.print("%Y-%X-%d"); + return (date.getMonth() > 0 && (BI.parseDateTime(v, "%Y-%X").print("%Y-%X") === v || + BI.parseDateTime(v, "%Y-%x").print("%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; + }, + + _setInnerValue: function (date) { + var dateStr = date.print("%Y-%x-%e"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + }, + + _getText: function (obj) { + var value = ""; + var endText = ""; + if(BI.isNotNull(obj.year)) { + if(BI.parseInt(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")); + } + endText = getPositionText(BI.i18nText("BI-Basic_Year"), obj.position); + } + if(BI.isNotNull(obj.quarter)) { + if(BI.parseInt(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")); + } + endText = getPositionText(BI.i18nText("BI-Basic_Single_Quarter"), obj.position); + } + if(BI.isNotNull(obj.month)) { + if(BI.parseInt(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")); + } + endText = getPositionText(BI.i18nText("BI-Basic_Month"), obj.position); + } + if(BI.isNotNull(obj.week)) { + if(BI.parseInt(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")); + } + endText = getPositionText(BI.i18nText("BI-Basic_Week"), obj.position); + } + if(BI.isNotNull(obj.day)) { + if(BI.parseInt(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")); + } + endText = BI.size(obj) === 1 ? getPositionText(BI.i18nText("BI-Basic_Month"), obj.position) : ""; + } + if(BI.isNotNull(obj.workDay) && BI.parseInt(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 + endText; + + 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(""); + } else { + var dateStr = BI.getDate(value.year, (value.month - 1), value.day).print("%Y-%X-%d"); + this.editor.setState(dateStr); + this.editor.setValue(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() + 1 + }; + 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._checkDynamicValue(self.storeValue); + 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() + 1, + 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(); + }, + + isValid: function () { + return this.trigger.isValid(); + } +}); + +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() + 1, + 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() + 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: 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 () { + var value = this.getValue(); + self._checkHour(value); + this.setValue(self._formatValueToDoubleDigit(value)); + 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 () { + var value = this.getValue(); + self._checkMinute(value); + this.setValue(self._formatValueToDoubleDigit(value), 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 () { + var value = this.getValue(); + self._checkSecond(value); + this.setValue(self._formatValueToDoubleDigit(value)); + self.fireEvent(BI.DynamicDateTimeSelect.EVENT_CONFIRM); + } + }], + width: 60, + height: 24 + }] + }] + }; + }, + + _checkBorder: function (v) { + v = v || {}; + this._checkHour(v.hour); + this._checkMinute(v.minute); + this._checkSecond(v.second); + }, + + _checkHour: function (value) { + this.hour.setDownEnable(BI.parseInt(value) > 0); + this.hour.setUpEnable(BI.parseInt(value) < 23); + }, + + _checkMinute: function (value) { + this.minute.setDownEnable(BI.parseInt(value) > 0); + this.minute.setUpEnable(BI.parseInt(value) < 59); + }, + + _checkSecond: function (value) { + this.second.setDownEnable(BI.parseInt(value) > 0); + this.second.setUpEnable(BI.parseInt(value) < 59); + }, + + _autoSwitch: function (v, type) { + var limit = 0; + var value = v; + switch (type) { + case BI.DynamicDateTimeSelect.HOUR: + limit = 2; + break; + case BI.DynamicDateTimeSelect.MINUTE: + limit = 5; + 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); + this._checkBorder(v); + } + +}); +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: 6, + yearFullMonthLength: 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] | 0, + month: date[1] | 0, + day: date[2] | 0 + }); + }, + 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"); + }, + title: function () { + var storeValue = self.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = self._getText(value); + var date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = date.print("%Y-%x-%e %H:%M:%S"); + return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + return ""; + } + return BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, + value.second || 0).print("%Y-%X-%d %H:%M:%S"); + } + } + }); + 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] | 0, + 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: + case this._const.yearFullMonthLength: + var splitMonth = v.split("-")[1]; + if ((BI.isNotNull(splitMonth) && splitMonth.length === 2) || 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"); + var dateStr = date.print("%Y-%X-%d"); + return (date.getMonth() > 0 && (BI.parseDateTime(v, "%Y-%X").print("%Y-%X") === v || + BI.parseDateTime(v, "%Y-%x").print("%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; + }, + + _setInnerValue: function (date) { + var dateStr = date.print("%Y-%x-%e %H:%M:%S"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + }, + + _getText: function (obj) { + var value = ""; + var endText = ""; + if(BI.isNotNull(obj.year)) { + if(BI.parseInt(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")); + } + endText = getPositionText(BI.i18nText("BI-Basic_Year"), obj.position); + } + if(BI.isNotNull(obj.quarter)) { + if(BI.parseInt(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")); + } + endText = getPositionText(BI.i18nText("BI-Basic_Single_Quarter"), obj.position); + } + if(BI.isNotNull(obj.month)) { + if(BI.parseInt(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")); + } + endText = getPositionText(BI.i18nText("BI-Basic_Month"), obj.position); + } + if(BI.isNotNull(obj.week)) { + if(BI.parseInt(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")); + } + endText = getPositionText(BI.i18nText("BI-Basic_Week"), obj.position); + } + if(BI.isNotNull(obj.day)) { + if(BI.parseInt(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")); + } + endText = BI.size(obj) === 1 ? getPositionText(BI.i18nText("BI-Basic_Month"), obj.position) : ""; + } + if(BI.isNotNull(obj.workDay) && BI.parseInt(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 + endText; + + 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(""); + } else { + var dateStr = BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, + value.second || 0).print("%Y-%X-%d %H:%M:%S"); + this.editor.setState(dateStr); + this.editor.setValue(dateStr); + } + break; + } + }, + + getKey: function () { + return this.editor.getValue(); + }, + getValue: function () { + return this.storeValue; + }, + + isValid: function () { + return this.editor.isValid(); + } + +}); + +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]; + } + }, + + getKeywords: function () { + var val = this.editor.getValue(); + var keywords = val.match(/[\S]+/g); + if (BI.isEndWithBlank(val)) { + return keywords.concat([" "]); + } + return keywords; + }, + + 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"; @@ -90136,2133 +93669,1821 @@ BI.extend(BI.FileManagerNav, { }); BI.FileManagerNav.EVENT_CHANGE = "FileManagerNav.EVENT_CHANGE"; BI.shortcut("bi.file_manager_nav", BI.FileManagerNav);/** - * Created by zcf on 2016/9/26. + * 过滤条件抽象类 + * + * @class BI.AbstractFilterItem + * @extend BI.Widget */ -BI.IntervalSlider = BI.inherit(BI.Widget, { - _constant: { - EDITOR_WIDTH: 58, - EDITOR_R_GAP: 60, - EDITOR_HEIGHT: 30, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 - }, - - _defaultConfig: function () { - return BI.extend(BI.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(); - }, +BI.AbstractFilterItem = BI.inherit(BI.Widget, { - _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); - }, document); - 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()); - } + props: { + baseCls: "bi-filter-item bi-border-right bi-border-bottom" }, - _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%" - }; + isSelectedCondition: function () { + return this.emptyItem && this.emptyItem.isVisible(); }, - _createSliderWrapper: function () { - var c = this._constant; - return { - el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: this.sliderOne, - top: 0, - left: "0%" - }] - }, { + setSelectedCondition: function (b) { + if (b) { + if (!this.emptyItem) { + this.emptyItem = BI.createWidget({ type: "bi.absolute", + height: 40, + cls: "filter-item-empty-item bi-border-top", 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%" - }] + el: { + type: "bi.center_adapt", + cls: "empty-filter-item-leaf" + } }], - 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}); + hgap: 10, + vgap: 5 + }); + BI.createWidget({ + type: "bi.vertical", + element: this, + items: [this.emptyItem], + scrolly: false + }); } } - }, - - _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); - }, + this.emptyItem && this.emptyItem.setVisible(b); + } +}); +BI.extend(BI.AbstractFilterItem, { + FILTER_OPERATION_FORMULA: 1, + FILTER_OPERATION_CONDITION: 2, + FILTER_OPERATION_CONDITION_AND: 3, + FILTER_OPERATION_CONDITION_OR: 4, + FILTER_OPERATION_FORMULA_AND: 5, + FILTER_OPERATION_FORMULA_OR: 6 +});/** + * Created by Urthur on 2017/11/21. + */ +!(function () { + var Expander = BI.inherit(BI.Widget, { + props: { + baseCls: "bi-filter-expander", + el: {}, + popup: {} + }, - _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); - }, + render: function () { + var self = this, o = this.options; + return { + type: "bi.filter_expander", + el: o.el, + popup: o.popup, + id: o.id, + value: o.value, + listeners: [{ + eventName: BI.Controller.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + } + }], + ref: function (_ref) { + self.expander = _ref; + } + }; + }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; - }, + populate: function () { + this.expander.populate.apply(this.expander, arguments); + }, - // 其中取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)); + getValue: function () { + var val = this.expander.getValue(); + return { + filterType: val.type, + filterValue: val.value, + id: val.id + }; } - return BI.parseFloat(this.calculation.accurateAddition(div, this.min).toFixed(this.precision)); - - }, + }); + BI.shortcut("bi.and.or.filter.expander", Expander); +}());/** + * @class BI.FilterExpander + * @extend BI.AbstractFilterItem + * 过滤树的一个expander节点 + */ +!(function () { + var FilterExpander = BI.inherit(BI.AbstractFilterItem, { + _constant: { + EXPANDER_WIDTH: 20 + }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); - }, + props: { + baseCls: "bi-filter-item bi-filter-expander", + el: {}, + popup: {} + }, - _setDraggableEnable: function (enable) { - this.sliderOne.setEnable(enable); - this.sliderTwo.setEnable(enable); - }, + render: function () { + var self = this, o = this.options; + var value = o.el.value, text = ""; + if (value === BI.Filter.FILTER_TYPE.AND) { + text = BI.i18nText("BI-Basic_And"); + } else { + text = BI.i18nText("BI-Basic_Or"); + } + return { + type: "bi.horizontal_adapt", + cls: "filter-item-empty-item", + verticalAlign: BI.VerticalAlign.Middle, + items: [{ + type: "bi.text_button", + cls: "condition-and-or", + text: text, + value: value, + id: o.id, + width: this._constant.EXPANDER_WIDTH, + height: "100%", + ref: function (_ref) { + self.expander = _ref; + }, + listeners: [{ + eventName: BI.TextButton.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.CLICK, "", self); + } + }] + }, BI.extend(o.popup, { + ref: function (_ref) { + self.conditionsView = _ref; + }, + listeners: [{ + eventName: BI.Controller.EVENT_CHANGE, + action: function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + } + }] + })] + }; + }, - _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; + getValue: function () { + return { + type: this.expander.getValue(), + value: this.conditionsView.getValue(), + id: this.options.id + }; + }, + + populate: function () { + this.conditionsView.populate.apply(this.conditionsView, arguments); } - arr = pre.split("."); - return arr.length > 1 ? arr[1].length : 0; - + }); + BI.shortcut("bi.filter_expander", FilterExpander); +}());/** + * 过滤 + * + * Created by GUY on 2015/11/20. + * @class BI.Filter + * @extend BI.Widget + */ +BI.Filter = BI.inherit(BI.Widget, { + + constants: { + FIELD_TYPE_NUMBER: 1, + FIELD_TYPE_STRING: 0, + FIELD_TYPE_DATE: 2 }, - _assertValue: function (value) { - if(value <= this.min) { - return this.min; - } - if(value >= this.max) { - return this.max; - } - return value; + props: { + baseCls: "bi-filter", + expander: {}, + items: [], + el: {}, + itemCreator: BI.empty }, - getValue: function () { - if (this.valueOne <= this.valueTwo) { - return {min: this.valueOne, max: this.valueTwo}; - } - return {min: this.valueTwo, max: this.valueOne}; - + render: function () { + var self = this, o = this.options; + return BI.extend({ + type: "bi.filter_operation", + expander: o.expander, + listeners: [{ + eventName: "EVENT_OPERATION", + action: function (type) { + switch (type) { + case BI.AbstractFilterItem.FILTER_OPERATION_CONDITION: + case BI.AbstractFilterItem.FILTER_OPERATION_CONDITION_AND: + self._addAndOrCondition(BI.Filter.FILTER_TYPE.EMPTY_CONDITION); + break; + case BI.AbstractFilterItem.FILTER_OPERATION_CONDITION_OR: + self._addAndOrCondition(BI.Filter.FILTER_TYPE.EMPTY_CONDITION, 1); + break; + case BI.AbstractFilterItem.FILTER_OPERATION_FORMULA: + case BI.AbstractFilterItem.FILTER_OPERATION_FORMULA_AND: + self._addAndOrCondition(BI.Filter.FILTER_TYPE.EMPTY_FORMULA); + break; + case BI.AbstractFilterItem.FILTER_OPERATION_FORMULA_OR: + self._addAndOrCondition(BI.Filter.FILTER_TYPE.EMPTY_FORMULA, 1); + break; + } + } + }, { + eventName: "BI.FilterOperation.EVENT_DESTROY_ITEM", + action: function (id) { + self._removeCondition(id); + } + }], + ref: function (_ref) { + self.filter = _ref; + } + }, o.el); }, - 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); - } + mounted: function () { + this.tree = new BI.Tree(); + this.tree.initTree(this.options.items); + this._populate(this.tree.toJSONWithNode()); }, - 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; + _createEmptyNode: function (type) { + var node = new BI.Node(BI.UUID()); + node.set("data", { + value: type + }); + return node; + }, + + _insertAndOrCondition: function (id, formulaOrField, type) { + var ANDOR = ["AND", "OR"]; + type || (type = 0); + var finded = this.tree.search(id); + if (BI.isNotNull(finded)) { + var data = finded.get("data"); + var parent = finded.getParent(); + var index = parent.getChildIndex(finded.id); + var pdata = parent.get("data") || {}; + var node = this._createEmptyNode(formulaOrField); + if (data.value === BI.Filter.FILTER_TYPE[ANDOR[type]]) { + this.tree.addNode(finded, node); + return; } - if (valueOne < this.min) { - this.valueOne = this.min; + if (data.value === BI.Filter.FILTER_TYPE[ANDOR[1 - type]]) { + if (pdata.value === BI.Filter.FILTER_TYPE[ANDOR[type]]) { + parent.addChild(node, index + 1); + return; + } } - if (valueTwo > this.max) { - this.valueTwo = this.max; + if ((data.value === BI.Filter.FILTER_TYPE[ANDOR[1 - type]] && pdata.value !== BI.Filter.FILTER_TYPE[ANDOR[type]]) + || pdata.value === BI.Filter.FILTER_TYPE[ANDOR[1 - type]] + || (pdata.value !== BI.Filter.FILTER_TYPE.AND && pdata.value !== BI.Filter.FILTER_TYPE.OR)) { + var andor = new BI.Node(BI.UUID()); + andor.set("data", { + value: BI.Filter.FILTER_TYPE[ANDOR[type]], + children: [finded.get("data"), node.get("data")] + }); + parent.removeChildByIndex(index); + parent.addChild(andor, index); + andor.addChild(finded); + andor.addChild(node); + return; } + parent.addChild(node, index + 1); } }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.valueOne = ""; - this.valueTwo = ""; - this.min = NaN; - this.max = NaN; - this._setBlueTrackWidth(0); + _removeCondition: function (id) { + var finded = this.tree.search(id); + if (BI.isNotNull(finded)) { + var parent = finded.getParent(); + parent.removeChild(id); + if (parent.getChildrenLength() <= 1) { + var prev = parent.getParent(); + if (BI.isNotNull(prev)) { + var index = prev.getChildIndex(parent.id); + prev.removeChildByIndex(index); + if (parent.getChildrenLength() === 1) { + prev.addChild(parent.getFirstChild(), index); + } + } + } + this._populate(this.tree.toJSONWithNode()); + this.fireEvent("EVENT_CHANGE"); + } }, - 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)); + _addAndOrCondition: function (formulaOrField, type) { + var ANDOR = ["AND", "OR"]; + type || (type = 0); + var currentSelectItem = this.filter.getCurrentSelectItem(); + if (BI.isNotNull(currentSelectItem)) { + var id = currentSelectItem.attr("id"); + this._insertAndOrCondition(id, formulaOrField, type); + } else { + var node = this._createEmptyNode(formulaOrField); + var root = this.tree.getRoot(); + var child = root.getLastChild(); + if (BI.isNotNull(child)) { + var data = child.get("data"); + if (data.value === BI.Filter.FILTER_TYPE[ANDOR[type]]) { + this.tree.addNode(child, node); + } else { + var andor = new BI.Node(BI.UUID()); + andor.set("data", { + value: BI.Filter.FILTER_TYPE[ANDOR[type]], + children: [child.get("data"), node.get("data")] + }); + root.removeChild(child.id); + this.tree.addNode(andor); + this.tree.addNode(andor, child); + this.tree.addNode(andor, node); + } } else { - this.labelOne.setValue(this.min); - this.labelTwo.setValue(this.max); - this._setAllPosition(0, 100); + this.tree.addNode(node); } } - } -}); -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: "" - }); + this._populate(this.tree.toJSONWithNode()); + this.fireEvent("EVENT_CHANGE"); }, - _init: function () { - BI.AccurateCalculationModel.superclass._init.apply(this, arguments); + _populate: function (items) { + this.filter.defaultState(); + var o = this.options; + o.items = items; + BI.Tree.traversal(items, function (i, item) { + o.itemCreator(item); + }); + this.filter.populate.apply(this.filter, [items]); }, - _getMagnitude: function (n) { - var magnitude = "1"; - for (var i = 0; i < n; i++) { - magnitude += "0"; - } - return BI.parseInt(magnitude); + populate: function (conditions) { + this.tree.initTree(conditions); + this._populate(this.tree.toJSONWithNode()); }, - _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"; - } - }, + getValue: function () { + return this.filter.getValue(); + } +}); - _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 - }; - }, +BI.shortcut("bi.filter", BI.Filter); - _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.Filter.FILTER_TYPE = {}; +BI.Filter.FILTER_TYPE.FORMULA = 33; +BI.Filter.FILTER_TYPE.AND = 34; +BI.Filter.FILTER_TYPE.OR = 35; +BI.Filter.FILTER_TYPE.EMPTY_FORMULA = 36; +BI.Filter.FILTER_TYPE.EMPTY_CONDITION = 37; +/** + * Created by windy on 2017/3/28. + */ +!(function () { + var FilterList = BI.inherit(BI.ButtonTree, { + props: { + baseCls: "bi-button-map" + }, - 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); + _createBtns: function (items) { + var o = this.options; + var buttons = BI.createWidgets(BI.createItems(items, {type: "bi.text_button", once: o.chooseType === 0})); + var keys = BI.map(items, function (i, item) { + item = BI.stripEL(item); + if (!(item.id || item.value)) { + throw new Error("item must have 'id' or 'value' as its property"); + } + return item.id || item.value; + }); + return BI.zipObject(keys, buttons); + }, - function getDecimalMaxLength (num1, num2) { - if (num1.numDecimal.length >= num2.numDecimal.length) { - return num1.numDecimal.length; - } - return num2.numDecimal.length; - } + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + BI.each(this.buttons, function (val, item) { + if (!BI.isFunction(item.setSelected)) { + item.setValue(v); + return; + } + if (v.contains(val)) { + item.setSelected && item.setSelected(true); + } else { + item.setSelected && item.setSelected(false); + } + }); + }, - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; + setNotSelectedValue: function (v) { + v = BI.isArray(v) ? v : [v]; + BI.each(this.buttons, function (val, item) { + if (!BI.isFunction(item.setSelected)) { + item.setNotSelectedValue(v); + return; + } + if (v.contains(val)) { + item.setSelected && item.setSelected(false); + } else { + item.setSelected && item.setSelected(true); + } + }); + }, + + populate: function (items) { + var self = this; + var args = [].slice.call(arguments); + var linkHashMap = new BI.LinkHashMap(); + var val = function (item) { + return item.id || item.value; + }; + if (!this.buttons) { + this.buttons = {}; } - return resultTemp; - } - }, + // 所有已存在的和新添加的 + var willCreated = []; + BI.each(items, function (i, item) { + item = BI.stripEL(item); + if (self.buttons[val(item)]) { + var ob = self.buttons[val(item)]; + args[0] = item.items; + args[2] = item; + ob.populate && ob.populate.apply(ob, args); + } else { + willCreated.push(item); + } + }); + // 创建新元素 + args[0] = willCreated; + var newBtns = this._btnsCreator.apply(this, args); - _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 array = []; + BI.each(items, function (i, item) { + item = BI.stripEL(item); + var button = self.buttons[val(item)] || newBtns[val(item)]; + linkHashMap.add(val(item), button); + array.push(button); + }); + this.buttons = linkHashMap.map; - var decimalResult = (BI.parseInt(stringNumber1.numDecimal) + BI.parseInt(stringNumber2.numDecimal)).toString(); + BI.DOM.hang(this.buttons); + this.element.empty(); - if (decimalResult !== "0") { - if (decimalResult.length <= stringNumber1.numDecimal.length) { - decimalResult = addZero(decimalResult, stringNumber1.numDecimal.length); - } else { - integerResult++;// 进一 - decimalResult = decimalResult.slice(1); - } + var packages = this._packageItems(items, this._packageBtns(array)); + BI.createWidget(BI.extend({element: this}, this._packageLayout(packages))); + }, + + getIndexByValue: function () { + throw new Error("Can not use getIndexByValue"); } - var result = integerResult + "." + decimalResult; - return BI.parseFloat(result); + }); + BI.shortcut("bi.filter_list", FilterList); +}());/** + * 过滤条件 + * + * Created by GUY on 2015/9/25. + * @class BI.FilterOperation + * @extend BI.Widget + */ +!(function () { + var OPERATION_ADD_CONDITION = 0, OPERATION_ADD_ANDOR_CONDITION = 1; + var FilterOperation = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(FilterOperation.superclass._defaultConfig.apply(this, arguments), { + constants: { + FORMULA_COMBO: [{ + text: BI.i18nText("BI-Conf_Formula_And"), + value: BI.AbstractFilterItem.FILTER_OPERATION_FORMULA_AND + }, { + text: BI.i18nText("BI-Conf_Formula_Or"), + value: BI.AbstractFilterItem.FILTER_OPERATION_FORMULA_OR + }], + CONDITION_COMBO: [{ + text: BI.i18nText("BI-Conf_Condition_And"), + value: BI.AbstractFilterItem.FILTER_OPERATION_CONDITION_AND + }, { + text: BI.i18nText("BI-Conf_Condition_Or"), + value: BI.AbstractFilterItem.FILTER_OPERATION_CONDITION_OR + }] + } + }); + }, + + props: { + baseCls: "bi-filter-operation", + expander: {}, + items: [], + selections: [BI.AbstractFilterItem.FILTER_OPERATION_CONDITION, BI.AbstractFilterItem.FILTER_OPERATION_FORMULA], + itemsCreator: BI.emptyFn + }, - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; + render: function () { + var self = this, o = this.options; + this.currentSelected = null; + + return { + type: "bi.vtape", + items: [{ + el: { + type: "bi.tab", + showIndex: OPERATION_ADD_CONDITION, + cardCreator: BI.bind(this._createTabs, this), + ref: function (_ref) { + self.buttonComboTab = _ref; + } + }, + height: 40 + }, { + el: { + type: "bi.absolute", + scrollable: true, + items: [{ + el: { + type: "bi.left", + items: [{ + type: "bi.filter_pane", + expander: o.expander, + items: o.items, + itemsCreator: o.itemsCreator, + listeners: [{ + eventName: "EVENT_CHANGE", + action: function (type, value, obj) { + if (type === BI.Events.CLICK) { + if (BI.isNotNull(self.currentSelected) && self.currentSelected === obj) { + obj.setSelectedCondition(!obj.isSelectedCondition()); + } else { + if (BI.isNotNull(self.currentSelected)) { + self.currentSelected.setSelectedCondition(false); + } + self.currentSelected = obj; + obj.setSelectedCondition(true); + } + if (self.currentSelected.isSelectedCondition()) { + self.buttonComboTab.setSelect(OPERATION_ADD_ANDOR_CONDITION); + } else { + self.buttonComboTab.setSelect(OPERATION_ADD_CONDITION); + } + } + if (type === BI.Events.DESTROY) { + if (self.currentSelected === obj) { + self.currentSelected = null; + self.buttonComboTab.setSelect(OPERATION_ADD_CONDITION); + } + self.fireEvent("BI.FilterOperation.EVENT_DESTROY_ITEM", value, obj); + } + } + }], + ref: function (_ref) { + self.filter = _ref; + } + }] + }, + top: 0, + right: 2, + bottom: 0, + left: 0 + }] + } + }] + }; + }, + + _createTabs: function (v) { + var self = this; + switch (v) { + case OPERATION_ADD_CONDITION: + return { + type: "bi.button_group", + items: BI.createItems(self._createButtons(), { + type: "bi.icon_text_item", + height: 30, + width: 100 + }), + chooseType: BI.ButtonGroup.CHOOSE_TYPE_DEFAULT, + layouts: [{ + type: "bi.left", + vgap: 5 + }], + listeners: [{ + eventName: BI.ButtonGroup.EVENT_CHANGE, + action: function (value, obj) { + if (BI.isEmptyArray(self.filter.getValue())) { + self.filter.element.addClass("bi-border-top bi-border-left"); + } + self.fireEvent("EVENT_OPERATION", obj.getValue()); + self.defaultState(); + } + }] + }; + case OPERATION_ADD_ANDOR_CONDITION: + return { + type: "bi.button_group", + chooseType: BI.ButtonGroup.CHOOSE_TYPE_DEFAULT, + items: self._buildOperationButton(), + layouts: [{ + type: "bi.left", + vgap: 5 + }] + }; } - return resultTemp; - } - }, + }, - _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)); + _createButtons: function () { + var buttons = []; + BI.each(this.options.selections, function (i, type) { + switch (type) { + case BI.AbstractFilterItem.FILTER_OPERATION_FORMULA: + buttons.push({ + text: BI.i18nText("BI-Conf_Add_Formula"), + value: BI.AbstractFilterItem.FILTER_OPERATION_FORMULA, + cls: "operation-trigger filter-formula-font" + }); + break; + case BI.AbstractFilterItem.FILTER_OPERATION_CONDITION: + buttons.push({ + text: BI.i18nText("BI-Conf_Add_Condition"), + value: BI.AbstractFilterItem.FILTER_OPERATION_CONDITION, + cls: "operation-trigger filter-condition-font" + }); + break; + } + }); + return buttons; + }, - return this._accurateAddition(this._accurateAddition(this._accurateAddition(integerResult, dec1Int2), int1dec2), dec1dec2); - }, + _buildOperationButton: function () { + var self = this, combos = []; + BI.each(this.options.selections, function (i, type) { + var text = "", cls = "", items = []; + switch (type) { + case BI.AbstractFilterItem.FILTER_OPERATION_FORMULA: + text = BI.i18nText("BI-Conf_Add_Formula"); + cls = "filter-formula-font"; + items = self.options.constants.FORMULA_COMBO; + break; + case BI.AbstractFilterItem.FILTER_OPERATION_CONDITION: + default: + text = BI.i18nText("BI-Conf_Add_Condition"); + cls = "filter-condition-font"; + items = self.options.constants.CONDITION_COMBO; + break; + } - _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); + var trigger = BI.createWidget({ + type: "bi.icon_text_item", + cls: "operation-trigger " + cls, + text: text, + height: 30, + width: 100 + }); + combos.push({ + type: "bi.combo", + el: trigger, + popup: { + el: { + type: "bi.button_group", + chooseType: BI.ButtonGroup.CHOOSE_TYPE_NONE, + items: BI.createItems(items, { + type: "bi.single_select_item", + height: 25 + }), + layouts: [{ + type: "bi.vertical" + }] + } + }, + listeners: [{ + eventName: BI.Combo.EVENT_CHANGE, + action: function (value, obj) { + if (BI.isEmptyArray(self.filter.getValue())) { + self.filter.element.addClass("bi-border-top bi-border-left"); + } - function addZero (resultTemp, length) { - var diff = length - resultTemp.length; - for (var i = 0; i < diff; i++) { - resultTemp = "0" + resultTemp; - } - return resultTemp; - } - }, + switch (value) { + case BI.AbstractFilterItem.FILTER_OPERATION_CONDITION_AND: + case BI.AbstractFilterItem.FILTER_OPERATION_CONDITION_OR: + trigger.setText(BI.i18nText("BI-Conf_Add_Condition")); + break; + case BI.AbstractFilterItem.FILTER_OPERATION_FORMULA_AND: + case BI.AbstractFilterItem.FILTER_OPERATION_FORMULA_OR: + trigger.setText(BI.i18nText("BI-Conf_Add_Formula")); + break; + default: + trigger.setText(); + } + self.fireEvent("EVENT_OPERATION", obj.getValue()); + self.defaultState(); + this.hideView(); + } + }] + }); + }); + return combos; + }, - accurateSubtraction: function (num1, num2) { - if (num1 >= 0 && num2 >= 0) { - if (num1 >= num2) { - return this._accurateSubtraction(num1, num2); + defaultState: function () { + if (BI.isNotNull(this.currentSelected)) { + this.currentSelected.setSelectedCondition(false); } - 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.buttonComboTab.setSelect(OPERATION_ADD_CONDITION); + }, + + getCurrentSelectItem: function () { + if (BI.isNotNull(this.currentSelected) && this.currentSelected.isSelectedCondition()) { + return this.currentSelected; } - return this._accurateSubtraction(-num1, -num2); - } - }, + }, - 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); - } - }, + populate: function (items) { + this.filter.populate.apply(this.filter, arguments); + }, - 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.filter.getValue(); } - }, + }); + BI.shortcut("bi.filter_operation", FilterOperation); +}()); +/** + * @class BI.FilterPane + * @extend BI.Widget + * 过滤面板 + */ +!(function () { + var FilterPane = BI.inherit(BI.Widget, { + props: { + baseCls: "bi-filter-pane", + expander: {}, + items: [], + itemsCreator: BI.emptyFn + }, - accurateDivisionTenExponent: function (num1, n) { - if (num1 >= 0) { - return this._accurateDivisionTenExponent(num1, n); + render: function () { + var self = this, o = this.options; + return { + type: "bi.custom_tree", + cls: BI.isNotEmptyArray(o.items) ? "bi-border-top bi-border-left" : "", + expander: BI.extend({ + type: "bi.filter_expander", + el: {}, + popup: { + type: "bi.custom_tree" + } + }, o.expander), + el: { + type: "bi.filter_list", + chooseType: BI.ButtonGroup.CHOOSE_TYPE_DEFAULT, + layouts: [{ + type: "bi.vertical", + scrolly: false + }] + }, + items: o.items, + listeners: [{ + eventName: BI.Controller.EVENT_CHANGE, + action: function () { + self.fireEvent("EVENT_CHANGE", arguments); + } + }], + ref: function (_ref) { + self.tree = _ref; + } + }; + }, + + populate: function (items) { + if (BI.isNotEmptyArray(items)) { + this.element.addClass("bi-border-top bi-border-left"); + } else { + this.element.removeClass("bi-border-top bi-border-left"); + } + this.tree.populate.apply(this.tree, arguments); + }, + + getValue: function () { + return this.tree.getValue(); } - return -this._accurateDivisionTenExponent(-num1, n); - } -});/** - * 月份下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.MonthCombo - * @extends BI.Trigger + }); + BI.shortcut("bi.filter_pane", FilterPane); +}());/** + * Created by zcf on 2016/9/26. */ -BI.MonthCombo = BI.inherit(BI.Widget, { +BI.IntervalSlider = BI.inherit(BI.Widget, { + _constant: { + EDITOR_WIDTH: 58, + EDITOR_R_GAP: 60, + EDITOR_HEIGHT: 30, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, + _defaultConfig: function () { - return BI.extend(BI.MonthCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-month-combo", - behaviors: {}, - height: 25 + return BI.extend(BI.IntervalSlider.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-interval-slider bi-slider-track", + digit: false, + unit: "" }); }, + _init: function () { - BI.MonthCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.IntervalSlider.superclass._init.apply(this, arguments); - this.trigger = BI.createWidget({ - type: "bi.month_trigger", - value: o.value + var self = this; + var c = this._constant; + this.enable = false; + this.valueOne = ""; + this.valueTwo = ""; + this.calculation = new BI.AccurateCalculationModel(); + + // this.backgroundTrack = BI.createWidget({ + // type: "bi.layout", + // cls: "background-track", + // height: c.TRACK_HEIGHT + // }); + this.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 }); + this.blueTrack = BI.createWidget({ + type: "bi.layout", + cls: "blue-track bi-high-light-background", + height: 6 + }); + this.track = this._createTrackWrapper(); - this.trigger.on(BI.MonthTrigger.EVENT_CONFIRM, function (v) { - if (self.combo.isViewVisible()) { - return; - } - if (this.getKey() && this.getKey() !== self.storeValue) { - self.setValue(this.getValue()); - } else if (!this.getKey()) { - self.setValue(); + 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); } - self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); }); - this.trigger.on(BI.MonthTrigger.EVENT_FOCUS, function () { - self.storeValue = this.getKey(); + this.labelOne.element.hover(function () { + self.labelOne.element.removeClass("bi-border").addClass("bi-border"); + }, function () { + self.labelOne.element.removeClass("bi-border"); }); - this.trigger.on(BI.MonthTrigger.EVENT_START, function () { - self.combo.hideView(); + 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.trigger.on(BI.MonthTrigger.EVENT_STOP, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); + + 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.popup = BI.createWidget({ - type: "bi.month_popup", - behaviors: o.behaviors, - value: o.value + this.labelTwo.element.hover(function () { + self.labelTwo.element.removeClass("bi-border").addClass("bi-border"); + }, function () { + self.labelTwo.element.removeClass("bi-border"); }); - this.popup.on(BI.MonthPopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); - self.fireEvent(BI.MonthCombo.EVENT_CONFIRM); + 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.combo = BI.createWidget({ - type: "bi.combo", - element: this, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, - el: this.trigger, - popup: { - minWidth: 85, - el: this.popup - } + this.sliderOne = BI.createWidget({ + type: "bi.single_slider_button" }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW); + this.sliderTwo = BI.createWidget({ + type: "bi.single_slider_button" }); - }, + this._draggable(this.sliderOne, true); + this._draggable(this.sliderTwo, false); + this._setVisible(false); - setValue: function (v) { - this.trigger.setValue(v); - this.popup.setValue(v); + 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() + ] + }); }, - getValue: function () { - if (BI.isNull(this.popup)) { - return this.options.value || ""; - } else { - return this.popup.getValue() || ""; + _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(); + }, -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, { + _rePosBySizeAfterStop: function (size, isLeft) { + var percent = size * 100 / (this._getGrayTrackLength()); + var significantPercent = BI.parseFloat(percent.toFixed(1)); + isLeft ? this._setSliderOnePosition(significantPercent) : this._setSliderTwoPosition(significantPercent); + }, - _defaultConfig: function () { - return BI.extend(BI.MonthPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-month-popup", - behaviors: {} + _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()); + } }, - _init: function () { - BI.MonthPopup.superclass._init.apply(this, arguments); - var self = this, o = this.options; + _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%" + }; + }, - // 纵向排列月 - 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 - }; - }); - }); + _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%" + }; + }, - 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; }, - getValue: function () { - return this.month.getValue()[0]; + _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}); + } + } }, - 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") + _setLabelOnePosition: function (percent) { + this.labelOne.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 - }); + _setLabelTwoPosition: function (percent) { + this.labelTwo.element.css({left: percent + "%"}); + this._checkOverlap(); }, - _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); + + _setSliderOnePosition: function (percent) { + this.sliderOne.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; + + _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, - maxHeight: this.constants.popupHeight, - 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", - width: 268, - height: 260 + 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-multidate-popup-tab 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 }, _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: BI.i18nText("BI-Month_Trigger_Error_Text") }); - 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, { @@ -92400,7 +95621,9 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, { var changedValue = value; if (BI.isNotNull(self.childValueMap[value])) { changedValue = self.childValueMap[value]; - self.fireEvent(BI.MultiLayerDownListPopup.EVENT_SON_VALUE_CHANGE, changedValue, self.fatherValueMap[value]); + var fatherValue = self.fatherValueMap[value]; + var fatherArrayValue = (fatherValue + "").split("_"); + self.fireEvent(BI.MultiLayerDownListPopup.EVENT_SON_VALUE_CHANGE, changedValue, fatherArrayValue.length > 1 ? fatherArrayValue : fatherValue); } else { self.fireEvent(BI.MultiLayerDownListPopup.EVENT_CHANGE, changedValue, object); } @@ -92660,7 +95883,8 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, { if (BI.isNotNull(self.childValueMap[value])) { var fartherValue = self.fatherValueMap[value]; valueItem.childValue = self.childValueMap[value]; - valueItem.value = fartherValue.split("_"); + var fatherArrayValue = (fartherValue + "").split("_"); + valueItem.value = fatherArrayValue.length > 1 ? fatherArrayValue : fartherValue; } else { valueItem.value = value; } @@ -92819,7 +96043,7 @@ BI.MultiLayerSelectLevelTree = BI.inherit(BI.Widget, { this._assertId(nodes); this.tree = BI.createWidget({ type: "bi.custom_tree", - element: this, + cls: "tree-view display-inline", expander: { type: "bi.select_tree_expander", isDefaultInit: o.isDefaultInit, @@ -92847,6 +96071,13 @@ BI.MultiLayerSelectLevelTree = BI.inherit(BI.Widget, { self.fireEvent(BI.MultiLayerSelectLevelTree.EVENT_CHANGE, arguments); } }); + + BI.createWidget({ + type: "bi.adaptive", + element: this, + scrollable: true, + items: [this.tree] + }) }, populate: function (nodes) { @@ -93253,6 +96484,7 @@ BI.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, { this.popup = BI.createWidget({ type: "bi.multilayer_single_tree_popup", isDefaultInit: o.isDefaultInit, + itemsCreator: o.itemsCreator, items: o.items, value: o.value }); @@ -93366,7 +96598,7 @@ BI.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { this._assertId(nodes); this.tree = BI.createWidget({ type: "bi.custom_tree", - element: this, + cls: "tree-view display-inline", expander: { isDefaultInit: o.isDefaultInit, el: {}, @@ -93397,6 +96629,13 @@ BI.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { self.fireEvent(BI.MultiLayerSingleLevelTree.EVENT_CHANGE, v); } }); + + BI.createWidget({ + type: "bi.adaptive", + element: this, + scrollable: true, + items: [this.tree] + }) }, populate: function (nodes) { @@ -93408,7 +96647,10 @@ BI.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { }, getValue: function () { - return BI.uniq(this.tree.getValue()); + return BI.filter(BI.uniq(this.tree.getValue()), function (idx, value) { + return BI.isNotNull(value); + }); + }, getAllLeaves: function () { @@ -93528,7 +96770,8 @@ BI.MultiLayerSingleTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.node.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) {// 本身实现click功能 @@ -93611,7 +96854,8 @@ BI.MultiLayerSingleTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.node.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) {// 本身实现click功能 @@ -93694,7 +96938,8 @@ BI.MultiLayerSingleTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.node.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) {// 本身实现click功能 @@ -93776,7 +97021,8 @@ BI.MultiLayerSingleTreeFirstTreeLeafItem = BI.inherit(BI.BasicButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.item.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) {// 本身实现click功能 @@ -93803,14 +97049,6 @@ BI.MultiLayerSingleTreeFirstTreeLeafItem = BI.inherit(BI.BasicButton, { }); }, - doRedMark: function () { - this.item.doRedMark.apply(this.item, arguments); - }, - - unRedMark: function () { - this.item.unRedMark.apply(this.item, arguments); - }, - doHighLight: function () { this.item.doHighLight.apply(this.item, arguments); }, @@ -93872,7 +97110,8 @@ BI.MultiLayerSingleTreeLastTreeLeafItem = BI.inherit(BI.BasicButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.item.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) {// 本身实现click功能 @@ -93899,14 +97138,6 @@ BI.MultiLayerSingleTreeLastTreeLeafItem = BI.inherit(BI.BasicButton, { }); }, - doRedMark: function () { - this.item.doRedMark.apply(this.item, arguments); - }, - - unRedMark: function () { - this.item.unRedMark.apply(this.item, arguments); - }, - doHighLight: function () { this.item.doHighLight.apply(this.item, arguments); }, @@ -93968,7 +97199,8 @@ BI.MultiLayerSingleTreeMidTreeLeafItem = BI.inherit(BI.BasicButton, { hgap: o.hgap, text: o.text, value: o.value, - py: o.py + py: o.py, + keyword: o.keyword }); this.item.on(BI.Controller.EVENT_CHANGE, function (type) { if (type === BI.Events.CLICK) {// 本身实现click功能 @@ -93995,14 +97227,6 @@ BI.MultiLayerSingleTreeMidTreeLeafItem = BI.inherit(BI.BasicButton, { }); }, - doRedMark: function () { - this.item.doRedMark.apply(this.item, arguments); - }, - - unRedMark: function () { - this.item.unRedMark.apply(this.item, arguments); - }, - doHighLight: function () { this.item.doHighLight.apply(this.item, arguments); }, @@ -94247,7 +97471,7 @@ BI.MultiSelectInsertCombo = BI.inherit(BI.Single, { self.trigger.getSearcher().setState(self.storeValue); self.trigger.getCounter().setButtonChecked(self.storeValue); }; - this.storeValue = {}; + this.storeValue = o.value || {}; // 标记正在请求数据 this.requesting = false; @@ -94402,7 +97626,364 @@ BI.MultiSelectInsertCombo = BI.inherit(BI.Single, { if (self.requesting === true) { self.wants2Quit = true; } else { - self.fireEvent(BI.MultiSelectInsertCombo.EVENT_CONFIRM); + self.fireEvent(BI.MultiSelectInsertCombo.EVENT_CONFIRM); + } + }); + + 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 + }, { + el: triggerBtn, + right: 0, + top: 0, + bottom: 0 + }] + }); + }, + + _defaultState: function () { + this.trigger.stopEditing(); + this.combo.hideView(); + }, + + _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); + this.requesting = true; + o.itemsCreator({ + type: BI.MultiSelectInsertCombo.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[self.storeValue.type === BI.Selection.Multi ? "pushDistinct" : "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.MultiSelectInsertCombo.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; + adjust(); + callback(); + function adjust () { + if (self.wants2Quit === true) { + self.fireEvent(BI.MultiSelectInsertCombo.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 BI.deepClone(this.storeValue); + }, + + populate: function () { + this.combo.populate.apply(this.combo, arguments); + } +}); + +BI.extend(BI.MultiSelectInsertCombo, { + REQ_GET_DATA_LENGTH: 1, + REQ_GET_ALL_DATA: -1 +}); + +BI.MultiSelectInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; + +BI.shortcut("bi.multi_select_insert_combo", BI.MultiSelectInsertCombo);/** + * + * @class BI.MultiSelectCombo + * @extends BI.Single + */ +BI.MultiSelectCombo = BI.inherit(BI.Single, { + + _defaultConfig: function () { + return BI.extend(BI.MultiSelectCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-combo", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + height: 28 + }); + }, + + _init: function () { + BI.MultiSelectCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; + + var assertShowValue = function () { + BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); + self.trigger.getSearcher().setState(self.storeValue); + self.trigger.getCounter().setButtonChecked(self.storeValue); + }; + this.storeValue = o.value || {}; + + this._assertValue(this.storeValue); + + // 标记正在请求数据 + this.requesting = false; + + this.trigger = BI.createWidget({ + type: "bi.multi_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(BI.deepClone(self.getValue())); + } + callback.apply(self, arguments); + }); + }, + value: this.storeValue + }); + + this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { + self._setStartValue(""); + this.getSearcher().setValue(self.storeValue); + }); + this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { + self._setStartValue(""); + }); + this.trigger.on(BI.MultiSelectTrigger.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.MultiSelectTrigger.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.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) { + if (obj instanceof BI.MultiSelectBar) { + self._joinAll(this.getValue(), function () { + assertShowValue(); + }); + } else { + self._join(this.getValue(), function () { + assertShowValue(); + }); + } + }); + this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { + this.getCounter().setValue(self.storeValue); + }); + this.trigger.on(BI.MultiSelectTrigger.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.multi_select_popup_view", + ref: function () { + self.popup = this; + self.trigger.setAdapter(this); + }, + listeners: [{ + eventName: BI.MultiSelectPopupView.EVENT_CHANGE, + action: function () { + self.storeValue = this.getValue(); + self._adjust(function () { + assertShowValue(); + }); + } + }, { + eventName: BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM, + action: function () { + self._defaultState(); + } + }, { + eventName: BI.MultiSelectPopupView.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.getCounter().adjustView(); + self.trigger.getSearcher().adjustView(); + }); + } + }, + value: o.value, + 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.MultiSelectCombo.EVENT_CONFIRM); } }); @@ -94458,7 +98039,7 @@ BI.MultiSelectInsertCombo = BI.inherit(BI.Single, { this._assertValue(this.storeValue); this.requesting = true; o.itemsCreator({ - type: BI.MultiSelectInsertCombo.REQ_GET_ALL_DATA, + type: BI.MultiSelectCombo.REQ_GET_ALL_DATA, keywords: keywords }, function (ob) { var values = BI.map(ob.items, "value"); @@ -94481,7 +98062,7 @@ BI.MultiSelectInsertCombo = BI.inherit(BI.Single, { this._assertValue(res); this.requesting = true; o.itemsCreator({ - type: BI.MultiSelectInsertCombo.REQ_GET_ALL_DATA, + type: BI.MultiSelectCombo.REQ_GET_ALL_DATA, keywords: [this.trigger.getKey()] }, function (ob) { var items = BI.map(ob.items, "value"); @@ -94516,11 +98097,34 @@ BI.MultiSelectInsertCombo = BI.inherit(BI.Single, { _adjust: function (callback) { var self = this, o = this.options; - adjust(); - callback(); + if (!this._count) { + o.itemsCreator({ + type: BI.MultiSelectCombo.REQ_GET_DATA_LENGTH + }, function (res) { + self._count = res.count; + adjust(); + callback(); + }); + } else { + adjust(); + callback(); + + } + 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: [] + }; + } if (self.wants2Quit === true) { - self.fireEvent(BI.MultiSelectInsertCombo.EVENT_CONFIRM); + self.fireEvent(BI.MultiSelectCombo.EVENT_CONFIRM); self.wants2Quit = false; } self.requesting = false; @@ -94569,436 +98173,468 @@ BI.MultiSelectInsertCombo = BI.inherit(BI.Single, { }, populate: function () { + this._count = null; this.combo.populate.apply(this.combo, arguments); } }); -BI.extend(BI.MultiSelectInsertCombo, { - REQ_GET_DATA_LENGTH: 0, +BI.extend(BI.MultiSelectCombo, { + REQ_GET_DATA_LENGTH: 1, REQ_GET_ALL_DATA: -1 }); -BI.MultiSelectInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.MultiSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.shortcut("bi.multi_select_insert_combo", BI.MultiSelectInsertCombo);/** - * - * @class BI.MultiSelectCombo - * @extends BI.Single +BI.shortcut("bi.multi_select_combo", BI.MultiSelectCombo);/** + * 多选加载数据面板 + * Created by guy on 15/11/2. + * @class BI.MultiSelectLoader + * @extends Widget */ -BI.MultiSelectCombo = BI.inherit(BI.Single, { +BI.MultiSelectLoader = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-combo", - itemsCreator: BI.emptyFn, + return BI.extend(BI.MultiSelectLoader.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-loader", + logic: { + dynamic: true + }, + el: { + height: 400 + }, valueFormatter: BI.emptyFn, - height: 28 + itemsCreator: BI.emptyFn, + onLoaded: BI.emptyFn }); }, _init: function () { - BI.MultiSelectCombo.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.MultiSelectLoader.superclass._init.apply(this, arguments); - var assertShowValue = function () { - BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); - self.trigger.getSearcher().setState(self.storeValue); - self.trigger.getCounter().setButtonChecked(self.storeValue); - }; - this.storeValue = o.value || {}; - + var self = this, opts = this.options; + var hasNext = false; + + this.storeValue = opts.value || {}; this._assertValue(this.storeValue); - - // 标记正在请求数据 - this.requesting = false; - this.trigger = BI.createWidget({ - type: "bi.multi_select_trigger", - height: o.height, - // adapter: this.popup, - masker: { - offset: { - left: 1, - top: 1, - right: 2, - bottom: 33 + 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" + }] + } } - }, - valueFormatter: o.valueFormatter, + }, opts.el), itemsCreator: function (op, callback) { - o.itemsCreator(op, function (res) { - if (op.times === 1 && BI.isNotNull(op.keywords)) { - // 预防trigger内部把当前的storeValue改掉 - self.trigger.setValue(BI.deepClone(self.getValue())); + 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.apply(self, arguments); + 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.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { - self._setStartValue(""); - this.getSearcher().setValue(self.storeValue); - }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { - self._setStartValue(""); - }); - this.trigger.on(BI.MultiSelectTrigger.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.button_group.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.trigger.on(BI.MultiSelectTrigger.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.button_group.on(BI.SelectList.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectLoader.EVENT_CHANGE, arguments); }); + }, - this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) { - if (obj instanceof BI.MultiSelectBar) { - self._joinAll(this.getValue(), function () { - assertShowValue(); - }); - } else { - self._join(this.getValue(), function () { - assertShowValue(); - }); - } + _createItems: function (items) { + return BI.createItems(items, { + type: "bi.multi_select_item", + logic: this.options.logic, + height: 25, + selected: this.isAllSelected() }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { - this.getCounter().setValue(self.storeValue); + }, + + _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 }); - this.trigger.on(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } + }, + + _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.combo = BI.createWidget({ - type: "bi.combo", - toggle: false, - el: this.trigger, - adjustLength: 1, - popup: { - type: "bi.multi_select_popup_view", - ref: function () { - self.popup = this; - self.trigger.setAdapter(this); - }, - listeners: [{ - eventName: BI.MultiSelectPopupView.EVENT_CHANGE, - action: function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - }); - } - }, { - eventName: BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM, - action: function () { - self._defaultState(); - } - }, { - eventName: BI.MultiSelectPopupView.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.getCounter().adjustView(); - self.trigger.getSearcher().adjustView(); - }); - } - }, - value: o.value, - hideChecker: function (e) { - return triggerBtn.element.find(e.target).length === 0; - } + 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.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - this.setValue(self.storeValue); - BI.nextTick(function () { - self.populate(); - }); + this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectPopupView.EVENT_CHANGE); }); - // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 - 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.MultiSelectCombo.EVENT_CONFIRM); + 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; } }); + }, - var triggerBtn = BI.createWidget({ - type: "bi.trigger_icon_button", - width: o.height, + 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, - cls: "multi-select-trigger-icon-button" + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, + popup: {}, + adapter: o.adapter, + masker: o.masker, + value: o.value }); - triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { - self.trigger.getCounter().hideView(); - if (self.combo.isViewVisible()) { - self.combo.hideView(); - } else { - self.combo.showView(); - } + 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); }); - BI.createWidget({ - type: "bi.absolute", - element: this, + + var wrapNumberCounter = BI.createWidget({ + type: "bi.right_vertical_adapt", + hgap: 4, items: [{ - el: this.combo, - left: 0, - right: 0, - top: 0, - bottom: 0 - }, { - el: triggerBtn, - right: 0, - top: 0, - bottom: 0 + el: this.numberCounter }] }); - }, - - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); - }, - - _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); - this.requesting = true; - o.itemsCreator({ - type: BI.MultiSelectCombo.REQ_GET_ALL_DATA, - keywords: keywords - }, function (ob) { - var values = BI.map(ob.items, "value"); - digest(values); + var wrapper = BI.createWidget({ + type: "bi.htape", + element: this, + items: [ + { + el: this.searcher, + width: "fill" + }, { + el: wrapNumberCounter, + width: 0 + }, { + el: BI.createWidget(), + width: 30 + }] }); - 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); - } + 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(); }); - self._adjust(callback); - } - }, + }); - _joinAll: function (res, callback) { - var self = this, o = this.options; - this._assertValue(res); - this.requesting = true; - o.itemsCreator({ - type: BI.MultiSelectCombo.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; + this.element.click(function (e) { + if (self.element.__isMouseInBounds__(e) && !self.numberCounter.element.__isMouseInBounds__(e)) { + self.numberCounter.hideView(); } - 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.MultiSelectCombo.REQ_GET_DATA_LENGTH - }, function (res) { - self._count = res.count; - adjust(); - callback(); - }); - } else { - adjust(); - callback(); - - } + getCounter: function () { + return this.numberCounter; + }, - 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: [] - }; - } - if (self.wants2Quit === true) { - self.fireEvent(BI.MultiSelectCombo.EVENT_CONFIRM); - self.wants2Quit = false; - } - self.requesting = false; - } + getSearcher: function () { + return this.searcher; }, - _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); + stopEditing: function () { + this.searcher.stopSearch(); + this.numberCounter.hideView(); }, - _setStartValue: function (value) { - this._startValue = value; - this.popup.setStartValue(value); + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + this.numberCounter.setAdapter(adapter); }, - setValue: function (v) { - this.storeValue = v || {}; - this._assertValue(this.storeValue); - this.combo.setValue(this.storeValue); + setValue: function (ob) { + this.searcher.setValue(ob); + this.numberCounter.setValue(ob); }, - getValue: function () { - return BI.deepClone(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.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, @@ -95018,92 +98654,80 @@ 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(); }, - _assertValue: function (val) { - val || (val = {}); - val.type || (val.type = BI.Selection.Multi); - val.value || (val.value = []); - }, - - setStartValue: function (v) { - this._startValue = v; + _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) { - this.storeValue = v || {}; - this._assertValue(this.storeValue); - this.button_group.setValue(this.storeValue); + // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = BI.deepClone(v); + this.button_group.setValue(v); }, getValue: function () { @@ -95122,1096 +98746,1301 @@ BI.MultiSelectLoader = BI.inherit(BI.Widget, { this.button_group.populate.apply(this.button_group, arguments); }, - resetHeight: function (h) { - this.button_group.resetHeight(h); - }, + 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, { + + _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(BI.i18nText("BI-Check_Selected")); + }, 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 () { - 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 +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.MultiSelectPopupView = BI.inherit(BI.Widget, { +BI.MultiSelectEditor = 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 + return BI.extend(BI.MultiSelectEditor.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-editor", + el: {} }); }, _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 + 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.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.editor.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectPopupView.EVENT_CHANGE); + this.editor.on(BI.StateEditor.EVENT_PAUSE, function () { + self.fireEvent(BI.MultiSelectEditor.EVENT_PAUSE); }); - 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.editor.on(BI.StateEditor.EVENT_CLICK_LABEL, function () { + }); }, - isAllSelected: function () { - return this.loader.isAllSelected(); + focus: function () { + this.editor.focus(); }, - setStartValue: function (v) { - this.loader.setStartValue(v); + blur: function () { + this.editor.blur(); + }, + + setState: function (state) { + this.editor.setState(state); }, setValue: function (v) { - this.popupView.setValue(v); + this.editor.setValue(v); }, getValue: function () { - return this.popupView.getValue(); - }, + var v = this.editor.getState(); + if (BI.isArray(v) && v.length > 0) { + return v[v.length - 1]; + } + return ""; - populate: function (items) { - this.popupView.populate.apply(this.popupView, arguments); }, - resetHeight: function (h) { - this.popupView.resetHeight(h); + getKeywords: function () { + var val = this.editor.getLastValidValue(); + var keywords = val.match(/[\S]+/g); + if (BI.isEndWithBlank(val)) { + return keywords.concat([" "]); + } + return keywords; }, - resetWidth: function (w) { - this.popupView.resetWidth(w); + populate: function (items) { + } }); - -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.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.MultiSelectTrigger = BI.inherit(BI.Trigger, { - - constants: { - height: 14, - rgap: 4, - lgap: 4 - }, +BI.MultiSelectSearcher = 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.MultiSelectSearcher.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-searcher", itemsCreator: BI.emptyFn, + el: {}, + popup: {}, valueFormatter: BI.emptyFn, - searcher: {}, - switcher: {}, - adapter: null, masker: {} }); }, _init: function () { - BI.MultiSelectTrigger.superclass._init.apply(this, arguments); - + BI.MultiSelectSearcher.superclass._init.apply(this, arguments); var self = this, o = this.options; - if (o.height) { - this.setHeight(o.height - 2); - } + this.editor = BI.createWidget(o.el, { + type: "bi.multi_select_editor", + height: o.height + }); - this.searcher = BI.createWidget(o.searcher, { - type: "bi.multi_select_searcher", + this.searcher = BI.createWidget({ + type: "bi.searcher", + element: this, height: o.height, - itemsCreator: o.itemsCreator, - valueFormatter: o.valueFormatter, - popup: {}, + 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) { + var keyword = self.editor.getValue(); + op.keywords = [keyword]; + this.setKeyword(keyword); + o.itemsCreator(op, callback); + }, + value: o.value + }, o.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); + masker: o.masker }); - this.searcher.on(BI.MultiSelectSearcher.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_CHANGE, arguments); + this.searcher.on(BI.Searcher.EVENT_START, function () { + self.fireEvent(BI.MultiSelectSearcher.EVENT_START); }); - 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.searcher.on(BI.Searcher.EVENT_PAUSE, function () { + if (this.hasMatched()) { + + } + self.fireEvent(BI.MultiSelectSearcher.EVENT_PAUSE); }); - this.numberCounter.on(BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK); + this.searcher.on(BI.Searcher.EVENT_STOP, function () { + self.fireEvent(BI.MultiSelectSearcher.EVENT_STOP); }); - this.numberCounter.on(BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW); + this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectSearcher.EVENT_CHANGE, arguments); }); - - var wrapNumberCounter = BI.createWidget({ - type: "bi.right_vertical_adapt", - hgap: 4, - items: [{ - el: this.numberCounter - }] + 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); + } + }, - var wrapper = BI.createWidget({ - type: "bi.htape", - element: this, - items: [ - { - el: this.searcher, - width: "fill" - }, { - el: wrapNumberCounter, - width: 0 - }, { - el: BI.createWidget(), - width: 30 - }] - }); + adjustView: function () { + this.searcher.adjustView(); + }, - 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(); - }); - }); + isSearching: function () { + return this.searcher.isSearching(); + }, - this.element.click(function (e) { - if (self.element.__isMouseInBounds__(e) && !self.numberCounter.element.__isMouseInBounds__(e)) { - self.numberCounter.hideView(); - } - }); + stopSearch: function () { + this.searcher.stopSearch(); }, - getCounter: function () { - return this.numberCounter; + getKeyword: function () { + return this.editor.getValue(); }, - getSearcher: function () { - return this.searcher; + hasMatched: function () { + return this.searcher.hasMatched(); }, - stopEditing: function () { - this.searcher.stopSearch(); - this.numberCounter.hideView(); + hasChecked: function () { + return this.searcher.getView() && this.searcher.getView().hasChecked(); }, setAdapter: function (adapter) { this.searcher.setAdapter(adapter); - this.numberCounter.setAdapter(adapter); + }, + + 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); + } + } }, setValue: function (ob) { + this.setState(ob); this.searcher.setValue(ob); - this.numberCounter.setValue(ob); }, getKey: function () { - return this.searcher.getKey(); + return this.editor.getValue(); }, getValue: function () { return this.searcher.getValue(); + }, + + populate: function (items) { + this.searcher.populate.apply(this.searcher, 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.shortcut("bi.multi_select_trigger", BI.MultiSelectTrigger);/** - * 多选加载数据搜索loader面板 - * Created by guy on 15/11/4. - * @class BI.MultiSelectSearchLoader +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.MultiSelectSearchLoader = BI.inherit(BI.Widget, { +BI.MultiSelectCheckSelectedSwitcher = 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.MultiSelectCheckSelectedSwitcher.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-check-selected-switcher", itemsCreator: BI.emptyFn, - keywordGetter: BI.emptyFn, - valueFormatter: BI.emptyFn + valueFormatter: BI.emptyFn, + el: {}, + popup: {}, + adapter: null, + masker: {} }); }, _init: function () { - BI.MultiSelectSearchLoader.superclass._init.apply(this, arguments); + BI.MultiSelectCheckSelectedSwitcher.superclass._init.apply(this, arguments); + var self = this, o = this.options; - var self = this, opts = this.options; - var hasNext = false; - this.storeValue = BI.deepClone(opts.value); - this.button_group = BI.createWidget({ - type: "bi.select_list", + this.button = BI.createWidget(o.el, { + type: "bi.multi_select_check_selected_button", + itemsCreator: o.itemsCreator, + value: o.value + }); + this.button.on(BI.Events.VIEW, function () { + self.fireEvent(BI.Events.VIEW, arguments); + }); + this.switcher = BI.createWidget({ + type: "bi.switcher", + toggle: false, element: this, - 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" - }] - } - } - }, - 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; - } + 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.button_group.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.switcher.on(BI.Switcher.EVENT_TRIGGER_CHANGE, function () { + self.fireEvent(BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE); }); - this.button_group.on(BI.SelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiSelectSearchLoader.EVENT_CHANGE, arguments); + this.switcher.on(BI.Switcher.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW); }); - }, - - _createItems: function (items) { - return BI.createItems(items, { - type: "bi.multi_select_item", - logic: { - dynamic: false - }, - height: 25, - selected: this.isAllSelected() + this.switcher.on(BI.Switcher.EVENT_AFTER_POPUPVIEW, function () { + var me = this; + BI.nextTick(function () { + me.populate(); + }); }); - }, - - 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 - }; + this.switcher.element.click(function (e) { + e.stopPropagation(); }); }, - setValue: function (v) { - // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 - this.storeValue = BI.deepClone(v); - this.button_group.setValue(v); + adjustView: function () { + this.switcher.adjustView(); }, - getValue: function () { - return this.button_group.getValue(); + hideView: function () { + this.switcher.empty(); + this.switcher.hideView(); }, - getAllButtons: function () { - return this.button_group.getAllButtons(); + setAdapter: function (adapter) { + this.switcher.setAdapter(adapter); }, - empty: function () { - this.button_group.empty(); + setValue: function (v) { + this.switcher.setValue(v); }, - populate: function (items) { - this.button_group.populate.apply(this.button_group, arguments); + setButtonChecked: function (v) { + this.button.setValue(v); }, - resetHeight: function (h) { - this.button_group.resetHeight(h); + getValue: function () { + }, - resetWidth: function (w) { - this.button_group.resetWidth(w); + populate: function (items) { + this.switcher.populate.apply(this.switcher, arguments); } }); -BI.MultiSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.multi_select_search_loader", BI.MultiSelectSearchLoader);/** - * - * 在搜索框中输入文本弹出的面板 - * @class BI.MultiSelectSearchPane - * @extends Widget +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.MultiSelectSearchPane = BI.inherit(BI.Widget, { - - constants: { - height: 25, - lgap: 10, - tgap: 5 - }, - +BI.MultiSelectInsertList = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectSearchPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-search-pane bi-card", + return BI.extend(BI.MultiSelectInsertList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-insert-list", itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn, - keywordGetter: BI.emptyFn + valueFormatter: BI.emptyFn }); }, - _init: function () { - BI.MultiSelectSearchPane.superclass._init.apply(this, arguments); + BI.MultiSelectInsertList.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.storeValue = o.value || {}; - 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 + 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 + }, + // onLoaded: o.onLoaded, + el: {}, + value: o.value + }); + this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { + self.storeValue = this.getValue(); + assertShowValue(); + self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); }); - this.loader = BI.createWidget({ - type: "bi.multi_select_search_loader", - keywordGetter: o.keywordGetter, + 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) { - o.itemsCreator.apply(self, [op, function (res) { - callback(res); - self.setKeyword(o.keywordGetter()); - }]); + op.keyword = self.trigger.getKeyword(); + this.setKeyword(op.keyword); + o.itemsCreator(op, callback); + } + }); + 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.getKeywords(); + 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); + }); + } + } + }], value: o.value }); - this.loader.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - this.resizer = BI.createWidget({ + BI.createWidget({ type: "bi.vtape", element: this, items: [{ - el: this.tooltipClick, - height: 0 + el: this.trigger, + height: 24 }, { - el: this.loader + el: this.adapter, + height: "fill" + }] + }); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 }] }); - 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); + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); }, - getValue: function () { - return this.loader.getValue(); + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); }, - empty: function () { - this.loader.empty(); + _defaultState: function () { + this.trigger.stopEditing(); }, - 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") + _assertValue: function (val) { + val || (val = {}); + val.type || (val.type = BI.Selection.Multi); + val.value || (val.value = []); }, - _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 - }); + _makeMap: function (values) { + return BI.makeObject(values || []); }, - _init: function () { - BI.MultiSelectCheckSelectedButton.superclass._init.apply(this, arguments); + _joinKeywords: function (keywords, callback) { 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._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.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); + 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(); } }, - setValue: function (ob) { + _joinAll: function (res, callback) { 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); + 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); + } }); - 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: {} + self.storeValue.value = newItems.concat(BI.values(selectedMap)); + callback(); }); }, - _init: function () { - BI.MultiSelectEditor.superclass._init.apply(this, arguments); + _join: function (res, callback) { 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 () { - - }); + 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); }, - focus: function () { - this.editor.focus(); + _setStartValue: function (value) { + this._startValue = value; + this.adapter.setStartValue(value); }, - blur: function () { - this.editor.blur(); + isAllSelected: function () { + return this.adapter.isAllSelected(); }, - setState: function (state) { - this.editor.setState(state); + resize: function () { + // this.trigger.getCounter().adjustView(); + // this.trigger.adjustView(); }, - setValue: function (v) { - this.editor.setValue(v); + this.storeValue = v || {}; + this._assertValue(this.storeValue); + this.adapter.setValue(this.storeValue); + this.trigger.setValue(this.storeValue); }, 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; + return BI.deepClone(this.storeValue); }, - populate: function (items) { - + populate: function () { + this._count = null; + this._allData = null; + this.adapter.populate.apply(this.adapter, arguments); + this.trigger.populate.apply(this.trigger, 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.MultiSelectSearcher = BI.inherit(BI.Widget, { +BI.extend(BI.MultiSelectInsertList, { + REQ_GET_DATA_LENGTH: 1, + REQ_GET_ALL_DATA: -1 +}); + +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.MultiSelectList = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectSearcher.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-searcher", + return BI.extend(BI.MultiSelectList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-list", itemsCreator: BI.emptyFn, - el: {}, - popup: {}, - valueFormatter: BI.emptyFn, - adapter: null, - masker: {} + valueFormatter: BI.emptyFn + }); + }, + _init: function () { + BI.MultiSelectList.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); + }; + + 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: {} + }); + this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { + self.storeValue = this.getValue(); + self._adjust(function () { + assertShowValue(); + self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); + }); }); - }, - _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.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); + } }); + this.searcherPane.setVisible(false); - this.searcher = BI.createWidget({ + this.trigger = 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); + 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); + }); + } + } + }] }); - 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); + BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.trigger, + height: 24 + }, { + el: this.adapter, + height: "fill" + }] }); - this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { - var keywords = this.getKeywords(); - self.fireEvent(BI.MultiSelectSearcher.EVENT_SEARCHING, keywords); + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.searcherPane, + top: 30, + bottom: 0, + left: 0, + right: 0 + }] }); - if(BI.isNotNull(o.value)){ - this.setState(o.value); - } }, - adjustView: function () { - this.searcher.adjustView(); + _showAdapter: function () { + this.adapter.setVisible(true); + this.searcherPane.setVisible(false); }, - isSearching: function () { - return this.searcher.isSearching(); + _showSearcherPane: function () { + this.searcherPane.setVisible(true); + this.adapter.setVisible(false); }, - stopSearch: function () { - this.searcher.stopSearch(); + _defaultState: function () { + this.trigger.stopEditing(); }, - getKeyword: function () { - return this.editor.getValue(); + _assertValue: function (val) { + val || (val = {}); + val.type || (val.type = BI.Selection.Multi); + val.value || (val.value = []); }, - hasMatched: function () { - return this.searcher.hasMatched(); + _makeMap: function (values) { + return BI.makeObject(values || []); }, - hasChecked: function () { - return this.searcher.getView() && this.searcher.getView().hasChecked(); - }, + _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); + } - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + 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); + } }, - 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); + _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]; } }); - this.editor.setState(state); - } else { - this.editor.setState(BI.Selection.Multi); + change && (self.storeValue.value = BI.values(map)); + self._adjust(callback); + return; } - } - }, - - 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.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.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, { - - _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: {} + 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.MultiSelectCheckSelectedSwitcher.superclass._init.apply(this, arguments); + _adjust: function (callback) { var self = this, o = this.options; - - this.button = BI.createWidget(o.el, { - type: "bi.multi_select_check_selected_button", - itemsCreator: o.itemsCreator, - value: o.value - }); - this.button.on(BI.Events.VIEW, function () { - self.fireEvent(BI.Events.VIEW, arguments); - }); - 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(); - }, - value: o.value - }, o.popup), - adapter: o.adapter, - masker: o.masker - }); - this.switcher.on(BI.Switcher.EVENT_TRIGGER_CHANGE, function () { - self.fireEvent(BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE); - }); - 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(); + if (!this._count) { + o.itemsCreator({ + type: BI.MultiSelectList.REQ_GET_DATA_LENGTH + }, function (res) { + self._count = res.count; + adjust(); + callback(); }); - }); + } else { + adjust(); + callback(); + } - this.switcher.element.click(function (e) { - e.stopPropagation(); - }); + 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: [] + }; + } + } }, - adjustView: function () { - this.switcher.adjustView(); + _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); }, - hideView: function () { - this.switcher.empty(); - this.switcher.hideView(); + _setStartValue: function (value) { + this._startValue = value; + this.adapter.setStartValue(value); }, - setAdapter: function (adapter) { - this.switcher.setAdapter(adapter); + isAllSelected: function () { + return this.adapter.isAllSelected(); }, - setValue: function (v) { - this.switcher.setValue(v); + resize: function () { + // this.trigger.getCounter().adjustView(); + // this.trigger.adjustView(); }, - - setButtonChecked: function (v) { - this.button.setValue(v); + setValue: function (v) { + this.storeValue = v || {}; + this._assertValue(this.storeValue); + this.adapter.setValue(this.storeValue); + this.trigger.setValue(this.storeValue); }, getValue: function () { - + return BI.deepClone(this.storeValue); }, - populate: function (items) { - this.switcher.populate.apply(this.switcher, arguments); + populate: function () { + this._count = null; + this._allData = null; + this.adapter.populate.apply(this.adapter, arguments); + this.trigger.populate.apply(this.trigger, 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.extend(BI.MultiSelectList, { + REQ_GET_DATA_LENGTH: 1, + 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.MultiSelectInsertList = BI.inherit(BI.Widget, { +BI.MultiSelectTree = BI.inherit(BI.Widget, { _defaultConfig: function () { - return BI.extend(BI.MultiSelectInsertList.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-insert-list", - itemsCreator: BI.emptyFn, - valueFormatter: BI.emptyFn + return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-tree", + itemsCreator: BI.emptyFn }); }, - _init: function () { - BI.MultiSelectInsertList.superclass._init.apply(this, arguments); + _init: function () { + BI.MultiSelectTree.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); - }; + this.storeValue = {value: {}}; 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: {} + type: "bi.multi_select_tree_popup", + itemsCreator: o.itemsCreator }); - this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { - self.storeValue = this.getValue(); - assertShowValue(); - self.fireEvent(BI.MultiSelectInsertList.EVENT_CHANGE); + 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); }); + // 搜索中的时候用的是parttree,同adapter中的synctree不一样 this.searcherPane = BI.createWidget({ - type: "bi.multi_select_search_pane", + type: "bi.multi_tree_search_pane", cls: "bi-border-left bi-border-right bi-border-bottom", - valueFormatter: o.valueFormatter, keywordGetter: function () { - return self.trigger.getKeyword(); + return self.searcher.getKeyword(); }, itemsCreator: function (op, callback) { - op.keyword = self.trigger.getKeyword(); - this.setKeyword(op.keyword); + op.keyword = self.searcher.getKeyword(); o.itemsCreator(op, callback); } }); this.searcherPane.setVisible(false); - this.trigger = BI.createWidget({ + this.searcher = BI.createWidget({ type: "bi.searcher", isAutoSearch: false, isAutoSync: false, onSearch: function (op, callback) { - callback(); + callback({ + keyword: self.searcher.getKeyword() + }); }, 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)); + // self.storeValue = {value: self.adapter.getValue()}; + // self.searcherPane.setSelectedValue(self.storeValue.value); } }, { eventName: BI.Searcher.EVENT_STOP, action: function () { self._showAdapter(); - self._setStartValue(""); - self.adapter.setValue(self.storeValue); - // 需要刷新回到初始界面,否则搜索的结果不能放在最前面 - self.adapter.populate(); + // self.storeValue = {value: self.searcherPane.getValue()}; + // self.adapter.setSelectedValue(self.storeValue.value); + BI.nextTick(function () { + self.adapter.populate(); + }); } }, { - eventName: BI.Searcher.EVENT_PAUSE, + eventName: BI.Searcher.EVENT_CHANGE, 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); - }); + if (self.searcher.isSearching()) { + self.storeValue = {value: self.searcherPane.getValue()}; } 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); - } + self.storeValue = {value: self.adapter.getValue()}; } + self.setSelectedValue(self.storeValue.value); + self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE); } }, { - eventName: BI.Searcher.EVENT_SEARCHING, + eventName: BI.Searcher.EVENT_PAUSE, 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); - }); - } + self._showAdapter(); } }] }); @@ -96220,7 +100049,7 @@ BI.MultiSelectInsertList = BI.inherit(BI.Widget, { type: "bi.vtape", element: this, items: [{ - el: this.trigger, + el: this.searcher, height: 24 }, { el: this.adapter, @@ -96238,6 +100067,7 @@ BI.MultiSelectInsertList = BI.inherit(BI.Widget, { right: 0 }] }); + }, _showAdapter: function () { @@ -96250,2221 +100080,2418 @@ BI.MultiSelectInsertList = BI.inherit(BI.Widget, { this.adapter.setVisible(false); }, - _defaultState: function () { - this.trigger.stopEditing(); + resize: function () { + }, - _assertValue: function (val) { - val || (val = {}); - val.type || (val.type = BI.Selection.Multi); - val.value || (val.value = []); + setSelectedValue: function (v) { + this.storeValue.value = v || {}; + this.adapter.setSelectedValue(v); + this.searcherPane.setSelectedValue(v); + this.searcher.setValue({ + value: v || {} + }); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + setValue: function (v) { + this.adapter.setValue(v); }, - _joinKeywords: function (keywords, callback) { + stopSearch: function () { + this.searcher.stopSearch(); + }, + + updateValue: function (v) { + this.adapter.updateValue(v); + }, + + 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 + }); + }, + _init: function () { + BI.MultiSelectTreePopup.superclass._init.apply(this, arguments); 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.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); + }); + }, - 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); - } + hasChecked: function () { + return this.popup.hasChecked(); + }, + + getValue: function () { + return this.popup.getValue(); + }, + + setValue: function (v) { + v || (v = {}); + this.popup.setValue(v); + }, + + setSelectedValue: function (v) { + v || (v = {}); + this.popup.setSelectedValue(v); + }, + + updateValue: function (v) { + this.popup.updateValue(v); + this.popup.refresh(); + }, + + populate: function (config) { + this.popup.stroke(config); + } + +}); +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, { + + 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.MultiTreeCheckPane.superclass._init.apply(this, arguments); + + 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" + }); + continueSelect.on(BI.TextButton.EVENT_CHANGE, function () { + opts.onClickContinueSelect(); + BI.nextTick(function () { + self.empty(); }); - callback(); + }); + + 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 + }] + }); + + 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.display.on(BI.Events.AFTERINIT, function () { + self.fireEvent(BI.Events.AFTERINIT); + }); + + this.display.on(BI.TreeView.EVENT_INIT, function () { + backToPopup.setVisible(false); + }); + + this.display.on(BI.TreeView.EVENT_AFTERINIT, function () { + backToPopup.setVisible(true); + }); + + BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + height: this.constants.height, + el: backToPopup + }, { + height: "fill", + el: this.display + }] + }); + + }, + + empty: function () { + this.display.empty(); + }, + + populate: function (configs) { + this.display.stroke(configs); + }, + + setValue: function (v) { + v || (v = {}); + this.display.setSelectedValue(v.value); + }, + + getValue: function () { + + } +}); + +BI.MultiTreeCheckPane.EVENT_CONTINUE_CLICK = "EVENT_CONTINUE_CLICK"; + + +BI.shortcut("bi.multi_tree_check_pane", BI.MultiTreeCheckPane);/** + * + * @class BI.MultiTreeCombo + * @extends BI.Single + */ + +BI.MultiTreeCombo = BI.inherit(BI.Single, { + + constants: { + offset: { + top: 1, + left: 1, + right: 2, + bottom: 33 } }, - _joinAll: function (res, callback) { + _defaultConfig: function () { + 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.MultiTreeCombo.superclass._init.apply(this, arguments); + 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])) { + + var isInit = false; + var want2showCounter = false; + + this.storeValue = {value: o.value || {}}; + + this.trigger = BI.createWidget({ + type: "bi.multi_select_trigger", + height: o.height, + valueFormatter: o.valueFormatter, + // 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 || {}} + + }); + + 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; - delete map[v]; + var val = { + type: BI.Selection.Multi, + value: this.hasChecked() ? this.getValue() : {} + }; + self.trigger.getSearcher().setState(val); + self.trigger.getCounter().setButtonChecked(val); } - }); - change && (self.storeValue.value = BI.values(map)); - callback(); + }, { + 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; // 标识当前是否点击了清空 + + 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(); + } + }); + }); + + 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; } - 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(); - }); - }, + if (change === true) { + self.storeValue = {value: self.combo.getValue()}; + change = false; + } + self.combo.setValue(self.storeValue); + self.populate(); - _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]; + }); + 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); } - }); - change && (this.storeValue.value = BI.values(map)); - callback(); - return; - } - this._joinAll(res, callback); - }, + } + clear = false; + change = false; + }); - _setStartValue: function (value) { - this._startValue = value; - this.adapter.setStartValue(value); + 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 + }, { + el: triggerBtn, + right: 0, + top: 0, + bottom: 0 + }] + }); }, - isAllSelected: function () { - return this.adapter.isAllSelected(); + _defaultState: function () { + this.trigger.stopEditing(); + this.combo.hideView(); }, - resize: function () { - // this.trigger.getCounter().adjustView(); - // this.trigger.adjustView(); - }, setValue: function (v) { - this.storeValue = v || {}; - this._assertValue(this.storeValue); - this.adapter.setValue(this.storeValue); - this.trigger.setValue(this.storeValue); + this.storeValue.value = v || {}; + this.combo.setValue({ + value: v || {} + }); }, getValue: function () { - return BI.deepClone(this.storeValue); + return this.storeValue.value; }, populate: function () { - this._count = null; - this._allData = null; - this.adapter.populate.apply(this.adapter, arguments); - this.trigger.populate.apply(this.trigger, arguments); + this.combo.populate.apply(this.combo, arguments); } }); -BI.extend(BI.MultiSelectInsertList, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 -}); +BI.MultiTreeCombo.EVENT_CONFIRM = "MultiTreeCombo.EVENT_CONFIRM"; -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.shortcut("bi.multi_tree_combo", BI.MultiTreeCombo);/** + * 带加载的多选下拉面板 + * @class BI.MultiTreePopup + * @extends BI.Pane */ -BI.MultiSelectList = BI.inherit(BI.Widget, { +BI.MultiTreePopup = BI.inherit(BI.Pane, { + _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.MultiTreePopup.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-popup", + maxWidth: "auto", + minWidth: 100, + maxHeight: 400, + onLoaded: BI.emptyFn }); }, + _init: function () { - BI.MultiSelectList.superclass._init.apply(this, arguments); + BI.MultiTreePopup.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = {}; + var self = this, opts = this.options; - 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.selectedValues = {}; - 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: {} + this.tree = BI.createWidget({ + type: "bi.async_tree", + height: 400, + cls: "popup-view-tree", + itemsCreator: opts.itemsCreator, + onLoaded: opts.onLoaded, + value: opts.value || {} }); - this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - self.fireEvent(BI.MultiSelectList.EVENT_CHANGE); - }); + + 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.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); + 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.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 () { - 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); - }); - } - } - }] + this.tree.on(BI.TreeView.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiTreePopup.EVENT_CHANGE); }); - BI.createWidget({ - type: "bi.vtape", - element: this, - items: [{ - el: this.trigger, - height: 24 - }, { - el: this.adapter, - height: "fill" - }] - }); - BI.createWidget({ - type: "bi.absolute", - element: this, - items: [{ - el: this.searcherPane, - top: 30, - bottom: 0, - left: 0, - right: 0 - }] + 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.MultiSelectList.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); - } - }); - self._adjust(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.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); + +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 }); }, - _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(); - } + _init: function () { + BI.MultiTreeSearchPane.superclass._init.apply(this, arguments); - 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: [] - }; - } - } - }, + var self = this, opts = this.options; - _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); - }, + 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 + }); - _setStartValue: function (value) { - this._startValue = value; - this.adapter.setStartValue(value); - }, + this.partTree.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); - isAllSelected: function () { - return this.adapter.isAllSelected(); + 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); + + setValue: function (v) { + 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.MultiSelectList, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 -}); +BI.MultiTreeSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; -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.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.MultiSelectTree = BI.inherit(BI.Widget, { +BI.MultiTreeCheckSelectedButton = BI.inherit(BI.Single, { + _defaultConfig: function () { - return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-select-tree", + return BI.extend(BI.MultiTreeCheckSelectedButton.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-tree-check-selected-button", itemsCreator: BI.emptyFn }); }, _init: function () { - BI.MultiSelectTree.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.storeValue = {value: {}}; + 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.adapter = BI.createWidget({ - type: "bi.multi_select_tree_popup", - itemsCreator: o.itemsCreator + this.checkSelected = BI.createWidget({ + type: "bi.text_button", + cls: "trigger-check-selected", + invisible: true, + hgap: 4, + text: BI.i18nText("BI-Check_Selected"), + textAlign: "center", + textHeight: 15 }); - 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.checkSelected.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - // 搜索中的时候用的是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.checkSelected.on(BI.TextButton.EVENT_CHANGE, function () { + self.fireEvent(BI.MultiSelectCheckSelectedButton.EVENT_CHANGE, arguments); + }); + + BI.createWidget({ + type: "bi.horizontal", + element: this, + items: [this.indicator, this.checkSelected] + }); + + 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, + valueFormatter: function (v) { + return v; }, - itemsCreator: function (op, callback) { - op.keyword = self.searcher.getKeyword(); - o.itemsCreator(op, callback); + 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.searcher = BI.createWidget({ type: "bi.searcher", + element: this, isAutoSearch: false, isAutoSync: false, onSearch: function (op, callback) { callback({ - keyword: self.searcher.getKeyword() + keyword: self.editor.getValue() }); }, - 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(); - } - }] - }); + el: this.editor, - BI.createWidget({ - type: "bi.vtape", - element: this, - items: [{ - el: this.searcher, - 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); - }, - - _showSearcherPane: function () { - this.searcherPane.setVisible(true); - this.adapter.setVisible(false); - }, - - resize: function () { - + adjustView: function () { + this.searcher.adjustView(); }, - setSelectedValue: function (v) { - this.storeValue.value = v || {}; - this.adapter.setSelectedValue(v); - this.searcherPane.setSelectedValue(v); - this.searcher.setValue({ - value: v || {} - }); + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - setValue: function (v) { - this.adapter.setValue(v); + isSearching: function () { + return this.searcher.isSearching(); }, stopSearch: function () { this.searcher.stopSearch(); }, - updateValue: function (v) { - this.adapter.updateValue(v); - }, - - getValue: function () { - return this.storeValue.value; + getKeyword: function () { + return this.editor.getValue(); }, - 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 - }); - }, - _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); - }); + hasMatched: function () { + return this.searcher.hasMatched(); }, hasChecked: function () { - return this.popup.hasChecked(); + return this.searcher.getView() && this.searcher.getView().hasChecked(); }, - getValue: function () { - return this.popup.getValue(); + setState: function (ob) { + var o = this.options; + ob || (ob = {}); + ob.value || (ob.value = {}); + var count = 0; + 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 += (o.valueFormatter(name + "") || name) + (childNodes === "" ? "" : (":" + childNodes)) + "; "; + if (childNodes === "") { + count++; + } + }); + + if (count > 20) { + this.editor.setState(BI.Selection.Multi); + } else { + 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 += (o.valueFormatter(name + "") || name) + (childNodes === "" ? "" : (":" + childNodes)) + (index === size ? "" : ","); + if (childNodes === "") { + count++; + } + }); + return text; + } }, - setValue: function (v) { - v || (v = {}); - this.popup.setValue(v); + setValue: function (ob) { + this.setState(ob); + this.searcher.setValue(ob); }, - setSelectedValue: function (v) { - v || (v = {}); - this.popup.setSelectedValue(v); + getKey: function () { + return this.editor.getValue(); }, - updateValue: function (v) { - this.popup.updateValue(v); - this.popup.refresh(); + getValue: function () { + return this.searcher.getValue(); }, - populate: function (config) { - this.popup.stroke(config); + populate: function (items) { + this.searcher.populate.apply(this.searcher, arguments); } - }); -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, { - - constants: { - height: 25, - lgap: 10, - tgap: 5 - }, +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.MultiTreeCheckPane.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-check-pane bi-background", - onClickContinueSelect: 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.MultiTreeCheckPane.superclass._init.apply(this, arguments); - - 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" + 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 }); - continueSelect.on(BI.TextButton.EVENT_CHANGE, function () { - opts.onClickContinueSelect(); - BI.nextTick(function () { - self.empty(); - }); + this.editor.on(BI.TextEditor.EVENT_CHANGE, function () { + o.value = this.getValue(); + self.fireEvent(BI.NumberEditor.EVENT_CHANGE); }); - - 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 - }] + this.editor.on(BI.TextEditor.EVENT_CONFIRM, function () { + this.setValue(BI.parseFloat(this.getValue())); + self.fireEvent(BI.NumberEditor.EVENT_CONFIRM); }); - - 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.topBtn = BI.createWidget({ + type: "bi.icon_button", + trigger: "lclick,", + cls: "column-pre-page-h-font top-button bi-border-left bi-border-bottom" }); - - this.display.on(BI.Events.AFTERINIT, function () { - self.fireEvent(BI.Events.AFTERINIT); + 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.display.on(BI.TreeView.EVENT_INIT, function () { - backToPopup.setVisible(false); + 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.display.on(BI.TreeView.EVENT_AFTERINIT, function () { - backToPopup.setVisible(true); + 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.vtape", + type: "bi.htape", element: this, - items: [{ - height: this.constants.height, - el: backToPopup - }, { - height: "fill", - el: this.display + 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 }] }); - }, - empty: function () { - this.display.empty(); + focus: function () { + this.editor.focus(); + }, + + // 微调 + _finetuning: function (add) { + var v = BI.parseFloat(this.getValue()); + this.setValue(v.add(add)); }, - populate: function (configs) { - this.display.stroke(configs); + setUpEnable: function (v) { + this.topBtn.setEnable(!!v); }, - setValue: function (v) { - v || (v = {}); - this.display.setSelectedValue(v.value); + setDownEnable: function (v) { + this.bottomBtn.setEnable(!!v); }, getValue: function () { + return this.options.value; + }, + setValue: function (v) { + var o = this.options; + o.value = v; + this.editor.setValue(o.valueFormatter(v)); } -}); - -BI.MultiTreeCheckPane.EVENT_CONTINUE_CLICK = "EVENT_CONTINUE_CLICK"; - -BI.shortcut("bi.multi_tree_check_pane", BI.MultiTreeCheckPane);/** +}); +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. * - * @class BI.MultiTreeCombo - * @extends BI.Single */ - -BI.MultiTreeCombo = BI.inherit(BI.Single, { - +BI.NumberInterval = BI.inherit(BI.Single, { constants: { - offset: { - top: 1, - left: 1, - right: 2, - bottom: 33 - } + 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.MultiTreeCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-combo", - itemsCreator: BI.emptyFn, - height: 25 + var conf = BI.NumberInterval.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-number-interval", + height: 25, + validation: "valid" }); }, - _init: function () { - BI.MultiTreeCombo.superclass._init.apply(this, arguments); - - var self = this, o = this.options; - - var isInit = false; - var want2showCounter = 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 - }, - searcher: { - type: "bi.multi_tree_searcher", - itemsCreator: o.itemsCreator + 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; }, - switcher: { - el: { - type: "bi.multi_tree_check_selected_button" - }, - popup: { - type: "bi.multi_tree_check_pane", - itemsCreator: o.itemsCreator + validationChecker: function (v) { + if (!BI.isNumeric(v)) { + self.smallEditorBubbleType = c.typeError; + return false; } + return true; }, - value: {value: o.value || {}} + 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.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(); - }); + 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; }, - value: {value: o.value || {}}, - hideChecker: function (e) { - return triggerBtn.element.find(e.target).length === 0; - } + cls: "number-interval-big-editor bi-border-top bi-border-bottom bi-border-right" }); - - var change = false; - var clear = false; // 标识当前是否点击了清空 - - 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.bigTip = BI.createWidget({ + type: "bi.label", + text: o.numTip, + height: o.height - 2, + invisible: true }); - 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(); - } - }); + BI.createWidget({ + type: "bi.absolute", + element: this.bigEditor.element, + items: [{ + el: this.bigTip, + top: 0, + right: 5 + }] }); - 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.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.trigger.on(BI.MultiSelectTrigger.EVENT_TRIGGER_CLICK, function () { - self.combo.toggle(); + 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.trigger.on(BI.MultiSelectTrigger.EVENT_COUNTER_CLICK, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } + 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 + }] - 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.right = BI.createWidget({ + type: "bi.htape", + items: [{ + el: self.bigCombo, + width: c.width - c.border * 2 + }, { + el: self.bigEditor + }] }); - 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); + 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 + }] } - } - 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 - }, { - el: triggerBtn, - right: 0, - top: 0, - bottom: 0 - }] + 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); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + _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 ""; + + + + + + }, + + _setTitle: function (v) { + var self = this; + self.bigEditor.setTitle(v); + self.smallEditor.setTitle(v); + self.label.setTitle(v); }, - setValue: function (v) { - this.storeValue.value = v || {}; - this.combo.setValue({ - value: v || {} + _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; + } + }); }, - - getValue: function () { - return this.storeValue.value; + _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(""); + } + }); }, - 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 + _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); }); }, - _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 || {} + _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); + } }); + }, - 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); + _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 1: - self.fireEvent(BI.MultiTreePopup.EVENT_CLICK_CONFIRM); + 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); }); - - this.tree.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreePopup.EVENT_CHANGE); + w.on(BI.Editor.EVENT_CONFIRM, function () { + self.fireEvent(BI.NumberInterval.EVENT_CONFIRM); }); + }, - this.tree.on(BI.TreeView.EVENT_AFTERINIT, function () { - self.fireEvent(BI.MultiTreePopup.EVENT_AFTERINIT); + _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_CONFIRM); + self.fireEvent(BI.NumberInterval.EVENT_VALID); + } }); - }, - getValue: function () { - return this.tree.getValue(); + isStateValid: function () { + return this.options.validation === "valid"; }, - setValue: function (v) { - v || (v = {}); - this.tree.setSelectedValue(v.value); + setMinEnable: function (b) { + this.smallEditor.setEnable(b); }, - populate: function (config) { - this.tree.stroke(config); + setCloseMinEnable: function (b) { + this.smallCombo.setEnable(b); }, - hasChecked: function () { - return this.tree.hasChecked(); + setMaxEnable: function (b) { + this.bigEditor.setEnable(b); }, - resetHeight: function (h) { - this.popupView.resetHeight(h); + setCloseMaxEnable: function (b) { + this.bigCombo.setEnable(b); }, - 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 - */ + showNumTip: function () { + this.smallTip.setVisible(true); + this.bigTip.setVisible(true); + }, -BI.MultiTreeSearchPane = BI.inherit(BI.Pane, { + hideNumTip: function () { + this.smallTip.setVisible(false); + this.bigTip.setVisible(false); + }, - _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 - }); + setNumTip: function (numTip) { + this.smallTip.setText(numTip); + this.bigTip.setText(numTip); }, - _init: function () { - BI.MultiTreeSearchPane.superclass._init.apply(this, arguments); + getNumTip: function () { + return this.smallTip.getText(); + }, - var self = this, opts = this.options; + 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.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 - }); + if (!BI.isNotNull(data.min)) { + self.smallEditor.setValue(""); + } - this.partTree.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); + if (BI.isNumeric(data.max) || BI.isEmptyString(data.max)) { + self.bigEditor.setValue(data.max); + } - this.partTree.on(BI.TreeView.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreeSearchPane.EVENT_CHANGE); - }); - }, + if (!BI.isNotNull(data.max)) { + self.bigEditor.setValue(""); + } - hasChecked: function () { - return this.partTree.hasChecked(); - }, + if (!BI.isNull(data.closeMin)) { + if (data.closeMin === true) { + combo_value = 1; + } else { + combo_value = 0; + } + self.smallCombo.setValue(combo_value); + } - setValue: function (v) { - this.setSelectedValue(v.value); + if (!BI.isNull(data.closeMax)) { + if (data.closeMax === true) { + combo_value = 1; + } else { + combo_value = 0; + } + self.bigCombo.setValue(combo_value); + } }, - setSelectedValue: function (v) { - v || (v = {}); - this.partTree.setSelectedValue(v); - }, getValue: function () { - return this.partTree.getValue(); - }, - - empty: function () { - this.partTree.empty(); - }, + 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; + } - populate: function (op) { - this.partTree.stroke.apply(this.partTree, arguments); + if (maxComboValue[0] === 0) { + value.closeMax = false; + } else { + value.closeMax = true; + } + return value; } }); - -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 +BI.NumberInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.NumberInterval.EVENT_CONFIRM = "EVENT_CONFIRM"; +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.MultiTreeCheckSelectedButton = BI.inherit(BI.Single, { - - _const: { - checkSelected: BI.i18nText("BI-Check_Selected") - }, - +BI.PageTableCell = 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.PageTableCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-page-table-cell", + text: "", + title: "" }); }, _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.createWidget({ - type: "bi.horizontal", + BI.PageTableCell.superclass._init.apply(this, arguments); + var label = BI.createWidget({ + type: "bi.label", element: this, - items: [this.indicator, this.checkSelected] - }); - - this.element.hover(function () { - self.indicator.setVisible(false); - self.checkSelected.setVisible(true); - }, function () { - self.indicator.setVisible(true); - self.checkSelected.setVisible(false); + textAlign: "left", + whiteSpace: "nowrap", + height: this.options.height, + text: this.options.text, + title: this.options.title, + value: this.options.value, + lgap: 5, + rgap: 5 }); - this.setVisible(false); - }, - setValue: function (v) { - v || (v = {}); - this.setVisible(BI.size(v.value) > 0); + if (BI.isNotNull(this.options.styles) && BI.isObject(this.options.styles)) { + this.element.css(this.options.styles); + } } }); -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.page_table_cell", BI.PageTableCell);/** + * 分页表格 + * + * Created by GUY on 2016/2/15. + * @class BI.PageTable + * @extends BI.Widget */ -BI.MultiTreeSearcher = BI.inherit(BI.Widget, { +BI.PageTable = BI.inherit(BI.Widget, { + + _const: { + scrollWidth: 18, + minScrollWidth: 100 + }, _defaultConfig: function () { - return BI.extend(BI.MultiTreeSearcher.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-multi-tree-searcher", + 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 + } + }, + itemsCreator: BI.emptyFn, - popup: {}, - adapter: null, - masker: {} + 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: [] }); }, _init: function () { - BI.MultiTreeSearcher.superclass._init.apply(this, arguments); + BI.PageTable.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.hCurr = 1; + this.vCurr = 1; - 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, + this.table = BI.createWidget(o.el, { + type: "bi.sequence_table", + width: o.width, + height: o.height && o.height - 30, - 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), + 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, + + regionColumnSize: o.regionColumnSize, + + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter, + + header: o.header, + items: o.items, + // 交叉表头 + crossHeader: o.crossHeader, + crossItems: o.crossItems + }); - adapter: o.adapter, - masker: o.masker + this.table.on(BI.Table.EVENT_TABLE_SCROLL, function () { + self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }); - this.searcher.on(BI.Searcher.EVENT_START, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_START); + 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.searcher.on(BI.Searcher.EVENT_PAUSE, function () { - if (this.hasMatched()) { - } - self.fireEvent(BI.MultiTreeSearcher.EVENT_PAUSE); + this.pager = BI.createWidget(o.pager, { + type: "bi.direction_pager", + height: 30 }); - this.searcher.on(BI.Searcher.EVENT_STOP, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_STOP); + 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); + }); }); - this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { - self.fireEvent(BI.MultiTreeSearcher.EVENT_CHANGE, arguments); + + BI.createWidget({ + type: "bi.absolute", + element: this, + items: [{ + el: this.table, + left: 0, + top: 0 + }, { + el: this.pager, + left: 0, + right: 0, + bottom: 0 + }] }); - if (BI.isNotNull(o.value)) { - this.setState(o.value); - } }, - adjustView: function () { - this.searcher.adjustView(); + setHPage: function (v) { + this.hCurr = v; + this.pager.setHPage && this.pager.setHPage(v); + this.table.setHPage && this.table.setHPage(v); }, - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + setVPage: function (v) { + this.vCurr = v; + this.pager.setVPage && this.pager.setVPage(v); + this.table.setVPage && this.table.setVPage(v); }, - isSearching: function () { - return this.searcher.isSearching(); + 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; }, - stopSearch: function () { - this.searcher.stopSearch(); + 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; }, - getKeyword: function () { - return this.editor.getValue(); + setWidth: function (width) { + BI.PageTable.superclass.setWidth.apply(this, arguments); + this.table.setWidth(width); }, - hasMatched: function () { - return this.searcher.hasMatched(); + 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)); }, - hasChecked: function () { - return this.searcher.getView() && this.searcher.getView().hasChecked(); + setColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setColumnSize(columnSize); }, - 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; - } + getColumnSize: function () { + return this.table.getColumnSize(); }, - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); + setRegionColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setRegionColumnSize(columnSize); }, - getKey: function () { - return this.editor.getValue(); + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); }, - getValue: function () { - return this.searcher.getValue(); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); }, - 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 - }); + setLeftHorizontalScroll: function (scrollLeft) { + this.table.setLeftHorizontalScroll(scrollLeft); }, - _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); - }); - 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 - }] - }); + setRightHorizontalScroll: function (scrollLeft) { + this.table.setRightHorizontalScroll(scrollLeft); }, - // 微调 - _finetuning: function (add) { - var v = BI.parseFloat(this.getValue()); - this.setValue(v.add(add)); + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); }, - setUpEnable: function (v) { - this.topBtn.setEnable(!!v); + restore: function () { + this.table.restore(); }, - setDownEnable: function (v) { - this.bottomBtn.setEnable(!!v); + attr: function () { + BI.PageTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); }, - getValue: function () { - return this.options.value; + populate: function () { + this.pager.populate(); + this.table.populate.apply(this.table, arguments); }, - setValue: function (v) { - var o = this.options; - o.value = v; - this.editor.setValue(o.valueFormatter(v)); + destroy: function () { + this.table.destroy(); + this.pager && this.pager.destroy(); + BI.PageTable.superclass.destroy.apply(this, arguments); } - }); -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.shortcut("bi.page_table", BI.PageTable);/** + * 预览表列 * + * Created by GUY on 2015/12/25. + * @class BI.PreviewTableCell + * @extends 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: "" - }, +BI.PreviewTableCell = BI.inherit(BI.Widget, { + _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.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table-cell", + text: "" }); }, - _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 - }] - }); - 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" - }); + _init: function () { + BI.PreviewTableCell.superclass._init.apply(this, arguments); + var self = this, o = this.options; - 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 - }, { - 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 - }, { - text: "(" + BI.i18nText("BI-Less_And_Equal") + ")", - value: 1, - iconCls: "less-equal-font" - }] - }); - 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 - }] - - }); - this.right = BI.createWidget({ - type: "bi.htape", - items: [{ - 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 - }] - } - ] + element: this, + 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, { - BI.createWidget({ - element: self, - type: "bi.horizontal_auto", - items: [ - self.label - ] + _defaultConfig: function () { + return BI.extend(BI.PreviewTableHeaderCell.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-preview-table-header-cell", + text: "" }); + }, + _init: function () { + BI.PreviewTableHeaderCell.superclass._init.apply(this, arguments); + var self = this, o = this.options; - 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); + 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, { + + _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: [] + }); }, - _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 ""; + _init: function () { + BI.PreviewTable.superclass._init.apply(this, arguments); + var self = this, o = this.options; - } - 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 ""; + 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.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, arguments); + }); + this.table.on(BI.Table.EVENT_TABLE_RESIZE, function () { + self._adjustColumns(); + }); + this._adjustColumns(); + }, + // 是否有自适应调节的列,即列宽为"" + _hasAdaptCol: function (columnSize) { + return BI.any(columnSize, function (i, size) { + return size === ""; + }); }, - _setTitle: function (v) { - var self = this; - self.bigEditor.setTitle(v); - self.smallEditor.setTitle(v); - self.label.setTitle(v); + _isPercentage: function (columnSize) { + return columnSize[0] <= 1; }, - _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" + _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; + } }); - break; - case c.signalError: - BI.Bubbles.show(c.signalError, BI.i18nText("BI-Numerical_Interval_Signal_Value"), self, { - offsetStyle: "center" + remain = 1 - remain; + var average = remain / findCols.length; + BI.each(findCols, function (i, col) { + o.columnSize[col] = average; }); - break; - default : - return; + } + 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%"]); } + } + }, - }); + setColumnSize: function (columnSize) { + return this.table.setColumnSize(columnSize); }, - _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(""); - } - }); + + getColumnSize: function () { + return this.table.getColumnSize(); }, - _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); - }); + getCalculateColumnSize: function () { + return this.table.getCalculateColumnSize(); }, + setHeaderColumnSize: function (columnSize) { + return this.table.setHeaderColumnSize(columnSize); + }, - _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); - } - }); + setRegionColumnSize: function (columnSize) { + return this.table.setRegionColumnSize(columnSize); }, + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); + }, - _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); - }); + getCalculateRegionColumnSize: function () { + return this.table.getCalculateRegionColumnSize(); }, - _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); - } - }); + getCalculateRegionRowSize: function () { + return this.table.getCalculateRegionRowSize(); }, - isStateValid: function () { - return this.options.validation === "valid"; + getClientRegionColumnSize: function () { + return this.table.getClientRegionColumnSize(); }, - setMinEnable: function (b) { - this.smallEditor.setEnable(b); + getScrollRegionColumnSize: function () { + return this.table.getScrollRegionColumnSize(); }, - setCloseMinEnable: function (b) { - this.smallCombo.setEnable(b); + getScrollRegionRowSize: function () { + return this.table.getScrollRegionRowSize(); }, - setMaxEnable: function (b) { - this.bigEditor.setEnable(b); + hasVerticalScroll: function () { + return this.table.hasVerticalScroll(); }, - setCloseMaxEnable: function (b) { - this.bigCombo.setEnable(b); + setVerticalScroll: function (scrollTop) { + return this.table.setVerticalScroll(scrollTop); }, - showNumTip: function () { - this.smallTip.setVisible(true); - this.bigTip.setVisible(true); + setLeftHorizontalScroll: function (scrollLeft) { + return this.table.setLeftHorizontalScroll(scrollLeft); }, - hideNumTip: function () { - this.smallTip.setVisible(false); - this.bigTip.setVisible(false); + setRightHorizontalScroll: function (scrollLeft) { + return this.table.setRightHorizontalScroll(scrollLeft); }, - setNumTip: function (numTip) { - this.smallTip.setText(numTip); - this.bigTip.setText(numTip); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); }, - getNumTip: function () { - return this.smallTip.getText(); + getLeftHorizontalScroll: function () { + return this.table.getLeftHorizontalScroll(); }, - setValue: function (data) { - data = data || {}; - var self = this, combo_value; - if (BI.isNumeric(data.min) || BI.isEmptyString(data.min)) { - self.smallEditor.setValue(data.min); - } + getRightHorizontalScroll: function () { + return this.table.getRightHorizontalScroll(); + }, - if (!BI.isNotNull(data.min)) { - self.smallEditor.setValue(""); - } + getColumns: function () { + return this.table.getColumns(); + }, - if (BI.isNumeric(data.max) || BI.isEmptyString(data.max)) { - self.bigEditor.setValue(data.max); - } + populate: function (items, header) { + this.table.populate(items, header); + this._adjustColumns(); + } +}); +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 + }); - if (!BI.isNotNull(data.max)) { - self.bigEditor.setValue(""); + 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 () { + 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: {} + }); + }, + + _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 + }); + }); - if (!BI.isNull(data.closemin)) { - if (data.closemin === true) { - combo_value = 1; - } else { - combo_value = 0; - } - self.smallCombo.setValue(combo_value); - } + this.quarter = BI.createWidget({ + type: "bi.button_group", + element: this, + behaviors: o.behaviors, + items: BI.createItems(items, {}), + layouts: [{ + type: "bi.vertical" + }], + value: o.value + }); - if (!BI.isNull(data.closemax)) { - if (data.closemax === true) { - combo_value = 1; - } else { - combo_value = 0; + 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); } - 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; - } + return this.quarter.getValue()[0]; + }, - if (maxComboValue[0] === 0) { - value.closemax = false; - } else { - value.closemax = true; - } - return value; + setValue: function (v) { + this.quarter.setValue([v]); } }); -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.QuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.quarter_popup", BI.QuarterPopup);/** + * 季度trigger * - * Created by GUY on 2015/9/22. - * @class BI.PageTableCell - * @extends BI.Single + * Created by GUY on 2015/8/21. + * @class BI.QuarterTrigger + * @extends BI.Trigger */ -BI.PageTableCell = BI.inherit(BI.Widget, { +BI.QuarterTrigger = BI.inherit(BI.Trigger, { + _const: { + hgap: 4, + vgap: 2, + textWidth: 40 + }, + _defaultConfig: function () { - return BI.extend(BI.PageTableCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-page-table-cell", - text: "", - title: "" + return BI.extend(BI.QuarterTrigger.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-quarter-trigger bi-border", + height: 24 }); }, - _init: function () { - BI.PageTableCell.superclass._init.apply(this, arguments); - var label = BI.createWidget({ - type: "bi.label", + 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: BI.i18nText("BI-Quarter_Trigger_Error_Text") + }); + 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, - textAlign: "left", - whiteSpace: "nowrap", - height: this.options.height, - text: this.options.text, - title: this.options.title, - value: this.options.value, - lgap: 5, - rgap: 5 + 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); + }, - if (BI.isNotNull(this.options.styles) && BI.isObject(this.options.styles)) { - this.element.css(this.options.styles); - } + setValue: function (v) { + v = v || ""; + this.editor.setState(v); + this.editor.setValue(v); + this.editor.setTitle(v); + }, + + getKey: function () { + return this.editor.getValue(); } }); - -BI.shortcut("bi.page_table_cell", BI.PageTableCell);/** - * 分页表格 +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/15. - * @class BI.PageTable + * Created by GUY on 2016/2/3. + * @class BI.ResponisveTable * @extends BI.Widget */ -BI.PageTable = BI.inherit(BI.Widget, { +BI.ResponisveTable = BI.inherit(BI.Widget, { _const: { - scrollWidth: 18, - minScrollWidth: 100 + perColumnSize: 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 - } - }, - - itemsCreator: BI.emptyFn, - + 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: BI.emptyFn, + mergeRule: function (row1, row2) { // 合并规则, 默认相等时合并 + return BI.isEqual(row1, row2); + }, columnSize: [], - minColumnSize: [], - maxColumnSize: [], headerRowSize: 25, + footerRowSize: 25, rowSize: 25, - regionColumnSize: [], - - headerCellStyleGetter: BI.emptyFn, - summaryCellStyleGetter: BI.emptyFn, - sequenceCellStyleGetter: BI.emptyFn, + regionColumnSize: false, header: [], + footer: false, items: [], // 二维数组 // 交叉表头 @@ -98474,18 +102501,13 @@ BI.PageTable = BI.inherit(BI.Widget, { }, _init: function () { - BI.PageTable.superclass._init.apply(this, arguments); + BI.ResponisveTable.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, + this.table = BI.createWidget({ + type: "bi.table_view", + element: this, + logic: o.logic, isNeedFreeze: o.isNeedFreeze, freezeCols: o.freezeCols, @@ -98495,156 +102517,266 @@ BI.PageTable = BI.inherit(BI.Widget, { mergeRule: o.mergeRule, columnSize: o.columnSize, - minColumnSize: o.minColumnSize, - maxColumnSize: o.maxColumnSize, headerRowSize: o.headerRowSize, + footerRowSize: o.footerRowSize, rowSize: o.rowSize, regionColumnSize: o.regionColumnSize, - headerCellStyleGetter: o.headerCellStyleGetter, - summaryCellStyleGetter: o.summaryCellStyleGetter, - sequenceCellStyleGetter: o.sequenceCellStyleGetter, - 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 () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); + self._resizeHeader(); self.fireEvent(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, 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.table.on(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, function () { - o.regionColumnSize = this.getRegionColumnSize(); - o.columnSize = this.getColumnSize(); + self._resizeRegion(); + self._resizeHeader(); self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE, arguments); }); + }, - 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(); + _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]); + } } - 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); - }); - }); - - 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); + _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 + }; }, - setVPage: function (v) { - this.vCurr = v; - this.pager.setVPage && this.pager.setVPage(v); - this.table.setVPage && this.table.setVPage(v); + _isAdaptiveColumn: function (columnSize) { + return !(BI.last(columnSize || this.table.getColumnSize()) > 1.05); }, - 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; + _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; + + var newLeft = BI.clone(columnSizeLeft), newRight = BI.clone(columnSizeRight); + newLeft[newLeft.length - 1] = ""; + newRight[newRight.length - 1] = ""; + this.table.setColumnSize(newLeft.concat(newRight)); + + 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]; + } + + 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; + + size[size.length - 1] += regionColumnSize[0] - sum; + + 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); + } } - return this.hpage; }, - 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; + _resizeBody: function () { + if (this._isAdaptiveColumn()) { + var columnSize = this.table.getCalculateColumnSize(); + this.setColumnSize(columnSize); } - return this.vpage; }, - setWidth: function (width) { - BI.PageTable.superclass.setWidth.apply(this, arguments); - this.table.setWidth(width); + _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(); + } }, - 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; + _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"]); + } } - this.table.setHeight(height - (showPager ? 30 : 0)); + }, + + + resize: function () { + this.table.resize(); + this._resizeRegion(); + this._resizeHeader(); }, 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(); }, - getVerticalScroll: function () { - return this.table.getVerticalScroll(); + 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(); + }, + + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); }, setLeftHorizontalScroll: function (scrollLeft) { @@ -98655,617 +102787,924 @@ BI.PageTable = BI.inherit(BI.Widget, { this.table.setRightHorizontalScroll(scrollLeft); }, - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); + getVerticalScroll: function () { + return this.table.getVerticalScroll(); }, - restore: function () { - this.table.restore(); + getLeftHorizontalScroll: function () { + return this.table.getLeftHorizontalScroll(); + }, + + getRightHorizontalScroll: function () { + return this.table.getRightHorizontalScroll(); + }, + + getColumns: function () { + return this.table.getColumns(); }, attr: function () { - BI.PageTable.superclass.attr.apply(this, arguments); + BI.ResponisveTable.superclass.attr.apply(this, arguments); this.table.attr.apply(this.table, arguments); }, - populate: function () { - this.pager.populate(); + populate: function (items) { + var self = this, o = this.options; this.table.populate.apply(this.table, arguments); - }, - - destroy: function () { - this.table.destroy(); - this.pager && this.pager.destroy(); - BI.PageTable.superclass.destroy.apply(this, arguments); + if (o.isNeedFreeze === true) { + BI.nextTick(function () { + self._initRegionSize(); + self.table.resize(); + self._resizeHeader(); + }); + } } }); -BI.shortcut("bi.page_table", BI.PageTable);/** - * 预览表列 - * - * Created by GUY on 2015/12/25. - * @class BI.PreviewTableCell - * @extends BI.Widget +BI.shortcut("bi.responsive_table", BI.ResponisveTable);/** + * 加号表示的组节点 + * Created by GUY on 2015/9/6. + * @class BI.SelectTreeFirstPlusGroupNode + * @extends BI.NodeButton */ -BI.PreviewTableCell = BI.inherit(BI.Widget, { - +BI.SelectTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { _defaultConfig: function () { - return BI.extend(BI.PreviewTableCell.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table-cell", - text: "" + 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.PreviewTableCell.superclass._init.apply(this, arguments); + BI.SelectTreeFirstPlusGroupNode.superclass._init.apply(this, arguments); var self = this, o = this.options; - - BI.createWidget({ + this.checkbox = BI.createWidget({ + type: "bi.first_tree_node_checkbox", + stopPropagation: true + }); + this.text = BI.createWidget({ type: "bi.label", - element: this, textAlign: "left", - whiteSpace: "normal", - height: this.options.height, - text: this.options.text, - value: this.options.value + whiteSpace: "nowrap", + textHeight: o.height, + height: o.height, + hgap: o.hgap, + text: o.text, + value: o.value, + py: o.py }); - } -}); -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.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 + })))); }, - _init: function () { - BI.PreviewTableHeaderCell.superclass._init.apply(this, arguments); - var self = this, o = this.options; + isOnce: function () { + return true; + }, - BI.createWidget({ - type: "bi.label", - element: this, - textAlign: "left", - whiteSpace: "normal", - height: this.options.height, - text: this.options.text, - value: this.options.value - }); + 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); + }, + + setOpened: function (v) { + BI.SelectTreeFirstPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } } }); -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, { +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 () { - return BI.extend(BI.PreviewTable.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-preview-table", - isNeedFreeze: false, - freezeCols: [], - rowSize: null, - columnSize: [], - headerRowSize: 30, - header: [], - items: [] + 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.PreviewTable.superclass._init.apply(this, arguments); + BI.SelectTreeLastPlusGroupNode.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.checkbox = BI.createWidget({ + type: "bi.last_tree_node_checkbox", + stopPropagation: true }); - this.table.on(BI.Table.EVENT_TABLE_AFTER_INIT, function () { - self._adjustColumns(); - self.fireEvent(BI.Table.EVENT_TABLE_AFTER_INIT, 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_RESIZE, function () { - self._adjustColumns(); + 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 + })))); }, - // 是否有自适应调节的列,即列宽为"" - _hasAdaptCol: function (columnSize) { - return BI.any(columnSize, function (i, size) { - return size === ""; - }); + isOnce: function () { + return true; }, - _isPercentage: function (columnSize) { - return columnSize[0] <= 1; + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); }, - _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%"]); - } - } + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - setColumnSize: function (columnSize) { - return this.table.setColumnSize(columnSize); + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); }, - getColumnSize: function () { - return this.table.getColumnSize(); - }, + setOpened: function (v) { + BI.SelectTreeLastPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } + } +}); - getCalculateColumnSize: function () { - return this.table.getCalculateColumnSize(); +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 + }); }, - - setHeaderColumnSize: function (columnSize) { - return this.table.setHeaderColumnSize(columnSize); + _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 + })))); }, - setRegionColumnSize: function (columnSize) { - return this.table.setRegionColumnSize(columnSize); + isOnce: function () { + return true; }, - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); }, - getCalculateRegionColumnSize: function () { - return this.table.getCalculateRegionColumnSize(); + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); }, - getCalculateRegionRowSize: function () { - return this.table.getCalculateRegionRowSize(); + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); }, - getClientRegionColumnSize: function () { - return this.table.getClientRegionColumnSize(); - }, + setOpened: function (v) { + BI.SelectTreeMidPlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } + } +}); - getScrollRegionColumnSize: function () { - return this.table.getScrollRegionColumnSize(); - }, +BI.shortcut("bi.select_tree_mid_plus_group_node", BI.SelectTreeMidPlusGroupNode);/** + * @class BI.SelectTreeCombo + * @extends BI.Widget + */ +BI.SelectTreeCombo = BI.inherit(BI.Widget, { - getScrollRegionRowSize: function () { - return this.table.getScrollRegionRowSize(); + _defaultConfig: function () { + return BI.extend(BI.SelectTreeCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-tree-combo", + height: 30, + text: "", + items: [], + value: "" + }); }, - hasVerticalScroll: function () { - return this.table.hasVerticalScroll(); - }, + _init: function () { + BI.SelectTreeCombo.superclass._init.apply(this, arguments); + var self = this, o = this.options; - setVerticalScroll: function (scrollTop) { - return this.table.setVerticalScroll(scrollTop); - }, + this.trigger = BI.createWidget({ + type: "bi.single_tree_trigger", + text: o.text, + height: o.height, + items: o.items, + value: o.value + }); - setLeftHorizontalScroll: function (scrollLeft) { - return this.table.setLeftHorizontalScroll(scrollLeft); - }, + this.popup = BI.createWidget({ + type: "bi.select_level_tree", + items: o.items, + value: o.value + }); - setRightHorizontalScroll: function (scrollLeft) { - return this.table.setRightHorizontalScroll(scrollLeft); - }, + 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); + }); - getLeftHorizontalScroll: function () { - return this.table.getLeftHorizontalScroll(); + this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + }); }, - getRightHorizontalScroll: function () { - return this.table.getRightHorizontalScroll(); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.trigger.setValue(v); + this.popup.setValue(v); }, - getColumns: function () { - return this.table.getColumns(); + getValue: function () { + return this.popup.getValue(); }, - populate: function (items, header) { - this.table.populate(items, header); + populate: function (items) { + this.combo.populate(items); } }); -BI.PreviewTable.EVENT_CHANGE = "PreviewTable.EVENT_CHANGE"; -BI.shortcut("bi.preview_table", BI.PreviewTable);/** - * 季度下拉框 - * - * Created by GUY on 2015/8/28. - * @class BI.QuarterCombo + + +BI.shortcut("bi.select_tree_combo", BI.SelectTreeCombo);/** + * @class BI.SelectTreeExpander * @extends BI.Widget */ -BI.QuarterCombo = BI.inherit(BI.Widget, { +BI.SelectTreeExpander = BI.inherit(BI.Widget, { + _defaultConfig: function () { - return BI.extend(BI.QuarterCombo.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-quarter-combo", - behaviors: {}, - height: 25 + 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.QuarterCombo.superclass._init.apply(this, arguments); + BI.SelectTreeExpander.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(); + 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.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); + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.combo = BI.createWidget({ - type: "bi.combo", + this.expander = BI.createWidget({ + type: "bi.expander", element: this, - isNeedAdjustHeight: false, - isNeedAdjustWidth: false, + trigger: o.trigger, + toggle: o.toggle, + direction: o.direction, + isDefaultInit: o.isDefaultInit, el: this.trigger, - popup: { - minWidth: 85, - el: this.popup - } + popup: o.popup }); - this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.QuarterCombo.EVENT_BEFORE_POPUPVIEW); + 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) { - this.trigger.setValue(v); - this.popup.setValue(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 (BI.isNull(this.popup)) { - return this.options.value || ""; - } else { - return this.popup.getValue() || ""; + if (this.trigger.isSelected()) { + return [this.trigger.getValue()]; } + return this.expander.getValue(); + }, + + populate: function (items) { + this.expander.populate(items); } }); -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_expander", BI.SelectTreeExpander);/** + * @class BI.SelectTreePopup + * @extends BI.Pane */ -BI.QuarterPopup = BI.inherit(BI.Widget, { + +BI.SelectTreePopup = BI.inherit(BI.Pane, { _defaultConfig: function () { - return BI.extend(BI.QuarterPopup.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-quarter-popup", - behaviors: {} + 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; + } + 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; }, _init: function () { - BI.QuarterPopup.superclass._init.apply(this, arguments); + BI.SelectTreePopup.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.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.quarter = BI.createWidget({ - type: "bi.button_group", + BI.createWidget({ + type: "bi.vertical", element: this, - behaviors: o.behaviors, - items: BI.createItems(items, {}), - layouts: [{ - type: "bi.vertical" - }], - value: o.value + items: [this.tree] }); - this.quarter.on(BI.Controller.EVENT_CHANGE, function (type) { + this.tree.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.tree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SelectTreePopup.EVENT_CHANGE); + }); + + this.check(); }, getValue: function () { - return this.quarter.getValue()[0]; + return this.tree.getValue(); }, setValue: function (v) { - this.quarter.setValue([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.QuarterPopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.quarter_popup", BI.QuarterPopup);/** - * 季度trigger + +BI.SelectTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.select_level_tree", BI.SelectTreePopup);/** * - * Created by GUY on 2015/8/21. - * @class BI.QuarterTrigger - * @extends BI.Trigger + * Created by GUY on 2016/8/10. + * @class BI.SequenceTableDynamicNumber + * @extends BI.SequenceTableTreeNumber */ -BI.QuarterTrigger = BI.inherit(BI.Trigger, { - _const: { - hgap: 4, - vgap: 2, - textWidth: 40, - errorText: BI.i18nText("BI-Quarter_Trigger_Error_Text") +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++; + } + 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; + }); + 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, { + _defaultConfig: function () { - return BI.extend(BI.QuarterTrigger.superclass._defaultConfig.apply(this, arguments), { - extraCls: "bi-quarter-trigger bi-border", - height: 24 + 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 }); }, + _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 + 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.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_FOCUS); + + this.scrollContainer = BI.createWidget({ + type: "bi.vertical", + scrollable: false, + scrolly: false, + items: [this.container] }); - this.editor.on(BI.SignEditor.EVENT_CHANGE, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_CHANGE); + + this.headerContainer = BI.createWidget({ + type: "bi.absolute", + cls: "bi-border", + width: 58, + scrollable: false }); - 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.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(); + }, + + _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) { + + } + }, + + _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 + }] + }); + }, + + _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; } - self.fireEvent(BI.QuarterTrigger.EVENT_CONFIRM); }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); + BI.each(this.renderedKeys, function (i, key) { + if (BI.deepContains(existSet, key)) { + return; + } + if (BI.deepContains(addSet, key)) { + return; } + deleteArray.push(i); }); - this.editor.on(BI.SignEditor.EVENT_START, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_START); + BI.each(deleteArray, function (i, index) { + self.renderedCells[index].el.destroy(); }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.QuarterTrigger.EVENT_STOP); + var addedItems = []; + BI.each(addSet, function (index) { + addedItems.push(renderedCells[index]); }); - 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 - } - ] + type: "bi.absolute", + element: this.container, + items: addedItems }); - this.setValue(o.value); + this.renderedCells = renderedCells; + this.renderedKeys = renderedKeys; }, - setValue: function (v) { - v = v || ""; - this.editor.setState(v); - this.editor.setValue(v); - this.editor.setTitle(v); + _populate: function () { + this.headerContainer.empty(); + this._createHeader(); + this._layout(); + this._calculateChildrenToRender(); }, - getKey: function () { - return this.editor.getValue(); + setVerticalScroll: function (scrollTop) { + if (this.options.scrollTop !== scrollTop) { + this.options.scrollTop = scrollTop; + try { + this.scrollContainer.element.scrollTop(scrollTop); + } catch (e) { + + } + } + }, + + getVerticalScroll: function () { + return this.options.scrollTop; + }, + + setVPage: function (v) { + v = v < 1 ? 1 : v; + var o = this.options; + this.start = (v - 1) * o.pageSize + 1; + }, + + _restore: function () { + var o = this.options; + BI.each(this.renderedCells, function (i, cell) { + cell.el.destroy(); + }); + this.renderedCells = []; + this.renderedKeys = []; + }, + + restore: function () { + this._restore(); + }, + + 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, + 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, @@ -99275,457 +103714,815 @@ BI.ResponisveTable = BI.inherit(BI.Widget, { mergeRule: o.mergeRule, columnSize: o.columnSize, + minColumnSize: o.minColumnSize, + maxColumnSize: o.maxColumnSize, headerRowSize: o.headerRowSize, - footerRowSize: o.footerRowSize, rowSize: o.rowSize, regionColumnSize: o.regionColumnSize, + headerCellStyleGetter: o.headerCellStyleGetter, + summaryCellStyleGetter: o.summaryCellStyleGetter, + sequenceCellStyleGetter: o.sequenceCellStyleGetter, + 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.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_REGION_RESIZE, arguments); + self.fireEvent(BI.Table.EVENT_TABLE_SCROLL, arguments); }); this.table.on(BI.Table.EVENT_TABLE_AFTER_REGION_RESIZE, function () { - self._resizeHeader(); + 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_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(); + 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._populate(); }, - _initRegionSize: function () { + _populate: 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]); - } - } + 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); } }, - _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 - }; + setWidth: function (width) { + BI.PageTable.superclass.setWidth.apply(this, arguments); + this.table.setWidth(this.options.showSequence ? width - 60 : width); }, - _isAdaptiveColumn: function (columnSize) { - return !(BI.last(columnSize || this.table.getColumnSize()) > 1.05); + setHeight: function (height) { + BI.PageTable.superclass.setHeight.apply(this, arguments); + this.table.setHeight(height); + this.sequence.setHeight(height - BI.GridTableScrollbar.SIZE); }, - _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; + setColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setColumnSize(columnSize); + }, - var newLeft = BI.clone(columnSizeLeft), newRight = BI.clone(columnSizeRight); - newLeft[newLeft.length - 1] = ""; - newRight[newRight.length - 1] = ""; - this.table.setColumnSize(newLeft.concat(newRight)); + getColumnSize: function () { + return this.table.getColumnSize(); + }, - 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]; - } + setRegionColumnSize: function (columnSize) { + this.options.columnSize = columnSize; + this.table.setRegionColumnSize(columnSize); + }, - 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; + getRegionColumnSize: function () { + return this.table.getRegionColumnSize(); + }, - size[size.length - 1] += regionColumnSize[0] - sum; + hasLeftHorizontalScroll: function () { + return this.table.hasLeftHorizontalScroll(); + }, - var newSize = BI.clone(size); - newSize[newSize.length - 1] = ""; - this.table.setColumnSize(newSize); - block = this._getBlockSize(); + hasRightHorizontalScroll: function () { + return this.table.hasRightHorizontalScroll(); + }, - if (size[size.length - 1] < block.size[block.size.length - 1]) { - size[size.length - 1] = block.size[block.size.length - 1]; + setLeftHorizontalScroll: function (scrollLeft) { + this.table.setLeftHorizontalScroll(scrollLeft); + }, + + setRightHorizontalScroll: function (scrollLeft) { + this.table.setRightHorizontalScroll(scrollLeft); + }, + + setVerticalScroll: function (scrollTop) { + this.table.setVerticalScroll(scrollTop); + this.sequence.setVerticalScroll(scrollTop); + }, + + getVerticalScroll: function () { + return this.table.getVerticalScroll(); + }, + + setVPage: function (page) { + this.sequence.setVPage && this.sequence.setVPage(page); + }, + + setHPage: function (page) { + this.sequence.setHPage && this.sequence.setHPage(page); + }, + + attr: function () { + BI.SequenceTable.superclass.attr.apply(this, arguments); + this.table.attr.apply(this.table, arguments); + this.sequence.attr.apply(this.sequence, arguments); + }, + + 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.sequence_table", BI.SequenceTable);/** + * 单选加载数据搜索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 + }); + }, + + _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 + }, + 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_SINGLE, + behaviors: { + redmark: function () { + return true; + } + }, + layouts: [{ + type: "bi.vertical" + }] + } } - this.table.setColumnSize(size); + }, + 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; } - } - }, - - _resizeBody: function () { - if (this._isAdaptiveColumn()) { - var columnSize = this.table.getCalculateColumnSize(); - this.setColumnSize(columnSize); - } + }); + 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); + }); }, - _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(); - } + _createItems: function (items) { + return BI.createItems(items, { + type: "bi.single_select_combo.item", + logic: { + dynamic: false + }, + height: 25, + selected: false + }); }, - _resizeRegion: function () { + _filterValues: function (src) { 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"]); - } + 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 + }; + }); }, - - resize: function () { - this.table.resize(); - this._resizeRegion(); - this._resizeHeader(); - }, - - setColumnSize: function (columnSize) { - this.table.setColumnSize(columnSize); - this._adjustRegion(); - this._resizeHeader(); + setValue: function (v) { + // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 + this.storeValue = v; + this.button_group.setValue(v); }, - getColumnSize: function () { - return this.table.getColumnSize(); + getValue: function () { + return this.button_group.getValue(); }, - getCalculateColumnSize: function () { - return this.table.getCalculateColumnSize(); + getAllButtons: function () { + return this.button_group.getAllButtons(); }, - setHeaderColumnSize: function (columnSize) { - this.table.setHeaderColumnSize(columnSize); - this._adjustRegion(); - this._resizeHeader(); + empty: function () { + this.button_group.empty(); }, - setRegionColumnSize: function (columnSize) { - this.table.setRegionColumnSize(columnSize); - this._resizeHeader(); + populate: function (items) { + this.button_group.populate.apply(this.button_group, arguments); }, - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); + resetHeight: function (h) { + this.button_group.resetHeight(h); }, - getCalculateRegionColumnSize: function () { - return this.table.getCalculateRegionColumnSize(); - }, + resetWidth: function (w) { + this.button_group.resetWidth(w); + } +}); - getCalculateRegionRowSize: function () { - return this.table.getCalculateRegionRowSize(); - }, +BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_search_loader", BI.SingleSelectSearchLoader);/** + * + * 在搜索框中输入文本弹出的面板 + * @class BI.SingleSelectSearchPane + * @extends Widget + */ - getClientRegionColumnSize: function () { - return this.table.getClientRegionColumnSize(); - }, +BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { - getScrollRegionColumnSize: function () { - return this.table.getScrollRegionColumnSize(); + constants: { + height: 25, + lgap: 10, + tgap: 5 }, - getScrollRegionRowSize: function () { - return this.table.getScrollRegionRowSize(); + _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 + }); }, - hasVerticalScroll: function () { - return this.table.hasVerticalScroll(); - }, + _init: function () { + BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); + var self = this, o = this.options; - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); - }, + 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 + }); - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); - }, + 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()); + }]); + }, + value: o.value + }); + this.loader.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + this.resizer = BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.tooltipClick, + height: 0 + }, { + el: this.loader + }] + }); + this.tooltipClick.setVisible(false); }, - getVerticalScroll: function () { - return this.table.getVerticalScroll(); + 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(); + } }, - getLeftHorizontalScroll: function () { - return this.table.getLeftHorizontalScroll(); + hasMatched: function () { + return this.tooltipClick.isVisible(); }, - getRightHorizontalScroll: function () { - return this.table.getRightHorizontalScroll(); + setValue: function (v) { + this.loader.setValue(v); }, - getColumns: function () { - return this.table.getColumns(); + getValue: function () { + return this.loader.getValue(); }, - attr: function () { - BI.ResponisveTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); + empty: function () { + this.loader.empty(); }, 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(); - }); - } + this.loader.populate.apply(this.loader, arguments); } }); -BI.shortcut("bi.responsive_table", BI.ResponisveTable);/** - * 加号表示的组节点 - * Created by GUY on 2015/9/6. - * @class BI.SelectTreeFirstPlusGroupNode - * @extends BI.NodeButton + +BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; + +BI.shortcut("bi.single_select_search_pane", BI.SingleSelectSearchPane);/** + * + * @class BI.SingleSelectCombo + * @extends BI.Single */ -BI.SelectTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { +BI.SingleSelectCombo = BI.inherit(BI.Single, { + _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.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-combo", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + height: 28 }); }, + _init: function () { - BI.SelectTreeFirstPlusGroupNode.superclass._init.apply(this, arguments); + BI.SingleSelectCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.checkbox = BI.createWidget({ - type: "bi.first_tree_node_checkbox", - stopPropagation: true + + var assertShowValue = function () { + BI.isKey(self._startValue) && (self.storeValue = self._startValue); + self.trigger.getSearcher().setState(self.storeValue); + }; + this.storeValue = o.value; + // 标记正在请求数据 + 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); + }); + }, + value: this.storeValue }); - this.text = BI.createWidget({ - type: "bi.label", - textAlign: "left", - whiteSpace: "nowrap", - textHeight: o.height, + + 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(); + self._defaultState(); + }); + 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(); + 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; + }, + value: o.value + }); + + 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, - hgap: o.hgap, - text: o.text, - value: o.value, - py: o.py + cls: "single-select-trigger-icon-button" }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { - if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); + 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); }); - 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; + _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; + } }, - doRedMark: function () { - this.text.doRedMark.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); + return; + } + this._joinAll(res, callback); }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); + _setStartValue: function (value) { + this._startValue = value; + this.popup.setStartValue(value); }, - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); + setValue: function (v) { + this.storeValue = v; + this._assertValue(this.storeValue); + this.combo.setValue(this.storeValue); }, - setOpened: function (v) { - BI.SelectTreeFirstPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } + getValue: function () { + return this.storeValue; + }, + + populate: function () { + this._count = null; + this.combo.populate.apply(this.combo, arguments); } }); -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.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); +/** + * guy + * 单选框item + * @type {*|void|Object} */ -BI.SelectTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, { +BI.SingleSelectComboItem = BI.inherit(BI.BasicButton, { _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", + return BI.extend(BI.SingleSelectComboItem.superclass._defaultConfig.apply(this, arguments), { + extraCls: "bi-single-select-radio-item", logic: { dynamic: false }, - id: "", - pId: "", - readonly: true, - open: false, + hgap: 10, height: 25 }); }, _init: function () { - BI.SelectTreeLastPlusGroupNode.superclass._init.apply(this, arguments); + BI.SingleSelectComboItem.superclass._init.apply(this, arguments); var self = this, o = this.options; - this.checkbox = BI.createWidget({ - type: "bi.last_tree_node_checkbox", - stopPropagation: true + this.radio = BI.createWidget({ + type: "bi.radio" }); this.text = BI.createWidget({ type: "bi.label", + cls: "list-item-text", textAlign: "left", whiteSpace: "nowrap", textHeight: o.height, height: o.height, hgap: o.hgap, text: o.text, + keyword: o.keyword, 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 + }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, { + items: BI.LogicFactory.createLogicItemsByDirection("left", { + type: "bi.center_adapt", + items: [this.radio], + width: 36 + }, this.text) })))); }, - isOnce: function () { - return true; - }, - doRedMark: function () { this.text.doRedMark.apply(this.text, arguments); }, @@ -99735,907 +104532,1036 @@ BI.SelectTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, { }, doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); + BI.SingleSelectComboItem.superclass.doClick.apply(this, arguments); + this.radio.setSelected(this.isSelected()); }, - setOpened: function (v) { - BI.SelectTreeLastPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } + setSelected: function (v) { + BI.SingleSelectComboItem.superclass.setSelected.apply(this, arguments); + this.radio.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.shortcut("bi.single_select_combo.item", BI.SingleSelectComboItem);/** + * 选择列表 + * + * Created by GUY on 2015/11/1. + * @class BI.SingleSelectList + * @extends BI.Widget */ -BI.SelectTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, { +BI.SingleSelectList = BI.inherit(BI.Widget, { + _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", + return BI.extend(BI.SingleSelectList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-select-list", + direction: BI.Direction.Top, // toolbar的位置 logic: { - dynamic: false + dynamic: true }, - id: "", - pId: "", - readonly: true, - open: false, - height: 25 + items: [], + itemsCreator: BI.emptyFn, + hasNext: BI.emptyFn, + onLoaded: BI.emptyFn, + el: { + type: "bi.list_pane" + } }); }, _init: function () { - BI.SelectTreeMidPlusGroupNode.superclass._init.apply(this, arguments); + BI.SingleSelectList.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.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, + value: o.value }); - this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { + + this.list.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { if (type === BI.Events.CLICK) { - if (this.isSelected()) { - self.triggerExpand(); - } else { - self.triggerCollapse(); - } + self.fireEvent(BI.SingleSelectList.EVENT_CHANGE, value, obj); } + self.fireEvent(BI.Controller.EVENT_CHANGE, 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.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ + scrolly: true + }, o.logic, { + items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.list) })))); + }, - - isOnce: function () { - return true; + + hasPrev: function () { + return this.list.hasPrev(); }, - - doRedMark: function () { - this.text.doRedMark.apply(this.text, arguments); + + hasNext: function () { + return this.list.hasNext(); }, - - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); + + prependItems: function (items) { + this.list.prependItems.apply(this.list, arguments); }, - - doClick: function () { - BI.NodeButton.superclass.doClick.apply(this, arguments); + + addItems: function (items) { + this.list.addItems.apply(this.list, arguments); }, - - setOpened: function (v) { - BI.SelectTreeMidPlusGroupNode.superclass.setOpened.apply(this, arguments); - if (BI.isNotNull(this.checkbox)) { - this.checkbox.setSelected(v); - } + + 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.shortcut("bi.select_tree_mid_plus_group_node", BI.SelectTreeMidPlusGroupNode);/** - * @class BI.SelectTreeCombo - * @extends BI.Widget +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.SelectTreeCombo = BI.inherit(BI.Widget, { +BI.SingleSelectLoader = 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: "" + 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.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 - }); + BI.SingleSelectLoader.superclass._init.apply(this, arguments); - this.popup = BI.createWidget({ - type: "bi.select_level_tree", - items: o.items, - value: o.value - }); + var self = this, opts = this.options; + var hasNext = false; - this.combo = BI.createWidget({ - type: "bi.combo", + this.button_group = BI.createWidget({ + type: "bi.single_select_list", element: this, - adjustLength: 2, - el: this.trigger, - popup: { - el: this.popup - } + 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" + }] + } + } + }, 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; + }, + value: this.storeValue }); - - this.combo.on(BI.Controller.EVENT_CHANGE, function () { + 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); + }); + }, - this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { - self.setValue(self.popup.getValue()); - self.combo.hideView(); + _createItems: function (items) { + return BI.createItems(items, { + type: "bi.single_select_combo.item", + logic: this.options.logic, + height: 25, + 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 = BI.isArray(v) ? v : [v]; - this.trigger.setValue(v); - this.popup.setValue(v); + this.storeValue = v || ""; + this._assertValue(this.storeValue); + this.button_group.setValue(this.storeValue); }, getValue: function () { - return this.popup.getValue(); + return this.button_group.getValue(); + }, + + getAllButtons: function () { + return this.button_group.getAllButtons(); + }, + + empty: function () { + this.button_group.empty(); }, populate: function (items) { - this.combo.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_combo", BI.SelectTreeCombo);/** - * @class BI.SelectTreeExpander - * @extends BI.Widget +BI.SingleSelectLoader.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.single_select_loader", BI.SingleSelectLoader);/** + * 带加载的单选下拉面板 + * @class BI.SingleSelectPopupView + * @extends Widget */ -BI.SelectTreeExpander = BI.inherit(BI.Widget, { +BI.SingleSelectPopupView = 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.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 }); }, _init: function () { - BI.SelectTreeExpander.superclass._init.apply(this, arguments); - var self = this, o = this.options; + BI.SingleSelectPopupView.superclass._init.apply(this, arguments); + var self = this, opts = this.options; - 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.loader = BI.createWidget({ + type: "bi.single_select_loader", + itemsCreator: opts.itemsCreator, + valueFormatter: opts.valueFormatter, + onLoaded: opts.onLoaded, + value: opts.value }); - this.expander = BI.createWidget({ - type: "bi.expander", + this.popupView = BI.createWidget({ + type: "bi.popup_view", + stopPropagation: false, + maxWidth: opts.maxWidth, + minWidth: opts.minWidth, + maxHeight: opts.maxHeight, element: this, - trigger: o.trigger, - toggle: o.toggle, - direction: o.direction, - isDefaultInit: o.isDefaultInit, - el: this.trigger, - popup: o.popup + el: this.loader, + value: opts.value }); - 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); + + this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleSelectPopupView.EVENT_CHANGE); }); }, + setStartValue: function (v) { + this.loader.setStartValue(v); + }, + 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); - } + this.popupView.setValue(v); }, getValue: function () { - if (this.trigger.isSelected()) { - return [this.trigger.getValue()]; - } - return this.expander.getValue(); + return this.popupView.getValue(); }, populate: function (items) { - this.expander.populate(items); + this.popupView.populate.apply(this.popupView, arguments); + }, + + resetHeight: function (h) { + this.popupView.resetHeight(h); + }, + + resetWidth: function (w) { + this.popupView.resetWidth(w); } }); -BI.shortcut("bi.select_tree_expander", BI.SelectTreeExpander);/** - * @class BI.SelectTreePopup - * @extends BI.Pane +BI.SingleSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE"; + + +BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView);/** + * + * 单选下拉框 + * @class BI.SingleSelectTrigger + * @extends BI.Trigger */ -BI.SelectTreePopup = BI.inherit(BI.Pane, { +BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { - _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: 14, + rgap: 4, + lgap: 4 }, - _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.SingleSelectTrigger.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-trigger bi-border", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn, + searcher: {}, + switcher: {}, + + adapter: null, + masker: {} }); - return nodes; }, _init: function () { - BI.SelectTreePopup.superclass._init.apply(this, arguments); + BI.SingleSelectTrigger.superclass._init.apply(this, arguments); var self = this, o = this.options; + if (o.height) { + this.setHeight(o.height - 2); + } - 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.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, + value: o.value }); - - BI.createWidget({ - type: "bi.vertical", - element: this, - items: [this.tree] + this.searcher.on(BI.SingleSelectSearcher.EVENT_START, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_START); }); - - this.tree.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + this.searcher.on(BI.SingleSelectSearcher.EVENT_PAUSE, function () { + self.fireEvent(BI.SingleSelectTrigger.EVENT_PAUSE); }); - - this.tree.on(BI.LevelTree.EVENT_CHANGE, function () { - self.fireEvent(BI.SelectTreePopup.EVENT_CHANGE); + 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); }); - this.check(); + var wrapper = BI.createWidget({ + type: "bi.htape", + element: this, + items: [ + { + el: this.searcher, + width: "fill" + }, { + el: BI.createWidget(), + width: 30 + }] + }); }, - getValue: function () { - return this.tree.getValue(); + getSearcher: function () { + return this.searcher; }, - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.tree.setValue(v); + stopEditing: function () { + this.searcher.stopSearch(); }, - 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" - }); + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - _init: function () { - BI.SequenceTableDynamicNumber.superclass._init.apply(this, arguments); + setValue: function (v) { + this.searcher.setValue(v); }, - _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++; - } - return cnt; - } + getKey: function () { + return this.searcher.getKey(); + }, - 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; + getValue: function () { + return this.searcher.getValue(); } }); -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: [], +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"; - pageSize: 20 +BI.shortcut("bi.single_select_trigger", BI.SingleSelectTrigger);/** + * @author: Teller + * @createdAt: 2018/3/28 + * @Description +*/ +BI.SingleSelectInsertList = BI.inherit(BI.Widget, { + _defaultConfig: function () { + return BI.extend(BI.SingleSelectInsertList.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-multi-select-insert-list", + itemsCreator: BI.emptyFn, + valueFormatter: BI.emptyFn }); }, - _init: function () { - BI.SequenceTableListNumber.superclass._init.apply(this, arguments); + BI.SingleSelectInsertList.superclass._init.apply(this, arguments); + var self = this, o = this.options; - this.start = o.startSequence; - this.renderedCells = []; - this.renderedKeys = []; + this.storeValue = o.value || {}; - this.container = BI.createWidget({ - type: "bi.absolute", - width: 60, - scrollable: false - }); + 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.scrollContainer = BI.createWidget({ - type: "bi.vertical", - scrollable: false, - scrolly: false, - items: [this.container] + this.adapter = BI.createWidget({ + type: "bi.single_select_loader", + cls: "popup-single-select-list bi-border-left bi-border-right bi-border-bottom", + itemsCreator: o.itemsCreator, + valueFormatter: o.valueFormatter, + logic: { + dynamic: false + }, + // onLoaded: o.onLoaded, + el: {}, + value: o.value + }); + this.adapter.on(BI.SingleSelectLoader.EVENT_CHANGE, function () { + self.storeValue = this.getValue(); + assertShowValue(); + self.fireEvent(BI.SingleSelectInsertList.EVENT_CHANGE); }); - this.headerContainer = BI.createWidget({ - type: "bi.absolute", - cls: "bi-border", - width: 58, - scrollable: false + this.searcherPane = BI.createWidget({ + type: "bi.single_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); + } }); + this.searcherPane.setVisible(false); - this.layout = BI.createWidget({ - type: "bi.vtape", - element: this, - items: [{ - el: this.headerContainer, - height: o.headerRowSize * o.header.length - 2 + 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, + value: o.value, + listeners: [{ + eventName: BI.Searcher.EVENT_START, + action: function () { + self._showSearcherPane(); + self._setStartValue(""); + this.setValue(BI.deepClone(self.storeValue)); + } }, { - el: {type: "bi.layout"}, - height: 2 + eventName: BI.Searcher.EVENT_STOP, + action: function () { + self._showAdapter(); + self._setStartValue(""); + self.adapter.setValue(self.storeValue); + // 需要刷新回到初始界面,否则搜索的结果不能放在最前面 + self.adapter.populate(); + } }, { - el: this.scrollContainer + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + var keyword = this.getKeyword(); + if (this.hasMatched()) { + self._join({ + type: BI.Selection.Single, + value: [keyword] + }, function () { + if (self.storeValue.type === BI.Selection.Single) { + self.storeValue.value.pushDistinct(keyword); + } + self._showAdapter(); + self.adapter.setValue(self.storeValue); + self._setStartValue(keyword); + assertShowValue(); + self.adapter.populate(); + self._setStartValue(""); + self.fireEvent(BI.SingleSelectInsertList.EVENT_CHANGE); + }); + } else { + if (self.storeValue.type === BI.Selection.Single) { + self.storeValue.value.pushDistinct(keyword); + } + self._showAdapter(); + self.adapter.setValue(self.storeValue); + self.adapter.populate(); + if (self.storeValue.type === BI.Selection.Single) { + self.fireEvent(BI.SingleSelectInsertList.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.SingleSelectInsertList.EVENT_CHANGE); + }); + } else { + self._join(this.getValue(), function () { + assertShowValue(); + self.fireEvent(BI.SingleSelectInsertList.EVENT_CHANGE); + }); + } + } }] }); - 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) { - - } - }, - _createHeader: function () { - var o = this.options; + BI.createWidget({ + type: "bi.vtape", + element: this, + items: [{ + el: this.trigger, + height: 24 + }, { + el: this.adapter, + height: "fill" + }] + }); BI.createWidget({ type: "bi.absolute", - element: this.headerContainer, + element: this, items: [{ - el: o.sequenceHeaderCreator || { - type: "bi.table_style_cell", - cls: "sequence-table-title-cell", - styleGetter: o.headerCellStyleGetter, - text: BI.i18nText("BI-Number_Index") - }, + el: this.searcherPane, + top: 30, + bottom: 0, left: 0, - top: 0, - right: 0, - bottom: 0 + right: 0 }] }); }, - _calculateChildrenToRender: function () { + _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 = ""); + }, + + _makeMap: function (values) { + return BI.makeObject(values || []); + }, + + _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); + if (!this._allData) { + o.itemsCreator({ + type: BI.SingleSelectInsertList.REQ_GET_ALL_DATA + }, function (ob) { + self._allData = BI.map(ob.items, "value"); + digest(self._allData); + }); + } else { + digest(this._allData); + } + + 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.Single ? "pushDistinct" : "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); + }); + 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); + o.itemsCreator({ + type: BI.SingleSelectInsertList.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; } - 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)); + callback(); }); - this.renderedCells = renderedCells; - this.renderedKeys = renderedKeys; }, - _populate: function () { - this.headerContainer.empty(); - this._createHeader(); - this._layout(); - this._calculateChildrenToRender(); - }, - - setVerticalScroll: function (scrollTop) { - if (this.options.scrollTop !== scrollTop) { - this.options.scrollTop = scrollTop; - try { - this.scrollContainer.element.scrollTop(scrollTop); - } catch (e) { - - } + _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); }, - getVerticalScroll: function () { - return this.options.scrollTop; + _setStartValue: function (value) { + this._startValue = value; + this.adapter.setStartValue(value); }, - setVPage: function (v) { - v = v < 1 ? 1 : v; - var o = this.options; - this.start = (v - 1) * o.pageSize + 1; + isAllSelected: function () { + return this.adapter.isAllSelected(); }, - _restore: function () { - var o = this.options; - BI.each(this.renderedCells, function (i, cell) { - cell.el.destroy(); - }); - this.renderedCells = []; - this.renderedKeys = []; + resize: function () { + // this.trigger.getCounter().adjustView(); + // this.trigger.adjustView(); + }, + setValue: function (v) { + this.storeValue = v || ""; + this.adapter.setValue(this.storeValue); + this.trigger.setValue(this.storeValue); }, - restore: function () { - this._restore(); + getValue: function () { + return BI.deepClone(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._allData = null; + this.adapter.populate.apply(this.adapter, arguments); + this.trigger.populate.apply(this.trigger, arguments); } }); -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" - }, - - 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: [], // 二维数组 +BI.extend(BI.SingleSelectInsertList, { + REQ_GET_DATA_LENGTH: 0, + REQ_GET_ALL_DATA: -1 +}); - // 交叉表头 - crossHeader: [], - crossItems: [], +BI.SingleSelectInsertList.EVENT_CHANGE = "BI.SingleSelectInsertList.EVENT_CHANGE"; +BI.shortcut("bi.single_select_insert_list", BI.SingleSelectInsertList); +/** + * 单选输入框 + * Created by guy on 15/11/3. + * @class BI.SingleSelectEditor + * @extends Widget + */ +BI.SingleSelectEditor = BI.inherit(BI.Widget, { - showSequence: false, - startSequence: 1// 开始的序号 + _defaultConfig: function () { + return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-single-select-editor", + el: {} }); }, _init: function () { - BI.SequenceTable.superclass._init.apply(this, arguments); + BI.SingleSelectEditor.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, + this.editor = BI.createWidget(o.el, { + type: "bi.state_editor", + element: this, 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 + watermark: BI.i18nText("BI-Basic_Search"), + allowBlank: true, + value: o.value }); - 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.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; + }, + + 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: {} + }); }, - getRegionColumnSize: function () { - return this.table.getRegionColumnSize(); + _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); + }, + value: o.value + }, 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); + }); + + if(BI.isNotNull(o.value)){ + this.setState(o.value); + } }, - hasLeftHorizontalScroll: function () { - return this.table.hasLeftHorizontalScroll(); + adjustView: function () { + this.searcher.adjustView(); }, - hasRightHorizontalScroll: function () { - return this.table.hasRightHorizontalScroll(); + isSearching: function () { + return this.searcher.isSearching(); }, - setLeftHorizontalScroll: function (scrollLeft) { - this.table.setLeftHorizontalScroll(scrollLeft); + stopSearch: function () { + this.searcher.stopSearch(); }, - setRightHorizontalScroll: function (scrollLeft) { - this.table.setRightHorizontalScroll(scrollLeft); + getKeyword: function () { + return this.editor.getValue(); }, - setVerticalScroll: function (scrollTop) { - this.table.setVerticalScroll(scrollTop); - this.sequence.setVerticalScroll(scrollTop); + hasMatched: function () { + return this.searcher.hasMatched(); }, - getVerticalScroll: function () { - return this.table.getVerticalScroll(); + hasChecked: function () { + return this.searcher.getView() && this.searcher.getView().hasChecked(); }, - setVPage: function (page) { - this.sequence.setVPage && this.sequence.setVPage(page); + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); }, - setHPage: function (page) { - this.sequence.setHPage && this.sequence.setHPage(page); + 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 + "")); + } }, - attr: function () { - BI.SequenceTable.superclass.attr.apply(this, arguments); - this.table.attr.apply(this.table, arguments); - this.sequence.attr.apply(this.sequence, arguments); + setValue: function (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 @@ -100706,6 +105632,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); @@ -100726,7 +105669,7 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { _createItems: function (items) { return BI.createItems(items, { - type: "bi.single_select_radio_item", + type: "bi.single_select_combo.item", logic: { dynamic: false }, @@ -100791,7 +105734,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 @@ -100828,7 +105771,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) { @@ -100888,15 +105831,15 @@ 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 + * @class BI.SingleSelectInsertCombo * @extends BI.Single */ -BI.SingleSelectCombo = BI.inherit(BI.Single, { +BI.SingleSelectInsertCombo = BI.inherit(BI.Single, { _defaultConfig: function () { - return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { + return BI.extend(BI.SingleSelectInsertCombo.superclass._defaultConfig.apply(this, arguments), { baseCls: "bi-single-select-combo", itemsCreator: BI.emptyFn, valueFormatter: BI.emptyFn, @@ -100905,7 +105848,7 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { }, _init: function () { - BI.SingleSelectCombo.superclass._init.apply(this, arguments); + BI.SingleSelectInsertCombo.superclass._init.apply(this, arguments); var self = this, o = this.options; var assertShowValue = function () { @@ -100917,7 +105860,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: { @@ -101007,19 +105950,9 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { self.storeValue = this.getValue(); self._adjust(function () { assertShowValue(); + self._defaultState(); }); } - }, { - 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, @@ -101050,7 +105983,7 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { if (self.requesting === true) { self.wants2Quit = true; } else { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + self.fireEvent(BI.SingleSelectInsertCombo.EVENT_CONFIRM); } }); @@ -101103,7 +106036,7 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { this._assertValue(this.storeValue); this.requesting = true; o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + type: BI.SingleSelectInsertCombo.REQ_GET_ALL_DATA, keywords: keywords }, function (ob) { var values = BI.map(ob.items, "value"); @@ -101126,7 +106059,7 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { this._assertValue(res); this.requesting = true; o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, + type: BI.SingleSelectInsertCombo.REQ_GET_ALL_DATA, keywords: [this.trigger.getKey()] }, function (ob) { var items = BI.map(ob.items, "value"); @@ -101163,7 +106096,7 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { var self = this, o = this.options; if (!this._count) { o.itemsCreator({ - type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH + type: BI.SingleSelectInsertCombo.REQ_GET_DATA_LENGTH }, function (res) { self._count = res.count; adjust(); @@ -101177,7 +106110,7 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { function adjust () { if (self.wants2Quit === true) { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); + self.fireEvent(BI.SingleSelectInsertCombo.EVENT_CONFIRM); self.wants2Quit = false; } self.requesting = false; @@ -101215,399 +106148,30 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, { 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_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" - } - }); - }, - _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 - }); - - 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(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.SingleSelectLoader = 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, - itemsCreator: BI.emptyFn, - onLoaded: BI.emptyFn - }); - }, - - _init: function () { - BI.SingleSelectLoader.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: 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" - }] - } - } - }, 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; - } - }); - 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); - }); - }, - - _createItems: function (items) { - return BI.createItems(items, { - type: "bi.single_select_radio_item", - logic: this.options.logic, - height: 25, - 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) { - 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.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 - }); - }, - - _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; - } - }); - }, - - 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); + 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.SingleSelectInsertCombo, { + REQ_GET_DATA_LENGTH: 0, + REQ_GET_ALL_DATA: -1 +}); +BI.SingleSelectInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView);/** +BI.shortcut("bi.single_select_insert_combo", BI.SingleSelectInsertCombo);/** * * 单选下拉框 * @class BI.SingleSelectTrigger @@ -101644,7 +106208,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, @@ -101716,88 +106280,7 @@ BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE"; BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING"; BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW"; -BI.shortcut("bi.single_select_trigger", BI.SingleSelectTrigger);/** - * 单选输入框 - * Created by guy on 15/11/3. - * @class BI.SingleSelectEditor - * @extends Widget - */ -BI.SingleSelectEditor = BI.inherit(BI.Widget, { - - _const: { - checkSelected: BI.i18nText("BI-Check_Selected") - }, - - _defaultConfig: function () { - return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-select-editor", - el: {} - }); - }, - - _init: function () { - BI.SingleSelectEditor.superclass._init.apply(this, arguments); - var self = this, o = this.options; - this.editor = BI.createWidget(o.el, { - type: "bi.state_editor", - element: this, - height: o.height, - watermark: BI.i18nText("BI-Basic_Search"), - allowBlank: true - }); - - this.editor.on(BI.Controller.EVENT_CHANGE, function () { - self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); - }); - - this.editor.on(BI.StateEditor.EVENT_PAUSE, function () { - self.fireEvent(BI.SingleSelectEditor.EVENT_PAUSE); - }); - this.editor.on(BI.StateEditor.EVENT_CLICK_LABEL, function () { - - }); - }, - - focus: function () { - this.editor.focus(); - }, - - blur: function () { - this.editor.blur(); - }, - - setState: function (state) { - this.editor.setState(state); - }, - - setValue: function (v) { - this.editor.setValue(v); - }, - - getValue: function () { - var v = this.editor.getState(); - if (BI.isArray(v) && v.length > 0) { - return v[v.length - 1]; - } - return ""; - - }, - - getKeywords: function () { - var val = this.editor.getLastValidValue(); - var keywords = val.match(/[\S]+/g); - if (BI.isEndWithBlank(val)) { - return keywords.concat([" "]); - } - return keywords; - }, - - populate: function (items) { - - } -}); -BI.SingleSelectEditor.EVENT_PAUSE = "SingleSelectEditor.EVENT_PAUSE"; -BI.shortcut("bi.single_select_editor", BI.SingleSelectEditor);/** +BI.shortcut("bi.single_select_add_trigger", BI.SingleSelectTrigger);/** * searcher * Created by guy on 15/11/3. * @class BI.SingleSelectSearcher @@ -101837,7 +106320,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(); @@ -101935,2330 +106418,3346 @@ 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.shortcut("bi.single_select_add_searcher", BI.SingleSelectSearcher);/** + * Created by User on 2017/11/16. */ -BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, { - +BI.SignTextEditor = 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 + 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.SingleSelectSearchLoader.superclass._init.apply(this, arguments); + 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(); + }, - var self = this, opts = this.options; - var hasNext = false; + _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)); + }, - this.button_group = BI.createWidget({ - type: "bi.single_select_list", + _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, - 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" - }] - } + 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: "" + }); + }, + _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(); + + 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; } - }, - 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; + 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.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.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); + 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: { - dynamic: false - }, - 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); }); - }, - _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); + function optimizeSize (s) { + return BI.clamp(s, 0, self._getGrayTrackLength()); } - 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); + _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%" + }] + }); }, - getValue: function () { - return this.button_group.getValue(); + _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; }, - getAllButtons: function () { - return this.button_group.getAllButtons(); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - empty: function () { - this.button_group.empty(); + _setLabelPosition: function (percent) { + this.label.element.css({left: percent + "%"}); }, - populate: function (items) { - this.button_group.populate.apply(this.button_group, arguments); + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); }, - resetHeight: function (h) { - this.button_group.resetHeight(h); + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setLabelPosition(percent); + this._setBlueTrack(percent); }, - 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 + _setVisible: function (visible) { + this.slider.setVisible(visible); + this.label.setVisible(visible); }, - _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 - }); + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - _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); + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - 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(); - } + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, - hasMatched: function () { - return this.tooltipClick.isVisible(); + getValue: function () { + return this.value; }, setValue: function (v) { - this.loader.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.loader.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; + } }, - empty: function () { - this.loader.empty(); + reset: function () { + this._setVisible(false); + this.enable = false; + this.value = ""; + this.min = 0; + this.max = 0; + this._setBlueTrack(0); + }, - populate: function (items) { - this.loader.populate.apply(this.loader, arguments); + 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.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; - -BI.shortcut("bi.single_select_search_add_pane", BI.SingleSelectSearchPane);/** - * - * @class BI.SingleSelectCombo - * @extends BI.Single +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; - - var assertShowValue = function () { - BI.isKey(self._startValue) && (self.storeValue = self._startValue); - self.trigger.getSearcher().setState(self.storeValue); - }; - this.storeValue = ""; - // 标记正在请求数据 - this.requesting = false; + BI.SingleSliderLabel.superclass._init.apply(this, arguments); - 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); - }); - } - }); + var self = this, o = this.options; + var c = this._constant; + this.enable = false; + this.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.grayTrack = BI.createWidget({ + type: "bi.layout", + cls: "gray-track", + height: 6 }); - 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.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_CHANGE, function (value, obj) { - self.storeValue = this.getValue(); - assertShowValue(); + this.slider = BI.createWidget({ + type: "bi.single_slider_button" }); - this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { - if (!self.combo.isViewVisible()) { - self.combo.showView(); - } + 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.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(); - }); + 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; } - }, - hideChecker: function (e) { - return triggerBtn.element.find(e.target).length === 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.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.label = BI.createWidget({ + type: "bi.label", + height: c.HEIGHT, + width: c.EDITOR_WIDTH - 2 }); - 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(); - } - }); + this._setVisible(false); BI.createWidget({ type: "bi.absolute", element: this, items: [{ - el: this.combo, + 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, - right: 0, - top: 0, - bottom: 0 + width: "100%" }, { - el: triggerBtn, - right: 0, + 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, - bottom: 0 + left: 0, + width: "100%" }] }); }, - _defaultState: function () { - this.trigger.stopEditing(); - this.combo.hideView(); + _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()); + } }, - _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%" + }] + }); }, - _makeMap: function (values) { - return BI.makeObject(values || []); + _checkValidation: function (v) { + return BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max); }, - _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); - }); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); + }, - 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); - } + _setLabelPosition: function (percent) { + this.label.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); - }); + _setSliderPosition: function (percent) { + this.slider.element.css({left: 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(); + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setLabelPosition(percent); + this._setBlueTrack(percent); + }, - } + _setVisible: function (visible) { + this.slider.setVisible(visible); + this.label.setVisible(visible); + }, - function adjust () { - if (self.wants2Quit === true) { - self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); - self.wants2Quit = false; - } - self.requesting = false; - } + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - _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); + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - _setStartValue: function (value) { - this._startValue = value; - this.popup.setStartValue(value); + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); + }, + + 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; + } + } }, - getValue: function () { - return this.storeValue; + 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 () { - 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.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.extend(BI.SingleSelectCombo, { - REQ_GET_DATA_LENGTH: 0, - REQ_GET_ALL_DATA: -1 -}); + _constant: { + HEIGHT: 28, + SLIDER_WIDTH_HALF: 15, + SLIDER_WIDTH: 30, + SLIDER_HEIGHT: 30, + TRACK_HEIGHT: 24 + }, -BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; + props: { + baseCls: "bi-single-slider-normal bi-slider-track", + minMax: { + min: 0, + max: 100 + } + // color: "#3f8ce8" + }, -BI.shortcut("bi.single_select_add_combo", BI.SingleSelectCombo);/** - * - * 单选下拉框 - * @class BI.SingleSelectTrigger - * @extends BI.Trigger - */ + 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); -BI.SingleSelectTrigger = BI.inherit(BI.Trigger, { + 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); + } + }); - constants: { - height: 14, - rgap: 4, - lgap: 4 + 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; + 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 + }, + top: 8, + left: 0, + width: "100%" + }], + ref: function (ref) { + self.track = ref; + } + }; }, - _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: {}, + _checkValidation: function (v) { + return !(BI.isNull(v) || v < this.min || v > this.max); + }, - adapter: null, - masker: {} - }); + _setBlueTrack: function (percent) { + this.blueTrack.element.css({width: percent + "%"}); }, - _init: function () { - BI.SingleSelectTrigger.superclass._init.apply(this, arguments); + _setSliderPosition: function (percent) { + this.slider.element.css({left: percent + "%"}); + }, - var self = this, o = this.options; - if (o.height) { - this.setHeight(o.height - 2); - } + _setAllPosition: function (percent) { + this._setSliderPosition(percent); + this._setBlueTrack(percent); + }, - 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); - }); + _setVisible: function (visible) { + this.slider.setVisible(visible); + }, - var wrapper = BI.createWidget({ - type: "bi.htape", - element: this, - items: [ - { - el: this.searcher, - width: "fill" - }, { - el: BI.createWidget(), - width: 30 - }] - }); + _getGrayTrackLength: function () { + return this.grayTrack.element[0].scrollWidth; }, - getSearcher: function () { - return this.searcher; + _getValueByPercent: function (percent) { + var thousandth = BI.parseInt(percent * 10); + return (((this.max - this.min) * thousandth) / 1000 + this.min); }, - stopEditing: function () { - this.searcher.stopSearch(); + _getPercentByValue: function (v) { + return (v - this.min) * 100 / (this.max - this.min); }, - setAdapter: function (adapter) { - this.searcher.setAdapter(adapter); + getValue: function () { + return this.value; }, setValue: function (v) { - this.searcher.setValue(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; + } + } }, - getKey: function () { - return this.searcher.getKey(); + 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.searcher.getValue(); + 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.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.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.searcher.on(BI.Searcher.EVENT_CHANGE, function () { - self.fireEvent(BI.SingleSelectSearcher.EVENT_CHANGE, arguments); + + this.combo.on(BI.Controller.EVENT_CHANGE, function () { + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); - this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { - var keywords = this.getKeywords(); - self.fireEvent(BI.SingleSelectSearcher.EVENT_SEARCHING, keywords); + this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { + self.fireEvent(BI.SingleTreeCombo.EVENT_BEFORE_POPUPVIEW, arguments); }); - }, - - 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 + "")); - } + this.popup.on(BI.SingleTreePopup.EVENT_CHANGE, function () { + self.setValue(self.popup.getValue()); + self.combo.hideView(); + self.fireEvent(BI.SingleTreeCombo.EVENT_CHANGE); + }); }, - setValue: function (ob) { - this.setState(ob); - this.searcher.setValue(ob); + populate: function (items) { + this.combo.populate(items); }, - getKey: function () { - return this.editor.getValue(); + setValue: function (v) { + v = BI.isArray(v) ? v : [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); + return this.popup.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.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.SignTextEditor = BI.inherit(BI.Widget, { + +BI.SingleTreePopup = BI.inherit(BI.Pane, { + _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 + 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.SignTextEditor.superclass._init.apply(this, arguments); + BI.SingleTreePopup.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, + + this.tree = BI.createWidget({ + type: "bi.level_tree", + expander: { + isDefaultInit: true + }, + items: o.items, 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); - }); + chooseType: BI.Selection.Single }); + BI.createWidget({ - type: "bi.absolute", + type: "bi.vertical", element: this, - items: [{ - el: this.text, - left: 0, - right: 0, - top: 0, - bottom: 0 - }] + items: [this.tree] }); - this.editor.on(BI.Controller.EVENT_CHANGE, function () { + + this.tree.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.tree.on(BI.LevelTree.EVENT_CHANGE, function () { + self.fireEvent(BI.SingleTreePopup.EVENT_CHANGE); }); - 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)); + this.check(); }, - _showInput: function () { - this.editor.visible(); - this.text.invisible(); + getValue: function () { + return this.tree.getValue(); }, - _showHint: function () { - this.editor.invisible(); - this.text.visible(); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.tree.setValue(v); }, - setTitle: function (title) { - this.text.setTitle(title); - }, + populate: function (items) { + BI.SingleTreePopup.superclass.populate.apply(this, arguments); + this.tree.populate(items); + } +}); - setWarningTitle: function (title) { - this.text.setWarningTitle(title); +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: "" + }); }, - focus: function () { - this._showInput(); - this.editor.focus(); + _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 + }); }, - blur: function () { - this.editor.blur(); - this._showHint(); - this._checkText(); + _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; + } + }); }, - doRedMark: function () { - if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { - return; - } - this.text.doRedMark.apply(this.text, arguments); + setValue: function (v) { + v = BI.isArray(v) ? v : [v]; + this.options.value = v; + this.trigger.setValue(v); + this._checkTitle(); }, - unRedMark: function () { - this.text.unRedMark.apply(this.text, arguments); + getValue: function () { + return this.options.value || []; }, - doHighLight: function () { - if (this.editor.getValue() === "" && BI.isKey(this.options.watermark)) { - return; - } - this.text.doHighLight.apply(this.text, arguments); + populate: function (items) { + BI.SingleTreeTrigger.superclass.populate.apply(this, arguments); + this.trigger.populate(items); + } + +}); + +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: [] + }); }, - 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.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: "" + BI.createWidget({ + type: "bi.horizontal_auto", + element: this, + items: [ + self.label + ] }); }, - _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 + _createCombo: function (v) { + var self = this; + var combo = BI.createWidget({ + type: "bi.dynamic_date_combo", + value: v }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 + combo.on(BI.DynamicDateCombo.EVENT_ERROR, function () { + self._clearTitle(); + BI.Bubbles.hide("error"); + self.element.removeClass(self.constants.timeErrorCls); + self.fireEvent(BI.DateInterval.EVENT_ERROR); }); - 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 + 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); + } }); - 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); + + 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); } }); - 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); + + 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); } }); - this.label.element.hover(function () { - self.label.element.removeClass("bi-border").addClass("bi-border"); - }, function () { - self.label.element.removeClass("bi-border"); + 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] }); - 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); + }, + _compare: function (smallDate, bigDate) { + smallDate = BI.parseDateTime(smallDate, "%Y-%X-%d").print("%Y-%X-%d"); + bigDate = BI.parseDateTime(bigDate, "%Y-%X-%d").print("%Y-%X-%d"); + return BI.isNotNull(smallDate) && BI.isNotNull(bigDate) && smallDate > bigDate; + }, + _setTitle: function (v) { + this.left.setTitle(v); + this.right.setTitle(v); + this.label.setTitle(v); + }, + _clearTitle: function () { + this.left.setTitle(""); + this.right.setTitle(""); + this.label.setTitle(""); + }, + setValue: function (date) { + date = date || {}; + this.left.setValue(date.start); + this.right.setValue(date.end); + }, + getValue: function () { + return {start: this.left.getValue(), end: this.right.getValue()}; + } +}); +BI.DateInterval.EVENT_VALID = "EVENT_VALID"; +BI.DateInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.DateInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.shortcut("bi.date_interval", BI.DateInterval);/** + * Created by Baron on 2015/10/19. + */ +BI.TimeInterval = BI.inherit(BI.Single, { + constants: { + height: 25, + 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" + }); + }, + _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: "-" }); - 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%" - }] - }); - }, - - _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); - }, document); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; + 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_time_combo", + value: v + }); + combo.on(BI.DynamicDateTimeCombo.EVENT_ERROR, function () { + self._clearTitle(); + BI.Bubbles.hide("error"); + 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.left.isValid() && self.right.isValid() && 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()); - } - }, + combo.on(BI.DynamicDateTimeCombo.EVENT_FOCUS, function () { + BI.Bubbles.hide("error"); + var smallDate = self.left.getKey(), bigDate = self.right.getKey(); + if (self.left.isValid() && self.right.isValid() && 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); + } + }); - _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(); }); - }, - _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.left.isValid() && self.right.isValid() && 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; - }, - - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); + }); + return combo; }, - - _setLabelPosition: function (percent) { - this.label.element.css({left: percent + "%"}); + _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; }, - - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); + _checkVoid: function (obj) { + return !BI.checkDateVoid(obj.year, obj.month, obj.day, this.constants.DATE_MIN_VALUE, this.constants.DATE_MAX_VALUE)[0]; }, - - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setLabelPosition(percent); - this._setBlueTrack(percent); + _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] + }); }, - - _setVisible: function (visible) { - this.slider.setVisible(visible); - this.label.setVisible(visible); + _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; }, - - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + _setTitle: function (v) { + this.left.setTitle(v); + this.right.setTitle(v); + this.label.setTitle(v); }, - - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); + _clearTitle: function () { + this.left.setTitle(""); + this.right.setTitle(""); + this.label.setTitle(""); }, - - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); + setValue: function (date) { + date = date || {}; + this.left.setValue(date.start); + this.right.setValue(date.end); }, - getValue: function () { - return this.value; + 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" }, - 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; - } - } + 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 + }; }, - 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; - } + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.value = ""; - this.min = 0; - this.max = 0; - this._setBlueTrack(0); - + setValue: function (v) { + v = v || {year: 0}; + this.item.setValue(this._createValue(BI.DynamicDateCard.TYPE.YEAR, v.year)); }, - 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 () { + var value = this.item.getValue(); + return { + year: (value.offset === 0 ? -value.value : value.value) + }; } }); -BI.SingleSlider.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_slider", BI.SingleSlider);/** - * Created by Urthur on 2017/9/12. +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.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.StaticYearCard = BI.inherit(BI.Widget, { + _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.StaticYearCard.superclass._defaultConfig.apply(this, arguments), { + baseCls: "bi-year-card", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31" // 最大日期 }); }, - _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); - } - }); - this.label = BI.createWidget({ - type: "bi.label", - height: c.HEIGHT, - width: c.EDITOR_WIDTH - 2 - }); + _createYearCalendar: function (v) { + var o = this.options, y = this._year; - 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%" - }] + 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; }, - _draggable: function (widget) { + _init: function () { + BI.StaticYearCard.superclass._init.apply(this, arguments); 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); - }, document); - 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.selectedYear = this._year = BI.getDate().getFullYear(); - _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.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(); + } }] }); - }, - _checkValidation: function (v) { - return BI.isNumeric(v) && !(BI.isNull(v) || v < this.min || v > this.max); - }, + 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(); + } + }] + }); - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); - }, + 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), - _setLabelPosition: function (percent) { - this.label.element.css({left: percent + "%"}); - }, + afterCardShow: function () { + this.setValue(self.selectedYear); + var calendar = this.getSelectedCard(); + self.backBtn.setEnable(!calendar.isFrontYear()); + self.preBtn.setEnable(!calendar.isFinalYear()); + } + }); - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); - }, + 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); + }); - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setLabelPosition(percent); - this._setBlueTrack(percent); + if(BI.isKey(o.value)){ + this.setValue(o.value); + } }, - _setVisible: function (visible) { - this.slider.setVisible(visible); - this.label.setVisible(visible); + _checkLeftValid: function () { + var o = this.options; + var valid = true; + this.backBtn.setEnable(valid); + return valid; }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + _checkRightValid: function () { + var o = this.options; + var valid = true; + this.preBtn.setEnable(valid); + return valid; }, - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); + getValue: function () { + return { + year: this.selectedYear + }; }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); - }, + 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, { - getValue: function () { - return this.value; + props: { + baseCls: "bi-year-combo bi-border", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, - 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; + _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 (v > this.max) { - this.value = this.max; + 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 (v < this.min) { - this.value = this.min; + self._checkDynamicValue(self.storeValue); + 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); }, - 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; + _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; } }, - reset: function () { - this._setVisible(false); - this.enable = false; - this.value = ""; - this.min = 0; - this.max = 0; - this._setBlueTrack(0); + setValue: function (v) { + this.storeValue = v; + this.trigger.setValue(v); + this._checkDynamicValue(v); }, - 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 this.storeValue; } + }); -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.DynamicYearCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; +BI.DynamicYearCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.dynamic_year_combo", BI.DynamicYearCombo); - _constant: { - HEIGHT: 28, - SLIDER_WIDTH_HALF: 15, - SLIDER_WIDTH: 30, - SLIDER_HEIGHT: 30, - TRACK_HEIGHT: 24 +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-single-slider-normal bi-slider-track", - minMax: { - min: 0, - max: 100 - } - // color: "#3f8ce8" + baseCls: "bi-year-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 }, 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); - } - }); - + var self = this, opts = this.options; + this.storeValue = {type: BI.DynamicYearCombo.Static}; return { - type: "bi.absolute", - element: this, + type: "bi.vtape", items: [{ + el: this._getTabJson() + }, { el: { - type: "bi.vertical", - items: [{ - type: "bi.absolute", - items: [{ - el: track, - width: "100%", - height: c.TRACK_HEIGHT + 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: 7, - height: c.TRACK_HEIGHT + }, { + 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: 3, - left: 0, - width: "100%" - }, { - el: sliderVertical, - top: 0, - left: 0, - width: "100%" + height: 24 }] }; }, - _draggable: function (widget) { + _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; - 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); - }, document); - widget.element.on("mousedown", function (event) { - if(!widget.isEnabled()) { - return; - } - defaultSize = this.offsetLeft; - optimizeSize(defaultSize); - mouseMoveTracker.captureMouseMoves(event); - }); + 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; + } + } + }] + }; + }, - function optimizeSize (s) { - return BI.clamp(s, 0, self._getGrayTrackLength()); + 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; } }, - _createTrack: function () { - var self = this; - var c = this._constant; - this.grayTrack = BI.createWidget({ - type: "bi.layout", - cls: "gray-track", - height: 6 + 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 + }, + + _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 }); - this.blueTrack = BI.createWidget({ - type: "bi.layout", - cls: "blue-track bi-high-light-background", - height: 6 + }, + _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 () { + return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + } }); - if (this.options.color) { - this.blueTrack.element.css({"background-color": this.options.color}); - } + 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 + } + }; + } - return { - type: "bi.absolute", + 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.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%" - }], - ref: function (ref) { - self.track = ref; - } - }; + width: o.height + }, { + el: { + type: "bi.trigger_icon_button", + width: o.height + }, + width: o.height + }] + }); + this.setValue(o.value); }, - _checkValidation: function (v) { - return !(BI.isNull(v) || v < this.min || v > this.max); + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year) && BI.parseInt(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; }, - _setBlueTrack: function (percent) { - this.blueTrack.element.css({width: percent + "%"}); + _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)); }, - _setSliderPosition: function (percent) { - this.slider.element.css({left: percent + "%"}); + 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.setTitle(value.year); + break; + } }, - _setAllPosition: function (percent) { - this._setSliderPosition(percent); - this._setBlueTrack(percent); + getValue: function () { + return this.storeValue; }, - _setVisible: function (visible) { - this.slider.setVisible(visible); + 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" }, - _getGrayTrackLength: function () { - return this.grayTrack.element[0].scrollWidth; + 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 + }; }, - _getValueByPercent: function (percent) { - var thousandth = BI.parseInt(percent * 10); - return (((this.max - this.min) * thousandth) / 1000 + this.min); + _createValue: function (type, v) { + return { + dateType: type, + value: Math.abs(v), + offset: v > 0 ? 1 : 0 + }; }, - _getPercentByValue: function (v) { - return (v - this.min) * 100 / (this.max - this.min); + 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 () { - return this.value; + 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: {} }, - 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; - } - } + _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 + }; + }); + }); }, - 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; - } + render: function () { + var self = this, o = this.options; + return { + type: "bi.vertical", + items: [{ + type: "bi.year_picker", + ref: function () { + self.yearPicker = this; + }, + behaviors: o.behaviors, + 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); + } + }] + }] + }; }, - 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 (obj.year === 0 || obj.month === 0 || BI.checkDateVoid(obj.year, obj.month, 1, o.min, o.max)[0]) { + var year = obj.year || BI.getDate().getFullYear(); + this.selectedYear = year; + this.selectedMonth = ""; + this.yearPicker.setValue(year); + this.month.setValue(); + } 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.storeTriggerValue = ""; + 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_KEY_DOWN, function () { + self.combo.isViewVisible() && self.combo.hideView(); + }); + 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; + } + 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()); + } + self._checkDynamicValue(self.storeValue); + self.fireEvent(BI.DynamicYearMonthCombo.EVENT_CONFIRM); + }); + this.trigger.on(BI.DynamicYearMonthTrigger.EVENT_FOCUS, function () { + self.storeTriggerValue = self.trigger.getKey(); + 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({type: BI.DynamicYearMonthCombo.Static, value: {year: date.getFullYear(), month: date.getMonth() + 1}}); + 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(); + return this.storeValue; }, - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.tree.setValue(v); + getKey: function () { + return this.trigger.getKey(); }, - populate: function (items) { - BI.SingleTreePopup.superclass.populate.apply(this, arguments); - this.tree.populate(items); + isValid: function () { + return this.trigger.isValid(); } -}); -BI.SingleTreePopup.EVENT_CHANGE = "EVENT_CHANGE"; -BI.shortcut("bi.single_level_tree", BI.SingleTreePopup);/** - * @class BI.SingleTreeTrigger +}); +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 + }, -BI.SingleTreeTrigger = BI.inherit(BI.Trigger, { + props: { + baseCls: "bi-year-month-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 + }, - _defaultConfig: function () { - return BI.extend(BI.SingleTreeTrigger.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-single-tree-trigger", - height: 24, - text: "", - items: [], - value: "" - }); + 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.SingleTreeTrigger.superclass._init.apply(this, arguments); + _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; - - this.trigger = BI.createWidget({ - type: "bi.select_text_trigger", - element: this, - text: o.text, - items: o.items, - height: o.height, - value: o.value - }); + 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_Month"), + 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() + 1}); + 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; + } + } + }] + }; }, - _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; - } - }); + 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; + } }, - setValue: function (v) { - v = BI.isArray(v) ? v : [v]; - this.options.value = v; - this.trigger.setValue(v); - this._checkTitle(); + 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 }, - getValue: function () { - return this.options.value || []; + props: { + extraCls: "bi-year-month-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, - populate: function (items) { - BI.SingleTreeTrigger.superclass.populate.apply(this, arguments); - this.trigger.populate(items); - } - -}); + _init: function () { + BI.DynamicYearMonthTrigger.superclass._init.apply(this, arguments); + var o = this.options; -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, { + this.yearEditor = this._createEditor(true); + this.monthEditor = this._createEditor(false); - _defaultConfig: function () { - return BI.extend(BI.SwitchTree.superclass._defaultConfig.apply(this, arguments), { - baseCls: "bi-switch-tree", - items: [] + 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); }, - _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) + _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 === "" || ((BI.isPositiveInteger(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.i18nText("BI-Year_Trigger_Invalid_Text"); + }, + hgap: c.hgap, + vgap: c.vgap, + allowBlank: true + }); + editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicYearMonthTrigger.EVENT_KEY_DOWN); + }); + 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); + } + var monthValue = self.monthEditor.getValue(); + self.storeValue = { + type: BI.DynamicDateCombo.Static, + value: { + year: self.yearEditor.getValue(), + month: BI.isEmptyString(self.monthEditor.getValue()) ? "" : monthValue + } + }; + self.setTitle(self._getStaticTitle(self.storeValue.value)); + + 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; }, - _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; - } + _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; }, - _removeIsParent: function (items) { - BI.each(items, function (i, item) { - BI.isNotNull(item.isParent) && delete item.isParent; - }); - return items; + _autoSwitch: function (v) { + if (BI.checkDateLegal(v)) { + if (v.length === 4 && this._yearCheck(v)) { + this.monthEditor.focus(); + } + } }, - 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; + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year) && BI.parseInt(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")); } + if(BI.isNotNull(obj.month) && BI.parseInt(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")); + } + return value; }, - setSelect: function (v) { - this.tab.setSelect(v); + _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)); }, - getSelect: function () { - return this.tab.getSelect(); + _getStaticTitle: function (value) { + value = value || {}; + var yearStr = (BI.isNull(value.year) || BI.isEmptyString(value.year)) ? "" : value.year; + var monthStr = (BI.isNull(value.month) || BI.isEmptyString(value.month)) ? "" : "-" + value.month; + return yearStr + monthStr; }, 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); + this.setTitle(this._getStaticTitle(value)); 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(); + }, + + isValid: function () { + return this.yearEditor.isValid() && this.monthEditor.isValid(); } }); -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.TimeInterval = BI.inherit(BI.Single, { +BI.DynamicYearMonthTrigger.EVENT_VALID = "EVENT_VALID"; +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.DynamicYearMonthTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.shortcut("bi.dynamic_year_month_trigger", BI.DynamicYearMonthTrigger);BI.YearMonthInterval = BI.inherit(BI.Single, { constants: { - height: 25, + height: 26, width: 25, lgap: 15, offset: -15, @@ -104266,15 +109765,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); @@ -104320,105 +109818,106 @@ BI.TimeInterval = BI.inherit(BI.Single, { }, _createCombo: function (v) { - var self = this; + var self = this, o = this.options; var combo = BI.createWidget({ - type: "bi.multidate_combo", - value: v + type: "bi.dynamic_year_month_combo", + behaviors: o.behaviors, + value: v, + listeners: [{ + eventName: BI.DynamicYearMonthCombo.EVENT_BEFORE_POPUPVIEW, + action: function () { + self.fireEvent(BI.YearMonthInterval.EVENT_BEFORE_POPUPVIEW); + } + }] }); - combo.on(BI.MultiDateCombo.EVENT_ERROR, function () { + combo.on(BI.DynamicYearMonthCombo.EVENT_ERROR, function () { self._clearTitle(); + BI.Bubbles.hide("error"); self.element.removeClass(self.constants.timeErrorCls); - self.fireEvent(BI.TimeInterval.EVENT_ERROR); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); }); - combo.on(BI.MultiDateCombo.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)) { + if (self.left.isValid() && self.right.isValid() && 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); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); } else { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); } }); - combo.on(BI.MultiDateCombo.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)) { + if (self.left.isValid() && self.right.isValid() && 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); + self.fireEvent(BI.YearMonthInterval.EVENT_ERROR); } else { self._clearTitle(); self.element.removeClass(self.constants.timeErrorCls); } }); - combo.on(BI.MultiDateCombo.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.MultiDateCombo.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.MultiDateCombo.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)) { + if (self.left.isValid() && self.right.isValid() && 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").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) { @@ -104440,64 +109939,246 @@ BI.TimeInterval = BI.inherit(BI.Single, { 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);/** - * 年份下拉框 +BI.YearMonthInterval.EVENT_VALID = "EVENT_VALID"; +BI.YearMonthInterval.EVENT_ERROR = "EVENT_ERROR"; +BI.YearMonthInterval.EVENT_CHANGE = "EVENT_CHANGE"; +BI.YearMonthInterval.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; +BI.shortcut("bi.year_month_interval", BI.YearMonthInterval);/** + * 年份展示面板 * - * Created by GUY on 2015/8/28. - * @class BI.YearCombo - * @extends BI.Widget + * Created by GUY on 2015/9/2. + * @class BI.YearCard + * @extends BI.Trigger */ -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.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; + }, + behaviors: o.behaviors, + 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 (obj.quarter === 0 || obj.year === 0 || BI.checkDateVoid(obj.year, obj.quarter, 1, o.min, o.max)[0]) { + var year = obj.year || BI.getDate().getFullYear(); + this.selectedYear = year; + this.selectedQuarter = ""; + this.yearPicker.setValue(year); + this.quarter.setValue(); + } 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.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; + self.storeTriggerValue = ""; 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.DynamicYearQuarterTrigger.EVENT_KEY_DOWN, function () { + self.combo.isViewVisible() && self.combo.hideView(); }); - 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(); + 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()); } - self.fireEvent(BI.YearCombo.EVENT_CONFIRM); + self._checkDynamicValue(self.storeValue); + self.fireEvent(BI.DynamicYearQuarterCombo.EVENT_CONFIRM); + }); + this.trigger.on(BI.DynamicYearQuarterTrigger.EVENT_FOCUS, function () { + self.storeTriggerValue = self.trigger.getKey(); }); this.combo = BI.createWidget({ type: "bi.combo", - element: this, - destroyWhenHide: true, isNeedAdjustHeight: false, isNeedAdjustWidth: false, el: this.trigger, @@ -104505,16 +110186,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({type: BI.DynamicYearMonthCombo.Static, value: {year: date.getFullYear(), quarter: date.getQuarter()}}); + 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, @@ -104525,390 +110228,472 @@ 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.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.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);/** - * 年份展示面板 - * - * 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" // 最大日期 - }); +}); +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 }, - _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-year-quarter-popup", + behaviors: {}, + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期, + width: 180, + height: 240 }, - _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); - }); + 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 + }] + }; + }, - if(BI.isKey(o.value)){ - this.setValue(o.value); + _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-%Q"); + this.textButton.setValue(date); + this.textButton.setEnable(false); } }, - getValue: function () { - return this.selectedYear; + _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_Quarter"), + 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) { - 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); + 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.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, { +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") + vgap: 2 }, - _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: { + extraCls: "bi-year-quarter-trigger", + min: "1900-01-01", // 最小日期 + max: "2099-12-31", // 最大日期 + height: 24 }, + _init: function () { - BI.YearTrigger.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); + + 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; - this.editor = BI.createWidget({ + var 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]); + if(isYear) { + return v === "" || (BI.isPositiveInteger(v) && !BI.checkDateVoid(v, 1, 1, o.min, o.max)[0]); + } + return v === "" || ((BI.isPositiveInteger(v) && v >= 1 && v <= 4) && !BI.checkDateVoid(BI.getDate().getFullYear(), v, 1, o.min, o.max)[0]); }, - quitChecker: function (v) { + quitChecker: function () { return false; }, + errorText: function (v) { + return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + }, + watermark: BI.i18nText("BI-Basic_Unrestricted"), hgap: c.hgap, vgap: c.vgap, - allowBlank: true, - errorText: c.errorText, - value: o.value + title: "", + allowBlank: true }); - this.editor.on(BI.SignEditor.EVENT_FOCUS, function () { - self.fireEvent(BI.YearTrigger.EVENT_FOCUS); + editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_KEY_DOWN); }); - this.editor.on(BI.SignEditor.EVENT_STOP, function () { - self.fireEvent(BI.YearTrigger.EVENT_STOP); + editor.on(BI.SignEditor.EVENT_FOCUS, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_FOCUS); }); - 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); + editor.on(BI.SignEditor.EVENT_STOP, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_STOP); }); - this.editor.on(BI.SignEditor.EVENT_SPACE, function () { - if (self.editor.isValid()) { - self.editor.blur(); + editor.on(BI.SignEditor.EVENT_CONFIRM, function () { + var value = editor.getValue(); + if (BI.isNotNull(value)) { + editor.setValue(value); } - }); - 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: { - 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 + var quarterValue = self.quarterEditor.getValue(); + self.storeValue = { + type: BI.DynamicYearQuarterCombo.Static, + value: { + year: self.yearEditor.getValue(), + quarter: BI.isEmptyString(self.quarterEditor.getValue()) ? "" : quarterValue } - ] - }); - }, - 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 - }); - }, - _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 - }); + }; + self.setTitle(self._getStaticTitle(self.storeValue.value)); - this.year.on(BI.YearCombo.EVENT_CONFIRM, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_CONFIRM); + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_CONFIRM); }); - this.year.on(BI.YearCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW); + editor.on(BI.SignEditor.EVENT_SPACE, function () { + if (editor.isValid()) { + editor.blur(); + } }); - - this.month.on(BI.MonthCombo.EVENT_CONFIRM, function () { - self.getValue(); - self.fireEvent(BI.YearMonthCombo.EVENT_CONFIRM); + editor.on(BI.SignEditor.EVENT_START, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_START); }); - this.month.on(BI.MonthCombo.EVENT_BEFORE_POPUPVIEW, function () { - self.fireEvent(BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW); + editor.on(BI.SignEditor.EVENT_ERROR, function () { + self.fireEvent(BI.DynamicYearQuarterTrigger.EVENT_ERROR); }); - - BI.createWidget({ - type: "bi.center", - element: this, - hgap: 5, - items: [this.year, this.month] + editor.on(BI.SignEditor.EVENT_CHANGE, function () { + if(isYear) { + self._autoSwitch(editor.getValue()); + } }); + return editor; }, - setValue: function (v) { - v = v || {}; - this.month.setValue(v.month); - this.year.setValue(v.year); + _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 { - year: this.year.getValue(), - month: this.month.getValue() - }; - } -}); -BI.YearMonthCombo.EVENT_CONFIRM = "EVENT_CONFIRM"; -BI.YearMonthCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW"; -BI.shortcut("bi.year_month_combo", BI.YearMonthCombo);/** - * 年份 + 月份下拉框 - * - * @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 - }); + _autoSwitch: function (v) { + if (BI.checkDateLegal(v)) { + if (v.length === 4 && this._yearCheck(v)) { + this.quarterEditor.focus(); + } + } }, - _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); - }); + _getStaticTitle: function (value) { + value = value || {}; + var yearStr = (BI.isNull(value.year) || BI.isEmptyString(value.year)) ? "" : value.year; + var quarterStr = (BI.isNull(value.quarter) || BI.isEmptyString(value.quarter)) ? "" : "-" + value.quarter; + return yearStr + quarterStr; + }, - BI.createWidget({ - type: "bi.center", - element: this, - hgap: 5, - items: [this.year, this.quarter] - }); + _getText: function (obj) { + var value = ""; + if(BI.isNotNull(obj.year) && BI.parseInt(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")); + } + if(BI.isNotNull(obj.quarter) && BI.parseInt(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")); + } + return value; + }, + _setInnerValue: function (date, text) { + var dateStr = date.print("%Y-%Q"); + 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); + this.setTitle(this._getStaticTitle(value)); + break; + } }, getValue: function () { - return { - year: this.year.getValue(), - quarter: this.quarter.getValue() - }; + return this.storeValue; + }, + + getKey: function () { + return this.yearEditor.getValue() + "-" + this.quarterEditor.getValue(); } }); -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.DynamicYearQuarterTrigger.EVENT_KEY_DOWN = "EVENT_KEY_DOWN"; +BI.shortcut("bi.dynamic_year_quarter_trigger", BI.DynamicYearQuarterTrigger);/** * 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 * 封装了字段处理逻辑 * @@ -104936,7 +110721,8 @@ BI.AbstractAllValueChooser = BI.inherit(BI.Widget, { var text = v; if (BI.isNotNull(this.items)) { BI.some(this.items, function (i, item) { - if (item.value === v) { + // 把value都换成字符串 + if (item.value + "" === v) { text = item.text; return true; } @@ -105046,7 +110832,9 @@ BI.AllValueChooserCombo = BI.inherit(BI.AbstractAllValueChooser, { return val.value || []; }, - populate: function () { + populate: function (items) { + // 直接用combo的populate不会作用到AbstractValueChooser上 + this.items = items; this.combo.populate.apply(this, arguments); } }); @@ -105107,7 +110895,9 @@ BI.AllValueChooserPane = BI.inherit(BI.AbstractAllValueChooser, { return val.value || []; }, - populate: function () { + populate: function (items) { + // 直接用combo的populate不会作用到AbstractValueChooser上 + this.items = items; this.list.populate.apply(this.list, arguments); } }); @@ -105125,6 +110915,19 @@ BI.shortcut("bi.all_value_chooser_pane", BI.AllValueChooserPane);BI.AbstractTree }); }, + _valueFormatter: function (v) { + var text = v; + if (BI.isNotNull(this.items)) { + BI.some(this.items, function (i, item) { + if (item.value + "" === v) { + text = item.text; + return true; + } + }); + } + return text; + }, + _initData: function (items) { this.items = items; var nodes = BI.Tree.treeFormat(items); @@ -105798,6 +111601,7 @@ BI.TreeValueChooserCombo = BI.inherit(BI.AbstractTreeValueChooser, { type: "bi.multi_tree_combo", element: this, itemsCreator: BI.bind(this._itemsCreator, this), + valueFormatter: BI.bind(this._valueFormatter, this), width: o.width, height: o.height }); @@ -105898,7 +111702,8 @@ BI.AbstractValueChooser = BI.inherit(BI.Widget, { var text = v; if (BI.isNotNull(this.items)) { BI.some(this.items, function (i, item) { - if (item.value === v) { + // 把value都换成字符串 + if (item.value + "" === v) { text = item.text; return true; } @@ -105931,9 +111736,6 @@ BI.AbstractValueChooser = BI.inherit(BI.Widget, { } function call (items) { var keywords = (options.keywords || []).slice(); - if (options.keyword) { - keywords.push(options.keyword); - } BI.each(keywords, function (i, kw) { var search = BI.Func.getSearchResult(items, kw); items = search.match.concat(search.find); @@ -106013,7 +111815,9 @@ BI.ValueChooserCombo = BI.inherit(BI.AbstractValueChooser, { }; }, - populate: function () { + populate: function (items) { + // 直接用combo的populate不会作用到AbstractValueChooser上 + this.items = items; this.combo.populate.apply(this, arguments); } }); @@ -106068,12 +111872,240 @@ BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, { }; }, - populate: function () { + populate: function (items) { + // 直接用combo的populate不会作用到AbstractValueChooser上 + this.items = items; this.list.populate.apply(this.list, arguments); } }); BI.ValueChooserPane.EVENT_CHANGE = "ValueChooserPane.EVENT_CHANGE"; -BI.shortcut("bi.value_chooser_pane", BI.ValueChooserPane);(function () { +BI.shortcut("bi.value_chooser_pane", BI.ValueChooserPane);;(function () { + function initWatch (vm, watch) { + vm._watchers || (vm._watchers = []); + for (var key in watch) { + var handler = watch[key]; + if (BI.isArray(handler)) { + for (var i = 0; i < handler.length; i++) { + vm._watchers.push(createWatcher(vm, key, handler[i])); + } + } else { + vm._watchers.push(createWatcher(vm, key, handler)); + } + } + } + + function createWatcher (vm, keyOrFn, handler) { + return Fix.watch(vm.model, keyOrFn, _.bind(handler, vm), { + store: vm.store + }); + } + + var target = null; + var targetStack = []; + + function pushTarget (_target) { + if (target) targetStack.push(target); + Fix.Model.target = target = _target; + } + + function popTarget () { + Fix.Model.target = target = targetStack.pop(); + } + + var context = null; + var contextStack = []; + + function pushContext (_context) { + if (context) contextStack.push(context); + Fix.Model.context = context = _context; + } + + function popContext () { + Fix.Model.context = context = contextStack.pop(); + } + + var oldWatch = Fix.watch; + Fix.watch = function (model, expOrFn, cb, options) { + if (BI.isPlainObject(cb)) { + options = cb; + cb = cb.handler; + } + if (typeof cb === "string") { + cb = model[cb]; + } + return oldWatch.call(this, model, expOrFn, function () { + options && options.store && pushTarget(options.store); + var res = cb.apply(this, arguments); + options && options.store && popTarget(); + return res; + }, options); + }; + + function findStore (widget) { + if (target != null) { + return target; + } + widget = widget || context; + var p = widget; + while (p) { + if (p instanceof Fix.Model || p.store || p.__cacheStore) { + break; + } + p = p._parent || (p.options && p.options.element); + } + if (p) { + if (p instanceof Fix.Model) { + return widget.__cacheStore = p; + } + widget.__cacheStore = p.store || p.__cacheStore; + return p.__cacheStore || p.store; + } + } + + var _create = BI.createWidget; + BI.createWidget = function (item, options, context) { + var pushed = false; + if (BI.isWidget(options)) { + pushContext(options); + pushed = true; + } else if (context != null) { + pushContext(context); + pushed = true; + } + var result = _create.apply(this, arguments); + pushed && popContext(); + return result; + }; + + var populate = BI.Loader.prototype.populate; + BI.Loader.prototype.populate = function () { + pushContext(this); + var result = populate.apply(this, arguments); + popContext(); + return result; + }; + + var _init = BI.Widget.prototype._init; + BI.Widget.prototype._init = function () { + var self = this; + var needPop = false; + if (window.Fix && this._store) { + var store = findStore(this.options.context || this.options.element); + if (store) { + pushTarget(store); + needPop = true; + } + this.store = this._store(); + this.store && (this.store._widget = this); + needPop && popTarget(); + needPop = false; + pushTarget(this.store); + if (this.store instanceof Fix.Model) { + this.model = this.store.model; + } else { + this.model = this.store; + } + needPop = true; + } + _init.apply(this, arguments); + needPop && popTarget(); + }; + + var _render = BI.Widget.prototype._render; + BI.Widget.prototype._render = function () { + var needPop = false; + if (window.Fix && this._store) { + needPop = true; + pushTarget(this.store); + initWatch(this, this.watch); + } + _render.apply(this, arguments); + needPop && popTarget(); + }; + + var unMount = BI.Widget.prototype.__d; + BI.Widget.prototype.__d = function () { + unMount.apply(this, arguments); + this.store && BI.isFunction(this.store.destroy) && this.store.destroy(); + BI.each(this._watchers, function (i, unwatches) { + unwatches = BI.isArray(unwatches) ? unwatches : [unwatches]; + BI.each(unwatches, function (j, unwatch) { + unwatch(); + }); + }); + this._watchers && (this._watchers = []); + if (this.store) { + this.store._parent && (this.store._parent = null); + this.store._widget && (this.store._widget = null); + this.store = null; + } + delete this.__cacheStore; + }; + + _.each(["_mount"], function (name) { + var old = BI.Widget.prototype[name]; + old && (BI.Widget.prototype[name] = function () { + this.store && pushTarget(this.store); + var res = old.apply(this, arguments); + this.store && popTarget(); + return res; + }); + }); + + if (BI.isIE9Below()) { + _.each(["each", "map", "reduce", "reduceRight", "find", "filter", "reject", "every", "all", "some", "any", "max", "min", + "sortBy", "groupBy", "indexBy", "countBy", "partition", + "keys", "allKeys", "values", "pairs", "invert", + "mapObject", "findKey", "pick", "omit", "tap"], function (name) { + var old = BI[name]; + BI[name] = function (obj, fn) { + return typeof fn === "function" ? old(obj, function (key, value) { + if (!(key in Fix.$$skipArray)) { + return fn.apply(this, arguments); + } + }) : old.apply(this, arguments); + }; + }); + BI.isEmpty = function (ob) { + if (BI.isPlainObject(ob) && ob.__ob__) { + return BI.keys(ob).length === 0; + } + return _.isEmpty(ob); + }; + BI.keys = function (ob) { + var keys = _.keys(ob); + var nKeys = []; + for (var i = 0; i < keys.length; i++) { + if (!(keys[i] in Fix.$$skipArray)) { + nKeys.push(keys[i]); + } + } + return nKeys; + }; + BI.values = function (ob) { + var keys = BI.keys(obj); + var length = keys.length; + var values = []; + for (var i = 0; i < length; i++) { + values[i] = obj[keys[i]]; + } + return values; + }; + BI.size = function (ob) { + if (BI.isPlainObject(ob) && ob.__ob__) { + return BI.keys(ob).length; + } + return _.size(ob); + }; + BI.isEmptyObject = function (ob) { + return BI.size(ob) === 0; + }; + BI.deepClone = function (ob) { + return Fix.toJSON(ob); + }; + } + BI.watch = Fix.watch; +}());(function () { var Events = { // Bind an event to a `callback` function. Passing `"all"` will bind @@ -106657,9 +112689,7 @@ BI.shortcut("bi.value_chooser_pane", BI.ValueChooserPane);(function () { // Create the default BI.history. BI.history = new History; -}());BI.serverURL = "${serverURL}"; -BI.servletURL = "${servletURL}"; -BI.resourceURL = "file?path=/com/fr/web/ui/resource"; +}());BI.resourceURL = "file?path=/com/fr/web/ui/resource"; BI.i18n = { "BI-Multi_Date_Quarter_End": "季度末", "BI-Multi_Date_Month_Begin": "月初", @@ -106742,7 +112772,6 @@ BI.i18n = { "BI-Multi_Date_Quarter_Next": "个季度后", "BI-Basic_October": "十月", "BI-Basic_Simple_Friday": "五", - "BI-Primary_Key": "主键", "BI-Basic_Save": "保存", "BI-Numerical_Interval_Number_Value": "请保证前面的数值小于/等于后面的数值", "BI-Previous_Page": "上一页", @@ -106772,7 +112801,7 @@ BI.i18n = { "BI-Transparent_Color": "透明", "BI-Basic_Simple_Monday": "一", "BI-Multi_Date_Year_End": "年末", - "BI-Time_Interval_Error_Text": "请保证前面时间小于/等于后面的时间", + "BI-Time_Interval_Error_Text": "请保证开始时间早于/等于结束时间", "BI-Basic_Time": "时间", "BI-Basic_OK": "确定", "BI-Basic_Sure": "确定", @@ -106780,5 +112809,46 @@ BI.i18n = { "BI-Multi_Date_Year_Prev": "年前", "BI-Tiao_Data": "条数据", "BI-Basic_Italic": "斜体", - "BI-Basic_Union_Relation": "联合关联" + "BI-Basic_Dynamic_Title": "动态时间", + "BI-Basic_Year": "年", + "BI-Basic_Single_Quarter": "季", + "BI-Basic_Month": "月", + "BI-Basic_Week": "周", + "BI-Basic_Day": "天", + "BI-Basic_Work_Day": "工作日", + "BI-Basic_Front": "前", + "BI-Basic_Behind": "后", + "BI-Basic_Empty": "空", + "BI-Basic_Month_End": "月末", + "BI-Basic_Month_Begin": "月初", + "BI-Basic_Year_End": "年末", + "BI-Basic_Year_Begin": "年初", + "BI-Basic_Quarter_End": "季末", + "BI-Basic_Quarter_Begin": "季初", + "BI-Basic_Week_End": "周末", + "BI-Basic_Week_Begin": "周初", + "BI-Basic_Current_Day": "当天", + "BI-Basic_Begin_Start": "初", + "BI-Basic_End_Stop": "末", + "BI-Basic_Current_Year": "今年", + "BI-Basic_Year_Fen": "年份", + "BI-Basic_Current_Month": "本月", + "BI-Basic_Current_Quarter": "本季度", + "BI-Basic_Year_Month": "年月", + "BI-Basic_Year_Quarter": "年季度", + "BI-Basic_Input_Can_Not_Null": "输入框不能为空", + "BI-Basic_Date_Time_Error_Text": "日期格式示例:2015-3-11 00:00:00", + "BI-Basic_Input_From_To_Number": "请输入{R1}的数值", + "BI-Basic_Or": "或", + "BI-Basic_And": "且", + "BI-Conf_Add_Formula": "添加公式", + "BI-Conf_Add_Condition": "添加条件", + "BI-Conf_Formula_And": "且公式条件", + "BI-Conf_Formula_Or": "或公式条件", + "BI-Conf_Condition_And": "且条件", + "BI-Conf_Condition_Or": "或条件", + "BI-Microsoft_YaHei": "微软雅黑", + "BI-Apple_Light": "苹方-light", + "BI-Font_Family": "字体", + "BI-Basic_Please_Input_Content": "请输入内容" }; \ No newline at end of file diff --git a/dist/widget.js b/dist/widget.js index 4f9731047..3084a8c75 100644 --- a/dist/widget.js +++ b/dist/widget.js @@ -3718,6 +3718,25 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger return BI.i18nText("BI-Date_Trigger_Error_Text"); } return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + }, + title: function () { + var storeValue = self.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = self._getText(value); + var date = BI.getDate(); + date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = date.print("%Y-%x-%e"); + return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + return ""; + } + return BI.getDate(value.year, (value.month - 1), value.day).print("%Y-%X-%d"); + } } }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { @@ -3817,11 +3836,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger BI.parseDateTime(v, "%Y-%x").print("%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; }, - _setInnerValue: function (date, text) { + _setInnerValue: function (date) { 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) { @@ -3894,12 +3912,10 @@ BI.shortcut("bi.dynamic_date_popup", BI.DynamicDatePopup);BI.DynamicDateTrigger if (BI.isNull(value) || BI.isNull(value.day)) { this.editor.setState(""); this.editor.setValue(""); - this.setTitle(""); } else { var dateStr = BI.getDate(value.year, (value.month - 1), value.day).print("%Y-%X-%d"); this.editor.setState(dateStr); this.editor.setValue(dateStr); - this.setTitle(dateStr); } break; } @@ -4656,6 +4672,25 @@ BI.extend(BI.DynamicDateTimeSelect, { return BI.i18nText("BI-Basic_Date_Time_Error_Text"); } return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + }, + title: function () { + var storeValue = self.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = self._getText(value); + var date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = date.print("%Y-%x-%e %H:%M:%S"); + return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + return ""; + } + return BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, + value.second || 0).print("%Y-%X-%d %H:%M:%S"); + } } }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { @@ -4758,11 +4793,10 @@ BI.extend(BI.DynamicDateTimeSelect, { BI.parseDateTime(v, "%Y-%x").print("%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; }, - _setInnerValue: function (date, text) { + _setInnerValue: function (date) { 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) { @@ -4835,13 +4869,11 @@ BI.extend(BI.DynamicDateTimeSelect, { if (BI.isNull(value) || BI.isNull(value.day)) { this.editor.setState(""); this.editor.setValue(""); - this.setTitle(""); } else { var dateStr = BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, value.second || 0).print("%Y-%X-%d %H:%M:%S"); this.editor.setState(dateStr); this.editor.setValue(dateStr); - this.setTitle(dateStr); } break; } diff --git a/src/widget/dynamicdate/dynamicdate.trigger.js b/src/widget/dynamicdate/dynamicdate.trigger.js index 25d5b55fb..0b343fb21 100644 --- a/src/widget/dynamicdate/dynamicdate.trigger.js +++ b/src/widget/dynamicdate/dynamicdate.trigger.js @@ -41,6 +41,25 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { return BI.i18nText("BI-Date_Trigger_Error_Text"); } return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + }, + title: function () { + var storeValue = self.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = self._getText(value); + var date = BI.getDate(); + date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = date.print("%Y-%x-%e"); + return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + return ""; + } + return BI.getDate(value.year, (value.month - 1), value.day).print("%Y-%X-%d"); + } } }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { @@ -140,11 +159,10 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { BI.parseDateTime(v, "%Y-%x").print("%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; }, - _setInnerValue: function (date, text) { + _setInnerValue: function (date) { 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) { @@ -217,12 +235,10 @@ BI.DynamicDateTrigger = BI.inherit(BI.Trigger, { if (BI.isNull(value) || BI.isNull(value.day)) { this.editor.setState(""); this.editor.setValue(""); - this.setTitle(""); } else { var dateStr = BI.getDate(value.year, (value.month - 1), value.day).print("%Y-%X-%d"); this.editor.setState(dateStr); this.editor.setValue(dateStr); - this.setTitle(dateStr); } break; } diff --git a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js index 9dd9d305c..dda72788d 100644 --- a/src/widget/dynamicdatetime/dynamicdatetime.trigger.js +++ b/src/widget/dynamicdatetime/dynamicdatetime.trigger.js @@ -41,6 +41,25 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { return BI.i18nText("BI-Basic_Date_Time_Error_Text"); } return BI.i18nText("BI-Year_Trigger_Invalid_Text"); + }, + title: function () { + var storeValue = self.storeValue || {}; + var type = storeValue.type || BI.DynamicDateCombo.Static; + var value = storeValue.value; + switch (type) { + case BI.DynamicDateCombo.Dynamic: + var text = self._getText(value); + var date = BI.DynamicDateHelper.getCalculation(value); + var dateStr = date.print("%Y-%x-%e %H:%M:%S"); + return BI.isEmptyString(text) ? dateStr : (text + ":" + dateStr); + case BI.DynamicDateCombo.Static: + default: + if (BI.isNull(value) || BI.isNull(value.day)) { + return ""; + } + return BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, + value.second || 0).print("%Y-%X-%d %H:%M:%S"); + } } }); this.editor.on(BI.SignEditor.EVENT_KEY_DOWN, function () { @@ -143,11 +162,10 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { BI.parseDateTime(v, "%Y-%x").print("%Y-%x") === v)) && dateStr >= this.options.min && dateStr <= this.options.max; }, - _setInnerValue: function (date, text) { + _setInnerValue: function (date) { 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) { @@ -220,13 +238,11 @@ BI.DynamicDateTimeTrigger = BI.inherit(BI.Trigger, { if (BI.isNull(value) || BI.isNull(value.day)) { this.editor.setState(""); this.editor.setValue(""); - this.setTitle(""); } else { var dateStr = BI.getDate(value.year, (value.month - 1), value.day, value.hour || 0, value.minute || 0, value.second || 0).print("%Y-%X-%d %H:%M:%S"); this.editor.setState(dateStr); this.editor.setValue(dateStr); - this.setTitle(dateStr); } break; }