functionAll.js 3.25 KB
/**
 * 功能管理
 */
var functionAll = function() {

	return {

		collapse : function() {
			var node = $('#dg').treegrid('getSelected');
			if (node) {
				$('#dg').treegrid('collapse', node.id);
			}
		},

		expand : function() {
			var node = $('#dg').treegrid('getSelected');
			if (node) {
				$('#dg').treegrid('expand', node.id);
			}
		},
		removeIt : function() {
			var row = $("#dg").datagrid("getSelected");
			if (row) {
				$.messager.confirm('确认', '您确认删除数据吗?', function(r) {
					if (r) {
						$.post("/function/deleteFunction", {
							id : row.id
						}, function(data) {
								$('#dg').treegrid('reload');
						})
					}
				});
			}
		},
		append : function() {
			var row = $('#dg').treegrid('getSelected');
			if (row) {
				$("#ff").form("clear");
				$("#pid").val(row.id);
				$("#lianjie").textbox("enableValidation");
				$("#dlg").dialog("setTitle", "追加子权限").dialog("open");
			}
		}

	}

}();

$(function() {
	$("#dlg").dialog({
		width : 400,
		closed : true,
		buttons : [ {
			text : '提交',
			iconCls : 'icon-ok',
			handler : function() {
				$('#ff').form('submit', {
					url : '/function/addOrUpdateFunction',
					success : function(data) {
							$('#dg').treegrid('reload');
							$("#dlg").dialog("close");
					}
				});
			}
		}, {
			text : '重置',
			iconCls : 'icon-cancel'
		} ]
	});
	var toolbar = [ {
		text : '添加权限模块',
		iconCls : 'icon-add',
		handler : function() {
			$("#ff").form("clear");
			$("#pid").val(0);
			$("#lianjie").textbox("disableValidation");
			$("#dlg").dialog("setTitle", "添加权限模块").dialog("open");
		}
	}, '-', {
		text : '修改',
		iconCls : 'icon-edit',
		handler : function() {
			var row = $("#dg").datagrid("getSelected");
			if (row) {
				$("#ff").form("load", row);
				$("#pid").val(row.parentId);
				$("#lianjie").textbox("enableValidation");
				$("#dlg").dialog("setTitle", "修改权限").dialog("open");
			}
		}
	}, '-', {
		text : '删除',
		iconCls : 'icon-remove',
		handler : function() {
			var row = $("#dg").datagrid("getSelected");
			if (row) {
				$.messager.confirm('确认', '您确认删除数据吗?', function(r) {
					if (r) {
						$.post("/function/deleteFunction", {
							id : row.id
						}, function(data) {
								$('#dg').treegrid('reload');
						})
					}
				});
			}
		}
	}, '-', {
		text : '折叠所有',
		iconCls : 'icon-remove',
		handler : function() {
			$("#dg").treegrid('collapseAll');
		}
	}, '-', {
		text : '展开所有',
		iconCls : 'icon-remove',
		handler : function() {
			$("#dg").treegrid('expandAll');
		}
	} ];
	$("#dg").treegrid({
		title : '权限列表',
		toolbar : toolbar,
		url : '/function/queryAll',
		fit : true,
		border : false,
		fitColumns : true,
		striped : true,
		rownumbers : true,
		remoteSort : false,
		idField : 'id',
		treeField : 'functionName',
		columns : [ [ {
			field : 'functionName',
			title : '权限名称',
			width : 100
		}, {
			field : 'functionDescription',
			title : '权限描述',
			width : 100
		}, {
			field : 'url',
			title : '地址',
			width : 200
		} ] ],
		onContextMenu : createMenu

	});
	function createMenu(e, row) {
		e.preventDefault();
		$(this).treegrid('select', row.id);
		$('#mm').menu('show', {
			left : e.pageX,
			top : e.pageY
		});
	}
})