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
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
#
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 = '';
var currentlyDisplayedDropdownMenu;
-var hideCurrentDropdownMenu = function() {
+var hideCurrentDropdownMenu = function () {
menu = $j('#' + currentlyDisplayedDropdownMenu);
if (menu) {
menu.hide();
$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');