From 5b90141c03208873fc15e2a1e807ede52868ac41 Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Fri, 31 Mar 2017 16:34:42 +1300 Subject: [PATCH 1/3] ENHANCEMENT Update archive warning message --- client/dist/js/bundle.js | 7 ++--- client/lang/en.js | 3 +- client/lang/src/en.js | 3 +- client/src/legacy/CMSMain.EditForm.js | 10 +++---- code/Controllers/CMSMain.php | 40 +++++++++++++++++++++++++++ lang/en.yml | 4 +++ 6 files changed, 54 insertions(+), 13 deletions(-) diff --git a/client/dist/js/bundle.js b/client/dist/js/bundle.js index e6908567..b4eeb6c0 100644 --- a/client/dist/js/bundle.js +++ b/client/dist/js/bundle.js @@ -67,10 +67,9 @@ return"http://"!=a.substr(0,7)&&(a=t("base").attr("href")+a),window.open(a,"prin return i=a?r.default.sprintf(r.default._t("CMSMain.RollbackToVersion"),a):r.default._t("CMSMain.ConfirmRestoreFromLive"),!!confirm(i)&&this._super(e)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_archive").entwine({ -onclick:function t(e){var n=this.parents("form:first"),a=n.find(":input[name=Version]").val(),i="" -return i=r.default.sprintf(r.default._t("CMSMain.Archive"),a),!!confirm(i)&&this._super(e)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_restore").entwine({onclick:function t(e){var n=this.parents("form:first"),a=n.find(":input[name=Version]").val(),i="",s=this.data("toRoot") - - +onclick:function t(e){var n=this.parents("form:first"),a="" +return a=n.find("input[name=ArchiveWarningMessage").val().replace(/\\n/g,"\n"),!!confirm(a)&&this._super(e)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_restore").entwine({onclick:function t(e){ +var n=this.parents("form:first"),a=n.find(":input[name=Version]").val(),i="",s=this.data("toRoot") return i=r.default.sprintf(r.default._t(s?"CMSMain.RestoreToRoot":"CMSMain.Restore"),a),!!confirm(i)&&this._super(e)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_unpublish").entwine({onclick:function t(e){ var n=this.parents("form:first"),a=n.find(":input[name=Version]").val(),i="" return i=r.default.sprintf(r.default._t("CMSMain.Unpublish"),a),!!confirm(i)&&this._super(e)}}),t(".cms-edit-form.changed").entwine({onmatch:function t(e){var n=this.find("button[name=action_save]") diff --git a/client/lang/en.js b/client/lang/en.js index 768bb8c7..428b2a89 100644 --- a/client/lang/en.js +++ b/client/lang/en.js @@ -30,7 +30,6 @@ if (typeof(ss) === 'undefined' || typeof(ss.i18n) === 'undefined') { "CMSMAIN.SELECTONEPAGE": "Please select at least 1 page.", "CMSMAIN.URLSEGMENTVALIDATION": "URLs can only be made up of letters, digits and hyphens.", "CMSMAIN.WARNINGSAVEPAGESBEFOREADDING": "You have to save a page before adding children underneath it", - "CMSMain.Archive": "Are you sure you want to archive this page and all of its children pages?\n\nThis page and all of its children will be unpublished and sent to the archive.", "CMSMain.ConfirmRestoreFromLive": "Are you sure you want to revert draft to when the page was last published?", "CMSMain.DeleteFromDraft": "Are you sure you want to remove your page from the draft site?\n\nThis page will remain on the published site.", "CMSMain.Restore": "Are you sure you want to restore this page from archive?", @@ -51,4 +50,4 @@ if (typeof(ss) === 'undefined' || typeof(ss.i18n) === 'undefined') { "URLSEGMENT.UpdateURL": "Update URL", "WidgetAreaEditor.TOOMANY": "Sorry, you have reached the maximum number of widgets in this area" }); -} \ No newline at end of file +} diff --git a/client/lang/src/en.js b/client/lang/src/en.js index fecfcb1c..e0e4abd5 100644 --- a/client/lang/src/en.js +++ b/client/lang/src/en.js @@ -23,7 +23,6 @@ "CMSMAIN.SELECTONEPAGE": "Please select at least 1 page.", "CMSMAIN.URLSEGMENTVALIDATION": "URLs can only be made up of letters, digits and hyphens.", "CMSMAIN.WARNINGSAVEPAGESBEFOREADDING": "You have to save a page before adding children underneath it", - "CMSMain.Archive": "Are you sure you want to archive this page and all of its children pages?\n\nThis page and all of its children will be unpublished and sent to the archive.", "CMSMain.ConfirmRestoreFromLive": "Are you sure you want to revert draft to when the page was last published?", "CMSMain.DeleteFromDraft": "Are you sure you want to remove your page from the draft site?\n\nThis page will remain on the published site.", "CMSMain.Restore": "Are you sure you want to restore this page from archive?", @@ -43,4 +42,4 @@ "URLSEGMENT.OK": "OK", "URLSEGMENT.UpdateURL": "Update URL", "WidgetAreaEditor.TOOMANY": "Sorry, you have reached the maximum number of widgets in this area" -} \ No newline at end of file +} diff --git a/client/src/legacy/CMSMain.EditForm.js b/client/src/legacy/CMSMain.EditForm.js index 45adff14..d3c0f87c 100644 --- a/client/src/legacy/CMSMain.EditForm.js +++ b/client/src/legacy/CMSMain.EditForm.js @@ -306,11 +306,11 @@ $.entwine('ss', function($){ * (Event) e */ onclick: function(e) { - var form = this.parents('form:first'), version = form.find(':input[name=Version]').val(), message = ''; - message = i18n.sprintf( - i18n._t('CMSMain.Archive'), - version - ); + var form = this.parents('form:first'), message = ''; + message = form.find('input[name=ArchiveWarningMessage') + .val() + .replace(/\\n/g, '\n'); + if(confirm(message)) { return this._super(e); } else { diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index adf221f1..ca99abd5 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -60,6 +60,8 @@ use SilverStripe\View\ArrayData; use SilverStripe\View\Requirements; use Translatable; use InvalidArgumentException; +use SilverStripe\Versioned\ChangeSet; +use SilverStripe\Versioned\ChangeSetItem; /** * The main "content" area of the CMS. @@ -742,8 +744,46 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $fields->push($liveLinkField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink())); $fields->push($liveLinkField = new HiddenField("LiveLink")); $fields->push($stageLinkField = new HiddenField("StageLink")); + $fields->push($archiveWarningMsg = new HiddenField("ArchiveWarningMessage")); $fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle)); + // Get all page's descendants + $record->collateDescendants(true, $descendants); + if (!$descendants) { + $descendants = []; + } + + // Get all campaigns that the page and its descendants belong to + $inChangeSetIDs = ChangeSetItem::get_for_object($record)->column('ChangeSetID'); + + foreach ($descendants as $page) { + $inChangeSetIDs = array_merge($inChangeSetIDs, ChangeSetItem::get_for_object($page)->column('ChangeSetID')); + } + + if (count($inChangeSetIDs) > 0) { + $inChangeSets = ChangeSet::get()->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN]); + } else { + $inChangeSets = new ArrayList(); + } + + if (count($descendants) > 0 && $inChangeSets->count() > 0) { + $archiveWarningTerm = 'CMSMain.ArchiveWarningWithChildrenAndCampaigns'; + $archiveWarningTransDefault = 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?'; + } else if (count($descendants) > 0) { + $archiveWarningTerm = 'CMSMain.ArchiveWarningWithChildren'; + $archiveWarningTransDefault = 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?'; + } else if ($inChangeSets->count() > 0) { + $archiveWarningTerm = 'CMSMain.ArchiveWarningWithCampaigns'; + $archiveWarningTransDefault = 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?'; + } else { + $archiveWarningTerm = 'CMSMain.ArchiveWarning'; + $archiveWarningTransDefault = 'Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?'; + } + + $numCampaigns = ChangeSet::singleton()->i18n_pluralise($inChangeSets->count()); + $numCampaigns = mb_strtolower($numCampaigns); + $archiveWarningMsg->setValue(_t($archiveWarningTerm, $archiveWarningTransDefault, [ 'NumCampaigns' => $numCampaigns ])); + if ($record->ID && is_numeric($record->ID)) { $liveLink = $record->getAbsoluteLiveLink(); if ($liveLink) { diff --git a/lang/en.yml b/lang/en.yml index 3baca161..82a958b4 100644 --- a/lang/en.yml +++ b/lang/en.yml @@ -133,6 +133,10 @@ en: TreeFiltered: 'Showing search results.' TreeFilteredClear: Clear UNPUBLISH_AND_ARCHIVE: 'Unpublish and archive' + ArchiveWarning: 'Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?' + ArchiveWarningWithChildren: 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?' + ArchiveWarningWithCampaigns: 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?' + ArchiveWarningWithChildrenAndCampaigns: 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?' CMSMain_left_ss: APPLY_FILTER: Search CLEAR_FILTER: Clear From b8db45055ca8f08291d5d2ba4317a755339917a7 Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Tue, 4 Apr 2017 11:44:41 +1200 Subject: [PATCH 2/3] Enhancement Refactor archive message to a separate method --- code/Controllers/CMSMain.php | 76 ++++++++++++++++++------------------ 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/code/Controllers/CMSMain.php b/code/Controllers/CMSMain.php index ca99abd5..be84a3b8 100644 --- a/code/Controllers/CMSMain.php +++ b/code/Controllers/CMSMain.php @@ -744,45 +744,10 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr $fields->push($liveLinkField = new HiddenField("AbsoluteLink", false, $record->AbsoluteLink())); $fields->push($liveLinkField = new HiddenField("LiveLink")); $fields->push($stageLinkField = new HiddenField("StageLink")); - $fields->push($archiveWarningMsg = new HiddenField("ArchiveWarningMessage")); + $fields->push($archiveWarningMsgField = new HiddenField("ArchiveWarningMessage")); $fields->push(new HiddenField("TreeTitle", false, $record->TreeTitle)); - // Get all page's descendants - $record->collateDescendants(true, $descendants); - if (!$descendants) { - $descendants = []; - } - - // Get all campaigns that the page and its descendants belong to - $inChangeSetIDs = ChangeSetItem::get_for_object($record)->column('ChangeSetID'); - - foreach ($descendants as $page) { - $inChangeSetIDs = array_merge($inChangeSetIDs, ChangeSetItem::get_for_object($page)->column('ChangeSetID')); - } - - if (count($inChangeSetIDs) > 0) { - $inChangeSets = ChangeSet::get()->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN]); - } else { - $inChangeSets = new ArrayList(); - } - - if (count($descendants) > 0 && $inChangeSets->count() > 0) { - $archiveWarningTerm = 'CMSMain.ArchiveWarningWithChildrenAndCampaigns'; - $archiveWarningTransDefault = 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?'; - } else if (count($descendants) > 0) { - $archiveWarningTerm = 'CMSMain.ArchiveWarningWithChildren'; - $archiveWarningTransDefault = 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?'; - } else if ($inChangeSets->count() > 0) { - $archiveWarningTerm = 'CMSMain.ArchiveWarningWithCampaigns'; - $archiveWarningTransDefault = 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?'; - } else { - $archiveWarningTerm = 'CMSMain.ArchiveWarning'; - $archiveWarningTransDefault = 'Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?'; - } - - $numCampaigns = ChangeSet::singleton()->i18n_pluralise($inChangeSets->count()); - $numCampaigns = mb_strtolower($numCampaigns); - $archiveWarningMsg->setValue(_t($archiveWarningTerm, $archiveWarningTransDefault, [ 'NumCampaigns' => $numCampaigns ])); + $archiveWarningMsgField->setValue($this->getArchiveWarningMessage($record)); if ($record->ID && is_numeric($record->ID)) { $liveLink = $record->getAbsoluteLiveLink(); @@ -868,6 +833,43 @@ class CMSMain extends LeftAndMain implements CurrentPageIdentifier, PermissionPr } } + protected function getArchiveWarningMessage($record) + { + // Get all page's descendants + $record->collateDescendants(true, $descendants); + if (!$descendants) { + $descendants = []; + } + + // Get all campaigns that the page and its descendants belong to + $inChangeSetIDs = ChangeSetItem::get_for_object($record)->column('ChangeSetID'); + + foreach ($descendants as $page) { + $inChangeSetIDs = array_merge($inChangeSetIDs, ChangeSetItem::get_for_object($page)->column('ChangeSetID')); + } + + if (count($inChangeSetIDs) > 0) { + $inChangeSets = ChangeSet::get()->filter(['ID' => $inChangeSetIDs, 'State' => ChangeSet::STATE_OPEN]); + } else { + $inChangeSets = new ArrayList(); + } + + $numCampaigns = ChangeSet::singleton()->i18n_pluralise($inChangeSets->count()); + $numCampaigns = mb_strtolower($numCampaigns); + + if (count($descendants) > 0 && $inChangeSets->count() > 0) { + $archiveWarningMsg = _t('CMSMain.ArchiveWarningWithChildrenAndCampaigns', 'Warning: This page and all of its child pages will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]); + } elseif (count($descendants) > 0) { + $archiveWarningMsg = _t('CMSMain.ArchiveWarningWithChildren', 'Warning: This page and all of its child pages will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?'); + } elseif ($inChangeSets->count() > 0) { + $archiveWarningMsg = _t('CMSMain.ArchiveWarningWithCampaigns', 'Warning: This page will be unpublished and automatically removed from their associated {NumCampaigns} before being sent to the archive.\n\nAre you sure you want to proceed?', [ 'NumCampaigns' => $numCampaigns ]); + } else { + $archiveWarningMsg = _t('CMSMain.ArchiveWarning', 'Warning: This page will be unpublished before being sent to the archive.\n\nAre you sure you want to proceed?'); + } + + return $archiveWarningMsg; + } + /** * @param HTTPRequest $request * @return string HTML From e12a2709d0dc92f684f5056d20f9bc0981736cb4 Mon Sep 17 00:00:00 2001 From: Christopher Joe Date: Wed, 5 Apr 2017 15:14:12 +1200 Subject: [PATCH 3/3] Fix syntax error in selector --- client/dist/js/bundle.js | 2 +- client/src/legacy/CMSMain.EditForm.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/client/dist/js/bundle.js b/client/dist/js/bundle.js index b4eeb6c0..5cbc629e 100644 --- a/client/dist/js/bundle.js +++ b/client/dist/js/bundle.js @@ -68,7 +68,7 @@ return"http://"!=a.substr(0,7)&&(a=t("base").attr("href")+a),window.open(a,"prin return i=a?r.default.sprintf(r.default._t("CMSMain.RollbackToVersion"),a):r.default._t("CMSMain.ConfirmRestoreFromLive"),!!confirm(i)&&this._super(e)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_archive").entwine({ onclick:function t(e){var n=this.parents("form:first"),a="" -return a=n.find("input[name=ArchiveWarningMessage").val().replace(/\\n/g,"\n"),!!confirm(a)&&this._super(e)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_restore").entwine({onclick:function t(e){ +return a=n.find("input[name=ArchiveWarningMessage]").val().replace(/\\n/g,"\n"),!!confirm(a)&&this._super(e)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_restore").entwine({onclick:function t(e){ var n=this.parents("form:first"),a=n.find(":input[name=Version]").val(),i="",s=this.data("toRoot") return i=r.default.sprintf(r.default._t(s?"CMSMain.RestoreToRoot":"CMSMain.Restore"),a),!!confirm(i)&&this._super(e)}}),t(".cms-edit-form .btn-toolbar #Form_EditForm_action_unpublish").entwine({onclick:function t(e){ var n=this.parents("form:first"),a=n.find(":input[name=Version]").val(),i="" diff --git a/client/src/legacy/CMSMain.EditForm.js b/client/src/legacy/CMSMain.EditForm.js index d3c0f87c..9912b720 100644 --- a/client/src/legacy/CMSMain.EditForm.js +++ b/client/src/legacy/CMSMain.EditForm.js @@ -307,7 +307,7 @@ $.entwine('ss', function($){ */ onclick: function(e) { var form = this.parents('form:first'), message = ''; - message = form.find('input[name=ArchiveWarningMessage') + message = form.find('input[name=ArchiveWarningMessage]') .val() .replace(/\\n/g, '\n');