* Finish task #89841.

This commit is contained in:
liumengyi
2023-04-07 16:58:20 +08:00
parent cb4c41b19e
commit bacf6bb174
4 changed files with 62 additions and 107 deletions
+7 -36
View File
@@ -295,11 +295,12 @@ class group extends control
$relatedPrivData = $this->group->getDependentPrivs($selectedPrivIdList);
$this->view->privList = $privList;
$this->view->privMethods = $privMethods;
$this->view->selectPrivs = $selectPrivs;
$this->view->privPackages = $privPackages;
$this->view->relatedPrivData = json_encode($relatedPrivData);
$this->view->privList = $privList;
$this->view->privMethods = $privMethods;
$this->view->selectPrivs = $selectPrivs;
$this->view->privPackages = $privPackages;
$this->view->selectedPrivIdList = $selectedPrivIdList;
$this->view->relatedPrivData = json_encode($relatedPrivData);
}
elseif($type == 'byModule')
{
@@ -1060,37 +1061,7 @@ class group extends control
*/
public function ajaxGetDependentPrivs($privIdList)
{
$relatedPrivs = $this->dao->select('t1.relationPriv,t2.parent,t2.module,t2.method,t3.`key`,t3.value')->from(TABLE_PRIVRELATION)->alias('t1')
->leftJoin(TABLE_PRIV)->alias('t2')->on('t1.relationPriv=t2.id')
->leftJoin(TABLE_PRIVLANG)->alias('t3')->on('t2.relationPriv=t3.objectID')
->leftJoin(TABLE_PRIVMANAGER)->alias('t4')->on('t2.parent=t4.id')
->where('t1.priv')->in($privIdList)
->andWhere('t1.relationPriv')->notin($privIdList)
->andWhere('t2.type')->eq('depend')
->andWhere('t3.objectType')->eq('priv')
->andWhere('t1.edition')->like("%,{$this->config->edition},%")
->andWhere('t1.vision')->like("%,{$this->config->vision},%")
->fetchAll('relationPriv');
if(empty($relatedPrivs)) return print('');
$modulePairs = $this->group->getPrivManagerPairs('module');
$managerList = $this->dao->select('*')->from(TABLE_PRIVMANAGER)->fetchAll('id');
$relatedPrivs = $this->group->transformPrivLang($relatedPrivs);
$privList = array('depend' => array(), 'recommend' => array());
foreach($relatedPrivs as $privID => $relatedPriv)
{
$module = $relatedPriv->module;
if(!isset($privList['depend'][$module])) $privList[$type][$module] = array();
$moduleCode = $managerList[$relatedPriv->parent]->type == 'package' ? $managerList[$managerList[$relatedPriv->parent]->parent]->code : $managerList[$relatedPriv->parent]->code;
$privList['depend'][$module]['title'] = $modulePairs[$moduleCode];
$privList['depend'][$module]['module'] = $moduleCode;
$privList['depend'][$module]['children'][] = array('title' => $relatedPriv->name, 'relationPriv' => $privID);
}
$privList['depend'] = array_values($privList[$type]);
$privList = $this->group->getDependentPrivs($privIdList);
return print(json_encode($privList));
}
}
+3 -3
View File
@@ -33,8 +33,8 @@ td.menus + td {border-left: 0;}
#mainContent .main-content {padding: 2px;}
#privList .table-bordered th {border: 1px solid #FFF;}
#privList th.module {width: 142px; min-width: 142px; background-color: #EDEEF2CC; font-weight: 600;}
#privList th.package {width: 142px; min-width: 142px; background-color: #F4F5F7; font-weight: 600;}
#privList th.module {width: 142px; min-width: 142px; background-color: #EDEEF28C; font-weight: 600;}
#privList th.package {width: 142px; min-width: 142px; background-color: #F4F5F78C; font-weight: 600;}
#privList th.method {min-width: 585px;}
#privList th .checkbox-inline input {margin-left: 0px;}
#privList .check-all {display: inline-block;}
@@ -43,7 +43,7 @@ td.menus + td {border-left: 0;}
#privList tbody > tr > td {padding: 4px 20px 20px 20px;}
#privList .group-item {margin-top: 16px;}
#privList .group-item .checkbox-inline label {padding-left: 3px;}
#privList.table-bordered td, #privList.table-bordered th {border-top-style: dashed; border-bottom-style: dashed;}
#privList.table-bordered td, #privList.table-bordered th {border-top-style: dashed; border-bottom-style: dashed; border-color: #FFF;}
#privList .check-all>label.checkbox-indeterminate-block:before {content: ' '; opacity: 1; transform: scale(1);}
.priv-footer {padding: 14px; z-index: 3; box-shadow: inset 0 0px 0px rgb(0 0 0 / 10%), 0 0 5px rgb(0 0 0 / 10%); position: relative; min-height: 40px; background: #fff; border-radius: 0 0 4px 4px;}
.priv-footer .btn {margin 0px; padding-top: 7px;}
+50 -67
View File
@@ -160,78 +160,44 @@ function initDependTree(data)
* @access public
* @return void
*/
function updatePrivTree(objTree)
function updatePrivTree(privList)
{
$(".menuTree.depend").data('zui.tree').reload(objTree.dependData || [] );
if(objTree.dependData && objTree.dependData.length)
if(privList == null)
{
$(".menuTree.depend + .empty-tip").addClass('hidden');
var privCount = 0;
$.each(objTree.dependData, function(index, item){if(item.children) privCount += item.children.length;});
$(".menuTree.depend").closest('.priv-panel').find('.panel-title .priv-count').html('(' + privCount + ')');
}
else
{
$(".menuTree.depend + .empty-tip").removeClass('hidden');
$(".menuTree.depend").closest('.priv-panel').find('.panel-title .priv-count').html('');
}
$(".menuTree.recommend").data('zui.tree').reload(objTree.recommendData || []);
if(objTree.recommendData && objTree.recommendData.length)
{
$(".menuTree.recommend + .empty-tip").addClass('hidden');
var privCount = 0;
$.each(objTree.recommendData, function(index, item){if(item.children) privCount += item.children.length;});
$(".menuTree.recommend").closest('.priv-panel').find('.panel-title .priv-count').html('(' + privCount + ')');
}
else
{
$(".menuTree.recommend + .empty-tip").removeClass('hidden');
$(".menuTree.recommend").closest('.priv-panel').find('.panel-title .priv-count').html('');
}
if(!canDeleteRelation) $('.side a.priv-item .icon-close').remove();
}
/**
* Get relation side.
*
* @param int $privID
* @access public
* @return void
*/
function getSideRelation(privID)
{
$.get(createLink('group', 'ajaxGetPrivRelations', "privID=" + privID), function(data)
{
var objTree = {};
if(data)
privList = new Array();
$('#privList .group-item input:checked').each(function()
{
var relatedPriv = JSON.parse(data);
objTree.dependData = relatedPriv.depend;
objTree.recommendData = relatedPriv.recommend;
privList.push($(this).closest('.group-item').attr('data-id'));
});
}
$.get(createLink('group', 'ajaxGetDependentPrivs', 'privList=' + privList.toString()), function(data)
{
data = $.parseJSON(data);
if(data.depend == undefined || data.recommend.length > 0)
{
$('.side .menuTree.depend').empty();
$('.side .menuTree.depend').siblings('.empty-tip').show();
}
else
{
$(".menuTree.depend").data('zui.tree').reload(data.depend);
$('.side .menuTree.depend').siblings('.empty-tip').hide();
}
updatePrivTree(objTree);
})
}
/**
* Update depend and recommend privs.
*
* @param e $e
* @access public
* @return void
*/
function updateRelations(e)
{
if($('.bg-primary-pale').length) $('.bg-primary-pale').removeClass('bg-primary-pale');
$('#privListTable').length > 0 ? $(e.target).closest('tr').addClass('bg-primary-pale') : $(e.target).addClass('bg-primary-pale');
if(data.recommend == undefined || data.recommend.length > 0)
{
$('.side .menuTree.recommend').empty();
$('.side .menuTree.recommend').siblings('.empty-tip').show();
}
else
{
$(".menuTree.recommend").data('zui.tree').reload(data.recommend);
$('.side .menuTree.recommend').siblings('.empty-tip').hide();
}
var selectedID = $('#privListTable').length == 0 ? $(e.target).siblings('input:checkbox').data('id') : $(e.target).closest('tr').attr('data-id');
$('.side a#addDependent').attr('href', createLink('group', 'addRelation', "privIdList=" + selectedID + '&type=depend')).removeAttr('disabled');
$('.side a#addRecommendation').attr('href', createLink('group', 'addRelation', "privIdList=" + selectedID + '&type=recommend')).removeAttr('disabled');
if(!$('.side a#addDependent').hasClass('modaled')) $('.side a#addDependent,.side a#addRecommendation').modal().addClass('modaled');
getSideRelation(selectedID);
});
}
function checkAllChange()
@@ -245,7 +211,9 @@ function checkAllChange()
if(checked) $('input[type=checkbox]').attr('checked', checked);
if(!checked) $('input[type=checkbox]').removeAttr('checked');
$(this).closest('.priv-footer').siblings('#mainContent').find('#privList tbody .checkbox-indeterminate-block').removeClass('checkbox-indeterminate-block');
$('#privList tbody .checkbox-indeterminate-block').removeClass('checkbox-indeterminate-block');
$('.side .menuTree').empty();
$('.side .empty-tip').show();
}
else
{
@@ -260,11 +228,15 @@ function checkAllChange()
if(!checked) $children.find('input[type=checkbox]').removeAttr('checked');
changeParentChecked($(this), moduleName, packageID);
updatePrivTree(null);
}
}
$(function()
{
selectedPrivIdList = Object.values(selectedPrivIdList);
relatedPrivData = $.parseJSON(relatedPrivData);
initDependTree(relatedPrivData.depend);
if(relatedPrivData.depend) $(".menuTree.depend + .empty-tip").hide();
@@ -288,6 +260,17 @@ $(function()
var moduleName = $(this).closest('.group-item').attr('data-module');
var packageID = $(this).closest('.group-item').attr('data-package');
changeParentChecked($(this), moduleName, packageID);
var privID = $(this).closest('.group-item').attr('data-id');
if(privID != 0)
{
var index = selectedPrivIdList.indexOf(privID);
if(privID > 0 && index < 0 && checked) selectedPrivIdList.push(privID);
if(privID > 0 && index > -1 && !checked) selectedPrivIdList.splice(index, 1);
updatePrivTree(selectedPrivIdList);
}
});
$('#submit').click(function()
+2 -1
View File
@@ -145,7 +145,7 @@
<?php endif;?>
<td id='<?php echo $moduleName;?>' class='pv-10px' colspan='<?php echo !empty($lang->$moduleName->menus) ? 1 : 2?>'>
<?php foreach($privs as $privID => $priv):?>
<div class="group-item" data-module='<?php echo $moduleName;?>' data-package='<?php echo $packageID;?>'>
<div class="group-item" data-module='<?php echo $moduleName;?>' data-package='<?php echo $packageID;?>' data-id='<?php echo zget($priv, 'id', 0);?>'>
<div class="checkbox-primary">
<?php echo html::checkbox("actions[$priv->module]", array($priv->method => $priv->name), isset($groupPrivs[$priv->module][$priv->method]) ? $priv->method : '', "title='{$priv->name}' id='actions[$priv->module]$priv->method' data-id='$privID'");?>
</div>
@@ -202,6 +202,7 @@
<?php js::set('groupID', $groupID);?>
<?php js::set('menu', $menu);?>
<?php js::set('relatedPrivData', $relatedPrivData);?>
<?php js::set('selectedPrivIdList', isset($selectedPrivIdList) ? $selectedPrivIdList : array());?>
<script>
$(document).ready(function()
{