Skip to content

Commit

Permalink
FEATURE: sendFromUiNodeType option
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaip committed Mar 15, 2017
1 parent bdf7c1c commit 6f6a5d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
19 changes: 15 additions & 4 deletions Classes/Psmb/Newsletter/Controller/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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']);
Expand All @@ -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);
Expand Down
1 change: 1 addition & 0 deletions Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ Neos:
# -
# identifier: 'daily'
# renderer: 'Your:LetterRenderer'
# sendFromUiNodeType: 'Your:NodeType'
# label: 'Our daily newsletter'
# interval: P1D
# dimensions:
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Psmb:
-
identifier: handcrafted
renderer: 'Your.NameSpace:HandcraftedDigestRenderer'
sendFromUiNodeType: 'Your.NameSpace:HandcraftedDigest'
label: 'Manually crafted newsletter'
interval: manual
```
Expand All @@ -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.|
Expand Down
5 changes: 3 additions & 2 deletions Resources/Public/JavaScript/Inspector/Views/NewsletterView.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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();
},
Expand Down

0 comments on commit 6f6a5d4

Please sign in to comment.