module ActiveScaffold::Helpers::ViewHelpers

All extra helpers that should be included in the View. Also a dumping ground for uncategorized helpers.

Public Instance Methods

active_scaffold_config() click to toggle source

access to the configuration variable

# File lib/active_scaffold/helpers/view_helpers.rb, line 20
def active_scaffold_config
  controller.class.active_scaffold_config
end
active_scaffold_config_for(*args) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 24
def active_scaffold_config_for(*args)
  controller.class.active_scaffold_config_for(*args)
end
active_scaffold_controller_for(*args) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 28
def active_scaffold_controller_for(*args)
  controller.class.active_scaffold_controller_for(*args)
end
active_scaffold_error_messages_for(*params) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 318
def active_scaffold_error_messages_for(*params)
  options = params.extract_options!.symbolize_keys
  options.reverse_merge!(:container_tag => :div, :list_type => :ul)

  objects = Array.wrap(options.delete(:object) || params).map do |object|
    object = instance_variable_get("@#{object}") unless object.respond_to?(:to_model)
    object = convert_to_model(object)

    if object.class.respond_to?(:model_name)
      options[:object_name] ||= object.class.model_name.human.downcase
    end

    object
  end

  objects.compact!
  count = objects.inject(0) {|sum, object| sum + object.errors.count }

  unless count.zero?
    html = {}
    [:id, :class].each do |key|
      if options.include?(key)
        value = options[key]
        html[key] = value unless value.blank?
      else
        html[key] = 'errorExplanation'
      end
    end
    options[:object_name] ||= params.first

    header_message = if options.include?(:header_message)
      options[:header_message]
    else
      as_('errors.template.header', :count => count, :model => options[:object_name].to_s.gsub('_', ' '))
    end

    message = options.include?(:message) ? options[:message] : as_('errors.template.body')

    error_messages = objects.sum do |object|
      object.errors.full_messages.map do |msg|
        options[:list_type] != :br ? content_tag(:li, msg) : msg
      end
    end
    error_messages = if options[:list_type] == :br
      error_messages.join('<br/>').html_safe
    else
      content_tag(options[:list_type], error_messages.join.html_safe)
    end

    contents = []
    contents << content_tag(options[:header_tag] || :h2, header_message) unless header_message.blank?
    contents << content_tag(:p, message) unless message.blank?
    contents << error_messages
    contents = contents.join.html_safe
    options[:container_tag] ? content_tag(options[:container_tag], contents, html) : contents
  else
    ''
  end
end
active_scaffold_ie_stylesheets(frontend = :default) click to toggle source

Provides stylesheets for IE to include with stylesheet_link_tag

# File lib/active_scaffold/helpers/view_helpers.rb, line 96
def active_scaffold_ie_stylesheets(frontend = :default)
  [ActiveScaffold::Config::Core.asset_path("stylesheet-ie.css", frontend)]
end
active_scaffold_includes(*args) click to toggle source

easy way to include ActiveScaffold assets

# File lib/active_scaffold/helpers/view_helpers.rb, line 101
def active_scaffold_includes(*args)
  frontend = args.first.is_a?(Symbol) ? args.shift : :default
  options = args.first.is_a?(Hash) ? args.shift : {}
  js = javascript_include_tag(*active_scaffold_javascripts(frontend).push(options))

  css = stylesheet_link_tag(*active_scaffold_stylesheets(frontend).push(options))
  options[:cache] += '_ie' if options[:cache].is_a? String
  options[:concat] += '_ie' if options[:concat].is_a? String
  ie_css = stylesheet_link_tag(*active_scaffold_ie_stylesheets(frontend).push(options))

  js + "\n" + css + "\n<!--[if IE]>".html_safe + ie_css + "<![endif]-->\n".html_safe
end
active_scaffold_javascripts(frontend = :default) click to toggle source

Provides list of javascripts to include with javascript_include_tag You can use this with your javascripts like

<%= javascript_include_tag :defaults, 'your_own_cool_script', active_scaffold_javascripts, :cache => true %>
# File lib/active_scaffold/helpers/view_helpers.rb, line 84
def active_scaffold_javascripts(frontend = :default)
  ActiveScaffold::Config::Core.javascripts(frontend).collect do |name|
    ActiveScaffold::Config::Core.asset_path(name, frontend)
  end
end
active_scaffold_stylesheets(frontend = :default) click to toggle source

Provides stylesheets to include with stylesheet_link_tag

# File lib/active_scaffold/helpers/view_helpers.rb, line 91
def active_scaffold_stylesheets(frontend = :default)
  [ActiveScaffold::Config::Core.asset_path("stylesheet.css", frontend)]
end
as_main_div_class() click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 267
def as_main_div_class
  classes = ["active-scaffold", "active-scaffold-#{controller_id}", "#{params[:controller]}-view", "#{active_scaffold_config.theme}-theme"]
  classes << "as_touch" if touch_device?
  classes.join(' ')
end
clean_class_name(name) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 314
def clean_class_name(name)
  name.underscore.gsub('/', '_')
end
clean_column_name(name) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 310
def clean_column_name(name)
  name.to_s.gsub('?', '')
end
column_calculation(column) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 280
def column_calculation(column)
  unless column.calculate.instance_of? Proc
    conditions = controller.send(:all_conditions)
    includes = active_scaffold_config.list.count_includes
    includes ||= controller.send(:active_scaffold_includes) unless conditions.nil?
    calculation = beginning_of_chain.calculate(column.calculate, column.name, :conditions => conditions,
     :joins => controller.send(:joins_for_collection), :include => includes)
  else
    column.calculate.call(@records)
  end
end
column_class(column, column_value, record) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 243
def column_class(column, column_value, record)
  classes = []
  classes << "#{column.name}-column"
  if column.css_class.is_a?(Proc)
    css_class = column.css_class.call(column_value, record)
    classes << css_class unless css_class.nil?
  else
    classes << column.css_class
  end unless column.css_class.nil?
   
  classes << 'empty' if column_empty? column_value
  classes << 'sorted' if active_scaffold_config.list.user.sorting.sorts_on?(column)
  classes << 'numeric' if column.column and [:decimal, :float, :integer].include?(column.column.type)
  classes.join(' ').rstrip
end
column_empty?(column_value) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 273
def column_empty?(column_value)
  empty = column_value.nil?
  empty ||= column_value.blank? if column_value.respond_to? :blank?
  empty ||= ['&nbsp;', active_scaffold_config.list.empty_field_text].include? column_value if String === column_value
  return empty
end
column_heading_class(column, sorting) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 259
def column_heading_class(column, sorting)
  classes = []
  classes << "#{column.name}-column_heading"
  classes << "sorted #{sorting.direction_of(column).downcase}" if sorting.sorts_on? column
  classes << column.css_class unless column.css_class.nil? || column.css_class.is_a?(Proc)
  classes.join(' ')
end
column_show_add_existing(column) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 300
def column_show_add_existing(column)
  (column.allow_add_existing and options_for_association_count(column.association) > 0)
end
column_show_add_new(column, associated, record) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 304
def column_show_add_new(column, associated, record)
  value = (column.plural_association? && !column.readonly_association?) || (column.singular_association? and not associated.empty?)
  value = false unless column.association.klass.authorized_for?(:crud_type => :create)
  value
end
controller_path_for_activerecord(klass) click to toggle source

Uncategorized

# File lib/active_scaffold/helpers/view_helpers.rb, line 36
def controller_path_for_activerecord(klass)
  begin
    controller = active_scaffold_controller_for(klass)
    controller.controller_path
  rescue ActiveScaffold::ControllerNotFound
    controller = nil
  end
end
form_remote_upload_tag(url_for_options = {}, options = {}) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 72
def form_remote_upload_tag(url_for_options = {}, options = {})
  options[:target] = action_iframe_id(url_for_options)
  options[:multipart] ||= true
  options[:class] = "#{options[:class]} as_remote_upload".strip 
  output=""
  output << form_tag(url_for_options, options)
  (output << "<iframe id='#{action_iframe_id(url_for_options)}' name='#{action_iframe_id(url_for_options)}' style='display:none'></iframe>").html_safe
end
generate_temporary_id() click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 45
def generate_temporary_id
  (Time.now.to_f*1000).to_i.to_s
end
in_subform?(column, parent_record) click to toggle source

Should this column be displayed in the subform?

# File lib/active_scaffold/helpers/view_helpers.rb, line 60
def in_subform?(column, parent_record)
  return true unless column.association

  # Polymorphic associations can't appear because they *might* be the reverse association, and because you generally don't assign an association from the polymorphic side ... I think.
  return false if column.polymorphic_association?

  # A column shouldn't be in the subform if it's the reverse association to the parent
  return false if column.association.reverse_for?(parent_record.class)

  return true
end
loading_indicator_tag(options) click to toggle source

a general-use loading indicator (the “stuff is happening, please wait” feedback)

# File lib/active_scaffold/helpers/view_helpers.rb, line 115
def loading_indicator_tag(options)
  image_tag "/images/active_scaffold/default/indicator.gif", :style => "visibility:hidden;", :id => loading_indicator_id(options), :alt => "loading indicator", :class => "loading-indicator"
end
option_tags_for(select_options, options = {}) click to toggle source

Turns [[label, value]] into <option> tags Takes optional parameter of :include_blank

# File lib/active_scaffold/helpers/view_helpers.rb, line 51
def option_tags_for(select_options, options = {})
  select_options.insert(0,[as_(:_select_),nil]) if options[:include_blank]
  select_options.collect do |option|
    label, value = option[0], option[1]
    value.nil? ? "<option value="">#{label}</option>" : "<option value=\"#{value}\">#{label}</option>"
  end
end
render_column_calculation(column) click to toggle source
# File lib/active_scaffold/helpers/view_helpers.rb, line 292
def render_column_calculation(column)
  calculation = column_calculation(column)
  override_formatter = "render_#{column.name}_#{column.calculate}"
  calculation = send(override_formatter, calculation) if respond_to? override_formatter

  "#{"#{as_(column.calculate)}: " unless column.calculate.is_a? Proc}#{format_column_value nil, column, calculation}"
end