mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix #678
This commit is contained in:
parent
dc5bd648cf
commit
310db374c8
@ -16,8 +16,8 @@ var descriptions = {};
|
||||
|
||||
$(document).ready(function () {
|
||||
"use strict";
|
||||
$('.btn-do-split').click(cloneRow);
|
||||
$('.remove-current-split').click(removeRow);
|
||||
$('.btn-do-split').click(cloneDivRow);
|
||||
$('.remove-current-split').click(removeDivRow);
|
||||
|
||||
$.getJSON('json/expense-accounts').done(function (data) {
|
||||
destAccounts = data;
|
||||
@ -67,7 +67,33 @@ $(document).ready(function () {
|
||||
}
|
||||
});
|
||||
|
||||
/**
|
||||
* New and cool
|
||||
* @param e
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function removeDivRow(e) {
|
||||
"use strict";
|
||||
var rows = $('div.split_row');
|
||||
if (rows.length === 1) {
|
||||
return false;
|
||||
}
|
||||
var row = $(e.target);
|
||||
var index = row.data('split');
|
||||
$('div.split_row[data-split="' + index + '"]').remove();
|
||||
|
||||
|
||||
resetDivSplits();
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* OLD
|
||||
* @param e
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function removeRow(e) {
|
||||
"use strict";
|
||||
var rows = $('table.split-table tbody tr');
|
||||
@ -85,6 +111,47 @@ function removeRow(e) {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* New and cool
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function cloneDivRow() {
|
||||
"use strict";
|
||||
var source = $('div.split_row').last().clone();
|
||||
var count = $('div.split_row').length + 1;
|
||||
source.removeClass('initial-row');
|
||||
source.find('.count').text('#' + count);
|
||||
|
||||
source.find('input[name$="][amount]"]').val("").on('input', calculateSum);
|
||||
if (destAccounts.length > 0) {
|
||||
source.find('input[name$="destination_account_name]"]').typeahead({source: destAccounts});
|
||||
}
|
||||
|
||||
if (destAccounts.length > 0) {
|
||||
source.find('input[name$="source_account_name]"]').typeahead({source: srcAccounts});
|
||||
}
|
||||
if (categories.length > 0) {
|
||||
source.find('input[name$="category]"]').typeahead({source: categories});
|
||||
}
|
||||
if (descriptions.length > 0) {
|
||||
source.find('input[name$="description]"]').typeahead({source: descriptions});
|
||||
}
|
||||
|
||||
$('div.split_row_holder').append(source);
|
||||
|
||||
// remove original click things, add them again:
|
||||
$('.remove-current-split').unbind('click').click(removeRow);
|
||||
|
||||
calculateSum();
|
||||
resetDivSplits();
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* OLD
|
||||
* @returns {boolean}
|
||||
*/
|
||||
function cloneRow() {
|
||||
"use strict";
|
||||
var source = $('.table.split-table tbody tr').last().clone();
|
||||
@ -119,6 +186,100 @@ function cloneRow() {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* New and hip
|
||||
*/
|
||||
function resetDivSplits() {
|
||||
"use strict";
|
||||
// loop rows, reset numbers:
|
||||
|
||||
// update the row split number:
|
||||
$.each($('div.split_row'), function (i, v) {
|
||||
var row = $(v);
|
||||
row.attr('data-split', i);
|
||||
|
||||
// add or remove class with bg thing
|
||||
if(i % 2 === 0) {
|
||||
row.removeClass('bg-gray-light');
|
||||
}
|
||||
if(i % 2 === 1) {
|
||||
row.addClass('bg-gray-light');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
// loop each remove button, update the index
|
||||
$.each($('.remove-current-split'), function (i, v) {
|
||||
var button = $(v);
|
||||
button.attr('data-split', i);
|
||||
button.find('i').attr('data-split', i);
|
||||
|
||||
});
|
||||
|
||||
// loop each indicator (#) and update it:
|
||||
$.each($('td.count'), function (i, v) {
|
||||
var cell = $(v);
|
||||
var index = i + 1;
|
||||
cell.text('#' + index);
|
||||
});
|
||||
|
||||
// loop each possible field.
|
||||
|
||||
// ends with ][description]
|
||||
$.each($('input[name$="][description]"]'), function (i, v) {
|
||||
var input = $(v);
|
||||
input.attr('name', 'transactions[' + i + '][description]');
|
||||
});
|
||||
// ends with ][destination_account_name]
|
||||
$.each($('input[name$="][destination_account_name]"]'), function (i, v) {
|
||||
var input = $(v);
|
||||
input.attr('name', 'transactions[' + i + '][destination_account_name]');
|
||||
});
|
||||
// ends with ][source_account_name]
|
||||
$.each($('input[name$="][source_account_name]"]'), function (i, v) {
|
||||
var input = $(v);
|
||||
input.attr('name', 'transactions[' + i + '][source_account_name]');
|
||||
});
|
||||
// ends with ][amount]
|
||||
$.each($('input[name$="][amount]"]'), function (i, v) {
|
||||
var input = $(v);
|
||||
input.attr('name', 'transactions[' + i + '][amount]');
|
||||
});
|
||||
|
||||
// ends with ][foreign_amount]
|
||||
$.each($('input[name$="][foreign_amount]"]'), function (i, v) {
|
||||
var input = $(v);
|
||||
input.attr('name', 'transactions[' + i + '][foreign_amount]');
|
||||
});
|
||||
|
||||
// ends with ][transaction_currency_id]
|
||||
$.each($('input[name$="][transaction_currency_id]"]'), function (i, v) {
|
||||
var input = $(v);
|
||||
input.attr('name', 'transactions[' + i + '][transaction_currency_id]');
|
||||
});
|
||||
|
||||
// ends with ][foreign_currency_id]
|
||||
$.each($('input[name$="][foreign_currency_id]"]'), function (i, v) {
|
||||
var input = $(v);
|
||||
input.attr('name', 'transactions[' + i + '][foreign_currency_id]');
|
||||
});
|
||||
|
||||
// ends with ][budget_id]
|
||||
$.each($('select[name$="][budget_id]"]'), function (i, v) {
|
||||
var input = $(v);
|
||||
input.attr('name', 'transactions[' + i + '][budget_id]');
|
||||
});
|
||||
|
||||
// ends with ][category]
|
||||
$.each($('input[name$="][category]"]'), function (i, v) {
|
||||
var input = $(v);
|
||||
input.attr('name', 'transactions[' + i + '][category]');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* OLD
|
||||
*/
|
||||
function resetSplits() {
|
||||
"use strict";
|
||||
// loop rows, reset numbers:
|
||||
|
@ -30,7 +30,7 @@
|
||||
</div>
|
||||
{% endif %}
|
||||
<div class="row">
|
||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'transaction_data'|_ }}</h3>
|
||||
@ -65,7 +65,7 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-6 col-md-6 col-sm-6">
|
||||
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
|
||||
<div class="box">
|
||||
<div class="box-header with-border">
|
||||
<h3 class="box-title">{{ 'optional_field_meta_data'|_ }}</h3>
|
||||
@ -185,105 +185,108 @@
|
||||
<h3 class="box-title">{{ 'splits'|_ }}</h3>
|
||||
</div>
|
||||
<div class="box-body">
|
||||
<table class="table table-bordered table-condensed table-striped split-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th> </th>
|
||||
<th>{{ trans('list.split_number') }}</th>
|
||||
<th>{{ trans('list.description') }}</th>
|
||||
|
||||
<div class="container-fluid split_row_holder">
|
||||
<div class="row bg-gray-light" style="padding-bottom:3px;">
|
||||
<div class="col-lg-1 col-md-1 col-sm-6 col-xs-6"> </div>
|
||||
<div class="col-lg-1 col-md-1 col-sm-6 col-xs-6"><strong>{{ trans('list.split_number') }}</strong></div>
|
||||
<div class="col-lg-3 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.description') }}</strong></div>
|
||||
{# withdrawal and deposit have a destination. #}
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<th>{{ trans('list.destination') }}</th>
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.destination') }}</strong></div>
|
||||
{% endif %}
|
||||
|
||||
{# DEPOSIT HAS A SOURCE #}
|
||||
{# Deposit has a source #}
|
||||
{% if preFilled.what == 'deposit' %}
|
||||
<th>{{ trans('list.source') }}</th>
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.source') }}</strong></div>
|
||||
{% endif %}
|
||||
<div class="col-lg-1 col-md-5 col-sm-12 col-xs-12"><strong>{{ trans('list.amount') }}</strong></div>
|
||||
{% if transaction.foreign_amount != null %}
|
||||
<div class="col-lg-1 col-md-7 col-sm-12 col-xs-12"> </div>
|
||||
{% endif %}
|
||||
|
||||
<th colspan="2">{{ trans('list.amount') }}</th>
|
||||
|
||||
{# only withdrawal has budget #}
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<th>{{ trans('list.budget') }}</th>
|
||||
<div class="col-lg-1 col-md-6 col-sm-12 col-xs-12"><strong>{{ trans('list.budget') }}</strong></div>
|
||||
{% endif %}
|
||||
<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12"><strong>{{ trans('list.category') }}</strong></div>
|
||||
</div>
|
||||
|
||||
{% for index, transaction in preFilled.transactions %}
|
||||
<div class="row {% if loop.index0 % 2 == 1 %}bg-gray-light{% endif %} split_row" data-split="{{ loop.index0 }}">
|
||||
{# button #}
|
||||
<div class="col-lg-1 col-md-1 col-sm-6 col-xs-6">
|
||||
<a href="#" class="btn btn-xs btn-danger remove-current-split" data-split="{{ loop.index0 }}">
|
||||
<i class="fa fa-trash" data-split="{{ loop.index0 }}"></i></a>
|
||||
</div>
|
||||
|
||||
{# index #}
|
||||
<div class="col-lg-1 col-md-1 col-sm-6 col-xs-6 count">#{{ loop.index }}</div>
|
||||
|
||||
{# description #}
|
||||
<div class="col-lg-3 col-md-5 col-sm-12 col-xs-12">
|
||||
<input type="text" name="transactions[{{ loop.index0 }}][description]" value="{{ transaction.description }}"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
|
||||
{# destination for withdrawals: #}
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
|
||||
<input type="text" name="transactions[{{ loop.index0 }}][destination_account_name]"
|
||||
value="{{ transaction.destination_account_name }}" class="form-control"/>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<th>{{ trans('list.category') }}</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{% for index, transaction in preFilled.transactions %}
|
||||
<tr data-split="{{ loop.index0 }}">
|
||||
<td><a href="#" class="btn btn-xs btn-danger remove-current-split" data-split="{{ loop.index0 }}"><i
|
||||
class="fa fa-trash" data-split="{{ loop.index0 }}"></i></a></td>
|
||||
<td class="count">#{{ loop.index }}</td>
|
||||
<td>
|
||||
<input type="text" name="transactions[{{ loop.index0 }}][description]" value="{{ transaction.description }}"
|
||||
class="form-control"/>
|
||||
</td>
|
||||
{# source for deposits #}
|
||||
{% if preFilled.what == 'deposit' %}
|
||||
<div class="col-lg-2 col-md-5 col-sm-12 col-xs-12">
|
||||
<input type="text" name="transactions[{{ loop.index0 }}][source_account_name]"
|
||||
value="{{ transaction.source_account_name }}" class="form-control"/>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
<!-- withdrawal has several destination names. -->
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<td>
|
||||
<input type="text" name="transactions[{{ loop.index0 }}][destination_account_name]"
|
||||
value="{{ transaction.destination_account_name }}"
|
||||
class="form-control"/>
|
||||
</td>
|
||||
{% endif %}
|
||||
{# amount#}
|
||||
<div class="col-lg-1 col-md-5 col-sm-12 col-xs-12">
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon">{{ transaction.transaction_currency_symbol }}</div>
|
||||
<input type="number" name="transactions[{{ loop.index0 }}][amount]" value="{{ transaction.amount }}"
|
||||
class="form-control" autocomplete="off" step="any" min="0.01">
|
||||
</div>
|
||||
<input type="hidden" name="transactions[{{ loop.index0 }}][transaction_currency_id]"
|
||||
value="{{ transaction.transaction_currency_id }}">
|
||||
</div>
|
||||
|
||||
{# deposit has several source names #}
|
||||
{% if preFilled.what == 'deposit' %}
|
||||
<td>
|
||||
<input type="text" name="transactions[{{ loop.index0 }}][source_account_name]"
|
||||
value="{{ transaction.source_account_name }}"
|
||||
class="form-control"/>
|
||||
</td>
|
||||
{% endif %}
|
||||
|
||||
{# two fields for amount #}
|
||||
<td style="width:10%;">
|
||||
{# foreign amount #}
|
||||
{% if transaction.foreign_amount != null %}
|
||||
<div class="col-lg-1 col-md-7 col-sm-12 col-xs-12">
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon">{{ transaction.transaction_currency_symbol }}</div>
|
||||
<input type="number" name="transactions[{{ loop.index0 }}][amount]" value="{{ transaction.amount }}"
|
||||
<div class="input-group-addon">{{ transaction.foreign_currency_symbol }}</div>
|
||||
<input type="number" name="transactions[{{ loop.index0 }}][foreign_amount]" value="{{ transaction.foreign_amount }}"
|
||||
class="form-control" autocomplete="off" step="any" min="0.01">
|
||||
</div>
|
||||
<input type="hidden" name="transactions[{{ loop.index0 }}][transaction_currency_id]" value="{{ transaction.transaction_currency_id }}">
|
||||
</td>
|
||||
{# foreign amount #}
|
||||
<td style="width:10%;">
|
||||
{% if transaction.foreign_amount != null %}
|
||||
<div class="input-group">
|
||||
<div class="input-group-addon">{{ transaction.foreign_currency_symbol }}</div>
|
||||
<input type="number" name="transactions[{{ loop.index0 }}][foreign_amount]"
|
||||
value="{{ transaction.foreign_amount }}"
|
||||
class="form-control" autocomplete="off" step="any" min="0.01">
|
||||
</div>
|
||||
<input type="hidden" name="transactions[{{ loop.index0 }}][foreign_currency_id]" value="{{ transaction.foreign_currency_id }}">
|
||||
{% endif %}
|
||||
</td>
|
||||
<input type="hidden"
|
||||
name="transactions[{{ loop.index0 }}][foreign_currency_id]"
|
||||
value="{{ transaction.foreign_currency_id }}">
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<td>
|
||||
<select class="form-control" name="transactions[{{ loop.index0 }}][budget_id]">
|
||||
{% for key, budget in budgets %}
|
||||
<option label="{{ budget }}" value="{{ key }}"
|
||||
{% if transaction.budget_id == key %}
|
||||
selected="selected"
|
||||
{% endif %}
|
||||
>{{ budget }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</td>
|
||||
{% endif %}
|
||||
<td>
|
||||
<input type="text" name="transactions[{{ loop.index0 }}][category]" value="{{ transaction.category }}"
|
||||
class="form-control"/>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
{# budget #}
|
||||
{% if preFilled.what == 'withdrawal' %}
|
||||
<div class="col-lg-1 col-md-6 col-sm-12 col-xs-12">
|
||||
<select class="form-control" name="transactions[{{ loop.index0 }}][budget_id]">
|
||||
{% for key, budget in budgets %}
|
||||
<option label="{{ budget }}" value="{{ key }}"
|
||||
{% if transaction.budget_id == key %} selected="selected"{% endif %}>{{ budget }}</option>
|
||||
{% endfor %}
|
||||
</select>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
{# category #}
|
||||
<div class="col-lg-2 col-md-6 col-sm-12 col-xs-12">
|
||||
<input type="text" name="transactions[{{ loop.index0 }}][category]" value="{{ transaction.category }}"
|
||||
class="form-control"/>
|
||||
</div>
|
||||
</div>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<p>
|
||||
<br/>
|
||||
<a href="#" class="btn btn-default btn-do-split"><i class="fa fa-plus-circle"></i> {{ 'add_another_split'|_ }}</a>
|
||||
|
Loading…
Reference in New Issue
Block a user