NEW Show picto and color into combo for selection of tags
This commit is contained in:
parent
840428200c
commit
1e76422a50
@ -1152,6 +1152,7 @@ class Categorie extends CommonObject
|
||||
$this->cats[$obj->rowid]['color'] = $obj->color;
|
||||
$this->cats[$obj->rowid]['visible'] = $obj->visible;
|
||||
$this->cats[$obj->rowid]['ref_ext'] = $obj->ref_ext;
|
||||
$this->cats[$obj->rowid]['picto'] = 'category';
|
||||
$i++;
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -50,6 +50,10 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
|
||||
if (isModEnabled('categorie')) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
|
||||
}
|
||||
|
||||
// Load translation files required by the page
|
||||
$langs->loadLangs(array('companies', 'propal', 'compta', 'bills', 'orders', 'products', 'deliveries', 'categories'));
|
||||
@ -1080,13 +1084,12 @@ if ($resql) {
|
||||
$moreforfilter .= '</div>';
|
||||
}
|
||||
// If the user can view products
|
||||
if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
|
||||
if (isModEnabled('categorie') && $user->hasRight('categorie', 'read') && ($user->rights->produit->lire || $user->rights->service->lire)) {
|
||||
$searchCategoryProductOperator = -1;
|
||||
include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
$moreforfilter .= '<div class="divsearchfield">';
|
||||
$tmptitle = $langs->trans('IncludingProductWithTag');
|
||||
$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
|
||||
$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, (empty($conf->dol_optimize_smallscreen) ? 'maxwidth300 widthcentpercentminusx' : 'maxwidth250 widthcentpercentminusx'), 1);
|
||||
$moreforfilter .= '</div>';
|
||||
$formcategory = new FormCategory($db);
|
||||
$moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PRODUCT, array($search_product_category), 'maxwidth300', $searchCategoryProductOperator, 0, 0, $tmptitle);
|
||||
}
|
||||
if (isModEnabled('categorie') && $user->rights->categorie->lire) {
|
||||
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
|
||||
|
||||
@ -4859,7 +4859,7 @@ class Form
|
||||
* - int (id of category)
|
||||
* - string (categories ids seprated by comma)
|
||||
* - array (list of categories ids)
|
||||
* @param int $outputmode 0=HTML select string, 1=Array
|
||||
* @param int $outputmode 0=HTML select string, 1=Array, 2=Array extended
|
||||
* @param int $include [=0] Removed or 1=Keep only
|
||||
* @param string $morecss More CSS
|
||||
* @return string|array
|
||||
@ -4892,7 +4892,7 @@ class Form
|
||||
while ($i < $num) {
|
||||
$objp = $this->db->fetch_object($result);
|
||||
if ($objp) {
|
||||
$cate_arbo[$objp->rowid] = array('id'=>$objp->rowid, 'fulllabel'=>$objp->label);
|
||||
$cate_arbo[$objp->rowid] = array('id'=>$objp->rowid, 'fulllabel'=>$objp->label, 'color'=>'', 'picto'=>'category');
|
||||
}
|
||||
$i++;
|
||||
}
|
||||
@ -4905,8 +4905,9 @@ class Form
|
||||
$cate_arbo = $cat->get_full_arbo($type, $markafterid, $include);
|
||||
}
|
||||
|
||||
$output = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
|
||||
$outarray = array();
|
||||
|
||||
$output = '<select class="flat'.($morecss ? ' '.$morecss : '').'" name="'.$htmlname.'" id="'.$htmlname.'">';
|
||||
if (is_array($cate_arbo)) {
|
||||
if (!count($cate_arbo)) {
|
||||
$output .= '<option value="-1" disabled>'.$langs->trans("NoCategoriesDefined").'</option>';
|
||||
@ -4918,7 +4919,11 @@ class Form
|
||||
} else {
|
||||
$add = '';
|
||||
}
|
||||
$output .= '<option '.$add.'value="'.$cate_arbo[$key]['id'].'">'.dol_trunc($cate_arbo[$key]['fulllabel'], $maxlength, 'middle').'</option>';
|
||||
$output .= '<option '.$add.'value="'.$cate_arbo[$key]['id'].'"';
|
||||
$output .= ' data-html="'.dol_escape_htmltag(img_picto('', 'category', 'class="pictofixedwidth" style="color: #'.$cate_arbo[$key]['color'].'"').dol_trunc($cate_arbo[$key]['fulllabel'], $maxlength, 'middle')).'"';
|
||||
$output .= '>';
|
||||
$output .= dol_trunc($cate_arbo[$key]['fulllabel'], $maxlength, 'middle');
|
||||
$output .= '</option>';
|
||||
|
||||
$outarray[$cate_arbo[$key]['id']] = $cate_arbo[$key]['fulllabel'];
|
||||
}
|
||||
@ -4927,7 +4932,9 @@ class Form
|
||||
$output .= '</select>';
|
||||
$output .= "\n";
|
||||
|
||||
if ($outputmode) {
|
||||
if ($outputmode == 2) {
|
||||
return $cate_arbo;
|
||||
} elseif ($outputmode) {
|
||||
return $outarray;
|
||||
}
|
||||
return $output;
|
||||
@ -8326,8 +8333,8 @@ class Form
|
||||
* Show a multiselect form from an array. WARNING: Use this only for short lists.
|
||||
*
|
||||
* @param string $htmlname Name of select
|
||||
* @param array $array Array with key+value
|
||||
* @param array $selected Array with key+value preselected
|
||||
* @param array $array Array(key=>value) or Array(key=>array('id'=> , 'label'=> ))
|
||||
* @param array $selected Array of keys preselected
|
||||
* @param int $key_in_label 1 to show key like in "[key] value"
|
||||
* @param int $value_as_key 1 to use value as key
|
||||
* @param string $morecss Add more css style
|
||||
@ -8363,14 +8370,24 @@ class Form
|
||||
|
||||
if (!empty($array)) {
|
||||
foreach ($array as $key => $value) {
|
||||
$newval = ($translate ? $langs->trans($value) : $value);
|
||||
$newval = ($key_in_label ? $key.' - '.$newval : $newval);
|
||||
$tmpkey = $key;
|
||||
$tmpvalue = $value;
|
||||
$tmpcolor = '';
|
||||
$tmppicto = '';
|
||||
if (is_array($value) && array_key_exists('id', $value) && array_key_exists('label', $value)) {
|
||||
$tmpkey = $value['id'];
|
||||
$tmpvalue = $value['label'];
|
||||
$tmpcolor = $value['color'];
|
||||
$tmppicto = $value['picto'];
|
||||
}
|
||||
$newval = ($translate ? $langs->trans($tmpvalue) : $tmpvalue);
|
||||
$newval = ($key_in_label ? $tmpkey.' - '.$newval : $newval);
|
||||
|
||||
$out .= '<option value="'.$key.'"';
|
||||
if (is_array($selected) && !empty($selected) && in_array((string) $key, $selected) && ((string) $key != '')) {
|
||||
$out .= '<option value="'.$tmpkey.'"';
|
||||
if (is_array($selected) && !empty($selected) && in_array((string) $tmpkey, $selected) && ((string) $tmpkey != '')) {
|
||||
$out .= ' selected';
|
||||
}
|
||||
$out .= ' data-html="'.dol_escape_htmltag($newval).'"';
|
||||
$out .= ' data-html="'.dol_escape_htmltag(($tmppicto ? img_picto('', $tmppicto, 'class="pictofixedwidth" style="color: #'.$tmpcolor.'"') : '').$newval).'"';
|
||||
$out .= '>';
|
||||
$out .= dol_htmlentitiesbr($newval);
|
||||
$out .= '</option>'."\n";
|
||||
|
||||
@ -36,29 +36,45 @@ class FormCategory extends Form
|
||||
* @param array $preSelected A list with the elements that should pre-selected
|
||||
* @param string $morecss More CSS
|
||||
* @param int $searchCategoryProductOperator 0 or 1 to enable the checkbox to search with a or (0=not preseleted, 1=preselected)
|
||||
* @param int $multiselect 0 or 1
|
||||
* @param int $nocateg 1=Add an entry '- No Category -'
|
||||
* @param string $showempty 1 or 'string' to add an empty entry
|
||||
* @return string A HTML filter box (Note: selected results can get with GETPOST("search_category_".$type."_list"))
|
||||
*/
|
||||
public function getFilterBox($type, array $preSelected, $morecss = "minwidth300 widthcentpercentminusx", $searchCategoryProductOperator = -1)
|
||||
public function getFilterBox($type, array $preSelected, $morecss = "minwidth300 widthcentpercentminusx", $searchCategoryProductOperator = -1, $multiselect = 1, $nocateg = 1, $showempty = '')
|
||||
{
|
||||
global $langs;
|
||||
global $langs, $db;
|
||||
|
||||
if (empty($preSelected) || !is_array($preSelected)) {
|
||||
$preSelected = array();
|
||||
}
|
||||
|
||||
$htmlName = "search_category_".$type."_list";
|
||||
$htmlName2 = "search_category_".$type."_operator";
|
||||
|
||||
$categoryArray = $this->select_all_categories($type, "", "", 64, 0, 1);
|
||||
$categoryArray[-2] = "- ".$langs->trans('NotCategorized')." -";
|
||||
|
||||
$tmptitle = $langs->transnoentitiesnoconv("Category");
|
||||
if ($showempty && !is_numeric($showempty)) {
|
||||
$tmptitle = $showempty;
|
||||
} else {
|
||||
$tmptitle = $langs->transnoentitiesnoconv("Category");
|
||||
}
|
||||
|
||||
$filter = '';
|
||||
$filter .= '<div class="divsearchfield">';
|
||||
$filter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
|
||||
//$filter .= $langs->trans('Categories').": ";
|
||||
$filter .= Form::multiselectarray($htmlName, $categoryArray, $preSelected, 0, 0, $morecss, 0, 0, '', '', $tmptitle);
|
||||
if ($multiselect) {
|
||||
$categoryArray = $this->select_all_categories($type, '', '', 64, 0, 2);
|
||||
if ($nocateg) {
|
||||
$categoryArray[-2] = "- ".$langs->trans('NotCategorized')." -";
|
||||
}
|
||||
$htmlName = "search_category_".$type."_list";
|
||||
$htmlName2 = "search_category_".$type."_operator";
|
||||
|
||||
$filter .= Form::multiselectarray($htmlName, $categoryArray, $preSelected, 0, 0, $morecss, 0, 0, '', '', $tmptitle);
|
||||
} else {
|
||||
$htmlName = "search_".$type."_category";
|
||||
$htmlName2 = "";
|
||||
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
|
||||
$formother = new FormOther($db);
|
||||
|
||||
$filter .= $formother->select_categories($type, $preSelected[0], $htmlName, $nocateg, $tmptitle, $morecss);
|
||||
}
|
||||
if ($searchCategoryProductOperator >= 0) {
|
||||
$filter .= ' <input type="checkbox" class="valignmiddle" id="'.$htmlName2.'" name="'.$htmlName2.'" value="1"'.($searchCategoryProductOperator == 1 ? ' checked="checked"' : '').'/><label class="none valignmiddle" for="'.$htmlName2.'">'.$langs->trans('UseOrOperatorForCategories').'</label>';
|
||||
}
|
||||
|
||||
@ -823,7 +823,7 @@ if ($resql) {
|
||||
|
||||
// Filter on categories
|
||||
$moreforfilter = '';
|
||||
if (isModEnabled('categorie') && $user->rights->categorie->lire) {
|
||||
if (isModEnabled('categorie') && $user->hasRight('categorie', 'read')) {
|
||||
$formcategory = new FormCategory($db);
|
||||
$moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_PRODUCT, $searchCategoryProductList, 'minwidth300', $searchCategoryProductOperator ? $searchCategoryProductOperator : 0);
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user