Export in ajax

This commit is contained in:
Michael RICOIS 2018-02-01 17:39:33 +01:00
parent 1ae7e28abe
commit e73277ec38
3 changed files with 29 additions and 9 deletions

View File

@ -33,9 +33,13 @@ class AdminStatsLogistic extends AdminTab
parent::__construct();
}
public function postProcess()
public function ajaxProcess()
{
global $currentIndex, $cookie;
global $cookie;
if (!$cookie->isLoggedBack()) {
exit;
}
// Téléchargement fichier
if (Tools::getValue('dl')) {
@ -58,6 +62,11 @@ class AdminStatsLogistic extends AdminTab
}
exit;
}
}
public function postProcess()
{
global $currentIndex, $cookie;
if (Tools::getValue('submitExport')) {
$this->date_export_begin = Tools::getValue('date_export_begin', $this->date_export_begin);

View File

@ -11,8 +11,8 @@ switch ($action) {
$path = dirname(__FILE__) . '/export';
$file = $path . '/' . $filename;
if (file_exists($file)) {
echo '<a href="http://'.$_SERVER['SERVER_NAME'].'/adm/index.php?tab=AdminStatsLogistic&token='.
Tools::getValue('token').'&dl=1&file='.$filename.'" target="_blank">Télécharger le fichier</a>';
echo '<a href="./ajax-tab.php?tab=AdminStatsLogistic&ajax=1&token='.
Tools::getValue('token').'&dl=1&file='.$filename.'" target="_blank">Télécharger le fichier '.$filename.'</a>';
} else {
echo "";
}
@ -26,7 +26,7 @@ switch ($action) {
if (empty($start) || empty($end)) {
$url = '';
} else {
$url = 'http://'.$_SERVER['SERVER_NAME'].__PS_BASE_URI__.
$url = Tools::getCurrentUrlProtocolPrefix() . Tools::getShopDomain() . '/' .
'modules/stats_logistic/ajax.php?action=check&token='.Tools::getValue('token');
}
@ -40,6 +40,8 @@ switch ($action) {
));
break;
case 'dl':
default:
exit;

View File

@ -2,29 +2,38 @@ $(function(){
var timer;
var delay = 1000;
var count = 0;
var countMax = 300;
var url;
var file;
function checkFile()
{
count++;
$('#msg').text('Construction du fichier...('+ count +')...');
if (count > countMax) {
clearInterval(timer);
$('input#submitExport').removeAttr('disabled');
count = 0;
$('#msg').html("Génération du fichier interrompu, délai max dépassé !");
}
$('#msg').text("Construction du fichier...("+ count +")...");
$.post(url, {count: count, file: file}, function (data, textStatus) {
if (data != '') {
clearInterval(timer);
$('input#submitExport').removeAttr('disabled');
count = 0;
$('#msg').html(data);
}
});
}
$('form').submit(function(e) {
e.preventDefault();
$('form').submit(function(e) {
e.preventDefault();
$(this).find('input#submitExport').attr('disabled', 'disabled');
url = $(this).attr('action');
console.log(url);
console.log($(this).serialize());
$.post(url, $(this).serialize(), function (data, textStatus) {
if (data.url != '') {
if (data.url != '') {
url = data.url;
file = data.file;
timer = setInterval(checkFile, delay);