diff --git a/forms/ComplexTableField.php b/forms/ComplexTableField.php index 09abad26b..5baa99dec 100755 --- a/forms/ComplexTableField.php +++ b/forms/ComplexTableField.php @@ -133,16 +133,19 @@ class ComplexTableField extends TableListField { 'show' => array( 'label' => 'Show', 'icon' => 'cms/images/show.png', + 'icon_disabled' => 'cms/images/show_disabled.png', 'class' => 'popuplink showlink', ), 'edit' => array( 'label' => 'Edit', 'icon' => 'cms/images/edit.gif', + 'icon_disabled' => 'cms/images/show_disabled.png', 'class' => 'popuplink editlink', ), 'delete' => array( 'label' => 'Delete', 'icon' => 'cms/images/delete.gif', + 'icon_disabled' => 'cms/images/show_disabled.png', 'class' => 'popuplink deletelink', ), ); diff --git a/forms/TableListField.php b/forms/TableListField.php index 9aaa3ac15..bd117aabe 100755 --- a/forms/TableListField.php +++ b/forms/TableListField.php @@ -102,13 +102,19 @@ class TableListField extends FormField { * Actions can be disabled through $permissions. * Format (key is used for the methodname and CSS-class): * array( - * 'delete' => array('label' => 'Delete', 'icon' => 'cms/images/delete.gif') + * 'delete' => array( + * 'label' => 'Delete', + * 'icon' => 'cms/images/delete.gif', + * 'icon_disabled' => 'cms/images/delete_disabled.gif', + * 'class' => 'deletelink', + * ) * ) */ public $actions = array( 'delete' => array( 'label' => 'Delete', 'icon' => 'cms/images/delete.gif', + 'icon_disabled' => 'cms/images/delete_disabled.gif', 'class' => 'deletelink' ) ); @@ -677,7 +683,11 @@ JS */ /** - * Template accessor for Permissions + * Template accessor for Permissions. + * See {@link TableListField_Item->Can()} for object-specific + * permissions. + * + * @return boolean */ function Can($mode) { if($mode == 'add' && $this->isReadonly()) { @@ -1199,7 +1209,17 @@ JS * @see TableListField */ class TableListField_Item extends ViewableData { - protected $item, $parent; + + /** + * @var DataObject The underlying data record, + * usually an element of {@link TableListField->sourceItems()}. + */ + protected $item; + + /** + * @var TableListField + */ + protected $parent; function __construct($item, $parent) { $this->failover = $this->item = $item; @@ -1272,8 +1292,26 @@ class TableListField_Item extends ViewableData { return $this->parent->Markable; } + /** + * Checks global permissions for field in {@link TableListField->Can()}. + * If they are allowed, it checks for object permissions by assuming + * a method with "can" + $mode parameter naming, e.g. canDelete(). + * + * @param string $mode See {@link TableListField::$permissions} array. + * @return boolean + */ function Can($mode) { - return $this->parent->Can($mode); + $canMethod = "can" . ucfirst($mode); + if(!$this->parent->Can($mode)) { + // check global settings for the field instance + return false; + } elseif($this->item->hasMethod($canMethod)) { + // if global allows, check object specific permissions (e.g. canDelete()) + return $this->item->$canMethod(); + } else { + // otherwise global allowed this action, so return TRUE + return true; + } } function Link() { @@ -1303,9 +1341,11 @@ class TableListField_Item extends ViewableData { 'Name' => $actionName, 'Link' => $this->{ucfirst($actionName).'Link'}(), 'Icon' => $actionSettings['icon'], + 'IconDisabled' => $actionSettings['icon_disabled'], 'Label' => $actionSettings['label'], 'Class' => $actionSettings['class'], 'Default' => ($actionName == $this->parent->defaultAction), + 'IsAllowed' => $this->Can($actionName), ))); } } diff --git a/templates/Includes/TableListField_Item.ss b/templates/Includes/TableListField_Item.ss index 69c69d03a..414be8cb0 100755 --- a/templates/Includes/TableListField_Item.ss +++ b/templates/Includes/TableListField_Item.ss @@ -4,6 +4,16 @@ $Value <% end_control %> <% control Actions %> - <% if Icon %>$Label<% else %>$Label<% end_if %> + + <% if IsAllowed %> + + <% if Icon %>$Label<% else %>$Label<% end_if %> + + <% else %> + + <% if IconDisabled %>$Label<% else %>$Label<% end_if %> + + <% end_if %> + <% end_control %> \ No newline at end of file