Sha256: 22f62e2e345e688f818bedcbed2bdee5dffb979936d6068f2fc5f467fe9c8a3a

Contents?: true

Size: 1.03 KB

Versions: 1

Compression:

Stored size: 1.03 KB

Contents

module NsSettingsUi
  module SettingsHelper
    def setting_value_class(setting)
      return 'alert-danger' if setting.value.nil? || setting.value.empty?
      return 'alert-warning' if setting.value != setting.default_value
      ''
    end

    def render_value_field(form, setting)
      render_field(form, setting.value_type, :value, setting_value_class(setting))
    end

    def render_default_value_field(form, setting)
      render_field(form, setting.value_type, :default_value)
    end

    private

    def render_field(form, value_type, name, additional_class = '')
      if [NsSettingsUi::Setting::TYPES[:boolean], NsSettingsUi::Setting::TYPES[:nullable_boolean]].include?(value_type)
        form.select(name, [[:true, 'true'], [:false, 'false']], {include_blank: true}, {class: "form-select form-select-sm"})
      else
        form.text_field(name, size: 10, class: "form-control form-control-sm #{additional_class}")
      end
    end

    def recursive_hash
      Hash.new { |hash, key| hash[key] = recursive_hash }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ns_settings_ui-1.6.0 app/helpers/ns_settings_ui/settings_helper.rb