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 * @return DataObjectSet of forms
*/ */
protected function getModelForms() { protected function getModelForms() {
$modelClasses = $this->getManagedModels(); $models = $this->getManagedModels();
$forms = new DataObjectSet(); $forms = new DataObjectSet();
foreach($modelClasses as $modelClass) {
$this->$modelClass()->SearchForm();
foreach($models as $class) {
$forms->push(new ArrayData(array ( $forms->push(new ArrayData(array (
'SearchForm' => $this->$modelClass()->SearchForm(), 'Title' => singleton($class)->singular_name(),
'CreateForm' => $this->$modelClass()->CreateForm(), 'ClassName' => $class,
'ImportForm' => $this->$modelClass()->ImportForm(), 'Content' => $this->$class()->getModelSidebar()
'Title' => singleton($modelClass)->singular_name(),
'ClassName' => $modelClass,
))); )));
} }
@ -314,7 +310,16 @@ class ModelAdmin_CollectionController extends Controller {
return new $class($this, $request); 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. * Get a search form for a single {@link DataObject} subclass.

View File

@ -1,7 +1,7 @@
<% require javascript(jsparty/tabstrip/tabstrip.js) %> <% require javascript(jsparty/tabstrip/tabstrip.js) %>
<% require css(jsparty/tabstrip/tabstrip.css) %> <% require css(jsparty/tabstrip/tabstrip.css) %>
<div id="LeftPane"> <div id="LeftPane">
<!-- <h2><% _t('SEARCHLISTINGS','Search Listings') %></h2> -->
<div id="SearchForm_holder" class="leftbottom"> <div id="SearchForm_holder" class="leftbottom">
<% if SearchClassSelector = tabs %> <% if SearchClassSelector = tabs %>
<ul class="tabstrip"> <ul class="tabstrip">
@ -24,19 +24,7 @@
<% control ModelForms %> <% control ModelForms %>
<div class="tab" id="{$Form.Name}_$ClassName"> <div class="tab" id="{$Form.Name}_$ClassName">
<% if CreateForm %> $Content
<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>
<% end_control %> <% 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 %>