").__textKeywordMarked__(n.text, o.paras.keyword, n.py).html();
+ } else {
+ n.text = BI.replaceAll((n.text + ""), " ", " ");
+ }
+ });
+ return nodes;
},
- restore: function () {
- BI.each(this.renderedCells, function (i, cell) {
- cell.el._destroy();
+ _loadMore: function () {
+ var self = this, o = this.options;
+ this.tip.setLoading();
+ var op = BI.extend({}, o.paras, {
+ times: ++this.times
});
- this._clearChildren();
- this.renderedCells = [];
- this.renderedKeys = [];
- this.renderRange = {};
- this._scrollLock = false;
- },
+ o.itemsCreator(op, function (res) {
+ if (self._stop === true) {
+ return;
+ }
+ var hasNext = !!res.hasNext, nodes = res.items || [];
- populate: function (items) {
- if (items && items !== this.options.items) {
- this.restore();
- }
- this._populate(items);
- }
-});
-BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL";
-BI.shortcut("bi.collection_view", BI.CollectionView);/**
- * @class BI.Combo
- * @extends BI.Widget
- */
-BI.Combo = BI.inherit(BI.Widget, {
- _defaultConfig: function () {
- var conf = BI.Combo.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-combo",
- trigger: "click",
- toggle: true,
- direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right
- container: null, // popupview放置的容器,默认为this.element
- isDefaultInit: false,
- destroyWhenHide: false,
- isNeedAdjustHeight: true, // 是否需要高度调整
- isNeedAdjustWidth: true,
- stopEvent: false,
- stopPropagation: false,
- adjustLength: 0, // 调整的距离
- adjustXOffset: 0,
- adjustYOffset: 0,
- hideChecker: BI.emptyFn,
- offsetStyle: "left", // left,right,center
- el: {},
- popup: {},
- comboClass: "bi-combo-popup",
- hoverClass: "bi-combo-hover"
+ if (!hasNext) {
+ self.tip.setEnd();
+ } else {
+ self.tip.setLoaded();
+ }
+ if (nodes.length > 0) {
+ self.nodes.addNodes(null, self._dealWidthNodes(nodes));
+ }
});
},
- _init: function () {
- BI.Combo.superclass._init.apply(this, arguments);
+ // 生成树内部方法
+ _initTree: function (setting) {
var self = this, o = this.options;
- this._initCombo();
- this._initPullDownAction();
- this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- if (self.isEnabled() && self.isValid()) {
- if (type === BI.Events.EXPAND) {
- self._popupView();
- }
- if (type === BI.Events.COLLAPSE) {
- self._hideView();
- }
- if (type === BI.Events.EXPAND) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- self.fireEvent(BI.Combo.EVENT_EXPAND);
- }
- if (type === BI.Events.COLLAPSE) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- self.isViewVisible() && self.fireEvent(BI.Combo.EVENT_COLLAPSE);
- }
- if (type === BI.Events.CLICK) {
- self.fireEvent(BI.Combo.EVENT_TRIGGER_CHANGE, obj);
- }
+ self.fireEvent(BI.Events.INIT);
+ this.times = 1;
+ var tree = this.tree;
+ tree.empty();
+ this.loading();
+ this.tip.setVisible(false);
+ var callback = function (nodes) {
+ if (self._stop === true) {
+ return;
}
+ self.nodes = $.fn.zTree.init(tree.element, setting, nodes);
+ };
+ var op = BI.extend({}, o.paras, {
+ times: 1
});
- self.element.on("mouseenter." + self.getName(), function (e) {
- if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
- self.element.addClass(o.hoverClass);
+ o.itemsCreator(op, function (res) {
+ if (self._stop === true) {
+ return;
}
- });
- self.element.on("mouseleave." + self.getName(), function (e) {
- if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
- self.element.removeClass(o.hoverClass);
+ var hasNext = !!res.hasNext, nodes = res.items || [];
+ if (nodes.length > 0) {
+ callback(self._dealWidthNodes(nodes));
}
- });
-
- BI.createWidget({
- type: "bi.vertical",
- scrolly: false,
- element: this,
- items: [
- {el: this.combo}
- ]
- });
- o.isDefaultInit && (this._assertPopupView());
- BI.Resizers.add(this.getName(), BI.bind(function () {
- if (this.isViewVisible()) {
- this._hideView();
+ self.setTipVisible(nodes.length <= 0);
+ self.loaded();
+ if (!hasNext) {
+ self.tip.invisible();
+ } else {
+ self.tip.setLoaded();
}
- }, this));
+ op.times === 1 && self.fireEvent(BI.Events.AFTERINIT);
+ });
},
- _toggle: function () {
- this._assertPopupViewRender();
- if (this.popupView.isVisible()) {
- this._hideView();
- } else {
- if (this.isEnabled()) {
- this._popupView();
- }
- }
+ // 构造树结构,
+ initTree: function (nodes, setting) {
+ var setting = setting || {
+ async: {
+ enable: false
+ },
+ check: {
+ enable: false
+ },
+ data: {
+ key: {
+ title: "title",
+ name: "text"
+ },
+ simpleData: {
+ enable: true
+ }
+ },
+ view: {
+ showIcon: false,
+ expandSpeed: "",
+ nameIsHTML: true
+ },
+ callback: {}
+ };
+ this.nodes = $.fn.zTree.init(this.tree.element, setting, nodes);
},
- _initPullDownAction: function () {
- var self = this, o = this.options;
- var evs = this.options.trigger.split(",");
- var st = function (e) {
- if (o.stopEvent) {
- e.stopEvent();
- }
- if (o.stopPropagation) {
- e.stopPropagation();
- }
- };
+ start: function () {
+ this._stop = false;
+ },
- var enterPopup = false;
+ stop: function () {
+ this._stop = true;
+ },
- function hide () {
- if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid() && o.toggle === true) {
- self._hideView();
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo);
- self.fireEvent(BI.Combo.EVENT_COLLAPSE);
- }
- self.popupView && self.popupView.element.off("mouseenter." + self.getName()).off("mouseleave." + self.getName());
- enterPopup = false;
- }
-
- BI.each(evs, function (i, ev) {
- switch (ev) {
- case "hover":
- self.element.on("mouseenter." + self.getName(), function (e) {
- if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
- self._popupView();
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo);
- self.fireEvent(BI.Combo.EVENT_EXPAND);
- }
- });
- self.element.on("mouseleave." + self.getName(), function (e) {
- if (self.popupView) {
- self.popupView.element.on("mouseenter." + self.getName(), function (e) {
- enterPopup = true;
- self.popupView.element.on("mouseleave." + self.getName(), function (e) {
- hide();
- });
- self.popupView.element.off("mouseenter." + self.getName());
- });
- BI.defer(function () {
- if (!enterPopup) {
- hide();
- }
- }, 50);
- }
- });
- break;
- case "click":
- var debounce = BI.debounce(function (e) {
- if (self.combo.element.__isMouseInBounds__(e)) {
- if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
- // if (!o.toggle && self.isViewVisible()) {
- // return;
- // }
- o.toggle ? self._toggle() : self._popupView();
- if (self.isViewVisible()) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo);
- self.fireEvent(BI.Combo.EVENT_EXPAND);
- } else {
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo);
- self.fireEvent(BI.Combo.EVENT_COLLAPSE);
- }
- }
- }
- }, BI.EVENT_RESPONSE_TIME, {
- "leading": true,
- "trailing": false
- });
- self.element.off(ev + "." + self.getName()).on(ev + "." + self.getName(), function (e) {
- debounce(e);
- st(e);
- });
- break;
- case "click-hover":
- var debounce = BI.debounce(function (e) {
- if (self.combo.element.__isMouseInBounds__(e)) {
- if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
- // if (self.isViewVisible()) {
- // return;
- // }
- self._popupView();
- if (self.isViewVisible()) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo);
- self.fireEvent(BI.Combo.EVENT_EXPAND);
- }
- }
- }
- }, BI.EVENT_RESPONSE_TIME, {
- "leading": true,
- "trailing": false
- });
- self.element.off("click." + self.getName()).on("click." + self.getName(), function (e) {
- debounce(e);
- st(e);
- });
- self.element.on("mouseleave." + self.getName(), function (e) {
- if (self.popupView) {
- self.popupView.element.on("mouseenter." + self.getName(), function (e) {
- enterPopup = true;
- self.popupView.element.on("mouseleave." + self.getName(), function (e) {
- hide();
- });
- self.popupView.element.off("mouseenter." + self.getName());
- });
- BI.defer(function () {
- if (!enterPopup) {
- hide();
- }
- }, 50);
- }
- });
- break;
- }
- });
+ // 生成树方法
+ stroke: function (config) {
+ delete this.options.keyword;
+ BI.extend(this.options.paras, config);
+ var setting = this._configSetting();
+ this._createTree();
+ this.start();
+ this._initTree(setting);
},
- _initCombo: function () {
- this.combo = BI.createWidget(this.options.el, {
- value: this.options.value
- });
+ populate: function () {
+ this.stroke.apply(this, arguments);
},
- _assertPopupView: function () {
- var self = this, o = this.options;
- if (this.popupView == null) {
- this.popupView = BI.createWidget(this.options.popup, {
- type: "bi.popup_view",
- value: o.value
- }, this);
- this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- if (type === BI.Events.CLICK) {
- self.combo.setValue(self.getValue());
- self.fireEvent(BI.Combo.EVENT_CHANGE, value, obj);
- }
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- });
- this.popupView.setVisible(false);
- BI.nextTick(function () {
- self.fireEvent(BI.Combo.EVENT_AFTER_INIT);
- });
- }
+ hasChecked: function () {
+ var treeObj = this.nodes;
+ return treeObj.getCheckedNodes(true).length > 0;
},
- _assertPopupViewRender: function () {
- this._assertPopupView();
- if (!this._rendered) {
- BI.createWidget({
- type: "bi.vertical",
- scrolly: false,
- element: this.options.container || this,
- items: [
- {el: this.popupView}
- ]
+ checkAll: function (checked) {
+ function setNode (children) {
+ BI.each(children, function (i, child) {
+ child.halfCheck = false;
+ setNode(child.children);
});
- this._rendered = true;
}
- },
- _hideIf: function (e) {
- // if (this.element.__isMouseInBounds__(e) || (this.popupView && this.popupView.element.__isMouseInBounds__(e))) {
- // return;
- // }
- // BI-10290 公式combo双击公式内容会收起
- if ((this.element.find(e.target).length > 0)
- || (this.popupView && this.popupView.element.find(e.target).length > 0)
- || e.target.className === "CodeMirror-cursor" || BI.Widget._renderEngine.createElement(e.target).closest(".CodeMirror-hints").length > 0) {// BI-9887 CodeMirror的公式弹框需要特殊处理下
- return;
- }
- var isHide = this.options.hideChecker.apply(this, [e]);
- if (isHide === false) {
+ if (!this.nodes) {
return;
}
- this._hideView();
- },
-
- _hideView: function () {
- this.fireEvent(BI.Combo.EVENT_BEFORE_HIDEVIEW);
- if (this.options.destroyWhenHide === true) {
- this.popupView && this.popupView.destroy();
- this.popupView = null;
- this._rendered = false;
- } else {
- this.popupView && this.popupView.invisible();
- }
- this.element.removeClass(this.options.comboClass);
- BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName());
- this.fireEvent(BI.Combo.EVENT_AFTER_HIDEVIEW);
+ BI.each(this.nodes.getNodes(), function (i, node) {
+ node.halfCheck = false;
+ setNode(node.children);
+ });
+ this.nodes.checkAllNodes(checked);
},
- _popupView: function () {
- this._assertPopupViewRender();
- this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW);
+ expandAll: function (flag) {
+ this.nodes && this.nodes.expandAll(flag);
+ },
- this.popupView.visible();
- this.adjustWidth();
- this.adjustHeight();
+ // 设置树节点的状态
+ setValue: function (value, param) {
+ this.checkAll(false);
+ this.updateValue(value, param);
+ this.refresh();
+ },
- this.element.addClass(this.options.comboClass);
- BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName());
- BI.Widget._renderEngine.createElement(document).bind("mousedown." + this.getName(), BI.bind(this._hideIf, this)).bind("mousewheel." + this.getName(), BI.bind(this._hideIf, this));
- this.fireEvent(BI.Combo.EVENT_AFTER_POPUPVIEW);
+ setSelectedValue: function (value) {
+ this.options.paras.selectedValues = BI.deepClone(value || {});
},
- adjustWidth: function () {
- var o = this.options;
- if (!this.popupView) {
+ updateValue: function (values, param) {
+ if (!this.nodes) {
return;
}
- if (o.isNeedAdjustWidth === true) {
- this.resetListWidth("");
- var width = this.popupView.element.outerWidth();
- var maxW = this.element.outerWidth() || o.width;
- if (width > maxW + 80) {
- maxW = maxW + 80;
- } else if (width > maxW) {
- maxW = width;
- }
- this.resetListWidth(maxW < 100 ? 100 : maxW);
- }
+ param || (param = "value");
+ var treeObj = this.nodes;
+ BI.each(values, function (v, op) {
+ var nodes = treeObj.getNodesByParam(param, v, null);
+ BI.each(nodes, function (j, node) {
+ BI.extend(node, {checked: true}, op);
+ treeObj.updateNode(node);
+ });
+ });
},
- adjustHeight: function () {
- var o = this.options, p = {};
- if (!this.popupView) {
- return;
+ refresh: function () {
+ this.nodes && this.nodes.refresh();
+ },
+
+ getValue: function () {
+ if (!this.nodes) {
+ return null;
}
- var isVisible = this.popupView.isVisible();
- this.popupView.visible();
- switch (o.direction) {
- case "bottom":
- case "bottom,right":
- p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["bottom", "top", "right", "left"], o.offsetStyle);
- break;
- case "top":
- case "top,right":
- p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["top", "bottom", "right", "left"], o.offsetStyle);
- break;
- case "left":
- case "left,bottom":
- p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["left", "right", "bottom", "top"], o.offsetStyle);
- break;
- case "right":
- case "right,bottom":
- p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "bottom", "top"], o.offsetStyle);
- break;
- case "top,left":
- p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["top", "bottom", "left", "right"], o.offsetStyle);
- break;
- case "bottom,left":
- p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["bottom", "top", "left", "right"], o.offsetStyle);
- break;
- case "left,top":
- p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["left", "right", "top", "bottom"], o.offsetStyle);
- break;
- case "right,top":
- p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle);
- break;
- case "top,custom":
- case "custom,top":
- p = $.getTopAdaptPosition(this.combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight);
- break;
- case "custom,bottom":
- case "bottom,custom":
- p = $.getBottomAdaptPosition(this.combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight);
- break;
- case "left,custom":
- case "custom,left":
- p = $.getLeftAdaptPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength);
- delete p.top;
- delete p.adaptHeight;
- break;
- case "custom,right":
- case "right,custom":
- p = $.getRightAdaptPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength);
- delete p.top;
- delete p.adaptHeight;
- break;
- }
-
- if ("adaptHeight" in p) {
- this.resetListHeight(p["adaptHeight"]);
- }
- if ("left" in p) {
- this.popupView.element.css({
- left: p.left
- });
- }
- if ("top" in p) {
- this.popupView.element.css({
- top: p.top
- });
- }
- this.position = p;
- this.popupView.setVisible(isVisible);
+ return this._getSelectedValues();
},
- resetListHeight: function (h) {
- this._assertPopupView();
- this.popupView.resetHeight && this.popupView.resetHeight(h);
- },
+ destroyed: function () {
+ this.stop();
+ this.nodes && this.nodes.destroy();
+ }
+});
+BI.extend(BI.TreeView, {
+ REQ_TYPE_INIT_DATA: 1,
+ REQ_TYPE_ADJUST_DATA: 2,
+ REQ_TYPE_SELECT_DATA: 3,
+ REQ_TYPE_GET_SELECTED_DATA: 4
+});
- resetListWidth: function (w) {
- this._assertPopupView();
- this.popupView.resetWidth && this.popupView.resetWidth(w);
- },
+BI.TreeView.EVENT_CHANGE = "EVENT_CHANGE";
+BI.TreeView.EVENT_INIT = BI.Events.INIT;
+BI.TreeView.EVENT_AFTERINIT = BI.Events.AFTERINIT;
- populate: function (items) {
- this._assertPopupView();
- this.popupView.populate.apply(this.popupView, arguments);
- this.combo.populate.apply(this.combo, arguments);
+BI.shortcut("bi.tree_view", BI.TreeView);/**
+ * guy
+ * 同步树
+ * @class BI.AsyncTree
+ * @extends BI.TreeView
+ */
+BI.AsyncTree = BI.inherit(BI.TreeView, {
+ _defaultConfig: function () {
+ return BI.extend(BI.AsyncTree.superclass._defaultConfig.apply(this, arguments), {});
+ },
+ _init: function () {
+ BI.AsyncTree.superclass._init.apply(this, arguments);
},
- _setEnable: function (arg) {
- BI.Combo.superclass._setEnable.apply(this, arguments);
- if (arg === true) {
- this.element.removeClass("base-disabled disabled");
- } else if (arg === false) {
- this.element.addClass("base-disabled disabled");
+ // 配置属性
+ _configSetting: function () {
+ var paras = this.options.paras;
+ var self = this;
+ var setting = {
+ async: {
+ enable: false,
+ otherParam: BI.cjkEncodeDO(paras)
+ },
+ check: {
+ enable: true
+ },
+ data: {
+ key: {
+ title: "title",
+ name: "text"
+ },
+ simpleData: {
+ enable: true
+ }
+ },
+ view: {
+ showIcon: false,
+ expandSpeed: "",
+ nameIsHTML: true,
+ dblClickExpand: false
+ },
+ callback: {
+ beforeCheck: beforeCheck,
+ onCheck: onCheck,
+ beforeExpand: beforeExpand,
+ onExpand: onExpand,
+ onCollapse: onCollapse,
+ onClick: onClick
+ }
+ };
+
+ function onClick (event, treeId, treeNode) {
+ var zTree = $.fn.zTree.getZTreeObj(treeId);
+ zTree.checkNode(treeNode, !treeNode.checked, true, true);
}
- !arg && this.element.removeClass(this.options.hoverClass);
- !arg && this.isViewVisible() && this._hideView();
- },
- setValue: function (v) {
- this.combo.setValue(v);
- if (BI.isNull(this.popupView)) {
- this.options.popup.value = v;
- } else {
- this.popupView.setValue(v);
+ function beforeCheck (treeId, treeNode) {
+ treeNode.halfCheck = false;
+ if (treeNode.checked === true) {
+ // 将展开的节点halfCheck设为false,解决展开节点存在halfCheck=true的情况 guy
+ // 所有的半选状态都需要取消halfCheck=true的情况
+ function track (children) {
+ BI.each(children, function (i, ch) {
+ if (ch.halfCheck === true) {
+ ch.halfCheck = false;
+ track(ch.children);
+ }
+ });
+ }
+
+ track(treeNode.children);
+
+ var treeObj = $.fn.zTree.getZTreeObj(treeId);
+ var nodes = treeObj.getSelectedNodes();
+ BI.each(nodes, function (index, node) {
+ node.halfCheck = false;
+ });
+ }
+ var status = treeNode.getCheckStatus();
+ // 当前点击节点的状态是半选,且为true_part, 则将其改为false_part,使得点击半选后切换到的是全选
+ if(status.half === true && status.checked === true) {
+ treeNode.checked = false;
+ }
}
- },
- getValue: function () {
- if (BI.isNull(this.popupView)) {
- return this.options.popup.value;
- } else {
- return this.popupView.getValue();
+ function beforeExpand (treeId, treeNode) {
+ self._beforeExpandNode(treeId, treeNode);
}
- },
- isViewVisible: function () {
- return this.isEnabled() && this.combo.isEnabled() && !!this.popupView && this.popupView.isVisible();
- },
+ function onCheck (event, treeId, treeNode) {
+ self._selectTreeNode(treeId, treeNode);
+ }
- showView: function () {
- if (this.isEnabled() && this.combo.isEnabled()) {
- this._popupView();
+ function onExpand (event, treeId, treeNode) {
+ treeNode.halfCheck = false;
}
- },
- hideView: function () {
- this._hideView();
- },
+ function onCollapse (event, treeId, treeNode) {
+ treeNode.halfCheck = false;
+ }
- getView: function () {
- return this.popupView;
+ return setting;
},
- getPopupPosition: function () {
- return this.position;
+ _selectTreeNode: function (treeId, treeNode) {
+ var self = this, o = this.options;
+ var parentValues = BI.deepClone(treeNode.parentValues || self._getParentValues(treeNode));
+ var name = this._getNodeValue(treeNode);
+ // var values = parentValues.concat([name]);
+ if (treeNode.checked === true) {
+ } else {
+ var tNode = treeNode;
+ var pNode = this._getTree(this.options.paras.selectedValues, parentValues);
+ if (BI.isNotNull(pNode[name])) {
+ delete pNode[name];
+ }
+ while (tNode != null && BI.isEmpty(pNode)) {
+ parentValues = parentValues.slice(0, parentValues.length - 1);
+ tNode = tNode.getParentNode();
+ if (tNode != null) {
+ pNode = this._getTree(this.options.paras.selectedValues, parentValues);
+ name = this._getNodeValue(tNode);
+ delete pNode[name];
+ }
+ }
+ }
+ BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments);
},
- toggle: function () {
- this._toggle();
- },
+ // 展开节点
+ _beforeExpandNode: function (treeId, treeNode) {
+ var self = this, o = this.options;
+ var parentValues = treeNode.parentValues || self._getParentValues(treeNode);
+ var op = BI.extend({}, o.paras, {
+ id: treeNode.id,
+ times: 1,
+ parentValues: parentValues.concat(this._getNodeValue(treeNode)),
+ checkState: treeNode.getCheckStatus()
+ });
+ var complete = function (d) {
+ var nodes = d.items || [];
+ if (nodes.length > 0) {
+ callback(self._dealWidthNodes(nodes), !!d.hasNext);
+ }
+ };
+ var times = 1;
- destroy: function () {
- BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName())
- .unbind("mousewheel." + this.getName())
- .unbind("mouseenter." + this.getName())
- .unbind("mousemove." + this.getName())
- .unbind("mouseleave." + this.getName());
- BI.Resizers.remove(this.getName());
- BI.Combo.superclass.destroy.apply(this, arguments);
- }
-});
-BI.Combo.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE";
-BI.Combo.EVENT_CHANGE = "EVENT_CHANGE";
-BI.Combo.EVENT_EXPAND = "EVENT_EXPAND";
-BI.Combo.EVENT_COLLAPSE = "EVENT_COLLAPSE";
-BI.Combo.EVENT_AFTER_INIT = "EVENT_AFTER_INIT";
-
-
-BI.Combo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
-BI.Combo.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW";
-BI.Combo.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW";
-BI.Combo.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";
-
-BI.shortcut("bi.combo", BI.Combo);/**
- *
- * 某个可以展开的节点
- *
- * Created by GUY on 2015/9/10.
- * @class BI.Expander
- * @extends BI.Widget
- */
-BI.Expander = BI.inherit(BI.Widget, {
- _defaultConfig: function () {
- return BI.extend(BI.Expander.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-expander",
- trigger: "click",
- toggle: true,
- // direction: "bottom", //top,bottom四个方向
- isDefaultInit: false, // 是否默认初始化子节点
- el: {},
- popup: {},
- expanderClass: "bi-expander-popup",
- hoverClass: "bi-expander-hover"
- });
- },
+ function callback (nodes, hasNext) {
+ self.nodes.addNodes(treeNode, nodes);
- _init: function () {
- BI.Expander.superclass._init.apply(this, arguments);
- var self = this, o = this.options;
- this._expanded = !!o.el.open;
- this._initExpander();
- this._initPullDownAction();
- this.expander.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- if (self.isEnabled() && self.isValid()) {
- if (type === BI.Events.EXPAND) {
- self._popupView();
- }
- if (type === BI.Events.COLLAPSE) {
- self._hideView();
- }
- if (type === BI.Events.EXPAND) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- self.fireEvent(BI.Expander.EVENT_EXPAND);
- }
- if (type === BI.Events.COLLAPSE) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- self.isViewVisible() && self.fireEvent(BI.Expander.EVENT_COLLAPSE);
- }
- if (type === BI.Events.CLICK) {
- self.fireEvent(BI.Expander.EVENT_TRIGGER_CHANGE, value, obj);
- }
+ if (hasNext === true) {
+ BI.delay(function () {
+ times++;
+ op.times = times;
+ o.itemsCreator(op, complete);
+ }, 100);
}
- });
+ }
- this.element.hover(function () {
- if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) {
- self.element.addClass(o.hoverClass);
- }
- }, function () {
- if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) {
- self.element.removeClass(o.hoverClass);
- }
- });
- BI.createWidget({
- type: "bi.vertical",
- scrolly: false,
- element: this,
- items: [
- {el: this.expander}
- ]
- });
- o.isDefaultInit && this._assertPopupView();
- if (this.expander.isOpened() === true) {
- this._popupView();
+ if (!treeNode.children) {
+ setTimeout(function () {
+ o.itemsCreator(op, complete);
+ }, 17);
}
},
- _toggle: function () {
- this._assertPopupViewRender();
- if (this.popupView.isVisible()) {
- this._hideView();
- } else {
- if (this.isEnabled()) {
- this._popupView();
- }
+ _join: function (valueA, valueB) {
+ var self = this;
+ var map = {};
+ track([], valueA, valueB);
+ track([], valueB, valueA);
+ function track (parent, node, compare) {
+ BI.each(node, function (n, item) {
+ if (BI.isNull(compare[n])) {
+ self._addTreeNode(map, parent, n, item);
+ } else if (BI.isEmpty(compare[n])) {
+ self._addTreeNode(map, parent, n, {});
+ } else {
+ track(parent.concat([n]), node[n], compare[n]);
+ }
+ });
}
- },
- _initPullDownAction: function () {
- var self = this, o = this.options;
- var evs = this.options.trigger.split(",");
- BI.each(evs, function (i, e) {
- switch (e) {
- case "hover":
- self.element[e](function (e) {
- if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) {
- self._popupView();
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.expander);
- self.fireEvent(BI.Expander.EVENT_EXPAND);
- }
- }, function () {
- if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid() && o.toggle) {
- self._hideView();
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.expander);
- self.fireEvent(BI.Expander.EVENT_COLLAPSE);
- }
- });
- break;
- case "click":
- if (e) {
- self.element.off(e + "." + self.getName()).on(e + "." + self.getName(), BI.debounce(function (e) {
- if (self.expander.element.__isMouseInBounds__(e)) {
- if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) {
- o.toggle ? self._toggle() : self._popupView();
- if (self.isExpanded()) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.expander);
- self.fireEvent(BI.Expander.EVENT_EXPAND);
- } else {
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.expander);
- self.fireEvent(BI.Expander.EVENT_COLLAPSE);
- }
- }
- }
- }, BI.EVENT_RESPONSE_TIME, {
- "leading": true,
- "trailing": false
- }));
- }
- break;
- }
- });
+ return map;
},
- _initExpander: function () {
- this.expander = BI.createWidget(this.options.el);
+ hasChecked: function () {
+ return !BI.isEmpty(this.options.paras.selectedValues) || BI.AsyncTree.superclass.hasChecked.apply(this, arguments);
},
- _assertPopupView: function () {
- var self = this, o = this.options;
- if (this.popupView == null) {
- this.popupView = BI.createWidget(this.options.popup, {
- type: "bi.button_group",
- cls: "expander-popup",
- layouts: [{
- type: "bi.vertical",
- hgap: 0,
- vgap: 0
- }],
- value: o.value
- }, this);
- this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- if (type === BI.Events.CLICK) {
- // self.setValue(self.getValue());
- self.fireEvent(BI.Expander.EVENT_CHANGE, value, obj);
- }
- });
- this.popupView.setVisible(this.isExpanded());
- BI.nextTick(function () {
- self.fireEvent(BI.Expander.EVENT_AFTER_INIT);
- });
+ getValue: function () {
+ if (!this.nodes) {
+ return {};
}
- },
-
- _assertPopupViewRender: function () {
- this._assertPopupView();
- if (!this._rendered) {
- BI.createWidget({
- type: "bi.vertical",
- scrolly: false,
- element: this,
- items: [
- {el: this.popupView}
- ]
- });
- this._rendered = true;
+ var checkedValues = this._getSelectedValues();
+ if (BI.isEmpty(checkedValues)) {
+ return BI.deepClone(this.options.paras.selectedValues);
}
+ if (BI.isEmpty(this.options.paras.selectedValues)) {
+ return checkedValues;
+ }
+ return this._join(checkedValues, this.options.paras.selectedValues);
},
- _hideView: function () {
- this.fireEvent(BI.Expander.EVENT_BEFORE_HIDEVIEW);
- this._expanded = false;
- this.expander.setOpened(false);
- this.popupView && this.popupView.invisible();
- this.element.removeClass(this.options.expanderClass);
+ // 生成树方法
+ stroke: function (config) {
+ delete this.options.keyword;
+ BI.extend(this.options.paras, config);
+ var setting = this._configSetting();
+ this._initTree(setting);
+ }
+});
- this.fireEvent(BI.Expander.EVENT_AFTER_HIDEVIEW);
+BI.shortcut("bi.async_tree", BI.AsyncTree);/**
+ * guy
+ * 局部树,两个请求树, 第一个请求构造树,第二个请求获取节点
+ * @class BI.PartTree
+ * @extends BI.AsyncTree
+ */
+BI.PartTree = BI.inherit(BI.AsyncTree, {
+ _defaultConfig: function () {
+ return BI.extend(BI.PartTree.superclass._defaultConfig.apply(this, arguments), {});
},
- _popupView: function () {
- this._assertPopupViewRender();
- this.fireEvent(BI.Expander.EVENT_BEFORE_POPUPVIEW);
- this._expanded = true;
- this.expander.setOpened(true);
- this.popupView.visible();
- this.element.addClass(this.options.expanderClass);
- this.fireEvent(BI.Expander.EVENT_AFTER_POPUPVIEW);
+ _init: function () {
+ BI.PartTree.superclass._init.apply(this, arguments);
},
- populate: function (items) {
- // this._assertPopupView();
- this.popupView && this.popupView.populate.apply(this.popupView, arguments);
- this.expander.populate.apply(this.expander, arguments);
- },
-
- _setEnable: function (arg) {
- BI.Expander.superclass._setEnable.apply(this, arguments);
- !arg && this.element.removeClass(this.options.hoverClass);
- !arg && this.isViewVisible() && this._hideView();
+ _loadMore: function () {
+ var self = this, o = this.options;
+ var op = BI.extend({}, o.paras, {
+ type: BI.TreeView.REQ_TYPE_INIT_DATA,
+ times: ++this.times
+ });
+ this.tip.setLoading();
+ o.itemsCreator(op, function (d) {
+ var hasNext = !!d.hasNext, nodes = d.items || [];
+ o.paras.lastSearchValue = d.lastSearchValue;
+ if (self._stop === true) {
+ return;
+ }
+ if (!hasNext) {
+ self.tip.setEnd();
+ } else {
+ self.tip.setLoaded();
+ }
+ if (nodes.length > 0) {
+ self.nodes.addNodes(null, self._dealWidthNodes(nodes));
+ }
+ });
},
- setValue: function (v) {
- this.expander.setValue(v);
- if (BI.isNull(this.popupView)) {
- this.options.popup.value = v;
+ _selectTreeNode: function (treeId, treeNode) {
+ var self = this, o = this.options;
+ var parentValues = BI.deepClone(treeNode.parentValues || self._getParentValues(treeNode));
+ var name = this._getNodeValue(treeNode);
+ if (treeNode.checked === true) {
+ BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments);
} else {
- this.popupView.setValue(v);
+ // 如果选中的值中不存在该值不处理
+ var t = this.options.paras.selectedValues;
+ var p = parentValues.concat(name);
+ for (var i = 0, len = p.length; i < len; i++) {
+ t = t[p[i]];
+ if (t == null) {
+ return;
+ }
+ if (BI.isEmpty(t)) {
+ break;
+ }
+ }
+ o.itemsCreator(BI.extend({}, o.paras, {
+ type: BI.TreeView.REQ_TYPE_SELECT_DATA,
+ notSelectedValue: name,
+ parentValues: parentValues
+ }), function (new_values) {
+ self.options.paras.selectedValues = new_values;
+ BI.AsyncTree.superclass._selectTreeNode.apply(self, arguments);
+ });
}
},
- getValue: function () {
- if (BI.isNull(this.popupView)) {
- return this.options.popup.value;
- } else {
- return this.popupView.getValue();
+ _getSelectedValues: function () {
+ var self = this;
+ var hashMap = {};
+ var rootNoots = this.nodes.getNodes();
+ track(rootNoots);
+ function track (nodes) {
+ BI.each(nodes, function (i, node) {
+ var checkState = node.getCheckStatus();
+ if (checkState.checked === false) {
+ return true;
+ }
+ var parentValues = node.parentValues || self._getParentValues(node);
+ // 把文字中的html去掉,其实就是把文字颜色去掉
+ var values = parentValues.concat([self._getNodeValue(node)]);
+ self._buildTree(hashMap, values);
+ // if(checkState.checked === true && checkState.half === false && nodes[i].flag === true){
+ // continue;
+ // }
+ if (BI.isNotEmptyArray(node.children)) {
+ track(node.children);
+ return true;
+ }
+ if (checkState.half === true) {
+ self._getHalfSelectedValues(hashMap, node);
+ }
+ });
}
- },
- isViewVisible: function () {
- return this.isEnabled() && this.expander.isEnabled() && !!this.popupView && this.popupView.isVisible();
+ return hashMap;
},
- isExpanded: function () {
- return this._expanded;
- },
+ _initTree: function (setting, keyword) {
+ var self = this, o = this.options;
+ this.times = 1;
+ var tree = this.tree;
+ tree.empty();
+ self.tip.setVisible(false);
+ this.loading();
+ var op = BI.extend({}, o.paras, {
+ type: BI.TreeView.REQ_TYPE_INIT_DATA,
+ times: this.times
+ });
+ var complete = function (d) {
+ if (self._stop === true || keyword != o.paras.keyword) {
+ return;
+ }
+ var hasNext = !!d.hasNext, nodes = d.items || [];
+ o.paras.lastSearchValue = d.lastSearchValue;
+ if (nodes.length > 0) {
+ callback(self._dealWidthNodes(nodes));
+ }
+ self.setTipVisible(nodes.length <= 0);
+ self.loaded();
+ if (!hasNext) {
+ self.tip.invisible();
+ } else {
+ self.tip.setLoaded();
+ }
+ self.fireEvent(BI.Events.AFTERINIT);
+ };
- showView: function () {
- if (this.isEnabled() && this.expander.isEnabled()) {
- this._popupView();
+ function callback (nodes) {
+ if (self._stop === true) {
+ return;
+ }
+ self.nodes = $.fn.zTree.init(tree.element, setting, nodes);
}
- },
-
- hideView: function () {
- this._hideView();
- },
-
- getView: function () {
- return this.popupView;
- },
- getAllLeaves: function () {
- return this.popupView && this.popupView.getAllLeaves();
- },
-
- getNodeById: function (id) {
- if (this.expander.options.id === id) {
- return this.expander;
- }
- return this.popupView && this.popupView.getNodeById(id);
+ BI.delay(function () {
+ o.itemsCreator(op, complete);
+ }, 100);
},
- getNodeByValue: function (value) {
- if (this.expander.getValue() === value) {
- return this.expander;
- }
- return this.popupView && this.popupView.getNodeByValue(value);
+ getValue: function () {
+ var o = this.options;
+ var result = BI.PartTree.superclass.getValue.apply(this, arguments);
+ o.itemsCreator({
+ type: BI.TreeView.REQ_TYPE_ADJUST_DATA,
+ selectedValues: result
+ }, function (res) {
+ result = res;
+ });
+ return result;
},
- destroy: function () {
- BI.Expander.superclass.destroy.apply(this, arguments);
+ // 生成树方法
+ stroke: function (config) {
+ var o = this.options;
+ delete o.paras.keyword;
+ BI.extend(o.paras, config);
+ delete o.paras.lastSearchValue;
+ var setting = this._configSetting();
+ this._initTree(setting, o.paras.keyword);
}
});
-BI.Expander.EVENT_EXPAND = "EVENT_EXPAND";
-BI.Expander.EVENT_COLLAPSE = "EVENT_COLLAPSE";
-BI.Expander.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE";
-BI.Expander.EVENT_CHANGE = "EVENT_CHANGE";
-BI.Expander.EVENT_AFTER_INIT = "EVENT_AFTER_INIT";
-
-
-BI.Expander.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
-BI.Expander.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW";
-BI.Expander.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW";
-BI.Expander.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";
-BI.shortcut("bi.expander", BI.Expander);/**
- * Created by GUY on 2015/8/10.
+BI.shortcut("bi.part_tree", BI.PartTree);BI.prepares.push(function () {
+ BI.Resizers = new BI.ResizeController();
+ BI.Layers = new BI.LayerController();
+ BI.Maskers = new BI.MaskersController();
+ BI.Bubbles = new BI.BubblesController();
+ BI.Tooltips = new BI.TooltipsController();
+ BI.Popovers = new BI.PopoverController();
+ BI.Broadcasts = new BI.BroadcastController();
+ BI.StyleLoaders = new BI.StyleLoaderManager();
+});
+/**
+ * CollectionView
+ *
+ * Created by GUY on 2016/1/15.
+ * @class BI.CollectionView
+ * @extends BI.Widget
*/
-
-BI.ComboGroup = BI.inherit(BI.Widget, {
+BI.CollectionView = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- return BI.extend(BI.ComboGroup.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-combo-group bi-list-item",
-
- // 以下这些属性对每一个combo都是公用的
- trigger: "click,hover",
- direction: "right",
- adjustLength: 0,
- isDefaultInit: false,
- isNeedAdjustHeight: false,
- isNeedAdjustWidth: false,
-
- el: {type: "bi.text_button", text: "", value: ""},
- children: [],
-
- popup: {
- el: {
- type: "bi.button_tree",
- chooseType: 0,
- layouts: [{
- type: "bi.vertical"
- }]
- }
- }
+ return BI.extend(BI.CollectionView.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-collection",
+ // width: 400, //必设
+ // height: 300, //必设
+ overflowX: true,
+ overflowY: true,
+ cellSizeAndPositionGetter: BI.emptyFn,
+ horizontalOverscanSize: 0,
+ verticalOverscanSize: 0,
+ scrollLeft: 0,
+ scrollTop: 0,
+ items: []
});
},
_init: function () {
- BI.ComboGroup.superclass._init.apply(this, arguments);
- this._populate(this.options.el);
- },
-
- _populate: function (item) {
+ BI.CollectionView.superclass._init.apply(this, arguments);
var self = this, o = this.options;
- var children = o.children;
- if (BI.isEmpty(children)) {
- throw new Error("ComboGroup构造错误");
- }
- BI.each(children, function (i, ch) {
- var son = BI.formatEL(ch).el.children;
- ch = BI.formatEL(ch).el;
- if (!BI.isEmpty(son)) {
- ch.el = BI.clone(ch);
- ch.children = son;
- ch.type = "bi.combo_group";
- ch.action = o.action;
- ch.height = o.height;
- ch.direction = o.direction;
- ch.isDefaultInit = o.isDefaultInit;
- ch.isNeedAdjustHeight = o.isNeedAdjustHeight;
- ch.isNeedAdjustWidth = o.isNeedAdjustWidth;
- ch.adjustLength = o.adjustLength;
- ch.popup = o.popup;
- }
- });
- this.combo = BI.createWidget({
- type: "bi.combo",
- element: this,
- container: o.container,
- height: o.height,
- trigger: o.trigger,
- direction: o.direction,
- isDefaultInit: o.isDefaultInit,
- isNeedAdjustWidth: o.isNeedAdjustWidth,
- isNeedAdjustHeight: o.isNeedAdjustHeight,
- adjustLength: o.adjustLength,
- el: item,
- popup: BI.extend({}, o.popup, {
- el: BI.extend({
- items: children
- }, o.popup.el)
- })
+ this.renderedCells = [];
+ this.renderedKeys = [];
+ this.renderRange = {};
+ this._scrollLock = false;
+ this._debounceRelease = BI.debounce(function () {
+ self._scrollLock = false;
+ }, 1000 / 60);
+ this.container = BI.createWidget({
+ type: "bi.absolute"
});
- this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- if (type === BI.Events.CLICK) {
- self.fireEvent(BI.ComboGroup.EVENT_CHANGE, obj);
+ this.element.scroll(function () {
+ if (self._scrollLock === true) {
+ return;
}
+ o.scrollLeft = self.element.scrollLeft();
+ o.scrollTop = self.element.scrollTop();
+ self._calculateChildrenToRender();
+ self.fireEvent(BI.CollectionView.EVENT_SCROLL, {
+ scrollLeft: o.scrollLeft,
+ scrollTop: o.scrollTop
+ });
});
- },
-
- getValue: function () {
- return this.combo.getValue();
- },
-
- setValue: function (v) {
- this.combo.setValue(v);
- }
-});
-BI.ComboGroup.EVENT_CHANGE = "EVENT_CHANGE";
-
-BI.shortcut("bi.combo_group", BI.ComboGroup);BI.VirtualGroup = BI.inherit(BI.Widget, {
- _defaultConfig: function () {
- return BI.extend(BI.VirtualGroup.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-virtual-group",
- items: [],
- layouts: [{
- type: "bi.center",
- hgap: 0,
- vgap: 0
- }]
+ BI.createWidget({
+ type: "bi.vertical",
+ element: this,
+ scrollable: o.overflowX === true && o.overflowY === true,
+ scrolly: o.overflowX === false && o.overflowY === true,
+ scrollx: o.overflowX === true && o.overflowY === false,
+ items: [this.container]
});
- },
-
- render: function () {
- var o = this.options;
- this.populate(o.items);
- if (BI.isKey(o.value)) {
- this.setValue(o.value);
- }
- },
-
- _packageBtns: function (items) {
- var o = this.options;
- var map = this.buttonMap = {};
- for (var i = o.layouts.length - 1; i > 0; i--) {
- items = BI.map(items, function (k, it) {
- var el = BI.stripEL(it);
- return BI.extend({}, o.layouts[i], {
- items: [
- BI.extend({}, o.layouts[i].el, {
- el: BI.extend({
- ref: function (_ref) {
- if (BI.isKey(map[el.value])) {
- map[el.value] = _ref;
- }
- }
- }, el)
- })
- ]
- });
- });
+ if (o.items.length > 0) {
+ this._calculateSizeAndPositionData();
+ this._populate();
}
- return items;
},
- _packageLayout: function (items) {
- var o = this.options, layout = BI.deepClone(o.layouts[0]);
-
- var lay = BI.formatEL(layout).el;
- while (lay && lay.items && !BI.isEmpty(lay.items)) {
- lay = BI.formatEL(lay.items[0]).el;
+ mounted: function () {
+ var o = this.options;
+ if (o.scrollLeft !== 0 || o.scrollTop !== 0) {
+ this.element.scrollTop(o.scrollTop);
+ this.element.scrollLeft(o.scrollLeft);
}
- lay.items = items;
- return layout;
- },
-
- addItems: function (items) {
- this.layouts.addItems(items);
},
- prependItems: function (items) {
- this.layouts.prependItems(items);
- },
+ _calculateSizeAndPositionData: function () {
+ var o = this.options;
+ var cellMetadata = [];
+ var sectionManager = new BI.SectionManager();
+ var height = 0;
+ var width = 0;
- setValue: function (v) {
- v = BI.isArray(v) ? v : [v];
- BI.each(this.buttonMap, function (key, item) {
- if (item) {
- if (v.deepContains(key)) {
- item.setSelected && item.setSelected(true);
- } else {
- item.setSelected && item.setSelected(false);
- }
- }
- });
- },
+ for (var index = 0, len = o.items.length; index < len; index++) {
+ var cellMetadatum = o.cellSizeAndPositionGetter(index);
- getNotSelectedValue: function () {
- var v = [];
- BI.each(this.buttonMap, function (i, item) {
- if (item) {
- if (item.isEnabled() && !(item.isSelected && item.isSelected())) {
- v.push(item.getValue());
- }
+ if (cellMetadatum.height == null || isNaN(cellMetadatum.height) ||
+ cellMetadatum.width == null || isNaN(cellMetadatum.width) ||
+ cellMetadatum.x == null || isNaN(cellMetadatum.x) ||
+ cellMetadatum.y == null || isNaN(cellMetadatum.y)) {
+ throw Error();
}
- });
- return v;
- },
- getValue: function () {
- var v = [];
- BI.each(this.buttonMap, function (i, item) {
- if (item) {
- if (item.isEnabled() && item.isSelected && item.isSelected()) {
- v.push(item.getValue());
- }
- }
- });
- return v;
- },
+ height = Math.max(height, cellMetadatum.y + cellMetadatum.height);
+ width = Math.max(width, cellMetadatum.x + cellMetadatum.width);
- populate: function (items) {
- var self = this;
- items = items || [];
- this.options.items = items;
- items = this._packageBtns(items);
- if (!this.layouts) {
- this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items)));
- } else {
- this.layouts.populate(items);
+ cellMetadatum.index = index;
+ cellMetadata[index] = cellMetadatum;
+ sectionManager.registerCell(cellMetadatum, index);
}
- }
-});
-BI.VirtualGroup.EVENT_CHANGE = "EVENT_CHANGE";
-
-BI.shortcut("bi.virtual_group", BI.VirtualGroup);/**
- * 加载控件
- *
- * Created by GUY on 2015/8/31.
- * @class BI.Loader
- * @extends BI.Widget
- */
-BI.Loader = BI.inherit(BI.Widget, {
- _defaultConfig: function () {
- return BI.extend(BI.Loader.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-loader",
- direction: "top",
- isDefaultInit: true, // 是否默认初始化数据
- logic: {
- dynamic: true,
- scrolly: true
- },
-
- // 下面是button_group的属性
- el: {
- type: "bi.button_group"
- },
+ this._cellMetadata = cellMetadata;
+ this._sectionManager = sectionManager;
+ this._height = height;
+ this._width = width;
+ },
- items: [],
- itemsCreator: BI.emptyFn,
- onLoaded: BI.emptyFn,
+ _cellRenderers: function (height, width, x, y) {
+ this._lastRenderedCellIndices = this._sectionManager.getCellIndices(height, width, x, y);
+ return this._cellGroupRenderer();
+ },
- // 下面是分页信息
- count: false,
- prev: false,
- next: {},
- hasPrev: BI.emptyFn,
- hasNext: BI.emptyFn
+ _cellGroupRenderer: function () {
+ var self = this, o = this.options;
+ var rendered = [];
+ BI.each(this._lastRenderedCellIndices, function (i, index) {
+ var cellMetadata = self._sectionManager.getCellMetadata(index);
+ rendered.push(cellMetadata);
});
+ return rendered;
},
- _prevLoad: function () {
+ _calculateChildrenToRender: function () {
var self = this, o = this.options;
- this.prev.setLoading();
- o.itemsCreator.apply(this, [{times: --this.times}, function () {
- self.prev.setLoaded();
- self.prependItems.apply(self, arguments);
- }]);
- },
-
- _nextLoad: function () {
- var self = this, o = this.options;
- this.next.setLoading();
- o.itemsCreator.apply(this, [{times: ++this.times}, function () {
- self.next.setLoaded();
- self.addItems.apply(self, arguments);
- }]);
- },
-
- _init: function () {
- BI.Loader.superclass._init.apply(this, arguments);
- var self = this, o = this.options;
- if (o.itemsCreator === false) {
- o.prev = false;
- o.next = false;
- }
- if (o.prev !== false) {
- this.prev = BI.createWidget(BI.extend({
- type: "bi.loading_bar"
- }, o.prev));
- this.prev.on(BI.Controller.EVENT_CHANGE, function (type) {
- if (type === BI.Events.CLICK) {
- self._prevLoad();
+ var scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft());
+ var scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop());
+ var left = Math.max(0, scrollLeft - o.horizontalOverscanSize);
+ var top = Math.max(0, scrollTop - o.verticalOverscanSize);
+ var right = Math.min(this._width, scrollLeft + o.width + o.horizontalOverscanSize);
+ var bottom = Math.min(this._height, scrollTop + o.height + o.verticalOverscanSize);
+ if (right > 0 && bottom > 0) {
+ // 如果滚动的区间并没有超出渲染的范围
+ if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) {
+ return;
+ }
+ var childrenToDisplay = this._cellRenderers(bottom - top, right - left, left, top);
+ var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
+ // 存储所有的left和top
+ var lefts = {}, tops = {};
+ for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
+ var datum = childrenToDisplay[i];
+ lefts[datum.x] = datum.x;
+ lefts[datum.x + datum.width] = datum.x + datum.width;
+ tops[datum.y] = datum.y;
+ tops[datum.y + datum.height] = datum.y + datum.height;
+ }
+ lefts = BI.toArray(lefts);
+ tops = BI.toArray(tops);
+ var leftMap = BI.invert(lefts);
+ var topMap = BI.invert(tops);
+ // 存储上下左右四个边界
+ var leftBorder = {}, rightBorder = {}, topBorder = {}, bottomBorder = {};
+ var assertMinBorder = function (border, offset) {
+ if (border[offset] == null) {
+ border[offset] = Number.MAX_VALUE;
+ }
+ };
+ var assertMaxBorder = function (border, offset) {
+ if (border[offset] == null) {
+ border[offset] = 0;
+ }
+ };
+ for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
+ var datum = childrenToDisplay[i];
+ var index = this.renderedKeys[datum.index] && this.renderedKeys[datum.index][1];
+ var child;
+ if (index >= 0) {
+ if (datum.width !== this.renderedCells[index]._width) {
+ this.renderedCells[index]._width = datum.width;
+ this.renderedCells[index].el.setWidth(datum.width);
+ }
+ if (datum.height !== this.renderedCells[index]._height) {
+ this.renderedCells[index]._height = datum.height;
+ this.renderedCells[index].el.setHeight(datum.height);
+ }
+ if (this.renderedCells[index]._left !== datum.x) {
+ this.renderedCells[index].el.element.css("left", datum.x + "px");
+ }
+ if (this.renderedCells[index]._top !== datum.y) {
+ this.renderedCells[index].el.element.css("top", datum.y + "px");
+ }
+ renderedCells.push(child = this.renderedCells[index]);
+ } else {
+ child = BI.createWidget(BI.extend({
+ type: "bi.label",
+ width: datum.width,
+ height: datum.height
+ }, o.items[datum.index], {
+ cls: (o.items[datum.index].cls || "") + " container-cell" + (datum.y === 0 ? " first-row" : "") + (datum.x === 0 ? " first-col" : ""),
+ _left: datum.x,
+ _top: datum.y
+ }));
+ renderedCells.push({
+ el: child,
+ left: datum.x,
+ top: datum.y,
+ _left: datum.x,
+ _top: datum.y,
+ _width: datum.width,
+ _height: datum.height
+ });
+ }
+ var startTopIndex = topMap[datum.y] | 0;
+ var endTopIndex = topMap[datum.y + datum.height] | 0;
+ for (var k = startTopIndex; k <= endTopIndex; k++) {
+ var t = tops[k];
+ assertMinBorder(leftBorder, t);
+ assertMaxBorder(rightBorder, t);
+ leftBorder[t] = Math.min(leftBorder[t], datum.x);
+ rightBorder[t] = Math.max(rightBorder[t], datum.x + datum.width);
+ }
+ var startLeftIndex = leftMap[datum.x] | 0;
+ var endLeftIndex = leftMap[datum.x + datum.width] | 0;
+ for (var k = startLeftIndex; k <= endLeftIndex; k++) {
+ var l = lefts[k];
+ assertMinBorder(topBorder, l);
+ assertMaxBorder(bottomBorder, l);
+ topBorder[l] = Math.min(topBorder[l], datum.y);
+ bottomBorder[l] = Math.max(bottomBorder[l], datum.y + datum.height);
}
- });
- }
- this.button_group = BI.createWidget(o.el, {
- type: "bi.button_group",
- chooseType: 0,
- items: o.items,
- behaviors: {},
- layouts: [{
- type: "bi.vertical"
- }]
- });
- this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- if (type === BI.Events.CLICK) {
- self.fireEvent(BI.Loader.EVENT_CHANGE, obj);
+ renderedKeys[datum.index] = [datum.index, i];
+ renderedWidgets[i] = child;
}
- });
-
- if (o.next !== false) {
- this.next = BI.createWidget(BI.extend({
- type: "bi.loading_bar"
- }, o.next));
- this.next.on(BI.Controller.EVENT_CHANGE, function (type) {
- if (type === BI.Events.CLICK) {
- self._nextLoad();
+ // 已存在的, 需要添加的和需要删除的
+ var existSet = {}, addSet = {}, deleteArray = [];
+ BI.each(renderedKeys, function (i, key) {
+ if (self.renderedKeys[i]) {
+ existSet[i] = key;
+ } else {
+ addSet[i] = key;
}
});
- }
+ BI.each(this.renderedKeys, function (i, key) {
+ if (existSet[i]) {
+ return;
+ }
+ if (addSet[i]) {
+ return;
+ }
+ deleteArray.push(key[1]);
+ });
+ BI.each(deleteArray, function (i, index) {
+ // 性能优化,不调用destroy方法防止触发destroy事件
+ self.renderedCells[index].el._destroy();
+ });
+ var addedItems = [];
+ BI.each(addSet, function (index, key) {
+ addedItems.push(renderedCells[key[1]]);
+ });
+ this.container.addItems(addedItems);
+ // 拦截父子级关系
+ this.container._children = renderedWidgets;
+ this.container.attr("items", renderedCells);
+ this.renderedCells = renderedCells;
+ this.renderedKeys = renderedKeys;
- 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.prev, this.button_group, this.next)
- }))));
+ // Todo 左右比较特殊
+ var minX = BI.min(leftBorder);
+ var maxX = BI.max(rightBorder);
- o.isDefaultInit && BI.isEmpty(o.items) && BI.nextTick(BI.bind(function () {
- o.isDefaultInit && BI.isEmpty(o.items) && this.populate();
- }, this));
- if (BI.isNotEmptyArray(o.items)) {
- this.populate(o.items);
+ var minY = BI.max(topBorder);
+ var maxY = BI.min(bottomBorder);
+
+ this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
}
},
- hasPrev: function () {
- var o = this.options;
- if (BI.isNumber(o.count)) {
- return this.count < o.count;
- }
- return !!o.hasPrev.apply(this, [{
- times: this.times,
- count: this.count
- }]);
+ _getMaxScrollLeft: function () {
+ return Math.max(0, this._width - this.options.width + (this.options.overflowX ? BI.DOM.getScrollWidth() : 0));
},
- hasNext: function () {
- var o = this.options;
- if (BI.isNumber(o.count)) {
- return this.count < o.count;
- }
- return !!o.hasNext.apply(this, [{
- times: this.times,
- count: this.count
- }]);
+ _getMaxScrollTop: function () {
+ return Math.max(0, this._height - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0));
},
- prependItems: function (items) {
- this.count += items.length;
- if (this.next !== false) {
- if (this.hasPrev()) {
- this.options.items = this.options.items.concat(items);
- this.prev.setLoaded();
- } else {
- this.prev.setEnd();
- }
+ _populate: function (items) {
+ var o = this.options;
+ this._reRange();
+ if (items && items !== this.options.items) {
+ this.options.items = items;
+ this._calculateSizeAndPositionData();
}
- this.button_group.prependItems.apply(this.button_group, arguments);
- },
+ if (o.items.length > 0) {
+ this.container.setWidth(this._width);
+ this.container.setHeight(this._height);
- addItems: function (items) {
- this.count += items.length;
- if (BI.isObject(this.next)) {
- if (this.hasNext()) {
- this.options.items = this.options.items.concat(items);
- this.next.setLoaded();
- } else {
- this.next.setEnd();
+ this._calculateChildrenToRender();
+ // 元素未挂载时不能设置scrollTop
+ try {
+ this.element.scrollTop(o.scrollTop);
+ this.element.scrollLeft(o.scrollLeft);
+ } catch (e) {
}
}
- this.button_group.addItems.apply(this.button_group, arguments);
},
- populate: function (items) {
- var self = this, o = this.options;
- if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) {
- o.itemsCreator.apply(this, [{times: 1}, function () {
- if (arguments.length === 0) {
- throw new Error("arguments can not be null!!!");
- }
- self.populate.apply(self, arguments);
- o.onLoaded();
- }]);
+ setScrollLeft: function (scrollLeft) {
+ if (this.options.scrollLeft === scrollLeft) {
return;
}
- this.options.items = items;
- this.times = 1;
- this.count = 0;
- this.count += items.length;
- if (BI.isObject(this.next)) {
- if (this.hasNext()) {
- this.next.setLoaded();
- } else {
- this.next.invisible();
- }
- }
- if (BI.isObject(this.prev)) {
- if (this.hasPrev()) {
- this.prev.setLoaded();
- } else {
- this.prev.invisible();
- }
- }
- this.button_group.populate.apply(this.button_group, arguments);
- },
-
- setNotSelectedValue: function () {
- this.button_group.setNotSelectedValue.apply(this.button_group, arguments);
- },
-
- getNotSelectedValue: function () {
- return this.button_group.getNotSelectedValue();
+ this._scrollLock = true;
+ this.options.scrollLeft = BI.clamp(scrollLeft || 0, 0, this._getMaxScrollLeft());
+ this._debounceRelease();
+ this._calculateChildrenToRender();
+ this.element.scrollLeft(this.options.scrollLeft);
},
- setValue: function () {
- this.button_group.setValue.apply(this.button_group, arguments);
+ setScrollTop: function (scrollTop) {
+ if (this.options.scrollTop === scrollTop) {
+ return;
+ }
+ this._scrollLock = true;
+ this.options.scrollTop = BI.clamp(scrollTop || 0, 0, this._getMaxScrollTop());
+ this._debounceRelease();
+ this._calculateChildrenToRender();
+ this.element.scrollTop(this.options.scrollTop);
},
- getValue: function () {
- return this.button_group.getValue.apply(this.button_group, arguments);
+ setOverflowX: function (b) {
+ var self = this;
+ if (this.options.overflowX !== !!b) {
+ this.options.overflowX = !!b;
+ BI.nextTick(function () {
+ self.element.css({overflowX: b ? "auto" : "hidden"});
+ });
+ }
},
- getAllButtons: function () {
- return this.button_group.getAllButtons();
+ setOverflowY: function (b) {
+ var self = this;
+ if (this.options.overflowY !== !!b) {
+ this.options.overflowY = !!b;
+ BI.nextTick(function () {
+ self.element.css({overflowY: b ? "auto" : "hidden"});
+ });
+ }
},
- getAllLeaves: function () {
- return this.button_group.getAllLeaves();
+ getScrollLeft: function () {
+ return this.options.scrollLeft;
},
- getSelectedButtons: function () {
- return this.button_group.getSelectedButtons();
+ getScrollTop: function () {
+ return this.options.scrollTop;
},
- getNotSelectedButtons: function () {
- return this.button_group.getNotSelectedButtons();
+ getMaxScrollLeft: function () {
+ return this._getMaxScrollLeft();
},
- getIndexByValue: function (value) {
- return this.button_group.getIndexByValue(value);
+ getMaxScrollTop: function () {
+ return this._getMaxScrollTop();
},
- getNodeById: function (id) {
- return this.button_group.getNodeById(id);
+ // 重新计算children
+ _reRange: function () {
+ this.renderRange = {};
},
- getNodeByValue: function (value) {
- return this.button_group.getNodeByValue(value);
+ _clearChildren: function () {
+ this.container._children = {};
+ this.container.attr("items", []);
},
- empty: function () {
- this.button_group.empty();
- BI.each([this.prev, this.next], function (i, ob) {
- ob && ob.setVisible(false);
+ restore: function () {
+ BI.each(this.renderedCells, function (i, cell) {
+ cell.el._destroy();
});
+ this._clearChildren();
+ this.renderedCells = [];
+ this.renderedKeys = [];
+ this.renderRange = {};
+ this._scrollLock = false;
},
- destroy: function () {
- BI.Loader.superclass.destroy.apply(this, arguments);
+ populate: function (items) {
+ if (items && items !== this.options.items) {
+ this.restore();
+ }
+ this._populate(items);
}
});
-BI.Loader.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.loader", BI.Loader);/**
- * Created by GUY on 2015/6/26.
+BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL";
+BI.shortcut("bi.collection_view", BI.CollectionView);/**
+ * @class BI.Combo
+ * @extends BI.Widget
*/
-
-BI.Navigation = BI.inherit(BI.Widget, {
+BI.Combo = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), {
- direction: "bottom", // top, bottom, left, right, custom
- logic: {
- dynamic: false
- },
- single: false,
- showIndex: false,
- tab: false,
- cardCreator: function (v) {
- return BI.createWidget();
- },
-
- afterCardCreated: BI.emptyFn,
- afterCardShow: BI.emptyFn
+ var conf = BI.Combo.superclass._defaultConfig.apply(this, arguments);
+ return BI.extend(conf, {
+ baseCls: (conf.baseCls || "") + " bi-combo",
+ trigger: "click",
+ toggle: true,
+ direction: "bottom", // top||bottom||left||right||top,left||top,right||bottom,left||bottom,right
+ container: null, // popupview放置的容器,默认为this.element
+ isDefaultInit: false,
+ destroyWhenHide: false,
+ isNeedAdjustHeight: true, // 是否需要高度调整
+ isNeedAdjustWidth: true,
+ stopEvent: false,
+ stopPropagation: false,
+ adjustLength: 0, // 调整的距离
+ adjustXOffset: 0,
+ adjustYOffset: 0,
+ hideChecker: BI.emptyFn,
+ offsetStyle: "left", // left,right,center
+ el: {},
+ popup: {},
+ comboClass: "bi-combo-popup",
+ hoverClass: "bi-combo-hover"
});
},
- render: function () {
+ _init: function () {
+ BI.Combo.superclass._init.apply(this, arguments);
var self = this, o = this.options;
- this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"});
- this.cardMap = {};
- this.showIndex = 0;
- this.layout = BI.createWidget({
- type: "bi.card"
+ this._initCombo();
+ this._initPullDownAction();
+ this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ if (self.isEnabled() && self.isValid()) {
+ if (type === BI.Events.EXPAND) {
+ self._popupView();
+ }
+ if (type === BI.Events.COLLAPSE) {
+ self._hideView();
+ }
+ if (type === BI.Events.EXPAND) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ self.fireEvent(BI.Combo.EVENT_EXPAND);
+ }
+ if (type === BI.Events.COLLAPSE) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ self.isViewVisible() && self.fireEvent(BI.Combo.EVENT_COLLAPSE);
+ }
+ if (type === BI.Events.CLICK) {
+ self.fireEvent(BI.Combo.EVENT_TRIGGER_CHANGE, obj);
+ }
+ }
});
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout)
- }))));
+ self.element.on("mouseenter." + self.getName(), function (e) {
+ if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
+ self.element.addClass(o.hoverClass);
+ }
+ });
+ self.element.on("mouseleave." + self.getName(), function (e) {
+ if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
+ self.element.removeClass(o.hoverClass);
+ }
+ });
- new BI.ShowListener({
- eventObj: this.tab,
- cardLayout: this.layout,
- cardNameCreator: function (v) {
- return self.showIndex + v;
- },
- cardCreator: function (v) {
- var card = o.cardCreator(v);
- self.cardMap[v] = card;
- return card;
- },
- afterCardCreated: BI.bind(this.afterCardCreated, this),
- afterCardShow: BI.bind(this.afterCardShow, this)
+ BI.createWidget({
+ type: "bi.vertical",
+ scrolly: false,
+ element: this,
+ items: [
+ {el: this.combo}
+ ]
});
+ o.isDefaultInit && (this._assertPopupView());
+ BI.Resizers.add(this.getName(), BI.bind(function () {
+ if (this.isViewVisible()) {
+ this._hideView();
+ }
+ }, this));
},
- mounted: function () {
- var o = this.options;
- if (o.showIndex !== false) {
- this.setSelect(o.showIndex);
+ _toggle: function () {
+ this._assertPopupViewRender();
+ if (this.popupView.isVisible()) {
+ this._hideView();
+ } else {
+ if (this.isEnabled()) {
+ this._popupView();
+ }
}
},
- _deleteOtherCards: function (currCardName) {
+ _initPullDownAction: function () {
var self = this, o = this.options;
- if (o.single === true) {
- BI.each(this.cardMap, function (name, card) {
- if (name !== (currCardName + "")) {
- self.layout.deleteCardByName(name);
- delete self.cardMap[name];
- }
- });
+ var evs = this.options.trigger.split(",");
+ var st = function (e) {
+ if (o.stopEvent) {
+ e.stopEvent();
+ }
+ if (o.stopPropagation) {
+ e.stopPropagation();
+ }
+ };
+
+ var enterPopup = false;
+
+ function hide () {
+ if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid() && o.toggle === true) {
+ self._hideView();
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo);
+ self.fireEvent(BI.Combo.EVENT_COLLAPSE);
+ }
+ self.popupView && self.popupView.element.off("mouseenter." + self.getName()).off("mouseleave." + self.getName());
+ enterPopup = false;
}
- },
- afterCardCreated: function (v) {
- var self = this;
- this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- if (type === BI.Events.CLICK) {
- self.fireEvent(BI.Navigation.EVENT_CHANGE, obj);
+ BI.each(evs, function (i, ev) {
+ switch (ev) {
+ case "hover":
+ self.element.on("mouseenter." + self.getName(), function (e) {
+ if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
+ self._popupView();
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo);
+ self.fireEvent(BI.Combo.EVENT_EXPAND);
+ }
+ });
+ self.element.on("mouseleave." + self.getName(), function (e) {
+ if (self.popupView) {
+ self.popupView.element.on("mouseenter." + self.getName(), function (e) {
+ enterPopup = true;
+ self.popupView.element.on("mouseleave." + self.getName(), function (e) {
+ hide();
+ });
+ self.popupView.element.off("mouseenter." + self.getName());
+ });
+ BI.defer(function () {
+ if (!enterPopup) {
+ hide();
+ }
+ }, 50);
+ }
+ });
+ break;
+ case "click":
+ var debounce = BI.debounce(function (e) {
+ if (self.combo.element.__isMouseInBounds__(e)) {
+ if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
+ // if (!o.toggle && self.isViewVisible()) {
+ // return;
+ // }
+ o.toggle ? self._toggle() : self._popupView();
+ if (self.isViewVisible()) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo);
+ self.fireEvent(BI.Combo.EVENT_EXPAND);
+ } else {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.combo);
+ self.fireEvent(BI.Combo.EVENT_COLLAPSE);
+ }
+ }
+ }
+ }, BI.EVENT_RESPONSE_TIME, {
+ "leading": true,
+ "trailing": false
+ });
+ self.element.off(ev + "." + self.getName()).on(ev + "." + self.getName(), function (e) {
+ debounce(e);
+ st(e);
+ });
+ break;
+ case "click-hover":
+ var debounce = BI.debounce(function (e) {
+ if (self.combo.element.__isMouseInBounds__(e)) {
+ if (self.isEnabled() && self.isValid() && self.combo.isEnabled() && self.combo.isValid()) {
+ // if (self.isViewVisible()) {
+ // return;
+ // }
+ self._popupView();
+ if (self.isViewVisible()) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.combo);
+ self.fireEvent(BI.Combo.EVENT_EXPAND);
+ }
+ }
+ }
+ }, BI.EVENT_RESPONSE_TIME, {
+ "leading": true,
+ "trailing": false
+ });
+ self.element.off("click." + self.getName()).on("click." + self.getName(), function (e) {
+ debounce(e);
+ st(e);
+ });
+ self.element.on("mouseleave." + self.getName(), function (e) {
+ if (self.popupView) {
+ self.popupView.element.on("mouseenter." + self.getName(), function (e) {
+ enterPopup = true;
+ self.popupView.element.on("mouseleave." + self.getName(), function (e) {
+ hide();
+ });
+ self.popupView.element.off("mouseenter." + self.getName());
+ });
+ BI.defer(function () {
+ if (!enterPopup) {
+ hide();
+ }
+ }, 50);
+ }
+ });
+ break;
}
});
- this.options.afterCardCreated.apply(this, arguments);
},
- afterCardShow: function (v) {
- this.showIndex = v;
- this._deleteOtherCards(v);
- this.options.afterCardShow.apply(this, arguments);
+ _initCombo: function () {
+ this.combo = BI.createWidget(this.options.el, {
+ value: this.options.value
+ });
},
- populate: function () {
- var card = this.layout.getShowingCard();
- if (card) {
- return card.populate.apply(card, arguments);
+ _assertPopupView: function () {
+ var self = this, o = this.options;
+ if (this.popupView == null) {
+ this.popupView = BI.createWidget(this.options.popup, {
+ type: "bi.popup_view",
+ value: o.value
+ }, this);
+ this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ if (type === BI.Events.CLICK) {
+ self.combo.setValue(self.getValue());
+ self.fireEvent(BI.Combo.EVENT_CHANGE, value, obj);
+ }
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ });
+ this.popupView.setVisible(false);
+ BI.nextTick(function () {
+ self.fireEvent(BI.Combo.EVENT_AFTER_INIT);
+ });
}
},
- _assertCard: function (v) {
- if (!this.layout.isCardExisted(v)) {
- var card = this.options.cardCreator(v);
- this.cardMap[v] = card;
- this.layout.addCardByName(v, card);
- this.afterCardCreated(v);
+ _assertPopupViewRender: function () {
+ this._assertPopupView();
+ if (!this._rendered) {
+ BI.createWidget({
+ type: "bi.vertical",
+ scrolly: false,
+ element: this.options.container || this,
+ items: [
+ {el: this.popupView}
+ ]
+ });
+ this._rendered = true;
}
},
- setSelect: function (v) {
- this._assertCard(v);
- this.layout.showCardByName(v);
- this._deleteOtherCards(v);
- if (this.showIndex !== v) {
- this.showIndex = v;
- BI.nextTick(BI.bind(this.afterCardShow, this, v));
+ _hideIf: function (e) {
+ // if (this.element.__isMouseInBounds__(e) || (this.popupView && this.popupView.element.__isMouseInBounds__(e))) {
+ // return;
+ // }
+ // BI-10290 公式combo双击公式内容会收起
+ if ((this.element.find(e.target).length > 0)
+ || (this.popupView && this.popupView.element.find(e.target).length > 0)
+ || e.target.className === "CodeMirror-cursor" || BI.Widget._renderEngine.createElement(e.target).closest(".CodeMirror-hints").length > 0) {// BI-9887 CodeMirror的公式弹框需要特殊处理下
+ return;
}
- },
-
- getSelect: function () {
- return this.showIndex;
- },
-
- getSelectedCard: function () {
- if (BI.isKey(this.showIndex)) {
- return this.cardMap[this.showIndex];
+ var isHide = this.options.hideChecker.apply(this, [e]);
+ if (isHide === false) {
+ return;
}
+ this._hideView();
},
- /**
- * @override
- */
- setValue: function (v) {
- var card = this.layout.getShowingCard();
- if (card) {
- card.setValue(v);
+ _hideView: function () {
+ this.fireEvent(BI.Combo.EVENT_BEFORE_HIDEVIEW);
+ if (this.options.destroyWhenHide === true) {
+ this.popupView && this.popupView.destroy();
+ this.popupView = null;
+ this._rendered = false;
+ } else {
+ this.popupView && this.popupView.invisible();
}
- },
+ this.element.removeClass(this.options.comboClass);
- /**
- * @override
- */
- getValue: function () {
- var card = this.layout.getShowingCard();
- if (card) {
- return card.getValue();
- }
+ BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName());
+ this.fireEvent(BI.Combo.EVENT_AFTER_HIDEVIEW);
},
- empty: function () {
- this.layout.deleteAllCard();
- this.cardMap = {};
- },
+ _popupView: function () {
+ this._assertPopupViewRender();
+ this.fireEvent(BI.Combo.EVENT_BEFORE_POPUPVIEW);
- destroy: function () {
- BI.Navigation.superclass.destroy.apply(this, arguments);
- }
-});
-BI.Navigation.EVENT_CHANGE = "EVENT_CHANGE";
+ this.popupView.visible();
+ this.adjustWidth();
+ this.adjustHeight();
-BI.shortcut("bi.navigation", BI.Navigation);/**
- * 搜索逻辑控件
- *
- * Created by GUY on 2015/9/28.
- * @class BI.Searcher
- * @extends BI.Widget
- */
+ this.element.addClass(this.options.comboClass);
+ BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName()).unbind("mousewheel." + this.getName());
+ BI.Widget._renderEngine.createElement(document).bind("mousedown." + this.getName(), BI.bind(this._hideIf, this)).bind("mousewheel." + this.getName(), BI.bind(this._hideIf, this));
+ this.fireEvent(BI.Combo.EVENT_AFTER_POPUPVIEW);
+ },
-BI.Searcher = BI.inherit(BI.Widget, {
- _defaultConfig: function () {
- return BI.extend(BI.Searcher.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-searcher",
- lgap: 0,
- rgap: 0,
- tgap: 0,
- bgap: 0,
- vgap: 0,
- hgap: 0,
-
- isDefaultInit: false,
- isAutoSearch: true, // 是否自动搜索
- isAutoSync: true, // 是否自动同步数据, 即是否保持搜索面板和adapter面板状态值的统一
- chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE,
-
- // isAutoSearch为false时启用
- onSearch: function (op, callback) {
- callback([]);
- },
-
- el: {
- type: "bi.search_editor"
- },
-
- popup: {
- type: "bi.searcher_view"
- },
-
- adapter: null,
- masker: { // masker层
- offset: {}
+ adjustWidth: function () {
+ var o = this.options;
+ if (!this.popupView) {
+ return;
+ }
+ if (o.isNeedAdjustWidth === true) {
+ this.resetListWidth("");
+ var width = this.popupView.element.outerWidth();
+ var maxW = this.element.outerWidth() || o.width;
+ if (width > maxW + 80) {
+ maxW = maxW + 80;
+ } else if (width > maxW) {
+ maxW = width;
}
- });
+ this.resetListWidth(maxW < 100 ? 100 : maxW);
+ }
},
- _init: function () {
- BI.Searcher.superclass._init.apply(this, arguments);
- var self = this, o = this.options;
-
- this.editor = BI.createWidget(o.el, {
- type: "bi.search_editor"
- });
-
- BI.createWidget({
- type: "bi.vertical",
- element: this,
- lgap: o.lgap,
- rgap: o.rgap,
- tgap: o.tgap,
- bgap: o.bgap,
- vgap: o.vgap,
- hgap: o.hgap,
- items: [this.editor]
- });
- o.isDefaultInit && (this._assertPopupView());
-
- var search = BI.debounce(BI.bind(this._search, this), BI.EVENT_RESPONSE_TIME, {
- "leading": true,
- "trailing": false
- });
- this.editor.on(BI.Controller.EVENT_CHANGE, function (type) {
- switch (type) {
- case BI.Events.STARTEDIT:
- self._startSearch();
- break;
- case BI.Events.EMPTY:
- self._stopSearch();
- break;
- case BI.Events.CHANGE:
- search();
- break;
- case BI.Events.PAUSE:
- self._pauseSearch();
- break;
- }
- });
- },
+ adjustHeight: function () {
+ var o = this.options, p = {};
+ if (!this.popupView) {
+ return;
+ }
+ var isVisible = this.popupView.isVisible();
+ this.popupView.visible();
+ switch (o.direction) {
+ case "bottom":
+ case "bottom,right":
+ p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["bottom", "top", "right", "left"], o.offsetStyle);
+ break;
+ case "top":
+ case "top,right":
+ p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["top", "bottom", "right", "left"], o.offsetStyle);
+ break;
+ case "left":
+ case "left,bottom":
+ p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["left", "right", "bottom", "top"], o.offsetStyle);
+ break;
+ case "right":
+ case "right,bottom":
+ p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "bottom", "top"], o.offsetStyle);
+ break;
+ case "top,left":
+ p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["top", "bottom", "left", "right"], o.offsetStyle);
+ break;
+ case "bottom,left":
+ p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight, ["bottom", "top", "left", "right"], o.offsetStyle);
+ break;
+ case "left,top":
+ p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["left", "right", "top", "bottom"], o.offsetStyle);
+ break;
+ case "right,top":
+ p = $.getComboPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength, o.adjustYOffset, o.isNeedAdjustHeight, ["right", "left", "top", "bottom"], o.offsetStyle);
+ break;
+ case "top,custom":
+ case "custom,top":
+ p = $.getTopAdaptPosition(this.combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight);
+ break;
+ case "custom,bottom":
+ case "bottom,custom":
+ p = $.getBottomAdaptPosition(this.combo, this.popupView, o.adjustYOffset || o.adjustLength, o.isNeedAdjustHeight);
+ break;
+ case "left,custom":
+ case "custom,left":
+ p = $.getLeftAdaptPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength);
+ delete p.top;
+ delete p.adaptHeight;
+ break;
+ case "custom,right":
+ case "right,custom":
+ p = $.getRightAdaptPosition(this.combo, this.popupView, o.adjustXOffset || o.adjustLength);
+ delete p.top;
+ delete p.adaptHeight;
+ break;
+ }
- _assertPopupView: function () {
- var self = this, o = this.options;
- 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
- });
- this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- if (type === BI.Events.CLICK) {
- if (o.isAutoSync) {
- var values = o.adapter && o.adapter.getValue();
- if (!obj.isSelected()) {
- o.adapter && o.adapter.setValue(BI.deepWithout(values, obj.getValue()));
- } else {
- switch (o.chooseType) {
- case BI.ButtonGroup.CHOOSE_TYPE_SINGLE:
- o.adapter && o.adapter.setValue([obj.getValue()]);
- break;
- case BI.ButtonGroup.CHOOSE_TYPE_MULTI:
- values.push(obj.getValue());
- o.adapter && o.adapter.setValue(values);
- break;
- }
- }
- }
- self.fireEvent(BI.Searcher.EVENT_CHANGE, value, obj);
- }
- });
- BI.nextTick(function () {
- self.fireEvent(BI.Searcher.EVENT_AFTER_INIT);
+ if ("adaptHeight" in p) {
+ this.resetListHeight(p["adaptHeight"]);
+ }
+ if ("left" in p) {
+ this.popupView.element.css({
+ left: p.left
});
}
- if (o.masker && !BI.Maskers.has(this.getName())) {
- BI.Maskers.create(this.getName(), o.adapter, BI.extend({
- container: this,
- render: this.popupView
- }, o.masker), this);
+ if ("top" in p) {
+ this.popupView.element.css({
+ top: p.top
+ });
}
+ this.position = p;
+ this.popupView.setVisible(isVisible);
},
- _startSearch: function () {
+ resetListHeight: function (h) {
this._assertPopupView();
- this._stop = false;
- this._isSearching = true;
- this.fireEvent(BI.Searcher.EVENT_START);
- this.popupView.startSearch && this.popupView.startSearch();
- // 搜索前先清空dom
- // BI.Maskers.get(this.getName()).empty();
- BI.nextTick(function (name) {
- BI.Maskers.show(name);
- }, this.getName());
+ this.popupView.resetHeight && this.popupView.resetHeight(h);
},
- _pauseSearch: function () {
- var o = this.options, name = this.getName();
- this._stop = true;
- BI.nextTick(function (name) {
- BI.Maskers.hide(name);
- }, this.getName());
- if (this._isSearching === true) {
- this.popupView && this.popupView.pauseSearch && this.popupView.pauseSearch();
- this.fireEvent(BI.Searcher.EVENT_PAUSE);
+ resetListWidth: function (w) {
+ this._assertPopupView();
+ this.popupView.resetWidth && this.popupView.resetWidth(w);
+ },
+
+ populate: function (items) {
+ this._assertPopupView();
+ this.popupView.populate.apply(this.popupView, arguments);
+ this.combo.populate.apply(this.combo, arguments);
+ },
+
+ _setEnable: function (arg) {
+ BI.Combo.superclass._setEnable.apply(this, arguments);
+ if (arg === true) {
+ this.element.removeClass("base-disabled disabled");
+ } else if (arg === false) {
+ this.element.addClass("base-disabled disabled");
}
- this._isSearching = false;
+ !arg && this.element.removeClass(this.options.hoverClass);
+ !arg && this.isViewVisible() && this._hideView();
},
- _stopSearch: function () {
- var o = this.options, name = this.getName();
- this._stop = true;
- BI.Maskers.hide(name);
- if (this._isSearching === true) {
- this.popupView && this.popupView.stopSearch && this.popupView.stopSearch();
- this.fireEvent(BI.Searcher.EVENT_STOP);
+ setValue: function (v) {
+ this.combo.setValue(v);
+ if (BI.isNull(this.popupView)) {
+ this.options.popup.value = v;
+ } else {
+ this.popupView.setValue(v);
}
- this._isSearching = false;
},
- _search: function () {
- var self = this, o = this.options, keyword = this.editor.getValue();
- if (keyword === "" || this._stop) {
- return;
+ getValue: function () {
+ if (BI.isNull(this.popupView)) {
+ return this.options.popup.value;
+ } else {
+ return this.popupView.getValue();
}
- if (o.isAutoSearch) {
- var items = (o.adapter && ((o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items"))) || [];
- var finding = BI.Func.getSearchResult(items, keyword);
- var match = finding.match, find = finding.find;
- this.popupView.populate(find, match, keyword);
- o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue());
- self.fireEvent(BI.Searcher.EVENT_SEARCHING);
- return;
- }
- this.popupView.loading && this.popupView.loading();
- o.onSearch({
- times: 1,
- keyword: keyword,
- selectedValues: o.adapter && o.adapter.getValue()
- }, function (searchResult, matchResult) {
- if (!self._stop) {
- var args = [].slice.call(arguments);
- if (args.length > 0) {
- args.push(keyword);
- }
- BI.Maskers.show(self.getName());
- self.popupView.populate.apply(self.popupView, args);
- 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);
- }
- });
- },
-
- setAdapter: function (adapter) {
- this.options.adapter = adapter;
- BI.Maskers.remove(this.getName());
},
- doSearch: function () {
- if (this.isSearching()) {
- this._search();
- }
+ isViewVisible: function () {
+ return this.isEnabled() && this.combo.isEnabled() && !!this.popupView && this.popupView.isVisible();
},
- stopSearch: function () {
- this._stopSearch();// 先停止搜索,然后再去设置editor为空
- // important:停止搜索必须退出编辑状态,这里必须加上try(input框不显示时blur会抛异常)
- try {
- this.editor.blur();
- } catch (e) {
- if (!this.editor.blur) {
- throw new Error("editor没有实现blur方法");
- }
- } finally {
- this.editor.setValue("");
+ showView: function () {
+ if (this.isEnabled() && this.combo.isEnabled()) {
+ this._popupView();
}
},
- isSearching: function () {
- return this._isSearching;
- },
-
- isViewVisible: function () {
- return this.editor.isEnabled() && BI.Maskers.isVisible(this.getName());
+ hideView: function () {
+ this._hideView();
},
getView: function () {
return this.popupView;
},
- hasMatched: function () {
- this._assertPopupView();
- return this.popupView.hasMatched();
- },
-
- adjustHeight: function () {
- if (BI.Maskers.has(this.getName()) && BI.Maskers.get(this.getName()).isVisible()) {
- BI.Maskers.show(this.getName());
- }
- },
-
- adjustView: function () {
- this.isViewVisible() && BI.Maskers.show(this.getName());
- },
-
- setValue: function (v) {
- if (BI.isNull(this.popupView)) {
- this.options.popup.value = v;
- } else {
- this.popupView.setValue(v);
- }
- },
-
- getKeyword: function () {
- return this.editor.getValue();
- },
-
- getKeywords: function () {
- return this.editor.getKeywords();
- },
-
- getValue: function () {
- var o = this.options;
- if (o.isAutoSync && o.adapter && o.adapter.getValue) {
- return o.adapter.getValue();
- }
- if (this.isSearching()) {
- return this.popupView.getValue();
- } else if (o.adapter && o.adapter.getValue) {
- return o.adapter.getValue();
- }
- if (BI.isNull(this.popupView)) {
- return o.popup.value;
- }
- return this.popupView.getValue();
-
- },
-
- populate: function (result, searchResult, keyword) {
- var o = this.options;
- this._assertPopupView();
- this.popupView.populate.apply(this.popupView, arguments);
- if (o.isAutoSync && o.adapter && o.adapter.getValue) {
- this.popupView.setValue(o.adapter.getValue());
- }
+ getPopupPosition: function () {
+ return this.position;
},
- empty: function () {
- this.popupView && this.popupView.empty();
+ toggle: function () {
+ this._toggle();
},
destroy: function () {
- BI.Maskers.remove(this.getName());
- BI.Searcher.superclass.destroy.apply(this, arguments);
+ BI.Widget._renderEngine.createElement(document).unbind("mousedown." + this.getName())
+ .unbind("mousewheel." + this.getName())
+ .unbind("mouseenter." + this.getName())
+ .unbind("mousemove." + this.getName())
+ .unbind("mouseleave." + this.getName());
+ BI.Resizers.remove(this.getName());
+ BI.Combo.superclass.destroy.apply(this, arguments);
}
});
-BI.Searcher.EVENT_CHANGE = "EVENT_CHANGE";
-BI.Searcher.EVENT_START = "EVENT_START";
-BI.Searcher.EVENT_STOP = "EVENT_STOP";
-BI.Searcher.EVENT_PAUSE = "EVENT_PAUSE";
-BI.Searcher.EVENT_SEARCHING = "EVENT_SEARCHING";
-BI.Searcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT";
+BI.Combo.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE";
+BI.Combo.EVENT_CHANGE = "EVENT_CHANGE";
+BI.Combo.EVENT_EXPAND = "EVENT_EXPAND";
+BI.Combo.EVENT_COLLAPSE = "EVENT_COLLAPSE";
+BI.Combo.EVENT_AFTER_INIT = "EVENT_AFTER_INIT";
-BI.shortcut("bi.searcher", BI.Searcher);/**
+
+BI.Combo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
+BI.Combo.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW";
+BI.Combo.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW";
+BI.Combo.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";
+
+BI.shortcut("bi.combo", BI.Combo);/**
*
- * 切换显示或隐藏面板
+ * 某个可以展开的节点
*
- * Created by GUY on 2015/11/2.
- * @class BI.Switcher
+ * Created by GUY on 2015/9/10.
+ * @class BI.Expander
* @extends BI.Widget
*/
-BI.Switcher = BI.inherit(BI.Widget, {
+BI.Expander = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- return BI.extend(BI.Switcher.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-switcher",
- direction: BI.Direction.Top,
+ return BI.extend(BI.Expander.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-expander",
trigger: "click",
toggle: true,
+ // direction: "bottom", //top,bottom四个方向
+ isDefaultInit: false, // 是否默认初始化子节点
el: {},
popup: {},
- adapter: null,
- masker: {},
- switcherClass: "bi-switcher-popup",
- hoverClass: "bi-switcher-hover"
+ expanderClass: "bi-expander-popup",
+ hoverClass: "bi-expander-hover"
});
},
_init: function () {
- BI.Switcher.superclass._init.apply(this, arguments);
+ BI.Expander.superclass._init.apply(this, arguments);
var self = this, o = this.options;
- this._initSwitcher();
+ this._expanded = !!o.el.open;
+ this._initExpander();
this._initPullDownAction();
- this.switcher.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ this.expander.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (self.isEnabled() && self.isValid()) {
if (type === BI.Events.EXPAND) {
self._popupView();
@@ -39359,24 +39048,24 @@ BI.Switcher = BI.inherit(BI.Widget, {
}
if (type === BI.Events.EXPAND) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- self.fireEvent(BI.Switcher.EVENT_EXPAND);
+ self.fireEvent(BI.Expander.EVENT_EXPAND);
}
if (type === BI.Events.COLLAPSE) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- self.isViewVisible() && self.fireEvent(BI.Switcher.EVENT_COLLAPSE);
+ self.isViewVisible() && self.fireEvent(BI.Expander.EVENT_COLLAPSE);
}
if (type === BI.Events.CLICK) {
- self.fireEvent(BI.Switcher.EVENT_TRIGGER_CHANGE, value, obj);
+ self.fireEvent(BI.Expander.EVENT_TRIGGER_CHANGE, value, obj);
}
}
});
this.element.hover(function () {
- if (self.isEnabled() && self.switcher.isEnabled()) {
+ if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) {
self.element.addClass(o.hoverClass);
}
}, function () {
- if (self.isEnabled() && self.switcher.isEnabled()) {
+ if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) {
self.element.removeClass(o.hoverClass);
}
});
@@ -39385,15 +39074,18 @@ BI.Switcher = BI.inherit(BI.Widget, {
scrolly: false,
element: this,
items: [
- {el: this.switcher}
+ {el: this.expander}
]
});
- o.isDefaultInit && (this._assertPopupView());
+ o.isDefaultInit && this._assertPopupView();
+ if (this.expander.isOpened() === true) {
+ this._popupView();
+ }
},
_toggle: function () {
- this._assertPopupView();
- if (this.isExpanded()) {
+ this._assertPopupViewRender();
+ if (this.popupView.isVisible()) {
this._hideView();
} else {
if (this.isEnabled()) {
@@ -39409,31 +39101,31 @@ BI.Switcher = BI.inherit(BI.Widget, {
switch (e) {
case "hover":
self.element[e](function (e) {
- if (self.isEnabled() && self.switcher.isEnabled()) {
+ if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) {
self._popupView();
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.switcher);
- self.fireEvent(BI.Switcher.EVENT_EXPAND);
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.expander);
+ self.fireEvent(BI.Expander.EVENT_EXPAND);
}
}, function () {
- if (self.isEnabled() && self.switcher.isEnabled() && o.toggle) {
+ if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid() && o.toggle) {
self._hideView();
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.switcher);
- self.fireEvent(BI.Switcher.EVENT_COLLAPSE);
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.expander);
+ self.fireEvent(BI.Expander.EVENT_COLLAPSE);
}
});
break;
- default :
+ case "click":
if (e) {
self.element.off(e + "." + self.getName()).on(e + "." + self.getName(), BI.debounce(function (e) {
- if (self.switcher.element.__isMouseInBounds__(e)) {
- if (self.isEnabled() && self.switcher.isEnabled()) {
+ if (self.expander.element.__isMouseInBounds__(e)) {
+ if (self.isEnabled() && self.isValid() && self.expander.isEnabled() && self.expander.isValid()) {
o.toggle ? self._toggle() : self._popupView();
if (self.isExpanded()) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.switcher);
- self.fireEvent(BI.Switcher.EVENT_EXPAND);
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.expander);
+ self.fireEvent(BI.Expander.EVENT_EXPAND);
} else {
- self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.switcher);
- self.fireEvent(BI.Switcher.EVENT_COLLAPSE);
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.expander);
+ self.fireEvent(BI.Expander.EVENT_COLLAPSE);
}
}
}
@@ -39447,19 +39139,16 @@ BI.Switcher = BI.inherit(BI.Widget, {
});
},
- _initSwitcher: function () {
- this.switcher = BI.createWidget(this.options.el, {
- value: this.options.value
- });
+ _initExpander: function () {
+ this.expander = BI.createWidget(this.options.el);
},
_assertPopupView: function () {
var self = this, o = this.options;
- if (!this._created) {
- this.popupView = BI.createWidget(o.popup, {
+ if (this.popupView == null) {
+ this.popupView = BI.createWidget(this.options.popup, {
type: "bi.button_group",
- element: o.adapter && BI.Maskers.create(this.getName(), o.adapter, BI.extend({container: this}, o.masker)),
- cls: "switcher-popup",
+ cls: "expander-popup",
layouts: [{
type: "bi.vertical",
hgap: 0,
@@ -39470,62 +39159,66 @@ BI.Switcher = BI.inherit(BI.Widget, {
this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
if (type === BI.Events.CLICK) {
- self.fireEvent(BI.Switcher.EVENT_CHANGE, value, obj);
+ // self.setValue(self.getValue());
+ self.fireEvent(BI.Expander.EVENT_CHANGE, value, obj);
}
});
- if (o.direction !== BI.Direction.Custom && !o.adapter) {
- BI.createWidget({
- type: "bi.vertical",
- scrolly: false,
- element: this,
- items: [
- {el: this.popupView}
- ]
- });
- }
- this._created = true;
+ this.popupView.setVisible(this.isExpanded());
BI.nextTick(function () {
- self.fireEvent(BI.Switcher.EVENT_AFTER_INIT);
+ self.fireEvent(BI.Expander.EVENT_AFTER_INIT);
});
}
},
- _hideView: function () {
- this.fireEvent(BI.Switcher.EVENT_BEFORE_HIDEVIEW);
- var self = this, o = this.options;
- o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false));
- BI.nextTick(function () {
- o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false));
- self.element.removeClass(o.switcherClass);
- self.fireEvent(BI.Switcher.EVENT_AFTER_HIDEVIEW);
- });
+ _assertPopupViewRender: function () {
+ this._assertPopupView();
+ if (!this._rendered) {
+ BI.createWidget({
+ type: "bi.vertical",
+ scrolly: false,
+ element: this,
+ items: [
+ {el: this.popupView}
+ ]
+ });
+ this._rendered = true;
+ }
+ },
+
+ _hideView: function () {
+ this.fireEvent(BI.Expander.EVENT_BEFORE_HIDEVIEW);
+ this._expanded = false;
+ this.expander.setOpened(false);
+ this.popupView && this.popupView.invisible();
+ this.element.removeClass(this.options.expanderClass);
+
+ this.fireEvent(BI.Expander.EVENT_AFTER_HIDEVIEW);
},
_popupView: function () {
- var self = this, o = this.options;
- this._assertPopupView();
- this.fireEvent(BI.Switcher.EVENT_BEFORE_POPUPVIEW);
- o.adapter ? BI.Maskers.show(this.getName()) : self.popupView.setVisible(true);
- BI.nextTick(function (name) {
- o.adapter ? BI.Maskers.show(name) : self.popupView.setVisible(true);
- self.element.addClass(o.switcherClass);
- self.fireEvent(BI.Switcher.EVENT_AFTER_POPUPVIEW);
- }, this.getName());
+ this._assertPopupViewRender();
+ this.fireEvent(BI.Expander.EVENT_BEFORE_POPUPVIEW);
+ this._expanded = true;
+ this.expander.setOpened(true);
+ this.popupView.visible();
+ this.element.addClass(this.options.expanderClass);
+ this.fireEvent(BI.Expander.EVENT_AFTER_POPUPVIEW);
},
populate: function (items) {
- this._assertPopupView();
- this.popupView.populate.apply(this.popupView, arguments);
- this.switcher.populate.apply(this.switcher, arguments);
+ // this._assertPopupView();
+ this.popupView && this.popupView.populate.apply(this.popupView, arguments);
+ this.expander.populate.apply(this.expander, arguments);
},
_setEnable: function (arg) {
- BI.Switcher.superclass._setEnable.apply(this, arguments);
+ BI.Expander.superclass._setEnable.apply(this, arguments);
+ !arg && this.element.removeClass(this.options.hoverClass);
!arg && this.isViewVisible() && this._hideView();
},
setValue: function (v) {
- this.switcher.setValue(v);
+ this.expander.setValue(v);
if (BI.isNull(this.popupView)) {
this.options.popup.value = v;
} else {
@@ -39541,22 +39234,16 @@ BI.Switcher = BI.inherit(BI.Widget, {
}
},
- 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()));
+ return this.isEnabled() && this.expander.isEnabled() && !!this.popupView && this.popupView.isVisible();
},
isExpanded: function () {
- return this.isViewVisible();
+ return this._expanded;
},
showView: function () {
- if (this.isEnabled() && this.switcher.isEnabled()) {
+ if (this.isEnabled() && this.expander.isEnabled()) {
this._popupView();
}
},
@@ -39569,5646 +39256,4548 @@ BI.Switcher = BI.inherit(BI.Widget, {
return this.popupView;
},
- adjustView: function () {
- this.isViewVisible() && BI.Maskers.show(this.getName());
- },
-
getAllLeaves: function () {
return this.popupView && this.popupView.getAllLeaves();
},
getNodeById: function (id) {
- if (this.switcher.attr("id") === id) {
- return this.switcher;
+ if (this.expander.options.id === id) {
+ return this.expander;
}
return this.popupView && this.popupView.getNodeById(id);
},
getNodeByValue: function (value) {
- if (this.switcher.getValue() === value) {
- return this.switcher;
+ if (this.expander.getValue() === value) {
+ return this.expander;
}
return this.popupView && this.popupView.getNodeByValue(value);
},
- empty: function () {
- this.popupView && this.popupView.empty();
- },
-
destroy: function () {
- BI.Switcher.superclass.destroy.apply(this, arguments);
+ BI.Expander.superclass.destroy.apply(this, arguments);
}
});
-BI.Switcher.EVENT_EXPAND = "EVENT_EXPAND";
-BI.Switcher.EVENT_COLLAPSE = "EVENT_COLLAPSE";
-BI.Switcher.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE";
-BI.Switcher.EVENT_CHANGE = "EVENT_CHANGE";
-BI.Switcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT";
+BI.Expander.EVENT_EXPAND = "EVENT_EXPAND";
+BI.Expander.EVENT_COLLAPSE = "EVENT_COLLAPSE";
+BI.Expander.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE";
+BI.Expander.EVENT_CHANGE = "EVENT_CHANGE";
+BI.Expander.EVENT_AFTER_INIT = "EVENT_AFTER_INIT";
-BI.Switcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
-BI.Switcher.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW";
-BI.Switcher.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW";
-BI.Switcher.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";
+BI.Expander.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
+BI.Expander.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW";
+BI.Expander.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW";
+BI.Expander.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";
-BI.shortcut("bi.switcher", BI.Switcher);/**
- * Created by GUY on 2015/6/26.
+BI.shortcut("bi.expander", BI.Expander);/**
+ * Created by GUY on 2015/8/10.
*/
-BI.Tab = BI.inherit(BI.Widget, {
+BI.ComboGroup = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-tab",
- direction: "top", // top, bottom, left, right, custom
- single: false, // 是不是单页面
- logic: {
- dynamic: false
- },
- showIndex: false,
- tab: false,
- cardCreator: function (v) {
- return BI.createWidget();
+ return BI.extend(BI.ComboGroup.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-combo-group bi-list-item",
+
+ // 以下这些属性对每一个combo都是公用的
+ trigger: "click,hover",
+ direction: "right",
+ adjustLength: 0,
+ isDefaultInit: false,
+ isNeedAdjustHeight: false,
+ isNeedAdjustWidth: false,
+
+ el: {type: "bi.text_button", text: "", value: ""},
+ children: [],
+
+ popup: {
+ el: {
+ type: "bi.button_tree",
+ chooseType: 0,
+ layouts: [{
+ type: "bi.vertical"
+ }]
+ }
}
});
},
- render: function () {
+ _init: function () {
+ BI.ComboGroup.superclass._init.apply(this, arguments);
+ this._populate(this.options.el);
+ },
+
+ _populate: function (item) {
var self = this, o = this.options;
- if (BI.isObject(o.tab)) {
- this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"});
- this.tab.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- });
+ var children = o.children;
+ if (BI.isEmpty(children)) {
+ throw new Error("ComboGroup构造错误");
}
- this.cardMap = {};
- this.layout = BI.createWidget({
- type: "bi.card"
- });
-
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout)
- }))));
-
- var listener = new BI.ShowListener({
- eventObj: this.tab,
- cardLayout: this.layout,
- cardCreator: function (v) {
- var card = o.cardCreator.apply(self, arguments);
- self.cardMap[v] = card;
- return card;
- },
- afterCardShow: function (v) {
- self._deleteOtherCards(v);
- self.curr = v;
+ BI.each(children, function (i, ch) {
+ var son = BI.formatEL(ch).el.children;
+ ch = BI.formatEL(ch).el;
+ if (!BI.isEmpty(son)) {
+ ch.el = BI.clone(ch);
+ ch.children = son;
+ ch.type = "bi.combo_group";
+ ch.action = o.action;
+ ch.height = o.height;
+ ch.direction = o.direction;
+ ch.isDefaultInit = o.isDefaultInit;
+ ch.isNeedAdjustHeight = o.isNeedAdjustHeight;
+ ch.isNeedAdjustWidth = o.isNeedAdjustWidth;
+ ch.adjustLength = o.adjustLength;
+ ch.popup = o.popup;
}
});
- listener.on(BI.ShowListener.EVENT_CHANGE, function (value) {
- self.fireEvent(BI.Tab.EVENT_CHANGE, value, self);
+ this.combo = BI.createWidget({
+ type: "bi.combo",
+ element: this,
+ container: o.container,
+ height: o.height,
+ trigger: o.trigger,
+ direction: o.direction,
+ isDefaultInit: o.isDefaultInit,
+ isNeedAdjustWidth: o.isNeedAdjustWidth,
+ isNeedAdjustHeight: o.isNeedAdjustHeight,
+ adjustLength: o.adjustLength,
+ el: item,
+ popup: BI.extend({}, o.popup, {
+ el: BI.extend({
+ items: children
+ }, o.popup.el)
+ })
+ });
+ this.combo.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ if (type === BI.Events.CLICK) {
+ self.fireEvent(BI.ComboGroup.EVENT_CHANGE, obj);
+ }
});
},
- _deleteOtherCards: function (currCardName) {
- var self = this, o = this.options;
- if (o.single === true) {
- BI.each(this.cardMap, function (name, card) {
- if (name !== (currCardName + "")) {
- self.layout.deleteCardByName(name);
- delete self.cardMap[name];
- }
- });
- }
+ getValue: function () {
+ return this.combo.getValue();
},
- _assertCard: function (v) {
- if (!this.layout.isCardExisted(v)) {
- var card = this.options.cardCreator(v);
- this.cardMap[v] = card;
- this.layout.addCardByName(v, card);
- }
+ setValue: function (v) {
+ this.combo.setValue(v);
+ }
+});
+BI.ComboGroup.EVENT_CHANGE = "EVENT_CHANGE";
+
+BI.shortcut("bi.combo_group", BI.ComboGroup);BI.VirtualGroup = BI.inherit(BI.Widget, {
+ _defaultConfig: function () {
+ return BI.extend(BI.VirtualGroup.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-virtual-group",
+ items: [],
+ layouts: [{
+ type: "bi.center",
+ hgap: 0,
+ vgap: 0
+ }]
+ });
},
- mounted: function () {
+ render: function () {
var o = this.options;
- if (o.showIndex !== false) {
- this.setSelect(o.showIndex);
+ this.populate(o.items);
+ if (BI.isKey(o.value)) {
+ this.setValue(o.value);
}
},
- setSelect: function (v) {
- this.tab && this.tab.setValue(v);
- this._assertCard(v);
- this.layout.showCardByName(v);
- this._deleteOtherCards(v);
- if (this.curr !== v) {
- this.curr = v;
+ _packageBtns: function (items) {
+ var o = this.options;
+ var map = this.buttonMap = {};
+ for (var i = o.layouts.length - 1; i > 0; i--) {
+ items = BI.map(items, function (k, it) {
+ var el = BI.stripEL(it);
+ return BI.extend({}, o.layouts[i], {
+ items: [
+ BI.extend({}, o.layouts[i].el, {
+ el: BI.extend({
+ ref: function (_ref) {
+ if (BI.isKey(map[el.value])) {
+ map[el.value] = _ref;
+ }
+ }
+ }, el)
+ })
+ ]
+ });
+ });
}
+ return items;
},
- removeTab: function (cardname) {
- var self = this, o = this.options;
- BI.any(this.cardMap, function (name, card) {
- if (BI.isEqual(name, (cardname + ""))) {
- self.layout.deleteCardByName(name);
- delete self.cardMap[name];
- return true;
- }
- });
- },
+ _packageLayout: function (items) {
+ var o = this.options, layout = BI.deepClone(o.layouts[0]);
- getSelect: function () {
- return this.curr;
+ var lay = BI.formatEL(layout).el;
+ while (lay && lay.items && !BI.isEmpty(lay.items)) {
+ lay = BI.formatEL(lay.items[0]).el;
+ }
+ lay.items = items;
+ return layout;
},
- getSelectedTab: function () {
- return this.layout.getShowingCard();
+ addItems: function (items) {
+ this.layouts.addItems(items);
},
- getTab: function (v) {
- this._assertCard(v);
- return this.layout.getCardByName(v);
+ prependItems: function (items) {
+ this.layouts.prependItems(items);
},
setValue: function (v) {
- var card = this.layout.getShowingCard();
- if (card) {
- card.setValue(v);
- }
- },
-
- getValue: function () {
- var card = this.layout.getShowingCard();
- if (card) {
- return card.getValue();
- }
+ v = BI.isArray(v) ? v : [v];
+ BI.each(this.buttonMap, function (key, item) {
+ if (item) {
+ if (v.deepContains(key)) {
+ item.setSelected && item.setSelected(true);
+ } else {
+ item.setSelected && item.setSelected(false);
+ }
+ }
+ });
},
- populate: function () {
- var card = this.layout.getShowingCard();
- if (card) {
- return card.populate && card.populate.apply(card, arguments);
- }
+ getNotSelectedValue: function () {
+ var v = [];
+ BI.each(this.buttonMap, function (i, item) {
+ if (item) {
+ if (item.isEnabled() && !(item.isSelected && item.isSelected())) {
+ v.push(item.getValue());
+ }
+ }
+ });
+ return v;
},
- empty: function () {
- this.layout.deleteAllCard();
- this.cardMap = {};
+ getValue: function () {
+ var v = [];
+ BI.each(this.buttonMap, function (i, item) {
+ if (item) {
+ if (item.isEnabled() && item.isSelected && item.isSelected()) {
+ v.push(item.getValue());
+ }
+ }
+ });
+ return v;
},
- destroy: function () {
- this.cardMap = {};
- BI.Tab.superclass.destroy.apply(this, arguments);
+ populate: function (items) {
+ var self = this;
+ items = items || [];
+ this.options.items = items;
+ items = this._packageBtns(items);
+ if (!this.layouts) {
+ this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items)));
+ } else {
+ this.layouts.populate(items);
+ }
}
});
-BI.Tab.EVENT_CHANGE = "EVENT_CHANGE";
+BI.VirtualGroup.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.tab", BI.Tab);/**
- * 表示当前对象
+BI.shortcut("bi.virtual_group", BI.VirtualGroup);/**
+ * 加载控件
*
- * Created by GUY on 2015/9/7.
- * @class BI.EL
+ * Created by GUY on 2015/8/31.
+ * @class BI.Loader
* @extends BI.Widget
*/
-BI.EL = BI.inherit(BI.Widget, {
+BI.Loader = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- return BI.extend(BI.EL.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-el",
- el: {},
- layout: {}
+ return BI.extend(BI.Loader.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-loader",
+
+ direction: "top",
+ isDefaultInit: true, // 是否默认初始化数据
+ logic: {
+ dynamic: true,
+ scrolly: true
+ },
+
+ // 下面是button_group的属性
+ el: {
+ type: "bi.button_group"
+ },
+
+ items: [],
+ itemsCreator: BI.emptyFn,
+ onLoaded: BI.emptyFn,
+
+ // 下面是分页信息
+ count: false,
+ prev: false,
+ next: {},
+ hasPrev: BI.emptyFn,
+ hasNext: BI.emptyFn
});
},
+
+ _prevLoad: function () {
+ var self = this, o = this.options;
+ this.prev.setLoading();
+ o.itemsCreator.apply(this, [{times: --this.times}, function () {
+ self.prev.setLoaded();
+ self.prependItems.apply(self, arguments);
+ }]);
+ },
+
+ _nextLoad: function () {
+ var self = this, o = this.options;
+ this.next.setLoading();
+ o.itemsCreator.apply(this, [{times: ++this.times}, function () {
+ self.next.setLoaded();
+ self.addItems.apply(self, arguments);
+ }]);
+ },
+
_init: function () {
- BI.EL.superclass._init.apply(this, arguments);
+ BI.Loader.superclass._init.apply(this, arguments);
var self = this, o = this.options;
- this.ele = BI.createWidget(o.el);
- BI.createWidget(o.layout, {
- type: "bi.adaptive",
- element: this,
- items: [this.ele]
+ if (o.itemsCreator === false) {
+ o.prev = false;
+ o.next = false;
+ }
+ if (o.prev !== false) {
+ this.prev = BI.createWidget(BI.extend({
+ type: "bi.loading_bar"
+ }, o.prev));
+ this.prev.on(BI.Controller.EVENT_CHANGE, function (type) {
+ if (type === BI.Events.CLICK) {
+ self._prevLoad();
+ }
+ });
+ }
+
+ this.button_group = BI.createWidget(o.el, {
+ type: "bi.button_group",
+ chooseType: 0,
+ items: o.items,
+ behaviors: {},
+ layouts: [{
+ type: "bi.vertical"
+ }]
});
- this.ele.on(BI.Controller.EVENT_CHANGE, function () {
+ this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ if (type === BI.Events.CLICK) {
+ self.fireEvent(BI.Loader.EVENT_CHANGE, obj);
+ }
});
- },
- setValue: function (v) {
- this.ele.setValue(v);
- },
+ if (o.next !== false) {
+ this.next = BI.createWidget(BI.extend({
+ type: "bi.loading_bar"
+ }, o.next));
+ this.next.on(BI.Controller.EVENT_CHANGE, function (type) {
+ if (type === BI.Events.CLICK) {
+ self._nextLoad();
+ }
+ });
+ }
- getValue: function () {
- return this.ele.getValue();
+ 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.prev, this.button_group, this.next)
+ }))));
+
+ o.isDefaultInit && BI.isEmpty(o.items) && BI.nextTick(BI.bind(function () {
+ o.isDefaultInit && BI.isEmpty(o.items) && this.populate();
+ }, this));
+ if (BI.isNotEmptyArray(o.items)) {
+ this.populate(o.items);
+ }
},
- populate: function () {
- this.ele.populate.apply(this, arguments);
- }
-});
-BI.shortcut("bi.el", BI.EL);/**
- * z-index在1亿层级
- * 弹出提示消息框,用于模拟阻塞操作(通过回调函数实现)
- * @class BI.Msg
- */
-BI.Msg = function () {
-
- var messageShow, $mask, $pop;
+ hasPrev: function () {
+ var o = this.options;
+ if (BI.isNumber(o.count)) {
+ return this.count < o.count;
+ }
+ return !!o.hasPrev.apply(this, [{
+ times: this.times,
+ count: this.count
+ }]);
+ },
- return {
- alert: function (title, message, callback) {
- this._show(false, title, message, callback);
- },
- confirm: function (title, message, callback) {
- this._show(true, title, message, callback);
- },
- prompt: function (title, message, value, callback, min_width) {
- // BI.Msg.prompt(title, message, value, callback, min_width);
- },
- toast: function (message, options, context) {
- options = options || {};
- context = context || BI.Widget._renderEngine.createElement("body");
- var level = options.level || "normal";
- var autoClose = BI.isNull(options.autoClose) ? true : options.autoClose;
- var toast = BI.createWidget({
- type: "bi.toast",
- cls: "bi-message-animate bi-message-leave",
- level: level,
- autoClose: autoClose,
- text: message
- });
- BI.createWidget({
- type: "bi.absolute",
- element: context,
- items: [{
- el: toast,
- left: "50%",
- top: 10
- }]
- });
- toast.element.css({"margin-left": -1 * toast.element.outerWidth() / 2});
- toast.element.removeClass("bi-message-leave").addClass("bi-message-enter");
+ hasNext: function () {
+ var o = this.options;
+ if (BI.isNumber(o.count)) {
+ return this.count < o.count;
+ }
+ return !!o.hasNext.apply(this, [{
+ times: this.times,
+ count: this.count
+ }]);
+ },
- autoClose && BI.delay(function () {
- toast.element.removeClass("bi-message-enter").addClass("bi-message-leave");
- BI.delay(function () {
- toast.destroy();
- }, 1000);
- }, 5000);
- },
- _show: function (hasCancel, title, message, callback) {
- $mask = BI.Widget._renderEngine.createElement("
").css({
- position: "absolute",
- zIndex: BI.zIndex_tip - 2,
- top: 0,
- left: 0,
- right: 0,
- bottom: 0,
- opacity: 0.5
- }).appendTo("body");
- $pop = BI.Widget._renderEngine.createElement("
").css({
- position: "absolute",
- zIndex: BI.zIndex_tip - 1,
- top: 0,
- left: 0,
- right: 0,
- bottom: 0
- }).appendTo("body");
- var close = function () {
- messageShow.destroy();
- $mask.remove();
- };
- var controlItems = [];
- if (hasCancel === true) {
- controlItems.push({
- el: {
- type: "bi.button",
- text: BI.i18nText("BI-Basic_Cancel"),
- level: "ignore",
- handler: function () {
- close();
- if (BI.isFunction(callback)) {
- callback.apply(null, [false]);
- }
- }
- }
- });
+ prependItems: function (items) {
+ this.count += items.length;
+ if (this.next !== false) {
+ if (this.hasPrev()) {
+ this.options.items = this.options.items.concat(items);
+ this.prev.setLoaded();
+ } else {
+ this.prev.setEnd();
}
- controlItems.push({
- el: {
- type: "bi.button",
- text: BI.i18nText("BI-Basic_OK"),
- handler: function () {
- close();
- if (BI.isFunction(callback)) {
- callback.apply(null, [true]);
- }
- }
- }
- });
- var conf = {
- element: $pop,
- type: "bi.center_adapt",
- items: [
- {
- type: "bi.border",
- cls: "bi-message-content bi-card",
- items: {
- north: {
- el: {
- type: "bi.border",
- cls: "bi-message-title bi-background",
- items: {
- center: {
- el: {
- type: "bi.label",
- text: title || BI.i18nText("BI-Basic_Prompt"),
- textAlign: "left",
- hgap: 20,
- height: 50
- }
- },
- east: {
- el: {
- type: "bi.icon_button",
- cls: "bi-message-close close-font",
- // height: 50,
- handler: function () {
- close();
- if (BI.isFunction(callback)) {
- callback.apply(null, [false]);
- }
- }
- },
- width: 60
- }
- }
- },
- height: 50
- },
- center: {
- el: {
- type: "bi.text",
- cls: "bi-message-text",
- tgap: 60,
- hgap: 20,
- lineHeight: 30,
- whiteSpace: "normal",
- text: message
- }
- },
- south: {
- el: {
- type: "bi.absolute",
- items: [{
- el: {
- type: "bi.right_vertical_adapt",
- hgap: 5,
- items: controlItems
- },
- top: 0,
- left: 20,
- right: 20,
- bottom: 0
- }]
-
- },
- height: 60
- }
- },
- width: 400,
- height: 300
- }
- ]
- };
+ }
+ this.button_group.prependItems.apply(this.button_group, arguments);
+ },
- messageShow = BI.createWidget(conf);
+ addItems: function (items) {
+ this.count += items.length;
+ if (BI.isObject(this.next)) {
+ if (this.hasNext()) {
+ this.options.items = this.options.items.concat(items);
+ this.next.setLoaded();
+ } else {
+ this.next.setEnd();
+ }
}
- };
-}();/**
- * GridView
- *
- * Created by GUY on 2016/1/11.
- * @class BI.GridView
- * @extends BI.Widget
- */
-BI.GridView = BI.inherit(BI.Widget, {
- _defaultConfig: function () {
- return BI.extend(BI.GridView.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-grid-view",
- // width: 400, //必设
- // height: 300, //必设
- overflowX: true,
- overflowY: true,
- overscanColumnCount: 0,
- overscanRowCount: 0,
- rowHeightGetter: BI.emptyFn, // number类型或function类型
- columnWidthGetter: BI.emptyFn, // number类型或function类型
- // estimatedColumnSize: 100, //columnWidthGetter为function时必设
- // estimatedRowSize: 30, //rowHeightGetter为function时必设
- scrollLeft: 0,
- scrollTop: 0,
- items: []
- });
+ this.button_group.addItems.apply(this.button_group, arguments);
},
- _init: function () {
- BI.GridView.superclass._init.apply(this, arguments);
+ populate: function (items) {
var self = this, o = this.options;
- this.renderedCells = [];
- this.renderedKeys = [];
- this.renderRange = {};
- this._scrollLock = false;
- this._debounceRelease = BI.debounce(function () {
- self._scrollLock = false;
- }, 1000 / 60);
- this.container = BI.createWidget({
- type: "bi.absolute"
- });
- this.element.scroll(function () {
- if (self._scrollLock === true) {
- return;
- }
- o.scrollLeft = self.element.scrollLeft();
- o.scrollTop = self.element.scrollTop();
- self._calculateChildrenToRender();
- self.fireEvent(BI.GridView.EVENT_SCROLL, {
- scrollLeft: o.scrollLeft,
- scrollTop: o.scrollTop
- });
- });
- BI.createWidget({
- type: "bi.vertical",
- element: this,
- scrollable: o.overflowX === true && o.overflowY === true,
- scrolly: o.overflowX === false && o.overflowY === true,
- scrollx: o.overflowX === true && o.overflowY === false,
- items: [this.container]
- });
- if (o.items.length > 0) {
- this._populate();
+ if (arguments.length === 0 && (BI.isFunction(o.itemsCreator))) {
+ o.itemsCreator.apply(this, [{times: 1}, function () {
+ if (arguments.length === 0) {
+ throw new Error("arguments can not be null!!!");
+ }
+ self.populate.apply(self, arguments);
+ o.onLoaded();
+ }]);
+ return;
+ }
+ this.options.items = items;
+ this.times = 1;
+ this.count = 0;
+ this.count += items.length;
+ if (BI.isObject(this.next)) {
+ if (this.hasNext()) {
+ this.next.setLoaded();
+ } else {
+ this.next.invisible();
+ }
+ }
+ if (BI.isObject(this.prev)) {
+ if (this.hasPrev()) {
+ this.prev.setLoaded();
+ } else {
+ this.prev.invisible();
+ }
}
+ this.button_group.populate.apply(this.button_group, arguments);
},
- mounted: function () {
- var o = this.options;
- if (o.scrollLeft !== 0 || o.scrollTop !== 0) {
- this.element.scrollTop(o.scrollTop);
- this.element.scrollLeft(o.scrollLeft);
- }
+ setNotSelectedValue: function () {
+ this.button_group.setNotSelectedValue.apply(this.button_group, arguments);
},
- _getOverscanIndices: function (cellCount, overscanCellsCount, startIndex, stopIndex) {
- return {
- overscanStartIndex: Math.max(0, startIndex - overscanCellsCount),
- overscanStopIndex: Math.min(cellCount - 1, stopIndex + overscanCellsCount)
- };
+ getNotSelectedValue: function () {
+ return this.button_group.getNotSelectedValue();
},
- _calculateChildrenToRender: function () {
- var self = this, o = this.options;
+ setValue: function () {
+ this.button_group.setValue.apply(this.button_group, arguments);
+ },
- var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()),
- scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()),
- overscanColumnCount = o.overscanColumnCount, overscanRowCount = o.overscanRowCount;
+ getValue: function () {
+ return this.button_group.getValue.apply(this.button_group, arguments);
+ },
- if (height > 0 && width > 0) {
- var visibleColumnIndices = this._columnSizeAndPositionManager.getVisibleCellRange(width, scrollLeft);
- var visibleRowIndices = this._rowSizeAndPositionManager.getVisibleCellRange(height, scrollTop);
+ getAllButtons: function () {
+ return this.button_group.getAllButtons();
+ },
- if (BI.isEmpty(visibleColumnIndices) || BI.isEmpty(visibleRowIndices)) {
- return;
- }
- var horizontalOffsetAdjustment = this._columnSizeAndPositionManager.getOffsetAdjustment(width, scrollLeft);
- var verticalOffsetAdjustment = this._rowSizeAndPositionManager.getOffsetAdjustment(height, scrollTop);
+ getAllLeaves: function () {
+ return this.button_group.getAllLeaves();
+ },
- this._renderedColumnStartIndex = visibleColumnIndices.start;
- this._renderedColumnStopIndex = visibleColumnIndices.stop;
- this._renderedRowStartIndex = visibleRowIndices.start;
- this._renderedRowStopIndex = visibleRowIndices.stop;
+ getSelectedButtons: function () {
+ return this.button_group.getSelectedButtons();
+ },
- var overscanColumnIndices = this._getOverscanIndices(this.columnCount, overscanColumnCount, this._renderedColumnStartIndex, this._renderedColumnStopIndex);
+ getNotSelectedButtons: function () {
+ return this.button_group.getNotSelectedButtons();
+ },
- var overscanRowIndices = this._getOverscanIndices(this.rowCount, overscanRowCount, this._renderedRowStartIndex, this._renderedRowStopIndex);
+ getIndexByValue: function (value) {
+ return this.button_group.getIndexByValue(value);
+ },
- var columnStartIndex = overscanColumnIndices.overscanStartIndex;
- var columnStopIndex = overscanColumnIndices.overscanStopIndex;
- var rowStartIndex = overscanRowIndices.overscanStartIndex;
- var rowStopIndex = overscanRowIndices.overscanStopIndex;
+ getNodeById: function (id) {
+ return this.button_group.getNodeById(id);
+ },
- // 算区间size
- var minRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStartIndex);
- var minColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStartIndex);
- var maxRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStopIndex);
- var maxColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStopIndex);
- var top = minRowDatum.offset + verticalOffsetAdjustment;
- var left = minColumnDatum.offset + horizontalOffsetAdjustment;
- var bottom = maxRowDatum.offset + verticalOffsetAdjustment + maxRowDatum.size;
- var right = maxColumnDatum.offset + horizontalOffsetAdjustment + maxColumnDatum.size;
- // 如果滚动的区间并没有超出渲染的范围
- if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) {
- return;
- }
+ getNodeByValue: function (value) {
+ return this.button_group.getNodeByValue(value);
+ },
- var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
- var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
- var count = 0;
- for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
- var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
+ empty: function () {
+ this.button_group.empty();
+ BI.each([this.prev, this.next], function (i, ob) {
+ ob && ob.setVisible(false);
+ });
+ },
- for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
- var key = rowIndex + "-" + columnIndex;
- var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
+ destroy: function () {
+ BI.Loader.superclass.destroy.apply(this, arguments);
+ }
+});
+BI.Loader.EVENT_CHANGE = "EVENT_CHANGE";
+BI.shortcut("bi.loader", BI.Loader);/**
+ * Created by GUY on 2015/6/26.
+ */
- var index = this.renderedKeys[key] && this.renderedKeys[key][2];
- var child;
- if (index >= 0) {
- if (columnDatum.size !== this.renderedCells[index]._width) {
- this.renderedCells[index]._width = columnDatum.size;
- this.renderedCells[index].el.setWidth(columnDatum.size);
- }
- if (rowDatum.size !== this.renderedCells[index]._height) {
- this.renderedCells[index]._height = rowDatum.size;
- this.renderedCells[index].el.setHeight(rowDatum.size);
- }
- if (this.renderedCells[index]._left !== columnDatum.offset + horizontalOffsetAdjustment) {
- this.renderedCells[index].el.element.css("left", (columnDatum.offset + horizontalOffsetAdjustment) + "px");
- }
- if (this.renderedCells[index]._top !== rowDatum.offset + verticalOffsetAdjustment) {
- this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px");
- }
- renderedCells.push(child = this.renderedCells[index]);
- } else {
- child = BI.createWidget(BI.extend({
- type: "bi.label",
- width: columnDatum.size,
- height: rowDatum.size
- }, o.items[rowIndex][columnIndex], {
- cls: (o.items[rowIndex][columnIndex].cls || "") + " grid-cell" + (rowIndex === 0 ? " first-row" : "") + (columnIndex === 0 ? " first-col" : ""),
- _rowIndex: rowIndex,
- _columnIndex: columnIndex,
- _left: columnDatum.offset + horizontalOffsetAdjustment,
- _top: rowDatum.offset + verticalOffsetAdjustment
- }));
- renderedCells.push({
- el: child,
- left: columnDatum.offset + horizontalOffsetAdjustment,
- top: rowDatum.offset + verticalOffsetAdjustment,
- _left: columnDatum.offset + horizontalOffsetAdjustment,
- _top: rowDatum.offset + verticalOffsetAdjustment,
- _width: columnDatum.size,
- _height: rowDatum.size
- });
- }
- minX = Math.min(minX, columnDatum.offset + horizontalOffsetAdjustment);
- maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
- minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
- maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
- renderedKeys[key] = [rowIndex, columnIndex, count];
- renderedWidgets[count] = child;
- count++;
- }
- }
- // 已存在的, 需要添加的和需要删除的
- var existSet = {}, addSet = {}, deleteArray = [];
- BI.each(renderedKeys, function (i, key) {
- if (self.renderedKeys[i]) {
- existSet[i] = key;
- } else {
- addSet[i] = key;
- }
- });
- BI.each(this.renderedKeys, function (i, key) {
- if (existSet[i]) {
- return;
- }
- if (addSet[i]) {
- return;
- }
- deleteArray.push(key[2]);
- });
- BI.each(deleteArray, function (i, index) {
- // 性能优化,不调用destroy方法防止触发destroy事件
- self.renderedCells[index].el._destroy();
- });
- var addedItems = [];
- BI.each(addSet, function (index, key) {
- addedItems.push(renderedCells[key[2]]);
- });
- this.container.addItems(addedItems);
- // 拦截父子级关系
- this.container._children = renderedWidgets;
- this.container.attr("items", renderedCells);
- this.renderedCells = renderedCells;
- this.renderedKeys = renderedKeys;
- this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
- }
- },
+BI.Navigation = BI.inherit(BI.Widget, {
+ _defaultConfig: function () {
+ return BI.extend(BI.Navigation.superclass._defaultConfig.apply(this, arguments), {
+ direction: "bottom", // top, bottom, left, right, custom
+ logic: {
+ dynamic: false
+ },
+ single: false,
+ showIndex: false,
+ tab: false,
+ cardCreator: function (v) {
+ return BI.createWidget();
+ },
- /**
- * 获取真实的可滚动的最大宽度
- * 对于grid_view如果没有全部渲染过,this._columnSizeAndPositionManager.getTotalSize获取的宽度是不准确的
- * 因此在调用setScrollLeft等函数时会造成没法移动到最右端(预估可移动具体太短)
- */
- _getRealMaxScrollLeft: function () {
- var o = this.options;
- var totalWidth = 0;
- BI.count(0, this.columnCount, function (index) {
- totalWidth += o.columnWidthGetter(index);
+ afterCardCreated: BI.emptyFn,
+ afterCardShow: BI.emptyFn
});
- return Math.max(0, totalWidth - this.options.width + (this.options.overflowX ? BI.DOM.getScrollWidth() : 0));
},
- _getMaxScrollLeft: function () {
- return Math.max(0, this._columnSizeAndPositionManager.getTotalSize() - this.options.width + (this.options.overflowX ? BI.DOM.getScrollWidth() : 0));
- },
-
- _getMaxScrollTop: function () {
- return Math.max(0, this._rowSizeAndPositionManager.getTotalSize() - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0));
- },
-
- _populate: function (items) {
+ render: function () {
var self = this, o = this.options;
- this._reRange();
- this.columnCount = 0;
- this.rowCount = 0;
- if (items && items !== this.options.items) {
- this.options.items = items;
- }
- if (BI.isNumber(o.columnCount)) {
- this.columnCount = o.columnCount;
- } else if (o.items.length > 0) {
- this.columnCount = o.items[0].length;
- }
- if (BI.isNumber(o.rowCount)) {
- this.rowCount = o.rowCount;
- } else {
- this.rowCount = o.items.length;
- }
- this.container.setWidth(this.columnCount * o.estimatedColumnSize);
- this.container.setHeight(this.rowCount * o.estimatedRowSize);
-
- this._columnSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.columnCount, o.columnWidthGetter, o.estimatedColumnSize);
- this._rowSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.rowCount, o.rowHeightGetter, o.estimatedRowSize);
+ this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"});
+ this.cardMap = {};
+ this.showIndex = 0;
+ this.layout = BI.createWidget({
+ type: "bi.card"
+ });
+ BI.createWidget(BI.extend({
+ element: this
+ }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
+ items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout)
+ }))));
- this._calculateChildrenToRender();
- // 元素未挂载时不能设置scrollTop
- try {
- this.element.scrollTop(o.scrollTop);
- this.element.scrollLeft(o.scrollLeft);
- } catch (e) {
- }
- },
- setScrollLeft: function (scrollLeft) {
- if (this.options.scrollLeft === scrollLeft) {
- return;
- }
- this._scrollLock = true;
- this.options.scrollLeft = BI.clamp(scrollLeft || 0, 0, this._getRealMaxScrollLeft());
- this._debounceRelease();
- this._calculateChildrenToRender();
- this.element.scrollLeft(this.options.scrollLeft);
+ new BI.ShowListener({
+ eventObj: this.tab,
+ cardLayout: this.layout,
+ cardNameCreator: function (v) {
+ return self.showIndex + v;
+ },
+ cardCreator: function (v) {
+ var card = o.cardCreator(v);
+ self.cardMap[v] = card;
+ return card;
+ },
+ afterCardCreated: BI.bind(this.afterCardCreated, this),
+ afterCardShow: BI.bind(this.afterCardShow, this)
+ });
},
- setScrollTop: function (scrollTop) {
- if (this.options.scrollTop === scrollTop) {
- return;
+ mounted: function () {
+ var o = this.options;
+ if (o.showIndex !== false) {
+ this.setSelect(o.showIndex);
}
- this._scrollLock = true;
- this.options.scrollTop = BI.clamp(scrollTop || 0, 0, this._getMaxScrollTop());
- this._debounceRelease();
- this._calculateChildrenToRender();
- this.element.scrollTop(this.options.scrollTop);
- },
-
- setColumnCount: function (columnCount) {
- this.options.columnCount = columnCount;
- },
-
- setRowCount: function (rowCount) {
- this.options.rowCount = rowCount;
},
- setOverflowX: function (b) {
- var self = this;
- if (this.options.overflowX !== !!b) {
- this.options.overflowX = !!b;
- BI.nextTick(function () {
- self.element.css({overflowX: b ? "auto" : "hidden"});
+ _deleteOtherCards: function (currCardName) {
+ var self = this, o = this.options;
+ if (o.single === true) {
+ BI.each(this.cardMap, function (name, card) {
+ if (name !== (currCardName + "")) {
+ self.layout.deleteCardByName(name);
+ delete self.cardMap[name];
+ }
});
}
},
- setOverflowY: function (b) {
+ afterCardCreated: function (v) {
var self = this;
- if (this.options.overflowY !== !!b) {
- this.options.overflowY = !!b;
- BI.nextTick(function () {
- self.element.css({overflowY: b ? "auto" : "hidden"});
- });
- }
+ this.cardMap[v].on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ if (type === BI.Events.CLICK) {
+ self.fireEvent(BI.Navigation.EVENT_CHANGE, obj);
+ }
+ });
+ this.options.afterCardCreated.apply(this, arguments);
},
- getScrollLeft: function () {
- return this.options.scrollLeft;
+ afterCardShow: function (v) {
+ this.showIndex = v;
+ this._deleteOtherCards(v);
+ this.options.afterCardShow.apply(this, arguments);
},
- getScrollTop: function () {
- return this.options.scrollTop;
+ populate: function () {
+ var card = this.layout.getShowingCard();
+ if (card) {
+ return card.populate.apply(card, arguments);
+ }
},
- getMaxScrollLeft: function () {
- return this._getMaxScrollLeft();
+ _assertCard: function (v) {
+ if (!this.layout.isCardExisted(v)) {
+ var card = this.options.cardCreator(v);
+ this.cardMap[v] = card;
+ this.layout.addCardByName(v, card);
+ this.afterCardCreated(v);
+ }
},
- getMaxScrollTop: function () {
- return this._getMaxScrollTop();
+ setSelect: function (v) {
+ this._assertCard(v);
+ this.layout.showCardByName(v);
+ this._deleteOtherCards(v);
+ if (this.showIndex !== v) {
+ this.showIndex = v;
+ BI.nextTick(BI.bind(this.afterCardShow, this, v));
+ }
},
- setEstimatedColumnSize: function (width) {
- this.options.estimatedColumnSize = width;
+ getSelect: function () {
+ return this.showIndex;
},
- setEstimatedRowSize: function (height) {
- this.options.estimatedRowSize = height;
+ getSelectedCard: function () {
+ if (BI.isKey(this.showIndex)) {
+ return this.cardMap[this.showIndex];
+ }
},
- // 重新计算children
- _reRange: function () {
- this.renderRange = {};
+ /**
+ * @override
+ */
+ setValue: function (v) {
+ var card = this.layout.getShowingCard();
+ if (card) {
+ card.setValue(v);
+ }
},
- _clearChildren: function () {
- this.container._children = {};
- this.container.attr("items", []);
+ /**
+ * @override
+ */
+ getValue: function () {
+ var card = this.layout.getShowingCard();
+ if (card) {
+ return card.getValue();
+ }
},
- restore: function () {
- BI.each(this.renderedCells, function (i, cell) {
- cell.el._destroy();
- });
- this._clearChildren();
- this.renderedCells = [];
- this.renderedKeys = [];
- this.renderRange = {};
- this._scrollLock = false;
+ empty: function () {
+ this.layout.deleteAllCard();
+ this.cardMap = {};
},
- populate: function (items) {
- if (items && items !== this.options.items) {
- this.restore();
- }
- this._populate(items);
+ destroy: function () {
+ BI.Navigation.superclass.destroy.apply(this, arguments);
}
});
-BI.GridView.EVENT_SCROLL = "EVENT_SCROLL";
-BI.shortcut("bi.grid_view", BI.GridView);/**
- * Popover弹出层,
- * @class BI.Popover
+BI.Navigation.EVENT_CHANGE = "EVENT_CHANGE";
+
+BI.shortcut("bi.navigation", BI.Navigation);/**
+ * 搜索逻辑控件
+ *
+ * Created by GUY on 2015/9/28.
+ * @class BI.Searcher
* @extends BI.Widget
*/
-BI.Popover = BI.inherit(BI.Widget, {
- _constant: {
- SIZE: {
- SMALL: "small",
- NORMAL: "normal",
- BIG: "big"
- },
- HEADER_HEIGHT: 40
- },
+BI.Searcher = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- return BI.extend(BI.Popover.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-popover bi-card",
- // width: 600,
- // height: 500,
- size: "normal", // small, normal, big
- header: null,
- body: null,
- footer: null
- });
- },
- render: function () {
- var self = this, o = this.options;
- this.startX = 0;
- this.startY = 0;
- this.tracker = new BI.MouseMoveTracker(function (deltaX, deltaY) {
- var size = self._calculateSize();
- var W = BI.Widget._renderEngine.createElement("body").width(), H = BI.Widget._renderEngine.createElement("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();
- }, _global);
- var items = {
- north: {
- el: {
- type: "bi.htape",
- cls: "bi-message-title bi-header-background",
- ref: function (_ref) {
- self.dragger = _ref;
- },
- items: [{
- type: "bi.absolute",
- items: [{
- el: BI.isPlainObject(o.header) ? BI.createWidget(o.header, {
- extraCls: "bi-font-bold"
- }) : {
- type: "bi.label",
- cls: "bi-font-bold",
- height: this._constant.HEADER_HEIGHT,
- text: o.header,
- textAlign: "left"
- },
- left: 20,
- top: 0,
- right: 0,
- bottom: 0
- }]
- }, {
- el: {
- type: "bi.icon_button",
- cls: "bi-message-close close-font",
- height: this._constant.HEADER_HEIGHT,
- handler: function () {
- self.close();
- }
- },
- width: 56
- }]
- },
- height: this._constant.HEADER_HEIGHT
+ return BI.extend(BI.Searcher.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-searcher",
+ lgap: 0,
+ rgap: 0,
+ tgap: 0,
+ bgap: 0,
+ vgap: 0,
+ hgap: 0,
+
+ isDefaultInit: false,
+ isAutoSearch: true, // 是否自动搜索
+ isAutoSync: true, // 是否自动同步数据, 即是否保持搜索面板和adapter面板状态值的统一
+ chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE,
+
+ // isAutoSearch为false时启用
+ onSearch: function (op, callback) {
+ callback([]);
},
- center: {
- el: {
- type: "bi.absolute",
- items: [{
- el: BI.createWidget(o.body),
- left: 20,
- top: 10,
- right: 20,
- bottom: 0
- }]
- }
- }
- };
- if (o.footer) {
- items.south = {
- el: {
- type: "bi.absolute",
- items: [{
- el: BI.createWidget(o.footer),
- left: 20,
- top: 0,
- right: 20,
- bottom: 0
- }]
- },
- height: 44
- };
- }
- var size = this._calculateSize();
+ el: {
+ type: "bi.search_editor"
+ },
- return {
- type: "bi.border",
- items: items,
- width: size.width,
- height: size.height
- };
- },
+ popup: {
+ type: "bi.searcher_view"
+ },
- 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);
+ adapter: null,
+ masker: { // masker层
+ offset: {}
+ }
});
},
- _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;
+ _init: function () {
+ BI.Searcher.superclass._init.apply(this, arguments);
+ var self = this, o = this.options;
+
+ this.editor = BI.createWidget(o.el, {
+ type: "bi.search_editor"
+ });
+
+ BI.createWidget({
+ type: "bi.vertical",
+ element: this,
+ lgap: o.lgap,
+ rgap: o.rgap,
+ tgap: o.tgap,
+ bgap: o.bgap,
+ vgap: o.vgap,
+ hgap: o.hgap,
+ items: [this.editor]
+ });
+ o.isDefaultInit && (this._assertPopupView());
+
+ var search = BI.debounce(BI.bind(this._search, this), BI.EVENT_RESPONSE_TIME, {
+ "leading": true,
+ "trailing": false
+ });
+ this.editor.on(BI.Controller.EVENT_CHANGE, function (type) {
+ switch (type) {
+ case BI.Events.STARTEDIT:
+ self._startSearch();
break;
- case this._constant.SIZE.BIG:
- size.width = 900;
- size.height = 500;
+ case BI.Events.EMPTY:
+ self._stopSearch();
+ break;
+ case BI.Events.CHANGE:
+ search();
+ break;
+ case BI.Events.PAUSE:
+ self._pauseSearch();
break;
- default:
- size.width = 550;
- size.height = 500;
}
- }
- return {
- width: o.width || size.width,
- height: o.height || size.height
- };
- },
-
- hide: function () {
-
+ });
},
- open: function () {
- this.show();
- this.fireEvent(BI.Popover.EVENT_OPEN, arguments);
+ _assertPopupView: function () {
+ var self = this, o = this.options;
+ 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
+ });
+ this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ if (type === BI.Events.CLICK) {
+ if (o.isAutoSync) {
+ var values = o.adapter && o.adapter.getValue();
+ if (!obj.isSelected()) {
+ o.adapter && o.adapter.setValue(BI.deepWithout(values, obj.getValue()));
+ } else {
+ switch (o.chooseType) {
+ case BI.ButtonGroup.CHOOSE_TYPE_SINGLE:
+ o.adapter && o.adapter.setValue([obj.getValue()]);
+ break;
+ case BI.ButtonGroup.CHOOSE_TYPE_MULTI:
+ values.push(obj.getValue());
+ o.adapter && o.adapter.setValue(values);
+ break;
+ }
+ }
+ }
+ self.fireEvent(BI.Searcher.EVENT_CHANGE, value, obj);
+ }
+ });
+ BI.nextTick(function () {
+ 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), this);
+ }
},
- close: function () {
- this.hide();
- this.fireEvent(BI.Popover.EVENT_CLOSE, arguments);
+ _startSearch: function () {
+ this._assertPopupView();
+ this._stop = false;
+ this._isSearching = true;
+ this.fireEvent(BI.Searcher.EVENT_START);
+ this.popupView.startSearch && this.popupView.startSearch();
+ // 搜索前先清空dom
+ // BI.Maskers.get(this.getName()).empty();
+ BI.nextTick(function (name) {
+ BI.Maskers.show(name);
+ }, this.getName());
},
- setZindex: function (zindex) {
- this.element.css({"z-index": zindex});
+ _pauseSearch: function () {
+ var o = this.options, name = this.getName();
+ this._stop = true;
+ BI.nextTick(function (name) {
+ BI.Maskers.hide(name);
+ }, this.getName());
+ if (this._isSearching === true) {
+ this.popupView && this.popupView.pauseSearch && this.popupView.pauseSearch();
+ this.fireEvent(BI.Searcher.EVENT_PAUSE);
+ }
+ this._isSearching = false;
},
- destroyed: function () {
- }
-});
-
-BI.shortcut("bi.popover", BI.Popover);
-
-BI.BarPopover = BI.inherit(BI.Popover, {
- _defaultConfig: function () {
- return BI.extend(BI.BarPopover.superclass._defaultConfig.apply(this, arguments), {
- btns: [BI.i18nText(BI.i18nText("BI-Basic_Sure")), BI.i18nText(BI.i18nText("BI-Basic_Cancel"))]
- });
+ _stopSearch: function () {
+ var o = this.options, name = this.getName();
+ this._stop = true;
+ BI.Maskers.hide(name);
+ if (this._isSearching === true) {
+ this.popupView && this.popupView.stopSearch && this.popupView.stopSearch();
+ this.fireEvent(BI.Searcher.EVENT_STOP);
+ }
+ this._isSearching = false;
},
- beforeCreate: function () {
- var self = this, o = this.options;
- o.footer || (o.footer = {
- type: "bi.right_vertical_adapt",
- lgap: 10,
- items: [{
- type: "bi.button",
- text: this.options.btns[1],
- value: 1,
- level: "ignore",
- handler: function (v) {
- self.fireEvent(BI.Popover.EVENT_CANCEL, v);
- self.close(v);
- }
- }, {
- type: "bi.button",
- text: this.options.btns[0],
- warningTitle: o.warningTitle,
- value: 0,
- handler: function (v) {
- self.fireEvent(BI.Popover.EVENT_CONFIRM, v);
- self.close(v);
+ _search: function () {
+ var self = this, o = this.options, keyword = this.editor.getValue();
+ if (keyword === "" || this._stop) {
+ return;
+ }
+ if (o.isAutoSearch) {
+ var items = (o.adapter && ((o.adapter.getItems && o.adapter.getItems()) || o.adapter.attr("items"))) || [];
+ var finding = BI.Func.getSearchResult(items, keyword);
+ var match = finding.match, find = finding.find;
+ this.popupView.populate(find, match, keyword);
+ o.isAutoSync && o.adapter && o.adapter.getValue && this.popupView.setValue(o.adapter.getValue());
+ self.fireEvent(BI.Searcher.EVENT_SEARCHING);
+ return;
+ }
+ this.popupView.loading && this.popupView.loading();
+ o.onSearch({
+ times: 1,
+ keyword: keyword,
+ selectedValues: o.adapter && o.adapter.getValue()
+ }, function (searchResult, matchResult) {
+ if (!self._stop) {
+ var args = [].slice.call(arguments);
+ if (args.length > 0) {
+ args.push(keyword);
}
- }]
+ BI.Maskers.show(self.getName());
+ self.popupView.populate.apply(self.popupView, args);
+ 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);
+ }
});
- }
-});
-
-BI.shortcut("bi.bar_popover", BI.BarPopover);
+ },
-BI.Popover.EVENT_CLOSE = "EVENT_CLOSE";
-BI.Popover.EVENT_OPEN = "EVENT_OPEN";
-BI.Popover.EVENT_CANCEL = "EVENT_CANCEL";
-BI.Popover.EVENT_CONFIRM = "EVENT_CONFIRM";
-/**
- * 下拉框弹出层, zIndex在1000w
- * @class BI.PopupView
- * @extends BI.Widget
- */
-BI.PopupView = BI.inherit(BI.Widget, {
- _defaultConfig: function () {
- return BI.extend(BI.PopupView.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-popup-view",
- maxWidth: "auto",
- minWidth: 100,
- // maxHeight: 200,
- minHeight: 24,
- lgap: 0,
- rgap: 0,
- tgap: 0,
- bgap: 0,
- vgap: 0,
- hgap: 0,
- innerVGap: 0,
- direction: BI.Direction.Top, // 工具栏的方向
- stopEvent: false, // 是否停止mousedown、mouseup事件
- stopPropagation: false, // 是否停止mousedown、mouseup向上冒泡
- logic: {
- dynamic: true
- },
+ setAdapter: function (adapter) {
+ this.options.adapter = adapter;
+ BI.Maskers.remove(this.getName());
+ },
- tool: false, // 自定义工具栏
- tabs: [], // 导航栏
- buttons: [], // toolbar栏
+ doSearch: function () {
+ if (this.isSearching()) {
+ this._search();
+ }
+ },
- el: {
- type: "bi.button_group",
- items: [],
- chooseType: 0,
- behaviors: {},
- layouts: [{
- type: "bi.vertical"
- }]
+ stopSearch: function () {
+ this._stopSearch();// 先停止搜索,然后再去设置editor为空
+ // important:停止搜索必须退出编辑状态,这里必须加上try(input框不显示时blur会抛异常)
+ try {
+ this.editor.blur();
+ } catch (e) {
+ if (!this.editor.blur) {
+ throw new Error("editor没有实现blur方法");
}
- });
+ } finally {
+ this.editor.setValue("");
+ }
},
- _init: function () {
- BI.PopupView.superclass._init.apply(this, arguments);
- var self = this, o = this.options;
- var fn = function (e) {
- e.stopPropagation();
- }, stop = function (e) {
- e.stopEvent();
- return false;
- };
- this.element.css({
- "z-index": BI.zIndex_popup,
- "min-width": o.minWidth + "px",
- "max-width": o.maxWidth + "px"
- }).bind({click: fn});
+ isSearching: function () {
+ return this._isSearching;
+ },
- this.element.bind("mousewheel", fn);
+ isViewVisible: function () {
+ return this.editor.isEnabled() && BI.Maskers.isVisible(this.getName());
+ },
- o.stopPropagation && this.element.bind({mousedown: fn, mouseup: fn, mouseover: fn});
- o.stopEvent && this.element.bind({mousedown: stop, mouseup: stop, mouseover: stop});
- this.tool = this._createTool();
- this.tab = this._createTab();
- this.view = this._createView();
- this.toolbar = this._createToolBar();
+ getView: function () {
+ return this.popupView;
+ },
- this.button_group.on(BI.Controller.EVENT_CHANGE, function (type) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- if (type === BI.Events.CLICK) {
- self.fireEvent(BI.PopupView.EVENT_CHANGE);
- }
- });
+ hasMatched: function () {
+ this._assertPopupView();
+ return this.popupView.hasMatched();
+ },
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
- scrolly: false,
- lgap: o.lgap,
- rgap: o.rgap,
- tgap: o.tgap,
- bgap: o.bgap,
- vgap: o.vgap,
- hgap: o.hgap,
- items: BI.LogicFactory.createLogicItemsByDirection(o.direction,
- BI.extend({
- cls: "list-view-outer bi-card list-view-shadow"
- }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tool, this.tab, this.view, this.toolbar)
- })))
- )
- }))));
+ adjustHeight: function () {
+ if (BI.Maskers.has(this.getName()) && BI.Maskers.get(this.getName()).isVisible()) {
+ BI.Maskers.show(this.getName());
+ }
},
- _createView: function () {
- var o = this.options;
- this.button_group = BI.createWidget(o.el, {type: "bi.button_group", value: o.value});
- this.button_group.element.css({"min-height": o.minHeight + "px", "padding-top": o.innerVGap + "px", "padding-bottom": o.innerVGap + "px"});
- return this.button_group;
+ adjustView: function () {
+ this.isViewVisible() && BI.Maskers.show(this.getName());
},
- _createTool: function () {
- var o = this.options;
- if (false === o.tool) {
- return;
+ setValue: function (v) {
+ if (BI.isNull(this.popupView)) {
+ this.options.popup.value = v;
+ } else {
+ this.popupView.setValue(v);
}
- return BI.createWidget(o.tool);
},
- _createTab: function () {
- var o = this.options;
- if (o.tabs.length === 0) {
- return;
- }
- return BI.createWidget({
- type: "bi.center",
- cls: "list-view-tab",
- height: 25,
- items: o.tabs,
- value: o.value
- });
+ getKeyword: function () {
+ return this.editor.getValue();
},
- _createToolBar: function () {
+ getKeywords: function () {
+ return this.editor.getKeywords();
+ },
+
+ getValue: function () {
var o = this.options;
- if (o.buttons.length === 0) {
- return;
+ if (o.isAutoSync && o.adapter && o.adapter.getValue) {
+ return o.adapter.getValue();
+ }
+ if (this.isSearching()) {
+ return this.popupView.getValue();
+ } else if (o.adapter && o.adapter.getValue) {
+ return o.adapter.getValue();
}
+ if (BI.isNull(this.popupView)) {
+ return o.popup.value;
+ }
+ return this.popupView.getValue();
- return BI.createWidget({
- type: "bi.center",
- cls: "list-view-toolbar bi-high-light bi-split-top",
- height: 24,
- items: BI.createItems(o.buttons, {
- once: false,
- shadow: true,
- isShadowShowingOnSelected: true
- })
- });
},
- getView: function () {
- return this.button_group;
+ populate: function (result, searchResult, keyword) {
+ var o = this.options;
+ this._assertPopupView();
+ this.popupView.populate.apply(this.popupView, arguments);
+ if (o.isAutoSync && o.adapter && o.adapter.getValue) {
+ this.popupView.setValue(o.adapter.getValue());
+ }
},
- populate: function (items) {
- this.button_group.populate.apply(this.button_group, arguments);
+ empty: function () {
+ this.popupView && this.popupView.empty();
},
- resetWidth: function (w) {
- this.options.width = w;
- this.element.width(w);
- },
-
- resetHeight: function (h) {
- var tbHeight = this.toolbar ? (this.toolbar.attr("height") || 24) : 0,
- tabHeight = this.tab ? (this.tab.attr("height") || 24) : 0,
- toolHeight = ((this.tool && this.tool.attr("height")) || 24) * ((this.tool && this.tool.isVisible()) ? 1 : 0);
- var resetHeight = h - tbHeight - tabHeight - toolHeight - 2 * this.options.innerVGap - 2;
- this.view.resetHeight ? this.view.resetHeight(resetHeight) :
- this.view.element.css({"max-height": resetHeight + "px"});
- },
-
- setValue: function (selectedValues) {
- this.tab && this.tab.setValue(selectedValues);
- this.button_group.setValue(selectedValues);
- },
-
- getValue: function () {
- return this.button_group.getValue();
+ destroy: function () {
+ BI.Maskers.remove(this.getName());
+ BI.Searcher.superclass.destroy.apply(this, arguments);
}
});
-BI.PopupView.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.popup_view", BI.PopupView);/**
- * 搜索面板
+BI.Searcher.EVENT_CHANGE = "EVENT_CHANGE";
+BI.Searcher.EVENT_START = "EVENT_START";
+BI.Searcher.EVENT_STOP = "EVENT_STOP";
+BI.Searcher.EVENT_PAUSE = "EVENT_PAUSE";
+BI.Searcher.EVENT_SEARCHING = "EVENT_SEARCHING";
+BI.Searcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT";
+
+BI.shortcut("bi.searcher", BI.Searcher);/**
*
- * Created by GUY on 2015/9/28.
- * @class BI.SearcherView
- * @extends BI.Pane
+ * 切换显示或隐藏面板
+ *
+ * Created by GUY on 2015/11/2.
+ * @class BI.Switcher
+ * @extends BI.Widget
*/
-
-BI.SearcherView = BI.inherit(BI.Pane, {
+BI.Switcher = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- var conf = BI.SearcherView.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-searcher-view bi-card",
- tipText: BI.i18nText("BI-No_Select"),
- chooseType: BI.Selection.Single,
-
- matcher: {// 完全匹配的构造器
- type: "bi.button_group",
- behaviors: {
- redmark: function () {
- return true;
- }
- },
- items: [],
- layouts: [{
- type: "bi.vertical"
- }]
- },
- searcher: {
- type: "bi.button_group",
- behaviors: {
- redmark: function () {
- return true;
- }
- },
- items: [],
- layouts: [{
- type: "bi.vertical"
- }]
- }
+ return BI.extend(BI.Switcher.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-switcher",
+ direction: BI.Direction.Top,
+ trigger: "click",
+ toggle: true,
+ el: {},
+ popup: {},
+ adapter: null,
+ masker: {},
+ switcherClass: "bi-switcher-popup",
+ hoverClass: "bi-switcher-hover"
});
},
_init: function () {
- BI.SearcherView.superclass._init.apply(this, arguments);
+ BI.Switcher.superclass._init.apply(this, arguments);
var self = this, o = this.options;
-
- this.matcher = BI.createWidget(o.matcher, {
- type: "bi.button_group",
- chooseType: o.chooseType,
- behaviors: {
- redmark: function () {
- return true;
+ this._initSwitcher();
+ this._initPullDownAction();
+ this.switcher.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ if (self.isEnabled() && self.isValid()) {
+ if (type === BI.Events.EXPAND) {
+ self._popupView();
}
- },
- layouts: [{
- type: "bi.vertical"
- }],
- value: o.value
- });
- this.matcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- if (type === BI.Events.CLICK) {
- self.fireEvent(BI.SearcherView.EVENT_CHANGE, val, ob);
- }
- });
- this.spliter = BI.createWidget({
- type: "bi.vertical",
- height: 1,
- hgap: 10,
- items: [{
- type: "bi.layout",
- height: 1,
- cls: "searcher-view-spliter bi-background"
- }]
- });
- this.searcher = BI.createWidget(o.searcher, {
- type: "bi.button_group",
- chooseType: o.chooseType,
- behaviors: {
- redmark: function () {
- return true;
+ if (type === BI.Events.COLLAPSE) {
+ self._hideView();
+ }
+ if (type === BI.Events.EXPAND) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ self.fireEvent(BI.Switcher.EVENT_EXPAND);
+ }
+ if (type === BI.Events.COLLAPSE) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ self.isViewVisible() && self.fireEvent(BI.Switcher.EVENT_COLLAPSE);
+ }
+ if (type === BI.Events.CLICK) {
+ self.fireEvent(BI.Switcher.EVENT_TRIGGER_CHANGE, value, obj);
}
- },
- layouts: [{
- type: "bi.vertical"
- }],
- value: o.value
- });
- this.searcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- if (type === BI.Events.CLICK) {
- self.fireEvent(BI.SearcherView.EVENT_CHANGE, val, ob);
}
});
+ this.element.hover(function () {
+ if (self.isEnabled() && self.switcher.isEnabled()) {
+ self.element.addClass(o.hoverClass);
+ }
+ }, function () {
+ if (self.isEnabled() && self.switcher.isEnabled()) {
+ self.element.removeClass(o.hoverClass);
+ }
+ });
BI.createWidget({
type: "bi.vertical",
+ scrolly: false,
element: this,
- items: [this.matcher, this.spliter, this.searcher]
+ items: [
+ {el: this.switcher}
+ ]
});
+ o.isDefaultInit && (this._assertPopupView());
},
- startSearch: function () {
-
- },
-
- stopSearch: function () {
-
- },
-
- setValue: function (v) {
- this.matcher.setValue(v);
- this.searcher.setValue(v);
- },
-
- getValue: function () {
- return this.matcher.getValue().concat(this.searcher.getValue());
+ _toggle: function () {
+ this._assertPopupView();
+ if (this.isExpanded()) {
+ this._hideView();
+ } else {
+ if (this.isEnabled()) {
+ this._popupView();
+ }
+ }
},
- populate: function (searchResult, matchResult, keyword) {
- searchResult || (searchResult = []);
- matchResult || (matchResult = []);
- this.setTipVisible(searchResult.length + matchResult.length === 0);
- this.spliter.setVisible(BI.isNotEmptyArray(matchResult) && BI.isNotEmptyArray(searchResult));
- this.matcher.populate(matchResult, keyword);
- this.searcher.populate(searchResult, keyword);
+ _initPullDownAction: function () {
+ var self = this, o = this.options;
+ var evs = this.options.trigger.split(",");
+ BI.each(evs, function (i, e) {
+ switch (e) {
+ case "hover":
+ self.element[e](function (e) {
+ if (self.isEnabled() && self.switcher.isEnabled()) {
+ self._popupView();
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.switcher);
+ self.fireEvent(BI.Switcher.EVENT_EXPAND);
+ }
+ }, function () {
+ if (self.isEnabled() && self.switcher.isEnabled() && o.toggle) {
+ self._hideView();
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.switcher);
+ self.fireEvent(BI.Switcher.EVENT_COLLAPSE);
+ }
+ });
+ break;
+ default :
+ if (e) {
+ self.element.off(e + "." + self.getName()).on(e + "." + self.getName(), BI.debounce(function (e) {
+ if (self.switcher.element.__isMouseInBounds__(e)) {
+ if (self.isEnabled() && self.switcher.isEnabled()) {
+ o.toggle ? self._toggle() : self._popupView();
+ if (self.isExpanded()) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.EXPAND, "", self.switcher);
+ self.fireEvent(BI.Switcher.EVENT_EXPAND);
+ } else {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, BI.Events.COLLAPSE, "", self.switcher);
+ self.fireEvent(BI.Switcher.EVENT_COLLAPSE);
+ }
+ }
+ }
+ }, BI.EVENT_RESPONSE_TIME, {
+ "leading": true,
+ "trailing": false
+ }));
+ }
+ break;
+ }
+ });
},
- empty: function () {
- this.searcher.empty();
- this.matcher.empty();
+ _initSwitcher: function () {
+ this.switcher = BI.createWidget(this.options.el, {
+ value: this.options.value
+ });
},
- hasMatched: function () {
- return this.matcher.getAllButtons().length > 0;
- }
-});
-BI.SearcherView.EVENT_CHANGE = "EVENT_CHANGE";
-
-BI.shortcut("bi.searcher_view", BI.SearcherView);/**
- * 表示当前对象
- *
- * Created by GUY on 2017/5/23.
- * @class BI.ListView
- * @extends BI.Widget
- */
-BI.ListView = BI.inherit(BI.Widget, {
- props: function () {
- return {
- baseCls: "bi-list-view",
- overscanHeight: 100,
- blockSize: 10,
- scrollTop: 0,
- el: {},
- items: []
- };
- },
-
- init: function () {
- var self = this;
- this.renderedIndex = -1;
- this.cache = {};
- },
-
- render: function () {
+ _assertPopupView: function () {
var self = this, o = this.options;
- return {
- type: "bi.vertical",
- items: [BI.extend({
- type: "bi.vertical",
- scrolly: false,
- ref: function () {
- self.container = this;
+ if (!this._created) {
+ this.popupView = BI.createWidget(o.popup, {
+ type: "bi.button_group",
+ element: o.adapter && BI.Maskers.create(this.getName(), o.adapter, BI.extend({container: this}, o.masker)),
+ cls: "switcher-popup",
+ layouts: [{
+ type: "bi.vertical",
+ hgap: 0,
+ vgap: 0
+ }],
+ value: o.value
+ }, this);
+ this.popupView.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ if (type === BI.Events.CLICK) {
+ self.fireEvent(BI.Switcher.EVENT_CHANGE, value, obj);
}
- }, o.el)],
- element: this
- };
+ });
+ if (o.direction !== BI.Direction.Custom && !o.adapter) {
+ BI.createWidget({
+ type: "bi.vertical",
+ scrolly: false,
+ element: this,
+ items: [
+ {el: this.popupView}
+ ]
+ });
+ }
+ this._created = true;
+ BI.nextTick(function () {
+ self.fireEvent(BI.Switcher.EVENT_AFTER_INIT);
+ });
+ }
},
- mounted: function () {
+ _hideView: function () {
+ this.fireEvent(BI.Switcher.EVENT_BEFORE_HIDEVIEW);
var self = this, o = this.options;
- this._populate();
- this.element.scroll(function (e) {
- o.scrollTop = self.element.scrollTop();
- self._calculateBlocksToRender();
- });
- BI.ResizeDetector.addResizeListener(this, function () {
- self._calculateBlocksToRender();
+ o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false));
+ BI.nextTick(function () {
+ o.adapter ? BI.Maskers.hide(self.getName()) : (self.popupView && self.popupView.setVisible(false));
+ self.element.removeClass(o.switcherClass);
+ self.fireEvent(BI.Switcher.EVENT_AFTER_HIDEVIEW);
});
},
- _renderMoreIf: function () {
+ _popupView: function () {
var self = this, o = this.options;
- var height = this.element.height();
- var minContentHeight = o.scrollTop + height + o.overscanHeight;
- var index = (this.cache[this.renderedIndex] && (this.cache[this.renderedIndex].index + o.blockSize)) || 0,
- cnt = this.renderedIndex + 1;
- var lastHeight;
- var getElementHeight = function () {
- return self.container.element.height();
- };
- while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
- var items = o.items.slice(index, index + o.blockSize);
- this.container.addItems(items);
- var addedHeight = getElementHeight() - lastHeight;
- this.cache[cnt] = {
- index: index,
- scrollTop: lastHeight,
- height: addedHeight
- };
- this.renderedIndex = cnt;
- cnt++;
- index += o.blockSize;
- }
+ this._assertPopupView();
+ this.fireEvent(BI.Switcher.EVENT_BEFORE_POPUPVIEW);
+ o.adapter ? BI.Maskers.show(this.getName()) : self.popupView.setVisible(true);
+ BI.nextTick(function (name) {
+ o.adapter ? BI.Maskers.show(name) : self.popupView.setVisible(true);
+ self.element.addClass(o.switcherClass);
+ self.fireEvent(BI.Switcher.EVENT_AFTER_POPUPVIEW);
+ }, this.getName());
},
- _calculateBlocksToRender: function () {
- var o = this.options;
- this._renderMoreIf();
+ populate: function (items) {
+ this._assertPopupView();
+ this.popupView.populate.apply(this.popupView, arguments);
+ this.switcher.populate.apply(this.switcher, arguments);
},
- _populate: function (items) {
- var o = this.options;
- if (items && this.options.items !== items) {
- this.options.items = items;
- }
- this._calculateBlocksToRender();
- this.element.scrollTop(o.scrollTop);
+ _setEnable: function (arg) {
+ BI.Switcher.superclass._setEnable.apply(this, arguments);
+ !arg && this.isViewVisible() && this._hideView();
},
- restore: function () {
- this.renderedIndex = -1;
- this.container.empty();
- this.cache = {};
+ setValue: function (v) {
+ this.switcher.setValue(v);
+ if (BI.isNull(this.popupView)) {
+ this.options.popup.value = v;
+ } else {
+ this.popupView.setValue(v);
+ }
},
- populate: function (items) {
- if (items && this.options.items !== items) {
- this.restore();
+ getValue: function () {
+ if (BI.isNull(this.popupView)) {
+ return this.options.popup.value;
+ } else {
+ return this.popupView.getValue();
}
- this._populate(items);
},
- destroyed: function () {
- this.restore();
- }
-});
-BI.shortcut("bi.list_view", BI.ListView);
+ setAdapter: function (adapter) {
+ this.options.adapter = adapter;
+ BI.Maskers.remove(this.getName());
+ },
-/**
- * 表示当前对象
- *
- * Created by GUY on 2017/5/22.
- * @class BI.VirtualList
- * @extends BI.Widget
- */
-BI.VirtualList = BI.inherit(BI.Widget, {
- props: function () {
- return {
- baseCls: "bi-virtual-list",
- overscanHeight: 100,
- blockSize: 10,
- scrollTop: 0,
- items: []
- };
+ isViewVisible: function () {
+ return this.isEnabled() && this.switcher.isEnabled() &&
+ (this.options.adapter ? BI.Maskers.isVisible(this.getName()) : (this.popupView && this.popupView.isVisible()));
},
- init: function () {
- var self = this;
- this.renderedIndex = -1;
- this.cache = {};
+ isExpanded: function () {
+ return this.isViewVisible();
},
- render: function () {
- var self = this, o = this.options;
- return {
- type: "bi.vertical",
- items: [{
- type: "bi.layout",
- ref: function () {
- self.topBlank = this;
- }
- }, {
- type: "bi.vertical",
- scrolly: false,
- ref: function () {
- self.container = this;
- }
- }, {
- type: "bi.layout",
- ref: function () {
- self.bottomBlank = this;
- }
- }],
- element: this
- };
+ showView: function () {
+ if (this.isEnabled() && this.switcher.isEnabled()) {
+ this._popupView();
+ }
},
- mounted: function () {
- var self = this, o = this.options;
- this._populate();
- this.element.scroll(function (e) {
- o.scrollTop = self.element.scrollTop();
- self._calculateBlocksToRender();
- });
- BI.ResizeDetector.addResizeListener(this, function () {
- self._calculateBlocksToRender();
- });
+ hideView: function () {
+ this._hideView();
},
- _renderMoreIf: function () {
- var self = this, o = this.options;
- var height = this.element.height();
- var minContentHeight = o.scrollTop + height + o.overscanHeight;
- var index = (this.cache[this.renderedIndex] && (this.cache[this.renderedIndex].index + o.blockSize)) || 0,
- cnt = this.renderedIndex + 1;
- var lastHeight;
- var getElementHeight = function () {
- return self.container.element.height() + self.topBlank.element.height() + self.bottomBlank.element.height();
- };
- while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
- var items = o.items.slice(index, index + o.blockSize);
- this.container.addItems(items);
- var addedHeight = getElementHeight() - lastHeight;
- this.cache[cnt] = {
- index: index,
- scrollTop: lastHeight,
- height: addedHeight
- };
- this.tree.set(cnt, addedHeight);
- this.renderedIndex = cnt;
- cnt++;
- index += o.blockSize;
- }
+ getView: function () {
+ return this.popupView;
},
- _calculateBlocksToRender: function () {
- var o = this.options;
- this._renderMoreIf();
- var height = this.element.height();
- var minContentHeightFrom = o.scrollTop - o.overscanHeight;
- var minContentHeightTo = o.scrollTop + height + o.overscanHeight;
- var start = this.tree.greatestLowerBound(minContentHeightFrom);
- var end = this.tree.leastUpperBound(minContentHeightTo);
- var needDestroyed = [];
- for (var i = 0; i < start; i++) {
- var index = this.cache[i].index;
- if (!this.cache[i].destroyed) {
- for (var j = index; j < index + o.blockSize && j < o.items.length; j++) {
- needDestroyed.push(this.container._children[j]);
- this.container._children[j] = null;
- }
- this.cache[i].destroyed = true;
- }
- }
- for (var i = end + 1; i <= this.renderedIndex; i++) {
- var index = this.cache[i].index;
- if (!this.cache[i].destroyed) {
- for (var j = index; j < index + o.blockSize && j < o.items.length; j++) {
- needDestroyed.push(this.container._children[j]);
- this.container._children[j] = null;
- }
- this.cache[i].destroyed = true;
- }
- }
- var firstFragment = BI.Widget._renderEngine.createFragment(), lastFragment = BI.Widget._renderEngine.createFragment();
- var currentFragment = firstFragment;
- for (var i = (start < 0 ? 0 : start); i <= end && i <= this.renderedIndex; i++) {
- var index = this.cache[i].index;
- if (!this.cache[i].destroyed) {
- currentFragment = lastFragment;
- }
- if (this.cache[i].destroyed === true) {
- for (var j = index; j < index + o.blockSize && j < o.items.length; j++) {
- var w = this.container._addElement(j, BI.extend({root: true}, BI.stripEL(o.items[j])));
- currentFragment.appendChild(w.element[0]);
- }
- this.cache[i].destroyed = false;
- }
- }
- this.container.element.prepend(firstFragment);
- this.container.element.append(lastFragment);
- this.topBlank.setHeight(this.cache[start < 0 ? 0 : start].scrollTop);
- var lastCache = this.cache[Math.min(end, this.renderedIndex)];
- this.bottomBlank.setHeight(this.tree.sumTo(this.renderedIndex) - lastCache.scrollTop - lastCache.height);
- BI.each(needDestroyed, function (i, child) {
- child && child._destroy();
- });
+ adjustView: function () {
+ this.isViewVisible() && BI.Maskers.show(this.getName());
},
- _populate: function (items) {
- var o = this.options;
- if (items && this.options.items !== items) {
- this.options.items = items;
- }
- this.tree = BI.PrefixIntervalTree.empty(Math.ceil(o.items.length / o.blockSize));
- this._calculateBlocksToRender();
- this.element.scrollTop(o.scrollTop);
+ getAllLeaves: function () {
+ return this.popupView && this.popupView.getAllLeaves();
},
- _clearChildren: function () {
- BI.each(this.container._children, function (i, cell) {
- cell && cell.el._destroy();
- });
- this.container._children = {};
- this.container.attr("items", []);
+ getNodeById: function (id) {
+ if (this.switcher.attr("id") === id) {
+ return this.switcher;
+ }
+ return this.popupView && this.popupView.getNodeById(id);
},
- restore: function () {
- this.renderedIndex = -1;
- this._clearChildren();
- this.cache = {};
- this.options.scrollTop = 0;
+ getNodeByValue: function (value) {
+ if (this.switcher.getValue() === value) {
+ return this.switcher;
+ }
+ return this.popupView && this.popupView.getNodeByValue(value);
},
- populate: function (items) {
- if (items && this.options.items !== items) {
- this.restore();
- }
- this._populate();
+ empty: function () {
+ this.popupView && this.popupView.empty();
},
- destroyed: function () {
- this.restore();
+ destroy: function () {
+ BI.Switcher.superclass.destroy.apply(this, arguments);
}
});
-BI.shortcut("bi.virtual_list", BI.VirtualList);
+BI.Switcher.EVENT_EXPAND = "EVENT_EXPAND";
+BI.Switcher.EVENT_COLLAPSE = "EVENT_COLLAPSE";
+BI.Switcher.EVENT_TRIGGER_CHANGE = "EVENT_TRIGGER_CHANGE";
+BI.Switcher.EVENT_CHANGE = "EVENT_CHANGE";
+BI.Switcher.EVENT_AFTER_INIT = "EVENT_AFTER_INIT";
-/**
- * 分页控件
- *
- * Created by GUY on 2015/8/31.
- * @class BI.Pager
- * @extends BI.Widget
- */
-BI.Pager = BI.inherit(BI.Widget, {
- _defaultConfig: function () {
- return BI.extend(BI.Pager.superclass._defaultConfig.apply(this, arguments), {
- baseCls: "bi-pager",
- behaviors: {},
- layouts: [{
- type: "bi.horizontal",
- hgap: 10,
- vgap: 0
- }],
- dynamicShow: true, // 是否动态显示上一页、下一页、首页、尾页, 若为false,则指对其设置使能状态
- // dynamicShow为false时以下两个有用
- dynamicShowFirstLast: false, // 是否动态显示首页、尾页
- dynamicShowPrevNext: false, // 是否动态显示上一页、下一页
- pages: false, // 总页数
- curr: function () {
- return 1;
- }, // 初始化当前页
- groups: 0, // 连续显示分页数
- jump: BI.emptyFn, // 分页的回调函数
+BI.Switcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
+BI.Switcher.EVENT_AFTER_POPUPVIEW = "EVENT_AFTER_POPUPVIEW";
+BI.Switcher.EVENT_BEFORE_HIDEVIEW = "EVENT_BEFORE_HIDEVIEW";
+BI.Switcher.EVENT_AFTER_HIDEVIEW = "EVENT_AFTER_HIDEVIEW";
- first: false, // 是否显示首页
- last: false, // 是否显示尾页
- prev: "上一页",
- next: "下一页",
+BI.shortcut("bi.switcher", BI.Switcher);/**
+ * Created by GUY on 2015/6/26.
+ */
- firstPage: 1,
- lastPage: function () { // 在万不得已时才会调用这个函数获取最后一页的页码, 主要作用于setValue方法
- return 1;
+BI.Tab = BI.inherit(BI.Widget, {
+ _defaultConfig: function () {
+ return BI.extend(BI.Tab.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-tab",
+ direction: "top", // top, bottom, left, right, custom
+ single: false, // 是不是单页面
+ logic: {
+ dynamic: false
},
- hasPrev: BI.emptyFn, // pages不可用时有效
- hasNext: BI.emptyFn // pages不可用时有效
+ showIndex: false,
+ tab: false,
+ cardCreator: function (v) {
+ return BI.createWidget();
+ }
});
},
- _init: function () {
- BI.Pager.superclass._init.apply(this, arguments);
- var self = this;
- this.currPage = BI.result(this.options, "curr");
- // 翻页太灵敏
- // this._lock = false;
- // this._debouce = BI.debounce(function () {
- // self._lock = false;
- // }, 300);
- this._populate();
- },
-
- _populate: function () {
- var self = this, o = this.options, view = [], dict = {};
- this.empty();
- var pages = BI.result(o, "pages");
- var curr = BI.result(this, "currPage");
- var groups = BI.result(o, "groups");
- var first = BI.result(o, "first");
- var last = BI.result(o, "last");
- var prev = BI.result(o, "prev");
- var next = BI.result(o, "next");
- if (pages === false) {
- groups = 0;
- first = false;
- last = false;
- } else {
- groups > pages && (groups = pages);
+ render: function () {
+ var self = this, o = this.options;
+ if (BI.isObject(o.tab)) {
+ this.tab = BI.createWidget(this.options.tab, {type: "bi.button_group"});
+ this.tab.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ });
}
+ this.cardMap = {};
+ this.layout = BI.createWidget({
+ type: "bi.card"
+ });
- // 计算当前组
- dict.index = Math.ceil((curr + ((groups > 1 && groups !== pages) ? 1 : 0)) / (groups === 0 ? 1 : groups));
+ BI.createWidget(BI.extend({
+ element: this
+ }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
+ items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tab, this.layout)
+ }))));
- // 当前页非首页,则输出上一页
- if (((!o.dynamicShow && !o.dynamicShowPrevNext) || curr > 1) && prev !== false) {
- if (BI.isKey(prev)) {
- view.push({
- text: prev,
- value: "prev",
- disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false)
- });
- } else {
- view.push(BI.extend({
- disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false)
- }, prev));
+ var listener = new BI.ShowListener({
+ eventObj: this.tab,
+ cardLayout: this.layout,
+ cardCreator: function (v) {
+ var card = o.cardCreator.apply(self, arguments);
+ self.cardMap[v] = card;
+ return card;
+ },
+ afterCardShow: function (v) {
+ self._deleteOtherCards(v);
+ self.curr = v;
}
- }
+ });
+ listener.on(BI.ShowListener.EVENT_CHANGE, function (value) {
+ self.fireEvent(BI.Tab.EVENT_CHANGE, value, self);
+ });
+ },
- // 当前组非首组,则输出首页
- if (((!o.dynamicShow && !o.dynamicShowFirstLast) || (dict.index > 1 && groups !== 0)) && first) {
- view.push({
- text: first,
- value: "first",
- disabled: !(dict.index > 1 && groups !== 0)
+ _deleteOtherCards: function (currCardName) {
+ var self = this, o = this.options;
+ if (o.single === true) {
+ BI.each(this.cardMap, function (name, card) {
+ if (name !== (currCardName + "")) {
+ self.layout.deleteCardByName(name);
+ delete self.cardMap[name];
+ }
});
- if (dict.index > 1 && groups !== 0) {
- view.push({
- type: "bi.label",
- cls: "page-ellipsis",
- text: "\u2026"
- });
- }
}
+ },
- // 输出当前页组
- dict.poor = Math.floor((groups - 1) / 2);
- dict.start = dict.index > 1 ? curr - dict.poor : 1;
- dict.end = dict.index > 1 ? (function () {
- var max = curr + (groups - dict.poor - 1);
- return max > pages ? pages : max;
- }()) : groups;
- if (dict.end - dict.start < groups - 1) { // 最后一组状态
- dict.start = dict.end - groups + 1;
- }
- var s = dict.start, e = dict.end;
- if (first && last && (dict.index > 1 && groups !== 0) && (pages > groups && dict.end < pages && groups !== 0)) {
- s++;
- e--;
- }
- for (; s <= e; s++) {
- if (s === curr) {
- view.push({
- text: s,
- value: s,
- selected: true
- });
- } else {
- view.push({
- text: s,
- value: s
- });
- }
+ _assertCard: function (v) {
+ if (!this.layout.isCardExisted(v)) {
+ var card = this.options.cardCreator(v);
+ this.cardMap[v] = card;
+ this.layout.addCardByName(v, card);
}
+ },
- // 总页数大于连续分页数,且当前组最大页小于总页,输出尾页
- if (((!o.dynamicShow && !o.dynamicShowFirstLast) || (pages > groups && dict.end < pages && groups !== 0)) && last) {
- if (pages > groups && dict.end < pages && groups !== 0) {
- view.push({
- type: "bi.label",
- cls: "page-ellipsis",
- text: "\u2026"
- });
- }
- view.push({
- text: last,
- value: "last",
- disabled: !(pages > groups && dict.end < pages && groups !== 0)
- });
+ mounted: function () {
+ var o = this.options;
+ if (o.showIndex !== false) {
+ this.setSelect(o.showIndex);
}
+ },
- // 当前页不为尾页时,输出下一页
- dict.flow = !prev && groups === 0;
- if (((!o.dynamicShow && !o.dynamicShowPrevNext) && next) || (curr !== pages && next || dict.flow)) {
- view.push((function () {
- if (BI.isKey(next)) {
- if (pages === false) {
- return {text: next, value: "next", disabled: o.hasNext(curr) === false};
- }
- return (dict.flow && curr === pages)
- ?
- {text: next, value: "next", disabled: true}
- :
- {text: next, value: "next", disabled: !(curr !== pages && next || dict.flow)};
- }
- return BI.extend({
- disabled: pages === false ? o.hasNext(curr) === false : !(curr !== pages && next || dict.flow)
- }, next);
-
- }()));
+ setSelect: function (v) {
+ this.tab && this.tab.setValue(v);
+ this._assertCard(v);
+ this.layout.showCardByName(v);
+ this._deleteOtherCards(v);
+ if (this.curr !== v) {
+ this.curr = v;
}
+ },
- this.button_group = BI.createWidget({
- type: "bi.button_group",
- element: this,
- items: BI.createItems(view, {
- cls: "bi-list-item-select",
- height: 23,
- hgap: 10
- }),
- behaviors: o.behaviors,
- layouts: o.layouts
- });
- this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
- // if (self._lock === true) {
- // return;
- // }
- // self._lock = true;
- // self._debouce();
- if (type === BI.Events.CLICK) {
- var v = self.button_group.getValue()[0];
- switch (v) {
- case "first":
- self.currPage = 1;
- break;
- case "last":
- self.currPage = pages;
- break;
- case "prev":
- self.currPage--;
- break;
- case "next":
- self.currPage++;
- break;
- default:
- self.currPage = v;
- break;
- }
- o.jump.apply(self, [{
- pages: pages,
- curr: self.currPage
- }]);
- self._populate();
- self.fireEvent(BI.Pager.EVENT_CHANGE, obj);
+ removeTab: function (cardname) {
+ var self = this, o = this.options;
+ BI.any(this.cardMap, function (name, card) {
+ if (BI.isEqual(name, (cardname + ""))) {
+ self.layout.deleteCardByName(name);
+ delete self.cardMap[name];
+ return true;
}
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
- this.fireEvent(BI.Pager.EVENT_AFTER_POPULATE);
- },
-
- getCurrentPage: function () {
- return this.currPage;
},
- setAllPages: function (pages) {
- this.options.pages = pages;
+ getSelect: function () {
+ return this.curr;
},
- hasPrev: function (v) {
- v || (v = 1);
- var o = this.options;
- var pages = this.options.pages;
- return pages === false ? o.hasPrev(v) : v > 1;
+ getSelectedTab: function () {
+ return this.layout.getShowingCard();
},
- hasNext: function (v) {
- v || (v = 1);
- var o = this.options;
- var pages = this.options.pages;
- return pages === false ? o.hasNext(v) : v < pages;
+ getTab: function (v) {
+ this._assertCard(v);
+ return this.layout.getCardByName(v);
},
setValue: function (v) {
- var o = this.options;
- v = v | 0;
- v = v < 1 ? 1 : v;
- if (o.pages === false) {
- var lastPage = BI.result(o, "lastPage"), firstPage = 1;
- this.currPage = v > lastPage ? lastPage : ((firstPage = BI.result(o, "firstPage")), (v < firstPage ? firstPage : v));
- } else {
- v = v > o.pages ? o.pages : v;
- this.currPage = v;
+ var card = this.layout.getShowingCard();
+ if (card) {
+ card.setValue(v);
}
- this._populate();
},
getValue: function () {
- var val = this.button_group.getValue()[0];
- switch (val) {
- case "prev":
- return -1;
- case "next":
- return 1;
- case "first":
- return BI.MIN;
- case "last":
- return BI.MAX;
- default :
- return val;
+ var card = this.layout.getShowingCard();
+ if (card) {
+ return card.getValue();
}
},
- attr: function (key, value) {
- BI.Pager.superclass.attr.apply(this, arguments);
- if (key === "curr") {
- this.currPage = BI.result(this.options, "curr");
+ populate: function () {
+ var card = this.layout.getShowingCard();
+ if (card) {
+ return card.populate && card.populate.apply(card, arguments);
}
},
- populate: function () {
- this._populate();
+ empty: function () {
+ this.layout.deleteAllCard();
+ this.cardMap = {};
+ },
+
+ destroy: function () {
+ this.cardMap = {};
+ BI.Tab.superclass.destroy.apply(this, arguments);
}
});
-BI.Pager.EVENT_CHANGE = "EVENT_CHANGE";
-BI.Pager.EVENT_AFTER_POPULATE = "EVENT_AFTER_POPULATE";
-BI.shortcut("bi.pager", BI.Pager);/**
- * 超链接
+BI.Tab.EVENT_CHANGE = "EVENT_CHANGE";
+
+BI.shortcut("bi.tab", BI.Tab);/**
+ * 表示当前对象
*
- * Created by GUY on 2015/9/9.
- * @class BI.A
- * @extends BI.Text
- * @abstract
+ * Created by GUY on 2015/9/7.
+ * @class BI.EL
+ * @extends BI.Widget
*/
-BI.A = BI.inherit(BI.Text, {
+BI.EL = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- var conf = BI.A.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-a display-block",
- href: "",
- target: "_blank",
- el: null,
- tagName: "a"
+ return BI.extend(BI.EL.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-el",
+ el: {},
+ layout: {}
});
},
_init: function () {
- var o = this.options;
- BI.A.superclass._init.apply(this, arguments);
- this.element.attr({href: o.href, target: o.target});
- if (o.el) {
- BI.createWidget(o.el, {
- element: this
- });
- }
- }
-});
-
-BI.shortcut("bi.a", BI.A);/**
- * guy
- * 加载条
- * @type {*|void|Object}
- */
-BI.LoadingBar = BI.inherit(BI.Single, {
- _defaultConfig: function () {
- var conf = BI.LoadingBar.superclass._defaultConfig.apply(this, arguments);
- return BI.extend( conf, {
- baseCls: (conf.baseCls || "") + " bi-loading-bar bi-tips",
- height: 30,
- handler: BI.emptyFn
+ BI.EL.superclass._init.apply(this, arguments);
+ var self = this, o = this.options;
+ this.ele = BI.createWidget(o.el);
+ BI.createWidget(o.layout, {
+ type: "bi.adaptive",
+ element: this,
+ items: [this.ele]
+ });
+ this.ele.on(BI.Controller.EVENT_CHANGE, function () {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
},
- _init: function () {
- BI.LoadingBar.superclass._init.apply(this, arguments);
- var self = this;
- this.loaded = BI.createWidget({
- type: "bi.text_button",
- cls: "loading-text bi-list-item-simple",
- text: BI.i18nText("BI-Load_More"),
- width: 120,
- handler: this.options.handler
- });
- this.loaded.on(BI.Controller.EVENT_CHANGE, function (type) {
- self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
- });
-
- this.loading = BI.createWidget({
- type: "bi.layout",
- width: this.options.height,
- height: this.options.height,
- cls: "loading-background cursor-default"
- });
- var loaded = BI.createWidget({
- type: "bi.center_adapt",
- items: [this.loaded]
- });
- var loading = BI.createWidget({
- type: "bi.center_adapt",
- items: [this.loading]
- });
- this.cardLayout = BI.createWidget({
- type: "bi.card",
- element: this,
- items: [{
- el: loaded,
- cardName: "loaded"
- }, {
- el: loading,
- cardName: "loading"
- }]
- });
- this.invisible();
- },
-
- _reset: function () {
- this.visible();
- this.loaded.setText(BI.i18nText("BI-Load_More"));
- this.loaded.enable();
- },
- setLoaded: function () {
- this._reset();
- this.cardLayout.showCardByName("loaded");
+ setValue: function (v) {
+ this.ele.setValue(v);
},
- setEnd: function () {
- this.setLoaded();
- this.loaded.setText(BI.i18nText("BI-No_More_Data"));
- this.loaded.disable();
+ getValue: function () {
+ return this.ele.getValue();
},
- setLoading: function () {
- this._reset();
- this.cardLayout.showCardByName("loading");
+ populate: function () {
+ this.ele.populate.apply(this, arguments);
}
});
-
-BI.shortcut("bi.loading_bar", BI.LoadingBar);/**
- * @class BI.IconButton
- * @extends BI.BasicButton
- * 图标的button
+BI.shortcut("bi.el", BI.EL);/**
+ * z-index在1亿层级
+ * 弹出提示消息框,用于模拟阻塞操作(通过回调函数实现)
+ * @class BI.Msg
*/
-BI.IconButton = BI.inherit(BI.BasicButton, {
- _defaultConfig: function () {
- var conf = BI.IconButton.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-icon-button horizon-center",
- iconWidth: null,
- iconHeight: null
- });
- },
-
- _init: function () {
- BI.IconButton.superclass._init.apply(this, arguments);
- var o = this.options;
- this.element.css({
- textAlign: "center"
- });
- this.icon = BI.createWidget({
- type: "bi.icon",
- width: o.iconWidth,
- height: o.iconHeight
- });
- if (BI.isNumber(o.height) && o.height > 0 && BI.isNull(o.iconWidth) && BI.isNull(o.iconHeight)) {
- this.element.css("lineHeight", o.height + "px");
- BI.createWidget({
- type: "bi.default",
- element: this,
- items: [this.icon]
- });
- } else {
- this.element.css("lineHeight", "1");
- BI.createWidget({
- element: this,
- type: "bi.center_adapt",
- items: [this.icon]
- });
- }
- },
+BI.Msg = function () {
- doClick: function () {
- BI.IconButton.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.IconButton.EVENT_CHANGE, this);
- }
- }
-});
-BI.IconButton.EVENT_CHANGE = "IconButton.EVENT_CHANGE";
-BI.shortcut("bi.icon_button", BI.IconButton);/**
- * 图片的button
- *
- * Created by GUY on 2016/1/27.
- * @class BI.ImageButton
- * @extends BI.BasicButton
- */
-BI.ImageButton = BI.inherit(BI.BasicButton, {
- _defaultConfig: function () {
- var conf = BI.ImageButton.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-image-button",
- src: "",
- iconWidth: "100%",
- iconHeight: "100%"
- });
- },
+ var messageShow, $mask, $pop;
- _init: function () {
- BI.ImageButton.superclass._init.apply(this, arguments);
- var o = this.options;
- this.image = BI.createWidget({
- type: "bi.img",
- width: o.iconWidth,
- height: o.iconHeight,
- src: o.src
- });
- if (BI.isNumber(o.iconWidth) || BI.isNumber(o.iconHeight)) {
- BI.createWidget({
- type: "bi.center_adapt",
- element: this,
- items: [this.image]
+ return {
+ alert: function (title, message, callback) {
+ this._show(false, title, message, callback);
+ },
+ confirm: function (title, message, callback) {
+ this._show(true, title, message, callback);
+ },
+ prompt: function (title, message, value, callback, min_width) {
+ // BI.Msg.prompt(title, message, value, callback, min_width);
+ },
+ toast: function (message, options, context) {
+ options = options || {};
+ context = context || BI.Widget._renderEngine.createElement("body");
+ var level = options.level || "normal";
+ var autoClose = BI.isNull(options.autoClose) ? true : options.autoClose;
+ var toast = BI.createWidget({
+ type: "bi.toast",
+ cls: "bi-message-animate bi-message-leave",
+ level: level,
+ autoClose: autoClose,
+ text: message
});
- } else {
BI.createWidget({
- type: "bi.adaptive",
- element: this,
- items: [this.image],
- scrollable: false
+ type: "bi.absolute",
+ element: context,
+ items: [{
+ el: toast,
+ left: "50%",
+ top: 10
+ }]
});
- }
- },
-
- setWidth: function (w) {
- BI.ImageButton.superclass.setWidth.apply(this, arguments);
- this.options.width = w;
- },
-
- setHeight: function (h) {
- BI.ImageButton.superclass.setHeight.apply(this, arguments);
- this.options.height = h;
- },
-
- setImageWidth: function (w) {
- this.image.setWidth(w);
- },
-
- setImageHeight: function (h) {
- this.image.setHeight(h);
- },
-
- getImageWidth: function () {
- return this.image.element.width();
- },
-
- getImageHeight: function () {
- return this.image.element.height();
- },
-
- setSrc: function (src) {
- this.options.src = src;
- this.image.setSrc(src);
- },
-
- getSrc: function () {
- return this.image.getSrc();
- },
-
- doClick: function () {
- BI.ImageButton.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.ImageButton.EVENT_CHANGE, this);
- }
- }
-});
-BI.ImageButton.EVENT_CHANGE = "ImageButton.EVENT_CHANGE";
-BI.shortcut("bi.image_button", BI.ImageButton);
-/**
- * 文字类型的按钮
- * @class BI.Button
- * @extends BI.BasicButton
- *
- * @cfg {JSON} options 配置属性
- * @cfg {'common'/'success'/'warning'/'ignore'} [options.level='common'] 按钮类型,用不同颜色强调不同的场景
- */
-BI.Button = BI.inherit(BI.BasicButton, {
+ toast.element.css({"margin-left": -1 * toast.element.outerWidth() / 2});
+ toast.element.removeClass("bi-message-leave").addClass("bi-message-enter");
- _defaultConfig: function (props) {
- var conf = BI.Button.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-button",
- minWidth: (props.block === true || props.clear === true) ? 0 : 80,
- height: 24,
- shadow: props.clear !== true,
- isShadowShowingOnSelected: true,
- readonly: true,
- iconCls: "",
- level: "common",
- block: false, // 是否块状显示,即不显示边框,没有最小宽度的限制
- clear: false, // 是否去掉边框和背景
- ghost: false, // 是否幽灵显示, 即正常状态无背景
- textAlign: "center",
- whiteSpace: "nowrap",
- forceCenter: false,
- textWidth: null,
- textHeight: null,
- hgap: props.clear ? 0 : 10,
- vgap: 0,
- tgap: 0,
- bgap: 0,
- lgap: 0,
- rgap: 0
- });
- },
-
- _init: function () {
- BI.Button.superclass._init.apply(this, arguments);
- var o = this.options, self = this;
- if (BI.isNumber(o.height) && !o.clear && !o.block) {
- this.element.css({height: o.height + "px", lineHeight: (o.height - 2) + "px"});
- } else if (o.clear || o.block) {
- this.element.css({lineHeight: o.height + "px"});
- } else {
- this.element.css({lineHeight: (o.height - 2) + "px"});
- }
- if (BI.isKey(o.iconCls)) {
- this.icon = BI.createWidget({
- type: "bi.icon",
- width: 18,
- height: o.height - 2
- });
- this.text = BI.createWidget({
- type: "bi.label",
- text: o.text,
- value: o.value,
- height: o.height - 2
- });
- BI.createWidget({
- type: "bi.horizontal_auto",
- cls: o.iconCls,
- element: this,
- hgap: o.hgap,
- vgap: o.vgap,
- tgap: o.tgap,
- bgap: o.bgap,
- lgap: o.lgap,
- rgap: o.rgap,
- items: [{
- type: "bi.horizontal",
- items: [this.icon, this.text]
- }]
- });
- } else {
- this.text = BI.createWidget({
- type: "bi.label",
- textAlign: o.textAlign,
- whiteSpace: o.whiteSpace,
- forceCenter: o.forceCenter,
- textWidth: o.textWidth,
- textHeight: o.textHeight,
- hgap: o.hgap,
- vgap: o.vgap,
- tgap: o.tgap,
- bgap: o.bgap,
- lgap: o.lgap,
- rgap: o.rgap,
- element: this,
- text: o.text,
- value: o.value
+ autoClose && BI.delay(function () {
+ toast.element.removeClass("bi-message-enter").addClass("bi-message-leave");
+ BI.delay(function () {
+ toast.destroy();
+ }, 1000);
+ }, 5000);
+ },
+ _show: function (hasCancel, title, message, callback) {
+ $mask = BI.Widget._renderEngine.createElement("
").css({
+ position: "absolute",
+ zIndex: BI.zIndex_tip - 2,
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0,
+ opacity: 0.5
+ }).appendTo("body");
+ $pop = BI.Widget._renderEngine.createElement("
").css({
+ position: "absolute",
+ zIndex: BI.zIndex_tip - 1,
+ top: 0,
+ left: 0,
+ right: 0,
+ bottom: 0
+ }).appendTo("body");
+ var close = function () {
+ messageShow.destroy();
+ $mask.remove();
+ };
+ var controlItems = [];
+ if (hasCancel === true) {
+ controlItems.push({
+ el: {
+ type: "bi.button",
+ text: BI.i18nText("BI-Basic_Cancel"),
+ level: "ignore",
+ handler: function () {
+ close();
+ if (BI.isFunction(callback)) {
+ callback.apply(null, [false]);
+ }
+ }
+ }
+ });
+ }
+ controlItems.push({
+ el: {
+ type: "bi.button",
+ text: BI.i18nText("BI-Basic_OK"),
+ handler: function () {
+ close();
+ if (BI.isFunction(callback)) {
+ callback.apply(null, [true]);
+ }
+ }
+ }
});
- }
- if (o.block === true) {
- this.element.addClass("block");
- }
- if (o.clear === true) {
- this.element.addClass("clear");
- }
- if (o.ghost === true) {
- this.element.addClass("ghost");
- }
- if (o.minWidth > 0) {
- this.element.css({"min-width": o.minWidth + "px"});
- }
- },
-
- doClick: function () {
- BI.Button.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.Button.EVENT_CHANGE, this);
- }
- },
+ var conf = {
+ element: $pop,
+ type: "bi.center_adapt",
+ items: [
+ {
+ type: "bi.border",
+ cls: "bi-message-content bi-card",
+ items: {
+ north: {
+ el: {
+ type: "bi.border",
+ cls: "bi-message-title bi-background",
+ items: {
+ center: {
+ el: {
+ type: "bi.label",
+ text: title || BI.i18nText("BI-Basic_Prompt"),
+ textAlign: "left",
+ hgap: 20,
+ height: 50
+ }
+ },
+ east: {
+ el: {
+ type: "bi.icon_button",
+ cls: "bi-message-close close-font",
+ // height: 50,
+ handler: function () {
+ close();
+ if (BI.isFunction(callback)) {
+ callback.apply(null, [false]);
+ }
+ }
+ },
+ width: 60
+ }
+ }
+ },
+ height: 50
+ },
+ center: {
+ el: {
+ type: "bi.text",
+ cls: "bi-message-text",
+ tgap: 60,
+ hgap: 20,
+ lineHeight: 30,
+ whiteSpace: "normal",
+ text: message
+ }
+ },
+ south: {
+ el: {
+ type: "bi.absolute",
+ items: [{
+ el: {
+ type: "bi.right_vertical_adapt",
+ hgap: 5,
+ items: controlItems
+ },
+ top: 0,
+ left: 20,
+ right: 20,
+ bottom: 0
+ }]
- setText: function (text) {
- BI.Button.superclass.setText.apply(this, arguments);
- this.text.setText(text);
- },
+ },
+ height: 60
+ }
+ },
+ width: 400,
+ height: 300
+ }
+ ]
+ };
- setValue: function (text) {
- BI.Button.superclass.setValue.apply(this, arguments);
- if (!this.isReadOnly()) {
- this.text.setValue(text);
+ messageShow = BI.createWidget(conf);
}
- },
-
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
- },
-
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
- },
-
- doHighLight: function () {
- this.text.doHighLight.apply(this.text, arguments);
- },
-
- unHighLight: function () {
- this.text.unHighLight.apply(this.text, arguments);
- },
-
- destroy: function () {
- BI.Button.superclass.destroy.apply(this, arguments);
- }
-});
-BI.shortcut("bi.button", BI.Button);
-BI.Button.EVENT_CHANGE = "EVENT_CHANGE";
-/**
- * guy
- * 可以点击的一行文字
- * @class BI.TextButton
- * @extends BI.BasicButton
- * 文字button
- */
-BI.TextButton = BI.inherit(BI.BasicButton, {
- _defaultConfig: function () {
- var conf = BI.TextButton.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-text-button",
- textAlign: "center",
- whiteSpace: "nowrap",
- forceCenter: false,
- textWidth: null,
- textHeight: null,
- hgap: 0,
- lgap: 0,
- rgap: 0,
- text: "",
- py: ""
- });
+ };
+}();/**
+ * GridView
+ *
+ * Created by GUY on 2016/1/11.
+ * @class BI.GridView
+ * @extends BI.Widget
+ */
+BI.GridView = BI.inherit(BI.Widget, {
+ _defaultConfig: function () {
+ return BI.extend(BI.GridView.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-grid-view",
+ // width: 400, //必设
+ // height: 300, //必设
+ overflowX: true,
+ overflowY: true,
+ overscanColumnCount: 0,
+ overscanRowCount: 0,
+ rowHeightGetter: BI.emptyFn, // number类型或function类型
+ columnWidthGetter: BI.emptyFn, // number类型或function类型
+ // estimatedColumnSize: 100, //columnWidthGetter为function时必设
+ // estimatedRowSize: 30, //rowHeightGetter为function时必设
+ scrollLeft: 0,
+ scrollTop: 0,
+ items: []
+ });
},
_init: function () {
- BI.TextButton.superclass._init.apply(this, arguments);
- var o = this.options;
- this.text = BI.createWidget({
- type: "bi.label",
+ BI.GridView.superclass._init.apply(this, arguments);
+ var self = this, o = this.options;
+ this.renderedCells = [];
+ this.renderedKeys = [];
+ this.renderRange = {};
+ this._scrollLock = false;
+ this._debounceRelease = BI.debounce(function () {
+ self._scrollLock = false;
+ }, 1000 / 60);
+ this.container = BI.createWidget({
+ type: "bi.absolute"
+ });
+ this.element.scroll(function () {
+ if (self._scrollLock === true) {
+ return;
+ }
+ o.scrollLeft = self.element.scrollLeft();
+ o.scrollTop = self.element.scrollTop();
+ self._calculateChildrenToRender();
+ self.fireEvent(BI.GridView.EVENT_SCROLL, {
+ scrollLeft: o.scrollLeft,
+ scrollTop: o.scrollTop
+ });
+ });
+ BI.createWidget({
+ type: "bi.vertical",
element: this,
- textAlign: o.textAlign,
- whiteSpace: o.whiteSpace,
- textWidth: o.textWidth,
- textHeight: o.textHeight,
- forceCenter: o.forceCenter,
- width: o.width,
- height: o.height,
- hgap: o.hgap,
- lgap: o.lgap,
- rgap: o.rgap,
- text: o.text,
- value: o.value,
- py: o.py,
- keyword: o.keyword
+ scrollable: o.overflowX === true && o.overflowY === true,
+ scrolly: o.overflowX === false && o.overflowY === true,
+ scrollx: o.overflowX === true && o.overflowY === false,
+ items: [this.container]
});
+ if (o.items.length > 0) {
+ this._populate();
+ }
},
- doClick: function () {
- BI.TextButton.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.TextButton.EVENT_CHANGE, this.getValue(), this);
+ mounted: function () {
+ var o = this.options;
+ if (o.scrollLeft !== 0 || o.scrollTop !== 0) {
+ this.element.scrollTop(o.scrollTop);
+ this.element.scrollLeft(o.scrollLeft);
}
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ _getOverscanIndices: function (cellCount, overscanCellsCount, startIndex, stopIndex) {
+ return {
+ overscanStartIndex: Math.max(0, startIndex - overscanCellsCount),
+ overscanStopIndex: Math.min(cellCount - 1, stopIndex + overscanCellsCount)
+ };
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
- },
+ _calculateChildrenToRender: function () {
+ var self = this, o = this.options;
- doHighLight: function () {
- this.text.doHighLight.apply(this.text, arguments);
- },
+ var width = o.width, height = o.height, scrollLeft = BI.clamp(o.scrollLeft, 0, this._getMaxScrollLeft()),
+ scrollTop = BI.clamp(o.scrollTop, 0, this._getMaxScrollTop()),
+ overscanColumnCount = o.overscanColumnCount, overscanRowCount = o.overscanRowCount;
- unHighLight: function () {
- this.text.unHighLight.apply(this.text, arguments);
- },
+ if (height > 0 && width > 0) {
+ var visibleColumnIndices = this._columnSizeAndPositionManager.getVisibleCellRange(width, scrollLeft);
+ var visibleRowIndices = this._rowSizeAndPositionManager.getVisibleCellRange(height, scrollTop);
- setText: function (text) {
- BI.TextButton.superclass.setText.apply(this, arguments);
- text = BI.isArray(text) ? text.join(",") : text;
- this.text.setText(text);
- },
+ if (BI.isEmpty(visibleColumnIndices) || BI.isEmpty(visibleRowIndices)) {
+ return;
+ }
+ var horizontalOffsetAdjustment = this._columnSizeAndPositionManager.getOffsetAdjustment(width, scrollLeft);
+ var verticalOffsetAdjustment = this._rowSizeAndPositionManager.getOffsetAdjustment(height, scrollTop);
- setStyle: function (style) {
- this.text.setStyle(style);
- },
+ this._renderedColumnStartIndex = visibleColumnIndices.start;
+ this._renderedColumnStopIndex = visibleColumnIndices.stop;
+ this._renderedRowStartIndex = visibleRowIndices.start;
+ this._renderedRowStopIndex = visibleRowIndices.stop;
- setValue: function (text) {
- BI.TextButton.superclass.setValue.apply(this, arguments);
- if (!this.isReadOnly()) {
- text = BI.isArray(text) ? text.join(",") : text;
- this.text.setValue(text);
- }
- }
-});
-BI.TextButton.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.text_button", BI.TextButton);/**
- * 带有一个占位
- *
- * Created by GUY on 2015/9/11.
- * @class BI.BlankIconIconTextItem
- * @extends BI.BasicButton
- */
-BI.BlankIconIconTextItem = BI.inherit(BI.BasicButton, {
+ var overscanColumnIndices = this._getOverscanIndices(this.columnCount, overscanColumnCount, this._renderedColumnStartIndex, this._renderedColumnStopIndex);
- _defaultConfig: function () {
- var conf = BI.BlankIconIconTextItem.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-blank-icon-text-item",
- logic: {
- dynamic: false
- },
- iconCls1: "close-ha-font",
- iconCls2: "close-ha-font",
- blankWidth: 0,
- iconHeight: null,
- iconWidth: null,
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
- });
- },
- _init: function () {
- BI.BlankIconIconTextItem.superclass._init.apply(this, arguments);
- var o = this.options, c = this._const;
- var blank = BI.createWidget({
- type: "bi.layout",
- width: o.blankWidth,
- height: o.height
- });
- this.text = BI.createWidget({
- type: "bi.label",
- cls: "list-item-text",
- textAlign: "left",
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- height: o.height
- });
- this.icon1 = BI.createWidget({
- type: "bi.icon_button",
- cls: o.iconCls1,
- forceNotSelected: true,
- width: o.height,
- height: o.height
- });
- this.icon2 = BI.createWidget({
- type: "bi.icon_button",
- cls: o.iconCls2,
- forceNotSelected: true,
- width: o.height,
- height: o.height
- });
+ var overscanRowIndices = this._getOverscanIndices(this.rowCount, overscanRowCount, this._renderedRowStartIndex, this._renderedRowStopIndex);
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection("left", blank, this.icon1, this.icon2, this.text)
- }))));
- },
+ var columnStartIndex = overscanColumnIndices.overscanStartIndex;
+ var columnStopIndex = overscanColumnIndices.overscanStopIndex;
+ var rowStartIndex = overscanRowIndices.overscanStartIndex;
+ var rowStopIndex = overscanRowIndices.overscanStopIndex;
- doClick: function () {
- BI.BlankIconIconTextItem.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.BlankIconIconTextItem.EVENT_CHANGE, this.getValue(), this);
- }
- },
+ // 算区间size
+ var minRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStartIndex);
+ var minColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStartIndex);
+ var maxRowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowStopIndex);
+ var maxColumnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnStopIndex);
+ var top = minRowDatum.offset + verticalOffsetAdjustment;
+ var left = minColumnDatum.offset + horizontalOffsetAdjustment;
+ var bottom = maxRowDatum.offset + verticalOffsetAdjustment + maxRowDatum.size;
+ var right = maxColumnDatum.offset + horizontalOffsetAdjustment + maxColumnDatum.size;
+ // 如果滚动的区间并没有超出渲染的范围
+ if (top >= this.renderRange.minY && bottom <= this.renderRange.maxY && left >= this.renderRange.minX && right <= this.renderRange.maxX) {
+ return;
+ }
- setSelected: function (b) {
- BI.BlankIconIconTextItem.superclass.setSelected.apply(this, arguments);
- this.icon1.setSelected(b);
- this.icon2.setSelected(b);
- },
+ var renderedCells = [], renderedKeys = {}, renderedWidgets = {};
+ var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
+ var count = 0;
+ for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
+ var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
- }
- },
-
- getValue: function () {
- return this.text.getValue();
- },
+ for (var columnIndex = columnStartIndex; columnIndex <= columnStopIndex; columnIndex++) {
+ var key = rowIndex + "-" + columnIndex;
+ var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
- setText: function () {
- this.text.setText.apply(this.text, arguments);
+ var index = this.renderedKeys[key] && this.renderedKeys[key][2];
+ var child;
+ if (index >= 0) {
+ if (columnDatum.size !== this.renderedCells[index]._width) {
+ this.renderedCells[index]._width = columnDatum.size;
+ this.renderedCells[index].el.setWidth(columnDatum.size);
+ }
+ if (rowDatum.size !== this.renderedCells[index]._height) {
+ this.renderedCells[index]._height = rowDatum.size;
+ this.renderedCells[index].el.setHeight(rowDatum.size);
+ }
+ if (this.renderedCells[index]._left !== columnDatum.offset + horizontalOffsetAdjustment) {
+ this.renderedCells[index].el.element.css("left", (columnDatum.offset + horizontalOffsetAdjustment) + "px");
+ }
+ if (this.renderedCells[index]._top !== rowDatum.offset + verticalOffsetAdjustment) {
+ this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px");
+ }
+ renderedCells.push(child = this.renderedCells[index]);
+ } else {
+ child = BI.createWidget(BI.extend({
+ type: "bi.label",
+ width: columnDatum.size,
+ height: rowDatum.size
+ }, o.items[rowIndex][columnIndex], {
+ cls: (o.items[rowIndex][columnIndex].cls || "") + " grid-cell" + (rowIndex === 0 ? " first-row" : "") + (columnIndex === 0 ? " first-col" : ""),
+ _rowIndex: rowIndex,
+ _columnIndex: columnIndex,
+ _left: columnDatum.offset + horizontalOffsetAdjustment,
+ _top: rowDatum.offset + verticalOffsetAdjustment
+ }));
+ renderedCells.push({
+ el: child,
+ left: columnDatum.offset + horizontalOffsetAdjustment,
+ top: rowDatum.offset + verticalOffsetAdjustment,
+ _left: columnDatum.offset + horizontalOffsetAdjustment,
+ _top: rowDatum.offset + verticalOffsetAdjustment,
+ _width: columnDatum.size,
+ _height: rowDatum.size
+ });
+ }
+ minX = Math.min(minX, columnDatum.offset + horizontalOffsetAdjustment);
+ maxX = Math.max(maxX, columnDatum.offset + horizontalOffsetAdjustment + columnDatum.size);
+ minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
+ maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
+ renderedKeys[key] = [rowIndex, columnIndex, count];
+ renderedWidgets[count] = child;
+ count++;
+ }
+ }
+ // 已存在的, 需要添加的和需要删除的
+ var existSet = {}, addSet = {}, deleteArray = [];
+ BI.each(renderedKeys, function (i, key) {
+ if (self.renderedKeys[i]) {
+ existSet[i] = key;
+ } else {
+ addSet[i] = key;
+ }
+ });
+ BI.each(this.renderedKeys, function (i, key) {
+ if (existSet[i]) {
+ return;
+ }
+ if (addSet[i]) {
+ return;
+ }
+ deleteArray.push(key[2]);
+ });
+ BI.each(deleteArray, function (i, index) {
+ // 性能优化,不调用destroy方法防止触发destroy事件
+ self.renderedCells[index].el._destroy();
+ });
+ var addedItems = [];
+ BI.each(addSet, function (index, key) {
+ addedItems.push(renderedCells[key[2]]);
+ });
+ this.container.addItems(addedItems);
+ // 拦截父子级关系
+ this.container._children = renderedWidgets;
+ this.container.attr("items", renderedCells);
+ this.renderedCells = renderedCells;
+ this.renderedKeys = renderedKeys;
+ this.renderRange = {minX: minX, minY: minY, maxX: maxX, maxY: maxY};
+ }
},
- getText: function () {
- return this.text.getText();
+ /**
+ * 获取真实的可滚动的最大宽度
+ * 对于grid_view如果没有全部渲染过,this._columnSizeAndPositionManager.getTotalSize获取的宽度是不准确的
+ * 因此在调用setScrollLeft等函数时会造成没法移动到最右端(预估可移动具体太短)
+ */
+ _getRealMaxScrollLeft: function () {
+ var o = this.options;
+ var totalWidth = 0;
+ BI.count(0, this.columnCount, function (index) {
+ totalWidth += o.columnWidthGetter(index);
+ });
+ return Math.max(0, totalWidth - this.options.width + (this.options.overflowX ? BI.DOM.getScrollWidth() : 0));
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ _getMaxScrollLeft: function () {
+ return Math.max(0, this._columnSizeAndPositionManager.getTotalSize() - this.options.width + (this.options.overflowX ? BI.DOM.getScrollWidth() : 0));
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
+ _getMaxScrollTop: function () {
+ return Math.max(0, this._rowSizeAndPositionManager.getTotalSize() - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0));
},
- doHighLight: function () {
- this.text.doHighLight.apply(this.text, arguments);
- },
+ _populate: function (items) {
+ var self = this, o = this.options;
+ this._reRange();
+ this.columnCount = 0;
+ this.rowCount = 0;
+ if (items && items !== this.options.items) {
+ this.options.items = items;
+ }
+ if (BI.isNumber(o.columnCount)) {
+ this.columnCount = o.columnCount;
+ } else if (o.items.length > 0) {
+ this.columnCount = o.items[0].length;
+ }
+ if (BI.isNumber(o.rowCount)) {
+ this.rowCount = o.rowCount;
+ } else {
+ this.rowCount = o.items.length;
+ }
+ this.container.setWidth(this.columnCount * o.estimatedColumnSize);
+ this.container.setHeight(this.rowCount * o.estimatedRowSize);
- unHighLight: function () {
- this.text.unHighLight.apply(this.text, arguments);
- }
-});
-BI.BlankIconIconTextItem.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.blank_icon_icon_text_item", BI.BlankIconIconTextItem);/**
- * guy
- * 一个占位符和两个icon和一行数 组成的一行listitem
- *
- * Created by GUY on 2015/9/15.
- * @class BI.BlankIconTextIconItem
- * @extends BI.BasicButton
- */
-BI.BlankIconTextIconItem = BI.inherit(BI.BasicButton, {
+ this._columnSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.columnCount, o.columnWidthGetter, o.estimatedColumnSize);
+ this._rowSizeAndPositionManager = new BI.ScalingCellSizeAndPositionManager(this.rowCount, o.rowHeightGetter, o.estimatedRowSize);
- _defaultConfig: function () {
- var conf = BI.BlankIconTextIconItem.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-blank-icon-text-icon-item",
- logic: {
- dynamic: false
- },
- iconCls1: "close-ha-font",
- iconCls2: "close-ha-font",
- blankWidth: 0,
- iconHeight: null,
- iconWidth: null,
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
- });
+ this._calculateChildrenToRender();
+ // 元素未挂载时不能设置scrollTop
+ try {
+ this.element.scrollTop(o.scrollTop);
+ this.element.scrollLeft(o.scrollLeft);
+ } catch (e) {
+ }
},
- _init: function () {
- BI.BlankIconTextIconItem.superclass._init.apply(this, arguments);
- var o = this.options, c = this._const;
- this.text = BI.createWidget({
- type: "bi.label",
- textAlign: "left",
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- height: o.height
- });
-
- var icon1 = BI.createWidget({
- type: "bi.icon_label",
- cls: o.iconCls1,
- width: o.height,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
- });
- BI.createWidget({
- type: "bi.absolute",
- element: this,
- items: [{
- el: {
- type: "bi.icon_label",
- cls: o.iconCls2,
- width: o.height,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
- },
- top: 0,
- bottom: 0,
- right: 0
- }]
- });
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection("left", {
- type: "bi.layout",
- width: o.blankWidth
- }, icon1, this.text, {
- type: "bi.layout",
- width: o.height
- })
- }))));
+ setScrollLeft: function (scrollLeft) {
+ if (this.options.scrollLeft === scrollLeft) {
+ return;
+ }
+ this._scrollLock = true;
+ this.options.scrollLeft = BI.clamp(scrollLeft || 0, 0, this._getRealMaxScrollLeft());
+ this._debounceRelease();
+ this._calculateChildrenToRender();
+ this.element.scrollLeft(this.options.scrollLeft);
},
- doClick: function () {
- BI.BlankIconTextIconItem.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.BlankIconTextIconItem.EVENT_CHANGE, this.getValue(), this);
+ setScrollTop: function (scrollTop) {
+ if (this.options.scrollTop === scrollTop) {
+ return;
}
+ this._scrollLock = true;
+ this.options.scrollTop = BI.clamp(scrollTop || 0, 0, this._getMaxScrollTop());
+ this._debounceRelease();
+ this._calculateChildrenToRender();
+ this.element.scrollTop(this.options.scrollTop);
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ setColumnCount: function (columnCount) {
+ this.options.columnCount = columnCount;
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
- },
-
- doHighLight: function () {
- this.text.doHighLight.apply(this.text, arguments);
- },
-
- unHighLight: function () {
- this.text.unHighLight.apply(this.text, arguments);
+ setRowCount: function (rowCount) {
+ this.options.rowCount = rowCount;
},
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
+ setOverflowX: function (b) {
+ var self = this;
+ if (this.options.overflowX !== !!b) {
+ this.options.overflowX = !!b;
+ BI.nextTick(function () {
+ self.element.css({overflowX: b ? "auto" : "hidden"});
+ });
}
},
- getValue: function () {
- return this.text.getValue();
- },
-
- setText: function () {
- this.text.setText.apply(this.text, arguments);
- },
-
- getText: function () {
- return this.text.getText();
- }
-});
-BI.BlankIconTextIconItem.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.blank_icon_text_icon_item", BI.BlankIconTextIconItem);/**
- * 带有一个占位
- *
- * Created by GUY on 2015/9/11.
- * @class BI.BlankIconTextItem
- * @extends BI.BasicButton
- */
-BI.BlankIconTextItem = BI.inherit(BI.BasicButton, {
-
- _defaultConfig: function () {
- var conf = BI.BlankIconTextItem.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-blank-icon-text-item",
- logic: {
- dynamic: false
- },
- cls: "close-ha-font",
- blankWidth: 0,
- iconHeight: null,
- iconWidth: null,
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
- });
+ setOverflowY: function (b) {
+ var self = this;
+ if (this.options.overflowY !== !!b) {
+ this.options.overflowY = !!b;
+ BI.nextTick(function () {
+ self.element.css({overflowY: b ? "auto" : "hidden"});
+ });
+ }
},
- _init: function () {
- BI.BlankIconTextItem.superclass._init.apply(this, arguments);
- var o = this.options, c = this._const;
- var blank = BI.createWidget({
- type: "bi.layout",
- width: o.blankWidth
- });
- this.text = BI.createWidget({
- type: "bi.label",
- cls: "list-item-text",
- textAlign: "left",
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- height: o.height
- });
- this.icon = BI.createWidget({
- type: "bi.icon_label",
- width: o.height,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
- });
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection("left", blank, this.icon, this.text)
- }))));
+ getScrollLeft: function () {
+ return this.options.scrollLeft;
},
- doClick: function () {
- BI.BlankIconTextItem.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.BlankIconTextItem.EVENT_CHANGE, this.getValue(), this);
- }
+ getScrollTop: function () {
+ return this.options.scrollTop;
},
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
- }
+ getMaxScrollLeft: function () {
+ return this._getMaxScrollLeft();
},
- getValue: function () {
- return this.text.getValue();
+ getMaxScrollTop: function () {
+ return this._getMaxScrollTop();
},
- setText: function () {
- this.text.setText.apply(this.text, arguments);
+ setEstimatedColumnSize: function (width) {
+ this.options.estimatedColumnSize = width;
},
- getText: function () {
- return this.text.getText();
+ setEstimatedRowSize: function (height) {
+ this.options.estimatedRowSize = height;
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ // 重新计算children
+ _reRange: function () {
+ this.renderRange = {};
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
+ _clearChildren: function () {
+ this.container._children = {};
+ this.container.attr("items", []);
},
- doHighLight: function () {
- this.text.doHighLight.apply(this.text, arguments);
+ restore: function () {
+ BI.each(this.renderedCells, function (i, cell) {
+ cell.el._destroy();
+ });
+ this._clearChildren();
+ this.renderedCells = [];
+ this.renderedKeys = [];
+ this.renderRange = {};
+ this._scrollLock = false;
},
- unHighLight: function () {
- this.text.unHighLight.apply(this.text, arguments);
+ populate: function (items) {
+ if (items && items !== this.options.items) {
+ this.restore();
+ }
+ this._populate(items);
}
});
-BI.BlankIconTextItem.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.blank_icon_text_item", BI.BlankIconTextItem);/**
- * guy
- * 两个icon和一行数 组成的一行listitem
- *
- * Created by GUY on 2015/9/9.
- * @class BI.IconTextIconItem
- * @extends BI.BasicButton
+BI.GridView.EVENT_SCROLL = "EVENT_SCROLL";
+BI.shortcut("bi.grid_view", BI.GridView);/**
+ * Popover弹出层,
+ * @class BI.Popover
+ * @extends BI.Widget
*/
-BI.IconTextIconItem = BI.inherit(BI.BasicButton, {
+BI.Popover = BI.inherit(BI.Widget, {
+ _constant: {
+ SIZE: {
+ SMALL: "small",
+ NORMAL: "normal",
+ BIG: "big"
+ },
+ HEADER_HEIGHT: 40
+ },
_defaultConfig: function () {
- var conf = BI.IconTextIconItem.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-icon-text-icon-item",
- logic: {
- dynamic: false
- },
- iconCls1: "close-ha-font",
- iconCls2: "close-ha-font",
- iconHeight: null,
- iconWidth: null,
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
+ return BI.extend(BI.Popover.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-popover bi-card",
+ // width: 600,
+ // height: 500,
+ size: "normal", // small, normal, big
+ header: null,
+ body: null,
+ footer: null
});
},
- _init: function () {
- BI.IconTextIconItem.superclass._init.apply(this, arguments);
- var o = this.options, c = this._const;
- this.text = BI.createWidget({
- type: "bi.label",
- textAlign: "left",
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- height: o.height
- });
-
- var icon1 = BI.createWidget({
- type: "bi.icon_label",
- cls: o.iconCls1,
- width: o.leftIconWrapperWidth,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
- });
- var blank = BI.createWidget({
- type: "bi.layout",
- width: o.height
- });
- BI.createWidget({
- type: "bi.absolute",
- element: this,
- items: [{
+ render: function () {
+ var self = this, o = this.options;
+ this.startX = 0;
+ this.startY = 0;
+ this.tracker = new BI.MouseMoveTracker(function (deltaX, deltaY) {
+ var size = self._calculateSize();
+ var W = BI.Widget._renderEngine.createElement("body").width(), H = BI.Widget._renderEngine.createElement("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();
+ }, _global);
+ var items = {
+ north: {
el: {
- type: "bi.icon_label",
- cls: o.iconCls2,
- width: o.rightIconWrapperWidth,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
+ type: "bi.htape",
+ cls: "bi-message-title bi-header-background",
+ ref: function (_ref) {
+ self.dragger = _ref;
+ },
+ items: [{
+ type: "bi.absolute",
+ items: [{
+ el: BI.isPlainObject(o.header) ? BI.createWidget(o.header, {
+ extraCls: "bi-font-bold"
+ }) : {
+ type: "bi.label",
+ cls: "bi-font-bold",
+ height: this._constant.HEADER_HEIGHT,
+ text: o.header,
+ textAlign: "left"
+ },
+ left: 20,
+ top: 0,
+ right: 0,
+ bottom: 0
+ }]
+ }, {
+ el: {
+ type: "bi.icon_button",
+ cls: "bi-message-close close-font",
+ height: this._constant.HEADER_HEIGHT,
+ handler: function () {
+ self.close();
+ }
+ },
+ width: 56
+ }]
},
- top: 0,
- bottom: 0,
- right: 0
- }]
- });
+ height: this._constant.HEADER_HEIGHT
+ },
+ center: {
+ el: {
+ type: "bi.absolute",
+ items: [{
+ el: BI.createWidget(o.body),
+ left: 20,
+ top: 10,
+ right: 20,
+ bottom: 0
+ }]
+ }
+ }
+ };
+ if (o.footer) {
+ items.south = {
+ el: {
+ type: "bi.absolute",
+ items: [{
+ el: BI.createWidget(o.footer),
+ left: 20,
+ top: 0,
+ right: 20,
+ bottom: 0
+ }]
+ },
+ height: 44
+ };
+ }
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection("left", icon1, this.text, blank)
- }))));
- },
+ var size = this._calculateSize();
- doClick: function () {
- BI.IconTextIconItem.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.IconTextIconItem.EVENT_CHANGE, this.getValue(), this);
- }
+ return {
+ type: "bi.border",
+ items: items,
+ width: size.width,
+ height: size.height
+ };
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ 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);
+ });
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
+ _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
+ };
},
- doHighLight: function () {
- this.text.doHighLight.apply(this.text, arguments);
+ hide: function () {
+
},
- unHighLight: function () {
- this.text.unHighLight.apply(this.text, arguments);
+ open: function () {
+ this.show();
+ this.fireEvent(BI.Popover.EVENT_OPEN, arguments);
},
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
- }
+ close: function () {
+ this.hide();
+ this.fireEvent(BI.Popover.EVENT_CLOSE, arguments);
},
- getValue: function () {
- return this.text.getValue();
+ setZindex: function (zindex) {
+ this.element.css({"z-index": zindex});
},
- setText: function () {
- this.text.setText.apply(this.text, arguments);
+ destroyed: function () {
+ }
+});
+
+BI.shortcut("bi.popover", BI.Popover);
+
+BI.BarPopover = BI.inherit(BI.Popover, {
+ _defaultConfig: function () {
+ return BI.extend(BI.BarPopover.superclass._defaultConfig.apply(this, arguments), {
+ btns: [BI.i18nText(BI.i18nText("BI-Basic_Sure")), BI.i18nText(BI.i18nText("BI-Basic_Cancel"))]
+ });
},
- getText: function () {
- return this.text.getText();
+ beforeCreate: function () {
+ var self = this, o = this.options;
+ o.footer || (o.footer = {
+ type: "bi.right_vertical_adapt",
+ lgap: 10,
+ items: [{
+ type: "bi.button",
+ text: this.options.btns[1],
+ value: 1,
+ level: "ignore",
+ handler: function (v) {
+ self.fireEvent(BI.Popover.EVENT_CANCEL, v);
+ self.close(v);
+ }
+ }, {
+ type: "bi.button",
+ text: this.options.btns[0],
+ warningTitle: o.warningTitle,
+ value: 0,
+ handler: function (v) {
+ self.fireEvent(BI.Popover.EVENT_CONFIRM, v);
+ self.close(v);
+ }
+ }]
+ });
}
});
-BI.IconTextIconItem.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.icon_text_icon_item", BI.IconTextIconItem);/**
- * guy
- *
- * Created by GUY on 2015/9/9.
- * @class BI.IconTextItem
- * @extends BI.BasicButton
- */
-BI.IconTextItem = BI.inherit(BI.BasicButton, {
+BI.shortcut("bi.bar_popover", BI.BarPopover);
+
+BI.Popover.EVENT_CLOSE = "EVENT_CLOSE";
+BI.Popover.EVENT_OPEN = "EVENT_OPEN";
+BI.Popover.EVENT_CANCEL = "EVENT_CANCEL";
+BI.Popover.EVENT_CONFIRM = "EVENT_CONFIRM";
+/**
+ * 下拉框弹出层, zIndex在1000w
+ * @class BI.PopupView
+ * @extends BI.Widget
+ */
+BI.PopupView = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- var conf = BI.IconTextItem.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-icon-text-item",
- direction: BI.Direction.Left,
+ return BI.extend(BI.PopupView.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-popup-view",
+ maxWidth: "auto",
+ minWidth: 100,
+ // maxHeight: 200,
+ minHeight: 24,
+ lgap: 0,
+ rgap: 0,
+ tgap: 0,
+ bgap: 0,
+ vgap: 0,
+ hgap: 0,
+ innerVGap: 0,
+ direction: BI.Direction.Top, // 工具栏的方向
+ stopEvent: false, // 是否停止mousedown、mouseup事件
+ stopPropagation: false, // 是否停止mousedown、mouseup向上冒泡
logic: {
- dynamic: false
+ dynamic: true
},
- iconWrapperWidth: null,
- iconHeight: null,
- iconWidth: null,
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
+
+ tool: false, // 自定义工具栏
+ tabs: [], // 导航栏
+ buttons: [], // toolbar栏
+
+ el: {
+ type: "bi.button_group",
+ items: [],
+ chooseType: 0,
+ behaviors: {},
+ layouts: [{
+ type: "bi.vertical"
+ }]
+ }
});
},
+
_init: function () {
- BI.IconTextItem.superclass._init.apply(this, arguments);
- var o = this.options, c = this._const;
- this.text = BI.createWidget({
- type: "bi.label",
- cls: "list-item-text",
- textAlign: "left",
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- height: o.height
- });
- this.icon = BI.createWidget({
- type: "bi.icon_label",
- width: o.iconWrapperWidth || o.height,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
+ BI.PopupView.superclass._init.apply(this, arguments);
+ var self = this, o = this.options;
+ var fn = function (e) {
+ e.stopPropagation();
+ }, stop = function (e) {
+ e.stopEvent();
+ return false;
+ };
+ this.element.css({
+ "z-index": BI.zIndex_popup,
+ "min-width": o.minWidth + "px",
+ "max-width": o.maxWidth + "px"
+ }).bind({click: fn});
+
+ this.element.bind("mousewheel", fn);
+
+ o.stopPropagation && this.element.bind({mousedown: fn, mouseup: fn, mouseover: fn});
+ o.stopEvent && this.element.bind({mousedown: stop, mouseup: stop, mouseover: stop});
+ this.tool = this._createTool();
+ this.tab = this._createTab();
+ this.view = this._createView();
+ this.toolbar = this._createToolBar();
+
+ this.button_group.on(BI.Controller.EVENT_CHANGE, function (type) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ if (type === BI.Events.CLICK) {
+ self.fireEvent(BI.PopupView.EVENT_CHANGE);
+ }
});
BI.createWidget(BI.extend({
element: this
- }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend(o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.icon, this.text)
+ }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
+ scrolly: false,
+ lgap: o.lgap,
+ rgap: o.rgap,
+ tgap: o.tgap,
+ bgap: o.bgap,
+ vgap: o.vgap,
+ hgap: o.hgap,
+ items: BI.LogicFactory.createLogicItemsByDirection(o.direction,
+ BI.extend({
+ cls: "list-view-outer bi-card list-view-shadow"
+ }, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({}, o.logic, {
+ items: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.tool, this.tab, this.view, this.toolbar)
+ })))
+ )
}))));
},
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
+ _createView: function () {
+ var o = this.options;
+ this.button_group = BI.createWidget(o.el, {type: "bi.button_group", value: o.value});
+ this.button_group.element.css({"min-height": o.minHeight + "px", "padding-top": o.innerVGap + "px", "padding-bottom": o.innerVGap + "px"});
+ return this.button_group;
+ },
+
+ _createTool: function () {
+ var o = this.options;
+ if (false === o.tool) {
+ return;
}
+ return BI.createWidget(o.tool);
},
- getValue: function () {
- return this.text.getValue();
+ _createTab: function () {
+ var o = this.options;
+ if (o.tabs.length === 0) {
+ return;
+ }
+ return BI.createWidget({
+ type: "bi.center",
+ cls: "list-view-tab",
+ height: 25,
+ items: o.tabs,
+ value: o.value
+ });
},
- setText: function () {
- this.text.setText.apply(this.text, arguments);
+ _createToolBar: function () {
+ var o = this.options;
+ if (o.buttons.length === 0) {
+ return;
+ }
+
+ return BI.createWidget({
+ type: "bi.center",
+ cls: "list-view-toolbar bi-high-light bi-split-top",
+ height: 24,
+ items: BI.createItems(o.buttons, {
+ once: false,
+ shadow: true,
+ isShadowShowingOnSelected: true
+ })
+ });
},
- getText: function () {
- return this.text.getText();
+ getView: function () {
+ return this.button_group;
},
- doClick: function () {
- BI.IconTextItem.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.IconTextItem.EVENT_CHANGE, this.getValue(), this);
- }
+ populate: function (items) {
+ this.button_group.populate.apply(this.button_group, arguments);
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ resetWidth: function (w) {
+ this.options.width = w;
+ this.element.width(w);
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
+ resetHeight: function (h) {
+ var tbHeight = this.toolbar ? (this.toolbar.attr("height") || 24) : 0,
+ tabHeight = this.tab ? (this.tab.attr("height") || 24) : 0,
+ toolHeight = ((this.tool && this.tool.attr("height")) || 24) * ((this.tool && this.tool.isVisible()) ? 1 : 0);
+ var resetHeight = h - tbHeight - tabHeight - toolHeight - 2 * this.options.innerVGap - 2;
+ this.view.resetHeight ? this.view.resetHeight(resetHeight) :
+ this.view.element.css({"max-height": resetHeight + "px"});
},
- doHighLight: function () {
- this.text.doHighLight.apply(this.text, arguments);
+ setValue: function (selectedValues) {
+ this.tab && this.tab.setValue(selectedValues);
+ this.button_group.setValue(selectedValues);
},
- unHighLight: function () {
- this.text.unHighLight.apply(this.text, arguments);
+ getValue: function () {
+ return this.button_group.getValue();
}
});
-BI.IconTextItem.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.icon_text_item", BI.IconTextItem);/**
- *
- * 图标的button
+BI.PopupView.EVENT_CHANGE = "EVENT_CHANGE";
+BI.shortcut("bi.popup_view", BI.PopupView);/**
+ * 搜索面板
*
- * Created by GUY on 2015/9/9.
- * @class BI.TextIconItem
- * @extends BI.BasicButton
+ * Created by GUY on 2015/9/28.
+ * @class BI.SearcherView
+ * @extends BI.Pane
*/
-BI.TextIconItem = BI.inherit(BI.BasicButton, {
+BI.SearcherView = BI.inherit(BI.Pane, {
_defaultConfig: function () {
- var conf = BI.TextIconItem.superclass._defaultConfig.apply(this, arguments);
+ var conf = BI.SearcherView.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-text-icon-item",
- logic: {
- dynamic: false
+ baseCls: (conf.baseCls || "") + " bi-searcher-view bi-card",
+ tipText: BI.i18nText("BI-No_Select"),
+ chooseType: BI.Selection.Single,
+
+ matcher: {// 完全匹配的构造器
+ type: "bi.button_group",
+ behaviors: {
+ redmark: function () {
+ return true;
+ }
+ },
+ items: [],
+ layouts: [{
+ type: "bi.vertical"
+ }]
},
- cls: "close-ha-font",
- iconHeight: null,
- iconWidth: null,
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
+ searcher: {
+ type: "bi.button_group",
+ behaviors: {
+ redmark: function () {
+ return true;
+ }
+ },
+ items: [],
+ layouts: [{
+ type: "bi.vertical"
+ }]
+ }
});
},
+
_init: function () {
- BI.TextIconItem.superclass._init.apply(this, arguments);
- var o = this.options, c = this._const;
- this.text = BI.createWidget({
- type: "bi.label",
- cls: "list-item-text",
- textAlign: "left",
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- height: o.height
+ BI.SearcherView.superclass._init.apply(this, arguments);
+ var self = this, o = this.options;
+
+ this.matcher = BI.createWidget(o.matcher, {
+ type: "bi.button_group",
+ chooseType: o.chooseType,
+ behaviors: {
+ redmark: function () {
+ return true;
+ }
+ },
+ layouts: [{
+ type: "bi.vertical"
+ }],
+ value: o.value
});
- this.icon = BI.createWidget({
- type: "bi.icon_label",
- width: o.height,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
+ this.matcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ if (type === BI.Events.CLICK) {
+ self.fireEvent(BI.SearcherView.EVENT_CHANGE, val, ob);
+ }
+ });
+ this.spliter = BI.createWidget({
+ type: "bi.vertical",
+ height: 1,
+ hgap: 10,
+ items: [{
+ type: "bi.layout",
+ height: 1,
+ cls: "searcher-view-spliter bi-background"
+ }]
+ });
+ this.searcher = BI.createWidget(o.searcher, {
+ type: "bi.button_group",
+ chooseType: o.chooseType,
+ behaviors: {
+ redmark: function () {
+ return true;
+ }
+ },
+ layouts: [{
+ type: "bi.vertical"
+ }],
+ value: o.value
+ });
+ this.searcher.on(BI.Controller.EVENT_CHANGE, function (type, val, ob) {
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
+ if (type === BI.Events.CLICK) {
+ self.fireEvent(BI.SearcherView.EVENT_CHANGE, val, ob);
+ }
+ });
+
+ BI.createWidget({
+ type: "bi.vertical",
+ element: this,
+ items: [this.matcher, this.spliter, this.searcher]
});
-
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection("left", this.text, this.icon)
- }))));
- },
-
- doClick: function () {
- BI.TextIconItem.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.TextIconItem.EVENT_CHANGE, this.getValue(), this);
- }
- },
-
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
- }
- },
-
- getValue: function () {
- return this.text.getValue();
},
- setText: function () {
- this.text.setText.apply(this.text, arguments);
+ startSearch: function () {
+
},
- getText: function () {
- return this.text.getText();
+ stopSearch: function () {
+
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ setValue: function (v) {
+ this.matcher.setValue(v);
+ this.searcher.setValue(v);
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
+ getValue: function () {
+ return this.matcher.getValue().concat(this.searcher.getValue());
},
- doHighLight: function () {
- this.text.doHighLight.apply(this.text, arguments);
+ populate: function (searchResult, matchResult, keyword) {
+ searchResult || (searchResult = []);
+ matchResult || (matchResult = []);
+ this.setTipVisible(searchResult.length + matchResult.length === 0);
+ this.spliter.setVisible(BI.isNotEmptyArray(matchResult) && BI.isNotEmptyArray(searchResult));
+ this.matcher.populate(matchResult, keyword);
+ this.searcher.populate(searchResult, keyword);
},
- unHighLight: function () {
- this.text.unHighLight.apply(this.text, arguments);
+ empty: function () {
+ this.searcher.empty();
+ this.matcher.empty();
+ },
+
+ hasMatched: function () {
+ return this.matcher.getAllButtons().length > 0;
}
});
-BI.TextIconItem.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.text_icon_item", BI.TextIconItem);/**
- * guy
- * 一个button和一行数 组成的一行listitem
+BI.SearcherView.EVENT_CHANGE = "EVENT_CHANGE";
+
+BI.shortcut("bi.searcher_view", BI.SearcherView);/**
+ * 表示当前对象
*
- * Created by GUY on 2015/9/9.
- * @class BI.TextItem
- * @extends BI.BasicButton
+ * Created by GUY on 2017/5/23.
+ * @class BI.ListView
+ * @extends BI.Widget
*/
-BI.TextItem = BI.inherit(BI.BasicButton, {
-
- _defaultConfig: function () {
- var conf = BI.TextItem.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-text-item",
- textAlign: "left",
- whiteSpace: "nowrap",
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
- });
- },
- _init: function () {
- BI.TextItem.superclass._init.apply(this, arguments);
- var o = this.options;
- this.text = BI.createWidget({
- type: "bi.label",
- element: this,
- textAlign: o.textAlign,
- whiteSpace: o.whiteSpace,
- textHeight: o.whiteSpace == "nowrap" ? o.height : o.textHeight,
- height: o.height,
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- py: o.py
- });
+BI.ListView = BI.inherit(BI.Widget, {
+ props: function () {
+ return {
+ baseCls: "bi-list-view",
+ overscanHeight: 100,
+ blockSize: 10,
+ scrollTop: 0,
+ el: {},
+ items: []
+ };
},
- doClick: function () {
- BI.TextItem.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.TextItem.EVENT_CHANGE, this.getValue(), this);
- }
+ init: function () {
+ var self = this;
+ this.renderedIndex = -1;
+ this.cache = {};
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ render: function () {
+ var self = this, o = this.options;
+ return {
+ type: "bi.vertical",
+ items: [BI.extend({
+ type: "bi.vertical",
+ scrolly: false,
+ ref: function () {
+ self.container = this;
+ }
+ }, o.el)],
+ element: this
+ };
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
+ mounted: function () {
+ var self = this, o = this.options;
+ this._populate();
+ this.element.scroll(function (e) {
+ o.scrollTop = self.element.scrollTop();
+ self._calculateBlocksToRender();
+ });
+ BI.ResizeDetector.addResizeListener(this, function () {
+ self._calculateBlocksToRender();
+ });
},
- doHighLight: function () {
- this.text.doHighLight.apply(this.text, arguments);
+ _renderMoreIf: function () {
+ var self = this, o = this.options;
+ var height = this.element.height();
+ var minContentHeight = o.scrollTop + height + o.overscanHeight;
+ var index = (this.cache[this.renderedIndex] && (this.cache[this.renderedIndex].index + o.blockSize)) || 0,
+ cnt = this.renderedIndex + 1;
+ var lastHeight;
+ var getElementHeight = function () {
+ return self.container.element.height();
+ };
+ while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
+ var items = o.items.slice(index, index + o.blockSize);
+ this.container.addItems(items);
+ var addedHeight = getElementHeight() - lastHeight;
+ this.cache[cnt] = {
+ index: index,
+ scrollTop: lastHeight,
+ height: addedHeight
+ };
+ this.renderedIndex = cnt;
+ cnt++;
+ index += o.blockSize;
+ }
},
- unHighLight: function () {
- this.text.unHighLight.apply(this.text, arguments);
+ _calculateBlocksToRender: function () {
+ var o = this.options;
+ this._renderMoreIf();
},
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
+ _populate: function (items) {
+ var o = this.options;
+ if (items && this.options.items !== items) {
+ this.options.items = items;
}
+ this._calculateBlocksToRender();
+ this.element.scrollTop(o.scrollTop);
},
- getValue: function () {
- return this.text.getValue();
+ restore: function () {
+ this.renderedIndex = -1;
+ this.container.empty();
+ this.cache = {};
},
- setText: function () {
- this.text.setText.apply(this.text, arguments);
+ populate: function (items) {
+ if (items && this.options.items !== items) {
+ this.restore();
+ }
+ this._populate(items);
},
- getText: function () {
- return this.text.getText();
+ destroyed: function () {
+ this.restore();
}
});
-BI.TextItem.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.text_item", BI.TextItem);/**
- * guy
- * Created by GUY on 2015/9/9.
- * @class BI.IconTextIconNode
- * @extends BI.NodeButton
+BI.shortcut("bi.list_view", BI.ListView);
+
+/**
+ * 表示当前对象
+ *
+ * Created by GUY on 2017/5/22.
+ * @class BI.VirtualList
+ * @extends BI.Widget
*/
-BI.IconTextIconNode = BI.inherit(BI.NodeButton, {
+BI.VirtualList = BI.inherit(BI.Widget, {
+ props: function () {
+ return {
+ baseCls: "bi-virtual-list",
+ overscanHeight: 100,
+ blockSize: 10,
+ scrollTop: 0,
+ items: []
+ };
+ },
- _defaultConfig: function () {
- var conf = BI.IconTextIconNode.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-icon-text-icon-node",
- logic: {
- dynamic: false
- },
- iconCls1: "close-ha-font",
- iconCls2: "close-ha-font",
- iconHeight: null,
- iconWidth: null,
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
- });
+ init: function () {
+ var self = this;
+ this.renderedIndex = -1;
+ this.cache = {};
},
- _init: function () {
- BI.IconTextIconNode.superclass._init.apply(this, arguments);
- var o = this.options, c = this._const;
- this.text = BI.createWidget({
- type: "bi.label",
- textAlign: "left",
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- height: o.height
- });
- var icon1 = BI.createWidget({
- type: "bi.icon_label",
- cls: o.iconCls1,
- width: o.height,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
- });
- var blank = BI.createWidget({
- type: "bi.layout",
- width: o.height,
- height: o.height
- });
- BI.createWidget({
- type: "bi.absolute",
- element: this,
+ render: function () {
+ var self = this, o = this.options;
+ return {
+ type: "bi.vertical",
items: [{
- el: {
- type: "bi.icon_label",
- cls: o.iconCls2,
- width: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
- },
- top: 0,
- bottom: 0,
- right: 0
- }]
- });
-
- BI.createWidget(BI.extend({
+ type: "bi.layout",
+ ref: function () {
+ self.topBlank = this;
+ }
+ }, {
+ type: "bi.vertical",
+ scrolly: false,
+ ref: function () {
+ self.container = this;
+ }
+ }, {
+ type: "bi.layout",
+ ref: function () {
+ self.bottomBlank = this;
+ }
+ }],
element: this
- }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection("left", icon1, this.text, blank)
- }))));
+ };
},
- doClick: function () {
- BI.IconTextIconNode.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.IconTextIconNode.EVENT_CHANGE, this.getValue(), this);
- }
+ mounted: function () {
+ var self = this, o = this.options;
+ this._populate();
+ this.element.scroll(function (e) {
+ o.scrollTop = self.element.scrollTop();
+ self._calculateBlocksToRender();
+ });
+ BI.ResizeDetector.addResizeListener(this, function () {
+ self._calculateBlocksToRender();
+ });
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ _renderMoreIf: function () {
+ var self = this, o = this.options;
+ var height = this.element.height();
+ var minContentHeight = o.scrollTop + height + o.overscanHeight;
+ var index = (this.cache[this.renderedIndex] && (this.cache[this.renderedIndex].index + o.blockSize)) || 0,
+ cnt = this.renderedIndex + 1;
+ var lastHeight;
+ var getElementHeight = function () {
+ return self.container.element.height() + self.topBlank.element.height() + self.bottomBlank.element.height();
+ };
+ while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) {
+ var items = o.items.slice(index, index + o.blockSize);
+ this.container.addItems(items);
+ var addedHeight = getElementHeight() - lastHeight;
+ this.cache[cnt] = {
+ index: index,
+ scrollTop: lastHeight,
+ height: addedHeight
+ };
+ this.tree.set(cnt, addedHeight);
+ this.renderedIndex = cnt;
+ cnt++;
+ index += o.blockSize;
+ }
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
+ _calculateBlocksToRender: function () {
+ var o = this.options;
+ this._renderMoreIf();
+ var height = this.element.height();
+ var minContentHeightFrom = o.scrollTop - o.overscanHeight;
+ var minContentHeightTo = o.scrollTop + height + o.overscanHeight;
+ var start = this.tree.greatestLowerBound(minContentHeightFrom);
+ var end = this.tree.leastUpperBound(minContentHeightTo);
+ var needDestroyed = [];
+ for (var i = 0; i < start; i++) {
+ var index = this.cache[i].index;
+ if (!this.cache[i].destroyed) {
+ for (var j = index; j < index + o.blockSize && j < o.items.length; j++) {
+ needDestroyed.push(this.container._children[j]);
+ this.container._children[j] = null;
+ }
+ this.cache[i].destroyed = true;
+ }
+ }
+ for (var i = end + 1; i <= this.renderedIndex; i++) {
+ var index = this.cache[i].index;
+ if (!this.cache[i].destroyed) {
+ for (var j = index; j < index + o.blockSize && j < o.items.length; j++) {
+ needDestroyed.push(this.container._children[j]);
+ this.container._children[j] = null;
+ }
+ this.cache[i].destroyed = true;
+ }
+ }
+ var firstFragment = BI.Widget._renderEngine.createFragment(), lastFragment = BI.Widget._renderEngine.createFragment();
+ var currentFragment = firstFragment;
+ for (var i = (start < 0 ? 0 : start); i <= end && i <= this.renderedIndex; i++) {
+ var index = this.cache[i].index;
+ if (!this.cache[i].destroyed) {
+ currentFragment = lastFragment;
+ }
+ if (this.cache[i].destroyed === true) {
+ for (var j = index; j < index + o.blockSize && j < o.items.length; j++) {
+ var w = this.container._addElement(j, BI.extend({root: true}, BI.stripEL(o.items[j])));
+ currentFragment.appendChild(w.element[0]);
+ }
+ this.cache[i].destroyed = false;
+ }
+ }
+ this.container.element.prepend(firstFragment);
+ this.container.element.append(lastFragment);
+ this.topBlank.setHeight(this.cache[start < 0 ? 0 : start].scrollTop);
+ var lastCache = this.cache[Math.min(end, this.renderedIndex)];
+ this.bottomBlank.setHeight(this.tree.sumTo(this.renderedIndex) - lastCache.scrollTop - lastCache.height);
+ BI.each(needDestroyed, function (i, child) {
+ child && child._destroy();
+ });
},
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
+ _populate: function (items) {
+ var o = this.options;
+ if (items && this.options.items !== items) {
+ this.options.items = items;
}
+ this.tree = BI.PrefixIntervalTree.empty(Math.ceil(o.items.length / o.blockSize));
+ this._calculateBlocksToRender();
+ this.element.scrollTop(o.scrollTop);
},
- getValue: function () {
- return this.text.getValue();
+ _clearChildren: function () {
+ BI.each(this.container._children, function (i, cell) {
+ cell && cell.el._destroy();
+ });
+ this.container._children = {};
+ this.container.attr("items", []);
},
- setText: function () {
- this.text.setText.apply(this.text, arguments);
+ restore: function () {
+ this.renderedIndex = -1;
+ this._clearChildren();
+ this.cache = {};
+ this.options.scrollTop = 0;
},
- getText: function () {
- return this.text.getText();
+ populate: function (items) {
+ if (items && this.options.items !== items) {
+ this.restore();
+ }
+ this._populate();
+ },
+
+ destroyed: function () {
+ this.restore();
}
});
-BI.IconTextIconNode.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.icon_text_icon_node", BI.IconTextIconNode);/**
- * guy
- * Created by GUY on 2015/9/9.
- * @class BI.IconTextNode
- * @extends BI.NodeButton
- */
-BI.IconTextNode = BI.inherit(BI.NodeButton, {
+BI.shortcut("bi.virtual_list", BI.VirtualList);
+/**
+ * 分页控件
+ *
+ * Created by GUY on 2015/8/31.
+ * @class BI.Pager
+ * @extends BI.Widget
+ */
+BI.Pager = BI.inherit(BI.Widget, {
_defaultConfig: function () {
- var conf = BI.IconTextNode.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-icon-text-node",
- logic: {
- dynamic: false
- },
- cls: "close-ha-font",
- iconHeight: null,
- iconWidth: null,
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
- });
- },
- _init: function () {
- BI.IconTextNode.superclass._init.apply(this, arguments);
- var o = this.options, c = this._const;
- this.text = BI.createWidget({
- type: "bi.label",
- cls: "list-item-text",
- textAlign: "left",
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- height: o.height
- });
- this.icon = BI.createWidget({
- type: "bi.icon_label",
- width: o.height,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
- });
-
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection("left", this.icon, this.text)
- }))));
- },
-
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
- }
- },
-
- getValue: function () {
- return this.text.getValue();
- },
-
- setText: function () {
- this.text.setText.apply(this.text, arguments);
- },
-
- getText: function () {
- return this.text.getText();
- },
-
- doClick: function () {
- BI.IconTextNode.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.IconTextNode.EVENT_CHANGE, this.getValue(), this);
- }
- },
+ return BI.extend(BI.Pager.superclass._defaultConfig.apply(this, arguments), {
+ baseCls: "bi-pager",
+ behaviors: {},
+ layouts: [{
+ type: "bi.horizontal",
+ hgap: 10,
+ vgap: 0
+ }],
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
- },
+ dynamicShow: true, // 是否动态显示上一页、下一页、首页、尾页, 若为false,则指对其设置使能状态
+ // dynamicShow为false时以下两个有用
+ dynamicShowFirstLast: false, // 是否动态显示首页、尾页
+ dynamicShowPrevNext: false, // 是否动态显示上一页、下一页
+ pages: false, // 总页数
+ curr: function () {
+ return 1;
+ }, // 初始化当前页
+ groups: 0, // 连续显示分页数
+ jump: BI.emptyFn, // 分页的回调函数
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
- }
-});
-BI.IconTextNode.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.icon_text_node", BI.IconTextNode);/**
- * Created by GUY on 2015/9/9.
- * @class BI.TextIconNode
- * @extends BI.NodeButton
- */
-BI.TextIconNode = BI.inherit(BI.NodeButton, {
+ first: false, // 是否显示首页
+ last: false, // 是否显示尾页
+ prev: "上一页",
+ next: "下一页",
- _defaultConfig: function () {
- var conf = BI.TextIconNode.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-text-icon-node",
- logic: {
- dynamic: false
+ firstPage: 1,
+ lastPage: function () { // 在万不得已时才会调用这个函数获取最后一页的页码, 主要作用于setValue方法
+ return 1;
},
- cls: "close-ha-font",
- iconHeight: null,
- iconWidth: null,
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
+ hasPrev: BI.emptyFn, // pages不可用时有效
+ hasNext: BI.emptyFn // pages不可用时有效
});
},
_init: function () {
- BI.TextIconNode.superclass._init.apply(this, arguments);
- var o = this.options, c = this._const;
- this.text = BI.createWidget({
- type: "bi.label",
- cls: "list-item-text",
- textAlign: "left",
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- height: o.height
- });
- this.icon = BI.createWidget({
- type: "bi.icon_label",
- width: o.height,
- height: o.height,
- iconWidth: o.iconWidth,
- iconHeight: o.iconHeight
- });
-
- BI.createWidget(BI.extend({
- element: this
- }, BI.LogicFactory.createLogic("horizontal", BI.extend(o.logic, {
- items: BI.LogicFactory.createLogicItemsByDirection("left", this.text, this.icon)
- }))));
+ BI.Pager.superclass._init.apply(this, arguments);
+ var self = this;
+ this.currPage = BI.result(this.options, "curr");
+ // 翻页太灵敏
+ // this._lock = false;
+ // this._debouce = BI.debounce(function () {
+ // self._lock = false;
+ // }, 300);
+ this._populate();
},
- doClick: function () {
- BI.TextIconNode.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.TextIconNode.EVENT_CHANGE, this.getValue(), this);
- }
- },
+ _populate: function () {
+ var self = this, o = this.options, view = [], dict = {};
+ this.empty();
+ var pages = BI.result(o, "pages");
+ var curr = BI.result(this, "currPage");
+ var groups = BI.result(o, "groups");
+ var first = BI.result(o, "first");
+ var last = BI.result(o, "last");
+ var prev = BI.result(o, "prev");
+ var next = BI.result(o, "next");
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
+ if (pages === false) {
+ groups = 0;
+ first = false;
+ last = false;
+ } else {
+ groups > pages && (groups = pages);
}
- },
- getValue: function () {
- return this.text.getValue();
- },
+ // 计算当前组
+ dict.index = Math.ceil((curr + ((groups > 1 && groups !== pages) ? 1 : 0)) / (groups === 0 ? 1 : groups));
- setText: function () {
- this.text.setText.apply(this.text, arguments);
- },
+ // 当前页非首页,则输出上一页
+ if (((!o.dynamicShow && !o.dynamicShowPrevNext) || curr > 1) && prev !== false) {
+ if (BI.isKey(prev)) {
+ view.push({
+ text: prev,
+ value: "prev",
+ disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false)
+ });
+ } else {
+ view.push(BI.extend({
+ disabled: pages === false ? o.hasPrev(curr) === false : !(curr > 1 && prev !== false)
+ }, prev));
+ }
+ }
- getText: function () {
- return this.text.getText();
- },
+ // 当前组非首组,则输出首页
+ if (((!o.dynamicShow && !o.dynamicShowFirstLast) || (dict.index > 1 && groups !== 0)) && first) {
+ view.push({
+ text: first,
+ value: "first",
+ disabled: !(dict.index > 1 && groups !== 0)
+ });
+ if (dict.index > 1 && groups !== 0) {
+ view.push({
+ type: "bi.label",
+ cls: "page-ellipsis",
+ text: "\u2026"
+ });
+ }
+ }
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
- },
+ // 输出当前页组
+ dict.poor = Math.floor((groups - 1) / 2);
+ dict.start = dict.index > 1 ? curr - dict.poor : 1;
+ dict.end = dict.index > 1 ? (function () {
+ var max = curr + (groups - dict.poor - 1);
+ return max > pages ? pages : max;
+ }()) : groups;
+ if (dict.end - dict.start < groups - 1) { // 最后一组状态
+ dict.start = dict.end - groups + 1;
+ }
+ var s = dict.start, e = dict.end;
+ if (first && last && (dict.index > 1 && groups !== 0) && (pages > groups && dict.end < pages && groups !== 0)) {
+ s++;
+ e--;
+ }
+ for (; s <= e; s++) {
+ if (s === curr) {
+ view.push({
+ text: s,
+ value: s,
+ selected: true
+ });
+ } else {
+ view.push({
+ text: s,
+ value: s
+ });
+ }
+ }
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
- }
-});
-BI.TextIconNode.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.text_icon_node", BI.TextIconNode);/**
- * guy
- *
- * Created by GUY on 2015/9/9.
- * @class BI.TextNode
- * @extends BI.NodeButton
- */
-BI.TextNode = BI.inherit(BI.NodeButton, {
+ // 总页数大于连续分页数,且当前组最大页小于总页,输出尾页
+ if (((!o.dynamicShow && !o.dynamicShowFirstLast) || (pages > groups && dict.end < pages && groups !== 0)) && last) {
+ if (pages > groups && dict.end < pages && groups !== 0) {
+ view.push({
+ type: "bi.label",
+ cls: "page-ellipsis",
+ text: "\u2026"
+ });
+ }
+ view.push({
+ text: last,
+ value: "last",
+ disabled: !(pages > groups && dict.end < pages && groups !== 0)
+ });
+ }
- _defaultConfig: function () {
- var conf = BI.TextNode.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-text-node",
- textAlign: "left",
- whiteSpace: "nowrap",
- textHgap: 0,
- textVgap: 0,
- textLgap: 0,
- textRgap: 0
- });
- },
- _init: function () {
- BI.TextNode.superclass._init.apply(this, arguments);
- var o = this.options;
- this.text = BI.createWidget({
- type: "bi.label",
+ // 当前页不为尾页时,输出下一页
+ dict.flow = !prev && groups === 0;
+ if (((!o.dynamicShow && !o.dynamicShowPrevNext) && next) || (curr !== pages && next || dict.flow)) {
+ view.push((function () {
+ if (BI.isKey(next)) {
+ if (pages === false) {
+ return {text: next, value: "next", disabled: o.hasNext(curr) === false};
+ }
+ return (dict.flow && curr === pages)
+ ?
+ {text: next, value: "next", disabled: true}
+ :
+ {text: next, value: "next", disabled: !(curr !== pages && next || dict.flow)};
+ }
+ return BI.extend({
+ disabled: pages === false ? o.hasNext(curr) === false : !(curr !== pages && next || dict.flow)
+ }, next);
+
+ }()));
+ }
+
+ this.button_group = BI.createWidget({
+ type: "bi.button_group",
element: this,
- textAlign: o.textAlign,
- whiteSpace: o.whiteSpace,
- textHeight: o.whiteSpace == "nowrap" ? o.height : o.textHeight,
- height: o.height,
- hgap: o.textHgap,
- vgap: o.textVgap,
- lgap: o.textLgap,
- rgap: o.textRgap,
- text: o.text,
- value: o.value,
- keyword: o.keyword,
- py: o.py
+ items: BI.createItems(view, {
+ cls: "bi-list-item-select",
+ height: 23,
+ hgap: 10
+ }),
+ behaviors: o.behaviors,
+ layouts: o.layouts
+ });
+ this.button_group.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
+ // if (self._lock === true) {
+ // return;
+ // }
+ // self._lock = true;
+ // self._debouce();
+ if (type === BI.Events.CLICK) {
+ var v = self.button_group.getValue()[0];
+ switch (v) {
+ case "first":
+ self.currPage = 1;
+ break;
+ case "last":
+ self.currPage = pages;
+ break;
+ case "prev":
+ self.currPage--;
+ break;
+ case "next":
+ self.currPage++;
+ break;
+ default:
+ self.currPage = v;
+ break;
+ }
+ o.jump.apply(self, [{
+ pages: pages,
+ curr: self.currPage
+ }]);
+ self._populate();
+ self.fireEvent(BI.Pager.EVENT_CHANGE, obj);
+ }
+ self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
+ this.fireEvent(BI.Pager.EVENT_AFTER_POPULATE);
},
- doClick: function () {
- BI.TextNode.superclass.doClick.apply(this, arguments);
- if (this.isValid()) {
- this.fireEvent(BI.TextNode.EVENT_CHANGE, this.getValue(), this);
- }
+ getCurrentPage: function () {
+ return this.currPage;
},
- doRedMark: function () {
- this.text.doRedMark.apply(this.text, arguments);
+ setAllPages: function (pages) {
+ this.options.pages = pages;
},
- unRedMark: function () {
- this.text.unRedMark.apply(this.text, arguments);
+ hasPrev: function (v) {
+ v || (v = 1);
+ var o = this.options;
+ var pages = this.options.pages;
+ return pages === false ? o.hasPrev(v) : v > 1;
},
- setValue: function () {
- if (!this.isReadOnly()) {
- this.text.setValue.apply(this.text, arguments);
+ hasNext: function (v) {
+ v || (v = 1);
+ var o = this.options;
+ var pages = this.options.pages;
+ return pages === false ? o.hasNext(v) : v < pages;
+ },
+
+ setValue: function (v) {
+ var o = this.options;
+ v = v | 0;
+ v = v < 1 ? 1 : v;
+ if (o.pages === false) {
+ var lastPage = BI.result(o, "lastPage"), firstPage = 1;
+ this.currPage = v > lastPage ? lastPage : ((firstPage = BI.result(o, "firstPage")), (v < firstPage ? firstPage : v));
+ } else {
+ v = v > o.pages ? o.pages : v;
+ this.currPage = v;
}
+ this._populate();
},
getValue: function () {
- return this.text.getValue();
+ var val = this.button_group.getValue()[0];
+ switch (val) {
+ case "prev":
+ return -1;
+ case "next":
+ return 1;
+ case "first":
+ return BI.MIN;
+ case "last":
+ return BI.MAX;
+ default :
+ return val;
+ }
},
- setText: function () {
- this.text.setText.apply(this.text, arguments);
+ attr: function (key, value) {
+ BI.Pager.superclass.attr.apply(this, arguments);
+ if (key === "curr") {
+ this.currPage = BI.result(this.options, "curr");
+ }
},
- getText: function () {
- return this.text.getText();
+ populate: function () {
+ this._populate();
}
});
-BI.TextNode.EVENT_CHANGE = "EVENT_CHANGE";
-BI.shortcut("bi.text_node", BI.TextNode);/**
- * Created by GUY on 2015/4/15.
- * @class BI.Editor
- * @extends BI.Single
+BI.Pager.EVENT_CHANGE = "EVENT_CHANGE";
+BI.Pager.EVENT_AFTER_POPULATE = "EVENT_AFTER_POPULATE";
+BI.shortcut("bi.pager", BI.Pager);/**
+ * 超链接
+ *
+ * Created by GUY on 2015/9/9.
+ * @class BI.A
+ * @extends BI.Text
+ * @abstract
*/
-BI.Editor = BI.inherit(BI.Single, {
+BI.A = BI.inherit(BI.Text, {
_defaultConfig: function () {
- var conf = BI.Editor.superclass._defaultConfig.apply(this, arguments);
+ var conf = BI.A.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, {
- baseCls: "bi-editor bi-focus-shadow",
- hgap: 4,
- vgap: 2,
- lgap: 0,
- rgap: 0,
- tgap: 0,
- bgap: 0,
- // title,warningTitle这两个属性没用
- tipType: "warning",
- inputType: "text",
- validationChecker: BI.emptyFn,
- quitChecker: BI.emptyFn,
- allowBlank: false,
- watermark: "",
- errorText: ""
+ baseCls: (conf.baseCls || "") + " bi-a display-block",
+ href: "",
+ target: "_blank",
+ el: null,
+ tagName: "a"
});
},
+ _init: function () {
+ var o = this.options;
+ BI.A.superclass._init.apply(this, arguments);
+ this.element.attr({href: o.href, target: o.target});
+ if (o.el) {
+ BI.createWidget(o.el, {
+ element: this
+ });
+ }
+ }
+});
+BI.shortcut("bi.a", BI.A);/**
+ * guy
+ * 加载条
+ * @type {*|void|Object}
+ */
+BI.LoadingBar = BI.inherit(BI.Single, {
+ _defaultConfig: function () {
+ var conf = BI.LoadingBar.superclass._defaultConfig.apply(this, arguments);
+ return BI.extend( conf, {
+ baseCls: (conf.baseCls || "") + " bi-loading-bar bi-tips",
+ height: 30,
+ handler: BI.emptyFn
+ });
+ },
_init: function () {
- BI.Editor.superclass._init.apply(this, arguments);
- var self = this, o = this.options;
- this.editor = this.addWidget(BI.createWidget({
- type: "bi.input",
- element: "
",
- root: true,
- value: o.value,
- watermark: o.watermark,
- validationChecker: o.validationChecker,
- quitChecker: o.quitChecker,
- allowBlank: o.allowBlank
- }));
- this.editor.element.css({
- width: "100%",
- height: "100%",
- border: "none",
- outline: "none",
- padding: "0",
- margin: "0"
+ BI.LoadingBar.superclass._init.apply(this, arguments);
+ var self = this;
+ this.loaded = BI.createWidget({
+ type: "bi.text_button",
+ cls: "loading-text bi-list-item-simple",
+ text: BI.i18nText("BI-Load_More"),
+ width: 120,
+ handler: this.options.handler
});
- if (BI.isKey(this.options.watermark)) {
- this.watermark = BI.createWidget({
- type: "bi.label",
- cls: "bi-water-mark",
- text: this.options.watermark,
- forceCenter: true,
- height: o.height - 2 * (o.vgap + o.tgap),
- whiteSpace: "nowrap",
- textAlign: "left"
- });
- this.watermark.element.bind({
- mousedown: function (e) {
- if (self.isEnabled()) {
- self.editor.isEditing() || self.editor.focus();
- } else {
- self.editor.isEditing() && self.editor.blur();
- }
- e.stopEvent();
- }
- });
- this.watermark.element.bind("click", function (e) {
- if (self.isEnabled()) {
- self.editor.isEditing() || self.editor.focus();
- } else {
- self.editor.isEditing() && self.editor.blur();
- }
- e.stopEvent();
- });
- this.watermark.element.css({
- position: "absolute",
- left: "3px",
- right: "3px",
- top: "0px",
- bottom: "0px"
- });
- }
- var items = [{
- el: {
- type: "bi.default",
- items: this.watermark ? [this.editor, this.watermark] : [this.editor]
- },
- left: o.hgap + o.lgap,
- right: o.hgap + o.rgap,
- top: o.vgap + o.tgap,
- bottom: o.vgap + o.bgap
- }];
-
- BI.createWidget({
- type: "bi.absolute",
- element: this,
- items: items
- });
- this.editor.on(BI.Controller.EVENT_CHANGE, function () {
+ this.loaded.on(BI.Controller.EVENT_CHANGE, function (type) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
- this.editor.on(BI.Input.EVENT_FOCUS, function () {
- self._checkError();
- self.element.addClass("bi-editor-focus");
- self.fireEvent(BI.Editor.EVENT_FOCUS, arguments);
- });
- this.editor.on(BI.Input.EVENT_BLUR, function () {
- self._setErrorVisible(false);
- self.element.removeClass("bi-editor-focus");
- self.fireEvent(BI.Editor.EVENT_BLUR, arguments);
- });
- this.editor.on(BI.Input.EVENT_CLICK, function () {
- self.fireEvent(BI.Editor.EVENT_CLICK, arguments);
- });
- this.editor.on(BI.Input.EVENT_CHANGE, function () {
- self.fireEvent(BI.Editor.EVENT_CHANGE, arguments);
- });
- this.editor.on(BI.Input.EVENT_KEY_DOWN, function (v) {
- self.fireEvent(BI.Editor.EVENT_KEY_DOWN, arguments);
- });
- this.editor.on(BI.Input.EVENT_QUICK_DOWN, function (v) {
- self.watermark && self.watermark.invisible();
- });
- this.editor.on(BI.Input.EVENT_VALID, function () {
- self._checkWaterMark();
- 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());
- });
- this.editor.on(BI.Input.EVENT_RESTRICT, function () {
- self._checkWaterMark();
- var tip = self._setErrorVisible(true);
- tip && tip.element.fadeOut(100, function () {
- tip.element.fadeIn(100);
- });
- self.fireEvent(BI.Editor.EVENT_RESTRICT, arguments);
- });
- this.editor.on(BI.Input.EVENT_EMPTY, function () {
- self._checkWaterMark();
- self.fireEvent(BI.Editor.EVENT_EMPTY, arguments);
- });
- this.editor.on(BI.Input.EVENT_ENTER, function () {
- self.fireEvent(BI.Editor.EVENT_ENTER, arguments);
- });
- this.editor.on(BI.Input.EVENT_SPACE, function () {
- self.fireEvent(BI.Editor.EVENT_SPACE, arguments);
- });
- this.editor.on(BI.Input.EVENT_BACKSPACE, function () {
- self.fireEvent(BI.Editor.EVENT_BACKSPACE, arguments);
- });
- this.editor.on(BI.Input.EVENT_REMOVE, function () {
- self.fireEvent(BI.Editor.EVENT_REMOVE, arguments);
- });
- this.editor.on(BI.Input.EVENT_START, function () {
- self.fireEvent(BI.Editor.EVENT_START, arguments);
- });
- this.editor.on(BI.Input.EVENT_PAUSE, function () {
- self.fireEvent(BI.Editor.EVENT_PAUSE, arguments);
+ this.loading = BI.createWidget({
+ type: "bi.layout",
+ width: this.options.height,
+ height: this.options.height,
+ cls: "loading-background cursor-default"
});
- this.editor.on(BI.Input.EVENT_STOP, function () {
- self.fireEvent(BI.Editor.EVENT_STOP, arguments);
+ var loaded = BI.createWidget({
+ type: "bi.center_adapt",
+ items: [this.loaded]
});
- this.editor.on(BI.Input.EVENT_CONFIRM, function () {
- self.fireEvent(BI.Editor.EVENT_CONFIRM, arguments);
+ var loading = BI.createWidget({
+ type: "bi.center_adapt",
+ items: [this.loading]
});
- this.element.click(function (e) {
- e.stopPropagation();
- return false;
+ this.cardLayout = BI.createWidget({
+ type: "bi.card",
+ element: this,
+ items: [{
+ el: loaded,
+ cardName: "loaded"
+ }, {
+ el: loading,
+ cardName: "loading"
+ }]
});
- if (BI.isKey(this.options.value) || BI.isEmptyString(this.options.value)) {
- this._checkError();
- this._checkWaterMark();
- } else {
- this._checkWaterMark();
- }
+ this.invisible();
},
- _checkToolTip: function () {
- var o = this.options;
- var errorText = o.errorText;
- if (BI.isFunction(errorText)) {
- errorText = errorText(this.editor.getValue());
- }
- if (BI.isKey(errorText)) {
- if (!this.isEnabled() || this.isValid() || (BI.Bubbles.has(this.getName()) && BI.Bubbles.get(this.getName()).isVisible())) {
- this.setTitle("");
- } else {
- this.setTitle(errorText);
- }
- }
+ _reset: function () {
+ this.visible();
+ this.loaded.setText(BI.i18nText("BI-Load_More"));
+ this.loaded.enable();
},
- _checkError: function () {
- this._setErrorVisible(this.isEnabled() && !this.isValid());
- this._checkToolTip();
+ setLoaded: function () {
+ this._reset();
+ this.cardLayout.showCardByName("loaded");
},
- _checkWaterMark: function () {
- var o = this.options;
- if (!this.disabledWaterMark && this.editor.getValue() === "" && BI.isKey(o.watermark)) {
- this.watermark && this.watermark.visible();
- } else {
- this.watermark && this.watermark.invisible();
- }
+ setEnd: function () {
+ this.setLoaded();
+ this.loaded.setText(BI.i18nText("BI-No_More_Data"));
+ this.loaded.disable();
},
- setErrorText: function (text) {
- this.options.errorText = text;
- },
+ setLoading: function () {
+ this._reset();
+ this.cardLayout.showCardByName("loading");
+ }
+});
- getErrorText: function () {
- return this.options.errorText;
+BI.shortcut("bi.loading_bar", BI.LoadingBar);/**
+ * @class BI.IconButton
+ * @extends BI.BasicButton
+ * 图标的button
+ */
+BI.IconButton = BI.inherit(BI.BasicButton, {
+ _defaultConfig: function () {
+ var conf = BI.IconButton.superclass._defaultConfig.apply(this, arguments);
+ return BI.extend(conf, {
+ baseCls: (conf.baseCls || "") + " bi-icon-button horizon-center",
+ iconWidth: null,
+ iconHeight: null
+ });
},
- _setErrorVisible: function (b) {
+ _init: function () {
+ BI.IconButton.superclass._init.apply(this, arguments);
var o = this.options;
- var errorText = o.errorText;
- if (BI.isFunction(errorText)) {
- errorText = errorText(this.editor.getValue());
- }
- if (!this.disabledError && BI.isKey(errorText)) {
- BI.Bubbles[b ? "show" : "hide"](this.getName(), errorText, this, {
- adjustYOffset: 2
+ this.element.css({
+ textAlign: "center"
+ });
+ this.icon = BI.createWidget({
+ type: "bi.icon",
+ width: o.iconWidth,
+ height: o.iconHeight
+ });
+ if (BI.isNumber(o.height) && o.height > 0 && BI.isNull(o.iconWidth) && BI.isNull(o.iconHeight)) {
+ this.element.css("lineHeight", o.height + "px");
+ BI.createWidget({
+ type: "bi.default",
+ element: this,
+ items: [this.icon]
+ });
+ } else {
+ this.element.css("lineHeight", "1");
+ BI.createWidget({
+ element: this,
+ type: "bi.center_adapt",
+ items: [this.icon]
});
- this._checkToolTip();
- return BI.Bubbles.get(this.getName());
}
},
- disableError: function () {
- this.disabledError = true;
- this._checkError();
- },
-
- enableError: function () {
- this.disabledError = false;
- this._checkError();
- },
-
- disableWaterMark: function () {
- this.disabledWaterMark = true;
- this._checkWaterMark();
- },
-
- enableWaterMark: function () {
- this.disabledWaterMark = false;
- this._checkWaterMark();
- },
-
- focus: function () {
- this.element.addClass("text-editor-focus");
- this.editor.focus();
- },
-
- blur: function () {
- this.element.removeClass("text-editor-focus");
- this.editor.blur();
- },
-
- selectAll: function () {
- this.editor.selectAll();
- },
-
- onKeyDown: function (k) {
- this.editor.onKeyDown(k);
- },
-
- setValue: function (v) {
- BI.Editor.superclass.setValue.apply(this, arguments);
- this.editor.setValue(v);
- this._checkError();
- this._checkWaterMark();
- },
-
- getLastValidValue: function () {
- return this.editor.getLastValidValue();
- },
-
- resetLastValidValue: function () {
- this.editor.resetLastValidValue();
- },
-
- getValue: function () {
- if (!this.isValid()) {
- return BI.trim(this.editor.getLastValidValue());
+ doClick: function () {
+ BI.IconButton.superclass.doClick.apply(this, arguments);
+ if (this.isValid()) {
+ this.fireEvent(BI.IconButton.EVENT_CHANGE, this);
}
- return BI.trim(this.editor.getValue());
- },
-
- isEditing: function () {
- return this.editor.isEditing();
- },
-
- isValid: function () {
- return this.editor.isValid();
- },
-
- destroyed: function () {
- BI.Bubbles.remove(this.getName());
}
});
-BI.Editor.EVENT_CHANGE = "EVENT_CHANGE";
-BI.Editor.EVENT_FOCUS = "EVENT_FOCUS";
-BI.Editor.EVENT_BLUR = "EVENT_BLUR";
-BI.Editor.EVENT_CLICK = "EVENT_CLICK";
-BI.Editor.EVENT_KEY_DOWN = "EVENT_KEY_DOWN";
-BI.Editor.EVENT_SPACE = "EVENT_SPACE";
-BI.Editor.EVENT_BACKSPACE = "EVENT_BACKSPACE";
-
-BI.Editor.EVENT_START = "EVENT_START";
-BI.Editor.EVENT_PAUSE = "EVENT_PAUSE";
-BI.Editor.EVENT_STOP = "EVENT_STOP";
-BI.Editor.EVENT_CONFIRM = "EVENT_CONFIRM";
-BI.Editor.EVENT_VALID = "EVENT_VALID";
-BI.Editor.EVENT_ERROR = "EVENT_ERROR";
-BI.Editor.EVENT_ENTER = "EVENT_ENTER";
-BI.Editor.EVENT_RESTRICT = "EVENT_RESTRICT";
-BI.Editor.EVENT_REMOVE = "EVENT_REMOVE";
-BI.Editor.EVENT_EMPTY = "EVENT_EMPTY";
-
-BI.shortcut("bi.editor", BI.Editor);/**
- * 多文件
+BI.IconButton.EVENT_CHANGE = "IconButton.EVENT_CHANGE";
+BI.shortcut("bi.icon_button", BI.IconButton);/**
+ * 图片的button
*
- * Created by GUY on 2016/4/13.
- * @class BI.MultifileEditor
- * @extends BI.Single
- * @abstract
+ * Created by GUY on 2016/1/27.
+ * @class BI.ImageButton
+ * @extends BI.BasicButton
*/
-BI.MultifileEditor = BI.inherit(BI.Widget, {
+BI.ImageButton = BI.inherit(BI.BasicButton, {
_defaultConfig: function () {
- var conf = BI.MultifileEditor.superclass._defaultConfig.apply(this, arguments);
+ var conf = BI.ImageButton.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-multifile-editor",
- multiple: false,
- maxSize: -1, // 1024 * 1024
- accept: "",
- url: ""
+ baseCls: (conf.baseCls || "") + " bi-image-button",
+ src: "",
+ iconWidth: "100%",
+ iconHeight: "100%"
});
},
_init: function () {
- var self = this, o = this.options;
- BI.MultifileEditor.superclass._init.apply(this, arguments);
- this.file = BI.createWidget({
- type: "bi.file",
- cls: "multifile-editor",
- width: "100%",
- height: "100%",
- name: o.name,
- url: o.url,
- multiple: o.multiple,
- accept: o.accept,
- maxSize: o.maxSize,
- title: o.title
- });
- this.file.on(BI.File.EVENT_CHANGE, function () {
- self.fireEvent(BI.MultifileEditor.EVENT_CHANGE, arguments);
- });
- this.file.on(BI.File.EVENT_UPLOADSTART, function () {
- self.fireEvent(BI.MultifileEditor.EVENT_UPLOADSTART, arguments);
- });
- this.file.on(BI.File.EVENT_ERROR, function () {
- self.fireEvent(BI.MultifileEditor.EVENT_ERROR, arguments);
- });
- this.file.on(BI.File.EVENT_PROGRESS, function () {
- self.fireEvent(BI.MultifileEditor.EVENT_PROGRESS, arguments);
- });
- this.file.on(BI.File.EVENT_UPLOADED, function () {
- self.fireEvent(BI.MultifileEditor.EVENT_UPLOADED, arguments);
+ BI.ImageButton.superclass._init.apply(this, arguments);
+ var o = this.options;
+ this.image = BI.createWidget({
+ type: "bi.img",
+ width: o.iconWidth,
+ height: o.iconHeight,
+ src: o.src
});
+ if (BI.isNumber(o.iconWidth) || BI.isNumber(o.iconHeight)) {
+ BI.createWidget({
+ type: "bi.center_adapt",
+ element: this,
+ items: [this.image]
+ });
+ } else {
+ BI.createWidget({
+ type: "bi.adaptive",
+ element: this,
+ items: [this.image],
+ scrollable: false
+ });
+ }
+ },
- BI.createWidget({
- type: "bi.absolute",
- element: this,
- items: [{
- el: {
- type: "bi.adaptive",
- scrollable: false,
- items: [this.file]
- },
- top: 0,
- right: 0,
- left: 0,
- bottom: 0
- }]
- });
+ setWidth: function (w) {
+ BI.ImageButton.superclass.setWidth.apply(this, arguments);
+ this.options.width = w;
},
- select: function () {
- this.file.select();
+ setHeight: function (h) {
+ BI.ImageButton.superclass.setHeight.apply(this, arguments);
+ this.options.height = h;
},
- getValue: function () {
- return this.file.getValue();
+ setImageWidth: function (w) {
+ this.image.setWidth(w);
},
- upload: function () {
- this.file.upload();
+ setImageHeight: function (h) {
+ this.image.setHeight(h);
},
- reset: function () {
- this.file.reset();
+ getImageWidth: function () {
+ return this.image.element.width();
+ },
+
+ getImageHeight: function () {
+ return this.image.element.height();
+ },
+
+ setSrc: function (src) {
+ this.options.src = src;
+ this.image.setSrc(src);
+ },
+
+ getSrc: function () {
+ return this.image.getSrc();
+ },
+
+ doClick: function () {
+ BI.ImageButton.superclass.doClick.apply(this, arguments);
+ if (this.isValid()) {
+ this.fireEvent(BI.ImageButton.EVENT_CHANGE, this);
+ }
}
});
-BI.MultifileEditor.EVENT_CHANGE = "MultifileEditor.EVENT_CHANGE";
-BI.MultifileEditor.EVENT_UPLOADSTART = "MultifileEditor.EVENT_UPLOADSTART";
-BI.MultifileEditor.EVENT_ERROR = "MultifileEditor.EVENT_ERROR";
-BI.MultifileEditor.EVENT_PROGRESS = "MultifileEditor.EVENT_PROGRESS";
-BI.MultifileEditor.EVENT_UPLOADED = "MultifileEditor.EVENT_UPLOADED";
-BI.shortcut("bi.multifile_editor", BI.MultifileEditor);/**
+BI.ImageButton.EVENT_CHANGE = "ImageButton.EVENT_CHANGE";
+BI.shortcut("bi.image_button", BI.ImageButton);
+/**
+ * 文字类型的按钮
+ * @class BI.Button
+ * @extends BI.BasicButton
*
- * Created by GUY on 2016/1/18.
- * @class BI.TextAreaEditor
- * @extends BI.Single
+ * @cfg {JSON} options 配置属性
+ * @cfg {'common'/'success'/'warning'/'ignore'} [options.level='common'] 按钮类型,用不同颜色强调不同的场景
*/
-BI.TextAreaEditor = BI.inherit(BI.Single, {
- _defaultConfig: function () {
- return $.extend(BI.TextAreaEditor.superclass._defaultConfig.apply(), {
- baseCls: "bi-textarea-editor",
- value: ""
+BI.Button = BI.inherit(BI.BasicButton, {
+
+ _defaultConfig: function (props) {
+ var conf = BI.Button.superclass._defaultConfig.apply(this, arguments);
+ return BI.extend(conf, {
+ baseCls: (conf.baseCls || "") + " bi-button",
+ minWidth: (props.block === true || props.clear === true) ? 0 : 80,
+ height: 24,
+ shadow: props.clear !== true,
+ isShadowShowingOnSelected: true,
+ readonly: true,
+ iconCls: "",
+ level: "common",
+ block: false, // 是否块状显示,即不显示边框,没有最小宽度的限制
+ clear: false, // 是否去掉边框和背景
+ ghost: false, // 是否幽灵显示, 即正常状态无背景
+ textAlign: "center",
+ whiteSpace: "nowrap",
+ forceCenter: false,
+ textWidth: null,
+ textHeight: null,
+ hgap: props.clear ? 0 : 10,
+ vgap: 0,
+ tgap: 0,
+ bgap: 0,
+ lgap: 0,
+ rgap: 0
});
},
+
_init: function () {
- BI.TextAreaEditor.superclass._init.apply(this, arguments);
+ BI.Button.superclass._init.apply(this, arguments);
var o = this.options, self = this;
- this.content = BI.createWidget({
- type: "bi.layout",
- tagName: "textarea",
- width: "100%",
- height: "100%",
- cls: "bi-textarea textarea-editor-content display-block"
- });
- this.content.element.css({resize: "none", whiteSpace: "normal"});
- BI.createWidget({
- type: "bi.absolute",
- element: this,
- items: [{
- el: {
- type: "bi.adaptive",
- items: [this.content]
- },
- left: 0,
- right: 3,
- top: 6,
- bottom: 5
- }]
- });
-
- this.content.element.on("input propertychange", function (e) {
- self._checkWaterMark();
- self.fireEvent(BI.TextAreaEditor.EVENT_CHANGE);
- });
-
- this.content.element.focus(function () {
- if (self.isValid()) {
- self._focus();
- self.fireEvent(BI.TextAreaEditor.EVENT_FOCUS);
- }
- BI.Widget._renderEngine.createElement(document).bind("mousedown." + self.getName(), function (e) {
- if (BI.DOM.isExist(self) && !self.element.__isMouseInBounds__(e)) {
- BI.Widget._renderEngine.createElement(document).unbind("mousedown." + self.getName());
- self.content.element.blur();
- }
+ if (BI.isNumber(o.height) && !o.clear && !o.block) {
+ this.element.css({height: o.height + "px", lineHeight: (o.height - 2) + "px"});
+ } else if (o.clear || o.block) {
+ this.element.css({lineHeight: o.height + "px"});
+ } else {
+ this.element.css({lineHeight: (o.height - 2) + "px"});
+ }
+ if (BI.isKey(o.iconCls)) {
+ this.icon = BI.createWidget({
+ type: "bi.icon",
+ width: 18,
+ height: o.height - 2
+ });
+ this.text = BI.createWidget({
+ type: "bi.label",
+ text: o.text,
+ value: o.value,
+ height: o.height - 2
+ });
+ BI.createWidget({
+ type: "bi.horizontal_auto",
+ cls: o.iconCls,
+ element: this,
+ hgap: o.hgap,
+ vgap: o.vgap,
+ tgap: o.tgap,
+ bgap: o.bgap,
+ lgap: o.lgap,
+ rgap: o.rgap,
+ items: [{
+ type: "bi.horizontal",
+ items: [this.icon, this.text]
+ }]
+ });
+ } else {
+ this.text = BI.createWidget({
+ type: "bi.label",
+ textAlign: o.textAlign,
+ whiteSpace: o.whiteSpace,
+ forceCenter: o.forceCenter,
+ textWidth: o.textWidth,
+ textHeight: o.textHeight,
+ hgap: o.hgap,
+ vgap: o.vgap,
+ tgap: o.tgap,
+ bgap: o.bgap,
+ lgap: o.lgap,
+ rgap: o.rgap,
+ element: this,
+ text: o.text,
+ value: o.value
});
- });
- this.content.element.blur(function () {
- if (self.isValid()) {
- self._blur();
- self.fireEvent(BI.TextAreaEditor.EVENT_BLUR);
- }
- BI.Widget._renderEngine.createElement(document).unbind("mousedown." + self.getName());
- });
- if (BI.isKey(o.value)) {
- self.setValue(o.value);
}
- if (BI.isNotNull(o.style)) {
- self.setStyle(o.style);
+ if (o.block === true) {
+ this.element.addClass("block");
}
- this._checkWaterMark();
- },
-
- _checkWaterMark: function () {
- var self = this, o = this.options;
- var val = this.getValue();
- if (BI.isNotEmptyString(val)) {
- this.watermark && this.watermark.destroy();
- this.watermark = null;
- } else {
- if (BI.isNotEmptyString(o.watermark)) {
- if (!this.watermark) {
- this.watermark = BI.createWidget({
- type: "bi.text_button",
- cls: "bi-water-mark",
- textAlign: "left",
- height: 30,
- text: o.watermark,
- invalid: o.invalid,
- disabled: o.disabled
- });
- this.watermark.on(BI.TextButton.EVENT_CHANGE, function () {
- self.focus();
- });
- BI.createWidget({
- type: "bi.absolute",
- element: this,
- items: [{
- el: this.watermark,
- left: 0,
- top: 0,
- right: 0
- }]
- });
- } else {
- this.watermark.setText(o.watermark);
- this.watermark.setValid(!o.invalid);
- this.watermark.setEnable(!o.disabled);
- }
- }
+ if (o.clear === true) {
+ this.element.addClass("clear");
+ }
+ if (o.ghost === true) {
+ this.element.addClass("ghost");
+ }
+ if (o.minWidth > 0) {
+ this.element.css({"min-width": o.minWidth + "px"});
}
},
- _focus: function () {
- this.content.element.addClass("textarea-editor-focus");
- this._checkWaterMark();
- },
-
- _blur: function () {
- this.content.element.removeClass("textarea-editor-focus");
- this._checkWaterMark();
+ doClick: function () {
+ BI.Button.superclass.doClick.apply(this, arguments);
+ if (this.isValid()) {
+ this.fireEvent(BI.Button.EVENT_CHANGE, this);
+ }
},
- focus: function () {
- this._focus();
- this.content.element.focus();
+ setText: function (text) {
+ BI.Button.superclass.setText.apply(this, arguments);
+ this.text.setText(text);
},
- blur: function () {
- this._blur();
- this.content.element.blur();
+ setValue: function (text) {
+ BI.Button.superclass.setValue.apply(this, arguments);
+ if (!this.isReadOnly()) {
+ this.text.setValue(text);
+ }
},
- getValue: function () {
- return this.content.element.val();
+ doRedMark: function () {
+ this.text.doRedMark.apply(this.text, arguments);
},
- setValue: function (value) {
- this.content.element.val(value);
- this._checkWaterMark();
+ unRedMark: function () {
+ this.text.unRedMark.apply(this.text, arguments);
},
- setStyle: function (style) {
- this.style = style;
- this.element.css(style);
- this.content.element.css(BI.extend({}, style, {
- color: style.color || BI.DOM.getContrastColor(BI.DOM.isRGBColor(style.backgroundColor) ? BI.DOM.rgb2hex(style.backgroundColor) : style.backgroundColor)
- }));
+ doHighLight: function () {
+ this.text.doHighLight.apply(this.text, arguments);
},
- getStyle: function () {
- return this.style;
+ unHighLight: function () {
+ this.text.unHighLight.apply(this.text, arguments);
},
- _setValid: function (b) {
- BI.TextAreaEditor.superclass._setValid.apply(this, arguments);
- // this.content.setValid(b);
- // this.watermark && this.watermark.setValid(b);
- }
-});
-BI.TextAreaEditor.EVENT_CHANGE = "EVENT_CHANGE";
-BI.TextAreaEditor.EVENT_BLUR = "EVENT_BLUR";
-BI.TextAreaEditor.EVENT_FOCUS = "EVENT_FOCUS";
-BI.shortcut("bi.textarea_editor", BI.TextAreaEditor);/**
- * guy 图标
- * @class BI.Icon
- * @extends BI.Single
- */
-BI.Icon = BI.inherit(BI.Single, {
- _defaultConfig: function () {
- var conf = BI.Icon.superclass._defaultConfig.apply(this, arguments);
- return BI.extend(conf, {
- tagName: "i",
- baseCls: (conf.baseCls || "") + " x-icon b-font horizon-center display-block"
- });
- },
- _init: function () {
- BI.Icon.superclass._init.apply(this, arguments);
- if (BI.isIE9Below && BI.isIE9Below()) {
- this.element.addClass("hack");
- }
+ destroy: function () {
+ BI.Button.superclass.destroy.apply(this, arguments);
}
});
-BI.shortcut("bi.icon", BI.Icon);/**
- * @class BI.Iframe
- * @extends BI.Single
- * @abstract
- * Created by GameJian on 2016/3/2.
+BI.shortcut("bi.button", BI.Button);
+BI.Button.EVENT_CHANGE = "EVENT_CHANGE";
+/**
+ * guy
+ * 可以点击的一行文字
+ * @class BI.TextButton
+ * @extends BI.BasicButton
+ * 文字button
*/
-BI.Iframe = BI.inherit(BI.Single, {
+BI.TextButton = BI.inherit(BI.BasicButton, {
_defaultConfig: function () {
- var conf = BI.Iframe.superclass._defaultConfig.apply(this, arguments);
+ var conf = BI.TextButton.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, {
- baseCls: (conf.baseCls || "") + " bi-iframe",
- src: "",
- width: "100%",
- height: "100%"
+ baseCls: (conf.baseCls || "") + " bi-text-button",
+ textAlign: "center",
+ whiteSpace: "nowrap",
+ forceCenter: false,
+ textWidth: null,
+ textHeight: null,
+ hgap: 0,
+ lgap: 0,
+ rgap: 0,
+ text: "",
+ py: ""
});
},
_init: function () {
+ BI.TextButton.superclass._init.apply(this, arguments);
var o = this.options;
- this.options.element = BI.Widget._renderEngine.createElement("