From db9dbf03d88cfbd68ce99a242730b9e870339539 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Thu, 7 Mar 2013 13:15:35 +0100 Subject: Added Switchboard scaffold. --- app/controllers/switchboards_controller.rb | 65 ++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 app/controllers/switchboards_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/switchboards_controller.rb b/app/controllers/switchboards_controller.rb new file mode 100644 index 0000000..8f21d5e --- /dev/null +++ b/app/controllers/switchboards_controller.rb @@ -0,0 +1,65 @@ +class SwitchboardsController < ApplicationController + load_and_authorize_resource :user + authorize_resource :switchboard, :through => :user + + def index + @switchboards = @user.switchboards + spread_breadcrumbs + end + + def show + @switchboard = @user.switchboards.find(params[:id]) + spread_breadcrumbs + end + + def new + @switchboard = @user.switchboards.build + spread_breadcrumbs + end + + def create + @switchboard = @user.switchboards.build(switchboard_params) + spread_breadcrumbs + if @switchboard.save + redirect_to user_switchboards_path(@user), :notice => t('switchboards.controller.successfuly_created') + else + render :new + end + end + + def edit + @switchboard = @user.switchboards.find(params[:id]) + spread_breadcrumbs + end + + def update + @switchboard = @user.switchboards.find(params[:id]) + spread_breadcrumbs + if @switchboard.update_attributes(switchboard_params) + redirect_to [@user, @switchboard], :notice => t('switchboards.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @switchboard = @user.switchboards.find(params[:id]) + @switchboard.destroy + spread_breadcrumbs + redirect_to user_switchboards_path(@user), :notice => t('switchboards.controller.successfuly_destroyed') + end + + private + def switchboard_params + params.require(:switchboard).permit(:name) + end + + def spread_breadcrumbs + 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("switchboards.index.page_title"), user_switchboards_path(@user) + if @switchboard && !@switchboard.new_record? + add_breadcrumb @switchboard, user_switchboard_path(@user, @switchboard) + end + end +end -- cgit v1.2.3 From 6374c0b3e38dfc74eb1b4a5a1fcc5229eacdcaf2 Mon Sep 17 00:00:00 2001 From: Stefan Wintermeyer Date: Fri, 8 Mar 2013 12:09:17 +0100 Subject: Added SwitchboardEntry scaffold. switchboard has_many switchboard_entries --- app/controllers/switchboard_entries_controller.rb | 74 +++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 app/controllers/switchboard_entries_controller.rb (limited to 'app/controllers') diff --git a/app/controllers/switchboard_entries_controller.rb b/app/controllers/switchboard_entries_controller.rb new file mode 100644 index 0000000..ef6c72e --- /dev/null +++ b/app/controllers/switchboard_entries_controller.rb @@ -0,0 +1,74 @@ +class SwitchboardEntriesController < ApplicationController + load_and_authorize_resource :switchboard + authorize_resource :switchboard_entry, :through => :switchboard, :except => [:sort] + + def index + @switchboard_entries = @switchboard.switchboard_entries + spread_breadcrumbs + end + + def show + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + spread_breadcrumbs + end + + def new + @switchboard_entry = @switchboard.switchboard_entries.build + @sip_accounts = SipAccount.all - @switchboard.sip_accounts + spread_breadcrumbs + end + + def create + @switchboard_entry = @switchboard.switchboard_entries.build(switchboard_entry_params) + spread_breadcrumbs + if @switchboard_entry.save + redirect_to switchboard_switchboard_entries_path(@switchboard), :notice => t('switchboard_entries.controller.successfuly_created') + else + render :new + end + end + + def edit + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + @sip_accounts = SipAccount.all - @switchboard.sip_accounts + [@switchboard_entry.sip_account] + spread_breadcrumbs + end + + def update + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + if @switchboard_entry.update_attributes(switchboard_entry_params) + redirect_to [@switchboard, @switchboard_entry], :notice => t('switchboard_entries.controller.successfuly_updated') + else + render :edit + end + end + + def destroy + @switchboard_entry = @switchboard.switchboard_entries.find(params[:id]) + @switchboard_entry.destroy + redirect_to switchboard_switchboard_entries_path(@switchboard), :notice => t('switchboard_entries.controller.successfuly_destroyed') + end + + def sort + params[:switchboard_entry].reverse.each do |id| + @switchboard.switchboard_entries.find(id).move_to_top + end + render nothing: true + end + + private + def switchboard_entry_params + params.require(:switchboard_entry).permit(:name, :sip_account_id) + end + + def spread_breadcrumbs + add_breadcrumb t("users.index.page_title"), tenant_users_path(@switchboard.user.current_tenant) + add_breadcrumb @switchboard.user, tenant_user_path(@switchboard.user.current_tenant, @switchboard.user) + add_breadcrumb t("switchboards.index.page_title"), user_switchboards_path(@switchboard.user) + add_breadcrumb @switchboard, user_switchboard_path(@switchboard.user, @switchboard) + add_breadcrumb t("switchboard_entries.index.page_title"), switchboard_switchboard_entries_path(@switchboard) + if @switchboard_entry && !@switchboard_entry.new_record? + add_breadcrumb @switchboard_entry, switchboard_switchboard_entries_path(@switchboard, @switchboard_entry) + end + end +end -- cgit v1.2.3