mwf.xdesktop.requireapp("process.xform", "$module", null, false);
/**树组件数据结构
* @typedef {object} treedata
* @example
* [
* {
* "expand": true, //是否默认展开
* "title": "", //鼠标移上叶子节点的文字
* "text": "根节点", //叶子节点的文字
* "action": "", //执行的脚本
* "default": true, //是否默认选中
* "icon": "folder.png", //图标
* "sub": [ //该节点的子节点
* {
* "expand": true,
* "title": "",
* "text": "[none]",
* "action": "",
* "default": false,
* "icon": "folder.png",
* "sub": []
* },
* ...
* ]
* }
* ]
*/
/** @class tree 树组件。
* @o2cn 树组件
* @example
* //可以在脚本中获取该组件
* //方法1:
* var datagrid = this.form.get("name"); //获取组件
* //方法2
* var datagrid = this.target; //在组件事件脚本中获取
* @see {@link treedata|树组件数据结构}
* @extends mwf.xapplication.process.xform.$module
* @o2category formcomponents
* @o2range {process|cms|portal}
* @hideconstructor
*/
mwf.xapplication.process.xform.tree = mwf.apptree = new class(
/** @lends mwf.xapplication.process.xform.tree# */
{
extends: mwf.app$module,
options: {
/**
* 异步加载树前执行。this.target指向当前组件。
* @event mwf.xapplication.process.xform.tree#beforeloadtree
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 异步加载树后执行。this.target指向当前组件。
* @event mwf.xapplication.process.xform.tree#afterloadtree
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 加载树的叶子前执行。this.target指向加载的叶子。
* @event mwf.xapplication.process.xform.tree#beforeloadtreenode
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 加载树的叶子后执行。this.target指向加载的叶子。
* @event mwf.xapplication.process.xform.tree#afterloadtreenode
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 加载树的叶子后执行。this.target指向加载的叶子。
* @event mwf.xapplication.process.xform.tree#expand
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 折叠节点的时候执行。this.target指向被折叠的节点。
* @event mwf.xapplication.process.xform.tree#collapse
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 选中节点前执行。此时原来被选中的节点还未取消。this.target指向选中的节点。
* @event mwf.xapplication.process.xform.tree#beforeselect
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
/**
* 选中节点后执行。this.target指向选中的节点。
* @event mwf.xapplication.process.xform.tree#afterselect
* @see {@link https://www.yuque.com/o2oa/ixsnyt/hm5uft#i0zts|组件事件说明}
*/
"moduleevents": ["load", "queryload", "postload", "beforeloadtree", "afterloadtree", "beforeloadtreenode", "afterloadtreenode", "expand", "collapse", "beforeselect", "afterselect"]
},
_loaduserinterface: function(){
this.node.empty();
mwf.require("mwf.widget.tree", function(){
var options = {"style":"form"};
if( this.json.events && typeof(this.json.events) === "object" ){
[
{ "beforeloadtree" : "onqueryload" },
{ "afterloadtree" : "onpostload" },
{ "beforeloadtreenode" : "onbeforeloadtreenode" },
{ "afterloadtreenode" : "onafterloadtreenode" },
{ "expand" : "onpostexpand" },
{ "collapse" : "onpostcollapse" },
{ "beforeselect" : "onbeforeselect" },
{ "afterselect" : "onafterselect" }
].each( function (obj) {
var moduleevent = object.keys(obj)[0];
var treeevent = obj[moduleevent];
if( this.json.events[moduleevent] && this.json.events[moduleevent].code ){
options[treeevent] = function( target ){
return this.form.macro.fire(this.json.events[moduleevent].code, target || this);
}.bind(this)
}
}.bind(this));
}
/**
* @summary 树组件,平台使用该组件实现树的功能,该组件为异步加载
* @member {o2.widget.tree}
* @example
* //可以在脚本中获取该组件
* var tree = this.form.get("fieldid").tree; //获取组件对象
* var children = tree.children[]; //获取第一层树叶
* tree.reload( json ); //给整颗树重新赋数据,并重新加载
*/
this.tree = new mwf.widget.tree(this.node, options);
this.tree.form = this.form;
this._settreewidgetstyles();
var treedata = this.json.data;
if (this.json.datatype == "script") treedata = this.form.macro.exec(((this.json.datascript) ? this.json.datascript.code : ""), this);
this.tree.load(treedata);
}.bind(this));
},
_settreewidgetstyles: function(){
this.tree.css.areanode = this.json.areanodestyle;
this.tree.css.treeitemnode = this.json.treeitemnodestyle;
this.tree.css.textdivnode = this.json.textdivnodestyle;
this.tree.css.textdivnodeselected = this.json.textdivnodeselectedstyle;
}
});
source