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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
|
class PhoneNumbersController < ApplicationController
load_resource :phone_book_entry, :except => [:sort]
load_resource :sip_account, :except => [:sort]
load_resource :conference, :except => [:sort]
load_resource :fax_account, :except => [:sort]
load_resource :phone_number_range, :except => [:sort]
load_resource :callthrough, :except => [:sort]
load_resource :whitelist, :except => [:sort]
load_resource :access_authorization, :except => [:sort]
load_resource :hunt_group, :except => [:sort]
load_resource :hunt_group_member, :except => [:sort]
load_resource :automatic_call_distributor, :except => [:sort]
load_and_authorize_resource :phone_number, :except => [:sort], :through => [:phone_book_entry, :sip_account, :conference,
:fax_account, :phone_number_range, :callthrough,
:whitelist, :access_authorization, :hunt_group,
:hunt_group_member, :automatic_call_distributor]
before_filter :set_and_authorize_parent, :except => [:sort]
before_filter :spread_breadcrumbs, :except => [:sort]
def index
end
def show
@ringtoneable_classes = {
'SipAccount' => true,
'HuntGroup' => true,
'AutomaticCallDistributor' => true,
'PhoneBookEntry' => true,
}
@forwardable_classes = {
'SipAccount' => true,
'HuntGroup' => true,
'AutomaticCallDistributor' => true,
}
end
def new
@phone_number = @parent.phone_numbers.build()
end
def create
@phone_number = @parent.phone_numbers.new( params[:phone_number] )
if @phone_number.save
m = method( :"#{@parent.class.name.underscore}_phone_number_path" )
redirect_to m.( @parent, @phone_number ), :notice => t('phone_numbers.controller.successfuly_created')
else
render :new
end
end
def edit
end
def update
if @phone_number.update_attributes(params[:phone_number])
m = method( :"#{@parent.class.name.underscore}_phone_number_path" )
redirect_to m.( @parent, @phone_number ), :notice => t('phone_numbers.controller.successfuly_updated')
else
render :edit
end
end
def destroy
@phone_number.destroy
m = method( :"#{@parent.class.name.underscore}_phone_numbers_url" )
redirect_to m.(), :notice => t('phone_numbers.controller.successfuly_destroyed')
end
def call
sip_account = nil
current_user.sip_accounts.each do |user_sip_account|
if user_sip_account.registration
sip_account = user_sip_account
break
end
end
if can?(:call, @phone_number) && sip_account
if ! @phone_number.number.blank?
sip_account.call(@phone_number.number)
end
end
redirect_to(:back)
end
def sort
params[:phone_number].each_with_index do |id, index|
PhoneNumber.update_all({position: index+1}, {id: id})
end
render nothing: true
end
private
def set_and_authorize_parent
@parent = @phone_book_entry || @sip_account || @conference || @fax_account ||
@phone_number_range || @callthrough || @whitelist || @access_authorization ||
@hunt_group || @hunt_group_member || @automatic_call_distributor
authorize! :read, @parent
@show_path_method = method( :"#{@parent.class.name.underscore}_phone_number_path" )
@index_path_method = method( :"#{@parent.class.name.underscore}_phone_numbers_path" )
@new_path_method = method( :"new_#{@parent.class.name.underscore}_phone_number_path" )
@edit_path_method = method( :"edit_#{@parent.class.name.underscore}_phone_number_path" )
end
def spread_breadcrumbs
if @parent.class == Callthrough
add_breadcrumb t("#{@parent.class.name.underscore.pluralize}.index.page_title"), tenant_callthroughs_path(@parent.tenant)
add_breadcrumb @callthrough, tenant_callthrough_path(@parent.tenant, @callthrough)
add_breadcrumb t("phone_numbers.index.page_title"), callthrough_phone_numbers_path(@parent)
if @phone_number && !@phone_number.new_record?
add_breadcrumb @phone_number, callthrough_phone_number_path(@callthrough, @phone_number)
end
end
if @parent.class == SipAccount
if @sip_account.sip_accountable.class == User
add_breadcrumb t("#{@sip_account.sip_accountable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore.pluralize}_path" ).(@sip_account.tenant)
add_breadcrumb @sip_account.sip_accountable, method( :"tenant_#{@sip_account.sip_accountable.class.name.underscore}_path" ).(@sip_account.tenant, @sip_account.sip_accountable)
end
add_breadcrumb t("sip_accounts.index.page_title"), method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_accounts_path" ).(@sip_account.sip_accountable)
add_breadcrumb @sip_account, method( :"#{@sip_account.sip_accountable.class.name.underscore}_sip_account_path" ).(@sip_account.sip_accountable, @sip_account)
add_breadcrumb t("phone_numbers.index.page_title"), sip_account_phone_numbers_path(@sip_account)
if @phone_number && !@phone_number.new_record?
add_breadcrumb @phone_number, sip_account_phone_number_path(@sip_account, @phone_number)
end
end
if @parent.class == Conference
@conference = @parent
conference_parent = @conference.conferenceable
if conference_parent && conference_parent.class == User
@user = conference_parent
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("conferences.index.page_title"), user_conferences_path(@user)
add_breadcrumb @conference, user_conference_path(@user, @conference)
end
if conference_parent && conference_parent.class == Tenant
@tenant = conference_parent
add_breadcrumb t("conferences.index.page_title"), tenant_conferences_path(@tenant)
add_breadcrumb @conference, tenant_conference_path(@tenant, @conference)
end
add_breadcrumb t("phone_numbers.index.page_title"), conference_phone_numbers_path(@conference)
if @phone_number && !@phone_number.new_record?
add_breadcrumb @phone_number, conference_phone_number_path(@conference, @phone_number)
end
end
if @parent.class == HuntGroup
add_breadcrumb t("#{@parent.class.name.underscore.pluralize}.index.page_title"), tenant_hunt_groups_path(@parent.tenant)
add_breadcrumb @hunt_group, tenant_hunt_group_path(@parent.tenant, @hunt_group)
add_breadcrumb t("phone_numbers.index.page_title"), hunt_group_phone_numbers_path(@parent)
end
if @parent.class == HuntGroupMember
add_breadcrumb t("hunt_groups.index.page_title"), tenant_hunt_groups_path(@parent.hunt_group.tenant)
add_breadcrumb @parent.hunt_group, tenant_hunt_group_path(@parent.hunt_group.tenant, @parent.hunt_group)
add_breadcrumb t("hunt_group_members.index.page_title"), hunt_group_hunt_group_members_path(@parent.hunt_group)
add_breadcrumb @parent, hunt_group_hunt_group_member_path(@parent.hunt_group, @parent)
add_breadcrumb t("phone_numbers.index.page_title"), hunt_group_member_phone_numbers_path(@parent)
if @phone_number && !@phone_number.new_record?
add_breadcrumb @phone_number, hunt_group_member_phone_number_path(@parent, @phone_number)
end
end
if @parent.class == AccessAuthorization
if @parent.access_authorizationable.class == Callthrough
callthrough = @parent.access_authorizationable
tenant = callthrough.tenant
add_breadcrumb t("callthroughs.index.page_title"), tenant_callthroughs_path(tenant)
add_breadcrumb callthrough, tenant_callthrough_path(tenant, callthrough)
add_breadcrumb t("access_authorizations.index.page_title"), callthrough_access_authorizations_path(callthrough)
add_breadcrumb @parent, callthrough_access_authorization_path(callthrough, @parent)
add_breadcrumb t("phone_numbers.index.page_title"), access_authorization_phone_numbers_path(@parent)
if @phone_number && !@phone_number.new_record?
add_breadcrumb @phone_number, access_authorization_phone_number_path(@parent, @phone_number)
end
end
end
if @parent.class == PhoneBookEntry
@phone_book = @parent.phone_book
if @parent.phone_book.phone_bookable.class == Tenant
@tenant = @parent.phone_book.phone_bookable
add_breadcrumb t("phone_books.index.page_title"), tenant_phone_books_path(@tenant)
add_breadcrumb @phone_book, tenant_phone_book_path(@tenant, @phone_book)
add_breadcrumb @phone_book_entry, phone_book_phone_book_entry_path(@phone_book, @phone_book_entry)
if @phone_number && !@phone_number.new_record?
add_breadcrumb @phone_number, phone_book_entry_phone_number_path(@phone_book_entry, @phone_number)
end
end
if @parent.phone_book.phone_bookable.class == User
@user = @parent.phone_book.phone_bookable
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("phone_books.index.page_title"), user_phone_books_path(@user)
add_breadcrumb @phone_book, user_phone_book_path(@user, @phone_book)
add_breadcrumb @phone_book_entry, phone_book_phone_book_entry_path(@phone_book, @phone_book_entry)
if @phone_number && !@phone_number.new_record?
add_breadcrumb @phone_number, phone_book_entry_phone_number_path(@phone_book_entry, @phone_number)
end
end
end
if @parent.class == Whitelist
@tenant = @parent.whitelistable.tenant
@callthrough = @parent.whitelistable
@whitelist = @parent
add_breadcrumb t("callthroughs.name").pluralize, tenant_callthroughs_path(@tenant)
add_breadcrumb @callthrough, tenant_callthrough_path(@tenant, @callthrough)
add_breadcrumb t("whitelists.index.page_title"), callthrough_whitelists_path(@callthrough)
add_breadcrumb @whitelist, callthrough_whitelist_path(@callthrough, @whitelist)
add_breadcrumb t("phone_numbers.index.page_title"), whitelist_phone_numbers_path(@whitelist)
if @phone_number && !@phone_number.new_record?
add_breadcrumb @phone_number, whitelist_phone_number_path(@whitelist, @phone_number)
end
end
if @parent.class == AutomaticCallDistributor
if @automatic_call_distributor.automatic_call_distributorable.class == User
add_breadcrumb t("#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}.index.page_title"), method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore.pluralize}_path" ).(@automatic_call_distributor.tenant)
add_breadcrumb @automatic_call_distributor.automatic_call_distributorable, method( :"tenant_#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_path" ).(@automatic_call_distributor.tenant, @automatic_call_distributor.automatic_call_distributorable)
end
add_breadcrumb t("automatic_call_distributors.index.page_title"), method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributors_path" ).(@automatic_call_distributor.automatic_call_distributorable)
add_breadcrumb @automatic_call_distributor, method( :"#{@automatic_call_distributor.automatic_call_distributorable.class.name.underscore}_automatic_call_distributor_path" ).(@automatic_call_distributor.automatic_call_distributorable, @automatic_call_distributor)
add_breadcrumb t("phone_numbers.index.page_title"), automatic_call_distributor_phone_numbers_path(@automatic_call_distributor)
if @phone_number && !@phone_number.new_record?
add_breadcrumb @phone_number, automatic_call_distributor_phone_number_path(@automatic_call_distributor, @phone_number)
end
end
end
end
|