summaryrefslogtreecommitdiff
path: root/app/controllers/extension_modules_controller.rb
blob: 3f8fe982efdf5128e6bd3edb2b2304559286c922 (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
73
class ExtensionModulesController < ApplicationController
  load_resource :phone
  load_and_authorize_resource :extension_module, :through => [:phone]

  before_filter :spread_breadcrumbs

  def index
    @extension_modules = @phone.extension_modules.all
  end

  def show
    @extension_module = @phone.extension_modules.find(params[:id])
  end

  def new
    @extension_module = @phone.extension_modules.build()
  end

  def create
    @extension_module = @phone.extension_modules.build(params[:extension_module])
    if @extension_module.save
      redirect_to phone_extension_module_path(@phone, @extension_module), :notice => t('extension_modules.controller.successfuly_created')
    else
      render :new
    end
  end

  def edit
    @extension_module = @phone.extension_modules.find(params[:id])
  end

  def update
    @extension_module = @phone.extension_modules.find(params[:id])
    if @extension_module.update_attributes(params[:extension_module])
      redirect_to phone_extension_module_path(@phone, @extension_module), :notice  => t('extension_modules.controller.successfuly_updated')
    else
      render :edit
    end
  end

  def destroy
    @extension_module = @phone.extension_modules.find(params[:id])
    @extension_module.destroy
    redirect_to phone_extension_modules_url(@phone), :notice => t('extension_modules.controller.successfuly_destroyed')
  end

  def restart
    if @extension_module.resync
      redirect_to phone_extension_module_path(@phone, @extension_module), :notice  => t('extension_modules.controller.restart_invoked')
    else
      redirect_to phone_extension_module_path(@phone, @extension_module), :error  => t('extension_modules.controller.restart_failed')
    end
  end

  private
  def spread_breadcrumbs
    if @phone.phoneable.class == User
      add_breadcrumb t('users.index.page_title'), tenant_users_path(@phone.phoneable.current_tenant) 
      add_breadcrumb @phone.phoneable, tenant_user_path(@phone.phoneable.current_tenant, @phone.phoneable) 
      add_breadcrumb t('phones.index.page_title'), user_phones_path(@phone.phoneable) 
    elsif @phone.phoneable.class == Tenant
      add_breadcrumb t('phones.index.page_title'), tenant_phones_path(@phone.phoneable) 
    end

    add_breadcrumb @phone, method( :"#{@phone.phoneable.class.name.underscore}_phone_path" ).(@phone.phoneable, @phone)
    add_breadcrumb t("extension_modules.index.page_title"), phone_extension_modules_path(@phone)

    if @extension_module && !@extension_module.new_record?
      add_breadcrumb @extension_module
    end

  end
end