diff --git a/app/controllers/admin/bank_gateways_controller.rb b/app/controllers/admin/bank_gateways_controller.rb new file mode 100644 index 00000000..3965c91b --- /dev/null +++ b/app/controllers/admin/bank_gateways_controller.rb @@ -0,0 +1,41 @@ +class Admin::BankGatewaysController < Admin::BaseController + inherit_resources + + def new + @bank_gateway = BankGateway.new(params[:bank_gateway]) + render layout: false + end + + def create + @bank_gateway = BankGateway.new(params[:bank_gateway]) + if @bank_gateway.valid? && @bank_gateway.save + redirect_to update_bank_gateways_admin_finances_url, status: :see_other + else + render action: 'new', layout: false + end + end + + def edit + @bank_gateway = BankGateway.find(params[:id]) + render action: 'new', layout: false + end + + def update + @bank_gateway = BankGateway.find(params[:id]) + + if @bank_gateway.update(params[:bank_gateway]) + redirect_to update_bank_gateways_admin_finances_url, status: :see_other + else + render action: 'new', layout: false + end + end + + def destroy + @bank_gateway = BankGateway.find(params[:id]) + @bank_gateway.destroy + redirect_to update_bank_gateways_admin_finances_url, status: :see_other + rescue StandardError => e + flash.now[:alert] = e.message + render template: 'shared/alert' + end +end diff --git a/app/controllers/admin/finances_controller.rb b/app/controllers/admin/finances_controller.rb index 5eaea177..76a93619 100644 --- a/app/controllers/admin/finances_controller.rb +++ b/app/controllers/admin/finances_controller.rb @@ -3,6 +3,7 @@ class Admin::FinancesController < Admin::BaseController def index @bank_accounts = BankAccount.order('name') + @bank_gateways = BankGateway.order('name') @financial_transaction_classes = FinancialTransactionClass.includes(:financial_transaction_types).order('name ASC') end @@ -11,6 +12,11 @@ class Admin::FinancesController < Admin::BaseController render :layout => false end + def update_bank_gateways + @bank_gateways = BankGateway.order('name') + render :layout => false + end + def update_transaction_types @financial_transaction_classes = FinancialTransactionClass.includes(:financial_transaction_types).order('name ASC') render :layout => false diff --git a/app/views/admin/bank_accounts/_form.html.haml b/app/views/admin/bank_accounts/_form.html.haml index fbb43bd1..8ce2433c 100644 --- a/app/views/admin/bank_accounts/_form.html.haml +++ b/app/views/admin/bank_accounts/_form.html.haml @@ -7,6 +7,7 @@ = f.input :iban = f.input :description, as: :text = f.input :balance + = f.association :bank_gateway .modal-footer = link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'} = f.submit class: 'btn btn-primary' diff --git a/app/views/admin/bank_gateways/_form.html.haml b/app/views/admin/bank_gateways/_form.html.haml new file mode 100644 index 00000000..ad06dcdb --- /dev/null +++ b/app/views/admin/bank_gateways/_form.html.haml @@ -0,0 +1,12 @@ += simple_form_for [:admin, @bank_gateway], :validate => true, :remote => true do |f| + .modal-header + = close_button :modal + %h3= @bank_gateway.new_record? ? t('.title_new') : t('.title_edit') + .modal-body + = f.input :name + = f.input :url + = f.input :authorization + = f.association :unattended_user + .modal-footer + = link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'} + = f.submit class: 'btn btn-primary' diff --git a/app/views/admin/bank_gateways/new.js.haml b/app/views/admin/bank_gateways/new.js.haml new file mode 100644 index 00000000..504f5527 --- /dev/null +++ b/app/views/admin/bank_gateways/new.js.haml @@ -0,0 +1,2 @@ +$('#modalContainer').html('#{j(render("form"))}'); +$('#modalContainer').modal(); diff --git a/app/views/admin/finances/_bank_gateways.html.haml b/app/views/admin/finances/_bank_gateways.html.haml new file mode 100644 index 00000000..2c71561c --- /dev/null +++ b/app/views/admin/finances/_bank_gateways.html.haml @@ -0,0 +1,13 @@ +%table.table.table-striped + %thead + %tr + %th= heading_helper BankGateway, :name + %th + %tbody + - @bank_gateways.each do |bank_gateway| + %tr + %td= bank_gateway.name + %td + = link_to t('ui.edit'), edit_admin_bank_gateway_path(bank_gateway), remote: true, class: 'btn btn-mini' + = link_to t('ui.delete'), [:admin, bank_gateway], :method => :delete, :data => {:confirm => t('ui.confirm_delete', name: bank_gateway.name)}, + remote: true, class: 'btn btn-mini btn-danger' diff --git a/app/views/admin/finances/index.html.haml b/app/views/admin/finances/index.html.haml index e39ddd67..f798beca 100644 --- a/app/views/admin/finances/index.html.haml +++ b/app/views/admin/finances/index.html.haml @@ -3,6 +3,7 @@ - content_for :actionbar do = link_to t('.new_financial_transaction_class'), new_admin_financial_transaction_class_path, remote: true, class: 'btn btn-primary' = link_to t('.new_bank_account'), new_admin_bank_account_path, remote: true, class: 'btn' + = link_to t('.new_bank_gateway'), new_admin_bank_gateway_path, remote: true, class: 'btn' - content_for :sidebar do %p= t('.first_paragraph').html_safe @@ -12,3 +13,6 @@ %h2= t('.bank_accounts') #bank_accounts_table= render 'bank_accounts' + +%h2= t('.bank_gateways') +#bank_gateways_table= render 'bank_gateways' diff --git a/app/views/admin/finances/update_bank_gateways.js.haml b/app/views/admin/finances/update_bank_gateways.js.haml new file mode 100644 index 00000000..1be9ae86 --- /dev/null +++ b/app/views/admin/finances/update_bank_gateways.js.haml @@ -0,0 +1,2 @@ +$('#bank_gateways_table').html('#{escape_javascript(render("admin/finances/bank_gateways"))}'); +$('#modalContainer').modal('hide'); diff --git a/config/locales/de.yml b/config/locales/de.yml index fa47d4ee..2d96146c 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -290,6 +290,14 @@ de: title: Administration type: Typ username: Benutzername + bank_accounts: + form: + title_edit: Bankkonto bearbeiten + title_new: Bankkonto anlegen + bank_gateways: + form: + title_edit: Bankgateway bearbeiten + title_new: Bankgateway anlegen configs: list: key: Schlüssel diff --git a/config/locales/en.yml b/config/locales/en.yml index 3d38d7b9..d94c7204 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -290,6 +290,14 @@ en: title: Administration type: type username: username + bank_accounts: + form: + title_edit: Edit bank account + title_new: Add new bank account + bank_gateways: + form: + title_edit: Edit bank gateway + title_new: Add new bank gateway configs: list: key: Key diff --git a/config/routes.rb b/config/routes.rb index d7ec44a7..d1aa8886 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -224,10 +224,12 @@ Rails.application.routes.draw do resources :finances, only: [:index] do get :update_bank_accounts, on: :collection + get :update_bank_gateways, on: :collection get :update_transaction_types, on: :collection end resources :bank_accounts + resources :bank_gateways resources :financial_transaction_classes resources :financial_transaction_types