On 04 Sep 2009, at 18:37, Heinz Strunk wrote:
>
> Heinz Strunk wrote:
>> Well, I know how to show and hide a div box but my question was if
>> it's
>> possible to do it for all remote calls or do I have to add
>> :loading => "Element.show('ajax-loader')"
>> and
>> :complete => "Element.hide('ajax-loader')"
>> to every single remote call I wanna use the loader for?
>
> Got it... helper was the solution:
> def link_to_remote(name, options = {}, html_options = nil)
> options[:loading] = "Element.show('loading')"
> options[:complete] = "Element.hide('loading')"
> link_to_function(name, remote_function(options), html_options ||
> options.delete(:html))
> end
A much better solution than patching the rails helpers would be to add
the following to public/javascripts/application.js (it adds a nice
little fade in and fade out too):
Ajax.Responders.register({
onCreate: function() {
new Effect.Appear('loading', { duration: 0.3 });
},
onComplete: function(request, transport, json) {
if (0 == Ajax.activeRequestCount) {
new Effect.Fade('loading', { duration: 0.3 });
}
if(!request.success()) {
alert('An error occurred while processing this request');
}
}
});
Best regards
Peter De Berdt
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---