From 6f6a5d4246f55de3b7421f09c2f10962d3fad44b Mon Sep 17 00:00:00 2001 From: Dmitri Pisarev Date: Wed, 15 Mar 2017 17:16:36 +0300 Subject: [PATCH] FEATURE: sendFromUiNodeType option --- .../Controller/NewsletterController.php | 19 +++++++++++++++---- Configuration/Settings.yaml | 1 + README.md | 2 ++ .../Inspector/Views/NewsletterView.js | 5 +++-- 4 files changed, 21 insertions(+), 6 deletions(-) diff --git a/Classes/Psmb/Newsletter/Controller/NewsletterController.php b/Classes/Psmb/Newsletter/Controller/NewsletterController.php index dbc7c5c..7bfde76 100644 --- a/Classes/Psmb/Newsletter/Controller/NewsletterController.php +++ b/Classes/Psmb/Newsletter/Controller/NewsletterController.php @@ -53,15 +53,24 @@ class NewsletterController extends ActionController /** * Get manual subscriptions for AJAX sending * + * @param string $nodeType * @return void */ - public function getSubscriptionsAction() { - $manualSubscriptions = array_filter($this->subscriptions, function ($item) { - return $item['interval'] == 'manual'; + public function getSubscriptionsAction($nodeType) { + $subscriptions = array_filter($this->subscriptions, function ($item) use ($nodeType) { + if (isset($item['sendFromUiNodeType'])) { + return $item['sendFromUiNodeType'] == $nodeType; + } + return false; }); + if(!count($subscriptions)) { + $subscriptions = array_filter($this->subscriptions, function ($item) { + return $item['interval'] == 'manual'; + }); + } $subscriptionsJsonArray = array_map(function ($item) { return ['label' => $item['label'], 'value' => $item['identifier']]; - }, $manualSubscriptions); + }, $subscriptions); $this->view->assign('value', array_values($subscriptionsJsonArray)); } @@ -78,6 +87,7 @@ public function sendAction($subscription, NodeInterface $node) return $item['identifier'] == $subscription; }); array_walk($subscriptions, function ($subscription) use ($node) { + $subscription['isSendFromUi'] = true; $this->sendLettersForSubscription($subscription, $node); }); $this->view->assign('value', ['status' => 'success']); @@ -97,6 +107,7 @@ public function testSendAction($subscription, NodeInterface $node, $email) return $item['identifier'] == $subscription; }); $subscription = reset($subscriptions); + $subscription['isSendFromUi'] = true; $subscriber = new Subscriber(); $subscriber->setEmail($email); diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index a66f10e..bceb569 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -46,6 +46,7 @@ Neos: # - # identifier: 'daily' # renderer: 'Your:LetterRenderer' +# sendFromUiNodeType: 'Your:NodeType' # label: 'Our daily newsletter' # interval: P1D # dimensions: diff --git a/README.md b/README.md index d3d898a..72fd659 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,7 @@ Psmb: - identifier: handcrafted renderer: 'Your.NameSpace:HandcraftedDigestRenderer' + sendFromUiNodeType: 'Your.NameSpace:HandcraftedDigest' label: 'Manually crafted newsletter' interval: manual ``` @@ -44,6 +45,7 @@ Define as many subscription types under Psmb.Newsletter.subscriptions as you nee | --- | --- | |`identifier`| Identifier of the subscription| |`renderer`| Fusion object that would be used for rendering emails sent to this subscription. Defaults to `Psmb.Newsletter:MailRenderer`. Must inherit from it.| +|`sendFromUiNodeType`| Show this subscription for the nodes of given nodetype when sending from UI. | |`interval`| Time interval identifier that would be used for selecting subscriptions. Can be used for cron jobs. Those marked as `manual` would appear as options when sending from the UI. Optional.| |`senderName`, `senderAddress`| Override options from `globalSettings`.| |`dimensions`| Array of dimensions in form of "dimensionName: ['dimensionValues']". Falls back to default dimension values.| diff --git a/Resources/Public/JavaScript/Inspector/Views/NewsletterView.js b/Resources/Public/JavaScript/Inspector/Views/NewsletterView.js index ffdd05b..e7ec917 100644 --- a/Resources/Public/JavaScript/Inspector/Views/NewsletterView.js +++ b/Resources/Public/JavaScript/Inspector/Views/NewsletterView.js @@ -52,7 +52,7 @@ define([ return I18n.translate('Psmb.Newsletter:Main:' + this.get('testButtonLabelId'), 'Send'); }.property('testButtonLabelId'), - init: function () { + didInsertElement: function () { var subscriptionsEndpoint = '/newsletter/getSubscriptions'; var callback = function (response) { @@ -66,7 +66,8 @@ define([ this.set('errorMessageId', 'js.error'); } }.bind(this); - HttpClient.getResource(subscriptionsEndpoint).then(callback); + var data = {nodeType: this.get('controller.nodeProperties._nodeType')}; + HttpClient.getResource(subscriptionsEndpoint, {data: data}).then(callback); return this._super(); },