firefly-iii/public/js/firefly.js

115 lines
3.6 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";
// when you click on a currency, this happens:
$('.currency-option').click(currencySelect);
2015-03-02 05:35:14 -06:00
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";
// 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 00:23:26 -06:00
var symbol = target.data('symbol');
// id of the selected currency.
2015-02-06 00:23:26 -06:00
var id = target.data('id');
// update the hidden input:
$('input[name="' + hiddenInputName + '"]').val(id);
2015-02-06 00:23:26 -06:00
// update the symbol:
$('#' + spanId).text(symbol);
// close the menu (hack hack)
$('#' + menuID).click();
2015-02-06 00:23:26 -06:00
return false;
//var code = target.data('code');
//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
}