Skip to content

Commit

Permalink
FEATURE: test email
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaip committed Jan 26, 2017
1 parent eaa215d commit 5454df2
Show file tree
Hide file tree
Showing 9 changed files with 213 additions and 40 deletions.
25 changes: 25 additions & 0 deletions Classes/Psmb/Newsletter/Controller/NewsletterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ public function sendAction($subscription, NodeInterface $node)
$this->view->assign('value', ['status' => 'success']);
}

/**
* Sends a test letter for subscription
*
* @param string $subscription Subscription id to send newsletter to
* @param NodeInterface $node Node of the current newsletter item
* @param string $email Test email address
* @return void
*/
public function testSendAction($subscription, NodeInterface $node, $email)
{
$this->fusionMailService->setupObject($this->getControllerContext(), $this->request);
$subscriptions = array_filter($this->subscriptions, function ($item) use ($subscription) {
return $item['identifier'] == $subscription;
});

$subscriber = new Subscriber();
$subscriber->setEmail($email);
$subscriber->setName('Test User');

$letter = $this->fusionMailService->generateSubscriptionLetter($subscriber, $subscriptions[0], $node);
$this->fusionMailService->sendLetter($letter);

$this->view->assign('value', ['status' => 'success']);
}

/**
* Generate a letter for each subscriber in the subscription
*
Expand Down
13 changes: 13 additions & 0 deletions Resources/Private/Translations/en/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,19 @@
<trans-unit id="js.loading" xml:space="preserve">
<source>Loading...</source>
</trans-unit>

<trans-unit id="js.confirmationTitle" xml:space="preserve">
<source>Send Newsletter</source>
</trans-unit>
<trans-unit id="js.confirmationDescription" xml:space="preserve">
<source>This will send the letter to all subscribers. Check that all your changes are published to live workspace and hit "Send".</source>
</trans-unit>
<trans-unit id="js.testConfirmationTitle" xml:space="preserve">
<source>Send Test Newsletter</source>
</trans-unit>
<trans-unit id="js.testEmailLabel" xml:space="preserve">
<source>Enter test email:</source>
</trans-unit>
</body>
</file>
</xliff>
17 changes: 17 additions & 0 deletions Resources/Private/Translations/ru/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,23 @@
<source>Loading...</source>
<target>Загрузка...</target>
</trans-unit>

<trans-unit id="js.confirmationTitle" xml:space="preserve">
<source>Send newsletter</source>
<target>Отправить рассылку</target>
</trans-unit>
<trans-unit id="js.confirmationDescription" xml:space="preserve">
<source>This will send the letter to all subscribers. Check that all your changes are published to live workspace and hit "Send".</source>
<target>Вы отправляете письмо всем подписчикам! Проверьте, что все изменения опубликованы и нажмите "Отправить".</target>
</trans-unit>
<trans-unit id="js.testConfirmationTitle" xml:space="preserve">
<source>Send test newsletter</source>
<target>Отправить тестовое письмо</target>
</trans-unit>
<trans-unit id="js.testEmailLabel" xml:space="preserve">
<source>Enter test email:</source>
<target>Введите тестовый email:</target>
</trans-unit>
</body>
</file>
</xliff>
19 changes: 19 additions & 0 deletions Resources/Public/JavaScript/Inspector/Views/Confirmation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<div class="neos-modal sandstorm-newsletter-confirmation">
<div class="neos-modal-header">
<button class="neos-close neos-button" title="{{translate id='close' fallback='Close'}}" {{action "cancel" target="view"}}></button>
<div class="neos-header">{{translate id='Psmb.Newsletter:Main:js.confirmationTitle' fallback='Send newsletter'}}</div>
</div>
<div>
<div class="neos-subheader">
<p>{{translate id='Psmb.Newsletter:Main:js.confirmationDescription' fallback='This will send the letter to all subscribers. Check that all your changes are published to live workspace and hit "Send"'}}</p>
</div>
</div>
<div class="neos-modal-footer">
<button class="neos-button" title="{{translate id='cancel' fallback='Cancel'}}" {{action "cancel" target="view"}}>{{translate id="cancel" fallback="Cancel"}}</button>

<button class="neos-button neos-button-danger" title="Send" {{action "sendNewsletter" target="view"}} >
{{translate id='Psmb.Newsletter:Main:js.send' fallback='Send'}}
</button>
</div>
</div>
<div class="neos-modal-backdrop neos-in"></div>
11 changes: 11 additions & 0 deletions Resources/Public/JavaScript/Inspector/Views/Confirmation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
define(
[
'emberjs',
'Shared/AbstractModal',
'text!./Confirmation.html'
],
function (Ember, AbstractModal, template) {
return AbstractModal.extend({
template: Ember.Handlebars.compile(template)
});
});
28 changes: 20 additions & 8 deletions Resources/Public/JavaScript/Inspector/Views/NewsletterView.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,34 @@
<div>
{{#if view.doneLoading}}
{{#if view.selectContent}}
{{view view._select}}
{{view view.select}}
{{else}}
<div style="padding: 12px 0">
{{view._sendTo}} {{view.subscription.label}}
{{translate id='Psmb.Newsletter:Main:js.sendTo' fallback='Send newsletter to: '}} {{view.subscription.label}}
</div>
{{/if}}
<button {{action "send" target="view"}} {{bindAttr disabled="view.sendingDisabled"}}>
{{view._buttonLabel}}
</button>

<div>
<button class="neos-button-danger" {{action "finalSend" target="view"}}>
{{translate id='Psmb.Newsletter:Main:js.send' fallback='Send'}}
</button>

<button {{action "testSend" target="view"}}>
{{translate id='Psmb.Newsletter:Main:js.test' fallback='Test'}}
</button>
</div>
{{else}}
{{view._loadingLabel}}
{{translate id='Psmb.Newsletter:Main:js.loading' fallback='Loading...'}}
{{/if}}
{{#if view.errorMessage}}
{{#if view.notificationMessageId}}
<div style="padding: 12px 0">
{{view.notificationMessage}}
</div>
{{/if}}
{{#if view.errorMessageId}}
<div style="color: #ff460d; padding: 12px 0">
<i class="icon-warning-sign"></i>
{{view._errorMessage}}
{{view.errorMessage}}
</div>
{{/if}}
</div>
Expand Down
105 changes: 73 additions & 32 deletions Resources/Public/JavaScript/Inspector/Views/NewsletterView.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,23 @@ define([
'emberjs',
'text!./NewsletterView.html',
'Shared/I18n',
'Shared/HttpClient'
'Shared/HttpClient',
'./Confirmation',
'./TestConfirmation'
],
function (Ember,
template,
I18n,
HttpClient) {
HttpClient,
Confirmation,
TestConfirmation) {
return Ember.View.extend({
template: Ember.Handlebars.compile(template),
_select: Ember.Select.extend({

subscription: null,
doneLoading: false,

select: Ember.Select.extend({
content: function () {
return this.get('parentView.selectContent');
}.property('parentView.selectContent'),
Expand All @@ -19,29 +27,31 @@ define([
prompt: I18n.translate('Psmb.Newsletter:Main:js.selectSubscription', 'Please select a subscription'),
valueDidChange: function() {
this.set('parentView.subscription', this.get('value'));
this.set('parentView.buttonLabel', 'js.send');
this.set('parentView.buttonLabelId', 'js.send');
}.observes('value')
}),
selectContent: null,
subscription: null,
errorMessage: null,
doneLoading: false,
_errorMessage: function () {
return I18n.translate('Psmb.Newsletter:Main:' + this.get('errorMessage'), '');
}.property('errorMessage'),
buttonLabel: 'js.send',
_buttonLabel: function () {
return I18n.translate('Psmb.Newsletter:Main:' + this.get('buttonLabel'), 'Send');
}.property('buttonLabel'),
sendingDisabled: function () {
return this.get('buttonLabel') !== 'js.send';
}.property('buttonLabel'),
_sendTo: function () {
return I18n.translate('Psmb.Newsletter:Main:js.sendTo', 'Send newsletter to: ');
}.property(),
_loadingLabel: function () {
return I18n.translate('Psmb.Newsletter:Main:js.loading', 'Loading...');
}.property(),

notificationMessageId: null,
notificationMessage: function () {
return I18n.translate('Psmb.Newsletter:Main:' + this.get('notificationMessageId'), '');
}.property('notificationMessageId'),

errorMessageId: null,
errorMessage: function () {
return I18n.translate('Psmb.Newsletter:Main:' + this.get('errorMessageId'), '');
}.property('errorMessageId'),

buttonLabelId: 'js.send',
buttonLabel: function () {
return I18n.translate('Psmb.Newsletter:Main:' + this.get('buttonLabelId'), 'Send');
}.property('buttonLabelId'),

testButtonLabelId: 'js.send',
testButtonLabel: function () {
return I18n.translate('Psmb.Newsletter:Main:' + this.get('testButtonLabelId'), 'Send');
}.property('testButtonLabelId'),

init: function () {
var subscriptionsEndpoint = '/newsletter/getSubscriptions';

Expand All @@ -53,36 +63,67 @@ define([
this.set('selectContent', response);
this.set('doneLoading', true);
} else {
this.set('errorMessage', 'js.error');
this.set('errorMessageId', 'js.error');
}
}.bind(this);
HttpClient.getResource(subscriptionsEndpoint).then(callback);

return this._super();
},
send: function () {
finalSend: function () {
var subscription = this.get('subscription');
if (!subscription) {
this.set('errorMessage', 'js.selectSubscription');
this.set('errorMessageId', 'js.selectSubscription');
return;
}
this.set('errorMessage', null);
this.set('errorMessageId', null);

var sendEndpointUrl = '/newsletter/send';
Confirmation.create({
sendRequest: this.sendRequest.bind(this),
sendNewsletter: function () {
this.sendRequest();
this.cancel();
}
});
},
testSend: function () {
var subscription = this.get('subscription');
if (!subscription) {
this.set('errorMessageId', 'js.selectSubscription');
return;
}
this.set('errorMessageId', null);

TestConfirmation.create({
sendRequest: this.sendRequest.bind(this),
sendNewsletter: function () {
var testEmail = this.get('testEmail');
if (testEmail) {
this.sendRequest(testEmail);
}
this.cancel();
}
});
},
sendRequest: function (testEmail) {
var sendEndpointUrl = testEmail ? '/newsletter/testSend' : '/newsletter/send';

var callback = function (response) {
if (response.status == 'success') {
this.set('buttonLabel', 'js.sent');
this.set('notificationMessageId', 'js.sent');
} else {
this.set('errorMessage', 'js.error');
this.set('errorMessageId', 'js.error');
}
}.bind(this);
var data = {
subscription: subscription,
subscription: this.get('subscription'),
node: this.get('controller.nodeProperties._path')
};
if (testEmail) {
data.email = testEmail;
}
HttpClient.createResource(sendEndpointUrl, {data: data}).then(callback);
this.set('buttonLabel', 'js.sending');
this.set('notificationMessageId', 'js.sending');
}
});
});
20 changes: 20 additions & 0 deletions Resources/Public/JavaScript/Inspector/Views/TestConfirmation.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<div class="neos-modal sandstorm-newsletter-confirmation">
<div class="neos-modal-header">
<button class="neos-close neos-button" title="{{translate id='close' fallback='Close'}}" {{action "cancel" target="view"}}></button>
<div class="neos-header">{{translate id='Psmb.Newsletter:Main:js.testConfirmationTitle' fallback='Send test newsletter'}}</div>
</div>
<div>
<div class="neos-subheader">
<p style="padding-bottom: 6px">{{translate id='Psmb.Newsletter:Main:js.testEmailLabel' fallback='Enter test email:'}}</p>
<p>{{view Ember.TextField type="email" name="testEmail" valueBinding="view.testEmail"}}</p>
</div>
</div>
<div class="neos-modal-footer">
<button class="neos-button" title="{{translate id='cancel' fallback='Cancel'}}" {{action "cancel" target="view"}}>{{translate id="cancel" fallback="Cancel"}}</button>

<button class="neos-button neos-button-danger" title="Send" {{action "sendNewsletter" target="view"}} {{bindAttr disabled="view.sendingDisabled"}}>
{{translate id='Psmb.Newsletter:Main:js.send' fallback='Send'}}
</button>
</div>
</div>
<div class="neos-modal-backdrop neos-in"></div>
15 changes: 15 additions & 0 deletions Resources/Public/JavaScript/Inspector/Views/TestConfirmation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
define(
[
'emberjs',
'Shared/AbstractModal',
'text!./TestConfirmation.html'
],
function (Ember, AbstractModal, template) {
return AbstractModal.extend({
template: Ember.Handlebars.compile(template),
testEmail: null,
sendingDisabled: function () {
return !this.get('testEmail');
}.property('testEmail')
});
});

0 comments on commit 5454df2

Please sign in to comment.