Skip to content

Commit

Permalink
Merge pull request #58 from nfauchelle/custom-templates
Browse files Browse the repository at this point in the history
Allow GridField / ModelAdmin panels to have their own templates
  • Loading branch information
unclecheese committed Nov 4, 2014
2 parents 40db2bd + 0e985d5 commit 9eef489
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 30 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

The Dashboard module provides a splash page for the CMS in SilverStripe 3 with configurable widgets that display relevant information. Panels can be created and extended easily. The goal of the Dashboard module is to provide users with a launchpad for common CMS actions such as creating specific page types or browsing new content.

Videos can also be found at [in this blog post.](http://www.leftandmain.com/silverstripe-screencasts/2012/10/03/dashboard-module-for-silverstripe-3/)

## Screenshot
![Screenshot](http://www.leftandmain.com/wp-content/themes/bueno/thumb.php?src=wp-content/uploads/2012/10/screenshot.png&w=640&zc=1&q=90)
## Screenshot & Videos
Images and videos about this module can be found [in this blog post.](http://www.leftandmain.com/silverstripe-screencasts/2012/10/03/dashboard-module-for-silverstripe-3/)


## Included panels
Expand Down Expand Up @@ -104,6 +103,8 @@ public function PanelHolder() {
}
```



### Adding a chart to visualize data

The Dashboard module comes with an API for creating charts using the Google API.
Expand All @@ -130,4 +131,20 @@ The Dashboard module comes with an API for creating charts using the Google API.
$Chart
```

### Custom templates for ModelAdmin / GridField panels

You can create your own templates for either of these panel types which will override the default templates. Due to the naming structure the custom templates will be specific to that partiular panel, thus you can have a seperate template for each ModelAdmin / GridField panel.

You can access all the properties of your model in the template as normal along with a EditLink method which will contain the CMS edit link for that item.


For model admin panels, create a templated called DashboardModelAdminPanel\_**ModelAdminClass**\_**ModelAdminModel**.ss and place it in your _mysite/templates/Includes folder_.
eg;
**DashboardModelAdminPanel\_MyAdmin\_Product.ss**

A gridfield panel uses a similar convention, DashboardGridFieldPanel\_**PageClassName**\_**GridFieldName**.ss

eg;
**DashboardGridFieldPanel\_ContactPage\_Submissions.ss**


40 changes: 27 additions & 13 deletions code/panels/DashboardGridFieldPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ class DashboardGridFieldPanel extends DashboardPanel {



/**
* Override to check if there is a custom template for this panel, otherwise fall back.
*
* @return string
*/
protected function getTemplate() {
$templateName = get_class($this) . '_' . $this->SubjectPage()->ClassName . '_' . $this->GridFieldName;
if(SS_TemplateLoader::instance()->findTemplates($templateName)) {
return $templateName;
}
return parent::getTemplate();
}




/**
* @var string Overrides the standard request handler to provide custom controller actions
*/
Expand Down Expand Up @@ -275,19 +291,17 @@ public function GridFieldItems() {
->sort("LastEdited DESC");
$ret = ArrayList::create(array());
foreach($list as $record) {
$ret->push(ArrayData::create(array(
'EditLink' => Controller::join_links(
Injector::inst()->get("CMSMain")->Link("edit"),
"EditForm",
"field",
$this->GridFieldName,
"item",
$record->ID,
"edit",
"?ID={$this->SubjectPageID}"
),
'Title' => $record->getTitle()
)));
$record->EditLink = Controller::join_links(
Injector::inst()->get("CMSMain")->Link("edit"),
"EditForm",
"field",
$this->GridFieldName,
"item",
$record->ID,
"edit",
"?ID={$this->SubjectPageID}"
);
$ret->push($record);
}
return $ret;
}
Expand Down
40 changes: 26 additions & 14 deletions code/panels/DashboardModelAdminPanel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ class DashboardModelAdminPanel extends DashboardPanel {



/**
* Override to check if there is a custom template for this panel, otherwise fall back
*
* @return string
*/
protected function getTemplate() {
$templateName = get_class($this) . '_' . $this->ModelAdminClass . '_' . $this->ModelAdminModel;
if(SS_TemplateLoader::instance()->findTemplates($templateName)) {
return $templateName;
}
return parent::getTemplate();
}



public function getLabel() {
return _t('Dashboard.MODELADMINPANELTITLE','Model Admin Editor');
}
Expand Down Expand Up @@ -228,20 +243,17 @@ public function ModelAdminItems() {
$url_segment = Injector::inst()->get($this->ModelAdminClass)->Link();
$ret = ArrayList::create(array());
foreach($records as $rec) {
$ret->push(ArrayData::create(array(
'EditLink' => Controller::join_links(
$url_segment,
$this->ModelAdminModel,
"EditForm",
"field",
$this->ModelAdminModel,
"item",
$rec->ID,
"edit"
),
'Title' => $rec->getTitle()

)));
$rec->EditLink = Controller::join_links(
$url_segment,
$this->ModelAdminModel,
"EditForm",
"field",
$this->ModelAdminModel,
"item",
$rec->ID,
"edit"
);
$ret->push($rec);
}
return $ret;
}
Expand Down

0 comments on commit 9eef489

Please sign in to comment.