Browse Source

Merge pull request #47 in FUI/fineui from ~GUY/fineui:master to master

* commit 'e93655a1c1fc9c7d29b398b039ff3d9c106fd261':
  add
  性能优化
  update
  add
  bug
  add
  function
  function
  add
  enable
es6
guy 8 years ago
parent
commit
e02eab60d2
  1. 121
      bi/base.js
  2. 2
      bi/case.js
  3. 745
      bi/core.js
  4. 462
      bi/widget.js
  5. 121
      docs/base.js
  6. 2
      docs/case.js
  7. 745
      docs/core.js
  8. 462
      docs/widget.js
  9. 29
      src/base/collection/collection.js
  10. 29
      src/base/grid/grid.js
  11. 9
      src/base/single/button/button.basic.js
  12. 25
      src/base/table/table.collection.js
  13. 23
      src/base/table/table.grid.js
  14. 6
      src/base/table/table.resizable.js
  15. 2
      src/case/table/table.adaptive.js
  16. 249
      src/core/alias.js
  17. 496
      src/core/func/function.js
  18. 3
      src/core/proto/date.js
  19. 2
      src/core/view.js
  20. 14
      src/core/widget.js
  21. 228
      src/widget/multistringlist/multistringlist.js
  22. 214
      src/widget/multitreelist/multitreelist.js
  23. 20
      src/widget/multitreelist/multitreelist.popup.js

121
bi/base.js

@ -881,9 +881,14 @@ BI.BasicButton = BI.inherit(BI.Single, {
return this.options.text;
},
_setEnable: function (b) {
_setEnable: function (enable) {
BI.BasicButton.superclass._setEnable.apply(this, arguments);
if (!b) {
if (enable === true) {
this.element.removeClass("base-disabled disabled");
} else if (enable === false) {
this.element.addClass("base-disabled disabled");
}
if (!enable) {
if (this.options.shadow) {
this.$mask && this.$mask.setVisible(false);
}
@ -2661,6 +2666,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
var child;
if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
@ -2676,9 +2682,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px");
}
renderedCells.push(this.renderedCells[index]);
renderedCells.push(child = this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
child = BI.createWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
@ -2769,8 +2775,12 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return Math.max(0, this._height - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0));
},
_populate: function () {
_populate: function (items) {
var o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
this._calculateSizeAndPositionData();
}
if (o.items.length > 0) {
this.container.setWidth(this._width);
this.container.setHeight(this._height);
@ -2839,10 +2849,21 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return this._getMaxScrollTop();
},
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () {
BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy();
cell.el._destroy();
});
this._clearChildren();
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
@ -2851,10 +2872,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
populate: function (items) {
if (items && items !== this.options.items) {
this.options.items = items;
this._calculateSizeAndPositionData();
this.restore();
}
this._populate();
this._populate(items);
}
});
BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL";
@ -14753,6 +14773,7 @@ BI.GridView = BI.inherit(BI.Widget, {
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
@ -14761,6 +14782,7 @@ BI.GridView = BI.inherit(BI.Widget, {
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key);
var child;
if (index > -1) {
if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size;
@ -14776,9 +14798,9 @@ BI.GridView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) {
this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px");
}
renderedCells.push(this.renderedCells[index]);
renderedCells.push(child = this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
child = BI.createWidget(BI.extend({
type: "bi.label",
width: columnDatum.size,
height: rowDatum.size
@ -14802,7 +14824,7 @@ BI.GridView = BI.inherit(BI.Widget, {
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
renderedWidgets[i] = child;
renderedWidgets[count++] = child;
}
}
//已存在的, 需要添加的和需要删除的
@ -14849,8 +14871,11 @@ BI.GridView = BI.inherit(BI.Widget, {
return Math.max(0, this._rowSizeAndPositionManager.getTotalSize() - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0));
},
_populate: function () {
_populate: function (items) {
var self = this, o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
}
if (o.items.length > 0) {
this.columnCount = o.items[0].length;
this.rowCount = o.items.length;
@ -14935,10 +14960,21 @@ BI.GridView = BI.inherit(BI.Widget, {
this.options.estimatedRowSize = height;
},
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () {
BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy();
cell.el._destroy();
});
this._clearChildren();
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
@ -14947,10 +14983,9 @@ BI.GridView = BI.inherit(BI.Widget, {
populate: function (items) {
if (items && items !== this.options.items) {
this.options.items = items;
this.restore();
}
this._populate();
this._populate(items);
}
});
BI.GridView.EVENT_SCROLL = "EVENT_SCROLL";
@ -28704,7 +28739,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
_populateScrollbar: function () {
var o = this.options;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0,
summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -28745,7 +28781,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
_populateTable: function () {
var self = this, o = this.options;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0,
summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -28776,7 +28813,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
var trh = otrh + this._scrollBarSize;
var blw = oblw + this._scrollBarSize;
var blh = oblh + this._scrollBarSize;
var brw = obrw+ this._scrollBarSize;
var brw = obrw + this._scrollBarSize;
var brh = obrh + this._scrollBarSize;
var digest = function (el) {
@ -28833,10 +28870,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
run(this.bottomLeftItems, o.items, leftItems);
run(this.bottomRightItems, o.items, rightItems);
this.topLeftCollection.populate(leftHeader);
this.topRightCollection.populate(rightHeader);
this.bottomLeftCollection.populate(leftItems);
this.bottomRightCollection.populate(rightItems);
this.topLeftCollection._populate(leftHeader);
this.topRightCollection._populate(rightHeader);
this.bottomLeftCollection._populate(leftItems);
this.bottomRightCollection._populate(rightItems);
},
_digest: function () {
@ -28956,8 +28993,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
return;
}
if (this._isNeedDigest === true) {
this._reRange();
this._digest();
}
this._isNeedDigest = false;
this._populateTable();
this._populateScrollbar();
},
@ -29052,6 +29091,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
this.bottomRightCollection.restore();
},
_reRange: function () {
this.topLeftCollection.reRange();
this.topRightCollection.reRange();
this.bottomLeftCollection.reRange();
this.bottomRightCollection.reRange();
},
restore: function () {
this._restore();
}
@ -29654,16 +29700,20 @@ BI.GridTable = BI.inherit(BI.Widget, {
this.contextLayout.attr("items", items);
this.contextLayout.resize();
this.topLeftGrid.populate(this.header[0]);
this.topRightGrid.populate(this.header[1]);
this.bottomLeftGrid.populate(this.items[0]);
this.bottomRightGrid.populate(this.items[1]);
this.topLeftGrid._populate(this.header[0]);
this.topRightGrid._populate(this.header[1]);
this.bottomLeftGrid._populate(this.items[0]);
this.bottomRightGrid._populate(this.items[1]);
},
_populate: function () {
if (this._width <= 0 || this._height <= 0) {
return;
}
if (this._isNeedDigest === true) {
this._reRange();
this._isNeedDigest = false;
}
this._populateTable();
this._populateScrollbar();
},
@ -29721,10 +29771,12 @@ BI.GridTable = BI.inherit(BI.Widget, {
setColumnSize: function (columnSize) {
this.options.columnSize = columnSize;
this._isNeedDigest = true;
},
setRegionColumnSize: function (regionColumnSize) {
this.options.regionColumnSize = regionColumnSize;
this._isNeedDigest = true;
},
getColumnSize: function () {
@ -29737,11 +29789,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
populate: function (items, header) {
if (items && this.options.items !== items) {
this._isNeedDigest = true;
this.options.items = items;
this.items = this._getItems();
this._restore();
}
if (header && this.options.header !== header) {
this._isNeedDigest = true;
this.options.header = header;
this.header = this._getHeader();
this._restore();
@ -29756,6 +29810,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
this.bottomRightGrid.restore();
},
_reRange: function () {
this.topLeftGrid.reRange();
this.topRightGrid.reRange();
this.bottomLeftGrid.reRange();
this.bottomRightGrid.reRange();
},
restore: function () {
this._restore();
}
@ -32349,8 +32410,10 @@ BI.ResizableTable = BI.inherit(BI.Widget, {
};
var stop = function (j, size) {
self.resizer.setVisible(false);
o.columnSize[j] = size;
self.table.setColumnSize(o.columnSize);
var columnSize = o.columnSize.slice();
columnSize[j] = size;
o.columnSize = columnSize;
self.table.setColumnSize(columnSize);
self.table.populate();
self._populate();
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE);

2
bi/case.js

@ -8762,7 +8762,7 @@ BI.AdaptiveTable = BI.inherit(BI.Widget, {
freezeCols = [];
}
if (!BI.isNumber(columnSize[0])) {
columnSize = o.minColumnSize;
columnSize = o.minColumnSize.slice();
}
var summaryFreezeColumnSize = 0, summaryColumnSize = 0;
BI.each(columnSize, function (i, size) {

745
bi/core.js

@ -3042,6 +3042,9 @@ if (!window.BI) {
}
});
})(jQuery);;(function () {
if (!window.BI) {
window.BI = {};
}
function isEmpty(value) {
// 判断是否为空值
var result = value === "" || value === null || value === undefined;
@ -3102,124 +3105,6 @@ if (!window.BI) {
return text;
}
/**
* 把日期对象按照指定格式转化成字符串
*
* @example
* var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800');
* var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12
*
* @class BI.date2Str
* @param date 日期
* @param format 日期格式
* @returns {String}
*/
function date2Str(date, format) {
if (!date) {
return '';
}
// O(len(format))
var len = format.length, result = '';
if (len > 0) {
var flagch = format.charAt(0), start = 0, str = flagch;
for (var i = 1; i < len; i++) {
var ch = format.charAt(i);
if (flagch !== ch) {
result += compileJFmt({
'char': flagch,
'str': str,
'len': i - start
}, date);
flagch = ch;
start = i;
str = flagch;
} else {
str += ch;
}
}
result += compileJFmt({
'char': flagch,
'str': str,
'len': len - start
}, date);
}
return result;
function compileJFmt(jfmt, date) {
var str = jfmt.str, len = jfmt.len, ch = jfmt['char'];
switch (ch) {
case 'E': //星期
str = Date._DN[date.getDay()];
break;
case 'y': //年
if (len <= 3) {
str = (date.getFullYear() + '').slice(2, 4);
} else {
str = date.getFullYear();
}
break;
case 'M': //月
if (len > 2) {
str = Date._MN[date.getMonth()];
} else if (len < 2) {
str = date.getMonth() + 1;
} else {
str = String.leftPad(date.getMonth() + 1 + '', 2, '0');
}
break;
case 'd': //日
if (len > 1) {
str = String.leftPad(date.getDate() + '', 2, '0');
} else {
str = date.getDate();
}
break;
case 'h': //时(12)
var hour = date.getHours() % 12;
if (hour === 0) {
hour = 12;
}
if (len > 1) {
str = String.leftPad(hour + '', 2, '0');
} else {
str = hour;
}
break;
case 'H': //时(24)
if (len > 1) {
str = String.leftPad(date.getHours() + '', 2, '0');
} else {
str = date.getHours();
}
break;
case 'm':
if (len > 1) {
str = String.leftPad(date.getMinutes() + '', 2, '0');
} else {
str = date.getMinutes();
}
break;
case 's':
if (len > 1) {
str = String.leftPad(date.getSeconds() + '', 2, '0');
} else {
str = date.getSeconds();
}
break;
case 'a':
str = date.getHours() < 12 ? 'am' : 'pm';
break;
case 'z':
str = date.getTimezone();
break;
default:
str = jfmt.str;
break;
}
return str;
}
};
/**
* 数字格式
*/
@ -3262,7 +3147,8 @@ if (!window.BI) {
} else {
return left + '.' + right;
}
};
}
/**
* 处理小数点右边小数部分
* @param tright 右边内容
@ -3306,7 +3192,7 @@ if (!window.BI) {
if (newnum.length > orilen) {
newnum = newnum.substr(1);
} else {
newnum = BI.leftPad(newnum, orilen, '0');
newnum = String.leftPad(newnum, orilen, '0');
result.leftPlus = false;
}
right = right.replace(/^[0-9]+/, newnum);
@ -3567,7 +3453,7 @@ if (!window.BI) {
return o;
})(jo);
}
};
BI.contentFormat = function (cv, fmt) {
if (isEmpty(cv)) {
@ -3609,15 +3495,122 @@ if (!window.BI) {
return text;
};
BI.leftPad = function (val, size, ch) {
var result = String(val);
if (!ch) {
ch = " ";
/**
* 把日期对象按照指定格式转化成字符串
*
* @example
* var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800');
* var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12
*
* @class BI.date2Str
* @param date 日期
* @param format 日期格式
* @returns {String}
*/
BI.date2Str = function (date, format) {
if (!date) {
return '';
}
while (result.length < size) {
result = ch + result;
// O(len(format))
var len = format.length, result = '';
if (len > 0) {
var flagch = format.charAt(0), start = 0, str = flagch;
for (var i = 1; i < len; i++) {
var ch = format.charAt(i);
if (flagch !== ch) {
result += compileJFmt({
'char': flagch,
'str': str,
'len': i - start
}, date);
flagch = ch;
start = i;
str = flagch;
} else {
str += ch;
}
}
result += compileJFmt({
'char': flagch,
'str': str,
'len': len - start
}, date);
}
return result;
function compileJFmt(jfmt, date) {
var str = jfmt.str, len = jfmt.len, ch = jfmt['char'];
switch (ch) {
case 'E': //星期
str = Date._DN[date.getDay()];
break;
case 'y': //年
if (len <= 3) {
str = (date.getFullYear() + '').slice(2, 4);
} else {
str = date.getFullYear();
}
break;
case 'M': //月
if (len > 2) {
str = Date._MN[date.getMonth()];
} else if (len < 2) {
str = date.getMonth() + 1;
} else {
str = String.leftPad(date.getMonth() + 1 + '', 2, '0');
}
break;
case 'd': //日
if (len > 1) {
str = String.leftPad(date.getDate() + '', 2, '0');
} else {
str = date.getDate();
}
break;
case 'h': //时(12)
var hour = date.getHours() % 12;
if (hour === 0) {
hour = 12;
}
if (len > 1) {
str = String.leftPad(hour + '', 2, '0');
} else {
str = hour;
}
break;
case 'H': //时(24)
if (len > 1) {
str = String.leftPad(date.getHours() + '', 2, '0');
} else {
str = date.getHours();
}
break;
case 'm':
if (len > 1) {
str = String.leftPad(date.getMinutes() + '', 2, '0');
} else {
str = date.getMinutes();
}
break;
case 's':
if (len > 1) {
str = String.leftPad(date.getSeconds() + '', 2, '0');
} else {
str = date.getSeconds();
}
break;
case 'a':
str = date.getHours() < 12 ? 'am' : 'pm';
break;
case 'z':
str = date.getTimezone();
break;
default:
str = jfmt.str;
break;
}
return str;
}
return result.toString();
};
BI.object2Number = function (value) {
@ -4492,6 +4485,7 @@ BI.Widget = BI.inherit(BI.OB, {
this._mountChildren && this._mountChildren();
BI.each(this._children, function (i, widget) {
!self.isEnabled() && widget._setEnable(false);
!self.isValid() && widget._setValid(false);
widget._mount && widget._mount();
});
this.mounted && this.mounted();
@ -4525,6 +4519,18 @@ BI.Widget = BI.inherit(BI.OB, {
});
},
_setValid: function (valid) {
if (valid === true) {
this.options.invalid = false;
} else if (valid === false) {
this.options.invalid = true;
}
//递归将所有子组件使有效
BI.each(this._children, function (i, child) {
child._setValid && child._setValid(valid);
});
},
setEnable: function (enable) {
this._setEnable(enable);
if (enable === true) {
@ -4549,6 +4555,7 @@ BI.Widget = BI.inherit(BI.OB, {
setValid: function (valid) {
this.options.invalid = !valid;
this._setValid(valid);
if (valid === true) {
this.element.removeClass("base-invalid invalid");
} else if (valid === false) {
@ -5377,7 +5384,7 @@ BI.View = BI.inherit(BI.V, {
BI.each(cardNames, function (i, name) {
delete self._cards[name];
});
this._cardLayouts[key] && this._cardLayouts[key].destroy();
this._cardLayouts[key] && this._cardLayouts[key]._destroy();
return this;
},
@ -6026,7 +6033,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"),
BI.i18nText("BI-Quarter_3"),
BI.i18nText("BI-Quarter_4")];
/** Adds the number of days array to the Date object. */
Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
@ -6500,7 +6506,8 @@ Date.parseDateTime = function (str, fmt) {
return new Date(y, m, d, hr, min, sec);
}
return today;
};/*
};
/*
* 给jQuery.Event对象添加的工具方法
*/
$.extend($.Event.prototype, {
@ -16615,284 +16622,280 @@ BI.extend(jQuery, {
* 基本的函数
* Created by GUY on 2015/6/24.
*/
$(function () {
BI.Func = {};
var formulas = {};
BI.extend(BI.Func, {
BI.Func = {};
BI.extend(BI.Func, {
/**
* 获取搜索结果
* @param items
* @param keyword
* @param param 搜索哪个属性
*/
getSearchResult: function (items, keyword, param) {
var isArray = BI.isArray(items);
items = isArray ? BI.flatten(items) : items;
param || (param = "text");
if (!BI.isKey(keyword)) {
return {
finded: BI.deepClone(items),
matched: isArray ? [] : {}
};
}
var t, text, py;
keyword = keyword + "";
keyword = BI.toUpperCase(keyword);
var matched = isArray ? [] : {}, finded = isArray ? [] : {};
BI.each(items, function (i, item) {
item = BI.deepClone(item);
t = BI.stripEL(item);
text = t[param] || t.text || t.value || t.name || t;
py = BI.makeFirstPY(text);
text = BI.toUpperCase(text);
py = BI.toUpperCase(py);
var pidx;
if (text.indexOf(keyword) > -1) {
if (text === keyword) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
} else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) {
if (text === keyword || keyword.length === text.length) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
}
});
/**
* 获取搜索结果
* @param items
* @param keyword
* @param param 搜索哪个属性
*/
getSearchResult: function (items, keyword, param) {
var isArray = BI.isArray(items);
items = isArray ? BI.flatten(items) : items;
param || (param = "text");
if (!BI.isKey(keyword)) {
return {
matched: matched,
finded: finded
finded: BI.deepClone(items),
matched: isArray ? [] : {}
};
}
var t, text, py;
keyword = BI.toUpperCase(keyword);
var matched = isArray ? [] : {}, finded = isArray ? [] : {};
BI.each(items, function (i, item) {
item = BI.deepClone(item);
t = BI.stripEL(item);
text = t[param] || t.text || t.value || t.name || t;
py = BI.makeFirstPY(text);
text = BI.toUpperCase(text);
py = BI.toUpperCase(py);
var pidx;
if (text.indexOf(keyword) > -1) {
if (text === keyword) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
} else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) {
if (text === keyword || keyword.length === text.length) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
}
},
});
});
return {
matched: matched,
finded: finded
}
},
});
/**
* 对DOM操作的通用函数
* @type {{}}
*/
BI.DOM = {};
BI.extend(BI.DOM, {
/**
* 对DOM操作的通用函数
* @type {{}}
* 把dom数组或元素悬挂起来,使其不对html产生影响
* @param dom
*/
BI.DOM = {};
BI.extend(BI.DOM, {
/**
* 把dom数组或元素悬挂起来,使其不对html产生影响
* @param dom
*/
hang: function (doms) {
if (BI.isEmpty(doms)) {
return;
}
var frag = document.createDocumentFragment();
BI.each(doms, function (i, dom) {
dom instanceof BI.Widget && (dom = dom.element);
dom instanceof $ && dom[0] && frag.appendChild(dom[0]);
});
return frag;
},
hang: function (doms) {
if (BI.isEmpty(doms)) {
return;
}
var frag = document.createDocumentFragment();
BI.each(doms, function (i, dom) {
dom instanceof BI.Widget && (dom = dom.element);
dom instanceof $ && dom[0] && frag.appendChild(dom[0]);
});
return frag;
},
isExist: function (obj) {
return $("body").find(obj.element).length > 0;
},
isExist: function (obj) {
return $("body").find(obj.element).length > 0;
},
//预加载图片
preloadImages: function (srcArray, onload) {
var count = 0, images = [];
//预加载图片
preloadImages: function (srcArray, onload) {
var count = 0, images = [];
function complete() {
count++;
if (count >= srcArray.length) {
onload();
}
function complete() {
count++;
if (count >= srcArray.length) {
onload();
}
}
BI.each(srcArray, function (i, src) {
images[i] = new Image();
images[i].src = src;
images[i].onload = function () {
complete()
};
images[i].onerror = function () {
complete()
};
});
},
BI.each(srcArray, function (i, src) {
images[i] = new Image();
images[i].src = src;
images[i].onload = function () {
complete()
};
images[i].onerror = function () {
complete()
};
});
},
isColor: function (color) {
return this.isRGBColor(color) || this.isHexColor(color);
},
isColor: function (color) {
return this.isRGBColor(color) || this.isHexColor(color);
},
isRGBColor: function (color) {
if (!color) {
return false;
}
return color.substr(0, 3) === "rgb";
},
isRGBColor: function (color) {
if (!color) {
return false;
}
return color.substr(0, 3) === "rgb";
},
isHexColor: function (color) {
if (!color) {
return false;
}
return color[0] === "#" && color.length === 7;
},
isHexColor: function (color) {
if (!color) {
return false;
}
return color[0] === "#" && color.length === 7;
},
isDarkColor: function (hex) {
if (!hex) {
return false;
}
var rgb = this.rgb2json(this.hex2rgb(hex));
var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114);
if (grayLevel < 140) {
return true;
}
isDarkColor: function (hex) {
if (!hex) {
return false;
},
}
var rgb = this.rgb2json(this.hex2rgb(hex));
var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114);
if (grayLevel < 140) {
return true;
}
return false;
},
//获取对比颜色
getContrastColor: function (color) {
if (!color) {
return "";
}
if (this.isDarkColor(color)) {
return "#ffffff";
}
return "#1a1a1a";
},
//获取对比颜色
getContrastColor: function (color) {
if (!color) {
return "";
}
if (this.isDarkColor(color)) {
return "#ffffff";
}
return "#1a1a1a";
},
rgb2hex: function (rgbColour) {
if (!rgbColour || rgbColour.substr(0, 3) != "rgb") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
var red = BI.parseInt(rgbValues[0]);
var green = BI.parseInt(rgbValues[1]);
var blue = BI.parseInt(rgbValues[2]);
rgb2hex: function (rgbColour) {
if (!rgbColour || rgbColour.substr(0, 3) != "rgb") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
var red = BI.parseInt(rgbValues[0]);
var green = BI.parseInt(rgbValues[1]);
var blue = BI.parseInt(rgbValues[2]);
var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue);
var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue);
return hexColour;
},
return hexColour;
},
rgb2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2])
};
},
rgb2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2])
};
},
rgba2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]),
a: BI.parseFloat(rgbValues[3])
};
},
rgba2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]),
a: BI.parseFloat(rgbValues[3])
};
},
json2rgb: function (rgb) {
if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) {
return "";
}
return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
},
json2rgb: function (rgb) {
if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) {
return "";
}
return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
},
json2rgba: function (rgba) {
if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) {
return "";
}
return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")";
},
json2rgba: function (rgba) {
if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) {
return "";
}
return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")";
},
int2hex: function (strNum) {
var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
int2hex: function (strNum) {
var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15];
},
return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15];
},
hex2rgb: function (color) {
if (!color) {
return "";
}
var tempValue = "rgb(", colorArray;
hex2rgb: function (color) {
if (!color) {
return "";
}
var tempValue = "rgb(", colorArray;
if (color.length === 7) {
colorArray = [BI.parseInt('0x' + color.substring(1, 3)),
BI.parseInt('0x' + color.substring(3, 5)),
BI.parseInt('0x' + color.substring(5, 7))];
}
else if (color.length === 4) {
colorArray = [BI.parseInt('0x' + color.substring(1, 2)),
BI.parseInt('0x' + color.substring(2, 3)),
BI.parseInt('0x' + color.substring(3, 4))];
}
tempValue += colorArray[0] + ",";
tempValue += colorArray[1] + ",";
tempValue += colorArray[2] + ")";
if (color.length === 7) {
colorArray = [BI.parseInt('0x' + color.substring(1, 3)),
BI.parseInt('0x' + color.substring(3, 5)),
BI.parseInt('0x' + color.substring(5, 7))];
}
else if (color.length === 4) {
colorArray = [BI.parseInt('0x' + color.substring(1, 2)),
BI.parseInt('0x' + color.substring(2, 3)),
BI.parseInt('0x' + color.substring(3, 4))];
}
tempValue += colorArray[0] + ",";
tempValue += colorArray[1] + ",";
tempValue += colorArray[2] + ")";
return tempValue;
},
return tempValue;
},
rgba2rgb: function (rgbColour, BGcolor) {
if (BI.isNull(BGcolor)) {
BGcolor = 1;
}
if (rgbColour.substr(0, 4) != "rgba") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
if (rgbValues.length < 4) {
return "";
}
var R = BI.parseFloat(rgbValues[0]);
var G = BI.parseFloat(rgbValues[1]);
var B = BI.parseFloat(rgbValues[2]);
var A = BI.parseFloat(rgbValues[3]);
rgba2rgb: function (rgbColour, BGcolor) {
if (BI.isNull(BGcolor)) {
BGcolor = 1;
}
if (rgbColour.substr(0, 4) != "rgba") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
if (rgbValues.length < 4) {
return "";
}
var R = BI.parseFloat(rgbValues[0]);
var G = BI.parseFloat(rgbValues[1]);
var B = BI.parseFloat(rgbValues[2]);
var A = BI.parseFloat(rgbValues[3]);
return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")";
},
return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")";
},
getTextSizeWidth: function (text, fontSize) {
var span = $("<span></span>").addClass("text-width-span").appendTo($("body"));
getTextSizeWidth: function (text, fontSize) {
var span = $("<span></span>").addClass("text-width-span").appendTo($("body"));
if (fontSize == null) {
fontSize = 12;
}
fontSize = fontSize + "px";
if (fontSize == null) {
fontSize = 12;
}
fontSize = fontSize + "px";
span.css("font-size", fontSize).text(text);
span.css("font-size", fontSize).text(text);
var width = span.width();
span.remove();
var width = span.width();
span.remove();
return width;
},
return width;
},
//获取滚动条的宽度
getScrollWidth: function () {
if (this._scrollWidth == null) {
var ul = $("<div>").width(50).height(50).css({
position: "absolute",
top: "-9999px",
overflow: "scroll"
}).appendTo($("body"));
this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth;
ul.destroy();
}
return this._scrollWidth;
//获取滚动条的宽度
getScrollWidth: function () {
if (this._scrollWidth == null) {
var ul = $("<div>").width(50).height(50).css({
position: "absolute",
top: "-9999px",
overflow: "scroll"
}).appendTo($("body"));
this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth;
ul.destroy();
}
});
return this._scrollWidth;
}
});/**
* guy
* 检测某个Widget的EventChange事件然后去show某个card

462
bi/widget.js

@ -10955,7 +10955,7 @@ BI.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, {
BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE = "MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE";
BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW";
BI.shortcut('bi.multi_select_check_selected_switcher', BI.MultiSelectCheckSelectedSwitcher);/**
* Created by zcf on 2016/12/14.
* Created by zcf_1 on 2017/5/2.
*/
BI.MultiStringList = BI.inherit(BI.Widget, {
_defaultConfig: function () {
@ -10963,33 +10963,30 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
baseCls: 'bi-multi-string-list',
itemsCreator: BI.emptyFn,
valueFormatter: BI.emptyFn,
height: 25
el: {}
})
},
_init: function () {
BI.MultiStringList.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.storeValue = {};
var assertShowValue = function () {
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue);
self.trigger.getSearcher().setState(self.storeValue);
self.trigger.getCounter().setButtonChecked(self.storeValue);
};
this.storeValue = {};
this.popup = BI.createWidget({
this.adapter = BI.createWidget({
type: "bi.multi_select_loader",
cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter,
onLoaded: o.onLoaded,
// onLoaded: o.onLoaded,
el: {
height: ""
}
});
this.popup.on(BI.MultiSelectLoader.EVENT_CHANGE, function () {
this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue();
self._adjust(function () {
assertShowValue();
@ -10997,90 +10994,105 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
});
});
this.trigger = BI.createWidget({
type: "bi.multi_select_trigger",
height: o.height,
adapter: this.popup,
masker: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
this.searcherPane = BI.createWidget({
type: "bi.multi_select_search_pane",
cls: "bi-border-left bi-border-right bi-border-bottom",
valueFormatter: o.valueFormatter,
keywordGetter: function () {
return self.trigger.getKeyword();
},
itemsCreator: function (op, callback) {
o.itemsCreator(op, function (res) {
if (op.times === 1 && BI.isNotNull(op.keyword)) {
self.trigger.setValue(self.getValue());
}
callback.apply(self, arguments);
});
op.keyword = self.trigger.getKeyword();
this.setKeyword(op.keyword);
o.itemsCreator(op, callback);
}
});
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () {
self._setStartValue("");
this.getSearcher().setValue(self.storeValue);
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () {
self._setStartValue("");
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () {
if (this.getSearcher().hasMatched()) {
var keyword = this.getSearcher().getKeyword();
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.populate();
this.trigger = BI.createWidget({
type: "bi.searcher",
isAutoSearch: false,
isAutoSync: false,
onSearch: function (op, callback) {
callback();
},
adapter: this.adapter,
popup: this.searcherPane,
height: 200,
masker: false,
listeners: [{
eventName: BI.Searcher.EVENT_START,
action: function () {
self._showSearcherPane();
self._setStartValue("");
self.fireEvent(BI.MultiStringList.EVENT_CHANGE);
})
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords);
keywords = BI.initial(keywords || []);
if (keywords.length > 0) {
self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) {
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
assertShowValue();
self.popup.populate();
self._setStartValue("");
this.setValue(self.storeValue);
}
}, {
eventName: BI.Searcher.EVENT_STOP,
action: function () {
self._showAdapter();
self._setStartValue("");
self.adapter.setValue(self.storeValue);
}
}, {
eventName: BI.Searcher.EVENT_PAUSE,
action: function () {
if (this.hasMatched()) {
var keyword = this.getKeyword();
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
self._showAdapter();
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self._setStartValue("");
self.fireEvent(BI.MultiStringList.EVENT_CHANGE);
})
} else {
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
assertShowValue();
self._showAdapter();
}
});
}
}
}, {
eventName: BI.Searcher.EVENT_SEARCHING,
action: function () {
var keywords = this.getKeyword();
var last = BI.last(keywords);
keywords = BI.initial(keywords || []);
if (keywords.length > 0) {
self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue);
assertShowValue();
self.adapter.populate();
self._setStartValue("");
} else {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue);
assertShowValue();
}
});
}
}
}, {
eventName: BI.Searcher.EVENT_CHANGE,
action: function (value, obj) {
if (obj instanceof BI.MultiSelectBar) {
self._joinAll(this.getValue(), function () {
assertShowValue();
});
} else {
self._join(this.getValue(), function () {//安徽省 北京
assertShowValue();
});
}
}
}]
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) {
if (obj instanceof BI.MultiSelectBar) {
self._joinAll(this.getValue(), function () {
assertShowValue();
});
} else {
self._join(this.getValue(), function () {//安徽省 北京
assertShowValue();
});
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () {
this.getCounter().setValue(self.storeValue);
});
var div = BI.createWidget({
type: "bi.layout"
});
BI.createWidget({
type: "bi.vtape",
element: this,
@ -11088,16 +11100,37 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
width: "100%",
items: [{
el: this.trigger,
height: 25
}, {
el: div,
height: 2
height: 30
}, {
el: this.popup,
el: this.adapter,
height: "fill"
}]
});
BI.createWidget({
type: "bi.absolute",
element: this,
height: "100%",
width: "100%",
items: [{
el: this.searcherPane,
top: 30,
bottom: 0,
left: 0,
right: 0
}]
})
},
_showAdapter: function () {
this.adapter.setVisible(true);
this.searcherPane.setVisible(false);
},
_showSearcherPane: function () {
this.searcherPane.setVisible(true);
this.adapter.setVisible(false);
},
_defaultState: function () {
this.trigger.stopEditing();
},
@ -11142,7 +11175,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
this._assertValue(res);
o.itemsCreator({
type: BI.MultiStringList.REQ_GET_ALL_DATA,
keyword: this.trigger.getKey()
keyword: self.trigger.getKeyword()
}, function (ob) {
var items = BI.pluck(ob.items, "value");
if (self.storeValue.type === res.type) {
@ -11231,22 +11264,21 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
_setStartValue: function (value) {
this._startValue = value;
this.popup.setStartValue(value);
this.adapter.setStartValue(value);
},
// isAllSelected: function () {
// return this.popup.isAllSelected();
// },
isAllSelected: function () {
return this.adapter.isAllSelected();
},
resize: function () {
this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView();
// this.trigger.getCounter().adjustView();
// this.trigger.adjustView();
},
setValue: function (v) {
this.storeValue = v || {};
this._assertValue(this.storeValue);
this.popup.setValue(this.storeValue);
this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue);
},
@ -11257,7 +11289,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
populate: function () {
this._count = null;
this._allData = null;
this.popup.populate.apply(this.popup, arguments);
this.adapter.populate.apply(this.adapter, arguments);
this.trigger.populate.apply(this.trigger, arguments);
}
});
@ -12008,130 +12040,96 @@ BI.MultiTreeSearcher.EVENT_START = "EVENT_START";
BI.MultiTreeSearcher.EVENT_STOP = "EVENT_STOP";
BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE";
BI.shortcut('bi.multi_tree_searcher', BI.MultiTreeSearcher);/**
* Created by zcf on 2016/12/20.
* Created by zcf_1 on 2017/5/11.
*/
BI.MultiTreeList = BI.inherit(BI.Widget, {
constants: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
BI.MultiSelectTree = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.MultiTreeList.superclass._defaultConfig.apply(this, arguments), {
return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), {
baseCls: 'bi-multi-tree-combo',
itemsCreator: BI.emptyFn,
height: 25
});
})
},
_init: function () {
BI.MultiTreeList.superclass._init.apply(this, arguments);
BI.MultiSelectTree.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.storeValue = {value: {}};
var isInit = false;
var want2showCounter = false;
this.popup = BI.createWidget({
type: "bi.multi_tree_list_popup",
this.adapter = BI.createWidget({
type: "bi.multi_select_tree_popup",
itemsCreator: o.itemsCreator
});
this.popup.on(BI.MultiStringListPopup.EVENT_AFTER_INIT, function () {
self.trigger.getCounter().adjustView();
isInit = true;
if (want2showCounter === true) {
showCounter();
this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () {
if (self.trigger.isSearching()) {
self.storeValue = {value: self.searcherPane.getValue()};
} else {
self.storeValue = {value: self.adapter.getValue()};
}
self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
});
this.trigger = BI.createWidget({
type: "bi.multi_select_trigger",
height: o.height,
adapter: this.popup,
masker: {
offset: this.constants.offset
this.searcherPane = BI.createWidget({//搜索中的时候用的是parttree,同adapter中的synctree不一样
type: "bi.multi_tree_search_pane",
cls: "bi-border-left bi-border-right bi-border-bottom",
keywordGetter: function () {
return self.trigger.getKeyword();
},
searcher: {
type: "bi.multi_tree_searcher",
itemsCreator: o.itemsCreator
},
switcher: {
el: {
type: "bi.multi_tree_check_selected_button"
},
popup: {
type: "bi.multi_tree_check_pane",
itemsCreator: o.itemsCreator
}
}
});
this.storeValue = {value: {}};
var isSearching = function () {
return self.trigger.getSearcher().isSearching();
};
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () {
self.storeValue = {value: self.popup.getValue()};
this.setValue(self.storeValue);
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () {
self.storeValue = {value: this.getValue()};
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
BI.nextTick(function () {
self.trigger.populate();
self.popup.populate();
});
});
function showCounter() {
if (isSearching()) {
self.storeValue = {value: self.trigger.getValue()};
} else {
self.storeValue = {value: self.popup.getValue()};
}
self.trigger.setValue(self.storeValue);
}
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () {
if (want2showCounter === false) {
want2showCounter = true;
}
if (isInit === true) {
want2showCounter = null;
showCounter();
itemsCreator: function (op, callback) {
op.keyword = self.trigger.getKeyword();
o.itemsCreator(op, callback);
}
});
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () {
var val = {
type: BI.Selection.Multi,
value: this.getSearcher().hasChecked() ? {1: 1} : {}
};
this.getSearcher().setState(val);
this.getCounter().setButtonChecked(val);
});
this.popup.on(BI.MultiStringListPopup.EVENT_CHANGE, function () {
showCounter();
var val = {
type: BI.Selection.Multi,
value: this.hasChecked() ? {1: 1} : {}
};
self.trigger.getSearcher().setState(val);
self.trigger.getCounter().setButtonChecked(val);
self.fireEvent(BI.MultiTreeList.EVENT_CHANGE);
this.trigger = BI.createWidget({
type: "bi.searcher",
isAutoSearch: false,
isAutoSync: false,
onSearch: function (op, callback) {
callback({
keyword: self.trigger.getKeyword()
});
},
adapter: this.adapter,
popup: this.searcherPane,
height: 200,
masker: false,
listeners: [{
eventName: BI.Searcher.EVENT_START,
action: function () {
self._showSearcherPane();
self.storeValue = {value: self.adapter.getValue()};
self.searcherPane.setValue(self.storeValue);
}
}, {
eventName: BI.Searcher.EVENT_STOP,
action: function () {
self._showAdapter();
// self.storeValue = {value: self.searcherPane.getValue()};
self.adapter.setValue(self.storeValue);
BI.nextTick(function () {
self.adapter.populate();
});
}
}, {
eventName: BI.Searcher.EVENT_CHANGE,
action: function () {
if (self.trigger.isSearching()) {
self.storeValue = {value: self.searcherPane.getValue()};
} else {
self.storeValue = {value: self.adapter.getValue()};
}
self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
}
}, {
eventName: BI.Searcher.EVENT_PAUSE,
action: function () {
self._showAdapter();
}
}]
});
var div = BI.createWidget({
type: "bi.layout"
});
BI.createWidget({
type: "bi.vtape",
element: this,
@ -12139,29 +12137,45 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
width: "100%",
items: [{
el: this.trigger,
height: 25
}, {
el: div,
height: 2
height: 30
}, {
el: this.popup,
el: this.adapter,
height: "fill"
}]
});
BI.createWidget({
type: "bi.absolute",
element: this,
height: "100%",
width: "100%",
items: [{
el: this.searcherPane,
top: 30,
bottom: 0,
left: 0,
right: 0
}]
})
},
_defaultState: function () {
this.trigger.stopEditing();
_showAdapter: function () {
this.adapter.setVisible(true);
this.searcherPane.setVisible(false);
},
_showSearcherPane: function () {
this.searcherPane.setVisible(true);
this.adapter.setVisible(false);
},
resize: function () {
this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView();
},
setValue: function (v) {
this.storeValue.value = v || {};
this.popup.setValue({
this.adapter.setValue({
value: v || {}
});
this.trigger.setValue({
@ -12175,22 +12189,22 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
populate: function () {
this.trigger.populate.apply(this.trigger, arguments);
this.popup.populate.apply(this.popup, arguments);
this.adapter.populate.apply(this.adapter, arguments);
}
});
BI.MultiTreeList.EVENT_CHANGE = "MultiTreeList.EVENT_CHANGE";
BI.shortcut('bi.multi_tree_list', BI.MultiTreeList);/**
BI.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE";
BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree);/**
* Created by zcf on 2016/12/21.
*/
BI.MultiStringListPopup=BI.inherit(BI.Widget,{
_defaultConfig:function () {
return BI.extend(BI.MultiStringListPopup.superclass._defaultConfig.apply(this, arguments), {
BI.MultiSelectTreePopup = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom",
itemsCreator: BI.emptyFn
});
},
_init:function () {
BI.MultiStringListPopup.superclass._init.apply(this, arguments);
_init: function () {
BI.MultiSelectTreePopup.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.popup = BI.createWidget({
type: "bi.sync_tree",
@ -12199,10 +12213,10 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{
itemsCreator: o.itemsCreator
});
this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () {
self.fireEvent(BI.MultiStringListPopup.EVENT_AFTER_INIT)
self.fireEvent(BI.MultiSelectTreePopup.EVENT_AFTER_INIT)
});
this.popup.on(BI.TreeView.EVENT_CHANGE, function () {
self.fireEvent(BI.MultiStringListPopup.EVENT_CHANGE)
self.fireEvent(BI.MultiSelectTreePopup.EVENT_CHANGE)
});
},
@ -12224,9 +12238,9 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{
}
});
BI.MultiStringListPopup.EVENT_AFTER_INIT="BI.MultiStringListPopup.EVENT_AFTER_INIT";
BI.MultiStringListPopup.EVENT_CHANGE="BI.MultiStringListPopup.EVENT_CHANGE";
BI.shortcut("bi.multi_tree_list_popup",BI.MultiStringListPopup);//小于号的值为:0,小于等于号的值为:1
BI.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT";
BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE";
BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);//小于号的值为:0,小于等于号的值为:1
//closeMIn:最小值的符号,closeMax:最大值的符号
/**
* Created by roy on 15/9/17.

121
docs/base.js

@ -881,9 +881,14 @@ BI.BasicButton = BI.inherit(BI.Single, {
return this.options.text;
},
_setEnable: function (b) {
_setEnable: function (enable) {
BI.BasicButton.superclass._setEnable.apply(this, arguments);
if (!b) {
if (enable === true) {
this.element.removeClass("base-disabled disabled");
} else if (enable === false) {
this.element.addClass("base-disabled disabled");
}
if (!enable) {
if (this.options.shadow) {
this.$mask && this.$mask.setVisible(false);
}
@ -2661,6 +2666,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
var child;
if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
@ -2676,9 +2682,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px");
}
renderedCells.push(this.renderedCells[index]);
renderedCells.push(child = this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
child = BI.createWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
@ -2769,8 +2775,12 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return Math.max(0, this._height - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0));
},
_populate: function () {
_populate: function (items) {
var o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
this._calculateSizeAndPositionData();
}
if (o.items.length > 0) {
this.container.setWidth(this._width);
this.container.setHeight(this._height);
@ -2839,10 +2849,21 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return this._getMaxScrollTop();
},
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () {
BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy();
cell.el._destroy();
});
this._clearChildren();
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
@ -2851,10 +2872,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
populate: function (items) {
if (items && items !== this.options.items) {
this.options.items = items;
this._calculateSizeAndPositionData();
this.restore();
}
this._populate();
this._populate(items);
}
});
BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL";
@ -14753,6 +14773,7 @@ BI.GridView = BI.inherit(BI.Widget, {
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
@ -14761,6 +14782,7 @@ BI.GridView = BI.inherit(BI.Widget, {
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key);
var child;
if (index > -1) {
if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size;
@ -14776,9 +14798,9 @@ BI.GridView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) {
this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px");
}
renderedCells.push(this.renderedCells[index]);
renderedCells.push(child = this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
child = BI.createWidget(BI.extend({
type: "bi.label",
width: columnDatum.size,
height: rowDatum.size
@ -14802,7 +14824,7 @@ BI.GridView = BI.inherit(BI.Widget, {
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
renderedWidgets[i] = child;
renderedWidgets[count++] = child;
}
}
//已存在的, 需要添加的和需要删除的
@ -14849,8 +14871,11 @@ BI.GridView = BI.inherit(BI.Widget, {
return Math.max(0, this._rowSizeAndPositionManager.getTotalSize() - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0));
},
_populate: function () {
_populate: function (items) {
var self = this, o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
}
if (o.items.length > 0) {
this.columnCount = o.items[0].length;
this.rowCount = o.items.length;
@ -14935,10 +14960,21 @@ BI.GridView = BI.inherit(BI.Widget, {
this.options.estimatedRowSize = height;
},
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () {
BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy();
cell.el._destroy();
});
this._clearChildren();
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
@ -14947,10 +14983,9 @@ BI.GridView = BI.inherit(BI.Widget, {
populate: function (items) {
if (items && items !== this.options.items) {
this.options.items = items;
this.restore();
}
this._populate();
this._populate(items);
}
});
BI.GridView.EVENT_SCROLL = "EVENT_SCROLL";
@ -28704,7 +28739,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
_populateScrollbar: function () {
var o = this.options;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0,
summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -28745,7 +28781,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
_populateTable: function () {
var self = this, o = this.options;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0,
summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -28776,7 +28813,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
var trh = otrh + this._scrollBarSize;
var blw = oblw + this._scrollBarSize;
var blh = oblh + this._scrollBarSize;
var brw = obrw+ this._scrollBarSize;
var brw = obrw + this._scrollBarSize;
var brh = obrh + this._scrollBarSize;
var digest = function (el) {
@ -28833,10 +28870,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
run(this.bottomLeftItems, o.items, leftItems);
run(this.bottomRightItems, o.items, rightItems);
this.topLeftCollection.populate(leftHeader);
this.topRightCollection.populate(rightHeader);
this.bottomLeftCollection.populate(leftItems);
this.bottomRightCollection.populate(rightItems);
this.topLeftCollection._populate(leftHeader);
this.topRightCollection._populate(rightHeader);
this.bottomLeftCollection._populate(leftItems);
this.bottomRightCollection._populate(rightItems);
},
_digest: function () {
@ -28956,8 +28993,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
return;
}
if (this._isNeedDigest === true) {
this._reRange();
this._digest();
}
this._isNeedDigest = false;
this._populateTable();
this._populateScrollbar();
},
@ -29052,6 +29091,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
this.bottomRightCollection.restore();
},
_reRange: function () {
this.topLeftCollection.reRange();
this.topRightCollection.reRange();
this.bottomLeftCollection.reRange();
this.bottomRightCollection.reRange();
},
restore: function () {
this._restore();
}
@ -29654,16 +29700,20 @@ BI.GridTable = BI.inherit(BI.Widget, {
this.contextLayout.attr("items", items);
this.contextLayout.resize();
this.topLeftGrid.populate(this.header[0]);
this.topRightGrid.populate(this.header[1]);
this.bottomLeftGrid.populate(this.items[0]);
this.bottomRightGrid.populate(this.items[1]);
this.topLeftGrid._populate(this.header[0]);
this.topRightGrid._populate(this.header[1]);
this.bottomLeftGrid._populate(this.items[0]);
this.bottomRightGrid._populate(this.items[1]);
},
_populate: function () {
if (this._width <= 0 || this._height <= 0) {
return;
}
if (this._isNeedDigest === true) {
this._reRange();
this._isNeedDigest = false;
}
this._populateTable();
this._populateScrollbar();
},
@ -29721,10 +29771,12 @@ BI.GridTable = BI.inherit(BI.Widget, {
setColumnSize: function (columnSize) {
this.options.columnSize = columnSize;
this._isNeedDigest = true;
},
setRegionColumnSize: function (regionColumnSize) {
this.options.regionColumnSize = regionColumnSize;
this._isNeedDigest = true;
},
getColumnSize: function () {
@ -29737,11 +29789,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
populate: function (items, header) {
if (items && this.options.items !== items) {
this._isNeedDigest = true;
this.options.items = items;
this.items = this._getItems();
this._restore();
}
if (header && this.options.header !== header) {
this._isNeedDigest = true;
this.options.header = header;
this.header = this._getHeader();
this._restore();
@ -29756,6 +29810,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
this.bottomRightGrid.restore();
},
_reRange: function () {
this.topLeftGrid.reRange();
this.topRightGrid.reRange();
this.bottomLeftGrid.reRange();
this.bottomRightGrid.reRange();
},
restore: function () {
this._restore();
}
@ -32349,8 +32410,10 @@ BI.ResizableTable = BI.inherit(BI.Widget, {
};
var stop = function (j, size) {
self.resizer.setVisible(false);
o.columnSize[j] = size;
self.table.setColumnSize(o.columnSize);
var columnSize = o.columnSize.slice();
columnSize[j] = size;
o.columnSize = columnSize;
self.table.setColumnSize(columnSize);
self.table.populate();
self._populate();
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE);

2
docs/case.js

@ -8762,7 +8762,7 @@ BI.AdaptiveTable = BI.inherit(BI.Widget, {
freezeCols = [];
}
if (!BI.isNumber(columnSize[0])) {
columnSize = o.minColumnSize;
columnSize = o.minColumnSize.slice();
}
var summaryFreezeColumnSize = 0, summaryColumnSize = 0;
BI.each(columnSize, function (i, size) {

745
docs/core.js

@ -14487,6 +14487,7 @@ BI.Widget = BI.inherit(BI.OB, {
this._mountChildren && this._mountChildren();
BI.each(this._children, function (i, widget) {
!self.isEnabled() && widget._setEnable(false);
!self.isValid() && widget._setValid(false);
widget._mount && widget._mount();
});
this.mounted && this.mounted();
@ -14520,6 +14521,18 @@ BI.Widget = BI.inherit(BI.OB, {
});
},
_setValid: function (valid) {
if (valid === true) {
this.options.invalid = false;
} else if (valid === false) {
this.options.invalid = true;
}
//递归将所有子组件使有效
BI.each(this._children, function (i, child) {
child._setValid && child._setValid(valid);
});
},
setEnable: function (enable) {
this._setEnable(enable);
if (enable === true) {
@ -14544,6 +14557,7 @@ BI.Widget = BI.inherit(BI.OB, {
setValid: function (valid) {
this.options.invalid = !valid;
this._setValid(valid);
if (valid === true) {
this.element.removeClass("base-invalid invalid");
} else if (valid === false) {
@ -15372,7 +15386,7 @@ BI.View = BI.inherit(BI.V, {
BI.each(cardNames, function (i, name) {
delete self._cards[name];
});
this._cardLayouts[key] && this._cardLayouts[key].destroy();
this._cardLayouts[key] && this._cardLayouts[key]._destroy();
return this;
},
@ -19906,6 +19920,9 @@ BI.PopoverSection = BI.inherit(BI.Widget, {
}
});
BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
if (!window.BI) {
window.BI = {};
}
function isEmpty(value) {
// 判断是否为空值
var result = value === "" || value === null || value === undefined;
@ -19966,124 +19983,6 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
return text;
}
/**
* 把日期对象按照指定格式转化成字符串
*
* @example
* var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800');
* var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12
*
* @class BI.date2Str
* @param date 日期
* @param format 日期格式
* @returns {String}
*/
function date2Str(date, format) {
if (!date) {
return '';
}
// O(len(format))
var len = format.length, result = '';
if (len > 0) {
var flagch = format.charAt(0), start = 0, str = flagch;
for (var i = 1; i < len; i++) {
var ch = format.charAt(i);
if (flagch !== ch) {
result += compileJFmt({
'char': flagch,
'str': str,
'len': i - start
}, date);
flagch = ch;
start = i;
str = flagch;
} else {
str += ch;
}
}
result += compileJFmt({
'char': flagch,
'str': str,
'len': len - start
}, date);
}
return result;
function compileJFmt(jfmt, date) {
var str = jfmt.str, len = jfmt.len, ch = jfmt['char'];
switch (ch) {
case 'E': //星期
str = Date._DN[date.getDay()];
break;
case 'y': //年
if (len <= 3) {
str = (date.getFullYear() + '').slice(2, 4);
} else {
str = date.getFullYear();
}
break;
case 'M': //月
if (len > 2) {
str = Date._MN[date.getMonth()];
} else if (len < 2) {
str = date.getMonth() + 1;
} else {
str = String.leftPad(date.getMonth() + 1 + '', 2, '0');
}
break;
case 'd': //日
if (len > 1) {
str = String.leftPad(date.getDate() + '', 2, '0');
} else {
str = date.getDate();
}
break;
case 'h': //时(12)
var hour = date.getHours() % 12;
if (hour === 0) {
hour = 12;
}
if (len > 1) {
str = String.leftPad(hour + '', 2, '0');
} else {
str = hour;
}
break;
case 'H': //时(24)
if (len > 1) {
str = String.leftPad(date.getHours() + '', 2, '0');
} else {
str = date.getHours();
}
break;
case 'm':
if (len > 1) {
str = String.leftPad(date.getMinutes() + '', 2, '0');
} else {
str = date.getMinutes();
}
break;
case 's':
if (len > 1) {
str = String.leftPad(date.getSeconds() + '', 2, '0');
} else {
str = date.getSeconds();
}
break;
case 'a':
str = date.getHours() < 12 ? 'am' : 'pm';
break;
case 'z':
str = date.getTimezone();
break;
default:
str = jfmt.str;
break;
}
return str;
}
};
/**
* 数字格式
*/
@ -20126,7 +20025,8 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
} else {
return left + '.' + right;
}
};
}
/**
* 处理小数点右边小数部分
* @param tright 右边内容
@ -20170,7 +20070,7 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
if (newnum.length > orilen) {
newnum = newnum.substr(1);
} else {
newnum = BI.leftPad(newnum, orilen, '0');
newnum = String.leftPad(newnum, orilen, '0');
result.leftPlus = false;
}
right = right.replace(/^[0-9]+/, newnum);
@ -20431,7 +20331,7 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
return o;
})(jo);
}
};
BI.contentFormat = function (cv, fmt) {
if (isEmpty(cv)) {
@ -20473,15 +20373,122 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
return text;
};
BI.leftPad = function (val, size, ch) {
var result = String(val);
if (!ch) {
ch = " ";
/**
* 把日期对象按照指定格式转化成字符串
*
* @example
* var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800');
* var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12
*
* @class BI.date2Str
* @param date 日期
* @param format 日期格式
* @returns {String}
*/
BI.date2Str = function (date, format) {
if (!date) {
return '';
}
while (result.length < size) {
result = ch + result;
// O(len(format))
var len = format.length, result = '';
if (len > 0) {
var flagch = format.charAt(0), start = 0, str = flagch;
for (var i = 1; i < len; i++) {
var ch = format.charAt(i);
if (flagch !== ch) {
result += compileJFmt({
'char': flagch,
'str': str,
'len': i - start
}, date);
flagch = ch;
start = i;
str = flagch;
} else {
str += ch;
}
}
result += compileJFmt({
'char': flagch,
'str': str,
'len': len - start
}, date);
}
return result;
function compileJFmt(jfmt, date) {
var str = jfmt.str, len = jfmt.len, ch = jfmt['char'];
switch (ch) {
case 'E': //星期
str = Date._DN[date.getDay()];
break;
case 'y': //年
if (len <= 3) {
str = (date.getFullYear() + '').slice(2, 4);
} else {
str = date.getFullYear();
}
break;
case 'M': //月
if (len > 2) {
str = Date._MN[date.getMonth()];
} else if (len < 2) {
str = date.getMonth() + 1;
} else {
str = String.leftPad(date.getMonth() + 1 + '', 2, '0');
}
break;
case 'd': //日
if (len > 1) {
str = String.leftPad(date.getDate() + '', 2, '0');
} else {
str = date.getDate();
}
break;
case 'h': //时(12)
var hour = date.getHours() % 12;
if (hour === 0) {
hour = 12;
}
if (len > 1) {
str = String.leftPad(hour + '', 2, '0');
} else {
str = hour;
}
break;
case 'H': //时(24)
if (len > 1) {
str = String.leftPad(date.getHours() + '', 2, '0');
} else {
str = date.getHours();
}
break;
case 'm':
if (len > 1) {
str = String.leftPad(date.getMinutes() + '', 2, '0');
} else {
str = date.getMinutes();
}
break;
case 's':
if (len > 1) {
str = String.leftPad(date.getSeconds() + '', 2, '0');
} else {
str = date.getSeconds();
}
break;
case 'a':
str = date.getHours() < 12 ? 'am' : 'pm';
break;
case 'z':
str = date.getTimezone();
break;
default:
str = jfmt.str;
break;
}
return str;
}
return result.toString();
};
BI.object2Number = function (value) {
@ -22638,284 +22645,280 @@ BI.extend(jQuery, {
* 基本的函数
* Created by GUY on 2015/6/24.
*/
$(function () {
BI.Func = {};
var formulas = {};
BI.extend(BI.Func, {
BI.Func = {};
BI.extend(BI.Func, {
/**
* 获取搜索结果
* @param items
* @param keyword
* @param param 搜索哪个属性
*/
getSearchResult: function (items, keyword, param) {
var isArray = BI.isArray(items);
items = isArray ? BI.flatten(items) : items;
param || (param = "text");
if (!BI.isKey(keyword)) {
return {
finded: BI.deepClone(items),
matched: isArray ? [] : {}
};
}
var t, text, py;
keyword = keyword + "";
keyword = BI.toUpperCase(keyword);
var matched = isArray ? [] : {}, finded = isArray ? [] : {};
BI.each(items, function (i, item) {
item = BI.deepClone(item);
t = BI.stripEL(item);
text = t[param] || t.text || t.value || t.name || t;
py = BI.makeFirstPY(text);
text = BI.toUpperCase(text);
py = BI.toUpperCase(py);
var pidx;
if (text.indexOf(keyword) > -1) {
if (text === keyword) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
} else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) {
if (text === keyword || keyword.length === text.length) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
}
});
/**
* 获取搜索结果
* @param items
* @param keyword
* @param param 搜索哪个属性
*/
getSearchResult: function (items, keyword, param) {
var isArray = BI.isArray(items);
items = isArray ? BI.flatten(items) : items;
param || (param = "text");
if (!BI.isKey(keyword)) {
return {
matched: matched,
finded: finded
finded: BI.deepClone(items),
matched: isArray ? [] : {}
};
}
var t, text, py;
keyword = BI.toUpperCase(keyword);
var matched = isArray ? [] : {}, finded = isArray ? [] : {};
BI.each(items, function (i, item) {
item = BI.deepClone(item);
t = BI.stripEL(item);
text = t[param] || t.text || t.value || t.name || t;
py = BI.makeFirstPY(text);
text = BI.toUpperCase(text);
py = BI.toUpperCase(py);
var pidx;
if (text.indexOf(keyword) > -1) {
if (text === keyword) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
} else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) {
if (text === keyword || keyword.length === text.length) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
}
},
});
});
return {
matched: matched,
finded: finded
}
},
});
/**
* 对DOM操作的通用函数
* @type {{}}
*/
BI.DOM = {};
BI.extend(BI.DOM, {
/**
* 对DOM操作的通用函数
* @type {{}}
* 把dom数组或元素悬挂起来,使其不对html产生影响
* @param dom
*/
BI.DOM = {};
BI.extend(BI.DOM, {
/**
* 把dom数组或元素悬挂起来,使其不对html产生影响
* @param dom
*/
hang: function (doms) {
if (BI.isEmpty(doms)) {
return;
}
var frag = document.createDocumentFragment();
BI.each(doms, function (i, dom) {
dom instanceof BI.Widget && (dom = dom.element);
dom instanceof $ && dom[0] && frag.appendChild(dom[0]);
});
return frag;
},
hang: function (doms) {
if (BI.isEmpty(doms)) {
return;
}
var frag = document.createDocumentFragment();
BI.each(doms, function (i, dom) {
dom instanceof BI.Widget && (dom = dom.element);
dom instanceof $ && dom[0] && frag.appendChild(dom[0]);
});
return frag;
},
isExist: function (obj) {
return $("body").find(obj.element).length > 0;
},
isExist: function (obj) {
return $("body").find(obj.element).length > 0;
},
//预加载图片
preloadImages: function (srcArray, onload) {
var count = 0, images = [];
//预加载图片
preloadImages: function (srcArray, onload) {
var count = 0, images = [];
function complete() {
count++;
if (count >= srcArray.length) {
onload();
}
function complete() {
count++;
if (count >= srcArray.length) {
onload();
}
}
BI.each(srcArray, function (i, src) {
images[i] = new Image();
images[i].src = src;
images[i].onload = function () {
complete()
};
images[i].onerror = function () {
complete()
};
});
},
BI.each(srcArray, function (i, src) {
images[i] = new Image();
images[i].src = src;
images[i].onload = function () {
complete()
};
images[i].onerror = function () {
complete()
};
});
},
isColor: function (color) {
return this.isRGBColor(color) || this.isHexColor(color);
},
isColor: function (color) {
return this.isRGBColor(color) || this.isHexColor(color);
},
isRGBColor: function (color) {
if (!color) {
return false;
}
return color.substr(0, 3) === "rgb";
},
isRGBColor: function (color) {
if (!color) {
return false;
}
return color.substr(0, 3) === "rgb";
},
isHexColor: function (color) {
if (!color) {
return false;
}
return color[0] === "#" && color.length === 7;
},
isHexColor: function (color) {
if (!color) {
return false;
}
return color[0] === "#" && color.length === 7;
},
isDarkColor: function (hex) {
if (!hex) {
return false;
}
var rgb = this.rgb2json(this.hex2rgb(hex));
var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114);
if (grayLevel < 140) {
return true;
}
isDarkColor: function (hex) {
if (!hex) {
return false;
},
}
var rgb = this.rgb2json(this.hex2rgb(hex));
var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114);
if (grayLevel < 140) {
return true;
}
return false;
},
//获取对比颜色
getContrastColor: function (color) {
if (!color) {
return "";
}
if (this.isDarkColor(color)) {
return "#ffffff";
}
return "#1a1a1a";
},
//获取对比颜色
getContrastColor: function (color) {
if (!color) {
return "";
}
if (this.isDarkColor(color)) {
return "#ffffff";
}
return "#1a1a1a";
},
rgb2hex: function (rgbColour) {
if (!rgbColour || rgbColour.substr(0, 3) != "rgb") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
var red = BI.parseInt(rgbValues[0]);
var green = BI.parseInt(rgbValues[1]);
var blue = BI.parseInt(rgbValues[2]);
rgb2hex: function (rgbColour) {
if (!rgbColour || rgbColour.substr(0, 3) != "rgb") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
var red = BI.parseInt(rgbValues[0]);
var green = BI.parseInt(rgbValues[1]);
var blue = BI.parseInt(rgbValues[2]);
var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue);
var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue);
return hexColour;
},
return hexColour;
},
rgb2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2])
};
},
rgb2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2])
};
},
rgba2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]),
a: BI.parseFloat(rgbValues[3])
};
},
rgba2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]),
a: BI.parseFloat(rgbValues[3])
};
},
json2rgb: function (rgb) {
if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) {
return "";
}
return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
},
json2rgb: function (rgb) {
if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) {
return "";
}
return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
},
json2rgba: function (rgba) {
if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) {
return "";
}
return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")";
},
json2rgba: function (rgba) {
if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) {
return "";
}
return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")";
},
int2hex: function (strNum) {
var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
int2hex: function (strNum) {
var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15];
},
return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15];
},
hex2rgb: function (color) {
if (!color) {
return "";
}
var tempValue = "rgb(", colorArray;
hex2rgb: function (color) {
if (!color) {
return "";
}
var tempValue = "rgb(", colorArray;
if (color.length === 7) {
colorArray = [BI.parseInt('0x' + color.substring(1, 3)),
BI.parseInt('0x' + color.substring(3, 5)),
BI.parseInt('0x' + color.substring(5, 7))];
}
else if (color.length === 4) {
colorArray = [BI.parseInt('0x' + color.substring(1, 2)),
BI.parseInt('0x' + color.substring(2, 3)),
BI.parseInt('0x' + color.substring(3, 4))];
}
tempValue += colorArray[0] + ",";
tempValue += colorArray[1] + ",";
tempValue += colorArray[2] + ")";
if (color.length === 7) {
colorArray = [BI.parseInt('0x' + color.substring(1, 3)),
BI.parseInt('0x' + color.substring(3, 5)),
BI.parseInt('0x' + color.substring(5, 7))];
}
else if (color.length === 4) {
colorArray = [BI.parseInt('0x' + color.substring(1, 2)),
BI.parseInt('0x' + color.substring(2, 3)),
BI.parseInt('0x' + color.substring(3, 4))];
}
tempValue += colorArray[0] + ",";
tempValue += colorArray[1] + ",";
tempValue += colorArray[2] + ")";
return tempValue;
},
return tempValue;
},
rgba2rgb: function (rgbColour, BGcolor) {
if (BI.isNull(BGcolor)) {
BGcolor = 1;
}
if (rgbColour.substr(0, 4) != "rgba") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
if (rgbValues.length < 4) {
return "";
}
var R = BI.parseFloat(rgbValues[0]);
var G = BI.parseFloat(rgbValues[1]);
var B = BI.parseFloat(rgbValues[2]);
var A = BI.parseFloat(rgbValues[3]);
rgba2rgb: function (rgbColour, BGcolor) {
if (BI.isNull(BGcolor)) {
BGcolor = 1;
}
if (rgbColour.substr(0, 4) != "rgba") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
if (rgbValues.length < 4) {
return "";
}
var R = BI.parseFloat(rgbValues[0]);
var G = BI.parseFloat(rgbValues[1]);
var B = BI.parseFloat(rgbValues[2]);
var A = BI.parseFloat(rgbValues[3]);
return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")";
},
return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")";
},
getTextSizeWidth: function (text, fontSize) {
var span = $("<span></span>").addClass("text-width-span").appendTo($("body"));
getTextSizeWidth: function (text, fontSize) {
var span = $("<span></span>").addClass("text-width-span").appendTo($("body"));
if (fontSize == null) {
fontSize = 12;
}
fontSize = fontSize + "px";
if (fontSize == null) {
fontSize = 12;
}
fontSize = fontSize + "px";
span.css("font-size", fontSize).text(text);
span.css("font-size", fontSize).text(text);
var width = span.width();
span.remove();
var width = span.width();
span.remove();
return width;
},
return width;
},
//获取滚动条的宽度
getScrollWidth: function () {
if (this._scrollWidth == null) {
var ul = $("<div>").width(50).height(50).css({
position: "absolute",
top: "-9999px",
overflow: "scroll"
}).appendTo($("body"));
this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth;
ul.destroy();
}
return this._scrollWidth;
//获取滚动条的宽度
getScrollWidth: function () {
if (this._scrollWidth == null) {
var ul = $("<div>").width(50).height(50).css({
position: "absolute",
top: "-9999px",
overflow: "scroll"
}).appendTo($("body"));
this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth;
ul.destroy();
}
});
return this._scrollWidth;
}
});/**
* guy
* 检测某个Widget的EventChange事件然后去show某个card
@ -23528,7 +23531,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"),
BI.i18nText("BI-Quarter_3"),
BI.i18nText("BI-Quarter_4")];
/** Adds the number of days array to the Date object. */
Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
@ -24002,7 +24004,8 @@ Date.parseDateTime = function (str, fmt) {
return new Date(y, m, d, hr, min, sec);
}
return today;
};/*
};
/*
* 给jQuery.Event对象添加的工具方法
*/
$.extend($.Event.prototype, {

462
docs/widget.js

@ -10955,7 +10955,7 @@ BI.MultiSelectCheckSelectedSwitcher = BI.inherit(BI.Widget, {
BI.MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE = "MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE";
BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW";
BI.shortcut('bi.multi_select_check_selected_switcher', BI.MultiSelectCheckSelectedSwitcher);/**
* Created by zcf on 2016/12/14.
* Created by zcf_1 on 2017/5/2.
*/
BI.MultiStringList = BI.inherit(BI.Widget, {
_defaultConfig: function () {
@ -10963,33 +10963,30 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
baseCls: 'bi-multi-string-list',
itemsCreator: BI.emptyFn,
valueFormatter: BI.emptyFn,
height: 25
el: {}
})
},
_init: function () {
BI.MultiStringList.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.storeValue = {};
var assertShowValue = function () {
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue);
self.trigger.getSearcher().setState(self.storeValue);
self.trigger.getCounter().setButtonChecked(self.storeValue);
};
this.storeValue = {};
this.popup = BI.createWidget({
this.adapter = BI.createWidget({
type: "bi.multi_select_loader",
cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter,
onLoaded: o.onLoaded,
// onLoaded: o.onLoaded,
el: {
height: ""
}
});
this.popup.on(BI.MultiSelectLoader.EVENT_CHANGE, function () {
this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue();
self._adjust(function () {
assertShowValue();
@ -10997,90 +10994,105 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
});
});
this.trigger = BI.createWidget({
type: "bi.multi_select_trigger",
height: o.height,
adapter: this.popup,
masker: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
this.searcherPane = BI.createWidget({
type: "bi.multi_select_search_pane",
cls: "bi-border-left bi-border-right bi-border-bottom",
valueFormatter: o.valueFormatter,
keywordGetter: function () {
return self.trigger.getKeyword();
},
itemsCreator: function (op, callback) {
o.itemsCreator(op, function (res) {
if (op.times === 1 && BI.isNotNull(op.keyword)) {
self.trigger.setValue(self.getValue());
}
callback.apply(self, arguments);
});
op.keyword = self.trigger.getKeyword();
this.setKeyword(op.keyword);
o.itemsCreator(op, callback);
}
});
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () {
self._setStartValue("");
this.getSearcher().setValue(self.storeValue);
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () {
self._setStartValue("");
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () {
if (this.getSearcher().hasMatched()) {
var keyword = this.getSearcher().getKeyword();
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.populate();
this.trigger = BI.createWidget({
type: "bi.searcher",
isAutoSearch: false,
isAutoSync: false,
onSearch: function (op, callback) {
callback();
},
adapter: this.adapter,
popup: this.searcherPane,
height: 200,
masker: false,
listeners: [{
eventName: BI.Searcher.EVENT_START,
action: function () {
self._showSearcherPane();
self._setStartValue("");
self.fireEvent(BI.MultiStringList.EVENT_CHANGE);
})
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords);
keywords = BI.initial(keywords || []);
if (keywords.length > 0) {
self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) {
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
assertShowValue();
self.popup.populate();
self._setStartValue("");
this.setValue(self.storeValue);
}
}, {
eventName: BI.Searcher.EVENT_STOP,
action: function () {
self._showAdapter();
self._setStartValue("");
self.adapter.setValue(self.storeValue);
}
}, {
eventName: BI.Searcher.EVENT_PAUSE,
action: function () {
if (this.hasMatched()) {
var keyword = this.getKeyword();
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
self._showAdapter();
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self._setStartValue("");
self.fireEvent(BI.MultiStringList.EVENT_CHANGE);
})
} else {
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
assertShowValue();
self._showAdapter();
}
});
}
}
}, {
eventName: BI.Searcher.EVENT_SEARCHING,
action: function () {
var keywords = this.getKeyword();
var last = BI.last(keywords);
keywords = BI.initial(keywords || []);
if (keywords.length > 0) {
self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue);
assertShowValue();
self.adapter.populate();
self._setStartValue("");
} else {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue);
assertShowValue();
}
});
}
}
}, {
eventName: BI.Searcher.EVENT_CHANGE,
action: function (value, obj) {
if (obj instanceof BI.MultiSelectBar) {
self._joinAll(this.getValue(), function () {
assertShowValue();
});
} else {
self._join(this.getValue(), function () {//安徽省 北京
assertShowValue();
});
}
}
}]
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) {
if (obj instanceof BI.MultiSelectBar) {
self._joinAll(this.getValue(), function () {
assertShowValue();
});
} else {
self._join(this.getValue(), function () {//安徽省 北京
assertShowValue();
});
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () {
this.getCounter().setValue(self.storeValue);
});
var div = BI.createWidget({
type: "bi.layout"
});
BI.createWidget({
type: "bi.vtape",
element: this,
@ -11088,16 +11100,37 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
width: "100%",
items: [{
el: this.trigger,
height: 25
}, {
el: div,
height: 2
height: 30
}, {
el: this.popup,
el: this.adapter,
height: "fill"
}]
});
BI.createWidget({
type: "bi.absolute",
element: this,
height: "100%",
width: "100%",
items: [{
el: this.searcherPane,
top: 30,
bottom: 0,
left: 0,
right: 0
}]
})
},
_showAdapter: function () {
this.adapter.setVisible(true);
this.searcherPane.setVisible(false);
},
_showSearcherPane: function () {
this.searcherPane.setVisible(true);
this.adapter.setVisible(false);
},
_defaultState: function () {
this.trigger.stopEditing();
},
@ -11142,7 +11175,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
this._assertValue(res);
o.itemsCreator({
type: BI.MultiStringList.REQ_GET_ALL_DATA,
keyword: this.trigger.getKey()
keyword: self.trigger.getKeyword()
}, function (ob) {
var items = BI.pluck(ob.items, "value");
if (self.storeValue.type === res.type) {
@ -11231,22 +11264,21 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
_setStartValue: function (value) {
this._startValue = value;
this.popup.setStartValue(value);
this.adapter.setStartValue(value);
},
// isAllSelected: function () {
// return this.popup.isAllSelected();
// },
isAllSelected: function () {
return this.adapter.isAllSelected();
},
resize: function () {
this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView();
// this.trigger.getCounter().adjustView();
// this.trigger.adjustView();
},
setValue: function (v) {
this.storeValue = v || {};
this._assertValue(this.storeValue);
this.popup.setValue(this.storeValue);
this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue);
},
@ -11257,7 +11289,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
populate: function () {
this._count = null;
this._allData = null;
this.popup.populate.apply(this.popup, arguments);
this.adapter.populate.apply(this.adapter, arguments);
this.trigger.populate.apply(this.trigger, arguments);
}
});
@ -12008,130 +12040,96 @@ BI.MultiTreeSearcher.EVENT_START = "EVENT_START";
BI.MultiTreeSearcher.EVENT_STOP = "EVENT_STOP";
BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE";
BI.shortcut('bi.multi_tree_searcher', BI.MultiTreeSearcher);/**
* Created by zcf on 2016/12/20.
* Created by zcf_1 on 2017/5/11.
*/
BI.MultiTreeList = BI.inherit(BI.Widget, {
constants: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
BI.MultiSelectTree = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.MultiTreeList.superclass._defaultConfig.apply(this, arguments), {
return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), {
baseCls: 'bi-multi-tree-combo',
itemsCreator: BI.emptyFn,
height: 25
});
})
},
_init: function () {
BI.MultiTreeList.superclass._init.apply(this, arguments);
BI.MultiSelectTree.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.storeValue = {value: {}};
var isInit = false;
var want2showCounter = false;
this.popup = BI.createWidget({
type: "bi.multi_tree_list_popup",
this.adapter = BI.createWidget({
type: "bi.multi_select_tree_popup",
itemsCreator: o.itemsCreator
});
this.popup.on(BI.MultiStringListPopup.EVENT_AFTER_INIT, function () {
self.trigger.getCounter().adjustView();
isInit = true;
if (want2showCounter === true) {
showCounter();
this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () {
if (self.trigger.isSearching()) {
self.storeValue = {value: self.searcherPane.getValue()};
} else {
self.storeValue = {value: self.adapter.getValue()};
}
self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
});
this.trigger = BI.createWidget({
type: "bi.multi_select_trigger",
height: o.height,
adapter: this.popup,
masker: {
offset: this.constants.offset
this.searcherPane = BI.createWidget({//搜索中的时候用的是parttree,同adapter中的synctree不一样
type: "bi.multi_tree_search_pane",
cls: "bi-border-left bi-border-right bi-border-bottom",
keywordGetter: function () {
return self.trigger.getKeyword();
},
searcher: {
type: "bi.multi_tree_searcher",
itemsCreator: o.itemsCreator
},
switcher: {
el: {
type: "bi.multi_tree_check_selected_button"
},
popup: {
type: "bi.multi_tree_check_pane",
itemsCreator: o.itemsCreator
}
}
});
this.storeValue = {value: {}};
var isSearching = function () {
return self.trigger.getSearcher().isSearching();
};
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () {
self.storeValue = {value: self.popup.getValue()};
this.setValue(self.storeValue);
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () {
self.storeValue = {value: this.getValue()};
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
BI.nextTick(function () {
self.trigger.populate();
self.popup.populate();
});
});
function showCounter() {
if (isSearching()) {
self.storeValue = {value: self.trigger.getValue()};
} else {
self.storeValue = {value: self.popup.getValue()};
}
self.trigger.setValue(self.storeValue);
}
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () {
if (want2showCounter === false) {
want2showCounter = true;
}
if (isInit === true) {
want2showCounter = null;
showCounter();
itemsCreator: function (op, callback) {
op.keyword = self.trigger.getKeyword();
o.itemsCreator(op, callback);
}
});
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () {
var val = {
type: BI.Selection.Multi,
value: this.getSearcher().hasChecked() ? {1: 1} : {}
};
this.getSearcher().setState(val);
this.getCounter().setButtonChecked(val);
});
this.popup.on(BI.MultiStringListPopup.EVENT_CHANGE, function () {
showCounter();
var val = {
type: BI.Selection.Multi,
value: this.hasChecked() ? {1: 1} : {}
};
self.trigger.getSearcher().setState(val);
self.trigger.getCounter().setButtonChecked(val);
self.fireEvent(BI.MultiTreeList.EVENT_CHANGE);
this.trigger = BI.createWidget({
type: "bi.searcher",
isAutoSearch: false,
isAutoSync: false,
onSearch: function (op, callback) {
callback({
keyword: self.trigger.getKeyword()
});
},
adapter: this.adapter,
popup: this.searcherPane,
height: 200,
masker: false,
listeners: [{
eventName: BI.Searcher.EVENT_START,
action: function () {
self._showSearcherPane();
self.storeValue = {value: self.adapter.getValue()};
self.searcherPane.setValue(self.storeValue);
}
}, {
eventName: BI.Searcher.EVENT_STOP,
action: function () {
self._showAdapter();
// self.storeValue = {value: self.searcherPane.getValue()};
self.adapter.setValue(self.storeValue);
BI.nextTick(function () {
self.adapter.populate();
});
}
}, {
eventName: BI.Searcher.EVENT_CHANGE,
action: function () {
if (self.trigger.isSearching()) {
self.storeValue = {value: self.searcherPane.getValue()};
} else {
self.storeValue = {value: self.adapter.getValue()};
}
self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
}
}, {
eventName: BI.Searcher.EVENT_PAUSE,
action: function () {
self._showAdapter();
}
}]
});
var div = BI.createWidget({
type: "bi.layout"
});
BI.createWidget({
type: "bi.vtape",
element: this,
@ -12139,29 +12137,45 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
width: "100%",
items: [{
el: this.trigger,
height: 25
}, {
el: div,
height: 2
height: 30
}, {
el: this.popup,
el: this.adapter,
height: "fill"
}]
});
BI.createWidget({
type: "bi.absolute",
element: this,
height: "100%",
width: "100%",
items: [{
el: this.searcherPane,
top: 30,
bottom: 0,
left: 0,
right: 0
}]
})
},
_defaultState: function () {
this.trigger.stopEditing();
_showAdapter: function () {
this.adapter.setVisible(true);
this.searcherPane.setVisible(false);
},
_showSearcherPane: function () {
this.searcherPane.setVisible(true);
this.adapter.setVisible(false);
},
resize: function () {
this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView();
},
setValue: function (v) {
this.storeValue.value = v || {};
this.popup.setValue({
this.adapter.setValue({
value: v || {}
});
this.trigger.setValue({
@ -12175,22 +12189,22 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
populate: function () {
this.trigger.populate.apply(this.trigger, arguments);
this.popup.populate.apply(this.popup, arguments);
this.adapter.populate.apply(this.adapter, arguments);
}
});
BI.MultiTreeList.EVENT_CHANGE = "MultiTreeList.EVENT_CHANGE";
BI.shortcut('bi.multi_tree_list', BI.MultiTreeList);/**
BI.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE";
BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree);/**
* Created by zcf on 2016/12/21.
*/
BI.MultiStringListPopup=BI.inherit(BI.Widget,{
_defaultConfig:function () {
return BI.extend(BI.MultiStringListPopup.superclass._defaultConfig.apply(this, arguments), {
BI.MultiSelectTreePopup = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom",
itemsCreator: BI.emptyFn
});
},
_init:function () {
BI.MultiStringListPopup.superclass._init.apply(this, arguments);
_init: function () {
BI.MultiSelectTreePopup.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.popup = BI.createWidget({
type: "bi.sync_tree",
@ -12199,10 +12213,10 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{
itemsCreator: o.itemsCreator
});
this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () {
self.fireEvent(BI.MultiStringListPopup.EVENT_AFTER_INIT)
self.fireEvent(BI.MultiSelectTreePopup.EVENT_AFTER_INIT)
});
this.popup.on(BI.TreeView.EVENT_CHANGE, function () {
self.fireEvent(BI.MultiStringListPopup.EVENT_CHANGE)
self.fireEvent(BI.MultiSelectTreePopup.EVENT_CHANGE)
});
},
@ -12224,9 +12238,9 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{
}
});
BI.MultiStringListPopup.EVENT_AFTER_INIT="BI.MultiStringListPopup.EVENT_AFTER_INIT";
BI.MultiStringListPopup.EVENT_CHANGE="BI.MultiStringListPopup.EVENT_CHANGE";
BI.shortcut("bi.multi_tree_list_popup",BI.MultiStringListPopup);//小于号的值为:0,小于等于号的值为:1
BI.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT";
BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE";
BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);//小于号的值为:0,小于等于号的值为:1
//closeMIn:最小值的符号,closeMax:最大值的符号
/**
* Created by roy on 15/9/17.

29
src/base/collection/collection.js

@ -156,6 +156,7 @@ BI.CollectionView = BI.inherit(BI.Widget, {
for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index);
var child;
if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width;
@ -171,9 +172,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px");
}
renderedCells.push(this.renderedCells[index]);
renderedCells.push(child = this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
child = BI.createWidget(BI.extend({
type: "bi.label",
width: datum.width,
height: datum.height
@ -264,8 +265,12 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return Math.max(0, this._height - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0));
},
_populate: function () {
_populate: function (items) {
var o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
this._calculateSizeAndPositionData();
}
if (o.items.length > 0) {
this.container.setWidth(this._width);
this.container.setHeight(this._height);
@ -334,10 +339,21 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return this._getMaxScrollTop();
},
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () {
BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy();
cell.el._destroy();
});
this._clearChildren();
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
@ -346,10 +362,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
populate: function (items) {
if (items && items !== this.options.items) {
this.options.items = items;
this._calculateSizeAndPositionData();
this.restore();
}
this._populate();
this._populate(items);
}
});
BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL";

29
src/base/grid/grid.js

@ -123,6 +123,7 @@ BI.GridView = BI.inherit(BI.Widget, {
var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
@ -131,6 +132,7 @@ BI.GridView = BI.inherit(BI.Widget, {
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key);
var child;
if (index > -1) {
if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size;
@ -146,9 +148,9 @@ BI.GridView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) {
this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px");
}
renderedCells.push(this.renderedCells[index]);
renderedCells.push(child = this.renderedCells[index]);
} else {
var child = BI.createWidget(BI.extend({
child = BI.createWidget(BI.extend({
type: "bi.label",
width: columnDatum.size,
height: rowDatum.size
@ -172,7 +174,7 @@ BI.GridView = BI.inherit(BI.Widget, {
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key);
renderedWidgets[i] = child;
renderedWidgets[count++] = child;
}
}
//已存在的, 需要添加的和需要删除的
@ -219,8 +221,11 @@ BI.GridView = BI.inherit(BI.Widget, {
return Math.max(0, this._rowSizeAndPositionManager.getTotalSize() - this.options.height + (this.options.overflowY ? BI.DOM.getScrollWidth() : 0));
},
_populate: function () {
_populate: function (items) {
var self = this, o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
}
if (o.items.length > 0) {
this.columnCount = o.items[0].length;
this.rowCount = o.items.length;
@ -305,10 +310,21 @@ BI.GridView = BI.inherit(BI.Widget, {
this.options.estimatedRowSize = height;
},
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () {
BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy();
cell.el._destroy();
});
this._clearChildren();
this.renderedCells = [];
this.renderedKeys = [];
this.renderRange = {};
@ -317,10 +333,9 @@ BI.GridView = BI.inherit(BI.Widget, {
populate: function (items) {
if (items && items !== this.options.items) {
this.options.items = items;
this.restore();
}
this._populate();
this._populate(items);
}
});
BI.GridView.EVENT_SCROLL = "EVENT_SCROLL";

9
src/base/single/button/button.basic.js

@ -298,9 +298,14 @@ BI.BasicButton = BI.inherit(BI.Single, {
return this.options.text;
},
_setEnable: function (b) {
_setEnable: function (enable) {
BI.BasicButton.superclass._setEnable.apply(this, arguments);
if (!b) {
if (enable === true) {
this.element.removeClass("base-disabled disabled");
} else if (enable === false) {
this.element.addClass("base-disabled disabled");
}
if (!enable) {
if (this.options.shadow) {
this.$mask && this.$mask.setVisible(false);
}

25
src/base/table/table.collection.js

@ -175,7 +175,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
_populateScrollbar: function () {
var o = this.options;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0,
summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -216,7 +217,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
_populateTable: function () {
var self = this, o = this.options;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0, summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var regionSize = this.getRegionSize(), totalLeftColumnSize = 0, totalRightColumnSize = 0, totalColumnSize = 0,
summaryColumnSizeArray = [], totalRowSize = o.items.length * o.rowSize;
var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -247,7 +249,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
var trh = otrh + this._scrollBarSize;
var blw = oblw + this._scrollBarSize;
var blh = oblh + this._scrollBarSize;
var brw = obrw+ this._scrollBarSize;
var brw = obrw + this._scrollBarSize;
var brh = obrh + this._scrollBarSize;
var digest = function (el) {
@ -304,10 +306,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
run(this.bottomLeftItems, o.items, leftItems);
run(this.bottomRightItems, o.items, rightItems);
this.topLeftCollection.populate(leftHeader);
this.topRightCollection.populate(rightHeader);
this.bottomLeftCollection.populate(leftItems);
this.bottomRightCollection.populate(rightItems);
this.topLeftCollection._populate(leftHeader);
this.topRightCollection._populate(rightHeader);
this.bottomLeftCollection._populate(leftItems);
this.bottomRightCollection._populate(rightItems);
},
_digest: function () {
@ -427,8 +429,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
return;
}
if (this._isNeedDigest === true) {
this._reRange();
this._digest();
}
this._isNeedDigest = false;
this._populateTable();
this._populateScrollbar();
},
@ -523,6 +527,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
this.bottomRightCollection.restore();
},
_reRange: function () {
this.topLeftCollection.reRange();
this.topRightCollection.reRange();
this.bottomLeftCollection.reRange();
this.bottomRightCollection.reRange();
},
restore: function () {
this._restore();
}

23
src/base/table/table.grid.js

@ -347,16 +347,20 @@ BI.GridTable = BI.inherit(BI.Widget, {
this.contextLayout.attr("items", items);
this.contextLayout.resize();
this.topLeftGrid.populate(this.header[0]);
this.topRightGrid.populate(this.header[1]);
this.bottomLeftGrid.populate(this.items[0]);
this.bottomRightGrid.populate(this.items[1]);
this.topLeftGrid._populate(this.header[0]);
this.topRightGrid._populate(this.header[1]);
this.bottomLeftGrid._populate(this.items[0]);
this.bottomRightGrid._populate(this.items[1]);
},
_populate: function () {
if (this._width <= 0 || this._height <= 0) {
return;
}
if (this._isNeedDigest === true) {
this._reRange();
this._isNeedDigest = false;
}
this._populateTable();
this._populateScrollbar();
},
@ -414,10 +418,12 @@ BI.GridTable = BI.inherit(BI.Widget, {
setColumnSize: function (columnSize) {
this.options.columnSize = columnSize;
this._isNeedDigest = true;
},
setRegionColumnSize: function (regionColumnSize) {
this.options.regionColumnSize = regionColumnSize;
this._isNeedDigest = true;
},
getColumnSize: function () {
@ -430,11 +436,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
populate: function (items, header) {
if (items && this.options.items !== items) {
this._isNeedDigest = true;
this.options.items = items;
this.items = this._getItems();
this._restore();
}
if (header && this.options.header !== header) {
this._isNeedDigest = true;
this.options.header = header;
this.header = this._getHeader();
this._restore();
@ -449,6 +457,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
this.bottomRightGrid.restore();
},
_reRange: function () {
this.topLeftGrid.reRange();
this.topRightGrid.reRange();
this.bottomLeftGrid.reRange();
this.bottomRightGrid.reRange();
},
restore: function () {
this._restore();
}

6
src/base/table/table.resizable.js

@ -219,8 +219,10 @@ BI.ResizableTable = BI.inherit(BI.Widget, {
};
var stop = function (j, size) {
self.resizer.setVisible(false);
o.columnSize[j] = size;
self.table.setColumnSize(o.columnSize);
var columnSize = o.columnSize.slice();
columnSize[j] = size;
o.columnSize = columnSize;
self.table.setColumnSize(columnSize);
self.table.populate();
self._populate();
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE);

2
src/case/table/table.adaptive.js

@ -115,7 +115,7 @@ BI.AdaptiveTable = BI.inherit(BI.Widget, {
freezeCols = [];
}
if (!BI.isNumber(columnSize[0])) {
columnSize = o.minColumnSize;
columnSize = o.minColumnSize.slice();
}
var summaryFreezeColumnSize = 0, summaryColumnSize = 0;
BI.each(columnSize, function (i, size) {

249
src/core/alias.js

@ -1,4 +1,7 @@
;(function () {
if (!window.BI) {
window.BI = {};
}
function isEmpty(value) {
// 判断是否为空值
var result = value === "" || value === null || value === undefined;
@ -59,124 +62,6 @@
return text;
}
/**
* 把日期对象按照指定格式转化成字符串
*
* @example
* var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800');
* var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12
*
* @class BI.date2Str
* @param date 日期
* @param format 日期格式
* @returns {String}
*/
function date2Str(date, format) {
if (!date) {
return '';
}
// O(len(format))
var len = format.length, result = '';
if (len > 0) {
var flagch = format.charAt(0), start = 0, str = flagch;
for (var i = 1; i < len; i++) {
var ch = format.charAt(i);
if (flagch !== ch) {
result += compileJFmt({
'char': flagch,
'str': str,
'len': i - start
}, date);
flagch = ch;
start = i;
str = flagch;
} else {
str += ch;
}
}
result += compileJFmt({
'char': flagch,
'str': str,
'len': len - start
}, date);
}
return result;
function compileJFmt(jfmt, date) {
var str = jfmt.str, len = jfmt.len, ch = jfmt['char'];
switch (ch) {
case 'E': //星期
str = Date._DN[date.getDay()];
break;
case 'y': //年
if (len <= 3) {
str = (date.getFullYear() + '').slice(2, 4);
} else {
str = date.getFullYear();
}
break;
case 'M': //月
if (len > 2) {
str = Date._MN[date.getMonth()];
} else if (len < 2) {
str = date.getMonth() + 1;
} else {
str = String.leftPad(date.getMonth() + 1 + '', 2, '0');
}
break;
case 'd': //日
if (len > 1) {
str = String.leftPad(date.getDate() + '', 2, '0');
} else {
str = date.getDate();
}
break;
case 'h': //时(12)
var hour = date.getHours() % 12;
if (hour === 0) {
hour = 12;
}
if (len > 1) {
str = String.leftPad(hour + '', 2, '0');
} else {
str = hour;
}
break;
case 'H': //时(24)
if (len > 1) {
str = String.leftPad(date.getHours() + '', 2, '0');
} else {
str = date.getHours();
}
break;
case 'm':
if (len > 1) {
str = String.leftPad(date.getMinutes() + '', 2, '0');
} else {
str = date.getMinutes();
}
break;
case 's':
if (len > 1) {
str = String.leftPad(date.getSeconds() + '', 2, '0');
} else {
str = date.getSeconds();
}
break;
case 'a':
str = date.getHours() < 12 ? 'am' : 'pm';
break;
case 'z':
str = date.getTimezone();
break;
default:
str = jfmt.str;
break;
}
return str;
}
};
/**
* 数字格式
*/
@ -219,7 +104,8 @@
} else {
return left + '.' + right;
}
};
}
/**
* 处理小数点右边小数部分
* @param tright 右边内容
@ -263,7 +149,7 @@
if (newnum.length > orilen) {
newnum = newnum.substr(1);
} else {
newnum = BI.leftPad(newnum, orilen, '0');
newnum = String.leftPad(newnum, orilen, '0');
result.leftPlus = false;
}
right = right.replace(/^[0-9]+/, newnum);
@ -524,7 +410,7 @@
return o;
})(jo);
}
};
BI.contentFormat = function (cv, fmt) {
if (isEmpty(cv)) {
@ -566,15 +452,122 @@
return text;
};
BI.leftPad = function (val, size, ch) {
var result = String(val);
if (!ch) {
ch = " ";
/**
* 把日期对象按照指定格式转化成字符串
*
* @example
* var date = new Date('Thu Dec 12 2013 00:00:00 GMT+0800');
* var result = BI.date2Str(date, 'yyyy-MM-dd');//2013-12-12
*
* @class BI.date2Str
* @param date 日期
* @param format 日期格式
* @returns {String}
*/
BI.date2Str = function (date, format) {
if (!date) {
return '';
}
while (result.length < size) {
result = ch + result;
// O(len(format))
var len = format.length, result = '';
if (len > 0) {
var flagch = format.charAt(0), start = 0, str = flagch;
for (var i = 1; i < len; i++) {
var ch = format.charAt(i);
if (flagch !== ch) {
result += compileJFmt({
'char': flagch,
'str': str,
'len': i - start
}, date);
flagch = ch;
start = i;
str = flagch;
} else {
str += ch;
}
}
result += compileJFmt({
'char': flagch,
'str': str,
'len': len - start
}, date);
}
return result;
function compileJFmt(jfmt, date) {
var str = jfmt.str, len = jfmt.len, ch = jfmt['char'];
switch (ch) {
case 'E': //星期
str = Date._DN[date.getDay()];
break;
case 'y': //年
if (len <= 3) {
str = (date.getFullYear() + '').slice(2, 4);
} else {
str = date.getFullYear();
}
break;
case 'M': //月
if (len > 2) {
str = Date._MN[date.getMonth()];
} else if (len < 2) {
str = date.getMonth() + 1;
} else {
str = String.leftPad(date.getMonth() + 1 + '', 2, '0');
}
break;
case 'd': //日
if (len > 1) {
str = String.leftPad(date.getDate() + '', 2, '0');
} else {
str = date.getDate();
}
break;
case 'h': //时(12)
var hour = date.getHours() % 12;
if (hour === 0) {
hour = 12;
}
if (len > 1) {
str = String.leftPad(hour + '', 2, '0');
} else {
str = hour;
}
break;
case 'H': //时(24)
if (len > 1) {
str = String.leftPad(date.getHours() + '', 2, '0');
} else {
str = date.getHours();
}
break;
case 'm':
if (len > 1) {
str = String.leftPad(date.getMinutes() + '', 2, '0');
} else {
str = date.getMinutes();
}
break;
case 's':
if (len > 1) {
str = String.leftPad(date.getSeconds() + '', 2, '0');
} else {
str = date.getSeconds();
}
break;
case 'a':
str = date.getHours() < 12 ? 'am' : 'pm';
break;
case 'z':
str = date.getTimezone();
break;
default:
str = jfmt.str;
break;
}
return str;
}
return result.toString();
};
BI.object2Number = function (value) {

496
src/core/func/function.js

@ -2,282 +2,278 @@
* 基本的函数
* Created by GUY on 2015/6/24.
*/
$(function () {
BI.Func = {};
var formulas = {};
BI.extend(BI.Func, {
/**
* 获取搜索结果
* @param items
* @param keyword
* @param param 搜索哪个属性
*/
getSearchResult: function (items, keyword, param) {
var isArray = BI.isArray(items);
items = isArray ? BI.flatten(items) : items;
param || (param = "text");
if (!BI.isKey(keyword)) {
return {
finded: BI.deepClone(items),
matched: isArray ? [] : {}
};
}
var t, text, py;
keyword = keyword + "";
keyword = BI.toUpperCase(keyword);
var matched = isArray ? [] : {}, finded = isArray ? [] : {};
BI.each(items, function (i, item) {
item = BI.deepClone(item);
t = BI.stripEL(item);
text = t[param] || t.text || t.value || t.name || t;
py = BI.makeFirstPY(text);
text = BI.toUpperCase(text);
py = BI.toUpperCase(py);
var pidx;
if (text.indexOf(keyword) > -1) {
if (text === keyword) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
} else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) {
if (text === keyword || keyword.length === text.length) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
}
});
return {
matched: matched,
finded: finded
}
},
});
BI.Func = {};
BI.extend(BI.Func, {
/**
* 对DOM操作的通用函数
* @type {{}}
* 获取搜索结果
* @param items
* @param keyword
* @param param 搜索哪个属性
*/
BI.DOM = {};
BI.extend(BI.DOM, {
/**
* 把dom数组或元素悬挂起来,使其不对html产生影响
* @param dom
*/
hang: function (doms) {
if (BI.isEmpty(doms)) {
return;
}
var frag = document.createDocumentFragment();
BI.each(doms, function (i, dom) {
dom instanceof BI.Widget && (dom = dom.element);
dom instanceof $ && dom[0] && frag.appendChild(dom[0]);
});
return frag;
},
isExist: function (obj) {
return $("body").find(obj.element).length > 0;
},
//预加载图片
preloadImages: function (srcArray, onload) {
var count = 0, images = [];
function complete() {
count++;
if (count >= srcArray.length) {
onload();
getSearchResult: function (items, keyword, param) {
var isArray = BI.isArray(items);
items = isArray ? BI.flatten(items) : items;
param || (param = "text");
if (!BI.isKey(keyword)) {
return {
finded: BI.deepClone(items),
matched: isArray ? [] : {}
};
}
var t, text, py;
keyword = BI.toUpperCase(keyword);
var matched = isArray ? [] : {}, finded = isArray ? [] : {};
BI.each(items, function (i, item) {
item = BI.deepClone(item);
t = BI.stripEL(item);
text = t[param] || t.text || t.value || t.name || t;
py = BI.makeFirstPY(text);
text = BI.toUpperCase(text);
py = BI.toUpperCase(py);
var pidx;
if (text.indexOf(keyword) > -1) {
if (text === keyword) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
} else if (pidx = py.indexOf(keyword), (pidx > -1 && Math.floor(pidx / text.length) === Math.floor((pidx + keyword.length - 1) / text.length))) {
if (text === keyword || keyword.length === text.length) {
isArray ? matched.push(item) : (matched[i] = item);
} else {
isArray ? finded.push(item) : (finded[i] = item);
}
}
});
return {
matched: matched,
finded: finded
}
},
});
BI.each(srcArray, function (i, src) {
images[i] = new Image();
images[i].src = src;
images[i].onload = function () {
complete()
};
images[i].onerror = function () {
complete()
};
});
},
isColor: function (color) {
return this.isRGBColor(color) || this.isHexColor(color);
},
isRGBColor: function (color) {
if (!color) {
return false;
}
return color.substr(0, 3) === "rgb";
},
/**
* 对DOM操作的通用函数
* @type {{}}
*/
BI.DOM = {};
BI.extend(BI.DOM, {
isHexColor: function (color) {
if (!color) {
return false;
/**
* 把dom数组或元素悬挂起来,使其不对html产生影响
* @param dom
*/
hang: function (doms) {
if (BI.isEmpty(doms)) {
return;
}
var frag = document.createDocumentFragment();
BI.each(doms, function (i, dom) {
dom instanceof BI.Widget && (dom = dom.element);
dom instanceof $ && dom[0] && frag.appendChild(dom[0]);
});
return frag;
},
isExist: function (obj) {
return $("body").find(obj.element).length > 0;
},
//预加载图片
preloadImages: function (srcArray, onload) {
var count = 0, images = [];
function complete() {
count++;
if (count >= srcArray.length) {
onload();
}
return color[0] === "#" && color.length === 7;
},
}
isDarkColor: function (hex) {
if (!hex) {
return false;
}
var rgb = this.rgb2json(this.hex2rgb(hex));
var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114);
if (grayLevel < 140) {
return true;
}
BI.each(srcArray, function (i, src) {
images[i] = new Image();
images[i].src = src;
images[i].onload = function () {
complete()
};
images[i].onerror = function () {
complete()
};
});
},
isColor: function (color) {
return this.isRGBColor(color) || this.isHexColor(color);
},
isRGBColor: function (color) {
if (!color) {
return false;
},
}
return color.substr(0, 3) === "rgb";
},
//获取对比颜色
getContrastColor: function (color) {
if (!color) {
return "";
}
if (this.isDarkColor(color)) {
return "#ffffff";
}
return "#1a1a1a";
},
isHexColor: function (color) {
if (!color) {
return false;
}
return color[0] === "#" && color.length === 7;
},
rgb2hex: function (rgbColour) {
if (!rgbColour || rgbColour.substr(0, 3) != "rgb") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
var red = BI.parseInt(rgbValues[0]);
var green = BI.parseInt(rgbValues[1]);
var blue = BI.parseInt(rgbValues[2]);
isDarkColor: function (hex) {
if (!hex) {
return false;
}
var rgb = this.rgb2json(this.hex2rgb(hex));
var grayLevel = Math.round(rgb.r * 0.299 + rgb.g * 0.587 + rgb.b * 0.114);
if (grayLevel < 140) {
return true;
}
return false;
},
var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue);
//获取对比颜色
getContrastColor: function (color) {
if (!color) {
return "";
}
if (this.isDarkColor(color)) {
return "#ffffff";
}
return "#1a1a1a";
},
return hexColour;
},
rgb2hex: function (rgbColour) {
if (!rgbColour || rgbColour.substr(0, 3) != "rgb") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
var red = BI.parseInt(rgbValues[0]);
var green = BI.parseInt(rgbValues[1]);
var blue = BI.parseInt(rgbValues[2]);
rgb2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2])
};
},
var hexColour = "#" + this.int2hex(red) + this.int2hex(green) + this.int2hex(blue);
rgba2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]),
a: BI.parseFloat(rgbValues[3])
};
},
return hexColour;
},
json2rgb: function (rgb) {
if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) {
return "";
}
return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
},
rgb2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2])
};
},
rgba2json: function (rgbColour) {
if (!rgbColour) {
return {};
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return {
r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]),
a: BI.parseFloat(rgbValues[3])
};
},
json2rgb: function (rgb) {
if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) {
return "";
}
return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
},
json2rgba: function (rgba) {
if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) {
return "";
}
return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")";
},
json2rgba: function (rgba) {
if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) {
return "";
}
return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")";
},
int2hex: function (strNum) {
var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
int2hex: function (strNum) {
var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'];
return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15];
},
return hexdig[strNum >>> 4] + '' + hexdig[strNum & 15];
},
hex2rgb: function (color) {
if (!color) {
return "";
}
var tempValue = "rgb(", colorArray;
hex2rgb: function (color) {
if (!color) {
return "";
}
var tempValue = "rgb(", colorArray;
if (color.length === 7) {
colorArray = [BI.parseInt('0x' + color.substring(1, 3)),
BI.parseInt('0x' + color.substring(3, 5)),
BI.parseInt('0x' + color.substring(5, 7))];
}
else if (color.length === 4) {
colorArray = [BI.parseInt('0x' + color.substring(1, 2)),
BI.parseInt('0x' + color.substring(2, 3)),
BI.parseInt('0x' + color.substring(3, 4))];
}
tempValue += colorArray[0] + ",";
tempValue += colorArray[1] + ",";
tempValue += colorArray[2] + ")";
if (color.length === 7) {
colorArray = [BI.parseInt('0x' + color.substring(1, 3)),
BI.parseInt('0x' + color.substring(3, 5)),
BI.parseInt('0x' + color.substring(5, 7))];
}
else if (color.length === 4) {
colorArray = [BI.parseInt('0x' + color.substring(1, 2)),
BI.parseInt('0x' + color.substring(2, 3)),
BI.parseInt('0x' + color.substring(3, 4))];
}
tempValue += colorArray[0] + ",";
tempValue += colorArray[1] + ",";
tempValue += colorArray[2] + ")";
return tempValue;
},
return tempValue;
},
rgba2rgb: function (rgbColour, BGcolor) {
if (BI.isNull(BGcolor)) {
BGcolor = 1;
}
if (rgbColour.substr(0, 4) != "rgba") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
if (rgbValues.length < 4) {
return "";
}
var R = BI.parseFloat(rgbValues[0]);
var G = BI.parseFloat(rgbValues[1]);
var B = BI.parseFloat(rgbValues[2]);
var A = BI.parseFloat(rgbValues[3]);
rgba2rgb: function (rgbColour, BGcolor) {
if (BI.isNull(BGcolor)) {
BGcolor = 1;
}
if (rgbColour.substr(0, 4) != "rgba") {
return "";
}
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
if (rgbValues.length < 4) {
return "";
}
var R = BI.parseFloat(rgbValues[0]);
var G = BI.parseFloat(rgbValues[1]);
var B = BI.parseFloat(rgbValues[2]);
var A = BI.parseFloat(rgbValues[3]);
return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")";
},
return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + G * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")";
},
getTextSizeWidth: function (text, fontSize) {
var span = $("<span></span>").addClass("text-width-span").appendTo($("body"));
getTextSizeWidth: function (text, fontSize) {
var span = $("<span></span>").addClass("text-width-span").appendTo($("body"));
if (fontSize == null) {
fontSize = 12;
}
fontSize = fontSize + "px";
span.css("font-size", fontSize).text(text);
var width = span.width();
span.remove();
return width;
},
//获取滚动条的宽度
getScrollWidth: function () {
if (this._scrollWidth == null) {
var ul = $("<div>").width(50).height(50).css({
position: "absolute",
top: "-9999px",
overflow: "scroll"
}).appendTo($("body"));
this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth;
ul.destroy();
}
return this._scrollWidth;
if (fontSize == null) {
fontSize = 12;
}
fontSize = fontSize + "px";
span.css("font-size", fontSize).text(text);
var width = span.width();
span.remove();
return width;
},
//获取滚动条的宽度
getScrollWidth: function () {
if (this._scrollWidth == null) {
var ul = $("<div>").width(50).height(50).css({
position: "absolute",
top: "-9999px",
overflow: "scroll"
}).appendTo($("body"));
this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth;
ul.destroy();
}
});
return this._scrollWidth;
}
});

3
src/core/proto/date.js

@ -55,7 +55,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"),
BI.i18nText("BI-Quarter_3"),
BI.i18nText("BI-Quarter_4")];
/** Adds the number of days array to the Date object. */
Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
@ -529,4 +528,4 @@ Date.parseDateTime = function (str, fmt) {
return new Date(y, m, d, hr, min, sec);
}
return today;
};
};

2
src/core/view.js

@ -168,7 +168,7 @@ BI.View = BI.inherit(BI.V, {
BI.each(cardNames, function (i, name) {
delete self._cards[name];
});
this._cardLayouts[key] && this._cardLayouts[key].destroy();
this._cardLayouts[key] && this._cardLayouts[key]._destroy();
return this;
},

14
src/core/widget.js

@ -165,6 +165,7 @@ BI.Widget = BI.inherit(BI.OB, {
this._mountChildren && this._mountChildren();
BI.each(this._children, function (i, widget) {
!self.isEnabled() && widget._setEnable(false);
!self.isValid() && widget._setValid(false);
widget._mount && widget._mount();
});
this.mounted && this.mounted();
@ -198,6 +199,18 @@ BI.Widget = BI.inherit(BI.OB, {
});
},
_setValid: function (valid) {
if (valid === true) {
this.options.invalid = false;
} else if (valid === false) {
this.options.invalid = true;
}
//递归将所有子组件使有效
BI.each(this._children, function (i, child) {
child._setValid && child._setValid(valid);
});
},
setEnable: function (enable) {
this._setEnable(enable);
if (enable === true) {
@ -222,6 +235,7 @@ BI.Widget = BI.inherit(BI.OB, {
setValid: function (valid) {
this.options.invalid = !valid;
this._setValid(valid);
if (valid === true) {
this.element.removeClass("base-invalid invalid");
} else if (valid === false) {

228
src/widget/multistringlist/multistringlist.js

@ -1,5 +1,5 @@
/**
* Created by zcf on 2016/12/14.
* Created by zcf_1 on 2017/5/2.
*/
BI.MultiStringList = BI.inherit(BI.Widget, {
_defaultConfig: function () {
@ -7,33 +7,30 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
baseCls: 'bi-multi-string-list',
itemsCreator: BI.emptyFn,
valueFormatter: BI.emptyFn,
height: 25
el: {}
})
},
_init: function () {
BI.MultiStringList.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.storeValue = {};
var assertShowValue = function () {
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue);
self.trigger.getSearcher().setState(self.storeValue);
self.trigger.getCounter().setButtonChecked(self.storeValue);
};
this.storeValue = {};
this.popup = BI.createWidget({
this.adapter = BI.createWidget({
type: "bi.multi_select_loader",
cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter,
onLoaded: o.onLoaded,
// onLoaded: o.onLoaded,
el: {
height: ""
}
});
this.popup.on(BI.MultiSelectLoader.EVENT_CHANGE, function () {
this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue();
self._adjust(function () {
assertShowValue();
@ -41,90 +38,105 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
});
});
this.trigger = BI.createWidget({
type: "bi.multi_select_trigger",
height: o.height,
adapter: this.popup,
masker: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
this.searcherPane = BI.createWidget({
type: "bi.multi_select_search_pane",
cls: "bi-border-left bi-border-right bi-border-bottom",
valueFormatter: o.valueFormatter,
keywordGetter: function () {
return self.trigger.getKeyword();
},
itemsCreator: function (op, callback) {
o.itemsCreator(op, function (res) {
if (op.times === 1 && BI.isNotNull(op.keyword)) {
self.trigger.setValue(self.getValue());
}
callback.apply(self, arguments);
});
op.keyword = self.trigger.getKeyword();
this.setKeyword(op.keyword);
o.itemsCreator(op, callback);
}
});
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () {
self._setStartValue("");
this.getSearcher().setValue(self.storeValue);
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () {
self._setStartValue("");
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () {
if (this.getSearcher().hasMatched()) {
var keyword = this.getSearcher().getKeyword();
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.populate();
this.trigger = BI.createWidget({
type: "bi.searcher",
isAutoSearch: false,
isAutoSync: false,
onSearch: function (op, callback) {
callback();
},
adapter: this.adapter,
popup: this.searcherPane,
height: 200,
masker: false,
listeners: [{
eventName: BI.Searcher.EVENT_START,
action: function () {
self._showSearcherPane();
self._setStartValue("");
self.fireEvent(BI.MultiStringList.EVENT_CHANGE);
})
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) {
var last = BI.last(keywords);
keywords = BI.initial(keywords || []);
if (keywords.length > 0) {
self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) {
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
assertShowValue();
self.popup.populate();
self._setStartValue("");
this.setValue(self.storeValue);
}
}, {
eventName: BI.Searcher.EVENT_STOP,
action: function () {
self._showAdapter();
self._setStartValue("");
self.adapter.setValue(self.storeValue);
}
}, {
eventName: BI.Searcher.EVENT_PAUSE,
action: function () {
if (this.hasMatched()) {
var keyword = this.getKeyword();
self._join({
type: BI.Selection.Multi,
value: [keyword]
}, function () {
self._showAdapter();
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self._setStartValue("");
self.fireEvent(BI.MultiStringList.EVENT_CHANGE);
})
} else {
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
assertShowValue();
self._showAdapter();
}
});
}
}
}, {
eventName: BI.Searcher.EVENT_SEARCHING,
action: function () {
var keywords = this.getKeyword();
var last = BI.last(keywords);
keywords = BI.initial(keywords || []);
if (keywords.length > 0) {
self._joinKeywords(keywords, function () {
if (BI.isEndWithBlank(last)) {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue);
assertShowValue();
self.adapter.populate();
self._setStartValue("");
} else {
self.trigger.setValue(self.storeValue);
self.adapter.setValue(self.storeValue);
assertShowValue();
}
});
}
}
}, {
eventName: BI.Searcher.EVENT_CHANGE,
action: function (value, obj) {
if (obj instanceof BI.MultiSelectBar) {
self._joinAll(this.getValue(), function () {
assertShowValue();
});
} else {
self._join(this.getValue(), function () {//安徽省 北京
assertShowValue();
});
}
}
}]
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function (value, obj) {
if (obj instanceof BI.MultiSelectBar) {
self._joinAll(this.getValue(), function () {
assertShowValue();
});
} else {
self._join(this.getValue(), function () {//安徽省 北京
assertShowValue();
});
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () {
this.getCounter().setValue(self.storeValue);
});
var div = BI.createWidget({
type: "bi.layout"
});
BI.createWidget({
type: "bi.vtape",
element: this,
@ -132,16 +144,37 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
width: "100%",
items: [{
el: this.trigger,
height: 25
}, {
el: div,
height: 2
height: 30
}, {
el: this.popup,
el: this.adapter,
height: "fill"
}]
});
BI.createWidget({
type: "bi.absolute",
element: this,
height: "100%",
width: "100%",
items: [{
el: this.searcherPane,
top: 30,
bottom: 0,
left: 0,
right: 0
}]
})
},
_showAdapter: function () {
this.adapter.setVisible(true);
this.searcherPane.setVisible(false);
},
_showSearcherPane: function () {
this.searcherPane.setVisible(true);
this.adapter.setVisible(false);
},
_defaultState: function () {
this.trigger.stopEditing();
},
@ -186,7 +219,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
this._assertValue(res);
o.itemsCreator({
type: BI.MultiStringList.REQ_GET_ALL_DATA,
keyword: this.trigger.getKey()
keyword: self.trigger.getKeyword()
}, function (ob) {
var items = BI.pluck(ob.items, "value");
if (self.storeValue.type === res.type) {
@ -275,22 +308,21 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
_setStartValue: function (value) {
this._startValue = value;
this.popup.setStartValue(value);
this.adapter.setStartValue(value);
},
// isAllSelected: function () {
// return this.popup.isAllSelected();
// },
isAllSelected: function () {
return this.adapter.isAllSelected();
},
resize: function () {
this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView();
// this.trigger.getCounter().adjustView();
// this.trigger.adjustView();
},
setValue: function (v) {
this.storeValue = v || {};
this._assertValue(this.storeValue);
this.popup.setValue(this.storeValue);
this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue);
},
@ -301,7 +333,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
populate: function () {
this._count = null;
this._allData = null;
this.popup.populate.apply(this.popup, arguments);
this.adapter.populate.apply(this.adapter, arguments);
this.trigger.populate.apply(this.trigger, arguments);
}
});

214
src/widget/multitreelist/multitreelist.js

@ -1,128 +1,94 @@
/**
* Created by zcf on 2016/12/20.
* Created by zcf_1 on 2017/5/11.
*/
BI.MultiTreeList = BI.inherit(BI.Widget, {
constants: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
BI.MultiSelectTree = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.MultiTreeList.superclass._defaultConfig.apply(this, arguments), {
return BI.extend(BI.MultiSelectTree.superclass._defaultConfig.apply(this, arguments), {
baseCls: 'bi-multi-tree-combo',
itemsCreator: BI.emptyFn,
height: 25
});
})
},
_init: function () {
BI.MultiTreeList.superclass._init.apply(this, arguments);
BI.MultiSelectTree.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.storeValue = {value: {}};
var isInit = false;
var want2showCounter = false;
this.popup = BI.createWidget({
type: "bi.multi_tree_list_popup",
this.adapter = BI.createWidget({
type: "bi.multi_select_tree_popup",
itemsCreator: o.itemsCreator
});
this.popup.on(BI.MultiStringListPopup.EVENT_AFTER_INIT, function () {
self.trigger.getCounter().adjustView();
isInit = true;
if (want2showCounter === true) {
showCounter();
this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () {
if (self.trigger.isSearching()) {
self.storeValue = {value: self.searcherPane.getValue()};
} else {
self.storeValue = {value: self.adapter.getValue()};
}
self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
});
this.trigger = BI.createWidget({
type: "bi.multi_select_trigger",
height: o.height,
adapter: this.popup,
masker: {
offset: this.constants.offset
this.searcherPane = BI.createWidget({//搜索中的时候用的是parttree,同adapter中的synctree不一样
type: "bi.multi_tree_search_pane",
cls: "bi-border-left bi-border-right bi-border-bottom",
keywordGetter: function () {
return self.trigger.getKeyword();
},
searcher: {
type: "bi.multi_tree_searcher",
itemsCreator: o.itemsCreator
},
switcher: {
el: {
type: "bi.multi_tree_check_selected_button"
},
popup: {
type: "bi.multi_tree_check_pane",
itemsCreator: o.itemsCreator
}
itemsCreator: function (op, callback) {
op.keyword = self.trigger.getKeyword();
o.itemsCreator(op, callback);
}
});
this.searcherPane.setVisible(false);
this.storeValue = {value: {}};
var isSearching = function () {
return self.trigger.getSearcher().isSearching();
};
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () {
self.storeValue = {value: self.popup.getValue()};
this.setValue(self.storeValue);
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () {
self.storeValue = {value: this.getValue()};
self.trigger.setValue(self.storeValue);
self.popup.setValue(self.storeValue);
BI.nextTick(function () {
self.trigger.populate();
self.popup.populate();
});
});
function showCounter() {
if (isSearching()) {
self.storeValue = {value: self.trigger.getValue()};
} else {
self.storeValue = {value: self.popup.getValue()};
}
self.trigger.setValue(self.storeValue);
}
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () {
if (want2showCounter === false) {
want2showCounter = true;
}
if (isInit === true) {
want2showCounter = null;
showCounter();
}
});
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () {
var val = {
type: BI.Selection.Multi,
value: this.getSearcher().hasChecked() ? {1: 1} : {}
};
this.getSearcher().setState(val);
this.getCounter().setButtonChecked(val);
});
this.popup.on(BI.MultiStringListPopup.EVENT_CHANGE, function () {
showCounter();
var val = {
type: BI.Selection.Multi,
value: this.hasChecked() ? {1: 1} : {}
};
self.trigger.getSearcher().setState(val);
self.trigger.getCounter().setButtonChecked(val);
self.fireEvent(BI.MultiTreeList.EVENT_CHANGE);
this.trigger = BI.createWidget({
type: "bi.searcher",
isAutoSearch: false,
isAutoSync: false,
onSearch: function (op, callback) {
callback({
keyword: self.trigger.getKeyword()
});
},
adapter: this.adapter,
popup: this.searcherPane,
height: 200,
masker: false,
listeners: [{
eventName: BI.Searcher.EVENT_START,
action: function () {
self._showSearcherPane();
self.storeValue = {value: self.adapter.getValue()};
self.searcherPane.setValue(self.storeValue);
}
}, {
eventName: BI.Searcher.EVENT_STOP,
action: function () {
self._showAdapter();
// self.storeValue = {value: self.searcherPane.getValue()};
self.adapter.setValue(self.storeValue);
BI.nextTick(function () {
self.adapter.populate();
});
}
}, {
eventName: BI.Searcher.EVENT_CHANGE,
action: function () {
if (self.trigger.isSearching()) {
self.storeValue = {value: self.searcherPane.getValue()};
} else {
self.storeValue = {value: self.adapter.getValue()};
}
self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
}
}, {
eventName: BI.Searcher.EVENT_PAUSE,
action: function () {
self._showAdapter();
}
}]
});
var div = BI.createWidget({
type: "bi.layout"
});
BI.createWidget({
type: "bi.vtape",
element: this,
@ -130,29 +96,45 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
width: "100%",
items: [{
el: this.trigger,
height: 25
height: 30
}, {
el: div,
height: 2
}, {
el: this.popup,
el: this.adapter,
height: "fill"
}]
});
BI.createWidget({
type: "bi.absolute",
element: this,
height: "100%",
width: "100%",
items: [{
el: this.searcherPane,
top: 30,
bottom: 0,
left: 0,
right: 0
}]
})
},
_defaultState: function () {
this.trigger.stopEditing();
_showAdapter: function () {
this.adapter.setVisible(true);
this.searcherPane.setVisible(false);
},
_showSearcherPane: function () {
this.searcherPane.setVisible(true);
this.adapter.setVisible(false);
},
resize: function () {
this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView();
},
setValue: function (v) {
this.storeValue.value = v || {};
this.popup.setValue({
this.adapter.setValue({
value: v || {}
});
this.trigger.setValue({
@ -166,8 +148,8 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
populate: function () {
this.trigger.populate.apply(this.trigger, arguments);
this.popup.populate.apply(this.popup, arguments);
this.adapter.populate.apply(this.adapter, arguments);
}
});
BI.MultiTreeList.EVENT_CHANGE = "MultiTreeList.EVENT_CHANGE";
BI.shortcut('bi.multi_tree_list', BI.MultiTreeList);
BI.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE";
BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree);

20
src/widget/multitreelist/multitreelist.popup.js

@ -1,15 +1,15 @@
/**
* Created by zcf on 2016/12/21.
*/
BI.MultiStringListPopup=BI.inherit(BI.Widget,{
_defaultConfig:function () {
return BI.extend(BI.MultiStringListPopup.superclass._defaultConfig.apply(this, arguments), {
BI.MultiSelectTreePopup = BI.inherit(BI.Widget, {
_defaultConfig: function () {
return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom",
itemsCreator: BI.emptyFn
});
},
_init:function () {
BI.MultiStringListPopup.superclass._init.apply(this, arguments);
_init: function () {
BI.MultiSelectTreePopup.superclass._init.apply(this, arguments);
var self = this, o = this.options;
this.popup = BI.createWidget({
type: "bi.sync_tree",
@ -18,10 +18,10 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{
itemsCreator: o.itemsCreator
});
this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () {
self.fireEvent(BI.MultiStringListPopup.EVENT_AFTER_INIT)
self.fireEvent(BI.MultiSelectTreePopup.EVENT_AFTER_INIT)
});
this.popup.on(BI.TreeView.EVENT_CHANGE, function () {
self.fireEvent(BI.MultiStringListPopup.EVENT_CHANGE)
self.fireEvent(BI.MultiSelectTreePopup.EVENT_CHANGE)
});
},
@ -43,6 +43,6 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{
}
});
BI.MultiStringListPopup.EVENT_AFTER_INIT="BI.MultiStringListPopup.EVENT_AFTER_INIT";
BI.MultiStringListPopup.EVENT_CHANGE="BI.MultiStringListPopup.EVENT_CHANGE";
BI.shortcut("bi.multi_tree_list_popup",BI.MultiStringListPopup);
BI.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT";
BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE";
BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);
Loading…
Cancel
Save