From 8edc079e92ba4626170ef593d524793431c2a4e2 Mon Sep 17 00:00:00 2001 From: Damian Mooyman Date: Thu, 23 Apr 2015 14:27:30 +1200 Subject: [PATCH 1/4] API Improve sizing of blog sidebar --- code/model/Blog.php | 3 +- code/model/BlogPost.php | 1 + js/cms.js | 118 +++++++++++++++++++++++++++++++++++++ js/expandable-help-text.js | 49 --------------- js/merge-action.js | 44 -------------- 5 files changed, 120 insertions(+), 95 deletions(-) create mode 100644 js/cms.js delete mode 100644 js/expandable-help-text.js delete mode 100644 js/merge-action.js diff --git a/code/model/Blog.php b/code/model/Blog.php index d3c7e9c..b4f2c8c 100644 --- a/code/model/Blog.php +++ b/code/model/Blog.php @@ -80,8 +80,7 @@ class Blog extends Page implements PermissionProvider { public function getCMSFields() { Requirements::css(BLOGGER_DIR . '/css/cms.css'); - Requirements::javascript(BLOGGER_DIR . '/js/expandable-help-text.js'); - Requirements::javascript(BLOGGER_DIR . '/js/merge-action.js'); + Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); $self =& $this; diff --git a/code/model/BlogPost.php b/code/model/BlogPost.php index 7f05cbb..95634c8 100644 --- a/code/model/BlogPost.php +++ b/code/model/BlogPost.php @@ -108,6 +108,7 @@ class BlogPost extends Page { public function getCMSFields() { Requirements::css(BLOGGER_DIR . '/css/cms.css'); + Requirements::javascript(BLOGGER_DIR . '/js/cms.js'); $self =& $this; $this->beforeUpdateCMSFields(function($fields) use ($self) { diff --git a/js/cms.js b/js/cms.js new file mode 100644 index 0000000..15bae53 --- /dev/null +++ b/js/cms.js @@ -0,0 +1,118 @@ +(function ($) { + + $.entwine('ss', function ($) { + + /** + * Register expandable help text functions with fields. + */ + $('.toggle-description').entwine({ + 'onadd': function () { + var $this = $(this); + + /** + * Prevent multiple events being added. + */ + if ($this.hasClass('toggle-description-enabled')) { + return; + } + + $this.addClass('toggle-description-enabled'); + + /** + * Toggle next description when button is clicked. + */ + var shown = false; + + $this.on('click', function() { + $this.parent().next('.description')[shown ? 'hide' : 'show'](); + + $this.toggleClass('toggle-description-shown'); + + shown = !shown; + }); + + /** + * Hide next description by default. + */ + $this.parent().next('.description').hide(); + + /** + * Add classes to correct inherited layout issues in a small context. + */ + $this.parent().addClass('toggle-description-correct-right'); + $this.parent().prev('.middleColumn').addClass('toggle-description-correct-middle'); + $this.parent().next('.description').addClass('toggle-description-correct-description'); + } + }); + + /** + * Custom merge actions for tags and categories + */ + $('.MergeAction').entwine({ + 'onadd': function() { + var $this = $(this); + + $this.on('click', 'select', function() { + return false; + }); + + $this.children('button').each(function(i, button) { + var $button = $(button); + var $select = $button.prev('select'); + + $button.before(''); + }); + + $this.on('change', 'select', function(e) { + var $target = $(e.target); + + $target.next('input').val($target.val()); + }); + + $this.children('button, select').hide(); + + $this.on('click', '.MergeActionReveal', function(e) { + var $target = $(e.target); + + $target.parent().children('button, select').show(); + $target.hide(); + + return false; + }); + } + }); + + /** + * Customise the cms-panel behaviour for blog sidebar + * + * see LeftAndMain.Panel.js for base behaviour + */ + $('.blog-admin-sidebar.cms-panel').entwine({ + minInnerWidth: 620, + onadd: function() { + this._super(); + this.updateLayout(); + + // If this panel is open and the left hand column is smaller than the minimum, contract it instead + if(!this.hasClass('collapsed') && ($(".blog-admin-outer").width() < this.getminInnerWidth())) { + this.collapsePanel(); + } + }, + togglePanel: function(bool, silent) { + this._super(bool, silent); + this.updateLayout(); + }, + /** + * Adjust minimum width of content to account for extra panel + * + * @returns {undefined} + */ + updateLayout: function() { + $('.cms-container').updateLayoutOptions({ + minContentWidth: 820 + this.width() + }); + } + }); + + }); +})(jQuery); diff --git a/js/expandable-help-text.js b/js/expandable-help-text.js deleted file mode 100644 index e64a3fe..0000000 --- a/js/expandable-help-text.js +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Register expandable help text functions with fields. - */ -(function ($) { - - $.entwine('ss', function ($) { - - $('.toggle-description').entwine({ - 'onadd': function () { - var $this = $(this); - - /** - * Prevent multiple events being added. - */ - if ($this.hasClass('toggle-description-enabled')) { - return; - } - - $this.addClass('toggle-description-enabled'); - - /** - * Toggle next description when button is clicked. - */ - var shown = false; - - $this.on('click', function() { - $this.parent().next('.description')[shown ? 'hide' : 'show'](); - - $this.toggleClass('toggle-description-shown'); - - shown = !shown; - }); - - /** - * Hide next description by default. - */ - $this.parent().next('.description').hide(); - - /** - * Add classes to correct inherited layout issues in a small context. - */ - $this.parent().addClass('toggle-description-correct-right'); - $this.parent().prev('.middleColumn').addClass('toggle-description-correct-middle'); - $this.parent().next('.description').addClass('toggle-description-correct-description'); - } - }); - - }); -})(jQuery); diff --git a/js/merge-action.js b/js/merge-action.js deleted file mode 100644 index 74530b8..0000000 --- a/js/merge-action.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Register expandable help text functions with fields. - */ -(function ($) { - - $.entwine('ss', function ($) { - - $('.MergeAction').entwine({ - 'onadd': function() { - var $this = $(this); - - $this.on('click', 'select', function() { - return false; - }); - - $this.children('button').each(function(i, button) { - var $button = $(button); - var $select = $button.prev('select'); - - $button.before(''); - }); - - $this.on('change', 'select', function(e) { - var $target = $(e.target); - - $target.next('input').val($target.val()); - }); - - $this.children('button, select').hide(); - - $this.on('click', '.MergeActionReveal', function(e) { - var $target = $(e.target); - - $target.parent().children('button, select').show(); - $target.hide(); - - return false; - }); - } - }) - - }); - -}(jQuery)); From 97498cc3f6cd205a5a9297111737633c199b1e57 Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Thu, 23 Apr 2015 16:47:54 +1200 Subject: [PATCH 2/4] Hide current parent for merge options --- code/admin/GridFieldMergeAction.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/code/admin/GridFieldMergeAction.php b/code/admin/GridFieldMergeAction.php index 2c25153..71aef18 100644 --- a/code/admin/GridFieldMergeAction.php +++ b/code/admin/GridFieldMergeAction.php @@ -65,7 +65,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action */ public function getColumnContent($gridField, $record, $columnName) { if($columnName === 'MergeAction') { - $dropdown = new DropdownField('Target', 'Target', $this->records->map()); + $dropdown = new DropdownField('Target', 'Target', $this->records->exclude('ID', $record->ID)->map()); $prefix = strtolower($this->parentMethod . '-' . $this->childMethod); From 5c099aa0dc8e0eb2bc0356594484a605f782c91a Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Thu, 23 Apr 2015 16:50:50 +1200 Subject: [PATCH 3/4] Small improvements to merge column --- code/admin/GridFieldMergeAction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/admin/GridFieldMergeAction.php b/code/admin/GridFieldMergeAction.php index 2c25153..0c5d11c 100644 --- a/code/admin/GridFieldMergeAction.php +++ b/code/admin/GridFieldMergeAction.php @@ -84,7 +84,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action 'data-target' => $prefix . '-target-record-' . $record->ID )); - return $dropdown->Field() . $action->Field() . 'move posts to'; + return $dropdown->Field() . $action->Field() . 'move posts to'; } return null; @@ -101,7 +101,7 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action * {@inheritdoc} */ public function getColumnMetadata($gridField, $columnName) { - return array('title' => 'Move Posts To'); + return array('title' => 'Move posts to'); } /** From c7b374f80046c9cd840344e9c78f694821c3d487 Mon Sep 17 00:00:00 2001 From: Christopher Pitt Date: Thu, 23 Apr 2015 16:43:19 +1200 Subject: [PATCH 4/4] Hide merge for empty parents --- code/admin/GridFieldMergeAction.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/admin/GridFieldMergeAction.php b/code/admin/GridFieldMergeAction.php index 17ebdc9..6901609 100644 --- a/code/admin/GridFieldMergeAction.php +++ b/code/admin/GridFieldMergeAction.php @@ -64,9 +64,9 @@ class GridFieldMergeAction implements GridField_ColumnProvider, GridField_Action * {@inheritdoc} */ public function getColumnContent($gridField, $record, $columnName) { - if($columnName === 'MergeAction') { + if($columnName === 'MergeAction' && $record->{$this->childMethod}()->Count() > 0) { $dropdown = new DropdownField('Target', 'Target', $this->records->exclude('ID', $record->ID)->map()); - + $prefix = strtolower($this->parentMethod . '-' . $this->childMethod); $action = GridFieldFormAction::create(