From b80bd744ad873f6fc43018bc4bfb90677de167bd Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Mon, 17 Dec 2012 12:01:45 +0100 Subject: Start of GS5. --- app/controllers/whitelists_controller.rb | 61 ++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 app/controllers/whitelists_controller.rb (limited to 'app/controllers/whitelists_controller.rb') 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 -- cgit v1.2.3