summaryrefslogtreecommitdiff
path: root/app/controllers/whitelists_controller.rb
diff options
context:
space:
mode:
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