NEW Add a new component to select categories/tags from the main edit

page of product. The dedicated tab is also removed.
This commit is contained in:
Laurent Destailleur 2015-05-03 15:51:55 +02:00
parent 0479bd5a59
commit f0b10c14d7
6 changed files with 106 additions and 23 deletions

View File

@ -1064,11 +1064,11 @@ class Categorie extends CommonObject
*/
function print_all_ways($sep = " >> ", $url='')
{
$ways = array ();
$ways = array();
foreach ($this->get_all_ways() as $way)
{
$w = array ();
$w = array();
foreach ($way as $cat)
{
if ($url == '')

View File

@ -4407,13 +4407,15 @@ class Form
* @param array $selected Array with key+value preselected
* @param int $key_in_label 1 pour afficher la key dans la valeur "[key] value"
* @param int $value_as_key 1 to use value as key
* @param string $option Valeur de l'option en fonction du type choisi
* @param string $morecss Add more css style
* @param int $translate Translate and encode value
* @param int $width Force width of select box. May be used only when using jquery couch.
* @param int $width Force width of select box. May be used only when using jquery couch. Example: 250, 95%
* @param string $moreattrib Add more options on select component. Example: 'disabled="disabled"'
* @param string $elemtype Type of element we show ('category', ...)
* @return string HTML multiselect string
* @see selectarray
*/
static function multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $option='', $translate=0, $width=0)
static function multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='',$elemtype='')
{
global $conf, $langs;
@ -4423,8 +4425,36 @@ class Form
$tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT'):$conf->global->MAIN_USE_JQUERY_MULTISELECT;
print '<!-- JS CODE TO ENABLE '.$tmpplugin.' for id '.$htmlname.' -->
<script type="text/javascript">
function formatResult(record) {'."\n";
if ($elemtype == 'category')
{
print ' //return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png'.'"> <a href="'.DOL_URL_ROOT.'/categories/viewcat.php?type=0&id=\'+record.id+\'">\'+record.text+\'</a></span>\';
return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png'.'"> \'+record.text+\'</span>\';';
}
else
{
print 'return record.text;';
}
print ' };
function formatSelection(record) {'."\n";
if ($elemtype == 'category')
{
print ' //return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png'.'"> <a href="'.DOL_URL_ROOT.'/categories/viewcat.php?type=0&id=\'+record.id+\'">\'+record.text+\'</a></span>\';
return \'<span><img src="'.DOL_URL_ROOT.'/theme/eldy/img/object_category.png'.'"> \'+record.text+\'</span>\';';
}
else
{
print 'return record.text;';
}
print ' };
$(document).ready(function () {
$(\'#'.$htmlname.'\').'.$tmpplugin.'({
// Specify format function for dropdown item
formatResult: formatResult,
templateResult: formatResult, /* For 4.0 */
// Specify format function for selected item
formatSelection: formatSelection,
templateResult: formatSelection /* For 4.0 */
});
});
</script>';
@ -4433,7 +4463,7 @@ class Form
// Try also magic suggest
// Add data-role="none" to disable jmobile decoration
$out = '<select data-role="none" id="'.$htmlname.'" class="multiselect" multiple="multiple" name="'.$htmlname.'[]"'.$option.($width?' style="width: '.$width.'px"':'').'>'."\n";
$out = '<select data-role="none" id="'.$htmlname.'" class="multiselect'.($morecss?' '.$morecss:'').'" multiple="multiple" name="'.$htmlname.'[]"'.($moreattrib?' '.$moreattrib:'').($width?' style="width: '.(preg_match('/%/',$width)?$width:$width.'px').'"':'').'>'."\n";
if (is_array($array) && ! empty($array))
{
if ($value_as_key) $array=array_combine($array, $array);
@ -4462,6 +4492,49 @@ class Form
}
/**
* Render list of categories linked to object with id $id and type $type
*
* @param int $id Id of object
* @param string $type Type of category ('member', 'customer', 'supplier', 'product', 'contact'). Old mode (0, 1, 2, ...) is deprecated.
* @param int $rendermode 0=Default, use multiselect. 1=Use text with link
* @return mixed Array of category objects or < 0 if KO
*/
function showCategories($id, $type, $rendermode=0)
{
global $db;
$cat = new Categorie($db);
$categories = $cat->containing($id, $type);
if ($rendermode == 1)
{
$toprint = array();
foreach($categories as $c)
{
$ways = $c->print_all_ways();
foreach($ways as $way)
{
$toprint[] = img_object('','category').' '.$way;
}
}
return implode('<br>', $toprint);
}
if ($rendermode == 0)
{
$cate_arbo = $this->select_all_categories(0, '', 'parent', 64, 0, 1);
foreach($categories as $c) {
$arrayselected[] = $c->id;
}
return $this->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%', 'disabled="disabled"', 'category');
}
return 'ErrorBadValueForParameterRenderMode'; // Should not happened
}
/**
* Return an html string with a select combo box to choose yes or no
*

View File

@ -57,13 +57,14 @@ function product_prepare_head($object)
}
// Show category tab
/* No more required. Replaced with new multiselect component
if (! empty($conf->categorie->enabled) && $user->rights->categorie->lire)
{
$head[$h][0] = DOL_URL_ROOT."/categories/categorie.php?id=".$object->id.'&type=0';
$head[$h][1] = $langs->trans('Categories');
$head[$h][2] = 'category';
$h++;
}
}*/
// Multilangs
if (! empty($conf->global->MAIN_MULTILANGS))

View File

@ -12,7 +12,6 @@ Notify_FICHINTER_VALIDATE=Validation fiche intervention
Notify_FICHINTER_SENTBYMAIL=Envoi fiche d'intervention par email
Notify_BILL_VALIDATE=Validation facture client
Notify_BILL_UNVALIDATE=Dévalidation facture client
Notify_ORDER_SUPPLIER_VALIDATE=Commande fournisseur enregistrée
Notify_ORDER_SUPPLIER_APPROVE=Approbation commande fournisseur
Notify_ORDER_SUPPLIER_REFUSE=Refus commande fournisseur
Notify_ORDER_VALIDATE=Validation commande client

View File

@ -1174,7 +1174,7 @@ else
$type = $langs->trans('Product');
if ($object->isservice()) $type = $langs->trans('Service');
print_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), "");
//print_fiche_titre($langs->trans('Modify').' '.$type.' : '.(is_object($object->oldcopy)?$object->oldcopy->ref:$object->ref), "");
// Main official, simple, and not duplicated code
print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">'."\n";
@ -1182,6 +1182,12 @@ else
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="id" value="'.$object->id.'">';
print '<input type="hidden" name="canvas" value="'.$object->canvas.'">';
$head=product_prepare_head($object);
$titre=$langs->trans("CardProduct".$object->type);
$picto=($object->type== Product::TYPE_SERVICE?'service':'product');
dol_fiche_head($head, 'card', $titre, 0, $picto);
print '<table class="border allwidth">';
// Ref
@ -1374,7 +1380,7 @@ else
foreach($cats as $cat) {
$arrayselected[] = $cat->id;
}
print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, 250);
print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%');
print "</td></tr>";
// Units
@ -1409,10 +1415,10 @@ else
print '</td></tr>';
print '</table>';
print '<br>';
//}
dol_fiche_end();
print '<div class="center">';
print '<input type="submit" class="button" value="'.$langs->trans("Save").'">';
print '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;';
@ -1688,16 +1694,8 @@ else
print '<!-- End show Note --> '."\n";
// Categories
print '<tr><td valign="top">'.$langs->trans("Categories").'</td><td colspan="3">';
$cat = new Categorie($db);
$categories = $cat->containing($object->id,0);
$catarray = $form->select_all_categories(0, '', 'parent', 64, 0, 1);
$toprint = array();
foreach($categories as $c) {
$toprint[] = $catarray[$c->id];
}
print implode('<br>', $toprint);
print '<tr><td valign="middle">'.$langs->trans("Categories").'</td><td colspan="3">';
print $form->showCategories($object->id,'product');
print "</td></tr>";
print "</table>\n";

View File

@ -3054,11 +3054,23 @@ a span.select2-chosen
.select2-container .select2-choice {
background-image: none;
}
.select2-choices .select2-search-choice {
border: 1px solid #aaa !important;
}
.select2-results .select2-no-results, .select2-results .select2-searching, .select2-results .select2-ajax-error, .select2-results .select2-selection-limit
{
background: #FFFFFF;
}
.select2-container-multi.select2-container-disabled .select2-choices {
background-color: #FFFFFF;
background-image: none;
border: none;
cursor: default;
}
.select2-container-multi .select2-choices .select2-search-choice {
margin-top: 2px;
margin-bottom: 2px;
}
/* ============================================================================== */
/* JMobile */