forked from fanruan/fineui
Browse Source
* commit '007613a6430f1059d46b5d1fa01dc0d95a920985': (27 commits) 复制到粘贴板IE8兼容 add 复制到粘贴板改用clipboard add add add class写错了 listview add floatOpened virtuallist add 精度 update _setValid add add add add update ...master
guy
8 years ago
69 changed files with 7328 additions and 3093 deletions
File diff suppressed because one or more lines are too long
@ -1,40 +0,0 @@
|
||||
Demo.TreeValueChooser = BI.inherit(BI.Widget, { |
||||
props: { |
||||
baseCls: "demo-tree-value-chooser" |
||||
}, |
||||
render: function () { |
||||
|
||||
var tree = []; |
||||
for (var i = 0; i < 21; i++) { |
||||
tree.push({ |
||||
value: "" + i + "", |
||||
text: "" + i + "", |
||||
id: i + "", |
||||
pId: null |
||||
}); |
||||
for (var j = 0; j < 9; j++) { |
||||
tree.push({ |
||||
value: i + "-" + j, |
||||
text: j + "", |
||||
id: i + "-" + j, |
||||
pId: i + "" |
||||
}) |
||||
} |
||||
} |
||||
var widget = BI.createWidget({ |
||||
type: "bi.tree_value_chooser_combo", |
||||
width: 300, |
||||
items: tree, |
||||
itemsCreator: function (op, callback) { |
||||
callback(tree); |
||||
} |
||||
}); |
||||
return { |
||||
type: "bi.vertical", |
||||
hgap: 200, |
||||
vgap: 10, |
||||
items: [widget] |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.tree_value_chooser", Demo.TreeValueChooser); |
@ -0,0 +1,23 @@
|
||||
Demo.TreeValueChooser = BI.inherit(BI.Widget, { |
||||
props: { |
||||
baseCls: "demo-tree-value-chooser-combo" |
||||
}, |
||||
render: function () { |
||||
|
||||
var widget = BI.createWidget({ |
||||
type: "bi.tree_value_chooser_combo", |
||||
width: 300, |
||||
// items: BI.deepClone(Demo.CONSTANTS.TREEITEMS),
|
||||
itemsCreator: function (op, callback) { |
||||
callback(BI.deepClone(Demo.CONSTANTS.TREEITEMS)); |
||||
} |
||||
}); |
||||
return { |
||||
type: "bi.vertical", |
||||
hgap: 200, |
||||
vgap: 10, |
||||
items: [widget] |
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.tree_value_chooser_combo", Demo.TreeValueChooser); |
@ -0,0 +1,16 @@
|
||||
Demo.TreeValueChooser = BI.inherit(BI.Widget, { |
||||
props: { |
||||
baseCls: "demo-tree-value-chooser" |
||||
}, |
||||
render: function () { |
||||
|
||||
return { |
||||
type: "bi.tree_value_chooser_pane", |
||||
items: BI.deepClone(Demo.CONSTANTS.TREEITEMS), |
||||
// itemsCreator: function (op, callback) {
|
||||
// callback(tree);
|
||||
// }
|
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.tree_value_chooser_pane", Demo.TreeValueChooser); |
@ -0,0 +1,15 @@
|
||||
Demo.ValueChooserPane = BI.inherit(BI.Widget, { |
||||
props: { |
||||
baseCls: "demo-value-chooser-pane" |
||||
}, |
||||
render: function () { |
||||
return { |
||||
type: "bi.value_chooser_pane", |
||||
items: BI.deepClone(Demo.CONSTANTS.ITEMS), |
||||
// itemsCreator: function (op, callback) {
|
||||
// callback(BI.deepClone(Demo.CONSTANTS.ITEMS));
|
||||
// }
|
||||
}; |
||||
} |
||||
}); |
||||
BI.shortcut("demo.value_chooser_pane", Demo.ValueChooserPane); |
@ -0,0 +1,22 @@
|
||||
Demo.Func = BI.inherit(BI.Widget, { |
||||
props: { |
||||
baseCls: "demo-func" |
||||
}, |
||||
render: function () { |
||||
return { |
||||
type: "bi.list_view", |
||||
el: { |
||||
type: "bi.left" |
||||
}, |
||||
items: BI.map(Demo.CONSTANTS.ITEMS, function (i, item) { |
||||
return BI.extend({}, item, { |
||||
type: "bi.label", |
||||
width: 200, |
||||
height: 200, |
||||
text: (i + 1) + "." + item.text, |
||||
}); |
||||
}) |
||||
} |
||||
} |
||||
}); |
||||
BI.shortcut("demo.list_view", Demo.Func); |
@ -0,0 +1,18 @@
|
||||
Demo.Func = BI.inherit(BI.Widget, { |
||||
props: { |
||||
baseCls: "demo-func" |
||||
}, |
||||
render: function () { |
||||
return { |
||||
type: "bi.virtual_list", |
||||
items: BI.map(Demo.CONSTANTS.ITEMS, function (i, item) { |
||||
return BI.extend({}, item, { |
||||
type: "bi.label", |
||||
height: 30, |
||||
text: (i + 1) + "." + item.text, |
||||
}); |
||||
}) |
||||
} |
||||
} |
||||
}); |
||||
BI.shortcut("demo.virtual_list", Demo.Func); |
File diff suppressed because one or more lines are too long
@ -0,0 +1,110 @@
|
||||
/** |
||||
* 表示当前对象 |
||||
* |
||||
* Created by GUY on 2017/5/23. |
||||
* @class BI.ListView |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.ListView = BI.inherit(BI.Widget, { |
||||
props: function () { |
||||
return { |
||||
baseCls: "bi-list-view", |
||||
overscanHeight: 100, |
||||
blockSize: 10, |
||||
scrollTop: 0, |
||||
el: {}, |
||||
items: [] |
||||
}; |
||||
}, |
||||
|
||||
init: function () { |
||||
var self = this; |
||||
this.renderedIndex = -1; |
||||
this.cache = {}; |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this, o = this.options; |
||||
return { |
||||
type: "bi.vertical", |
||||
items: [BI.extend({ |
||||
type: "bi.vertical", |
||||
scrolly: false, |
||||
ref: function () { |
||||
self.container = this; |
||||
} |
||||
}, o.el)], |
||||
element: this |
||||
} |
||||
}, |
||||
|
||||
mounted: function () { |
||||
var self = this, o = this.options; |
||||
this._populate(); |
||||
this.element.scroll(function (e) { |
||||
o.scrollTop = self.element.scrollTop(); |
||||
self._calculateBlocksToRender(); |
||||
}); |
||||
BI.ResizeDetector.addResizeListener(this, function () { |
||||
self._calculateBlocksToRender(); |
||||
}); |
||||
}, |
||||
|
||||
_renderMoreIf: function () { |
||||
var self = this, o = this.options; |
||||
var height = this.element.height(); |
||||
var minContentHeight = o.scrollTop + height + o.overscanHeight; |
||||
var index = (this.cache[this.renderedIndex] && (this.cache[this.renderedIndex].index + o.blockSize)) || 0, |
||||
cnt = this.renderedIndex + 1; |
||||
var lastHeight; |
||||
var getElementHeight = function () { |
||||
return self.container.element.height(); |
||||
}; |
||||
while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) { |
||||
var items = o.items.slice(index, index + o.blockSize); |
||||
this.container.addItems(items); |
||||
var addedHeight = getElementHeight() - lastHeight; |
||||
this.cache[cnt] = { |
||||
index: index, |
||||
scrollTop: lastHeight, |
||||
height: addedHeight |
||||
}; |
||||
this.renderedIndex = cnt; |
||||
cnt++; |
||||
index += o.blockSize; |
||||
} |
||||
}, |
||||
|
||||
_calculateBlocksToRender: function () { |
||||
var o = this.options; |
||||
this._renderMoreIf(); |
||||
}, |
||||
|
||||
_populate: function (items) { |
||||
var o = this.options; |
||||
if (items && this.options.items !== items) { |
||||
this.options.items = items; |
||||
} |
||||
this._calculateBlocksToRender(); |
||||
this.element.scrollTop(o.scrollTop); |
||||
}, |
||||
|
||||
restore: function () { |
||||
this.renderedIndex = -1; |
||||
this.container.empty(); |
||||
this.cache = {}; |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
if (items && this.options.items !== items) { |
||||
this.restore(); |
||||
} |
||||
this._populate(); |
||||
}, |
||||
|
||||
destroyed: function () { |
||||
this.restore(); |
||||
} |
||||
}); |
||||
BI.shortcut('bi.list_view', BI.ListView); |
||||
|
@ -0,0 +1,179 @@
|
||||
/** |
||||
* 表示当前对象 |
||||
* |
||||
* Created by GUY on 2017/5/22. |
||||
* @class BI.VirtualList |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.VirtualList = BI.inherit(BI.Widget, { |
||||
props: function () { |
||||
return { |
||||
baseCls: "bi-virtual-list", |
||||
overscanHeight: 100, |
||||
blockSize: 10, |
||||
scrollTop: 0, |
||||
items: [] |
||||
}; |
||||
}, |
||||
|
||||
init: function () { |
||||
var self = this; |
||||
this.renderedIndex = -1; |
||||
this.cache = {}; |
||||
}, |
||||
|
||||
render: function () { |
||||
var self = this, o = this.options; |
||||
return { |
||||
type: "bi.vertical", |
||||
items: [{ |
||||
type: "bi.layout", |
||||
ref: function () { |
||||
self.topBlank = this; |
||||
} |
||||
}, { |
||||
type: "bi.vertical", |
||||
scrolly: false, |
||||
ref: function () { |
||||
self.container = this; |
||||
} |
||||
}, { |
||||
type: "bi.layout", |
||||
ref: function () { |
||||
self.bottomBlank = this; |
||||
} |
||||
}], |
||||
element: this |
||||
} |
||||
}, |
||||
|
||||
mounted: function () { |
||||
var self = this, o = this.options; |
||||
this._populate(); |
||||
this.element.scroll(function (e) { |
||||
o.scrollTop = self.element.scrollTop(); |
||||
self._calculateBlocksToRender(); |
||||
}); |
||||
BI.ResizeDetector.addResizeListener(this, function () { |
||||
self._calculateBlocksToRender(); |
||||
}); |
||||
}, |
||||
|
||||
_renderMoreIf: function () { |
||||
var self = this, o = this.options; |
||||
var height = this.element.height(); |
||||
var minContentHeight = o.scrollTop + height + o.overscanHeight; |
||||
var index = (this.cache[this.renderedIndex] && (this.cache[this.renderedIndex].index + o.blockSize)) || 0, |
||||
cnt = this.renderedIndex + 1; |
||||
var lastHeight; |
||||
var getElementHeight = function () { |
||||
return self.container.element.height() + self.topBlank.element.height() + self.bottomBlank.element.height(); |
||||
}; |
||||
while ((lastHeight = getElementHeight()) < minContentHeight && index < o.items.length) { |
||||
var items = o.items.slice(index, index + o.blockSize); |
||||
this.container.addItems(items); |
||||
var addedHeight = getElementHeight() - lastHeight; |
||||
this.cache[cnt] = { |
||||
index: index, |
||||
scrollTop: lastHeight, |
||||
height: addedHeight |
||||
}; |
||||
this.tree.set(cnt, addedHeight); |
||||
this.renderedIndex = cnt; |
||||
cnt++; |
||||
index += o.blockSize; |
||||
} |
||||
}, |
||||
|
||||
_calculateBlocksToRender: function () { |
||||
var o = this.options; |
||||
this._renderMoreIf(); |
||||
var height = this.element.height(); |
||||
var minContentHeightFrom = o.scrollTop - o.overscanHeight; |
||||
var minContentHeightTo = o.scrollTop + height + o.overscanHeight; |
||||
var start = this.tree.greatestLowerBound(minContentHeightFrom); |
||||
var end = this.tree.leastUpperBound(minContentHeightTo); |
||||
var needDestroyed = []; |
||||
for (var i = 0; i < start; i++) { |
||||
var index = this.cache[i].index; |
||||
if (!this.cache[i].destroyed) { |
||||
for (var j = index; j < index + o.blockSize && j < o.items.length; j++) { |
||||
needDestroyed.push(this.container._children[j]); |
||||
this.container._children[j] = null; |
||||
} |
||||
this.cache[i].destroyed = true; |
||||
} |
||||
} |
||||
for (var i = end + 1; i <= this.renderedIndex; i++) { |
||||
var index = this.cache[i].index; |
||||
if (!this.cache[i].destroyed) { |
||||
for (var j = index; j < index + o.blockSize && j < o.items.length; j++) { |
||||
needDestroyed.push(this.container._children[j]); |
||||
this.container._children[j] = null; |
||||
} |
||||
this.cache[i].destroyed = true; |
||||
} |
||||
} |
||||
var firstFragment = document.createDocumentFragment(), lastFragment = document.createDocumentFragment(); |
||||
var currentFragment = firstFragment; |
||||
for (var i = (start < 0 ? 0 : start); i <= end && i <= this.renderedIndex; i++) { |
||||
var index = this.cache[i].index; |
||||
if (!this.cache[i].destroyed) { |
||||
currentFragment = lastFragment; |
||||
} |
||||
if (this.cache[i].destroyed === true) { |
||||
for (var j = index; j < index + o.blockSize && j < o.items.length; j++) { |
||||
var w = this.container._addElement(j, BI.extend({root: true}, BI.stripEL(o.items[j]))); |
||||
currentFragment.appendChild(w.element[0]); |
||||
} |
||||
this.cache[i].destroyed = false; |
||||
} |
||||
} |
||||
this.container.element.prepend(firstFragment); |
||||
this.container.element.append(lastFragment); |
||||
this.topBlank.setHeight(this.cache[start < 0 ? 0 : start].scrollTop); |
||||
var lastCache = this.cache[Math.min(end, this.renderedIndex)]; |
||||
this.bottomBlank.setHeight(this.tree.sumTo(this.renderedIndex) - lastCache.scrollTop - lastCache.height); |
||||
BI.each(needDestroyed, function (i, child) { |
||||
child && child._destroy(); |
||||
}); |
||||
}, |
||||
|
||||
_populate: function (items) { |
||||
var o = this.options; |
||||
if (items && this.options.items !== items) { |
||||
this.options.items = items; |
||||
} |
||||
this.tree = BI.PrefixIntervalTree.empty(Math.ceil(o.items.length / o.blockSize)); |
||||
this._calculateBlocksToRender(); |
||||
this.element.scrollTop(o.scrollTop); |
||||
}, |
||||
|
||||
_clearChildren: function () { |
||||
BI.each(this.container._children, function (i, cell) { |
||||
cell && cell.el._destroy(); |
||||
}); |
||||
this.container._children = {}; |
||||
this.container.attr("items", []); |
||||
}, |
||||
|
||||
restore: function () { |
||||
this.renderedIndex = -1; |
||||
this._clearChildren(); |
||||
this.cache = {}; |
||||
this.options.scrollTop = 0; |
||||
}, |
||||
|
||||
populate: function (items) { |
||||
if (items && this.options.items !== items) { |
||||
this.restore(); |
||||
} |
||||
this._populate(); |
||||
}, |
||||
|
||||
destroyed: function () { |
||||
this.restore(); |
||||
} |
||||
}); |
||||
BI.shortcut('bi.virtual_list', BI.VirtualList); |
||||
|
File diff suppressed because it is too large
Load Diff
@ -0,0 +1,46 @@
|
||||
/** |
||||
* 复制 |
||||
* Created by GUY on 2016/2/16. |
||||
* @class BI.ClipBoard |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.ClipBoard = BI.inherit(BI.BasicButton, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.ClipBoard.superclass._defaultConfig.apply(this, arguments), { |
||||
extraCls: "bi-clipboard", |
||||
copy: BI.emptyFn, |
||||
afterCopy: BI.emptyFn |
||||
}) |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.ClipBoard.superclass._init.apply(this, arguments); |
||||
}, |
||||
|
||||
mounted: function () { |
||||
var self = this, o = this.options; |
||||
if (window.Clipboard) { |
||||
this.clipboard = new Clipboard(this.element[0], { |
||||
text: function () { |
||||
return BI.isFunction(o.copy) ? o.copy() : o.copy; |
||||
} |
||||
}); |
||||
this.clipboard.on("success", function (e) { |
||||
o.afterCopy(); |
||||
}) |
||||
} else { |
||||
this.element.zclip({ |
||||
path: BI.resourceURL + "/ZeroClipboard.swf", |
||||
copy: o.copy, |
||||
beforeCopy: o.beforeCopy, |
||||
afterCopy: o.afterCopy |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
destroyed: function () { |
||||
this.clipboard && this.clipboard.destroy(); |
||||
} |
||||
}); |
||||
|
||||
BI.shortcut("bi.clipboard", BI.ClipBoard); |
@ -1,495 +0,0 @@
|
||||
/* |
||||
* zClip :: jQuery ZeroClipboard v1.1.1 |
||||
* http://steamdev.com/zclip
|
||||
* |
||||
* Copyright 2011, SteamDev |
||||
* Released under the MIT license. |
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
* |
||||
* Date: Wed Jun 01, 2011 |
||||
*/ |
||||
|
||||
|
||||
(function ($) { |
||||
|
||||
$.fn.zclip = function (params) { |
||||
|
||||
if (typeof params == "object" && !params.length) { |
||||
|
||||
var settings = $.extend({ |
||||
|
||||
path: 'ZeroClipboard.swf', |
||||
copy: null, |
||||
beforeCopy: null, |
||||
afterCopy: null, |
||||
clickAfter: true, |
||||
setHandCursor: true, |
||||
setCSSEffects: true |
||||
|
||||
}, params); |
||||
|
||||
|
||||
return this.each(function () { |
||||
|
||||
var o = $(this); |
||||
|
||||
if (o.is(':visible') && (typeof settings.copy == 'string' || $.isFunction(settings.copy))) { |
||||
|
||||
ZeroClipboard.setMoviePath(settings.path); |
||||
var clip = new ZeroClipboard.Client(); |
||||
|
||||
if($.isFunction(settings.copy)){ |
||||
o.bind('zClip_copy',settings.copy); |
||||
} |
||||
if($.isFunction(settings.beforeCopy)){ |
||||
o.bind('zClip_beforeCopy',settings.beforeCopy); |
||||
} |
||||
if($.isFunction(settings.afterCopy)){ |
||||
o.bind('zClip_afterCopy',settings.afterCopy); |
||||
}
|
||||
|
||||
clip.setHandCursor(settings.setHandCursor); |
||||
clip.setCSSEffects(settings.setCSSEffects); |
||||
clip.addEventListener('mouseOver', function (client) { |
||||
o.trigger('mouseenter'); |
||||
}); |
||||
clip.addEventListener('mouseOut', function (client) { |
||||
o.trigger('mouseleave'); |
||||
}); |
||||
clip.addEventListener('mouseDown', function (client) { |
||||
|
||||
o.trigger('mousedown'); |
||||
|
||||
if(!$.isFunction(settings.copy)){ |
||||
clip.setText(settings.copy); |
||||
} else { |
||||
clip.setText(o.triggerHandler('zClip_copy')); |
||||
}
|
||||
|
||||
if ($.isFunction(settings.beforeCopy)) { |
||||
o.trigger('zClip_beforeCopy');
|
||||
} |
||||
|
||||
}); |
||||
|
||||
clip.addEventListener('complete', function (client, text) { |
||||
|
||||
if ($.isFunction(settings.afterCopy)) { |
||||
|
||||
o.trigger('zClip_afterCopy'); |
||||
|
||||
} else { |
||||
if (text.length > 500) { |
||||
text = text.substr(0, 500) + "...\n\n(" + (text.length - 500) + " characters not shown)"; |
||||
} |
||||
|
||||
o.removeClass('hover'); |
||||
alert("Copied text to clipboard:\n\n " + text); |
||||
} |
||||
|
||||
if (settings.clickAfter) { |
||||
o.trigger('click'); |
||||
} |
||||
|
||||
}); |
||||
|
||||
|
||||
clip.glue(o[0], o.parent()[0]); |
||||
|
||||
$(window).bind('load resize',function(){clip.reposition();}); |
||||
|
||||
|
||||
} |
||||
|
||||
}); |
||||
|
||||
} else if (typeof params == "string") { |
||||
|
||||
return this.each(function () { |
||||
|
||||
var o = $(this); |
||||
|
||||
params = params.toLowerCase(); |
||||
var zclipId = o.data('zclipId'); |
||||
var clipElm = $('#' + zclipId + '.zclip'); |
||||
|
||||
if (params == "remove") { |
||||
|
||||
clipElm.remove(); |
||||
o.removeClass('active hover'); |
||||
|
||||
} else if (params == "hide") { |
||||
|
||||
clipElm.hide(); |
||||
o.removeClass('active hover'); |
||||
|
||||
} else if (params == "show") { |
||||
|
||||
clipElm.show(); |
||||
|
||||
} |
||||
|
||||
}); |
||||
|
||||
} |
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
})(jQuery); |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
// ZeroClipboard
|
||||
// Simple Set Clipboard System
|
||||
// Author: Joseph Huckaby
|
||||
var ZeroClipboard = { |
||||
|
||||
version: "1.0.7", |
||||
clients: {}, |
||||
// registered upload clients on page, indexed by id
|
||||
moviePath: 'ZeroClipboard.swf', |
||||
// URL to movie
|
||||
nextId: 1, |
||||
// ID of next movie
|
||||
$: function (thingy) { |
||||
// simple DOM lookup utility function
|
||||
if (typeof(thingy) == 'string') thingy = document.getElementById(thingy); |
||||
if (!thingy.addClass) { |
||||
// extend element with a few useful methods
|
||||
thingy.hide = function () { |
||||
this.style.display = 'none'; |
||||
}; |
||||
thingy.show = function () { |
||||
this.style.display = ''; |
||||
}; |
||||
thingy.addClass = function (name) { |
||||
this.removeClass(name); |
||||
this.className += ' ' + name; |
||||
}; |
||||
thingy.removeClass = function (name) { |
||||
var classes = this.className.split(/\s+/); |
||||
var idx = -1; |
||||
for (var k = 0; k < classes.length; k++) { |
||||
if (classes[k] == name) { |
||||
idx = k; |
||||
k = classes.length; |
||||
} |
||||
} |
||||
if (idx > -1) { |
||||
classes.splice(idx, 1); |
||||
this.className = classes.join(' '); |
||||
} |
||||
return this; |
||||
}; |
||||
thingy.hasClass = function (name) { |
||||
return !!this.className.match(new RegExp("\\s*" + name + "\\s*")); |
||||
}; |
||||
} |
||||
return thingy; |
||||
}, |
||||
|
||||
setMoviePath: function (path) { |
||||
// set path to ZeroClipboard.swf
|
||||
this.moviePath = path; |
||||
}, |
||||
|
||||
dispatch: function (id, eventName, args) { |
||||
// receive event from flash movie, send to client
|
||||
var client = this.clients[id]; |
||||
if (client) { |
||||
client.receiveEvent(eventName, args); |
||||
} |
||||
}, |
||||
|
||||
register: function (id, client) { |
||||
// register new client to receive events
|
||||
this.clients[id] = client; |
||||
}, |
||||
|
||||
getDOMObjectPosition: function (obj, stopObj) { |
||||
// get absolute coordinates for dom element
|
||||
var info = { |
||||
left: 0, |
||||
top: 0, |
||||
width: obj.width ? obj.width : obj.offsetWidth, |
||||
height: obj.height ? obj.height : obj.offsetHeight |
||||
}; |
||||
|
||||
if (obj && (obj != stopObj)) { |
||||
info.left += obj.offsetLeft; |
||||
info.top += obj.offsetTop; |
||||
} |
||||
|
||||
return info; |
||||
}, |
||||
|
||||
Client: function (elem) { |
||||
// constructor for new simple upload client
|
||||
this.handlers = {}; |
||||
|
||||
// unique ID
|
||||
this.id = ZeroClipboard.nextId++; |
||||
this.movieId = 'ZeroClipboardMovie_' + this.id; |
||||
|
||||
// register client with singleton to receive flash events
|
||||
ZeroClipboard.register(this.id, this); |
||||
|
||||
// create movie
|
||||
if (elem) this.glue(elem); |
||||
} |
||||
}; |
||||
|
||||
ZeroClipboard.Client.prototype = { |
||||
|
||||
id: 0, |
||||
// unique ID for us
|
||||
ready: false, |
||||
// whether movie is ready to receive events or not
|
||||
movie: null, |
||||
// reference to movie object
|
||||
clipText: '', |
||||
// text to copy to clipboard
|
||||
handCursorEnabled: true, |
||||
// whether to show hand cursor, or default pointer cursor
|
||||
cssEffects: true, |
||||
// enable CSS mouse effects on dom container
|
||||
handlers: null, |
||||
// user event handlers
|
||||
glue: function (elem, appendElem, stylesToAdd) { |
||||
// glue to DOM element
|
||||
// elem can be ID or actual DOM element object
|
||||
this.domElement = ZeroClipboard.$(elem); |
||||
|
||||
// float just above object, or zIndex 99 if dom element isn't set
|
||||
var zIndex = 99; |
||||
if (this.domElement.style.zIndex) { |
||||
zIndex = parseInt(this.domElement.style.zIndex, 10) + 1; |
||||
} |
||||
|
||||
if (typeof(appendElem) == 'string') { |
||||
appendElem = ZeroClipboard.$(appendElem); |
||||
} else if (typeof(appendElem) == 'undefined') { |
||||
appendElem = document.getElementsByTagName('body')[0]; |
||||
} |
||||
|
||||
// find X/Y position of domElement
|
||||
var box = ZeroClipboard.getDOMObjectPosition(this.domElement, appendElem); |
||||
|
||||
// create floating DIV above element
|
||||
this.div = document.createElement('div'); |
||||
this.div.className = "zclip"; |
||||
this.div.id = "zclip-" + this.movieId; |
||||
$(this.domElement).data('zclipId', 'zclip-' + this.movieId); |
||||
var style = this.div.style; |
||||
style.position = 'absolute'; |
||||
style.left = '' + box.left + 'px'; |
||||
style.top = '' + box.top + 'px'; |
||||
style.width = '' + box.width + 'px'; |
||||
style.height = '' + box.height + 'px'; |
||||
style.zIndex = zIndex; |
||||
|
||||
if (typeof(stylesToAdd) == 'object') { |
||||
for (addedStyle in stylesToAdd) { |
||||
style[addedStyle] = stylesToAdd[addedStyle]; |
||||
} |
||||
} |
||||
|
||||
// style.backgroundColor = '#f00'; // debug
|
||||
appendElem.appendChild(this.div); |
||||
|
||||
this.div.innerHTML = this.getHTML(box.width, box.height); |
||||
}, |
||||
|
||||
getHTML: function (width, height) { |
||||
// return HTML for movie
|
||||
var html = ''; |
||||
var flashvars = 'id=' + this.id + '&width=' + width + '&height=' + height; |
||||
|
||||
if (navigator.userAgent.match(/MSIE/)) { |
||||
// IE gets an OBJECT tag
|
||||
var protocol = location.href.match(/^https/i) ? 'https://' : 'http://'; |
||||
html += '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="' + protocol + 'download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,0,0" width="' + width + '" height="' + height + '" id="' + this.movieId + '" align="middle"><param name="allowScriptAccess" value="always" /><param name="allowFullScreen" value="false" /><param name="movie" value="' + ZeroClipboard.moviePath + '" /><param name="loop" value="false" /><param name="menu" value="false" /><param name="quality" value="best" /><param name="bgcolor" value="#ffffff" /><param name="flashvars" value="' + flashvars + '"/><param name="wmode" value="transparent"/></object>'; |
||||
} else { |
||||
// all other browsers get an EMBED tag
|
||||
html += '<embed id="' + this.movieId + '" src="' + ZeroClipboard.moviePath + '" loop="false" menu="false" quality="best" bgcolor="#ffffff" width="' + width + '" height="' + height + '" name="' + this.movieId + '" align="middle" allowScriptAccess="always" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" flashvars="' + flashvars + '" wmode="transparent" />'; |
||||
} |
||||
return html; |
||||
}, |
||||
|
||||
hide: function () { |
||||
// temporarily hide floater offscreen
|
||||
if (this.div) { |
||||
this.div.style.left = '-2000px'; |
||||
} |
||||
}, |
||||
|
||||
show: function () { |
||||
// show ourselves after a call to hide()
|
||||
this.reposition(); |
||||
}, |
||||
|
||||
destroy: function () { |
||||
// destroy control and floater
|
||||
if (this.domElement && this.div) { |
||||
this.hide(); |
||||
this.div.innerHTML = ''; |
||||
|
||||
var body = document.getElementsByTagName('body')[0]; |
||||
try { |
||||
body.removeChild(this.div); |
||||
} catch (e) {; |
||||
} |
||||
|
||||
this.domElement = null; |
||||
this.div = null; |
||||
} |
||||
}, |
||||
|
||||
reposition: function (elem) { |
||||
// reposition our floating div, optionally to new container
|
||||
// warning: container CANNOT change size, only position
|
||||
if (elem) { |
||||
this.domElement = ZeroClipboard.$(elem); |
||||
if (!this.domElement) this.hide(); |
||||
} |
||||
|
||||
if (this.domElement && this.div) { |
||||
var box = ZeroClipboard.getDOMObjectPosition(this.domElement); |
||||
var style = this.div.style; |
||||
style.left = '' + box.left + 'px'; |
||||
style.top = '' + box.top + 'px'; |
||||
} |
||||
}, |
||||
|
||||
setText: function (newText) { |
||||
// set text to be copied to clipboard
|
||||
this.clipText = newText; |
||||
if (this.ready) { |
||||
this.movie.setText(newText); |
||||
} |
||||
}, |
||||
|
||||
addEventListener: function (eventName, func) { |
||||
// add user event listener for event
|
||||
// event types: load, queueStart, fileStart, fileComplete, queueComplete, progress, error, cancel
|
||||
eventName = eventName.toString().toLowerCase().replace(/^on/, ''); |
||||
if (!this.handlers[eventName]) { |
||||
this.handlers[eventName] = []; |
||||
} |
||||
this.handlers[eventName].push(func); |
||||
}, |
||||
|
||||
setHandCursor: function (enabled) { |
||||
// enable hand cursor (true), or default arrow cursor (false)
|
||||
this.handCursorEnabled = enabled; |
||||
if (this.ready) { |
||||
this.movie.setHandCursor(enabled); |
||||
} |
||||
}, |
||||
|
||||
setCSSEffects: function (enabled) { |
||||
// enable or disable CSS effects on DOM container
|
||||
this.cssEffects = !! enabled; |
||||
}, |
||||
|
||||
receiveEvent: function (eventName, args) { |
||||
// receive event from flash
|
||||
eventName = eventName.toString().toLowerCase().replace(/^on/, ''); |
||||
|
||||
// special behavior for certain events
|
||||
switch (eventName) { |
||||
case 'load': |
||||
// movie claims it is ready, but in IE this isn't always the case...
|
||||
// bug fix: Cannot extend EMBED DOM elements in Firefox, must use traditional function
|
||||
this.movie = document.getElementById(this.movieId); |
||||
if (!this.movie) { |
||||
var self = this; |
||||
setTimeout(function () { |
||||
self.receiveEvent('load', null); |
||||
}, 1); |
||||
return; |
||||
} |
||||
|
||||
// firefox on pc needs a "kick" in order to set these in certain cases
|
||||
if (!this.ready && navigator.userAgent.match(/Firefox/) && navigator.userAgent.match(/Windows/)) { |
||||
var self = this; |
||||
setTimeout(function () { |
||||
self.receiveEvent('load', null); |
||||
}, 100); |
||||
this.ready = true; |
||||
return; |
||||
} |
||||
|
||||
this.ready = true; |
||||
try { |
||||
this.movie.setText(this.clipText); |
||||
} catch (e) {} |
||||
try { |
||||
this.movie.setHandCursor(this.handCursorEnabled); |
||||
} catch (e) {} |
||||
break; |
||||
|
||||
case 'mouseover': |
||||
if (this.domElement && this.cssEffects) { |
||||
this.domElement.addClass('hover'); |
||||
if (this.recoverActive) { |
||||
this.domElement.addClass('active'); |
||||
} |
||||
|
||||
|
||||
} |
||||
|
||||
|
||||
break; |
||||
|
||||
case 'mouseout': |
||||
if (this.domElement && this.cssEffects) { |
||||
this.recoverActive = false; |
||||
if (this.domElement.hasClass('active')) { |
||||
this.domElement.removeClass('active'); |
||||
this.recoverActive = true; |
||||
} |
||||
this.domElement.removeClass('hover'); |
||||
|
||||
} |
||||
break; |
||||
|
||||
case 'mousedown': |
||||
if (this.domElement && this.cssEffects) { |
||||
this.domElement.addClass('active'); |
||||
} |
||||
break; |
||||
|
||||
case 'mouseup': |
||||
if (this.domElement && this.cssEffects) { |
||||
this.domElement.removeClass('active'); |
||||
this.recoverActive = false; |
||||
} |
||||
break; |
||||
} // switch eventName
|
||||
if (this.handlers[eventName]) { |
||||
for (var idx = 0, len = this.handlers[eventName].length; idx < len; idx++) { |
||||
var func = this.handlers[eventName][idx]; |
||||
|
||||
if (typeof(func) == 'function') { |
||||
// actual function reference
|
||||
func(this, args); |
||||
} else if ((typeof(func) == 'object') && (func.length == 2)) { |
||||
// PHP style object + method, i.e. [myObject, 'myMethod']
|
||||
func[0][func[1]](this, args); |
||||
} else if (typeof(func) == 'string') { |
||||
// name of function
|
||||
window[func](this, args); |
||||
} |
||||
} // foreach event handler defined
|
||||
} // user defined handler for event
|
||||
} |
||||
|
||||
};
|
||||
|
@ -1,31 +0,0 @@
|
||||
/** |
||||
* 复制 |
||||
* Created by GUY on 2016/2/16. |
||||
* @class BI.ZeroClip |
||||
* @extends BI.BasicButton |
||||
*/ |
||||
BI.ZeroClip = BI.inherit(BI.BasicButton, { |
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.ZeroClip.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-zero-clip", |
||||
copy: BI.emptyFn, |
||||
beforeCopy: BI.emptyFn, |
||||
afterCopy: BI.emptyFn |
||||
}) |
||||
}, |
||||
_init: function () { |
||||
BI.ZeroClip.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
|
||||
BI.nextTick(function () { |
||||
self.element.zclip({ |
||||
path: BI.resourceURL + "/ZeroClipboard.swf", |
||||
copy: o.copy, |
||||
beforeCopy: o.beforeCopy, |
||||
afterCopy: o.afterCopy |
||||
}); |
||||
}); |
||||
} |
||||
}); |
||||
|
||||
BI.shortcut("bi.zero_clip", BI.ZeroClip); |
@ -0,0 +1,79 @@
|
||||
/** |
||||
* 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 |
||||
* 封装了字段处理逻辑 |
||||
* |
||||
* Created by GUY on 2015/10/29. |
||||
* @class BI.AbstractAllValueChooser |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.AbstractAllValueChooser = BI.inherit(BI.Widget, { |
||||
|
||||
_const: { |
||||
perPage: 100 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.AbstractAllValueChooser.superclass._defaultConfig.apply(this, arguments), { |
||||
width: 200, |
||||
height: 30, |
||||
items: null, |
||||
itemsCreator: BI.emptyFn, |
||||
cache: true |
||||
}); |
||||
}, |
||||
|
||||
_valueFormatter: function (v) { |
||||
var text = v; |
||||
if (BI.isNotNull(this.items)) { |
||||
BI.some(this.items, function (i, item) { |
||||
if (item.value === v) { |
||||
text = item.text; |
||||
return true; |
||||
} |
||||
}); |
||||
} |
||||
return text; |
||||
}, |
||||
|
||||
_itemsCreator: function (options, callback) { |
||||
var self = this, o = this.options; |
||||
if (!o.cache || !this.items) { |
||||
o.itemsCreator({}, function (items) { |
||||
self.items = items; |
||||
call(items); |
||||
}); |
||||
} else { |
||||
call(this.items); |
||||
} |
||||
function call(items) { |
||||
var keywords = (options.keywords || []).slice(); |
||||
if (options.keyword) { |
||||
keywords.push(options.keyword); |
||||
} |
||||
BI.each(keywords, function (i, kw) { |
||||
var search = BI.Func.getSearchResult(items, kw); |
||||
items = search.matched.concat(search.finded); |
||||
}); |
||||
if (options.selectedValues) {//过滤
|
||||
var filter = BI.makeObject(options.selectedValues, true); |
||||
items = BI.filter(items, function (i, ob) { |
||||
return !filter[ob.value]; |
||||
}); |
||||
} |
||||
if (options.type === BI.MultiSelectCombo.REQ_GET_ALL_DATA) { |
||||
callback({ |
||||
items: items |
||||
}); |
||||
return; |
||||
} |
||||
if (options.type === BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) { |
||||
callback({count: items.length}); |
||||
return; |
||||
} |
||||
callback({ |
||||
items: items, |
||||
hasNext: false |
||||
}); |
||||
} |
||||
} |
||||
}); |
@ -0,0 +1,62 @@
|
||||
/** |
||||
* 简单的复选下拉框控件, 适用于数据量少的情况, 与valuechooser的区别是allvaluechooser setValue和getValue返回的是所有值 |
||||
* 封装了字段处理逻辑 |
||||
* |
||||
* Created by GUY on 2015/10/29. |
||||
* @class BI.AllValueChooserPane |
||||
* @extends BI.AbstractAllValueChooser |
||||
*/ |
||||
BI.AllValueChooserPane = BI.inherit(BI.AbstractAllValueChooser, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.AllValueChooserPane.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-all-value-chooser-pane", |
||||
width: 200, |
||||
height: 30, |
||||
items: null, |
||||
itemsCreator: BI.emptyFn, |
||||
cache: true |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.AllValueChooserPane.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
if (BI.isNotNull(o.items)) { |
||||
this.items = o.items; |
||||
} |
||||
this.list = BI.createWidget({ |
||||
type: 'bi.multi_select_list', |
||||
element: this, |
||||
itemsCreator: BI.bind(this._itemsCreator, this), |
||||
valueFormatter: BI.bind(this._valueFormatter, this), |
||||
width: o.width, |
||||
height: o.height |
||||
}); |
||||
|
||||
this.list.on(BI.MultiSelectList.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.AllValueChooserPane.EVENT_CHANGE); |
||||
}); |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.list.setValue({ |
||||
type: BI.Selection.Multi, |
||||
value: v || [] |
||||
}); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
var val = this.list.getValue() || {}; |
||||
if (val.type === BI.Selection.All) { |
||||
return val.assist; |
||||
} |
||||
return val.value || []; |
||||
}, |
||||
|
||||
populate: function () { |
||||
this.list.populate.apply(this.list, arguments); |
||||
} |
||||
}); |
||||
BI.AllValueChooserPane.EVENT_CHANGE = "AllValueChooserPane.EVENT_CHANGE"; |
||||
BI.shortcut('bi.all_value_chooser_pane', BI.AllValueChooserPane); |
@ -0,0 +1,548 @@
|
||||
BI.AbstractTreeValueChooser = BI.inherit(BI.Widget, { |
||||
|
||||
_const: { |
||||
perPage: 100 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.AbstractTreeValueChooser.superclass._defaultConfig.apply(this, arguments), { |
||||
items: null, |
||||
itemsCreator: BI.emptyFn |
||||
}); |
||||
}, |
||||
|
||||
_initData: function (items) { |
||||
this.items = items; |
||||
var nodes = BI.Tree.treeFormat(items); |
||||
this.tree = new BI.Tree(); |
||||
this.tree.initTree(nodes); |
||||
}, |
||||
|
||||
_itemsCreator: function (options, callback) { |
||||
var self = this, o = this.options; |
||||
if (!this.items) { |
||||
o.itemsCreator({}, function (items) { |
||||
self._initData(items); |
||||
call(); |
||||
}); |
||||
} else { |
||||
call(); |
||||
} |
||||
function call() { |
||||
switch (options.type) { |
||||
case BI.TreeView.REQ_TYPE_INIT_DATA: |
||||
self._reqInitTreeNode(options, callback); |
||||
break; |
||||
case BI.TreeView.REQ_TYPE_ADJUST_DATA: |
||||
self._reqAdjustTreeNode(options, callback); |
||||
break; |
||||
case BI.TreeView.REQ_TYPE_SELECT_DATA: |
||||
self._reqSelectedTreeNode(options, callback); |
||||
break; |
||||
case BI.TreeView.REQ_TYPE_GET_SELECTED_DATA: |
||||
self._reqDisplayTreeNode(options, callback); |
||||
break; |
||||
default : |
||||
self._reqTreeNode(options, callback); |
||||
break; |
||||
} |
||||
} |
||||
}, |
||||
|
||||
_reqDisplayTreeNode: function (op, callback) { |
||||
var self = this; |
||||
var result = []; |
||||
var selectedValues = op.selectedValues; |
||||
|
||||
if (selectedValues == null || BI.isEmpty(selectedValues)) { |
||||
callback({}); |
||||
return; |
||||
} |
||||
|
||||
doCheck([], this.tree.getRoot(), selectedValues); |
||||
|
||||
callback({ |
||||
items: result |
||||
}); |
||||
|
||||
function doCheck(parentValues, node, selected) { |
||||
if (selected == null || BI.isEmpty(selected)) { |
||||
BI.each(node.getChildren(), function (i, child) { |
||||
var newParents = BI.clone(parentValues); |
||||
newParents.push(child.value); |
||||
var llen = self._getChildCount(newParents); |
||||
createOneJson(child, node.id, llen); |
||||
doCheck(newParents, child, {}); |
||||
}); |
||||
return; |
||||
} |
||||
BI.each(selected, function (k) { |
||||
var node = self._getNode(parentValues, k); |
||||
var newParents = BI.clone(parentValues); |
||||
newParents.push(node.value); |
||||
createOneJson(node, BI.last(parentValues), getCount(selected[k], newParents)); |
||||
doCheck(newParents, node, selected[k]); |
||||
}) |
||||
} |
||||
|
||||
function getCount(jo, parentValues) { |
||||
if (jo == null) { |
||||
return 0; |
||||
} |
||||
if (BI.isEmpty(jo)) { |
||||
return self._getChildCount(parentValues); |
||||
} |
||||
|
||||
return BI.size(jo); |
||||
} |
||||
|
||||
function createOneJson(node, pId, llen) { |
||||
result.push({ |
||||
id: node.id, |
||||
pId: pId, |
||||
text: node.text + (llen > 0 ? ("(" + BI.i18nText("BI-Basic_Altogether") + llen + BI.i18nText("BI-Basic_Count") + ")") : ""), |
||||
value: node.value, |
||||
open: true |
||||
}); |
||||
} |
||||
}, |
||||
|
||||
_reqSelectedTreeNode: function (op, callback) { |
||||
var self = this; |
||||
var selectedValues = op.selectedValues; |
||||
var notSelectedValue = op.notSelectedValue || {}; |
||||
var keyword = op.keyword || ""; |
||||
var parentValues = op.parentValues || []; |
||||
|
||||
if (selectedValues == null || BI.isEmpty(selectedValues)) { |
||||
callback({}); |
||||
return; |
||||
} |
||||
|
||||
dealWithSelectedValues(selectedValues); |
||||
callback(selectedValues); |
||||
|
||||
|
||||
function dealWithSelectedValues(selectedValues) { |
||||
var p = BI.clone(parentValues); |
||||
p.push(notSelectedValue); |
||||
|
||||
if (isChild(selectedValues, p)) { |
||||
var result = []; |
||||
var finded = search(parentValues.length + 1, parentValues, notSelectedValue, result); |
||||
|
||||
if (finded === true) { |
||||
var next = selectedValues; |
||||
BI.each(p, function (i, v) { |
||||
var t = next[v]; |
||||
if (t == null) { |
||||
if (BI.isEmpty(next)) { |
||||
var split = p.slice(0, i); |
||||
var expanded = self._getChildren(split); |
||||
BI.each(expanded, function (m, child) { |
||||
if (i === p.length - 1 && child.value === notSelectedValue) { |
||||
return true; |
||||
} |
||||
next[child.value] = {}; |
||||
}); |
||||
next = next[v]; |
||||
} else { |
||||
next = {}; |
||||
next[v] = {}; |
||||
} |
||||
} else { |
||||
next = t; |
||||
} |
||||
}); |
||||
|
||||
if (result.length > 0) { |
||||
BI.each(result, function (i, strs) { |
||||
self._buildTree(selectedValues, strs); |
||||
}) |
||||
} |
||||
} |
||||
} |
||||
|
||||
} |
||||
|
||||
function search(deep, parents, current, result) { |
||||
var newParents = BI.clone(parents); |
||||
newParents.push(current); |
||||
if (self._isMatch(current, keyword)) { |
||||
return true; |
||||
} |
||||
|
||||
var children = self._getChildren(newParents); |
||||
|
||||
var notSearch = []; |
||||
var can = false; |
||||
|
||||
BI.each(children, function (i, child) { |
||||
if (search(deep + 1, newParents, child.value, result)) { |
||||
can = true; |
||||
} else { |
||||
notSearch.push(child.value); |
||||
} |
||||
}); |
||||
if (can === true) { |
||||
BI.each(notSearch, function (i, v) { |
||||
var next = BI.clone(newParents); |
||||
next.push(v); |
||||
result.push(next); |
||||
}); |
||||
} |
||||
return can; |
||||
} |
||||
|
||||
function isChild(selectedValues, parents) { |
||||
var t = selectedValues; |
||||
for (var i = 0; i < parents.length; i++) { |
||||
var v = parents[i]; |
||||
if (!BI.has(t, v)) { |
||||
return false; |
||||
} |
||||
t = t[v]; |
||||
if (t == null || BI.isEmpty(t)) { |
||||
return true; |
||||
} |
||||
} |
||||
return true; |
||||
} |
||||
}, |
||||
|
||||
_reqAdjustTreeNode: function (op, callback) { |
||||
var self = this; |
||||
var result = []; |
||||
var selectedValues = op.selectedValues; |
||||
if (selectedValues == null || BI.isEmpty(selectedValues)) { |
||||
callback({}); |
||||
return; |
||||
} |
||||
BI.each(selectedValues, function (k, v) { |
||||
result.push([k]); |
||||
}); |
||||
|
||||
dealWithSelectedValues(selectedValues, []); |
||||
|
||||
var jo = {}; |
||||
BI.each(result, function (i, strs) { |
||||
self._buildTree(jo, strs); |
||||
}); |
||||
callback(jo); |
||||
|
||||
function dealWithSelectedValues(selected, parents) { |
||||
if (selected == null || BI.isEmpty(selected)) { |
||||
return true; |
||||
} |
||||
var can = true; |
||||
BI.each(selected, function (k, v) { |
||||
var p = BI.clone(parents); |
||||
p.push(k); |
||||
if (!dealWithSelectedValues(selected[k], p)) { |
||||
BI.each(selected[k], function (nk, nv) { |
||||
var t = BI.clone(p); |
||||
t.push(nk); |
||||
result.push(t); |
||||
}); |
||||
can = false; |
||||
} |
||||
}); |
||||
return can && isAllSelected(selected, parents); |
||||
} |
||||
|
||||
function isAllSelected(selected, parents) { |
||||
return BI.isEmpty(selected) || self._getChildCount(parents) === BI.size(selected); |
||||
} |
||||
}, |
||||
|
||||
_reqInitTreeNode: function (op, callback) { |
||||
var self = this; |
||||
var result = []; |
||||
var keyword = op.keyword || ""; |
||||
var selectedValues = op.selectedValues; |
||||
var lastSearchValue = op.lastSearchValue || ""; |
||||
var output = search(); |
||||
BI.nextTick(function () { |
||||
callback({ |
||||
hasNext: output.length > self._const.perPage, |
||||
items: result, |
||||
lastSearchValue: BI.last(output) |
||||
}) |
||||
}); |
||||
|
||||
function search() { |
||||
var children = self._getChildren([]); |
||||
var start = children.length; |
||||
if (lastSearchValue !== "") { |
||||
for (var j = 0, len = start; j < len; j++) { |
||||
if (children[j].value === lastSearchValue) { |
||||
start = j + 1; |
||||
break; |
||||
} |
||||
} |
||||
} else { |
||||
start = 0; |
||||
} |
||||
var output = []; |
||||
for (var i = start, len = children.length; i < len; i++) { |
||||
if (output.length < self._const.perPage) { |
||||
var find = nodeSearch(1, [], children[i].value, false, result); |
||||
} else if (output.length === self._const.perPage) { |
||||
var find = nodeSearch(1, [], children[i].value, false, []); |
||||
} |
||||
if (find[0] === true) { |
||||
output.push(children[i].value); |
||||
} |
||||
if (output.length > self._const.perPage) { |
||||
break; |
||||
} |
||||
} |
||||
return output; |
||||
} |
||||
|
||||
function nodeSearch(deep, parentValues, current, isAllSelect, result) { |
||||
if (self._isMatch(current, keyword)) { |
||||
var checked = isAllSelect || isSelected(parentValues, current); |
||||
createOneJson(parentValues, current, false, checked, !isAllSelect && isHalf(parentValues, current), true, result); |
||||
return [true, checked]; |
||||
} |
||||
var newParents = BI.clone(parentValues); |
||||
newParents.push(current); |
||||
var children = self._getChildren(newParents); |
||||
|
||||
var can = false, checked = false; |
||||
|
||||
var isCurAllSelected = isAllSelect || isAllSelected(parentValues, current); |
||||
BI.each(children, function (i, child) { |
||||
var state = nodeSearch(deep + 1, newParents, child.value, isCurAllSelected, result); |
||||
if (state[1] === true) { |
||||
checked = true; |
||||
} |
||||
if (state[0] === true) { |
||||
can = true; |
||||
} |
||||
}); |
||||
if (can === true) { |
||||
checked = isCurAllSelected || (isSelected(parentValues, current) && checked); |
||||
createOneJson(parentValues, current, true, checked, false, false, result); |
||||
} |
||||
return [can, checked]; |
||||
} |
||||
|
||||
function createOneJson(parentValues, value, isOpen, checked, half, flag, result) { |
||||
var node = self._getNode(parentValues, value) |
||||
result.push({ |
||||
id: node.id, |
||||
pId: node.pId, |
||||
text: node.text, |
||||
value: node.value, |
||||
title: node.title, |
||||
isParent: node.getChildrenLength() > 0, |
||||
open: isOpen, |
||||
checked: checked, |
||||
halfCheck: half, |
||||
flag: flag |
||||
}); |
||||
} |
||||
|
||||
function isHalf(parentValues, value) { |
||||
var find = findSelectedObj(parentValues); |
||||
if (find == null) { |
||||
return null; |
||||
} |
||||
return BI.any(find, function (v, ob) { |
||||
if (v === value) { |
||||
if (ob != null && !BI.isEmpty(ob)) { |
||||
return true; |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
function isAllSelected(parentValues, value) { |
||||
var find = findSelectedObj(parentValues); |
||||
if (find == null) { |
||||
return null; |
||||
} |
||||
return BI.any(find, function (v, ob) { |
||||
if (v === value) { |
||||
if (ob != null && BI.isEmpty(ob)) { |
||||
return true; |
||||
} |
||||
} |
||||
}); |
||||
} |
||||
|
||||
function isSelected(parentValues, value) { |
||||
var find = findSelectedObj(parentValues); |
||||
if (find == null) { |
||||
return false; |
||||
} |
||||
return BI.any(find, function (v) { |
||||
if (v === value) { |
||||
return true; |
||||
} |
||||
}); |
||||
} |
||||
|
||||
function findSelectedObj(parentValues) { |
||||
var find = selectedValues; |
||||
if (find == null) { |
||||
return null; |
||||
} |
||||
BI.every(parentValues, function (i, v) { |
||||
find = find[v]; |
||||
if (find == null) { |
||||
return false; |
||||
} |
||||
return true; |
||||
}); |
||||
return find; |
||||
} |
||||
}, |
||||
|
||||
_reqTreeNode: function (op, callback) { |
||||
var self = this; |
||||
var result = []; |
||||
var times = op.times; |
||||
var checkState = op.checkState || {}; |
||||
var parentValues = op.parentValues || []; |
||||
var selectedValues = op.selectedValues; |
||||
var valueMap = {}; |
||||
if (judgeState(parentValues, selectedValues, checkState)) { |
||||
valueMap = dealWidthSelectedValue(parentValues, selectedValues); |
||||
} |
||||
var nodes = this._getChildren(parentValues); |
||||
for (var i = (times - 1) * this._const.perPage; nodes[i] && i < times * this._const.perPage; i++) { |
||||
var state = getCheckState(nodes[i].value, parentValues, valueMap, checkState); |
||||
result.push({ |
||||
id: nodes[i].id, |
||||
pId: nodes[i].pId, |
||||
value: nodes[i].value, |
||||
text: nodes[i].text, |
||||
times: 1, |
||||
isParent: nodes[i].getChildrenLength() > 0, |
||||
checked: state[0], |
||||
halfCheck: state[1] |
||||
}) |
||||
} |
||||
BI.nextTick(function () { |
||||
callback({ |
||||
items: result, |
||||
hasNext: nodes.length > times * self._const.perPage |
||||
}); |
||||
}); |
||||
|
||||
function judgeState(parentValues, selected_value, checkState) { |
||||
var checked = checkState.checked, half = checkState.half; |
||||
if (parentValues.length > 0 && !checked) { |
||||
return false; |
||||
} |
||||
return (parentValues.length === 0 || (checked && half) && !BI.isEmpty(selected_value)); |
||||
} |
||||
|
||||
function dealWidthSelectedValue(parentValues, selectedValues) { |
||||
var valueMap = {}; |
||||
BI.each(parentValues, function (i, v) { |
||||
selectedValues = selectedValues[v]; |
||||
}); |
||||
BI.each(selectedValues, function (value, obj) { |
||||
if (BI.isNull(obj)) { |
||||
valueMap[value] = [0, 0]; |
||||
return; |
||||
} |
||||
if (BI.isEmpty(obj)) { |
||||
valueMap[value] = [2, 0]; |
||||
return; |
||||
} |
||||
var nextNames = {}; |
||||
BI.each(obj, function (t, o) { |
||||
if (BI.isNull(o) || BI.isEmpty(o)) { |
||||
nextNames[t] = true; |
||||
} |
||||
}); |
||||
valueMap[value] = [1, BI.size(nextNames)]; |
||||
}); |
||||
return valueMap; |
||||
} |
||||
|
||||
function getCheckState(current, parentValues, valueMap, checkState) { |
||||
var checked = checkState.checked, half = checkState.half; |
||||
var tempCheck = false, halfCheck = false; |
||||
if (BI.has(valueMap, current)) { |
||||
//可能是半选
|
||||
if (valueMap[current][0] === 1) { |
||||
var values = BI.clone(parentValues); |
||||
values.push(current); |
||||
var childCount = self._getChildCount(values); |
||||
if (childCount > 0 && childCount !== valueMap[current][1]) { |
||||
halfCheck = true; |
||||
} |
||||
} else if (valueMap[current][0] === 2) { |
||||
tempCheck = true; |
||||
} |
||||
} |
||||
var check; |
||||
if (!checked && !halfCheck && !tempCheck) { |
||||
check = BI.has(valueMap, current); |
||||
} else { |
||||
check = ((tempCheck || checked) && !half) || BI.has(valueMap, current); |
||||
} |
||||
return [check, halfCheck]; |
||||
} |
||||
}, |
||||
|
||||
|
||||
_buildTree: function (jo, values) { |
||||
var t = jo; |
||||
BI.each(values, function (i, v) { |
||||
if (!BI.has(t, v)) { |
||||
t[v] = {}; |
||||
} |
||||
t = t[v]; |
||||
}); |
||||
}, |
||||
|
||||
_isMatch: function (value, keyword) { |
||||
var finded = BI.Func.getSearchResult([value], keyword); |
||||
return finded.finded.length > 0 || finded.matched.length > 0; |
||||
}, |
||||
|
||||
_getNode: function (parentValues, v) { |
||||
var self = this; |
||||
var findedParentNode; |
||||
var index = 0; |
||||
this.tree.traverse(function (node) { |
||||
if (self.tree.isRoot(node)) { |
||||
return; |
||||
} |
||||
if (index > parentValues.length) { |
||||
return false; |
||||
} |
||||
if (index === parentValues.length && node.value === v) { |
||||
findedParentNode = node; |
||||
return false; |
||||
} |
||||
if (node.value === parentValues[index]) { |
||||
index++; |
||||
return; |
||||
} |
||||
return true; |
||||
}); |
||||
return findedParentNode; |
||||
}, |
||||
|
||||
_getChildren: function (parentValues) { |
||||
if (parentValues.length > 0) { |
||||
var value = BI.last(parentValues); |
||||
var parent = this._getNode(parentValues.slice(0, parentValues.length - 1), value); |
||||
} else { |
||||
var parent = this.tree.getRoot(); |
||||
} |
||||
return parent.getChildren(); |
||||
}, |
||||
|
||||
_getChildCount: function (parentValues) { |
||||
return this._getChildren(parentValues).length; |
||||
} |
||||
}); |
@ -0,0 +1,49 @@
|
||||
/** |
||||
* 简单的复选下拉树控件, 适用于数据量少的情况 |
||||
* |
||||
* Created by GUY on 2015/10/29. |
||||
* @class BI.TreeValueChooserPane |
||||
* @extends BI.AbstractTreeValueChooser |
||||
*/ |
||||
BI.TreeValueChooserPane = BI.inherit(BI.AbstractTreeValueChooser, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.TreeValueChooserPane.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-tree-value-chooser-pane", |
||||
items: null, |
||||
itemsCreator: BI.emptyFn |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.TreeValueChooserPane.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.pane = BI.createWidget({ |
||||
type: 'bi.multi_select_tree', |
||||
element: this, |
||||
itemsCreator: BI.bind(this._itemsCreator, this) |
||||
}); |
||||
|
||||
this.pane.on(BI.MultiSelectTree.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.TreeValueChooserPane.EVENT_CHANGE); |
||||
}); |
||||
if (BI.isNotNull(o.items)) { |
||||
this._initData(o.items); |
||||
this.populate(); |
||||
} |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.pane.setValue(v); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
return this.pane.getValue(); |
||||
}, |
||||
|
||||
populate: function () { |
||||
this.pane.populate.apply(this.pane, arguments); |
||||
} |
||||
}); |
||||
BI.TreeValueChooserPane.EVENT_CHANGE = "TreeValueChooserPane.EVENT_CHANGE"; |
||||
BI.shortcut('bi.tree_value_chooser_pane', BI.TreeValueChooserPane); |
@ -0,0 +1,89 @@
|
||||
/** |
||||
* 简单的复选下拉框控件, 适用于数据量少的情况 |
||||
* 封装了字段处理逻辑 |
||||
* |
||||
* Created by GUY on 2015/10/29. |
||||
* @class BI.AbstractValueChooser |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.AbstractValueChooser = BI.inherit(BI.Widget, { |
||||
|
||||
_const: { |
||||
perPage: 100 |
||||
}, |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.AbstractValueChooser.superclass._defaultConfig.apply(this, arguments), { |
||||
items: null, |
||||
itemsCreator: BI.emptyFn, |
||||
cache: true |
||||
}); |
||||
}, |
||||
|
||||
_valueFormatter: function (v) { |
||||
var text = v; |
||||
if (BI.isNotNull(this.items)) { |
||||
BI.some(this.items, function (i, item) { |
||||
if (item.value === v) { |
||||
text = item.text; |
||||
return true; |
||||
} |
||||
}); |
||||
} |
||||
return text; |
||||
}, |
||||
|
||||
_getItemsByTimes: function (items, times) { |
||||
var res = []; |
||||
for (var i = (times - 1) * this._const.perPage; items[i] && i < times * this._const.perPage; i++) { |
||||
res.push(items[i]); |
||||
} |
||||
return res; |
||||
}, |
||||
|
||||
_hasNextByTimes: function (items, times) { |
||||
return times * this._const.perPage < items.length; |
||||
}, |
||||
|
||||
_itemsCreator: function (options, callback) { |
||||
var self = this, o = this.options; |
||||
if (!o.cache || !this.items) { |
||||
o.itemsCreator({}, function (items) { |
||||
self.items = items; |
||||
call(items); |
||||
}); |
||||
} else { |
||||
call(this.items); |
||||
} |
||||
function call(items) { |
||||
var keywords = (options.keywords || []).slice(); |
||||
if (options.keyword) { |
||||
keywords.push(options.keyword); |
||||
} |
||||
BI.each(keywords, function (i, kw) { |
||||
var search = BI.Func.getSearchResult(items, kw); |
||||
items = search.matched.concat(search.finded); |
||||
}); |
||||
if (options.selectedValues) {//过滤
|
||||
var filter = BI.makeObject(options.selectedValues, true); |
||||
items = BI.filter(items, function (i, ob) { |
||||
return !filter[ob.value]; |
||||
}); |
||||
} |
||||
if (options.type === BI.MultiSelectCombo.REQ_GET_ALL_DATA) { |
||||
callback({ |
||||
items: items |
||||
}); |
||||
return; |
||||
} |
||||
if (options.type === BI.MultiSelectCombo.REQ_GET_DATA_LENGTH) { |
||||
callback({count: items.length}); |
||||
return; |
||||
} |
||||
callback({ |
||||
items: self._getItemsByTimes(items, options.times), |
||||
hasNext: self._hasNextByTimes(items, options.times) |
||||
}); |
||||
} |
||||
} |
||||
}); |
@ -0,0 +1,56 @@
|
||||
/** |
||||
* 简单的复选下拉框控件, 适用于数据量少的情况 |
||||
* 封装了字段处理逻辑 |
||||
* |
||||
* Created by GUY on 2015/10/29. |
||||
* @class BI.ValueChooserPane |
||||
* @extends BI.Widget |
||||
*/ |
||||
BI.ValueChooserPane = BI.inherit(BI.AbstractValueChooser, { |
||||
|
||||
_defaultConfig: function () { |
||||
return BI.extend(BI.ValueChooserPane.superclass._defaultConfig.apply(this, arguments), { |
||||
baseCls: "bi-value-chooser-pane", |
||||
items: null, |
||||
itemsCreator: BI.emptyFn, |
||||
cache: true |
||||
}); |
||||
}, |
||||
|
||||
_init: function () { |
||||
BI.ValueChooserPane.superclass._init.apply(this, arguments); |
||||
var self = this, o = this.options; |
||||
this.list = BI.createWidget({ |
||||
type: 'bi.multi_select_list', |
||||
element: this, |
||||
itemsCreator: BI.bind(this._itemsCreator, this), |
||||
valueFormatter: BI.bind(this._valueFormatter, this) |
||||
}); |
||||
|
||||
this.list.on(BI.MultiSelectList.EVENT_CHANGE, function () { |
||||
self.fireEvent(BI.ValueChooserPane.EVENT_CHANGE); |
||||
}); |
||||
if (BI.isNotNull(o.items)) { |
||||
this.items = o.items; |
||||
this.populate(); |
||||
} |
||||
}, |
||||
|
||||
setValue: function (v) { |
||||
this.list.setValue(v); |
||||
}, |
||||
|
||||
getValue: function () { |
||||
var val = this.list.getValue() || {}; |
||||
return { |
||||
type: val.type, |
||||
value: val.value |
||||
} |
||||
}, |
||||
|
||||
populate: function () { |
||||
this.list.populate.apply(this.list, arguments); |
||||
} |
||||
}); |
||||
BI.ValueChooserPane.EVENT_CHANGE = "ValueChooserPane.EVENT_CHANGE"; |
||||
BI.shortcut('bi.value_chooser_pane', BI.ValueChooserPane); |
Loading…
Reference in new issue