<%@page trimDirectiveWhitespaces="true"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="gen" uri="http://help.jspgen.com/taglib/jstl"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="ie=edge,chrome=1" />
<title>角色</title>
<!-- ZTree树形插件 -->
<link type="text/css" href="${config.statie}js/ztree/images/ztree.css" rel="stylesheet">
<!-- 当前页面 -->
<link type="text/css" href="${config.statie}ui/admin/images/admin.css" rel="stylesheet">
<style type="text/css">
/*权限区域*/
.ztree * {font-size:12px; line-height:20px;}
.ztree li ul.level0 {padding:0; background:none;}

.purview{}
.purview .tree{margin:5px; width:220px; height:280px; overflow:auto;}
.operate{line-height:30px; text-align:center;}
</style>
</head>
<body>
<div id="wrapper">
  <div class="area">
    <h2><i><gen:if test='${empty param.id}'>添加<gen:else />编辑</gen:if>角色</i></h2>
    <div class="area-content">
      <form id="form" name="form" method="post" action="<gen:if test='${empty param.id}'>admin_role!save.gen<gen:else />admin_role!update.gen</gen:if>">
        <table width="100%" border="0" cellspacing="0" cellpadding="0" class="table">
          <tr>
            <td width="30%" align="right">名 称：</td>
            <td><input name="name" type="text" class="text small" size="35" value="${adminRole.name}" />
              <label for="name" generated="true" class="tip normal" tip="长度保持在50个字节之内[一个中文算两个字节]"></label></td>
          </tr>
          <tr class="border-top">
            <td align="right">属 性：</td>
            <td><label><input name="isDefault" type="checkbox" value="1" <gen:if test='${adminRole.isDefault == 1}'>checked="checked"</gen:if> />
            默认</label></td>
          </tr>
          <tr class="border-top">
            <td align="right" valign="top">备 注：</td>
            <td><textarea name="remark" class="text small textarea general">${adminRole.remark}</textarea></td>
          </tr>
          <tr class="border-top">
          	<td align="right" valign="top">访问权限：</td>
          	<td valign="top"><table border="0" cellspacing="0" cellpadding="0" class="purview">
            	<tr class="ignore">
              	<c:forEach items="${treeList}" var="tree" varStatus="i">
              		<td valign="middle"<gen:if test="${i.count%3 != 0}"> class="border-right"</gen:if>>
              			<ul id="tree${tree.id}" name="tree${tree.id}" class="ztree tree"></ul>
              			<div class="operate"> <a href="javascript:void(0);" class="check" for="tree${tree.id}" title="全选">全选</a> <a href="javascript:void(0);" class="uncheck" for="tree${tree.id}" title="全不选">全不选</a></div>
            		</td>
            		<gen:if test="${i.count%3 == 0}"></tr><tr class="ignore"></gen:if>
            	</c:forEach>
            	</tr>
          	</table><input type="hidden" name="purview" value="${adminRole.purview}" /></td>
          </tr>
          <tr class="border-top">
            <td colspan="2" class="push txt-c"><input type="hidden" name="formHash" value="${formHash}"/>
              <input type="hidden" name="id" value="${adminRole.id}" />
              <input name="submit" class="button blue small" type="submit" value="确 定" />
              &nbsp;&nbsp;&nbsp;&nbsp;
              <input name="reset" class="button gray small" type="reset" value="取 消" /></td>
          </tr>
        </table>
      </form>
    </div>
  </div>
</div>
<!-- 必备插件 -->
<script type="text/javascript" src="${config.statie}js/jquery.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.form.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.grapes.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.mousewheel.js"></script>
<script type="text/javascript" src="${config.statie}js/jquery.tablecolor.js"></script>
<!-- ZTree树形插件 -->
<script type="text/javascript" src="${config.statie}js/ztree/jquery.ztree.core-3.5.js"></script>
<script type="text/javascript" src="${config.statie}js/ztree/jquery.ztree.excheck-3.5.js"></script>
<script type="text/javascript" src="${config.statie}js/ztree/jquery.ztree.exhide-3.5.js"></script>
<!-- 弹窗插件 -->
<script type="text/javascript" src="${config.statie}js/dialog/jquery.dialog.js?self=true"></script>
<script type="text/javascript" src="${config.statie}js/dialog/jquery.dialog.plugins.js"></script>
<!-- 表单验证插件 -->
<script type="text/javascript" src="${config.statie}js/validate/jquery.validate.js"></script>
<script type="text/javascript" src="${config.statie}js/validate/validate.expand.js"></script>
<script type="text/javascript" src="${config.statie}js/validate/messages_zh.js"></script>
<!-- UI界面必备 -->
<script type="text/javascript" src="${config.statie}ui/js/jspgen.js"></script>
<script type="text/javascript" src="${config.statie}ui/js/jspgen.ajax.js"></script>
<script type="text/javascript" src="${config.statie}ui/js/jspgen.ready.js"></script>
<!-- 当前页面 -->
<script type="text/javascript" src="${config.statie}ui/admin/js/tree-icon.js"></script>
<script type="text/javascript" src="${config.statie}ui/admin/js/tree-admin-role.js"></script>
<script type="text/javascript">
// document.domain = "baidu.com";

// 调用
$(document).ready(function(){	
	var $form = $('#form');
	var $reset = $('input:reset');
	var $purview = $('input[name="purview"]');
	
	// 表单验证
	var validate = $form.validate({
		rules: {
			name: {
				required: true,
				rangebyte: [4, 50]
			}
		},
		messages: {
			name: {
				required: '名称不允许为空！'
			}
		},
		submitHandler: function(form) {
			var val = checkedAll('tree'); $purview.prop('value', val);
			// $(form).find(':submit').prop('disabled', true).removeClass('blue').addClass('disabled');
			// form.submit();
			
			// alert($purview.prop('value'));
			// return false;
			
			$(form).ajaxSubmit($.extend({
				success: function(result) {
					// {'status':false,'message':'message', 'store':{'id':'id'}}
					if (result) {
						if (result.status) {
							$dialog.success(result.message, function() {
								refleshFromTab(); removeTab();
							});
						}else{
							$dialog.error(result.message);
						}
					}
				}
			}, formOptions));
			
			// 阻止表单默认提交
			return false;
		}
	});
	$reset.bind('click', function () {
		validate.resetForm();
	});
	
	$('.purview').delegate('.check', 'click', function(){
		check($(this).attr('for'), true);
	});
	$('.purview').delegate('.uncheck', 'click', function(){
		check($(this).attr('for'), false);
	});		
	$('.purview .operate a').addClass('button gray tiny green-hover');
	
	// 创建树权限
	<c:forEach items="${treeList}" var="tree">
	createTree('tree${tree.id}', ${tree.id}, '${tree.name}', '${adminRole.purview}');
	</c:forEach>
});
</script>
</body>
</html>
