Sha256: a265877f72ba9d2f6c9a5df4b31f2b0ce6b007165469f83f3ea5a0c1f37728b2

Contents?: true

Size: 1.39 KB

Versions: 9

Compression:

Stored size: 1.39 KB

Contents

module RailsAdminAasm
  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

9 entries across 9 versions & 1 rubygems

Version Path
rails_admin_aasm-0.3.0 lib/rails_admin_aasm/configuration.rb
rails_admin_aasm-0.2.2 lib/rails_admin_aasm/configuration.rb
rails_admin_aasm-0.2.1 lib/rails_admin_aasm/configuration.rb
rails_admin_aasm-0.2.0 lib/rails_admin_aasm/configuration.rb
rails_admin_aasm-0.1.1 lib/rails_admin_aasm/configuration.rb
rails_admin_aasm-0.1.0 lib/rails_admin_aasm/configuration.rb
rails_admin_aasm-0.0.6 lib/rails_admin_aasm/configuration.rb
rails_admin_aasm-0.0.5 lib/rails_admin_aasm/configuration.rb
rails_admin_aasm-0.0.4 lib/rails_admin_aasm/configuration.rb