Module: SpreeCmCommissioner::Admin::ServiceCalendarsHelper

Defined in:
app/helpers/spree_cm_commissioner/admin/service_calendars_helper.rb

Instance Method Summary collapse

Instance Method Details

#toggle_status_btn(resource) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/helpers/spree_cm_commissioner/admin/service_calendars_helper.rb', line 4

def toggle_status_btn(resource)
  label = resource.active ? 'Active' : 'Disabled'
  btn_active_class = resource.active ? 'btn-primary' : 'btn-warning'

  # Determine the correct URL based on the calendarable type
  url = if resource.calendarable_type == 'Spree::Product'
          update_status_admin_product_product_service_calendar_path(resource.calendarable, resource)
        else
          update_status_admin_vendor_vendor_service_calendar_url(resource.calendarable, resource)
        end

  button_to(
    label,
    url,
    form: { data: { confirm: 'Are you sure?' }, class: "btn btn-sm btn-active #{btn_active_class}" },
    method: :patch
  )
end