Sha256: 25655b95e4c29ccfda725d21b13bdaa6a44bce415baa4756e1ab1c8dbb575692

Contents?: true

Size: 1.46 KB

Versions: 17

Compression:

Stored size: 1.46 KB

Contents

module SettingsHelper
  def field(form, key, opts = {})
    html = '<div class="form-group">'

    case form.object.column_type(key)
    when :hidden
      return form.hidden_field(key)
    when :boolean, :flag
      html << form.check_box(key, {}, "true", "false")
      html << " " # NOTE: Adding space for padding
      html << h(form.label(key))
    when :choice
      html << h(form.label(key))
      html << " " # NOTE: Adding space for padding
      html << form.select(key, form.object.values_of(key), opts)
    when :nested
      child_data = form.object.class.children[key]
      klass = child_data[:class]
      options = child_data[:options]
      children = form.object.send(key) || {"0" => {}}
      children.each_pair do |index, child|
        html << %Q!<div class="js-nested-column #{options[:multiple] ? "js-multiple" : ""} well well-sm">!
        if options[:multiple]
          html << %Q!<a class="btn btn-xs btn-default js-append">#{icon('fa-plus')}</a> !
          html << %Q!<a class="btn btn-xs btn-default js-remove" style="display:none">#{icon('fa-minus')}</a> !
        end
        html << h(form.label(key))
        form.fields_for("#{key}[#{index}]", klass.new(child)) do |ff|
          klass::KEYS.each do |k|
            html << field(ff, k)
          end
        end
        html << "</div>"
      end
    else
      html << h(form.label(key))
      html << form.text_field(key, class: "form-control")
    end

    html << "</div>"
    html.html_safe
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
fluentd-ui-0.3.11 app/helpers/settings_helper.rb
fluentd-ui-0.3.10 app/helpers/settings_helper.rb
fluentd-ui-0.3.9 app/helpers/settings_helper.rb
fluentd-ui-0.3.8 app/helpers/settings_helper.rb
fluentd-ui-0.3.7 app/helpers/settings_helper.rb
fluentd-ui-0.3.6 app/helpers/settings_helper.rb
fluentd-ui-0.3.5 app/helpers/settings_helper.rb
fluentd-ui-0.3.3 app/helpers/settings_helper.rb
fluentd-ui-0.3.2 app/helpers/settings_helper.rb
fluentd-ui-0.3.1 app/helpers/settings_helper.rb
fluentd-ui-0.3.0 app/helpers/settings_helper.rb
fluentd-ui-0.2.0 app/helpers/settings_helper.rb
fluentd-ui-0.1.4 app/helpers/settings_helper.rb
fluentd-ui-0.1.3 app/helpers/settings_helper.rb
fluentd-ui-0.1.2 app/helpers/settings_helper.rb
fluentd-ui-0.1.1 app/helpers/settings_helper.rb
fluentd-ui-0.1.0 app/helpers/settings_helper.rb