From bf8bc1d856602d13d51c7c1bf7e48b6ca73163c1 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 30 Apr 2011 16:49:36 +1200 Subject: [PATCH 1/7] MINOR Added CMSPageHistoryController, CMSPageReportsController, marked placeholders for new functionality in AssetAdmin --- _config.php | 4 +++- code/controller/CMSPageHistoryController.php | 12 ++++++++++++ code/controller/CMSPageReportsController.php | 12 ++++++++++++ templates/Includes/AssetAdmin_Content.ss | 4 ++-- .../Includes/CMSPageHistoryController_Content.ss | 3 +++ .../Includes/CMSPageReportsController_Content.ss | 3 +++ templates/Includes/CMSPagesController_Content.ss | 8 ++------ 7 files changed, 37 insertions(+), 9 deletions(-) create mode 100644 code/controller/CMSPageHistoryController.php create mode 100644 code/controller/CMSPageReportsController.php create mode 100644 templates/Includes/CMSPageHistoryController_Content.ss create mode 100644 templates/Includes/CMSPageReportsController_Content.ss diff --git a/_config.php b/_config.php index b4cf76ec..97caa90f 100644 --- a/_config.php +++ b/_config.php @@ -32,4 +32,6 @@ Object::add_extension('File', 'SiteTreeFileExtension'); // TODO Remove once we can configure CMSMenu through static, nested configuration files CMSMenu::remove_menu_item('CMSPageEditController'); -CMSMenu::remove_menu_item('CMSPageSettingsController'); \ No newline at end of file +CMSMenu::remove_menu_item('CMSPageSettingsController'); +CMSMenu::remove_menu_item('CMSPageHistoryController'); +CMSMenu::remove_menu_item('CMSPageReportsController'); \ No newline at end of file diff --git a/code/controller/CMSPageHistoryController.php b/code/controller/CMSPageHistoryController.php new file mode 100644 index 00000000..2a1c38d2 --- /dev/null +++ b/code/controller/CMSPageHistoryController.php @@ -0,0 +1,12 @@ +
- ... + Not implemented yet
- ... + Not implemented yet
diff --git a/templates/Includes/CMSPageHistoryController_Content.ss b/templates/Includes/CMSPageHistoryController_Content.ss new file mode 100644 index 00000000..eca8c331 --- /dev/null +++ b/templates/Includes/CMSPageHistoryController_Content.ss @@ -0,0 +1,3 @@ +
+ Not implemented yet +
\ No newline at end of file diff --git a/templates/Includes/CMSPageReportsController_Content.ss b/templates/Includes/CMSPageReportsController_Content.ss new file mode 100644 index 00000000..eca8c331 --- /dev/null +++ b/templates/Includes/CMSPageReportsController_Content.ss @@ -0,0 +1,3 @@ +
+ Not implemented yet +
\ No newline at end of file diff --git a/templates/Includes/CMSPagesController_Content.ss b/templates/Includes/CMSPagesController_Content.ss index ade81db3..f609a883 100644 --- a/templates/Includes/CMSPagesController_Content.ss +++ b/templates/Includes/CMSPagesController_Content.ss @@ -38,10 +38,6 @@ $SiteTreeAsUL -
- <% include CMSPagesController_ContentToolbar %> -
-
$AddForm
@@ -49,11 +45,11 @@
- ... + Not implemented yet
- ... + Not implemented yet
From 4f157e31334c8d4f43767c91d24f250c553aeff6 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sat, 30 Apr 2011 18:34:52 +1200 Subject: [PATCH 2/7] MINOR Fixed CreateToplevelGroups toggling in CMSMain.EditForm.js --- javascript/CMSMain.EditForm.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/javascript/CMSMain.EditForm.js b/javascript/CMSMain.EditForm.js index 06c0c570..89762551 100644 --- a/javascript/CMSMain.EditForm.js +++ b/javascript/CMSMain.EditForm.js @@ -173,21 +173,22 @@ * Toggle display of group dropdown in "access" tab, * based on selection of radiobuttons. */ - $('.cms-edit-form #CanViewType, .cms-edit-form #CanEditType').entwine({ + $('.cms-edit-form #CanViewType, .cms-edit-form #CanEditType, .cms-edit-form #CanCreateTopLevelType').entwine({ // Constructor: onmatch onmatch: function() { // TODO Decouple var dropdown; if(this.attr('id') == 'CanViewType') dropdown = $('#ViewerGroups'); else if(this.attr('id') == 'CanEditType') dropdown = $('#EditorGroups'); + else if(this.attr('id') == 'CanCreateTopLevelType') dropdown = $('#CreateTopLevelGroups'); this.find('.optionset :input').bind('change', function(e) { - dropdown.toggle(e.target.value == 'OnlyTheseUsers'); + dropdown[e.target.value == 'OnlyTheseUsers' ? 'show' : 'hide'](); }); // initial state var currentVal = this.find('input[name=' + this.attr('id') + ']:checked').val(); - dropdown.toggle(currentVal == 'OnlyTheseUsers'); + dropdown[currentVal == 'OnlyTheseUsers' ? 'show' : 'hide'](); this._super(); } From e33576d23e3dbfdbe5e7a0add534a05bdcd3b1ca Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sun, 1 May 2011 12:34:16 +1200 Subject: [PATCH 3/7] MINOR Grouping date search fields in CMSMain->SearchForm --- code/controller/CMSMain.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/code/controller/CMSMain.php b/code/controller/CMSMain.php index 9b5e6459..208049a4 100755 --- a/code/controller/CMSMain.php +++ b/code/controller/CMSMain.php @@ -172,8 +172,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $fields = new FieldSet( new TextField('Term', _t('CMSSearch.FILTERLABELTEXT', 'Content')), - $dateFrom = new DateField('LastEditedFrom', _t('CMSSearch.FilterDateFrom', 'from')), - $dateTo = new DateField('LastEditedTo', _t('CMSSearch.FilterDateFrom', 'to')), + $dateGroup = new FieldGroup( + $dateFrom = new DateField('LastEditedFrom', _t('CMSSearch.FilterDateFrom', 'from')), + $dateTo = new DateField('LastEditedTo', _t('CMSSearch.FilterDateFrom', 'to')) + ), new DropdownField( 'FilterClass', _t('CMSMain.SearchTreeFormPagesDropdown', 'Pages'), @@ -189,6 +191,7 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr ) // new TextField('MetaTags', _t('CMSMain.SearchMetaTags', 'Meta tags')) ); + $dateGroup->subfieldParam = 'FieldHolder'; $dateFrom->setConfig('showcalendar', true); $dateTo->setConfig('showcalendar', true); From 42b31d4410b192f166c1384b85419c6eb043540a Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Mon, 2 May 2011 11:45:27 +1200 Subject: [PATCH 4/7] MINOR Adding temporary preview view to CMSPageEditController->getEditForm() --- code/controller/CMSPageEditController.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/code/controller/CMSPageEditController.php b/code/controller/CMSPageEditController.php index 47dfe085..aac1cc92 100644 --- a/code/controller/CMSPageEditController.php +++ b/code/controller/CMSPageEditController.php @@ -7,7 +7,15 @@ class CMSPageEditController extends CMSMain { function getEditForm($id = null, $fields = null) { $record = $this->getRecord($id ? $id : $this->currentPageID()); - return parent::getEditForm($record, ($record) ? $record->getCMSFields() : null); + $form = parent::getEditForm($record, ($record) ? $record->getCMSFields() : null); + + // TODO Replace with preview button + $form->Fields()->addFieldToTab( + 'Root.Main', + new LiteralField('SwitchView', sprintf('
%s
', $this->SwitchView())) + ); + + return $form; } } \ No newline at end of file From b4366c9ca9d76102ea7d80db687816a1a4ac5256 Mon Sep 17 00:00:00 2001 From: Frank Mullenger Date: Fri, 15 Apr 2011 21:27:37 +1200 Subject: [PATCH 5/7] ENHANCEMENT 'data-hints' attribute into root of CMSMain site tree, changed from 'allowedParents' to 'disallowedParents', 'allowedChildren' to 'disallowedChildren' for brevity (fixes #6577) --- code/controller/CMSMain.php | 39 +++++++++++++------ .../Includes/CMSPagesController_Content.ss | 2 +- 2 files changed, 28 insertions(+), 13 deletions(-) diff --git a/code/controller/CMSMain.php b/code/controller/CMSMain.php index 208049a4..3d59203e 100755 --- a/code/controller/CMSMain.php +++ b/code/controller/CMSMain.php @@ -139,7 +139,6 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr * Return the entire site tree as a nested set of ULs */ public function SiteTreeAsUL() { - $this->generateDataTreeHints(); $this->generateTreeStylingJS(); // Pre-cache sitetree version numbers for querying efficiency @@ -213,27 +212,43 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr return $this->getsubtree($this->request); } - public function generateDataTreeHints() { - $classes = ClassInfo::subclassesFor( $this->stat('tree_class') ); + /** + * Create serialized JSON string with site tree hints data to be injected into + * 'data-hints' attribute of root node of jsTree. + * + * @return String Serialized JSON + */ + public function SiteTreeHints() { + $classes = ClassInfo::subclassesFor( $this->stat('tree_class') ); $def['Root'] = array(); + $def['Root']['disallowedChildren'] = array(); + $def['Root']['disallowedParents'] = array(); foreach($classes as $class) { $obj = singleton($class); if($obj instanceof HiddenClass) continue; - + $allowedChildren = $obj->allowedChildren(); - if($allowedChildren != "none") $def[$class]['allowedChildren'] = $allowedChildren; - $def[$class]['defaultChild'] = $obj->defaultChild(); - $def[$class]['defaultParent'] = isset(SiteTree::get_by_link($obj->defaultParent())->ID) ? SiteTree::get_by_link($obj->defaultParent())->ID : null; - - if($obj->stat('can_be_root')) { - $def['Root']['allowedChildren'][] = $class; + //SiteTree::allowedChildren() returns null rather than an empty array if SiteTree::allowed_chldren == 'none' + if ($allowedChildren == null) $allowedChildren = array(); + $def[$class]['disallowedChildren'] = array_keys(array_diff($classes, $allowedChildren)); + + $defaultChild = $obj->defaultChild(); + if ($defaultChild != 'Page' && $defaultChild != null) $def[$class]['defaultChild'] = $defaultChild; + + $defaultParent = isset(SiteTree::get_by_link($obj->defaultParent())->ID) ? SiteTree::get_by_link($obj->defaultParent())->ID : null; + if ($defaultParent != 1 && $defaultParent != null) $def[$class]['defaultParent'] = $defaultParent; + + if(is_array($def[$class]['disallowedChildren'])) foreach($def[$class]['disallowedChildren'] as $disallowedChild) { + $def[$disallowedChild]['disallowedParents'][] = $class; } + + //Are any classes allowed to be parents of root? + $def['Root']['disallowedParents'][] = $class; } - // Put data hints into a script tag at the top - Requirements::customScript("siteTreeHints = " . Convert::raw2json($def) . ";"); + return Convert::raw2xml(Convert::raw2json($def)); } public function generateTreeStylingJS() { diff --git a/templates/Includes/CMSPagesController_Content.ss b/templates/Includes/CMSPagesController_Content.ss index f609a883..352e4e54 100644 --- a/templates/Includes/CMSPagesController_Content.ss +++ b/templates/Includes/CMSPagesController_Content.ss @@ -34,7 +34,7 @@ <% include CMSPagesController_ContentToolbar %> -
+
$SiteTreeAsUL
From 26151f2e4c8f8d667f8e6e7625c47cedaffac189 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Sun, 8 May 2011 23:36:55 +1200 Subject: [PATCH 6/7] ENHANCEMENT Limiting page types based on SiteTree::$allowed_children in CMSMain.AddForm.js --- code/controller/CMSMain.php | 3 ++ javascript/CMSMain.AddForm.js | 52 ++++++++++++++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/code/controller/CMSMain.php b/code/controller/CMSMain.php index 3d59203e..8293ec21 100755 --- a/code/controller/CMSMain.php +++ b/code/controller/CMSMain.php @@ -1297,6 +1297,8 @@ JS; $fields = new FieldSet( // new HiddenField("ParentID", false, ($this->parentRecord) ? $this->parentRecord->ID : null), + // TODO Should be part of the form attribute, but not possible in current form API + $hintsField = new LiteralField('Hints', sprintf('', $this->SiteTreeHints())), $parentField = new TreeDropdownField("ParentID", _t('CMSMain.AddFormParentLabel', 'Parent page'), 'SiteTree'), new OptionsetField("PageType", "", $pageTypes, 'Page') ); @@ -1312,6 +1314,7 @@ JS; $this->extend('updatePageOptions', $fields); $form = new Form($this, "AddForm", $fields, $actions); + $form->addExtraClass('cms-add-form'); return $form; } diff --git a/javascript/CMSMain.AddForm.js b/javascript/CMSMain.AddForm.js index 1e636f30..765309ec 100644 --- a/javascript/CMSMain.AddForm.js +++ b/javascript/CMSMain.AddForm.js @@ -20,7 +20,57 @@ this._super(); }, onclick: function() { - this.parents('li:first').addClass('selected').siblings().removeClass('selected'); + var el = this.parents('li:first'); + el.setSelected(true); + el.siblings().setSelected(false); + } + }); + + $(".cms-add-form").entwine({ + onmatch: function() { + var self = this; + this.find('#ParentID .TreeDropdownField').bind('change', function() { + self.updateTypeList(); + }); + }, + + /** + * Limit page type selection based on parent class. + * Similar implementation to LeftAndMain.Tree.js. + */ + updateTypeList: function() { + var hints = this.find('.hints').data('hints'), + metadata = this.find('#ParentID .TreeDropdownField').data('metadata'), + id = this.find('#ParentID .TreeDropdownField').getValue(), + newClassName = metadata[0].ClassName, + disallowedChildren = hints[newClassName ? newClassName : 'Root'].disallowedChildren || [], + defaultChildClass = hints[newClassName ? newClassName : 'Root'].defaultChild || null; + + // Limit selection + this.find('#PageType li').each(function() { + var className = $(this).find('input').val(), isAllowed = ($.inArray(className, disallowedChildren) == -1); + $(this).setEnabled(isAllowed); + }); + + // Set default child selection, or fall back to first available option + if(defaultChildClass) { + var selectedEl = this.find('#PageType li input[value=' + defaultChildClass + ']').parents('li:first'); + } else { + var selectedEl = this.find('#PageType li:not(.disabled):first'); + } + selectedEl.setSelected(true); + selectedEl.siblings().setSelected(false); + } + }); + + $(".cms-add-form #PageType li").entwine({ + setSelected: function(bool) { + this.toggleClass('selected', bool); + this.find('input').attr('checked', bool ? 'checked' : null); + }, + setEnabled: function(bool) { + $(this).toggleClass('disabled', bool); + $(this).find('input').attr('disabled', bool ? '' : 'disabled'); } }); From c196c47c52f986dd09427bf4157ef5fa8aa17cd6 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Thu, 19 May 2011 11:11:48 +1200 Subject: [PATCH 7/7] MINOR Temporarily disabled deprecation notice in SiteTreeDecorator, to be re-enabled once we're in beta --- code/model/SiteTreeDecorator.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/code/model/SiteTreeDecorator.php b/code/model/SiteTreeDecorator.php index fc5f2b22..bea4e5dc 100644 --- a/code/model/SiteTreeDecorator.php +++ b/code/model/SiteTreeDecorator.php @@ -7,10 +7,11 @@ abstract class SiteTreeDecorator extends SiteTreeExtension { public function __construct() { - user_error( - 'SiteTreeDecorator is deprecated, please use SiteTreeExtension instead.', - E_USER_NOTICE - ); + // TODO Re-enable before we release 3.0 beta, for now it "breaks" too many modules + // user_error( + // 'SiteTreeDecorator is deprecated, please use SiteTreeExtension instead.', + // E_USER_NOTICE + // ); parent::__construct(); }