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

View File

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

View File

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

View File

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

View File

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

View File

@ -94,7 +94,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
if ($obj->canCreate()) {
$id = $gridField->getList()->add($obj);
if (!$id) {
$gridField->setError(
$gridField->setCustomValidationMessage(
_t(
'GridFieldAddByDBField.AddFail',
'Unable to save {class} to the database.',
@ -102,8 +102,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
array(
'class' => get_class($obj),
)
),
'error'
)
);
}
} else {
@ -174,7 +173,7 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$obj = singleton($dataClass);
if (!$obj->canCreate()) {
return "";
return '';
}
$dbField = $this->getDataObjectField();
@ -192,16 +191,17 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$addAction = new GridField_FormAction(
$gridField,
'add',
_t('GridFieldAddByDBField.Add',
'Add {name}', "Add button text",
array(
'name' => $obj->i18n_singular_name(),
)
_t(
'GridFieldAddByDBField.Add',
'Add {name}',
'Add button text',
['name' => $obj->i18n_singular_name()]
),
'add',
'add'
);
$addAction->setAttribute('data-icon', 'add');
$addAction->addExtraClass('btn btn-primary');
$forTemplate = new ArrayData(array());
@ -210,7 +210,9 @@ class GridFieldAddByDBField implements GridField_ActionProvider, GridField_HTMLP
$forTemplate->Fields->push($addAction);
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;
use Page;
use Page_Controller;
use PageController;
use SilverStripe\Blog\Admin\GridFieldCategorisationConfig;
use SilverStripe\Blog\Forms\GridField\GridFieldConfig_BlogPost;
use SilverStripe\CMS\Controllers\RootURLController;
@ -272,7 +272,7 @@ class Blog extends Page implements PermissionProvider
public function RoleOf($member)
{
if (is_numeric($member)) {
$member = DataObject::get_by_id(Member::class, $member);
$member = Member::get()->byId($member);
}
if (!$member) {

View File

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

View File

@ -36,8 +36,10 @@ trait BlogObject
*/
public function getCMSFields()
{
$fields = TabSet::create('Root',
Tab::create('Main',
$fields = TabSet::create(
'Root',
Tab::create(
'Main',
TextField::create('Title', _t(self::class . '.Title', 'Title'))
)
);
@ -65,9 +67,10 @@ trait BlogObject
return $validation;
}
if ($this->getDuplicatesByUrlSegment()->count() > 0) {
if ($this->getDuplicatesByField('Title')->count() > 0) {
$validation->addError($this->getDuplicateError(), self::DUPLICATE_EXCEPTION);
}
return $validation;
}
@ -134,7 +137,7 @@ trait BlogObject
return $extended;
}
return $this->Blog()->canEdit($member);
return $this->Blog()->canDelete($member);
}
/**
@ -178,36 +181,37 @@ trait BlogObject
$increment = (int) $increment;
$filter = URLSegmentFilter::create();
$this->URLSegment = $filter->filter($this->owner->Title);
$this->URLSegment = $filter->filter($this->Title);
if ($increment > 0) {
$this->URLSegment .= '-' . $increment;
}
if ($this->getDuplicatesByUrlSegment()->count() > 0) {
$this->owner->generateURLSegment($increment + 1);
if ($this->getDuplicatesByField('URLSegment')->count() > 0) {
$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
*/
protected function getDuplicatesByUrlSegment()
protected function getDuplicatesByField($field)
{
$duplicates = DataList::create(self::class)
->filter(
array(
'URLSegment' => $this->URLSegment,
'BlogID' => (int) $this->BlogID,
)
[
$field => $this->$field,
'BlogID' => (int) $this->BlogID
]
);
if ($this->ID) {
$duplicates = $duplicates->exclude('ID', $this->ID);
$duplicates->exclude('ID', $this->ID);
}
return $duplicates;

View File

@ -74,7 +74,7 @@ class BlogPost extends Page
private static $many_many = array(
'Categories' => 'SilverStripe\\Blog\\Model\\BlogCategory',
'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->push(HiddenField::create('MenuTitle'));
$urlSegment = $fields->dataFieldByName('URLSegment');
$urlSegment->setURLPrefix($this->Parent()->RelativeLink());

View File

@ -2,13 +2,13 @@
namespace SilverStripe\Blog\Model;
use Page_Controller;
use PageController;
/**
* @package silverstripe
* @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()
{
return _t('BlogTag.Duplicate', 'A blog tags already exists with that name.');
return _t('BlogTag.Duplicate', 'A blog tag already exists with that name.');
}
}