Add UI to manage the financial transaction types and classes

This commit is contained in:
Patrick Gansterer 2017-06-28 12:56:56 +02:00
parent 924f346b4c
commit dae4d075fe
18 changed files with 171 additions and 0 deletions

View file

@ -0,0 +1,13 @@
class Admin::FinancesController < Admin::BaseController
inherit_resources
def index
@financial_transaction_classes = FinancialTransactionClass.order('name ASC')
end
def update_transaction_types
@financial_transaction_classes = FinancialTransactionClass.order('name ASC')
render :layout => false
end
end

View file

@ -0,0 +1,41 @@
class Admin::FinancialTransactionClassesController < Admin::BaseController
inherit_resources
def new
@financial_transaction_class = FinancialTransactionClass.new(params[:financial_transaction_class])
render layout: false
end
def create
@financial_transaction_class = FinancialTransactionClass.new(params[:financial_transaction_class])
if @financial_transaction_class.save
redirect_to update_transaction_types_admin_finances_url, status: 303
else
render action: 'new', layout: false
end
end
def edit
@financial_transaction_class = FinancialTransactionClass.find(params[:id])
render action: 'new', layout: false
end
def update
@financial_transaction_class = FinancialTransactionClass.find(params[:id])
if @financial_transaction_class.update_attributes(params[:financial_transaction_class])
redirect_to update_transaction_types_admin_finances_url, status: 303
else
render action: 'new', layout: false
end
end
def destroy
@financial_transaction_class = FinancialTransactionClass.find(params[:id])
@financial_transaction_class.destroy!
redirect_to update_transaction_types_admin_finances_url, status: 303
rescue => error
flash.now[:alert] = error.message
render template: 'shared/alert'
end
end

View file

@ -0,0 +1,42 @@
class Admin::FinancialTransactionTypesController < Admin::BaseController
inherit_resources
def new
@financial_transaction_type = FinancialTransactionType.new(params[:financial_transaction_type])
@financial_transaction_type.financial_transaction_class = FinancialTransactionClass.find_by_id(params[:financial_transaction_class]) if params[:financial_transaction_class]
render layout: false
end
def create
@financial_transaction_type = FinancialTransactionType.new(params[:financial_transaction_type])
if @financial_transaction_type.save
redirect_to update_transaction_types_admin_finances_url, status: 303
else
render action: 'new', layout: false
end
end
def edit
@financial_transaction_type = FinancialTransactionType.find(params[:id])
render action: 'new', layout: false
end
def update
@financial_transaction_type = FinancialTransactionType.find(params[:id])
if @financial_transaction_type.update_attributes(params[:financial_transaction_type])
redirect_to update_transaction_types_admin_finances_url, status: 303
else
render action: 'new', layout: false
end
end
def destroy
@financial_transaction_type = FinancialTransactionType.find(params[:id])
@financial_transaction_type.destroy!
redirect_to update_transaction_types_admin_finances_url, status: 303
rescue => error
flash.now[:alert] = error.message
render template: 'shared/alert'
end
end

View file

@ -0,0 +1,5 @@
= simple_form_for [:admin, @financial_transaction_class] do |f|
= f.input :name
.form-actions
= f.button :submit
= link_to t('ui.or_cancel'), :back

View file

@ -0,0 +1,23 @@
%table.table.table-striped
%thead
%tr
%th= t '.name'
%th= t 'ui.actions'
%tbody
- for financial_transaction_class in @financial_transaction_classes
%tr
%td
%strong= financial_transaction_class.name
%td
= link_to t('ui.edit'), edit_admin_financial_transaction_class_path(financial_transaction_class), remote: true, class: 'btn btn-mini'
= link_to t('ui.delete'), [:admin, financial_transaction_class], :data => {:confirm => t('ui.confirm_delete', name: financial_transaction_class.name)},
:method => :delete, remote: true, class: 'btn btn-mini btn-danger'
= link_to t('.new_financial_transaction_type'), new_admin_financial_transaction_type_path(financial_transaction_class: financial_transaction_class), remote: true, class: 'btn btn-success btn-mini'
- for financial_transaction_type in financial_transaction_class.financial_transaction_types
%tr
%td{:style => "padding-left: #{25}px"}
= financial_transaction_type.name
%td
= link_to t('ui.edit'), edit_admin_financial_transaction_type_path(financial_transaction_type), remote: true, class: 'btn btn-mini'
= link_to t('ui.delete'), [:admin, financial_transaction_type], :data => {:confirm => t('ui.confirm_delete', name: financial_transaction_type.name)},
:method => :delete, remote: true, class: 'btn btn-mini btn-danger'

View file

@ -0,0 +1,9 @@
- title t '.title'
- content_for :actionbar do
= link_to t('.new_financial_transaction_class'), new_admin_financial_transaction_class_path, remote: true, class: 'btn btn-primary'
- content_for :sidebar do
%p= t('.first_paragraph').html_safe
#transaction_types_table= render 'transaction_types'

View file

@ -0,0 +1,2 @@
$('#transaction_types_table').html('#{escape_javascript(render("admin/finances/transaction_types"))}');
$('#modalContainer').modal('hide');

View file

@ -0,0 +1,9 @@
= simple_form_for [:admin, @financial_transaction_class], :validate => true, :remote => true do |f|
.modal-header
= close_button :modal
%h3= @financial_transaction_class.new_record? ? t('.title_new') : t('.title_edit')
.modal-body
= f.input :name
.modal-footer
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
= f.submit class: 'btn btn-primary'

View file

@ -0,0 +1,2 @@
$('#modalContainer').html('#{j(render("form"))}');
$('#modalContainer').modal();

View file

@ -0,0 +1,10 @@
= simple_form_for [:admin, @financial_transaction_type], :validate => true, :remote => true do |f|
.modal-header
= close_button :modal
%h3= @financial_transaction_type.new_record? ? t('.title_new') : t('.title_edit')
.modal-body
= f.input :name
= f.association :financial_transaction_class, :include_blank => false
.modal-footer
= link_to t('ui.close'), '#', class: 'btn', data: {dismiss: 'modal'}
= f.submit class: 'btn btn-primary'

View file

@ -0,0 +1,2 @@
$('#modalContainer').html('#{j(render("form"))}');
$('#modalContainer').modal();

View file

@ -0,0 +1 @@
$('div.container-fluid').prepend('<%= bootstrap_flash_patched %>');

View file

@ -1418,6 +1418,7 @@ de:
navigation: navigation:
admin: admin:
config: Einstellungen config: Einstellungen
finance: Finanzen
home: Übersicht home: Übersicht
mail_delivery_status: E-Mail Probleme mail_delivery_status: E-Mail Probleme
messagegroups: Nachrichtengruppen messagegroups: Nachrichtengruppen

View file

@ -1428,6 +1428,7 @@ en:
navigation: navigation:
admin: admin:
config: Configuration config: Configuration
finance: Finances
home: Overview home: Overview
mail_delivery_status: Email problems mail_delivery_status: Email problems
messagegroups: Message groups messagegroups: Message groups

View file

@ -1416,6 +1416,7 @@ fr:
navigation: navigation:
admin: admin:
config: Configuration config: Configuration
finance: Trésorerie
home: Aperçu home: Aperçu
mail_delivery_status: mail_delivery_status:
messagegroups: messagegroups:

View file

@ -1418,6 +1418,7 @@ nl:
navigation: navigation:
admin: admin:
config: Instellingen config: Instellingen
finance: Financiën
home: Overzicht home: Overzicht
mail_delivery_status: Emailproblemen mail_delivery_status: Emailproblemen
messagegroups: Berichtengroepen messagegroups: Berichtengroepen

View file

@ -46,6 +46,7 @@ SimpleNavigation::Configuration.run do |navigation|
subnav.item :ordergroups, I18n.t('navigation.admin.ordergroups'), admin_ordergroups_path subnav.item :ordergroups, I18n.t('navigation.admin.ordergroups'), admin_ordergroups_path
subnav.item :workgroups, I18n.t('navigation.admin.workgroups'), admin_workgroups_path subnav.item :workgroups, I18n.t('navigation.admin.workgroups'), admin_workgroups_path
subnav.item :mail_delivery_status, I18n.t('navigation.admin.mail_delivery_status'), admin_mail_delivery_status_index_path subnav.item :mail_delivery_status, I18n.t('navigation.admin.mail_delivery_status'), admin_mail_delivery_status_index_path
subnav.item :finances, I18n.t('navigation.admin.finance'), admin_finances_path
subnav.item :config, I18n.t('navigation.admin.config'), admin_config_path subnav.item :config, I18n.t('navigation.admin.config'), admin_config_path
end end

View file

@ -179,6 +179,13 @@ Foodsoft::Application.routes.draw do
namespace :admin do namespace :admin do
root to: 'base#index' root to: 'base#index'
resources :finances, only: [:index] do
get :update_transaction_types, on: :collection
end
resources :financial_transaction_classes
resources :financial_transaction_types
resources :users do resources :users do
post :restore, on: :member post :restore, on: :member
post :sudo, on: :member post :sudo, on: :member