From 76e3cbd7ac101bbee44e6e9b6eaaf0b6a3a97386 Mon Sep 17 00:00:00 2001 From: Fabio Teixeira Date: Wed, 8 Jul 2015 12:08:55 -0300 Subject: [PATCH] Remove star rate ajax and set commment as optional --- plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb | 44 +++++++++----------------------------------- plugins/communities_ratings/public/rate.js | 26 ++++---------------------- plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb | 14 +++++++------- 3 files changed, 20 insertions(+), 64 deletions(-) diff --git a/plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb b/plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb index d3ff98e..b123c7c 100644 --- a/plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb +++ b/plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb @@ -1,36 +1,9 @@ class CommunitiesRatingsPluginProfileController < ProfileController - before_filter :login_required - # Inside a community, receive a ajax from the current logged person with its - # rate for the community. If the user already rated this commnity, update its - # rate value or else, create a new one - def rate - # If its not a ajax request or the profile isn't a community - if (not request.xhr?) or (profile.type != "Community") - # Redirect to the profile home page - return redirect_to :controller => 'profile', :action => :index - end - - community_rating = get_community_rating(user, profile) - community_rating.value = params[:value].to_i - - if community_rating.save - render :json => { - success: true, - message: "Successfully rated community #{community_rating.community.name}" - } - else - render :json => { - success: false, - message: "Could not rate community #{community_rating.community.name}", - errors: community_rating.errors.full_messages - } - end - end def new_rating @plugins = plugins - community_rating = get_community_rating(user, profile) + community_rating = get_community_rating(user, profile, params[:community_rating_value]) @actual_rate_value = if community_rating.value community_rating.value else @@ -38,17 +11,17 @@ class CommunitiesRatingsPluginProfileController < ProfileController end if request.post? - unless params[:comments][:body].empty? + if params[:comments] and not params[:comments][:body].empty? comment = Comment.new(params[:comments]) comment.author = current_user.person comment.community = profile comment.save + community_rating.comment = comment - community_rating.save - else - session[:notice] = _("You need to provide a decription to make a comment") - redirect_to action: :new_rating end + + community_rating.save! + session[:notice] = _("#{profile.name} successfully rated") end end @@ -56,7 +29,7 @@ class CommunitiesRatingsPluginProfileController < ProfileController # If there is already a rate by the current logged user to this community # return it or else, prepare a new one - def get_community_rating person, community + def get_community_rating person, community, community_rating_value=nil already_rated = CommunityRating.where( :community_id=>community.id, :person_id=>person.id @@ -66,7 +39,8 @@ class CommunitiesRatingsPluginProfileController < ProfileController already_rated.first else CommunityRating.new :person => person, - :community => community + :community => community, + :value => community_rating_value end end end diff --git a/plugins/communities_ratings/public/rate.js b/plugins/communities_ratings/public/rate.js index 777e66e..e8a4664 100644 --- a/plugins/communities_ratings/public/rate.js +++ b/plugins/communities_ratings/public/rate.js @@ -100,35 +100,17 @@ DATA.selected_rate = DATA.NOT_SELECTED_VALUE; } + // Mark the selected_rate + $("#selected-star-rate").val(DATA.selected_rate); + var star_notice = $(".star-notice"); + star_notice.find("span").html(DATA.selected_rate); star_notice.removeClass("star-hide"); - - // Call selected_rate_action to send the rate data. - selected_rate_action(star_notice); }); } /* - * Send the user rate to the server when he/she clicks on the rate button - */ - function selected_rate_action(notice_element) { - var profile = $("#community-profile").val(); - - $.ajax({ - url: "/profile/"+profile+"/plugin/communities_ratings/rate", - type: "POST", - data: { - value: DATA.selected_rate - }, - success: function(response) { - notice_element.html(response.message); - } - }); - } - - - /* * When the page DOM is ready, set all the stars events */ $(document).ready(function() { diff --git a/plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb b/plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb index 8f3b780..da94130 100644 --- a/plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb +++ b/plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb @@ -1,10 +1,5 @@ - - - -
-
-<%= @plugins.dispatch(:communities_ratings_title).collect { |content| instance_exec(&content) }.join("") %> + <%= @plugins.dispatch(:communities_ratings_title).collect { |content| instance_exec(&content) }.join("") %>
@@ -35,12 +30,15 @@ <% end %>
+
+ <%= _("Rated as") %> <%= _("stars") %> +
<%= form_for :comments do |c| %>
- <%= c.label :body, _('Comment:'), :class => "formlabel" %> + <%= c.label :body, _('Comment (Optional):'), :class => "formlabel" %> <%= c.text_area :body %>
@@ -48,6 +46,8 @@
<%= c.submit _("Send"), class: "button icon-save submit with-text" %>
+ + <% end %>
-- libgit2 0.21.2