WIP: Download wait message
This commit is contained in:
parent
14745a9625
commit
d525cb594c
|
@ -1055,7 +1055,7 @@ switch ($action) {
|
|||
]
|
||||
);
|
||||
$data[2] .= '</a>';
|
||||
$data[3] = '<a href="'.ui_get_full_url(false, false, false, false).'ajax.php?page='.$config['homedir'].'/operation/reporting/reporting_xml&id='.$report['id_report'].'">';
|
||||
$data[3] = '<a onclick="blockResubmit($(this))" href="'.ui_get_full_url(false, false, false, false).'ajax.php?page='.$config['homedir'].'/operation/reporting/reporting_xml&id='.$report['id_report'].'">';
|
||||
$data[3] .= html_print_image(
|
||||
'images/xml.png',
|
||||
true,
|
||||
|
|
|
@ -506,6 +506,7 @@ class ModuleTemplates extends HTML
|
|||
header('Content-Disposition: attachment; filename='.preg_replace('/\s/', '_', $fileName).'.csv');
|
||||
header('Pragma: no-cache');
|
||||
header('Expires: 0');
|
||||
setDownloadCookieToken();
|
||||
|
||||
// Clean up output buffering
|
||||
while (@ob_end_clean()) {
|
||||
|
@ -931,7 +932,7 @@ class ModuleTemplates extends HTML
|
|||
]
|
||||
);
|
||||
$data[3] = '<a href="'.$this->baseUrl.'&action=delete&id_np='.$row['id_np'].'" onclick="if (!confirm(\''.__('Are you sure?').'\')) return false;">'.html_print_image('images/cross.png', true, ['title' => __('Delete'), 'class' => 'invert_filter']).'</a>';
|
||||
$data[3] .= '<a href="'.$this->baseUrl.'&action=export&id_np='.$row['id_np'].'">'.html_print_image('images/csv.png', true, ['title' => __('Export to CSV'), 'class' => 'invert_filter']).'</a>';
|
||||
$data[3] .= '<a href="'.$this->baseUrl.'&action=export&id_np='.$row['id_np'].'" onclick="blockResubmit($(this))">'.html_print_image('images/csv.png', true, ['title' => __('Export to CSV'), 'class' => 'invert_filter']).'</a>';
|
||||
|
||||
array_push($table->data, $data);
|
||||
}
|
||||
|
|
|
@ -6271,31 +6271,22 @@ function arrayOutputSorting($sort, $sortField)
|
|||
}
|
||||
|
||||
|
||||
function setCookieToken($cookieName, $cookieValue, $httpOnly=true, $secure=false)
|
||||
{
|
||||
// See: http://stackoverflow.com/a/1459794/59087
|
||||
// See: http://shiflett.org/blog/2006/mar/server-name-versus-http-host
|
||||
// See: http://stackoverflow.com/a/3290474/59087
|
||||
setcookie(
|
||||
$cookieName,
|
||||
$cookieValue,
|
||||
2147483647,
|
||||
// expires January 1, 2038
|
||||
'/',
|
||||
// your path
|
||||
$_SERVER['HTTP_HOST'],
|
||||
// your domain
|
||||
$secure,
|
||||
// Use true over HTTPS
|
||||
$httpOnly
|
||||
// Set true for $AUTH_COOKIE_NAME
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get dowload started cookie from js and set ready cokkie for download ready comntrol.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
function setDownloadCookieToken()
|
||||
{
|
||||
$token = 'downloadToken';
|
||||
|
||||
setCookieToken($token, $_GET[$token], false, false);
|
||||
$download_cookie = get_cookie('downloadToken', false);
|
||||
if ($download_cookie === false) {
|
||||
return;
|
||||
} else {
|
||||
setcookie(
|
||||
'downloadReady',
|
||||
$download_cookie,
|
||||
(time() + 15),
|
||||
'/'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -46,6 +46,8 @@ function reporting_xml_get_report($report, $filename, $return=false)
|
|||
|
||||
// Download if marked to download.
|
||||
if ($filename !== false) {
|
||||
// Cookie for download control.
|
||||
setDownloadCookieToken();
|
||||
header('Content-Type: application/xml; charset=UTF-8');
|
||||
header('Content-Disposition: attachment; filename="'.$filename.'.xml"');
|
||||
}
|
||||
|
|
|
@ -3540,6 +3540,9 @@ function ui_print_datatable(array $parameters)
|
|||
titleAttr: "'.__('Export current page to CSV').'",
|
||||
title: "export_'.$parameters['id'].'_current_page_'.date('Y-m-d').'",
|
||||
fieldSeparator: "'.$config['csv_divider'].'",
|
||||
action: function ( e, dt, node, config ) {
|
||||
blockResubmit(node);
|
||||
},
|
||||
exportOptions : {
|
||||
modifier : {
|
||||
// DataTables core
|
||||
|
@ -3547,7 +3550,7 @@ function ui_print_datatable(array $parameters)
|
|||
page : "All",
|
||||
search : "applied"
|
||||
}'.$export_columns.'
|
||||
}
|
||||
},
|
||||
}
|
||||
] : [],
|
||||
lengthMenu: '.json_encode($pagination_options).',
|
||||
|
|
|
@ -51,6 +51,9 @@ $default_filename = 'data_exported - '.date($config['date_format']);
|
|||
$filename = (string) get_parameter('filename', $default_filename);
|
||||
$filename = io_safe_output($filename);
|
||||
|
||||
// Set cookie for download control.
|
||||
setDownloadCookieToken();
|
||||
|
||||
/*
|
||||
* $data = array(
|
||||
* 'head' => array(<column>,<column>,...,<column>),
|
||||
|
|
|
@ -2716,6 +2716,7 @@ function pandoraFlotArea(
|
|||
|
||||
$("#menu_export_csv_" + graph_id).click(function(e) {
|
||||
e.preventDefault();
|
||||
blockResubmit($(this));
|
||||
plot.exportDataCSV();
|
||||
var es_firefox =
|
||||
navigator.userAgent.toLowerCase().indexOf("firefox") > -1;
|
||||
|
|
|
@ -456,8 +456,7 @@ function load_modal(settings) {
|
|||
// Function that shows a dialog box to confirm closures of generic manners.
|
||||
// The modal id is random.
|
||||
// eslint-disable-next-line no-unused-vars
|
||||
function confirmDialog(settings) {
|
||||
var randomStr = uniqId();
|
||||
function confirmDialog(settings, idDialog = uniqId()) {
|
||||
var hideOkButton = "";
|
||||
var hideCancelButton = "";
|
||||
|
||||
|
@ -487,11 +486,11 @@ function confirmDialog(settings) {
|
|||
|
||||
if (typeof settings.message == "function") {
|
||||
$("body").append(
|
||||
'<div id="confirm_' + randomStr + '">' + settings.message() + "</div>"
|
||||
'<div id="confirm_' + idDialog + '">' + settings.message() + "</div>"
|
||||
);
|
||||
} else {
|
||||
$("body").append(
|
||||
'<div id="confirm_' + randomStr + '">' + settings.message + "</div>"
|
||||
'<div id="confirm_' + idDialog + '">' + settings.message + "</div>"
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -542,8 +541,8 @@ function confirmDialog(settings) {
|
|||
buttons.unshift(newButton);
|
||||
}
|
||||
|
||||
$("#confirm_" + randomStr);
|
||||
$("#confirm_" + randomStr)
|
||||
$("#confirm_" + idDialog);
|
||||
$("#confirm_" + idDialog)
|
||||
.dialog({
|
||||
open: settings.open,
|
||||
title: settings.title,
|
||||
|
@ -785,10 +784,11 @@ function setCursor(buttonStyle, button) {
|
|||
button.css("cursor", buttonStyle);
|
||||
}
|
||||
|
||||
function setFormToken(button) {
|
||||
function setToken() {
|
||||
var downloadToken = new Date().getTime();
|
||||
button.append("<input type='hidden' id='downloadToken'");
|
||||
$("#downloadToken").val(downloadToken);
|
||||
document.cookie =
|
||||
"downloadToken" + "=" + downloadToken + ";" + "-1" + ";path=/";
|
||||
|
||||
return downloadToken;
|
||||
}
|
||||
|
||||
|
@ -797,24 +797,28 @@ var attempts = 30;
|
|||
|
||||
// Prevents double-submits by waiting for a cookie from the server.
|
||||
function blockResubmit(button) {
|
||||
var downloadToken = setFormToken(button);
|
||||
var downloadToken = setToken();
|
||||
setCursor("wait", button);
|
||||
|
||||
// Disable butoon to prevent clicking until download is ready.
|
||||
button.disable();
|
||||
button.click(false);
|
||||
|
||||
//Show dialog.
|
||||
confirmDialog({
|
||||
title: get_php_value("prepareDownloadTitle"),
|
||||
message: get_php_value("prepareDownloadMsg"),
|
||||
hideCancelButton: true
|
||||
});
|
||||
confirmDialog(
|
||||
{
|
||||
title: get_php_value("prepareDownloadTitle"),
|
||||
message: get_php_value("prepareDownloadMsg"),
|
||||
hideCancelButton: true
|
||||
},
|
||||
"downloadDialog"
|
||||
);
|
||||
|
||||
downloadTimer = window.setInterval(function() {
|
||||
var token = getCookie("downloadToken");
|
||||
downloadTimer = setInterval(function() {
|
||||
var downloadReady = getCookie("downloadReady");
|
||||
|
||||
if (token == downloadToken || attempts == 0) {
|
||||
unblockSubmit();
|
||||
if (downloadToken == downloadReady || attempts == 0) {
|
||||
unblockSubmit(button);
|
||||
}
|
||||
|
||||
attempts--;
|
||||
|
@ -824,7 +828,10 @@ function blockResubmit(button) {
|
|||
function unblockSubmit(button) {
|
||||
setCursor("pointer", button);
|
||||
button.enable();
|
||||
window.clearInterval(downloadTimer);
|
||||
button.on("click");
|
||||
clearInterval(downloadTimer);
|
||||
$("#confirm_downloadDialog").dialog("close");
|
||||
expireCookie("downloadToken");
|
||||
expireCookie("downloadReady");
|
||||
attempts = 30;
|
||||
}
|
||||
|
|
|
@ -1428,7 +1428,7 @@ if ($pure) {
|
|||
|
||||
// CSV.
|
||||
$csv['active'] = false;
|
||||
$csv['text'] = '<a class="events_link" href="'.ui_get_full_url(false, false, false, false).'operation/events/export_csv.php?'.($filter_b64 ?? '').'">'.html_print_image(
|
||||
$csv['text'] = '<a class="events_link" onclick="blockResubmit($(this))" href="'.ui_get_full_url(false, false, false, false).'operation/events/export_csv.php?'.($filter_b64 ?? '').'">'.html_print_image(
|
||||
'images/csv.png',
|
||||
true,
|
||||
[
|
||||
|
|
|
@ -150,6 +150,7 @@ $now = date('Y-m-d');
|
|||
// Download header.
|
||||
header('Content-type: text/txt');
|
||||
header('Content-Disposition: attachment; filename="export_events_'.$now.'.csv"');
|
||||
setDownloadCookieToken();
|
||||
|
||||
try {
|
||||
$fb64 = get_parameter('fb64', null);
|
||||
|
|
|
@ -9478,6 +9478,8 @@ class Mpdf implements \Psr\Log\LoggerAwareInterface
|
|||
function Output($name = '', $dest = '')
|
||||
{
|
||||
$this->logger->debug(sprintf('PDF generated in %.6F seconds', microtime(true) - $this->time0), ['context' => LogContext::STATISTICS]);
|
||||
// Set cokie token to indicate download is ready.
|
||||
setDownloadCookieToken();
|
||||
|
||||
// Finish document if necessary
|
||||
if ($this->state < 3) {
|
||||
|
|
Loading…
Reference in New Issue