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