FIX cutomer or supplier categories visible or not when required

This commit is contained in:
Laurent Destailleur 2018-10-12 12:04:04 +02:00
parent 82c89f739d
commit 53b099858f

View File

@ -1063,6 +1063,39 @@ else
$("#TypeName").html(document.formsoc.LastName.value); $("#TypeName").html(document.formsoc.LastName.value);
document.formsoc.private.value=1; document.formsoc.private.value=1;
}); });
init_customer_categ();
$("#customerprospect").change(function() {
init_customer_categ();
});
function init_customer_categ() {
console.log("is customer or prospect = "+jQuery("#customerprospect").val());
if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER)?'1':'0').'))
{
jQuery(".visibleifcustomer").hide();
}
else
{
jQuery(".visibleifcustomer").show();
}
}
init_supplier_categ();
$("#fournisseur").change(function() {
init_supplier_categ();
});
function init_supplier_categ() {
console.log("is supplier = "+jQuery("#fournisseur").val());
if (jQuery("#fournisseur").val() == 0)
{
jQuery(".visibleifsupplier").hide();
}
else
{
jQuery(".visibleifsupplier").show();
}
}
$("#selectcountry_id").change(function() { $("#selectcountry_id").change(function() {
document.formsoc.action.value="create"; document.formsoc.action.value="create";
document.formsoc.submit(); document.formsoc.submit();
@ -1421,22 +1454,20 @@ else
$langs->load('categories'); $langs->load('categories');
// Customer // Customer
if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) { //if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) {
print '<tr><td class="toptd">' . fieldLabel('CustomersCategoriesShort', 'custcats') . '</td><td colspan="3">'; print '<tr class="visibleifcustomer"><td class="toptd">' . fieldLabel('CustomersCategoriesShort', 'custcats') . '</td><td colspan="3">';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1); $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, 'parent', null, null, 1);
print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, print $form->multiselectarray('custcats', $cate_arbo, GETPOST('custcats', 'array'), null, null, null, null, "90%");
null, "90%");
print "</td></tr>"; print "</td></tr>";
} //}
// Supplier // Supplier
if ($object->fournisseur) { //if ($object->fournisseur) {
print '<tr><td class="toptd">' . fieldLabel('SuppliersCategoriesShort', 'suppcats') . '</td><td colspan="3">'; print '<tr class="visibleifsupplier"><td class="toptd">' . fieldLabel('SuppliersCategoriesShort', 'suppcats') . '</td><td colspan="3">';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1); $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, 'parent', null, null, 1);
print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, print $form->multiselectarray('suppcats', $cate_arbo, GETPOST('suppcats', 'array'), null, null, null, null, "90%");
null, "90%");
print "</td></tr>"; print "</td></tr>";
} //}
} }
// Multicurrency // Multicurrency
@ -1488,11 +1519,6 @@ else
} }
elseif ($action == 'edit') elseif ($action == 'edit')
{ {
/*
* Edition
*/
//print load_fiche_titre($langs->trans("EditCompany")); //print load_fiche_titre($langs->trans("EditCompany"));
if ($socid) if ($socid)
@ -1612,6 +1638,8 @@ else
$sub2=0; $sub2=0;
}else{$sub2=1;} }else{$sub2=1;}
if ($conf->use_javascript_ajax)
{
print "\n".'<script type="text/javascript">'; print "\n".'<script type="text/javascript">';
print '$(document).ready(function () { print '$(document).ready(function () {
var val='.$sub.'; var val='.$sub.';
@ -1647,18 +1675,43 @@ else
} }
}); });
});'; init_customer_categ();
print '</script>'."\n"; $("#customerprospect").change(function() {
init_customer_categ();
});
if ($conf->use_javascript_ajax) function init_customer_categ() {
console.log("is customer or prospect = "+jQuery("#customerprospect").val());
if (jQuery("#customerprospect").val() == 0 && (jQuery("#fournisseur").val() == 0 || '.(empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER)?'1':'0').'))
{ {
print "\n".'<script type="text/javascript" language="javascript">'; jQuery(".visibleifcustomer").hide();
print '$(document).ready(function () { }
else
{
jQuery(".visibleifcustomer").show();
}
}
init_supplier_categ();
$("#fournisseur").change(function() {
init_supplier_categ();
});
function init_supplier_categ() {
console.log("is supplier = "+jQuery("#fournisseur").val());
if (jQuery("#fournisseur").val() == 0)
{
jQuery(".visibleifsupplier").hide();
}
else
{
jQuery(".visibleifsupplier").show();
}
};
$("#selectcountry_id").change(function() { $("#selectcountry_id").change(function() {
document.formsoc.action.value="edit"; document.formsoc.action.value="edit";
document.formsoc.submit(); document.formsoc.submit();
}); });
})'; })';
print '</script>'."\n"; print '</script>'."\n";
} }
@ -2022,8 +2075,7 @@ else
if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire))
{ {
// Customer // Customer
if ($object->prospect || $object->client || (! $object->fournisseur && ! empty($conf->global->THIRDPARTY_CAN_HAVE_CATEGORY_EVEN_IF_NOT_CUSTOMER_PROSPECT_SUPPLIER))) { print '<tr class="visibleifcustomer"><td>' . fieldLabel('CustomersCategoriesShort', 'custcats') . '</td>';
print '<tr><td>' . fieldLabel('CustomersCategoriesShort', 'custcats') . '</td>';
print '<td colspan="3">'; print '<td colspan="3">';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1); $cate_arbo = $form->select_all_categories(Categorie::TYPE_CUSTOMER, null, null, null, null, 1);
$c = new Categorie($db); $c = new Categorie($db);
@ -2034,11 +2086,9 @@ else
} }
print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%'); print $form->multiselectarray('custcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
print "</td></tr>"; print "</td></tr>";
}
// Supplier // Supplier
if ($object->fournisseur) { print '<tr class="visibleifsupplier"><td>' . fieldLabel('SuppliersCategoriesShort', 'suppcats') . '</td>';
print '<tr><td>' . fieldLabel('SuppliersCategoriesShort', 'suppcats') . '</td>';
print '<td colspan="3">'; print '<td colspan="3">';
$cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1); $cate_arbo = $form->select_all_categories(Categorie::TYPE_SUPPLIER, null, null, null, null, 1);
$c = new Categorie($db); $c = new Categorie($db);
@ -2050,7 +2100,6 @@ else
print $form->multiselectarray('suppcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%'); print $form->multiselectarray('suppcats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
print "</td></tr>"; print "</td></tr>";
} }
}
// Multicurrency // Multicurrency
if (! empty($conf->multicurrency->enabled)) if (! empty($conf->multicurrency->enabled))