mirror of
https://github.com/silverstripe/silverstripe-subsites
synced 2024-10-22 11:05:55 +02:00
Merge pull request #104 from adrexia/subsites-ui
API: Subsite support for menu of cms (hides admins that don't declare support) (fixes #101 and #89 )
This commit is contained in:
commit
110ce7751d
@ -17,3 +17,12 @@ ErrorPage::add_extension('ErrorPageSubsite');
|
|||||||
SiteConfig::add_extension('SiteConfigSubsites');
|
SiteConfig::add_extension('SiteConfigSubsites');
|
||||||
|
|
||||||
SS_Report::add_excluded_reports('SubsiteReportWrapper');
|
SS_Report::add_excluded_reports('SubsiteReportWrapper');
|
||||||
|
|
||||||
|
//Display in cms menu
|
||||||
|
AssetAdmin::add_extension('SubsiteMenuExtension');
|
||||||
|
SecurityAdmin::add_extension('SubsiteMenuExtension');
|
||||||
|
CMSMain::add_extension('SubsiteMenuExtension');
|
||||||
|
CMSPagesController::add_extension('SubsiteMenuExtension');
|
||||||
|
SubsiteAdmin::add_extension('SubsiteMenuExtension');
|
||||||
|
CMSSettingsController::add_extension('SubsiteMenuExtension');
|
||||||
|
|
||||||
|
@ -29,4 +29,18 @@ class SubsiteAdmin extends ModelAdmin {
|
|||||||
|
|
||||||
return $form;
|
return $form;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getResponseNegotiator() {
|
||||||
|
$negotiator = parent::getResponseNegotiator();
|
||||||
|
$self = $this;
|
||||||
|
// Register a new callback
|
||||||
|
$negotiator->setCallback('SubsiteList', function() use(&$self) {
|
||||||
|
return $self->SubsiteList();
|
||||||
|
});
|
||||||
|
return $negotiator;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function SubsiteList() {
|
||||||
|
return $this->renderWith('SubsiteList');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,17 @@ class FileSubsites extends DataExtension {
|
|||||||
$values[$site->ID] = $site->Title;
|
$values[$site->ID] = $site->Title;
|
||||||
}
|
}
|
||||||
ksort($values);
|
ksort($values);
|
||||||
if($sites)$fields->push(new DropdownField('SubsiteID', 'Subsite', $values));
|
if($sites){
|
||||||
|
//Dropdown needed to move folders between subsites
|
||||||
|
$fields->push($dropdown = new DropdownField('SubsiteID', 'Subsite', $values));
|
||||||
|
$fields->push(new LiteralField(
|
||||||
|
'Message',
|
||||||
|
'<p class="message notice">'.
|
||||||
|
_t('ASSETADMIN.SUBSITENOTICE', 'Folders and files created in the main site are accessible by all subsites.')
|
||||||
|
.'</p>'
|
||||||
|
));
|
||||||
|
$dropdown->addExtraClass('subsites-move-dropdown');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,6 +51,9 @@ class LeftAndMainSubsites extends Extension {
|
|||||||
$fields->push(new HiddenField('SubsiteID', 'SubsiteID', Subsite::currentSubsiteID()));
|
$fields->push(new HiddenField('SubsiteID', 'SubsiteID', Subsite::currentSubsiteID()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns a list of the subsites accessible to the current user
|
||||||
|
*/
|
||||||
public function Subsites() {
|
public function Subsites() {
|
||||||
// figure out what permission the controller needs
|
// figure out what permission the controller needs
|
||||||
// Subsite::accessible_sites() expects something, so if there's no permission
|
// Subsite::accessible_sites() expects something, so if there's no permission
|
||||||
@ -64,74 +67,72 @@ class LeftAndMainSubsites extends Extension {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch($this->owner->class) {
|
return Subsite::accessible_sites($permission);
|
||||||
case "AssetAdmin":
|
|
||||||
$subsites = Subsite::accessible_sites($permission, true, "Shared files & images");
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "SecurityAdmin":
|
|
||||||
$subsites = Subsite::accessible_sites($permission, true, "Groups accessing all sites");
|
|
||||||
if($subsites->find('ID',0)) {
|
|
||||||
$subsites->push(new ArrayData(array('Title' => 'All groups', 'ID' => -1)));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "CMSMain":
|
|
||||||
case "CMSPagesController":
|
|
||||||
// If there's a default site then main site has no meaning
|
|
||||||
$showMainSite = !DataObject::get_one('Subsite',"\"DefaultSite\"=1");
|
|
||||||
$subsites = Subsite::accessible_sites($permission, $showMainSite);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "SubsiteAdmin":
|
|
||||||
$subsites = Subsite::accessible_sites('ADMIN', true);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
$subsites = Subsite::accessible_sites($permission);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $subsites;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function SubsiteList() {
|
/*
|
||||||
|
* Generates a list of subsites with the data needed to
|
||||||
|
* produce a dropdown site switcher
|
||||||
|
* @return ArrayList
|
||||||
|
*/
|
||||||
|
|
||||||
|
public function ListSubsites(){
|
||||||
$list = $this->Subsites();
|
$list = $this->Subsites();
|
||||||
$currentSubsiteID = Subsite::currentSubsiteID();
|
$currentSubsiteID = Subsite::currentSubsiteID();
|
||||||
|
|
||||||
if($list->Count() > 1) {
|
if($list == null || $list->Count() == 1 && $list->First()->DefaultSite == true){
|
||||||
$output = '<div class="field dropdown">';
|
return false;
|
||||||
$output .= '<select id="SubsitesSelect">';
|
|
||||||
|
|
||||||
foreach($list as $subsite) {
|
|
||||||
$selected = $subsite->ID == $currentSubsiteID ? ' selected="selected"' : '';
|
|
||||||
|
|
||||||
$output .= "\n<option value=\"{$subsite->ID}\"$selected>". Convert::raw2xml($subsite->Title) . "</option>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$output .= '</select></div>';
|
|
||||||
|
|
||||||
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
|
|
||||||
return $output;
|
|
||||||
} elseif($list->Count() == 1) {
|
|
||||||
if($list->First()->DefaultSite==false) {
|
|
||||||
$output = '<div class="field dropdown">';
|
|
||||||
$output .= '<select id="SubsitesSelect">';
|
|
||||||
$output .= "\n<option value=\"0\">". _t('LeftAndMainSubsites.DEFAULT_SITE', 'Default site') . "</option>";
|
|
||||||
foreach($list as $subsite) {
|
|
||||||
$selected = $subsite->ID == $currentSubsiteID ? ' selected="selected"' : '';
|
|
||||||
|
|
||||||
$output .= "\n<option value=\"{$subsite->ID}\"$selected>". Convert::raw2xml($subsite->Title) . "</option>";
|
|
||||||
}
|
|
||||||
|
|
||||||
$output .= '</select></div>';
|
|
||||||
|
|
||||||
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
|
|
||||||
return $output;
|
|
||||||
} else {
|
|
||||||
return '<span>'.$list->First()->Title.'</span>';
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Requirements::javascript('subsites/javascript/LeftAndMain_Subsites.js');
|
||||||
|
|
||||||
|
$output = new ArrayList();
|
||||||
|
|
||||||
|
foreach($list as $subsite) {
|
||||||
|
$CurrentState = $subsite->ID == $currentSubsiteID ? 'selected' : '';
|
||||||
|
|
||||||
|
$output->push(new ArrayData(array(
|
||||||
|
'CurrentState' => $CurrentState,
|
||||||
|
'ID' => $subsite->ID,
|
||||||
|
'Title' => Convert::raw2xml($subsite->Title)
|
||||||
|
)));
|
||||||
|
}
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Returns a subset of the main menu, filtered by admins that have
|
||||||
|
* a subsiteCMSShowInMenu method returning true
|
||||||
|
*
|
||||||
|
* @return ArrayList
|
||||||
|
*/
|
||||||
|
public function SubsiteMainMenu(){
|
||||||
|
if(Subsite::currentSubsiteID() == 0){
|
||||||
|
return $this->owner->MainMenu();
|
||||||
|
}
|
||||||
|
// loop main menu items, add all items that have subsite support
|
||||||
|
$mainMenu = $this->owner->MainMenu();
|
||||||
|
$subsitesMenu = new ArrayList();
|
||||||
|
|
||||||
|
foreach($mainMenu as $menuItem){
|
||||||
|
|
||||||
|
$controllerName = $menuItem->MenuItem->controller;
|
||||||
|
|
||||||
|
if(class_exists($controllerName)){
|
||||||
|
$controller = singleton($controllerName);
|
||||||
|
|
||||||
|
if($controller->hasMethod('subsiteCMSShowInMenu') && $controller->subsiteCMSShowInMenu()){
|
||||||
|
$subsitesMenu->push($menuItem);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if($menuItem->Code == 'Help'){
|
||||||
|
$subsitesMenu->push($menuItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return $subsitesMenu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function CanAddSubsites() {
|
public function CanAddSubsites() {
|
||||||
|
19
code/extensions/SubsiteMenuExtension.php
Normal file
19
code/extensions/SubsiteMenuExtension.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Simple extension to show admins in the menu of subsites.
|
||||||
|
* If an admin area should be available to a subsite, you can attach
|
||||||
|
* this class to your admin in config. eg:
|
||||||
|
*
|
||||||
|
* MyAdmin::add_extension('SubsiteMenuExtension');
|
||||||
|
*
|
||||||
|
* Or you can include the subsiteCMSShowInMenu function in your admin class and have it return true
|
||||||
|
*/
|
||||||
|
|
||||||
|
class SubsiteMenuExtension extends Extension{
|
||||||
|
|
||||||
|
public function subsiteCMSShowInMenu(){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -219,7 +219,7 @@ class Subsite extends DataObject implements PermissionProvider {
|
|||||||
asort($pageTypeMap);
|
asort($pageTypeMap);
|
||||||
|
|
||||||
$fields = new FieldList(
|
$fields = new FieldList(
|
||||||
new TabSet('Root',
|
$subsiteTabs = new TabSet('Root',
|
||||||
new Tab('Configuration',
|
new Tab('Configuration',
|
||||||
new HeaderField($this->getClassName() . ' configuration', 2),
|
new HeaderField($this->getClassName() . ' configuration', 2),
|
||||||
new TextField('Title', 'Name of subsite:', $this->Title),
|
new TextField('Title', 'Name of subsite:', $this->Title),
|
||||||
@ -252,6 +252,8 @@ class Subsite extends DataObject implements PermissionProvider {
|
|||||||
new HiddenField('IsSubsite', '', 1)
|
new HiddenField('IsSubsite', '', 1)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$subsiteTabs->addExtraClass('subsite-model');
|
||||||
|
|
||||||
$this->extend('updateCMSFields', $fields);
|
$this->extend('updateCMSFields', $fields);
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
@ -81,3 +81,11 @@ body.SubsiteAdmin .right form #URL .fieldgroup * {
|
|||||||
.cms-add-form #PageType li .class-SubsitesVirtualPage, .class-SubsitesVirtualPage a .jstree-pageicon {
|
.cms-add-form #PageType li .class-SubsitesVirtualPage, .class-SubsitesVirtualPage a .jstree-pageicon {
|
||||||
background-position: 0 -32px !important;
|
background-position: 0 -32px !important;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.subsites-move-dropdown{
|
||||||
|
display:none;
|
||||||
|
}
|
||||||
|
|
||||||
|
#Root_DetailsView .subsites-move-dropdown{
|
||||||
|
display:block;
|
||||||
|
}
|
||||||
|
@ -1,7 +1,89 @@
|
|||||||
|
/*jslint browser: true, nomen: true*/
|
||||||
|
/*global $, window, jQuery*/
|
||||||
|
|
||||||
(function($) {
|
(function($) {
|
||||||
|
'use strict';
|
||||||
$.entwine('ss', function($) {
|
$.entwine('ss', function($) {
|
||||||
$('#SubsitesSelect').live('change', function() {
|
|
||||||
window.location.search=$.query.set('SubsiteID', $(this).val());
|
$('#SubsitesSelect').entwine({
|
||||||
|
onadd:function(){
|
||||||
|
this.on('change', function(){
|
||||||
|
window.location.search=$.query.set('SubsiteID', $(this).val());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$('.cms-container').entwine({
|
||||||
|
|
||||||
|
SubsiteCurrentXHR: null,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* LeftAndMain does not give us possibility to parallel-fetch a PJAX fragment.
|
||||||
|
* We provide our own fetcher that bypasses the history - that's because we
|
||||||
|
* don't want to load a panel, but rather just a subsite dropdown.
|
||||||
|
*/
|
||||||
|
subsiteFetchPjaxFragment: function(url, pjaxFragment) {
|
||||||
|
|
||||||
|
// Make sure only one subsite XHR request is ongoing.
|
||||||
|
if(this.getSubsiteCurrentXHR()){
|
||||||
|
this.getSubsiteCurrentXHR().abort();
|
||||||
|
}
|
||||||
|
|
||||||
|
var self = this,
|
||||||
|
xhr,
|
||||||
|
headers = {},
|
||||||
|
baseUrl = $('base').attr('href');
|
||||||
|
|
||||||
|
url = $.path.isAbsoluteUrl(url) ? url : $.path.makeUrlAbsolute(url, baseUrl);
|
||||||
|
headers['X-Pjax'] = pjaxFragment;
|
||||||
|
|
||||||
|
xhr = $.ajax({
|
||||||
|
headers: headers,
|
||||||
|
url: url,
|
||||||
|
complete: function() {
|
||||||
|
self.setSubsiteCurrentXHR(null);
|
||||||
|
},
|
||||||
|
success: function(data, status, xhr) {
|
||||||
|
self.handleAjaxResponse(data, status, xhr, null);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.setSubsiteCurrentXHR(xhr);
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reload subsites dropdown when links are processed
|
||||||
|
*/
|
||||||
|
$('.cms-container .cms-menu-list li a').entwine({
|
||||||
|
onclick: function(e) {
|
||||||
|
$('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList');
|
||||||
|
this._super(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reload subsites dropdown when the admin area reloads (for deleting sites)
|
||||||
|
*/
|
||||||
|
$('.cms-container .SubsiteAdmin .cms-edit-form fieldset.ss-gridfield').entwine({
|
||||||
|
onreload: function(e) {
|
||||||
|
$('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList');
|
||||||
|
this._super(e);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Reload subsites dropdown when subsites are added or names are modified
|
||||||
|
*/
|
||||||
|
$('.cms-container .cms-content-fields .subsite-model').entwine({
|
||||||
|
onadd: function(e) {
|
||||||
|
$('.cms-container').subsiteFetchPjaxFragment('admin/subsites/', 'SubsiteList');
|
||||||
|
this._super(e);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// Subsite tab of Group editor
|
// Subsite tab of Group editor
|
||||||
@ -72,7 +154,9 @@
|
|||||||
onafterIframeAdjustedForPreview: function(event, doc) {
|
onafterIframeAdjustedForPreview: function(event, doc) {
|
||||||
var subsiteId = $(doc).find('meta[name=x-subsite-id]').attr('content');
|
var subsiteId = $(doc).find('meta[name=x-subsite-id]').attr('content');
|
||||||
|
|
||||||
if (!subsiteId) return;
|
if (!subsiteId) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Inject the SubsiteID into internal links.
|
// Inject the SubsiteID into internal links.
|
||||||
$(doc).find('a').each(function() {
|
$(doc).find('a').each(function() {
|
||||||
@ -95,11 +179,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
}(jQuery));
|
||||||
})(jQuery);
|
|
||||||
|
9
templates/Includes/SubsiteList.ss
Normal file
9
templates/Includes/SubsiteList.ss
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<div class="cms-subsites" data-pjax-fragment="SubsiteList">
|
||||||
|
<div class="field dropdown">
|
||||||
|
<select id="SubsitesSelect">
|
||||||
|
<% loop $ListSubsites %>
|
||||||
|
<option value="$ID" $CurrentState>$Title</option>
|
||||||
|
<% end_loop %>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
@ -2,33 +2,32 @@
|
|||||||
<div class="cms-logo-header north">
|
<div class="cms-logo-header north">
|
||||||
<div class="cms-logo">
|
<div class="cms-logo">
|
||||||
<a href="$ApplicationLink" target="_blank" title="$ApplicationName (Version - $CMSVersion)">
|
<a href="$ApplicationLink" target="_blank" title="$ApplicationName (Version - $CMSVersion)">
|
||||||
$ApplicationName <% if CMSVersion %><abbr class="version">$CMSVersion</abbr><% end_if %>
|
$ApplicationName <% if $CMSVersion %><abbr class="version">$CMSVersion</abbr><% end_if %>
|
||||||
</a>
|
</a>
|
||||||
<span><% if SiteConfig %>$SiteConfig.Title<% else %>$ApplicationName<% end_if %></span>
|
<span><% if $SiteConfig %>$SiteConfig.Title<% else %>$ApplicationName<% end_if %></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="cms-login-status">
|
<div class="cms-login-status">
|
||||||
<a href="Security/logout" class="logout-link" title="<% _t('LeftAndMain_Menu.ss.LOGOUT','Log out') %>"><% _t('LeftAndMain_Menu.ss.LOGOUT','Log out') %></a>
|
<a href="Security/logout" class="logout-link" title="<% _t('LeftAndMain_Menu.ss.LOGOUT','Log out') %>"><% _t('LeftAndMain_Menu.ss.LOGOUT','Log out') %></a>
|
||||||
<% with CurrentMember %>
|
<% with $CurrentMember %>
|
||||||
<span>
|
<span>
|
||||||
<% _t('LeftAndMain_Menu.ss.Hello','Hi') %>
|
<% _t('LeftAndMain_Menu.ss.Hello','Hi') %>
|
||||||
<a href="{$AbsoluteBaseURL}admin/myprofile" class="profile-link ss-ui-dialog-link" data-popupclass="edit-profile-popup">
|
<a href="{$AbsoluteBaseURL}admin/myprofile" class="profile-link">
|
||||||
<% if FirstName && Surname %>$FirstName $Surname<% else_if FirstName %>$FirstName<% else %>$Email<% end_if %>
|
<% if $FirstName && $Surname %>$FirstName $Surname<% else_if $FirstName %>$FirstName<% else %>$Email<% end_if %>
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</span>
|
||||||
<% end_with %>
|
<% end_with %>
|
||||||
</div>
|
</div>
|
||||||
|
<% if $ListSubsites %>
|
||||||
<div class="cms-subsites">
|
<% include SubsiteList %>
|
||||||
$SubsiteList
|
<% end_if %>
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="cms-panel-content center">
|
<div class="cms-panel-content center">
|
||||||
<ul class="cms-menu-list">
|
<ul class="cms-menu-list">
|
||||||
<% loop MainMenu %>
|
<% loop $SubsiteMainMenu %>
|
||||||
<li class="$LinkingMode $FirstLast <% if LinkingMode == 'link' %><% else %>opened<% end_if %>" id="Menu-$Code" title="$Title.ATT">
|
<li class="$LinkingMode $FirstLast <% if $LinkingMode == 'link' %><% else %>opened<% end_if %>" id="Menu-$Code" title="$Title.ATT">
|
||||||
<a href="$Link" <% if Code == 'Help' %>target="_blank"<% end_if%>>
|
<a href="$Link" <% if $Code == 'Help' %>target="_blank"<% end_if %>>
|
||||||
<span class="icon icon-16 icon-{$Code.LowerCase}"> </span>
|
<span class="icon icon-16 icon-{$Code.LowerCase}"> </span>
|
||||||
<span class="text">$Title</span>
|
<span class="text">$Title</span>
|
||||||
</a>
|
</a>
|
||||||
|
Loading…
Reference in New Issue
Block a user