Edit JS file for split transaction

This commit is contained in:
James Cole
2017-01-15 19:16:46 +01:00
parent 9c09f93908
commit e336a45f79
5 changed files with 82 additions and 17 deletions

View File

@@ -112,7 +112,7 @@ class SplitController extends Controller
Session::forget('transactions.edit-split.fromUpdate'); Session::forget('transactions.edit-split.fromUpdate');
return view( return view(
'transactions.edit-split', 'transactions.split.edit',
compact( compact(
'subTitleIcon', 'currencies', 'optionalFields', 'subTitleIcon', 'currencies', 'optionalFields',
'preFilled', 'subTitle', 'amount', 'sourceAccounts', 'uploadSize', 'destinationAccounts', 'assetAccounts', 'preFilled', 'subTitle', 'amount', 'sourceAccounts', 'uploadSize', 'destinationAccounts', 'assetAccounts',

View File

@@ -33,7 +33,9 @@ $(document).ready(function () {
var opt = { var opt = {
typeahead: { typeahead: {
source: data, source: data,
afterSelect: function(val) { this.$element.val(""); } afterSelect: function () {
this.$element.val("");
}
} }
}; };
$('input[name="tags"]').tagsinput( $('input[name="tags"]').tagsinput(
@@ -94,6 +96,4 @@ $(document).ready(function () {
} }
}); });

View File

@@ -10,5 +10,48 @@
$(document).ready(function () { $(document).ready(function () {
"use strict"; "use strict";
// no special JS for edit transaction.
// withdrawal specific fields
if (what == 'withdrawal') {
$.getJSON('json/expense-accounts').done(function (data) {
$('input[name="destination_account_name"]').typeahead({source: data});
});
}
// deposit specific fields:
if (what == 'deposit') {
$.getJSON('json/revenue-accounts').done(function (data) {
$('input[name="source_account_name"]').typeahead({source: data});
});
}
// tags are always present:
if ($('input[name="tags"]').length > 0) {
$.getJSON('json/tags').done(function (data) {
var opt = {
typeahead: {
source: data,
afterSelect: function () {
this.$element.val("");
}
}
};
$('input[name="tags"]').tagsinput(
opt
);
});
}
// description
$.getJSON('json/transaction-journals/' + what).done(function (data) {
$('input[name="description"]').typeahead({source: data});
});
// category (always there)
$.getJSON('json/categories').done(function (data) {
$('input[name="category"]').typeahead({source: data});
});
}); });

View File

@@ -1,19 +1,20 @@
/* /*
* from-store.js * edit.js
* Copyright (C) 2016 thegrumpydictator@gmail.com * Copyright (c) 2017 thegrumpydictator@gmail.com
* * This software may be modified and distributed under the terms of the Creative Commons Attribution-ShareAlike 4.0 International License.
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
* *
* See the LICENSE file for details. * See the LICENSE file for details.
*/ */
/** global: originalSum, accounting */ /** global: originalSum, accounting */
var destAccounts = {}; var destAccounts = {};
var srcAccounts = {}; var srcAccounts = {};
var categories = {}; var categories = {};
$(function () { var descriptions = {};
$(document).ready(function () {
"use strict"; "use strict";
$('.btn-do-split').click(cloneRow); $('.btn-do-split').click(cloneRow);
$('.remove-current-split').click(removeRow); $('.remove-current-split').click(removeRow);
@@ -33,13 +34,32 @@ $(function () {
$('input[name$="category]"]').typeahead({source: categories}); $('input[name$="category]"]').typeahead({source: categories});
}); });
$.getJSON('json/transaction-journals/' + what).done(function (data) {
descriptions = data;
$('input[name="journal_description"]').typeahead({source: descriptions});
$('input[name$="description]"]').typeahead({source: descriptions});
});
$.getJSON('json/tags').done(function (data) {
var opt = {
typeahead: {
source: data,
afterSelect: function () {
this.$element.val("");
}
}
};
$('input[name="tags"]').tagsinput(
opt
);
});
$('input[name$="][amount]"]').on('input', calculateSum); $('input[name$="][amount]"]').on('input', calculateSum);
// add auto complete:
}); });
function removeRow(e) { function removeRow(e) {
"use strict"; "use strict";
var rows = $('table.split-table tbody tr'); var rows = $('table.split-table tbody tr');
@@ -75,6 +95,9 @@ function cloneRow() {
if (categories.length > 0) { if (categories.length > 0) {
source.find('input[name$="category]"]').typeahead({source: categories}); source.find('input[name$="category]"]').typeahead({source: categories});
} }
if (descriptions.length > 0) {
source.find('input[name$="description]"]').typeahead({source: descriptions});
}
$('.split-table tbody').append(source); $('.split-table tbody').append(source);

View File

@@ -307,6 +307,5 @@
</script> </script>
<script type="text/javascript" src="js/lib/bootstrap3-typeahead.min.js"></script> <script type="text/javascript" src="js/lib/bootstrap3-typeahead.min.js"></script>
<script type="text/javascript" src="js/lib/bootstrap-tagsinput.min.js"></script> <script type="text/javascript" src="js/lib/bootstrap-tagsinput.min.js"></script>
<script type="text/javascript" src="js/ff/transactions/create-edit.js"></script> <script type="text/javascript" src="js/ff/transactions/split/edit.js"></script>
<script type="text/javascript" src="js/ff/split/journal/from-store.js"></script>
{% endblock %} {% endblock %}