Module: RemoteHelpers

Defined in:
lib/generators/liquid_cms/templates/vendor/plugins/remote_helpers/lib/remote_helpers.rb

Overview

Progress indication is built in using the indicator method and the optional :indicator option for remote calls. See remote_function documentation for more information.

The :indicator options adds the functionality of using a remote indicator (an image) during the execution of all remote functions.

Functionality added to disable the form by default during a remote call using methods such as remote_function, form_remote_tag, remote_form_for and submit_to_remote.

This is useful to prevent a user from submitting a form twice while a remote call is in progress since the submit button will be disabled and therefore not clickable.

Additional options:

  • :indicator - The css id of an element to show and hide during a remote call. Defaults to RemoteIndicator.default_id. Set :indicator to false if no indicator is to be used. Set :indicator to true in order to use the default indicator (RemoteIndicator.default_id). If RemoteIndicator.enable_all is set to true, :indicator => true is not required. Set :indicator to a hash with the :toggle option to replace the current element with the dom element specified by :toggle. Ex. :indicator => {:toggle => dom_id(object)}

  • :disable_form - Specifies if the form will disable or not during the remote call. Defaults to true. Set :disable_form to false to keep the form enabled during a remote function call.

  • :before_effect - Specifies the before ‘effect’ for the indicator. Defaults to ‘Element.show’.

  • :after_effect - Specifies the after ‘effect’ for the indicator. Defaults to ‘Element.hide’.

Instance Method Summary collapse

Instance Method Details

#indicator(options = {}) ⇒ Object

Creates an indicator image. The options supplied are the same used with image_tag

Examples

Using a custom indicator id

<%= indicator :id => 'spinner' %>

Shorthand using a string for the options (sets the :id automatically)

<%= indicator 'spinner' %>

Toggle the current link with an indicator

<%= link_to_remote image_tag('add.png'), :url => do_something_path, :indicator => {:toggle => 'spinner'} %> <%= indicator 'spinner' %>

Using many indicators on the same page

<% collection.each do |id| %>
  <%= link_to_remote :url => do_something_path, :indicator => "link#{id}" %> <%= indicator :id => "link#{id}" %>
<% end %>


87
88
89
# File 'lib/generators/liquid_cms/templates/vendor/plugins/remote_helpers/lib/remote_helpers.rb', line 87

def indicator(options = {})
  indicator_image indicator_options(options)
end

#indicator_image(options = {}) ⇒ Object

Creates an indicator image. The options supplied are the same used with image_tag

This method differs from indicator in that it simply produces the indicator image without the additional indicator options to for hiding the image by default etc. Without the additional options, this method can create the standalone indicator image for use in more complex indicators that use the image in combination with additional markup.

Example

<%= content_tag ‘div’, ‘Updating Data… ’ + indicator_image, indicator_options %>



124
125
126
# File 'lib/generators/liquid_cms/templates/vendor/plugins/remote_helpers/lib/remote_helpers.rb', line 124

def indicator_image(options = {})
  image_tag RemoteIndicator.default_image, options
end

#indicator_options(options = {}) ⇒ Object

Sets the proper options for custom indicators.

Current and additional options are:

  • :id - The css id of the indicator. Defaults to RemoteIndicator.default_id

  • :class - The css class of the indicator. Defaults to RemoteIndicator.default_class

  • :hide - Hide the image by default. Defaults to true.

Example

Create an indicator with text

<%= content_tag 'span', 'Updating Data... ', indicator_options %>

Pass any options you’d normally use to the method itself

<%= content_tag 'span', 'Updating Data... ', indicator_options(:style => 'width:100px')


105
106
107
108
109
110
111
112
# File 'lib/generators/liquid_cms/templates/vendor/plugins/remote_helpers/lib/remote_helpers.rb', line 105

def indicator_options(options = {})
  # if options is a string then use it as the :id value
  options = {:id => options} if options.is_a?(String)

  options.reverse_merge!(:id => RemoteIndicator.default_id, :class => RemoteIndicator.default_class, :hide => true)
  options[:style] = [options[:style], 'display:none'].compact.join(';') if options.delete(:hide)
  options
end