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($models as $class) {
foreach($modelClasses as $modelClass) { $forms->push(new ArrayData(array (
$this->$modelClass()->SearchForm(); 'Title' => singleton($class)->singular_name(),
'ClassName' => $class,
$forms->push(new ArrayData(array( 'Content' => $this->$class()->getModelSidebar()
'SearchForm' => $this->$modelClass()->SearchForm(),
'CreateForm' => $this->$modelClass()->CreateForm(),
'ImportForm' => $this->$modelClass()->ImportForm(),
'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,43 +1,31 @@
<% 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">
<% control ModelForms %> <% control ModelForms %>
<li class="$FirstLast"><a href="#{$Form.Name}_$ClassName">$Title</a></li> <li class="$FirstLast"><a href="#{$Form.Name}_$ClassName">$Title</a></li>
<% end_control %> <% end_control %>
</ul> </ul>
<% end_if %> <% end_if %>
<% if SearchClassSelector = dropdown %> <% if SearchClassSelector = dropdown %>
<p id="ModelClassSelector"> <p id="ModelClassSelector">
Search for: Search for:
<select> <select>
<% control ModelForms %> <% control ModelForms %>
<option value="{$Form.Name}_$ClassName">$Title</option> <option value="{$Form.Name}_$ClassName">$Title</option>
<% end_control %> <% end_control %>
</select> </select>
</p> </p>
<% end_if %> <% end_if %>
<% 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> </div>
$CreateForm
<% end_if %>
<h3><% _t('SEARCHLISTINGS','Search') %></h3>
$SearchForm
<% if ImportForm %>
<h3><% _t('IMPORT_TAB_HEADER', 'Import') %></h3>
$ImportForm
<% end_if %>
</div>
<% end_control %> <% end_control %>
</div> </div>
</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 %>