mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
some tweaks into PickAddressType
This commit is contained in:
parent
6fccc70e41
commit
9a02665053
@ -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,
|
||||
|
@ -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
|
||||
|
@ -15,7 +15,7 @@
|
||||
<span v-if="forceRedirect">{{ $t('wait_redirection') }}</span>
|
||||
</div>
|
||||
|
||||
<div v-if="noAddressWithStickyActions" class="mt-5">
|
||||
<div v-if="showMessageWhenNoAddress" class="mt-5">
|
||||
<p class="chill-no-data-statement">
|
||||
{{ $t('not_yet_address') }}
|
||||
</p>
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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: `<app v-bind:addAddress="this.addAddress" @address-created="associateToInput"></app>`,
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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.
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user