From a5d0c5ccabf2ff3a46a41a5e33b9c335982d3d72 Mon Sep 17 00:00:00 2001 From: Patrick Gansterer Date: Sun, 6 Mar 2016 11:53:31 +0100 Subject: [PATCH] Add a button to add all ordergroups to a new finanacial transaction collection This function can be used if we need to add the same financial transaction to all ordergroups at the same time. E.g. the monthly membership fee. --- .../new_collection.html.haml | 29 +++++++++++++++---- config/locales/de.yml | 1 + config/locales/en.yml | 1 + 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/app/views/finance/financial_transactions/new_collection.html.haml b/app/views/finance/financial_transactions/new_collection.html.haml index 0c7bd0a9..40a1e4e0 100644 --- a/app/views/finance/financial_transactions/new_collection.html.haml +++ b/app/views/finance/financial_transactions/new_collection.html.haml @@ -2,7 +2,7 @@ - content_for :javascript do :javascript - var ordergroup = "#{escape_javascript(render('ordergroup'))}" + var ordergroup = $($.parseHTML("#{escape_javascript(render('ordergroup'))}")); $(function() { $(document).on('touchclick', 'a[data-remove-transaction]', function() { @@ -11,7 +11,21 @@ }); $(document).on('touchclick', 'a[data-add-transaction]', function() { - $('#ordergroups').append(ordergroup); + ordergroup.clone().appendTo('#ordergroups'); + return false; + }); + + $(document).on('touchclick', 'a[data-add-all-ordergroups]', function() { + var value = prompt("#{escape_javascript(heading_helper(FinancialTransaction, :amount))}:"); + if (value === null) + return false; + $('#ordergroups > tbody > tr').remove(); + var options = ordergroup.find('td > select > option').each(function() { + var row = ordergroup.clone(); + row.find('td > input').val(value); + row.find('td > select').val(this.value); + row.appendTo('#ordergroups'); + }); return false; }); }); @@ -25,12 +39,15 @@ = text_field_tag :note, params[:note], class: 'input-xlarge', required: 'required' %p %table#ordergroups{:style => "width:20em"} - %tr - %th= heading_helper FinancialTransaction, :ordergroup - %th= heading_helper FinancialTransaction, :amount - = render :partial => 'ordergroup', :collection => [1, 2, 3] + %thead + %tr + %th= heading_helper FinancialTransaction, :ordergroup + %th= heading_helper FinancialTransaction, :amount + %tbody + = render :partial => 'ordergroup', :collection => [1, 2, 3] %p = link_to t('.new_ordergroup'), '#', 'data-add-transaction' => true, class: 'btn' + = link_to t('.add_all_ordergroups'), '#', 'data-add-all-ordergroups' => true, class: 'btn' .form-actions = submit_tag t('.save'), class: 'btn btn-primary' = link_to t('ui.or_cancel'), finance_ordergroups_path diff --git a/config/locales/de.yml b/config/locales/de.yml index 62e9a8cd..44c28162 100644 --- a/config/locales/de.yml +++ b/config/locales/de.yml @@ -756,6 +756,7 @@ de: paragraph: Hier kannst du der Bestellgruppe %{name} Geld gutschreiben/abziehen. title: Neue Transaktion new_collection: + add_all_ordergroups: Alle Bestellgruppen hinzufügen new_ordergroup: Weitere Bestellgruppe hinzufügen save: Transaktionen speichern sidebar: Hier kannst Du mehrere Konten gleichzeitig aktualsieren. Z.B. alle Überweisungen der Bestellgruppen aus einem Kontoauszug. diff --git a/config/locales/en.yml b/config/locales/en.yml index 6497da03..2903083f 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -769,6 +769,7 @@ en: paragraph: Here you can credit and debit money for the ordergroup %{name}. title: New transaction new_collection: + add_all_ordergroups: Add all ordergroups new_ordergroup: Add new ordergroup save: Save transaction sidebar: Here you can update more accounts at the same time. For example all transfers of the ordergroup from one account statement.