Sha256: 72b1221d8d789a5051a001e542c124d6ec971f4fa52d941e6b20a63572a97161

Contents?: true

Size: 1.39 KB

Versions: 7

Compression:

Stored size: 1.39 KB

Contents

module RailsAdminState
  class Configuration
    def initialize(abstract_model)
      @abstract_model = abstract_model
    end

    def options
      @options ||= {
          states: {
            published: 'label-success',
            sent: 'label-success',
            done: 'label-success',
            cancelled: 'label-important',
            deleted: 'label-important',
            trashed: 'label-important',
            draft: 'label-important',
          },
          events: {
            publish: 'btn-success',
            confirm: 'btn-success',
            send: 'btn-success',
            done: 'btn-success',
            cancel: 'btn-danger',
            delete: 'btn-danger',
            trash: 'btn-danger',
          },
          disable: []
      }.merge(config)
      @options
    end

    def state(name)
      return '' if name.nil?
      options[:states][name.to_sym] || 'label-default'
    end

    def event(name)
      return '' if name.nil?
      options[:events][name.to_sym] || 'btn-default'
    end

    def disabled?(name)
      return '' if name.nil?
      options[:disable].include? name.to_sym
    end

    def authorize?
      options[:authorize]
    end

    protected
    def config
      begin
        opt = ::RailsAdmin::Config.model(@abstract_model.model).state
        if opt.nil?
          {}
        else
          opt
        end
      rescue
        {}
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rails_admin_state-1.9.1 lib/rails_admin_state/configuration.rb
rails_admin_state-1.9.0 lib/rails_admin_state/configuration.rb
rails_admin_state-1.8.0 lib/rails_admin_state/configuration.rb
rails_admin_state-1.6.2 lib/rails_admin_state/configuration.rb
rails_admin_state-1.6.1 lib/rails_admin_state/configuration.rb
rails_admin_state-1.6.0 lib/rails_admin_state/configuration.rb
rails_admin_state-1.5.0 lib/rails_admin_state/configuration.rb