FIX Page type blacklist not matching classes correctly (Fixes 297)

Tidied up the UI, removed custom javascript in favour of core Toggle field.
This commit is contained in:
Will Rossiter 2017-09-12 08:06:22 +12:00
parent 32385e580d
commit 188b02df6b
3 changed files with 23 additions and 46 deletions

View File

@ -1,6 +1,5 @@
/*jslint browser: true, nomen: true*/
/*global $, window, jQuery*/
(function($) {
'use strict';
$.entwine('ss', function($) {
@ -13,8 +12,8 @@
}
});
/*
* Reload subsites dropdown when links are processed
/*
* Reload subsites dropdown when links are processed
*/
$('.cms-container .cms-menu-list li a').entwine({
onclick: function(e) {
@ -23,8 +22,8 @@
}
});
/*
* Reload subsites dropdown when the admin area reloads (for deleting sites)
/*
* Reload subsites dropdown when the admin area reloads (for deleting sites)
*/
$('.cms-container .SubsiteAdmin .cms-edit-form fieldset.ss-gridfield').entwine({
onreload: function(e) {
@ -35,8 +34,8 @@
/*
/*
* Reload subsites dropdown when subsites are added or names are modified
*/
$('.cms-container .cms-content-fields .subsite-model').entwine({
@ -45,7 +44,7 @@
this._super(e);
}
});
// Subsite tab of Group editor
$('#Form_ItemEditForm_AccessAllSubsites').entwine({
/**
@ -53,18 +52,18 @@
*/
onmatch: function () {
this.showHideSubsiteList();
var ref=this;
$('#Form_ItemEditForm_AccessAllSubsites input').change(function() {
ref.showHideSubsiteList();
});
},
showHideSubsiteList: function () {
$('#Form_ItemEditForm_Subsites').parent().parent().css('display', ($('#Form_ItemEditForm_AccessAllSubsites_1').is(':checked') ? 'none':''));
}
});
$('.cms-edit-form').entwine({
/**
* TODO: Fix with Entwine API extension. See https://github.com/silverstripe/silverstripe-subsites/pull/125
@ -89,26 +88,6 @@
return opts;
}
});
/**
* Binding a visibility toggle anchor to a longer list of checkboxes.
* Hidden by default, unless either the toggle checkbox, or any of the
* actual value checkboxes are selected.
*/
$('#PageTypeBlacklist').entwine({
onmatch: function() {
var hasLimits=Boolean($('#PageTypeBlacklist').find('input:checked').length);
jQuery('#PageTypeBlacklist').toggle(hasLimits);
//Bind listener
$('a#PageTypeBlacklistToggle').click(function(e) {
jQuery('#PageTypeBlacklist').toggle();
e.stopPropagation();
return false;
});
}
});
$('.cms-edit-form input[name=action_copytosubsite]').entwine({
onclick: function(e) {

View File

@ -475,9 +475,12 @@ class SiteTreeSubsites extends DataExtension
{
// Typically called on a singleton, so we're not using the Subsite() relation
$subsite = Subsite::currentSubsite();
if ($subsite && $subsite->exists() && $subsite->PageTypeBlacklist) {
$blacklisted = explode(',', $subsite->PageTypeBlacklist);
// All subclasses need to be listed explicitly
$blacklist = str_replace(['[', '"', ']'], '', $subsite->PageTypeBlacklist);
$blacklist = str_replace(['\\\\'], '\\', $blacklist);
$blacklisted = explode(',', $blacklist);
if (in_array(get_class($this->owner), $blacklisted)) {
return false;
}

View File

@ -20,6 +20,7 @@ use SilverStripe\Forms\LiteralField;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\i18n\Data\Intl\IntlLocales;
use SilverStripe\i18n\i18n;
use SilverStripe\ORM\ArrayLib;
@ -34,6 +35,7 @@ use SilverStripe\Security\Permission;
use SilverStripe\Security\Security;
use SilverStripe\Subsites\State\SubsiteState;
use SilverStripe\Versioned\Versioned;
use UnexpectedValueException;
/**
@ -697,18 +699,12 @@ class Subsite extends DataObject
// new TextField('RedirectURL', 'Redirect to URL', $this->RedirectURL),
CheckboxField::create('DefaultSite', $this->fieldLabel('DefaultSite'), $this->DefaultSite),
CheckboxField::create('IsPublic', $this->fieldLabel('IsPublic'), $this->IsPublic),
LiteralField::create(
ToggleCompositeField::create(
'PageTypeBlacklistToggle',
sprintf(
'<div class="field"><a href="#" id="PageTypeBlacklistToggle">%s</a></div>',
_t(__CLASS__ . '.PageTypeBlacklistField', 'Disallow page types?')
)
),
CheckboxSetField::create(
'PageTypeBlacklist',
false,
$pageTypeMap
)
_t(__CLASS__ . '.PageTypeBlacklistField', 'Disallow page types?'),
[CheckboxSetField::create('PageTypeBlacklist', '', $pageTypeMap)]
)->setHeadingLevel(4)
)
),
HiddenField::create('ID', '', $this->ID),
@ -721,8 +717,7 @@ class Subsite extends DataObject
$fields->addFieldToTab(
'Root.Configuration',
DropdownField::create('Theme', $this->fieldLabel('Theme'), $this->allowedThemes(), $this->Theme)
->setEmptyString(_t(__CLASS__ . '.ThemeFieldEmptyString', '-')),
'PageTypeBlacklistToggle'
->setEmptyString(_t(__CLASS__ . '.ThemeFieldEmptyString', '-'))
);
}