windy 8 years ago
parent
commit
a1e253d733
  1. 2
      bi/base.css
  2. 4
      bi/base.js
  3. 14
      bi/core.js
  4. 664
      bi/widget.js
  5. 1
      demo/js/core/abstract/demo.virtual_group.js
  6. 2
      dist/base.css
  7. 4
      dist/base.js
  8. 14
      dist/core.js
  9. 664
      dist/widget.js
  10. 1
      src/core/base.js
  11. 5
      src/core/widget.js
  12. 6
      src/core/wrapper/layout.js

2
bi/base.css

@ -1035,7 +1035,7 @@ li.CodeMirror-hint-active {
overflow-x: hidden;
overflow-y: hidden;
white-space: nowrap;
word-break: break-all;
word-break: break-word;
}
/****添加计算宽度的--运算符直接需要space****/
/****** common color(常用颜色,可用于普遍场景) *****/

4
bi/base.js

@ -3636,11 +3636,11 @@ BI.shortcut("bi.combo_group", BI.ComboGroup);BI.VirtualGroup = BI.inherit(BI.Wid
var self = this;
items = items || [];
this.options.items = items;
items = this._packageItems(items, this._packageBtns(items));
items = this._packageBtns(items);
if (!this.layouts) {
this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items)));
} else {
this.layouts.populate(this._packageLayout(items).items);
this.layouts.populate(items);
}
}
});

14
bi/core.js

@ -2036,7 +2036,7 @@ if (!window.BI) {
},
formatEL: function (obj) {
if (obj && obj.el) {
if (obj && !obj.type && obj.el) {
return obj;
}
return {
@ -2997,7 +2997,6 @@ if (!window.BI) {
option.data = BI.cjkEncodeDO(option.data);
$.ajax({
url: option.url,
type: "POST",
@ -4458,7 +4457,8 @@ BI.Widget = BI.inherit(BI.OB, {
mounted: null,
update: null,
update: function () {
},
destroyed: null,
@ -4682,7 +4682,7 @@ BI.Widget = BI.inherit(BI.OB, {
}
widget._setParent && widget._setParent(this);
widget.on(BI.Events.DESTROY, function () {
delete self._children[name]
BI.remove(self._children, this);
});
return (this._children[name] = widget);
},
@ -11445,9 +11445,9 @@ BI.Layout = BI.inherit(BI.Widget, {
}
var child = this._children[this._getChildName(index)];
if (child.update) {
child.update(this._getOptions(item));
return true;
var updated;
if (updated = child.update(this._getOptions(item))) {
return updated;
}
var del = this._children[this._getChildName(index)];
delete this._children[this._getChildName(index)];

664
bi/widget.js

@ -7017,6 +7017,670 @@ BI.extend(BI.FileManagerNav, {
});
BI.FileManagerNav.EVENT_CHANGE = "FileManagerNav.EVENT_CHANGE";
BI.shortcut("bi.file_manager_nav", BI.FileManagerNav);/**
* 过滤条件抽象类
*
* @class BI.AbstractFilterItem
* @extend BI.Widget
*/
BI.AbstractFilterItem = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.AbstractFilterItem.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter-item"
})
},
_init: function () {
BI.AbstractFilterItem.superclass._init.apply(this, arguments);
},
isSelectedCondition: function () {
return this.emptyItem && this.emptyItem.isVisible();
},
setSelectedCondition: function (b) {
if (!!b) {
if (!this.emptyItem) {
this.emptyItem = BI.createWidget({
type: "bi.absolute",
height: 40,
cls: "filter-item-empty-item",
items: [{
el: {
type: "bi.center_adapt",
cls: "empty-filter-item-leaf"
}
}],
hgap: 10,
vgap: 5
});
BI.createWidget({
type: "bi.vertical",
element: this,
items: [this.emptyItem],
scrolly: false
});
}
}
this.emptyItem && this.emptyItem.setVisible(b);
}
});/**
* @class BI.FilterExpander
* @extend BI.AbstractFilterItem
* 过滤树的一个expander节点
*/
BI.FilterExpander = BI.inherit(BI.AbstractFilterItem, {
_constant: {
EXPANDER_WIDTH: 20
},
_defaultConfig: function () {
var conf = BI.FilterExpander.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-filter-expander",
el: {},
popup: {}
})
},
_init: function () {
BI.FilterExpander.superclass._init.apply(this, arguments);
this._initExpander();
this._initConditionsView();
BI.createWidget({
type: "bi.horizontal_adapt",
element: this,
items: [this.expander, this.conditionsView]
});
},
_initExpander: function () {
var self = this, o = this.options;
var value = o.value, text = "";
if (value === BICst.FILTER_TYPE.AND) {
text = BI.i18nText("BI-Basic_And");
} else {
text = BI.i18nText("BI-Basic_Or");
}
this.expander = BI.createWidget({
type: "bi.text_button",
cls: "condition-and-or",
text: text,
value: value,
id: o.id,
width: this._constant.EXPANDER_WIDTH,
height: "100%"
});
this.expander.on(BI.Controller.EVENT_CHANGE, function (type) {
arguments[2] = self;
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
},
_initConditionsView: function () {
var self = this, popup = this.options.popup;
this.conditionsView = BI.createWidget(popup);
this.conditionsView.on(BI.Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
},
getValue: function () {
return {
type: this.expander.getValue(),
value: this.conditionsView.getValue(),
id: this.options.id
};
},
setValue: function () {
},
populate: function (items) {
this.conditionsView.populate.apply(this.conditionsView, arguments);
}
});
BI.shortcut("bi.filter_expander", BI.FilterExpander);/**
* 过滤
*
* Created by GUY on 2015/11/20.
* @class BI.Filter
* @extend BI.Widget
*/
BI.Filter = BI.inherit(BI.Widget, {
constants: {
FIELD_TYPE_NUMBER: 1,
FIELD_TYPE_STRING: 0,
FIELD_TYPE_DATE: 2
},
_defaultConfig: function () {
return BI.extend(BI.Filter.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter",
expander: {},
items: [],
el: {},
itemCreator: BI.empty
})
},
_init: function () {
BI.Filter.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.filter = BI.createWidget(o.el,{
type: "bi.filter_operation",
expander: o.expander,
items: o.items,
element: this
});
this.filter.on(BI.FilterOperation.EVENT_OPERATION, function (type) {
switch (type) {
case BICst.FILTER_OPERATION_CONDITION:
case BICst.FILTER_OPERATION_CONDITION_AND:
self._addAndOrCondition(BICst.FILTER_TYPE.EMPTY_CONDITION);
break;
case BICst.FILTER_OPERATION_CONDITION_OR:
self._addAndOrCondition(BICst.FILTER_TYPE.EMPTY_CONDITION, 1);
break;
case BICst.FILTER_OPERATION_FORMULA:
case BICst.FILTER_OPERATION_FORMULA_AND:
self._addAndOrCondition(BICst.FILTER_TYPE.EMPTY_FORMULA);
break;
case BICst.FILTER_OPERATION_FORMULA_OR:
self._addAndOrCondition(BICst.FILTER_TYPE.EMPTY_FORMULA, 1);
break;
}
});
this.filter.on(BI.FilterOperation.EVENT_DESTROY_ITEM, function (id) {
self._removeCondition(id);
});
this.tree = new BI.Tree();
this.tree.initTree(o.items);
},
_removeCondition: function (id) {
var finded = this.tree.search(id);
if (BI.isNotNull(finded)) {
var parent = finded.getParent();
parent.removeChild(id);
if (parent.getChildrenLength() <= 1) {
var prev = parent.getParent();
if (BI.isNotNull(prev)) {
var index = prev.getChildIndex(parent.id);
prev.removeChildByIndex(index);
if (parent.getChildrenLength() === 1) {
prev.addChild(parent.getFirstChild(), index);
}
}
}
this._populate(this.tree.toJSONWithNode());
this.fireEvent(BI.Filter.EVENT_CHANGE);
}
},
_createEmptyNode: function (type) {
var node = new BI.Node(BI.UUID());
node.set("data", {
value: type
});
return node;
},
_insertAndOrCondition: function (id, formulaOrField, type) {
var ANDOR = ["AND", "OR"];
type || (type = 0);
var finded = this.tree.search(id);
if (BI.isNotNull(finded)) {
var data = finded.get("data");
var parent = finded.getParent();
var index = parent.getChildIndex(finded.id);
var pdata = parent.get("data") || {};
var node = this._createEmptyNode(formulaOrField);
if (data.value === BICst.FILTER_TYPE[ANDOR[type]]) {
this.tree.addNode(finded, node);
return;
}
if (data.value === BICst.FILTER_TYPE[ANDOR[1 - type]]) {
if (pdata.value === BICst.FILTER_TYPE[ANDOR[type]]) {
parent.addChild(node, index + 1);
return;
}
}
if ((data.value === BICst.FILTER_TYPE[ANDOR[1 - type]] && pdata.value !== BICst.FILTER_TYPE[ANDOR[type]])
|| pdata.value === BICst.FILTER_TYPE[ANDOR[1 - type]]
|| (pdata.value !== BICst.FILTER_TYPE.AND && pdata.value !== BICst.FILTER_TYPE.OR)) {
var andor = new BI.Node(BI.UUID());
andor.set("data", {
value: BICst.FILTER_TYPE[ANDOR[type]],
children: [finded.get("data"), node.get("data")]
});
parent.removeChildByIndex(index);
parent.addChild(andor, index);
andor.addChild(finded);
andor.addChild(node);
return;
}
parent.addChild(node, index + 1);
}
},
_addAndOrCondition: function (formulaOrField, type) {
var ANDOR = ["AND", "OR"];
type || (type = 0);
var o = this.options;
var currentSelectItem = this.filter.getCurrentSelectItem();
if (BI.isNotNull(currentSelectItem)) {
var id = currentSelectItem.attr("id");
this._insertAndOrCondition(id, formulaOrField, type);
} else {
var node = this._createEmptyNode(formulaOrField);
var root = this.tree.getRoot();
var child = root.getLastChild();
if (BI.isNotNull(child)) {
var data = child.get("data");
if (data.value === BICst.FILTER_TYPE[ANDOR[type]]) {
this.tree.addNode(child, node);
} else {
var andor = new BI.Node(BI.UUID());
andor.set("data", {
value: BICst.FILTER_TYPE[ANDOR[type]],
children: [child.get("data"), node.get("data")]
});
root.removeChild(child.id);
this.tree.addNode(andor);
this.tree.addNode(andor, child);
this.tree.addNode(andor, node);
}
} else {
this.tree.addNode(node);
}
}
this._populate(this.tree.toJSONWithNode());
this.fireEvent(BI.Filter.EVENT_CHANGE);
},
_populate: function (items) {
var self = this, o = this.options;
o.items = items;
ArrayUtils.traversal(items, function (i, item) {
o.itemCreator(item);
});
this.filter.populate.apply(this.filter, [items]);
},
populate: function (conditions) {
this.tree.initTree(conditions);
this._populate(this.tree.toJSONWithNode());
},
getValue: function () {
return this.filter.getValue();
}
});
BICst.FILTER_TYPE = {};
BICst.FILTER_TYPE.AND = 80;
BICst.FILTER_TYPE.OR = 81;
BICst.FILTER_TYPE.FORMULA = 82;
BICst.FILTER_TYPE.EMPTY_FORMULA = 90;
BICst.FILTER_TYPE.EMPTY_CONDITION = 91;
BI.Filter.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.filter", BI.Filter);/**
* Created by windy on 2017/3/28.
*/
BI.FilterList = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.FilterList.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter-list",
expander: {},
items: [],
itemsCreator: BI.emptyFn
})
},
render: function(){
var self = this, o = this.options;
this.group = null;
return {
type: "bi.virtual_group",
ref: function(_ref){
self.group = _ref;
},
items: BI.createItems(o.items, {
listeners: [{
eventName: BI.Controller.EVENT_CHANGE,
action: function () {
self.fireEvent(BI.Controller.EVENT_CHANGE);
}
}]
}),
layouts: [{
type: "bi.vertical",
scrolly: false
}]
}
},
populate: function (items) {
var self = this;
this.group.populate(BI.map(items, function(idx, item){
return BI.extend(item, {
listeners: [{
eventName: BI.Controller.EVENT_CHANGE,
action: function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
}
}]
});
}));
},
setValue: function (v) {
this.group.setValue(v);
},
getValue: function () {
return this.group.getValue();
}
});
BI.shortcut("bi.filter_list", BI.FilterList);/**
* 过滤条件
*
* Created by GUY on 2015/9/25.
* @class BI.FilterOperation
* @extend BI.Widget
*/
BI.FilterOperation = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.FilterOperation.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter-operation",
expander: {},
items: [],
selections: [BICst.FILTER_OPERATION_CONDITION, BICst.FILTER_OPERATION_FORMULA],
itemsCreator: BI.emptyFn
})
},
_defaultState: function () {
if (BI.isNotNull(this.currentSelected)) {
this.currentSelected.setSelectedCondition(false);
}
this.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_CONDITION);
},
_init: function () {
BI.FilterOperation.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.currentSelected = null;
this.filter = BI.createWidget({
type: "bi.filter_pane",
expander: o.expander,
items: o.items,
itemsCreator: o.itemsCreator
});
this.filter.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (type === BI.Events.CLICK) {
if (BI.isNotNull(self.currentSelected) && self.currentSelected === obj) {
obj.setSelectedCondition(!obj.isSelectedCondition());
} else {
if (BI.isNotNull(self.currentSelected)) {
self.currentSelected.setSelectedCondition(false);
}
self.currentSelected = obj;
obj.setSelectedCondition(true);
}
if (self.currentSelected.isSelectedCondition()) {
self.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_ANDOR_CONDITION);
} else {
self.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_CONDITION);
}
}
if (type === BI.Events.DESTROY) {
if (self.currentSelected === obj) {
self.currentSelected = null;
self.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_CONDITION);
}
self.fireEvent(BI.FilterOperation.EVENT_DESTROY_ITEM, value, obj);
}
});
this.filter.on(BI.FilterPane.EVENT_CHANGE, function () {
self.fireEvent(BI.FilterOperation.EVENT_CHANGE, arguments);
});
var operation = this._buildOperationTab();
BI.createWidget({
type: "bi.vtape",
element: this,
items: [{
el: operation,
height: 40
}, {
el: {
type: "bi.absolute",
scrollable: true,
items: [{
el: {
type: "bi.left",
items: [
this.filter
]
},
top: 0,
right: 2,
bottom: 0,
left: 0
}]
}
}]
})
},
_buildOperationTab: function () {
this.buttonComboTab = BI.createWidget({
type: "bi.tab",
tab: null,
cardCreator: BI.bind(this._createTabs, this)
});
this.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_CONDITION);
return this.buttonComboTab;
},
_createTabs: function (v) {
var self = this;
switch (v) {
case BI.FilterOperation.OPERATION_ADD_CONDITION:
var btnGroup = BI.createWidget({
type: "bi.button_group",
items: BI.createItems(self._createButtons(), {
type: "bi.button",
forceNotSelected: true,
level: "ignore",
height: 25
}),
chooseType: BI.ButtonGroup.CHOOSE_TYPE_DEFAULT,
layouts: [{
type: "bi.right",
hgap: 10,
vgap: 5
}]
});
btnGroup.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) {
self.fireEvent(BI.FilterOperation.EVENT_OPERATION, obj.getValue());
self._defaultState();
});
return btnGroup;
case BI.FilterOperation.OPERATION_ADD_ANDOR_CONDITION:
var btnGroup = BI.createWidget({
type: "bi.button_group",
chooseType: BI.ButtonGroup.CHOOSE_TYPE_DEFAULT,
items: self._createCombos(),
layouts: [{
type: "bi.right",
hgap: 10,
vgap: 5
}]
});
return btnGroup;
}
},
_createButtons: function(){
var buttons = [];
BI.each(this.options.selections, function(i, type){
switch (type){
case BICst.FILTER_OPERATION_FORMULA:
buttons.push({
text: BI.i18nText("BI-Add_Formula"),
value: BICst.FILTER_OPERATION_FORMULA
});
break;
case BICst.FILTER_OPERATION_CONDITION:
buttons.push({
text: BI.i18nText("BI-Add_Condition"),
value: BICst.FILTER_OPERATION_CONDITION
});
break;
}
});
return buttons;
},
_createCombos: function () {
var self = this, combos = [];
BI.each(this.options.selections, function(i, type){
var text = "", items = [];
switch (type) {
case BICst.FILTER_OPERATION_FORMULA:
text = BI.i18nText("BI-Add_Formula");
items = BICst.FILTER_ADD_FORMULA_COMBO;
break;
case BICst.FILTER_OPERATION_CONDITION:
text = BI.i18nText("BI-Add_Condition");
items = BICst.FILTER_ADD_CONDITION_COMBO;
break;
}
var addCombo = BI.createWidget({
type: "bi.static_combo",
text: text,
width: 90,
chooseType: BI.ButtonGroup.CHOOSE_TYPE_NONE,
items: BI.createItems(items, {
type: "bi.single_select_item",
height: 25
})
});
addCombo.on(BI.Combo.EVENT_CHANGE, function (value, obj) {
self.fireEvent(BI.FilterOperation.EVENT_OPERATION, obj.getValue());
self._defaultState();
});
combos.push(addCombo);
});
return combos;
},
getCurrentSelectItem: function () {
if (BI.isNotNull(this.currentSelected) && this.currentSelected.isSelectedCondition()) {
return this.currentSelected;
}
},
populate: function (items) {
this.filter.populate.apply(this.filter, arguments);
},
getValue: function () {
return this.filter.getValue();
}
});
BICst.FILTER_ADD_FORMULA_COMBO = [{
text: BI.i18nText("BI-Condition_Expression_And"), value: BICst.FILTER_OPERATION_FORMULA_AND
}, {
text: BI.i18nText("BI-Condition_Expression_Or"), value: BICst.FILTER_OPERATION_FORMULA_OR
}];
//添加条件combo
BICst.FILTER_ADD_CONDITION_COMBO = [{
text: BI.i18nText("BI-Condition_And"), value: BICst.FILTER_OPERATION_CONDITION_AND
}, {
text: BI.i18nText("BI-Condition_Or"), value: BICst.FILTER_OPERATION_CONDITION_OR
}];
BICst.FILTER_OPERATION_FORMULA = 1;
BICst.FILTER_OPERATION_CONDITION = 2;
BICst.FILTER_OPERATION_CONDITION_AND = 3;
BICst.FILTER_OPERATION_CONDITION_OR = 4;
BICst.FILTER_OPERATION_FORMULA_AND = 5;
BICst.FILTER_OPERATION_FORMULA_OR = 6;
BI.extend(BI.FilterOperation, {
OPERATION_ADD_CONDITION: 0,
OPERATION_ADD_ANDOR_CONDITION: 1
});
BI.FilterOperation.EVENT_OPERATION = "EVENT_OPERATION";
BI.FilterOperation.EVENT_CHANGE = "EVENT_CHANGE";
BI.FilterOperation.EVENT_DESTROY_ITEM = "BI.FilterOperation.EVENT_DESTROY_ITEM";
BI.shortcut("bi.filter_operation", BI.FilterOperation);/**
* @class BI.FilterPane
* @extend BI.Widget
* 过滤面板
*/
BI.FilterPane = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.FilterPane.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter-pane",
expander: {},
items: [],
itemsCreator: BI.emptyFn
})
},
_init: function () {
BI.FilterPane.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.tree = BI.createWidget({
type: "bi.custom_tree",
element: this,
expander: BI.extend({
type: "bi.filter_expander",
el: {},
popup: {
type: "bi.custom_tree"
}
}, o.expander),
el: {
type: "bi.filter_list"
}
});
this.tree.on(BI.Controller.EVENT_CHANGE, function (type) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
if (type === BI.Events.CLICK) {
self.fireEvent(BI.FilterPane.EVENT_CHANGE, [].slice.call(arguments, 1));
}
});
if (BI.isNotEmptyArray(o.items)) {
this.populate(o.items);
}
},
populate: function (items) {
this.tree.populate.apply(this.tree, arguments);
},
getValue: function () {
return this.tree.getValue();
}
});
BI.FilterPane.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.filter_pane", BI.FilterPane);/**
* Created by windy on 2017/3/13.
* 数值微调器
*/

1
demo/js/core/abstract/demo.virtual_group.js

@ -66,6 +66,7 @@ Demo.Item = BI.inherit(BI.Widget, {
update: function (item) {
this.label.setText(item.value);
console.log("更新了一项");
return true;
},
created: function () {

2
dist/base.css vendored

@ -1035,7 +1035,7 @@ li.CodeMirror-hint-active {
overflow-x: hidden;
overflow-y: hidden;
white-space: nowrap;
word-break: break-all;
word-break: break-word;
}
/****添加计算宽度的--运算符直接需要space****/
/****** common color(常用颜色,可用于普遍场景) *****/

4
dist/base.js vendored

@ -3636,11 +3636,11 @@ BI.shortcut("bi.combo_group", BI.ComboGroup);BI.VirtualGroup = BI.inherit(BI.Wid
var self = this;
items = items || [];
this.options.items = items;
items = this._packageItems(items, this._packageBtns(items));
items = this._packageBtns(items);
if (!this.layouts) {
this.layouts = BI.createWidget(BI.extend({element: this}, this._packageLayout(items)));
} else {
this.layouts.populate(this._packageLayout(items).items);
this.layouts.populate(items);
}
}
});

14
dist/core.js vendored

@ -13052,7 +13052,7 @@ if (!window.BI) {
},
formatEL: function (obj) {
if (obj && obj.el) {
if (obj && !obj.type && obj.el) {
return obj;
}
return {
@ -14013,7 +14013,6 @@ if (!window.BI) {
option.data = BI.cjkEncodeDO(option.data);
$.ajax({
url: option.url,
type: "POST",
@ -14370,7 +14369,8 @@ BI.Widget = BI.inherit(BI.OB, {
mounted: null,
update: null,
update: function () {
},
destroyed: null,
@ -14594,7 +14594,7 @@ BI.Widget = BI.inherit(BI.OB, {
}
widget._setParent && widget._setParent(this);
widget.on(BI.Events.DESTROY, function () {
delete self._children[name]
BI.remove(self._children, this);
});
return (this._children[name] = widget);
},
@ -19578,9 +19578,9 @@ BI.Layout = BI.inherit(BI.Widget, {
}
var child = this._children[this._getChildName(index)];
if (child.update) {
child.update(this._getOptions(item));
return true;
var updated;
if (updated = child.update(this._getOptions(item))) {
return updated;
}
var del = this._children[this._getChildName(index)];
delete this._children[this._getChildName(index)];

664
dist/widget.js vendored

@ -7017,6 +7017,670 @@ BI.extend(BI.FileManagerNav, {
});
BI.FileManagerNav.EVENT_CHANGE = "FileManagerNav.EVENT_CHANGE";
BI.shortcut("bi.file_manager_nav", BI.FileManagerNav);/**
* 过滤条件抽象类
*
* @class BI.AbstractFilterItem
* @extend BI.Widget
*/
BI.AbstractFilterItem = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.AbstractFilterItem.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter-item"
})
},
_init: function () {
BI.AbstractFilterItem.superclass._init.apply(this, arguments);
},
isSelectedCondition: function () {
return this.emptyItem && this.emptyItem.isVisible();
},
setSelectedCondition: function (b) {
if (!!b) {
if (!this.emptyItem) {
this.emptyItem = BI.createWidget({
type: "bi.absolute",
height: 40,
cls: "filter-item-empty-item",
items: [{
el: {
type: "bi.center_adapt",
cls: "empty-filter-item-leaf"
}
}],
hgap: 10,
vgap: 5
});
BI.createWidget({
type: "bi.vertical",
element: this,
items: [this.emptyItem],
scrolly: false
});
}
}
this.emptyItem && this.emptyItem.setVisible(b);
}
});/**
* @class BI.FilterExpander
* @extend BI.AbstractFilterItem
* 过滤树的一个expander节点
*/
BI.FilterExpander = BI.inherit(BI.AbstractFilterItem, {
_constant: {
EXPANDER_WIDTH: 20
},
_defaultConfig: function () {
var conf = BI.FilterExpander.superclass._defaultConfig.apply(this, arguments);
return BI.extend(conf, {
baseCls: (conf.baseCls || "") + " bi-filter-expander",
el: {},
popup: {}
})
},
_init: function () {
BI.FilterExpander.superclass._init.apply(this, arguments);
this._initExpander();
this._initConditionsView();
BI.createWidget({
type: "bi.horizontal_adapt",
element: this,
items: [this.expander, this.conditionsView]
});
},
_initExpander: function () {
var self = this, o = this.options;
var value = o.value, text = "";
if (value === BICst.FILTER_TYPE.AND) {
text = BI.i18nText("BI-Basic_And");
} else {
text = BI.i18nText("BI-Basic_Or");
}
this.expander = BI.createWidget({
type: "bi.text_button",
cls: "condition-and-or",
text: text,
value: value,
id: o.id,
width: this._constant.EXPANDER_WIDTH,
height: "100%"
});
this.expander.on(BI.Controller.EVENT_CHANGE, function (type) {
arguments[2] = self;
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
},
_initConditionsView: function () {
var self = this, popup = this.options.popup;
this.conditionsView = BI.createWidget(popup);
this.conditionsView.on(BI.Controller.EVENT_CHANGE, function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
});
},
getValue: function () {
return {
type: this.expander.getValue(),
value: this.conditionsView.getValue(),
id: this.options.id
};
},
setValue: function () {
},
populate: function (items) {
this.conditionsView.populate.apply(this.conditionsView, arguments);
}
});
BI.shortcut("bi.filter_expander", BI.FilterExpander);/**
* 过滤
*
* Created by GUY on 2015/11/20.
* @class BI.Filter
* @extend BI.Widget
*/
BI.Filter = BI.inherit(BI.Widget, {
constants: {
FIELD_TYPE_NUMBER: 1,
FIELD_TYPE_STRING: 0,
FIELD_TYPE_DATE: 2
},
_defaultConfig: function () {
return BI.extend(BI.Filter.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter",
expander: {},
items: [],
el: {},
itemCreator: BI.empty
})
},
_init: function () {
BI.Filter.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.filter = BI.createWidget(o.el,{
type: "bi.filter_operation",
expander: o.expander,
items: o.items,
element: this
});
this.filter.on(BI.FilterOperation.EVENT_OPERATION, function (type) {
switch (type) {
case BICst.FILTER_OPERATION_CONDITION:
case BICst.FILTER_OPERATION_CONDITION_AND:
self._addAndOrCondition(BICst.FILTER_TYPE.EMPTY_CONDITION);
break;
case BICst.FILTER_OPERATION_CONDITION_OR:
self._addAndOrCondition(BICst.FILTER_TYPE.EMPTY_CONDITION, 1);
break;
case BICst.FILTER_OPERATION_FORMULA:
case BICst.FILTER_OPERATION_FORMULA_AND:
self._addAndOrCondition(BICst.FILTER_TYPE.EMPTY_FORMULA);
break;
case BICst.FILTER_OPERATION_FORMULA_OR:
self._addAndOrCondition(BICst.FILTER_TYPE.EMPTY_FORMULA, 1);
break;
}
});
this.filter.on(BI.FilterOperation.EVENT_DESTROY_ITEM, function (id) {
self._removeCondition(id);
});
this.tree = new BI.Tree();
this.tree.initTree(o.items);
},
_removeCondition: function (id) {
var finded = this.tree.search(id);
if (BI.isNotNull(finded)) {
var parent = finded.getParent();
parent.removeChild(id);
if (parent.getChildrenLength() <= 1) {
var prev = parent.getParent();
if (BI.isNotNull(prev)) {
var index = prev.getChildIndex(parent.id);
prev.removeChildByIndex(index);
if (parent.getChildrenLength() === 1) {
prev.addChild(parent.getFirstChild(), index);
}
}
}
this._populate(this.tree.toJSONWithNode());
this.fireEvent(BI.Filter.EVENT_CHANGE);
}
},
_createEmptyNode: function (type) {
var node = new BI.Node(BI.UUID());
node.set("data", {
value: type
});
return node;
},
_insertAndOrCondition: function (id, formulaOrField, type) {
var ANDOR = ["AND", "OR"];
type || (type = 0);
var finded = this.tree.search(id);
if (BI.isNotNull(finded)) {
var data = finded.get("data");
var parent = finded.getParent();
var index = parent.getChildIndex(finded.id);
var pdata = parent.get("data") || {};
var node = this._createEmptyNode(formulaOrField);
if (data.value === BICst.FILTER_TYPE[ANDOR[type]]) {
this.tree.addNode(finded, node);
return;
}
if (data.value === BICst.FILTER_TYPE[ANDOR[1 - type]]) {
if (pdata.value === BICst.FILTER_TYPE[ANDOR[type]]) {
parent.addChild(node, index + 1);
return;
}
}
if ((data.value === BICst.FILTER_TYPE[ANDOR[1 - type]] && pdata.value !== BICst.FILTER_TYPE[ANDOR[type]])
|| pdata.value === BICst.FILTER_TYPE[ANDOR[1 - type]]
|| (pdata.value !== BICst.FILTER_TYPE.AND && pdata.value !== BICst.FILTER_TYPE.OR)) {
var andor = new BI.Node(BI.UUID());
andor.set("data", {
value: BICst.FILTER_TYPE[ANDOR[type]],
children: [finded.get("data"), node.get("data")]
});
parent.removeChildByIndex(index);
parent.addChild(andor, index);
andor.addChild(finded);
andor.addChild(node);
return;
}
parent.addChild(node, index + 1);
}
},
_addAndOrCondition: function (formulaOrField, type) {
var ANDOR = ["AND", "OR"];
type || (type = 0);
var o = this.options;
var currentSelectItem = this.filter.getCurrentSelectItem();
if (BI.isNotNull(currentSelectItem)) {
var id = currentSelectItem.attr("id");
this._insertAndOrCondition(id, formulaOrField, type);
} else {
var node = this._createEmptyNode(formulaOrField);
var root = this.tree.getRoot();
var child = root.getLastChild();
if (BI.isNotNull(child)) {
var data = child.get("data");
if (data.value === BICst.FILTER_TYPE[ANDOR[type]]) {
this.tree.addNode(child, node);
} else {
var andor = new BI.Node(BI.UUID());
andor.set("data", {
value: BICst.FILTER_TYPE[ANDOR[type]],
children: [child.get("data"), node.get("data")]
});
root.removeChild(child.id);
this.tree.addNode(andor);
this.tree.addNode(andor, child);
this.tree.addNode(andor, node);
}
} else {
this.tree.addNode(node);
}
}
this._populate(this.tree.toJSONWithNode());
this.fireEvent(BI.Filter.EVENT_CHANGE);
},
_populate: function (items) {
var self = this, o = this.options;
o.items = items;
ArrayUtils.traversal(items, function (i, item) {
o.itemCreator(item);
});
this.filter.populate.apply(this.filter, [items]);
},
populate: function (conditions) {
this.tree.initTree(conditions);
this._populate(this.tree.toJSONWithNode());
},
getValue: function () {
return this.filter.getValue();
}
});
BICst.FILTER_TYPE = {};
BICst.FILTER_TYPE.AND = 80;
BICst.FILTER_TYPE.OR = 81;
BICst.FILTER_TYPE.FORMULA = 82;
BICst.FILTER_TYPE.EMPTY_FORMULA = 90;
BICst.FILTER_TYPE.EMPTY_CONDITION = 91;
BI.Filter.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.filter", BI.Filter);/**
* Created by windy on 2017/3/28.
*/
BI.FilterList = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.FilterList.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter-list",
expander: {},
items: [],
itemsCreator: BI.emptyFn
})
},
render: function(){
var self = this, o = this.options;
this.group = null;
return {
type: "bi.virtual_group",
ref: function(_ref){
self.group = _ref;
},
items: BI.createItems(o.items, {
listeners: [{
eventName: BI.Controller.EVENT_CHANGE,
action: function () {
self.fireEvent(BI.Controller.EVENT_CHANGE);
}
}]
}),
layouts: [{
type: "bi.vertical",
scrolly: false
}]
}
},
populate: function (items) {
var self = this;
this.group.populate(BI.map(items, function(idx, item){
return BI.extend(item, {
listeners: [{
eventName: BI.Controller.EVENT_CHANGE,
action: function () {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
}
}]
});
}));
},
setValue: function (v) {
this.group.setValue(v);
},
getValue: function () {
return this.group.getValue();
}
});
BI.shortcut("bi.filter_list", BI.FilterList);/**
* 过滤条件
*
* Created by GUY on 2015/9/25.
* @class BI.FilterOperation
* @extend BI.Widget
*/
BI.FilterOperation = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.FilterOperation.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter-operation",
expander: {},
items: [],
selections: [BICst.FILTER_OPERATION_CONDITION, BICst.FILTER_OPERATION_FORMULA],
itemsCreator: BI.emptyFn
})
},
_defaultState: function () {
if (BI.isNotNull(this.currentSelected)) {
this.currentSelected.setSelectedCondition(false);
}
this.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_CONDITION);
},
_init: function () {
BI.FilterOperation.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.currentSelected = null;
this.filter = BI.createWidget({
type: "bi.filter_pane",
expander: o.expander,
items: o.items,
itemsCreator: o.itemsCreator
});
this.filter.on(BI.Controller.EVENT_CHANGE, function (type, value, obj) {
if (type === BI.Events.CLICK) {
if (BI.isNotNull(self.currentSelected) && self.currentSelected === obj) {
obj.setSelectedCondition(!obj.isSelectedCondition());
} else {
if (BI.isNotNull(self.currentSelected)) {
self.currentSelected.setSelectedCondition(false);
}
self.currentSelected = obj;
obj.setSelectedCondition(true);
}
if (self.currentSelected.isSelectedCondition()) {
self.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_ANDOR_CONDITION);
} else {
self.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_CONDITION);
}
}
if (type === BI.Events.DESTROY) {
if (self.currentSelected === obj) {
self.currentSelected = null;
self.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_CONDITION);
}
self.fireEvent(BI.FilterOperation.EVENT_DESTROY_ITEM, value, obj);
}
});
this.filter.on(BI.FilterPane.EVENT_CHANGE, function () {
self.fireEvent(BI.FilterOperation.EVENT_CHANGE, arguments);
});
var operation = this._buildOperationTab();
BI.createWidget({
type: "bi.vtape",
element: this,
items: [{
el: operation,
height: 40
}, {
el: {
type: "bi.absolute",
scrollable: true,
items: [{
el: {
type: "bi.left",
items: [
this.filter
]
},
top: 0,
right: 2,
bottom: 0,
left: 0
}]
}
}]
})
},
_buildOperationTab: function () {
this.buttonComboTab = BI.createWidget({
type: "bi.tab",
tab: null,
cardCreator: BI.bind(this._createTabs, this)
});
this.buttonComboTab.setSelect(BI.FilterOperation.OPERATION_ADD_CONDITION);
return this.buttonComboTab;
},
_createTabs: function (v) {
var self = this;
switch (v) {
case BI.FilterOperation.OPERATION_ADD_CONDITION:
var btnGroup = BI.createWidget({
type: "bi.button_group",
items: BI.createItems(self._createButtons(), {
type: "bi.button",
forceNotSelected: true,
level: "ignore",
height: 25
}),
chooseType: BI.ButtonGroup.CHOOSE_TYPE_DEFAULT,
layouts: [{
type: "bi.right",
hgap: 10,
vgap: 5
}]
});
btnGroup.on(BI.ButtonGroup.EVENT_CHANGE, function (value, obj) {
self.fireEvent(BI.FilterOperation.EVENT_OPERATION, obj.getValue());
self._defaultState();
});
return btnGroup;
case BI.FilterOperation.OPERATION_ADD_ANDOR_CONDITION:
var btnGroup = BI.createWidget({
type: "bi.button_group",
chooseType: BI.ButtonGroup.CHOOSE_TYPE_DEFAULT,
items: self._createCombos(),
layouts: [{
type: "bi.right",
hgap: 10,
vgap: 5
}]
});
return btnGroup;
}
},
_createButtons: function(){
var buttons = [];
BI.each(this.options.selections, function(i, type){
switch (type){
case BICst.FILTER_OPERATION_FORMULA:
buttons.push({
text: BI.i18nText("BI-Add_Formula"),
value: BICst.FILTER_OPERATION_FORMULA
});
break;
case BICst.FILTER_OPERATION_CONDITION:
buttons.push({
text: BI.i18nText("BI-Add_Condition"),
value: BICst.FILTER_OPERATION_CONDITION
});
break;
}
});
return buttons;
},
_createCombos: function () {
var self = this, combos = [];
BI.each(this.options.selections, function(i, type){
var text = "", items = [];
switch (type) {
case BICst.FILTER_OPERATION_FORMULA:
text = BI.i18nText("BI-Add_Formula");
items = BICst.FILTER_ADD_FORMULA_COMBO;
break;
case BICst.FILTER_OPERATION_CONDITION:
text = BI.i18nText("BI-Add_Condition");
items = BICst.FILTER_ADD_CONDITION_COMBO;
break;
}
var addCombo = BI.createWidget({
type: "bi.static_combo",
text: text,
width: 90,
chooseType: BI.ButtonGroup.CHOOSE_TYPE_NONE,
items: BI.createItems(items, {
type: "bi.single_select_item",
height: 25
})
});
addCombo.on(BI.Combo.EVENT_CHANGE, function (value, obj) {
self.fireEvent(BI.FilterOperation.EVENT_OPERATION, obj.getValue());
self._defaultState();
});
combos.push(addCombo);
});
return combos;
},
getCurrentSelectItem: function () {
if (BI.isNotNull(this.currentSelected) && this.currentSelected.isSelectedCondition()) {
return this.currentSelected;
}
},
populate: function (items) {
this.filter.populate.apply(this.filter, arguments);
},
getValue: function () {
return this.filter.getValue();
}
});
BICst.FILTER_ADD_FORMULA_COMBO = [{
text: BI.i18nText("BI-Condition_Expression_And"), value: BICst.FILTER_OPERATION_FORMULA_AND
}, {
text: BI.i18nText("BI-Condition_Expression_Or"), value: BICst.FILTER_OPERATION_FORMULA_OR
}];
//添加条件combo
BICst.FILTER_ADD_CONDITION_COMBO = [{
text: BI.i18nText("BI-Condition_And"), value: BICst.FILTER_OPERATION_CONDITION_AND
}, {
text: BI.i18nText("BI-Condition_Or"), value: BICst.FILTER_OPERATION_CONDITION_OR
}];
BICst.FILTER_OPERATION_FORMULA = 1;
BICst.FILTER_OPERATION_CONDITION = 2;
BICst.FILTER_OPERATION_CONDITION_AND = 3;
BICst.FILTER_OPERATION_CONDITION_OR = 4;
BICst.FILTER_OPERATION_FORMULA_AND = 5;
BICst.FILTER_OPERATION_FORMULA_OR = 6;
BI.extend(BI.FilterOperation, {
OPERATION_ADD_CONDITION: 0,
OPERATION_ADD_ANDOR_CONDITION: 1
});
BI.FilterOperation.EVENT_OPERATION = "EVENT_OPERATION";
BI.FilterOperation.EVENT_CHANGE = "EVENT_CHANGE";
BI.FilterOperation.EVENT_DESTROY_ITEM = "BI.FilterOperation.EVENT_DESTROY_ITEM";
BI.shortcut("bi.filter_operation", BI.FilterOperation);/**
* @class BI.FilterPane
* @extend BI.Widget
* 过滤面板
*/
BI.FilterPane = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.FilterPane.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-filter-pane",
expander: {},
items: [],
itemsCreator: BI.emptyFn
})
},
_init: function () {
BI.FilterPane.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.tree = BI.createWidget({
type: "bi.custom_tree",
element: this,
expander: BI.extend({
type: "bi.filter_expander",
el: {},
popup: {
type: "bi.custom_tree"
}
}, o.expander),
el: {
type: "bi.filter_list"
}
});
this.tree.on(BI.Controller.EVENT_CHANGE, function (type) {
self.fireEvent(BI.Controller.EVENT_CHANGE, arguments);
if (type === BI.Events.CLICK) {
self.fireEvent(BI.FilterPane.EVENT_CHANGE, [].slice.call(arguments, 1));
}
});
if (BI.isNotEmptyArray(o.items)) {
this.populate(o.items);
}
},
populate: function (items) {
this.tree.populate.apply(this.tree, arguments);
},
getValue: function () {
return this.tree.getValue();
}
});
BI.FilterPane.EVENT_CHANGE = "EVENT_CHANGE";
BI.shortcut("bi.filter_pane", BI.FilterPane);/**
* Created by windy on 2017/3/13.
* 数值微调器
*/

1
src/core/base.js

@ -1102,7 +1102,6 @@ if (!window.BI) {
option.data = BI.cjkEncodeDO(option.data);
$.ajax({
url: option.url,
type: "POST",

5
src/core/widget.js

@ -34,7 +34,8 @@ BI.Widget = BI.inherit(BI.OB, {
mounted: null,
update: null,
update: function () {
},
destroyed: null,
@ -258,7 +259,7 @@ BI.Widget = BI.inherit(BI.OB, {
}
widget._setParent && widget._setParent(this);
widget.on(BI.Events.DESTROY, function () {
delete self._children[name]
BI.remove(self._children, this);
});
return (this._children[name] = widget);
},

6
src/core/wrapper/layout.js

@ -246,9 +246,9 @@ BI.Layout = BI.inherit(BI.Widget, {
}
var child = this._children[this._getChildName(index)];
if (child.update) {
child.update(this._getOptions(item));
return true;
var updated;
if (updated = child.update(this._getOptions(item))) {
return updated;
}
var del = this._children[this._getChildName(index)];
delete this._children[this._getChildName(index)];

Loading…
Cancel
Save