From 4ca61315152202f28fab2e050fe5134c5d40dc04 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Fri, 14 Dec 2012 18:00:56 +0100 Subject: [PATCH] Fix favourite stars in filter widgets -> move from prototypejs to jquery --- .../app/controllers/favourites_controller.rb | 18 ++++++------------ .../WEB-INF/app/helpers/application_helper.rb | 17 ++++++++--------- .../src/main/webapp/javascripts/application.js | 13 +++++++++++-- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/sonar-server/src/main/webapp/WEB-INF/app/controllers/favourites_controller.rb b/sonar-server/src/main/webapp/WEB-INF/app/controllers/favourites_controller.rb index 1d2283c5e39..6343ed37c64 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/controllers/favourites_controller.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/controllers/favourites_controller.rb @@ -23,24 +23,18 @@ class FavouritesController < ApplicationController def toggle favourite_id=params[:id] + if current_user.favourite?(favourite_id) current_user.delete_favourite(favourite_id) - style='notfav' - tooltip='Click to add to favourites' + css='notfav' + title=message('click_to_add_to_favourites') else current_user.add_favourite(favourite_id) - style='fav' - tooltip='Click to remove from favourites' + css='fav' + title=message('click_to_remove_from_favourites') end - star_id=params[:elt] - render :update do |page| - page.element.removeClassName(star_id, 'notfav') - page.element.removeClassName(star_id, 'fav') - page.element.addClassName(star_id, style) - page.element.writeAttribute(star_id, 'alt', tooltip) - page.element.writeAttribute(star_id, 'title', tooltip) - end + render :json => {:css => css, :title => title}, :status => 200 end end diff --git a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb index bde14bf5859..5f271aadbe1 100644 --- a/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb +++ b/sonar-server/src/main/webapp/WEB-INF/app/helpers/application_helper.rb @@ -336,20 +336,19 @@ module ApplicationHelper image_tag("#{ApplicationController.root_context}/chart?#{parameters}", options) end - def link_to_favourite(resource, options={}) + def link_to_favourite(resource, deprecated_options=nil) return '' unless (logged_in?) return '' if resource.nil? resource_id=(resource.is_a?(Fixnum) ? resource : resource.permanent_id) - html_id=options['html_id'] || "fav#{resource_id}" - initial_class='notfav' - initial_tooltip=message('click_to_add_to_favourites') + if current_user.favourite?(resource_id) - initial_class='fav' - initial_tooltip=message('click_to_remove_from_favourites') + css='fav' + title=message('click_to_remove_from_favourites') + else + css='notfav' + title=message('click_to_add_to_favourites') end - - link_to_remote('', :url => {:controller => 'favourites', :action => 'toggle', :id => resource_id, :elt => html_id}, - :method => :post, :html => {:class => initial_class, :id => html_id, :alt => initial_tooltip, :title => initial_tooltip}) + link_to_function '', "toggleFav(#{resource_id}, this)", :class => css, :title => title end # diff --git a/sonar-server/src/main/webapp/javascripts/application.js b/sonar-server/src/main/webapp/javascripts/application.js index dab9e953d63..aa0d8c0a94b 100644 --- a/sonar-server/src/main/webapp/javascripts/application.js +++ b/sonar-server/src/main/webapp/javascripts/application.js @@ -11,6 +11,15 @@ function warning(message) { function info(message) { showMessage('info', message); } +function toggleFav(resourceId, elt) { + $j.ajax({type: 'POST', dataType: 'json', url: baseUrl + '/favourites/toggle/' + resourceId, + success: function (data) { + var star = $j(elt); + star.removeClass('fav notfav'); + star.addClass(data['css']); + star.attr('title', data['title']); + }}); +} function autocompleteResources() { $('searchInput').value = ''; @@ -316,7 +325,7 @@ function supports_html5_storage() { var currentlyDisplayedDropdownMenu; -var hideCurrentDropdownMenu = function() { +var hideCurrentDropdownMenu = function () { menu = $j('#' + currentlyDisplayedDropdownMenu); if (menu) { menu.hide(); @@ -324,7 +333,7 @@ var hideCurrentDropdownMenu = function() { $j(document).unbind('mouseup', hideCurrentDropdownMenu); } -var clickOnDropdownMenuLink = function(event) { +var clickOnDropdownMenuLink = function (event) { var link = $j(event.target).children('a'); if (link) { var href = link.attr('href'); -- 2.39.5