Browse Source

Pull request #3395: KERNEL-14101 refactor: widget/singleselect、multilayerdownlist、multilayersingletree

Merge in VISUAL/fineui from ~ZHENFEI.LI/fineui:es6 to es6

* commit 'b9900a1dcb4f51082f55c89a5ce31186c8193739':
  KERNEL-14101 refactor: multilayerdownlist、multilayersingletree
  KERNEL-14101 refactor:  widget/singleselect
es6
Zhenfei.Li-李振飞 2 years ago
parent
commit
399be46c6e
  1. 3
      .eslintrc
  2. 11
      src/widget/index.js
  3. 94
      src/widget/multilayerdownlist/combo.downlist.js
  4. 2
      src/widget/multilayerdownlist/index.js
  5. 380
      src/widget/multilayerdownlist/popup.downlist.js
  6. 7
      src/widget/multilayersingletree/index.js
  7. 356
      src/widget/multilayersingletree/multilayersingletree.combo.js
  8. 140
      src/widget/multilayersingletree/multilayersingletree.insert.search.pane.js
  9. 228
      src/widget/multilayersingletree/multilayersingletree.leveltree.js
  10. 79
      src/widget/multilayersingletree/multilayersingletree.popup.js
  11. 311
      src/widget/multilayersingletree/multilayersingletree.trigger.js
  12. 4
      src/widget/multilayersingletree/node/index.js
  13. 117
      src/widget/multilayersingletree/node/node.first.plus.js
  14. 117
      src/widget/multilayersingletree/node/node.last.plus.js
  15. 117
      src/widget/multilayersingletree/node/node.mid.plus.js
  16. 130
      src/widget/multilayersingletree/node/node.plus.js
  17. 3
      src/widget/multilayersingletree/treeitem/index.js
  18. 93
      src/widget/multilayersingletree/treeitem/item.first.treeleaf.js
  19. 93
      src/widget/multilayersingletree/treeitem/item.last.treeleaf.js
  20. 93
      src/widget/multilayersingletree/treeitem/item.mid.treeleaf.js
  21. 1
      src/widget/multiselect/index.js
  22. 9
      src/widget/singleselect/index.js
  23. 3
      src/widget/singleselect/search/index.js
  24. 181
      src/widget/singleselect/search/singleselect.search.loader.js
  25. 124
      src/widget/singleselect/search/singleselect.search.pane.insert.js
  26. 130
      src/widget/singleselect/search/singleselect.search.pane.js
  27. 321
      src/widget/singleselect/singleselect.combo.js
  28. 260
      src/widget/singleselect/singleselect.insert.combo.js
  29. 226
      src/widget/singleselect/singleselect.list.js
  30. 239
      src/widget/singleselect/singleselect.loader.js
  31. 88
      src/widget/singleselect/singleselect.popup.view.js
  32. 174
      src/widget/singleselect/singleselect.trigger.js
  33. 266
      src/widget/singleselect/singleselectlist.insert.js
  34. 102
      src/widget/singleselect/trigger/editor.singleselect.js
  35. 2
      src/widget/singleselect/trigger/index.js
  36. 189
      src/widget/singleselect/trigger/searcher.singleselect.js

3
.eslintrc

@ -36,7 +36,8 @@
"no-var": 2, "no-var": 2,
"prefer-const": 2, "prefer-const": 2,
"indent": ["error", 4], "indent": ["error", 4],
"no-use-before-define": 0 "no-use-before-define": 0,
"eqeqeq": 0
} }
}, { }, {
"files": ["webpack/*.js", "./*.js", "lib/**/*.js", "lib/*.js", "./bin/*.js", "./bin/**/*.js"], "files": ["webpack/*.js", "./*.js", "lib/**/*.js", "lib/*.js", "./bin/*.js", "./bin/**/*.js"],

11
src/widget/index.js

@ -21,6 +21,10 @@ import * as multiselect from "./multiselect";
import * as multiselectlist from "./multiselectlist"; import * as multiselectlist from "./multiselectlist";
import * as year from "./year"; import * as year from "./year";
import { YearInterval } from "./yearinterval/yearinterval"; import { YearInterval } from "./yearinterval/yearinterval";
import * as singleselect from "./singleselect";
import * as multilayerdownlist from "./multilayerdownlist";
import * as multilayersingletree from "./multilayersingletree";
Object.assign(BI, { Object.assign(BI, {
Collapse, Collapse,
...calendar, ...calendar,
@ -45,6 +49,9 @@ Object.assign(BI, {
YearInterval, YearInterval,
...multiselect, ...multiselect,
...multiselectlist, ...multiselectlist,
...singleselect,
...multilayerdownlist,
...multilayersingletree,
}); });
export * from "./date/calendar"; export * from "./date/calendar";
@ -61,6 +68,10 @@ export * from "./downlist";
export * from "./singleslider"; export * from "./singleslider";
export * from "./intervalslider"; export * from "./intervalslider";
export * from "./year"; export * from "./year";
export * from "./singleselect";
export * from "./multilayerdownlist";
export * from "./multilayersingletree";
export { export {
Collapse, Collapse,
NumberEditor, NumberEditor,

94
src/widget/multilayerdownlist/combo.downlist.js

@ -1,9 +1,18 @@
/** import { shortcut, Widget, extend, createWidget } from "@/core";
* Created by roy on 15/8/14. import { MultiLayerDownListPopup } from "./popup.downlist";
*/ import { Combo } from "@/base";
BI.MultiLayerDownListCombo = BI.inherit(BI.Widget, { import { IconTrigger } from "@/case";
_defaultConfig: function () {
return BI.extend(BI.MultiLayerDownListCombo.superclass._defaultConfig.apply(this, arguments), { @shortcut()
export class MultiLayerDownListCombo extends Widget {
static xtype = "bi.multi_layer_down_list_combo";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multilayer-down-list-combo", baseCls: "bi-multilayer-down-list-combo",
height: 24, height: 24,
items: [], items: [],
@ -12,79 +21,74 @@ BI.MultiLayerDownListCombo = BI.inherit(BI.Widget, {
trigger: "click", trigger: "click",
container: null, container: null,
stopPropagation: false, stopPropagation: false,
el: {} el: {},
}); });
}, }
_init: function () { _init() {
BI.MultiLayerDownListCombo.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
this.popupview = BI.createWidget({ this.popupview = createWidget({
type: "bi.multi_layer_down_list_popup", type: "bi.multi_layer_down_list_popup",
items: o.items, items: o.items,
chooseType: o.chooseType, chooseType: o.chooseType,
value: o.value value: o.value,
}); });
this.popupview.on(BI.MultiLayerDownListPopup.EVENT_CHANGE, function (value) { this.popupview.on(MultiLayerDownListPopup.EVENT_CHANGE, value => {
self.fireEvent(BI.MultiLayerDownListCombo.EVENT_CHANGE, value); this.fireEvent(MultiLayerDownListCombo.EVENT_CHANGE, value);
self.downlistcombo.hideView(); this.downlistcombo.hideView();
}); });
this.popupview.on(BI.MultiLayerDownListPopup.EVENT_SON_VALUE_CHANGE, function (value, fatherValue) { this.popupview.on(MultiLayerDownListPopup.EVENT_SON_VALUE_CHANGE, (value, fatherValue) => {
self.fireEvent(BI.MultiLayerDownListCombo.EVENT_SON_VALUE_CHANGE, value, fatherValue); this.fireEvent(MultiLayerDownListCombo.EVENT_SON_VALUE_CHANGE, value, fatherValue);
self.downlistcombo.hideView(); this.downlistcombo.hideView();
}); });
this.downlistcombo = createWidget({
this.downlistcombo = BI.createWidget({
element: this, element: this,
type: "bi.combo", type: Combo.xtype,
trigger: o.trigger, trigger: o.trigger,
isNeedAdjustWidth: false, isNeedAdjustWidth: false,
container: o.container, container: o.container,
adjustLength: o.adjustLength, adjustLength: o.adjustLength,
direction: o.direction, direction: o.direction,
stopPropagation: o.stopPropagation, stopPropagation: o.stopPropagation,
el: BI.createWidget(o.el, { el: createWidget(o.el, {
type: "bi.icon_trigger", type: IconTrigger.xtype,
extraCls: o.iconCls ? o.iconCls : "pull-down-font", extraCls: o.iconCls ? o.iconCls : "pull-down-font",
width: o.width, width: o.width,
height: o.height height: o.height,
}), }),
popup: { popup: {
el: this.popupview, el: this.popupview,
stopPropagation: o.stopPropagation, stopPropagation: o.stopPropagation,
maxHeight: 1000 maxHeight: 1000,
} },
}); });
this.downlistcombo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { this.downlistcombo.on(Combo.EVENT_BEFORE_POPUPVIEW, () => {
self.fireEvent(BI.MultiLayerDownListCombo.EVENT_BEFORE_POPUPVIEW); this.fireEvent(MultiLayerDownListCombo.EVENT_BEFORE_POPUPVIEW);
}); });
}, }
hideView: function () { hideView() {
this.downlistcombo.hideView(); this.downlistcombo.hideView();
}, }
showView: function (e) { showView(e) {
this.downlistcombo.showView(e); this.downlistcombo.showView(e);
}, }
populate: function (items) { populate(items) {
this.popupview.populate(items); this.popupview.populate(items);
}, }
setValue: function (v) { setValue(v) {
this.popupview.setValue(v); this.popupview.setValue(v);
},
getValue: function () {
return this.popupview.getValue();
} }
});
BI.MultiLayerDownListCombo.EVENT_CHANGE = "EVENT_CHANGE";
BI.MultiLayerDownListCombo.EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE";
BI.MultiLayerDownListCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.shortcut("bi.multi_layer_down_list_combo", BI.MultiLayerDownListCombo); getValue() {
return this.popupview.getValue();
}
}

2
src/widget/multilayerdownlist/index.js

@ -0,0 +1,2 @@
export { MultiLayerDownListCombo } from "./combo.downlist";
export { MultiLayerDownListPopup } from "./popup.downlist";

380
src/widget/multilayerdownlist/popup.downlist.js

@ -1,136 +1,173 @@
/** import {
* Created by roy on 15/9/8. shortcut,
* 处理popup中的item分组样式 extend,
* 一个item分组中的成员大于一时该分组设置为单选并且默认状态第一个成员设置为已选择项 Selection,
*/ createWidget,
BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, { createItems,
constants: { isNotNull,
contains,
each,
VerticalLayout,
isNotEmptyArray,
isEmpty,
Layout,
deepClone,
isArray,
isNotEmptyString,
some,
concat,
BlankSplitChar
} from "@/core";
import { Pane, ButtonTree, ComboGroup } from "@/base";
import { DownListGroup, DownListGroupItem, DownListItem } from "../downlist";
@shortcut()
export class MultiLayerDownListPopup extends Pane {
static xtype = "bi.multi_layer_down_list_popup";
constants = {
nextIcon: "pull-right-e-font", nextIcon: "pull-right-e-font",
height: 25, height: 25,
iconHeight: 12, iconHeight: 12,
iconWidth: 12, iconWidth: 12,
hgap: 0, hgap: 0,
vgap: 0, vgap: 0,
border: 1 border: 1,
}, };
_defaultConfig: function () {
var conf = BI.MultiLayerDownListPopup.superclass._defaultConfig.apply(this, arguments); static EVENT_CHANGE = "EVENT_CHANGE";
return BI.extend(conf, { static EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE";
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
baseCls: "bi-down-list-popup", baseCls: "bi-down-list-popup",
items: [], items: [],
chooseType: BI.Selection.Multi chooseType: Selection.Multi,
}); });
}, }
_init: function () {
BI.MultiLayerDownListPopup.superclass._init.apply(this, arguments); _init() {
super._init(...arguments);
this.singleValues = []; this.singleValues = [];
this.childValueMap = {}; this.childValueMap = {};
this.fatherValueMap = {}; this.fatherValueMap = {};
this.items = []; this.items = [];
var self = this, o = this.options, children = this._createPopupItems(o.items); const self = this,
this.popup = BI.createWidget({ o = this.options,
type: "bi.button_tree", children = this._createPopupItems(o.items);
items: BI.createItems(children, this.popup = createWidget({
{}, { type: ButtonTree.xtype,
adjustLength: -2 items: createItems(
children,
{},
{
adjustLength: -2,
} }
), ),
layouts: [{ layouts: [
type: "bi.vertical", {
hgap: this.constants.hgap, type: VerticalLayout.xtype,
vgap: this.constants.vgap hgap: this.constants.hgap,
}], vgap: this.constants.vgap,
}
],
value: this._digest(o.value), value: this._digest(o.value),
chooseType: o.chooseType chooseType: o.chooseType,
}); });
this.popup.on(BI.ButtonTree.EVENT_CHANGE, function (value, object) { this.popup.on(ButtonTree.EVENT_CHANGE, (value, object) => {
var changedValue = value; let changedValue = value;
if (BI.isNotNull(self.childValueMap[value])) { if (isNotNull(self.childValueMap[value])) {
changedValue = self.childValueMap[value]; changedValue = self.childValueMap[value];
var fatherValue = self.fatherValueMap[value]; const fatherValue = self.fatherValueMap[value];
var fatherArrayValue = (fatherValue + "").split(BI.BlankSplitChar); const fatherArrayValue = (`${fatherValue}`).split(BlankSplitChar);
self.fireEvent(BI.MultiLayerDownListPopup.EVENT_SON_VALUE_CHANGE, changedValue, fatherArrayValue.length > 1 ? fatherArrayValue : fatherValue); self.fireEvent(
MultiLayerDownListPopup.EVENT_SON_VALUE_CHANGE,
changedValue,
fatherArrayValue.length > 1 ? fatherArrayValue : fatherValue
);
} else { } else {
self.fireEvent(BI.MultiLayerDownListPopup.EVENT_CHANGE, changedValue, object); self.fireEvent(MultiLayerDownListPopup.EVENT_CHANGE, changedValue, object);
} }
if (!contains(self.singleValues, changedValue)) {
if (!BI.contains(self.singleValues, changedValue)) { const item = self.getValue();
var item = self.getValue(); const result = [];
var result = []; each(item, (i, valueObject) => {
BI.each(item, function (i, valueObject) {
if (valueObject.value != changedValue) { if (valueObject.value != changedValue) {
result.push(valueObject); result.push(valueObject);
} }
}); });
self.setValue(result); self.setValue(result);
} }
}); });
BI.createWidget({ createWidget({
type: "bi.vertical", type: VerticalLayout.xtype,
element: this, element: this,
items: [this.popup], items: [this.popup],
vgap: 5 vgap: 5,
}); });
}
}, _createPopupItems(items) {
_createPopupItems: function (items) { const self = this,
var self = this, result = []; result = [];
BI.each(items, function (i, it) { each(items, (i, it) => {
var item_done = { const item_done = {
type: "bi.down_list_group", type: DownListGroup.xtype,
items: [] items: [],
}; };
var storeItem = []; const storeItem = [];
BI.each(it, function (i, sourceItem) { each(it, (i, sourceItem) => {
var item = BI.extend({}, sourceItem); const item = extend({}, sourceItem);
if (BI.isNotEmptyArray(sourceItem.children) && !BI.isEmpty(sourceItem.el)) { if (isNotEmptyArray(sourceItem.children) && !isEmpty(sourceItem.el)) {
item.type = "bi.combo_group"; item.type = ComboGroup.xtype;
item.cls = "down-list-group"; item.cls = "down-list-group";
item.trigger = "hover"; item.trigger = "hover";
item.isNeedAdjustWidth = false; item.isNeedAdjustWidth = false;
item.el = sourceItem.el; item.el = sourceItem.el;
item.el.title = sourceItem.el.title || sourceItem.el.text; item.el.title = sourceItem.el.title || sourceItem.el.text;
item.el.type = "bi.down_list_group_item"; item.el.type = DownListGroupItem.xtype;
item.el.logic = { item.el.logic = {
dynamic: true dynamic: true,
}; };
item.el.height = sourceItem.el.height || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT; item.el.height = sourceItem.el.height || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT;
item.el.iconCls2 = self.constants.nextIcon; item.el.iconCls2 = self.constants.nextIcon;
item.popup = { item.popup = {
lgap: 1, lgap: 1,
el: { el: {
type: "bi.button_tree", type: ButtonTree.xtype,
chooseType: 0, chooseType: 0,
layouts: [{ layouts: [
type: "bi.vertical" {
}] type: VerticalLayout.xtype,
}
],
}, },
innerVgap: 5, innerVgap: 5,
maxHeight: 378, maxHeight: 378,
}; };
self._createChildren(item, sourceItem); self._createChildren(item, sourceItem);
} else { } else {
item.type = sourceItem.type || "bi.down_list_item"; item.type = sourceItem.type || DownListItem.xtype;
item.title = sourceItem.title || sourceItem.text; item.title = sourceItem.title || sourceItem.text;
item.textRgap = 10; item.textRgap = 10;
item.isNeedAdjustWidth = false; item.isNeedAdjustWidth = false;
item.logic = { item.logic = {
dynamic: true dynamic: true,
}; };
} }
var el_done = {}; const el_done = {};
el_done.el = item; el_done.el = item;
item_done.items.push(el_done); item_done.items.push(el_done);
storeItem.push(item); storeItem.push(item);
}); });
if (self._isGroup(item_done.items)) { if (self._isGroup(item_done.items)) {
BI.each(item_done.items, function (i, item) { each(item_done.items, (i, item) => {
self.singleValues.push(item.el.value); self.singleValues.push(item.el.value);
}); });
} }
@ -138,16 +175,17 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
result.push(item_done); result.push(item_done);
self.items.push(storeItem); self.items.push(storeItem);
if (self._needSpliter(i, items.length)) { if (self._needSpliter(i, items.length)) {
var spliter_container = BI.createWidget({ const spliter_container = createWidget({
type: "bi.vertical", type: VerticalLayout.xtype,
items: [{ items: [
el: { {
type: "bi.layout", el: {
cls: "bi-down-list-spliter bi-border-top cursor-pointer", type: Layout.xtype,
height: 0 cls: "bi-down-list-spliter bi-border-top cursor-pointer",
height: 0,
},
} }
],
}],
cls: "bi-down-list-spliter-container cursor-pointer", cls: "bi-down-list-spliter-container cursor-pointer",
vgap: 5, vgap: 5,
hgap: 12, hgap: 12,
@ -155,178 +193,180 @@ BI.MultiLayerDownListPopup = BI.inherit(BI.Pane, {
result.push(spliter_container); result.push(spliter_container);
} }
}); });
return result; return result;
}, }
_createChildren: function (targetItem, sourceItem) { _createChildren(targetItem, sourceItem) {
var self = this; const self = this;
this._formatEL(targetItem).el.childValues = []; this._formatEL(targetItem).el.childValues = [];
targetItem.items = targetItem.children = []; targetItem.items = targetItem.children = [];
BI.each(sourceItem.children, function (i, child) { each(sourceItem.children, (i, child) => {
var item = child.el ? BI.extend({}, child.el, {children: child.children}) : BI.extend({}, child); const item = child.el ? extend({}, child.el, { children: child.children }) : extend({}, child);
var fatherValue = BI.deepClone(self._formatEL(targetItem).el.value); const fatherValue = deepClone(self._formatEL(targetItem).el.value);
var childValue = BI.deepClone(item.value); const childValue = deepClone(item.value);
self.singleValues.push(item.value); self.singleValues.push(item.value);
item.type = item.type || "bi.down_list_item"; item.type = item.type || DownListItem.xtype;
item.extraCls = " child-down-list-item"; item.extraCls = " child-down-list-item";
item.title = item.title || item.text; item.title = item.title || item.text;
item.textRgap = 10; item.textRgap = 10;
item.isNeedAdjustWidth = false; item.isNeedAdjustWidth = false;
item.logic = { item.logic = {
dynamic: true dynamic: true,
}; };
item.father = fatherValue; item.father = fatherValue;
self.fatherValueMap[self._createChildValue(fatherValue, childValue)] = fatherValue; self.fatherValueMap[self._createChildValue(fatherValue, childValue)] = fatherValue;
self.childValueMap[self._createChildValue(fatherValue, childValue)] = childValue; self.childValueMap[self._createChildValue(fatherValue, childValue)] = childValue;
item.value = self._createChildValue(fatherValue, childValue); item.value = self._createChildValue(fatherValue, childValue);
self._formatEL(targetItem).el.childValues.push(item.value); self._formatEL(targetItem).el.childValues.push(item.value);
if (BI.isNotEmptyArray(child.children)) { if (isNotEmptyArray(child.children)) {
item.type = "bi.down_list_group_item"; item.type = DownListGroupItem.xtype;
item.iconCls2 = self.constants.nextIcon; item.iconCls2 = self.constants.nextIcon;
item.height = child.height || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT; item.height = child.height || BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT;
self._createChildren(item, child); self._createChildren(item, child);
} }
targetItem.items.push(item); targetItem.items.push(item);
}); });
}, }
_formatEL: function(obj) { _formatEL(obj) {
if (obj && obj.el) { if (obj && obj.el) {
return obj; return obj;
} }
return { return {
el: obj el: obj,
}; };
}, }
_isGroup: function (i) { _isGroup(i) {
return i.length > 1; return i.length > 1;
}, }
_needSpliter: function (i, itemLength) { _needSpliter(i, itemLength) {
return i < itemLength - 1; return i < itemLength - 1;
}, }
_createChildValue: function (fatherValue, childValue) { _createChildValue(fatherValue, childValue) {
var fValue = fatherValue; let fValue = fatherValue;
if(BI.isArray(fatherValue)) { if (isArray(fatherValue)) {
fValue = fatherValue.join(BI.BlankSplitChar); fValue = fatherValue.join(BlankSplitChar);
} }
return fValue + BI.BlankSplitChar + childValue;
}, return fValue + BlankSplitChar + childValue;
}
_digest: function (valueItem) { _digest(valueItem) {
var self = this; const self = this;
var valueArray = []; const valueArray = [];
BI.each(valueItem, function (i, item) { each(valueItem, (i, item) => {
var value; let value;
if (BI.isNotNull(item.childValue)) { if (isNotNull(item.childValue)) {
value = self._createChildValue(item.value, item.childValue); value = self._createChildValue(item.value, item.childValue);
} else { } else {
value = item.value; value = item.value;
}
valueArray.push(value);
} }
); valueArray.push(value);
});
return valueArray; return valueArray;
}, }
_checkValues: function (values) { _checkValues(values) {
var self = this, o = this.options; const value = [];
var value = []; each(this.items, (idx, itemGroup) => {
BI.each(this.items, function (idx, itemGroup) { each(itemGroup, (id, item) => {
BI.each(itemGroup, function (id, item) { if (isNotNull(item.children)) {
if(BI.isNotNull(item.children)) { const childValues = getChildrenValue(item);
var childValues = getChildrenValue(item); const v = joinValue(childValues, values[idx]);
var v = joinValue(childValues, values[idx]); if (isNotEmptyString(v)) {
if(BI.isNotEmptyString(v)) {
value.push(v); value.push(v);
} }
}else{ } else {
if(item.value === values[idx][0]) { if (item.value === values[idx][0]) {
value.push(values[idx][0]); value.push(values[idx][0]);
} }
} }
}); });
}); });
return value; return value;
function joinValue (sources, targets) { function joinValue(sources, targets) {
var value = ""; let value = "";
BI.some(sources, function (idx, s) { some(sources, (idx, s) => some(targets, (id, t) => {
return BI.some(targets, function (id, t) { if (s === t) {
if(s === t) { value = s;
value = s;
return true; return true;
} }
}); }));
});
return value; return value;
} }
function getChildrenValue (item) { function getChildrenValue(item) {
var children = []; let children = [];
if(BI.isNotNull(item.children)) { if (isNotNull(item.children)) {
BI.each(item.children, function (idx, child) { each(item.children, (idx, child) => {
children = BI.concat(children, getChildrenValue(child)); children = concat(children, getChildrenValue(child));
}); });
} else { } else {
children.push(item.value); children.push(item.value);
} }
return children; return children;
} }
}, }
populate: function (items) { populate(items) {
BI.MultiLayerDownListPopup.superclass.populate.apply(this, arguments); super.populate(...arguments);
var self = this; const self = this;
self.childValueMap = {}; self.childValueMap = {};
self.fatherValueMap = {}; self.fatherValueMap = {};
self.singleValues = []; self.singleValues = [];
this.items = []; this.items = [];
var children = self._createPopupItems(items); const children = self._createPopupItems(items);
var popupItem = BI.createItems(children, const popupItem = createItems(
{}, { children,
adjustLength: -2 {},
{
adjustLength: -2,
} }
); );
self.popup.populate(popupItem); self.popup.populate(popupItem);
}, }
setValue: function (valueItem) { setValue(valueItem) {
this.popup.setValue(this._digest(valueItem)); this.popup.setValue(this._digest(valueItem));
}, }
_getValue: function () { _getValue() {
var v = []; const v = [];
BI.each(this.popup.getAllButtons(), function (i, item) { each(this.popup.getAllButtons(), (i, item) => {
i % 2 === 0 && v.push(item.getValue()); i % 2 === 0 && v.push(item.getValue());
}); });
return v; return v;
}, }
getValue: function () { getValue() {
var self = this, result = []; const self = this,
var values = this._checkValues(this._getValue()); result = [];
BI.each(values, function (i, value) { const values = this._checkValues(this._getValue());
var valueItem = {}; each(values, (i, value) => {
if (BI.isNotNull(self.childValueMap[value])) { const valueItem = {};
var fartherValue = self.fatherValueMap[value]; if (isNotNull(self.childValueMap[value])) {
const fartherValue = self.fatherValueMap[value];
valueItem.childValue = self.childValueMap[value]; valueItem.childValue = self.childValueMap[value];
var fatherArrayValue = (fartherValue + "").split(BI.BlankSplitChar); const fatherArrayValue = (`${fartherValue}`).split(BlankSplitChar);
valueItem.value = fatherArrayValue.length > 1 ? fatherArrayValue : fartherValue; valueItem.value = fatherArrayValue.length > 1 ? fatherArrayValue : fartherValue;
} else { } else {
valueItem.value = value; valueItem.value = value;
} }
result.push(valueItem); result.push(valueItem);
}); });
return result; return result;
} }
}
});
BI.MultiLayerDownListPopup.EVENT_CHANGE = "EVENT_CHANGE";
BI.MultiLayerDownListPopup.EVENT_SON_VALUE_CHANGE = "EVENT_SON_VALUE_CHANGE";
BI.shortcut("bi.multi_layer_down_list_popup", BI.MultiLayerDownListPopup);

7
src/widget/multilayersingletree/index.js

@ -0,0 +1,7 @@
export { MultiLayerSingleTreeCombo } from "./multilayersingletree.combo";
export { MultiLayerSingleTreeInsertSearchPane } from "./multilayersingletree.insert.search.pane";
export { MultiLayerSingleLevelTree } from "./multilayersingletree.leveltree";
export { MultiLayerSingleTreePopup } from "./multilayersingletree.popup";
export { MultiLayerSingleTreeTrigger } from "./multilayersingletree.trigger";
export * from "./node";
export * from "./treeitem";

356
src/widget/multilayersingletree/multilayersingletree.combo.js

@ -1,81 +1,105 @@
/** import { shortcut, Widget, extend, emptyFn, isKey, toPix, AbsoluteLayout, nextTick, isArray } from "@/core";
* 多层级下拉单选树 import { SingleTreeTrigger } from "../singletree/singletree.trigger";
* Created by GUY on 2016/1/26. import { MultiLayerSingleTreePopup } from "./multilayersingletree.popup";
* import { Combo } from "@/base";
* @class BI.MultiLayerSingleTreeCombo import { MultiLayerSingleTreeTrigger } from "./multilayersingletree.trigger";
* @extends BI.Widget import { TriggerIconButton } from "@/case";
*/
BI.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.MultiLayerSingleTreeCombo.superclass._defaultConfig.apply(this, arguments), { export class MultiLayerSingleTreeCombo extends Widget {
static xtype = "bi.multilayer_single_tree_combo";
static EVENT_SEARCHING = "EVENT_SEARCHING";
static EVENT_BLUR = "EVENT_BLUR";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_STOP = "EVENT_STOP";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multilayer-single-tree-combo", baseCls: "bi-multilayer-single-tree-combo",
isDefaultInit: false, isDefaultInit: false,
height: 24, height: 24,
text: "", text: "",
defaultText: "", defaultText: "",
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
items: [], items: [],
allowEdit: false, allowEdit: false,
allowSearchValue: false, allowSearchValue: false,
allowInsertValue: false, allowInsertValue: false,
isNeedAdjustWidth: true, isNeedAdjustWidth: true,
}); });
}, }
render: function () { render() {
var self = this, o = this.options; const self = this,
o = this.options;
var cls = (o.simple ? "bi-border-bottom bi-focus-shadow " : "bi-border bi-border-radius bi-focus-shadow ") + (BI.isKey(o.status) ? ("status-" + o.status) : ""); const cls =
(o.simple ? "bi-border-bottom bi-focus-shadow " : "bi-border bi-border-radius bi-focus-shadow ") +
(isKey(o.status) ? `status-${o.status}` : "");
var baseConfig = this._getBaseConfig(); const baseConfig = this._getBaseConfig();
if (o.allowEdit) { if (o.allowEdit) {
return { return {
type: "bi.absolute", type: AbsoluteLayout.xtype,
width: BI.toPix(o.width, 2), width: toPix(o.width, 2),
height: BI.toPix(o.height, 2), height: toPix(o.height, 2),
cls, cls,
items: [ items: [
{ {
el: BI.extend(baseConfig, this._getSearchConfig()), el: extend(baseConfig, this._getSearchConfig()),
top: 0, bottom: 0, right: 0, left: 0 top: 0,
}, { bottom: 0,
el: self._getTriggerIconButton(), right: 0,
top: 0, bottom: 0, right: 0, left: 0,
}, },
] {
el: self._getTriggerIconButton(),
top: 0,
bottom: 0,
right: 0,
}
],
}; };
} }
return BI.extend(baseConfig, { return extend(
width: BI.toPix(o.width, 2), baseConfig,
height: BI.toPix(o.height, 2), {
el: { width: toPix(o.width, 2),
type: "bi.single_tree_trigger", height: toPix(o.height, 2),
ref: function (_ref) { el: {
self.textTrigger = _ref; type: SingleTreeTrigger.xtype,
ref (_ref) {
self.textTrigger = _ref;
},
text: o.text,
defaultText: o.defaultText,
height: toPix(o.height, 2),
items: o.items,
value: o.value,
tipType: o.tipType,
warningTitle: o.warningTitle,
valueFormatter: o.valueFormatter,
}, },
text: o.text,
defaultText: o.defaultText,
height: BI.toPix(o.height, 2),
items: o.items,
value: o.value,
tipType: o.tipType,
warningTitle: o.warningTitle,
valueFormatter: o.valueFormatter,
}, },
}, { cls }); { cls }
}, );
}
_getBaseConfig: function () { _getBaseConfig() {
var self = this, o = this.options; const self = this,
o = this.options;
return { return {
type: "bi.combo", type: Combo.xtype,
container: o.container, container: o.container,
destroyWhenHide: o.destroyWhenHide, destroyWhenHide: o.destroyWhenHide,
adjustLength: 2, adjustLength: 2,
ref: function (_ref) { ref (_ref) {
self.combo = _ref; self.combo = _ref;
}, },
popup: { popup: {
@ -84,41 +108,47 @@ BI.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, {
isDefaultInit: o.isDefaultInit, isDefaultInit: o.isDefaultInit,
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
items: o.items, items: o.items,
ref: function (_ref) { ref (_ref) {
self.trigger && self.trigger.getSearcher().setAdapter(_ref); self.trigger && self.trigger.getSearcher().setAdapter(_ref);
}, },
listeners: [{ listeners: [
eventName: BI.MultiLayerSingleTreePopup.EVENT_CHANGE, {
action: function () { eventName: MultiLayerSingleTreePopup.EVENT_CHANGE,
self.setValue(this.getValue()); action () {
self.combo.hideView(); self.setValue(this.getValue());
self.fireEvent(BI.MultiLayerSingleTreeCombo.EVENT_CHANGE); self.combo.hideView();
self.fireEvent(MultiLayerSingleTreeCombo.EVENT_CHANGE);
},
} }
}], ],
onLoaded: function () { onLoaded () {
BI.nextTick(function () { nextTick(() => {
self.combo.adjustWidth(); self.combo.adjustWidth();
self.combo.adjustHeight(); self.combo.adjustHeight();
}); });
} },
}, },
value: o.value, value: o.value,
maxHeight: 400, maxHeight: 400,
maxWidth: o.isNeedAdjustWidth ? "auto" : 500, maxWidth: o.isNeedAdjustWidth ? "auto" : 500,
minHeight: 240 minHeight: 240,
}, },
isNeedAdjustWidth: o.isNeedAdjustWidth, isNeedAdjustWidth: o.isNeedAdjustWidth,
listeners: [{ listeners: [
eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, {
action: function () { eventName: Combo.EVENT_BEFORE_POPUPVIEW,
self.fireEvent(BI.MultiLayerSingleTreeCombo.EVENT_BEFORE_POPUPVIEW); action () {
self.fireEvent(MultiLayerSingleTreeCombo.EVENT_BEFORE_POPUPVIEW);
},
} }
}] ],
}; };
}, }
_getSearchConfig: function () { _getSearchConfig() {
var self = this, o = this.options; const self = this,
o = this.options;
return { return {
el: { el: {
type: "bi.multilayer_single_tree_trigger", type: "bi.multilayer_single_tree_trigger",
@ -126,154 +156,162 @@ BI.MultiLayerSingleTreeCombo = BI.inherit(BI.Widget, {
allowInsertValue: o.allowInsertValue, allowInsertValue: o.allowInsertValue,
allowSearchValue: o.allowSearchValue, allowSearchValue: o.allowSearchValue,
cls: "multilayer-single-tree-trigger", cls: "multilayer-single-tree-trigger",
ref: function (_ref) { ref (_ref) {
self.trigger = _ref; self.trigger = _ref;
}, },
watermark: o.watermark, watermark: o.watermark,
items: o.items, items: o.items,
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
height: BI.toPix(o.height, 2), height: toPix(o.height, 2),
text: o.text, text: o.text,
defaultText: o.defaultText, defaultText: o.defaultText,
value: o.value, value: o.value,
tipType: o.tipType, tipType: o.tipType,
warningTitle: o.warningTitle, warningTitle: o.warningTitle,
title: o.title, title: o.title,
listeners: [{ listeners: [
eventName: BI.MultiLayerSingleTreeTrigger.EVENT_CHANGE, {
action: function () { eventName: MultiLayerSingleTreeTrigger.EVENT_CHANGE,
self.setValue(this.getValue()); action () {
self.combo.hideView(); self.setValue(this.getValue());
self.fireEvent(BI.MultiLayerSingleTreeCombo.EVENT_CHANGE); self.combo.hideView();
} self.fireEvent(MultiLayerSingleTreeCombo.EVENT_CHANGE);
}, { },
eventName: BI.MultiLayerSingleTreeTrigger.EVENT_FOCUS, },
action: function () { {
self.fireEvent(BI.MultiLayerSingleTreeCombo.EVENT_FOCUS); eventName: MultiLayerSingleTreeTrigger.EVENT_FOCUS,
} action () {
}, { self.fireEvent(MultiLayerSingleTreeCombo.EVENT_FOCUS);
eventName: BI.MultiLayerSingleTreeTrigger.EVENT_BLUR, },
action: function () { },
self.fireEvent(BI.MultiLayerSingleTreeCombo.EVENT_BLUR); {
} eventName: MultiLayerSingleTreeTrigger.EVENT_BLUR,
}, { action () {
eventName: BI.MultiLayerSingleTreeTrigger.EVENT_SEARCHING, self.fireEvent(MultiLayerSingleTreeCombo.EVENT_BLUR);
action: function () { },
self.fireEvent(BI.MultiLayerSingleTreeCombo.EVENT_SEARCHING); },
} {
}, { eventName: MultiLayerSingleTreeTrigger.EVENT_SEARCHING,
eventName: BI.MultiLayerSingleTreeTrigger.EVENT_STOP, action () {
action: function () { self.fireEvent(MultiLayerSingleTreeCombo.EVENT_SEARCHING);
self.fireEvent(BI.MultiLayerSingleTreeCombo.EVENT_STOP); },
} },
}, { {
eventName: BI.MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM, eventName: MultiLayerSingleTreeTrigger.EVENT_STOP,
action: function () { action () {
var value = self.trigger.getSearcher().getKeyword(); self.fireEvent(MultiLayerSingleTreeCombo.EVENT_STOP);
self.combo.setValue([value]); },
self.combo.hideView(); },
self.fireEvent(BI.MultiLayerSingleTreeCombo.EVENT_CHANGE); {
eventName: MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM,
action () {
const value = self.trigger.getSearcher().getKeyword();
self.combo.setValue([value]);
self.combo.hideView();
self.fireEvent(MultiLayerSingleTreeCombo.EVENT_CHANGE);
},
} }
}] ],
}, },
toggle: !o.allowEdit, toggle: !o.allowEdit,
hideChecker: function (e) { hideChecker (e) {
// 新增传配置container后对应hideChecker的修改 // 新增传配置container后对应hideChecker的修改
// IE11下,popover(position: fixed)下放置下拉控件(position: fixed), 滚动的时候会异常卡顿 // IE11下,popover(position: fixed)下放置下拉控件(position: fixed), 滚动的时候会异常卡顿
// 通过container参数将popup放置于popover之外解决此问题, 其他下拉控件由于元素少或者有分页,所以 // 通过container参数将popup放置于popover之外解决此问题, 其他下拉控件由于元素少或者有分页,所以
// 卡顿不明显, 先在此做尝试, 并在FineUI特殊处理待解决文档中标记跟踪 // 卡顿不明显, 先在此做尝试, 并在FineUI特殊处理待解决文档中标记跟踪
return (o.container && self.trigger.getSearcher().isSearching() && self.trigger.getSearcher().getView().element.find(e.target).length > 0) ? false : self.triggerBtn?.element.find(e.target).length === 0; return o.container &&
self.trigger.getSearcher().isSearching() &&
self.trigger.getSearcher().getView().element.find(e.target).length > 0
? false
: self.triggerBtn?.element.find(e.target).length === 0;
}, },
listeners: [{ listeners: [
eventName: BI.Combo.EVENT_AFTER_HIDEVIEW, {
action: function () { eventName: Combo.EVENT_AFTER_HIDEVIEW,
self.trigger.stopEditing(); action () {
} self.trigger.stopEditing();
}, { },
eventName: BI.Combo.EVENT_BEFORE_POPUPVIEW, },
action: function () { {
self.fireEvent(BI.MultiLayerSingleTreeCombo.EVENT_BEFORE_POPUPVIEW); eventName: Combo.EVENT_BEFORE_POPUPVIEW,
action () {
self.fireEvent(MultiLayerSingleTreeCombo.EVENT_BEFORE_POPUPVIEW);
},
} }
}] ],
}; };
}, }
_getTriggerIconButton: function () { _getTriggerIconButton() {
var self = this, o = this.options; const self = this,
o = this.options;
return { return {
type: "bi.trigger_icon_button", type: TriggerIconButton.xtype,
cls: "bi-trigger trigger-icon-button", cls: "bi-trigger trigger-icon-button",
ref: function (_ref) { ref (_ref) {
self.triggerBtn = _ref; self.triggerBtn = _ref;
}, },
width: BI.toPix(o.height, 2), width: toPix(o.height, 2),
height: BI.toPix(o.height, 2), height: toPix(o.height, 2),
listeners: [ listeners: [
{ {
eventName: BI.TriggerIconButton.EVENT_CHANGE, eventName: TriggerIconButton.EVENT_CHANGE,
action: function () { action () {
if (self.combo.isViewVisible()) { if (self.combo.isViewVisible()) {
self.combo.hideView(); self.combo.hideView();
} else { } else {
self.combo.showView(); self.combo.showView();
} }
} },
} }
] ],
}; };
}, }
getSearcher: function () { getSearcher() {
return this.trigger ? this.trigger.getSearcher() : this.textTrigger.getTextor(); return this.trigger ? this.trigger.getSearcher() : this.textTrigger.getTextor();
}, }
setValue: function (v) { setValue(v) {
v = BI.isArray(v) ? v : [v]; v = isArray(v) ? v : [v];
this.combo.setValue(v); this.combo.setValue(v);
}, }
getValue: function () { getValue() {
return this.combo.getValue(); return this.combo.getValue();
}, }
setStatus: function (status) { setStatus(status) {
if (BI.isKey(this.options.status)) { if (isKey(this.options.status)) {
this.element.removeClass("status-" + this.options.status); this.element.removeClass(`status-${this.options.status}`);
} }
this.element.addClass("status-" + status); this.element.addClass(`status-${status}`);
this.options.status = status; this.options.status = status;
}, }
setTipType: function (v) { setTipType(v) {
this.trigger ? this.trigger.setTipType(v) : this.textTrigger.setTipType(v); this.trigger ? this.trigger.setTipType(v) : this.textTrigger.setTipType(v);
}, }
populate: function (items) { populate(items) {
this.combo.populate(items); this.combo.populate(items);
}, }
focus: function () { focus() {
this.trigger.focus(); this.trigger.focus();
}, }
blur: function () { blur() {
this.trigger.blur(); this.trigger.blur();
}, }
showView: function () { showView() {
this.combo.showView(); this.combo.showView();
}, }
setWaterMark: function (v) { setWaterMark(v) {
this.trigger.setWaterMark(v); this.trigger.setWaterMark(v);
} }
}); }
BI.MultiLayerSingleTreeCombo.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.MultiLayerSingleTreeCombo.EVENT_BLUR = "EVENT_BLUR";
BI.MultiLayerSingleTreeCombo.EVENT_FOCUS = "EVENT_FOCUS";
BI.MultiLayerSingleTreeCombo.EVENT_CHANGE = "EVENT_CHANGE";
BI.MultiLayerSingleTreeCombo.EVENT_STOP = "EVENT_STOP";
BI.MultiLayerSingleTreeCombo.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.shortcut("bi.multilayer_single_tree_combo", BI.MultiLayerSingleTreeCombo);

140
src/widget/multilayersingletree/multilayersingletree.insert.search.pane.js

@ -1,92 +1,110 @@
/** import {
* Created by GUY on 2016/1/26. shortcut,
* Widget,
* @class BI.MultiLayerSingleTreeInsertSearchPane i18nText,
* @extends BI.Pane emptyFn,
*/ createWidget,
Controller,
VerticalLayout,
isEmptyArray,
isArray
} from "@/core";
import { MultiLayerSelectLevelTree } from "../multilayerselecttree/multilayerselecttree.leveltree";
import { TextButton } from "@/base";
BI.MultiLayerSingleTreeInsertSearchPane = BI.inherit(BI.Widget, { @shortcut()
export class MultiLayerSingleTreeInsertSearchPane extends Widget {
static xtype = "bi.multilayer_single_tree_insert_search_pane";
props: function() { static EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
static EVENT_CHANGE = "EVENT_CHANGE";
props() {
return { return {
baseCls: "bi-multilayer-single-tree-popup", baseCls: "bi-multilayer-single-tree-popup",
tipText: BI.i18nText("BI-No_Selected_Item"), tipText: i18nText("BI-No_Selected_Item"),
isDefaultInit: false, isDefaultInit: false,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
items: [], items: [],
value: "" value: "",
}; };
}, }
render: function() { render() {
var self = this, o = this.options; const o = this.options;
this.tree = BI.createWidget({ this.tree = createWidget({
type: "bi.multilayer_single_level_tree", type: "bi.multilayer_single_level_tree",
isDefaultInit: o.isDefaultInit, isDefaultInit: o.isDefaultInit,
items: o.items, items: o.items,
itemsCreator: o.itemsCreator === BI.emptyFn ? BI.emptyFn : function (op, callback) { itemsCreator:
o.itemsCreator(op, function (res) { o.itemsCreator === emptyFn
callback(res); ? emptyFn
self.setKeyword(o.keywordGetter()); : (op, callback) => {
}); o.itemsCreator(op, res => {
}, callback(res);
this.setKeyword(o.keywordGetter());
});
},
keywordGetter: o.keywordGetter, keywordGetter: o.keywordGetter,
value: o.value, value: o.value,
scrollable: null, scrollable: null,
listeners: [{ listeners: [
eventName: BI.Controller.EVENT_CHANGE, {
action: function () { eventName: Controller.EVENT_CHANGE,
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); action: (...args) => {
} this.fireEvent(Controller.EVENT_CHANGE, ...args);
}, { },
eventName: BI.MultiLayerSelectLevelTree.EVENT_CHANGE, },
action: function () { {
self.fireEvent(BI.MultiLayerSingleTreeInsertSearchPane.EVENT_CHANGE); eventName: MultiLayerSelectLevelTree.EVENT_CHANGE,
action: () => {
this.fireEvent(MultiLayerSingleTreeInsertSearchPane.EVENT_CHANGE);
},
} }
}] ],
}); });
return { return {
type: "bi.vertical", type: VerticalLayout.xtype,
scrolly: false, scrolly: false,
scrollable: true, scrollable: true,
vgap: 5, vgap: 5,
items: [{ items: [
type: "bi.text_button", {
invisible: true, type: TextButton.xtype,
text: BI.i18nText("BI-Basic_Click_To_Add_Text", ""), invisible: true,
height: 24, text: i18nText("BI-Basic_Click_To_Add_Text", ""),
cls: "bi-high-light", height: 24,
hgap: 5, cls: "bi-high-light",
ref: function (_ref) { hgap: 5,
self.addNotMatchTip = _ref; ref: _ref => {
this.addNotMatchTip = _ref;
},
handler: () => {
this.fireEvent(MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM, o.keywordGetter());
},
}, },
handler: function () { this.tree
self.fireEvent(BI.MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM, o.keywordGetter()); ],
}
}, this.tree]
}; };
}, }
setKeyword: function (keyword) { setKeyword(keyword) {
var showTip = BI.isEmptyArray(this.tree.getAllLeaves()); const showTip = isEmptyArray(this.tree.getAllLeaves());
this.addNotMatchTip.setVisible(showTip); this.addNotMatchTip.setVisible(showTip);
showTip && this.addNotMatchTip.setText(BI.i18nText("BI-Basic_Click_To_Add_Text", keyword)); showTip && this.addNotMatchTip.setText(i18nText("BI-Basic_Click_To_Add_Text", keyword));
}, }
getValue: function () { getValue() {
return this.tree.getValue(); return this.tree.getValue();
}, }
setValue: function (v) { setValue(v) {
v = BI.isArray(v) ? v : [v]; v = isArray(v) ? v : [v];
this.tree.setValue(v); this.tree.setValue(v);
}, }
populate: function (items) { populate(items) {
this.tree.populate(items); this.tree.populate(items);
} }
}); }
BI.MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
BI.MultiLayerSingleTreeInsertSearchPane.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.multilayer_single_tree_insert_search_pane", BI.MultiLayerSingleTreeInsertSearchPane);

228
src/widget/multilayersingletree/multilayersingletree.leveltree.js

@ -1,170 +1,202 @@
/** import {
* guy shortcut,
* 二级树 extend,
* @class BI.MultiLayerSingleLevelTree emptyFn,
* @extends BI.Single Selection,
*/ each,
BI.MultiLayerSingleLevelTree = BI.inherit(BI.Pane, { isKey,
_defaultConfig: function () { UUID,
return BI.extend(BI.MultiLayerSingleLevelTree.superclass._defaultConfig.apply(this, arguments), { isNotEmptyArray,
defaults,
createWidget,
Tree,
nextTick,
Controller,
Events,
VerticalLayout,
AdaptiveLayout,
isNull,
isArray
} from "@/core";
import { Pane, CustomTree, Loader, ButtonTree } from "@/base";
import { BasicTreeNode, BasicTreeItem, TreeExpander } from "@/case";
@shortcut()
export class MultiLayerSingleLevelTree extends Pane {
static xtype = "bi.multilayer_single_level_tree";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multilayer-single-level-tree", baseCls: "bi-multilayer-single-level-tree",
isDefaultInit: false, isDefaultInit: false,
items: [], items: [],
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
keywordGetter: BI.emptyFn, keywordGetter: emptyFn,
chooseType: BI.Selection.Single, chooseType: Selection.Single,
scrollable: true scrollable: true,
}); });
}, }
_init: function () { _init() {
var o = this.options; const o = this.options;
BI.MultiLayerSingleLevelTree.superclass._init.apply(this, arguments); super._init(...arguments);
this.storeValue = o.value; this.storeValue = o.value;
this.initTree(this.options.items); this.initTree(this.options.items);
this.check(); this.check();
}, }
_formatItems: function (nodes, layer, pNode) { _formatItems(nodes, layer, pNode) {
var self = this, o = this.options; const self = this,
var keyword = o.keywordGetter(); o = this.options;
BI.each(nodes, function (i, node) { const keyword = o.keywordGetter();
var extend = { each(nodes, (i, node) => {
const extend = {
isFirstNode: i === 0, isFirstNode: i === 0,
isLastNode: i === nodes.length - 1, isLastNode: i === nodes.length - 1,
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
}; };
node.layer = layer; node.layer = layer;
if (!BI.isKey(node.id)) { if (!isKey(node.id)) {
node.id = BI.UUID(); node.id = UUID();
} }
node.keyword = node.keyword || keyword; node.keyword = node.keyword || keyword;
extend.pNode = pNode; extend.pNode = pNode;
if (node.isParent === true || node.parent === true || BI.isNotEmptyArray(node.children)) { if (node.isParent === true || node.parent === true || isNotEmptyArray(node.children)) {
extend.type = "bi.tree_node"; extend.type = BasicTreeNode.xtype;
extend.selectable = false; extend.selectable = false;
BI.defaults(node, extend); defaults(node, extend);
self._formatItems(node.children, layer + 1, node); self._formatItems(node.children, layer + 1, node);
} else { } else {
extend.type = "bi.tree_item"; extend.type = BasicTreeItem.xtype;
BI.defaults(node, extend); defaults(node, extend);
} }
}); });
return nodes; return nodes;
}, }
_assertId: function (sNodes) { _assertId(sNodes) {
BI.each(sNodes, function (i, node) { each(sNodes, (i, node) => {
node.id = node.id || BI.UUID(); node.id = node.id || UUID();
}); });
}, }
// 构造树结构, initTree(nodes) {
initTree: function (nodes) { const self = this,
var self = this, o = this.options; o = this.options;
var hasNext = false; let hasNext = false;
this.empty(); this.empty();
this._assertId(nodes); this._assertId(nodes);
this.tree = BI.createWidget({ this.tree = createWidget({
type: "bi.custom_tree", type: CustomTree.xtype,
cls: "tree-view display-table", cls: "tree-view display-table",
expander: { expander: {
type: "bi.tree_expander", type: TreeExpander.xtype,
isDefaultInit: o.isDefaultInit, isDefaultInit: o.isDefaultInit,
el: {}, el: {},
popup: { popup: {
type: "bi.custom_tree" type: CustomTree.xtype,
} },
}, },
items: this._formatItems(BI.Tree.transformToTreeFormat(nodes), 0), items: this._formatItems(Tree.transformToTreeFormat(nodes), 0),
value: o.value, value: o.value,
itemsCreator: function (op, callback) { itemsCreator (op, callback) {
(op.times === 1 && !op.node) && BI.nextTick(function () { op.times === 1 &&
self.loading(); !op.node &&
}); nextTick(() => {
o.itemsCreator(op, function (ob) { self.loading();
});
o.itemsCreator(op, ob => {
hasNext = ob.hasNext; hasNext = ob.hasNext;
(op.times === 1 && !op.node) && self._populate(ob.items); op.times === 1 && !op.node && self._populate(ob.items);
callback(self._formatItems(BI.Tree.transformToTreeFormat(ob.items), op.node ? op.node.layer + 1 : 0, op.node)); callback(
self._formatItems(
Tree.transformToTreeFormat(ob.items),
op.node ? op.node.layer + 1 : 0,
op.node
)
);
self.setValue(self.storeValue); self.setValue(self.storeValue);
(op.times === 1 && !op.node) && BI.nextTick(function () { op.times === 1 &&
self.loaded(); !op.node &&
}); nextTick(() => {
self.loaded();
});
}); });
}, },
el: { el: {
type: "bi.loader", type: Loader.xtype,
isDefaultInit: o.itemsCreator !== BI.emptyFn, isDefaultInit: o.itemsCreator !== emptyFn,
el: { el: {
type: "bi.button_tree", type: ButtonTree.xtype,
chooseType: o.chooseType === BI.Selection.None ? BI.Selection.None : BI.Selection.Default, // 不使用buttontree内部getValue逻辑 chooseType: o.chooseType === Selection.None ? Selection.None : Selection.Default, // 不使用buttontree内部getValue逻辑
behaviors: o.behaviors, behaviors: o.behaviors,
layouts: [{ layouts: [
type: "bi.vertical" {
}] type: VerticalLayout.xtype,
}
],
}, },
hasNext: function () { hasNext () {
return hasNext; return hasNext;
} },
} },
}); });
this.tree.on(BI.Controller.EVENT_CHANGE, function (type, v) { this.tree.on(Controller.EVENT_CHANGE, function (type, v) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
if (type === BI.Events.CLICK) { if (type === Events.CLICK) {
self.setValue(v); self.setValue(v);
self.fireEvent(BI.MultiLayerSingleLevelTree.EVENT_CHANGE, v); self.fireEvent(MultiLayerSingleLevelTree.EVENT_CHANGE, v);
} }
}); });
BI.createWidget({ createWidget({
type: "bi.adaptive", type: AdaptiveLayout.xtype,
element: this, element: this,
scrollable: o.scrollable, scrollable: o.scrollable,
items: [this.tree] items: [this.tree],
}); });
}, }
_populate: function () { _populate() {
BI.MultiLayerSelectLevelTree.superclass.populate.apply(this, arguments); super.populate(...arguments);
}, }
populate: function (nodes) { populate(nodes) {
this._populate(nodes); this._populate(nodes);
BI.isNull(nodes) ? this.tree.populate() : this.tree.populate(this._formatItems(BI.Tree.transformToTreeFormat(nodes), 0)); isNull(nodes)
}, ? this.tree.populate()
: this.tree.populate(this._formatItems(Tree.transformToTreeFormat(nodes), 0));
}
setValue: function (v) { setValue(v) {
// getValue依赖于storeValue, 那么不选的时候就不要更新storeValue了 // getValue依赖于storeValue, 那么不选的时候就不要更新storeValue了
if (this.options.chooseType === BI.Selection.None) { if (this.options.chooseType !== Selection.None) {
} else {
this.storeValue = v; this.storeValue = v;
this.tree.setValue(v); this.tree.setValue(v);
} }
}, }
getValue: function () { getValue() {
return BI.isArray(this.storeValue) ? return isArray(this.storeValue) ? this.storeValue : isNull(this.storeValue) ? [] : [this.storeValue];
this.storeValue : BI.isNull(this.storeValue) ? }
[] : [this.storeValue];
},
getAllLeaves: function () { getAllLeaves() {
return this.tree.getAllLeaves(); return this.tree.getAllLeaves();
}, }
getNodeById: function (id) { getNodeById(id) {
return this.tree.getNodeById(id); return this.tree.getNodeById(id);
}, }
getNodeByValue: function (id) { getNodeByValue(id) {
return this.tree.getNodeByValue(id); return this.tree.getNodeByValue(id);
} }
}); }
BI.MultiLayerSingleLevelTree.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.multilayer_single_level_tree", BI.MultiLayerSingleLevelTree);

79
src/widget/multilayersingletree/multilayersingletree.popup.js

@ -1,76 +1,73 @@
/** import { shortcut, Widget, extend, i18nText, emptyFn, createWidget, Controller, VerticalLayout, isArray, pixFormat } from "@/core";
* Created by GUY on 2016/1/26. import { MultiLayerSingleLevelTree } from "./multilayersingletree.leveltree";
*
* @class BI.MultiLayerSingleTreePopup
* @extends BI.Pane
*/
BI.MultiLayerSingleTreePopup = BI.inherit(BI.Widget, { @shortcut()
export class MultiLayerSingleTreePopup extends Widget {
static xtype = "bi.multilayer_single_tree_popup";
_defaultConfig: function () { static EVENT_CHANGE = "EVENT_CHANGE";
return BI.extend(BI.MultiLayerSingleTreePopup.superclass._defaultConfig.apply(this, arguments), {
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-multilayer-singletree-popup", baseCls: "bi-multilayer-singletree-popup",
tipText: BI.i18nText("BI-No_Selected_Item"), tipText: i18nText("BI-No_Selected_Item"),
isDefaultInit: false, isDefaultInit: false,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
items: [], items: [],
onLoaded: BI.emptyFn, onLoaded: emptyFn,
minHeight: 240 minHeight: 240,
}); });
}, }
_init: function () { _init() {
BI.MultiLayerSingleTreePopup.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
this.tree = BI.createWidget({ this.tree = createWidget({
type: "bi.multilayer_single_level_tree", type: MultiLayerSingleLevelTree.xtype,
isDefaultInit: o.isDefaultInit, isDefaultInit: o.isDefaultInit,
items: o.items, items: o.items,
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
keywordGetter: o.keywordGetter, keywordGetter: o.keywordGetter,
value: o.value, value: o.value,
scrollable: null, scrollable: null,
onLoaded: function () { onLoaded: () => {
self.tree.check(); this.tree.check();
o.onLoaded(); o.onLoaded();
} },
}); });
BI.createWidget({ createWidget({
type: "bi.vertical", type: VerticalLayout.xtype,
scrolly: false, scrolly: false,
scrollable: true, scrollable: true,
element: this, element: this,
vgap: 5, vgap: 5,
items: [this.tree] items: [this.tree],
}); });
this.tree.on(BI.Controller.EVENT_CHANGE, function () { this.tree.on(Controller.EVENT_CHANGE, (...args) => {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); this.fireEvent(Controller.EVENT_CHANGE, ...args);
}); });
this.tree.on(BI.MultiLayerSingleLevelTree.EVENT_CHANGE, function () { this.tree.on(MultiLayerSingleLevelTree.EVENT_CHANGE, () => {
self.fireEvent(BI.MultiLayerSingleTreePopup.EVENT_CHANGE); this.fireEvent(MultiLayerSingleTreePopup.EVENT_CHANGE);
}); });
this.tree.css("min-height", BI.pixFormat(o.minHeight - 10)); this.tree.css("min-height", pixFormat(o.minHeight - 10));
}, }
getValue: function () { getValue() {
return this.tree.getValue(); return this.tree.getValue();
}, }
setValue: function (v) { setValue(v) {
v = BI.isArray(v) ? v : [v]; v = isArray(v) ? v : [v];
this.tree.setValue(v); this.tree.setValue(v);
}, }
populate: function (items) { populate(items) {
this.tree.populate(items); this.tree.populate(items);
} }
}); }
BI.MultiLayerSingleTreePopup.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.multilayer_single_tree_popup", BI.MultiLayerSingleTreePopup);

311
src/widget/multilayersingletree/multilayersingletree.trigger.js

@ -1,237 +1,282 @@
/** import {
* Created by Windy on 2018/2/2. shortcut,
*/ emptyFn,
BI.MultiLayerSingleTreeTrigger = BI.inherit(BI.Trigger, { i18nText,
bind,
isNotNull,
isKey,
HorizontalFillLayout,
Tree,
deepClone,
Func,
concat,
isNotEmptyArray,
each,
uniqBy,
map,
isFunction,
find
} from "@/core";
import { Trigger, Searcher } from "@/base";
import { StateEditor, DefaultTextEditor } from "@/case";
import { MultiLayerSingleTreeInsertSearchPane } from "./multilayersingletree.insert.search.pane";
import { MultiLayerSingleTreePopup } from "./multilayersingletree.popup";
props: function () { @shortcut()
export class MultiLayerSingleTreeTrigger extends Trigger {
static xtype = "bi.multilayer_single_tree_trigger";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
static EVENT_SEARCHING = "EVENT_SEARCHING";
static EVENT_STOP = "EVENT_STOP";
static EVENT_START = "EVENT_START";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
props() {
return { return {
extraCls: "bi-multi-layer-single-tree-trigger", extraCls: "bi-multi-layer-single-tree-trigger",
height: 24, height: 24,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
watermark: BI.i18nText("BI-Basic_Search"), watermark: i18nText("BI-Basic_Search"),
allowSearchValue: false, allowSearchValue: false,
title: BI.bind(this._getShowText, this) title: bind(this._getShowText, this),
}; };
}, }
render: function () { render() {
var self = this, o = this.options; const self = this,
if (o.itemsCreator === BI.emptyFn) { o = this.options;
if (o.itemsCreator === emptyFn) {
this._initData(); this._initData();
} }
return { return {
type: "bi.horizontal_fill", type: HorizontalFillLayout.xtype,
items: [ items: [
{ {
el: { el: {
type: "bi.searcher", type: Searcher.xtype,
ref: function () { ref () {
self.searcher = this; self.searcher = this;
}, },
masker: BI.isNotNull(o.container) ? { masker: isNotNull(o.container)
offset: {}, ? {
container: o.container offset: {},
} : { container: o.container,
offset: {} }
}, : {
offset: {},
},
isAutoSearch: false, isAutoSearch: false,
el: { el: {
type: "bi.default_text_editor", type: DefaultTextEditor.xtype,
ref: function () { ref () {
self.editor = this; self.editor = this;
}, },
defaultText: o.defaultText, defaultText: o.defaultText,
text: BI.isKey(o.value) ? this._digest(o.value) : o.text, text: isKey(o.value) ? this._digest(o.value) : o.text,
value: o.value, value: o.value,
height: o.height, height: o.height,
tipText: "", tipText: "",
watermark: o.watermark, watermark: o.watermark,
listeners: [{ listeners: [
eventName: BI.StateEditor.EVENT_FOCUS, {
action: function () { eventName: StateEditor.EVENT_FOCUS,
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_FOCUS); action () {
} self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_FOCUS);
}, { },
eventName: BI.StateEditor.EVENT_BLUR, },
action: function () { {
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_BLUR); eventName: StateEditor.EVENT_BLUR,
action () {
self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_BLUR);
},
},
{
eventName: StateEditor.EVENT_CHANGE,
action () {
self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_SEARCHING);
},
} }
}, { ],
eventName: BI.StateEditor.EVENT_CHANGE,
action: function () {
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_SEARCHING);
}
}]
}, },
popup: { popup: {
type: o.allowInsertValue ? "bi.multilayer_single_tree_insert_search_pane" : "bi.multilayer_single_tree_popup", type: o.allowInsertValue
itemsCreator: o.itemsCreator === BI.emptyFn ? BI.emptyFn : function (op, callback) { ? MultiLayerSingleTreeInsertSearchPane.xtype
op.keyword = self.editor.getValue(); : MultiLayerSingleTreePopup.xtype,
o.itemsCreator(op, callback); itemsCreator:
}, o.itemsCreator === emptyFn
keywordGetter: function () { ? emptyFn
: function (op, callback) {
op.keyword = self.editor.getValue();
o.itemsCreator(op, callback);
},
keywordGetter () {
return self.editor.getValue(); return self.editor.getValue();
}, },
cls: "bi-card", cls: "bi-card",
listeners: [{ listeners: [
eventName: BI.MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM, {
action: function () { eventName: MultiLayerSingleTreeInsertSearchPane.EVENT_ADD_ITEM,
self.options.text = self.getSearcher().getKeyword(); action () {
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM); self.options.text = self.getSearcher().getKeyword();
self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM);
},
} }
}], ],
ref: function (_ref) { ref (_ref) {
self.popup = _ref; self.popup = _ref;
} },
}, },
onSearch: function (obj, callback) { onSearch (obj, callback) {
var keyword = obj.keyword; const keyword = obj.keyword;
if (o.itemsCreator === BI.emptyFn) { if (o.itemsCreator === emptyFn) {
callback(self._getSearchItems(keyword)); callback(self._getSearchItems(keyword));
o.allowInsertValue && self.popup.setKeyword(keyword); o.allowInsertValue && self.popup.setKeyword(keyword);
} else { } else {
callback(); callback();
} }
}, },
listeners: [{ listeners: [
eventName: BI.Searcher.EVENT_CHANGE, {
action: function () { eventName: Searcher.EVENT_CHANGE,
self.fireEvent(BI.MultiLayerSingleTreeTrigger.EVENT_CHANGE); action () {
self.fireEvent(MultiLayerSingleTreeTrigger.EVENT_CHANGE);
},
} }
}] ],
}, },
width: "fill", width: "fill",
rgap: 24, rgap: 24,
}, }
] ],
}; };
}, }
_initData: function () { _initData() {
var o = this.options; const o = this.options;
this.tree = new BI.Tree(); this.tree = new Tree();
this.nodes = BI.Tree.treeFormat(BI.deepClone(o.items)); this.nodes = Tree.treeFormat(deepClone(o.items));
this.tree.initTree(this.nodes); this.tree.initTree(this.nodes);
}, }
_getSearchItems: function (keyword) { _getSearchItems(keyword) {
var self = this, o = this.options; const self = this,
o = this.options;
// 把数组搜索换成用BI.tree搜索节点, 搜到了就不再往下搜索 // 把数组搜索换成用BI.tree搜索节点, 搜到了就不再往下搜索
var items = []; const items = [];
this.tree.traverse(function (node) { this.tree.traverse(node => {
var find = BI.Func.getSearchResult(self.tree.isRoot(node) ? [] : BI.concat([node.text], (o.allowSearchValue ? [node.value] : [])), keyword); const find = Func.getSearchResult(
self.tree.isRoot(node) ? [] : concat([node.text], o.allowSearchValue ? [node.value] : []),
keyword
);
if (find.find.length > 0 || find.match.length > 0) { if (find.find.length > 0 || find.match.length > 0) {
items.push(node); items.push(node);
return true; return true;
} }
}); });
return this._fillTreeStructure4Search(items, "id"); return this._fillTreeStructure4Search(items, "id");
}, }
_createJson: function (node, open) { _createJson(node, open) {
return { return {
id: node.id, id: node.id,
pId: node.pId, pId: node.pId,
text: node.text, text: node.text,
value: node.value, value: node.value,
isParent: BI.isNotEmptyArray(node.children), isParent: isNotEmptyArray(node.children),
open: open open,
}; };
}, }
_getChildren: function (node) { _getChildren(node) {
var self = this; const self = this;
node.children = node.children || []; node.children = node.children || [];
var nodes = []; let nodes = [];
BI.each(node.children, function (idx, child) { each(node.children, (idx, child) => {
var children = self._getChildren(child); const children = self._getChildren(child);
nodes = nodes.concat(children); nodes = nodes.concat(children);
}); });
return node.children.concat(nodes); return node.children.concat(nodes);
}, }
// 将搜索到的节点进行补充,构造成一棵完整的树 _fillTreeStructure4Search(leaves) {
_fillTreeStructure4Search: function (leaves) { const self = this;
var self = this; let result = [];
var result = []; const queue = [];
var queue = []; each(leaves, (idx, node) => {
BI.each(leaves, function (idx, node) {
queue.push({ pId: node.pId }); queue.push({ pId: node.pId });
result.push(node); result.push(node);
result = result.concat(self._getChildren(node)); result = result.concat(self._getChildren(node));
}); });
queue.reverse(); queue.reverse();
while (BI.isNotEmptyArray(queue)) { while (isNotEmptyArray(queue)) {
var node = queue.pop(); const node = queue.pop();
var pNode = this.tree.search(this.tree.getRoot(), node.pId, "id"); const pNode = this.tree.search(this.tree.getRoot(), node.pId, "id");
if (pNode != null) { if (pNode != null) {
pNode.open = true; pNode.open = true;
queue.push({ pId: pNode.pId }); queue.push({ pId: pNode.pId });
result.push(pNode); result.push(pNode);
} }
} }
return BI.uniqBy(BI.map(result, function (idx, node) {
return self._createJson(node, node.open); return uniqBy(
}), "id"); map(result, (idx, node) => self._createJson(node, node.open)),
}, "id"
);
}
_digest: function (v) { _digest(v) {
var o = this.options; const o = this.options;
if (BI.isFunction(o.valueFormatter)) { if (isFunction(o.valueFormatter)) {
return o.valueFormatter(v); return o.valueFormatter(v);
} }
var result = BI.find(o.items, function (i, item) { const result = find(o.items, (i, item) => item.value === v);
return item.value === v;
});
return BI.isNotNull(result) ? result.text : (o.text ?? v); return isNotNull(result) ? result.text : o.text ?? v;
}, }
_getShowText: function () { _getShowText() {
return this.editor.getText(); return this.editor.getText();
}, }
stopEditing: function () { stopEditing() {
this.searcher.stopSearch(); this.searcher.stopSearch();
}, }
getSearcher: function () { getSearcher() {
return this.searcher; return this.searcher;
}, }
populate: function (items) { populate(items) {
this.options.items = items; this.options.items = items;
this._initData(); this._initData();
}, }
setValue: function (v) { setValue(v) {
this.editor.setState(this._digest(v[0])); this.editor.setState(this._digest(v[0]));
}, }
getValue: function () { getValue() {
return this.searcher.getValue(); return this.searcher.getValue();
}, }
focus: function () { focus() {
this.searcher.focus(); this.searcher.focus();
}, }
blur: function () { blur() {
this.searcher.blur(); this.searcher.blur();
}, }
setWaterMark: function (v) { setWaterMark(v) {
this.searcher.setWaterMark(v); this.searcher.setWaterMark(v);
} }
}); }
BI.MultiLayerSingleTreeTrigger.EVENT_FOCUS = "EVENT_FOCUS";
BI.MultiLayerSingleTreeTrigger.EVENT_BLUR = "EVENT_BLUR";
BI.MultiLayerSingleTreeTrigger.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.MultiLayerSingleTreeTrigger.EVENT_STOP = "EVENT_STOP";
BI.MultiLayerSingleTreeTrigger.EVENT_START = "EVENT_START";
BI.MultiLayerSingleTreeTrigger.EVENT_CHANGE = "EVENT_CHANGE";
BI.MultiLayerSingleTreeTrigger.EVENT_ADD_ITEM = "EVENT_ADD_ITEM";
BI.shortcut("bi.multilayer_single_tree_trigger", BI.MultiLayerSingleTreeTrigger);

4
src/widget/multilayersingletree/node/index.js

@ -0,0 +1,4 @@
export { MultiLayerSingleTreeFirstPlusGroupNode } from "./node.first.plus";
export { MultiLayerSingleTreeLastPlusGroupNode } from "./node.last.plus";
export { MultiLayerSingleTreeMidPlusGroupNode } from "./node.mid.plus";
export { MultiLayerSingleTreePlusGroupNode } from "./node.plus";

117
src/widget/multilayersingletree/node/node.first.plus.js

@ -1,69 +1,80 @@
/** import {
* 加号表示的组节点 shortcut,
* extend,
* Created by GUY on 2016/1/27. createWidget,
* @class BI.MultiLayerSingleTreeFirstPlusGroupNode makeArray,
* @extends BI.NodeButton HorizontalAdaptLayout,
*/ isNotNull,
BI.MultiLayerSingleTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, { Controller,
_defaultConfig: function () { Events
var conf = BI.MultiLayerSingleTreeFirstPlusGroupNode.superclass._defaultConfig.apply(this, arguments); } from "@/core";
return BI.extend(conf, { import { NodeButton } from "@/base";
import { FirstPlusGroupNode } from "@/case";
@shortcut()
export class MultiLayerSingleTreeFirstPlusGroupNode extends NodeButton {
static xtype = "bi.multilayer_single_tree_first_plus_group_node";
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
extraCls: "bi-multilayer-single-tree-first-plus-group-node bi-list-item", extraCls: "bi-multilayer-single-tree-first-plus-group-node bi-list-item",
layer: 0, // 第几层级 layer: 0, // 第几层级
id: "", id: "",
pId: "", pId: "",
open: false, open: false,
height: 24 height: 24,
}); });
}, }
_init: function () {
BI.MultiLayerSingleTreeFirstPlusGroupNode.superclass._init.apply(this, arguments); _init() {
var self = this, o = this.options; super._init(...arguments);
const o = this.options;
this.node = this._createNode(); this.node = this._createNode();
var items = []; const items = [];
items.push({ items.push({
el: this.node, el: this.node,
lgap: o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2 lgap: (o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT) / 2,
}); });
BI.createWidget({ createWidget({
type: "bi.horizontal_adapt", type: HorizontalAdaptLayout.xtype,
element: this, element: this,
columnSize: BI.makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2), columnSize: makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2),
items: items items,
}); });
}, }
doRedMark: function () { doRedMark() {
this.node.doRedMark.apply(this.node, arguments); this.node.doRedMark(...arguments);
}, }
unRedMark: function () { unRedMark() {
this.node.unRedMark.apply(this.node, arguments); this.node.unRedMark(...arguments);
}, }
doClick: function () { doClick() {
BI.MultiLayerSingleTreeFirstPlusGroupNode.superclass.doClick.apply(this, arguments); super.doClick(...arguments);
this.node.setSelected(this.isSelected()); this.node.setSelected(this.isSelected());
}, }
setOpened: function (v) { setOpened(v) {
BI.MultiLayerSingleTreeFirstPlusGroupNode.superclass.setOpened.apply(this, arguments); super.setOpened(...arguments);
if (BI.isNotNull(this.node)) { if (isNotNull(this.node)) {
this.node.setOpened(v); this.node.setOpened(v);
} }
}, }
_createNode: function () { _createNode() {
var self = this, o = this.options; const o = this.options;
return BI.createWidget({ return createWidget({
type: "bi.first_plus_group_node", type: FirstPlusGroupNode.xtype,
cls: "bi-list-item-none", cls: "bi-list-item-none",
logic: { logic: {
dynamic: true dynamic: true,
}, },
id: o.id, id: o.id,
pId: o.pId, pId: o.pId,
@ -75,17 +86,19 @@ BI.MultiLayerSingleTreeFirstPlusGroupNode = BI.inherit(BI.NodeButton, {
value: o.value, value: o.value,
py: o.py, py: o.py,
keyword: o.keyword, keyword: o.keyword,
listeners: [{ listeners: [
eventName: BI.Controller.EVENT_CHANGE, {
action: function (type) { eventName: Controller.EVENT_CHANGE,
if (type === BI.Events.CLICK) {// 本身实现click功能 action: (...args) => {
return; const [type] = args;
} if (type === Events.CLICK) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); // 本身实现click功能
return;
}
this.fireEvent(Controller.EVENT_CHANGE, ...args);
},
} }
}] ],
}); });
} }
}); }
BI.shortcut("bi.multilayer_single_tree_first_plus_group_node", BI.MultiLayerSingleTreeFirstPlusGroupNode);

117
src/widget/multilayersingletree/node/node.last.plus.js

@ -1,69 +1,80 @@
/** import {
* 加号表示的组节点 shortcut,
* extend,
* Created by GUY on 2016/1/27. createWidget,
* @class BI.MultiLayerSingleTreeLastPlusGroupNode makeArray,
* @extends BI.NodeButton HorizontalAdaptLayout,
*/ isNotNull,
BI.MultiLayerSingleTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, { Controller,
_defaultConfig: function () { Events
var conf = BI.MultiLayerSingleTreeLastPlusGroupNode.superclass._defaultConfig.apply(this, arguments); } from "@/core";
return BI.extend(conf, { import { NodeButton } from "@/base";
import { LastPlusGroupNode } from "@/case";
@shortcut()
export class MultiLayerSingleTreeLastPlusGroupNode extends NodeButton {
static xtype = "bi.multilayer_single_tree_last_plus_group_node";
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
extraCls: "bi-multilayer-single-tree-last-plus-group-node bi-list-item", extraCls: "bi-multilayer-single-tree-last-plus-group-node bi-list-item",
layer: 0, // 第几层级 layer: 0, // 第几层级
id: "", id: "",
pId: "", pId: "",
open: false, open: false,
height: 24 height: 24,
}); });
}, }
_init: function () {
BI.MultiLayerSingleTreeLastPlusGroupNode.superclass._init.apply(this, arguments); _init() {
var self = this, o = this.options; super._init(...arguments);
const o = this.options;
this.node = this._createNode(); this.node = this._createNode();
var items = []; const items = [];
items.push({ items.push({
el: this.node, el: this.node,
lgap: o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2 lgap: (o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT) / 2,
}); });
BI.createWidget({ createWidget({
type: "bi.horizontal_adapt", type: HorizontalAdaptLayout.xtype,
element: this, element: this,
columnSize: BI.makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2), columnSize: makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2),
items: items items,
}); });
}, }
doRedMark: function () { doRedMark() {
this.node.doRedMark.apply(this.node, arguments); this.node.doRedMark(...arguments);
}, }
unRedMark: function () { unRedMark() {
this.node.unRedMark.apply(this.node, arguments); this.node.unRedMark(...arguments);
}, }
doClick: function () { doClick() {
BI.MultiLayerSingleTreeLastPlusGroupNode.superclass.doClick.apply(this, arguments); super.doClick(...arguments);
this.node.setSelected(this.isSelected()); this.node.setSelected(this.isSelected());
}, }
setOpened: function (v) { setOpened(v) {
BI.MultiLayerSingleTreeLastPlusGroupNode.superclass.setOpened.apply(this, arguments); super.setOpened(...arguments);
if (BI.isNotNull(this.node)) { if (isNotNull(this.node)) {
this.node.setOpened(v); this.node.setOpened(v);
} }
}, }
_createNode: function () { _createNode() {
var self = this, o = this.options; const o = this.options;
return BI.createWidget({ return createWidget({
type: "bi.last_plus_group_node", type: LastPlusGroupNode.xtype,
cls: "bi-list-item-none", cls: "bi-list-item-none",
logic: { logic: {
dynamic: true dynamic: true,
}, },
id: o.id, id: o.id,
pId: o.pId, pId: o.pId,
@ -74,17 +85,19 @@ BI.MultiLayerSingleTreeLastPlusGroupNode = BI.inherit(BI.NodeButton, {
value: o.value, value: o.value,
py: o.py, py: o.py,
keyword: o.keyword, keyword: o.keyword,
listeners: [{ listeners: [
eventName: BI.Controller.EVENT_CHANGE, {
action: function (type) { eventName: Controller.EVENT_CHANGE,
if (type === BI.Events.CLICK) {// 本身实现click功能 action: (...args) => {
return; const [type] = args;
} if (type === Events.CLICK) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); // 本身实现click功能
return;
}
this.fireEvent(Controller.EVENT_CHANGE, ...args);
},
} }
}] ],
}); });
} }
}); }
BI.shortcut("bi.multilayer_single_tree_last_plus_group_node", BI.MultiLayerSingleTreeLastPlusGroupNode);

117
src/widget/multilayersingletree/node/node.mid.plus.js

@ -1,69 +1,80 @@
/** import {
* 加号表示的组节点 shortcut,
* extend,
* Created by GUY on 2016/1/27. createWidget,
* @class BI.MultiLayerSingleTreeMidPlusGroupNode makeArray,
* @extends BI.NodeButton HorizontalAdaptLayout,
*/ isNotNull,
BI.MultiLayerSingleTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, { Controller,
_defaultConfig: function () { Events
var conf = BI.MultiLayerSingleTreeMidPlusGroupNode.superclass._defaultConfig.apply(this, arguments); } from "@/core";
return BI.extend(conf, { import { NodeButton } from "@/base";
import { MidPlusGroupNode } from "@/case";
@shortcut()
export class MultiLayerSingleTreeMidPlusGroupNode extends NodeButton {
static xtype = "bi.multilayer_single_tree_mid_plus_group_node";
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
extraCls: "bi-multilayer-single-tree-mid-plus-group-node bi-list-item", extraCls: "bi-multilayer-single-tree-mid-plus-group-node bi-list-item",
layer: 0, // 第几层级 layer: 0, // 第几层级
id: "", id: "",
pId: "", pId: "",
open: false, open: false,
height: 24 height: 24,
}); });
}, }
_init: function () {
BI.MultiLayerSingleTreeMidPlusGroupNode.superclass._init.apply(this, arguments); _init() {
var self = this, o = this.options; super._init(...arguments);
const o = this.options;
this.node = this._createNode(); this.node = this._createNode();
var items = []; const items = [];
items.push({ items.push({
el: this.node, el: this.node,
lgap: o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2 lgap: (o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT) / 2,
}); });
BI.createWidget({ createWidget({
type: "bi.horizontal_adapt", type: HorizontalAdaptLayout.xtype,
element: this, element: this,
columnSize: BI.makeArray(o.layer, 12), columnSize: makeArray(o.layer, 12),
items: items items,
}); });
}, }
doRedMark: function () { doRedMark() {
this.node.doRedMark.apply(this.node, arguments); this.node.doRedMark(...arguments);
}, }
unRedMark: function () { unRedMark() {
this.node.unRedMark.apply(this.node, arguments); this.node.unRedMark(...arguments);
}, }
doClick: function () { doClick() {
BI.MultiLayerSingleTreeMidPlusGroupNode.superclass.doClick.apply(this, arguments); super.doClick(...arguments);
this.node.setSelected(this.isSelected()); this.node.setSelected(this.isSelected());
}, }
setOpened: function (v) { setOpened(v) {
BI.MultiLayerSingleTreeMidPlusGroupNode.superclass.setOpened.apply(this, arguments); super.setOpened(...arguments);
if (BI.isNotNull(this.node)) { if (isNotNull(this.node)) {
this.node.setOpened(v); this.node.setOpened(v);
} }
}, }
_createNode: function () { _createNode() {
var self = this, o = this.options; const o = this.options;
return BI.createWidget({ return createWidget({
type: "bi.mid_plus_group_node", type: MidPlusGroupNode.xtype,
cls: "bi-list-item-none", cls: "bi-list-item-none",
logic: { logic: {
dynamic: true dynamic: true,
}, },
id: o.id, id: o.id,
pId: o.pId, pId: o.pId,
@ -74,17 +85,19 @@ BI.MultiLayerSingleTreeMidPlusGroupNode = BI.inherit(BI.NodeButton, {
value: o.value, value: o.value,
py: o.py, py: o.py,
keyword: o.keyword, keyword: o.keyword,
listeners: [{ listeners: [
eventName: BI.Controller.EVENT_CHANGE, {
action: function (type) { eventName: Controller.EVENT_CHANGE,
if (type === BI.Events.CLICK) {// 本身实现click功能 action: (...args) => {
return; const [type] = args;
} if (type === Events.CLICK) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); // 本身实现click功能
return;
}
this.fireEvent(Controller.EVENT_CHANGE, ...args);
},
} }
}] ],
}); });
} }
}); }
BI.shortcut("bi.multilayer_single_tree_mid_plus_group_node", BI.MultiLayerSingleTreeMidPlusGroupNode);

130
src/widget/multilayersingletree/node/node.plus.js

@ -1,80 +1,96 @@
/** import {
*@desc 根节点,既是第一个又是最后一个 shortcut,
*@author dailer extend,
*@date 2018/09/16 count,
*/ contains,
BI.MultiLayerSingleTreePlusGroupNode = BI.inherit(BI.NodeButton, { createWidget,
_defaultConfig: function () { makeArray,
var conf = BI.MultiLayerSingleTreePlusGroupNode.superclass._defaultConfig.apply(this, arguments); Layout,
return BI.extend(conf, { HorizontalAdaptLayout,
isNotNull,
Controller,
Events
} from "@/core";
import { NodeButton } from "@/base";
import { PlusGroupNode } from "@/case";
@shortcut()
export class MultiLayerSingleTreePlusGroupNode extends NodeButton {
static xtype = "bi.multilayer_single_tree_plus_group_node";
_defaultConfig() {
const conf = super._defaultConfig(...arguments);
return extend(conf, {
extraCls: "bi-multilayer-single-tree-plus-group-node bi-list-item", extraCls: "bi-multilayer-single-tree-plus-group-node bi-list-item",
layer: 0, // 第几层级 layer: 0, // 第几层级
id: "", id: "",
pId: "", pId: "",
open: false, open: false,
height: 24 height: 24,
}); });
}, }
_init: function () {
BI.MultiLayerSingleTreePlusGroupNode.superclass._init.apply(this, arguments); _init() {
var self = this, o = this.options; super._init(...arguments);
const o = this.options;
this.node = this._createNode(); this.node = this._createNode();
var needBlankLayers = []; const needBlankLayers = [];
var pNode = o.pNode; let pNode = o.pNode;
while (pNode) { while (pNode) {
if (pNode.isLastNode) { if (pNode.isLastNode) {
needBlankLayers.push(pNode.layer) needBlankLayers.push(pNode.layer);
} }
pNode = pNode.pNode; pNode = pNode.pNode;
} }
var items = []; const items = [];
BI.count(0, o.layer, function (index) { count(0, o.layer, index => {
items.push({ items.push({
type: "bi.layout", type: Layout.xtype,
cls: BI.contains(needBlankLayers, index) ? "" : "base-line-conn-background", cls: contains(needBlankLayers, index) ? "" : "base-line-conn-background",
width: 12, width: 12,
height: o.height height: o.height,
}); });
}); });
items.push(this.node); items.push(this.node);
BI.createWidget({ createWidget({
type: "bi.horizontal_adapt", type: HorizontalAdaptLayout.xtype,
element: this, element: this,
columnSize: BI.makeArray(o.layer, 12), columnSize: makeArray(o.layer, 12),
items: items items,
}); });
}, }
doRedMark: function () { doRedMark() {
this.node.doRedMark.apply(this.node, arguments); this.node.doRedMark(...arguments);
}, }
unRedMark: function () { unRedMark() {
this.node.unRedMark.apply(this.node, arguments); this.node.unRedMark(...arguments);
}, }
doClick: function () { doClick() {
BI.MultiLayerSingleTreePlusGroupNode.superclass.doClick.apply(this, arguments); super.doClick(...arguments);
this.node.setSelected(this.isSelected()); this.node.setSelected(this.isSelected());
}, }
setOpened: function (v) { setOpened(v) {
BI.MultiLayerSingleTreePlusGroupNode.superclass.setOpened.apply(this, arguments); super.setOpened(...arguments);
if (BI.isNotNull(this.node)) { if (isNotNull(this.node)) {
this.node.setOpened(v); this.node.setOpened(v);
} }
}, }
_createNode: function () { _createNode() {
var self = this, o = this.options; const o = this.options;
return BI.createWidget({ return createWidget({
type: "bi.plus_group_node", type: PlusGroupNode.xtype,
cls: "bi-list-item-none", cls: "bi-list-item-none",
logic: { logic: {
dynamic: true dynamic: true,
}, },
id: o.id, id: o.id,
pId: o.pId, pId: o.pId,
@ -86,17 +102,19 @@ BI.MultiLayerSingleTreePlusGroupNode = BI.inherit(BI.NodeButton, {
value: o.value, value: o.value,
py: o.py, py: o.py,
keyword: o.keyword, keyword: o.keyword,
listeners: [{ listeners: [
eventName: BI.Controller.EVENT_CHANGE, {
action: function (type) { eventName: Controller.EVENT_CHANGE,
if (type === BI.Events.CLICK) {// 本身实现click功能 action: (...args) => {
return; const [type] = args;
} if (type === Events.CLICK) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); // 本身实现click功能
return;
}
this.fireEvent(Controller.EVENT_CHANGE, ...args);
},
} }
}] ],
}); });
} }
}); }
BI.shortcut("bi.multilayer_single_tree_plus_group_node", BI.MultiLayerSingleTreePlusGroupNode);

3
src/widget/multilayersingletree/treeitem/index.js

@ -0,0 +1,3 @@
export { MultiLayerSingleTreeFirstTreeLeafItem } from "./item.first.treeleaf";
export { MultiLayerSingleTreeLastTreeLeafItem } from "./item.last.treeleaf";
export { MultiLayerSingleTreeMidTreeLeafItem } from "./item.mid.treeleaf";

93
src/widget/multilayersingletree/treeitem/item.first.treeleaf.js

@ -1,30 +1,32 @@
/** import { shortcut, extend, createWidget, Controller, Events, makeArray, HorizontalAdaptLayout } from "@/core";
* import { BasicButton } from "@/base";
* Created by GUY on 2016/1/27.
* @class BI.MultiLayerSingleTreeFirstTreeLeafItem @shortcut()
* @extends BI.BasicButton export class MultiLayerSingleTreeFirstTreeLeafItem extends BasicButton {
*/ static xtype = "bi.multilayer_single_tree_first_tree_leaf_item";
BI.MultiLayerSingleTreeFirstTreeLeafItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig() {
return BI.extend(BI.MultiLayerSingleTreeFirstTreeLeafItem.superclass._defaultConfig.apply(this, arguments), { return extend(super._defaultConfig(...arguments), {
extraCls: "bi-multilayer-single-tree-first-tree-leaf-item bi-list-item-active", extraCls: "bi-multilayer-single-tree-first-tree-leaf-item bi-list-item-active",
logic: { logic: {
dynamic: false dynamic: false,
}, },
layer: 0, layer: 0,
id: "", id: "",
pId: "", pId: "",
height: 24 height: 24,
}); });
}, }
_init: function () {
BI.MultiLayerSingleTreeFirstTreeLeafItem.superclass._init.apply(this, arguments); _init() {
var self = this, o = this.options; super._init(...arguments);
this.item = BI.createWidget({ const self = this,
o = this.options;
this.item = createWidget({
type: "bi.first_tree_leaf_item", type: "bi.first_tree_leaf_item",
cls: "bi-list-item-none", cls: "bi-list-item-none",
logic: { logic: {
dynamic: true dynamic: true,
}, },
id: o.id, id: o.id,
pId: o.pId, pId: o.pId,
@ -33,54 +35,53 @@ BI.MultiLayerSingleTreeFirstTreeLeafItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
py: o.py, py: o.py,
keyword: o.keyword keyword: o.keyword,
}); });
this.item.on(BI.Controller.EVENT_CHANGE, function (type) { this.item.on(Controller.EVENT_CHANGE, function (type) {
if (type === BI.Events.CLICK) {// 本身实现click功能 if (type === Events.CLICK) {
// 本身实现click功能
return; return;
} }
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
var items = []; const items = [];
items.push({ items.push({
el: this.item, el: this.item,
lgap: o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2 lgap: (o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT) / 2,
}); });
BI.createWidget({ createWidget({
type: "bi.horizontal_adapt", type: HorizontalAdaptLayout.xtype,
element: this, element: this,
columnSize: BI.makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2), columnSize: makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2),
items: items items,
}); });
}, }
doHighLight: function () { doHighLight() {
this.item.doHighLight.apply(this.item, arguments); this.item.doHighLight(...arguments);
}, }
unHighLight: function () { unHighLight() {
this.item.unHighLight.apply(this.item, arguments); this.item.unHighLight(...arguments);
}, }
getId: function () { getId() {
return this.options.id; return this.options.id;
}, }
getPId: function () { getPId() {
return this.options.pId; return this.options.pId;
}, }
doClick: function () { doClick() {
BI.MultiLayerSingleTreeFirstTreeLeafItem.superclass.doClick.apply(this, arguments); super.doClick(...arguments);
this.item.setSelected(this.isSelected()); this.item.setSelected(this.isSelected());
}, }
setSelected: function (v) { setSelected(v) {
BI.MultiLayerSingleTreeFirstTreeLeafItem.superclass.setSelected.apply(this, arguments); super.setSelected(...arguments);
this.item.setSelected(v); this.item.setSelected(v);
} }
}); }
BI.shortcut("bi.multilayer_single_tree_first_tree_leaf_item", BI.MultiLayerSingleTreeFirstTreeLeafItem);

93
src/widget/multilayersingletree/treeitem/item.last.treeleaf.js

@ -1,30 +1,32 @@
/** import { shortcut, extend, createWidget, Controller, Events, makeArray, HorizontalAdaptLayout } from "@/core";
* import { BasicButton } from "@/base";
* Created by GUY on 2016/1/27.
* @class BI.MultiLayerSingleTreeLastTreeLeafItem @shortcut()
* @extends BI.BasicButton export class MultiLayerSingleTreeLastTreeLeafItem extends BasicButton {
*/ static xtype = "bi.multilayer_single_tree_last_tree_leaf_item";
BI.MultiLayerSingleTreeLastTreeLeafItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig() {
return BI.extend(BI.MultiLayerSingleTreeLastTreeLeafItem.superclass._defaultConfig.apply(this, arguments), { return extend(super._defaultConfig(...arguments), {
extraCls: "bi-multilayer-single-tree-last-tree-leaf-item bi-list-item-active", extraCls: "bi-multilayer-single-tree-last-tree-leaf-item bi-list-item-active",
logic: { logic: {
dynamic: false dynamic: false,
}, },
layer: 0, layer: 0,
id: "", id: "",
pId: "", pId: "",
height: 24 height: 24,
}); });
}, }
_init: function () {
BI.MultiLayerSingleTreeLastTreeLeafItem.superclass._init.apply(this, arguments); _init() {
var self = this, o = this.options; super._init(...arguments);
this.item = BI.createWidget({ const self = this,
o = this.options;
this.item = createWidget({
type: "bi.last_tree_leaf_item", type: "bi.last_tree_leaf_item",
cls: "bi-list-item-none", cls: "bi-list-item-none",
logic: { logic: {
dynamic: true dynamic: true,
}, },
id: o.id, id: o.id,
pId: o.pId, pId: o.pId,
@ -33,54 +35,53 @@ BI.MultiLayerSingleTreeLastTreeLeafItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
py: o.py, py: o.py,
keyword: o.keyword keyword: o.keyword,
}); });
this.item.on(BI.Controller.EVENT_CHANGE, function (type) { this.item.on(Controller.EVENT_CHANGE, function (type) {
if (type === BI.Events.CLICK) {// 本身实现click功能 if (type === Events.CLICK) {
// 本身实现click功能
return; return;
} }
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
var items = []; const items = [];
items.push({ items.push({
el: this.item, el: this.item,
lgap: o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2 lgap: (o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT) / 2,
}); });
BI.createWidget({ createWidget({
type: "bi.horizontal_adapt", type: HorizontalAdaptLayout.xtype,
element: this, element: this,
columnSize: BI.makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2), columnSize: makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2),
items: items items,
}); });
}, }
doHighLight: function () { doHighLight() {
this.item.doHighLight.apply(this.item, arguments); this.item.doHighLight(...arguments);
}, }
unHighLight: function () { unHighLight() {
this.item.unHighLight.apply(this.item, arguments); this.item.unHighLight(...arguments);
}, }
getId: function () { getId() {
return this.options.id; return this.options.id;
}, }
getPId: function () { getPId() {
return this.options.pId; return this.options.pId;
}, }
doClick: function () { doClick() {
BI.MultiLayerSingleTreeLastTreeLeafItem.superclass.doClick.apply(this, arguments); super.doClick(...arguments);
this.item.setSelected(this.isSelected()); this.item.setSelected(this.isSelected());
}, }
setSelected: function (v) { setSelected(v) {
BI.MultiLayerSingleTreeLastTreeLeafItem.superclass.setSelected.apply(this, arguments); super.setSelected(...arguments);
this.item.setSelected(v); this.item.setSelected(v);
} }
}); }
BI.shortcut("bi.multilayer_single_tree_last_tree_leaf_item", BI.MultiLayerSingleTreeLastTreeLeafItem);

93
src/widget/multilayersingletree/treeitem/item.mid.treeleaf.js

@ -1,30 +1,32 @@
/** import { shortcut, extend, createWidget, Controller, Events, makeArray, HorizontalAdaptLayout } from "@/core";
* import { BasicButton } from "@/base";
* Created by GUY on 2016/1/27.
* @class BI.MultiLayerSingleTreeMidTreeLeafItem @shortcut()
* @extends BI.BasicButton export class MultiLayerSingleTreeMidTreeLeafItem extends BasicButton {
*/ static xtype = "bi.multilayer_single_tree_mid_tree_leaf_item";
BI.MultiLayerSingleTreeMidTreeLeafItem = BI.inherit(BI.BasicButton, {
_defaultConfig: function () { _defaultConfig() {
return BI.extend(BI.MultiLayerSingleTreeMidTreeLeafItem.superclass._defaultConfig.apply(this, arguments), { return extend(super._defaultConfig(...arguments), {
extraCls: "bi-multilayer-single-tree-mid-tree-leaf-item bi-list-item-active", extraCls: "bi-multilayer-single-tree-mid-tree-leaf-item bi-list-item-active",
logic: { logic: {
dynamic: false dynamic: false,
}, },
layer: 0, layer: 0,
id: "", id: "",
pId: "", pId: "",
height: 24 height: 24,
}); });
}, }
_init: function () {
BI.MultiLayerSingleTreeMidTreeLeafItem.superclass._init.apply(this, arguments); _init() {
var self = this, o = this.options; super._init(...arguments);
this.item = BI.createWidget({ const self = this,
o = this.options;
this.item = createWidget({
type: "bi.mid_tree_leaf_item", type: "bi.mid_tree_leaf_item",
cls: "bi-list-item-none", cls: "bi-list-item-none",
logic: { logic: {
dynamic: true dynamic: true,
}, },
id: o.id, id: o.id,
pId: o.pId, pId: o.pId,
@ -33,54 +35,53 @@ BI.MultiLayerSingleTreeMidTreeLeafItem = BI.inherit(BI.BasicButton, {
text: o.text, text: o.text,
value: o.value, value: o.value,
py: o.py, py: o.py,
keyword: o.keyword keyword: o.keyword,
}); });
this.item.on(BI.Controller.EVENT_CHANGE, function (type) { this.item.on(Controller.EVENT_CHANGE, function (type) {
if (type === BI.Events.CLICK) {// 本身实现click功能 if (type === Events.CLICK) {
// 本身实现click功能
return; return;
} }
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
var items = []; const items = [];
items.push({ items.push({
el: this.item, el: this.item,
lgap: o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2 lgap: (o.layer * BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT) / 2,
}); });
BI.createWidget({ createWidget({
type: "bi.horizontal_adapt", type: HorizontalAdaptLayout.xtype,
element: this, element: this,
columnSize: BI.makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2), columnSize: makeArray(o.layer, BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT / 2),
items: items items,
}); });
}, }
doHighLight: function () { doHighLight() {
this.item.doHighLight.apply(this.item, arguments); this.item.doHighLight(...arguments);
}, }
unHighLight: function () { unHighLight() {
this.item.unHighLight.apply(this.item, arguments); this.item.unHighLight(...arguments);
}, }
getId: function () { getId() {
return this.options.id; return this.options.id;
}, }
getPId: function () { getPId() {
return this.options.pId; return this.options.pId;
}, }
doClick: function () { doClick() {
BI.MultiLayerSingleTreeMidTreeLeafItem.superclass.doClick.apply(this, arguments); super.doClick(...arguments);
this.item.setSelected(this.isSelected()); this.item.setSelected(this.isSelected());
}, }
setSelected: function (v) { setSelected(v) {
BI.MultiLayerSingleTreeMidTreeLeafItem.superclass.setSelected.apply(this, arguments); super.setSelected(...arguments);
this.item.setSelected(v); this.item.setSelected(v);
} }
}); }
BI.shortcut("bi.multilayer_single_tree_mid_tree_leaf_item", BI.MultiLayerSingleTreeMidTreeLeafItem);

1
src/widget/multiselect/index.js

@ -2,3 +2,4 @@ export { MultiSelectCombo } from "./multiselect.combo";
export { MultiSelectNoBarCombo } from "./multiselect.combo.nobar"; export { MultiSelectNoBarCombo } from "./multiselect.combo.nobar";
export { MultiSelectInsertCombo } from "./multiselect.insert.combo"; export { MultiSelectInsertCombo } from "./multiselect.insert.combo";
export { MultiSelectInsertNoBarCombo } from "./multiselect.insert.combo.nobar"; export { MultiSelectInsertNoBarCombo } from "./multiselect.insert.combo.nobar";
export { SelectPatchEditor } from "./trigger/editor/editor.patch";

9
src/widget/singleselect/index.js

@ -0,0 +1,9 @@
export { SingleSelectCombo } from "./singleselect.combo";
export { SingleSelectInsertCombo } from "./singleselect.insert.combo";
export { SingleSelectList } from "./singleselect.list";
export { SingleSelectLoader } from "./singleselect.loader";
export { SingleSelectPopupView } from "./singleselect.popup.view";
export { SingleSelectTrigger } from "./singleselect.trigger";
export { SingleSelectInsertList } from "./singleselectlist.insert";
export * from "./trigger";
export * from "./search";

3
src/widget/singleselect/search/index.js

@ -0,0 +1,3 @@
export { SingleSelectSearchLoader } from "./singleselect.search.loader";
export { SingleSelectSearchPane } from "./singleselect.search.pane";
export { SingleSelectSearchInsertPane } from "./singleselect.search.pane.insert";

181
src/widget/singleselect/search/singleselect.search.loader.js

@ -1,73 +1,80 @@
/** import { shortcut, Widget, extend, emptyFn, createWidget, i18nText, isUndefined, Controller, VerticalLayout, map, isArray, isKey, Func } from "@/core";
* 单选加载数据搜索loader面板 import { ButtonGroup, Loader } from "@/base";
* Created by guy on 15/11/4. import { SingleSelectList } from "../singleselect.list";
* @class BI.SingleSelectSearchLoader import { SingleSelectItem, SingleSelectRadioItem } from "@/case";
* @extends Widget
*/
BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.SingleSelectSearchLoader.superclass._defaultConfig.apply(this, arguments), { export class SingleSelectSearchLoader extends Widget {
static xtype = "bi.single_select_search_loader";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-search-loader", baseCls: "bi-single-select-search-loader",
allowNoSelect: false, allowNoSelect: false,
logic: { logic: {
dynamic: false dynamic: false,
}, },
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
keywordGetter: BI.emptyFn, keywordGetter: emptyFn,
valueFormatter: BI.emptyFn valueFormatter: emptyFn,
}); });
}, }
_init: function () { _init() {
BI.SingleSelectSearchLoader.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, opts = this.options; const self = this,
var hasNext = false; opts = this.options;
let hasNext = false;
this.button_group = BI.createWidget({ this.button_group = createWidget({
type: "bi.single_select_list", type: SingleSelectList.xtype,
allowNoSelect: opts.allowNoSelect, allowNoSelect: opts.allowNoSelect,
element: this, element: this,
logic: { logic: {
dynamic: false dynamic: false,
}, },
value: opts.value, value: opts.value,
el: { el: {
tipText: BI.i18nText("BI-No_Select"), tipText: i18nText("BI-No_Select"),
el: { el: {
type: "bi.loader", type: Loader.xtype,
isDefaultInit: false, isDefaultInit: false,
logic: { logic: {
dynamic: true, dynamic: true,
scrolly: true scrolly: true,
}, },
el: { el: {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE,
behaviors: { behaviors: {
redmark: function () { redmark () {
return true; return true;
} },
}, },
layouts: [{ layouts: [
type: "bi.vertical" {
}] type: VerticalLayout.xtype,
} }
} ],
},
},
}, },
itemsCreator: function (op, callback) { itemsCreator (op, callback) {
self.storeValue && (op = BI.extend(op || {}, { self.storeValue &&
selectedValues: [self.storeValue] (op = extend(op || {}, {
})); selectedValues: [self.storeValue],
opts.itemsCreator(op, function (ob) { }));
var keyword = ob.keyword = opts.keywordGetter(); opts.itemsCreator(op, ob => {
const keyword = (ob.keyword = opts.keywordGetter());
hasNext = ob.hasNext; hasNext = ob.hasNext;
var firstItems = []; let firstItems = [];
if (op.times === 1 && !BI.isUndefined(self.storeValue)) { if (op.times === 1 && !isUndefined(self.storeValue)) {
var json = self._filterValues(self.storeValue); const json = self._filterValues(self.storeValue);
firstItems = self._createItems(json); firstItems = self._createItems(json);
} }
var context = { const context = {
tipText: ob.tipText, tipText: ob.tipText,
}; };
callback(firstItems.concat(self._createItems(ob.items)), keyword || "", context); callback(firstItems.concat(self._createItems(ob.items)), keyword || "", context);
@ -76,88 +83,88 @@ BI.SingleSelectSearchLoader = BI.inherit(BI.Widget, {
} }
}); });
}, },
hasNext: function () { hasNext () {
return hasNext; return hasNext;
} },
}); });
this.button_group.on(BI.Controller.EVENT_CHANGE, function () { this.button_group.on(Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { this.button_group.on(SingleSelectList.EVENT_CHANGE, function () {
self.fireEvent(BI.SingleSelectSearchLoader.EVENT_CHANGE, arguments); self.fireEvent(SingleSelectSearchLoader.EVENT_CHANGE, arguments);
}); });
}, }
_createItems: function (items) { _createItems(items) {
var o = this.options; const o = this.options;
return BI.map(items, function (i, item) {
return BI.extend({ return map(items, (i, item) => extend(
type: o.allowNoSelect ? "bi.single_select_item" : "bi.single_select_radio_item", {
type: o.allowNoSelect ? SingleSelectItem.xtype : SingleSelectRadioItem.xtype,
logic: o.logic, logic: o.logic,
cls: "bi-list-item-active", cls: "bi-list-item-active",
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
selected: false, selected: false,
iconWrapperWidth: 26, iconWrapperWidth: 26,
hgap: o.allowNoSelect ? 10 : 0, hgap: o.allowNoSelect ? 10 : 0,
title: item.title || item.text title: item.title || item.text,
}, item); },
}); item
}, ));
}
_filterValues: function (src) { _filterValues(src) {
var o = this.options; const o = this.options;
var keyword = o.keywordGetter(); const keyword = o.keywordGetter();
var values = src || []; let values = src || [];
var newValues = BI.map(BI.isArray(values) ? values : [values], function (i, v) { const newValues = map(isArray(values) ? values : [values], (i, v) => {
return { return {
text: o.valueFormatter(v) || v, text: o.valueFormatter(v) || v,
value: v value: v,
}; };
}); });
if (BI.isKey(keyword)) { if (isKey(keyword)) {
var search = BI.Func.getSearchResult(newValues, keyword); const search = Func.getSearchResult(newValues, keyword);
values = search.match.concat(search.find); values = search.match.concat(search.find);
} }
return BI.map(values, function (i, v) {
return map(values, (i, v) => {
return { return {
text: v.text, text: v.text,
title: v.text, title: v.text,
value: v.value, value: v.value,
selected: false selected: false,
}; };
}); });
}, }
setValue: function (v) { setValue(v) {
// 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了 // 暂存的值一定是新的值,不然v改掉后,storeValue也跟着改了
this.storeValue = v; this.storeValue = v;
this.button_group.setValue(v); this.button_group.setValue(v);
}, }
getValue: function () { getValue() {
return this.button_group.getValue(); return this.button_group.getValue();
}, }
getAllButtons: function () { getAllButtons() {
return this.button_group.getAllButtons(); return this.button_group.getAllButtons();
}, }
empty: function () { empty() {
this.button_group.empty(); this.button_group.empty();
}, }
populate: function (items) { populate(items) {
this.button_group.populate.apply(this.button_group, arguments); this.button_group.populate(...arguments);
}, }
resetHeight: function (h) { resetHeight(h) {
this.button_group.resetHeight(h); this.button_group.resetHeight(h);
}, }
resetWidth: function (w) { resetWidth(w) {
this.button_group.resetWidth(w); this.button_group.resetWidth(w);
} }
}); }
BI.SingleSelectSearchLoader.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.single_select_search_loader", BI.SingleSelectSearchLoader);

124
src/widget/singleselect/search/singleselect.search.pane.insert.js

@ -1,96 +1,96 @@
/** import { shortcut, Widget, extend, emptyFn, createWidget, i18nText, Controller, VerticalFillLayout, VerticalLayout } from "@/core";
* import { Label } from "@/base";
* 在搜索框中输入文本弹出的面板 import { SingleSelectSearchLoader } from "./singleselect.search.loader";
* @class BI.SingleSelectSearchInsertPane
* @extends Widget
*/
BI.SingleSelectSearchInsertPane = BI.inherit(BI.Widget, { @shortcut()
export class SingleSelectSearchInsertPane extends Widget {
static xtype = "bi.single_select_search_insert_pane";
constants: { constants = { height: 25, lgap: 10, tgap: 5 };
height: 25,
lgap: 10,
tgap: 5
},
_defaultConfig: function () { static EVENT_CHANGE = "EVENT_CHANGE";
return BI.extend(BI.SingleSelectSearchInsertPane.superclass._defaultConfig.apply(this, arguments), {
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-search-pane-insert bi-card", baseCls: "bi-single-select-search-pane-insert bi-card",
allowNoSelect: false, allowNoSelect: false,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
keywordGetter: BI.emptyFn keywordGetter: emptyFn,
}); });
}, }
_init: function () { _init() {
BI.SingleSelectSearchInsertPane.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const self = this,
o = this.options;
this.addNotMatchTip = BI.createWidget({ this.addNotMatchTip = createWidget({
type: "bi.label", type: Label.xtype,
text: BI.i18nText("BI-Basic_Press_Enter_To_Add_Text", ""), text: i18nText("BI-Basic_Press_Enter_To_Add_Text", ""),
height: this.constants.height, height: this.constants.height,
cls: "bi-keyword-red-mark", cls: "bi-keyword-red-mark",
hgap: 5, hgap: 5,
}); });
this.loader = BI.createWidget({ this.loader = createWidget({
type: "bi.single_select_search_loader", type: SingleSelectSearchLoader.xtype,
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
keywordGetter: o.keywordGetter, keywordGetter: o.keywordGetter,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemsCreator: function (op, callback) { itemsCreator (op, callback) {
o.itemsCreator.apply(self, [op, function (res) { o.itemsCreator.apply(self, [
callback(res); op,
self.setKeyword(o.keywordGetter()); function (res) {
}]); callback(res);
self.setKeyword(o.keywordGetter());
}
]);
}, },
value: o.value value: o.value,
}); });
this.loader.on(BI.Controller.EVENT_CHANGE, function () { this.loader.on(Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
this.resizer = BI.createWidget({ this.resizer = createWidget({
type: "bi.vertical_fill", type: VerticalFillLayout.xtype,
rowSize: ["", "fill"], rowSize: ["", "fill"],
element: this, element: this,
items: [{ items: [
type: "bi.vertical", {
items: [this.addNotMatchTip], type: VerticalLayout.xtype,
height: this.constants.height items: [this.addNotMatchTip],
}, { height: this.constants.height,
el: this.loader },
}] {
el: this.loader,
}
],
}); });
}, }
setKeyword: function (keyword) { setKeyword(keyword) {
this.addNotMatchTip.setText(BI.i18nText("BI-Basic_Press_Enter_To_Add_Text", keyword)); this.addNotMatchTip.setText(i18nText("BI-Basic_Press_Enter_To_Add_Text", keyword));
}, }
hasMatched: function () { hasMatched() {
return false; return false;
}, }
setValue: function (v) { setValue(v) {
this.loader.setValue(v); this.loader.setValue(v);
}, }
getValue: function () { getValue() {
return this.loader.getValue(); return this.loader.getValue();
}, }
empty: function () { empty() {
this.loader.empty(); this.loader.empty();
},
populate: function (items) {
this.loader.populate.apply(this.loader, arguments);
} }
});
BI.SingleSelectSearchInsertPane.EVENT_CHANGE = "EVENT_CHANGE"; populate(items) {
this.loader.populate(...arguments);
BI.shortcut("bi.single_select_search_insert_pane", BI.SingleSelectSearchInsertPane); }
}

130
src/widget/singleselect/search/singleselect.search.pane.js

@ -1,101 +1,105 @@
/** import { shortcut, Widget, extend, emptyFn, createWidget, i18nText, Controller, VerticalFillLayout } from "@/core";
* import { Label } from "@/base";
* 在搜索框中输入文本弹出的面板 import { SingleSelectSearchLoader } from "./singleselect.search.loader";
* @class BI.SingleSelectSearchPane
* @extends Widget
*/
BI.SingleSelectSearchPane = BI.inherit(BI.Widget, { @shortcut()
export class SingleSelectSearchPane extends Widget {
static xtype = "bi.single_select_search_pane";
constants: { constants = { height: 25, lgap: 10, tgap: 5 };
height: 25,
lgap: 10,
tgap: 5
},
_defaultConfig: function () { static EVENT_CHANGE = "EVENT_CHANGE";
return BI.extend(BI.SingleSelectSearchPane.superclass._defaultConfig.apply(this, arguments), {
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-search-pane bi-card", baseCls: "bi-single-select-search-pane bi-card",
allowNoSelect: false, allowNoSelect: false,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
keywordGetter: BI.emptyFn keywordGetter: emptyFn,
}); });
}, }
_init: function () { _init() {
BI.SingleSelectSearchPane.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const self = this,
o = this.options;
this.tooltipClick = BI.createWidget({ this.tooltipClick = createWidget({
type: "bi.label", type: Label.xtype,
invisible: true, invisible: true,
text: BI.i18nText("BI-Click_Blank_To_Select"), text: i18nText("BI-Click_Blank_To_Select"),
cls: "single-select-toolbar", cls: "single-select-toolbar",
height: this.constants.height height: this.constants.height,
}); });
this.loader = BI.createWidget({ this.loader = createWidget({
type: "bi.single_select_search_loader", type: SingleSelectSearchLoader.xtype,
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
keywordGetter: o.keywordGetter, keywordGetter: o.keywordGetter,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemsCreator: function (op, callback) { itemsCreator (op, callback) {
o.itemsCreator.apply(self, [op, function (res) { o.itemsCreator.apply(self, [
callback(res); op,
self.setKeyword(o.keywordGetter()); function (res) {
}]); callback(res);
self.setKeyword(o.keywordGetter());
}
]);
}, },
value: o.value value: o.value,
}); });
this.loader.on(BI.Controller.EVENT_CHANGE, function () { this.loader.on(Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
this.resizer = BI.createWidget({ this.resizer = createWidget({
type: "bi.vertical_fill", type: VerticalFillLayout.xtype,
rowSize: ["", "fill"], rowSize: ["", "fill"],
element: this, element: this,
items: [{ items: [
el: this.tooltipClick, {
}, { el: this.tooltipClick,
el: this.loader },
}] {
el: this.loader,
}
],
}); });
this.tooltipClick.setVisible(false); this.tooltipClick.setVisible(false);
}, }
setKeyword: function (keyword) { setKeyword(keyword) {
var btn, o = this.options; let btn;
var isVisible = this.loader.getAllButtons().length > 0 && (btn = this.loader.getAllButtons()[0]) && (keyword === (o.valueFormatter(btn.getValue()) || btn.getValue())); const o = this.options;
const isVisible =
this.loader.getAllButtons().length > 0 &&
(btn = this.loader.getAllButtons()[0]) &&
keyword === (o.valueFormatter(btn.getValue()) || btn.getValue());
if (isVisible !== this.tooltipClick.isVisible()) { if (isVisible !== this.tooltipClick.isVisible()) {
this.tooltipClick.setVisible(isVisible); this.tooltipClick.setVisible(isVisible);
this.resizer.attr("items")[0].height = (isVisible ? this.constants.height : 0); this.resizer.attr("items")[0].height = isVisible ? this.constants.height : 0;
this.resizer.resize(); this.resizer.resize();
} }
}, }
hasMatched: function () { hasMatched() {
return this.tooltipClick.isVisible(); return this.tooltipClick.isVisible();
}, }
setValue: function (v) { setValue(v) {
this.loader.setValue(v); this.loader.setValue(v);
}, }
getValue: function () { getValue() {
return this.loader.getValue(); return this.loader.getValue();
}, }
empty: function () { empty() {
this.loader.empty(); this.loader.empty();
},
populate: function (items) {
this.loader.populate.apply(this.loader, arguments);
} }
});
BI.SingleSelectSearchPane.EVENT_CHANGE = "EVENT_CHANGE"; populate(items) {
this.loader.populate(...arguments);
BI.shortcut("bi.single_select_search_pane", BI.SingleSelectSearchPane); }
}

321
src/widget/singleselect/singleselect.combo.js

@ -1,89 +1,104 @@
/** import { shortcut, extend, emptyFn, isKey, createWidget, toPix, isNotNull, nextTick, AbsoluteLayout, makeObject, map, each, remove } from "@/core";
* import { Single, Combo } from "@/base";
* @class BI.SingleSelectCombo import { SingleSelectTrigger } from "./singleselect.trigger";
* @extends BI.Single import { SingleSelectPopupView } from "./singleselect.popup.view";
*/ import { TriggerIconButton } from "@/case";
BI.SingleSelectCombo = BI.inherit(BI.Single, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.SingleSelectCombo.superclass._defaultConfig.apply(this, arguments), { export class SingleSelectCombo extends Single {
static xtype = "bi.single_select_combo";
static REQ_GET_DATA_LENGTH = 0;
static REQ_GET_ALL_DATA = -1;
static EVENT_BLUR = "EVENT_BLUR";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_STOP = "EVENT_STOP";
static EVENT_SEARCHING = "EVENT_SEARCHING";
static EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
static EVENT_CONFIRM = "EVENT_CONFIRM";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-combo", baseCls: "bi-single-select-combo",
allowNoSelect: false, allowNoSelect: false,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
itemWrapper: BI.emptyFn, itemWrapper: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
height: 24, height: 24,
allowEdit: true allowEdit: true,
}); });
}, }
_init: function () { _init() {
var self = this, o = this.options; const o = this.options;
BI.SingleSelectCombo.superclass._init.apply(this, arguments); super._init(...arguments);
var assertShowValue = function () { const assertShowValue = () => {
BI.isKey(self._startValue) && (self.storeValue = self._startValue); isKey(this._startValue) && (this.storeValue = this._startValue);
self.trigger.getSearcher().setState(self.storeValue); this.trigger.getSearcher().setState(this.storeValue);
}; };
this.storeValue = o.value; this.storeValue = o.value;
// 标记正在请求数据 // 标记正在请求数据
this.requesting = false; this.requesting = false;
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.single_select_trigger", type: "bi.single_select_trigger",
height: BI.toPix(o.height, o.simple ? 1 : 2), height: toPix(o.height, o.simple ? 1 : 2),
// adapter: this.popup, // adapter: this.popup,
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
allowEdit: o.allowEdit, allowEdit: o.allowEdit,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemsCreator: function (op, callback) { itemsCreator: (op, callback) => {
o.itemsCreator(op, function (res) { o.itemsCreator(op, (...args) => {
if (op.times === 1 && BI.isNotNull(op.keywords)) { if (op.times === 1 && isNotNull(op.keywords)) {
// 预防trigger内部把当前的storeValue改掉 // 预防trigger内部把当前的storeValue改掉
self.trigger.setValue(self.getValue()); this.trigger.setValue(this.getValue());
} }
callback.apply(self, arguments); callback.apply(this, ...args);
}); });
}, },
text: o.text, text: o.text,
value: this.storeValue value: this.storeValue,
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_FOCUS, function () { this.trigger.on(SingleSelectTrigger.EVENT_FOCUS, () => {
self.fireEvent(BI.SingleSelectCombo.EVENT_FOCUS); this.fireEvent(SingleSelectCombo.EVENT_FOCUS);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_BLUR, function () { this.trigger.on(SingleSelectTrigger.EVENT_BLUR, () => {
self.fireEvent(BI.SingleSelectCombo.EVENT_BLUR); this.fireEvent(SingleSelectCombo.EVENT_BLUR);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { this.trigger.on(SingleSelectTrigger.EVENT_START, () => {
self._setStartValue(); this._setStartValue();
this.getSearcher().setValue(self.storeValue); this.getSearcher().setValue(this.storeValue);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { this.trigger.on(SingleSelectTrigger.EVENT_STOP, () => {
self._setStartValue(); this._setStartValue();
self.fireEvent(BI.SingleSelectCombo.EVENT_STOP); this.fireEvent(SingleSelectCombo.EVENT_STOP);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function () { this.trigger.on(SingleSelectTrigger.EVENT_SEARCHING, () => {
self._dataChange = true; this._dataChange = true;
self.fireEvent(BI.SingleSelectCombo.EVENT_SEARCHING); this.fireEvent(SingleSelectCombo.EVENT_SEARCHING);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { this.trigger.on(
self.storeValue = this.getValue(); SingleSelectTrigger.EVENT_CHANGE,
assertShowValue(); (value, obj) => {
self._defaultState(); this.storeValue = this.trigger.getValue();
self._dataChange = true; assertShowValue();
}); this._defaultState();
this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { this._dataChange = true;
if (!self.combo.isViewVisible()) { }
self.combo.showView(); );
this.trigger.on(SingleSelectTrigger.EVENT_COUNTER_CLICK, () => {
if (!this.combo.isViewVisible()) {
this.combo.showView();
} }
}); });
this.combo = BI.createWidget({ this.combo = createWidget({
type: "bi.combo", type: Combo.xtype,
cls: (o.simple ? "bi-border-bottom" : "bi-border bi-border-radius"), cls: o.simple ? "bi-border-bottom" : "bi-border bi-border-radius",
container: o.container, container: o.container,
toggle: false, toggle: false,
el: this.trigger, el: this.trigger,
@ -91,182 +106,174 @@ BI.SingleSelectCombo = BI.inherit(BI.Single, {
popup: { popup: {
type: "bi.single_select_popup_view", type: "bi.single_select_popup_view",
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
ref: function () { ref: _ref => {
self.popup = this; this.popup = _ref;
self.trigger.setAdapter(this); this.trigger.setAdapter(_ref);
}, },
listeners: [{ listeners: [{
eventName: BI.SingleSelectPopupView.EVENT_CHANGE, eventName: SingleSelectPopupView.EVENT_CHANGE,
action: function () { action: () => {
self._dataChange = true; this._dataChange = true;
self.storeValue = this.getValue(); this.storeValue = this.popup.getValue();
self._adjust(function () { this._adjust(() => {
assertShowValue(); assertShowValue();
self._defaultState(); this._defaultState();
}); });
self.fireEvent(BI.SingleSelectCombo.EVENT_CLICK_ITEM); this.fireEvent(SingleSelectCombo.EVENT_CLICK_ITEM);
} },
}], }],
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
itemWrapper: o.itemWrapper, itemWrapper: o.itemWrapper,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
onLoaded: function () { onLoaded: () => {
BI.nextTick(function () { nextTick(() => {
self.combo.adjustWidth(); this.combo.adjustWidth();
self.combo.adjustHeight(); this.combo.adjustHeight();
self.trigger.getSearcher().adjustView(); this.trigger.getSearcher().adjustView();
}); });
} },
}, },
hideChecker: function (e) { hideChecker(e) {
return triggerBtn.element.find(e.target).length === 0; return triggerBtn.element.find(e.target).length === 0;
}, },
value: o.value value: o.value,
}); });
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { this.combo.on(Combo.EVENT_BEFORE_POPUPVIEW, () => {
if (!this.isViewVisible()) { if (!this.combo.isViewVisible()) {
self._dataChange = false;// 标记数据是否发生变化 this._dataChange = false; // 标记数据是否发生变化
} }
this.setValue(self.storeValue); this.setValue(this.storeValue);
BI.nextTick(function () { nextTick(() => {
self.populate(); this.populate();
}); });
}); });
// 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件
this.wants2Quit = false; this.wants2Quit = false;
this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { this.combo.on(Combo.EVENT_AFTER_HIDEVIEW, () => {
// important:关闭弹出时又可能没有退出编辑状态 // important:关闭弹出时又可能没有退出编辑状态
self.trigger.stopEditing(); this.trigger.stopEditing();
if (self.requesting === true) { if (this.requesting === true) {
self.wants2Quit = true; this.wants2Quit = true;
} else { } else {
self._dataChange && self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM); this._dataChange &&
this.fireEvent(SingleSelectCombo.EVENT_CONFIRM);
} }
}); });
var triggerBtn = BI.createWidget({ const triggerBtn = createWidget({
type: "bi.trigger_icon_button", type: TriggerIconButton.xtype,
width: o.height, width: o.height,
height: o.height, height: o.height,
cls: "single-select-trigger-icon-button" cls: "single-select-trigger-icon-button",
}); });
triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { triggerBtn.on(TriggerIconButton.EVENT_CHANGE, () => {
if (self.combo.isViewVisible()) { if (this.combo.isViewVisible()) {
self.combo.hideView(); this.combo.hideView();
} else { } else {
self.combo.showView(); this.combo.showView();
} }
}); });
BI.createWidget({ createWidget({
type: "bi.absolute", type: AbsoluteLayout.xtype,
element: this, element: this,
items: [{ items: [{
el: this.combo, el: this.combo,
left: 0, left: 0,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0,
}, { },
{
el: triggerBtn, el: triggerBtn,
right: 0, right: 0,
top: 0, top: 0,
bottom: 0 bottom: 0,
}] }
],
}); });
}, }
_defaultState: function () { _defaultState() {
this.trigger.stopEditing(); this.trigger.stopEditing();
this.combo.hideView(); this.combo.hideView();
}, }
_assertValue: function (val) { _assertValue(val) {}
},
_makeMap: function (values) { _makeMap(values) {
return BI.makeObject(values || []); return makeObject(values || []);
}, }
_joinKeywords: function (keywords, callback) { _joinKeywords(keywords, callback) {
var self = this, o = this.options; const o = this.options;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.requesting = true; this.requesting = true;
o.itemsCreator({ o.itemsCreator({
type: BI.SingleSelectCombo.REQ_GET_ALL_DATA, type: SingleSelectCombo.REQ_GET_ALL_DATA,
keywords: keywords keywords,
}, function (ob) { },
var values = BI.map(ob.items, "value"); ob => {
const values = map(ob.items, "value");
digest(values); digest(values);
}); }
);
function digest (items) { const digest = items => {
var selectedMap = self._makeMap(items); const selectedMap = this._makeMap(items);
BI.each(keywords, function (i, val) { each(keywords, (i, val) => {
if (BI.isNotNull(selectedMap[val])) { if (isNotNull(selectedMap[val])) {
BI.remove(self.storeValue.value, val); remove(this.storeValue.value, val);
} }
}); });
self._adjust(callback); this._adjust(callback);
} };
}, }
_adjust: function (callback) { _adjust(callback) {
var self = this, o = this.options; const adjust = () => {
if (this.wants2Quit === true) {
this._dataChange &&
this.fireEvent(SingleSelectCombo.EVENT_CONFIRM);
this.wants2Quit = false;
}
this.requesting = false;
};
const o = this.options;
if (!this._count) { if (!this._count) {
o.itemsCreator({ o.itemsCreator({
type: BI.SingleSelectCombo.REQ_GET_DATA_LENGTH type: SingleSelectCombo.REQ_GET_DATA_LENGTH,
}, function (res) { },
self._count = res.count; res => {
this._count = res.count;
adjust(); adjust();
callback(); callback();
}); }
);
} else { } else {
adjust(); adjust();
callback(); callback();
} }
}
function adjust () { _setStartValue(value) {
if (self.wants2Quit === true) {
self._dataChange && self.fireEvent(BI.SingleSelectCombo.EVENT_CONFIRM);
self.wants2Quit = false;
}
self.requesting = false;
}
},
_setStartValue: function (value) {
this._startValue = value; this._startValue = value;
this.popup.setStartValue(value); this.popup.setStartValue(value);
}, }
setValue: function (v) { setValue(v) {
this.storeValue = v; this.storeValue = v;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.combo.setValue(this.storeValue); this.combo.setValue(this.storeValue);
}, }
getValue: function () { getValue() {
return this.storeValue; return this.storeValue;
}, }
populate: function () { populate() {
this._count = null; this._count = null;
this.combo.populate.apply(this.combo, arguments); this.combo.populate(...arguments);
} }
}); }
BI.extend(BI.SingleSelectCombo, {
REQ_GET_DATA_LENGTH: 0,
REQ_GET_ALL_DATA: -1
});
BI.SingleSelectCombo.EVENT_BLUR = "EVENT_BLUR";
BI.SingleSelectCombo.EVENT_FOCUS = "EVENT_FOCUS";
BI.SingleSelectCombo.EVENT_STOP = "EVENT_STOP";
BI.SingleSelectCombo.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.SingleSelectCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
BI.SingleSelectCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.shortcut("bi.single_select_combo", BI.SingleSelectCombo);

260
src/widget/singleselect/singleselect.insert.combo.js

@ -1,45 +1,58 @@
/** import { shortcut, extend, emptyFn, i18nText, isKey, createWidget, toPix, isNotNull, nextTick, AbsoluteLayout, makeObject } from "@/core";
* import { Single, Combo } from "@/base";
* @class BI.SingleSelectInsertCombo import { SingleSelectTrigger } from "./singleselect.trigger";
* @extends BI.Single import { SingleSelectPopupView } from "./singleselect.popup.view";
*/ import { TriggerIconButton } from "@/case";
BI.SingleSelectInsertCombo = BI.inherit(BI.Single, {
@shortcut()
_defaultConfig: function () { export class SingleSelectInsertCombo extends Single {
return BI.extend(BI.SingleSelectInsertCombo.superclass._defaultConfig.apply(this, arguments), { static xtype = "bi.single_select_insert_combo";
static REQ_GET_DATA_LENGTH = 0;
static REQ_GET_ALL_DATA = -1;
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
static EVENT_STOP = "EVENT_STOP";
static EVENT_SEARCHING = "EVENT_SEARCHING";
static EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
static EVENT_CONFIRM = "EVENT_CONFIRM";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-combo", baseCls: "bi-single-select-combo",
allowNoSelect: false, allowNoSelect: false,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
itemWrapper: BI.emptyFn, itemWrapper: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
height: 24, height: 24,
allowEdit: true, allowEdit: true,
watermark: BI.i18nText("BI-Basic_Search_And_Patch_Paste"), watermark: i18nText("BI-Basic_Search_And_Patch_Paste"),
}); });
}, }
_init: function () { _init() {
var self = this, o = this.options; const self = this,
BI.SingleSelectInsertCombo.superclass._init.apply(this, arguments); o = this.options;
var assertShowValue = function () { super._init(...arguments);
BI.isKey(self._startValue) && (self.storeValue = self._startValue); const assertShowValue = () => {
self.trigger.getSearcher().setState(self.storeValue); isKey(this._startValue) && (this.storeValue = this._startValue);
this.trigger.getSearcher().setState(this.storeValue);
}; };
this.storeValue = o.value; this.storeValue = o.value;
// 标记正在请求数据 // 标记正在请求数据
this.requesting = false; this.requesting = false;
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.single_select_trigger", type: SingleSelectTrigger.xtype,
watermark: o.watermark, watermark: o.watermark,
height: BI.toPix(o.height, o.simple ? 1 : 2), height: toPix(o.height, o.simple ? 1 : 2),
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
allowEdit: o.allowEdit, allowEdit: o.allowEdit,
// adapter: this.popup, // adapter: this.popup,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemsCreator: function (op, callback) { itemsCreator (op, callback) {
o.itemsCreator(op, function (res) { o.itemsCreator(op, function (res) {
if (op.times === 1 && BI.isNotNull(op.keywords)) { if (op.times === 1 && isNotNull(op.keywords)) {
// 预防trigger内部把当前的storeValue改掉 // 预防trigger内部把当前的storeValue改掉
self.trigger.setValue(self.getValue()); self.trigger.setValue(self.getValue());
} }
@ -51,198 +64,195 @@ BI.SingleSelectInsertCombo = BI.inherit(BI.Single, {
searcher: { searcher: {
popup: { popup: {
type: "bi.single_select_search_insert_pane", type: "bi.single_select_search_insert_pane",
} },
} },
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_FOCUS, function () { this.trigger.on(SingleSelectTrigger.EVENT_FOCUS, () => {
self.fireEvent(BI.SingleSelectInsertCombo.EVENT_FOCUS); self.fireEvent(SingleSelectInsertCombo.EVENT_FOCUS);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_BLUR, function () { this.trigger.on(SingleSelectTrigger.EVENT_BLUR, () => {
self.fireEvent(BI.SingleSelectInsertCombo.EVENT_BLUR); self.fireEvent(SingleSelectInsertCombo.EVENT_BLUR);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_START, function () { this.trigger.on(SingleSelectTrigger.EVENT_START, function () {
self._setStartValue(); self._setStartValue();
this.getSearcher().setValue(self.storeValue); this.getSearcher().setValue(self.storeValue);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_STOP, function () { this.trigger.on(SingleSelectTrigger.EVENT_STOP, () => {
self._setStartValue(); self._setStartValue();
self.fireEvent(BI.SingleSelectInsertCombo.EVENT_STOP); self.fireEvent(SingleSelectInsertCombo.EVENT_STOP);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_PAUSE, function () { this.trigger.on(SingleSelectTrigger.EVENT_PAUSE, () => {
self.storeValue = self.trigger.getSearcher().getKeyword(); self.storeValue = self.trigger.getSearcher().getKeyword();
assertShowValue(); assertShowValue();
self._defaultState(); self._defaultState();
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_SEARCHING, function () { this.trigger.on(SingleSelectTrigger.EVENT_SEARCHING, () => {
self._dataChange = true; self._dataChange = true;
self.fireEvent(BI.SingleSelectInsertCombo.EVENT_SEARCHING); self.fireEvent(SingleSelectInsertCombo.EVENT_SEARCHING);
}); });
this.trigger.on(BI.SingleSelectTrigger.EVENT_CHANGE, function (value, obj) { this.trigger.on(
self.storeValue = this.getValue(); SingleSelectTrigger.EVENT_CHANGE,
assertShowValue(); function (value, obj) {
self._defaultState(); self.storeValue = this.getValue();
self._dataChange = true; assertShowValue();
}); self._defaultState();
this.trigger.on(BI.SingleSelectTrigger.EVENT_COUNTER_CLICK, function () { self._dataChange = true;
}
);
this.trigger.on(SingleSelectTrigger.EVENT_COUNTER_CLICK, () => {
if (!self.combo.isViewVisible()) { if (!self.combo.isViewVisible()) {
self.combo.showView(); self.combo.showView();
} }
}); });
this.combo = BI.createWidget({ this.combo = createWidget({
type: "bi.combo", type: Combo.xtype,
cls: (o.simple ? "bi-border-bottom" : "bi-border bi-border-radius"), cls: o.simple ? "bi-border-bottom" : "bi-border bi-border-radius",
container: o.container, container: o.container,
toggle: false, toggle: false,
el: this.trigger, el: this.trigger,
adjustLength: 1, adjustLength: 1,
popup: { popup: {
type: "bi.single_select_popup_view", type: SingleSelectPopupView.xtype,
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
ref: function () { ref () {
self.popup = this; self.popup = this;
self.trigger.setAdapter(this); self.trigger.setAdapter(this);
}, },
listeners: [{ listeners: [
eventName: BI.SingleSelectPopupView.EVENT_CHANGE, {
action: function () { eventName: SingleSelectPopupView.EVENT_CHANGE,
self._dataChange = true; action () {
self.storeValue = this.getValue(); self._dataChange = true;
self._adjust(function () { self.storeValue = this.getValue();
assertShowValue(); self._adjust(() => {
self._defaultState(); assertShowValue();
}); self._defaultState();
self.fireEvent(BI.SingleSelectInsertCombo.EVENT_CLICK_ITEM); });
self.fireEvent(
SingleSelectInsertCombo.EVENT_CLICK_ITEM
);
},
} }
}], ],
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
itemWrapper: o.itemWrapper, itemWrapper: o.itemWrapper,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
onLoaded: function () { onLoaded () {
BI.nextTick(function () { nextTick(() => {
self.combo.adjustWidth(); self.combo.adjustWidth();
self.combo.adjustHeight(); self.combo.adjustHeight();
self.trigger.getSearcher().adjustView(); self.trigger.getSearcher().adjustView();
}); });
} },
}, },
hideChecker: function (e) { hideChecker (e) {
return triggerBtn.element.find(e.target).length === 0; return triggerBtn.element.find(e.target).length === 0;
}, },
value: o.value value: o.value,
}); });
this.combo.on(BI.Combo.EVENT_BEFORE_POPUPVIEW, function () { this.combo.on(Combo.EVENT_BEFORE_POPUPVIEW, function () {
if (!this.isViewVisible()) { if (!this.isViewVisible()) {
self._dataChange = false;// 标记数据是否发生变化 self._dataChange = false; // 标记数据是否发生变化
} }
this.setValue(self.storeValue); this.setValue(self.storeValue);
BI.nextTick(function () { nextTick(() => {
self.populate(); self.populate();
}); });
}); });
// 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件 // 当退出的时候如果还在处理请求,则等请求结束后再对外发确定事件
this.wants2Quit = false; this.wants2Quit = false;
this.combo.on(BI.Combo.EVENT_AFTER_HIDEVIEW, function () { this.combo.on(Combo.EVENT_AFTER_HIDEVIEW, () => {
// important:关闭弹出时又可能没有退出编辑状态 // important:关闭弹出时又可能没有退出编辑状态
self.trigger.stopEditing(); self.trigger.stopEditing();
if (self.requesting === true) { if (self.requesting === true) {
self.wants2Quit = true; self.wants2Quit = true;
} else { } else {
self._dataChange && self.fireEvent(BI.SingleSelectInsertCombo.EVENT_CONFIRM); self._dataChange &&
self.fireEvent(SingleSelectInsertCombo.EVENT_CONFIRM);
} }
}); });
var triggerBtn = BI.createWidget({ const triggerBtn = createWidget({
type: "bi.trigger_icon_button", type: TriggerIconButton.xtype,
width: o.height, width: o.height,
height: o.height, height: o.height,
cls: "single-select-trigger-icon-button" cls: "single-select-trigger-icon-button",
}); });
triggerBtn.on(BI.TriggerIconButton.EVENT_CHANGE, function () { triggerBtn.on(TriggerIconButton.EVENT_CHANGE, () => {
if (self.combo.isViewVisible()) { if (self.combo.isViewVisible()) {
self.combo.hideView(); self.combo.hideView();
} else { } else {
self.combo.showView(); self.combo.showView();
} }
}); });
BI.createWidget({ createWidget({
type: "bi.absolute", type: AbsoluteLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.combo, {
left: 0, el: this.combo,
right: 0, left: 0,
top: 0, right: 0,
bottom: 0 top: 0,
}, { bottom: 0,
el: triggerBtn, },
right: 0, {
top: 0, el: triggerBtn,
bottom: 0 right: 0,
}] top: 0,
bottom: 0,
}
],
}); });
}, }
_defaultState: function () { _defaultState() {
this.trigger.stopEditing(); this.trigger.stopEditing();
this.combo.hideView(); this.combo.hideView();
}, }
_assertValue: function (val) { _assertValue(val) {}
},
_makeMap: function (values) { _makeMap(values) {
return BI.makeObject(values || []); return makeObject(values || []);
}, }
_adjust: function (callback) { _adjust(callback) {
var self = this, o = this.options; const self = this;
adjust(); adjust();
callback(); callback();
function adjust () { function adjust() {
if (self.wants2Quit === true) { if (self.wants2Quit === true) {
self._dataChange && self.fireEvent(BI.SingleSelectInsertCombo.EVENT_CONFIRM); self._dataChange &&
self.fireEvent(SingleSelectInsertCombo.EVENT_CONFIRM);
self.wants2Quit = false; self.wants2Quit = false;
} }
self.requesting = false; self.requesting = false;
} }
}, }
_setStartValue: function (value) { _setStartValue(value) {
this._startValue = value; this._startValue = value;
this.popup.setStartValue(value); this.popup.setStartValue(value);
}, }
setValue: function (v) { setValue(v) {
this.storeValue = v; this.storeValue = v;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.combo.setValue(this.storeValue); this.combo.setValue(this.storeValue);
}, }
getValue: function () { getValue() {
return this.storeValue; return this.storeValue;
},
populate: function () {
this.combo.populate.apply(this.combo, arguments);
} }
});
BI.extend(BI.SingleSelectInsertCombo, { populate() {
REQ_GET_DATA_LENGTH: 0, this.combo.populate(...arguments);
REQ_GET_ALL_DATA: -1 }
}); }
BI.SingleSelectInsertCombo.EVENT_FOCUS = "EVENT_FOCUS";
BI.SingleSelectInsertCombo.EVENT_BLUR = "EVENT_BLUR";
BI.SingleSelectInsertCombo.EVENT_STOP = "EVENT_STOP";
BI.SingleSelectInsertCombo.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.SingleSelectInsertCombo.EVENT_CLICK_ITEM = "EVENT_CLICK_ITEM";
BI.SingleSelectInsertCombo.EVENT_CONFIRM = "EVENT_CONFIRM";
BI.shortcut("bi.single_select_insert_combo", BI.SingleSelectInsertCombo);

226
src/widget/singleselect/singleselect.list.js

@ -1,41 +1,41 @@
/** import { shortcut, Widget, extend, emptyFn, createWidget, Controller, Events, i18nText } from "@/core";
* 选择列表 import { ListPane, SingleSelectItem } from "@/case";
*
* Created by GUY on 2015/11/1. @shortcut()
* @class BI.SingleSelectList export class SingleSelectList extends Widget {
* @extends BI.Widget static xtype = "bi.single_select_list";
*/
BI.SingleSelectList = BI.inherit(BI.Widget, { _constants = { itemHeight: 24 };
_constants: { static EVENT_CHANGE = "EVENT_CHANGE";
itemHeight: 24
}, _defaultConfig() {
return extend(super._defaultConfig(...arguments), {
_defaultConfig: function () {
return BI.extend(BI.SingleSelectList.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-select-list", baseCls: "bi-select-list",
direction: BI.Direction.Top, // toolbar的位置 direction: BI.Direction.Top, // toolbar的位置
logic: { logic: {
dynamic: true dynamic: true,
}, },
items: [], items: [],
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
hasNext: BI.emptyFn, hasNext: emptyFn,
onLoaded: BI.emptyFn, onLoaded: emptyFn,
el: { el: {
type: "bi.list_pane" type: ListPane.xtype,
}, },
allowNoSelect: false allowNoSelect: false,
}); });
}, }
_init: function () {
BI.SingleSelectList.superclass._init.apply(this, arguments); _init() {
var self = this, o = this.options; super._init(...arguments);
const self = this,
o = this.options;
this.list = BI.createWidget(o.el, { this.list = createWidget(o.el, {
type: "bi.list_pane", type: ListPane.xtype,
items: o.items, items: o.items,
itemsCreator: function (op, callback) { itemsCreator (op, callback) {
op.times === 1 && self.toolbar && self.toolbar.setVisible(false); op.times === 1 && self.toolbar && self.toolbar.setVisible(false);
o.itemsCreator(op, function (items) { o.itemsCreator(op, function (items) {
callback.apply(self, arguments); callback.apply(self, arguments);
@ -47,117 +47,137 @@ BI.SingleSelectList = BI.inherit(BI.Widget, {
}, },
onLoaded: o.onLoaded, onLoaded: o.onLoaded,
hasNext: o.hasNext, hasNext: o.hasNext,
value: o.value value: o.value,
}); });
this.list.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) { this.list.on(Controller.EVENT_CHANGE, function (type, value, obj) {
if (type === BI.Events.CLICK) { if (type === Events.CLICK) {
self.fireEvent(BI.SingleSelectList.EVENT_CHANGE, value, obj); self.fireEvent(SingleSelectList.EVENT_CHANGE, value, obj);
} }
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
BI.createWidget(BI.extend({ createWidget(
element: this extend(
}, BI.LogicFactory.createLogic(BI.LogicFactory.createLogicTypeByDirection(o.direction), BI.extend({ {
scrolly: true element: this,
}, o.logic, {
items: o.allowNoSelect ? BI.LogicFactory.createLogicItemsByDirection(o.direction, {
type: "bi.single_select_item",
cls: "bi-list-item-active",
height: this._constants.itemHeight,
forceNotSelected: true,
text: BI.i18nText("BI-Basic_No_Select"),
ref: function (_ref) {
self.toolbar = _ref;
}, },
listeners: [{ BI.LogicFactory.createLogic(
eventName: BI.Controller.EVENT_CHANGE, BI.LogicFactory.createLogicTypeByDirection(o.direction),
action: function (type) { extend(
if (type === BI.Events.CLICK) { {
self.list.setValue(); scrolly: true,
self.fireEvent(BI.SingleSelectList.EVENT_CHANGE); },
o.logic,
{
items: o.allowNoSelect
? BI.LogicFactory.createLogicItemsByDirection(
o.direction,
{
type: SingleSelectItem.xtype,
cls: "bi-list-item-active",
height: this._constants.itemHeight,
forceNotSelected: true,
text: i18nText("BI-Basic_No_Select"),
ref (_ref) {
self.toolbar = _ref;
},
listeners: [
{
eventName: Controller.EVENT_CHANGE,
action (type) {
if (type === Events.CLICK) {
self.list.setValue();
self.fireEvent(SingleSelectList.EVENT_CHANGE);
}
self.fireEvent(Controller.EVENT_CHANGE, arguments);
},
}
],
},
this.list
)
: BI.LogicFactory.createLogicItemsByDirection(o.direction, this.list),
} }
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); )
} )
}] )
}, this.list) : BI.LogicFactory.createLogicItemsByDirection(o.direction, this.list) );
})))); }
},
hasPrev: function () { hasPrev() {
return this.list.hasPrev(); return this.list.hasPrev();
}, }
hasNext: function () { hasNext() {
return this.list.hasNext(); return this.list.hasNext();
}, }
prependItems: function (items) { prependItems(items) {
this.list.prependItems.apply(this.list, arguments); this.list.prependItems(...arguments);
}, }
addItems: function (items) { addItems(items) {
this.list.addItems.apply(this.list, arguments); this.list.addItems(...arguments);
}, }
setValue: function (v) { setValue(v) {
this.list.setValue([v]); this.list.setValue([v]);
}, }
getValue: function () { getValue() {
return this.list.getValue()[0]; return this.list.getValue()[0];
}, }
empty: function () { empty() {
this.list.empty(); this.list.empty();
}, }
populate: function (items) { populate(items) {
this.list.populate.apply(this.list, arguments); this.list.populate(...arguments);
}, }
resetHeight: function (h) { resetHeight(h) {
this.list.resetHeight ? this.list.resetHeight(h) : this.list.resetHeight
this.list.element.css({"max-height": BI.pixFormat(h - (this.options.allowNoSelect ? this._constants.itemHeight : 0))}); ? this.list.resetHeight(h)
}, : this.list.element.css({
"max-height": BI.pixFormat(h - (this.options.allowNoSelect ? this._constants.itemHeight : 0)),
});
}
setNotSelectedValue: function () { setNotSelectedValue() {
this.list.setNotSelectedValue.apply(this.list, arguments); this.list.setNotSelectedValue(...arguments);
}, }
getNotSelectedValue: function () { getNotSelectedValue() {
return this.list.getNotSelectedValue(); return this.list.getNotSelectedValue();
}, }
getAllButtons: function () { getAllButtons() {
return this.list.getAllButtons(); return this.list.getAllButtons();
}, }
getAllLeaves: function () { getAllLeaves() {
return this.list.getAllLeaves(); return this.list.getAllLeaves();
}, }
getSelectedButtons: function () { getSelectedButtons() {
return this.list.getSelectedButtons(); return this.list.getSelectedButtons();
}, }
getNotSelectedButtons: function () { getNotSelectedButtons() {
return this.list.getNotSelectedButtons(); return this.list.getNotSelectedButtons();
}, }
getIndexByValue: function (value) { getIndexByValue(value) {
return this.list.getIndexByValue(value); return this.list.getIndexByValue(value);
}, }
getNodeById: function (id) { getNodeById(id) {
return this.list.getNodeById(id); return this.list.getNodeById(id);
}, }
getNodeByValue: function (value) { getNodeByValue(value) {
return this.list.getNodeByValue(value); return this.list.getNodeByValue(value);
} }
}); }
BI.SingleSelectList.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.single_select_list", BI.SingleSelectList);

239
src/widget/singleselect/singleselect.loader.js

@ -1,178 +1,187 @@
/** import { shortcut, Widget, extend, emptyFn, createWidget, isUndefined, map, isKey, Controller, VerticalLayout, delay } from "@/core";
* 单选加载数据面板 import { ButtonGroup, Loader } from "@/base";
* Created by guy on 15/11/2. import { SingleSelectList } from "./singleselect.list";
* @class BI.SingleSelectLoader import { SingleSelectItem, SingleSelectRadioItem } from "@/case";
* @extends Widget
*/ @shortcut()
BI.SingleSelectLoader = BI.inherit(BI.Widget, { export class SingleSelectLoader extends Widget {
static xtype = "bi.single_select_loader";
_constants: {
itemVgap: 5 _constants = { itemVgap: 5 };
},
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig: function () {
return BI.extend(BI.SingleSelectLoader.superclass._defaultConfig.apply(this, arguments), { _defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-loader", baseCls: "bi-single-select-loader",
logic: { logic: {
dynamic: true dynamic: true,
}, },
el: { el: {
height: 400 height: 400,
}, },
allowNoSelect: false, allowNoSelect: false,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
itemWrapper: BI.emptyFn, itemWrapper: emptyFn,
onLoaded: BI.emptyFn onLoaded: emptyFn,
}); });
}, }
_init: function () { _init() {
BI.SingleSelectLoader.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, opts = this.options; const self = this,
var hasNext = false; opts = this.options;
let hasNext = false;
this.storeValue = opts.value; this.storeValue = opts.value;
this.button_group = BI.createWidget({ this.button_group = createWidget({
type: "bi.single_select_list", type: SingleSelectList.xtype,
allowNoSelect: opts.allowNoSelect, allowNoSelect: opts.allowNoSelect,
logic: opts.logic, logic: opts.logic,
el: BI.extend({ el: extend(
onLoaded: opts.onLoaded, {
el: { onLoaded: opts.onLoaded,
type: "bi.loader",
isDefaultInit: false,
logic: {
dynamic: true,
scrolly: true
},
el: { el: {
chooseType: BI.ButtonGroup.CHOOSE_TYPE_SINGLE, type: Loader.xtype,
behaviors: { isDefaultInit: false,
redmark: function () { logic: {
return true; dynamic: true,
} scrolly: true,
}, },
layouts: [{ el: {
type: "bi.vertical" chooseType: ButtonGroup.CHOOSE_TYPE_SINGLE,
}] behaviors: {
} redmark () {
} return true;
}, opts.el), },
itemsCreator: function (op, callback) { },
var startValue = self._startValue; layouts: [
!BI.isUndefined(self.storeValue) && (op = BI.extend(op || {}, { {
selectedValues: [self.storeValue] type: VerticalLayout.xtype,
})); }
opts.itemsCreator(op, function (ob) { ],
},
},
},
opts.el
),
itemsCreator (op, callback) {
const startValue = self._startValue;
!isUndefined(self.storeValue) &&
(op = extend(op || {}, {
selectedValues: [self.storeValue],
}));
opts.itemsCreator(op, ob => {
hasNext = ob.hasNext; hasNext = ob.hasNext;
var firstItems = []; let firstItems = [];
if (op.times === 1 && !BI.isUndefined(self.storeValue)) { if (op.times === 1 && !isUndefined(self.storeValue)) {
var json = BI.map([self.storeValue], function (i, v) { const json = map([self.storeValue], (i, v) => {
var txt = opts.valueFormatter(v) || v; const txt = opts.valueFormatter(v) || v;
return opts.itemWrapper({
text: txt, return (
value: v, opts.itemWrapper({
title: txt, text: txt,
selected: true value: v,
}) || { title: txt,
text: txt, selected: true,
value: v, }) || {
title: txt, text: txt,
selected: true value: v,
}; title: txt,
selected: true,
}
);
}); });
firstItems = self._createItems(json); firstItems = self._createItems(json);
} }
callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || ""); callback(firstItems.concat(self._createItems(ob.items)), ob.keyword || "");
if (op.times === 1 && self.storeValue) { if (op.times === 1 && self.storeValue) {
BI.isKey(startValue) && (self.storeValue = startValue); isKey(startValue) && (self.storeValue = startValue);
self.setValue(self.storeValue); self.setValue(self.storeValue);
} }
(op.times === 1) && self._scrollToTop(); op.times === 1 && self._scrollToTop();
}); });
}, },
hasNext: function () { hasNext () {
return hasNext; return hasNext;
}, },
value: this.storeValue value: this.storeValue,
}); });
BI.createWidget({ createWidget({
type: "bi.vertical", type: VerticalLayout.xtype,
element: this, element: this,
items: [this.button_group], items: [this.button_group],
vgap: this._constants.itemVgap vgap: this._constants.itemVgap,
}); });
this.button_group.on(BI.Controller.EVENT_CHANGE, function () { this.button_group.on(Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); self.fireEvent(Controller.EVENT_CHANGE, arguments);
}); });
this.button_group.on(BI.SingleSelectList.EVENT_CHANGE, function () { this.button_group.on(SingleSelectList.EVENT_CHANGE, function () {
self.fireEvent(BI.SingleSelectLoader.EVENT_CHANGE, arguments); self.fireEvent(SingleSelectLoader.EVENT_CHANGE, arguments);
}); });
}, }
_createItems: function (items) { _createItems(items) {
var o = this.options; const o = this.options;
return BI.map(items, function (i, item) {
return BI.extend({ return map(items, (i, item) => extend(
type: o.allowNoSelect ? "bi.single_select_item" : "bi.single_select_radio_item", {
type: o.allowNoSelect ? SingleSelectItem.xtype : SingleSelectRadioItem.xtype,
logic: o.logic, logic: o.logic,
cls: "bi-list-item-active", cls: "bi-list-item-active",
height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT, height: BI.SIZE_CONSANTS.LIST_ITEM_HEIGHT,
selected: false, selected: false,
iconWrapperWidth: 26, iconWrapperWidth: 26,
textHgap: o.allowNoSelect ? 10 : 0, textHgap: o.allowNoSelect ? 10 : 0,
title: item.title || item.text title: item.title || item.text,
}, item); },
}); item
}, ));
}
_scrollToTop: function () { _scrollToTop() {
var self = this; const self = this;
BI.delay(function () { delay(() => {
self.button_group.element.scrollTop(0); self.button_group.element.scrollTop(0);
}, 30); }, 30);
}, }
_assertValue: function (val) { _assertValue(val) {}
},
setStartValue: function (v) { setStartValue(v) {
this._startValue = v; this._startValue = v;
}, }
setValue: function (v) { setValue(v) {
this.storeValue = v; this.storeValue = v;
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.button_group.setValue(this.storeValue); this.button_group.setValue(this.storeValue);
}, }
getValue: function () { getValue() {
return this.button_group.getValue(); return this.button_group.getValue();
}, }
getAllButtons: function () { getAllButtons() {
return this.button_group.getAllButtons(); return this.button_group.getAllButtons();
}, }
empty: function () { empty() {
this.button_group.empty(); this.button_group.empty();
}, }
populate: function (items) { populate(items) {
this.button_group.populate.apply(this.button_group, arguments); this.button_group.populate(...arguments);
}, }
resetHeight: function (h) { resetHeight(h) {
this.button_group.resetHeight(h - this._constants.itemVgap * 2); this.button_group.resetHeight(h - this._constants.itemVgap * 2);
}, }
resetWidth: function (w) { resetWidth(w) {
this.button_group.resetWidth(w); this.button_group.resetWidth(w);
} }
}); }
BI.SingleSelectLoader.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.single_select_loader", BI.SingleSelectLoader);

88
src/widget/singleselect/singleselect.popup.view.js

@ -1,84 +1,82 @@
/** import { shortcut, Widget, extend, emptyFn, createWidget } from "@/core";
* 带加载的单选下拉面板 import { MultiPopupView } from "@/case";
* @class BI.SingleSelectPopupView import { PopupView } from "@/base";
* @extends Widget
*/
BI.SingleSelectPopupView = BI.inherit(BI.Widget, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.SingleSelectPopupView.superclass._defaultConfig.apply(this, arguments), { export class SingleSelectPopupView extends Widget {
static xtype = "bi.single_select_popup_view";
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-popup-view", baseCls: "bi-single-select-popup-view",
allowNoSelect: false, allowNoSelect: false,
maxWidth: "auto", maxWidth: "auto",
minWidth: 135, minWidth: 135,
maxHeight: 400, maxHeight: 400,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
itemWrapper: BI.emptyFn, itemWrapper: emptyFn,
onLoaded: BI.emptyFn onLoaded: emptyFn,
}); });
}, }
_init: function () { _init() {
BI.SingleSelectPopupView.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, opts = this.options; const opts = this.options;
this.loader = BI.createWidget({ this.loader = createWidget({
type: "bi.single_select_loader", type: "bi.single_select_loader",
allowNoSelect: opts.allowNoSelect, allowNoSelect: opts.allowNoSelect,
itemsCreator: opts.itemsCreator, itemsCreator: opts.itemsCreator,
itemWrapper: opts.itemWrapper, itemWrapper: opts.itemWrapper,
valueFormatter: opts.valueFormatter, valueFormatter: opts.valueFormatter,
onLoaded: opts.onLoaded, onLoaded: opts.onLoaded,
value: opts.value value: opts.value,
}); });
this.popupView = BI.createWidget({ this.popupView = createWidget({
type: "bi.popup_view", type: PopupView.xtype,
stopPropagation: false, stopPropagation: false,
maxWidth: opts.maxWidth, maxWidth: opts.maxWidth,
minWidth: opts.minWidth, minWidth: opts.minWidth,
maxHeight: opts.maxHeight, maxHeight: opts.maxHeight,
element: this, element: this,
el: this.loader, el: this.loader,
value: opts.value value: opts.value,
}); });
this.popupView.on(BI.MultiPopupView.EVENT_CHANGE, function () { this.popupView.on(MultiPopupView.EVENT_CHANGE, () => {
self.fireEvent(BI.SingleSelectPopupView.EVENT_CHANGE); this.fireEvent(SingleSelectPopupView.EVENT_CHANGE);
}); });
}, }
setStartValue: function (v) { setStartValue(v) {
this.loader.setStartValue(v); this.loader.setStartValue(v);
}, }
setValue: function (v) { setValue(v) {
this.popupView.setValue(v); this.popupView.setValue(v);
}, }
getValue: function () { getValue() {
return this.popupView.getValue(); return this.popupView.getValue();
}, }
populate: function (items) { populate(items) {
this.popupView.populate.apply(this.popupView, arguments); this.popupView.populate(...arguments);
}, }
resetHeight: function (h) { resetHeight(h) {
this.popupView.resetHeight(h); this.popupView.resetHeight(h);
}, }
resetWidth: function (w) { resetWidth(w) {
this.popupView.resetWidth(w); this.popupView.resetWidth(w);
}, }
setDirection: function (direction, position) { setDirection(direction, position) {
this.popupView.setDirection(direction, position); this.popupView.setDirection(direction, position);
}, }
}); }
BI.SingleSelectPopupView.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.single_select_popup_view", BI.SingleSelectPopupView);

174
src/widget/singleselect/singleselect.trigger.js

@ -1,40 +1,46 @@
/** import { shortcut, extend, emptyFn, createWidget, HTapeLayout, AbsoluteLayout } from "@/core";
* import { Trigger, Text } from "@/base";
* 单选下拉框 import { SingleSelectSearcher } from "./trigger";
* @class BI.SingleSelectTrigger
* @extends BI.Trigger @shortcut()
*/ export class SingleSelectTrigger extends Trigger {
static xtype = "bi.single_select_trigger";
BI.SingleSelectTrigger = BI.inherit(BI.Trigger, {
constants = { height: 14, rgap: 4, lgap: 4 };
constants: {
height: 14, static EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK";
rgap: 4, static EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK";
lgap: 4 static EVENT_CHANGE = "EVENT_CHANGE";
}, static EVENT_START = "EVENT_START";
static EVENT_STOP = "EVENT_STOP";
_defaultConfig: function () { static EVENT_PAUSE = "EVENT_PAUSE";
return BI.extend(BI.SingleSelectTrigger.superclass._defaultConfig.apply(this, arguments), { static EVENT_SEARCHING = "EVENT_SEARCHING";
static EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-trigger", baseCls: "bi-single-select-trigger",
allowNoSelect: false, allowNoSelect: false,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
searcher: {}, searcher: {},
switcher: {}, switcher: {},
adapter: null, adapter: null,
masker: {}, masker: {},
allowEdit: true allowEdit: true,
}); });
}, }
_init: function () { _init() {
BI.SingleSelectTrigger.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
this.searcher = BI.createWidget(o.searcher, { this.searcher = createWidget(o.searcher, {
type: "bi.single_select_searcher", type: SingleSelectSearcher.xtype,
watermark: o.watermark, watermark: o.watermark,
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
text: o.text, text: o.text,
@ -44,95 +50,85 @@ BI.SingleSelectTrigger = BI.inherit(BI.Trigger, {
popup: {}, popup: {},
adapter: o.adapter, adapter: o.adapter,
masker: o.masker, masker: o.masker,
value: o.value value: o.value,
}); });
this.searcher.on(BI.SingleSelectSearcher.EVENT_START, function () { this.searcher.on(SingleSelectSearcher.EVENT_START, () => {
self.fireEvent(BI.SingleSelectTrigger.EVENT_START); this.fireEvent(SingleSelectTrigger.EVENT_START);
}); });
this.searcher.on(BI.SingleSelectSearcher.EVENT_PAUSE, function () { this.searcher.on(SingleSelectSearcher.EVENT_PAUSE, () => {
self.fireEvent(BI.SingleSelectTrigger.EVENT_PAUSE); this.fireEvent(SingleSelectTrigger.EVENT_PAUSE);
}); });
this.searcher.on(BI.SingleSelectSearcher.EVENT_SEARCHING, function () { this.searcher.on(SingleSelectSearcher.EVENT_SEARCHING, (...args) => {
self.fireEvent(BI.SingleSelectTrigger.EVENT_SEARCHING, arguments); this.fireEvent(SingleSelectTrigger.EVENT_SEARCHING, ...args);
}); });
this.searcher.on(BI.SingleSelectSearcher.EVENT_STOP, function () { this.searcher.on(SingleSelectSearcher.EVENT_STOP, () => {
self.fireEvent(BI.SingleSelectTrigger.EVENT_STOP); this.fireEvent(SingleSelectTrigger.EVENT_STOP);
}); });
this.searcher.on(BI.SingleSelectSearcher.EVENT_CHANGE, function () { this.searcher.on(SingleSelectSearcher.EVENT_CHANGE, (...args) => {
self.fireEvent(BI.SingleSelectTrigger.EVENT_CHANGE, arguments); this.fireEvent(SingleSelectTrigger.EVENT_CHANGE, ...args);
}); });
this.searcher.on(BI.SingleSelectSearcher.EVENT_FOCUS, function () { this.searcher.on(SingleSelectSearcher.EVENT_FOCUS, () => {
self.fireEvent(BI.SingleSelectTrigger.EVENT_FOCUS); this.fireEvent(SingleSelectTrigger.EVENT_FOCUS);
}); });
this.searcher.on(BI.SingleSelectSearcher.EVENT_BLUR, function () { this.searcher.on(SingleSelectSearcher.EVENT_BLUR, (...args) => {
self.fireEvent(BI.SingleSelectTrigger.EVENT_BLUR, arguments); this.fireEvent(SingleSelectTrigger.EVENT_BLUR, ...args);
}); });
var wrapper = BI.createWidget({ createWidget({
type: "bi.htape", type: HTapeLayout.xtype,
element: this, element: this,
items: [ items: [
{ {
el: this.searcher, el: this.searcher,
width: "fill" width: "fill",
}, { },
el: BI.createWidget(), {
width: 24 el: createWidget(),
}] width: 24,
}
],
}); });
!o.allowEdit && BI.createWidget({ !o.allowEdit &&
type: "bi.absolute", createWidget({
element: this, type: AbsoluteLayout.xtype,
items: [{ element: this,
el: { items: [
type: "bi.text", {
title: function () { el: {
return self.searcher.getState(); type: Text.xtype,
title: () => this.searcher.getState(),
},
left: 0,
right: 24,
top: 0,
bottom: 0,
} }
}, ],
left: 0, });
right: 24, }
top: 0,
bottom: 0
}]
});
},
getSearcher: function () { getSearcher() {
return this.searcher; return this.searcher;
}, }
stopEditing: function () { stopEditing() {
this.searcher.stopSearch(); this.searcher.stopSearch();
}, }
setAdapter: function (adapter) { setAdapter(adapter) {
this.searcher.setAdapter(adapter); this.searcher.setAdapter(adapter);
}, }
setValue: function (v) { setValue(v) {
this.searcher.setValue(v); this.searcher.setValue(v);
}, }
getKey: function () { getKey() {
return this.searcher.getKey(); return this.searcher.getKey();
}, }
getValue: function () { getValue() {
return this.searcher.getValue(); return this.searcher.getValue();
} }
}); }
BI.SingleSelectTrigger.EVENT_TRIGGER_CLICK = "EVENT_TRIGGER_CLICK";
BI.SingleSelectTrigger.EVENT_COUNTER_CLICK = "EVENT_COUNTER_CLICK";
BI.SingleSelectTrigger.EVENT_CHANGE = "EVENT_CHANGE";
BI.SingleSelectTrigger.EVENT_START = "EVENT_START";
BI.SingleSelectTrigger.EVENT_STOP = "EVENT_STOP";
BI.SingleSelectTrigger.EVENT_PAUSE = "EVENT_PAUSE";
BI.SingleSelectTrigger.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.SingleSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW = "EVENT_BEFORE_COUNTER_POPUPVIEW";
BI.SingleSelectTrigger.EVENT_FOCUS = "EVENT_FOCUS";
BI.SingleSelectTrigger.EVENT_BLUR = "EVENT_BLUR";
BI.shortcut("bi.single_select_trigger", BI.SingleSelectTrigger);

266
src/widget/singleselect/singleselectlist.insert.js

@ -1,61 +1,83 @@
/** import {
* @author: Teller shortcut,
* @createdAt: 2018/3/28 extend,
* @Description emptyFn,
*/ isKey,
BI.SingleSelectInsertList = BI.inherit(BI.Single, { createWidget,
_defaultConfig: function () { isNotEmptyString,
return BI.extend(BI.SingleSelectInsertList.superclass._defaultConfig.apply(this, arguments), { i18nText,
deepClone,
VerticalFillLayout,
AbsoluteLayout,
makeObject
} from "@/core";
import { Single, Searcher } from "@/base";
import { SingleSelectLoader } from "./singleselect.loader";
import { SelectPatchEditor } from "../multiselect";
import { SearchEditor } from "../editor";
@shortcut()
export class SingleSelectInsertList extends Single {
static xtype = "bi.single_select_insert_list";
static REQ_GET_DATA_LENGTH = 0;
static REQ_GET_ALL_DATA = -1;
static EVENT_CHANGE = "EVENT_CHANGE";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-insert-list", baseCls: "bi-single-select-insert-list",
allowNoSelect: false, allowNoSelect: false,
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
itemWrapper: BI.emptyFn, itemWrapper: emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
searcherHeight: 24, searcherHeight: 24,
}); });
}, }
_init: function () {
BI.SingleSelectInsertList.superclass._init.apply(this, arguments); _init() {
super._init(...arguments);
var self = this, o = this.options; const self = this,
o = this.options;
this.storeValue = o.value; this.storeValue = o.value;
var assertShowValue = function () { const assertShowValue = () => {
BI.isKey(self._startValue) && (self.storeValue = self._startValue); isKey(this._startValue) && (this.storeValue = this._startValue);
// self.trigger.setValue(self.storeValue); // this.trigger.setValue(this.storeValue);
}; };
this.adapter = BI.createWidget({ this.adapter = createWidget({
type: "bi.single_select_loader", type: SingleSelectLoader.xtype,
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
cls: "popup-single-select-list bi-border-left bi-border-right bi-border-bottom", cls: "popup-single-select-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
itemWrapper: o.itemWrapper, itemWrapper: o.itemWrapper,
logic: { logic: {
dynamic: true dynamic: true,
}, },
// onLoaded: o.onLoaded, // onLoaded: o.onLoaded,
el: {}, el: {},
value: o.value value: o.value,
}); });
this.adapter.on(BI.SingleSelectLoader.EVENT_CHANGE, function () { this.adapter.on(SingleSelectLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue(); self.storeValue = this.getValue();
assertShowValue(); assertShowValue();
self.fireEvent(BI.SingleSelectInsertList.EVENT_CHANGE); self.fireEvent(SingleSelectInsertList.EVENT_CHANGE);
}); });
this.searcherPane = BI.createWidget({ this.searcherPane = createWidget({
type: "bi.single_select_search_insert_pane", type: "bi.single_select_search_insert_pane",
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
cls: "bi-border-left bi-border-right bi-border-bottom", cls: "bi-border-left bi-border-right bi-border-bottom",
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
keywordGetter: function () { keywordGetter () {
return self.trigger.getKeyword(); return self.trigger.getKeyword();
}, },
itemsCreator: function (op, callback) { itemsCreator (op, callback) {
op.keywords = [self.trigger.getKeyword()]; op.keywords = [self.trigger.getKeyword()];
if (BI.isNotEmptyString(op.keywords[0])) { if (isNotEmptyString(op.keywords[0])) {
this.setKeyword(op.keywords[0]); this.setKeyword(op.keywords[0]);
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
} }
@ -63,145 +85,147 @@ BI.SingleSelectInsertList = BI.inherit(BI.Single, {
}); });
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
this.trigger = BI.createWidget({ this.trigger = createWidget({
type: "bi.searcher", type: Searcher.xtype,
el: { el: {
type: "bi.select_patch_editor", type: SelectPatchEditor.xtype,
el: { el: {
type: "bi.search_editor", type: SearchEditor.xtype,
watermark: BI.i18nText("BI-Basic_Search_And_Patch_Paste"), watermark: i18nText("BI-Basic_Search_And_Patch_Paste"),
}, },
ref: function (ref) { ref (ref) {
self.editor = ref; self.editor = ref;
}, },
height: o.searcherHeight, height: o.searcherHeight,
}, },
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch (op, callback) {
callback(); callback();
}, },
adapter: this.adapter, adapter: this.adapter,
popup: this.searcherPane, popup: this.searcherPane,
masker: false, masker: false,
value: o.value, value: o.value,
listeners: [{ listeners: [
eventName: BI.Searcher.EVENT_START, {
action: function () { eventName: Searcher.EVENT_START,
self._showSearcherPane(); action () {
self._setStartValue(); self._showSearcherPane();
this.setValue(BI.deepClone(self.storeValue)); self._setStartValue();
} this.setValue(deepClone(self.storeValue));
}, { },
eventName: BI.Searcher.EVENT_STOP, },
action: function () { {
self._showAdapter(); eventName: Searcher.EVENT_STOP,
self._setStartValue(); action () {
self.adapter.setValue(self.storeValue); self._showAdapter();
// 需要刷新回到初始界面,否则搜索的结果不能放在最前面 self._setStartValue();
self.adapter.populate(); self.adapter.setValue(self.storeValue);
} // 需要刷新回到初始界面,否则搜索的结果不能放在最前面
}, { self.adapter.populate();
eventName: BI.Searcher.EVENT_PAUSE, },
action: function () { },
var keyword = this.getKeyword(); {
self.storeValue = keyword; eventName: Searcher.EVENT_PAUSE,
self._showAdapter(); action () {
self.adapter.setValue(self.storeValue); const keyword = this.getKeyword();
self._setStartValue(keyword); self.storeValue = keyword;
assertShowValue(); self._showAdapter();
self.adapter.populate(); self.adapter.setValue(self.storeValue);
self._setStartValue(); self._setStartValue(keyword);
self.fireEvent(BI.SingleSelectInsertList.EVENT_CHANGE); assertShowValue();
self.adapter.populate();
} self._setStartValue();
}, { self.fireEvent(SingleSelectInsertList.EVENT_CHANGE);
eventName: BI.Searcher.EVENT_CHANGE, },
action: function () { },
self.storeValue = this.getValue(); {
self.fireEvent(BI.SingleSelectInsertList.EVENT_CHANGE); eventName: Searcher.EVENT_CHANGE,
action () {
self.storeValue = this.getValue();
self.fireEvent(SingleSelectInsertList.EVENT_CHANGE);
},
} }
}] ],
}); });
BI.createWidget({ createWidget({
type: "bi.vertical_fill", type: VerticalFillLayout.xtype,
rowSize: ["", "fill"], rowSize: ["", "fill"],
element: this, element: this,
items: [{ items: [
el: this.trigger, {
}, { el: this.trigger,
el: this.adapter, },
}] {
el: this.adapter,
}
],
}); });
BI.createWidget({ createWidget({
type: "bi.absolute", type: AbsoluteLayout.xtype,
element: this, element: this,
items: [{ items: [
el: this.searcherPane, {
top: 24, el: this.searcherPane,
bottom: 0, top: 24,
left: 0, bottom: 0,
right: 0 left: 0,
}] right: 0,
}
],
}); });
}, }
_showAdapter: function () { _showAdapter() {
this.adapter.setVisible(true); this.adapter.setVisible(true);
this.searcherPane.setVisible(false); this.searcherPane.setVisible(false);
}, }
_showSearcherPane: function () { _showSearcherPane() {
this.searcherPane.setVisible(true); this.searcherPane.setVisible(true);
this.adapter.setVisible(false); this.adapter.setVisible(false);
}, }
_defaultState: function () { _defaultState() {
this.trigger.stopEditing(); this.trigger.stopEditing();
}, }
_assertValue: function () {}, _assertValue() {}
_makeMap: function (values) { _makeMap(values) {
return BI.makeObject(values || []); return makeObject(values || []);
}, }
_setStartValue: function (value) { _setStartValue(value) {
this._startValue = value; this._startValue = value;
this.adapter.setStartValue(value); this.adapter.setStartValue(value);
}, }
isAllSelected: function () { isAllSelected() {
return this.adapter.isAllSelected(); return this.adapter.isAllSelected();
}, }
resize: function () { resize() {
// this.trigger.getCounter().adjustView(); // this.trigger.getCounter().adjustView();
// this.trigger.adjustView(); // this.trigger.adjustView();
}, }
setValue: function (v) {
setValue(v) {
this.storeValue = v; this.storeValue = v;
this.adapter.setValue(this.storeValue); this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue); this.trigger.setValue(this.storeValue);
}, }
getValue: function () { getValue() {
return BI.deepClone(this.storeValue); return deepClone(this.storeValue);
}, }
populate: function () { populate() {
this._count = null; this._count = null;
this._allData = null; this._allData = null;
this.adapter.populate.apply(this.adapter, arguments); this.adapter.populate(...arguments);
this.trigger.populate.apply(this.trigger, arguments); this.trigger.populate(...arguments);
} }
}); }
BI.extend(BI.SingleSelectInsertList, {
REQ_GET_DATA_LENGTH: 0,
REQ_GET_ALL_DATA: -1
});
BI.SingleSelectInsertList.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.single_select_insert_list", BI.SingleSelectInsertList);

102
src/widget/singleselect/trigger/editor.singleselect.js

@ -1,25 +1,28 @@
/** import { shortcut, Widget, extend, i18nText, createWidget, Controller, isEmptyString, isEmptyArray, BlankSplitChar } from "@/core";
* 单选输入框 import { StateEditor } from "@/case";
* Created by guy on 15/11/3. import { SelectPatchEditor } from "../../multiselect";
* @class BI.SingleSelectEditor
* @extends Widget
*/
BI.SingleSelectEditor = BI.inherit(BI.Widget, {
_defaultConfig: function () { @shortcut()
return BI.extend(BI.SingleSelectEditor.superclass._defaultConfig.apply(this, arguments), { export class SingleSelectEditor extends Widget {
static xtype = "bi.single_select_editor";
static EVENT_FOCUS = "EVENT_FOCUS";
static EVENT_BLUR = "EVENT_BLUR";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-editor", baseCls: "bi-single-select-editor",
el: {}, el: {},
text: BI.i18nText("BI-Basic_Please_Select"), text: i18nText("BI-Basic_Please_Select"),
watermark: BI.i18nText("BI-Basic_Search"), watermark: i18nText("BI-Basic_Search"),
}); });
}, }
_init: function () { _init() {
BI.SingleSelectEditor.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const o = this.options;
this.editor = BI.createWidget(o.el, { this.editor = createWidget(o.el, {
type: "bi.select_patch_editor", type: SelectPatchEditor.xtype,
element: this, element: this,
height: o.height, height: o.height,
watermark: o.watermark, watermark: o.watermark,
@ -29,64 +32,59 @@ BI.SingleSelectEditor = BI.inherit(BI.Widget, {
text: o.text, text: o.text,
}); });
this.editor.on(BI.Controller.EVENT_CHANGE, function () { this.editor.on(Controller.EVENT_CHANGE, (...args) => {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments); this.fireEvent(Controller.EVENT_CHANGE, ...args);
}); });
this.editor.on(BI.StateEditor.EVENT_FOCUS, function () { this.editor.on(StateEditor.EVENT_FOCUS, () => {
self.fireEvent(BI.SingleSelectEditor.EVENT_FOCUS); this.fireEvent(SingleSelectEditor.EVENT_FOCUS);
}); });
this.editor.on(BI.StateEditor.EVENT_BLUR, function () { this.editor.on(StateEditor.EVENT_BLUR, () => {
self.fireEvent(BI.SingleSelectEditor.EVENT_BLUR); this.fireEvent(SingleSelectEditor.EVENT_BLUR);
}); });
}, }
focus: function () { focus() {
this.editor.focus(); this.editor.focus();
}, }
blur: function () { blur() {
this.editor.blur(); this.editor.blur();
}, }
setState: function (state) { setState(state) {
this.editor.setState(state); this.editor.setState(state);
}, }
setValue: function (v) { setValue(v) {
this.editor.setValue(v); this.editor.setValue(v);
}, }
getValue: function () { getValue() {
return this.editor.getValue(); return this.editor.getValue();
}, }
getKeywords: function () { getKeywords() {
var val = this.editor.getValue(); const val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/); let keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) { if (isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1); keywords = keywords.slice(0, keywords.length - 1);
} }
if (/\u200b\s\u200b$/.test(val)) { if (/\u200b\s\u200b$/.test(val)) {
return keywords.concat([BI.BlankSplitChar]); return keywords.concat([BlankSplitChar]);
} }
return keywords; return keywords;
}, }
getKeyword: function () { getKeyword() {
var val = this.editor.getValue(); const val = this.editor.getValue();
var keywords = val.split(/\u200b\s\u200b/); let keywords = val.split(/\u200b\s\u200b/);
if (BI.isEmptyString(keywords[keywords.length - 1])) { if (isEmptyString(keywords[keywords.length - 1])) {
keywords = keywords.slice(0, keywords.length - 1); keywords = keywords.slice(0, keywords.length - 1);
} }
return BI.isEmptyArray(keywords) ? "" : keywords[keywords.length - 1];
},
populate: function (items) {
return isEmptyArray(keywords) ? "" : keywords[keywords.length - 1];
} }
});
BI.SingleSelectEditor.EVENT_FOCUS = "EVENT_FOCUS"; populate(items) {}
BI.SingleSelectEditor.EVENT_BLUR = "EVENT_BLUR"; }
BI.shortcut("bi.single_select_editor", BI.SingleSelectEditor);

2
src/widget/singleselect/trigger/index.js

@ -0,0 +1,2 @@
export { SingleSelectEditor } from "./editor.singleselect";
export { SingleSelectSearcher } from "./searcher.singleselect";

189
src/widget/singleselect/trigger/searcher.singleselect.js

@ -1,162 +1,161 @@
/** import { shortcut, Widget, extend, emptyFn, createWidget, isNotNull, isUndefined, Selection } from "@/core";
* searcher import { SingleSelectEditor } from "./editor.singleselect";
* Created by guy on 15/11/3. import { Searcher } from "@/base";
* @class BI.SingleSelectSearcher
* @extends Widget @shortcut()
*/ export class SingleSelectSearcher extends Widget {
BI.SingleSelectSearcher = BI.inherit(BI.Widget, { static xtype = "bi.single_select_searcher";
_defaultConfig: function () { static EVENT_FOCUS = "EVENT_FOCUS";
return BI.extend(BI.SingleSelectSearcher.superclass._defaultConfig.apply(this, arguments), { static EVENT_BLUR = "EVENT_BLUR";
static EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
static EVENT_CHANGE = "EVENT_CHANGE";
static EVENT_START = "EVENT_START";
static EVENT_STOP = "EVENT_STOP";
static EVENT_PAUSE = "EVENT_PAUSE";
static EVENT_SEARCHING = "EVENT_SEARCHING";
_defaultConfig() {
return extend(super._defaultConfig(...arguments), {
baseCls: "bi-single-select-searcher", baseCls: "bi-single-select-searcher",
itemsCreator: BI.emptyFn, itemsCreator: emptyFn,
el: {}, el: {},
popup: {}, popup: {},
valueFormatter: BI.emptyFn, valueFormatter: emptyFn,
adapter: null, adapter: null,
masker: {}, masker: {},
allowNoSelect: false allowNoSelect: false,
}); });
}, }
_init: function () { _init() {
BI.SingleSelectSearcher.superclass._init.apply(this, arguments); super._init(...arguments);
var self = this, o = this.options; const self = this,
this.editor = BI.createWidget(o.el, { o = this.options;
this.editor = createWidget(o.el, {
type: "bi.single_select_editor", type: "bi.single_select_editor",
height: o.height, height: o.height,
watermark: o.watermark, watermark: o.watermark,
text: o.text, text: o.text,
listeners: [{ listeners: [{
eventName: BI.SingleSelectEditor.EVENT_FOCUS, eventName: SingleSelectEditor.EVENT_FOCUS,
action: function () { action: () => {
self.fireEvent(BI.SingleSelectSearcher.EVENT_FOCUS); this.fireEvent(SingleSelectSearcher.EVENT_FOCUS);
} },
}, { },
eventName: BI.SingleSelectEditor.EVENT_BLUR, {
action: function () { eventName: SingleSelectEditor.EVENT_BLUR,
self.fireEvent(BI.SingleSelectSearcher.EVENT_BLUR); action: () => {
} this.fireEvent(SingleSelectSearcher.EVENT_BLUR);
}] },
}
],
}); });
this.searcher = BI.createWidget({ this.searcher = createWidget({
type: "bi.searcher", type: Searcher.xtype,
element: this, element: this,
height: o.height, height: o.height,
isAutoSearch: false, isAutoSearch: false,
isAutoSync: false, isAutoSync: false,
onSearch: function (op, callback) { onSearch(op, callback) {
callback(); callback();
}, },
el: this.editor, el: this.editor,
popup: BI.extend({ popup: extend({
type: "bi.single_select_search_pane", type: "bi.single_select_search_pane",
allowNoSelect: o.allowNoSelect, allowNoSelect: o.allowNoSelect,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
keywordGetter: function () { keywordGetter: () => this.editor.getValue(),
return self.editor.getValue(); itemsCreator(op, callback) {
}, const keyword = self.editor.getValue();
itemsCreator: function (op, callback) {
var keyword = self.editor.getValue();
op.keywords = [keyword]; op.keywords = [keyword];
this.setKeyword(keyword); this.setKeyword(keyword);
o.itemsCreator(op, callback); o.itemsCreator(op, callback);
}, },
value: o.value value: o.value,
}, o.popup), },
o.popup
),
adapter: o.adapter, adapter: o.adapter,
masker: o.masker masker: o.masker,
}); });
this.searcher.on(BI.Searcher.EVENT_START, function () { this.searcher.on(Searcher.EVENT_START, () => {
self.fireEvent(BI.SingleSelectSearcher.EVENT_START); this.fireEvent(SingleSelectSearcher.EVENT_START);
}); });
this.searcher.on(BI.Searcher.EVENT_PAUSE, function () { this.searcher.on(Searcher.EVENT_PAUSE, () => {
if (this.hasMatched()) { this.fireEvent(SingleSelectSearcher.EVENT_PAUSE);
}
self.fireEvent(BI.SingleSelectSearcher.EVENT_PAUSE);
}); });
this.searcher.on(BI.Searcher.EVENT_STOP, function () { this.searcher.on(Searcher.EVENT_STOP, () => {
self.fireEvent(BI.SingleSelectSearcher.EVENT_STOP); this.fireEvent(SingleSelectSearcher.EVENT_STOP);
}); });
this.searcher.on(BI.Searcher.EVENT_CHANGE, function () { this.searcher.on(Searcher.EVENT_CHANGE, (...args) => {
self.fireEvent(BI.SingleSelectSearcher.EVENT_CHANGE, arguments); this.fireEvent(SingleSelectSearcher.EVENT_CHANGE, ...args);
}); });
this.searcher.on(BI.Searcher.EVENT_SEARCHING, function () { this.searcher.on(Searcher.EVENT_SEARCHING, () => {
var keywords = this.getKeywords(); const keywords = this.searcher.getKeywords();
self.fireEvent(BI.SingleSelectSearcher.EVENT_SEARCHING, keywords); this.fireEvent(SingleSelectSearcher.EVENT_SEARCHING, keywords);
}); });
if(BI.isNotNull(o.value)){ if (isNotNull(o.value)) {
this.setState(o.value); this.setState(o.value);
} }
}, }
adjustView: function () { adjustView() {
this.searcher.adjustView(); this.searcher.adjustView();
}, }
isSearching: function () { isSearching() {
return this.searcher.isSearching(); return this.searcher.isSearching();
}, }
stopSearch: function () { stopSearch() {
this.searcher.stopSearch(); this.searcher.stopSearch();
}, }
getKeyword: function () { getKeyword() {
return this.editor.getKeyword(); return this.editor.getKeyword();
}, }
hasMatched: function () { hasMatched() {
return this.searcher.hasMatched(); return this.searcher.hasMatched();
}, }
hasChecked: function () { hasChecked() {
return this.searcher.getView() && this.searcher.getView().hasChecked(); return this.searcher.getView() && this.searcher.getView().hasChecked();
}, }
setAdapter: function (adapter) { setAdapter(adapter) {
this.searcher.setAdapter(adapter); this.searcher.setAdapter(adapter);
}, }
setState: function (v) { setState(v) {
var o = this.options; const o = this.options;
if (BI.isUndefined(v)) { if (isUndefined(v)) {
this.editor.setState(BI.Selection.None); this.editor.setState(Selection.None);
} else { } else {
v = v ?? ""; v = v ?? "";
this.editor.setState(o.valueFormatter(v + "") || (v + "")); this.editor.setState(o.valueFormatter(`${v}`) || `${v}`);
} }
}, }
setValue: function (ob) { setValue(ob) {
this.setState(ob); this.setState(ob);
this.searcher.setValue(ob); this.searcher.setValue(ob);
}, }
getKey: function () { getKey() {
return this.editor.getValue(); return this.editor.getValue();
}, }
getValue: function () { getValue() {
return this.searcher.getValue(); return this.searcher.getValue();
}, }
populate: function (items) { populate(items) {
this.searcher.populate.apply(this.searcher, arguments); this.searcher.populate(...arguments);
} }
}); }
BI.SingleSelectSearcher.EVENT_FOCUS = "EVENT_FOCUS";
BI.SingleSelectSearcher.EVENT_BLUR = "EVENT_BLUR";
BI.SingleSelectSearcher.EVENT_BEFORE_POPUPVIEW = "EVENT_BEFORE_POPUPVIEW";
BI.SingleSelectSearcher.EVENT_CHANGE = "EVENT_CHANGE";
BI.SingleSelectSearcher.EVENT_START = "EVENT_START";
BI.SingleSelectSearcher.EVENT_STOP = "EVENT_STOP";
BI.SingleSelectSearcher.EVENT_PAUSE = "EVENT_PAUSE";
BI.SingleSelectSearcher.EVENT_SEARCHING = "EVENT_SEARCHING";
BI.shortcut("bi.single_select_searcher", BI.SingleSelectSearcher);

Loading…
Cancel
Save