Files
firefly-iii/public/v1/js/ff/transactions/show.js

97 lines
3.1 KiB
JavaScript
Raw Normal View History

/*
* show.js
2020-02-16 13:59:41 +01:00
* Copyright (c) 2019 james@firefly-iii.org
*
* This file is part of Firefly III (https://github.com/firefly-iii).
2017-10-21 08:40:00 +02:00
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
2017-10-21 08:40:00 +02:00
*
* This program is distributed in the hope that it will be useful,
2017-10-21 08:40:00 +02:00
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
2017-10-21 08:40:00 +02:00
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
$(function () {
"use strict";
2019-07-20 06:47:34 +02:00
$('.link-modal').click(getLinkModal);
2021-09-20 06:39:10 +02:00
$('.clone-transaction').click(cloneTransaction);
2019-07-20 06:47:34 +02:00
$('#linkJournalModal').on('shown.bs.modal', function () {
makeAutoComplete();
})
$('[data-toggle="tooltip"]').tooltip();
2019-07-20 06:47:34 +02:00
});
2019-04-16 16:20:46 +02:00
2019-07-20 06:47:34 +02:00
function getLinkModal(e) {
var button = $(e.currentTarget);
var journalId = parseInt(button.data('journal'));
2022-04-12 18:19:30 +02:00
var url = modalDialogURL.replace('%JOURNAL%', journalId);
2019-07-20 06:47:34 +02:00
console.log(url);
$.get(url).done(function (data) {
$('#linkJournalModal').html(data).modal('show');
}).fail(function () {
alert('Could not load the data to link journals. Sorry :(');
button.prop('disabled', true);
});
return false;
}
function makeAutoComplete() {
// input link-journal
var source = new Bloodhound({
datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),
queryTokenizer: Bloodhound.tokenizers.whitespace,
prefetch: {
2022-04-12 18:19:30 +02:00
url: acURL + '?uid=' + uid,
2019-07-20 06:47:34 +02:00
filter: function (list) {
return $.map(list, function (item) {
return item;
});
}
},
remote: {
2022-04-12 18:19:30 +02:00
url: acURL + '?query=%QUERY&uid=' + uid,
2019-07-20 06:47:34 +02:00
wildcard: '%QUERY',
filter: function (list) {
return $.map(list, function (item) {
return item;
});
}
}
});
source.initialize();
$('.link-journal').typeahead({hint: true, highlight: true,}, {source: source, displayKey: 'name', autoSelect: false})
.on('typeahead:select', selectedJournal);
}
function selectedJournal(event, journal) {
$('#journal-selector').hide();
$('#journal-selection').show();
2022-04-12 18:19:30 +02:00
$('#selected-journal').html('<a href="' + groupURL.replace('%GROUP%', journal.transaction_group_id) + '">' + journal.description + '</a>').show();
2019-07-20 06:47:34 +02:00
$('input[name="opposing"]').val(journal.id);
2020-07-31 06:19:48 +02:00
}
2021-09-20 06:39:10 +02:00
function cloneTransaction(e) {
var button = $(e.currentTarget);
var groupId = parseInt(button.data('id'));
$.post(cloneGroupUrl, {
_token: token,
id: groupId
}).done(function (data) {
// lame but it works
location.href = data.redirect;
}).fail(function () {
console.error('I failed :(');
});
return false;
}