FIX Validation of existing tags, duplicated GridField add button, formatting in categorisation, bootstrapify buttons

This commit is contained in:
Robbie Averill 2017-01-13 15:33:53 +13:00
parent 5f07a3cc23
commit c1cb8576b3
12 changed files with 179 additions and 166 deletions

View File

@ -117,6 +117,9 @@ label.right.toggle-description-correct-right {
.blog-cms-categorisation .MergeActionReveal { .blog-cms-categorisation .MergeActionReveal {
margin-left: 10px; } margin-left: 10px; }
.blog-cms-categorisation .toolbar--content {
margin-top: 0; }
.blog-cms-categorisation .MergeActionReveal:after { .blog-cms-categorisation .MergeActionReveal:after {
content: ''; content: '';
background: url("../images/move-icon.png"); background: url("../images/move-icon.png");
@ -124,3 +127,6 @@ label.right.toggle-description-correct-right {
height: 16px; height: 16px;
width: 16px; width: 16px;
margin-left: 4px; } margin-left: 4px; }
.blog-cms-categorisation button.action {
margin-left: 5px; }

View File

@ -1,20 +1,16 @@
(function ($) { (function ($) {
$.entwine('ss', function ($) { $.entwine('ss', function ($) {
/** /**
* Prevent the CMS hijacking the return key * Prevent the CMS hijacking the return key
*/ */
$('.add-existing-autocompleter input.text').entwine({ $('.add-existing-autocompleter input.text').entwine({
'onkeydown': function (e) { 'onkeydown': function (e) {
if(e.which == 13) { if (e.which == 13) {
$parent = $(this).parents('.add-existing-autocompleter'); $parent = $(this).parents('.add-existing-autocompleter');
$parent.find('button[type="submit"]').click(); $parent.find('button[type="submit"]').click();
return false; return false;
} }
} }
}); });
}); });
})(jQuery); })(jQuery);

View File

@ -87,7 +87,7 @@ en:
PLURALNAME: 'Blog Recent Posts Widgets' PLURALNAME: 'Blog Recent Posts Widgets'
SINGULARNAME: 'Blog Recent Posts Widget' SINGULARNAME: 'Blog Recent Posts Widget'
BlogTag: BlogTag:
Duplicate: 'A blog tags already exists with that name' Duplicate: 'A blog tag already exists with that name'
PLURALNAME: 'Blog Tags' PLURALNAME: 'Blog Tags'
SINGULARNAME: 'Blog Tag' SINGULARNAME: 'Blog Tag'
Title: Title Title: Title

View File

@ -17,185 +17,192 @@
} }
#FeaturedImage .middleColumn { #FeaturedImage .middleColumn {
clear: none; clear: none;
float: left; float: left;
} }
.has-panel .cms-content-tools.blog-admin-sidebar { .has-panel .cms-content-tools.blog-admin-sidebar {
width: 280px; width: 280px;
border-right: none; border-right: none;
border-left: 1px solid #C0C0C2; border-left: 1px solid #C0C0C2;
position: absolute !important; /* overrides cms !imporant style */ position: absolute !important; /* overrides cms !imporant style */
right: 0px; right: 0px;
top: 0; top: 0;
height: 100%; height: 100%;
.cms-panel-toggle a { .cms-panel-toggle a {
text-align: left; text-align: left;
margin: 0; margin: 0;
} }
.cms-panel-toggle.south { .cms-panel-toggle.south {
border-top: 1px solid #aaaaaa; border-top: 1px solid #aaaaaa;
} }
~ .blog-admin-outer { ~ .blog-admin-outer {
width: 100%; width: 100%;
padding-right: 280px; padding-right: 280px;
position: absolute; position: absolute;
height: 100%; height: 100%;
overflow-y: hidden; overflow-y: hidden;
overflow-x: hidden; overflow-x: hidden;
box-sizing: border-box; box-sizing: border-box;
> .ss-tabset { > .ss-tabset {
position: relative; position: relative;
overflow: auto; overflow: auto;
height: 100%; height: 100%;
width: 100%; width: 100%;
#Title { #Title {
label { label {
float: none; float: none;
} }
.middleColumn, input { .middleColumn, input {
width: 100%; width: 100%;
max-width: 100%; max-width: 100%;
margin-left: 0; margin-left: 0;
} }
} }
} }
} }
.cms-content-view { .cms-content-view {
> .field { > .field {
+ .field { + .field {
margin-top: 10px; margin-top: 10px;
} }
&.urlsegment { &.urlsegment {
.preview { .preview {
padding-top: 0; padding-top: 0;
line-height: 25px; line-height: 25px;
} }
.edit { .edit {
float: right; float: right;
} }
} }
&.datetime { &.datetime {
> .middleColumn { > .middleColumn {
> .date { > .date {
width: 60%; width: 60%;
} }
> .time { > .time {
width: 36%; width: 36%;
float: right; float: right;
} }
.middleColumn, input { .middleColumn, input {
width: 100%; width: 100%;
} }
} }
} }
} }
} }
&.collapsed { &.collapsed {
~ .blog-admin-outer { ~ .blog-admin-outer {
padding-right: 41px; padding-right: 41px;
#Root_Main { #Root_Main {
margin-right: 15px; margin-right: 15px;
} }
} }
} }
&.cms-content-tools { &.cms-content-tools {
.cms-panel-content { .cms-panel-content {
width: auto; width: auto;
} }
} }
} }
.toggle-description { .toggle-description {
text-indent: -1000000px; text-indent: -1000000px;
display: inline-block; display: inline-block;
background: url("../images/information.png") no-repeat center center; background: url("../images/information.png") no-repeat center center;
width: 20px; width: 20px;
height: 20px; height: 20px;
margin-left: 4px; margin-left: 4px;
} }
.middleColumn.toggle-description-correct-middle { .middleColumn.toggle-description-correct-middle {
margin-left: 0; margin-left: 0;
float: left; float: left;
width: 416px; width: 416px;
} }
label.right.toggle-description-correct-right { label.right.toggle-description-correct-right {
display: inline-block; display: inline-block;
margin-left: 0; margin-left: 0;
clear: none; clear: none;
float: left; float: left;
} }
.description.toggle-description-correct-description { .description.toggle-description-correct-description {
width: 416px; width: 416px;
padding: 12px 0; padding: 12px 0;
} }
.custom-summary { .custom-summary {
.ui-accordion-content .field { .ui-accordion-content .field {
margin: 0; margin: 0;
} }
.ui-accordion-content, .ui-accordion-content,
.ui-accordion-content .field { .ui-accordion-content .field {
padding: 0; padding: 0;
} }
.ui-icon-triangle-1-e { .ui-icon-triangle-1-e {
background-position: -16px -128px; background-position: -16px -128px;
} }
} }
.cms table.ss-gridfield-table { .cms table.ss-gridfield-table {
tr td.MergeAction { tr td.MergeAction {
width: 225px; width: 225px;
a { a {
display: block; display: block;
height: 100%; height: 100%;
width: 100%; width: 100%;
} }
select { select {
width: 150px; width: 150px;
} }
} }
} }
.cms-content-actions, .cms-content-actions,
.cms-preview-controls { .cms-preview-controls {
z-index: 999; z-index: 999;
} }
.blog-cms-categorisation { .blog-cms-categorisation {
.MergeActionReveal {
margin-left: 10px;
}
.MergeActionReveal { .toolbar--content {
margin-left: 10px; margin-top: 0;
} }
.MergeActionReveal:after { .MergeActionReveal:after {
content: ''; content: '';
background: url('../images/move-icon.png'); background: url('../images/move-icon.png');
display: inline-block; display: inline-block;
height: 16px; height: 16px;
width: 16px; width: 16px;
margin-left: 4px; margin-left: 4px;
} }
button.action {
margin-left: 5px;
}
} }

View File

@ -20,7 +20,7 @@ class GridFieldCategorisationConfig extends GridFieldConfig_RecordEditor
{ {
parent::__construct($itemsPerPage); parent::__construct($itemsPerPage);
$this->removeComponentsByType('GridFieldAddNewButton'); $this->removeComponentsByType('SilverStripe\\Forms\\GridField\\GridFieldAddNewButton');
$this->addComponent( $this->addComponent(
new GridFieldAddByDBField('buttons-before-left') new GridFieldAddByDBField('buttons-before-left')

View File

@ -94,7 +94,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
if ($obj->canCreate()) { if ($obj->canCreate()) {
$id = $gridField->getList()->add($obj); $id = $gridField->getList()->add($obj);
if (!$id) { if (!$id) {
$gridField->setError( $gridField->setCustomValidationMessage(
_t( _t(
'GridFieldAddByDBField.AddFail', 'GridFieldAddByDBField.AddFail',
'Unable to save {class} to the database.', 'Unable to save {class} to the database.',
@ -102,8 +102,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
array( array(
'class' => get_class($obj), 'class' => get_class($obj),
) )
), )
'error'
); );
} }
} else { } else {
@ -174,7 +173,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$obj = singleton($dataClass); $obj = singleton($dataClass);
if (!$obj->canCreate()) { if (!$obj->canCreate()) {
return ""; return '';
} }
$dbField = $this->getDataObjectField(); $dbField = $this->getDataObjectField();
@ -192,16 +191,17 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$addAction = new GridField_FormAction( $addAction = new GridField_FormAction(
$gridField, $gridField,
'add', 'add',
_t('GridFieldAddByDBField.Add', _t(
'Add {name}', "Add button text", 'GridFieldAddByDBField.Add',
array( 'Add {name}',
'name' => $obj->i18n_singular_name(), 'Add button text',
) ['name' => $obj->i18n_singular_name()]
), ),
'add', 'add',
'add' 'add'
); );
$addAction->setAttribute('data-icon', 'add'); $addAction->setAttribute('data-icon', 'add');
$addAction->addExtraClass('btn btn-primary');
$forTemplate = new ArrayData(array()); $forTemplate = new ArrayData(array());
@ -210,7 +210,9 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$forTemplate->Fields->push($addAction); $forTemplate->Fields->push($addAction);
return array( return array(
$this->targetFragment => $forTemplate->renderWith('SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField') $this->targetFragment => $forTemplate->renderWith(
'SilverStripe\\Blog\\Forms\\GridField\\GridFieldAddByDBField'
)
); );
} }
} }

View File

@ -3,7 +3,7 @@
namespace SilverStripe\Blog\Model; namespace SilverStripe\Blog\Model;
use Page; use Page;
use Page_Controller; use PageController;
use SilverStripe\Blog\Admin\GridFieldCategorisationConfig; use SilverStripe\Blog\Admin\GridFieldCategorisationConfig;
use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost; use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost;
use SilverStripe\CMS\Controllers\RootURLController; use SilverStripe\CMS\Controllers\RootURLController;
@ -272,7 +272,7 @@ class Blog extends Page implements PermissionProvider
public function RoleOf($member) public function RoleOf($member)
{ {
if (is_numeric($member)) { if (is_numeric($member)) {
$member = DataObject::get_by_id(Member::class, $member); $member = Member::get()->byId($member);
} }
if (!$member) { if (!$member) {

View File

@ -2,7 +2,7 @@
namespace SilverStripe\Blog\Model; namespace SilverStripe\Blog\Model;
use Page_Controller; use PageController;
use SilverStripe\Control\RSS\RSSFeed; use SilverStripe\Control\RSS\RSSFeed;
use SilverStripe\ORM\ArrayList; use SilverStripe\ORM\ArrayList;
use SilverStripe\ORM\FieldType\DBDatetime; use SilverStripe\ORM\FieldType\DBDatetime;
@ -13,7 +13,7 @@ use SilverStripe\Security\Member;
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class BlogController extends Page_Controller class BlogController extends PageController
{ {
/** /**
* @var array * @var array

View File

@ -36,8 +36,10 @@ trait BlogObject
*/ */
public function getCMSFields() public function getCMSFields()
{ {
$fields = TabSet::create('Root', $fields = TabSet::create(
Tab::create('Main', 'Root',
Tab::create(
'Main',
TextField::create('Title', _t(self::class . '.Title', 'Title')) TextField::create('Title', _t(self::class . '.Title', 'Title'))
) )
); );
@ -65,9 +67,10 @@ trait BlogObject
return $validation; return $validation;
} }
if ($this->getDuplicatesByUrlSegment()->count() > 0) { if ($this->getDuplicatesByField('Title')->count() > 0) {
$validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION); $validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION);
} }
return $validation; return $validation;
} }
@ -134,7 +137,7 @@ trait BlogObject
return $extended; return $extended;
} }
return $this->Blog()->canEdit($member); return $this->Blog()->canDelete($member);
} }
/** /**
@ -178,36 +181,37 @@ trait BlogObject
$increment = (int) $increment; $increment = (int) $increment;
$filter = URLSegmentFilter::create(); $filter = URLSegmentFilter::create();
$this->URLSegment = $filter->filter($this->owner->Title); $this->URLSegment = $filter->filter($this->Title);
if ($increment > 0) { if ($increment > 0) {
$this->URLSegment .= '-' . $increment; $this->URLSegment .= '-' . $increment;
} }
if ($this->getDuplicatesByUrlSegment()->count() > 0) { if ($this->getDuplicatesByField('URLSegment')->count() > 0) {
$this->owner->generateURLSegment($increment + 1); $this->generateURLSegment($increment + 1);
} }
return $this->owner->URLSegment; return $this->URLSegment;
} }
/** /**
* Looks for objects of the same type by url segment. * Looks for objects o the same type and the same value by the given Field
* *
* @param string $field E.g. URLSegment or Title
* @return DataList * @return DataList
*/ */
protected function getDuplicatesByUrlSegment() protected function getDuplicatesByField($field)
{ {
$duplicates = DataList::create(self::class) $duplicates = DataList::create(self::class)
->filter( ->filter(
array( [
'URLSegment' => $this->URLSegment, $field => $this->$field,
'BlogID' => (int) $this->BlogID, 'BlogID' => (int) $this->BlogID
) ]
); );
if ($this->ID) { if ($this->ID) {
$duplicates = $duplicates->exclude('ID', $this->ID); $duplicates->exclude('ID', $this->ID);
} }
return $duplicates; return $duplicates;

View File

@ -74,7 +74,7 @@ class BlogPost extends Page
private static $many_many = array( private static $many_many = array(
'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory', 'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory',
'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag', 'Tags' => 'SilverStripe\\Blog\\Model\\BlogTag',
'Authors' => 'SilverStripe\\Security\\Member' 'Authors' => Member::class
); );
/** /**
@ -230,8 +230,6 @@ class BlogPost extends Page
$fields->insertAfter($summaryHolder, 'FeaturedImage'); $fields->insertAfter($summaryHolder, 'FeaturedImage');
$fields->push(HiddenField::create('MenuTitle'));
$urlSegment = $fields->dataFieldByName('URLSegment'); $urlSegment = $fields->dataFieldByName('URLSegment');
$urlSegment->setURLPrefix($this->Parent()->RelativeLink()); $urlSegment->setURLPrefix($this->Parent()->RelativeLink());

View File

@ -2,13 +2,13 @@
namespace SilverStripe\Blog\Model; namespace SilverStripe\Blog\Model;
use Page_Controller; use PageController;
/** /**
* @package silverstripe * @package silverstripe
* @subpackage blog * @subpackage blog
*/ */
class BlogPostController extends Page_Controller class BlogPostController extends PageController
{ {
} }

View File

@ -72,6 +72,6 @@ class BlogTag extends DataObject implements CategorisationObject
*/ */
protected function getDuplicateError() protected function getDuplicateError()
{ {
return _t('BlogTag.Duplicate', 'A blog tags already exists with that name.'); return _t('BlogTag.Duplicate', 'A blog tag already exists with that name.');
} }
} }