firefly-iii/public/js/firefly.js

83 lines
2.7 KiB
JavaScript
Raw Normal View History

2015-09-27 10:45:01 -05:00
/* globals token, dateRangeConfig, $, */
2015-02-06 00:23:26 -06:00
$(function () {
2015-05-24 11:22:41 -05:00
"use strict";
2015-03-02 05:35:14 -06:00
$('.currencySelect').click(currencySelect);
2015-05-24 11:22:41 -05:00
var ranges = {};
2015-09-27 10:45:01 -05:00
// range for the current month:
ranges[dateRangeConfig.currentMonth] = [moment().startOf('month'), moment().endOf('month')];
// range for the previous month:
ranges[dateRangeConfig.previousMonth] = [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')];
// range for the next month:
ranges[dateRangeConfig.nextMonth] = [moment().add(1, 'month').startOf('month'), moment().add(1, 'month').endOf('month')];
// range for everything:
ranges[dateRangeConfig.everything] = [dateRangeConfig.firstDate, moment()];
// build the data range:
$('#daterange').text(dateRangeConfig.linkTitle).daterangepicker(
2015-03-04 02:42:47 -06:00
{
2015-05-21 00:44:44 -05:00
ranges: ranges,
2015-03-04 02:42:47 -06:00
opens: 'left',
2015-05-21 00:44:44 -05:00
locale: {
2015-09-27 10:45:01 -05:00
applyLabel: dateRangeConfig.applyLabel,
cancelLabel: dateRangeConfig.cancelLabel,
fromLabel: dateRangeConfig.fromLabel,
toLabel: dateRangeConfig.toLabel,
2015-05-21 00:44:44 -05:00
weekLabel: 'W',
2015-09-27 10:45:01 -05:00
customRangeLabel: dateRangeConfig.customRangeLabel,
2015-05-21 00:44:44 -05:00
daysOfWeek: moment.weekdaysMin(),
monthNames: moment.monthsShort(),
firstDay: moment.localeData()._week.dow
},
2015-09-27 10:45:01 -05:00
format: 'YYYY-MM-DD',
startDate: dateRangeConfig.startDate,
endDate: dateRangeConfig.endDate
2015-03-04 02:42:47 -06:00
},
function (start, end, label) {
// send post.
2015-09-27 10:45:01 -05:00
$.post(dateRangeConfig.URL, {
2015-03-04 02:42:47 -06:00
start: start.format('YYYY-MM-DD'),
end: end.format('YYYY-MM-DD'),
label: label,
_token: token
}).success(function () {
2015-08-16 14:18:12 -05:00
console.log('Succesfully sent new date range.');
2015-03-04 02:42:47 -06:00
window.location.reload(true);
}).fail(function () {
2015-08-16 14:18:12 -05:00
console.log('Could not send new date range.');
2015-03-04 02:42:47 -06: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 00:23:26 -06:00
});
function currencySelect(e) {
2015-05-24 11:22:41 -05:00
"use strict";
2015-02-06 00:23:26 -06:00
var target = $(e.target);
var symbol = target.data('symbol');
var code = target.data('code');
var id = target.data('id');
var fieldType = target.data('field');
var menu = $('.' + fieldType + 'CurrencyDropdown');
var symbolHolder = $('#' + fieldType + 'CurrentSymbol');
symbolHolder.text(symbol);
$('input[name="' + fieldType + '_currency_id"]').val(id);
// close dropdown (hack hack)
menu.click();
return false;
2015-03-02 05:35:14 -06:00
}