/**
 * 资源管理
 */
$(function(){
	var moduleId = '';
	
	AppModule = {
        Events : {'click .btn': function (e, value, row, index) {
			var event = $(e.target).data('event');
			if(event == 'edit'){
                AppModule.edit(value);
			}else if(event == 'del'){
                AppModule.del(value);
			}
		}},
		add : function(){
			window.location = String.format(Config.ROOT+'/auth/jump_basic?moduleId={0}&url=/sys/module/edit&parentId={1}', $('#moduleId').val(), moduleId);
		},
		edit: function(oid){
			window.location = String.format(Config.ROOT+'/auth/jump_basic?moduleId={0}&url=/sys/module/edit&oid={1}', $('#moduleId').val(), oid);
		},
		del : function(oids){
			if(!oids)return MsgBox.warnDelete();
			App.MsgBox.confirmDelete(function(){
				App.Ajax.request({
					url		: Config.ROOT+'/sys/module/batchDelete',
					params	: {
						'oids': oids
					},
					success: function(resp){
                        $table.reload(1);
					}
				});
			});
		},
		batchDelete : function(){
			var oids = $table.getColumn();
			AppModule.del(oids);
		}
	};

    $('#module_tree_id').zTreeInit({
        url 	: Config.ROOT + '/sys/module/treeList',
        callback: {
            onClick: function(event, treeId, treeNode) {
                moduleId = treeNode.oid;
                var postData = {
                    'parentId'	: moduleId
                };
                $table.search(postData);
            }
        }
    });
	
	//初始化表格
    var $table = new App.Table({
        url: Config.ROOT + '/sys/module/list',
        search: true,
        searchParamName: 'name',
        searchPlaceholder: '名称',
        columns	:[
            {checkbox: true},
            {field:'name', title:'名称'},
            {field:'mark', title:'代码'},
            {field:'visiturl', title:'访问地址'},
            {field:'state', title:'状态', tpl: 'tpl_state'},
            {field:'morder', title:'排序'},
            {field:'oid', title:'操作', width: 100, toolbar: 'tableRowToolbar', events: AppModule.Events}
        ]
    });

});