APICHANGE: Use the same navigator items in the CMS that are used on the frontend (from r97395) (from r99114)

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@106143 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Ingo Schommer 2010-06-03 02:45:23 +00:00
parent 42f237bb8f
commit 139c3e8c40
4 changed files with 37 additions and 51 deletions

View File

@ -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

View File

@ -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 .= '<div id="AjaxSwitchView">' . $this->SwitchView() . '</div>';
}
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();
}
//------------------------------------------------------------------------------------------//

View File

@ -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
*/

View File

@ -47,10 +47,7 @@
<div id="switchView" class="bottomTabs">
<% if ShowSwitchView %>
<div class="blank"> <% _t('VIEWPAGEIN','Page view:') %> </div>
<span class="current" title="<% _t('EDITINCMS', 'Edit this page in the CMS') %>"><% _t('EDIT','Edit') %></span>
<a id="viewStageSite" title="<% _t('VIEWINDRAFT', 'View the Page in the Draft Site') %>" href="home/?stage=Stage" class="{params:'stage=Stage'}"><% _t('DRAFTS','Draft Site') %></a>
<a id="viewLiveSite" title="<% _t('VIEWINPUBLISHED', 'View the Page in the Published Site') %>" href="home/?stage=Live" class="{params:'stage=Live'}"><% _t('PUBLIS','Published Site') %></a>
<a style="display: none; margin-left: 20px;" id="viewArchivedSite" href="home/"><% _t('ARCHS','Archived Site') %></a>
<span id="SwitchView">$SwitchView</span>
<% end_if %>
</div>
</div>