Sha256: cda1416636639ac379ca370d87817fe166ab8aa2401e0f21ef6f1e686efcfcc1

Contents?: true

Size: 1.24 KB

Versions: 5

Compression:

Stored size: 1.24 KB

Contents

module Admin
  class EffectiveEventProductsDatatable < Effective::Datatable
    filters do
      scope :unarchived, label: "All"
      scope :archived
    end

    datatable do
      reorder :position

      col :updated_at, visible: false
      col :created_at, visible: false
      col :id, visible: false

      col :event

      col :title
      col :price, as: :price

      col :capacity_to_s, label: 'Capacity' do |ticket|
        if ticket.capacity.present?
          "#{ticket.capacity_available} remaining / #{ticket.capacity} total"
        end
      end

      col :purchased_event_addons_count, label: 'Purchased'
      col :capacity, visible: false
      col :capacity_available, visible: false

      col :purchased_event_addons, label: 'Name' do |product|
        product.purchased_event_addons.reject(&:archived?).sort_by(&:to_s).map do |purchase|
          content_tag(:div, purchase.owner.to_s, class: 'col-resource_item')
        end.join.html_safe
      end

      actions_col
    end

    collection do
      scope = Effective::EventProduct.deep.all

      if attributes[:event_id]
        scope = scope.where(event: event)
      end

      scope
    end

    def event
      Effective::Event.find_by_id(attributes[:event_id])
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
effective_events-0.9.2 app/datatables/admin/effective_event_products_datatable.rb
effective_events-0.9.1 app/datatables/admin/effective_event_products_datatable.rb
effective_events-0.9.0 app/datatables/admin/effective_event_products_datatable.rb
effective_events-0.8.0 app/datatables/admin/effective_event_products_datatable.rb
effective_events-0.7.4 app/datatables/admin/effective_event_products_datatable.rb