//dashboard range date choice in ajax 👍
This commit is contained in:
@@ -25,8 +25,9 @@
|
||||
|
||||
<script>
|
||||
var dashboard_ajax_url = '{$link->getAdminLink('AdminDashboard')}';
|
||||
var adminstats_ajax_url = '{$link->getAdminLink('AdminStats')}';
|
||||
var no_results_translation = '{l s='No result'}';
|
||||
var use_push = 0;
|
||||
var dashboard_use_push = {$dashboard_use_push};
|
||||
</script>
|
||||
|
||||
<div class="page-head">
|
||||
|
||||
@@ -66,6 +66,7 @@ class AdminDashboardControllerCore extends AdminController
|
||||
'hookDashboardZoneTwo' => Hook::exec('dashboardZoneTwo'),
|
||||
'translations' => $translations,
|
||||
'action' => '#',
|
||||
'dashboard_use_push' => Configuration::get('PS_DASHBOARD_USE_PUSH'),
|
||||
'datepickerFrom' => Tools::getValue('datepickerFrom', $this->context->employee->stats_date_from),
|
||||
'datepickerTo' => Tools::getValue('datepickerTo', $this->context->employee->stats_date_to)
|
||||
);
|
||||
@@ -76,12 +77,16 @@ class AdminDashboardControllerCore extends AdminController
|
||||
{
|
||||
$id_module = null;
|
||||
if ($module = Tools::getValue('module'))
|
||||
$id_module = Module::getInstanceByName($module)->id;
|
||||
|
||||
{
|
||||
$module_obj = Module::getInstanceByName($module);
|
||||
if (Validate::isLoadedObject($module_obj))
|
||||
$id_module = $module_obj->id;
|
||||
}
|
||||
|
||||
$params = array(
|
||||
'date_from' => $this->context->employee->stats_date_from,
|
||||
'date_to' => $this->context->employee->stats_date_to,
|
||||
'use_push' => (int)Tools::getValue('use_push')
|
||||
'dashboard_use_push' => (int)Tools::getValue('dashboard_use_push')
|
||||
);
|
||||
|
||||
die(Tools::jsonEncode(Hook::exec('dashboardData', $params, $id_module, true)));
|
||||
|
||||
@@ -194,6 +194,25 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
|
||||
public function postProcess()
|
||||
{
|
||||
$this->context = Context::getContext();
|
||||
|
||||
$this->ajaxProcessSetDashboardDateRange();
|
||||
|
||||
if (Tools::getValue('submitSettings'))
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
{
|
||||
self::$currentIndex .= '&module='.Tools::getValue('module');
|
||||
Configuration::updateValue('PS_STATS_RENDER', Tools::getValue('PS_STATS_RENDER', Configuration::get('PS_STATS_RENDER')));
|
||||
Configuration::updateValue('PS_STATS_GRID_RENDER', Tools::getValue('PS_STATS_GRID_RENDER', Configuration::get('PS_STATS_GRID_RENDER')));
|
||||
Configuration::updateValue('PS_STATS_OLD_CONNECT_AUTO_CLEAN', Tools::getValue('PS_STATS_OLD_CONNECT_AUTO_CLEAN', Configuration::get('PS_STATS_OLD_CONNECT_AUTO_CLEAN')));
|
||||
}
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
|
||||
}
|
||||
}
|
||||
|
||||
public function ajaxProcessSetDashboardDateRange()
|
||||
{
|
||||
if (Tools::isSubmit('submitDatePicker'))
|
||||
{
|
||||
if (!Validate::isDate($from = Tools::getValue('datepickerFrom')) || !Validate::isDate($to = Tools::getValue('datepickerTo')))
|
||||
@@ -239,17 +258,21 @@ abstract class AdminStatsTabControllerCore extends AdminPreferencesControllerCor
|
||||
$this->context->employee->update();
|
||||
Tools::redirectAdmin($_SERVER['REQUEST_URI']);
|
||||
}
|
||||
if (Tools::getValue('submitSettings'))
|
||||
if ($this->isXmlHttpRequest())
|
||||
{
|
||||
if ($this->tabAccess['edit'] === '1')
|
||||
{
|
||||
self::$currentIndex .= '&module='.Tools::getValue('module');
|
||||
Configuration::updateValue('PS_STATS_RENDER', Tools::getValue('PS_STATS_RENDER', Configuration::get('PS_STATS_RENDER')));
|
||||
Configuration::updateValue('PS_STATS_GRID_RENDER', Tools::getValue('PS_STATS_GRID_RENDER', Configuration::get('PS_STATS_GRID_RENDER')));
|
||||
Configuration::updateValue('PS_STATS_OLD_CONNECT_AUTO_CLEAN', Tools::getValue('PS_STATS_OLD_CONNECT_AUTO_CLEAN', Configuration::get('PS_STATS_OLD_CONNECT_AUTO_CLEAN')));
|
||||
}
|
||||
if (is_array($this->errors) && count($this->errors))
|
||||
die(Tools::jsonEncode(array(
|
||||
'has_errors' => true,
|
||||
'errors' => array($this->errors),
|
||||
'date_from' => $this->context->employee->stats_date_from,
|
||||
'date_to' => $this->context->employee->stats_date_to)
|
||||
));
|
||||
else
|
||||
$this->errors[] = Tools::displayError('You do not have permission to edit this.');
|
||||
die(Tools::jsonEncode(array(
|
||||
'has_errors' => false,
|
||||
'date_from' => $this->context->employee->stats_date_from,
|
||||
'date_to' => $this->context->employee->stats_date_to)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+35
-28
@@ -23,34 +23,16 @@
|
||||
*/
|
||||
|
||||
$(document).ready( function () {
|
||||
refreshDashbard();
|
||||
/*
|
||||
if (use_push)
|
||||
launchPush();
|
||||
*/
|
||||
});
|
||||
|
||||
function launchPush()
|
||||
{
|
||||
$.ajax({
|
||||
url : dashboard_ajax_url,
|
||||
data : {
|
||||
ajax:true,
|
||||
action:'refreshDashboard',
|
||||
module:'dashactivity',
|
||||
use_push:1,
|
||||
},
|
||||
dataType: 'json',
|
||||
success : function(widgets){
|
||||
for (var name in widgets)
|
||||
{
|
||||
for (data_type in widgets[name])
|
||||
window[data_type](widgets[name][data_type]);
|
||||
}
|
||||
launchPush();
|
||||
},
|
||||
|
||||
$('#calendar_form input[type="submit"]').on('click', function (elt) {
|
||||
setDashboardDateRange(elt.currentTarget.name);
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
refreshDashbard();
|
||||
if (dashboard_use_push)
|
||||
refreshDashbard();
|
||||
});
|
||||
|
||||
function refreshDashbard(module_name)
|
||||
{
|
||||
@@ -78,7 +60,8 @@ function refreshDashbard(module_name)
|
||||
data : {
|
||||
ajax:true,
|
||||
action:'refreshDashboard',
|
||||
module:module_list[module_id]
|
||||
module:module_list[module_id],
|
||||
dashboard_use_push:dashboard_use_push
|
||||
},
|
||||
dataType: 'json',
|
||||
success : function(widgets){
|
||||
@@ -87,6 +70,8 @@ function refreshDashbard(module_name)
|
||||
for (data_type in widgets[widget_name])
|
||||
window[data_type](widget_name, widgets[widget_name][data_type]);
|
||||
}
|
||||
if (dashboard_use_push)
|
||||
refreshDashbard();
|
||||
},
|
||||
error : function(data){
|
||||
//@TODO display errors
|
||||
@@ -95,6 +80,28 @@ function refreshDashbard(module_name)
|
||||
}
|
||||
}
|
||||
|
||||
function setDashboardDateRange(action)
|
||||
{
|
||||
data = 'ajax=true&action=setDashboardDateRange&submitDatePicker=true&'+$('#calendar_form').serialize()+'&'+action+'=1';
|
||||
$.ajax({
|
||||
url : adminstats_ajax_url,
|
||||
data : data,
|
||||
dataType: 'json',
|
||||
type: 'POST',
|
||||
success : function(jsonData){
|
||||
if (!jsonData.has_errors)
|
||||
{
|
||||
refreshDashbard();
|
||||
$('#datepickerFrom').val(jsonData.date_from);
|
||||
$('#datepickerTo').val(jsonData.date_to);
|
||||
}
|
||||
},
|
||||
error : function(data){
|
||||
//@TODO display errors
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function data_value(widget_name, data)
|
||||
{
|
||||
for (var data_id in data)
|
||||
|
||||
Reference in New Issue
Block a user