mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 14:05:37 +02:00
ENHANCEMENT Allowing item-specific permissions in TableListField and subclasses (through TableListField_Item->Can() and DataObject->can*() methods). Adding "disabled" icons to template.
git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@73028 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
parent
982c2142de
commit
4499d1a8d0
@ -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',
|
||||
),
|
||||
);
|
||||
|
@ -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),
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
@ -4,6 +4,16 @@
|
||||
<td class="field-$Title.HTMLATT $FirstLast">$Value</td>
|
||||
<% end_control %>
|
||||
<% control Actions %>
|
||||
<td width="16"><a class="$Class" href="$Link"><% if Icon %><img src="$Icon" alt="$Label" /><% else %>$Label<% end_if %></a></td>
|
||||
<td width="16">
|
||||
<% if IsAllowed %>
|
||||
<a class="$Class" href="$Link">
|
||||
<% if Icon %><img src="$Icon" alt="$Label" /><% else %>$Label<% end_if %>
|
||||
</a>
|
||||
<% else %>
|
||||
<span class="disabled">
|
||||
<% if IconDisabled %><img src="$IconDisabled" alt="$Label" /><% else %>$Label<% end_if %>
|
||||
</span>
|
||||
<% end_if %>
|
||||
</td>
|
||||
<% end_control %>
|
||||
</tr>
|
Loading…
Reference in New Issue
Block a user