mirror of
https://github.com/pandorafms/pandorafms.git
synced 2025-07-30 01:05:39 +02:00
WIP:Prepare download control
This commit is contained in:
parent
b6055908ae
commit
14745a9625
@ -6269,3 +6269,33 @@ 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
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
function setDownloadCookieToken()
|
||||
{
|
||||
$token = 'downloadToken';
|
||||
|
||||
setCookieToken($token, $_GET[$token], false, false);
|
||||
}
|
||||
|
@ -763,3 +763,68 @@ function getGroupIcon(id_group, img_container) {
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/* Prepare download control */
|
||||
function getCookie(name) {
|
||||
var parts = document.cookie.split(name + "=");
|
||||
if (parts.length == 2)
|
||||
return parts
|
||||
.pop()
|
||||
.split(";")
|
||||
.shift();
|
||||
}
|
||||
|
||||
function expireCookie(cName) {
|
||||
document.cookie =
|
||||
encodeURIComponent(cName) +
|
||||
"=deleted; expires=" +
|
||||
new Date(0).toUTCString();
|
||||
}
|
||||
|
||||
function setCursor(buttonStyle, button) {
|
||||
button.css("cursor", buttonStyle);
|
||||
}
|
||||
|
||||
function setFormToken(button) {
|
||||
var downloadToken = new Date().getTime();
|
||||
button.append("<input type='hidden' id='downloadToken'");
|
||||
$("#downloadToken").val(downloadToken);
|
||||
return downloadToken;
|
||||
}
|
||||
|
||||
var downloadTimer;
|
||||
var attempts = 30;
|
||||
|
||||
// Prevents double-submits by waiting for a cookie from the server.
|
||||
function blockResubmit(button) {
|
||||
var downloadToken = setFormToken(button);
|
||||
setCursor("wait", button);
|
||||
|
||||
// Disable butoon to prevent clicking until download is ready.
|
||||
button.disable();
|
||||
|
||||
//Show dialog.
|
||||
confirmDialog({
|
||||
title: get_php_value("prepareDownloadTitle"),
|
||||
message: get_php_value("prepareDownloadMsg"),
|
||||
hideCancelButton: true
|
||||
});
|
||||
|
||||
downloadTimer = window.setInterval(function() {
|
||||
var token = getCookie("downloadToken");
|
||||
|
||||
if (token == downloadToken || attempts == 0) {
|
||||
unblockSubmit();
|
||||
}
|
||||
|
||||
attempts--;
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
function unblockSubmit(button) {
|
||||
setCursor("pointer", button);
|
||||
button.enable();
|
||||
window.clearInterval(downloadTimer);
|
||||
expireCookie("downloadToken");
|
||||
attempts = 30;
|
||||
}
|
||||
|
@ -23,4 +23,8 @@ html_print_div(['id' => 'forced_title_layer', 'class' => 'forced_title_layer', '
|
||||
set_js_value('absolute_homeurl', ui_get_full_url(false, false, false, false));
|
||||
set_js_value('homeurl', $config['homeurl']);
|
||||
set_js_value('homedir', $config['homedir'].'/');
|
||||
// Prevent double request message.
|
||||
set_js_value('prepareDownloadTitle', __('Generating content'));
|
||||
set_js_value('prepareDownloadMsg', __('Generating content, please wait'));
|
||||
|
||||
// ======================================================================
|
||||
|
Loading…
x
Reference in New Issue
Block a user