From 073e99992eac4362b9143933c4fe51632ed37d72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jonne=20Ha=C3=9F?= Date: Fri, 27 Feb 2015 15:31:30 +0100 Subject: [PATCH] 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. --- .../javascripts/app/views/stream_post_views.js | 6 ++++-- app/assets/stylesheets/application.css.scss | 8 +++----- app/assets/templates/stream-element_tpl.jst.hbs | 8 ++++---- app/controllers/participations_controller.rb | 14 +++++++------- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/app/assets/javascripts/app/views/stream_post_views.js b/app/assets/javascripts/app/views/stream_post_views.js index c91ddc27d..2c772c4af 100644 --- a/app/assets/javascripts/app/views/stream_post_views.js +++ b/app/assets/javascripts/app/views/stream_post_views.js @@ -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(); }); diff --git a/app/assets/stylesheets/application.css.scss b/app/assets/stylesheets/application.css.scss index 9e45891b6..65f0771cd 100644 --- a/app/assets/stylesheets/application.css.scss +++ b/app/assets/stylesheets/application.css.scss @@ -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 { diff --git a/app/assets/templates/stream-element_tpl.jst.hbs b/app/assets/templates/stream-element_tpl.jst.hbs index 24d976dc8..4ed0daeb9 100644 --- a/app/assets/templates/stream-element_tpl.jst.hbs +++ b/app/assets/templates/stream-element_tpl.jst.hbs @@ -18,13 +18,13 @@ {{#if participation}} -
+
{{else}} -
+
- {{/if}} + {{/if}}
@@ -35,7 +35,7 @@ {{/unless}}
{{/if}} - +
{{#with author}} {{name}} diff --git a/app/controllers/participations_controller.rb b/app/controllers/participations_controller.rb index a38089b91..95e8a2c03 100644 --- a/app/controllers/participations_controller.rb +++ b/app/controllers/participations_controller.rb @@ -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