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:
parent
eccab62e32
commit
073e99992e
4 changed files with 18 additions and 18 deletions
|
|
@ -117,16 +117,18 @@ app.views.StreamPost = app.views.Post.extend({
|
|||
},
|
||||
|
||||
createParticipation: function (evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
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.render();
|
||||
});
|
||||
},
|
||||
|
||||
destroyParticipation: function (evt) {
|
||||
if(evt) { evt.preventDefault(); }
|
||||
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.render();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -281,20 +281,18 @@ ul.as-selections {
|
|||
}
|
||||
.create_participation {
|
||||
display: inline-block;
|
||||
.icons-create-participation {
|
||||
.icons-create_participation {
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
background: image-url("icons/create_participation.png") center;
|
||||
}
|
||||
}
|
||||
.destroy_participation {
|
||||
display: inline-block;
|
||||
.icons-destroy-participation {
|
||||
.icons-destroy_participation {
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
background: image-url("icons/destroy_participation.png") center;
|
||||
}
|
||||
}
|
||||
}
|
||||
.delete {
|
||||
display: inline-block;
|
||||
.icons-deletelabel {
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@
|
|||
</a>
|
||||
{{#if participation}}
|
||||
<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>
|
||||
{{else}}
|
||||
<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>
|
||||
{{/if}}
|
||||
{{/if}}
|
||||
<a href="#" rel="nofollow" class="delete hide_post" title="{{t "stream.hide"}}">
|
||||
<div class="icons-deletelabel delete control_icon"/>
|
||||
</a>
|
||||
|
|
@ -35,7 +35,7 @@
|
|||
{{/unless}}
|
||||
</div>
|
||||
{{/if}}
|
||||
|
||||
|
||||
<div>
|
||||
{{#with author}}
|
||||
<a href="/people/{{guid}}" class="author {{{hovercardable this}}}">{{name}}</a>
|
||||
|
|
|
|||
|
|
@ -5,19 +5,19 @@ class ParticipationsController < ApplicationController
|
|||
post = current_user.find_visible_shareable_by_id(Post, params[:post_id])
|
||||
if post
|
||||
current_user.participate! post
|
||||
render :nothing => true, :status => :created
|
||||
render nothing: true, status: :created
|
||||
else
|
||||
render :nothing => true, :status => :forbidden
|
||||
render nothing: true, status: :forbidden
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@participation = current_user.participations.find_by :target_id => params[:post_id]
|
||||
if @participation
|
||||
@participation.destroy
|
||||
render :nothing => true, :status => :no_content
|
||||
participation = current_user.participations.find_by target_id: params[:post_id]
|
||||
if participation
|
||||
participation.destroy
|
||||
render nothing: true, status: :ok
|
||||
else
|
||||
render :nothing => true, :status => :unprocessable_entity
|
||||
render nothing: true, status: :unprocessable_entity
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Reference in a new issue