From 09586b4b12a2737e3248d80210819979e1592c9d Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Thu, 27 Feb 2014 11:43:56 +1300 Subject: [PATCH] Show next review date for inherited settings --- code/extensions/SiteTreeContentReview.php | 8 ++++- javascript/contentreview.js | 44 ++++++++++++++--------- 2 files changed, 35 insertions(+), 17 deletions(-) diff --git a/code/extensions/SiteTreeContentReview.php b/code/extensions/SiteTreeContentReview.php index 8f21735..c327879 100644 --- a/code/extensions/SiteTreeContentReview.php +++ b/code/extensions/SiteTreeContentReview.php @@ -307,15 +307,21 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider $notesField = GridField::create('ReviewNotes', 'Review Notes', $this->owner->ReviewLogs(), GridFieldConfig_RecordEditor::create()); + $schedule = self::get_schedule(); + $fields->addFieldsToTab("Root.ContentReview", array( new HeaderField(_t('ContentReview.REVIEWHEADER', "Content review"), 2), $viewersOptionsField, + CompositeField::create( + ReadonlyField::create('ROContentOwners', _t('ContentReview.CONTENTOWNERS', 'Content Owners'), $this->getOwnerNames()), + ReadonlyField::create('RONextReviewDate', _t("ContentReview.NEXTREVIEWDATE", "Next review date"), $this->owner->NextReviewDate) + )->addExtraClass('inherited-settings'), CompositeField::create( $userField, $groupField, $reviewDate, $reviewFrequency - )->addExtraClass('contentReviewSettings'), + )->addExtraClass('custom-settings'), $notesField )); } diff --git a/javascript/contentreview.js b/javascript/contentreview.js index 38852fb..a655c5d 100644 --- a/javascript/contentreview.js +++ b/javascript/contentreview.js @@ -15,30 +15,42 @@ jQuery(function($) { $('.cms-edit-form #ContentReviewType').entwine({ // Constructor: onmatch onmatch: function() { - // TODO Decouple - var dropdown; - if(this.attr('id') == 'ContentReviewType') dropdown = $('.contentReviewSettings'); - - this.find('.optionset :input').bind('change', function(e) { - var wrapper = $(this).closest('.middleColumn').parent('div'); - if(e.target.value == 'Custom') { - wrapper.addClass('remove-splitter'); - dropdown['show'](); - } - else { - wrapper.removeClass('remove-splitter'); - dropdown['hide'](); - } + var self = this; + this.find('.optionset :input').on('change', function(e) { + self.show_option(e.target.value); }); // initial state var currentVal = this.find('input[name=' + this.attr('id') + ']:checked').val(); - dropdown[currentVal == 'Custom' ? 'show' : 'hide'](); - + this.show_option(currentVal); this._super(); }, onunmatch: function() { + this.find('.optionset :input').off('change'); this._super(); + }, + + show_option: function(value) { + if(value === 'Custom') { + this._custom(); + } else if(value === 'Inherit') { + this._inherited(); + } else { + this._disabled(); + } + }, + + _custom: function() { + $('.custom-settings')['show'](); + $('.inherited-settings')['hide'](); + }, + _inherited: function() { + $('.inherited-settings')['show'](); + $('.custom-settings')['hide'](); + }, + _disabled: function() { + $('.inherited-settings')['hide'](); + $('.custom-settings')['hide'](); } });