This commit is contained in:
Jerome Nadaud
2013-09-12 14:47:47 +02:00
parent 91d3da310b
commit e63ce0a86d
12 changed files with 464 additions and 41 deletions
+7 -18
View File
@@ -139,7 +139,7 @@ class HelperFormCore extends Helper
case 'shop' :
$disable_shops = isset($params['disable_shared']) ? $params['disable_shared'] : false;
$params['html'] = $this->renderAssoShop($disable_shops);
$params['html'] = $this->renderAssoShop($params['tree'], $disable_shops);
if (Shop::getTotalShops(false) == 1)
unset($this->fields_form[$fieldset_key]['form']['input'][$key]);
break;
@@ -192,7 +192,7 @@ class HelperFormCore extends Helper
*
* @return string
*/
public function renderAssoShop($disable_shared = false)
public function renderAssoShop($params, $disable_shared = false)
{
if (!Shop::isFeatureActive())
return;
@@ -227,27 +227,16 @@ class HelperFormCore extends Helper
}
}
$tpl = $this->createTemplate('assoshop.tpl');
$tree = Shop::getTree();
$nb_shop = 0;
foreach ($tree as &$value)
{
$value['disable_shops'] = (isset($value[$disable_shared]) && $value[$disable_shared]);
$nb_shop += count($value['shops']);
}
$tpl->assign(array(
'input' => array(
'type' => 'shop',
'values' => $tree,
),
'fields_value' => array(
'shop' => $assos
),
'form_id' => $this->id,
'table' => $this->table,
'nb_shop' => $nb_shop
));
return $tpl->fetch();
$tree = new HelperTreeShops($params['id'],
isset($params['title']) ? $params['title'] : null);
$tree->setSelectedShops($assos);
return $tree->render();
}
}
+2 -2
View File
@@ -24,7 +24,7 @@
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperTreeCategories extends TreeCore
class HelperTreeCategoriesCore extends TreeCore
{
const DEFAULT_TEMPLATE = 'tree_categories.tpl';
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder_radio.tpl';
@@ -237,7 +237,7 @@ class HelperTreeCategories extends TreeCore
if ($this->useSearch())
{
$this->addAction(new TreeToolbarSearch(
$this->addAction(new TreeToolbarSearchCategories(
'Find a category:',
$this->getId().'-categories-search')
);
+174
View File
@@ -0,0 +1,174 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperTreeShopsCore extends TreeCore
{
const DEFAULT_TEMPLATE = 'tree_shops.tpl';
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder_checkbox.tpl';
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item_checkbox.tpl';
private $_lang;
private $_selected_shops;
public function __construct($id, $title = null, $lang = null)
{
parent::__construct($id);
if (isset($title))
$this->setTitle($title);
$this->setLang($lang);
}
public function getData()
{
if (!isset($this->_data))
$this->setData(Shop::getTree());
return $this->_data;
}
public function setLang($value)
{
$this->_lang = $value;
return $this;
}
public function getLang()
{
if (!isset($this->_lang))
$this->setLang($this->getContext()->employee->id_lang);
return $this->_lang;
}
public function getNodeFolderTemplate()
{
if (!isset($this->_node_folder_template))
$this->setNodeFolderTemplate(self::DEFAULT_NODE_FOLDER_TEMPLATE);
return $this->_node_folder_template;
}
public function getNodeItemTemplate()
{
if (!isset($this->_node_item_template))
$this->setNodeItemTemplate(self::DEFAULT_NODE_ITEM_TEMPLATE);
return $this->_node_item_template;
}
public function setSelectedShops($value)
{
if (!is_array($value))
throw new PrestaShopException('Selected shops value must be an array');
$this->_selected_shops = $value;
return $this;
}
public function getSelectedShops()
{
if (!isset($this->_selected_shops))
$this->_selected_shops = array();
return $this->_selected_shops;
}
public function getTemplate()
{
if (!isset($this->_template))
$this->setTemplate(self::DEFAULT_TEMPLATE);
return $this->_template;
}
public function render($data = NULL)
{
if (!isset($data))
$data = $this->getData();
$this->setActions(array(
new TreeToolbarLink(
'Collapse All',
'#',
'$(\'#'.$this->getId().'\').tree(\'collapseAll\')',
'icon-collapse-alt'),
new TreeToolbarLink(
'Expand All',
'#',
'$(\'#'.$this->getId().'\').tree(\'expandAll\')',
'icon-expand-alt'),
new TreeToolbarLink(
'Check All',
'#',
'checkAllAssociatedShops($(\'#'.$this->getId().'\'));',
'icon-check-sign'),
new TreeToolbarLink(
'Uncheck All',
'#',
'uncheckAllAssociatedShops($(\'#'.$this->getId().'\'));',
'icon-check-empty')
)
);
$this->setAttribute('selected_shops', $this->getSelectedShops());
return parent::render($data);
}
public function renderNodes($data = null)
{
if (!isset($data))
$data = $this->getData();
if (!is_array($data) && !$data instanceof Traversable)
throw new PrestaShopException('Data value must be an traversable array');
$html = '';
foreach ($data as $item)
{
if (array_key_exists('shops', $item)
&& !empty($item['shops']))
$html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getNodeFolderTemplate()),
$this->getContext()->smarty
)->assign(array(
'children' => $this->renderNodes($item['shops']),
'node' => $item
))->fetch();
else
$html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getNodeItemTemplate()),
$this->getContext()->smarty
)->assign(array(
'node' => $item
))->fetch();
}
return $html;
}
}
+15 -15
View File
@@ -73,15 +73,6 @@ class TreeCore
return $this->getToolbar()->getActions();
}
public function addAction($action)
{
if (!isset($this->_toolbar))
$this->setToolbar(new TreeToolbarCore());
$this->getToolbar()->addAction($action);
return $this;
}
public function setAttribute($name, $value)
{
if (!isset($this->_attributes))
@@ -297,14 +288,13 @@ class TreeCore
return $this->_toolbar;
}
public function useInput()
public function addAction($action)
{
return isset($this->_input_type);
}
if (!isset($this->_toolbar))
$this->setToolbar(new TreeToolbarCore());
public function useToolbar()
{
return isset($this->_toolbar);
$this->getToolbar()->addAction($action);
return $this;
}
public function render($data = null)
@@ -395,6 +385,16 @@ class TreeCore
return $this->getToolbar()->render();
}
public function useInput()
{
return isset($this->_input_type);
}
public function useToolbar()
{
return isset($this->_toolbar);
}
private function _normalizeDirectory($directory)
{
$last = $directory[strlen($directory) - 1];
+1 -4
View File
@@ -172,10 +172,7 @@ class TreeToolbarCore implements ITreeToolbarCore
public function render()
{
foreach ($this->getActions() as $action)
{
if ($action instanceof TreeToolbarSearchCore)
$action->setAttribute('data', $this->getData());
}
$action->setAttribute('data', $this->getData());
return $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getTemplate()),
+1 -1
View File
@@ -66,7 +66,7 @@ class TreeToolbarSearchCore extends TreeToolbarButtonCore implements
private function _renderData($data)
{
if (!is_array($data) && !$data instanceof Traversable)
throw new PrestaShopException('Data value must be an traversable array');
throw new PrestaShopException('Data value must be a traversable array');
$html = '';
@@ -0,0 +1,83 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class TreeToolbarSearchCategoriesCore extends TreeToolbarButtonCore implements
ITreeToolbarButtonCore
{
protected $_template = 'tree_toolbar_search.tpl';
public function __construct($label, $id, $name = null, $class = null)
{
parent::__construct($label);
$this->setId($id);
$this->setName($name);
$this->setClass($class);
}
public function render()
{
if ($this->hasAttribute('data'))
$this->setAttribute('typeahead_source',
$this->_renderData($this->getAttribute('data')));
$admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath);
$bo_theme = ((Validate::isLoadedObject($this->getContext()->employee)
&& $this->getContext()->employee->bo_theme) ? $this->getContext()->employee->bo_theme : 'default');
if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$bo_theme.DIRECTORY_SEPARATOR
.'template'))
$bo_theme = 'default';
if ($this->getContext()->controller->ajax)
$html = '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/vendor/typeahead.min.js"></script>';
else
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/vendor/typeahead.min.js');
return (isset($html)?$html:'').parent::render();
}
private function _renderData($data)
{
if (!is_array($data) && !$data instanceof Traversable)
throw new PrestaShopException('Data value must be a traversable array');
$html = '';
foreach ($data as $item)
{
$html .= '{id_category : '.$item['id_category'].', name : "'.$item['name'].'"},';
if (array_key_exists('children', $item) && !empty($item['children']))
$html .= $this->_renderData($item['children']);
}
return $html;
}
}