From a5552f3f85e01464532bbd567dd900be0a2e18f4 Mon Sep 17 00:00:00 2001 From: Damien Metzger Date: Tue, 5 Nov 2013 14:44:31 +0100 Subject: [PATCH] // Improved dashgoals configuration (tmp) --- ...{ajax.php => AdminDashgoalsController.php} | 20 +++-- modules/dashgoals/dashgoals.php | 45 +++++++++-- modules/dashgoals/views/js/dashgoals.js | 16 +++- .../dashgoals/views/templates/hook/config.tpl | 77 +++++++++++++++++++ .../templates/hook/dashboard_zone_two.tpl | 55 +------------ 5 files changed, 146 insertions(+), 67 deletions(-) rename modules/dashgoals/controllers/admin/{ajax.php => AdminDashgoalsController.php} (67%) create mode 100644 modules/dashgoals/views/templates/hook/config.tpl diff --git a/modules/dashgoals/controllers/admin/ajax.php b/modules/dashgoals/controllers/admin/AdminDashgoalsController.php similarity index 67% rename from modules/dashgoals/controllers/admin/ajax.php rename to modules/dashgoals/controllers/admin/AdminDashgoalsController.php index efdc50edf..8f01b57c5 100644 --- a/modules/dashgoals/controllers/admin/ajax.php +++ b/modules/dashgoals/controllers/admin/AdminDashgoalsController.php @@ -25,12 +25,20 @@ * International Registered Trademark & Property of PrestaShop SA */ -class DashGoalsAjaxModuleAdminController extends ModuleAdminController +class AdminDashgoalsController extends ModuleAdminController { - public function initContent() - { - parent::initContent(); - - die ('Todo'); + public function ajaxProcessChangeConfYear() + { + $year = (int)Tools::getValue('year'); + $months = $this->module->setMonths($year); + + $this->context->smarty->assign(array( + 'currency' => $this->context->currency, + 'goals_year' => $year, + 'goals_months' => $months, + 'link' => $this->context->link + )); + + echo $this->module->display(_PS_MODULE_DIR_.$this->module->name.DIRECTORY_SEPARATOR.$this->module->name.'.php', 'config.tpl'); } } \ No newline at end of file diff --git a/modules/dashgoals/dashgoals.php b/modules/dashgoals/dashgoals.php index 6578b156e..ca3f6efb7 100644 --- a/modules/dashgoals/dashgoals.php +++ b/modules/dashgoals/dashgoals.php @@ -73,23 +73,44 @@ class Dashgoals extends Module ConfigurationKPI::updateValue($key, 80); } + // Prepare tab + $tab = new Tab(); + $tab->active = 1; + $tab->class_name = "AdminDashgoals"; + $tab->name = array(); + foreach (Language::getLanguages(true) as $lang) + $tab->name[$lang['id_lang']] = 'Dashgoals'; + $tab->id_parent = -1; + $tab->module = $this->name; + return ( - parent::install() + $tab->add() + && parent::install() && $this->registerHook('dashboardZoneTwo') && $this->registerHook('dashboardData') && $this->registerHook('displayBackOfficeHeader') ); } + + public function uninstall() + { + $id_tab = (int)Tab::getIdFromClassName('AdminDashgoals'); + if ($id_tab) + { + $tab = new Tab($id_tab); + $tab->delete(); + } + return parent::uninstall(); + } public function hookDisplayBackOfficeHeader() { if (get_class($this->context->controller) == 'AdminDashboardController') $this->context->controller->addJs($this->_path.'views/js/'.$this->name.'.js'); } - - public function hookDashboardZoneTwo($params) + + public function setMonths($year) { - $year = date('Y'); $months = array(); for ($i = '01'; $i <= 12; $i = sprintf('%02d', $i + 1)) $months[$i.'_'.$year] = array('label' => Dashgoals::$month_labels[$i], 'values' => array()); @@ -102,10 +123,20 @@ class Dashgoals extends Module ConfigurationKPI::updateValue(strtoupper($key), (float)Tools::getValue($key)); $month_row['values'][$type] = ConfigurationKPI::get(strtoupper($key)); } + return $months; + } - $this->context->smarty->assign('currency', $this->context->currency); - $this->context->smarty->assign('goals_year', $year); - $this->context->smarty->assign('goals_months', $months); + public function hookDashboardZoneTwo($params) + { + $year = date('Y'); + $months = $this->setMonths($year); + + $this->context->smarty->assign(array( + 'currency' => $this->context->currency, + 'goals_year' => $year, + 'goals_months' => $months, + 'dashgoals_ajax_link' => $this->context->link->getAdminLink('AdminDashgoals') + )); return $this->display(__FILE__, 'dashboard_zone_two.tpl'); } diff --git a/modules/dashgoals/views/js/dashgoals.js b/modules/dashgoals/views/js/dashgoals.js index d1cc960d2..8d9ed7c5c 100644 --- a/modules/dashgoals/views/js/dashgoals.js +++ b/modules/dashgoals/views/js/dashgoals.js @@ -42,12 +42,24 @@ function dashgoals_changeYear(xward) function dashgoals_changeConfYear(xward) { - // Todo - // getModuleLink('dashgoals', 'ajax', array('year' => $('#dashgoals_conftitle').text()), $ssl = null, $id_lang = null, $id_shop = null) if (xward == 'forward') $('#dashgoals_conftitle').text(parseInt($('#dashgoals_conftitle').text()) + 1); else if (xward == 'backward') $('#dashgoals_conftitle').text(parseInt($('#dashgoals_conftitle').text()) - 1); + + $.ajax({ + url: dashgoals_ajax_link, + data: { + ajax: true, + action: 'changeconfyear', + year: parseInt($('#dashgoals_conftitle').text()) + }, + success : function(result){ + $('#dashgoals_config').fadeOut(); + $('#dashgoals_config').replaceWith(result); + $('#dashgoals_config').removeClass('hide').fadeIn(); + } + }); } $(document).ready(function() { diff --git a/modules/dashgoals/views/templates/hook/config.tpl b/modules/dashgoals/views/templates/hook/config.tpl new file mode 100644 index 000000000..94ec7fa89 --- /dev/null +++ b/modules/dashgoals/views/templates/hook/config.tpl @@ -0,0 +1,77 @@ +{* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} + +
+
{l s='Configuration' mod='dashgoals'}
+
+ + + + + + + + + + + + {foreach $goals_months as $month} + + + + + + + + {/foreach} + +
+ + {$goals_year} + + {l s='Traffic' mod='dashgoals'}{l s='Conversion Rate' mod='dashgoals'}{l s='Average Cart Value' mod='dashgoals'}{l s='Sales' mod='dashgoals'}
+ {$month.label} + +
+ +
+
+
+ + % +
+
+
+ {$currency->iso_code|escape} + +
+
+
+ +
+
\ No newline at end of file diff --git a/modules/dashgoals/views/templates/hook/dashboard_zone_two.tpl b/modules/dashgoals/views/templates/hook/dashboard_zone_two.tpl index 5e8eab7d0..ae8938c2d 100644 --- a/modules/dashgoals/views/templates/hook/dashboard_zone_two.tpl +++ b/modules/dashgoals/views/templates/hook/dashboard_zone_two.tpl @@ -30,6 +30,8 @@ var priceDisplayPrecision = 0; var dashgoals_year = {$goals_year|intval}; + + var dashgoals_ajax_link = '{$dashgoals_ajax_link|addslashes}';
@@ -46,58 +48,7 @@ -
-
{l s='Configuration' mod='dashgoals'}
-
- - - - - - - - - - - - {foreach $goals_months as $month} - - - - - - - - {/foreach} - -
- - {$goals_year} - - {l s='Traffic' mod='dashgoals'}{l s='Conversion Rate' mod='dashgoals'}{l s='Average Cart Value' mod='dashgoals'}{l s='Sales' mod='dashgoals'}
- {$month.label} - -
- -
-
-
- - % -
-
-
- {$currency->iso_code|escape} - -
-
-
- -
-
+ {include file='./config.tpl'}