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

111 lines
3.7 KiB
JavaScript
Raw Normal View History

2015-09-27 17:45:01 +02:00
/* globals token, dateRangeConfig, $, */
2015-02-06 07:23:26 +01:00
$(function () {
2015-05-24 18:22:41 +02:00
"use strict";
// when you click on a currency, this happens:
$('.currency-option').click(currencySelect);
2015-03-02 12:35:14 +01:00
2015-05-24 18:22:41 +02:00
var ranges = {};
2016-06-11 07:38:30 +02:00
ranges[dateRangeConfig.currentPeriod] = [moment(dateRangeConfig.ranges.current[0]), moment(dateRangeConfig.ranges.current[1])];
ranges[dateRangeConfig.previousPeriod] = [moment(dateRangeConfig.ranges.previous[0]), moment(dateRangeConfig.ranges.previous[1])];
ranges[dateRangeConfig.nextPeriod] = [moment(dateRangeConfig.ranges.next[0]), moment(dateRangeConfig.ranges.next[1])];
2015-09-27 17:45:01 +02:00
// range for everything:
ranges[dateRangeConfig.everything] = [dateRangeConfig.firstDate, moment()];
// build the data range:
$('#daterange').text(dateRangeConfig.linkTitle).daterangepicker(
2015-03-04 09:42:47 +01:00
{
2015-05-21 07:44:44 +02:00
ranges: ranges,
2015-03-04 09:42:47 +01:00
opens: 'left',
2015-05-21 07:44:44 +02:00
locale: {
2015-09-27 17:45:01 +02:00
applyLabel: dateRangeConfig.applyLabel,
cancelLabel: dateRangeConfig.cancelLabel,
fromLabel: dateRangeConfig.fromLabel,
toLabel: dateRangeConfig.toLabel,
2015-05-21 07:44:44 +02:00
weekLabel: 'W',
2015-09-27 17:45:01 +02:00
customRangeLabel: dateRangeConfig.customRangeLabel,
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.
2015-09-27 17:45:01 +02:00
$.post(dateRangeConfig.URL, {
2015-03-04 09:42:47 +01:00
start: start.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD'),
label: label,
_token: token
2016-02-04 07:30:12 +01:00
}).done(function () {
2016-06-11 06:36:46 +02:00
console.log('Succesfully sent new date range [' + start.format('YYYY-MM-DD') + '-' + end.format('YYYY-MM-DD') + '].');
2015-03-04 09:42:47 +01:00
window.location.reload(true);
}).fail(function () {
2016-06-11 07:38:30 +02:00
console.log('Could not send new date range.');
2015-03-04 09:42:47 +01:00
alert('Could not change date range');
});
//alert('A date range was chosen: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD'));
}
);
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)
$('#' + menuID).click();
2015-02-06 07:23:26 +01:00
return false;
2015-03-02 12:35:14 +01:00
}
// Settings object that controls default parameters for library methods:
accounting.settings = {
currency: {
symbol: currencySymbol, // default currency symbol is '$'
format: "%s %v", // 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: "."
}
};