From e73277ec386d31064b86aae462c582b6bfd6363b Mon Sep 17 00:00:00 2001 From: Michael RICOIS Date: Thu, 1 Feb 2018 17:39:33 +0100 Subject: [PATCH] Export in ajax --- modules/stats_logistic/AdminStatsLogistic.php | 13 +++++++++++-- modules/stats_logistic/ajax.php | 8 +++++--- modules/stats_logistic/views/js/export.js | 17 +++++++++++++---- 3 files changed, 29 insertions(+), 9 deletions(-) diff --git a/modules/stats_logistic/AdminStatsLogistic.php b/modules/stats_logistic/AdminStatsLogistic.php index a8303c01..c49abf76 100755 --- a/modules/stats_logistic/AdminStatsLogistic.php +++ b/modules/stats_logistic/AdminStatsLogistic.php @@ -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); diff --git a/modules/stats_logistic/ajax.php b/modules/stats_logistic/ajax.php index 9a7275a3..f8c44b39 100644 --- a/modules/stats_logistic/ajax.php +++ b/modules/stats_logistic/ajax.php @@ -11,8 +11,8 @@ switch ($action) { $path = dirname(__FILE__) . '/export'; $file = $path . '/' . $filename; if (file_exists($file)) { - echo 'Télécharger le fichier'; + echo 'Télécharger le fichier '.$filename.''; } 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; diff --git a/modules/stats_logistic/views/js/export.js b/modules/stats_logistic/views/js/export.js index 2bab0e3d..c212eb62 100644 --- a/modules/stats_logistic/views/js/export.js +++ b/modules/stats_logistic/views/js/export.js @@ -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);