Commit 9c3e9d1a by Damien Moulard

prestataire infos: deal with duplicates product family

parent f5ec1cab
......@@ -379,3 +379,11 @@ form[name="formEncaissement"] label {
cursor: pointer;
color: #a02923;
}
.presta-products-family-duplicate-warning {
display: none;
color: #ff4136;
margin-top: -0.25rem;
text-align: right;
font-style: italic;
}
\ No newline at end of file
......@@ -634,6 +634,10 @@ $(function() {
}
});
/**
* Delete a PrestataireProductFamily node on icon click
* @param {Event} e
*/
function deletePrestataireProductFamily(e) {
e.preventDefault();
$(this).closest('.presta-products-family')
......@@ -643,6 +647,35 @@ $(function() {
$(".presta-products-family-delete").on("click", deletePrestataireProductFamily);
/**
* Check if a product family is already selected on select change.
*/
function onPrestataireProductFamilyChange() {
let current_select_id = $(this).attr('id');
let current_select_selected_option = $( `#${current_select_id} option:selected` ).text();
let same_selected_option = false;
$('.prestataire-product-families-select').each(function() {
let select_id = $(this).attr('id');
let select_selected_option = $( `#${select_id} option:selected` ).text();
if (current_select_id !== select_id && current_select_selected_option === select_selected_option) {
same_selected_option = true;
return false;
}
});
$('.presta-products-family-fields .presta-products-family-duplicate-warning').hide();
$('.prestataire-product-families-products').attr('disabled', false);
if (same_selected_option) {
$(this).closest('.presta-products-family-fields').find('.presta-products-family-duplicate-warning').show();
$(this).closest('.presta-products-family-fields').find('.prestataire-product-families-products').attr('disabled', true);
}
}
$('.prestataire-product-families-select').on('change', onPrestataireProductFamilyChange);
/**
* Twig helper, add element to Collection in template based on collection prototype
* @param {*} e
*/
......@@ -665,8 +698,9 @@ $(function() {
$(".presta-products-family-delete").off("click", deletePrestataireProductFamily);
$(".presta-products-family-delete").on("click", deletePrestataireProductFamily);
$('.prestataire-product-families-select').off('change', onPrestataireProductFamilyChange);
$('.prestataire-product-families-select').on('change', onPrestataireProductFamilyChange);
};
$("#add-prestataire-products-family").on("click", addFormToCollection);
});
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -3,10 +3,10 @@
"app": {
"js": [
"/build/runtime.6ad5c9da.js",
"/build/app.e49db714.js"
"/build/app.a853f656.js"
],
"css": [
"/build/app.02f81748.css"
"/build/app.89f95ed2.css"
]
},
"admin": {
......
{
"build/app.css": "/build/app.02f81748.css",
"build/app.js": "/build/app.e49db714.js",
"build/app.css": "/build/app.89f95ed2.css",
"build/app.js": "/build/app.a853f656.js",
"build/admin.css": "/build/admin.5dc0eea7.css",
"build/admin.js": "/build/admin.86a2d986.js",
"build/runtime.js": "/build/runtime.6ad5c9da.js",
......
......@@ -49,6 +49,8 @@ class UserPrestataireController extends FluxController
}
$this->em->persist($adresse);
}
// caissiers validations
if (!empty($form->get('newcaissiers')->getData())) {
$caissiers = explode(';', $form->get('newcaissiers')->getData());
$errors = [];
......@@ -102,6 +104,17 @@ class UserPrestataireController extends FluxController
} elseif (!$request->isXmlHttpRequest()) {
return new Response('', Response::HTTP_BAD_REQUEST);
}
} else {
foreach ($form->getErrors(true, true) as $error) {
// Add flash error message in case of error with the embedded form
if (str_contains($error->getCause()->getPropertyPath(), 'productFamily')) {
$this->addFlash(
'error',
$error->getMessage()
);
break;
}
}
}
return $this->redirectToRoute('index');
......
......@@ -1228,6 +1228,8 @@ class Prestataire extends AccountableObject implements AccountableInterface
$prestataireProductFamily->setPrestataire(null);
}
}
return $this;
}
/**
......
......@@ -11,8 +11,8 @@ use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
* @ORM\Table(name="prestataire_product_family", uniqueConstraints={@ORM\UniqueConstraint(name="prestataireproductfamily", columns={"prestataire_id", "product_family_id"})}) )
* @UniqueEntity(
* fields={"prestataire", "productFamily"},
* errorPath="prestataire",
* message="Une relation existe déjà entre ce prestataire et cette famille de produits."
* errorPath="productFamily",
* message="Famille de produits déjà renseignée, les modifications n'ont pas été enregistrées."
* )
*/
class PrestataireProductFamily
......
......@@ -109,7 +109,11 @@ class PrestataireInfosFormType extends AbstractType
'allow_add' => true,
'allow_delete' => true,
'by_reference' => false,
'constraints' => new \Symfony\Component\Validator\Constraints\Valid(),
'label' => "Produits vendus, regroupés par famille ",
'error_mapping' => [
'productFamily' => 'prestataireProductFamilies',
],
]);
}
......
......@@ -21,10 +21,13 @@ class PrestataireProductFamilyFormType extends AbstractType
'choice_label' => 'name',
'label' => 'Famille de produits ',
'required' => true,
'placeholder' => 'Choisissez une famille',
'attr' => ['class' => 'prestataire-product-families-select']
))
->add('products', TextType::class, [
'label' => 'Produits ',
'required' => true,
'attr' => ['class' => 'prestataire-product-families-products']
])
;
}
......
......@@ -23,6 +23,7 @@
{{ form_label(prestataireProductFamilyForm.products) }}
{{ form_widget(prestataireProductFamilyForm.products) }}
</div>
<div class="presta-products-family-duplicate-warning">{{'Cette famille de produits est déjà renseignée.'|trans}}</div>
</div>
<a href="#" class="presta-products-family-delete">
<i
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment