Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions View/Acl/permissions.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<?php
$uglyIdent = Configure::read('AclManager.uglyIdent');
$lastIdent = null;
$permissionGroup = 0;
foreach ($acos as $id => $aco) {
$action = $aco['Action'];
$alias = $aco['Aco']['alias'];
Expand All @@ -27,16 +28,18 @@ foreach ($acos as $id => $aco) {
?></tr><?php
}
}
if ($ident != $lastIdent) {
?><tr class='aclmanager-ident-<?php echo $ident; ?>'><?php

if ($ident == 1) {
$permissionGroup = $permissionGroup +1;
}
?><tr><?php
?><td><?php echo ($ident == 1 ? "<strong>" : "" ) . ($uglyIdent ? str_repeat("&nbsp;&nbsp;", $ident) : "") . h($alias) . ($ident == 1 ? "</strong>" : "" ); ?></td>
<?php foreach ($aros as $aro):
$inherit = $this->Form->value("Perms." . str_replace("/", ":", $action) . ".{$aroAlias}:{$aro[$aroAlias]['id']}-inherit");
$allowed = $this->Form->value("Perms." . str_replace("/", ":", $action) . ".{$aroAlias}:{$aro[$aroAlias]['id']}");
$value = $inherit ? 'inherit' : null;
$icon = $this->Html->image(($allowed ? 'test-pass-icon.png' : 'test-fail-icon.png')); ?>
<td><?php echo $icon . " " . $this->Form->select("Perms." . str_replace("/", ":", $action) . ".{$aroAlias}:{$aro[$aroAlias]['id']}", array(array('inherit' => __('Inherit'), 'allow' => __('Allow'), 'deny' => __('Deny'))), array('empty' => __('No change'), 'value' => $value)); ?></td>
<td data-level='<?php echo $ident; ?>' data-controller='<?php echo "Perms" . str_replace("/", ":", $action) ; ?>'><?php echo $icon . " " . $this->Form->select("Perms." . str_replace("/", ":", $action) . ".{$aroAlias}:{$aro[$aroAlias]['id']}", array(array('inherit' => __('Inherit'), 'allow' => __('Allow'), 'deny' => __('Deny'))), array('empty' => __('No change'), 'value' => $value)); ?></td>
<?php endforeach; ?>
<?php
$lastIdent = $ident;
Expand Down Expand Up @@ -75,3 +78,6 @@ echo $this->Form->end(__("Save"));
<li><?php echo $this->Html->link(__('Drop permissions'), array('action' => 'drop_perms'), array(), __("Do you want to drop all the permissions?")); ?></li>
</ul>
</div>

<?php echo $this->Html->script('/AclManager/js/changePermissionsIcons.js'); ?>

109 changes: 109 additions & 0 deletions webroot/js/changePermissionsIcons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
* Change Permissions Icons
*
* A jQuery extension to change controllers's permissions icons.
*
* @author Pilar Rodriguez Cabrero - dongit.nl
*/

if (typeof jQuery != 'undefined') {
var notAllowIcon = "/img/test-fail-icon.png";
var allowIcon = "/img/test-pass-icon.png";

// Creating an inicial values with the icon for the "no changes" selected boxes
$( "select option:selected" ).each(function () {
if ( $(this).val() == '' ) {
select = $(this).parent()
$(select).data( 'init', $(select).prev().attr("src") )
}
})

// Funtion to set the icon
jQuery.fn.setIcon = function (icon) {
$(this).prev().attr( "src", icon )
}

// Check the children recursevely to change their icons
function checkChildren ( controllers_selection, level, newIcon ) {
$(controllers_selection).each(function() {
if ( $(this).attr('data-level') != level ) {
return
}
controllerName = $(this).attr('data-controller')
controllers_subselection = $(controllers_selection).filter(function() {
return $(this).attr('data-controller').match(controllerName + '+')
})
select = $(this).find('select')
// If 'inherit' option is selected, or if is selected 'no change' option and has no initial value, change his icon
if ( $(select).val() == 'inherit' || ( $(select).val() == '' && ( typeof $(select).data('init') === 'undefined' ))) {
$(select).setIcon(newIcon)
checkChildren( controllers_subselection, level + 1, newIcon )
}
})
}

// Check the parent's icon to set the value of the child's icon
function checkParent ( child, controllers_selection, controllerName, level ) {
if (level >= 0) {
// Select the controller name and drop the last part after :
parent_id = controllerName.split(':').slice( 0, level + 1 ).join(':')
$(controllers_selection).each(function() {
if ( $(this).attr('data-level') != level ) {
return
}
console.log(parent_id)
console.log($(this).attr('data-controller'))
if ( $(this).attr('data-controller') == parent_id ) {
newIcon = $(this).find('img').attr('src')
$(child).setIcon(newIcon)
controllers_selection = $(controllers_selection).filter(function() {
return $(this).attr('data-controller').match(controllerName + '+')
})
checkChildren( controllers_selection, level + 2, newIcon )
return false
}
})
}
// If is the root has no parent, so set the icon to 'not allow icon'
else {
$(child).setIcon(notAllowIcon)
checkChildren( controllers_selection, level + 1, notAllowIcon )
}
}

$('select').on('change', function() {
table_cell = $(this).parent().parent()
role = $(table_cell).find('td').index($(this).parent())
level = parseInt($(this).parent().attr('data-level'))
controllerName = $(this).parent().attr('data-controller')
role_column = $('tr').find('td:eq(' + role + ')')
// Select just the controllers that have to change their icons
controllers_selection = $(role_column).filter(function() {
return $(this).attr('data-controller').match(controllerName + '+')
})
switch( $(this).val() ) {
case 'deny' :
$(this).setIcon(notAllowIcon)
checkChildren( controllers_selection, level + 1, notAllowIcon )
break
case 'allow' :
$(this).setIcon(allowIcon)
checkChildren( controllers_selection, level + 1, allowIcon )
break
case 'inherit' :
checkParent( $(this), role_column, controllerName, level - 1 )
break
// If 'no change' is selected and if select has a previous value, set the icon to this value. Else set the icon to 'not allow icon' and check all
case '' :
if ( typeof $(this).data('init') !== 'undefined' ) {
$(this).setIcon($(this).data('init') )
checkChildren( controllers_selection, level + 1, $(this).data('init') )
}
else {
$(this).setIcon(notAllowIcon)
checkParent( $(this), role_column, controllerName, level - 1 )
}
break
}
})
}