ENHANCEMENT ajshort: Add the ability to overload getModelForms() and add new custom model sidebars.

API CHANGE: Move the generation of the content for the create / search / import model sidebar from ModelAdmin into the collection controller.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@76997 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-05-16 05:58:54 +00:00
parent b34dcd40b0
commit 4adb585e80
3 changed files with 50 additions and 45 deletions

View File

@ -188,18 +188,14 @@ abstract class ModelAdmin extends LeftAndMain {
* @return DataObjectSet of forms
*/
protected function getModelForms() {
$modelClasses = $this->getManagedModels();
$models = $this->getManagedModels();
$forms = new DataObjectSet();
$forms = new DataObjectSet();
foreach($modelClasses as $modelClass) {
$this->$modelClass()->SearchForm();
$forms->push(new ArrayData(array(
'SearchForm' => $this->$modelClass()->SearchForm(),
'CreateForm' => $this->$modelClass()->CreateForm(),
'ImportForm' => $this->$modelClass()->ImportForm(),
'Title' => singleton($modelClass)->singular_name(),
'ClassName' => $modelClass,
foreach($models as $class) {
$forms->push(new ArrayData(array (
'Title' => singleton($class)->singular_name(),
'ClassName' => $class,
'Content' => $this->$class()->getModelSidebar()
)));
}
@ -313,9 +309,18 @@ class ModelAdmin_CollectionController extends Controller {
$class = $this->parentController->stat('record_controller_class');
return new $class($this, $request);
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// -----------------------------------------------------------------------------------------------------------------
/**
* Get a combination of the Search, Import and Create forms that can be inserted into a {@link ModelAdmin} sidebar.
*
* @return string
*/
public function getModelSidebar() {
return $this->renderWith('ModelSidebar');
}
/**
* Get a search form for a single {@link DataObject} subclass.
*

View File

@ -1,43 +1,31 @@
<% require javascript(jsparty/tabstrip/tabstrip.js) %>
<% require css(jsparty/tabstrip/tabstrip.css) %>
<div id="LeftPane">
<!-- <h2><% _t('SEARCHLISTINGS','Search Listings') %></h2> -->
<div id="SearchForm_holder" class="leftbottom">
<% if SearchClassSelector = tabs %>
<ul class="tabstrip">
<% control ModelForms %>
<li class="$FirstLast"><a href="#{$Form.Name}_$ClassName">$Title</a></li>
<% end_control %>
</ul>
<% if SearchClassSelector = tabs %>
<ul class="tabstrip">
<% control ModelForms %>
<li class="$FirstLast"><a href="#{$Form.Name}_$ClassName">$Title</a></li>
<% end_control %>
</ul>
<% end_if %>
<% if SearchClassSelector = dropdown %>
<p id="ModelClassSelector">
Search for:
<select>
<% control ModelForms %>
<option value="{$Form.Name}_$ClassName">$Title</option>
<% end_control %>
</select>
</p>
<% end_if %>
<p id="ModelClassSelector">
Search for:
<select>
<% control ModelForms %>
<option value="{$Form.Name}_$ClassName">$Title</option>
<% end_control %>
</select>
</p>
<% end_if %>
<% control ModelForms %>
<div class="tab" id="{$Form.Name}_$ClassName">
<% if CreateForm %>
<h3><% _t('ADDLISTING','Add') %></h3>
$CreateForm
<% end_if %>
<h3><% _t('SEARCHLISTINGS','Search') %></h3>
$SearchForm
<% if ImportForm %>
<h3><% _t('IMPORT_TAB_HEADER', 'Import') %></h3>
$ImportForm
<% end_if %>
</div>
<div class="tab" id="{$Form.Name}_$ClassName">
$Content
</div>
<% end_control %>
</div>
</div>

12
templates/ModelSidebar.ss Normal file
View File

@ -0,0 +1,12 @@
<% if CreateForm %>
<h3><% _t('ADDLISTING','Add') %></h3>
$CreateForm
<% end_if %>
<h3><% _t('SEARCHLISTINGS','Search') %></h3>
$SearchForm
<% if ImportForm %>
<h3><% _t('IMPORT_TAB_HEADER', 'Import') %></h3>
$ImportForm
<% end_if %>