[+] Classes : Helper::renderAdminCategorieTree() have new params "$use_search" to add a input search
This commit is contained in:
@@ -906,3 +906,33 @@ if (Tools::isSubmit('ajaxFeaturesPositions'))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('searchCategory'))
|
||||
{
|
||||
$q = Tools::getValue('q');
|
||||
$limit = Tools::getValue('limit');
|
||||
$results = Db::getInstance()->executeS(
|
||||
'SELECT c.`id_category`, cl.`name`
|
||||
FROM `'._DB_PREFIX_.'category` c
|
||||
LEFT JOIN `'._DB_PREFIX_.'category_lang` cl ON (c.`id_category` = cl.`id_category`'.$context->shop->sqlLang('cl').')
|
||||
WHERE cl.`id_lang` = '.(int)($context->language->id).'
|
||||
AND cl.`name` LIKE \'%'.pSQL($q).'%\'
|
||||
GROUP BY c.id_category
|
||||
ORDER BY c.`position`
|
||||
LIMIT '.(int)$limit);
|
||||
if ($results)
|
||||
foreach ($results AS $result)
|
||||
echo trim($result['name']).'|'.(int)($result['id_category'])."\n";
|
||||
}
|
||||
|
||||
if (Tools::isSubmit('getParentCategoriesId') AND $id_category = Tools::getValue('id_category'))
|
||||
{
|
||||
$category = new Category((int)$id_category);
|
||||
$results = Db::getInstance()->executeS('SELECT `id_category` FROM `'._DB_PREFIX_.'category` c WHERE c.`nleft` < '.(int)$category->nleft.' AND c.`nright` > '.(int)$category->nright.'');
|
||||
$output = array();
|
||||
foreach($results as $result)
|
||||
$output[] = $result;
|
||||
|
||||
die(Tools::jsonEncode($output));
|
||||
}
|
||||
|
||||
|
||||
@@ -3106,9 +3106,10 @@ class AdminProducts extends AdminTab
|
||||
'Collapse All' => $this->l('Collapse All'),
|
||||
'Expand All' => $this->l('Expand All'),
|
||||
'Check All' => $this->l('Check All'),
|
||||
'Uncheck All' => $this->l('Uncheck All')
|
||||
'Uncheck All' => $this->l('Uncheck All'),
|
||||
'search' => $this->l('Search a category')
|
||||
);
|
||||
echo Helper::renderAdminCategorieTree($trads, $selectedCat).'
|
||||
echo Helper::renderAdminCategorieTree($trads, $selectedCat, 'categoryBox', false, true).'
|
||||
</td>
|
||||
</tr>
|
||||
<tr><td colspan="2" style="padding-bottom:5px;"><hr style="width:100%;" /></td></tr>
|
||||
|
||||
+2
-15
@@ -75,28 +75,15 @@ class HelperCore
|
||||
($use_search ? '<script type="text/javascript" src="'._PS_JS_DIR_.'jquery/jquery.autocomplete.js"></script>' : '' ).'
|
||||
<script type="text/javascript">
|
||||
var inputName = "'.$input_name.'";';
|
||||
if ($use_search)
|
||||
{
|
||||
|
||||
$html .= '
|
||||
$(\'document\').ready( function() {
|
||||
var dataCat = '. Tools::jsonEncode(array(array('name' => 'toto'), array('name' => 'titi'), array('name' => 'tutu'))).';
|
||||
$(\'input[name="search_cat"]\').autocomplete(dataCat);
|
||||
//$(\'input[name="search_cat"]\').result(function(event, data, formatted) {
|
||||
//alert(\'toto\');
|
||||
//});
|
||||
});
|
||||
';
|
||||
}
|
||||
if (sizeof($selected_cat) > 0)
|
||||
{
|
||||
if (isset($selected_cat[0]))
|
||||
$html .= 'var selectedCat = "'.implode(',', $selected_cat).'"';
|
||||
else
|
||||
$html .= 'var selectedCat = "'.implode(',', array_keys($selected_cat)).'"';
|
||||
} else {
|
||||
$html .= 'var selectedCat = ""';
|
||||
}
|
||||
else
|
||||
$html .= 'var selectedCat = ""';
|
||||
$html .= '
|
||||
var selectedLabel = \''.$trads['selected'].'\';
|
||||
var home = \''.$trads['Home'].'\';
|
||||
|
||||
@@ -256,4 +256,79 @@ function updateNbSubCategorySelected(category, add)
|
||||
|
||||
if (currentSpan.parent().children('.nb_sub_cat_selected').length != 0)
|
||||
updateNbSubCategorySelected(currentSpan.parent().children('input'), add);
|
||||
}
|
||||
}
|
||||
|
||||
$(document).ready( function() {
|
||||
var category_to_check;
|
||||
$('#search_cat').autocomplete('ajax.php?searchCategory=1', {
|
||||
delay: 100,
|
||||
minChars: 3,
|
||||
autoFill: true,
|
||||
max:20,
|
||||
matchContains: true,
|
||||
mustMatch:true,
|
||||
scroll:false,
|
||||
cacheLength:0,
|
||||
multipleSeparator:'||',
|
||||
formatItem: function(item)
|
||||
{
|
||||
return item[1]+' - '+item[0];
|
||||
}
|
||||
}).result(function(event, item)
|
||||
{
|
||||
parent_ids = getParentCategoriesIdAndOpen(item[1]);
|
||||
});
|
||||
});
|
||||
|
||||
function getParentCategoriesIdAndOpen(id_category)
|
||||
{
|
||||
category_to_check = id_category;
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
url: 'ajax.php',
|
||||
async: true,
|
||||
dataType: 'json',
|
||||
data: 'ajax=true&getParentCategoriesId=true&id_category=' + id_category ,
|
||||
success: function(jsonData) {
|
||||
for(var i= 0; i < jsonData.length; i++)
|
||||
if (jsonData[i].id_category != 1)
|
||||
arrayCatToExpand.push(jsonData[i].id_category);
|
||||
readyToExpand = true;
|
||||
interval = setInterval(openParentCategories, 10);
|
||||
},
|
||||
error: function(XMLHttpRequest, textStatus, errorThrown) {
|
||||
alert("TECHNICAL ERROR: \n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + 'Text status: ' + textStatus);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function openParentCategories()
|
||||
{
|
||||
if (id >= arrayCatToExpand.length && !readyToExpand)
|
||||
{
|
||||
clearInterval(interval);
|
||||
// delete interval value
|
||||
interval = null;
|
||||
readyToExpand = false;
|
||||
intervalCheck = setInterval(checkCategory, 10);
|
||||
}
|
||||
|
||||
if (readyToExpand)
|
||||
{
|
||||
if ($('li#'+arrayCatToExpand[id]+'.hasChildren').length > 0)
|
||||
readyToExpand = false;
|
||||
$('li#'+arrayCatToExpand[id]+'.expandable:visible span.category_label').trigger('click');
|
||||
id++;
|
||||
}
|
||||
}
|
||||
|
||||
function checkCategory()
|
||||
{
|
||||
if ($('li#'+category_to_check+' input[type=checkbox]').attr('checked') == 'checked')
|
||||
{
|
||||
clearInterval(intervalCheck);
|
||||
intervalCheck = null;
|
||||
}
|
||||
else
|
||||
$('li#'+category_to_check+' input[type=checkbox]').attr('checked', 'checked');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user