').appendTo('body').css({
+ width: opts.width,
+ height: 20,
+ position: 'absolute',
+ zIndex : 999999
+ });
+ var $loading = $('
').text(FR.i18nText('Loading'))
+ .css({
+ lineHeight: '20px'
+ });
+ $loading.appendTo(this.$view);
+ this.expand();
+ this.modifyPosition();
+ this.loadData();
+ } else {
+ this.expand();
+ }
+ }
+ },
+
+ loadData: function () {
+ var opts = this.options, self = this;
+ FR.ajax({
+ url: opts.widgetUrl,
+ data: {
+ widgetName: opts.widgetName,
+ level: -1
+ },
+ complete: function (res) {
+ var data = FR.jsonDecode(res.responseText);
+ self._initTreeWithNodes(data);
+ }
+ });
+
+ },
+
+ _initTreeWithNodes: function (nodes) {
+ var opts = this.options, self = this;
+ var setting = {
+ view: {
+ selectedMulti: false
+ },
+ async: {
+ enable: true,
+ url: opts.widgetUrl,
+ autoParam: ['text', 'value', 'level', 'pv', 'checked'],
+ type: 'post'
+ },
+ callback: {
+ onAsyncSuccess: function (event, treeId, treeNode, msg) {
+ if (setting.check.enable) {
+ if (treeNode.checked && opts.cascade === 'descendant') {
+ var nodes = treeNode.children;
+ for (var i = 0, len = nodes.length; i < len; i++) {
+ var child = nodes[i];
+ self.treeObj.expandNode(child, true, false, false);
+ }
+ }
+ self._didSelect();
+ }
+ },
+ onCheck: function (event, treeId, treeNode) {
+ if (opts.cascade !== 'none') {
+ self.treeObj.expandNode(treeNode, true, false, false);
+ }
+ self._didSelect();
+ },
+ onClick: function (event, treeId, treeNode, clickFlag) {
+ if (!setting.check.enable) {
+ self.setText(treeNode.text);
+ self.setValue(treeNode.value);
+ self.collapse();
+ self.fireEvent(FR.Events.AFTEREDIT);
+ }
+ }
+ }
+ };
+ $.extend(true, setting, opts.setting);
+ this.$view.empty();
+ this.$view.css({
+ width: Math.max(opts.popupWidth, opts.width),
+ height: opts.popupHeight
+ });
+ this.$tree = $('
').appendTo(this.$view);
+ this.treeObj = $.fn.zTree.init(this.$tree, setting, nodes);
+ },
+
+ _didSelect: function () {
+ var self = this;
+ var selected = self.treeObj.getCheckedNodes(true);
+ var len = selected.length;
+ self.setText(FR.i18nText('Plugin-ZTree_Select', len));
+ var result = [];
+ for (var i = 0; i < len; i++) {
+ result.push(selected[i].value);
+ }
+ self.options.value = result;
+ self.fireEvent(FR.Events.AFTEREDIT);
+ },
+
+ modifyPosition: function () {
+ var opts = this.options;
+ var p = this.element.offset();
+ this.$view.css({
+ top: p.top + opts.height,
+ left: p.left
+ });
+ },
+
+
+ isExpanded: function () {
+ return this.$view && this.$view.is(":visible");
+ },
+
+ expand: function () {
+ this.$view.show();
+ $(document).bind('mousedown', this, this.collapseIf);
+ },
+ collapseIf: function (e) {
+ var $target = $(e.target);
+ var off = $target.offset();
+ var self = e.data;
+ if ($target[0] == self.$view[0]) {
+ return;
+ }
+ var opts = self.options;
+ var vf = self.$view.offset();
+ // richie:加20的目的是保证有滚动条的时候也会判断在内部
+ if (off.left > vf.left && off.left < vf.left + Math.max(opts.width, opts.popupWidth) + 20
+ && off.top > vf.top && off.top < vf.top + opts.popupHeight) {
+
+ } else {
+ self.collapse();
+ }
+ },
+
+ collapse: function () {
+ if (!this.isExpanded()) {
+ return;
+ }
+ this.$view.hide();
+ $(document).unbind('mousedown', this.collapseIf);
+ },
+ setText: function (text) {
+ this.editComp.val(text);
+ },
+ setValue: function (value) {
+ this.options.value = value;
+ },
+ getValue: function () {
+ return this.options.value;
+ }
+ });
+ $.shortcut('ztree', FR.ZTree);
+})(jQuery);
\ No newline at end of file
diff --git a/ztree实现的下拉树控件/fr-plugin-ztree-5.7.zip b/ztree实现的下拉树控件/fr-plugin-ztree-5.7.zip
new file mode 100644
index 0000000..485464a
Binary files /dev/null and b/ztree实现的下拉树控件/fr-plugin-ztree-5.7.zip differ