diff --git a/src/Bundle/ChillMainBundle/Form/Type/PickAddressType.php b/src/Bundle/ChillMainBundle/Form/Type/PickAddressType.php index efd117b96..e613fdf65 100644 --- a/src/Bundle/ChillMainBundle/Form/Type/PickAddressType.php +++ b/src/Bundle/ChillMainBundle/Form/Type/PickAddressType.php @@ -10,6 +10,7 @@ use Symfony\Component\Form\FormBuilderInterface; use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Contracts\Translation\TranslatorInterface; /** * Form type for picking an address. @@ -32,10 +33,14 @@ use Symfony\Component\OptionsResolver\OptionsResolver; final class PickAddressType extends AbstractType { private AddressToIdDataTransformer $addressToIdDataTransformer; + private TranslatorInterface $translator; - public function __construct(AddressToIdDataTransformer $addressToIdDataTransformer) - { + public function __construct( + AddressToIdDataTransformer $addressToIdDataTransformer, + TranslatorInterface $translator + ) { $this->addressToIdDataTransformer = $addressToIdDataTransformer; + $this->translator = $translator; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -46,16 +51,20 @@ final class PickAddressType extends AbstractType public function buildView(FormView $view, FormInterface $form, array $options) { $view->vars['uniqid'] = $view->vars['attr']['data-input-address'] =\uniqid('input_address_'); - $view->vars['attr']['data-use-valid-from'] = $options['useValidFrom']; - $view->vars['attr']['data-use-valid-to'] = $options['useValidTo']; + $view->vars['attr']['data-use-valid-from'] = (int) $options['use_valid_from']; + $view->vars['attr']['data-use-valid-to'] = (int) $options['use_valid_to']; + $view->vars['attr']['data-button-text-create'] = $this->translator->trans($options['button_text_create']); + $view->vars['attr']['data-button-text-update'] = $this->translator->trans($options['button_text_update']); } public function configureOptions(OptionsResolver $resolver) { $resolver->setDefaults([ 'class' => Address::class, - 'useValidFrom' => false, - 'useValidTo' => false, + 'use_valid_to' => false, + 'use_valid_from' => false, + 'button_text_create' => 'Create an address', + 'button_text_update' => 'Update address', // reset default from hidden type 'required' => true, diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue index 55d8a93d1..5616ce0be 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/AddAddress.vue @@ -267,6 +267,9 @@ export default { title: { create: 'add_an_address_title', edit: 'edit_address' }, openPanesInModal: true, stickyActions: false, + // show a message when no address. + // if set to undefined, the value will be equivalent to false if stickyActions is false, true otherwise. + showMessageWhenNoAddress: undefined, useDate: { validFrom: false, validTo: false diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue index 8f80b840e..4be073991 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/components/ShowPane.vue @@ -15,7 +15,7 @@ {{ $t('wait_redirection') }} -
+

{{ $t('not_yet_address') }}

@@ -50,8 +50,8 @@ export default { }, props: [ 'context', - 'options', 'defaultz', + 'options', 'flag', 'entity', 'errorMsg', @@ -91,7 +91,11 @@ export default { forceRedirect() { return (!(this.context.backUrl === null || typeof this.context.backUrl === 'undefined')); }, - noAddressWithStickyActions() { + showMessageWhenNoAddress() { + let showMessageWhenNoAddress = this.options.showMessageWhenNoAddress === undefined ? this.defaultz.showMessageWhenNoAddress : this.options.showMessageWhenNoAddress; + if (showMessageWhenNoAddress === true || showMessageWhenNoAddress === false) { + return !this.context.edit && !this.address.id && showMessageWhenNoAddress; + } return !this.context.edit && !this.address.id && this.options.stickyActions; } } diff --git a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js index eb214296c..ad4a648f5 100644 --- a/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js +++ b/src/Bundle/ChillMainBundle/Resources/public/vuejs/Address/mod_input_address_index.js @@ -14,8 +14,6 @@ inputs.forEach(el => { addressId = el.value, uniqid = el.dataset.inputAddress, container = document.querySelector('div[data-input-address-container="' + uniqid + '"]'), - currentTarget = el, - i = 0, isEdit = addressId !== '', addressIdInt = addressId !== '' ? parseInt(addressId) : null ; @@ -23,6 +21,7 @@ inputs.forEach(el => { if (container === null) { throw Error("no container"); } + console.log('useValidFrom', el.dataset.useValidFrom === '1'); const app = createApp({ template: ``, @@ -43,11 +42,11 @@ inputs.forEach(el => { /// null value take default component value defined in AddAddress data() button: { text: { - create: null, - edit: null, + create: el.dataset.buttonTextCreate || null, + edit: el.dataset.buttonTextUpdate || null, }, size: null, - displayText: false + displayText: true }, /// Modal title text if create or edit address (trans chain, see i18n) @@ -61,11 +60,12 @@ inputs.forEach(el => { /// Display actions buttons of panes in a sticky-form-button navbar stickyActions: false, + showMessageWhenNoAddress: true, /// Use Date fields useDate: { - validFrom: el.dataset.useValidFrom === 'true', //boolean, default: false - validTo: el.dataset.useValidTo === 'true' //boolean, default: false + validFrom: el.dataset.useValidFrom === '1' || false, //boolean, default: false + validTo: el.dataset.useValidTo === '1' || false, //boolean, default: false }, /// Don't display show renderbox Address: showPane display only a button @@ -76,7 +76,6 @@ inputs.forEach(el => { }, methods: { associateToInput(payload) { - console.log(payload); el.value = payload.addressId; } } diff --git a/src/Bundle/ChillMainBundle/translations/messages.fr.yml b/src/Bundle/ChillMainBundle/translations/messages.fr.yml index a9ca52593..4beb43dd1 100644 --- a/src/Bundle/ChillMainBundle/translations/messages.fr.yml +++ b/src/Bundle/ChillMainBundle/translations/messages.fr.yml @@ -84,6 +84,8 @@ address more: extra: "" distribution: cedex Create a new address: Créer une nouvelle adresse +Create an address: Créer une adresse +Update address: Modifier l'adresse #serach Your search is empty. Please provide search terms.: La recherche est vide. Merci de fournir des termes de recherche. diff --git a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php index 139f6c0f9..2c7380116 100644 --- a/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php +++ b/src/Bundle/ChillThirdPartyBundle/Form/ThirdPartyType.php @@ -89,28 +89,6 @@ class ThirdPartyType extends AbstractType ]) ; - /* - $builder - /* - ->add('address', HiddenType::class) - ->get('address') - ->addModelTransformer(new CallbackTransformer( - function (?Address $address): string { - if (null === $address) { - return ''; - } - return $address->getId(); - }, - function (?string $addressId): ?Address { - if (null === $addressId) { - return null; - } - return $this->om - ->getRepository(Address::class) - ->findOneBy(['id' => (int) $addressId]); - } - ))*/ - // Contact Person ThirdParty (child) if (ThirdParty::KIND_CONTACT === $options['kind'] || ThirdParty::KIND_CHILD === $options['kind']) { $builder @@ -152,6 +130,12 @@ class ThirdPartyType extends AbstractType ->add('address', PickAddressType::class, [ 'label' => 'Address' ]) + ->add('address2', PickAddressType::class, [ + 'label' => 'Address', + 'use_valid_from' => true, + 'use_valid_to' => true, + 'mapped' => false, + ]) ->add('nameCompany', TextType::class, [ 'label' => 'thirdparty.NameCompany', 'required' => false