Commit 76e3cbd7ac101bbee44e6e9b6eaaf0b6a3a97386
Committed by
Pedro de Lyra Pereira
1 parent
1e289d8d
Exists in
communities_ratings
Remove star rate ajax and set commment as optional
Signed-off-by: Fábio Teixeira <fabio1079@gmail.com> Signed-off-by: Pedro de Lyra Pereira <pedrodelyra@gmail.com>
Showing
3 changed files
with
20 additions
and
64 deletions
Show diff stats
plugins/communities_ratings/controllers/communities_ratings_plugin_profile_controller.rb
| 1 | 1 | class CommunitiesRatingsPluginProfileController < ProfileController |
| 2 | - | |
| 3 | 2 | before_filter :login_required |
| 4 | - # Inside a community, receive a ajax from the current logged person with its | |
| 5 | - # rate for the community. If the user already rated this commnity, update its | |
| 6 | - # rate value or else, create a new one | |
| 7 | - def rate | |
| 8 | - # If its not a ajax request or the profile isn't a community | |
| 9 | - if (not request.xhr?) or (profile.type != "Community") | |
| 10 | - # Redirect to the profile home page | |
| 11 | - return redirect_to :controller => 'profile', :action => :index | |
| 12 | - end | |
| 13 | - | |
| 14 | - community_rating = get_community_rating(user, profile) | |
| 15 | - community_rating.value = params[:value].to_i | |
| 16 | - | |
| 17 | - if community_rating.save | |
| 18 | - render :json => { | |
| 19 | - success: true, | |
| 20 | - message: "Successfully rated community #{community_rating.community.name}" | |
| 21 | - } | |
| 22 | - else | |
| 23 | - render :json => { | |
| 24 | - success: false, | |
| 25 | - message: "Could not rate community #{community_rating.community.name}", | |
| 26 | - errors: community_rating.errors.full_messages | |
| 27 | - } | |
| 28 | - end | |
| 29 | - end | |
| 30 | 3 | |
| 31 | 4 | def new_rating |
| 32 | 5 | @plugins = plugins |
| 33 | - community_rating = get_community_rating(user, profile) | |
| 6 | + community_rating = get_community_rating(user, profile, params[:community_rating_value]) | |
| 34 | 7 | @actual_rate_value = if community_rating.value |
| 35 | 8 | community_rating.value |
| 36 | 9 | else |
| ... | ... | @@ -38,17 +11,17 @@ class CommunitiesRatingsPluginProfileController < ProfileController |
| 38 | 11 | end |
| 39 | 12 | |
| 40 | 13 | if request.post? |
| 41 | - unless params[:comments][:body].empty? | |
| 14 | + if params[:comments] and not params[:comments][:body].empty? | |
| 42 | 15 | comment = Comment.new(params[:comments]) |
| 43 | 16 | comment.author = current_user.person |
| 44 | 17 | comment.community = profile |
| 45 | 18 | comment.save |
| 19 | + | |
| 46 | 20 | community_rating.comment = comment |
| 47 | - community_rating.save | |
| 48 | - else | |
| 49 | - session[:notice] = _("You need to provide a decription to make a comment") | |
| 50 | - redirect_to action: :new_rating | |
| 51 | 21 | end |
| 22 | + | |
| 23 | + community_rating.save! | |
| 24 | + session[:notice] = _("#{profile.name} successfully rated") | |
| 52 | 25 | end |
| 53 | 26 | end |
| 54 | 27 | |
| ... | ... | @@ -56,7 +29,7 @@ class CommunitiesRatingsPluginProfileController < ProfileController |
| 56 | 29 | |
| 57 | 30 | # If there is already a rate by the current logged user to this community |
| 58 | 31 | # return it or else, prepare a new one |
| 59 | - def get_community_rating person, community | |
| 32 | + def get_community_rating person, community, community_rating_value=nil | |
| 60 | 33 | already_rated = CommunityRating.where( |
| 61 | 34 | :community_id=>community.id, |
| 62 | 35 | :person_id=>person.id |
| ... | ... | @@ -66,7 +39,8 @@ class CommunitiesRatingsPluginProfileController < ProfileController |
| 66 | 39 | already_rated.first |
| 67 | 40 | else |
| 68 | 41 | CommunityRating.new :person => person, |
| 69 | - :community => community | |
| 42 | + :community => community, | |
| 43 | + :value => community_rating_value | |
| 70 | 44 | end |
| 71 | 45 | end |
| 72 | 46 | end | ... | ... |
plugins/communities_ratings/public/rate.js
| ... | ... | @@ -100,35 +100,17 @@ |
| 100 | 100 | DATA.selected_rate = DATA.NOT_SELECTED_VALUE; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | + // Mark the selected_rate | |
| 104 | + $("#selected-star-rate").val(DATA.selected_rate); | |
| 105 | + | |
| 103 | 106 | var star_notice = $(".star-notice"); |
| 107 | + star_notice.find("span").html(DATA.selected_rate); | |
| 104 | 108 | star_notice.removeClass("star-hide"); |
| 105 | - | |
| 106 | - // Call selected_rate_action to send the rate data. | |
| 107 | - selected_rate_action(star_notice); | |
| 108 | 109 | }); |
| 109 | 110 | } |
| 110 | 111 | |
| 111 | 112 | |
| 112 | 113 | /* |
| 113 | - * Send the user rate to the server when he/she clicks on the rate button | |
| 114 | - */ | |
| 115 | - function selected_rate_action(notice_element) { | |
| 116 | - var profile = $("#community-profile").val(); | |
| 117 | - | |
| 118 | - $.ajax({ | |
| 119 | - url: "/profile/"+profile+"/plugin/communities_ratings/rate", | |
| 120 | - type: "POST", | |
| 121 | - data: { | |
| 122 | - value: DATA.selected_rate | |
| 123 | - }, | |
| 124 | - success: function(response) { | |
| 125 | - notice_element.html(response.message); | |
| 126 | - } | |
| 127 | - }); | |
| 128 | - } | |
| 129 | - | |
| 130 | - | |
| 131 | - /* | |
| 132 | 114 | * When the page DOM is ready, set all the stars events |
| 133 | 115 | */ |
| 134 | 116 | $(document).ready(function() { | ... | ... |
plugins/communities_ratings/views/communities_ratings_plugin_profile/new_rating.html.erb
| 1 | -<input type="hidden" id="community-profile" value="<%= @profile.identifier %>"> | |
| 2 | -<input type="hidden" id="selected-star-rate" value="<%= @actual_rate_value %>"> | |
| 3 | - | |
| 4 | -<div class="star-notice star-hide"></div> | |
| 5 | - | |
| 6 | 1 | <div class="star-page-title"> |
| 7 | -<%= @plugins.dispatch(:communities_ratings_title).collect { |content| instance_exec(&content) }.join("") %> | |
| 2 | + <%= @plugins.dispatch(:communities_ratings_title).collect { |content| instance_exec(&content) }.join("") %> | |
| 8 | 3 | </div> |
| 9 | 4 | |
| 10 | 5 | <div class="star-rate-data"> |
| ... | ... | @@ -35,12 +30,15 @@ |
| 35 | 30 | <% end %> |
| 36 | 31 | </div> |
| 37 | 32 | |
| 33 | + <div class="star-notice star-hide"> | |
| 34 | + <%= _("Rated as") %> <span></span> <%= _("stars") %> | |
| 35 | + </div> | |
| 38 | 36 | </div> |
| 39 | 37 | |
| 40 | 38 | <div class="star-comment-container"> |
| 41 | 39 | <%= form_for :comments do |c| %> |
| 42 | 40 | <div class="formfieldline formfield type-text"> |
| 43 | - <%= c.label :body, _('Comment:'), :class => "formlabel" %> | |
| 41 | + <%= c.label :body, _('Comment (Optional):'), :class => "formlabel" %> | |
| 44 | 42 | <%= c.text_area :body %> |
| 45 | 43 | </div> |
| 46 | 44 | |
| ... | ... | @@ -48,6 +46,8 @@ |
| 48 | 46 | <div class="button-bar"> |
| 49 | 47 | <%= c.submit _("Send"), class: "button icon-save submit with-text" %> |
| 50 | 48 | </div> |
| 49 | + | |
| 50 | + <input type="hidden" id="selected-star-rate" name="community_rating_value" value="<%= @actual_rate_value %>"> | |
| 51 | 51 | <% end %> |
| 52 | 52 | </div> |
| 53 | 53 | </div> | ... | ... |