Class: Crm::Scheduler::BookingPagesController

Inherits:
CrmController
  • Object
show all
Defined in:
app/controllers/crm/scheduler/booking_pages_controller.rb

Overview

CRUD for SchedulerBookingPage records, including host-assignment sync.

Instance Method Summary collapse

Instance Method Details

#createvoid

This method returns an undefined value.

Creates the booking page and syncs its hosts.



46
47
48
49
50
51
52
53
54
55
# File 'app/controllers/crm/scheduler/booking_pages_controller.rb', line 46

def create
  @booking_page = SchedulerBookingPage.new(booking_page_params)

  if @booking_page.save
    sync_hosts(@booking_page)
    redirect_to scheduler_admin_booking_page_path(@booking_page), notice: 'Booking page created.'
  else
    render :new, status: :unprocessable_content
  end
end

#destroyvoid

This method returns an undefined value.

Deletes the booking page loaded by #find_booking_page.



73
74
75
76
# File 'app/controllers/crm/scheduler/booking_pages_controller.rb', line 73

def destroy
  @booking_page.destroy
  redirect_to scheduler_admin_booking_pages_path, notice: 'Booking page deleted.'
end

#editvoid

This method returns an undefined value.

Loads the booking page to edit via #find_booking_page.



41
# File 'app/controllers/crm/scheduler/booking_pages_controller.rb', line 41

def edit; end

#indexvoid

This method returns an undefined value.

Lists booking pages with their hosts preloaded.



10
11
12
13
14
# File 'app/controllers/crm/scheduler/booking_pages_controller.rb', line 10

def index
  @booking_pages = SchedulerBookingPage
                   .includes(scheduler_hosts: { employee: :scheduler_profile })
                   .order(:name)
end

#newvoid

This method returns an undefined value.

Builds a new booking page.



34
35
36
# File 'app/controllers/crm/scheduler/booking_pages_controller.rb', line 34

def new
  @booking_page = SchedulerBookingPage.new
end

#showvoid

This method returns an undefined value.

Shows the booking page loaded by #find_booking_page: hosts,
questions, and its 20 most recent bookings.



20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/crm/scheduler/booking_pages_controller.rb', line 20

def show
  @hosts = @booking_page.scheduler_hosts
                        .includes(employee: %i[employee_record scheduler_profile])
                        .order(:priority)
  @questions = @booking_page.scheduler_booking_questions.ordered
  @bookings = @booking_page.scheduler_bookings
                           .includes(:employee)
                           .order(starts_at: :desc)
                           .limit(20)
end

#toggle_activevoid

This method returns an undefined value.

Flips the booking page's active flag.



81
82
83
84
# File 'app/controllers/crm/scheduler/booking_pages_controller.rb', line 81

def toggle_active
  @booking_page.update!(active: !@booking_page.active)
  redirect_to scheduler_admin_booking_pages_path, notice: "#{@booking_page.name} is now #{@booking_page.active? ? 'active' : 'inactive'}."
end

#updatevoid

This method returns an undefined value.

Updates the booking page loaded by #find_booking_page and syncs its
hosts.



61
62
63
64
65
66
67
68
# File 'app/controllers/crm/scheduler/booking_pages_controller.rb', line 61

def update
  if @booking_page.update(booking_page_params)
    sync_hosts(@booking_page)
    redirect_to scheduler_admin_booking_page_path(@booking_page), notice: 'Booking page updated.'
  else
    render :edit, status: :unprocessable_content
  end
end