diff --git a/code/CMSMain.php b/code/CMSMain.php
index 99c1752d..bcc51f57 100755
--- a/code/CMSMain.php
+++ b/code/CMSMain.php
@@ -99,6 +99,13 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr
function ShowSwitchView() {
return true;
}
+
+ function SwitchView() {
+ if($page = $this->currentPage()) {
+ $nav = SilverStripeNavigator::get_for_record($page);
+ return $nav['items'];
+ }
+ }
//------------------------------------------------------------------------------------------//
// Main controllers
diff --git a/code/LeftAndMain.php b/code/LeftAndMain.php
index 40502674..74ca2d26 100644
--- a/code/LeftAndMain.php
+++ b/code/LeftAndMain.php
@@ -352,11 +352,17 @@ class LeftAndMain extends Controller {
if(Director::is_ajax()) {
SSViewer::setOption('rewriteHashlinks', false);
$form = $this->getEditForm($request->param('ID'));
- return $form->formHtmlContent();
+ $content = $form->formHtmlContent();
} else {
// Rendering is handled by template, which will call EditForm() eventually
- return $this->renderWith($this->getViewer('show'));
+ $content = $this->renderWith($this->getViewer('show'));
}
+
+ if($this->ShowSwitchView()) {
+ $content .= '
' . $this->SwitchView() . '
';
+ }
+
+ return $content;
}
/**
@@ -364,8 +370,7 @@ class LeftAndMain extends Controller {
*/
public function getitem($request) {
$form = $this->getEditForm($request->getVar('ID'));
- if($form) return $form->formHtmlContent();
- else return "";
+ return $form->formHtmlContent();
}
//------------------------------------------------------------------------------------------//
diff --git a/javascript/LeftAndMain.js b/javascript/LeftAndMain.js
index c8ac9413..54dd9314 100644
--- a/javascript/LeftAndMain.js
+++ b/javascript/LeftAndMain.js
@@ -378,60 +378,37 @@ var ss_MainLayout;
}
}
});
+
+ /**
+ * Class: #switchView a
+ *
+ * Updates the different stage links which are generated through
+ * the SilverStripeNavigator class on the serverside each time a form record
+ * is reloaded.
+ */
+ $('#switchView').entwine({
+ onmatch: function() {
+ this._super();
+
+ $('#Form_EditForm').bind('load delete', function(e) {
+ var updatedSwitchView = $('#AjaxSwitchView');
+ console.debug(updatedSwitchView.html());
+ $('#SwitchView').html(updatedSwitchView.html());
+ updatedSwitchView.remove();
+ });
+ }
+ });
/**
* Class: #switchView a
*
* Links for viewing the currently loaded page
* in different modes: 'live', 'stage' or 'archived'.
- * Automatically updates on loading a new page.
*
* Requires:
* jquery.metadata
*/
$('#switchView a').entwine({
- /**
- * Variable: Form
- * (DOMElement)
- */
- Form: null,
-
- /**
- * Constructor: onmatch
- */
- onmatch: function() {
- var self = this;
- this.setForm($('#Form_EditForm'));
-
- jQuery('#Form_EditForm').bind('loadnewpage delete', function(e) {self.refresh();});
- self.refresh();
-
- this._super();
- },
-
- /**
- * Function: refresh
- *
- * Parse new links based on the underlying form URLSegment,
- * preserving the ?stage URL parameters if necessary.
- */
- refresh: function() {
- // TODO Compatible with nested urls?
- var urlSegment = this.getForm().find(':input[name=AbsoluteLink]').val();
- if(!urlSegment) urlSegment = this.getForm().find(':input[name=URLSegment]').val();
-
- if(urlSegment) {
- var locale = this.getForm().find(':input[name=Locale]').val();
- var url = urlSegment;
- if(this.metadata().params) url += '?' + this.metadata().params;
- if(locale) url += ((url.indexOf('?') > 0) ? '&' : '?') + "locale=" + locale;
- this.attr('href', url);
- }
-
- // hide fields if no URLSegment is present
- this.toggle((urlSegment));
- },
-
/**
* Function: onclick
*/
diff --git a/templates/LeftAndMain.ss b/templates/LeftAndMain.ss
index ca184e91..acd80e36 100644
--- a/templates/LeftAndMain.ss
+++ b/templates/LeftAndMain.ss
@@ -47,10 +47,7 @@