[+] BO : new display of payment modules in payment tab

This commit is contained in:
vAugagneur
2013-02-04 18:18:50 +01:00
parent bc203bfc3a
commit 0de5c242ca
15 changed files with 374 additions and 245 deletions
+174 -13
View File
@@ -96,7 +96,13 @@ class AdminControllerCore extends Controller
/** @var array list to be generated */
protected $fields_list;
/** @var array modules list filters */
protected $filter_modules_list = null;
/** @var array modules list filters */
protected $modules_list = array();
/** @var array edit form to be generated */
protected $fields_form;
@@ -227,6 +233,7 @@ class AdminControllerCore extends Controller
protected $action;
protected $display;
protected $_includeContainer = true;
protected $tab_modules_list = array('default_list' => array(), 'slider_list' => array());
public $tpl_folder;
@@ -1016,7 +1023,7 @@ class AdminControllerCore extends Controller
'desc' => $this->l('Add new')
);
}
$this->addToolBarModulesListButton();
}
/**
@@ -1385,6 +1392,7 @@ class AdminControllerCore extends Controller
}
elseif (!$this->ajax)
{
$this->content .= $this->renderModulesList();
$this->content .= $this->renderList();
$this->content .= $this->renderOptions();
@@ -1404,23 +1412,32 @@ class AdminControllerCore extends Controller
*/
protected function initTabModuleList()
{
$tab_modules_list = array();
if (!$this->isFresh(Module::CACHE_FILE_TAB_MODULES_LIST, 604800))
$this->refresh(Module::CACHE_FILE_TAB_MODULES_LIST, 'http://'.Tab::TAB_MODULE_LIST_URL);
$tab_modules_list = Tab::getTabModulesList($this->id);
if ($tab_modules_list)
$this->tab_modules_list = Tab::getTabModulesList($this->id);
if (is_array($this->tab_modules_list['default_list']) && count($this->tab_modules_list['default_list']))
$this->filter_modules_list = $tab_modules_list['default_list'];
else if (is_array($this->tab_modules_list['slider_list']) && count($this->tab_modules_list['slider_list']))
{
$this->addToolBarModulesListButton();
$this->context->smarty->assign(array(
'tab_modules_list' => implode(',', $this->tab_modules_list['slider_list']),
'admin_module_ajax_url' => $this->context->link->getAdminLink('AdminModules'),
'back_tab_modules_list' => $this->context->link->getAdminLink(Tools::getValue('controller')),
'tab_modules_open' => (int)Tools::getValue('tab_modules_open')
));
}
}
protected function addToolBarModulesListButton()
{
if (is_array($this->tab_modules_list['slider_list']) && count($this->tab_modules_list['slider_list']))
$this->toolbar_btn['modules-list'] = array(
'href' => '#',
'desc' => $this->l('Modules List')
);
$this->context->smarty->assign(array(
'tab_modules_list' => implode(',', $tab_modules_list),
'admin_module_ajax_url' => $this->context->link->getAdminLink('AdminModules'),
'back_tab_modules_list' => $this->context->link->getAdminLink(Tools::getValue('controller')),
'tab_modules_open' => (int)Tools::getValue('tab_modules_open')
));
}
/**
@@ -1448,7 +1465,17 @@ class AdminControllerCore extends Controller
'iso_is_fr' => strtoupper($this->context->language->iso_code) == 'FR',
));
}
public function renderModulesList()
{
if ($this->getModulesList($this->filter_modules_list))
{
$helper = new Helper();
return $helper->renderModulesList($this->modules_list);
}
}
/**
* Function used to render the list to display for this controller
*/
@@ -2114,6 +2141,31 @@ class AdminControllerCore extends Controller
else
$this->_listTotal = Db::getInstance()->getValue('SELECT FOUND_ROWS() AS `'._DB_PREFIX_.$this->table.'`');
}
public function getModulesList($filter_modules_list)
{
if (!is_array($filter_modules_list) && !is_null($filter_modules_list))
$filter_modules_list = array($filter_modules_list);
if (!count($filter_modules_list))
return false; //if there is no modules to display just return false;
$all_modules = Module::getModulesOnDisk(true);
$this->modules_list = array();
foreach($all_modules as $module)
{
if (in_array($module->name, $filter_modules_list))
{
$this->fillModuleData($module, 'select');
$this->modules_list[] = $module;
}
}
if (count($this->modules_list))
return true;
return false; //no module found on disk just return false;
}
public function getLanguages()
{
@@ -2811,4 +2863,113 @@ class AdminControllerCore extends Controller
// No content, return false
return false;
}
public function fillModuleData(&$module, $output_type = 'link', $back = null)
{
$obj = null;
if ($module->onclick_option)
$obj = new $module->name();
// Fill module data
$module->logo = '../../img/questionmark.png';
if (file_exists('../modules/'.$module->name.'/logo.gif'))
$module->logo = 'logo.gif';
if (file_exists('../modules/'.$module->name.'/logo.png'))
$module->logo = 'logo.png';
$module->optionsHtml = $this->displayModuleOptions($module, $output_type);
$module->options['install_url'] = self::$currentIndex.'&install='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
$module->options['update_url'] = self::$currentIndex.'&update='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
$module->options['uninstall_url'] = self::$currentIndex.'&uninstall='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name);
$module->options['uninstall_onclick'] = ((!$module->onclick_option) ?
((empty($module->confirmUninstall)) ? '' : 'return confirm(\''.addslashes($module->confirmUninstall).'\');') :
$obj->onclickOption('uninstall', $module->options['uninstall_url']));
if ((Tools::getValue('module_name') == $module->name || in_array($module->name, explode('|', Tools::getValue('modules_list')))) && (int)Tools::getValue('conf') > 0)
$module->message = $this->_conf[(int)Tools::getValue('conf')];
if ((Tools::getValue('module_name') == $module->name || in_array($module->name, explode('|', Tools::getValue('modules_list')))) && (int)Tools::getValue('conf') > 0)
unset($obj);
}
/**
* Display modules list
*
* @param $module
* @param $output_type (link or select)
* @param $back
*
* @return string
*/
protected $translationsTab = array();
public function displayModuleOptions($module, $output_type = 'link', $back = null)
{
if (!isset($this->translationsTab['Disable this module']))
{
$this->translationsTab['Disable this module'] = $this->l('Disable this module');
$this->translationsTab['Enable this module for all shops'] = $this->l('Enable this module for all shops');
$this->translationsTab['Disable'] = $this->l('Disable');
$this->translationsTab['Enable'] = $this->l('Enable');
$this->translationsTab['Reset'] = $this->l('Reset');
$this->translationsTab['Configure'] = $this->l('Configure');
$this->translationsTab['Delete'] = $this->l('Delete');
$this->translationsTab['Install'] = $this->l('Install');
$this->translationsTab['Uninstall'] = $this->l('Uninstall');
$this->translationsTab['This action will permanently remove the module from the server. Are you sure you want to do this?'] = $this->l('This action will permanently remove the module from the server. Are you sure you want to do this?');
}
$modules_options = array(
'configure-module' => array(
'href' => self::$currentIndex.'&configure='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.urlencode($module->name),
'onclick' => $module->onclick_option && isset($module->onclick_option_content['configure']) ? $module->onclick_option_content['configure'] : '',
'title' => '',
'text' => $this->translationsTab['Configure'],
'cond' => $module->id && isset($module->is_configurable) && $module->is_configurable,
),
'desactive-module' => array(
'href' => self::$currentIndex.'&token='.$this->token.'&module_name='.urlencode($module->name).'&'.($module->active ? 'enable=0' : 'enable=1').'&tab_module='.$module->tab,
'onclick' => $module->active && $module->onclick_option && isset($module->onclick_option_content['desactive']) ? $module->onclick_option_content['desactive'] : '' ,
'title' => Shop::isFeatureActive() ? htmlspecialchars($module->active ? $this->translationsTab['Disable this module'] : $this->translationsTab['Enable this module for all shops']) : '',
'text' => $module->active ? $this->translationsTab['Disable'] : $this->translationsTab['Enable'],
'cond' => $module->id,
),
'reset-module' => array(
'href' => self::$currentIndex.'&token='.$this->token.'&module_name='.urlencode($module->name).'&reset&tab_module='.$module->tab,
'onclick' => $module->onclick_option && isset($module->onclick_option_content['reset']) ? $module->onclick_option_content['reset'] : '',
'title' => '',
'text' => $this->translationsTab['Reset'],
'cond' => $module->id && $module->active,
),
'delete-module' => array(
'href' => self::$currentIndex.'&delete='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.urlencode($module->name),
'onclick' => $module->onclick_option && isset($module->onclick_option_content['delete']) ? $module->onclick_option_content['delete'] : 'return confirm(\''.$this->translationsTab['This action will permanently remove the module from the server. Are you sure you want to do this?'].'\');',
'title' => '',
'text' => $this->translationsTab['Delete'],
'cond' => true,
),
);
$return = '';
foreach($modules_options as $option_name => $option)
{
if ($option['cond'])
{
if ($output_type == 'link')
$return .= '<span class="'.$option_name.'">
<a class="action_module" href="'.$option['href'].(!is_null($back) ? '&back='.urlencode($back) : '').'" onclick="'.$option['onclick'].'" title="'.$option['title'].'">'.$option['text'].'</a>
</span>';
else if ($output_type == 'select')
$return .= '<option id="'.$option_name.'" data-href="'.$option['href'].(!is_null($back) ? '&back='.urlencode($back) : '').'" data-onclick="'.$option['onclick'].'">'.$option['text'].'</option>';
}
}
if ($output_type == 'select')
{
if (!$module->id)
$return = '<option data-onclick="" data-href="'.self::$currentIndex.'&install='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name).(!is_null($back) ? '&back='.urlencode($back) : '').'" >'.$this->translationsTab['Install'].'</option>'.$return;
else
$return = '<option data-onclick="" data-href="'.self::$currentIndex.'&uninstall='.urlencode($module->name).'&token='.$this->token.'&tab_module='.$module->tab.'&module_name='.$module->name.'&anchor=anchor'.ucfirst($module->name).(!is_null($back) ? '&back='.urlencode($back) : '').'" >'.$this->translationsTab['Uninstall'].'</option>'.$return;
$return = '<select id="select_'.$module->name.'">'.$return.'</select>';
}
return $return;
}
}