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

148 lines
3.3 KiB
JavaScript
Raw Normal View History

2016-02-04 17:16:16 +01:00
/*
* index.js
2017-10-21 08:40:00 +02:00
* Copyright (c) 2017 thegrumpydictator@gmail.com
2016-02-04 17:16:16 +01:00
*
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
2017-12-17 14:43:13 +01:00
* along with Firefly III. If not, see <http://www.gnu.org/licenses/>.
2016-02-04 17:16:16 +01:00
*/
/** global: jobKey, Modernizr */
2016-02-04 17:16:16 +01:00
var intervalId = 0;
$(function () {
"use strict";
// on click of export button:
// - hide form
// - post export command
// - start polling progress.
// - return false,
$('#export').submit(startExport);
if (!Modernizr.inputtypes.date) {
$('input[type="date"]').datepicker(
{
dateFormat: 'yy-mm-dd'
}
);
}
2016-02-04 17:16:16 +01:00
}
);
function startExport() {
"use strict";
hideForm();
showLoading();
2016-02-07 09:11:46 +01:00
hideError();
2016-02-04 17:16:16 +01:00
// do export
callExport();
return false;
}
2016-02-07 09:11:46 +01:00
function hideError() {
"use strict";
$('#export-error').hide();
}
2016-02-04 17:16:16 +01:00
function hideForm() {
"use strict";
$('#form-body').hide();
$('#do-export-button').hide();
}
function showForm() {
"use strict";
$('#form-body').show();
$('#do-export-button').show().prop('disabled', false);
// enable button again:
2016-02-04 17:16:16 +01:00
}
function showLoading() {
"use strict";
$('#export-loading').show();
}
function hideLoading() {
"use strict";
$('#export-loading').hide();
}
function showDownload() {
"use strict";
$('#export-download').show();
}
function showError(text) {
"use strict";
2017-08-11 05:42:15 +02:00
$('#export-error').show().find('p').text(text);
2016-02-04 17:16:16 +01:00
}
function callExport() {
"use strict";
var data = $('#export').serialize();
// call status, keep calling it until response is "finished"?
intervalId = window.setInterval(checkStatus, 500);
$.post('export/submit', data, null, 'json').done(function () {
2016-02-04 17:16:16 +01:00
// stop polling:
window.clearTimeout(intervalId);
// call it one last time:
window.setTimeout(checkStatus, 500);
// somewhere here is a download link.
// keep the loading thing, for debug.
hideLoading();
// show download
showDownload();
2017-09-16 07:17:58 +02:00
}).fail(function (jqXHR) {
2016-02-04 17:16:16 +01:00
// show error.
// show form again.
var response = jqXHR.responseJSON;
2017-06-06 19:29:10 +02:00
var errorText = 'The export failed. Please check the log files to find out why.';
if (typeof response === 'object') {
2017-11-15 11:33:07 +01:00
errorText = response.message;
2017-06-06 19:29:10 +02:00
}
showError(errorText);
2016-02-04 17:16:16 +01:00
// stop polling:
window.clearTimeout(intervalId);
hideLoading();
showForm();
});
}
function checkStatus() {
"use strict";
$.getJSON('export/status/' + jobKey).done(function (data) {
putStatusText(data.status);
});
}
function putStatusText(status) {
"use strict";
$('#status-message').text(status);
}