mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Some JS to process the report form beforehand.
This commit is contained in:
parent
1fd375b875
commit
16bfbc8a12
@ -16,9 +16,34 @@ $(function () {
|
||||
}
|
||||
);
|
||||
|
||||
// set values from cookies, if any:
|
||||
if (readCookie('report-type') !== null) {
|
||||
$('select[name="report_type"]').val(readCookie('report-type'));
|
||||
}
|
||||
|
||||
if ((readCookie('report-accounts') !== null)) {
|
||||
var arr = readCookie('report-accounts').split(',');
|
||||
arr.forEach(function (val) {
|
||||
$('input[type="checkbox"][value="' + val + '"]').prop('checked', true);
|
||||
});
|
||||
}
|
||||
|
||||
// set date:
|
||||
var startStr = readCookie('report-start');
|
||||
var endStr = readCookie('report-end');
|
||||
if (startStr !== null && endStr !== null && startStr.length == 8 && endStr.length == 8) {
|
||||
var startDate = moment(startStr, "YYYYMMDD");
|
||||
var endDate = moment(endStr, "YYYYMMDD");
|
||||
var datePicker = $('#inputDateRange').data('daterangepicker');
|
||||
datePicker.setStartDate(startDate);
|
||||
datePicker.setEndDate(endDate);
|
||||
}
|
||||
|
||||
$('.openModal').on('click', openModal);
|
||||
|
||||
$('.date-select').on('click',preSelectDate);
|
||||
$('.date-select').on('click', preSelectDate);
|
||||
|
||||
$('#report-form').on('submit', catchSubmit);
|
||||
|
||||
|
||||
// click open the top X income list:
|
||||
@ -27,6 +52,42 @@ $(function () {
|
||||
$('#showExpenses').click(showExpenses);
|
||||
});
|
||||
|
||||
function catchSubmit() {
|
||||
"use strict";
|
||||
// default;20141201;20141231;4;5
|
||||
// report name:
|
||||
var url = '' + $('select[name="report_type"]').val() + ';';
|
||||
|
||||
// date, processed:
|
||||
var picker = $('#inputDateRange').data('daterangepicker');
|
||||
url += moment(picker.startDate).format("YYYYMMDD") + ';';
|
||||
url += moment(picker.endDate).format("YYYYMMDD");
|
||||
|
||||
// all account ids:
|
||||
var count = 0;
|
||||
var accounts = [];
|
||||
$.each($('.account-checkbox'), function (i, v) {
|
||||
var c = $(v);
|
||||
if (c.prop('checked')) {
|
||||
url += ';' + c.val();
|
||||
accounts.push(c.val());
|
||||
count++;
|
||||
}
|
||||
});
|
||||
if (count > 0) {
|
||||
// set cookie to remember choices.
|
||||
createCookie('report-type', $('select[name="report_type"]').val(), 365);
|
||||
createCookie('report-accounts', accounts, 365);
|
||||
createCookie('report-start', moment(picker.startDate).format("YYYYMMDD"), 365);
|
||||
createCookie('report-end', moment(picker.endDate).format("YYYYMMDD"), 365);
|
||||
|
||||
window.location.replace(reportURL + "/" + url);
|
||||
}
|
||||
//console.log(url);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function preSelectDate(e) {
|
||||
"use strict";
|
||||
var link = $(e.target);
|
||||
@ -110,4 +171,32 @@ function showExpenses() {
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function createCookie(name, value, days) {
|
||||
var expires;
|
||||
|
||||
if (days) {
|
||||
var date = new Date();
|
||||
date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
|
||||
expires = "; expires=" + date.toGMTString();
|
||||
} else {
|
||||
expires = "";
|
||||
}
|
||||
document.cookie = encodeURIComponent(name) + "=" + encodeURIComponent(value) + expires + "; path=/";
|
||||
}
|
||||
|
||||
function readCookie(name) {
|
||||
var nameEQ = encodeURIComponent(name) + "=";
|
||||
var ca = document.cookie.split(';');
|
||||
for (var i = 0; i < ca.length; i++) {
|
||||
var c = ca[i];
|
||||
while (c.charAt(0) === ' ') c = c.substring(1, c.length);
|
||||
if (c.indexOf(nameEQ) === 0) return decodeURIComponent(c.substring(nameEQ.length, c.length));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function eraseCookie(name) {
|
||||
createCookie(name, "", -1);
|
||||
}
|
@ -55,7 +55,7 @@
|
||||
</div>
|
||||
<div class="box-body">
|
||||
|
||||
<form class="form-horizontal" action="{{ route('reports.select') }}" method="post">
|
||||
<form class="form-horizontal" id="report-form" action="{{ route('reports.select') }}" method="post">
|
||||
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
|
||||
<div class="form-group">
|
||||
<label for="inputReportType" class="col-sm-3 control-label">Report type</label>
|
||||
@ -73,7 +73,7 @@
|
||||
{% for account in accounts %}
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="accounts[]" value="{{ account.id }}">
|
||||
<input type="checkbox" class="account-checkbox" name="accounts[]" value="{{ account.id }}">
|
||||
{{ account.name }}
|
||||
{% if account.getMeta('accountRole') == 'sharedAsset' %}
|
||||
(shared)
|
||||
@ -131,6 +131,7 @@
|
||||
|
||||
{% block scripts %}
|
||||
<script type="text/javascript">
|
||||
var reportURL = "{{ route('reports.report', ['']) }}";
|
||||
var minDate = "{{ start.format('m/d/Y') }}";
|
||||
var picker;
|
||||
</script>
|
||||
|
Loading…
Reference in New Issue
Block a user