Skip to content

Commit

Permalink
Added the ability to attach inline help to all instances of a page type.
Browse files Browse the repository at this point in the history
  • Loading branch information
ajshort committed Jun 25, 2010
1 parent 933d1ff commit b471cce
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 21 deletions.
7 changes: 7 additions & 0 deletions code/InlineHelpExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
46 changes: 27 additions & 19 deletions code/InlineHelpTopic.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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')
);

/**
Expand All @@ -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;
}
}

Expand Down Expand Up @@ -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'),
Expand Down
13 changes: 11 additions & 2 deletions javascript/InlineHelpAdmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,37 @@
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;
}
});

$('#DisplayType :radio').live('change', function() {
switch ($(this).val()) {
case 'Tooltip':
$('#Text').show();
$('#Text.htmleditor').show();
break;

case 'Link':
$('#Text').hide();
$('#Text.htmleditor').hide();
break;
}
});
Expand Down
8 changes: 8 additions & 0 deletions tests/InlineHelpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
}

}
8 changes: 8 additions & 0 deletions tests/InlineHelpTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ SiteTree:
empty:
Title: Empty Page

ErrorPage:
404:
Title: Page Not Found

InlineHelpTopic:
all:
Title: All Pages Help
Expand All @@ -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

0 comments on commit b471cce

Please sign in to comment.