Files
firefly-iii/public/js/ff/firefly.js

162 lines
5.1 KiB
JavaScript
Raw Normal View History

/*
* firefly.js
2017-10-21 08:40:00 +02:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
*
2017-10-21 08:40:00 +02:00
* This file is part of Firefly III.
*
2017-10-21 08:40:00 +02:00
* Firefly III is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Firefly III is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
*/
2017-11-25 08:54:52 +01:00
/** global: moment, token, dateRangeMeta,dateRangeConfig, accountingConfig, accounting, currencySymbol, mon_decimal_point, frac_digits, showFullList, showOnlyTop, mon_thousands_sep */
2015-02-06 07:23:26 +01:00
$(function () {
2015-05-24 18:22:41 +02:00
"use strict";
2017-04-15 07:25:09 +02:00
configAccounting(currencySymbol);
2017-07-14 17:05:32 +02:00
// on submit of form, disable any button in form:
2017-11-01 16:17:14 +01:00
$('form.form-horizontal:not(.nodisablebutton)').on('submit', function () {
2017-08-12 07:47:42 +02:00
$('button[type="submit"]').prop('disabled', true);
2017-07-14 17:05:32 +02:00
});
2017-01-02 08:30:20 +01:00
$.ajaxSetup({
headers: {
'X-CSRF-Token': $('meta[name="_token"]').attr('content')
}
});
// when you click on a currency, this happens:
$('.currency-option').on('click', currencySelect);
2015-03-02 12:35:14 +01:00
2015-09-27 17:45:01 +02:00
// build the data range:
2017-08-10 20:41:33 +02:00
$('#daterange').text(dateRangeMeta.title).daterangepicker(
2015-03-04 09:42:47 +01:00
{
2017-08-10 20:41:33 +02:00
ranges: dateRangeConfig.ranges,
2015-03-04 09:42:47 +01:00
opens: 'left',
2015-05-21 07:44:44 +02:00
locale: {
2017-08-10 20:41:33 +02:00
applyLabel: dateRangeMeta.labels.apply,
cancelLabel: dateRangeMeta.labels.cancel,
fromLabel: dateRangeMeta.labels.from,
toLabel: dateRangeMeta.labels.to,
2015-05-21 07:44:44 +02:00
weekLabel: 'W',
2017-08-10 20:41:33 +02:00
customRangeLabel: dateRangeMeta.labels.customRange,
2015-05-21 07:44:44 +02:00
daysOfWeek: moment.weekdaysMin(),
monthNames: moment.monthsShort(),
firstDay: moment.localeData()._week.dow
},
2015-09-27 17:45:01 +02:00
format: 'YYYY-MM-DD',
startDate: dateRangeConfig.startDate,
endDate: dateRangeConfig.endDate
2015-03-04 09:42:47 +01:00
},
function (start, end, label) {
// send post.
2017-08-10 20:41:33 +02:00
$.post(dateRangeMeta.uri, {
2015-03-04 09:42:47 +01:00
start: start.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD'),
2017-10-29 20:02:34 +01:00
label: label,
_token: token
2016-02-04 07:30:12 +01:00
}).done(function () {
2015-03-04 09:42:47 +01:00
window.location.reload(true);
}).fail(function () {
alert('Could not change date range');
});
}
);
2015-02-06 07:23:26 +01:00
2016-11-17 20:02:55 +01:00
// trigger list thing
listLengthInitial();
2015-02-06 07:23:26 +01:00
});
function currencySelect(e) {
2015-05-24 18:22:41 +02:00
"use strict";
// clicked on
var target = $(e.target); // target is the <A> tag.
// name of the field in question:
var name = target.data('name');
// id of menu button (used later on):
var menuID = 'currency_dropdown_' + name;
// the hidden input with the actual value of the selected currency:
var hiddenInputName = 'amount_currency_id_' + target.data('name');
// span with the current selection (next to the caret):
var spanId = 'currency_select_symbol_' + target.data('name');
// the selected currency symbol:
2015-02-06 07:23:26 +01:00
var symbol = target.data('symbol');
// id of the selected currency.
2015-02-06 07:23:26 +01:00
var id = target.data('id');
// update the hidden input:
$('input[name="' + hiddenInputName + '"]').val(id);
2015-02-06 07:23:26 +01:00
// update the symbol:
$('#' + spanId).text(symbol);
// close the menu (hack hack)
2017-03-03 18:19:25 +01:00
$('#' + menuID).dropdown('toggle');
2015-02-06 07:23:26 +01:00
return false;
2015-03-02 12:35:14 +01:00
}
2017-04-15 07:25:09 +02:00
function configAccounting(customCurrency) {
2016-11-17 20:02:55 +01:00
2017-04-15 07:25:09 +02:00
// Settings object that controls default parameters for library methods:
accounting.settings = {
currency: {
symbol: customCurrency, // default currency symbol is '$'
format: accountingConfig, // controls output: %s = symbol, %v = value/number (can be object: see below)
decimal: mon_decimal_point, // decimal point separator
thousand: mon_thousands_sep, // thousands separator
precision: frac_digits // decimal places
},
number: {
precision: 0, // default precision on numbers is 0
thousand: ",",
decimal: "."
}
};
}
2016-11-17 20:02:55 +01:00
function listLengthInitial() {
"use strict";
$('.overListLength').hide();
$('.listLengthTrigger').unbind('click').click(triggerList)
}
function triggerList(e) {
"use strict";
var link = $(e.target);
var table = link.parent().parent().parent().parent();
if (table.attr('data-hidden') === 'no') {
// hide all elements, return false.
table.find('.overListLength').hide();
table.attr('data-hidden', 'yes');
link.text(showFullList);
return false;
}
// show all, return false
table.find('.overListLength').show();
table.attr('data-hidden', 'no');
link.text(showOnlyTop);
return false;
}