mirror of
https://github.com/silverstripe/silverstripe-contentreview
synced 2024-10-22 17:05:47 +02:00
Merge pull request #33 from scott1702/master
Make contentreview an inline form
This commit is contained in:
commit
c6d9df1ae2
@ -10,6 +10,9 @@ Member:
|
|||||||
CMSPageEditController:
|
CMSPageEditController:
|
||||||
extensions:
|
extensions:
|
||||||
- ContentReviewCMSExtension
|
- ContentReviewCMSExtension
|
||||||
|
CMSPageSettingsController:
|
||||||
|
extensions:
|
||||||
|
- ContentReviewCMSExtension
|
||||||
SiteConfig:
|
SiteConfig:
|
||||||
extensions:
|
extensions:
|
||||||
- ContentReviewDefaultSettings
|
- ContentReviewDefaultSettings
|
@ -11,59 +11,9 @@ class ContentReviewCMSExtension extends LeftAndMainExtension
|
|||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
private static $allowed_actions = array(
|
private static $allowed_actions = array(
|
||||||
"reviewed",
|
"savereview"
|
||||||
"AddReviewForm",
|
|
||||||
);
|
);
|
||||||
|
|
||||||
/**
|
|
||||||
* Shows a form with review notes.
|
|
||||||
*
|
|
||||||
* @param array $data
|
|
||||||
* @param Form $form
|
|
||||||
*
|
|
||||||
* @return SS_HTTPResponse
|
|
||||||
* @throws SS_HTTPResponse_Exception
|
|
||||||
*/
|
|
||||||
public function reviewed($data, Form $form)
|
|
||||||
{
|
|
||||||
$record = $this->findRecord($data);
|
|
||||||
if (!$record->canEdit()) {
|
|
||||||
return Security::permissionFailure($this->owner);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Populate and respond
|
|
||||||
$form = $this->AddReviewForm();
|
|
||||||
$form->loadDataFrom($record);
|
|
||||||
return $form->forTemplate();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Form handler for this page
|
|
||||||
*
|
|
||||||
* @return CMSForm
|
|
||||||
*/
|
|
||||||
public function AddReviewForm()
|
|
||||||
{
|
|
||||||
$reviewNotes = TextareaField::create("ReviewNotes", _t("ContentReview.REVIEWNOTES", "Review notes"));
|
|
||||||
$reviewNotes->setDescription(_t("ContentReview.REVIEWNOTESDESCRIPTION ", "Add comments for the content of this page."));
|
|
||||||
$fields = new FieldList();
|
|
||||||
$fields->push(HiddenField::create("ID"));
|
|
||||||
$fields->push($reviewNotes);
|
|
||||||
|
|
||||||
$actions = new FieldList(
|
|
||||||
FormAction::create("save_review", _t("ContentReview.SAVE", "Save"))
|
|
||||||
);
|
|
||||||
|
|
||||||
$form = CMSForm::create($this->owner, "AddReviewForm", $fields, $actions)->setHTMLID("Form_EditForm");
|
|
||||||
$form->setResponseNegotiator($this->owner->getResponseNegotiator());
|
|
||||||
$form->disableDefaultAction();
|
|
||||||
|
|
||||||
// TODO Can't merge $FormAttributes in template at the moment
|
|
||||||
$form->setTemplate($this->owner->getTemplatesWithSuffix("LeftAndMain_EditForm"));
|
|
||||||
|
|
||||||
return $form;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the review notes and redirect back to the page edit form.
|
* Save the review notes and redirect back to the page edit form.
|
||||||
*
|
*
|
||||||
@ -74,17 +24,19 @@ class ContentReviewCMSExtension extends LeftAndMainExtension
|
|||||||
*
|
*
|
||||||
* @throws SS_HTTPResponse_Exception
|
* @throws SS_HTTPResponse_Exception
|
||||||
*/
|
*/
|
||||||
public function save_review($data, Form $form)
|
public function savereview($data, Form $form)
|
||||||
{
|
{
|
||||||
$page = $this->findRecord($data);
|
$page = $this->findRecord($data);
|
||||||
if (!$page->canEdit()) {
|
if (!$page->canEdit()) {
|
||||||
return Security::permissionFailure($this->owner);
|
return Security::permissionFailure($this->owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
$page->addReviewNote(Member::currentUser(), $data["ReviewNotes"]);
|
$notes = (!empty($data["ReviewNotes"]) ? $data["ReviewNotes"] : _t("ContentReview.NOCOMMENTS", "(no comments)"));
|
||||||
|
$page->addReviewNote(Member::currentUser(), $notes);
|
||||||
$page->advanceReviewDate();
|
$page->advanceReviewDate();
|
||||||
|
|
||||||
return $this->owner->redirect($this->owner->Link("show/" . $page->ID));
|
$this->owner->getResponse()->addHeader("X-Status", _t("ContentReview.REVIEWSUCCESSFUL", "Content reviewed successfully"));
|
||||||
|
return $this->owner->redirectBack();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -119,11 +119,25 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
|
|||||||
public function updateCMSActions(FieldList $actions)
|
public function updateCMSActions(FieldList $actions)
|
||||||
{
|
{
|
||||||
if ($this->canBeReviewedBy(Member::currentUser())) {
|
if ($this->canBeReviewedBy(Member::currentUser())) {
|
||||||
$reviewAction = FormAction::create("reviewed", _t("ContentReview.BUTTONREVIEWED", "Review content"))
|
Requirements::css("contentreview/css/contentreview.css");
|
||||||
->setAttribute("data-icon", "pencil")
|
|
||||||
->setAttribute("data-text-alternate", _t("ContentReview.BUTTONREVIEWED", "Review content"));
|
|
||||||
|
|
||||||
$actions->push($reviewAction);
|
$reviewTitle = LiteralField::create(
|
||||||
|
"ReviewContentNotesLabel",
|
||||||
|
"<label class=\"left\" for=\"Form_EditForm_ReviewNotes\">" . _t("ContentReview.CONTENTREVIEW", "Content due for review") . "</label>"
|
||||||
|
);
|
||||||
|
|
||||||
|
$ReviewNotes = LiteralField::create("ReviewNotes", "<textarea class=\"no-change-track\" id=\"Form_EditForm_ReviewNotes\" name=\"ReviewNotes\" placeholder=\"" . _t("ContentReview.COMMENTS", "(optional) Add comments...") . "\" class=\"text\"></textarea>");
|
||||||
|
|
||||||
|
$quickReviewAction = FormAction::create("savereview", _t("ContentReview.MARKREVIEWED", "Mark as reviewed"))
|
||||||
|
->setAttribute("data-text-alternate", _t("ContentReview.MARKREVIEWED", "Mark as reviewed"));
|
||||||
|
|
||||||
|
$allFields = CompositeField::create($reviewTitle, $ReviewNotes, $quickReviewAction)
|
||||||
|
->addExtraClass('review-notes field');
|
||||||
|
|
||||||
|
$reviewTab = Tab::create('ReviewContent', $allFields);
|
||||||
|
$reviewTab->addExtraClass('contentreview-tab');
|
||||||
|
|
||||||
|
$actions->fieldByName('ActionMenus')->insertBefore($reviewTab, 'MoreOptions');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
36
css/contentreview.css
Normal file
36
css/contentreview.css
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
.review-notes textarea {
|
||||||
|
resize: none;
|
||||||
|
width: 284px;
|
||||||
|
height: 60px;
|
||||||
|
box-sizing: border-box;
|
||||||
|
margin: 4px 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cms .ss-ui-action-tabset.action-menus.ss-tabset .ui-tabs-panel .review-notes label.left {
|
||||||
|
padding: 0;
|
||||||
|
margin: 0 0 4px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cms .ss-ui-action-tabset.action-menus.ss-tabset .ui-tabs-panel .review-notes .cms-sitetree-information p.meta-info {
|
||||||
|
color: #f46b00;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cms .ss-ui-action-tabset.action-menus.ss-tabset ul.ui-tabs-nav li.contentreview-tab a {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
background: url('../images/icon-bell.png') center center no-repeat;
|
||||||
|
background-position: 0 0;
|
||||||
|
text-indent: -9999px;
|
||||||
|
padding: 0;
|
||||||
|
margin: 2px 4px 0 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cms .ss-ui-action-tabset.action-menus.ss-tabset ul.ui-tabs-nav li.contentreview-tab a:hover,
|
||||||
|
.cms .ss-ui-action-tabset.action-menus.ss-tabset ul.ui-tabs-nav li.contentreview-tab a:focus {
|
||||||
|
background-position: 0 -20px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.cms .ss-ui-action-tabset.action-menus.ss-tabset .ui-tabs-panel.contentreview-tab {
|
||||||
|
max-width: 300px;
|
||||||
|
}
|
BIN
images/icon-bell.png
Normal file
BIN
images/icon-bell.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 364 B |
@ -30,7 +30,7 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
|
|||||||
|
|
||||||
$dummyForm = new CMSForm($controller, "EditForm", new FieldList(), new FieldList());
|
$dummyForm = new CMSForm($controller, "EditForm", new FieldList(), new FieldList());
|
||||||
|
|
||||||
$controller->reviewed(array(
|
$controller->savereview(array(
|
||||||
"ID" => null,
|
"ID" => null,
|
||||||
"Message" => null,
|
"Message" => null,
|
||||||
), $dummyForm);
|
), $dummyForm);
|
||||||
@ -45,7 +45,7 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
|
|||||||
|
|
||||||
$dummyForm = new CMSForm($controller, "EditForm", new FieldList(), new FieldList());
|
$dummyForm = new CMSForm($controller, "EditForm", new FieldList(), new FieldList());
|
||||||
|
|
||||||
$controller->reviewed(array(
|
$controller->savereview(array(
|
||||||
"ID" => "FAIL",
|
"ID" => "FAIL",
|
||||||
"Message" => null,
|
"Message" => null,
|
||||||
), $dummyForm);
|
), $dummyForm);
|
||||||
@ -62,10 +62,11 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
|
|||||||
$page = $this->objFromFixture("Page", "home");
|
$page = $this->objFromFixture("Page", "home");
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
"action_reviewed" => 1,
|
"action_savereview" => 1,
|
||||||
"ID" => $page->ID,
|
"ID" => $page->ID,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->get('admin/pages/edit/show/' . $page->ID);
|
||||||
$response = $this->post("admin/pages/edit/EditForm", $data);
|
$response = $this->post("admin/pages/edit/EditForm", $data);
|
||||||
|
|
||||||
$this->assertEquals("OK", $response->getStatusDescription());
|
$this->assertEquals("OK", $response->getStatusDescription());
|
||||||
@ -83,12 +84,13 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest
|
|||||||
$page = $this->objFromFixture("Page", "home");
|
$page = $this->objFromFixture("Page", "home");
|
||||||
|
|
||||||
$data = array(
|
$data = array(
|
||||||
"action_save_review" => 1,
|
"action_savereview" => 1,
|
||||||
"ID" => $page->ID,
|
"ID" => $page->ID,
|
||||||
"ReviewNotes" => "This is the best page ever",
|
"ReviewNotes" => "This is the best page ever",
|
||||||
);
|
);
|
||||||
|
|
||||||
$response = $this->post("admin/pages/edit/AddReviewForm", $data);
|
$this->get('admin/pages/edit/show/' . $page->ID);
|
||||||
|
$response = $this->post("admin/pages/edit/EditForm", $data);
|
||||||
|
|
||||||
$this->assertEquals("OK", $response->getStatusDescription());
|
$this->assertEquals("OK", $response->getStatusDescription());
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
|
@ -258,7 +258,7 @@ class SiteTreeContentReviewTest extends ContentReviewBaseTest
|
|||||||
|
|
||||||
$fields = $page->getCMSActions();
|
$fields = $page->getCMSActions();
|
||||||
|
|
||||||
$this->assertNotNull($fields->fieldByName("action_reviewed"));
|
$this->assertNotNull($fields->fieldByName("ActionMenus.ReviewContent"));
|
||||||
|
|
||||||
SS_Datetime::clear_mock_now();
|
SS_Datetime::clear_mock_now();
|
||||||
}
|
}
|
||||||
@ -277,7 +277,7 @@ class SiteTreeContentReviewTest extends ContentReviewBaseTest
|
|||||||
|
|
||||||
$fields = $page->getCMSActions();
|
$fields = $page->getCMSActions();
|
||||||
|
|
||||||
$this->assertNull($fields->fieldByName("action_reviewed"));
|
$this->assertNull($fields->fieldByName("ActionMenus.ReviewContent"));
|
||||||
|
|
||||||
SS_Datetime::clear_mock_now();
|
SS_Datetime::clear_mock_now();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user