Skip to content

Commit

Permalink
TASK: send stuff using Neos' HttpClient
Browse files Browse the repository at this point in the history
  • Loading branch information
dimaip committed Jan 26, 2017
1 parent edb199c commit 8162302
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 42 deletions.
15 changes: 11 additions & 4 deletions Configuration/Policy.yaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
privilegeTargets:
TYPO3\Flow\Security\Authorization\Privilege\Method\MethodPrivilege:
'Psmb.Newsletter':
matcher: 'method(Psmb\Newsletter\Controller\(.*)Controller->(.*)Action())'
'Psmb.Newsletter:Subscription':
matcher: 'method(Psmb\Newsletter\Controller\SubscriptionController->(.*)Action())'
'Psmb.Newsletter:Backend':
matcher: 'method(Psmb\Newsletter\Controller\NewsletterController->(.*)Action())'

roles:
'TYPO3.Flow:Everybody':
privileges:
-
privilegeTarget: 'Psmb.Newsletter'
permission: GRANT
privilegeTarget: 'Psmb.Newsletter:Subscription'
permission: GRANT
'TYPO3.Neos:Editor':
privileges:
-
privilegeTarget: 'Psmb.Newsletter:Backend'
permission: GRANT
3 changes: 3 additions & 0 deletions Resources/Private/Translations/en/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
<trans-unit id="js.selectSubscription" xml:space="preserve">
<source>Please select a subscription</source>
</trans-unit>
<trans-unit id="js.sendTo" xml:space="preserve">
<source>Send newsletter to: </source>
</trans-unit>
</body>
</file>
</xliff>
4 changes: 4 additions & 0 deletions Resources/Private/Translations/ru/Main.xlf
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@
<source>Please select a subscription</source>
<target>Выбирите подписку</target>
</trans-unit>
<trans-unit id="js.sendTo" xml:space="preserve">
<source>Send newsletter to: </source>
<target>Отправить рассылку группе: </target>
</trans-unit>
</body>
</file>
</xliff>
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
<div class="neos-inspector-field">
<div>
{{view view._select}}
{{#if view.selectContent}}
{{view view._select}}
{{else}}
<div style="padding: 12px 0">
{{view._sendTo}} {{view.subscription.label}}
</div>
{{/if}}
<button {{action "send" target="view"}} {{bindAttr disabled="view.sendingDisabled"}}>
{{view._buttonLabel}}
</button>
Expand Down
56 changes: 19 additions & 37 deletions Resources/Public/JavaScript/Inspector/Views/NewsletterView.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
define([
'emberjs',
'text!./NewsletterView.html',
'Shared/I18n'
'Shared/I18n',
'Shared/HttpClient'
],
function (Ember,
template,
I18n) {
I18n,
HttpClient) {
return Ember.View.extend({
template: Ember.Handlebars.compile(template),
_select: Ember.Select.extend({
Expand All @@ -18,9 +20,9 @@ define([
valueDidChange: function() {
this.set('parentView.subscription', this.get('value'));
this.set('parentView.buttonLabel', 'js.send');
}.observes('value'),
}.observes('value')
}),
selectContent: [],
selectContent: null,
subscription: null,
errorMessage: null,
_errorMessage: function () {
Expand All @@ -33,25 +35,21 @@ define([
sendingDisabled: function () {
return this.get('buttonLabel') !== 'js.send';
}.property('buttonLabel'),
_sendTo: function () {
return I18n.translate('Psmb.Newsletter:Main:js.sendTo', 'Send newsletter to: ');
}.property(),
init: function () {
var subscriptionsEndpoint = '/newsletter/getSubscriptions';
var request = new XMLHttpRequest();
request.withCredentials = true;
request.open('GET', subscriptionsEndpoint, true);

request.onload = function () {
if (request.status >= 200 && request.status < 400) {
var response = JSON.parse(request.responseText);
this.set('selectContent', response);
var callback = function (response) {
if (response.length === 1) {
this.set('subscription', response[0]);
} else {
this.set('errorMessage', 'js.error');
this.set('selectContent', response);
}
}.bind(this);
HttpClient.getResource(subscriptionsEndpoint).then(callback);

request.onerror = function () {
this.set('errorMessage', 'js.error');
}.bind(this);
request.send();
return this._super();
},
send: function () {
Expand All @@ -64,31 +62,15 @@ define([

var sendEndpointUrl = '/newsletter/send';

var request = new XMLHttpRequest();
request.withCredentials = true;
request.open('POST', sendEndpointUrl, true);
request.onload = function () {
if (request.status >= 200 && request.status < 400) {
var response = JSON.parse(request.responseText);
if (response.status == 'success') {
this.set('buttonLabel', 'js.sent');
} else {
this.set('errorMessage', 'js.error');
}
var callback = function (response) {
if (response.status == 'success') {
this.set('buttonLabel', 'js.sent');
} else {
this.set('errorMessage', 'js.error');
}
}.bind(this);

request.onerror = function () {
this.set('errorMessage', 'js.error');
}.bind(this);

var formData = new FormData();
formData.append('subscription', subscription);
formData.append('node', this.get('controller.nodeProperties._path'));
request.send(formData);

debugger;
HttpClient.createResource(sendEndpointUrl, {data: {subscription: subscription.value, node: this.get('controller.nodeProperties._path')}}).then(callback);
this.set('buttonLabel', 'js.sending');
}
});
Expand Down

0 comments on commit 8162302

Please sign in to comment.