Sha256: decfdc85a9db8229c7012f90db4c27785d35a677852b7262f33571ef1bcb4e86

Contents?: true

Size: 1.45 KB

Versions: 30

Compression:

Stored size: 1.45 KB

Contents

class Marty::ConfigView < Marty::Grid
  has_marty_permissions \
  create: :admin,
  read: :admin,
  update: :admin,
  delete: :admin

  include Marty::Extras::Layout

  def configure(c)
    super

    c.title   = I18n.t('config', default: "Config")
    c.model   = "Marty::Config"
    c.attributes = [:key, :value, :description]
    c.store_config.merge!({sorters: [{property: :key, direction: 'ASC'}]})
    c.editing = :both
  end

  # need a getter / setter to call the []= and [] methods now
  # since value is no longer stored as is
  def my_jsonb_getter
    lambda { |r| Marty::Config[r.key].to_json }
  end

  def my_jsonb_setter
    lambda { |r, v|
      decoded = ActiveSupport::JSON.decode(v) rescue nil
      r.set_value(decoded)
    }
  end

  def default_form_items
    [
      :key,
      {
        name:        :value,
        width:       "100%",
        height:      150,
        xtype:       :textareafield,
        auto_scroll: true,
        spellcheck:  false,
        allow_blank: false,
        field_style: {
          font_family: 'courier new',
          font_size:   '12px'
        },
        getter:  my_jsonb_getter,
        setter:  my_jsonb_setter,
      },
      textarea_field(:description),
    ]
  end

  attribute :key do |c|
    c.flex = 1
  end

  attribute :value do |c|
    c.flex = 3
    c.getter  = my_jsonb_getter
    c.setter  = my_jsonb_setter
  end
  attribute :description do |c|
    c.flex = 1
  end

end

ConfigView = Marty::ConfigView

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
marty-1.0.32 app/components/marty/config_view.rb
marty-1.0.31 app/components/marty/config_view.rb
marty-1.0.30 app/components/marty/config_view.rb
marty-1.0.29 app/components/marty/config_view.rb
marty-1.0.28 app/components/marty/config_view.rb
marty-1.0.27 app/components/marty/config_view.rb
marty-1.0.26 app/components/marty/config_view.rb
marty-1.0.25 app/components/marty/config_view.rb
marty-1.0.24 app/components/marty/config_view.rb
marty-1.0.23 app/components/marty/config_view.rb
marty-1.0.22 app/components/marty/config_view.rb
marty-1.0.20 app/components/marty/config_view.rb
marty-1.0.19 app/components/marty/config_view.rb
marty-1.0.18 app/components/marty/config_view.rb
marty-1.0.17 app/components/marty/config_view.rb
marty-1.0.15 app/components/marty/config_view.rb
marty-1.0.14 app/components/marty/config_view.rb
marty-1.0.13 app/components/marty/config_view.rb
marty-1.0.12 app/components/marty/config_view.rb
marty-1.0.11 app/components/marty/config_view.rb