summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Kozak <spag@golwen.net>2013-02-25 11:41:55 -0500
committerPeter Kozak <spag@golwen.net>2013-02-25 11:41:55 -0500
commitfd07b7b85d2d40d7d2999c2899cc890eda2095fd (patch)
treebf4fbb797d4b645fbe4752a253297a09de466953
parent0442cd19bc9383669b506185356227361a16e442 (diff)
more polymorphic objects
-rw-r--r--app/controllers/call_forwards_controller.rb14
-rw-r--r--app/controllers/ringtones_controller.rb11
-rw-r--r--app/models/call_forward.rb3
-rw-r--r--app/models/ringtone.rb14
-rw-r--r--app/models/sip_account.rb2
-rw-r--r--app/views/call_forwards/_form_core.html.haml6
-rw-r--r--app/views/call_forwards/_index_core.html.haml10
-rw-r--r--app/views/call_forwards/show.html.haml8
-rw-r--r--app/views/ringtones/_form_core.html.haml2
-rw-r--r--app/views/ringtones/_index_core.html.haml4
-rw-r--r--app/views/ringtones/index.html.haml4
-rw-r--r--app/views/sip_accounts/show.html.haml7
-rw-r--r--app/views/users/show.html.haml2
-rw-r--r--config/routes.rb1
14 files changed, 48 insertions, 40 deletions
diff --git a/app/controllers/call_forwards_controller.rb b/app/controllers/call_forwards_controller.rb
index cd72a38..34fb77a 100644
--- a/app/controllers/call_forwards_controller.rb
+++ b/app/controllers/call_forwards_controller.rb
@@ -48,8 +48,8 @@ class CallForwardsController < ApplicationController
@call_forward = @parent.call_forwards.build( params[:call_forward] )
if @call_forward.save
- m = method( :"#{@parent.class.name.underscore}_call_forward_path" )
- redirect_to m.( @parent, @call_forward ), :notice => t('call_forwards.controller.successfuly_created')
+ m = method( :"#{@parent.class.name.underscore}_call_forwards_url" )
+ redirect_to m.( @parent ), :notice => t('call_forwards.controller.successfuly_created')
else
@available_call_forward_cases = CallForwardCase.all
render :new
@@ -64,8 +64,8 @@ class CallForwardsController < ApplicationController
def update
@available_call_forward_cases = CallForwardCase.all
if @call_forward.update_attributes(params[:call_forward])
- m = method( :"#{@parent.class.name.underscore}_call_forward_path" )
- redirect_to m.( @parent, @call_forward ), :notice => t('call_forwards.controller.successfuly_updated')
+ m = method( :"#{@parent.class.name.underscore}_call_forwards_url" )
+ redirect_to m.( @parent ), :notice => t('call_forwards.controller.successfuly_updated')
else
@call_forwarding_destinations = call_forwarding_destination_types()
render :edit
@@ -74,7 +74,8 @@ class CallForwardsController < ApplicationController
def destroy
@call_forward.destroy
- redirect_to :root, :notice => t('call_forwards.controller.successfuly_destroyed')
+ m = method( :"#{@parent.class.name.underscore}_call_forwards_url" )
+ redirect_to m.( @parent ), :notice => t('call_forwards.controller.successfuly_destroyed')
end
private
@@ -110,7 +111,8 @@ class CallForwardsController < ApplicationController
add_breadcrumb @sip_account, tenant_sip_account_path(@tenant, @sip_account)
end
- add_breadcrumb t("call_forwards.index.page_title"), phone_number_call_forwards_path(@parent)
+ m = method( :"#{@parent.class.name.underscore}_call_forwards_url" )
+ add_breadcrumb t("call_forwards.index.page_title"), m.(@parent)
if @call_forward && !@call_forward.new_record?
m = method( :"#{@parent.class.name.underscore}_call_forward_path" )
add_breadcrumb @call_forward, m.(@parent, @call_forward)
diff --git a/app/controllers/ringtones_controller.rb b/app/controllers/ringtones_controller.rb
index 7ffe30e..f726650 100644
--- a/app/controllers/ringtones_controller.rb
+++ b/app/controllers/ringtones_controller.rb
@@ -1,7 +1,8 @@
class RingtonesController < ApplicationController
load_resource :phone_number
+ load_resource :sip_account
load_resource :boss_assistant_cooperation
- load_and_authorize_resource :ringtone, :through => [:phone_number, :boss_assistant_cooperation]
+ load_and_authorize_resource :ringtone, :through => [:phone_number, :sip_account, :boss_assistant_cooperation]
before_filter :set_parent
before_filter :spread_breadcrumbs
@@ -19,7 +20,7 @@ class RingtonesController < ApplicationController
def create
@ringtone = @parent.ringtones.build(params[:ringtone])
if @ringtone.save
- redirect_to phone_number_ringtone_path(@parent, @ringtone), :notice => t('ringtones.controller.successfuly_created')
+ redirect_to method( :"#{@parent.class.name.underscore}_ringtones_url" ).(@parent), :notice => t('ringtones.controller.successfuly_created')
else
render :new
end
@@ -30,7 +31,7 @@ class RingtonesController < ApplicationController
def update
if @ringtone.update_attributes(params[:ringtone])
- redirect_to method( :"#{@parent.class.name.underscore}_ringtone_path" ).(@ringtone.ringtoneable, @ringtone), :notice => t('ringtones.controller.successfuly_updated')
+ redirect_to method( :"#{@parent.class.name.underscore}_ringtones_url" ).(@parent), :notice => t('ringtones.controller.successfuly_updated')
else
render :edit
end
@@ -38,12 +39,12 @@ class RingtonesController < ApplicationController
def destroy
@ringtone.destroy
- redirect_to phone_number_ringtones_path(@parent), :notice => t('ringtones.controller.successfuly_destroyed')
+ redirect_to method( :"#{@parent.class.name.underscore}_ringtones_url" ).(@parent), :notice => t('ringtones.controller.successfuly_destroyed')
end
private
def set_parent
- @parent = @phone_number || @boss_assistant_cooperation
+ @parent = @phone_number || @boss_assistant_cooperation || @sip_account
end
def spread_breadcrumbs
diff --git a/app/models/call_forward.rb b/app/models/call_forward.rb
index b304439..a932e11 100644
--- a/app/models/call_forward.rb
+++ b/app/models/call_forward.rb
@@ -24,8 +24,8 @@ class CallForward < ActiveRecord::Base
belongs_to :call_forward_case
- validates_presence_of :depth
validates_numericality_of :depth,
+ :allow_nil => true,
:only_integer => true,
:greater_than_or_equal_to => 1,
:less_than_or_equal_to => (GsParameter.get('MAX_CALL_FORWARD_DEPTH').nil? ? 0 : GsParameter.get('MAX_CALL_FORWARD_DEPTH'))
@@ -59,7 +59,6 @@ class CallForward < ActiveRecord::Base
before_save :split_and_format_destination_numbers
after_save :set_presence
after_save :deactivate_concurring_entries, :if => Proc.new { |cf| cf.active == true }
- before_destroy :check_if_other_callforward_rules_have_to_be_destroyed
before_destroy :deactivate_connected_softkeys
def case_string
diff --git a/app/models/ringtone.rb b/app/models/ringtone.rb
index 36053c0..45ecd93 100644
--- a/app/models/ringtone.rb
+++ b/app/models/ringtone.rb
@@ -1,11 +1,25 @@
class Ringtone < ActiveRecord::Base
attr_accessible :audio, :bellcore_id
+ CORE_RINGTONES_AVAILABLE = {
+ 'Silence' => 0,
+ 'Ringtone 1' => 1,
+ 'Ringtone 2' => 2,
+ 'Ringtone 3' => 3,
+ 'Ringtone 4' => 4,
+ 'Ringtone 5' => 5,
+ 'Ringtone 6' => 6,
+ 'Ringtone 7' => 7,
+ 'Ringtone 8' => 8,
+ 'Ringtone 9' => 9,
+ 'Ringtone 10' => 10,
+ }
mount_uploader :audio, AudioUploader
validates_presence_of :audio, :if => Proc.new{ |ringtone| ringtone.bellcore_id.blank? }
validates_presence_of :ringtoneable_type
validates_presence_of :ringtoneable_id
validates_presence_of :ringtoneable
+ validates_uniqueness_of :ringtoneable_id, :scope => [:ringtoneable_type]
belongs_to :ringtoneable, :polymorphic => true
diff --git a/app/models/sip_account.rb b/app/models/sip_account.rb
index a39982b..034af7c 100644
--- a/app/models/sip_account.rb
+++ b/app/models/sip_account.rb
@@ -36,6 +36,8 @@ class SipAccount < ActiveRecord::Base
has_many :group_memberships, :as => :item, :dependent => :destroy, :uniq => true
has_many :groups, :through => :group_memberships
+ has_many :ringtones, :as => :ringtoneable, :dependent => :destroy
+
# Delegations:
#
delegate :host, :to => :sip_domain, :allow_nil => true
diff --git a/app/views/call_forwards/_form_core.html.haml b/app/views/call_forwards/_form_core.html.haml
index b751fb3..83de044 100644
--- a/app/views/call_forwards/_form_core.html.haml
+++ b/app/views/call_forwards/_form_core.html.haml
@@ -1,5 +1,5 @@
.inputs
- = f.input :call_forward_case_id, :as => :select, :collection => @available_call_forward_cases.map {|x| [I18n.t("call_forward_cases.#{x.value}"), x.id] }, :label => t('call_forwards.form.call_forward_case_id.label'), :hint => conditional_hint('call_forwards.form.call_forward_case_id.hint'), :include_blank => false, :autofocus => true
+ = f.input :call_forward_case_id, :as => :select, :collection => @available_call_forward_cases.map {|x| [I18n.t("call_forward_cases.#{x.value}"), x.id] }, :label => t('call_forwards.form.call_forward_case.label'), :hint => conditional_hint('call_forwards.form.call_forward_case_id.hint'), :include_blank => false, :autofocus => true
= f.input :timeout, :label => t('call_forwards.form.timeout.label'), :hint => conditional_hint('call_forwards.form.timeout.hint')
= f.input :call_forwarding_destination , :as => :select, :collection => @call_forwarding_destinations, :label => t('call_forwards.form.call_forwarding_destination.label'), :hint => conditional_hint('call_forwards.form.call_forwarding_destination.hint'), :include_blank => false
@@ -8,8 +8,4 @@
= f.input :source, :label => t('call_forwards.form.source.label'), :hint => conditional_hint('call_forwards.form.source.hint')
- - if GuiFunction.display?('depth_field_in_call_forward_form', current_user)
- = f.input :depth, :collection => 1..GsParameter.get('MAX_CALL_FORWARD_DEPTH'), :label => t('call_forwards.form.depth.label'), :hint => conditional_hint('call_forwards.form.depth.hint')
- - else
- = f.hidden_field :depth
= f.input :active, :label => t('call_forwards.form.active.label'), :hint => conditional_hint('call_forwards.form.active.hint')
diff --git a/app/views/call_forwards/_index_core.html.haml b/app/views/call_forwards/_index_core.html.haml
index 48afa54..221baf2 100644
--- a/app/views/call_forwards/_index_core.html.haml
+++ b/app/views/call_forwards/_index_core.html.haml
@@ -1,21 +1,15 @@
%table.table.table-striped
%thead
%tr
- - if !@phone_number
- %th= t('call_forwards.index.call_forwardable')
- %th= t('call_forwards.index.call_forward_case_id')
+ %th= t('call_forwards.index.call_forward_case')
%th= t('call_forwards.index.timeout')
%th= t('call_forwards.index.destination')
%th= t('call_forwards.index.source')
- - if GuiFunction.display?('depth_field_value_in_index_table', current_user)
- %th= t('call_forwards.index.depth')
%th= t('call_forwards.index.active')
%tbody
- for call_forward in call_forwards
%tr
- - if !@phone_number
- %td= call_forward.call_forwardable
%td= t("call_forward_cases.#{call_forward.call_forward_case.value}")
%td= call_forward.timeout
%td
@@ -26,7 +20,5 @@
- if call_forward.destinationable_id
= ": #{call_forward.destinationable}"
%td= call_forward.source
- - if GuiFunction.display?('depth_field_value_in_index_table', current_user)
- %td= call_forward.depth
%td= call_forward.active
=render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => call_forward.call_forwardable, :child => call_forward} \ No newline at end of file
diff --git a/app/views/call_forwards/show.html.haml b/app/views/call_forwards/show.html.haml
index 9f9d27a..ad9ab16 100644
--- a/app/views/call_forwards/show.html.haml
+++ b/app/views/call_forwards/show.html.haml
@@ -1,9 +1,6 @@
- content_for :title, t("call_forwards.show.page_title")
%p
- %strong= t('call_forwards.show.call_forwardable') + ":"
- = "#{@call_forward.call_forwardable_type}: #{@call_forward.call_forwardable}"
-%p
%strong= t('call_forwards.show.call_forward_case') + ":"
= t("call_forward_cases.#{@call_forward.call_forward_case.value}")
%p
@@ -22,10 +19,7 @@
%strong= t('call_forwards.show.source') + ":"
= @call_forward.source
%p
- %strong= t('call_forwards.show.depth') + ":"
- = @call_forward.depth
-%p
%strong= t('call_forwards.show.active') + ":"
= @call_forward.active
-= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @parent, :child => @call_forward } \ No newline at end of file
+= render :partial => 'shared/show_edit_destroy_part', :locals => { :parent => @parent, :child => @call_forward }
diff --git a/app/views/ringtones/_form_core.html.haml b/app/views/ringtones/_form_core.html.haml
index e44c950..de1cc38 100644
--- a/app/views/ringtones/_form_core.html.haml
+++ b/app/views/ringtones/_form_core.html.haml
@@ -1,3 +1,3 @@
.inputs
/ = f.input :audio, :label => t('ringtones.form.audio.label'), :hint => conditional_hint('ringtones.form.audio.hint')
- = f.input :bellcore_id, :collection => 0..10, :label => t('ringtones.form.bellcore_id.label'), :hint => conditional_hint('ringtones.form.bellcore_id.hint'), :include_blank => true
+ = f.input :bellcore_id, :collection => Ringtone::CORE_RINGTONES_AVAILABLE, :label => t('ringtones.form.bellcore_id.label'), :hint => conditional_hint('ringtones.form.bellcore_id.hint'), :include_blank => false
diff --git a/app/views/ringtones/_index_core.html.haml b/app/views/ringtones/_index_core.html.haml
index 715db3c..51347a5 100644
--- a/app/views/ringtones/_index_core.html.haml
+++ b/app/views/ringtones/_index_core.html.haml
@@ -1,12 +1,12 @@
%table.table.table-striped
%thead
%tr
- %th= t('ringtones.index.audio')
+ /%th= t('ringtones.index.audio')
%th= t('ringtones.index.bellcore_id')
%tbody
- for ringtone in ringtones
%tr
- %td= ringtone.audio
+ /%td= ringtone.audio
%td= ringtone.bellcore_id
=render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => ringtone.ringtoneable, :child => ringtone} \ No newline at end of file
diff --git a/app/views/ringtones/index.html.haml b/app/views/ringtones/index.html.haml
index 2eea5fe..2e316a5 100644
--- a/app/views/ringtones/index.html.haml
+++ b/app/views/ringtones/index.html.haml
@@ -2,5 +2,5 @@
- if @ringtones.count > 0
= render "index_core", :ringtones => @ringtones
-
-= render :partial => 'shared/create_link', :locals => {:parent => @parent, :child_class => Ringtone} \ No newline at end of file
+- else
+ = render :partial => 'shared/create_link', :locals => {:parent => @parent, :child_class => Ringtone} \ No newline at end of file
diff --git a/app/views/sip_accounts/show.html.haml b/app/views/sip_accounts/show.html.haml
index 72e10df..0a332af 100644
--- a/app/views/sip_accounts/show.html.haml
+++ b/app/views/sip_accounts/show.html.haml
@@ -72,6 +72,13 @@
%br
= render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => PhoneNumber }
+- if @sip_account.call_forwards.count > 0 || can?(:create, @sip_account.call_forwards.build)
+ %h2= t('call_forwards.index.page_title')
+ - if @sip_account.call_forwards.count > 0
+ = render "call_forwards/index_core", :call_forwards => @sip_account.call_forwards
+ %br
+ = render :partial => 'shared/create_link', :locals => { :parent => @sip_account, :child_class => CallForward }
+
- if @sip_account.softkeys.count > 0 || can?(:create, @sip_account.softkeys.build)
%h2= t("softkeys.index.page_title")
- if @sip_account.softkeys.count > 0
diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml
index 0f6cc2c..8882c08 100644
--- a/app/views/users/show.html.haml
+++ b/app/views/users/show.html.haml
@@ -38,7 +38,7 @@
%br
=link_to t("voicemail_messages.index.page_title"), sip_account_voicemail_messages_path(sip_account)
%br
- =link_to t("call_forwards.index.page_title"), phone_number_call_forwards_path(phone_number)
+ =link_to t("call_forwards.index.page_title"), sip_account_call_forwards_path(sip_account)
%br
=link_to t("voicemail_settings.index.page_title"), sip_account_voicemail_settings_path(sip_account)
%br
diff --git a/config/routes.rb b/config/routes.rb
index 03fd4cf..b6943ab 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -254,6 +254,7 @@ Gemeinschaft42c::Application.routes.draw do
resources :phone_numbers
resources :softkeys
resources :call_forwards
+ resources :ringtones
resources :call_histories do
collection do
delete 'destroy_multiple'