diff --git a/admin/code/LeftAndMain.php b/admin/code/LeftAndMain.php index f12666e5d02..f477f967d85 100644 --- a/admin/code/LeftAndMain.php +++ b/admin/code/LeftAndMain.php @@ -476,9 +476,11 @@ public function Menu() { * Return a list of appropriate templates for this class, with the given suffix */ protected function getTemplatesWithSuffix($suffix) { + $templates = array(); $classes = array_reverse(ClassInfo::ancestry($this->class)); foreach($classes as $class) { - $templates[] = $class . $suffix; + $template = $class . $suffix; + if(SSViewer::hasTemplate($template)) $templates[] = $template; if($class == 'LeftAndMain') break; } return $templates; @@ -1017,6 +1019,46 @@ public function doAdd($data, $form) { public function EditorToolbar() { return Object::create('HtmlEditorField_Toolbar', $this, "EditorToolbar"); } + + /** + * Renders a panel containing tools which apply to all displayed + * "content" (mostly through {@link EditForm()}), for example a tree navigation or a filter panel. + * Auto-detects applicable templates by naming convention: "_Tools.ss", + * and takes the most specific template (see {@link getTemplatesWithSuffix()}). + * To explicitly disable the panel in the subclass, simply create a more specific, empty template. + * + * @return String HTML + */ + public function Tools() { + $templates = $this->getTemplatesWithSuffix('_Tools'); + if($templates) { + $viewer = new SSViewer($templates); + return $viewer->process($this); + } else { + return false; + } + } + + /** + * Renders a panel containing tools which apply to the currently displayed edit form. + * The main difference to {@link Tools()} is that the panel is displayed within + * the element structure of the form panel (rendered through {@link EditForm}). + * This means the panel will be loaded alongside new forms, and refreshed upon save, + * which can mean a performance hit, depending on how complex your panel logic gets. + * Any form fields contained in the returned markup will also be submitted with the main form, + * which might be desired depending on the implementation details. + * + * @return String HTML + */ + public function EditFormTools() { + $templates = $this->getTemplatesWithSuffix('_EditFormTools'); + if($templates) { + $viewer = new SSViewer($templates); + return $viewer->process($this); + } else { + return false; + } + } /** * Batch Actions Handler diff --git a/admin/javascript/LeftAndMain.Content.js b/admin/javascript/LeftAndMain.Content.js index 81450844e3e..7fcfe077f78 100644 --- a/admin/javascript/LeftAndMain.Content.js +++ b/admin/javascript/LeftAndMain.Content.js @@ -37,7 +37,13 @@ var url = $(node).find('a:first').attr('href'); if(url && url != '#') { if($(node).find('a:first').is(':internal')) url = $('base').attr('href') + url; - $('.cms-container').loadPanel(url); + // Reload only edit form if it exists (side-by-side view of tree and edit view), otherwise reload whole panel + if(self.find('.cms-edit-form').length) { + url += '?cms-view-form=1'; + $('.cms-container').loadPanel(url, null, {selector: '.cms-edit-form'}); + } else { + $('.cms-container').loadPanel(url); + } } else { self.removeForm(); } diff --git a/admin/javascript/LeftAndMain.js b/admin/javascript/LeftAndMain.js index 4ff86eb4ddb..2ac21615b55 100644 --- a/admin/javascript/LeftAndMain.js +++ b/admin/javascript/LeftAndMain.js @@ -95,8 +95,13 @@ redraw: function() { // Move from inner to outer layouts. Some of the elements might not exist. // Not all edit forms are layouted, so qualify by their data value. + this.find('.cms-edit-form[data-layout]').redraw(); - this.find('.cms-preview').redraw(); + + // Only redraw preview if its visible + var preview = this.find('.cms-preview'); + if(preview.is(':visible')) preview.redraw(); + // Only redraw the content area if its not the same as the edit form var contentEl = this.find('.cms-content'); if(!contentEl.is('.cms-edit-form')) contentEl.redraw(); diff --git a/admin/templates/Includes/LeftAndMain_Content.ss b/admin/templates/Includes/LeftAndMain_Content.ss index 40443e0462a..6b2cb07645e 100644 --- a/admin/templates/Includes/LeftAndMain_Content.ss +++ b/admin/templates/Includes/LeftAndMain_Content.ss @@ -1 +1,7 @@ -$EditForm \ No newline at end of file +
+ + $Tools + + $EditForm + +
\ No newline at end of file diff --git a/admin/templates/Includes/LeftAndMain_EditForm.ss b/admin/templates/Includes/LeftAndMain_EditForm.ss index 7084bfda278..0419f46bed1 100644 --- a/admin/templates/Includes/LeftAndMain_EditForm.ss +++ b/admin/templates/Includes/LeftAndMain_EditForm.ss @@ -23,44 +23,40 @@ + + <% control Controller %> + $EditFormTools + <% end_control %> - <% if Tools %> - - <% end_if %> - -
-
- <% if Message %> -

$Message

- <% else %> - - <% end_if %> +
+ <% if Message %> +

$Message

+ <% else %> + + <% end_if %> -
- <% if Legend %>$Legend<% end_if %> - <% control Fields %> - $FieldHolder - <% end_control %> -
-
-
+
+ <% if Legend %>$Legend<% end_if %> + <% control Fields %> + $FieldHolder + <% end_control %> +
+
+
-
- <% if Actions %> -
- <% control Actions %> - $Field - <% end_control %> - <% if CurrentPage.PreviewLink %> - - <% _t('LeftAndMain.PreviewButton', 'Preview') %> » - - <% end_if %> -
+
+ <% if Actions %> +
+ <% control Actions %> + $Field + <% end_control %> + <% if CurrentPage.PreviewLink %> + + <% _t('LeftAndMain.PreviewButton', 'Preview') %> » + <% end_if %>
+ <% end_if %>
<% if IncludeFormTag %> diff --git a/admin/templates/Includes/ModelAdmin_Content.ss b/admin/templates/Includes/ModelAdmin_Content.ss index 6f8ac5f848f..542295a5697 100644 --- a/admin/templates/Includes/ModelAdmin_Content.ss +++ b/admin/templates/Includes/ModelAdmin_Content.ss @@ -6,39 +6,7 @@
-
-
-

<% _t('Filter', 'Filter') %>

- -
- <% if SearchClassSelector = tabs %> -
    - <% control ModelForms %> -
  • $Title
  • - <% end_control %> -
- <% end_if %> - - <% if SearchClassSelector = dropdown %> -
- Search for: - -
- <% end_if %> - - <% control ModelForms %> -
- $Content -
- <% end_control %> -
-
- -
+ $Tools
$EditForm diff --git a/admin/templates/Includes/ModelAdmin_Tools.ss b/admin/templates/Includes/ModelAdmin_Tools.ss new file mode 100644 index 00000000000..a9ec746a354 --- /dev/null +++ b/admin/templates/Includes/ModelAdmin_Tools.ss @@ -0,0 +1,33 @@ +
+
+

<% _t('Filter', 'Filter') %>

+ +
+ <% if SearchClassSelector = tabs %> +
    + <% control ModelForms %> +
  • $Title
  • + <% end_control %> +
+ <% end_if %> + + <% if SearchClassSelector = dropdown %> +
+ Search for: + +
+ <% end_if %> + + <% control ModelForms %> +
+ $Content +
+ <% end_control %> +
+
+ +
\ No newline at end of file diff --git a/docs/en/reference/cms-architecture.md b/docs/en/reference/cms-architecture.md index 3505a657b64..bfad5ed7441 100644 --- a/docs/en/reference/cms-architecture.md +++ b/docs/en/reference/cms-architecture.md @@ -74,11 +74,12 @@ This requires manual assignment of the template to your form instance, see `[api Often its useful to have a "tools" panel in between the menu and your content, usually occupied by a search form or navigational helper. -In this case, you can either overload the template as described above, -or use the special `$Tools` placeholder on `LeftAndMain->getEditForm()`. -See `CMSPageEditController->getEditForm()` for sample usage. -As the base template is aware of this placeholder, it saves you from -overloading a complex template. +In this case, you can either overload the full base template as described above. +To avoid duplicating all this template code, you can also use the special `[api:LeftAndMain->Tools()]` and +`[api:LeftAndMain->EditFormTools()]` methods available in `LeftAndMain`. +These placeholders are populated by auto-detected templates, +with the naming convention of "_Tools.ss" and "_EditFormTools.ss". +So to add or "subclass" a tools panel, simply create this file and it's automatically picked up. ## Layout and Panels