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

2
bi/case.js

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

745
bi/core.js

@ -3042,6 +3042,9 @@ if (!window.BI) {
} }
}); });
})(jQuery);;(function () { })(jQuery);;(function () {
if (!window.BI) {
window.BI = {};
}
function isEmpty(value) { function isEmpty(value) {
// 判断是否为空值 // 判断是否为空值
var result = value === "" || value === null || value === undefined; var result = value === "" || value === null || value === undefined;
@ -3102,124 +3105,6 @@ if (!window.BI) {
return text; 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 { } else {
return left + '.' + right; return left + '.' + right;
} }
}; }
/** /**
* 处理小数点右边小数部分 * 处理小数点右边小数部分
* @param tright 右边内容 * @param tright 右边内容
@ -3306,7 +3192,7 @@ if (!window.BI) {
if (newnum.length > orilen) { if (newnum.length > orilen) {
newnum = newnum.substr(1); newnum = newnum.substr(1);
} else { } else {
newnum = BI.leftPad(newnum, orilen, '0'); newnum = String.leftPad(newnum, orilen, '0');
result.leftPlus = false; result.leftPlus = false;
} }
right = right.replace(/^[0-9]+/, newnum); right = right.replace(/^[0-9]+/, newnum);
@ -3567,7 +3453,7 @@ if (!window.BI) {
return o; return o;
})(jo); })(jo);
} };
BI.contentFormat = function (cv, fmt) { BI.contentFormat = function (cv, fmt) {
if (isEmpty(cv)) { if (isEmpty(cv)) {
@ -3609,15 +3495,122 @@ if (!window.BI) {
return text; 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) { // O(len(format))
result = ch + result; 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) { BI.object2Number = function (value) {
@ -4492,6 +4485,7 @@ BI.Widget = BI.inherit(BI.OB, {
this._mountChildren && this._mountChildren(); this._mountChildren && this._mountChildren();
BI.each(this._children, function (i, widget) { BI.each(this._children, function (i, widget) {
!self.isEnabled() && widget._setEnable(false); !self.isEnabled() && widget._setEnable(false);
!self.isValid() && widget._setValid(false);
widget._mount && widget._mount(); widget._mount && widget._mount();
}); });
this.mounted && this.mounted(); 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) { setEnable: function (enable) {
this._setEnable(enable); this._setEnable(enable);
if (enable === true) { if (enable === true) {
@ -4549,6 +4555,7 @@ BI.Widget = BI.inherit(BI.OB, {
setValid: function (valid) { setValid: function (valid) {
this.options.invalid = !valid; this.options.invalid = !valid;
this._setValid(valid);
if (valid === true) { if (valid === true) {
this.element.removeClass("base-invalid invalid"); this.element.removeClass("base-invalid invalid");
} else if (valid === false) { } else if (valid === false) {
@ -5377,7 +5384,7 @@ BI.View = BI.inherit(BI.V, {
BI.each(cardNames, function (i, name) { BI.each(cardNames, function (i, name) {
delete self._cards[name]; delete self._cards[name];
}); });
this._cardLayouts[key] && this._cardLayouts[key].destroy(); this._cardLayouts[key] && this._cardLayouts[key]._destroy();
return this; return this;
}, },
@ -6026,7 +6033,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"),
BI.i18nText("BI-Quarter_3"), BI.i18nText("BI-Quarter_3"),
BI.i18nText("BI-Quarter_4")]; BI.i18nText("BI-Quarter_4")];
/** Adds the number of days array to the Date object. */ /** Adds the number of days array to the Date object. */
Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 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 new Date(y, m, d, hr, min, sec);
} }
return today; return today;
};/* };
/*
* 给jQuery.Event对象添加的工具方法 * 给jQuery.Event对象添加的工具方法
*/ */
$.extend($.Event.prototype, { $.extend($.Event.prototype, {
@ -16615,284 +16622,280 @@ BI.extend(jQuery, {
* 基本的函数 * 基本的函数
* Created by GUY on 2015/6/24. * Created by GUY on 2015/6/24.
*/ */
$(function () { BI.Func = {};
BI.Func = {}; BI.extend(BI.Func, {
var formulas = {};
BI.extend(BI.Func, {
/** /**
* 获取搜索结果 * 获取搜索结果
* @param items * @param items
* @param keyword * @param keyword
* @param param 搜索哪个属性 * @param param 搜索哪个属性
*/ */
getSearchResult: function (items, keyword, param) { getSearchResult: function (items, keyword, param) {
var isArray = BI.isArray(items); var isArray = BI.isArray(items);
items = isArray ? BI.flatten(items) : items; items = isArray ? BI.flatten(items) : items;
param || (param = "text"); param || (param = "text");
if (!BI.isKey(keyword)) { 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 { return {
matched: matched, finded: BI.deepClone(items),
finded: finded 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操作的通用函数 * 把dom数组或元素悬挂起来,使其不对html产生影响
* @type {{}} * @param dom
*/ */
BI.DOM = {}; hang: function (doms) {
BI.extend(BI.DOM, { if (BI.isEmpty(doms)) {
return;
/** }
* 把dom数组或元素悬挂起来,使其不对html产生影响 var frag = document.createDocumentFragment();
* @param dom BI.each(doms, function (i, dom) {
*/ dom instanceof BI.Widget && (dom = dom.element);
hang: function (doms) { dom instanceof $ && dom[0] && frag.appendChild(dom[0]);
if (BI.isEmpty(doms)) { });
return; return frag;
} },
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) { isExist: function (obj) {
return $("body").find(obj.element).length > 0; return $("body").find(obj.element).length > 0;
}, },
//预加载图片 //预加载图片
preloadImages: function (srcArray, onload) { preloadImages: function (srcArray, onload) {
var count = 0, images = []; var count = 0, images = [];
function complete() { function complete() {
count++; count++;
if (count >= srcArray.length) { if (count >= srcArray.length) {
onload(); onload();
}
} }
}
BI.each(srcArray, function (i, src) { BI.each(srcArray, function (i, src) {
images[i] = new Image(); images[i] = new Image();
images[i].src = src; images[i].src = src;
images[i].onload = function () { images[i].onload = function () {
complete() complete()
}; };
images[i].onerror = function () { images[i].onerror = function () {
complete() complete()
}; };
}); });
}, },
isColor: function (color) { isColor: function (color) {
return this.isRGBColor(color) || this.isHexColor(color); return this.isRGBColor(color) || this.isHexColor(color);
}, },
isRGBColor: function (color) { isRGBColor: function (color) {
if (!color) { if (!color) {
return false; return false;
} }
return color.substr(0, 3) === "rgb"; return color.substr(0, 3) === "rgb";
}, },
isHexColor: function (color) { isHexColor: function (color) {
if (!color) { if (!color) {
return false; return false;
} }
return color[0] === "#" && color.length === 7; return color[0] === "#" && color.length === 7;
}, },
isDarkColor: function (hex) { isDarkColor: function (hex) {
if (!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; 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) { getContrastColor: function (color) {
if (!color) { if (!color) {
return ""; return "";
} }
if (this.isDarkColor(color)) { if (this.isDarkColor(color)) {
return "#ffffff"; return "#ffffff";
} }
return "#1a1a1a"; return "#1a1a1a";
}, },
rgb2hex: function (rgbColour) { rgb2hex: function (rgbColour) {
if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { if (!rgbColour || rgbColour.substr(0, 3) != "rgb") {
return ""; return "";
} }
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
var red = BI.parseInt(rgbValues[0]); var red = BI.parseInt(rgbValues[0]);
var green = BI.parseInt(rgbValues[1]); var green = BI.parseInt(rgbValues[1]);
var blue = BI.parseInt(rgbValues[2]); 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) { rgb2json: function (rgbColour) {
if (!rgbColour) { if (!rgbColour) {
return {}; return {};
} }
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return { return {
r: BI.parseInt(rgbValues[0]), r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]), g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]) b: BI.parseInt(rgbValues[2])
}; };
}, },
rgba2json: function (rgbColour) { rgba2json: function (rgbColour) {
if (!rgbColour) { if (!rgbColour) {
return {}; return {};
} }
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return { return {
r: BI.parseInt(rgbValues[0]), r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]), g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]), b: BI.parseInt(rgbValues[2]),
a: BI.parseFloat(rgbValues[3]) a: BI.parseFloat(rgbValues[3])
}; };
}, },
json2rgb: function (rgb) { json2rgb: function (rgb) {
if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) {
return ""; return "";
} }
return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
}, },
json2rgba: function (rgba) { json2rgba: function (rgba) {
if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) {
return ""; return "";
} }
return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")";
}, },
int2hex: function (strNum) { int2hex: function (strNum) {
var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; 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) { hex2rgb: function (color) {
if (!color) { if (!color) {
return ""; return "";
} }
var tempValue = "rgb(", colorArray; var tempValue = "rgb(", colorArray;
if (color.length === 7) { if (color.length === 7) {
colorArray = [BI.parseInt('0x' + color.substring(1, 3)), colorArray = [BI.parseInt('0x' + color.substring(1, 3)),
BI.parseInt('0x' + color.substring(3, 5)), BI.parseInt('0x' + color.substring(3, 5)),
BI.parseInt('0x' + color.substring(5, 7))]; BI.parseInt('0x' + color.substring(5, 7))];
} }
else if (color.length === 4) { else if (color.length === 4) {
colorArray = [BI.parseInt('0x' + color.substring(1, 2)), colorArray = [BI.parseInt('0x' + color.substring(1, 2)),
BI.parseInt('0x' + color.substring(2, 3)), BI.parseInt('0x' + color.substring(2, 3)),
BI.parseInt('0x' + color.substring(3, 4))]; BI.parseInt('0x' + color.substring(3, 4))];
} }
tempValue += colorArray[0] + ","; tempValue += colorArray[0] + ",";
tempValue += colorArray[1] + ","; tempValue += colorArray[1] + ",";
tempValue += colorArray[2] + ")"; tempValue += colorArray[2] + ")";
return tempValue; return tempValue;
}, },
rgba2rgb: function (rgbColour, BGcolor) { rgba2rgb: function (rgbColour, BGcolor) {
if (BI.isNull(BGcolor)) { if (BI.isNull(BGcolor)) {
BGcolor = 1; BGcolor = 1;
} }
if (rgbColour.substr(0, 4) != "rgba") { if (rgbColour.substr(0, 4) != "rgba") {
return ""; return "";
} }
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
if (rgbValues.length < 4) { if (rgbValues.length < 4) {
return ""; return "";
} }
var R = BI.parseFloat(rgbValues[0]); var R = BI.parseFloat(rgbValues[0]);
var G = BI.parseFloat(rgbValues[1]); var G = BI.parseFloat(rgbValues[1]);
var B = BI.parseFloat(rgbValues[2]); var B = BI.parseFloat(rgbValues[2]);
var A = BI.parseFloat(rgbValues[3]); var A = BI.parseFloat(rgbValues[3]);
return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * 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 )) + G * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")";
}, },
getTextSizeWidth: function (text, fontSize) { getTextSizeWidth: function (text, fontSize) {
var span = $("<span></span>").addClass("text-width-span").appendTo($("body")); var span = $("<span></span>").addClass("text-width-span").appendTo($("body"));
if (fontSize == null) { if (fontSize == null) {
fontSize = 12; fontSize = 12;
} }
fontSize = fontSize + "px"; fontSize = fontSize + "px";
span.css("font-size", fontSize).text(text); span.css("font-size", fontSize).text(text);
var width = span.width(); var width = span.width();
span.remove(); span.remove();
return width; return width;
}, },
//获取滚动条的宽度 //获取滚动条的宽度
getScrollWidth: function () { getScrollWidth: function () {
if (this._scrollWidth == null) { if (this._scrollWidth == null) {
var ul = $("<div>").width(50).height(50).css({ var ul = $("<div>").width(50).height(50).css({
position: "absolute", position: "absolute",
top: "-9999px", top: "-9999px",
overflow: "scroll" overflow: "scroll"
}).appendTo($("body")); }).appendTo($("body"));
this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth;
ul.destroy(); ul.destroy();
}
return this._scrollWidth;
} }
}); return this._scrollWidth;
}
});/** });/**
* guy * guy
* 检测某个Widget的EventChange事件然后去show某个card * 检测某个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_TRIGGER_CHANGE = "MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE";
BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW"; BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW";
BI.shortcut('bi.multi_select_check_selected_switcher', BI.MultiSelectCheckSelectedSwitcher);/** 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, { BI.MultiStringList = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
@ -10963,33 +10963,30 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
baseCls: 'bi-multi-string-list', baseCls: 'bi-multi-string-list',
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: BI.emptyFn,
height: 25 el: {}
}) })
}, },
_init: function () { _init: function () {
BI.MultiStringList.superclass._init.apply(this, arguments); BI.MultiStringList.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.storeValue = {};
var assertShowValue = function () { var assertShowValue = function () {
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); 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.adapter = BI.createWidget({
this.popup = BI.createWidget({
type: "bi.multi_select_loader", type: "bi.multi_select_loader",
cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom", cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
onLoaded: o.onLoaded, // onLoaded: o.onLoaded,
el: { el: {
height: "" height: ""
} }
}); });
this.popup.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue(); self.storeValue = this.getValue();
self._adjust(function () { self._adjust(function () {
assertShowValue(); assertShowValue();
@ -10997,90 +10994,105 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
}); });
}); });
this.trigger = BI.createWidget({ this.searcherPane = BI.createWidget({
type: "bi.multi_select_trigger", type: "bi.multi_select_search_pane",
height: o.height, cls: "bi-border-left bi-border-right bi-border-bottom",
adapter: this.popup,
masker: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
keywordGetter: function () {
return self.trigger.getKeyword();
},
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
o.itemsCreator(op, function (res) { op.keyword = self.trigger.getKeyword();
if (op.times === 1 && BI.isNotNull(op.keyword)) { this.setKeyword(op.keyword);
self.trigger.setValue(self.getValue()); o.itemsCreator(op, callback);
}
callback.apply(self, arguments);
});
} }
}); });
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { this.trigger = BI.createWidget({
self._setStartValue(""); type: "bi.searcher",
this.getSearcher().setValue(self.storeValue); isAutoSearch: false,
}); isAutoSync: false,
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { onSearch: function (op, callback) {
self._setStartValue(""); callback();
}); },
this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () { adapter: this.adapter,
if (this.getSearcher().hasMatched()) { popup: this.searcherPane,
var keyword = this.getSearcher().getKeyword(); height: 200,
self._join({ masker: false,
type: BI.Selection.Multi, listeners: [{
value: [keyword] eventName: BI.Searcher.EVENT_START,
}, function () { action: function () {
self.trigger.setValue(self.storeValue); self._showSearcherPane();
self.popup.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.populate();
self._setStartValue(""); self._setStartValue("");
self.fireEvent(BI.MultiStringList.EVENT_CHANGE); this.setValue(self.storeValue);
}) }
} }, {
}); eventName: BI.Searcher.EVENT_STOP,
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { action: function () {
var last = BI.last(keywords); self._showAdapter();
keywords = BI.initial(keywords || []); self._setStartValue("");
if (keywords.length > 0) { self.adapter.setValue(self.storeValue);
self._joinKeywords(keywords, function () { }
if (BI.isEndWithBlank(last)) { }, {
self.trigger.setValue(self.storeValue); eventName: BI.Searcher.EVENT_PAUSE,
self.popup.setValue(self.storeValue); action: function () {
assertShowValue(); if (this.hasMatched()) {
self.popup.populate(); var keyword = this.getKeyword();
self._setStartValue(""); 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 { } else {
self.trigger.setValue(self.storeValue); self._showAdapter();
self.popup.setValue(self.storeValue);
assertShowValue();
} }
}); }
} }, {
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({ BI.createWidget({
type: "bi.vtape", type: "bi.vtape",
element: this, element: this,
@ -11088,16 +11100,37 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
width: "100%", width: "100%",
items: [{ items: [{
el: this.trigger, el: this.trigger,
height: 25 height: 30
}, {
el: div,
height: 2
}, { }, {
el: this.popup, el: this.adapter,
height: "fill" 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 () { _defaultState: function () {
this.trigger.stopEditing(); this.trigger.stopEditing();
}, },
@ -11142,7 +11175,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
this._assertValue(res); this._assertValue(res);
o.itemsCreator({ o.itemsCreator({
type: BI.MultiStringList.REQ_GET_ALL_DATA, type: BI.MultiStringList.REQ_GET_ALL_DATA,
keyword: this.trigger.getKey() keyword: self.trigger.getKeyword()
}, function (ob) { }, function (ob) {
var items = BI.pluck(ob.items, "value"); var items = BI.pluck(ob.items, "value");
if (self.storeValue.type === res.type) { if (self.storeValue.type === res.type) {
@ -11231,22 +11264,21 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
_setStartValue: function (value) { _setStartValue: function (value) {
this._startValue = value; this._startValue = value;
this.popup.setStartValue(value); this.adapter.setStartValue(value);
}, },
// isAllSelected: function () { isAllSelected: function () {
// return this.popup.isAllSelected(); return this.adapter.isAllSelected();
// }, },
resize: function () { resize: function () {
this.trigger.getCounter().adjustView(); // this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView(); // this.trigger.adjustView();
}, },
setValue: function (v) { setValue: function (v) {
this.storeValue = v || {}; this.storeValue = v || {};
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.popup.setValue(this.storeValue); this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue); this.trigger.setValue(this.storeValue);
}, },
@ -11257,7 +11289,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
populate: function () { populate: function () {
this._count = null; this._count = null;
this._allData = 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); 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_STOP = "EVENT_STOP";
BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE"; BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE";
BI.shortcut('bi.multi_tree_searcher', BI.MultiTreeSearcher);/** 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, { BI.MultiSelectTree = BI.inherit(BI.Widget, {
constants: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
_defaultConfig: function () { _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', baseCls: 'bi-multi-tree-combo',
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
height: 25 height: 25
}); })
}, },
_init: function () { _init: function () {
BI.MultiTreeList.superclass._init.apply(this, arguments); BI.MultiSelectTree.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.storeValue = {value: {}};
var isInit = false; this.adapter = BI.createWidget({
var want2showCounter = false; type: "bi.multi_select_tree_popup",
this.popup = BI.createWidget({
type: "bi.multi_tree_list_popup",
itemsCreator: o.itemsCreator itemsCreator: o.itemsCreator
}); });
this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () {
this.popup.on(BI.MultiStringListPopup.EVENT_AFTER_INIT, function () { if (self.trigger.isSearching()) {
self.trigger.getCounter().adjustView(); self.storeValue = {value: self.searcherPane.getValue()};
isInit = true; } else {
if (want2showCounter === true) { self.storeValue = {value: self.adapter.getValue()};
showCounter();
} }
self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
}); });
this.trigger = BI.createWidget({ this.searcherPane = BI.createWidget({//搜索中的时候用的是parttree,同adapter中的synctree不一样
type: "bi.multi_select_trigger", type: "bi.multi_tree_search_pane",
height: o.height, cls: "bi-border-left bi-border-right bi-border-bottom",
adapter: this.popup, keywordGetter: function () {
masker: { return self.trigger.getKeyword();
offset: this.constants.offset
}, },
searcher: { itemsCreator: function (op, callback) {
type: "bi.multi_tree_searcher", op.keyword = self.trigger.getKeyword();
itemsCreator: o.itemsCreator o.itemsCreator(op, callback);
},
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();
} }
}); });
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () { this.trigger = BI.createWidget({
var val = { type: "bi.searcher",
type: BI.Selection.Multi, isAutoSearch: false,
value: this.getSearcher().hasChecked() ? {1: 1} : {} isAutoSync: false,
}; onSearch: function (op, callback) {
this.getSearcher().setState(val); callback({
this.getCounter().setButtonChecked(val); keyword: self.trigger.getKeyword()
}); });
},
this.popup.on(BI.MultiStringListPopup.EVENT_CHANGE, function () { adapter: this.adapter,
showCounter(); popup: this.searcherPane,
var val = { height: 200,
type: BI.Selection.Multi, masker: false,
value: this.hasChecked() ? {1: 1} : {} listeners: [{
}; eventName: BI.Searcher.EVENT_START,
self.trigger.getSearcher().setState(val); action: function () {
self.trigger.getCounter().setButtonChecked(val); self._showSearcherPane();
self.fireEvent(BI.MultiTreeList.EVENT_CHANGE); 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({ BI.createWidget({
type: "bi.vtape", type: "bi.vtape",
element: this, element: this,
@ -12139,29 +12137,45 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
width: "100%", width: "100%",
items: [{ items: [{
el: this.trigger, el: this.trigger,
height: 25 height: 30
}, {
el: div,
height: 2
}, { }, {
el: this.popup, el: this.adapter,
height: "fill" 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 () { _showAdapter: function () {
this.trigger.stopEditing(); this.adapter.setVisible(true);
this.searcherPane.setVisible(false);
},
_showSearcherPane: function () {
this.searcherPane.setVisible(true);
this.adapter.setVisible(false);
}, },
resize: function () { resize: function () {
this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView();
}, },
setValue: function (v) { setValue: function (v) {
this.storeValue.value = v || {}; this.storeValue.value = v || {};
this.popup.setValue({ this.adapter.setValue({
value: v || {} value: v || {}
}); });
this.trigger.setValue({ this.trigger.setValue({
@ -12175,22 +12189,22 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
populate: function () { populate: function () {
this.trigger.populate.apply(this.trigger, arguments); 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.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE";
BI.shortcut('bi.multi_tree_list', BI.MultiTreeList);/** BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree);/**
* Created by zcf on 2016/12/21. * Created by zcf on 2016/12/21.
*/ */
BI.MultiStringListPopup=BI.inherit(BI.Widget,{ BI.MultiSelectTreePopup = BI.inherit(BI.Widget, {
_defaultConfig:function () { _defaultConfig: function () {
return BI.extend(BI.MultiStringListPopup.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom", baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom",
itemsCreator: BI.emptyFn itemsCreator: BI.emptyFn
}); });
}, },
_init:function () { _init: function () {
BI.MultiStringListPopup.superclass._init.apply(this, arguments); BI.MultiSelectTreePopup.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.popup = BI.createWidget({ this.popup = BI.createWidget({
type: "bi.sync_tree", type: "bi.sync_tree",
@ -12199,10 +12213,10 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{
itemsCreator: o.itemsCreator itemsCreator: o.itemsCreator
}); });
this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () { 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 () { 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.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT";
BI.MultiStringListPopup.EVENT_CHANGE="BI.MultiStringListPopup.EVENT_CHANGE"; BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE";
BI.shortcut("bi.multi_tree_list_popup",BI.MultiStringListPopup);//小于号的值为:0,小于等于号的值为:1 BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);//小于号的值为:0,小于等于号的值为:1
//closeMIn:最小值的符号,closeMax:最大值的符号 //closeMIn:最小值的符号,closeMax:最大值的符号
/** /**
* Created by roy on 15/9/17. * 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; return this.options.text;
}, },
_setEnable: function (b) { _setEnable: function (enable) {
BI.BasicButton.superclass._setEnable.apply(this, arguments); 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) { if (this.options.shadow) {
this.$mask && this.$mask.setVisible(false); 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++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i]; var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index); var index = BI.deepIndexOf(this.renderedKeys, datum.index);
var child;
if (index > -1) { if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) { if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width; this.renderedCells[index]._width = datum.width;
@ -2676,9 +2682,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== datum.y) { if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px"); this.renderedCells[index].el.element.css("top", datum.y + "px");
} }
renderedCells.push(this.renderedCells[index]); renderedCells.push(child = this.renderedCells[index]);
} else { } else {
var child = BI.createWidget(BI.extend({ child = BI.createWidget(BI.extend({
type: "bi.label", type: "bi.label",
width: datum.width, width: datum.width,
height: datum.height 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)); 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; var o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
this._calculateSizeAndPositionData();
}
if (o.items.length > 0) { if (o.items.length > 0) {
this.container.setWidth(this._width); this.container.setWidth(this._width);
this.container.setHeight(this._height); this.container.setHeight(this._height);
@ -2839,10 +2849,21 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return this._getMaxScrollTop(); return this._getMaxScrollTop();
}, },
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () { restore: function () {
BI.each(this.renderedCells, function (i, cell) { BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy(); cell.el._destroy();
}); });
this._clearChildren();
this.renderedCells = []; this.renderedCells = [];
this.renderedKeys = []; this.renderedKeys = [];
this.renderRange = {}; this.renderRange = {};
@ -2851,10 +2872,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
populate: function (items) { populate: function (items) {
if (items && items !== this.options.items) { if (items && items !== this.options.items) {
this.options.items = items; this.restore();
this._calculateSizeAndPositionData();
} }
this._populate(); this._populate(items);
} }
}); });
BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL"; BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL";
@ -14753,6 +14773,7 @@ BI.GridView = BI.inherit(BI.Widget, {
var renderedCells = [], renderedKeys = [], renderedWidgets = {}; var renderedCells = [], renderedKeys = [], renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
@ -14761,6 +14782,7 @@ BI.GridView = BI.inherit(BI.Widget, {
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key); var index = BI.deepIndexOf(this.renderedKeys, key);
var child;
if (index > -1) { if (index > -1) {
if (columnDatum.size !== this.renderedCells[index]._width) { if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size; this.renderedCells[index]._width = columnDatum.size;
@ -14776,9 +14798,9 @@ BI.GridView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) { if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) {
this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px"); this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px");
} }
renderedCells.push(this.renderedCells[index]); renderedCells.push(child = this.renderedCells[index]);
} else { } else {
var child = BI.createWidget(BI.extend({ child = BI.createWidget(BI.extend({
type: "bi.label", type: "bi.label",
width: columnDatum.size, width: columnDatum.size,
height: rowDatum.size height: rowDatum.size
@ -14802,7 +14824,7 @@ BI.GridView = BI.inherit(BI.Widget, {
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key); 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)); 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; var self = this, o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
}
if (o.items.length > 0) { if (o.items.length > 0) {
this.columnCount = o.items[0].length; this.columnCount = o.items[0].length;
this.rowCount = o.items.length; this.rowCount = o.items.length;
@ -14935,10 +14960,21 @@ BI.GridView = BI.inherit(BI.Widget, {
this.options.estimatedRowSize = height; this.options.estimatedRowSize = height;
}, },
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () { restore: function () {
BI.each(this.renderedCells, function (i, cell) { BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy(); cell.el._destroy();
}); });
this._clearChildren();
this.renderedCells = []; this.renderedCells = [];
this.renderedKeys = []; this.renderedKeys = [];
this.renderRange = {}; this.renderRange = {};
@ -14947,10 +14983,9 @@ BI.GridView = BI.inherit(BI.Widget, {
populate: function (items) { populate: function (items) {
if (items && items !== this.options.items) { if (items && items !== this.options.items) {
this.options.items = items;
this.restore(); this.restore();
} }
this._populate(); this._populate(items);
} }
}); });
BI.GridView.EVENT_SCROLL = "EVENT_SCROLL"; BI.GridView.EVENT_SCROLL = "EVENT_SCROLL";
@ -28704,7 +28739,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
_populateScrollbar: function () { _populateScrollbar: function () {
var o = this.options; 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(); var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) { BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -28745,7 +28781,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
_populateTable: function () { _populateTable: function () {
var self = this, o = this.options; 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(); var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) { BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -28776,7 +28813,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
var trh = otrh + this._scrollBarSize; var trh = otrh + this._scrollBarSize;
var blw = oblw + this._scrollBarSize; var blw = oblw + this._scrollBarSize;
var blh = oblh + this._scrollBarSize; var blh = oblh + this._scrollBarSize;
var brw = obrw+ this._scrollBarSize; var brw = obrw + this._scrollBarSize;
var brh = obrh + this._scrollBarSize; var brh = obrh + this._scrollBarSize;
var digest = function (el) { var digest = function (el) {
@ -28833,10 +28870,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
run(this.bottomLeftItems, o.items, leftItems); run(this.bottomLeftItems, o.items, leftItems);
run(this.bottomRightItems, o.items, rightItems); run(this.bottomRightItems, o.items, rightItems);
this.topLeftCollection.populate(leftHeader); this.topLeftCollection._populate(leftHeader);
this.topRightCollection.populate(rightHeader); this.topRightCollection._populate(rightHeader);
this.bottomLeftCollection.populate(leftItems); this.bottomLeftCollection._populate(leftItems);
this.bottomRightCollection.populate(rightItems); this.bottomRightCollection._populate(rightItems);
}, },
_digest: function () { _digest: function () {
@ -28956,8 +28993,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
return; return;
} }
if (this._isNeedDigest === true) { if (this._isNeedDigest === true) {
this._reRange();
this._digest(); this._digest();
} }
this._isNeedDigest = false;
this._populateTable(); this._populateTable();
this._populateScrollbar(); this._populateScrollbar();
}, },
@ -29052,6 +29091,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
this.bottomRightCollection.restore(); this.bottomRightCollection.restore();
}, },
_reRange: function () {
this.topLeftCollection.reRange();
this.topRightCollection.reRange();
this.bottomLeftCollection.reRange();
this.bottomRightCollection.reRange();
},
restore: function () { restore: function () {
this._restore(); this._restore();
} }
@ -29654,16 +29700,20 @@ BI.GridTable = BI.inherit(BI.Widget, {
this.contextLayout.attr("items", items); this.contextLayout.attr("items", items);
this.contextLayout.resize(); this.contextLayout.resize();
this.topLeftGrid.populate(this.header[0]); this.topLeftGrid._populate(this.header[0]);
this.topRightGrid.populate(this.header[1]); this.topRightGrid._populate(this.header[1]);
this.bottomLeftGrid.populate(this.items[0]); this.bottomLeftGrid._populate(this.items[0]);
this.bottomRightGrid.populate(this.items[1]); this.bottomRightGrid._populate(this.items[1]);
}, },
_populate: function () { _populate: function () {
if (this._width <= 0 || this._height <= 0) { if (this._width <= 0 || this._height <= 0) {
return; return;
} }
if (this._isNeedDigest === true) {
this._reRange();
this._isNeedDigest = false;
}
this._populateTable(); this._populateTable();
this._populateScrollbar(); this._populateScrollbar();
}, },
@ -29721,10 +29771,12 @@ BI.GridTable = BI.inherit(BI.Widget, {
setColumnSize: function (columnSize) { setColumnSize: function (columnSize) {
this.options.columnSize = columnSize; this.options.columnSize = columnSize;
this._isNeedDigest = true;
}, },
setRegionColumnSize: function (regionColumnSize) { setRegionColumnSize: function (regionColumnSize) {
this.options.regionColumnSize = regionColumnSize; this.options.regionColumnSize = regionColumnSize;
this._isNeedDigest = true;
}, },
getColumnSize: function () { getColumnSize: function () {
@ -29737,11 +29789,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
populate: function (items, header) { populate: function (items, header) {
if (items && this.options.items !== items) { if (items && this.options.items !== items) {
this._isNeedDigest = true;
this.options.items = items; this.options.items = items;
this.items = this._getItems(); this.items = this._getItems();
this._restore(); this._restore();
} }
if (header && this.options.header !== header) { if (header && this.options.header !== header) {
this._isNeedDigest = true;
this.options.header = header; this.options.header = header;
this.header = this._getHeader(); this.header = this._getHeader();
this._restore(); this._restore();
@ -29756,6 +29810,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
this.bottomRightGrid.restore(); this.bottomRightGrid.restore();
}, },
_reRange: function () {
this.topLeftGrid.reRange();
this.topRightGrid.reRange();
this.bottomLeftGrid.reRange();
this.bottomRightGrid.reRange();
},
restore: function () { restore: function () {
this._restore(); this._restore();
} }
@ -32349,8 +32410,10 @@ BI.ResizableTable = BI.inherit(BI.Widget, {
}; };
var stop = function (j, size) { var stop = function (j, size) {
self.resizer.setVisible(false); self.resizer.setVisible(false);
o.columnSize[j] = size; var columnSize = o.columnSize.slice();
self.table.setColumnSize(o.columnSize); columnSize[j] = size;
o.columnSize = columnSize;
self.table.setColumnSize(columnSize);
self.table.populate(); self.table.populate();
self._populate(); self._populate();
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE); self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE);

2
docs/case.js

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

745
docs/core.js

@ -14487,6 +14487,7 @@ BI.Widget = BI.inherit(BI.OB, {
this._mountChildren && this._mountChildren(); this._mountChildren && this._mountChildren();
BI.each(this._children, function (i, widget) { BI.each(this._children, function (i, widget) {
!self.isEnabled() && widget._setEnable(false); !self.isEnabled() && widget._setEnable(false);
!self.isValid() && widget._setValid(false);
widget._mount && widget._mount(); widget._mount && widget._mount();
}); });
this.mounted && this.mounted(); 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) { setEnable: function (enable) {
this._setEnable(enable); this._setEnable(enable);
if (enable === true) { if (enable === true) {
@ -14544,6 +14557,7 @@ BI.Widget = BI.inherit(BI.OB, {
setValid: function (valid) { setValid: function (valid) {
this.options.invalid = !valid; this.options.invalid = !valid;
this._setValid(valid);
if (valid === true) { if (valid === true) {
this.element.removeClass("base-invalid invalid"); this.element.removeClass("base-invalid invalid");
} else if (valid === false) { } else if (valid === false) {
@ -15372,7 +15386,7 @@ BI.View = BI.inherit(BI.V, {
BI.each(cardNames, function (i, name) { BI.each(cardNames, function (i, name) {
delete self._cards[name]; delete self._cards[name];
}); });
this._cardLayouts[key] && this._cardLayouts[key].destroy(); this._cardLayouts[key] && this._cardLayouts[key]._destroy();
return this; return this;
}, },
@ -19906,6 +19920,9 @@ BI.PopoverSection = BI.inherit(BI.Widget, {
} }
}); });
BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () { BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
if (!window.BI) {
window.BI = {};
}
function isEmpty(value) { function isEmpty(value) {
// 判断是否为空值 // 判断是否为空值
var result = value === "" || value === null || value === undefined; var result = value === "" || value === null || value === undefined;
@ -19966,124 +19983,6 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
return text; 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 { } else {
return left + '.' + right; return left + '.' + right;
} }
}; }
/** /**
* 处理小数点右边小数部分 * 处理小数点右边小数部分
* @param tright 右边内容 * @param tright 右边内容
@ -20170,7 +20070,7 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
if (newnum.length > orilen) { if (newnum.length > orilen) {
newnum = newnum.substr(1); newnum = newnum.substr(1);
} else { } else {
newnum = BI.leftPad(newnum, orilen, '0'); newnum = String.leftPad(newnum, orilen, '0');
result.leftPlus = false; result.leftPlus = false;
} }
right = right.replace(/^[0-9]+/, newnum); right = right.replace(/^[0-9]+/, newnum);
@ -20431,7 +20331,7 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
return o; return o;
})(jo); })(jo);
} };
BI.contentFormat = function (cv, fmt) { BI.contentFormat = function (cv, fmt) {
if (isEmpty(cv)) { if (isEmpty(cv)) {
@ -20473,15 +20373,122 @@ BI.PopoverSection.EVENT_CLOSE = "EVENT_CLOSE";;(function () {
return text; 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) { // O(len(format))
result = ch + result; 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) { BI.object2Number = function (value) {
@ -22638,284 +22645,280 @@ BI.extend(jQuery, {
* 基本的函数 * 基本的函数
* Created by GUY on 2015/6/24. * Created by GUY on 2015/6/24.
*/ */
$(function () { BI.Func = {};
BI.Func = {}; BI.extend(BI.Func, {
var formulas = {};
BI.extend(BI.Func, {
/** /**
* 获取搜索结果 * 获取搜索结果
* @param items * @param items
* @param keyword * @param keyword
* @param param 搜索哪个属性 * @param param 搜索哪个属性
*/ */
getSearchResult: function (items, keyword, param) { getSearchResult: function (items, keyword, param) {
var isArray = BI.isArray(items); var isArray = BI.isArray(items);
items = isArray ? BI.flatten(items) : items; items = isArray ? BI.flatten(items) : items;
param || (param = "text"); param || (param = "text");
if (!BI.isKey(keyword)) { 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 { return {
matched: matched, finded: BI.deepClone(items),
finded: finded 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操作的通用函数 * 把dom数组或元素悬挂起来,使其不对html产生影响
* @type {{}} * @param dom
*/ */
BI.DOM = {}; hang: function (doms) {
BI.extend(BI.DOM, { if (BI.isEmpty(doms)) {
return;
/** }
* 把dom数组或元素悬挂起来,使其不对html产生影响 var frag = document.createDocumentFragment();
* @param dom BI.each(doms, function (i, dom) {
*/ dom instanceof BI.Widget && (dom = dom.element);
hang: function (doms) { dom instanceof $ && dom[0] && frag.appendChild(dom[0]);
if (BI.isEmpty(doms)) { });
return; return frag;
} },
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) { isExist: function (obj) {
return $("body").find(obj.element).length > 0; return $("body").find(obj.element).length > 0;
}, },
//预加载图片 //预加载图片
preloadImages: function (srcArray, onload) { preloadImages: function (srcArray, onload) {
var count = 0, images = []; var count = 0, images = [];
function complete() { function complete() {
count++; count++;
if (count >= srcArray.length) { if (count >= srcArray.length) {
onload(); onload();
}
} }
}
BI.each(srcArray, function (i, src) { BI.each(srcArray, function (i, src) {
images[i] = new Image(); images[i] = new Image();
images[i].src = src; images[i].src = src;
images[i].onload = function () { images[i].onload = function () {
complete() complete()
}; };
images[i].onerror = function () { images[i].onerror = function () {
complete() complete()
}; };
}); });
}, },
isColor: function (color) { isColor: function (color) {
return this.isRGBColor(color) || this.isHexColor(color); return this.isRGBColor(color) || this.isHexColor(color);
}, },
isRGBColor: function (color) { isRGBColor: function (color) {
if (!color) { if (!color) {
return false; return false;
} }
return color.substr(0, 3) === "rgb"; return color.substr(0, 3) === "rgb";
}, },
isHexColor: function (color) { isHexColor: function (color) {
if (!color) { if (!color) {
return false; return false;
} }
return color[0] === "#" && color.length === 7; return color[0] === "#" && color.length === 7;
}, },
isDarkColor: function (hex) { isDarkColor: function (hex) {
if (!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; 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) { getContrastColor: function (color) {
if (!color) { if (!color) {
return ""; return "";
} }
if (this.isDarkColor(color)) { if (this.isDarkColor(color)) {
return "#ffffff"; return "#ffffff";
} }
return "#1a1a1a"; return "#1a1a1a";
}, },
rgb2hex: function (rgbColour) { rgb2hex: function (rgbColour) {
if (!rgbColour || rgbColour.substr(0, 3) != "rgb") { if (!rgbColour || rgbColour.substr(0, 3) != "rgb") {
return ""; return "";
} }
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
var red = BI.parseInt(rgbValues[0]); var red = BI.parseInt(rgbValues[0]);
var green = BI.parseInt(rgbValues[1]); var green = BI.parseInt(rgbValues[1]);
var blue = BI.parseInt(rgbValues[2]); 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) { rgb2json: function (rgbColour) {
if (!rgbColour) { if (!rgbColour) {
return {}; return {};
} }
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return { return {
r: BI.parseInt(rgbValues[0]), r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]), g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]) b: BI.parseInt(rgbValues[2])
}; };
}, },
rgba2json: function (rgbColour) { rgba2json: function (rgbColour) {
if (!rgbColour) { if (!rgbColour) {
return {}; return {};
} }
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
return { return {
r: BI.parseInt(rgbValues[0]), r: BI.parseInt(rgbValues[0]),
g: BI.parseInt(rgbValues[1]), g: BI.parseInt(rgbValues[1]),
b: BI.parseInt(rgbValues[2]), b: BI.parseInt(rgbValues[2]),
a: BI.parseFloat(rgbValues[3]) a: BI.parseFloat(rgbValues[3])
}; };
}, },
json2rgb: function (rgb) { json2rgb: function (rgb) {
if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) { if (!BI.isKey(rgb.r) || !BI.isKey(rgb.g) || !BI.isKey(rgb.b)) {
return ""; return "";
} }
return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")"; return "rgb(" + rgb.r + "," + rgb.g + "," + rgb.b + ")";
}, },
json2rgba: function (rgba) { json2rgba: function (rgba) {
if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) { if (!BI.isKey(rgba.r) || !BI.isKey(rgba.g) || !BI.isKey(rgba.b)) {
return ""; return "";
} }
return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")"; return "rgba(" + rgba.r + "," + rgba.g + "," + rgba.b + "," + rgba.a + ")";
}, },
int2hex: function (strNum) { int2hex: function (strNum) {
var hexdig = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f']; 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) { hex2rgb: function (color) {
if (!color) { if (!color) {
return ""; return "";
} }
var tempValue = "rgb(", colorArray; var tempValue = "rgb(", colorArray;
if (color.length === 7) { if (color.length === 7) {
colorArray = [BI.parseInt('0x' + color.substring(1, 3)), colorArray = [BI.parseInt('0x' + color.substring(1, 3)),
BI.parseInt('0x' + color.substring(3, 5)), BI.parseInt('0x' + color.substring(3, 5)),
BI.parseInt('0x' + color.substring(5, 7))]; BI.parseInt('0x' + color.substring(5, 7))];
} }
else if (color.length === 4) { else if (color.length === 4) {
colorArray = [BI.parseInt('0x' + color.substring(1, 2)), colorArray = [BI.parseInt('0x' + color.substring(1, 2)),
BI.parseInt('0x' + color.substring(2, 3)), BI.parseInt('0x' + color.substring(2, 3)),
BI.parseInt('0x' + color.substring(3, 4))]; BI.parseInt('0x' + color.substring(3, 4))];
} }
tempValue += colorArray[0] + ","; tempValue += colorArray[0] + ",";
tempValue += colorArray[1] + ","; tempValue += colorArray[1] + ",";
tempValue += colorArray[2] + ")"; tempValue += colorArray[2] + ")";
return tempValue; return tempValue;
}, },
rgba2rgb: function (rgbColour, BGcolor) { rgba2rgb: function (rgbColour, BGcolor) {
if (BI.isNull(BGcolor)) { if (BI.isNull(BGcolor)) {
BGcolor = 1; BGcolor = 1;
} }
if (rgbColour.substr(0, 4) != "rgba") { if (rgbColour.substr(0, 4) != "rgba") {
return ""; return "";
} }
var rgbValues = rgbColour.match(/\d+(\.\d+)?/g); var rgbValues = rgbColour.match(/\d+(\.\d+)?/g);
if (rgbValues.length < 4) { if (rgbValues.length < 4) {
return ""; return "";
} }
var R = BI.parseFloat(rgbValues[0]); var R = BI.parseFloat(rgbValues[0]);
var G = BI.parseFloat(rgbValues[1]); var G = BI.parseFloat(rgbValues[1]);
var B = BI.parseFloat(rgbValues[2]); var B = BI.parseFloat(rgbValues[2]);
var A = BI.parseFloat(rgbValues[3]); var A = BI.parseFloat(rgbValues[3]);
return "rgb(" + Math.floor(255 * (BGcolor * (1 - A )) + R * 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 )) + G * A) + "," +
Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")"; Math.floor(255 * (BGcolor * (1 - A )) + B * A) + ")";
}, },
getTextSizeWidth: function (text, fontSize) { getTextSizeWidth: function (text, fontSize) {
var span = $("<span></span>").addClass("text-width-span").appendTo($("body")); var span = $("<span></span>").addClass("text-width-span").appendTo($("body"));
if (fontSize == null) { if (fontSize == null) {
fontSize = 12; fontSize = 12;
} }
fontSize = fontSize + "px"; fontSize = fontSize + "px";
span.css("font-size", fontSize).text(text); span.css("font-size", fontSize).text(text);
var width = span.width(); var width = span.width();
span.remove(); span.remove();
return width; return width;
}, },
//获取滚动条的宽度 //获取滚动条的宽度
getScrollWidth: function () { getScrollWidth: function () {
if (this._scrollWidth == null) { if (this._scrollWidth == null) {
var ul = $("<div>").width(50).height(50).css({ var ul = $("<div>").width(50).height(50).css({
position: "absolute", position: "absolute",
top: "-9999px", top: "-9999px",
overflow: "scroll" overflow: "scroll"
}).appendTo($("body")); }).appendTo($("body"));
this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth; this._scrollWidth = ul[0].offsetWidth - ul[0].clientWidth;
ul.destroy(); ul.destroy();
}
return this._scrollWidth;
} }
}); return this._scrollWidth;
}
});/** });/**
* guy * guy
* 检测某个Widget的EventChange事件然后去show某个card * 检测某个Widget的EventChange事件然后去show某个card
@ -23528,7 +23531,6 @@ Date._QN = ["", BI.i18nText("BI-Quarter_1"),
BI.i18nText("BI-Quarter_3"), BI.i18nText("BI-Quarter_3"),
BI.i18nText("BI-Quarter_4")]; BI.i18nText("BI-Quarter_4")];
/** Adds the number of days array to the Date object. */ /** Adds the number of days array to the Date object. */
Date._MD = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]; 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 new Date(y, m, d, hr, min, sec);
} }
return today; return today;
};/* };
/*
* 给jQuery.Event对象添加的工具方法 * 给jQuery.Event对象添加的工具方法
*/ */
$.extend($.Event.prototype, { $.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_TRIGGER_CHANGE = "MultiSelectCheckSelectedSwitcher.EVENT_TRIGGER_CHANGE";
BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW"; BI.MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW = "MultiSelectCheckSelectedSwitcher.EVENT_BEFORE_POPUPVIEW";
BI.shortcut('bi.multi_select_check_selected_switcher', BI.MultiSelectCheckSelectedSwitcher);/** 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, { BI.MultiStringList = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
@ -10963,33 +10963,30 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
baseCls: 'bi-multi-string-list', baseCls: 'bi-multi-string-list',
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: BI.emptyFn,
height: 25 el: {}
}) })
}, },
_init: function () { _init: function () {
BI.MultiStringList.superclass._init.apply(this, arguments); BI.MultiStringList.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.storeValue = {};
var assertShowValue = function () { var assertShowValue = function () {
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); 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.adapter = BI.createWidget({
this.popup = BI.createWidget({
type: "bi.multi_select_loader", type: "bi.multi_select_loader",
cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom", cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
onLoaded: o.onLoaded, // onLoaded: o.onLoaded,
el: { el: {
height: "" height: ""
} }
}); });
this.popup.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue(); self.storeValue = this.getValue();
self._adjust(function () { self._adjust(function () {
assertShowValue(); assertShowValue();
@ -10997,90 +10994,105 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
}); });
}); });
this.trigger = BI.createWidget({ this.searcherPane = BI.createWidget({
type: "bi.multi_select_trigger", type: "bi.multi_select_search_pane",
height: o.height, cls: "bi-border-left bi-border-right bi-border-bottom",
adapter: this.popup,
masker: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
keywordGetter: function () {
return self.trigger.getKeyword();
},
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
o.itemsCreator(op, function (res) { op.keyword = self.trigger.getKeyword();
if (op.times === 1 && BI.isNotNull(op.keyword)) { this.setKeyword(op.keyword);
self.trigger.setValue(self.getValue()); o.itemsCreator(op, callback);
}
callback.apply(self, arguments);
});
} }
}); });
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { this.trigger = BI.createWidget({
self._setStartValue(""); type: "bi.searcher",
this.getSearcher().setValue(self.storeValue); isAutoSearch: false,
}); isAutoSync: false,
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { onSearch: function (op, callback) {
self._setStartValue(""); callback();
}); },
this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () { adapter: this.adapter,
if (this.getSearcher().hasMatched()) { popup: this.searcherPane,
var keyword = this.getSearcher().getKeyword(); height: 200,
self._join({ masker: false,
type: BI.Selection.Multi, listeners: [{
value: [keyword] eventName: BI.Searcher.EVENT_START,
}, function () { action: function () {
self.trigger.setValue(self.storeValue); self._showSearcherPane();
self.popup.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.populate();
self._setStartValue(""); self._setStartValue("");
self.fireEvent(BI.MultiStringList.EVENT_CHANGE); this.setValue(self.storeValue);
}) }
} }, {
}); eventName: BI.Searcher.EVENT_STOP,
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { action: function () {
var last = BI.last(keywords); self._showAdapter();
keywords = BI.initial(keywords || []); self._setStartValue("");
if (keywords.length > 0) { self.adapter.setValue(self.storeValue);
self._joinKeywords(keywords, function () { }
if (BI.isEndWithBlank(last)) { }, {
self.trigger.setValue(self.storeValue); eventName: BI.Searcher.EVENT_PAUSE,
self.popup.setValue(self.storeValue); action: function () {
assertShowValue(); if (this.hasMatched()) {
self.popup.populate(); var keyword = this.getKeyword();
self._setStartValue(""); 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 { } else {
self.trigger.setValue(self.storeValue); self._showAdapter();
self.popup.setValue(self.storeValue);
assertShowValue();
} }
}); }
} }, {
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({ BI.createWidget({
type: "bi.vtape", type: "bi.vtape",
element: this, element: this,
@ -11088,16 +11100,37 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
width: "100%", width: "100%",
items: [{ items: [{
el: this.trigger, el: this.trigger,
height: 25 height: 30
}, {
el: div,
height: 2
}, { }, {
el: this.popup, el: this.adapter,
height: "fill" 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 () { _defaultState: function () {
this.trigger.stopEditing(); this.trigger.stopEditing();
}, },
@ -11142,7 +11175,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
this._assertValue(res); this._assertValue(res);
o.itemsCreator({ o.itemsCreator({
type: BI.MultiStringList.REQ_GET_ALL_DATA, type: BI.MultiStringList.REQ_GET_ALL_DATA,
keyword: this.trigger.getKey() keyword: self.trigger.getKeyword()
}, function (ob) { }, function (ob) {
var items = BI.pluck(ob.items, "value"); var items = BI.pluck(ob.items, "value");
if (self.storeValue.type === res.type) { if (self.storeValue.type === res.type) {
@ -11231,22 +11264,21 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
_setStartValue: function (value) { _setStartValue: function (value) {
this._startValue = value; this._startValue = value;
this.popup.setStartValue(value); this.adapter.setStartValue(value);
}, },
// isAllSelected: function () { isAllSelected: function () {
// return this.popup.isAllSelected(); return this.adapter.isAllSelected();
// }, },
resize: function () { resize: function () {
this.trigger.getCounter().adjustView(); // this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView(); // this.trigger.adjustView();
}, },
setValue: function (v) { setValue: function (v) {
this.storeValue = v || {}; this.storeValue = v || {};
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.popup.setValue(this.storeValue); this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue); this.trigger.setValue(this.storeValue);
}, },
@ -11257,7 +11289,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
populate: function () { populate: function () {
this._count = null; this._count = null;
this._allData = 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); 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_STOP = "EVENT_STOP";
BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE"; BI.MultiTreeSearcher.EVENT_PAUSE = "EVENT_PAUSE";
BI.shortcut('bi.multi_tree_searcher', BI.MultiTreeSearcher);/** 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, { BI.MultiSelectTree = BI.inherit(BI.Widget, {
constants: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
_defaultConfig: function () { _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', baseCls: 'bi-multi-tree-combo',
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
height: 25 height: 25
}); })
}, },
_init: function () { _init: function () {
BI.MultiTreeList.superclass._init.apply(this, arguments); BI.MultiSelectTree.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.storeValue = {value: {}};
var isInit = false; this.adapter = BI.createWidget({
var want2showCounter = false; type: "bi.multi_select_tree_popup",
this.popup = BI.createWidget({
type: "bi.multi_tree_list_popup",
itemsCreator: o.itemsCreator itemsCreator: o.itemsCreator
}); });
this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () {
this.popup.on(BI.MultiStringListPopup.EVENT_AFTER_INIT, function () { if (self.trigger.isSearching()) {
self.trigger.getCounter().adjustView(); self.storeValue = {value: self.searcherPane.getValue()};
isInit = true; } else {
if (want2showCounter === true) { self.storeValue = {value: self.adapter.getValue()};
showCounter();
} }
self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
}); });
this.trigger = BI.createWidget({ this.searcherPane = BI.createWidget({//搜索中的时候用的是parttree,同adapter中的synctree不一样
type: "bi.multi_select_trigger", type: "bi.multi_tree_search_pane",
height: o.height, cls: "bi-border-left bi-border-right bi-border-bottom",
adapter: this.popup, keywordGetter: function () {
masker: { return self.trigger.getKeyword();
offset: this.constants.offset
}, },
searcher: { itemsCreator: function (op, callback) {
type: "bi.multi_tree_searcher", op.keyword = self.trigger.getKeyword();
itemsCreator: o.itemsCreator o.itemsCreator(op, callback);
},
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();
} }
}); });
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () { this.trigger = BI.createWidget({
var val = { type: "bi.searcher",
type: BI.Selection.Multi, isAutoSearch: false,
value: this.getSearcher().hasChecked() ? {1: 1} : {} isAutoSync: false,
}; onSearch: function (op, callback) {
this.getSearcher().setState(val); callback({
this.getCounter().setButtonChecked(val); keyword: self.trigger.getKeyword()
}); });
},
this.popup.on(BI.MultiStringListPopup.EVENT_CHANGE, function () { adapter: this.adapter,
showCounter(); popup: this.searcherPane,
var val = { height: 200,
type: BI.Selection.Multi, masker: false,
value: this.hasChecked() ? {1: 1} : {} listeners: [{
}; eventName: BI.Searcher.EVENT_START,
self.trigger.getSearcher().setState(val); action: function () {
self.trigger.getCounter().setButtonChecked(val); self._showSearcherPane();
self.fireEvent(BI.MultiTreeList.EVENT_CHANGE); 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({ BI.createWidget({
type: "bi.vtape", type: "bi.vtape",
element: this, element: this,
@ -12139,29 +12137,45 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
width: "100%", width: "100%",
items: [{ items: [{
el: this.trigger, el: this.trigger,
height: 25 height: 30
}, {
el: div,
height: 2
}, { }, {
el: this.popup, el: this.adapter,
height: "fill" 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 () { _showAdapter: function () {
this.trigger.stopEditing(); this.adapter.setVisible(true);
this.searcherPane.setVisible(false);
},
_showSearcherPane: function () {
this.searcherPane.setVisible(true);
this.adapter.setVisible(false);
}, },
resize: function () { resize: function () {
this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView();
}, },
setValue: function (v) { setValue: function (v) {
this.storeValue.value = v || {}; this.storeValue.value = v || {};
this.popup.setValue({ this.adapter.setValue({
value: v || {} value: v || {}
}); });
this.trigger.setValue({ this.trigger.setValue({
@ -12175,22 +12189,22 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
populate: function () { populate: function () {
this.trigger.populate.apply(this.trigger, arguments); 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.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE";
BI.shortcut('bi.multi_tree_list', BI.MultiTreeList);/** BI.shortcut("bi.multi_select_tree", BI.MultiSelectTree);/**
* Created by zcf on 2016/12/21. * Created by zcf on 2016/12/21.
*/ */
BI.MultiStringListPopup=BI.inherit(BI.Widget,{ BI.MultiSelectTreePopup = BI.inherit(BI.Widget, {
_defaultConfig:function () { _defaultConfig: function () {
return BI.extend(BI.MultiStringListPopup.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom", baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom",
itemsCreator: BI.emptyFn itemsCreator: BI.emptyFn
}); });
}, },
_init:function () { _init: function () {
BI.MultiStringListPopup.superclass._init.apply(this, arguments); BI.MultiSelectTreePopup.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.popup = BI.createWidget({ this.popup = BI.createWidget({
type: "bi.sync_tree", type: "bi.sync_tree",
@ -12199,10 +12213,10 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{
itemsCreator: o.itemsCreator itemsCreator: o.itemsCreator
}); });
this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () { 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 () { 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.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT";
BI.MultiStringListPopup.EVENT_CHANGE="BI.MultiStringListPopup.EVENT_CHANGE"; BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE";
BI.shortcut("bi.multi_tree_list_popup",BI.MultiStringListPopup);//小于号的值为:0,小于等于号的值为:1 BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);//小于号的值为:0,小于等于号的值为:1
//closeMIn:最小值的符号,closeMax:最大值的符号 //closeMIn:最小值的符号,closeMax:最大值的符号
/** /**
* Created by roy on 15/9/17. * 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++) { for (var i = 0, len = childrenToDisplay.length; i < len; i++) {
var datum = childrenToDisplay[i]; var datum = childrenToDisplay[i];
var index = BI.deepIndexOf(this.renderedKeys, datum.index); var index = BI.deepIndexOf(this.renderedKeys, datum.index);
var child;
if (index > -1) { if (index > -1) {
if (datum.width !== this.renderedCells[index]._width) { if (datum.width !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = datum.width; this.renderedCells[index]._width = datum.width;
@ -171,9 +172,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== datum.y) { if (this.renderedCells[index].top !== datum.y) {
this.renderedCells[index].el.element.css("top", datum.y + "px"); this.renderedCells[index].el.element.css("top", datum.y + "px");
} }
renderedCells.push(this.renderedCells[index]); renderedCells.push(child = this.renderedCells[index]);
} else { } else {
var child = BI.createWidget(BI.extend({ child = BI.createWidget(BI.extend({
type: "bi.label", type: "bi.label",
width: datum.width, width: datum.width,
height: datum.height 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)); 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; var o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
this._calculateSizeAndPositionData();
}
if (o.items.length > 0) { if (o.items.length > 0) {
this.container.setWidth(this._width); this.container.setWidth(this._width);
this.container.setHeight(this._height); this.container.setHeight(this._height);
@ -334,10 +339,21 @@ BI.CollectionView = BI.inherit(BI.Widget, {
return this._getMaxScrollTop(); return this._getMaxScrollTop();
}, },
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () { restore: function () {
BI.each(this.renderedCells, function (i, cell) { BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy(); cell.el._destroy();
}); });
this._clearChildren();
this.renderedCells = []; this.renderedCells = [];
this.renderedKeys = []; this.renderedKeys = [];
this.renderRange = {}; this.renderRange = {};
@ -346,10 +362,9 @@ BI.CollectionView = BI.inherit(BI.Widget, {
populate: function (items) { populate: function (items) {
if (items && items !== this.options.items) { if (items && items !== this.options.items) {
this.options.items = items; this.restore();
this._calculateSizeAndPositionData();
} }
this._populate(); this._populate(items);
} }
}); });
BI.CollectionView.EVENT_SCROLL = "EVENT_SCROLL"; 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 renderedCells = [], renderedKeys = [], renderedWidgets = {};
var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0; var minX = this._getMaxScrollLeft(), minY = this._getMaxScrollTop(), maxX = 0, maxY = 0;
var count = 0;
for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) { for (var rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex); var rowDatum = this._rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
@ -131,6 +132,7 @@ BI.GridView = BI.inherit(BI.Widget, {
var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex); var columnDatum = this._columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
var index = BI.deepIndexOf(this.renderedKeys, key); var index = BI.deepIndexOf(this.renderedKeys, key);
var child;
if (index > -1) { if (index > -1) {
if (columnDatum.size !== this.renderedCells[index]._width) { if (columnDatum.size !== this.renderedCells[index]._width) {
this.renderedCells[index]._width = columnDatum.size; this.renderedCells[index]._width = columnDatum.size;
@ -146,9 +148,9 @@ BI.GridView = BI.inherit(BI.Widget, {
if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) { if (this.renderedCells[index].top !== rowDatum.offset + verticalOffsetAdjustment) {
this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px"); this.renderedCells[index].el.element.css("top", (rowDatum.offset + verticalOffsetAdjustment) + "px");
} }
renderedCells.push(this.renderedCells[index]); renderedCells.push(child = this.renderedCells[index]);
} else { } else {
var child = BI.createWidget(BI.extend({ child = BI.createWidget(BI.extend({
type: "bi.label", type: "bi.label",
width: columnDatum.size, width: columnDatum.size,
height: rowDatum.size height: rowDatum.size
@ -172,7 +174,7 @@ BI.GridView = BI.inherit(BI.Widget, {
minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment); minY = Math.min(minY, rowDatum.offset + verticalOffsetAdjustment);
maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size); maxY = Math.max(maxY, rowDatum.offset + verticalOffsetAdjustment + rowDatum.size);
renderedKeys.push(key); 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)); 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; var self = this, o = this.options;
if (items && items !== this.options.items) {
this.options.items = items;
}
if (o.items.length > 0) { if (o.items.length > 0) {
this.columnCount = o.items[0].length; this.columnCount = o.items[0].length;
this.rowCount = o.items.length; this.rowCount = o.items.length;
@ -305,10 +310,21 @@ BI.GridView = BI.inherit(BI.Widget, {
this.options.estimatedRowSize = height; this.options.estimatedRowSize = height;
}, },
//重新计算children
reRange: function () {
this.renderRange = {};
},
_clearChildren: function () {
this.container._children = {};
this.container.attr("items", []);
},
restore: function () { restore: function () {
BI.each(this.renderedCells, function (i, cell) { BI.each(this.renderedCells, function (i, cell) {
cell.el.destroy(); cell.el._destroy();
}); });
this._clearChildren();
this.renderedCells = []; this.renderedCells = [];
this.renderedKeys = []; this.renderedKeys = [];
this.renderRange = {}; this.renderRange = {};
@ -317,10 +333,9 @@ BI.GridView = BI.inherit(BI.Widget, {
populate: function (items) { populate: function (items) {
if (items && items !== this.options.items) { if (items && items !== this.options.items) {
this.options.items = items;
this.restore(); this.restore();
} }
this._populate(); this._populate(items);
} }
}); });
BI.GridView.EVENT_SCROLL = "EVENT_SCROLL"; 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; return this.options.text;
}, },
_setEnable: function (b) { _setEnable: function (enable) {
BI.BasicButton.superclass._setEnable.apply(this, arguments); 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) { if (this.options.shadow) {
this.$mask && this.$mask.setVisible(false); 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 () { _populateScrollbar: function () {
var o = this.options; 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(); var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) { BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -216,7 +217,8 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
_populateTable: function () { _populateTable: function () {
var self = this, o = this.options; 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(); var freezeColLength = this._getFreezeColLength();
BI.each(o.columnSize, function (i, size) { BI.each(o.columnSize, function (i, size) {
if (o.isNeedFreeze === true && o.freezeCols.contains(i)) { if (o.isNeedFreeze === true && o.freezeCols.contains(i)) {
@ -247,7 +249,7 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
var trh = otrh + this._scrollBarSize; var trh = otrh + this._scrollBarSize;
var blw = oblw + this._scrollBarSize; var blw = oblw + this._scrollBarSize;
var blh = oblh + this._scrollBarSize; var blh = oblh + this._scrollBarSize;
var brw = obrw+ this._scrollBarSize; var brw = obrw + this._scrollBarSize;
var brh = obrh + this._scrollBarSize; var brh = obrh + this._scrollBarSize;
var digest = function (el) { var digest = function (el) {
@ -304,10 +306,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
run(this.bottomLeftItems, o.items, leftItems); run(this.bottomLeftItems, o.items, leftItems);
run(this.bottomRightItems, o.items, rightItems); run(this.bottomRightItems, o.items, rightItems);
this.topLeftCollection.populate(leftHeader); this.topLeftCollection._populate(leftHeader);
this.topRightCollection.populate(rightHeader); this.topRightCollection._populate(rightHeader);
this.bottomLeftCollection.populate(leftItems); this.bottomLeftCollection._populate(leftItems);
this.bottomRightCollection.populate(rightItems); this.bottomRightCollection._populate(rightItems);
}, },
_digest: function () { _digest: function () {
@ -427,8 +429,10 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
return; return;
} }
if (this._isNeedDigest === true) { if (this._isNeedDigest === true) {
this._reRange();
this._digest(); this._digest();
} }
this._isNeedDigest = false;
this._populateTable(); this._populateTable();
this._populateScrollbar(); this._populateScrollbar();
}, },
@ -523,6 +527,13 @@ BI.CollectionTable = BI.inherit(BI.Widget, {
this.bottomRightCollection.restore(); this.bottomRightCollection.restore();
}, },
_reRange: function () {
this.topLeftCollection.reRange();
this.topRightCollection.reRange();
this.bottomLeftCollection.reRange();
this.bottomRightCollection.reRange();
},
restore: function () { restore: function () {
this._restore(); 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.attr("items", items);
this.contextLayout.resize(); this.contextLayout.resize();
this.topLeftGrid.populate(this.header[0]); this.topLeftGrid._populate(this.header[0]);
this.topRightGrid.populate(this.header[1]); this.topRightGrid._populate(this.header[1]);
this.bottomLeftGrid.populate(this.items[0]); this.bottomLeftGrid._populate(this.items[0]);
this.bottomRightGrid.populate(this.items[1]); this.bottomRightGrid._populate(this.items[1]);
}, },
_populate: function () { _populate: function () {
if (this._width <= 0 || this._height <= 0) { if (this._width <= 0 || this._height <= 0) {
return; return;
} }
if (this._isNeedDigest === true) {
this._reRange();
this._isNeedDigest = false;
}
this._populateTable(); this._populateTable();
this._populateScrollbar(); this._populateScrollbar();
}, },
@ -414,10 +418,12 @@ BI.GridTable = BI.inherit(BI.Widget, {
setColumnSize: function (columnSize) { setColumnSize: function (columnSize) {
this.options.columnSize = columnSize; this.options.columnSize = columnSize;
this._isNeedDigest = true;
}, },
setRegionColumnSize: function (regionColumnSize) { setRegionColumnSize: function (regionColumnSize) {
this.options.regionColumnSize = regionColumnSize; this.options.regionColumnSize = regionColumnSize;
this._isNeedDigest = true;
}, },
getColumnSize: function () { getColumnSize: function () {
@ -430,11 +436,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
populate: function (items, header) { populate: function (items, header) {
if (items && this.options.items !== items) { if (items && this.options.items !== items) {
this._isNeedDigest = true;
this.options.items = items; this.options.items = items;
this.items = this._getItems(); this.items = this._getItems();
this._restore(); this._restore();
} }
if (header && this.options.header !== header) { if (header && this.options.header !== header) {
this._isNeedDigest = true;
this.options.header = header; this.options.header = header;
this.header = this._getHeader(); this.header = this._getHeader();
this._restore(); this._restore();
@ -449,6 +457,13 @@ BI.GridTable = BI.inherit(BI.Widget, {
this.bottomRightGrid.restore(); this.bottomRightGrid.restore();
}, },
_reRange: function () {
this.topLeftGrid.reRange();
this.topRightGrid.reRange();
this.bottomLeftGrid.reRange();
this.bottomRightGrid.reRange();
},
restore: function () { restore: function () {
this._restore(); this._restore();
} }

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

@ -219,8 +219,10 @@ BI.ResizableTable = BI.inherit(BI.Widget, {
}; };
var stop = function (j, size) { var stop = function (j, size) {
self.resizer.setVisible(false); self.resizer.setVisible(false);
o.columnSize[j] = size; var columnSize = o.columnSize.slice();
self.table.setColumnSize(o.columnSize); columnSize[j] = size;
o.columnSize = columnSize;
self.table.setColumnSize(columnSize);
self.table.populate(); self.table.populate();
self._populate(); self._populate();
self.fireEvent(BI.Table.EVENT_TABLE_AFTER_COLUMN_RESIZE); 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 = []; freezeCols = [];
} }
if (!BI.isNumber(columnSize[0])) { if (!BI.isNumber(columnSize[0])) {
columnSize = o.minColumnSize; columnSize = o.minColumnSize.slice();
} }
var summaryFreezeColumnSize = 0, summaryColumnSize = 0; var summaryFreezeColumnSize = 0, summaryColumnSize = 0;
BI.each(columnSize, function (i, size) { BI.each(columnSize, function (i, size) {

249
src/core/alias.js

@ -1,4 +1,7 @@
;(function () { ;(function () {
if (!window.BI) {
window.BI = {};
}
function isEmpty(value) { function isEmpty(value) {
// 判断是否为空值 // 判断是否为空值
var result = value === "" || value === null || value === undefined; var result = value === "" || value === null || value === undefined;
@ -59,124 +62,6 @@
return text; 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 { } else {
return left + '.' + right; return left + '.' + right;
} }
}; }
/** /**
* 处理小数点右边小数部分 * 处理小数点右边小数部分
* @param tright 右边内容 * @param tright 右边内容
@ -263,7 +149,7 @@
if (newnum.length > orilen) { if (newnum.length > orilen) {
newnum = newnum.substr(1); newnum = newnum.substr(1);
} else { } else {
newnum = BI.leftPad(newnum, orilen, '0'); newnum = String.leftPad(newnum, orilen, '0');
result.leftPlus = false; result.leftPlus = false;
} }
right = right.replace(/^[0-9]+/, newnum); right = right.replace(/^[0-9]+/, newnum);
@ -524,7 +410,7 @@
return o; return o;
})(jo); })(jo);
} };
BI.contentFormat = function (cv, fmt) { BI.contentFormat = function (cv, fmt) {
if (isEmpty(cv)) { if (isEmpty(cv)) {
@ -566,15 +452,122 @@
return text; 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) { // O(len(format))
result = ch + result; 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) { BI.object2Number = function (value) {

496
src/core/func/function.js

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

2
src/core/view.js

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

14
src/core/widget.js

@ -165,6 +165,7 @@ BI.Widget = BI.inherit(BI.OB, {
this._mountChildren && this._mountChildren(); this._mountChildren && this._mountChildren();
BI.each(this._children, function (i, widget) { BI.each(this._children, function (i, widget) {
!self.isEnabled() && widget._setEnable(false); !self.isEnabled() && widget._setEnable(false);
!self.isValid() && widget._setValid(false);
widget._mount && widget._mount(); widget._mount && widget._mount();
}); });
this.mounted && this.mounted(); 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) { setEnable: function (enable) {
this._setEnable(enable); this._setEnable(enable);
if (enable === true) { if (enable === true) {
@ -222,6 +235,7 @@ BI.Widget = BI.inherit(BI.OB, {
setValid: function (valid) { setValid: function (valid) {
this.options.invalid = !valid; this.options.invalid = !valid;
this._setValid(valid);
if (valid === true) { if (valid === true) {
this.element.removeClass("base-invalid invalid"); this.element.removeClass("base-invalid invalid");
} else if (valid === false) { } 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, { BI.MultiStringList = BI.inherit(BI.Widget, {
_defaultConfig: function () { _defaultConfig: function () {
@ -7,33 +7,30 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
baseCls: 'bi-multi-string-list', baseCls: 'bi-multi-string-list',
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
valueFormatter: BI.emptyFn, valueFormatter: BI.emptyFn,
height: 25 el: {}
}) })
}, },
_init: function () { _init: function () {
BI.MultiStringList.superclass._init.apply(this, arguments); BI.MultiStringList.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.storeValue = {};
var assertShowValue = function () { var assertShowValue = function () {
BI.isKey(self._startValue) && self.storeValue.value[self.storeValue.type === BI.Selection.All ? "remove" : "pushDistinct"](self._startValue); 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.adapter = BI.createWidget({
this.popup = BI.createWidget({
type: "bi.multi_select_loader", type: "bi.multi_select_loader",
cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom", cls: "popup-multi-string-list bi-border-left bi-border-right bi-border-bottom",
itemsCreator: o.itemsCreator, itemsCreator: o.itemsCreator,
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
onLoaded: o.onLoaded, // onLoaded: o.onLoaded,
el: { el: {
height: "" height: ""
} }
}); });
this.popup.on(BI.MultiSelectLoader.EVENT_CHANGE, function () { this.adapter.on(BI.MultiSelectLoader.EVENT_CHANGE, function () {
self.storeValue = this.getValue(); self.storeValue = this.getValue();
self._adjust(function () { self._adjust(function () {
assertShowValue(); assertShowValue();
@ -41,90 +38,105 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
}); });
}); });
this.trigger = BI.createWidget({ this.searcherPane = BI.createWidget({
type: "bi.multi_select_trigger", type: "bi.multi_select_search_pane",
height: o.height, cls: "bi-border-left bi-border-right bi-border-bottom",
adapter: this.popup,
masker: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
valueFormatter: o.valueFormatter, valueFormatter: o.valueFormatter,
keywordGetter: function () {
return self.trigger.getKeyword();
},
itemsCreator: function (op, callback) { itemsCreator: function (op, callback) {
o.itemsCreator(op, function (res) { op.keyword = self.trigger.getKeyword();
if (op.times === 1 && BI.isNotNull(op.keyword)) { this.setKeyword(op.keyword);
self.trigger.setValue(self.getValue()); o.itemsCreator(op, callback);
}
callback.apply(self, arguments);
});
} }
}); });
this.searcherPane.setVisible(false);
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { this.trigger = BI.createWidget({
self._setStartValue(""); type: "bi.searcher",
this.getSearcher().setValue(self.storeValue); isAutoSearch: false,
}); isAutoSync: false,
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { onSearch: function (op, callback) {
self._setStartValue(""); callback();
}); },
this.trigger.on(BI.MultiSelectTrigger.EVENT_PAUSE, function () { adapter: this.adapter,
if (this.getSearcher().hasMatched()) { popup: this.searcherPane,
var keyword = this.getSearcher().getKeyword(); height: 200,
self._join({ masker: false,
type: BI.Selection.Multi, listeners: [{
value: [keyword] eventName: BI.Searcher.EVENT_START,
}, function () { action: function () {
self.trigger.setValue(self.storeValue); self._showSearcherPane();
self.popup.setValue(self.storeValue);
self._setStartValue(keyword);
assertShowValue();
self.populate();
self._setStartValue(""); self._setStartValue("");
self.fireEvent(BI.MultiStringList.EVENT_CHANGE); this.setValue(self.storeValue);
}) }
} }, {
}); eventName: BI.Searcher.EVENT_STOP,
this.trigger.on(BI.MultiSelectTrigger.EVENT_SEARCHING, function (keywords) { action: function () {
var last = BI.last(keywords); self._showAdapter();
keywords = BI.initial(keywords || []); self._setStartValue("");
if (keywords.length > 0) { self.adapter.setValue(self.storeValue);
self._joinKeywords(keywords, function () { }
if (BI.isEndWithBlank(last)) { }, {
self.trigger.setValue(self.storeValue); eventName: BI.Searcher.EVENT_PAUSE,
self.popup.setValue(self.storeValue); action: function () {
assertShowValue(); if (this.hasMatched()) {
self.popup.populate(); var keyword = this.getKeyword();
self._setStartValue(""); 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 { } else {
self.trigger.setValue(self.storeValue); self._showAdapter();
self.popup.setValue(self.storeValue);
assertShowValue();
} }
}); }
} }, {
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({ BI.createWidget({
type: "bi.vtape", type: "bi.vtape",
element: this, element: this,
@ -132,16 +144,37 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
width: "100%", width: "100%",
items: [{ items: [{
el: this.trigger, el: this.trigger,
height: 25 height: 30
}, {
el: div,
height: 2
}, { }, {
el: this.popup, el: this.adapter,
height: "fill" 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 () { _defaultState: function () {
this.trigger.stopEditing(); this.trigger.stopEditing();
}, },
@ -186,7 +219,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
this._assertValue(res); this._assertValue(res);
o.itemsCreator({ o.itemsCreator({
type: BI.MultiStringList.REQ_GET_ALL_DATA, type: BI.MultiStringList.REQ_GET_ALL_DATA,
keyword: this.trigger.getKey() keyword: self.trigger.getKeyword()
}, function (ob) { }, function (ob) {
var items = BI.pluck(ob.items, "value"); var items = BI.pluck(ob.items, "value");
if (self.storeValue.type === res.type) { if (self.storeValue.type === res.type) {
@ -275,22 +308,21 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
_setStartValue: function (value) { _setStartValue: function (value) {
this._startValue = value; this._startValue = value;
this.popup.setStartValue(value); this.adapter.setStartValue(value);
}, },
// isAllSelected: function () { isAllSelected: function () {
// return this.popup.isAllSelected(); return this.adapter.isAllSelected();
// }, },
resize: function () { resize: function () {
this.trigger.getCounter().adjustView(); // this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView(); // this.trigger.adjustView();
}, },
setValue: function (v) { setValue: function (v) {
this.storeValue = v || {}; this.storeValue = v || {};
this._assertValue(this.storeValue); this._assertValue(this.storeValue);
this.popup.setValue(this.storeValue); this.adapter.setValue(this.storeValue);
this.trigger.setValue(this.storeValue); this.trigger.setValue(this.storeValue);
}, },
@ -301,7 +333,7 @@ BI.MultiStringList = BI.inherit(BI.Widget, {
populate: function () { populate: function () {
this._count = null; this._count = null;
this._allData = 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); 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, { BI.MultiSelectTree = BI.inherit(BI.Widget, {
constants: {
offset: {
left: 1,
top: 0,
right: 2,
bottom: 1
}
},
_defaultConfig: function () { _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', baseCls: 'bi-multi-tree-combo',
itemsCreator: BI.emptyFn, itemsCreator: BI.emptyFn,
height: 25 height: 25
}); })
}, },
_init: function () { _init: function () {
BI.MultiTreeList.superclass._init.apply(this, arguments); BI.MultiSelectTree.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.storeValue = {value: {}};
var isInit = false; this.adapter = BI.createWidget({
var want2showCounter = false; type: "bi.multi_select_tree_popup",
this.popup = BI.createWidget({
type: "bi.multi_tree_list_popup",
itemsCreator: o.itemsCreator itemsCreator: o.itemsCreator
}); });
this.adapter.on(BI.MultiSelectTreePopup.EVENT_CHANGE, function () {
this.popup.on(BI.MultiStringListPopup.EVENT_AFTER_INIT, function () { if (self.trigger.isSearching()) {
self.trigger.getCounter().adjustView(); self.storeValue = {value: self.searcherPane.getValue()};
isInit = true; } else {
if (want2showCounter === true) { self.storeValue = {value: self.adapter.getValue()};
showCounter();
} }
self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
}); });
this.trigger = BI.createWidget({ this.searcherPane = BI.createWidget({//搜索中的时候用的是parttree,同adapter中的synctree不一样
type: "bi.multi_select_trigger", type: "bi.multi_tree_search_pane",
height: o.height, cls: "bi-border-left bi-border-right bi-border-bottom",
adapter: this.popup, keywordGetter: function () {
masker: { return self.trigger.getKeyword();
offset: this.constants.offset
}, },
searcher: { itemsCreator: function (op, callback) {
type: "bi.multi_tree_searcher", op.keyword = self.trigger.getKeyword();
itemsCreator: o.itemsCreator o.itemsCreator(op, callback);
},
switcher: {
el: {
type: "bi.multi_tree_check_selected_button"
},
popup: {
type: "bi.multi_tree_check_pane",
itemsCreator: o.itemsCreator
}
} }
}); });
this.searcherPane.setVisible(false);
this.storeValue = {value: {}}; this.trigger = BI.createWidget({
type: "bi.searcher",
var isSearching = function () { isAutoSearch: false,
return self.trigger.getSearcher().isSearching(); isAutoSync: false,
}; onSearch: function (op, callback) {
callback({
this.trigger.on(BI.MultiSelectTrigger.EVENT_START, function () { keyword: self.trigger.getKeyword()
self.storeValue = {value: self.popup.getValue()}; });
this.setValue(self.storeValue); },
}); adapter: this.adapter,
this.trigger.on(BI.MultiSelectTrigger.EVENT_STOP, function () { popup: this.searcherPane,
self.storeValue = {value: this.getValue()}; height: 200,
self.trigger.setValue(self.storeValue); masker: false,
self.popup.setValue(self.storeValue); listeners: [{
BI.nextTick(function () { eventName: BI.Searcher.EVENT_START,
self.trigger.populate(); action: function () {
self.popup.populate(); self._showSearcherPane();
}); self.storeValue = {value: self.adapter.getValue()};
}); self.searcherPane.setValue(self.storeValue);
function showCounter() { }
if (isSearching()) { }, {
self.storeValue = {value: self.trigger.getValue()}; eventName: BI.Searcher.EVENT_STOP,
} else { action: function () {
self.storeValue = {value: self.popup.getValue()}; self._showAdapter();
} // self.storeValue = {value: self.searcherPane.getValue()};
self.trigger.setValue(self.storeValue); self.adapter.setValue(self.storeValue);
} BI.nextTick(function () {
self.adapter.populate();
this.trigger.on(BI.MultiSelectTrigger.EVENT_BEFORE_COUNTER_POPUPVIEW, function () { });
if (want2showCounter === false) { }
want2showCounter = true; }, {
} eventName: BI.Searcher.EVENT_CHANGE,
if (isInit === true) { action: function () {
want2showCounter = null; if (self.trigger.isSearching()) {
showCounter(); self.storeValue = {value: self.searcherPane.getValue()};
} } else {
}); self.storeValue = {value: self.adapter.getValue()};
}
this.trigger.on(BI.MultiSelectTrigger.EVENT_CHANGE, function () { self.fireEvent(BI.MultiSelectTree.EVENT_CHANGE);
var val = { }
type: BI.Selection.Multi, }, {
value: this.getSearcher().hasChecked() ? {1: 1} : {} eventName: BI.Searcher.EVENT_PAUSE,
}; action: function () {
this.getSearcher().setState(val); self._showAdapter();
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);
}); });
var div = BI.createWidget({
type: "bi.layout"
});
BI.createWidget({ BI.createWidget({
type: "bi.vtape", type: "bi.vtape",
element: this, element: this,
@ -130,29 +96,45 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
width: "100%", width: "100%",
items: [{ items: [{
el: this.trigger, el: this.trigger,
height: 25 height: 30
}, { }, {
el: div, el: this.adapter,
height: 2
}, {
el: this.popup,
height: "fill" 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 () { _showAdapter: function () {
this.trigger.stopEditing(); this.adapter.setVisible(true);
this.searcherPane.setVisible(false);
},
_showSearcherPane: function () {
this.searcherPane.setVisible(true);
this.adapter.setVisible(false);
}, },
resize: function () { resize: function () {
this.trigger.getCounter().adjustView();
this.trigger.getSearcher().adjustView();
}, },
setValue: function (v) { setValue: function (v) {
this.storeValue.value = v || {}; this.storeValue.value = v || {};
this.popup.setValue({ this.adapter.setValue({
value: v || {} value: v || {}
}); });
this.trigger.setValue({ this.trigger.setValue({
@ -166,8 +148,8 @@ BI.MultiTreeList = BI.inherit(BI.Widget, {
populate: function () { populate: function () {
this.trigger.populate.apply(this.trigger, arguments); 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.MultiSelectTree.EVENT_CHANGE = "BI.MultiSelectTree.EVENT_CHANGE";
BI.shortcut('bi.multi_tree_list', BI.MultiTreeList); 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. * Created by zcf on 2016/12/21.
*/ */
BI.MultiStringListPopup=BI.inherit(BI.Widget,{ BI.MultiSelectTreePopup = BI.inherit(BI.Widget, {
_defaultConfig:function () { _defaultConfig: function () {
return BI.extend(BI.MultiStringListPopup.superclass._defaultConfig.apply(this, arguments), { return BI.extend(BI.MultiSelectTreePopup.superclass._defaultConfig.apply(this, arguments), {
baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom", baseCls: "bi-tree-list-popup bi-border-left bi-border-right bi-border-bottom",
itemsCreator: BI.emptyFn itemsCreator: BI.emptyFn
}); });
}, },
_init:function () { _init: function () {
BI.MultiStringListPopup.superclass._init.apply(this, arguments); BI.MultiSelectTreePopup.superclass._init.apply(this, arguments);
var self = this, o = this.options; var self = this, o = this.options;
this.popup = BI.createWidget({ this.popup = BI.createWidget({
type: "bi.sync_tree", type: "bi.sync_tree",
@ -18,10 +18,10 @@ BI.MultiStringListPopup=BI.inherit(BI.Widget,{
itemsCreator: o.itemsCreator itemsCreator: o.itemsCreator
}); });
this.popup.on(BI.TreeView.EVENT_AFTERINIT, function () { 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 () { 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.MultiSelectTreePopup.EVENT_AFTER_INIT = "BI.MultiSelectTreePopup.EVENT_AFTER_INIT";
BI.MultiStringListPopup.EVENT_CHANGE="BI.MultiStringListPopup.EVENT_CHANGE"; BI.MultiSelectTreePopup.EVENT_CHANGE = "BI.MultiSelectTreePopup.EVENT_CHANGE";
BI.shortcut("bi.multi_tree_list_popup",BI.MultiStringListPopup); BI.shortcut("bi.multi_select_tree_popup", BI.MultiSelectTreePopup);
Loading…
Cancel
Save