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

131 lines
2.6 KiB
JavaScript
Raw Normal View History

2016-02-04 17:16:16 +01:00
/*
* index.js
2016-04-01 16:46:11 +02:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
2016-02-04 17:16:16 +01:00
*
* This software may be modified and distributed under the terms of the
* Creative Commons Attribution-ShareAlike 4.0 International License.
*
* See the LICENSE file for details.
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();
}
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";
$('#export-error').show();
2017-02-25 05:57:01 +01:00
$('#export-error').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).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();
}).fail(function () {
// show error.
// show form again.
showError('The export failed. Please check the log files to find out why.');
// 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);
}