From 0610b12a4a720c3848f94ce1c3c3ded7d4f91e55 Mon Sep 17 00:00:00 2001 From: scott1702 Date: Thu, 12 Nov 2015 15:56:19 +1300 Subject: [PATCH] Make contentreview an inline form --- _config/config.yml | 3 + code/extensions/ContentReviewCMSExtension.php | 64 +++--------------- code/extensions/SiteTreeContentReview.php | 24 +++++-- css/contentreview.css | 36 ++++++++++ images/icon-bell.png | Bin 0 -> 364 bytes ...ContentReviewCMSPageEditControllerTest.php | 14 ++-- tests/SiteTreeContentReviewTest.php | 4 +- 7 files changed, 76 insertions(+), 69 deletions(-) create mode 100644 css/contentreview.css create mode 100644 images/icon-bell.png diff --git a/_config/config.yml b/_config/config.yml index 7f17b79..fe226a2 100644 --- a/_config/config.yml +++ b/_config/config.yml @@ -10,6 +10,9 @@ Member: CMSPageEditController: extensions: - ContentReviewCMSExtension +CMSPageSettingsController: + extensions: + - ContentReviewCMSExtension SiteConfig: extensions: - ContentReviewDefaultSettings \ No newline at end of file diff --git a/code/extensions/ContentReviewCMSExtension.php b/code/extensions/ContentReviewCMSExtension.php index af64c11..1504ba5 100644 --- a/code/extensions/ContentReviewCMSExtension.php +++ b/code/extensions/ContentReviewCMSExtension.php @@ -11,59 +11,9 @@ class ContentReviewCMSExtension extends LeftAndMainExtension * @var array */ private static $allowed_actions = array( - "reviewed", - "AddReviewForm", + "savereview" ); - /** - * 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. * @@ -74,19 +24,21 @@ class ContentReviewCMSExtension extends LeftAndMainExtension * * @throws SS_HTTPResponse_Exception */ - public function save_review($data, Form $form) + public function savereview($data, Form $form) { $page = $this->findRecord($data); if (!$page->canEdit()) { 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(); - - 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(); } - + /** * Find the page this form is updating * diff --git a/code/extensions/SiteTreeContentReview.php b/code/extensions/SiteTreeContentReview.php index 65ee758..604db7e 100644 --- a/code/extensions/SiteTreeContentReview.php +++ b/code/extensions/SiteTreeContentReview.php @@ -119,11 +119,25 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider public function updateCMSActions(FieldList $actions) { if ($this->canBeReviewedBy(Member::currentUser())) { - $reviewAction = FormAction::create("reviewed", _t("ContentReview.BUTTONREVIEWED", "Review content")) - ->setAttribute("data-icon", "pencil") - ->setAttribute("data-text-alternate", _t("ContentReview.BUTTONREVIEWED", "Review content")); - - $actions->push($reviewAction); + Requirements::css("contentreview/css/contentreview.css"); + + $reviewTitle = LiteralField::create( + "ReviewContentNotesLabel", + "" + ); + + $ReviewNotes = LiteralField::create("ReviewNotes", ""); + + $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'); } } diff --git a/css/contentreview.css b/css/contentreview.css new file mode 100644 index 0000000..b1be29d --- /dev/null +++ b/css/contentreview.css @@ -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; +} \ No newline at end of file diff --git a/images/icon-bell.png b/images/icon-bell.png new file mode 100644 index 0000000000000000000000000000000000000000..d584c46e1dc622100c10a6284d4c3df4c83d27e5 GIT binary patch literal 364 zcmeAS@N?(olHy`uVBq!ia0vp^B0#Lc!3HG%8Q!`Lq&N#aB8wRqxP?KOkzv*x380{4 ziEBhjaDG}zd16s2gJVj5QmTSyZen_BP-Trf%^cTkwVF!s9xA;{gIZWO#O}KPC z@w%%**?}|-VY%rqAAg)_cjYOMi)4qlp<$N69-fl93=^vSQ)DEV_SQB|;O6!4C}TQO zH8aOSoSD_*!ukgDpawywuw!g)Jj!SH_}st5<~~d0$kcw$D#=wF1wB^?&QD|xKhWpE ztbg3;mB`(r&1?M_ck!gpWh&9lEakdj&{WE0<~;Mmj+_bCG##!_3|Y>w*EVYTg-w2p zZXA)4(h`P;m--!?sK#3OG`T6REz4zP@CQjV6R(^G24;qb98>O0GQap77zhlWu6{1- HoD!M<8Y_ZS literal 0 HcmV?d00001 diff --git a/tests/ContentReviewCMSPageEditControllerTest.php b/tests/ContentReviewCMSPageEditControllerTest.php index 77a913a..32cd4ba 100644 --- a/tests/ContentReviewCMSPageEditControllerTest.php +++ b/tests/ContentReviewCMSPageEditControllerTest.php @@ -30,7 +30,7 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest $dummyForm = new CMSForm($controller, "EditForm", new FieldList(), new FieldList()); - $controller->reviewed(array( + $controller->savereview(array( "ID" => null, "Message" => null, ), $dummyForm); @@ -45,7 +45,7 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest $dummyForm = new CMSForm($controller, "EditForm", new FieldList(), new FieldList()); - $controller->reviewed(array( + $controller->savereview(array( "ID" => "FAIL", "Message" => null, ), $dummyForm); @@ -62,10 +62,11 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest $page = $this->objFromFixture("Page", "home"); $data = array( - "action_reviewed" => 1, + "action_savereview" => 1, "ID" => $page->ID, ); + $this->get('admin/pages/edit/show/' . $page->ID); $response = $this->post("admin/pages/edit/EditForm", $data); $this->assertEquals("OK", $response->getStatusDescription()); @@ -83,13 +84,14 @@ class ContentReviewCMSPageEditControllerTest extends ContentReviewBaseTest $page = $this->objFromFixture("Page", "home"); $data = array( - "action_save_review" => 1, + "action_savereview" => 1, "ID" => $page->ID, "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(200, $response->getStatusCode()); $this->assertEquals(1, $page->ReviewLogs()->count()); diff --git a/tests/SiteTreeContentReviewTest.php b/tests/SiteTreeContentReviewTest.php index 858f816..b5e0971 100644 --- a/tests/SiteTreeContentReviewTest.php +++ b/tests/SiteTreeContentReviewTest.php @@ -258,7 +258,7 @@ class SiteTreeContentReviewTest extends ContentReviewBaseTest $fields = $page->getCMSActions(); - $this->assertNotNull($fields->fieldByName("action_reviewed")); + $this->assertNotNull($fields->fieldByName("ActionMenus.ReviewContent")); SS_Datetime::clear_mock_now(); } @@ -277,7 +277,7 @@ class SiteTreeContentReviewTest extends ContentReviewBaseTest $fields = $page->getCMSActions(); - $this->assertNull($fields->fieldByName("action_reviewed")); + $this->assertNull($fields->fieldByName("ActionMenus.ReviewContent")); SS_Datetime::clear_mock_now(); }