From ec62df1867f7d5d6e7cf6783401412274c824dae Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 15 May 2017 11:20:37 +0800 Subject: [PATCH 1/2] add --- bi/polyfill.js | 93 +++++++++++++++++++ demo/js/config/widget.js | 8 ++ .../tree/demo.multilayer_select_tree_combo.js | 69 ++++++++++++++ docs/demo.js | 78 +++++++++++++++- docs/polyfill.js | 93 +++++++++++++++++++ 5 files changed, 340 insertions(+), 1 deletion(-) create mode 100644 bi/polyfill.js create mode 100644 demo/js/widget/tree/demo.multilayer_select_tree_combo.js create mode 100644 docs/polyfill.js diff --git a/bi/polyfill.js b/bi/polyfill.js new file mode 100644 index 0000000000..854ed288f6 --- /dev/null +++ b/bi/polyfill.js @@ -0,0 +1,93 @@ +if(![].indexOf){ + /** + * 检查指定的值是否在数组中 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].indexOf = function (o) { + for (var i = 0, len = this.length; i < len; i++) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} +if(![].lastIndexOf){ + /** + * 检查指定的值是否在数组中 + * ie67不支持数组的这个方法 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].lastIndexOf = function (o) { + for (var len = this.length, i = len - 1; i >= 0; i--) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +}/** + * 特殊情况 + * Created by wang on 15/6/23. + */ +//解决console未定义问题 guy +window.console = window.console || (function () { + var c = {}; + c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile + = c.clear = c.exception = c.trace = c.assert = function () { + }; + return c; + })(); +/* + * 前端缓存 + */ +window.localStorage || (window.localStorage = { + items: {}, + setItem: function (k, v) { + BI.Cache.addCookie(k, v); + }, + getItem: function (k) { + return BI.Cache.getCookie(k); + }, + removeItem: function (k) { + BI.Cache.deleteCookie(k); + }, + key: function () { + + }, + clear: function () { + this.items = {}; + } +});//修复ie9下sort方法的bug +!function (window) { + var ua = window.navigator.userAgent.toLowerCase(), + reg = /msie|applewebkit.+safari/; + if (reg.test(ua)) { + var _sort = Array.prototype.sort; + Array.prototype.sort = function (fn) { + if (!!fn && typeof fn === 'function') { + if (this.length < 2) { + return this; + } + var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; + for (; i < l; i++) { + for (j = i + 1; j < l; j++) { + t = fn.call(this, this[i], this[j]); + r = (typeof t === 'number' ? t : + !!t ? 1 : 0) > 0; + if (r === true) { + tmp = this[i]; + this[i] = this[j]; + this[j] = tmp; + } + } + } + return this; + } else { + return _sort.call(this); + } + }; + } +}(window); \ No newline at end of file diff --git a/demo/js/config/widget.js b/demo/js/config/widget.js index 423892244a..003cadc123 100644 --- a/demo/js/config/widget.js +++ b/demo/js/config/widget.js @@ -21,6 +21,14 @@ Demo.WIDGET_CONFIG = [{ pId: 401, text: "bi.page_table", value: "demo.page_table" +}, { + id: 402, + pId: 4, + text: "tree" +}, { + pId: 402, + text: "bi.multilayer_select_tree_combo", + value: "demo.multilayer_select_tree_combo" }, { pId: 4, text: "bi.multi_select_combo", diff --git a/demo/js/widget/tree/demo.multilayer_select_tree_combo.js b/demo/js/widget/tree/demo.multilayer_select_tree_combo.js new file mode 100644 index 0000000000..580587289f --- /dev/null +++ b/demo/js/widget/tree/demo.multilayer_select_tree_combo.js @@ -0,0 +1,69 @@ +/** + * Created by User on 2017/3/22. + */ +Demo.MultiSelectCombo = BI.inherit(BI.Widget, { + props: {}, + + render: function (vessel) { + var TREEWITHCHILDREN = [{ + id: -1, value: "根目录", text: "根目录", children: [ + { + id: 1, value: "第一级目录1", text: "第一级目录1", children: [ + {id: 11, value: "第二级文件1", text: "第二级文件1"}, + { + id: 12, value: "第二级目录2", text: "第二级目录2", children: [ + { + id: 121, value: "第三级目录1", text: "第三级目录1", children: [ + { + id: 1211, value: "第四级目录1", text: "第四级目录1", children: [ + {id: 12111, value: "第五级文件1", text: "第五级文件1"} + ] + } + ] + }, + {id: 122, value: "第三级文件1", text: "第三级文件1"} + ] + } + ] + }, + { + id: 2, value: "第一级目录2", text: "第一级目录2", children: [ + { + id: 21, value: "第二级目录3", text: "第二级目录3", children: [ + { + id: 211, value: "第三级目录2", text: "第三级目录2", children: [ + {id: 2111, value: "第四级文件1", text: "第四级文件1"} + ] + }, + {id: 212, value: "第三级文件2", text: "第三级文件2"} + ] + }, + {id: 22, value: "第二级文件2", text: "第二级文件2"} + ] + } + ] + }]; + var items = BI.deepClone(TREEWITHCHILDREN); + var combo = BI.createWidget({ + type: "bi.multilayer_select_tree_combo", + itemsCreator: function (op, callback) { + debugger; + } + }); + + combo.populate(); + return { + type: "bi.vertical", + items: [combo, { + type: "bi.button", + width: 100, + text: "getValue", + handler: function () { + BI.Msg.alert("", JSON.stringify(combo.getValue())); + } + }], + vgap: 100 + } + } +}); +BI.shortcut("demo.multilayer_select_tree_combo", Demo.MultiSelectCombo); \ No newline at end of file diff --git a/docs/demo.js b/docs/demo.js index a5ba8e5426..3c93eef27b 100644 --- a/docs/demo.js +++ b/docs/demo.js @@ -3112,6 +3112,14 @@ Demo.COMPONENT_CONFIG = [{ pId: 401, text: "bi.page_table", value: "demo.page_table" +}, { + id: 402, + pId: 4, + text: "tree" +}, { + pId: 402, + text: "bi.multilayer_select_tree_combo", + value: "demo.multilayer_select_tree_combo" }, { pId: 4, text: "bi.multi_select_combo", @@ -6725,7 +6733,75 @@ BI.shortcut("demo.responsive_table", Demo.Func);Demo.Func = BI.inherit(BI.Widget }) } }); -BI.shortcut("demo.sequence_table", Demo.Func);Demo.CONFIG = Demo.CORE_CONFIG.concat(Demo.BASE_CONFIG).concat(Demo.CASE_CONFIG).concat(Demo.WIDGET_CONFIG).concat(Demo.COMPONENT_CONFIG).concat(Demo.CHART_CONFIG); +BI.shortcut("demo.sequence_table", Demo.Func);/** + * Created by User on 2017/3/22. + */ +Demo.MultiSelectCombo = BI.inherit(BI.Widget, { + props: {}, + + render: function (vessel) { + var TREEWITHCHILDREN = [{ + id: -1, value: "根目录", text: "根目录", children: [ + { + id: 1, value: "第一级目录1", text: "第一级目录1", children: [ + {id: 11, value: "第二级文件1", text: "第二级文件1"}, + { + id: 12, value: "第二级目录2", text: "第二级目录2", children: [ + { + id: 121, value: "第三级目录1", text: "第三级目录1", children: [ + { + id: 1211, value: "第四级目录1", text: "第四级目录1", children: [ + {id: 12111, value: "第五级文件1", text: "第五级文件1"} + ] + } + ] + }, + {id: 122, value: "第三级文件1", text: "第三级文件1"} + ] + } + ] + }, + { + id: 2, value: "第一级目录2", text: "第一级目录2", children: [ + { + id: 21, value: "第二级目录3", text: "第二级目录3", children: [ + { + id: 211, value: "第三级目录2", text: "第三级目录2", children: [ + {id: 2111, value: "第四级文件1", text: "第四级文件1"} + ] + }, + {id: 212, value: "第三级文件2", text: "第三级文件2"} + ] + }, + {id: 22, value: "第二级文件2", text: "第二级文件2"} + ] + } + ] + }]; + var items = BI.deepClone(TREEWITHCHILDREN); + var combo = BI.createWidget({ + type: "bi.multilayer_select_tree_combo", + itemsCreator: function (op, callback) { + debugger; + } + }); + + combo.populate(); + return { + type: "bi.vertical", + items: [combo, { + type: "bi.button", + width: 100, + text: "getValue", + handler: function () { + BI.Msg.alert("", JSON.stringify(combo.getValue())); + } + }], + vgap: 100 + } + } +}); +BI.shortcut("demo.multilayer_select_tree_combo", Demo.MultiSelectCombo);Demo.CONFIG = Demo.CORE_CONFIG.concat(Demo.BASE_CONFIG).concat(Demo.CASE_CONFIG).concat(Demo.WIDGET_CONFIG).concat(Demo.COMPONENT_CONFIG).concat(Demo.CHART_CONFIG); Demo.CONSTANTS = { diff --git a/docs/polyfill.js b/docs/polyfill.js new file mode 100644 index 0000000000..854ed288f6 --- /dev/null +++ b/docs/polyfill.js @@ -0,0 +1,93 @@ +if(![].indexOf){ + /** + * 检查指定的值是否在数组中 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].indexOf = function (o) { + for (var i = 0, len = this.length; i < len; i++) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +} +if(![].lastIndexOf){ + /** + * 检查指定的值是否在数组中 + * ie67不支持数组的这个方法 + * @param {Object} o 要检查的值 + * @return {Number} o在数组中的索引(如果不在数组中则返回-1) + */ + [].lastIndexOf = function (o) { + for (var len = this.length, i = len - 1; i >= 0; i--) { + if (_.isEqual(o, this[i])) { + return i; + } + } + return -1; + } +}/** + * 特殊情况 + * Created by wang on 15/6/23. + */ +//解决console未定义问题 guy +window.console = window.console || (function () { + var c = {}; + c.log = c.warn = c.debug = c.info = c.error = c.time = c.dir = c.profile + = c.clear = c.exception = c.trace = c.assert = function () { + }; + return c; + })(); +/* + * 前端缓存 + */ +window.localStorage || (window.localStorage = { + items: {}, + setItem: function (k, v) { + BI.Cache.addCookie(k, v); + }, + getItem: function (k) { + return BI.Cache.getCookie(k); + }, + removeItem: function (k) { + BI.Cache.deleteCookie(k); + }, + key: function () { + + }, + clear: function () { + this.items = {}; + } +});//修复ie9下sort方法的bug +!function (window) { + var ua = window.navigator.userAgent.toLowerCase(), + reg = /msie|applewebkit.+safari/; + if (reg.test(ua)) { + var _sort = Array.prototype.sort; + Array.prototype.sort = function (fn) { + if (!!fn && typeof fn === 'function') { + if (this.length < 2) { + return this; + } + var i = 0, j = i + 1, l = this.length, tmp, r = false, t = 0; + for (; i < l; i++) { + for (j = i + 1; j < l; j++) { + t = fn.call(this, this[i], this[j]); + r = (typeof t === 'number' ? t : + !!t ? 1 : 0) > 0; + if (r === true) { + tmp = this[i]; + this[i] = this[j]; + this[j] = tmp; + } + } + } + return this; + } else { + return _sort.call(this); + } + }; + } +}(window); \ No newline at end of file From 2eb467d3962f0c1133aaf0fc21d6a3a6199477b7 Mon Sep 17 00:00:00 2001 From: guy Date: Mon, 15 May 2017 13:11:37 +0800 Subject: [PATCH 2/2] update --- bi/base.js | 5 + bi/widget.js | 173 +++++++++++------- .../tree/demo.multilayer_select_tree_combo.js | 5 +- docs/base.js | 5 + docs/demo.js | 5 +- docs/widget.js | 173 +++++++++++------- src/base/combination/switcher.js | 5 + src/widget/multiselect/multiselect.combo.js | 67 ++++--- src/widget/multiselect/multiselect.trigger.js | 5 + .../trigger/searcher.multiselect.js | 4 + .../trigger/switcher.checkselected.js | 4 + src/widget/multitree/multi.tree.combo.js | 89 +++++---- .../multitree/trigger/searcher.multi.tree.js | 4 + 13 files changed, 329 insertions(+), 215 deletions(-) diff --git a/bi/base.js b/bi/base.js index 9476b3d857..11cd5fd79f 100644 --- a/bi/base.js +++ b/bi/base.js @@ -4642,6 +4642,11 @@ BI.Switcher = BI.inherit(BI.Widget, { return this.popupView ? this.popupView.getValue() : []; }, + setAdapter: function (adapter) { + this.options.adapter = adapter; + BI.Maskers.remove(this.getName()); + }, + isViewVisible: function () { return this.isEnabled() && this.switcher.isEnabled() && (this.options.adapter ? BI.Maskers.isVisible(this.getName()) : (this.popupView && this.popupView.isVisible())); diff --git a/bi/widget.js b/bi/widget.js index bb810d8d12..a1c55f5e09 100644 --- a/bi/widget.js +++ b/bi/widget.js @@ -9559,38 +9559,11 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { self.trigger.getCounter().setButtonChecked(self.storeValue); }; this.storeValue = {}; - this.popup = BI.createWidget({ - type: 'bi.multi_select_popup_view', - 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(); - }); - } - }); - - this.popup.on(BI.MultiSelectPopupView.EVENT_CHANGE, function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - }); - }); - this.popup.on(BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM, function () { - self._defaultState(); - }); - this.popup.on(BI.MultiSelectPopupView.EVENT_CLICK_CLEAR, function () { - self.setValue(); - self._defaultState(); - }); this.trigger = BI.createWidget({ type: "bi.multi_select_trigger", height: o.height, - adapter: this.popup, + // adapter: this.popup, masker: { offset: { left: 1, @@ -9675,7 +9648,43 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { toggle: false, el: this.trigger, adjustLength: 1, - popup: this.popup, + 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(); + }); + } + }, hideChecker: function (e) { return triggerBtn.element.find(e.target).length === 0; } @@ -10272,6 +10281,11 @@ BI.MultiSelectTrigger = BI.inherit(BI.Trigger, { this.numberCounter.hideView(); }, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + this.numberCounter.setAdapter(adapter); + }, + setValue: function (ob) { this.searcher.setValue(ob); this.numberCounter.setValue(ob); @@ -10816,6 +10830,10 @@ BI.MultiSelectSearcher = BI.inherit(BI.Widget, { return this.searcher.getView() && this.searcher.getView().hasChecked(); }, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + }, + setState: function (ob) { var o = this.options; ob || (ob = {}); @@ -10937,6 +10955,10 @@ BI.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, { this.switcher.hideView(); }, + setAdapter: function (adapter) { + this.switcher.setAdapter(adapter); + }, + setValue: function (v) { this.switcher.setValue(v); }, @@ -11406,7 +11428,6 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { } }, - _defaultConfig: function () { return BI.extend(BI.MultiTreeCombo.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-tree-combo', @@ -11420,31 +11441,13 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { var self = this, o = this.options; - this.popup = BI.createWidget({ - type: 'bi.multi_tree_popup_view', - itemsCreator: o.itemsCreator, - onLoaded: function () { - BI.nextTick(function () { - self.trigger.getCounter().adjustView(); - self.trigger.getSearcher().adjustView(); - }); - } - }); var isInit = false; var want2showCounter = false; - this.popup.on(BI.MultiTreePopup.EVENT_AFTERINIT, function () { - self.trigger.getCounter().adjustView(); - isInit = true; - if (want2showCounter === true) { - showCounter(); - } - }); - this.trigger = BI.createWidget({ type: "bi.multi_select_trigger", height: o.height, - adapter: this.popup, + // adapter: this.popup, masker: { offset: this.constants.offset }, @@ -11469,7 +11472,53 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { toggle: false, el: this.trigger, adjustLength: 1, - popup: this.popup + 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() ? {1: 1} : {} + }; + self.trigger.getSearcher().setState(val); + self.trigger.getCounter().setButtonChecked(val); + } + }, { + eventName: BI.MultiTreePopup.EVENT_CLICK_CONFIRM, + action: function () { + self._defaultState(); + } + }, { + 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.storeValue = {value: {}}; @@ -11532,24 +11581,6 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { this.getSearcher().setState(val); this.getCounter().setButtonChecked(val); }); - this.popup.on(BI.MultiTreePopup.EVENT_CHANGE, function () { - change = true; - var val = { - type: BI.Selection.Multi, - value: this.hasChecked() ? {1: 1} : {} - }; - self.trigger.getSearcher().setState(val); - self.trigger.getCounter().setButtonChecked(val); - }); - - this.popup.on(BI.MultiTreePopup.EVENT_CLICK_CONFIRM, function () { - self._defaultState(); - }); - this.popup.on(BI.MultiTreePopup.EVENT_CLICK_CLEAR, function () { - clear = true; - self.setValue(); - self._defaultState(); - }); this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { if (isSearching()) { @@ -11618,7 +11649,7 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { this.combo.hideView(); }, - setEnable: function(v){ + setEnable: function (v) { this.combo.setEnable(v); }, @@ -11956,6 +11987,10 @@ BI.MultiTreeSearcher = BI.inherit(BI.Widget, { this.searcher.adjustView(); }, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + }, + isSearching: function () { return this.searcher.isSearching(); }, diff --git a/demo/js/widget/tree/demo.multilayer_select_tree_combo.js b/demo/js/widget/tree/demo.multilayer_select_tree_combo.js index 580587289f..4968bb7b16 100644 --- a/demo/js/widget/tree/demo.multilayer_select_tree_combo.js +++ b/demo/js/widget/tree/demo.multilayer_select_tree_combo.js @@ -46,12 +46,9 @@ Demo.MultiSelectCombo = BI.inherit(BI.Widget, { var items = BI.deepClone(TREEWITHCHILDREN); var combo = BI.createWidget({ type: "bi.multilayer_select_tree_combo", - itemsCreator: function (op, callback) { - debugger; - } }); - combo.populate(); + combo.populate(items); return { type: "bi.vertical", items: [combo, { diff --git a/docs/base.js b/docs/base.js index 9476b3d857..11cd5fd79f 100644 --- a/docs/base.js +++ b/docs/base.js @@ -4642,6 +4642,11 @@ BI.Switcher = BI.inherit(BI.Widget, { return this.popupView ? this.popupView.getValue() : []; }, + setAdapter: function (adapter) { + this.options.adapter = adapter; + BI.Maskers.remove(this.getName()); + }, + isViewVisible: function () { return this.isEnabled() && this.switcher.isEnabled() && (this.options.adapter ? BI.Maskers.isVisible(this.getName()) : (this.popupView && this.popupView.isVisible())); diff --git a/docs/demo.js b/docs/demo.js index 3c93eef27b..e7a4a5c0f7 100644 --- a/docs/demo.js +++ b/docs/demo.js @@ -6781,12 +6781,9 @@ Demo.MultiSelectCombo = BI.inherit(BI.Widget, { var items = BI.deepClone(TREEWITHCHILDREN); var combo = BI.createWidget({ type: "bi.multilayer_select_tree_combo", - itemsCreator: function (op, callback) { - debugger; - } }); - combo.populate(); + combo.populate(items); return { type: "bi.vertical", items: [combo, { diff --git a/docs/widget.js b/docs/widget.js index bb810d8d12..a1c55f5e09 100644 --- a/docs/widget.js +++ b/docs/widget.js @@ -9559,38 +9559,11 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { self.trigger.getCounter().setButtonChecked(self.storeValue); }; this.storeValue = {}; - this.popup = BI.createWidget({ - type: 'bi.multi_select_popup_view', - 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(); - }); - } - }); - - this.popup.on(BI.MultiSelectPopupView.EVENT_CHANGE, function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - }); - }); - this.popup.on(BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM, function () { - self._defaultState(); - }); - this.popup.on(BI.MultiSelectPopupView.EVENT_CLICK_CLEAR, function () { - self.setValue(); - self._defaultState(); - }); this.trigger = BI.createWidget({ type: "bi.multi_select_trigger", height: o.height, - adapter: this.popup, + // adapter: this.popup, masker: { offset: { left: 1, @@ -9675,7 +9648,43 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { toggle: false, el: this.trigger, adjustLength: 1, - popup: this.popup, + 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(); + }); + } + }, hideChecker: function (e) { return triggerBtn.element.find(e.target).length === 0; } @@ -10272,6 +10281,11 @@ BI.MultiSelectTrigger = BI.inherit(BI.Trigger, { this.numberCounter.hideView(); }, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + this.numberCounter.setAdapter(adapter); + }, + setValue: function (ob) { this.searcher.setValue(ob); this.numberCounter.setValue(ob); @@ -10816,6 +10830,10 @@ BI.MultiSelectSearcher = BI.inherit(BI.Widget, { return this.searcher.getView() && this.searcher.getView().hasChecked(); }, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + }, + setState: function (ob) { var o = this.options; ob || (ob = {}); @@ -10937,6 +10955,10 @@ BI.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, { this.switcher.hideView(); }, + setAdapter: function (adapter) { + this.switcher.setAdapter(adapter); + }, + setValue: function (v) { this.switcher.setValue(v); }, @@ -11406,7 +11428,6 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { } }, - _defaultConfig: function () { return BI.extend(BI.MultiTreeCombo.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-tree-combo', @@ -11420,31 +11441,13 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { var self = this, o = this.options; - this.popup = BI.createWidget({ - type: 'bi.multi_tree_popup_view', - itemsCreator: o.itemsCreator, - onLoaded: function () { - BI.nextTick(function () { - self.trigger.getCounter().adjustView(); - self.trigger.getSearcher().adjustView(); - }); - } - }); var isInit = false; var want2showCounter = false; - this.popup.on(BI.MultiTreePopup.EVENT_AFTERINIT, function () { - self.trigger.getCounter().adjustView(); - isInit = true; - if (want2showCounter === true) { - showCounter(); - } - }); - this.trigger = BI.createWidget({ type: "bi.multi_select_trigger", height: o.height, - adapter: this.popup, + // adapter: this.popup, masker: { offset: this.constants.offset }, @@ -11469,7 +11472,53 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { toggle: false, el: this.trigger, adjustLength: 1, - popup: this.popup + 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() ? {1: 1} : {} + }; + self.trigger.getSearcher().setState(val); + self.trigger.getCounter().setButtonChecked(val); + } + }, { + eventName: BI.MultiTreePopup.EVENT_CLICK_CONFIRM, + action: function () { + self._defaultState(); + } + }, { + 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.storeValue = {value: {}}; @@ -11532,24 +11581,6 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { this.getSearcher().setState(val); this.getCounter().setButtonChecked(val); }); - this.popup.on(BI.MultiTreePopup.EVENT_CHANGE, function () { - change = true; - var val = { - type: BI.Selection.Multi, - value: this.hasChecked() ? {1: 1} : {} - }; - self.trigger.getSearcher().setState(val); - self.trigger.getCounter().setButtonChecked(val); - }); - - this.popup.on(BI.MultiTreePopup.EVENT_CLICK_CONFIRM, function () { - self._defaultState(); - }); - this.popup.on(BI.MultiTreePopup.EVENT_CLICK_CLEAR, function () { - clear = true; - self.setValue(); - self._defaultState(); - }); this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { if (isSearching()) { @@ -11618,7 +11649,7 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { this.combo.hideView(); }, - setEnable: function(v){ + setEnable: function (v) { this.combo.setEnable(v); }, @@ -11956,6 +11987,10 @@ BI.MultiTreeSearcher = BI.inherit(BI.Widget, { this.searcher.adjustView(); }, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + }, + isSearching: function () { return this.searcher.isSearching(); }, diff --git a/src/base/combination/switcher.js b/src/base/combination/switcher.js index 25e28cd5da..c72715b633 100644 --- a/src/base/combination/switcher.js +++ b/src/base/combination/switcher.js @@ -204,6 +204,11 @@ BI.Switcher = BI.inherit(BI.Widget, { return this.popupView ? this.popupView.getValue() : []; }, + setAdapter: function (adapter) { + this.options.adapter = adapter; + BI.Maskers.remove(this.getName()); + }, + isViewVisible: function () { return this.isEnabled() && this.switcher.isEnabled() && (this.options.adapter ? BI.Maskers.isVisible(this.getName()) : (this.popupView && this.popupView.isVisible())); diff --git a/src/widget/multiselect/multiselect.combo.js b/src/widget/multiselect/multiselect.combo.js index f369f42a3a..d5d1e1f415 100644 --- a/src/widget/multiselect/multiselect.combo.js +++ b/src/widget/multiselect/multiselect.combo.js @@ -24,38 +24,11 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { self.trigger.getCounter().setButtonChecked(self.storeValue); }; this.storeValue = {}; - this.popup = BI.createWidget({ - type: 'bi.multi_select_popup_view', - 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(); - }); - } - }); - - this.popup.on(BI.MultiSelectPopupView.EVENT_CHANGE, function () { - self.storeValue = this.getValue(); - self._adjust(function () { - assertShowValue(); - }); - }); - this.popup.on(BI.MultiSelectPopupView.EVENT_CLICK_CONFIRM, function () { - self._defaultState(); - }); - this.popup.on(BI.MultiSelectPopupView.EVENT_CLICK_CLEAR, function () { - self.setValue(); - self._defaultState(); - }); this.trigger = BI.createWidget({ type: "bi.multi_select_trigger", height: o.height, - adapter: this.popup, + // adapter: this.popup, masker: { offset: { left: 1, @@ -140,7 +113,43 @@ BI.MultiSelectCombo = BI.inherit(BI.Single, { toggle: false, el: this.trigger, adjustLength: 1, - popup: this.popup, + 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(); + }); + } + }, hideChecker: function (e) { return triggerBtn.element.find(e.target).length === 0; } diff --git a/src/widget/multiselect/multiselect.trigger.js b/src/widget/multiselect/multiselect.trigger.js index 2d85f21224..e9a1dda38f 100644 --- a/src/widget/multiselect/multiselect.trigger.js +++ b/src/widget/multiselect/multiselect.trigger.js @@ -123,6 +123,11 @@ BI.MultiSelectTrigger = BI.inherit(BI.Trigger, { this.numberCounter.hideView(); }, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + this.numberCounter.setAdapter(adapter); + }, + setValue: function (ob) { this.searcher.setValue(ob); this.numberCounter.setValue(ob); diff --git a/src/widget/multiselect/trigger/searcher.multiselect.js b/src/widget/multiselect/trigger/searcher.multiselect.js index b641fddca4..337749a6ee 100644 --- a/src/widget/multiselect/trigger/searcher.multiselect.js +++ b/src/widget/multiselect/trigger/searcher.multiselect.js @@ -98,6 +98,10 @@ BI.MultiSelectSearcher = BI.inherit(BI.Widget, { return this.searcher.getView() && this.searcher.getView().hasChecked(); }, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + }, + setState: function (ob) { var o = this.options; ob || (ob = {}); diff --git a/src/widget/multiselect/trigger/switcher.checkselected.js b/src/widget/multiselect/trigger/switcher.checkselected.js index 321d1eceb6..011cd3794b 100644 --- a/src/widget/multiselect/trigger/switcher.checkselected.js +++ b/src/widget/multiselect/trigger/switcher.checkselected.js @@ -72,6 +72,10 @@ BI.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, { this.switcher.hideView(); }, + setAdapter: function (adapter) { + this.switcher.setAdapter(adapter); + }, + setValue: function (v) { this.switcher.setValue(v); }, diff --git a/src/widget/multitree/multi.tree.combo.js b/src/widget/multitree/multi.tree.combo.js index 53b039de60..7c302e9cd2 100644 --- a/src/widget/multitree/multi.tree.combo.js +++ b/src/widget/multitree/multi.tree.combo.js @@ -15,7 +15,6 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { } }, - _defaultConfig: function () { return BI.extend(BI.MultiTreeCombo.superclass._defaultConfig.apply(this, arguments), { baseCls: 'bi-multi-tree-combo', @@ -29,31 +28,13 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { var self = this, o = this.options; - this.popup = BI.createWidget({ - type: 'bi.multi_tree_popup_view', - itemsCreator: o.itemsCreator, - onLoaded: function () { - BI.nextTick(function () { - self.trigger.getCounter().adjustView(); - self.trigger.getSearcher().adjustView(); - }); - } - }); var isInit = false; var want2showCounter = false; - this.popup.on(BI.MultiTreePopup.EVENT_AFTERINIT, function () { - self.trigger.getCounter().adjustView(); - isInit = true; - if (want2showCounter === true) { - showCounter(); - } - }); - this.trigger = BI.createWidget({ type: "bi.multi_select_trigger", height: o.height, - adapter: this.popup, + // adapter: this.popup, masker: { offset: this.constants.offset }, @@ -78,7 +59,53 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { toggle: false, el: this.trigger, adjustLength: 1, - popup: this.popup + 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() ? {1: 1} : {} + }; + self.trigger.getSearcher().setState(val); + self.trigger.getCounter().setButtonChecked(val); + } + }, { + eventName: BI.MultiTreePopup.EVENT_CLICK_CONFIRM, + action: function () { + self._defaultState(); + } + }, { + 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.storeValue = {value: {}}; @@ -141,24 +168,6 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { this.getSearcher().setState(val); this.getCounter().setButtonChecked(val); }); - this.popup.on(BI.MultiTreePopup.EVENT_CHANGE, function () { - change = true; - var val = { - type: BI.Selection.Multi, - value: this.hasChecked() ? {1: 1} : {} - }; - self.trigger.getSearcher().setState(val); - self.trigger.getCounter().setButtonChecked(val); - }); - - this.popup.on(BI.MultiTreePopup.EVENT_CLICK_CONFIRM, function () { - self._defaultState(); - }); - this.popup.on(BI.MultiTreePopup.EVENT_CLICK_CLEAR, function () { - clear = true; - self.setValue(); - self._defaultState(); - }); this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { if (isSearching()) { @@ -227,7 +236,7 @@ BI.MultiTreeCombo = BI.inherit(BI.Single, { this.combo.hideView(); }, - setEnable: function(v){ + setEnable: function (v) { this.combo.setEnable(v); }, diff --git a/src/widget/multitree/trigger/searcher.multi.tree.js b/src/widget/multitree/trigger/searcher.multi.tree.js index 894e6accb5..5c07c576cc 100644 --- a/src/widget/multitree/trigger/searcher.multi.tree.js +++ b/src/widget/multitree/trigger/searcher.multi.tree.js @@ -76,6 +76,10 @@ BI.MultiTreeSearcher = BI.inherit(BI.Widget, { this.searcher.adjustView(); }, + setAdapter: function (adapter) { + this.searcher.setAdapter(adapter); + }, + isSearching: function () { return this.searcher.isSearching(); },