summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-15 14:49:16 +0100
committerStefan Wintermeyer <stefan.wintermeyer@amooma.de>2013-02-15 14:49:16 +0100
commit3d11d0a3a047a12bfd40b61252e269cabac76225 (patch)
treec16baf628633205b2e664f86f2e0038f3ee3b097 /app
parent124a421b19e08447fa790b65cc969dadd7408539 (diff)
Basic structure for sim_cards and sim_card_providers.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/sim_card_providers_controller.rb47
-rw-r--r--app/controllers/sim_cards_controller.rb57
-rw-r--r--app/helpers/sim_card_providers_helper.rb2
-rw-r--r--app/helpers/sim_cards_helper.rb2
-rw-r--r--app/models/ability.rb4
-rw-r--r--app/models/sim_card.rb25
-rw-r--r--app/models/sim_card_provider.rb28
-rw-r--r--app/views/sim_card_providers/_form.html.haml7
-rw-r--r--app/views/sim_card_providers/_form_core.html.haml9
-rw-r--r--app/views/sim_card_providers/_index_core.html.haml21
-rw-r--r--app/views/sim_card_providers/edit.html.haml3
-rw-r--r--app/views/sim_card_providers/index.html.haml6
-rw-r--r--app/views/sim_card_providers/new.html.haml3
-rw-r--r--app/views/sim_card_providers/show.html.haml72
-rw-r--r--app/views/sim_cards/_form.html.haml7
-rw-r--r--app/views/sim_cards/_form_core.html.haml3
-rw-r--r--app/views/sim_cards/_index_core.html.haml16
-rw-r--r--app/views/sim_cards/edit.html.haml3
-rw-r--r--app/views/sim_cards/index.html.haml6
-rw-r--r--app/views/sim_cards/new.html.haml3
-rw-r--r--app/views/sim_cards/show.html.haml32
-rw-r--r--app/views/tenants/_admin_area.de.html.haml3
-rw-r--r--app/views/tenants/_admin_area.en.html.haml3
-rw-r--r--app/views/tenants/_table_of_sim_card_providers.html.haml7
-rw-r--r--app/views/users/show.html.haml3
25 files changed, 372 insertions, 0 deletions
diff --git a/app/controllers/sim_card_providers_controller.rb b/app/controllers/sim_card_providers_controller.rb
new file mode 100644
index 0000000..e9a019c
--- /dev/null
+++ b/app/controllers/sim_card_providers_controller.rb
@@ -0,0 +1,47 @@
+class SimCardProvidersController < ApplicationController
+ load_and_authorize_resource :sim_card_provider
+ before_filter :spread_breadcrumbs
+
+ def index
+ end
+
+ def show
+ end
+
+ def new
+ end
+
+ def create
+ if @sim_card_provider.save
+ redirect_to @sim_card_provider, :notice => t('sim_card_providers.controller.successfuly_created')
+ else
+ render :new
+ end
+ end
+
+ def edit
+ end
+
+ def update
+ if @sim_card_provider.update_attributes(params[:sim_card_provider])
+ redirect_to @sim_card_provider, :notice => t('sim_card_providers.controller.successfuly_updated')
+ else
+ render :edit
+ end
+ end
+
+ def destroy
+ @sim_card_provider.destroy
+ redirect_to sim_card_providers_url, :notice => t('sim_card_providers.controller.successfuly_destroyed')
+ end
+
+ private
+
+ def spread_breadcrumbs
+ add_breadcrumb t("sim_card_providers.index.page_title"), sim_card_providers_path
+ if @sim_card_provider && !@sim_card_provider.new_record?
+ add_breadcrumb @sim_card_provider, sim_card_provider_path(@sim_card_provider)
+ end
+ end
+
+end
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
diff --git a/app/helpers/sim_card_providers_helper.rb b/app/helpers/sim_card_providers_helper.rb
new file mode 100644
index 0000000..306f589
--- /dev/null
+++ b/app/helpers/sim_card_providers_helper.rb
@@ -0,0 +1,2 @@
+module SimCardProvidersHelper
+end
diff --git a/app/helpers/sim_cards_helper.rb b/app/helpers/sim_cards_helper.rb
new file mode 100644
index 0000000..c0df165
--- /dev/null
+++ b/app/helpers/sim_cards_helper.rb
@@ -0,0 +1,2 @@
+module SimCardsHelper
+end
diff --git a/app/models/ability.rb b/app/models/ability.rb
index 4c0844c..d66577d 100644
--- a/app/models/ability.rb
+++ b/app/models/ability.rb
@@ -86,6 +86,10 @@ class Ability
# An admin can not destroy his/her account
#
cannot [:destroy], User, :id => user.id
+
+ # SIM cards
+ #
+ cannot [:edit, :update], SimCard
else
# Any user can do the following stuff.
#
diff --git a/app/models/sim_card.rb b/app/models/sim_card.rb
new file mode 100644
index 0000000..2cbf76b
--- /dev/null
+++ b/app/models/sim_card.rb
@@ -0,0 +1,25 @@
+class SimCard < ActiveRecord::Base
+ attr_accessible :auto_order_card, :sip_account_id, :auth_key, :sim_number
+
+ # Validations
+ #
+ validates :sim_card_provider_id,
+ :presence => true
+
+ belongs_to :sim_card_provider, :touch => true
+
+ validates :sim_card_provider,
+ :presence => true
+
+ validates :sip_account_id,
+ :presence => true
+
+ belongs_to :sip_account
+
+ validates :sip_account,
+ :presence => true
+
+ validates :sim_number,
+ :presence => true
+
+end
diff --git a/app/models/sim_card_provider.rb b/app/models/sim_card_provider.rb
new file mode 100644
index 0000000..854c61a
--- /dev/null
+++ b/app/models/sim_card_provider.rb
@@ -0,0 +1,28 @@
+class SimCardProvider < ActiveRecord::Base
+ attr_accessible :name, :homepage_url, :docu_url, :api_server_url, :api_username, :api_password, :ref, :sip_server, :include_order_card_function
+
+ # Validations
+ #
+ validates :name,
+ :presence => true,
+ :uniqueness => true
+
+ validates :api_username,
+ :presence => true
+
+ validates :api_password,
+ :presence => true
+
+ validates :api_server_url,
+ :presence => true
+
+ validates :sip_server,
+ :presence => true
+
+ has_many :sim_cards, :dependent => :destroy
+
+ def to_s
+ name.to_s
+ end
+
+end
diff --git a/app/views/sim_card_providers/_form.html.haml b/app/views/sim_card_providers/_form.html.haml
new file mode 100644
index 0000000..73953e0
--- /dev/null
+++ b/app/views/sim_card_providers/_form.html.haml
@@ -0,0 +1,7 @@
+= simple_form_for(@sim_card_provider) do |f|
+ = f.error_notification
+
+ = render "form_core", :f => f
+
+ .form-actions
+ = f.button :submit, conditional_t('sim_card_providers.form.submit')
diff --git a/app/views/sim_card_providers/_form_core.html.haml b/app/views/sim_card_providers/_form_core.html.haml
new file mode 100644
index 0000000..fc36579
--- /dev/null
+++ b/app/views/sim_card_providers/_form_core.html.haml
@@ -0,0 +1,9 @@
+.inputs
+ = f.input :name, :label => t('sim_card_providers.form.name.label'), :hint => conditional_hint('sim_card_providers.form.name.hint')
+ = f.input :homepage_url, :label => t('sim_card_providers.form.homepage_url.label'), :hint => conditional_hint('sim_card_providers.form.homepage_url.hint')
+ = f.input :docu_url, :label => t('sim_card_providers.form.docu_url.label'), :hint => conditional_hint('sim_card_providers.form.docu_url.hint')
+ = f.input :api_server_url, :label => t('sim_card_providers.form.api_server_url.label'), :hint => conditional_hint('sim_card_providers.form.api_server_url.hint')
+ = f.input :api_username, :label => t('sim_card_providers.form.api_username.label'), :hint => conditional_hint('sim_card_providers.form.api_username.hint')
+ = f.input :api_password, :label => t('sim_card_providers.form.api_password.label'), :hint => conditional_hint('sim_card_providers.form.api_password.hint')
+ = f.input :sip_server, :label => t('sim_card_providers.form.sip_server.label'), :hint => conditional_hint('sim_card_providers.form.sip_server.hint')
+ = f.input :include_order_card_function, :label => t('sim_card_providers.form.include_order_card_function.label'), :hint => conditional_hint('sim_card_providers.form.include_order_card_function.hint')
diff --git a/app/views/sim_card_providers/_index_core.html.haml b/app/views/sim_card_providers/_index_core.html.haml
new file mode 100644
index 0000000..6a24695
--- /dev/null
+++ b/app/views/sim_card_providers/_index_core.html.haml
@@ -0,0 +1,21 @@
+%table.table.table-striped
+ %tr
+ %th= t('sim_card_providers.index.name')
+ %th= t('sim_card_providers.index.api_server_url')
+ %th= t('sim_card_providers.index.api_username')
+ %th= t('sim_card_providers.index.api_password')
+ %th= t('sim_card_providers.index.sip_server')
+ %th
+
+ - for sim_card_provider in sim_card_providers
+ %tr
+ %td
+ - if sim_card_provider.homepage_url.blank?
+ = sim_card_provider.name
+ - else
+ = link_to sim_card_provider.name, sim_card_provider.homepage_url
+ %td= sim_card_provider.api_server_url
+ %td= sim_card_provider.api_username
+ %td= sim_card_provider.api_password
+ %td= sim_card_provider.sip_server
+ =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:child => sim_card_provider} \ No newline at end of file
diff --git a/app/views/sim_card_providers/edit.html.haml b/app/views/sim_card_providers/edit.html.haml
new file mode 100644
index 0000000..49b1f93
--- /dev/null
+++ b/app/views/sim_card_providers/edit.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("sim_card_providers.edit.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/sim_card_providers/index.html.haml b/app/views/sim_card_providers/index.html.haml
new file mode 100644
index 0000000..2264e53
--- /dev/null
+++ b/app/views/sim_card_providers/index.html.haml
@@ -0,0 +1,6 @@
+- content_for :title, t("sim_card_providers.index.page_title")
+
+- if @sim_card_providers && @sim_card_providers.count > 0
+ = render "index_core", :sim_card_providers => @sim_card_providers
+
+= render :partial => 'shared/create_link', :locals => {:child_class => SimCardProvider} \ No newline at end of file
diff --git a/app/views/sim_card_providers/new.html.haml b/app/views/sim_card_providers/new.html.haml
new file mode 100644
index 0000000..04c0445
--- /dev/null
+++ b/app/views/sim_card_providers/new.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("sim_card_providers.new.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/sim_card_providers/show.html.haml b/app/views/sim_card_providers/show.html.haml
new file mode 100644
index 0000000..37635d9
--- /dev/null
+++ b/app/views/sim_card_providers/show.html.haml
@@ -0,0 +1,72 @@
+- content_for :title, t("sim_card_providers.show.page_title")
+
+.row
+ .span6
+ %table.table.table-striped
+ %tr
+ %td
+ %strong= t('sim_card_providers.show.name') + ":"
+ %td
+ = @sim_card_provider.name
+ %tr
+ %td
+ %strong= t('sim_card_providers.show.homepage_url') + ":"
+ %td
+ = @sim_card_provider.homepage_url
+ %tr
+ %td
+ %strong= t('sim_card_providers.show.docu_url') + ":"
+ %td
+ = @sim_card_provider.docu_url
+ %tr
+ %td
+ %strong= t('sim_card_providers.show.api_server_url') + ":"
+ %td
+ = @sim_card_provider.api_server_url
+ %tr
+ %td
+ %strong= t('sim_card_providers.show.api_username') + ":"
+ %td
+ = @sim_card_provider.api_username
+ %tr
+ %td
+ %strong= t('sim_card_providers.show.api_password') + ":"
+ %td
+ = @sim_card_provider.api_password
+ %tr
+ %td
+ %strong= t('sim_card_providers.show.ref') + ":"
+ %td
+ = @sim_card_provider.ref
+ %tr
+ %td
+ %strong= t('sim_card_providers.show.sip_server') + ":"
+ %td
+ = @sim_card_provider.sip_server
+ %tr
+ %td
+ %strong= t('sim_card_providers.show.include_order_card_function') + ":"
+ %td
+ = @sim_card_provider.include_order_card_function
+
+ = render :partial => 'shared/show_edit_destroy_part', :locals => { :child => @sim_card_provider }
+
+.row
+ .span12
+ %h2= t("sim_cards.index.page_title")
+
+ %table.table.table-striped
+ %tr
+ %th= t('sim_cards.index.sip_account_id')
+ %th= t('sim_cards.index.auth_key')
+ %th= t('sim_cards.index.state')
+ %th
+
+ - for sim_card in @sim_card_provider.sim_cards
+ %tr
+ %td= sim_card.sip_account
+ %td= sim_card.auth_key
+ %td= sim_card.state
+ =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => @sim_card_provider, :child => sim_card}
+
+ = render :partial => 'shared/create_link', :locals => {:parent => @sim_card_provider, :child_class => SimCard} \ No newline at end of file
diff --git a/app/views/sim_cards/_form.html.haml b/app/views/sim_cards/_form.html.haml
new file mode 100644
index 0000000..7d3cfbe
--- /dev/null
+++ b/app/views/sim_cards/_form.html.haml
@@ -0,0 +1,7 @@
+= simple_form_for([@sim_card_provider, @sim_card]) do |f|
+ = f.error_notification
+
+ = render "form_core", :f => f
+
+ .form-actions
+ = f.button :submit, conditional_t('sim_cards.form.submit')
diff --git a/app/views/sim_cards/_form_core.html.haml b/app/views/sim_cards/_form_core.html.haml
new file mode 100644
index 0000000..7cba4e9
--- /dev/null
+++ b/app/views/sim_cards/_form_core.html.haml
@@ -0,0 +1,3 @@
+.inputs
+ = f.input :sim_number, :label => t('sim_cards.form.sim_number.label'), :hint => conditional_hint('sim_cards.form.sim_number.hint')
+ = f.association :sip_account, :collection => @available_sip_accounts, :label => t('phone_sip_accounts.form.sip_account_id.label'), :hint => conditional_hint('phone_sip_accounts.form.sip_account_id.hint'), :include_blank => false \ No newline at end of file
diff --git a/app/views/sim_cards/_index_core.html.haml b/app/views/sim_cards/_index_core.html.haml
new file mode 100644
index 0000000..c36b22b
--- /dev/null
+++ b/app/views/sim_cards/_index_core.html.haml
@@ -0,0 +1,16 @@
+%table.table.table-striped
+ %tr
+ %th= t('sim_cards.index.sip_account_id')
+ %th= t('sip_accounts.index.phone_numbers')
+ %th= t('sim_cards.index.auth_key')
+ %th= t('sim_cards.index.state')
+ %th
+
+ - for sim_card in sim_cards
+ %tr
+ %td= sim_card.sip_account
+ %td
+ = render 'phone_numbers/listing', :phone_numbers => sim_card.sip_account.phone_numbers.order(:number)
+ %td= sim_card.auth_key
+ %td= sim_card.state
+ =render :partial => 'shared/index_view_edit_destroy_part', :locals => {:parent => @parent, :child => sim_card} \ No newline at end of file
diff --git a/app/views/sim_cards/edit.html.haml b/app/views/sim_cards/edit.html.haml
new file mode 100644
index 0000000..97ee10e
--- /dev/null
+++ b/app/views/sim_cards/edit.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("sim_cards.edit.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/sim_cards/index.html.haml b/app/views/sim_cards/index.html.haml
new file mode 100644
index 0000000..803bd72
--- /dev/null
+++ b/app/views/sim_cards/index.html.haml
@@ -0,0 +1,6 @@
+- content_for :title, t("sim_cards.index.page_title")
+
+- if @sim_cards && @sim_cards.count > 0
+ = render "index_core", :sim_cards => @sim_cards
+
+= render :partial => 'shared/create_link', :locals => {:parent => @parent, :child_class => SimCard} \ No newline at end of file
diff --git a/app/views/sim_cards/new.html.haml b/app/views/sim_cards/new.html.haml
new file mode 100644
index 0000000..1eef168
--- /dev/null
+++ b/app/views/sim_cards/new.html.haml
@@ -0,0 +1,3 @@
+- content_for :title, t("sim_cards.new.page_title")
+
+= render "form" \ No newline at end of file
diff --git a/app/views/sim_cards/show.html.haml b/app/views/sim_cards/show.html.haml
new file mode 100644
index 0000000..88822f1
--- /dev/null
+++ b/app/views/sim_cards/show.html.haml
@@ -0,0 +1,32 @@
+- content_for :title, t("sim_cards.show.page_title")
+
+.row
+ .span6
+ %table.table.table-striped
+ %tr
+ %td
+ %strong= t('sim_cards.show.sip_account_id') + ":"
+ %td
+ = @sim_card.sip_account
+ %tr
+ %td
+ %strong= t('sip_accounts.index.phone_numbers')
+ %td
+ = render 'phone_numbers/listing', :phone_numbers => @sim_card.sip_account.phone_numbers.order(:number)
+ %tr
+ %td
+ %strong= t('sim_cards.show.auth_key') + ":"
+ %td
+ = @sim_card.auth_key
+ %tr
+ %td
+ %strong= t('sim_cards.show.state') + ":"
+ %td
+ = @sim_card.state
+ %tr
+ %td
+ %strong= t('sim_cards.show.log') + ":"
+ %td
+ = @sim_card.log
+
+= render :partial => 'shared/show_edit_destroy_part', :locals => {:parent => @parent, :child => @sim_card } \ No newline at end of file
diff --git a/app/views/tenants/_admin_area.de.html.haml b/app/views/tenants/_admin_area.de.html.haml
index 2aed4e1..8acc95d 100644
--- a/app/views/tenants/_admin_area.de.html.haml
+++ b/app/views/tenants/_admin_area.de.html.haml
@@ -35,6 +35,9 @@
= succeed '.' do
=link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer)
+ - if GsParameter.get('SIM_CARDS') == true
+ = render :partial => 'tenants/table_of_sim_card_providers'
+
= render :partial => 'call_routes', :locals => {:tenant => tenant}
= render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways}
diff --git a/app/views/tenants/_admin_area.en.html.haml b/app/views/tenants/_admin_area.en.html.haml
index 8e7bfea..c40e3ca 100644
--- a/app/views/tenants/_admin_area.en.html.haml
+++ b/app/views/tenants/_admin_area.en.html.haml
@@ -35,6 +35,9 @@
= succeed '.' do
=link_to link_to Haml::Engine.new("%i.icon-list").render + ' ' + manufacturer, manufacturer_path(manufacturer)
+ - if GsParameter.get('SIM_CARDS') == true
+ = render :partial => 'tenants/table_of_sim_card_providers'
+
= render :partial => 'call_routes', :locals => {:tenant => tenant}
= render :partial => 'gateways', :locals => {:tenant => tenant, :gateways => gateways}
diff --git a/app/views/tenants/_table_of_sim_card_providers.html.haml b/app/views/tenants/_table_of_sim_card_providers.html.haml
new file mode 100644
index 0000000..135bb65
--- /dev/null
+++ b/app/views/tenants/_table_of_sim_card_providers.html.haml
@@ -0,0 +1,7 @@
+- cache(['tenant_show_table_of_sim_card_providers', I18n.locale, SimCardProvider.count, SimCardProvider.reorder(:updated_at).last]) do
+ -# SIM card providers
+ -#
+ %h2= t('sim_card_providers.index.page_title')
+ - if SimCardProvider.any?
+ = render "sim_card_providers/index_core", :sim_card_providers => SimCardProvider.all
+ = render :partial => 'shared/create_link', :locals => {:child_class => SimCardProvider}
diff --git a/app/views/users/show.html.haml b/app/views/users/show.html.haml
index c63c791..ba38547 100644
--- a/app/views/users/show.html.haml
+++ b/app/views/users/show.html.haml
@@ -67,6 +67,9 @@
- cache(['user_show_phones_overview', I18n.locale, @user, @user.phones]) do
= render :partial => 'phones', :locals => {:user => @user}
+ / - cache(['user_show_sim_cards_overview', I18n.locale, @user, @user.phones]) do
+ / = render :partial => 'phones', :locals => {:user => @user}
+
- cache(['user_show_fax_accounts_overview', I18n.locale, @user, @user.fax_accounts]) do
= render :partial => 'fax_accounts', :locals => {:user => @user}