NEW: Add BulkEditing tool for managing comments. (Fixes #9)

This commit is contained in:
Will Rossiter 2013-12-21 12:19:11 +13:00
parent 5cfa476264
commit 5f6336646a
3 changed files with 60 additions and 3 deletions

View File

@ -46,7 +46,17 @@ class CommentAdmin extends LeftAndMain {
new GridFieldDetailForm(), new GridFieldDetailForm(),
new GridFieldExportButton(), new GridFieldExportButton(),
new GridFieldEditButton(), new GridFieldEditButton(),
new GridFieldDetailForm() new GridFieldDetailForm(),
$manager = new GridFieldBulkManager()
);
$manager->addBulkAction(
'markAsSpam', 'Mark as spam', 'CommentsGridFieldBulkAction_MarkAsSpam',
array(
'isAjax' => true,
'icon' => 'delete',
'isDestructive' => true
)
); );
$needs = new GridField( $needs = new GridField(

View File

@ -0,0 +1,46 @@
<?php
/**
* @package comments
*/
class CommentsGridFieldBulkAction extends GridFieldBulkActionHandler {
}
/**
* A {@link GridFieldBulkActionHandler} for bulk marking comments as spam
*
* @package comments
*/
class CommentsGridFieldBulkAction_MarkAsSpam extends CommentsGridFieldBulkAction {
private static $allowed_actions = array(
'markAsSpam'
);
private static $url_handlers = array(
'markAsSpam' => 'markAsSpam'
);
public function markAsSpam(SS_HTTPRequest $request) {
$ids = array();
foreach($this->getRecords() as $record) {
array_push($ids, $record->ID);
$record->Moderated = 1;
$record->IsSpam = 1;
$record->write();
}
$response = new SS_HTTPResponse(Convert::raw2json(array(
'done' => true,
'records' => $ids
)));
$response->addHeader('Content-Type', 'text/json');
return $response;
}
}

View File

@ -8,7 +8,8 @@
"email": "will@fullscreen.io" "email": "will@fullscreen.io"
}], }],
"require": { "require": {
"silverstripe/framework": "~3.1" "silverstripe/framework": "~3.1",
"colymba/gridfield-bulk-editing-tools": "dev-master"
}, },
"suggest": { "suggest": {
"ezyang/htmlpurifier": "4.*" "ezyang/htmlpurifier": "4.*"