Sha256: cbbf5dbc00550de629c90c9088b87803d15eb86b4965398310af975f26a1cd4e

Contents?: true

Size: 1.32 KB

Versions: 12

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

require 'active_admin'

module ActiveAdmin
  module DynamicFields
    class Engine < ::Rails::Engine
      engine_name 'activeadmin_dynamic_fields'
    end

    def self.edit_boolean(field, url, value)
      {
        'data-field': field,
        'data-field-type': 'boolean',
        'data-field-value': value,
        'data-content': "<span class=\"status_tag changed\">#{value ? 'no' : 'yes'}</span>",
        'data-save-url': url,
        'data-show-errors': '1'
      }
    end

    def self.edit_select(field, url)
      {
        'data-field': field,
        'data-field-type': 'select',
        'data-save-url': url,
        'data-show-errors': '1'
      }
    end

    def self.edit_string(field, url)
      {
        contenteditable: true,
        'data-field': field,
        'data-field-type': 'string',
        'data-save-url': url,
        'data-show-errors': '1'
      }
    end

    def self.update(resource, params, permit_params = nil)
      if params[:data]
        if resource.update(permit_params ? params[:data].permit(permit_params) : params[:data].permit!)
          { json: { status: 'ok' } }
        else
          { json: { status: 'error', message: resource.errors } }
        end
      else
        { json: { status: 'error', message: 'No data' }, status: 400 }
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
activeadmin_dynamic_fields-0.8.0 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.7.0 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.6.4 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.6.0 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.5.2 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.5.0 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.4.4 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.4.2 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.4.0 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.3.0 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.2.8 lib/activeadmin/dynamic_fields/engine.rb
activeadmin_dynamic_fields-0.2.6 lib/activeadmin/dynamic_fields/engine.rb