diff --git a/code/InlineHelpExtension.php b/code/InlineHelpExtension.php index dabdefa..86de1db 100755 --- a/code/InlineHelpExtension.php +++ b/code/InlineHelpExtension.php @@ -35,6 +35,13 @@ public function getHelpItems() { $items->merge(DataObject::get('InlineHelpTopic', '"AttachType" = \'All\'')); + $items->merge(DataObject::get( + 'InlineHelpTopic', + sprintf( + '"AttachType" = \'Type\' AND "AttachPageType" = \'%s\'', + $this->owner->class + ) + )); $items->merge($this->owner->HelpTopics()); $stack = $this->owner->parentStack(); diff --git a/code/InlineHelpTopic.php b/code/InlineHelpTopic.php index 29230a1..e573328 100755 --- a/code/InlineHelpTopic.php +++ b/code/InlineHelpTopic.php @@ -8,21 +8,22 @@ class InlineHelpTopic extends DataObject { public static $db = array( - 'Title' => 'Varchar(100)', - 'DisplayType' => 'Enum("Tooltip, Link", "Tooltip")', - 'Text' => 'HTMLText', - 'Link' => 'Varchar(100)', - 'AttachType' => 'Enum("All, Pages, Children", "Pages")', - 'DOMPattern' => 'Varchar(100)', - 'ShowTooltip' => 'Enum("Hover, Click", "Hover")', - 'TooltipWidth' => 'Varchar(6)', - 'TooltipHeight' => 'Varchar(6)', - 'IconHTML' => 'HTMLVarchar(255)', - 'IconMy' => 'Varchar(15)', - 'IconAt' => 'Varchar(15)', - 'IconOffset' => 'Varchar(10)', - 'TooltipMy' => 'Varchar(15)', - 'TooltipAt' => 'Varchar(15)' + 'Title' => 'Varchar(100)', + 'DisplayType' => 'Enum("Tooltip, Link", "Tooltip")', + 'Text' => 'HTMLText', + 'Link' => 'Varchar(100)', + 'AttachType' => 'Enum("All, Pages, Children, Type", "Pages")', + 'AttachPageType' => 'Varchar(100)', + 'DOMPattern' => 'Varchar(100)', + 'ShowTooltip' => 'Enum("Hover, Click", "Hover")', + 'TooltipWidth' => 'Varchar(6)', + 'TooltipHeight' => 'Varchar(6)', + 'IconHTML' => 'HTMLVarchar(255)', + 'IconMy' => 'Varchar(15)', + 'IconAt' => 'Varchar(15)', + 'IconOffset' => 'Varchar(10)', + 'TooltipMy' => 'Varchar(15)', + 'TooltipAt' => 'Varchar(15)' ); public static $has_one = array( @@ -47,9 +48,10 @@ class InlineHelpTopic extends DataObject { public static $searchable_fields = array( 'Title' => array('filter' => 'PartialMatchFilter'), + 'AttachType' => array('filter' => 'ExactMatchFilter'), 'DisplayType' => array('filter' => 'ExactMatchFilter'), - 'Text' => array('title' => 'Help text', 'filter' => 'PartialMatchFilter'), - 'Link' => array('title' => 'Help link', 'filter' => 'PartialMatchFilter') + 'Text' => array('title' => 'Help text', 'filter' => 'PartialMatchFilter'), + 'Link' => array('title' => 'Help link', 'filter' => 'PartialMatchFilter') ); /** @@ -66,6 +68,8 @@ public function getAttachedTo() { return 'Specific pages: ' . implode(', ', $this->Pages()->map()); case 'Children': return 'Children of ' . $this->ParentFilter()->Title; + case 'Type': + return 'Pages of type ' . $this->AttachPageType; } } @@ -100,10 +104,14 @@ public function getCMSFields() { new OptionSetField('AttachType', '', array( 'All' => 'All pages', 'Pages' => 'Specific pages', - 'Children' => 'Children of the selected page' + 'Children' => 'Children of the selected page', + 'Type' => 'Instances of a specific page type' )), new TreeMultiSelectField('Pages', 'Pages', 'SiteTree'), - new TreeDropdownField('ParentFilterID', 'Parent page', 'SiteTree') + new TreeDropdownField('ParentFilterID', 'Parent page', 'SiteTree'), + new DropdownField('AttachPageType', 'Page type', ArrayLib::valuekey( + ClassInfo::subclassesFor('Page') + )) ), new Tab('Advanced', new HeaderField('AdvancedHeader', 'Advanced Inline Help Options'), diff --git a/javascript/InlineHelpAdmin.js b/javascript/InlineHelpAdmin.js index cba999e..c5a5ef9 100755 --- a/javascript/InlineHelpAdmin.js +++ b/javascript/InlineHelpAdmin.js @@ -17,16 +17,25 @@ case 'All': $('#ParentFilterID').hide(); $('#Pages').hide(); + $('#AttachPageType').hide(); break; case 'Pages': $('#ParentFilterID').hide(); $('#Pages').show(); + $('#AttachPageType').hide(); break; case 'Children': $('#ParentFilterID').show(); $('#Pages').hide(); + $('#AttachPageType').hide(); + break; + + case 'Type': + $('#ParentFilterID').hide(); + $('#Pages').hide(); + $('#AttachPageType').show(); break; } }); @@ -34,11 +43,11 @@ $('#DisplayType :radio').live('change', function() { switch ($(this).val()) { case 'Tooltip': - $('#Text').show(); + $('#Text.htmleditor').show(); break; case 'Link': - $('#Text').hide(); + $('#Text.htmleditor').hide(); break; } }); diff --git a/tests/InlineHelpTest.php b/tests/InlineHelpTest.php index 41ff5cb..b28ee45 100755 --- a/tests/InlineHelpTest.php +++ b/tests/InlineHelpTest.php @@ -33,4 +33,12 @@ public function testAttachChildPages() { array_values($location->map())); } + public function testAttachPageType() { + $location = $this->objFromFixture('ErrorPage', '404')->getHelpItems(); + + $this->assertEquals(2, count($location)); + $this->assertEquals(array('All Pages Help', 'Error Page Help'), + array_values($location->map())); + } + } \ No newline at end of file diff --git a/tests/InlineHelpTest.yml b/tests/InlineHelpTest.yml index 26e0691..19bc679 100755 --- a/tests/InlineHelpTest.yml +++ b/tests/InlineHelpTest.yml @@ -11,6 +11,10 @@ SiteTree: empty: Title: Empty Page +ErrorPage: + 404: + Title: Page Not Found + InlineHelpTopic: all: Title: All Pages Help @@ -23,5 +27,9 @@ InlineHelpTopic: Title: Child Pages Help AttachType: Children ParentFilter: =>SiteTree.about + type: + Title: Error Page Help + AttachType: Type + AttachPageType: ErrorPage none: Title: No Page Help \ No newline at end of file