diff --git a/src/case/button/treeitem/item.first.treeleaf.js b/src/case/button/treeitem/item.first.treeleaf.js index 1a25b47e2..4db068ab8 100644 --- a/src/case/button/treeitem/item.first.treeleaf.js +++ b/src/case/button/treeitem/item.first.treeleaf.js @@ -45,7 +45,7 @@ BI.FirstTreeLeafItem = BI.inherit(BI.BasicButton, { width: 12, el: { type: "bi.layout", - cls: "base-line-conn-background", + cls: (o.pNode && o.pNode.isLastNode) ? "" : "base-line-conn-background", width: 12, height: o.height } diff --git a/src/case/button/treeitem/item.last.treeleaf.js b/src/case/button/treeitem/item.last.treeleaf.js index 718379be4..8f3f8e54a 100644 --- a/src/case/button/treeitem/item.last.treeleaf.js +++ b/src/case/button/treeitem/item.last.treeleaf.js @@ -45,7 +45,7 @@ BI.LastTreeLeafItem = BI.inherit(BI.BasicButton, { width: 12, el: { type: "bi.layout", - cls: "base-line-conn-background", + cls: (o.pNode && o.pNode.isLastNode) ? "" : "base-line-conn-background", width: 12, height: o.height } diff --git a/src/case/button/treeitem/item.mid.treeleaf.js b/src/case/button/treeitem/item.mid.treeleaf.js index d320d51c8..8b41612b0 100644 --- a/src/case/button/treeitem/item.mid.treeleaf.js +++ b/src/case/button/treeitem/item.mid.treeleaf.js @@ -45,7 +45,7 @@ BI.MidTreeLeafItem = BI.inherit(BI.BasicButton, { width: 12, el: { type: "bi.layout", - cls: "base-line-conn-background", + cls: (o.pNode && o.pNode.isLastNode) ? "" : "base-line-conn-background", width: 12, height: o.height } diff --git a/src/case/tree/tree.level.js b/src/case/tree/tree.level.js index eaf7274f3..1600a0d71 100644 --- a/src/case/tree/tree.level.js +++ b/src/case/tree/tree.level.js @@ -23,34 +23,35 @@ BI.LevelTree = BI.inherit(BI.Widget, { this.initTree(this.options.items); }, - _formatItems: function (nodes, layer) { + _formatItems: function (nodes, layer, pNode) { var self = this; BI.each(nodes, function (i, node) { var extend = {layer: layer}; if (!BI.isKey(node.id)) { node.id = BI.UUID(); } + extend.pNode = pNode; if (node.isParent === true || BI.isNotEmptyArray(node.children)) { - switch (i) { - case 0 : - extend.type = "bi.first_plus_group_node"; - break; - case nodes.length - 1 : - extend.type = "bi.last_plus_group_node"; - break; - default : - extend.type = "bi.mid_plus_group_node"; - break; + extend.type = "bi.mid_plus_group_node"; + if (i === nodes.length - 1) { + extend.type = "bi.last_plus_group_node"; + extend.isLastNode = true; + } + if (i === 0 && !pNode) { + extend.type = "bi.first_plus_group_node" + } + if (i === 0 && i === nodes.length - 1) { // 根 + extend.type = "bi.plus_group_node"; } BI.defaults(node, extend); - self._formatItems(node.children, layer + 1); + self._formatItems(node.children, layer + 1, node); } else { - switch (i) { - case nodes.length - 1: - extend.type = "bi.last_tree_leaf_item"; - break; - default : - extend.type = "bi.mid_tree_leaf_item"; + extend.type = "bi.mid_tree_leaf_item"; + if (i === 0 && !pNode) { + extend.type = "bi.first_tree_leaf_item" + } + if (i === nodes.length - 1) { + extend.type = "bi.last_tree_leaf_item"; } BI.defaults(node, extend); } diff --git a/src/widget/multilayerselecttree/multilayerselecttree.leveltree.js b/src/widget/multilayerselecttree/multilayerselecttree.leveltree.js index f81e9da7c..5f072737e 100644 --- a/src/widget/multilayerselecttree/multilayerselecttree.leveltree.js +++ b/src/widget/multilayerselecttree/multilayerselecttree.leveltree.js @@ -21,7 +21,7 @@ BI.MultiLayerSelectLevelTree = BI.inherit(BI.Widget, { this.initTree(this.options.items); }, - _formatItems: function (nodes, layer) { + _formatItems: function (nodes, layer, pNode) { var self = this; BI.each(nodes, function (i, node) { var extend = {}; @@ -29,28 +29,28 @@ BI.MultiLayerSelectLevelTree = BI.inherit(BI.Widget, { if (!BI.isKey(node.id)) { node.id = BI.UUID(); } + extend.pNode = pNode; if (node.isParent === true || BI.isNotEmptyArray(node.children)) { - switch (i) { - case 0 : - extend.type = "bi.multilayer_select_tree_first_plus_group_node"; - break; - case nodes.length - 1 : - extend.type = "bi.multilayer_select_tree_last_plus_group_node"; - break; - default : - extend.type = "bi.multilayer_select_tree_mid_plus_group_node"; - break; + extend.type = "bi.multilayer_select_tree_mid_plus_group_node"; + if (i === nodes.length - 1) { + extend.type = "bi.multilayer_select_tree_last_plus_group_node"; + extend.isLastNode = true; + } + if (i === 0 && !pNode) { + extend.type = "bi.multilayer_select_tree_first_plus_group_node" + } + if (i === 0 && i === nodes.length - 1 && !pNode) { // 根 + extend.type = "bi.multilayer_select_tree_plus_group_node"; } BI.defaults(node, extend); - - self._formatItems(node.children, layer + 1); + self._formatItems(node.children, layer + 1, node); } else { - switch (i) { - case nodes.length - 1: - extend.type = "bi.multilayer_single_tree_last_tree_leaf_item"; - break; - default : - extend.type = "bi.multilayer_single_tree_mid_tree_leaf_item"; + extend.type = "bi.multilayer_single_tree_mid_tree_leaf_item"; + if (i === 0 && !pNode) { + extend.type = "bi.multilayer_single_tree_first_tree_leaf_item" + } + if (i === nodes.length - 1) { + extend.type = "bi.multilayer_single_tree_last_tree_leaf_item"; } BI.defaults(node, extend); } diff --git a/src/widget/multilayerselecttree/node/node.first.plus.js b/src/widget/multilayerselecttree/node/node.first.plus.js index 43c35b861..aadd455c2 100644 --- a/src/widget/multilayerselecttree/node/node.first.plus.js +++ b/src/widget/multilayerselecttree/node/node.first.plus.js @@ -42,11 +42,20 @@ BI.MultiLayerSelectTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); + var needBlankLayers = []; + var pNode = o.pNode; + while (pNode) { + if (pNode.isLastNode) { + needBlankLayers.push(pNode.layer) + } + pNode = pNode.pNode; + } + var items = []; - BI.count(0, o.layer, function () { + BI.count(0, o.layer, function (index) { items.push({ type: "bi.layout", - cls: "base-line-conn-background", + cls: BI.contains(needBlankLayers, index) ? "" : "base-line-conn-background", width: 12, height: o.height }); diff --git a/src/widget/multilayerselecttree/node/node.last.plus.js b/src/widget/multilayerselecttree/node/node.last.plus.js index 0e7fff0d0..a48e14767 100644 --- a/src/widget/multilayerselecttree/node/node.last.plus.js +++ b/src/widget/multilayerselecttree/node/node.last.plus.js @@ -42,11 +42,20 @@ BI.MultiLayerSelectTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); + var needBlankLayers = []; + var pNode = o.pNode; + while (pNode) { + if (pNode.isLastNode) { + needBlankLayers.push(pNode.layer) + } + pNode = pNode.pNode; + } + var items = []; - BI.count(0, o.layer, function () { + BI.count(0, o.layer, function (index) { items.push({ type: "bi.layout", - cls: "base-line-conn-background", + cls: BI.contains(needBlankLayers, index) ? "" : "base-line-conn-background", width: 12, height: o.height }); diff --git a/src/widget/multilayerselecttree/node/node.mid.plus.js b/src/widget/multilayerselecttree/node/node.mid.plus.js index ddd922804..a80610160 100644 --- a/src/widget/multilayerselecttree/node/node.mid.plus.js +++ b/src/widget/multilayerselecttree/node/node.mid.plus.js @@ -42,11 +42,20 @@ BI.MultiLayerSelectTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, { self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); }); + var needBlankLayers = []; + var pNode = o.pNode; + while (pNode) { + if (pNode.isLastNode) { + needBlankLayers.push(pNode.layer) + } + pNode = pNode.pNode; + } + var items = []; - BI.count(0, o.layer, function () { + BI.count(0, o.layer, function (index) { items.push({ type: "bi.layout", - cls: "base-line-conn-background", + cls: BI.contains(needBlankLayers, index) ? "" : "base-line-conn-background", width: 12, height: o.height }); diff --git a/src/widget/multilayerselecttree/node/node.plus.js b/src/widget/multilayerselecttree/node/node.plus.js new file mode 100644 index 000000000..bfde57f66 --- /dev/null +++ b/src/widget/multilayerselecttree/node/node.plus.js @@ -0,0 +1,104 @@ +/** + * 加号表示的组节点 + * + * Created by GUY on 2016/1/27. + * @class BI.MultiLayerSelectTreePlusGroupNode + * @extends BI.NodeButton + */ +BI.MultiLayerSelectTreePlusGroupNode = BI.inherit(BI.NodeButton, { + _defaultConfig: function () { + var conf = BI.MultiLayerSelectTreePlusGroupNode.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + extraCls: "bi-multilayer-select-tree-first-plus-group-node bi-list-item-active", + layer: 0, // 第几层级 + id: "", + pId: "", + readonly: true, + open: false, + height: 24 + }); + }, + _init: function () { + BI.MultiLayerSelectTreePlusGroupNode.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.node = BI.createWidget({ + type: "bi.select_tree_plus_group_node", + cls: "bi-list-item-none", + stopPropagation: true, + logic: { + dynamic: true + }, + id: o.id, + pId: o.pId, + open: o.open, + height: o.height, + hgap: o.hgap, + text: o.text, + value: o.value, + py: o.py + }); + this.node.on(BI.Controller.EVENT_CHANGE, function (type) { + self.setSelected(self.isSelected()); + self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); + }); + + var needBlankLayers = []; + var pNode = o.pNode; + while (pNode) { + if (pNode.isLastNode) { + needBlankLayers.push(pNode.layer) + } + pNode = pNode.pNode; + } + + var items = []; + BI.count(0, o.layer, function (index) { + items.push({ + type: "bi.layout", + cls: BI.contains(needBlankLayers, index) ? "" : "base-line-conn-background", + width: 12, + height: o.height + }); + }); + items.push(this.node); + BI.createWidget({ + type: "bi.td", + element: this, + columnSize: BI.makeArray(o.layer, 12), + items: [items] + }); + }, + + isOnce: function () { + return true; + }, + + doRedMark: function () { + this.node.doRedMark.apply(this.node, arguments); + }, + + unRedMark: function () { + this.node.unRedMark.apply(this.node, arguments); + }, + + isSelected: function () { + return this.node.isSelected(); + }, + + setSelected: function (b) { + BI.MultiLayerSelectTreePlusGroupNode.superclass.setSelected.apply(this, arguments); + this.node.setSelected(b); + }, + + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); + this.node.setSelected(this.isSelected()); + }, + + setOpened: function (v) { + BI.MultiLayerSelectTreePlusGroupNode.superclass.setOpened.apply(this, arguments); + this.node.setOpened(v); + } +}); + +BI.shortcut("bi.multilayer_select_tree_plus_group_node", BI.MultiLayerSelectTreePlusGroupNode); \ No newline at end of file diff --git a/src/widget/multilayersingletree/multilayersingletree.leveltree.js b/src/widget/multilayersingletree/multilayersingletree.leveltree.js index bba61208f..76086042b 100644 --- a/src/widget/multilayersingletree/multilayersingletree.leveltree.js +++ b/src/widget/multilayersingletree/multilayersingletree.leveltree.js @@ -32,14 +32,14 @@ BI.MultiLayerSingleLevelTree = BI.inherit(BI.Widget, { extend.pNode = pNode; if (node.isParent === true || BI.isNotEmptyArray(node.children)) { extend.type = "bi.multilayer_single_tree_mid_plus_group_node"; - if (i === 0 && !pNode) { - extend.type = "bi.multilayer_single_tree_first_plus_group_node" - } if (i === nodes.length - 1) { extend.type = "bi.multilayer_single_tree_last_plus_group_node"; extend.isLastNode = true; } - if (i === 0 && i === nodes.length - 1) { // 根 + if (i === 0 && !pNode) { + extend.type = "bi.multilayer_single_tree_first_plus_group_node"; + } + if (i === 0 && i === nodes.length - 1 && !pNode) { // 根 extend.type = "bi.multilayer_single_tree_plus_group_node"; } BI.defaults(node, extend); diff --git a/src/widget/selecttree/nodes/node.plus.js b/src/widget/selecttree/nodes/node.plus.js new file mode 100644 index 000000000..e0f8e8632 --- /dev/null +++ b/src/widget/selecttree/nodes/node.plus.js @@ -0,0 +1,86 @@ +/** + * 加号表示的组节点 + * Created by GUY on 2015/9/6. + * @class BI.SelectTreePlusGroupNode + * @extends BI.NodeButton + */ +BI.SelectTreePlusGroupNode = BI.inherit(BI.NodeButton, { + _defaultConfig: function () { + var conf = BI.SelectTreePlusGroupNode.superclass._defaultConfig.apply(this, arguments); + return BI.extend(conf, { + baseCls: (conf.baseCls || "") + " bi-select-tree-plus-group-node bi-list-item-active", + logic: { + dynamic: false + }, + id: "", + pId: "", + readonly: true, + open: false, + height: 24 + }); + }, + _init: function () { + BI.SelectTreePlusGroupNode.superclass._init.apply(this, arguments); + var self = this, o = this.options; + this.checkbox = BI.createWidget({ + type: "bi.tree_node_checkbox", + stopPropagation: true + }); + this.text = BI.createWidget({ + type: "bi.label", + textAlign: "left", + whiteSpace: "nowrap", + textHeight: o.height, + height: o.height, + hgap: o.hgap, + text: o.text, + value: o.value, + keyword: o.keyword, + py: o.py + }); + this.checkbox.on(BI.Controller.EVENT_CHANGE, function (type) { + if (type === BI.Events.CLICK) { + if (this.isSelected()) { + self.triggerExpand(); + } else { + self.triggerCollapse(); + } + } + }); + var type = BI.LogicFactory.createLogicTypeByDirection(BI.Direction.Left); + var items = BI.LogicFactory.createLogicItemsByDirection(BI.Direction.Left, { + width: 24, + el: this.checkbox + }, this.text); + BI.createWidget(BI.extend({ + element: this + }, BI.LogicFactory.createLogic(type, BI.extend(o.logic, { + items: items + })))); + }, + + isOnce: function () { + return true; + }, + + doRedMark: function () { + this.text.doRedMark.apply(this.text, arguments); + }, + + unRedMark: function () { + this.text.unRedMark.apply(this.text, arguments); + }, + + doClick: function () { + BI.NodeButton.superclass.doClick.apply(this, arguments); + }, + + setOpened: function (v) { + BI.SelectTreePlusGroupNode.superclass.setOpened.apply(this, arguments); + if (BI.isNotNull(this.checkbox)) { + this.checkbox.setSelected(v); + } + } +}); + +BI.shortcut("bi.select_tree_plus_group_node", BI.SelectTreePlusGroupNode); \ No newline at end of file diff --git a/src/widget/selecttree/selecttree.popup.js b/src/widget/selecttree/selecttree.popup.js index 7b16bd365..b190686d6 100644 --- a/src/widget/selecttree/selecttree.popup.js +++ b/src/widget/selecttree/selecttree.popup.js @@ -14,32 +14,33 @@ BI.SelectTreePopup = BI.inherit(BI.Pane, { }); }, - _formatItems: function (nodes, layer) { + _formatItems: function (nodes, layer, pNode) { var self = this; BI.each(nodes, function (i, node) { var extend = {layer: layer}; node.id = node.id || BI.UUID(); + extend.pNode = pNode; if (node.isParent === true || BI.isNotEmptyArray(node.children)) { - switch (i) { - case 0 : - extend.type = "bi.select_tree_first_plus_group_node"; - break; - case nodes.length - 1 : - extend.type = "bi.select_tree_last_plus_group_node"; - break; - default : - extend.type = "bi.select_tree_mid_plus_group_node"; - break; + extend.type = "bi.select_tree_mid_plus_group_node"; + if (i === nodes.length - 1) { + extend.type = "bi.select_tree_last_plus_group_node"; + extend.isLastNode = true; + } + if (i === 0 && !pNode) { + extend.type = "bi.select_tree_first_plus_group_node" + } + if (i === 0 && i === nodes.length - 1) { // 根 + extend.type = "bi.select_tree_plus_group_node"; } BI.defaults(node, extend); - self._formatItems(node.children); + self._formatItems(node.children, layer + 1, node); } else { - switch (i) { - case nodes.length - 1: - extend.type = "bi.last_tree_leaf_item"; - break; - default : - extend.type = "bi.mid_tree_leaf_item"; + extend.type = "bi.mid_tree_leaf_item"; + if (i === 0 && !pNode) { + extend.type = "bi.first_tree_leaf_item" + } + if (i === nodes.length - 1) { + extend.type = "bi.last_tree_leaf_item"; } BI.defaults(node, extend); } @@ -58,7 +59,7 @@ BI.SelectTreePopup = BI.inherit(BI.Pane, { type: "bi.select_tree_expander", isDefaultInit: true }, - items: this._formatItems(BI.Tree.transformToTreeFormat(o.items)), + items: this._formatItems(BI.Tree.transformToTreeFormat(o.items), 0), value: o.value, chooseType: BI.Selection.Single });