From 4a210318d7fa57c4cfadad350e863b8ba17adc24 Mon Sep 17 00:00:00 2001 From: guy Date: Sat, 29 Apr 2017 21:34:08 +0800 Subject: [PATCH] searcher --- bi/base.js | 36 ++++++----- .../core/abstract/combination/demo.sercher.js | 59 +++++++++++++++++++ docs/base.js | 36 ++++++----- docs/demo.js | 58 ++++++++++++++++++ src/base/combination/searcher.js | 36 ++++++----- 5 files changed, 168 insertions(+), 57 deletions(-) create mode 100644 demo/js/core/abstract/combination/demo.sercher.js diff --git a/bi/base.js b/bi/base.js index 7ccd3f5f5..f665c730b 100644 --- a/bi/base.js +++ b/bi/base.js @@ -4106,7 +4106,6 @@ BI.Searcher = BI.inherit(BI.Widget, { callback([]) }, - el: { type: "bi.search_editor" }, @@ -4164,16 +4163,11 @@ BI.Searcher = BI.inherit(BI.Widget, { _assertPopupView: function () { var self = this, o = this.options; - if (!BI.Maskers.has(this.getName())) { + if ((o.masker && !BI.Maskers.has(this.getName())) || (o.masker === false && !this.popupView)) { this.popupView = BI.createWidget(o.popup, { type: "bi.searcher_view", chooseType: o.chooseType }); - BI.Maskers.create(this.getName(), o.adapter, BI.extend({ - container: this, - render: this.popupView - }, o.masker)); - this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { @@ -4200,6 +4194,12 @@ BI.Searcher = BI.inherit(BI.Widget, { self.fireEvent(BI.Searcher.EVENT_AFTER_INIT); }); } + if (o.masker && !BI.Maskers.has(this.getName())) { + BI.Maskers.create(this.getName(), o.adapter, BI.extend({ + container: this, + render: this.popupView + }, o.masker)); + } }, _startSearch: function () { @@ -4221,7 +4221,7 @@ BI.Searcher = BI.inherit(BI.Widget, { BI.nextTick(function (name) { BI.Maskers.hide(name); }, this.getName()); - if (BI.Maskers.has(name) && this._isSearching === true) { + if (this._isSearching === true) { this.popupView && this.popupView.pauseSearch && this.popupView.pauseSearch(); this.fireEvent(BI.Searcher.EVENT_PAUSE); } @@ -4232,11 +4232,7 @@ BI.Searcher = BI.inherit(BI.Widget, { var o = this.options, name = this.getName(); this._stop = true; BI.Maskers.hide(name); - if (BI.Maskers.has(name) && this._isSearching === true) { - //搜索后清空dom - // BI.nextTick(function () { - // BI.Maskers.has(name) && BI.Maskers.get(name).empty(); - // }); + if (this._isSearching === true) { this.popupView && this.popupView.stopSearch && this.popupView.stopSearch(); this.fireEvent(BI.Searcher.EVENT_STOP); } @@ -4249,11 +4245,11 @@ BI.Searcher = BI.inherit(BI.Widget, { return; } if (o.isAutoSearch) { - var items = (o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items") || []; + var items = (o.adapter && ((o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items"))) || []; var finding = BI.Func.getSearchResult(items, keyword); var matched = finding.matched, finded = finding.finded; this.popupView.populate(finded, matched, keyword); - o.isAutoSync && this.popupView.setValue(o.adapter.getValue()); + o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue()); self.fireEvent(BI.Searcher.EVENT_SEARCHING); return; } @@ -4270,7 +4266,7 @@ BI.Searcher = BI.inherit(BI.Widget, { } BI.Maskers.show(self.getName()); self.popupView.populate.apply(self.popupView, args); - o.isAutoSync && self.popupView.setValue(o.adapter && o.adapter.getValue()); + o.isAutoSync && o.adapter && o.adapter.getValue && self.popupView.setValue(o.adapter.getValue()); self.popupView.loaded && self.popupView.loaded(); self.fireEvent(BI.Searcher.EVENT_SEARCHING); } @@ -4344,13 +4340,15 @@ BI.Searcher = BI.inherit(BI.Widget, { getValue: function () { var o = this.options; - if (o.isAutoSync) { + if (o.isAutoSync && o.adapter && o.adapter.getValue) { return o.adapter.getValue(); } if (this.isSearching()) { return this.popupView.getValue(); - } else { + } else if (o.adapter && o.adapter.getValue) { return o.adapter.getValue(); + } else { + return this.popupView.getValue(); } }, @@ -4358,7 +4356,7 @@ BI.Searcher = BI.inherit(BI.Widget, { var o = this.options; this._assertPopupView(); this.popupView.populate.apply(this.popupView, arguments); - if (o.isAutoSync) { + if (o.isAutoSync && o.adapter && o.adapter.getValue) { this.popupView.setValue(o.adapter.getValue()); } }, diff --git a/demo/js/core/abstract/combination/demo.sercher.js b/demo/js/core/abstract/combination/demo.sercher.js new file mode 100644 index 000000000..d2d3fcec5 --- /dev/null +++ b/demo/js/core/abstract/combination/demo.sercher.js @@ -0,0 +1,59 @@ +Demo.Func = BI.inherit(BI.Widget, { + props: { + baseCls: "demo-func" + }, + render: function () { + var items = [{ + type: "bi.label", + value: "张三" + }, { + type: "bi.label", + value: "李四" + }]; + var popup = BI.createWidget({ + type: "bi.button_group", + cls: "bi-border layout-bg3", + items: items, + layouts: [{ + type: "bi.vertical" + }] + }); + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.searcher", + listeners: [{ + eventName: BI.Searcher.EVENT_STOP, + action: function () { + popup.populate(items) + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + popup.populate(items) + } + }], + height: 200, + adapter: { + getItems: function () { + return items + } + }, + popup: popup, + masker: false + }, + left: 0, + right: 0, + top: 0 + }, { + el: popup, + left: 0, + right: 0, + top: 50, + bottom: 0 + }] + } + } +}); +BI.shortcut("demo.searcher", Demo.Func); \ No newline at end of file diff --git a/docs/base.js b/docs/base.js index 7ccd3f5f5..f665c730b 100644 --- a/docs/base.js +++ b/docs/base.js @@ -4106,7 +4106,6 @@ BI.Searcher = BI.inherit(BI.Widget, { callback([]) }, - el: { type: "bi.search_editor" }, @@ -4164,16 +4163,11 @@ BI.Searcher = BI.inherit(BI.Widget, { _assertPopupView: function () { var self = this, o = this.options; - if (!BI.Maskers.has(this.getName())) { + if ((o.masker && !BI.Maskers.has(this.getName())) || (o.masker === false && !this.popupView)) { this.popupView = BI.createWidget(o.popup, { type: "bi.searcher_view", chooseType: o.chooseType }); - BI.Maskers.create(this.getName(), o.adapter, BI.extend({ - container: this, - render: this.popupView - }, o.masker)); - this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { @@ -4200,6 +4194,12 @@ BI.Searcher = BI.inherit(BI.Widget, { self.fireEvent(BI.Searcher.EVENT_AFTER_INIT); }); } + if (o.masker && !BI.Maskers.has(this.getName())) { + BI.Maskers.create(this.getName(), o.adapter, BI.extend({ + container: this, + render: this.popupView + }, o.masker)); + } }, _startSearch: function () { @@ -4221,7 +4221,7 @@ BI.Searcher = BI.inherit(BI.Widget, { BI.nextTick(function (name) { BI.Maskers.hide(name); }, this.getName()); - if (BI.Maskers.has(name) && this._isSearching === true) { + if (this._isSearching === true) { this.popupView && this.popupView.pauseSearch && this.popupView.pauseSearch(); this.fireEvent(BI.Searcher.EVENT_PAUSE); } @@ -4232,11 +4232,7 @@ BI.Searcher = BI.inherit(BI.Widget, { var o = this.options, name = this.getName(); this._stop = true; BI.Maskers.hide(name); - if (BI.Maskers.has(name) && this._isSearching === true) { - //搜索后清空dom - // BI.nextTick(function () { - // BI.Maskers.has(name) && BI.Maskers.get(name).empty(); - // }); + if (this._isSearching === true) { this.popupView && this.popupView.stopSearch && this.popupView.stopSearch(); this.fireEvent(BI.Searcher.EVENT_STOP); } @@ -4249,11 +4245,11 @@ BI.Searcher = BI.inherit(BI.Widget, { return; } if (o.isAutoSearch) { - var items = (o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items") || []; + var items = (o.adapter && ((o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items"))) || []; var finding = BI.Func.getSearchResult(items, keyword); var matched = finding.matched, finded = finding.finded; this.popupView.populate(finded, matched, keyword); - o.isAutoSync && this.popupView.setValue(o.adapter.getValue()); + o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue()); self.fireEvent(BI.Searcher.EVENT_SEARCHING); return; } @@ -4270,7 +4266,7 @@ BI.Searcher = BI.inherit(BI.Widget, { } BI.Maskers.show(self.getName()); self.popupView.populate.apply(self.popupView, args); - o.isAutoSync && self.popupView.setValue(o.adapter && o.adapter.getValue()); + o.isAutoSync && o.adapter && o.adapter.getValue && self.popupView.setValue(o.adapter.getValue()); self.popupView.loaded && self.popupView.loaded(); self.fireEvent(BI.Searcher.EVENT_SEARCHING); } @@ -4344,13 +4340,15 @@ BI.Searcher = BI.inherit(BI.Widget, { getValue: function () { var o = this.options; - if (o.isAutoSync) { + if (o.isAutoSync && o.adapter && o.adapter.getValue) { return o.adapter.getValue(); } if (this.isSearching()) { return this.popupView.getValue(); - } else { + } else if (o.adapter && o.adapter.getValue) { return o.adapter.getValue(); + } else { + return this.popupView.getValue(); } }, @@ -4358,7 +4356,7 @@ BI.Searcher = BI.inherit(BI.Widget, { var o = this.options; this._assertPopupView(); this.popupView.populate.apply(this.popupView, arguments); - if (o.isAutoSync) { + if (o.isAutoSync && o.adapter && o.adapter.getValue) { this.popupView.setValue(o.adapter.getValue()); } }, diff --git a/docs/demo.js b/docs/demo.js index 4d7cb0e89..e63bd9412 100644 --- a/docs/demo.js +++ b/docs/demo.js @@ -2937,6 +2937,64 @@ Demo.COMPONENT_CONFIG = [{ } }); BI.shortcut("demo.combo", Demo.Func);Demo.Func = BI.inherit(BI.Widget, { + props: { + baseCls: "demo-func" + }, + render: function () { + var items = [{ + type: "bi.label", + value: "张三" + }, { + type: "bi.label", + value: "李四" + }]; + var popup = BI.createWidget({ + type: "bi.button_group", + cls: "bi-border layout-bg3", + items: items, + layouts: [{ + type: "bi.vertical" + }] + }); + return { + type: "bi.absolute", + items: [{ + el: { + type: "bi.searcher", + listeners: [{ + eventName: BI.Searcher.EVENT_STOP, + action: function () { + popup.populate(items) + } + }, { + eventName: BI.Searcher.EVENT_PAUSE, + action: function () { + popup.populate(items) + } + }], + height: 200, + adapter: { + getItems: function () { + return items + } + }, + popup: popup, + masker: false + }, + left: 0, + right: 0, + top: 0 + }, { + el: popup, + left: 0, + right: 0, + top: 50, + bottom: 0 + }] + } + } +}); +BI.shortcut("demo.searcher", Demo.Func);Demo.Func = BI.inherit(BI.Widget, { props: { baseCls: "demo-func" }, diff --git a/src/base/combination/searcher.js b/src/base/combination/searcher.js index 87d87e299..604b923f5 100644 --- a/src/base/combination/searcher.js +++ b/src/base/combination/searcher.js @@ -27,7 +27,6 @@ BI.Searcher = BI.inherit(BI.Widget, { callback([]) }, - el: { type: "bi.search_editor" }, @@ -85,16 +84,11 @@ BI.Searcher = BI.inherit(BI.Widget, { _assertPopupView: function () { var self = this, o = this.options; - if (!BI.Maskers.has(this.getName())) { + if ((o.masker && !BI.Maskers.has(this.getName())) || (o.masker === false && !this.popupView)) { this.popupView = BI.createWidget(o.popup, { type: "bi.searcher_view", chooseType: o.chooseType }); - BI.Maskers.create(this.getName(), o.adapter, BI.extend({ - container: this, - render: this.popupView - }, o.masker)); - this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); if (type === BI.Events.CLICK) { @@ -121,6 +115,12 @@ BI.Searcher = BI.inherit(BI.Widget, { self.fireEvent(BI.Searcher.EVENT_AFTER_INIT); }); } + if (o.masker && !BI.Maskers.has(this.getName())) { + BI.Maskers.create(this.getName(), o.adapter, BI.extend({ + container: this, + render: this.popupView + }, o.masker)); + } }, _startSearch: function () { @@ -142,7 +142,7 @@ BI.Searcher = BI.inherit(BI.Widget, { BI.nextTick(function (name) { BI.Maskers.hide(name); }, this.getName()); - if (BI.Maskers.has(name) && this._isSearching === true) { + if (this._isSearching === true) { this.popupView && this.popupView.pauseSearch && this.popupView.pauseSearch(); this.fireEvent(BI.Searcher.EVENT_PAUSE); } @@ -153,11 +153,7 @@ BI.Searcher = BI.inherit(BI.Widget, { var o = this.options, name = this.getName(); this._stop = true; BI.Maskers.hide(name); - if (BI.Maskers.has(name) && this._isSearching === true) { - //搜索后清空dom - // BI.nextTick(function () { - // BI.Maskers.has(name) && BI.Maskers.get(name).empty(); - // }); + if (this._isSearching === true) { this.popupView && this.popupView.stopSearch && this.popupView.stopSearch(); this.fireEvent(BI.Searcher.EVENT_STOP); } @@ -170,11 +166,11 @@ BI.Searcher = BI.inherit(BI.Widget, { return; } if (o.isAutoSearch) { - var items = (o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items") || []; + var items = (o.adapter && ((o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items"))) || []; var finding = BI.Func.getSearchResult(items, keyword); var matched = finding.matched, finded = finding.finded; this.popupView.populate(finded, matched, keyword); - o.isAutoSync && this.popupView.setValue(o.adapter.getValue()); + o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue()); self.fireEvent(BI.Searcher.EVENT_SEARCHING); return; } @@ -191,7 +187,7 @@ BI.Searcher = BI.inherit(BI.Widget, { } BI.Maskers.show(self.getName()); self.popupView.populate.apply(self.popupView, args); - o.isAutoSync && self.popupView.setValue(o.adapter && o.adapter.getValue()); + o.isAutoSync && o.adapter && o.adapter.getValue && self.popupView.setValue(o.adapter.getValue()); self.popupView.loaded && self.popupView.loaded(); self.fireEvent(BI.Searcher.EVENT_SEARCHING); } @@ -265,13 +261,15 @@ BI.Searcher = BI.inherit(BI.Widget, { getValue: function () { var o = this.options; - if (o.isAutoSync) { + if (o.isAutoSync && o.adapter && o.adapter.getValue) { return o.adapter.getValue(); } if (this.isSearching()) { return this.popupView.getValue(); - } else { + } else if (o.adapter && o.adapter.getValue) { return o.adapter.getValue(); + } else { + return this.popupView.getValue(); } }, @@ -279,7 +277,7 @@ BI.Searcher = BI.inherit(BI.Widget, { var o = this.options; this._assertPopupView(); this.popupView.populate.apply(this.popupView, arguments); - if (o.isAutoSync) { + if (o.isAutoSync && o.adapter && o.adapter.getValue) { this.popupView.setValue(o.adapter.getValue()); } },