Sha256: 45ae8b1c495de53eb09741b17801ffdd139b96361ad5f20ce3844a0bff64c83f

Contents?: true

Size: 1.68 KB

Versions: 22

Compression:

Stored size: 1.68 KB

Contents

module MyAdmin
  class ModelConfiguration
    
    attr_accessor :collection, :member, :application, :list_display, :show_display, :export_display, :filters, :fieldsets, :fields, :permissions, :per_page
    
    def initialize(klass)
      begin
        @class = klass
        @application = "content"
        @permissions = [:list, :create, :update, :destroy, :export]
        if @class.table_exists?
          @list_display = (klass.columns.map{ |c| c.name } - ['id', 'created_at', 'updated_at']) #, 'created_at', 'updated_at'])
          @fieldsets = [{:fields => (klass.columns.map{ |c| c.name } - ['id', 'created_at', 'updated_at']) }] # , 'created_at', 'updated_at']) }]
          @show_display = nil #(klass.columns.map{ |c| c.name } - ['id'])
          @export_display = nil #(klass.columns.map{ |c| c.name })
          @filters = nil
        end
        @collection = []
        @member = []
        @fields = {}
        @per_page = 10
      rescue
      end
    end

    def application_url 
      # I18n.t!("my_admin.urls.applications."+@application) rescue @application
      @application
    end

    def url
      # I18n.t!("my_admin.urls.models.#{@class.model_tableize}") rescue @class.model_tableize
      @class.model_tableize
    end
    
    def url_single
      self.url.singularize
    end
    
    def can?(permission, user)
      (@permissions.member? permission.to_sym and (user.superuser or not user.permissions.to_a.find { |p| p.name == permission.to_s and p.model == @class.to_s and p.application == @application }.blank?))
    end
    
    def filters 
      @filters || @list_display
    end
    
    def export_display
      @export_display || @show_display || @list_display
    end

  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
my_admin-0.1.13 lib/my_admin/model_configuration.rb
my_admin-0.1.12 lib/my_admin/model_configuration.rb
my_admin-0.1.11 lib/my_admin/model_configuration.rb
my_admin-0.1.10 lib/my_admin/model_configuration.rb
my_admin-0.1.9 lib/my_admin/model_configuration.rb
my_admin-0.1.8 lib/my_admin/model_configuration.rb
my_admin-0.1.7 lib/my_admin/model_configuration.rb
my_admin-0.1.6 lib/my_admin/model_configuration.rb
my_admin-0.1.5 lib/my_admin/model_configuration.rb
my_admin-0.1.4 lib/my_admin/model_configuration.rb
my_admin-0.1.3 lib/my_admin/model_configuration.rb
my_admin-0.1.2 lib/my_admin/model_configuration.rb
my_admin-0.1.1 lib/my_admin/model_configuration.rb
my_admin-0.0.12 lib/my_admin/model_configuration.rb
my_admin-0.0.11 lib/my_admin/model_configuration.rb
my_admin-0.0.10 lib/my_admin/model_configuration.rb
my_admin-0.0.9 lib/my_admin/model_configuration.rb
my_admin-0.0.8 lib/my_admin/model_configuration.rb
my_admin-0.0.7 lib/my_admin/model_configuration.rb
my_admin-0.0.6 lib/my_admin/model_configuration.rb