Add admin UI for SupplierCategories

This commit is contained in:
mariandl 2022-02-20 16:43:20 +01:00 committed by GitHub
parent 7e8c1d041d
commit 708f85a839
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 108 additions and 0 deletions

View file

@ -5,6 +5,7 @@ class Admin::FinancesController < Admin::BaseController
@bank_accounts = BankAccount.order('name')
@bank_gateways = BankGateway.order('name')
@financial_transaction_classes = FinancialTransactionClass.includes(:financial_transaction_types).order('name ASC')
@supplier_categories = SupplierCategory.order('name')
end
def update_bank_accounts
@ -21,4 +22,9 @@ class Admin::FinancesController < Admin::BaseController
@financial_transaction_classes = FinancialTransactionClass.includes(:financial_transaction_types).order('name ASC')
render :layout => false
end
def update_supplier_categories
@supplier_categories = SupplierCategory.order('name')
render :layout => false
end
end

View file

@ -0,0 +1,41 @@
class Admin::SupplierCategoriesController < Admin::BaseController
inherit_resources
def new
@supplier_category = SupplierCategory.new(params[:supplier_category])
render layout: false
end
def create
@supplier_category = SupplierCategory.new(params[:supplier_category])
if @supplier_category.valid? && @supplier_category.save
redirect_to update_supplier_categories_admin_finances_url, status: :see_other
else
render action: 'new', layout: false
end
end
def edit
@supplier_category = SupplierCategory.find(params[:id])
render action: 'new', layout: false
end
def update
@supplier_category = SupplierCategory.find(params[:id])
if @supplier_category.update(params[:supplier_category])
redirect_to update_supplier_categories_admin_finances_url, status: :see_other
else
render action: 'new', layout: false
end
end
def destroy
@supplier_category = SupplierCategory.find(params[:id])
@supplier_category.destroy
redirect_to update_supplier_categories_admin_finances_url, status: :see_other
rescue StandardError => e
flash.now[:alert] = e.message
render template: 'shared/alert'
end
end

View file

@ -0,0 +1,13 @@
%table.table.table-striped
%thead
%tr
%th= heading_helper SupplierCategory, :name
%th
%tbody
- @supplier_categories.each do |supplier_category|
%tr
%td= supplier_category.name
%td
= link_to t('ui.edit'), edit_admin_supplier_category_path(supplier_category), remote: true, class: 'btn btn-mini'
= link_to t('ui.delete'), [:admin, supplier_category], :method => :delete, :data => {:confirm => t('ui.confirm_delete', name: supplier_category.name)},
remote: true, class: 'btn btn-mini btn-danger'

View file

@ -4,6 +4,7 @@
= 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'
= link_to t('.new_supplier_category'), new_admin_supplier_category_path, remote: true, class: 'btn'
- content_for :sidebar do
%p= t('.first_paragraph').html_safe
@ -16,3 +17,6 @@
%h2= t('.bank_gateways')
#bank_gateways_table= render 'bank_gateways'
%h2= t('.supplier_categories')
#supplier_categories_table= render 'supplier_categories'

View file

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

View file

@ -0,0 +1,12 @@
= simple_form_for [:admin, @supplier_category], :validate => true, :remote => true do |f|
.modal-header
= close_button :modal
%h3= @supplier_category.new_record? ? t('.title_new') : t('.title_edit')
.modal-body
= f.input :name
= f.input :description
= f.association :financial_transaction_class, :include_blank => false
= f.association :bank_account, :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();