From 5454df2e7f2b9063c026796f3b6c677e8dfc7119 Mon Sep 17 00:00:00 2001 From: Dmitri Pisarev Date: Thu, 26 Jan 2017 15:13:44 +0300 Subject: [PATCH] FEATURE: test email --- .../Controller/NewsletterController.php | 25 +++++ Resources/Private/Translations/en/Main.xlf | 13 +++ Resources/Private/Translations/ru/Main.xlf | 17 +++ .../Inspector/Views/Confirmation.html | 19 ++++ .../Inspector/Views/Confirmation.js | 11 ++ .../Inspector/Views/NewsletterView.html | 28 +++-- .../Inspector/Views/NewsletterView.js | 105 ++++++++++++------ .../Inspector/Views/TestConfirmation.html | 20 ++++ .../Inspector/Views/TestConfirmation.js | 15 +++ 9 files changed, 213 insertions(+), 40 deletions(-) create mode 100644 Resources/Public/JavaScript/Inspector/Views/Confirmation.html create mode 100644 Resources/Public/JavaScript/Inspector/Views/Confirmation.js create mode 100644 Resources/Public/JavaScript/Inspector/Views/TestConfirmation.html create mode 100644 Resources/Public/JavaScript/Inspector/Views/TestConfirmation.js diff --git a/Classes/Psmb/Newsletter/Controller/NewsletterController.php b/Classes/Psmb/Newsletter/Controller/NewsletterController.php index adc90b8..6fb566b 100644 --- a/Classes/Psmb/Newsletter/Controller/NewsletterController.php +++ b/Classes/Psmb/Newsletter/Controller/NewsletterController.php @@ -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 * diff --git a/Resources/Private/Translations/en/Main.xlf b/Resources/Private/Translations/en/Main.xlf index cde820e..aa12a9b 100644 --- a/Resources/Private/Translations/en/Main.xlf +++ b/Resources/Private/Translations/en/Main.xlf @@ -47,6 +47,19 @@ Loading... + + + Send Newsletter + + + This will send the letter to all subscribers. Check that all your changes are published to live workspace and hit "Send". + + + Send Test Newsletter + + + Enter test email: + diff --git a/Resources/Private/Translations/ru/Main.xlf b/Resources/Private/Translations/ru/Main.xlf index 860d7bc..3fae089 100644 --- a/Resources/Private/Translations/ru/Main.xlf +++ b/Resources/Private/Translations/ru/Main.xlf @@ -62,6 +62,23 @@ Loading... Загрузка... + + + Send newsletter + Отправить рассылку + + + This will send the letter to all subscribers. Check that all your changes are published to live workspace and hit "Send". + Вы отправляете письмо всем подписчикам! Проверьте, что все изменения опубликованы и нажмите "Отправить". + + + Send test newsletter + Отправить тестовое письмо + + + Enter test email: + Введите тестовый email: + diff --git a/Resources/Public/JavaScript/Inspector/Views/Confirmation.html b/Resources/Public/JavaScript/Inspector/Views/Confirmation.html new file mode 100644 index 0000000..78558bb --- /dev/null +++ b/Resources/Public/JavaScript/Inspector/Views/Confirmation.html @@ -0,0 +1,19 @@ +
+
+ +
{{translate id='Psmb.Newsletter:Main:js.confirmationTitle' fallback='Send newsletter'}}
+
+
+
+

{{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"'}}

+
+
+ +
+
\ No newline at end of file diff --git a/Resources/Public/JavaScript/Inspector/Views/Confirmation.js b/Resources/Public/JavaScript/Inspector/Views/Confirmation.js new file mode 100644 index 0000000..2077713 --- /dev/null +++ b/Resources/Public/JavaScript/Inspector/Views/Confirmation.js @@ -0,0 +1,11 @@ +define( + [ + 'emberjs', + 'Shared/AbstractModal', + 'text!./Confirmation.html' + ], + function (Ember, AbstractModal, template) { + return AbstractModal.extend({ + template: Ember.Handlebars.compile(template) + }); + }); \ No newline at end of file diff --git a/Resources/Public/JavaScript/Inspector/Views/NewsletterView.html b/Resources/Public/JavaScript/Inspector/Views/NewsletterView.html index 65b8572..f9e4180 100644 --- a/Resources/Public/JavaScript/Inspector/Views/NewsletterView.html +++ b/Resources/Public/JavaScript/Inspector/Views/NewsletterView.html @@ -2,22 +2,34 @@
{{#if view.doneLoading}} {{#if view.selectContent}} - {{view view._select}} + {{view view.select}} {{else}}
- {{view._sendTo}} {{view.subscription.label}} + {{translate id='Psmb.Newsletter:Main:js.sendTo' fallback='Send newsletter to: '}} {{view.subscription.label}}
{{/if}} - + +
+ + + +
{{else}} - {{view._loadingLabel}} + {{translate id='Psmb.Newsletter:Main:js.loading' fallback='Loading...'}} {{/if}} - {{#if view.errorMessage}} + {{#if view.notificationMessageId}} +
+ {{view.notificationMessage}} +
+ {{/if}} + {{#if view.errorMessageId}}
- {{view._errorMessage}} + {{view.errorMessage}}
{{/if}}
diff --git a/Resources/Public/JavaScript/Inspector/Views/NewsletterView.js b/Resources/Public/JavaScript/Inspector/Views/NewsletterView.js index b8a9540..7b3e54b 100644 --- a/Resources/Public/JavaScript/Inspector/Views/NewsletterView.js +++ b/Resources/Public/JavaScript/Inspector/Views/NewsletterView.js @@ -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'), @@ -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'; @@ -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'); } }); }); diff --git a/Resources/Public/JavaScript/Inspector/Views/TestConfirmation.html b/Resources/Public/JavaScript/Inspector/Views/TestConfirmation.html new file mode 100644 index 0000000..1b3955e --- /dev/null +++ b/Resources/Public/JavaScript/Inspector/Views/TestConfirmation.html @@ -0,0 +1,20 @@ +
+
+ +
{{translate id='Psmb.Newsletter:Main:js.testConfirmationTitle' fallback='Send test newsletter'}}
+
+
+
+

{{translate id='Psmb.Newsletter:Main:js.testEmailLabel' fallback='Enter test email:'}}

+

{{view Ember.TextField type="email" name="testEmail" valueBinding="view.testEmail"}}

+
+
+ +
+
\ No newline at end of file diff --git a/Resources/Public/JavaScript/Inspector/Views/TestConfirmation.js b/Resources/Public/JavaScript/Inspector/Views/TestConfirmation.js new file mode 100644 index 0000000..debd38d --- /dev/null +++ b/Resources/Public/JavaScript/Inspector/Views/TestConfirmation.js @@ -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') + }); + });