/**
* Created by dwj on 2017/2/28.
*/
Rsd.define('Rsd.data.Menu', {
extend: 'Rsd.common.Object',
xtype:'menu',
text:'unnamed',
icon:null,
/*页面*/
viewType:'',
key:'',
//提示信息
tip:'',
parent:null,
/*
* 子节点
* */
//children:[],
tag:null,
/*
* 页面参数
* */
args:null,
onAfterAddItem:null,
/*
*
* */
constructor: function Menu(config) {
config = config || {};
var _children = config['children'];
delete config['children'];
this.apply(config);
this.__mapping = {};
this.loadData(_children || []);
},
/**
* @description 加载菜单数据,加载前会清除所有子菜单
*/
loadData:function loadData(data)
{
var _ds = data||[];
if(Rsd.isArray(_ds))
{
this.children = _ds;
}
},
/**
* @description 清除所有子菜单
* */
removeAll:function removeAll()
{
this.__mapping = {};
this.children=[];
},
/**
* @description 添加子菜单
* */
addItem:function addItem(menu)
{
//debugger;
var me = this;
var _m = menu;
if(_m == null ||_m == undefined)
{
return;
}
if(_m instanceof Array)
{
for(var i in _m)
{
this.addItem(_m[i]);
}
return _m;
}
var _list = _m.children;
_m.children = [];
delete _m['children'];
if(_m instanceof Rsd.data.Menu)
{
}else
{
_m = Rsd.create('Rsd.data.Menu',Rsd.isObject(menu)?menu:{text:menu});
}
if(_m.key==null ||_m.key== undefined || _m.key=='')
{
_m.key = me.key + '_' + me.children.length;
}
if(_m.onAfterAddItem == null || _m.onAfterAddItem == undefined)
{
_m.onAfterAddItem = me.onAfterAddItem;
}
_m.parent = me;
this.__mapping[_m.key] = _m;
me.children.push(_m);
setTimeout(function () {
me.funApplyByIOC(me.onAfterAddItem,[_m]);
},0);
if(Rsd.isArray(_list))
{
for(var i in _list)
{
_m.addItem(_list[i])
}
}
if(!Rsd.isEmpty(_m.path))
{
var _plugin = _m;
var _fn = function () {
var _p = this;
var _s = new Rsd.data.Store({
proxy: {
url: _plugin.path + '/config.js',
method:'get'
}});
_s.load({},function (pConfig) {
if(pConfig)
{
pConfig.path = _p.path;
Rsd.app.loadPlugin(pConfig);
_p.loadData(pConfig.children);
}
});
}
_fn.call(_plugin);
}
return _m;
},
/**
* @description 获取子菜单
* */
getItem:function getItem(key)
{
if(Rsd.isEmpty(key))
{
throw new Error('argument key is not allow null.');
}
return this.__mapping[key];
}
},function(type) {
var childrenGetter = function () {
//debugger;
if (this.__children == undefined) {
this.__children = [];
}
return this.__children;
};
var childrenSetter = function (children) {
if(this.__children==undefined)
{
this.__children = [];
}
if(Rsd.isArray(children))
{
this.__mapping = {};
this.__children = [];
for(var i in children)
{
this.addItem(children[i]);
}
}
}
this.defineProperty(type, "children", childrenGetter, childrenSetter, true);
});