summaryrefslogtreecommitdiff
path: root/app/controllers/switchboards_controller.rb
blob: 03fd73ec64aae6f1b0fb9c0ba49c846c88b4b1d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
class SwitchboardsController < ApplicationController
  load_and_authorize_resource :user
  authorize_resource :switchboard, :through => :user

  def index
    @switchboards = @user.switchboards
    spread_breadcrumbs
  end

  def show
    @switchboard = @user.switchboards.find(params[:id])
    @switchboard_entries = @switchboard.switchboard_entries
    spread_breadcrumbs
  end

  def new
    @switchboard = @user.switchboards.build
    @switchboard.show_avatars = true
    @switchboard.entry_width = 2
    @switchboard.reload_interval = 2000
    @switchboard.amount_of_displayed_phone_numbers = 1
    @switchboard.blind_transfer_activated = true
    @switchboard.attended_transfer_activated = false
    spread_breadcrumbs
  end

  def create
    @switchboard = @user.switchboards.build(switchboard_params)
    spread_breadcrumbs
    if @switchboard.save
      redirect_to user_switchboards_path(@user), :notice => t('switchboards.controller.successfuly_created')
    else
      render :new
    end
  end

  def edit
    @switchboard = @user.switchboards.find(params[:id])
    spread_breadcrumbs
  end

  def update
    @switchboard = @user.switchboards.find(params[:id])
    spread_breadcrumbs
    if @switchboard.update_attributes(switchboard_params)
      redirect_to [@user, @switchboard], :notice  => t('switchboards.controller.successfuly_updated')
    else
      render :edit
    end
  end

  def destroy
    @switchboard = @user.switchboards.find(params[:id])
    @switchboard.destroy
    spread_breadcrumbs
    redirect_to user_switchboards_path(@user), :notice => t('switchboards.controller.successfuly_destroyed')
  end

  private
  def switchboard_params
    params.require(:switchboard).permit(:name, :reload_interval, :show_avatars, :entry_width, :amount_of_displayed_phone_numbers, :blind_transfer_activated, :attended_transfer_activated, :search_activated)
  end

  def spread_breadcrumbs
    add_breadcrumb t("users.index.page_title"), tenant_users_path(@user.current_tenant)
    add_breadcrumb @user, tenant_user_path(@user.current_tenant, @user)
    add_breadcrumb t("switchboards.index.page_title"), user_switchboards_path(@user)
    if @switchboard && !@switchboard.new_record?
      add_breadcrumb @switchboard, user_switchboard_path(@user, @switchboard)
    end
  end  
end