/**
 * 系统用户管理
 */
$(function(){
	
	AppUser = {
        Events : {'click .btn': function (e, value, row, index) {
			var event = $(e.target).data('event');
			if(event == 'view'){
                AppUser.view(value);
			}else if(event == 'edit'){
                AppUser.edit(value);
			}else if(event == 'auth'){
                AppUser.bindrole(value);
            }else if(event == 'del'){
                AppUser.del(value);
			}
		}},
		add : function(){
        	window.location = String.format(Config.ROOT+'/auth/jump_basic?moduleId={0}&url=/sys/user/edit', $('#moduleId').val());
		},
		edit: function(oid){
        	window.location = String.format(Config.ROOT+'/auth/jump_basic?moduleId={0}&url=/sys/user/edit&oid={1}', $('#moduleId').val(), oid);
		},
        view: function(oid){
            window.location = String.format(Config.ROOT+'/auth/jump_basic?moduleId={0}&url=/sys/user/edit&editType=view&oid={1}', $('#moduleId').val(), oid);
        },
		del : function(oids){
			if(!oids)return MsgBox.warnDelete();
			App.MsgBox.confirmDelete(function(){
				App.Ajax.request({
					url		: Config.ROOT+'/sys/user/batchDelete',
					params	: {
						'oids': oids
					},
					success: function(resp){
                        $table.reload(1);
					}
				});
			});
		},
		batchDelete : function(){
			var oids = $table.getColumn();
            AppUser.del(oids);
		},
		bindrole: function(oid){
            MsgBox.window({
                title	: '分配权限',
                url		: Config.ROOT+'/authoriz/editUserRole?userId='+oid,
                width	: 350
            });
		}
	};

    var $table = new App.Table({
        url: Config.ROOT + '/sys/user/list',
        search: true,
        searchParamName: 'realName',
        searchPlaceholder: '登录名',
        columns	:[
            {checkbox: true},
            {field:'deptName', title:'所属部门'},
            {field:'realName', title:'姓名'},
            {field:'username', title:'登录名'},
            {field:'mobileTel', title:'手机号码'},
            {field:'email', title:'邮箱'},
            {field:'state', title:'状态', tpl: 'tpl_state'},
            {field:'oid', title:'操作', width: 200, toolbar: 'tableRowToolbar', events: AppUser.Events}
        ]
    });

});