Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

MINOR Moved logics related to SSCP_Block from BlockHolderMain to anot…

…her controller.
  • Loading branch information...
commit 33979da457d6b9392df1d8031c33c995c4ca35cf 1 parent b8cee68
@yukiawano authored
View
1  code/blockholder/DefaultBlockHolder.php
@@ -21,7 +21,6 @@ class DefaultBlockHolder extends BlockHolderBase {
'DefaultSnippet' => 'SnippetBase'
);
-
public static $blockholder_name = 'Block Holder';
public function getCMSFields() {
View
20 code/blockholder/SSCP_Block.php
@@ -11,17 +11,29 @@ class SSCP_Block extends DataObject {
'SnippetBase' => 'SnippetBase'
);
+ public function getFields($blockHolderId) {
+ $fields = new FieldList();
+
+ $fields->push(new TextField('Title', 'Title'));
+ $fields->push(new TextField('AudienceType', 'AudienceType'));
+
+ return $fields;
+ }
+
public function getCMSFields() {
+ // $fields = parent::getCMSFields();
+
$fields = parent::getCMSFields();
+ // $fields->removeByName('BlockHolderID');
- $fields->removeByName('BlockHolderID');
- $fields->removeByName('AudienceType');
// Audience Types
+ /*
+ $env = CPEnvironment::getCPEnvironment();
$audienceTypeLoader = new AudienceTypeLoader();
- $audienceTypesArray = $audienceTypeLoader->getAudienceTypes($audienceTypeLoader->load());
+ $audienceTypesArray = $audienceTypeLoader->getAudienceTypes($env->getAudienceTypes());
$fields->push(new DropdownField('AudienceType', 'AudienceType', $audienceTypesArray));
-
+ */
return $fields;
}
View
79 code/controllers/BlockHolderMain.php
@@ -9,16 +9,15 @@ class BlockHolderMain extends LeftAndMain implements PermissionProvider {
static $url_segment = 'personalization';
static $url_rule = '/$Action/$ID/$OtherID';
+ static $url_priority = 39;
static $menu_title = 'Personalization';
static $menu_priority = -1;
-
+
static $allowed_actions = array(
'AddBlockHolderForm',
'doAddBlockHolder',
'AddSnippetForm',
- 'doAddSnippet',
- 'AddBlockForm',
- 'doAddBlock'
+ 'doAddSnippet'
);
function providePermissions() {
@@ -106,78 +105,6 @@ protected function getSnippetClasses() {
return $subClasses;
}
- public function addBlockForm(SS_HTTPRequest $request) {
- $blockHolderId = $request->getVar('block_holder_id');
-
- $obj = $this->customise(array(
- 'EditForm' => $this->getAddBlockForm($blockHolderId)
- ));
-
- if($request->isAjax()) {
- return $obj->renderWith($this->getTemplatesWithSuffix('_Content'));
- } else {
- return $obj->renderWith($this->getViewer('show'));
- }
- }
-
- public function getAddBlockForm($id = null, $fields = null) {
- $fields = new FieldList();
-
- $blockHolder = BlockHolderBase::get()->byID($id);
-
- // Snippet Bases
- $snippetBasesArray = array();
- $snippetBases = SnippetBase::get();
- foreach($snippetBases as $snippetBase) {
- $snippetBasesArray[$snippetBase->ID] = $snippetBase->Title;
- }
-
- // Audience Types
- $audienceTypeLoader = new AudienceTypeLoader();
- $env = CPEnvironment::getCPEnvironment();
- $audienceTypesArray = $audienceTypeLoader->getAudienceTypes($env->getAudienceTypes());
-
- $fields->push(new LabelField('description', "Create a new block to {$blockHolder->Title}."));
- $fields->push(new TextField('Title', 'Title'));
- $fields->push(new DropdownField('SnippetBaseID', 'SnippetBase', $snippetBasesArray));
- $fields->push(new DropdownField('AudienceType', 'AudienceType', $audienceTypesArray));
- $fields->push(new HiddenField('BlockHolderID', 'BlockHolderID', $id));
-
- $actions = new FieldList(
- FormAction::create('doAddBlock')
- ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
- ->setTitle('Create Block')
- );
-
- $form = new Form($this, "doAddBlock", $fields, $actions);
- $form->addExtraClass('add-form cms-add-form cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());
- $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
-
- return $form;
- }
-
- public function doAddBlock(SS_HTTPRequest $request) {
- $title = $request->postVar('Title');
- $snippetBaseID = $request->postVar('SnippetBaseID');
- $audienceType = $request->postVar('AudienceType');
- $blockHolderID = $request->postVar('BlockHolderID');
-
- $sscpBlock = new SSCP_Block();
- $sscpBlock->Title = $title;
- $sscpBlock->BlockHolderID = $blockHolderID;
- $sscpBlock->SnippetBaseID = $snippetBaseID;
- $sscpBlock->AudienceType = $audienceType;
- $sscpBlock->write();
-
- $link = Controller::join_links(
- $this->stat('url_base', true),
- "personalization/EditForm/field/BlockHolders/item/{$blockHolderID}/edit/"
- );
-
- $this->response->addHeader('X-Status', 'Created new block.');
- return $this->redirect($link);
- }
-
public function addBlockHolderForm(SS_HTTPRequest $request) {
$obj = $this->customise(array(
'EditForm' => $this->getAddBlockHolderForm()
View
97 code/controllers/SSCP_BlockController.php
@@ -0,0 +1,97 @@
+<?php
+class SSCP_BlockController extends LeftAndMain {
+
+ static $url_segment = 'personalization/sscpblock';
+ static $url_rule = '/$Action/$ID/$OtherID';
+ static $url_priority = 42;
+ static $menu_title = 'SSCP Block';
+ static $required_permission_codes = 'CMS_ACCESS_CMSMain';
+
+ static $allowed_actions = array(
+ 'addForm',
+ 'doAdd'
+ );
+
+ public function init() {
+ parent::init();
+ Requirements::css(SSCP_DIR . '/css/SSCP_BlockController.css');
+ }
+
+ /**
+ * Return addForm for SSCP_Block
+ * @param SS_HTTPRequest $request
+ */
+ public function addForm(SS_HTTPRequest $request) {
+ $blockHolderId = $request->getVar('block_holder_id');
+
+ $obj = $this->customise(
+ array('EditForm' => $this->getAddBlockForm($blockHolderId))
+ );
+
+ if($request->isAjax()) {
+ // Rendering is handled by template, which will call EditForm() eventually
+ return $obj->renderWith($this->getTemplatesWithSuffix('_Content'));
+ } else {
+ return $obj->renderWith($this->getViewer('show'));
+ }
+ }
+
+ public function getAddBlockForm($id = null, $fields = null) {
+ $fields = new FieldList();
+
+ $blockHolder = BlockHolderBase::get()->byID($id);
+
+ // Snippet Bases
+ $snippetBasesArray = array();
+ $snippetBases = SnippetBase::get();
+ foreach($snippetBases as $snippetBase) {
+ $snippetBasesArray[$snippetBase->ID] = $snippetBase->Title;
+ }
+
+ // Audience Types
+ $fields->push(new LabelField('description', "Create a new block to {$blockHolder->Title}."));
+ $fields->push(new TextField('Title', 'Title'));
+ $fields->push(new DropdownField('SnippetBaseID', 'SnippetBase', $snippetBasesArray));
+ $fields->push(new TextField('AudienceType', 'Audience Type'));
+ $fields->push(new HiddenField('BlockHolderID', 'BlockHolderID', $id));
+
+ $actions = new FieldList(
+ FormAction::create('doAdd')
+ ->addExtraClass('ss-ui-action-constructive')->setAttribute('data-icon', 'accept')
+ ->setTitle('Create Block')
+ );
+
+ $form = new Form($this, "doAdd", $fields, $actions);
+ $form->addExtraClass('add-form cms-add-form cms-edit-form cms-panel-padded center ' . $this->BaseCSSClasses());
+ $form->setTemplate($this->getTemplatesWithSuffix('_EditForm'));
+
+ return $form;
+ }
+
+ /**
+ * Add SSCP Block
+ * @param SS_HTTPRequest $request
+ */
+ public function doAdd(SS_HTTPRequest $request) {
+ $title = $request->postVar('Title');
+ $snippetBaseID = $request->postVar('SnippetBaseID');
+ $audienceType = $request->postVar('AudienceType');
+ $blockHolderID = $request->postVar('BlockHolderID');
+
+ $sscpBlock = new SSCP_Block();
+ $sscpBlock->Title = $title;
+ $sscpBlock->BlockHolderID = $blockHolderID;
+ $sscpBlock->SnippetBaseID = $snippetBaseID;
+ $sscpBlock->AudienceType = $audienceType;
+ $sscpBlock->write();
+
+ $link = Controller::join_links(
+ $this->stat('url_base', true),
+ "personalization/EditForm/field/BlockHolders/item/{$blockHolderID}/edit/"
+ );
+
+ $this->response->addHeader('X-Status', 'Created new block.');
+ return $this->redirect($link);
+ }
+
+}
View
2  code/controllers/actions/GridFieldAddNewBlockButton.php
@@ -12,7 +12,7 @@ public function __construct($id, $targetFragment = 'before') {
public function getHTMLFragments($gridField) {
$newLink = Controller::join_links(
$gridField->stat('url_base', true),
- "admin/personalization/AddBlockForm/?block_holder_id={$this->id}"
+ "admin/personalization/sscpblock/addForm/?block_holder_id={$this->id}"
);
$data = new ArrayData(array(
View
5 css/SSCP_BlockController.css
@@ -0,0 +1,5 @@
+@CHARSET "UTF-8";
+
+#Menu-SSCP_BlockController{
+ display: none;
+}
View
32 templates/Includes/SSCP_BlockController_Content.ss
@@ -0,0 +1,32 @@
+<div id="block-holder-main-controller-cms-content" class="cms-content center cms-tabset $BaseCSSClasses" data-layout-type="border" data-pjax-fragment="Content CurrentForm">
+
+ <div class="cms-content-header north">
+ <% with EditForm %>
+ <div class="cms-content-header-info">
+ <h2>
+ <% with Controller %>
+ <% include CMSBreadcrumbs %>
+ <% end_with %>
+ </h2>
+ </div>
+ <% if Fields.hasTabset %>
+ <% with Fields.fieldByName('Root') %>
+ <div class="cms-content-header-tabs">
+ <ul>
+ <% loop Tabs %>
+ <li<% if extraClass %> class="$extraClass"<% end_if %>><a href="#$id">$Title</a></li>
+ <% end_loop %>
+ </ul>
+ </div>
+ <% end_with %>
+ <% end_if %>
+ <% end_with %>
+ </div>
+
+ <div class="cms-content-fields center ui-widget-content" data-layout-type="border">
+
+ $EditForm
+
+ </div>
+
+</div>
View
24 templates/Includes/SSCP_BlockController_EditForm.ss
@@ -0,0 +1,24 @@
+<form $FormAttributes>
+
+ <% if Message %>
+ <p id="{$FormName}_error" class="message $MessageType">$Message</p>
+ <% else %>
+ <p id="{$FormName}_error" class="message $MessageType" style="display: none"></p>
+ <% end_if %>
+
+ <fieldset>
+ <% if Legend %><legend>$Legend</legend><% end_if %>
+ <% loop Fields %>
+ $FieldHolder
+ <% end_loop %>
+ <div class="clear"><!-- --></div>
+ </fieldset>
+
+ <% if Actions %>
+ <div class="Actions">
+ <% loop Actions %>
+ $Field
+ <% end_loop %>
+ </div>
+ <% end_if %>
+</form>
Please sign in to comment.
Something went wrong with that request. Please try again.