diff options
author | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-02-16 11:10:02 +0100 |
---|---|---|
committer | Stefan Wintermeyer <stefan.wintermeyer@amooma.de> | 2013-02-16 11:10:02 +0100 |
commit | 5d8ce5f4775ac8bc5f523964e6e36f63ff3c4683 (patch) | |
tree | 49ed889b1d10cda98c475f3453abff1b97afb4e7 /app/controllers/sim_cards_controller.rb | |
parent | c9066760fd1f5f2f892ce2be5cf2a83bb5210246 (diff) | |
parent | 55784bcffc0678ce6102c0b81447434a8030ebd2 (diff) |
Merge branch 'develop'5.1-beta5
Diffstat (limited to 'app/controllers/sim_cards_controller.rb')
-rw-r--r-- | app/controllers/sim_cards_controller.rb | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/app/controllers/sim_cards_controller.rb b/app/controllers/sim_cards_controller.rb new file mode 100644 index 0000000..ed46843 --- /dev/null +++ b/app/controllers/sim_cards_controller.rb @@ -0,0 +1,57 @@ +class SimCardsController < ApplicationController + load_and_authorize_resource :sim_card_provider + load_and_authorize_resource :sim_card, :through => [:sim_card_provider] + + before_filter :set_parent + before_filter :spread_breadcrumbs + + def index + end + + def show + end + + def new + @sim_card = @sim_card_provider.sim_cards.build + + @with_phones_connected_sip_account_ids = SipAccount.where(:id => PhoneSipAccount.pluck(:sip_account_id)).pluck(:id) + @with_sim_cards_connected_sip_account_ids = SimCard.pluck(:sip_account_id) + @available_sip_account_ids = SipAccount.pluck(:id) - (@with_phones_connected_sip_account_ids + @with_sim_cards_connected_sip_account_ids) + + @available_sip_accounts = SipAccount.where(:id => @available_sip_account_ids) + + if @available_sip_accounts.count == 0 + redirect_to sim_card_provider_sim_cards_path(@sim_card_provider), :alert => t('sim_cards.controller.no_existing_sip_accounts_warning') + end + + end + + def create + @sim_card = @sim_card_provider.sim_cards.build(params[:sim_card]) + if @sim_card.save + redirect_to [@sim_card_provider, @sim_card], :notice => t('sim_cards.controller.successfuly_created') + else + render :new + end + end + + def destroy + @sim_card.destroy + redirect_to sim_card_provider_sim_cards_url(@sim_card_provider), :notice => t('sim_cards.controller.successfuly_destroyed') + end + + private + def set_parent + @parent = @sim_card_provider + end + + def spread_breadcrumbs + add_breadcrumb t("sim_card_providers.index.page_title"), sim_card_providers_path + add_breadcrumb @sim_card_provider, sim_card_provider_path(@sim_card_provider) + add_breadcrumb t("sim_cards.index.page_title"), sim_card_provider_sim_cards_path(@sim_card_provider) + if @sim_card && !@sim_card.new_record? + add_breadcrumb @sim_card, sim_card_provider_sim_card_path(@sim_card_provider, @sim_card) + end + end + +end |