Add spam row highlight

This commit is contained in:
Christopher Pitt 2015-04-17 12:36:15 +12:00
parent 0c698a813a
commit 5c71b2f141
4 changed files with 48 additions and 6 deletions

View File

@ -50,7 +50,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider {
$newComments = Comment::get()->filter('Moderated', 0);
$newGrid = new GridField(
$newGrid = new CommentsGridField(
'NewComments',
_t('CommentsAdmin.NewComments', 'New'),
$newComments,
@ -59,7 +59,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider {
$approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0);
$approvedGrid = new GridField(
$approvedGrid = new CommentsGridField(
'ApprovedComments',
_t('CommentsAdmin.ApprovedComments', 'Approved'),
$approvedComments,
@ -68,7 +68,7 @@ class CommentAdmin extends LeftAndMain implements PermissionProvider {
$spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1);
$spamGrid = new GridField(
$spamGrid = new CommentsGridField(
'SpamComments',
_t('CommentsAdmin.SpamComments', 'Spam'),
$spamComments,

View File

@ -0,0 +1,37 @@
<?php
class CommentsGridField extends GridField
{
/**
* {@inheritdoc}
*/
protected function newRow($gridfield, $total, $index, $record, $attributes, $content) {
$classes = array('ss-gridfield-item');
if($index == 0) {
$classes[] = 'first';
}
if($index == $total - 1) {
$classes[] = 'last';
}
$classes[] = ($index % 2) ? 'even' : 'odd';
if ($record->IsSpam) {
$classes[] = 'spam';
}
$attributes = array(
'class' => implode(' ', $classes),
'data-id' => $record->ID,
'data-class' => $record->ClassName,
);
return FormField::create_tag(
'tr',
$attributes,
$content
);
}
}

View File

@ -457,11 +457,13 @@ class CommentsExtension extends DataExtension {
* @param FieldList $fields
*/
protected function updateModerationFields(FieldList $fields) {
Requirements::css(COMMENTS_DIR . '/css/Comments.css');
$commentsConfig = CommentsGridFieldConfig::create();
$newComments = $this->owner->AllComments()->filter('Moderated', 0);
$newGrid = new GridField(
$newGrid = new CommentsGridField(
'NewComments',
_t('CommentsAdmin.NewComments', 'New'),
$newComments,
@ -470,7 +472,7 @@ class CommentsExtension extends DataExtension {
$approvedComments = $this->owner->AllComments()->filter('Moderated', 1)->filter('IsSpam', 0);
$approvedGrid = new GridField(
$approvedGrid = new CommentsGridField(
'ApprovedComments',
_t('CommentsAdmin.Comments', 'Approved'),
$approvedComments,
@ -479,7 +481,7 @@ class CommentsExtension extends DataExtension {
$spamComments = $this->owner->AllComments()->filter('Moderated', 1)->filter('IsSpam', 1);
$spamGrid = new GridField(
$spamGrid = new CommentsGridField(
'SpamComments',
_t('CommentsAdmin.SpamComments', 'Spam'),
$spamComments,

3
css/Comments.css Normal file
View File

@ -0,0 +1,3 @@
.cms table.ss-gridfield-table tr.spam {
background-color: #FFD8D8 ;
}