Add a notification subscribtion to the single post view

This commit is contained in:
Augier 2015-03-02 18:51:30 +01:00
parent fb8bc7b99e
commit 0887137262
2 changed files with 32 additions and 2 deletions

View file

@ -6,12 +6,14 @@ app.views.SinglePostModeration = app.views.Feedback.extend({
events: function() {
return _.defaults({
"click .remove_post": "destroyModel",
"click .create_participation": "createParticipation",
"click .destroy_participation": "destroyParticipation"
}, app.views.Feedback.prototype.events);
},
presenter: function() {
return _.extend(this.defaultPresenter(), {
authorIsCurrentUser : this.authorIsCurrentUser(),
authorIsCurrentUser : this.authorIsCurrentUser()
});
},
@ -42,6 +44,25 @@ app.views.SinglePostModeration = app.views.Feedback.extend({
});
});
}
}
},
createParticipation: function (evt) {
if(evt) { evt.preventDefault(); }
var self = this;
$.post(Routes.post_participation_path(this.model.get("id")), {}, function () {
self.model.set({participation: true});
self.render();
});
},
destroyParticipation: function (evt) {
if(evt) { evt.preventDefault(); }
var self = this;
$.post(Routes.post_participation_path(this.model.get("id")), { _method: "delete" }, function () {
self.model.set({participation: false});
self.render();
});
},
participation: function(){ return this.model.get("participation"); }
});

View file

@ -11,6 +11,15 @@
<a href="#" data-type="post" class="block_user" title="{{t "ignore"}}">
<i class="entypo block"></i>
</a>
{{#if participation}}
<a href="#" data-type="nofollow" class="destroy_participation" title="{{t "stream.disable_post_notifications"}}">
<i class="entypo bell"></i>
</a>
{{else}}
<a href="#" data-type="nofollow" class="create_participation" title="{{t "stream.enable_post_notifications"}}">
<i class="entypo bell"></i>
</a>
{{/if}}
<a href="#" data-type="post" class="hide_post" title="{{t "stream.hide"}}">
<i class="entypo cross"></i>
</a>