Some fixes to participation controls

* prevent default event in JS handlers to prevent jumping back to the
  top.
* Use js-routes
* Use sprite for icons
* Reply with 200 instead of 204 when destroying a participation,
  to prevent errors in the browser console.
This commit is contained in:
Jonne Haß 2015-02-27 15:31:30 +01:00
parent eccab62e32
commit 073e99992e
4 changed files with 18 additions and 18 deletions

View file

@ -117,16 +117,18 @@ app.views.StreamPost = app.views.Post.extend({
}, },
createParticipation: function (evt) { createParticipation: function (evt) {
if(evt) { evt.preventDefault(); }
that = this; that = this;
$.post("/posts/" + this.model.get("id") + "/participation", {}, function () { $.post(Routes.post_participation_path(this.model.get("id")), {}, function () {
that.model.set({participation: true}); that.model.set({participation: true});
that.render(); that.render();
}); });
}, },
destroyParticipation: function (evt) { destroyParticipation: function (evt) {
if(evt) { evt.preventDefault(); }
that = this; that = this;
$.post("/posts/" + this.model.get("id") + "/participation", { _method: "delete" }, function () { $.post(Routes.post_participation_path(this.model.get("id")), { _method: "delete" }, function () {
that.model.set({participation: false}); that.model.set({participation: false});
that.render(); that.render();
}); });

View file

@ -281,18 +281,16 @@ ul.as-selections {
} }
.create_participation { .create_participation {
display: inline-block; display: inline-block;
.icons-create-participation { .icons-create_participation {
height: 14px; height: 14px;
width: 14px; width: 14px;
background: image-url("icons/create_participation.png") center;
} }
} }
.destroy_participation { .destroy_participation {
display: inline-block; display: inline-block;
.icons-destroy-participation { .icons-destroy_participation {
height: 14px; height: 14px;
width: 14px; width: 14px;
background: image-url("icons/destroy_participation.png") center;
} }
} }
.delete { .delete {

View file

@ -18,11 +18,11 @@
</a> </a>
{{#if participation}} {{#if participation}}
<a href="#" rel="nofollow" class="destroy_participation" title="{{t "stream.disable_post_notifications"}}"> <a href="#" rel="nofollow" class="destroy_participation" title="{{t "stream.disable_post_notifications"}}">
<div class="icons-destroy-participation control_icon"></div> <div class="icons-destroy_participation control_icon"></div>
</a> </a>
{{else}} {{else}}
<a href="#" rel="nofollow" class="create_participation" title="{{t "stream.enable_post_notifications"}}"> <a href="#" rel="nofollow" class="create_participation" title="{{t "stream.enable_post_notifications"}}">
<div class="icons-create-participation control_icon"></div> <div class="icons-create_participation control_icon"></div>
</a> </a>
{{/if}} {{/if}}
<a href="#" rel="nofollow" class="delete hide_post" title="{{t "stream.hide"}}"> <a href="#" rel="nofollow" class="delete hide_post" title="{{t "stream.hide"}}">

View file

@ -5,19 +5,19 @@ class ParticipationsController < ApplicationController
post = current_user.find_visible_shareable_by_id(Post, params[:post_id]) post = current_user.find_visible_shareable_by_id(Post, params[:post_id])
if post if post
current_user.participate! post current_user.participate! post
render :nothing => true, :status => :created render nothing: true, status: :created
else else
render :nothing => true, :status => :forbidden render nothing: true, status: :forbidden
end end
end end
def destroy def destroy
@participation = current_user.participations.find_by :target_id => params[:post_id] participation = current_user.participations.find_by target_id: params[:post_id]
if @participation if participation
@participation.destroy participation.destroy
render :nothing => true, :status => :no_content render nothing: true, status: :ok
else else
render :nothing => true, :status => :unprocessable_entity render nothing: true, status: :unprocessable_entity
end end
end end
end end