File: /www/wwwroot/hz.xxlht.com1/application/admin/template/auth_role/add.htm
{include file="public/layout" /}
<body class="rolecss bodystyle">
<div id="toolTipLayer" style="position: absolute; z-index: 9999; display: none; visibility: visible; left: 95px; top: 573px;"></div>
<div id="append_parent"></div>
<div id="ajaxwaitid"></div>
<div class="page" style=" min-width: auto;">
{lt name="$Request.param.iframe" value="1"}
{include file="admin/admin_bar" /}
{/lt}
<form class="form-horizontal" id="postForm" method="post" action="{:url('AuthRole/add')}">
<div class="ncap-form-default">
<dl class="row"><dt class="tit"><label><b>权限组基本信息</b></label></dt></dl>
<dl class="row">
<dt class="tit">
<label for="name"><em>*</em>组名称</label>
</dt>
<dd class="opt">
<input type="text" name="name" id="name" value="" class="input-txt">
<span class="err"></span>
<p class="notic"></p>
</dd>
</dl>
<dl class="row"><dt class="tit"><label><b>快捷勾选权限</b></label></dt></dl>
<dl class="row">
<dt class="tit">
<label for="name">参考权限组</label>
</dt>
<dd class="opt">
<p><label><input type="radio" name="tmp_role_id" value="-1" />超级管理员</label></p>
{foreach name="admin_role_list" item="role" key="k"}
<p>
<label><input type="radio" name="tmp_role_id" value="{$role.id}" />{$role.name}</label>
</p>
{/foreach}
</dd>
</dl>
<dl class="row"><dt class="tit"><label><b>权限组权限设置</b></label></dt></dl>
<dl class="row none">
<dt class="tit">
<label for="name">语言权限</label>
</dt>
<dd class="opt">
<label><input type="checkbox" name="language[]" value="cn" checked="checked" />简体中文</label>
<span class="err"></span>
<p class="notic"></p>
</dd>
</dl>
<dl class="row">
<dt class="tit">
<label for="name">在线升级</label>
</dt>
<dd class="opt">
<label><input type="checkbox" name="online_update" value="1" />允许操作</label>
<span class="err"></span>
<p class="notic"></p>
</dd>
</dl>
<dl class="row" id="dl_only_oneself">
<dt class="tit">
<label for="name">文档权限</label>
</dt>
<dd class="opt">
<label><input type="checkbox" name="only_oneself" value="1" />只允许查看自己发布的文档</label>
<span class="err"></span>
<p class="notic"></p>
</dd>
</dl>
<dl class="row">
<dt class="tit">
<label for="name">操作权限</label>
</dt>
<dd class="opt">
<p><label><input type="checkbox" id="select_cud" checked="checked" />完全控制</label></p>
<p><label><input type="checkbox" name="cud[]" value="add" checked="checked" />新增信息</label></p>
<p><label><input type="checkbox" name="cud[]" value="edit" checked="checked" />编辑信息</label></p>
<p><label><input type="checkbox" name="cud[]" value="del" checked="checked" />删除信息</label></p>
<p><label><input type="checkbox" name="cud[]" value="changetableval" checked="checked" />审核信息</label></p>
<span class="err"></span>
<p class="notic"></p>
</dd>
</dl>
<dl class="row">
<dt class="tit">
<label for="name"><em>*</em>功能权限</label>
</dt>
<dd class="opt">
<p>
<label><input type="checkbox" id="select_all_permission" />全部选择</label>
</p>
{foreach name="modules" item="vo"}
{foreach name="vo.child" item="vo2"}
{if condition="1 == $vo2['is_modules'] AND ! empty($auth_rule_list[$vo2.id])"}
{if condition="1002 == $vo2['id']"}
<div class="admin_poplistdiv">
<h2>{$vo2.name}</h2>
{php}$first_arctype_id = 0;{/php}
{if condition="! empty($arctypes)"}
<p>
{php}$first_arctype_id = '';{/php}
{foreach name="arctypes" item="arctype" key="k"}
{if condition="isset($arctype_array[$arctype['id']])"}
{if condition="$k>0"}
<em class="arctype_bg expandable"></em>
{else /}
<em class="arctype_bg collapsable"></em>
{php}$first_arctype_id = $arctype['id'];{/php}
{/if}
{/if}
<label><input type="checkbox" class="arctype_cbox arctype_id_{$arctype.id}" name="permission[arctype][]" value="{$arctype.id}" />{$arctype.typename}</label>
{/foreach}
</p>
{foreach name="arctypes" item="arctype"}
{if condition="isset($arctype_array[$arctype['id']])"}
<div class="arctype_child" id="arctype_child_{$arctype['id']}"{if condition="$first_arctype_id==$arctype['id']"} style="display: block;"{/if}>
{foreach $arctype_array[$arctype['id']] as $item}
<div class="arctype_child1">
<label><input type="checkbox" class="arctype_cbox arctype_id_{$item.id}" name="permission[arctype][]" value="{$item.id}" data-pid="{$item.parent_id}" />{$item.typename}</label>
</div>
{if condition="isset($arctype_array[$item['id']])"}
<div class="arctype_child2" id="arctype_child_{$item['id']}">
<span class="button level1 switch center_docu"></span>
{foreach $arctype_array[$item['id']] as $vo}
<label><input type="checkbox" class="arctype_cbox" name="permission[arctype][]" value="{$vo.id}" data-pid="{$vo.parent_id}" data-tpid="{$item.parent_id}" />{$vo.typename}</label>
{/foreach}
</div>
{/if}
{/foreach}
</div>
{/if}
{/foreach}
{/if}
</div>
{else /}
<div class="admin_poplistdiv">
<h2>{$vo2.name}</h2>
<p>
{foreach name="auth_rule_list[$vo2.id]" item="rule"}
<label><input type="checkbox" name="permission[rules][]" value="{$rule.id}" />{$rule.name}</label>
{/foreach}
</p>
</div>
{/if}
{/if}
{/foreach}
{/foreach}
{if condition="! empty($plugins)"}
<div class="admin_poplistdiv">
<h2>插件应用</h2>
<ul>
{foreach name="plugins" item="plugin"}
<li>
<label><input type="checkbox" name="permission[plugins][{$plugin.code}][code]" value="{$plugin.code}" />{$plugin.name}</label>
{php}$config = json_decode($plugin['config'], true);{/php}
{if condition="! empty($config['permission'])"}
<p style="padding-left:10px;">
<span class="button level1 switch center_docu"></span>
{foreach $config['permission'] as $index => $text}
<label><input type="checkbox" name="permission[plugins][{$plugin.code}][child][]" value="{$index}" />{$text}</label>
{/foreach}
</p>
{/if}
</li>
{/foreach}
</ul>
</div>
{/if}
</dd>
</dl>
<div class="bot2">
<a href="JavaScript:void(0);" onclick="postSubmit();" class="ncap-btn-big ncap-btn-green" id="submitBtn">确认提交</a>
</div>
</div>
</form>
</div>
<script type="text/javascript">
var admin_role_list = {$admin_role_list|json_encode};
$(function(){
$('#postForm input[name="tmp_role_id"]').bind('click', function(){
changeRole($(this).val());
});
$('.arctype_bg').bind('click', function(){
var acid = $(this).next().find('input').val(), input = 'arctype_child_' + acid;
$('.arctype_child').hide();
if( $(this).attr('class').indexOf('expandable') == -1 ){
$(this).removeClass('collapsable').addClass('expandable');
}else{
$('.arctype_bg').removeClass('collapsable').addClass('expandable');
$(this).removeClass('expandable').addClass('collapsable');
$('#'+input).show();
}
});
$('.arctype_cbox').bind('click', function(){
var acid = $(this).val(), input = 'arctype_child_' + acid;
var pid = $(this).data('pid');
var tpid = $(this).data('tpid');
if($(this).attr('checked')){
if (0 < $('input[data-pid="'+pid+'"]:checked').length) {
$('.arctype_id_'+pid).attr('checked', 'checked');
}
if (0 < $('#arctype_child_'+tpid).find('input[type="checkbox"]:checked').length) {
$('.arctype_id_'+tpid).attr('checked', 'checked');
}
$('#'+input).find('input[type="checkbox"]').attr('checked', 'checked');
}else{
if (1 > $('input[data-pid="'+pid+'"]:checked').length) {
$('.arctype_id_'+pid).removeAttr('checked');
}
if (1 > $('#arctype_child_'+tpid).find('input[type="checkbox"]:checked').length) {
$('.arctype_id_'+tpid).removeAttr('checked');
}
$('#'+input).find('input[type="checkbox"]').removeAttr('checked');
}
});
$('#select_cud').bind('click', function(){
if($(this).attr('checked')){
$('#postForm input[name^="cud"]').attr('checked', 'checked');
}else{
$('#postForm input[name^="cud"]').removeAttr('checked');
}
});
$('#select_all_permission').bind('click', function(){
if($(this).attr('checked')){
$('#postForm input[name^="permission"]').attr('checked', 'checked');
}else{
$('#postForm input[name^="permission"]').removeAttr('checked');
}
});
$('#postForm input[name^="permission"],#postForm input[name^="cud"]').bind('click', function(){
hasSelectAll();
});
});
function hasSelectAll(){
var c = true;
$('#postForm input[name^="permission"]').each(function(idx, ele){
if(! $(ele).attr('checked')){
c = false;
return;
}
});
if(c){
$('#select_all_permission').attr('checked', 'checked');
}else{
$('#select_all_permission').removeAttr('checked');
}
var c = true;
$('#postForm input[name^="cud"]').each(function(idx, ele){
if(! $(ele).attr('checked')){
c = false;
return;
}
});
if(c){
$('#select_cud').attr('checked', 'checked');
}else{
$('#select_cud').removeAttr('checked');
}
}
function changeRole(value){
if (-1 == value) {
$('#postForm input[type="checkbox"]').attr("checked","checked");
$('#postForm input[name="only_oneself"]').removeAttr('checked');
return;
}
$('#postForm input[type="checkbox"]').removeAttr('checked');
for(var i in admin_role_list){
var item = admin_role_list[i];
if(item.id == value){
if(item.language){
item.language.map(function(row){
$('#postForm input[name^="language"][value="'+row+'"]').attr('checked', 'checked');
});
}
if(item.online_update){
$('#postForm input[name="online_update"]').attr('checked', 'checked');
};
// if(item.editor_visual){
// $('#postForm input[name="editor_visual"]').attr('checked', 'checked');
// };
if(item.only_oneself){
$('#postForm input[name="only_oneself"]').attr('checked', 'checked');
};
if(item.cud){
item.cud.map(function(row){
$('#postForm input[name^="cud"][value="'+row+'"]').attr('checked', 'checked');
});
}
if(item.permission){
for(var p in item.permission){
if(p == 'plugins'){
if(item.permission[p]){
for(var pluginId in item.permission[p]){
$('#postForm input[name="permission['+p+']['+pluginId+'][code]"][value="'+pluginId+'"]').attr('checked', 'checked');
if(item.permission[p][pluginId].child){
item.permission[p][pluginId].child.map(function(row){
$('#postForm input[name="permission['+p+']['+pluginId+'][child][]"][value="'+row+'"]').attr('checked', 'checked');
});
}
}
}
}else{
item.permission[p].map(function(row){
$('#postForm input[name="permission['+p+'][]"][value="'+row+'"]').attr('checked', 'checked');
});
}
}
}
hasSelectAll();
break;
}
}
}
function postSubmit(){
if($('input[name=name]').val() == '' ){
showErrorMsg('组名称不能为空!');
$('input[name=name]').focus();
return false;
}
var a = [];
$('input[name^=permission]').each(function(i,o){
if($(o).is(':checked')){
a.push($(o).val());
}
})
if(a.length == 0){
showErrorMsg('请具体分配权限!');
return false;
}
var parentObj = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
layer_loading('正在处理');
{lt name="$Request.param.iframe" value="1"}
$('#postForm').submit();
{else /}
$.ajax({
url: "{:url('AuthRole/add', ['_ajax'=>1])}",
type: 'POST',
dataType: 'JSON',
data: $('#postForm').serialize(),
success: function(res){
layer.closeAll();
if (res.code == 1) {
var str = '<p><label><input type="radio" name="role_id" value="'+res.data.role_id+'" onclick="changeRole('+res.data.role_id+');" checked="checked" />'+res.data.role_name+'</label></p>';
parent.custom_role(str, res.data.role_id, res.data.admin_role_list);
parent.layer.close(parentObj);
parent.layer.msg(res.msg, {shade: 0.3, time: 1000});
} else {
parent.showErrorMsg(res.msg);
}
return false;
},
error: function(e){
layer.closeAll();
layer.msg('操作失败', {icon:5, time:1500});
return false;
}
});
{/lt}
}
</script>
{include file="public/footer" /}