// Toolbar

This commit is contained in:
Jerome Nadaud committed 2013-09-10 14:08:29 +02:00
1 parent 03d1697e19
commit 85dc552667
15 files changed
+366 -94

No files matched your search

+7
View File
@@ -0,0 +1,7 @@
/*!
* typeahead.js 0.9.3
* https://github.com/twitter/typeahead
* Copyright 2013 Twitter, Inc. and other contributors; Licensed MIT
*/
!function(a){var b="0.9.3",c={isMsie:function(){var a=/(msie) ([\w.]+)/i.exec(navigator.userAgent);return a?parseInt(a[2],10):!1},isBlankString:function(a){return!a||/^\s*$/.test(a)},escapeRegExChars:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},isString:function(a){return"string"==typeof a},isNumber:function(a){return"number"==typeof a},isArray:a.isArray,isFunction:a.isFunction,isObject:a.isPlainObject,isUndefined:function(a){return"undefined"==typeof a},bind:a.proxy,bindAll:function(b){var c;for(var d in b)a.isFunction(c=b[d])&&(b[d]=a.proxy(c,b))},indexOf:function(a,b){for(var c=0;c<a.length;c++)if(a[c]===b)return c;return-1},each:a.each,map:a.map,filter:a.grep,every:function(b,c){var d=!0;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?void 0:!1}),!!d):d},some:function(b,c){var d=!1;return b?(a.each(b,function(a,e){return(d=c.call(null,e,a,b))?!1:void 0}),!!d):d},mixin:a.extend,getUniqueId:function(){var a=0;return function(){return a++}}(),defer:function(a){setTimeout(a,0)},debounce:function(a,b,c){var d,e;return function(){var f,g,h=this,i=arguments;return f=function(){d=null,c||(e=a.apply(h,i))},g=c&&!d,clearTimeout(d),d=setTimeout(f,b),g&&(e=a.apply(h,i)),e}},throttle:function(a,b){var c,d,e,f,g,h;return g=0,h=function(){g=new Date,e=null,f=a.apply(c,d)},function(){var i=new Date,j=b-(i-g);return c=this,d=arguments,0>=j?(clearTimeout(e),e=null,g=i,f=a.apply(c,d)):e||(e=setTimeout(h,j)),f}},tokenizeQuery:function(b){return a.trim(b).toLowerCase().split(/[\s]+/)},tokenizeText:function(b){return a.trim(b).toLowerCase().split(/[\s\-_]+/)},getProtocol:function(){return location.protocol},noop:function(){}},d=function(){var a=/\s+/;return{on:function(b,c){var d;if(!c)return this;for(this._callbacks=this._callbacks||{},b=b.split(a);d=b.shift();)this._callbacks[d]=this._callbacks[d]||[],this._callbacks[d].push(c);return this},trigger:function(b,c){var d,e;if(!this._callbacks)return this;for(b=b.split(a);d=b.shift();)if(e=this._callbacks[d])for(var f=0;f<e.length;f+=1)e[f].call(this,{type:d,data:c});return this}}}(),e=function(){function b(b){b&&b.el||a.error("EventBus initialized without el"),this.$el=a(b.el)}var d="typeahead:";return c.mixin(b.prototype,{trigger:function(a){var b=[].slice.call(arguments,1);this.$el.trigger(d+a,b)}}),b}(),f=function(){function a(a){this.prefix=["__",a,"__"].join(""),this.ttlKey="__ttl__",this.keyMatcher=new RegExp("^"+this.prefix)}function b(){return(new Date).getTime()}function d(a){return JSON.stringify(c.isUndefined(a)?null:a)}function e(a){return JSON.parse(a)}var f,g;try{f=window.localStorage,f.setItem("~~~","!"),f.removeItem("~~~")}catch(h){f=null}return g=f&&window.JSON?{_prefix:function(a){return this.prefix+a},_ttlKey:function(a){return this._prefix(a)+this.ttlKey},get:function(a){return this.isExpired(a)&&this.remove(a),e(f.getItem(this._prefix(a)))},set:function(a,e,g){return c.isNumber(g)?f.setItem(this._ttlKey(a),d(b()+g)):f.removeItem(this._ttlKey(a)),f.setItem(this._prefix(a),d(e))},remove:function(a){return f.removeItem(this._ttlKey(a)),f.removeItem(this._prefix(a)),this},clear:function(){var a,b,c=[],d=f.length;for(a=0;d>a;a++)(b=f.key(a)).match(this.keyMatcher)&&c.push(b.replace(this.keyMatcher,""));for(a=c.length;a--;)this.remove(c[a]);return this},isExpired:function(a){var d=e(f.getItem(this._ttlKey(a)));return c.isNumber(d)&&b()>d?!0:!1}}:{get:c.noop,set:c.noop,remove:c.noop,clear:c.noop,isExpired:c.noop},c.mixin(a.prototype,g),a}(),g=function(){function a(a){c.bindAll(this),a=a||{},this.sizeLimit=a.sizeLimit||10,this.cache={},this.cachedKeysByAge=[]}return c.mixin(a.prototype,{get:function(a){return this.cache[a]},set:function(a,b){var c;this.cachedKeysByAge.length===this.sizeLimit&&(c=this.cachedKeysByAge.shift(),delete this.cache[c]),this.cache[a]=b,this.cachedKeysByAge.push(a)}}),a}(),h=function(){function b(a){c.bindAll(this),a=c.isString(a)?{url:a}:a,i=i||new g,h=c.isNumber(a.maxParallelRequests)?a.maxParallelRequests:h||6,this.url=a.url,this.wildcard=a.wildcard||"%QUERY",this.filter=a.filter,this.replace=a.replace,this.ajaxSettings={type:"get",cache:a.cache,timeout:a.timeout,dataType:a.dataType||"json",beforeSend:a.beforeSend},this._get=(/^throttle$/i.test(a.rateLimitFn)?c.throttle:c.debounce)(this._get,a.rateLimitWait||300)}function d(){j++}function e(){j--}function f(){return h>j}var h,i,j=0,k={};return c.mixin(b.prototype,{_get:function(a,b){function c(c){var e=d.filter?d.filter(c):c;b&&b(e),i.set(a,c)}var d=this;f()?this._sendRequest(a).done(c):this.onDeckRequestArgs=[].slice.call(arguments,0)},_sendRequest:function(b){function c(){e(),k[b]=null,f.onDeckRequestArgs&&(f._get.apply(f,f.onDeckRequestArgs),f.onDeckRequestArgs=null)}var f=this,g=k[b];return g||(d(),g=k[b]=a.ajax(b,this.ajaxSettings).always(c)),g},get:function(a,b){var d,e,f=this,g=encodeURIComponent(a||"");return b=b||c.noop,d=this.replace?this.replace(this.url,g):this.url.replace(this.wildcard,g),(e=i.get(d))?c.defer(function(){b(f.filLine truncated
@@ -24,7 +24,7 @@
*} *}
<li class="tree-folder"> <li class="tree-folder">
<span class="tree-folder-name"> <span class="tree-folder-name">
<input type="checkbox" name="id-category[]" value="{$node['id_category']}" /> <input type="checkbox" name="categoryBox[]" value="{$node['id_category']}" />
<i class="icon-folder-close"></i> <i class="icon-folder-close"></i>
<label class="tree-toggler">{$name}</label> <label class="tree-toggler">{$name}</label>
</span> </span>
@@ -24,7 +24,7 @@
*} *}
<li class="tree-item"> <li class="tree-item">
<label class="tree-item-name"> <label class="tree-item-name">
<input type="checkbox" name="id-category[]" value="{$node['id_category']}" /> <input type="checkbox" name="categoryBox[]" value="{$node['id_category']}" />
<i class="tree-dot"></i> <i class="tree-dot"></i>
{$name} {$name}
</label> </label>
@@ -22,6 +22,6 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*} *}
<a href="{$link}" onclick="{$action}" class="btn btn-default btn-xs"> <a href="{$link}"{if isset($action)}onclick="{$action}"{/if} class="btn btn-default btn-xs">
<i class="{$icon_class}"></i>&nbsp;{l s=$label} {if isset($icon_class)}<i class="{$icon_class}"></i>&nbsp;{/if}{l s=$label}
</a> </a>
@@ -22,4 +22,18 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*} *}
<label for="node-search">{l s=$label}</label>&nbsp;<input type="text" id="node-search" name="node-search"{if isset($class)} class="{$class}"{/if}{if isset($categories_name)} data-provide="typeahead" data-source="[{$categories_name}]"{/if} /> <label for="node-search">{l s=$label}</label>&nbsp;<input type="text"{if isset($id)} id="{$id}"{/if}{if isset($name)} name="{$name}"{/if}{if isset($class)} class="{$class}"{/if} />
{if isset($typeahead_source) && isset($id)}
<script type="text/javascript">
$(document).ready(
function()
{
$("#{$id}").typeahead(
{
name: "{$name}",
local: [{$typeahead_source}]
});
}
);
</script>
{/if}
@@ -22,6 +22,6 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*} *}
<a href="{$link}" onclick="{$action}" class="btn btn-default btn-xs"> <a href="{$link}"{if isset($action)}onclick="{$action}"{/if} class="btn btn-default btn-xs">
<i class="{$icon_class}"></i>&nbsp;{l s=$label} {if isset($icon_class)}<i class="{$icon_class}"></i>&nbsp;{/if}{l s=$label}
</a> </a>
@@ -22,4 +22,19 @@
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) * @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
* International Registered Trademark & Property of PrestaShop SA * International Registered Trademark & Property of PrestaShop SA
*} *}
<label for="node-search">{l s=$label}</label>&nbsp;<input type="text" id="node-search" name="node-search"{if isset($class)} class="{$class}"{/if}{if isset($data_source)} data-provide="typeahead" data-source="[{$data_source}]"{/if} /> <label for="node-search">{l s=$label}</label>&nbsp;<input type="text"{if isset($id)} id="{$id}"{/if}{if isset($name)} name="{$name}"{/if}{if isset($class)} class="{$class}"{/if} />
{if isset($typeahead_source) && isset($id)}
<script type="text/javascript">
$(document).ready(
function()
{
$("#{$id}").typeahead(
{
name: "{$name}",
valueKey: 'name',
local: [{$typeahead_source}]
});
}
);
</script>
{/if}
@@ -31,6 +31,8 @@ interface HelperITreeToolbarCore
public function getActions(); public function getActions();
public function setContext($value); public function setContext($value);
public function getContext(); public function getContext();
public function setData($value);
public function getData();
public function setTemplate($value); public function setTemplate($value);
public function getTemplate(); public function getTemplate();
public function setTemplateDirectory($value); public function setTemplateDirectory($value);
+7 -3
View File
@@ -27,20 +27,24 @@
interface HelperITreeToolbarButtonCore interface HelperITreeToolbarButtonCore
{ {
public function __toString(); public function __toString();
public function setAction($value); public function setAttribute($name, $value);
public function getAction(); public function getAttribute($name);
public function setAttributes($value); public function setAttributes($value);
public function getAttributes(); public function getAttributes();
public function setClass($value); public function setClass($value);
public function getClass(); public function getClass();
public function setContext($value); public function setContext($value);
public function getContext(); public function getContext();
public function setId($value);
public function getId();
public function setLabel($value); public function setLabel($value);
public function getLabel(); public function getLabel();
public function setName($value);
public function getName();
public function setTemplate($value); public function setTemplate($value);
public function getTemplate(); public function getTemplate();
public function setTemplateDirectory($value); public function setTemplateDirectory($value);
public function getTemplateDirectory(); public function getTemplateDirectory();
public function addAttribute($name, $value); public function hasAttribute($name);
public function render(); public function render();
} }
+53 -4
View File
@@ -32,10 +32,13 @@ class HelperTreeCore
const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder.tpl'; const DEFAULT_NODE_FOLDER_TEMPLATE = 'tree_node_folder.tpl';
const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item.tpl'; const DEFAULT_NODE_ITEM_TEMPLATE = 'tree_node_item.tpl';
private $_children_key;
private $_context; private $_context;
private $_data; private $_data;
private $_headerTemplate; private $_headerTemplate;
private $_id; private $_id;
private $_id_key;
private $_name_key;
private $_node_folder_template; private $_node_folder_template;
private $_node_item_template; private $_node_item_template;
private $_template_directory; private $_template_directory;
@@ -80,6 +83,20 @@ class HelperTreeCore
return $this; return $this;
} }
public function setChildrenKey($value)
{
$this->_children_key = (string)$value;
return $this;
}
public function getChildrenKey()
{
if (!isset($this->_children_key))
$this->setChildrenKey('children');
return $this->_children_key;
}
public function setContext($value) public function setContext($value)
{ {
$this->_context = $value; $this->_context = $value;
@@ -136,6 +153,34 @@ class HelperTreeCore
return $this->_id; return $this->_id;
} }
public function setIdKey($value)
{
$this->_id_key = (string)$value;
return $this;
}
public function getIdKey()
{
if (!isset($this->_id_key))
$this->setIdKey('id');
return $this->_id_key;
}
public function setNameKey($value)
{
$this->_name_key = (string)$value;
return $this;
}
public function getNameKey()
{
if (!isset($this->_name_key))
$this->setNameKey('name');
return $this->_name_key;
}
public function setNodeFolderTemplate($value) public function setNodeFolderTemplate($value)
{ {
$this->_node_folder_template = $value; $this->_node_folder_template = $value;
@@ -223,6 +268,9 @@ class HelperTreeCore
public function getToolbar() public function getToolbar()
{ {
if (isset($this->_toolbar))
$this->_toolbar->setData($this->getData());
return $this->_toolbar; return $this->_toolbar;
} }
@@ -296,13 +344,14 @@ class HelperTreeCore
foreach ($data as $item) foreach ($data as $item)
{ {
if (array_key_exists('children', $item) && !empty($item['children'])) if (array_key_exists($this->getChildrenKey(), $item)
&& !empty($item[$this->getChildrenKey()]))
$html .= $this->getContext()->smarty->createTemplate( $html .= $this->getContext()->smarty->createTemplate(
$this->getTemplateDirectory().$this->getNodeFolderTemplate(), $this->getTemplateDirectory().$this->getNodeFolderTemplate(),
$this->getContext()->smarty $this->getContext()->smarty
)->assign(array( )->assign(array(
'name' => $item['name'], 'name' => $item[$this->getNameKey()],
'children' => $this->renderNodes($item['children']), 'children' => $this->renderNodes($item[$this->getChildrenKey()]),
'node' => $item 'node' => $item
))->fetch(); ))->fetch();
else else
@@ -310,7 +359,7 @@ class HelperTreeCore
$this->getTemplateDirectory().$this->getNodeItemTemplate(), $this->getTemplateDirectory().$this->getNodeItemTemplate(),
$this->getContext()->smarty $this->getContext()->smarty
)->assign(array( )->assign(array(
'name' => $item['name'], 'name' => $item[$this->getNameKey()],
'node' => $item 'node' => $item
))->fetch(); ))->fetch();
} }
+21
View File
@@ -31,6 +31,7 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
private $_actions; private $_actions;
private $_context; private $_context;
private $_data;
private $_template; private $_template;
private $_template_directory; private $_template_directory;
@@ -69,6 +70,20 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
return $this->_context; return $this->_context;
} }
public function setData($value)
{
if (!is_array($value) && !$value instanceof Traversable)
throw new PrestaShopException('Data value must be an traversable array');
$this->_data = $value;
return $this;
}
public function getData()
{
return $this->_data;
}
public function setTemplate($value) public function setTemplate($value)
{ {
$this->_template = $value; $this->_template = $value;
@@ -118,6 +133,12 @@ class HelperTreeToolbarCore implements HelperITreeToolbarCore
public function render() public function render()
{ {
foreach ($this->getActions() as $action)
{
if (is_subclass_of($action, 'HelperTreeToolbarSearchCore'))
$action->setAttribute('data', $this->getData());
}
return $this->getContext()->smarty->createTemplate( return $this->getContext()->smarty->createTemplate(
$this->getTemplateDirectory().$this->getTemplate(), $this->getTemplateDirectory().$this->getTemplate(),
$this->getContext()->smarty $this->getContext()->smarty
+41 -21
View File
@@ -28,18 +28,20 @@ abstract class HelperTreeToolbarButtonCore
{ {
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree'; const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/tree';
private $_action; protected $_attributes;
private $_attributes;
private $_class; private $_class;
private $_context; private $_context;
private $_id;
private $_label; private $_label;
private $_name;
protected $_template; protected $_template;
protected $_template_directory; protected $_template_directory;
public function __construct($label, $action = null, $class = null) public function __construct($label, $id = null, $name = null, $class = null)
{ {
$this->setLabel($label); $this->setLabel($label);
$this->setAction($action); $this->setId($id);
$this->setName($name);
$this->setClass($class); $this->setClass($class);
} }
@@ -48,15 +50,18 @@ abstract class HelperTreeToolbarButtonCore
return $this->render(); return $this->render();
} }
public function setAction($value) public function setAttribute($name, $value)
{ {
$this->_action = $value; if (!isset($this->_attributes))
$this->_attributes = array();
$this->_attributes[$name] = $value;
return $this; return $this;
} }
public function getAction() public function getAttribute($name)
{ {
return $this->_action; return $this->hasAttribute($name) ? $this->_attributes[$name] : null;
} }
public function setAttributes($value) public function setAttributes($value)
@@ -78,13 +83,12 @@ abstract class HelperTreeToolbarButtonCore
public function setClass($value) public function setClass($value)
{ {
$this->_class = $value; return $this->setAttribute('class', $value);
return $this;
} }
public function getClass() public function getClass()
{ {
return $this->_class; return $this->getAttribute('class');
} }
public function setContext($value) public function setContext($value)
@@ -101,15 +105,34 @@ abstract class HelperTreeToolbarButtonCore
return $this->_context; return $this->_context;
} }
public function setId($value)
{
return $this->setAttribute('id', $value);
}
public function getId()
{
return $this->getAttribute('id');
}
public function setLabel($value) public function setLabel($value)
{ {
$this->_label = $value; return $this->setAttribute('label', $value);
return $this;
} }
public function getLabel() public function getLabel()
{ {
return $this->_label; return $this->getAttribute('label');
}
public function setName($value)
{
return $this->setAttribute('name', $value);
}
public function getName()
{
return $this->getAttribute('name');
} }
public function setTemplate($value) public function setTemplate($value)
@@ -139,13 +162,10 @@ abstract class HelperTreeToolbarButtonCore
return $this->_template_directory; return $this->_template_directory;
} }
public function addAttribute($name, $value) public function hasAttribute($name)
{ {
if (!isset($this->_attributes)) return (isset($this->_attributes)
$this->_attributes = array(); && array_key_exists($name, $this->_attributes));
$this->_attributes[$name] = $value;
return $this;
} }
public function render() public function render()
@@ -153,7 +173,7 @@ abstract class HelperTreeToolbarButtonCore
return $this->getContext()->smarty->createTemplate( return $this->getContext()->smarty->createTemplate(
$this->getTemplateDirectory().$this->getTemplate(), $this->getTemplateDirectory().$this->getTemplate(),
$this->getContext()->smarty $this->getContext()->smarty
)->assign($this->getAttributes()); )->assign($this->getAttributes())->fetch();
} }
private function _normalizeDirectory($directory) private function _normalizeDirectory($directory)
+19 -24
View File
@@ -27,52 +27,47 @@
class HelperTreeToolbarLinkCore extends HelperTreeToolbarButtonCore implements class HelperTreeToolbarLinkCore extends HelperTreeToolbarButtonCore implements
HelperITreeToolbarButtonCore HelperITreeToolbarButtonCore
{ {
private $_action;
private $_icon_class; private $_icon_class;
private $_link; private $_link;
protected $_template = 'tree_toolbar_link.tpl'; protected $_template = 'tree_toolbar_link.tpl';
public function __construct($label, $action = null, $link, $iconClass) public function __construct($label, $link, $action = null, $iconClass = null)
{ {
parent::__construct($label, $action); parent::__construct($label);
$this->setLink($link); $this->setLink($link);
$this->setAction($action);
$this->setIconClass($iconClass); $this->setIconClass($iconClass);
} }
public function setAction($value)
{
return $this->setAttribute('action', $value);
}
public function getAction()
{
return $this->getAttribute('action');
}
public function setIconClass($value) public function setIconClass($value)
{ {
$this->_icon_class = $value; return $this->setAttribute('icon_class', $value);
return $this;
} }
public function getIconClass() public function getIconClass()
{ {
return $this->_icon_class; return $this->getAttribute('icon_class');
} }
public function setLink($value) public function setLink($value)
{ {
$this->_link = $value; return $this->setAttribute('link', $value);
return $this;
} }
public function getLink() public function getLink()
{ {
if (!isset($this->_link)) return $this->getAttribute('link');
$this->_link = '';
return $this->_link;
}
public function render()
{
$template = parent::render();
$template->assign(array(
'link' => $this->getLink(),
'action' => $this->getAction(),
'label' => $this->getLabel(),
'class' => $this->getClass(),
'icon_class' => $this->getIconClass()
));
return $template->fetch();
} }
} }
+77 -7
View File
@@ -27,10 +27,68 @@
class HelperTreeToolbarSearchCore extends HelperTreeToolbarButtonCore implements class HelperTreeToolbarSearchCore extends HelperTreeToolbarButtonCore implements
HelperITreeToolbarButtonCore HelperITreeToolbarButtonCore
{ {
private $_children_key;
private $_id_key;
private $_name_key;
protected $_template = 'tree_toolbar_search.tpl'; 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 setChildrenKey($value)
{
$this->_children_key = (string)$value;
return $this;
}
public function getChildrenKey()
{
if (!isset($this->_children_key))
$this->setChildrenKey('children');
return $this->_children_key;
}
public function setIdKey($value)
{
$this->_id_key = (string)$value;
return $this;
}
public function getIdKey()
{
if (!isset($this->_id_key))
$this->setIdKey('id');
return $this->_id_key;
}
public function setNameKey($value)
{
$this->_name_key = (string)$value;
return $this;
}
public function getNameKey()
{
if (!isset($this->_name_key))
$this->setNameKey('name');
return $this->_name_key;
}
public function render() 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 = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_);
$admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath); $admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath);
$bo_theme = ((Validate::isLoadedObject($this->getContext()->employee) $bo_theme = ((Validate::isLoadedObject($this->getContext()->employee)
@@ -47,12 +105,24 @@ class HelperTreeToolbarSearchCore extends HelperTreeToolbarButtonCore implements
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/vendor/typeahead.min.js'); .'/themes/'.$bo_theme.'/js/vendor/typeahead.min.js');
$template = parent::render(); return (isset($html)?$html:'').parent::render();
$template->assign(array( }
'action' => $this->getAction(),
'label' => $this->getLabel(), private function _renderData($data)
'class' => $this->getClass() {
)); if (!is_array($data) && !$data instanceof Traversable)
return (isset($html)?$html:'').$template->fetch(); throw new PrestaShopException('Data value must be an traversable array');
$html = '';
foreach ($data as $item)
{
if (array_key_exists($this->getChildrenKey(), $item) && !empty($item[$this->getChildrenKey()]))
$html .= '{id : '.$item[$this->getIdKey()].', name : "'.$item[$this->getNameKey()].'"},'.$this->_renderData($item[$this->getChildrenKey()]);
else
$html .= '{id : '.$item[$this->getIdKey()].', name : "'.$item[$this->getNameKey()].'"},';
}
return $html;
} }
} }
+102 -27
View File
@@ -2328,14 +2328,23 @@ class AdminProductsControllerCore extends AdminController
return parent::renderList(); return parent::renderList();
} }
public function renderCategoriesTree($selectedCategory = null) public function renderCategoriesTree($selected_category = null)
{ {
$tree = new HelperTree('categories-tree', Category::getNestedCategories()); $tree = new HelperTree('categories-tree', Category::getNestedCategories(
1, $this->context->employee->id_lang));
$html = $tree->setTitle('Filter by category') $html = $tree->setTitle('Filter by category')
->setActions(array( ->setActions(array(
new HelperTreeToolbarLink('Collapse All', '$(\'#categories-tree\').tree(\'collapseAll\')', '#', 'icon-collapse-alt'), new HelperTreeToolbarLink(
new HelperTreeToolbarLink('Expand All', '$(\'#categories-tree\').tree(\'expandAll\')', '#', 'icon-expand-alt') 'Collapse All',
'#',
'$(\'#categories-tree\').tree(\'collapseAll\')',
'icon-collapse-alt'),
new HelperTreeToolbarLink(
'Expand All',
'#',
'$(\'#categories-tree\').tree(\'expandAll\')',
'icon-expand-alt')
)) ))
->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree') ->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree')
->render(); ->render();
@@ -2351,13 +2360,14 @@ class AdminProductsControllerCore extends AdminController
} }
);'; );';
if (isset($selectedCategory)) if (isset($selected_category))
$html .= '$("#categories-tree").find(":input").each( $html .= '$("#categories-tree").find(":input").each(
function() function()
{ {
if ($(this).val() == '.$selectedCategory.') if ($(this).val() == '.$selected_category.')
{ {
$(this).prop("checked", true); $(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each( $(this).parents("ul.tree").each(
function() function()
{ {
@@ -2375,29 +2385,43 @@ class AdminProductsControllerCore extends AdminController
return $html; return $html;
} }
public function renderAssociationsCategoriesTree() public function renderAssociationsCategoriesTree($root_category,
$selected_categories)
{ {
$categories = Category::getSimpleCategories(1); $tree = new HelperTree('associated-categories-tree',
$search_source = array(); Category::getNestedCategories(1, $this->context->employee->id_lang));
foreach ($categories as $key => $category) $search = new HelperTreeToolbarSearch('Find a category:',
$search_source[] = $category['name']; 'categories-search');
$search->setIdKey('id_category');
$tree = new HelperTree('associated-categories-tree', Category::getNestedCategories());
$search = new HelperTreeToolbarSearch('Find a category:');
$search->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree')
->addAttribute('categories_name', '"'.implode('","', $search_source).'"');
$html = $tree->setTitle('Associated categories') $html = $tree->setTitle('Associated categories')
->setActions(array( ->setActions(array(
new HelperTreeToolbarLink('Collapse All', '$(\'#associated-categories-tree\').tree(\'collapseAll\')', '#', 'icon-collapse-alt'), new HelperTreeToolbarLink(
new HelperTreeToolbarLink('Expand All', '$(\'#associated-categories-tree\').tree(\'expandAll\')', '#', 'icon-expand-alt'), 'Collapse All',
new HelperTreeToolbarLink('Check All', 'checkAllAssociatedCategories();', '#', 'icon-check-sign'), '#',
new HelperTreeToolbarLink('Uncheck All', 'uncheckAllAssociatedCategories();', '#', 'icon-check-empty'), '$(\'#associated-categories-tree\').tree(\'collapseAll\')',
'icon-collapse-alt'),
new HelperTreeToolbarLink(
'Expand All',
'#',
'$(\'#associated-categories-tree\').tree(\'expandAll\')',
'icon-expand-alt'),
new HelperTreeToolbarLink(
'Check All',
'#',
'checkAllAssociatedCategories();',
'icon-check-sign'),
new HelperTreeToolbarLink(
'Uncheck All',
'#',
'uncheckAllAssociatedCategories();',
'icon-check-empty'),
$search $search
)) ))
->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree') ->setTemplateDirectory($this->context->smarty->getTemplateDir(0).'/controllers/products/helpers/tree')
->setNodeFolderTemplate('tree_node_folder_associations.tpl') ->setNodeFolderTemplate('tree_node_folder_associations.tpl')
->setNodeFolderTemplate('tree_node_item_associations.tpl') ->setNodeItemTemplate('tree_node_item_associations.tpl')
->render(); ->render();
$html .= '<script type="text/javascript"> $html .= '<script type="text/javascript">
function checkAllAssociatedCategories() function checkAllAssociatedCategories()
{ {
@@ -2405,6 +2429,7 @@ class AdminProductsControllerCore extends AdminController
function() function()
{ {
$(this).prop("checked", true); $(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
} }
); );
} }
@@ -2415,13 +2440,60 @@ class AdminProductsControllerCore extends AdminController
function() function()
{ {
$(this).prop("checked", false); $(this).prop("checked", false);
$(this).parent().removeClass("tree-selected");
} }
); );
} }
$(document).ready(function () { $("#categories-search").bind("typeahead:selected", function(obj, datum) {
//$("#associated-categories-tree").tree("collapseAll"); $("#associated-categories-tree").find(":input").each(
function()
{
if ($(this).val() == datum.id)
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each(
function()
{
$(this).children().children(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);
}); });
$(document).ready(
function()
{
$("#associated-categories-tree").tree("collapseAll");
var selected_categories = new Array("'.implode('","', $selected_categories).'");
$("#associated-categories-tree").find(":input").each(
function()
{
if ($.inArray($(this).val(), selected_categories) != -1)
{
$(this).prop("checked", true);
$(this).parent().addClass("tree-selected");
$(this).parents("ul.tree").each(
function()
{
$(this).children().children(".icon-folder-close")
.removeClass("icon-folder-close")
.addClass("icon-folder-open");
$(this).show();
}
);
}
}
);
}
);
</script>'; </script>';
return $html; return $html;
} }
@@ -3027,14 +3099,17 @@ class AdminProductsControllerCore extends AdminController
$data->assign('accessories', $accessories); $data->assign('accessories', $accessories);
$product->manufacturer_name = Manufacturer::getNameById($product->id_manufacturer); $product->manufacturer_name = Manufacturer::getNameById($product->id_manufacturer);
$tab_root = array('id_category' => $root->id, 'name' => $root->name);
$category_tree = $helper->renderCategoryTree($tab_root, $selected_cat, 'categoryBox', false, true, array(), false, true); $categories = array();
$helper = new Helper(); foreach ($selected_cat as $key => $category)
$categories[] = $key;
$data->assign(array('default_category' => $default_category, $data->assign(array('default_category' => $default_category,
'selected_cat_ids' => implode(',', array_keys($selected_cat)), 'selected_cat_ids' => implode(',', array_keys($selected_cat)),
'selected_cat' => $selected_cat, 'selected_cat' => $selected_cat,
'id_category_default' => $product->getDefaultCategory(), 'id_category_default' => $product->getDefaultCategory(),
'category_tree' => $category_tree, 'category_tree' => $this->renderAssociationsCategoriesTree(
$root->id, $categories),
'product' => $product, 'product' => $product,
'link' => $this->context->link, 'link' => $this->context->link,
'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP 'is_shop_context' => Shop::getContext() == Shop::CONTEXT_SHOP