summaryrefslogtreecommitdiff
path: root/app/controllers/whitelists_controller.rb
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:05:14 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2012-12-17 12:05:14 +0100
commiteaad37485fe59d0306c37cc038dda6d210052910 (patch)
tree072c4b0e33d442528555b82c415f5e7a1712b2b0 /app/controllers/whitelists_controller.rb
parent3e706c2025ecc5523e81ad649639ef2ff75e7bac (diff)
parentb80bd744ad873f6fc43018bc4bfb90677de167bd (diff)
Merge branch 'develop'
Diffstat (limited to 'app/controllers/whitelists_controller.rb')
-rw-r--r--app/controllers/whitelists_controller.rb61
1 files changed, 61 insertions, 0 deletions
diff --git a/app/controllers/whitelists_controller.rb b/app/controllers/whitelists_controller.rb
new file mode 100644
index 0000000..0526844
--- /dev/null
+++ b/app/controllers/whitelists_controller.rb
@@ -0,0 +1,61 @@
+class WhitelistsController < ApplicationController
+ load_and_authorize_resource :callthrough
+ load_and_authorize_resource :whitelist, :through => [:callthrough]
+
+ before_filter :set_parent_and_path_methods
+ before_filter :spread_breadcrumbs
+
+ def index
+ end
+
+ def show
+ end
+
+ def new
+ @whitelist.phone_numbers.build
+ end
+
+ def create
+ @whitelist = @parent.whitelists.build(params[:whitelist])
+ if @whitelist.save
+ redirect_to @show_path_method.(@parent, @whitelist), :notice => t('whitelists.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @whitelist.update_attributes(params[:whitelist])
+ redirect_to @show_path_method.(@parent, @whitelist), :notice => t('whitelists.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @whitelist.destroy
+ redirect_to @index_path_method.(@parent), :notice => t('whitelists.controller.successfuly_destroyed')
+ end
+
+ private
+
+ def set_parent_and_path_methods
+ @parent = @callthrough
+ @show_path_method = method( :"#{@parent.class.name.underscore}_whitelist_path" )
+ @index_path_method = method( :"#{@parent.class.name.underscore}_whitelists_path" )
+ @new_path_method = method( :"new_#{@parent.class.name.underscore}_whitelist_path" )
+ @edit_path_method = method( :"edit_#{@parent.class.name.underscore}_whitelist_path" )
+ end
+
+ def spread_breadcrumbs
+ if @parent && @parent.class == Callthrough
+ add_breadcrumb t("#{@parent.class.name.underscore.pluralize}.name").pluralize, tenant_callthroughs_path(@parent.tenant)
+ add_breadcrumb @callthrough, tenant_callthrough_path(@parent.tenant, @callthrough)
+ add_breadcrumb t("whitelists.index.page_title"), callthrough_whitelists_path(@parent)
+ end
+ end
+
+end