mirror of
				https://gitlab.com/Chill-Projet/chill-bundles.git
				synced 2025-10-30 08:49:05 +00:00 
			
		
		
		
	Allow Pick*Type to submit the form when selection an entity, and apply inside Event
This commit is contained in:
		| @@ -411,20 +411,17 @@ final class EventController extends AbstractController | ||||
|                 ] | ||||
|             ); | ||||
|  | ||||
|         $builder->add('person_id', PickPersonDynamicType::class, ['as_id' => true, 'multiple' => false]); | ||||
|         $builder->add('person_id', PickPersonDynamicType::class, [ | ||||
|             'as_id' => true, | ||||
|             'multiple' => false, | ||||
|             'submit_on_adding_new_entity' => true, | ||||
|             'label' => 'Add a participation', | ||||
|         ]); | ||||
|  | ||||
|         $builder->add('event_id', HiddenType::class, [ | ||||
|             'data' => $event->getId(), | ||||
|         ]); | ||||
|  | ||||
|         $builder->add( | ||||
|             'submit', | ||||
|             SubmitType::class, | ||||
|             [ | ||||
|                 'label' => 'Add a participation', | ||||
|             ] | ||||
|         ); | ||||
|  | ||||
|         return $builder->getForm(); | ||||
|     } | ||||
|  | ||||
|   | ||||
| @@ -101,7 +101,12 @@ final readonly class EventListController | ||||
|                 ] | ||||
|             ); | ||||
|  | ||||
|         $builder->add('person_id', PickPersonDynamicType::class, ['as_id' => true, 'multiple' => false]); | ||||
|         $builder->add('person_id', PickPersonDynamicType::class, [ | ||||
|             'as_id' => true, | ||||
|             'multiple' => false, | ||||
|             'submit_on_adding_new_entity' => true, | ||||
|             'label' => 'Add a participation', | ||||
|         ]); | ||||
|  | ||||
|         $builder->add('event_id', HiddenType::class, [ | ||||
|             'data' => $event->getId(), | ||||
|   | ||||
| @@ -60,18 +60,13 @@ | ||||
|                             {% endif %} | ||||
|                         </div> | ||||
|                     {% endif %} | ||||
|                     {# | ||||
|                     <div class="item-row"> | ||||
|                         <div class="item-col"> | ||||
|                             {{ form_start(eventForms[e.id]) }} | ||||
|                             {{ form_widget(eventForms[e.id].person_id) }} | ||||
|                             <ul class="record_actions"> | ||||
|                                 <li><button type="submit" class="btn btn-create"></button></li> | ||||
|                             </ul> | ||||
|                             {{ form_end(eventForms[e.id]) }} | ||||
|                         </div> | ||||
|                     </div> | ||||
|                     #} | ||||
|                     <div class="item-row separator"> | ||||
|                         <div class="item-col item-meta"> | ||||
|                         </div> | ||||
|   | ||||
| @@ -136,11 +136,8 @@ | ||||
|                     'class' : 'custom-select', | ||||
|                     'style': 'min-width: 15em; max-width: 18em; display: inline-block;' | ||||
|                 }} ) }} | ||||
|                 <div class="input-group-append"> | ||||
|                     {{ form_widget(form_add_participation_by_person.submit, { 'attr' : { 'class' : 'btn btn-create' } } ) }} | ||||
|                 </div> | ||||
|             </div> | ||||
|             {{ form_rest(form_add_participation_by_person) }} | ||||
|             <input type="hidden" name="returnPath" value="{{ app.request.requestUri }}" /> | ||||
|             {{ form_end(form_add_participation_by_person) }} | ||||
|         </div> | ||||
|  | ||||
|   | ||||
| @@ -43,6 +43,7 @@ class PickUserDynamicType extends AbstractType | ||||
|         $view->vars['uniqid'] = uniqid('pick_user_dyn'); | ||||
|         $view->vars['suggested'] = []; | ||||
|         $view->vars['as_id'] = true === $options['as_id'] ? '1' : '0'; | ||||
|         $view->vars['submit_on_adding_new_entity'] = true === $options['submit_on_adding_new_entity'] ? '1' : '0'; | ||||
|  | ||||
|         foreach ($options['suggested'] as $user) { | ||||
|             $view->vars['suggested'][] = $this->normalizer->normalize($user, 'json', ['groups' => 'read']); | ||||
| @@ -58,7 +59,9 @@ class PickUserDynamicType extends AbstractType | ||||
|             ->setDefault('suggested', []) | ||||
|             // if set to true, only the id will be set inside the content. The denormalization will not work. | ||||
|             ->setDefault('as_id', false) | ||||
|             ->setAllowedTypes('as_id', ['bool']); | ||||
|             ->setAllowedTypes('as_id', ['bool']) | ||||
|             ->setDefault('submit_on_adding_new_entity', false) | ||||
|             ->setAllowedTypes('submit_on_adding_new_entity', ['bool']); | ||||
|     } | ||||
|  | ||||
|     public function getBlockPrefix() | ||||
|   | ||||
| @@ -25,7 +25,9 @@ function loadDynamicPicker(element) { | ||||
|                         null : [ JSON.parse(input.value) ] | ||||
|                 ) | ||||
|             suggested = JSON.parse(el.dataset.suggested), | ||||
|             as_id = parseInt(el.dataset.asId) === 1; | ||||
|             as_id = parseInt(el.dataset.asId) === 1, | ||||
|             submit_on_adding_new_entity = parseInt(el.dataset.submitOnAddingNewEntity) === 1 | ||||
|             label = el.dataset.label; | ||||
|  | ||||
|         if (!isMultiple) { | ||||
|             if (input.value === '[]'){ | ||||
| @@ -40,6 +42,7 @@ function loadDynamicPicker(element) { | ||||
|                 ':picked="picked" ' + | ||||
|                 ':uniqid="uniqid" ' + | ||||
|                 ':suggested="notPickedSuggested" ' + | ||||
|                 ':label="label" ' + | ||||
|                 '@addNewEntity="addNewEntity" ' + | ||||
|                 '@removeEntity="removeEntity"></pick-entity>', | ||||
|             components: { | ||||
| @@ -51,8 +54,10 @@ function loadDynamicPicker(element) { | ||||
|                     types: JSON.parse(el.dataset.types), | ||||
|                     picked: picked === null ? [] : picked, | ||||
|                     uniqid: el.dataset.uniqid, | ||||
|                     suggested: suggested, | ||||
|                     as_id: as_id, | ||||
|                     suggested, | ||||
|                     as_id, | ||||
|                     submit_on_adding_new_entity, | ||||
|                     label, | ||||
|                 } | ||||
|             }, | ||||
|             computed: { | ||||
| @@ -92,6 +97,10 @@ function loadDynamicPicker(element) { | ||||
|                             } | ||||
|                         } | ||||
|                     } | ||||
|  | ||||
|                     if (this.submit_on_adding_new_entity) { | ||||
|                         input.form.submit(); | ||||
|                     } | ||||
|                 }, | ||||
|                 removeEntity({entity}) { | ||||
|                     if (-1 === this.suggested.findIndex(e => e.type === entity.type && e.id === entity.id)) { | ||||
|   | ||||
| @@ -56,6 +56,10 @@ export default { | ||||
|         suggested: { | ||||
|           type: Array, | ||||
|           default: [] | ||||
|         }, | ||||
|         label: { | ||||
|             type: String, | ||||
|             required: false, | ||||
|         } | ||||
|     }, | ||||
|     emits: ['addNewEntity', 'removeEntity'], | ||||
| @@ -80,6 +84,10 @@ export default { | ||||
|           }; | ||||
|       }, | ||||
|       translatedListOfTypes() { | ||||
|           if (this.label !== '') { | ||||
|               return this.label; | ||||
|           } | ||||
|  | ||||
|           let trans = []; | ||||
|           this.types.forEach(t => { | ||||
|               if (this.$props.multiple) { | ||||
|   | ||||
| @@ -257,7 +257,9 @@ | ||||
|          data-multiple="{{ form.vars['multiple'] }}" | ||||
|          data-uniqid="{{ form.vars['uniqid'] }}" | ||||
|          data-suggested="{{ form.vars['suggested']|json_encode|escape('html_attr') }}" | ||||
|          data-as-id="{{ form.vars['as_id'] }}"></div> | ||||
|          data-as-id="{{ form.vars['as_id'] }}" | ||||
|          data-submit-on-adding-new-entity="{{ form.vars['submit_on_adding_new_entity'] }}" | ||||
|          data-label="{{ form.vars['label']|trans|escape('html_attr') }}"></div> | ||||
| {% endblock %} | ||||
|  | ||||
| {% block pick_postal_code_widget %} | ||||
|   | ||||
| @@ -42,6 +42,7 @@ class PickPersonDynamicType extends AbstractType | ||||
|         $view->vars['uniqid'] = uniqid('pick_user_dyn'); | ||||
|         $view->vars['suggested'] = []; | ||||
|         $view->vars['as_id'] = true === $options['as_id'] ? '1' : '0'; | ||||
|         $view->vars['submit_on_adding_new_entity'] = true === $options['submit_on_adding_new_entity'] ? '1' : '0'; | ||||
|  | ||||
|         foreach ($options['suggested'] as $person) { | ||||
|             $view->vars['suggested'][] = $this->normalizer->normalize($person, 'json', ['groups' => 'read']); | ||||
| @@ -56,7 +57,9 @@ class PickPersonDynamicType extends AbstractType | ||||
|             ->setDefault('compound', false) | ||||
|             ->setDefault('suggested', []) | ||||
|             ->setDefault('as_id', false) | ||||
|             ->setAllowedTypes('as_id', ['bool']); | ||||
|             ->setAllowedTypes('as_id', ['bool']) | ||||
|             ->setDefault('submit_on_adding_new_entity', false) | ||||
|             ->setAllowedTypes('submit_on_adding_new_entity', ['bool']); | ||||
|     } | ||||
|  | ||||
|     public function getBlockPrefix() | ||||
|   | ||||
| @@ -42,6 +42,7 @@ class PickThirdpartyDynamicType extends AbstractType | ||||
|         $view->vars['uniqid'] = uniqid('pick_user_dyn'); | ||||
|         $view->vars['suggested'] = []; | ||||
|         $view->vars['as_id'] = true === $options['as_id'] ? '1' : '0'; | ||||
|         $view->vars['submit_on_adding_new_entity'] = true === $options['submit_on_adding_new_entity'] ? '1' : '0'; | ||||
|  | ||||
|         foreach ($options['suggested'] as $tp) { | ||||
|             $view->vars['suggested'][] = $this->normalizer->normalize($tp, 'json', ['groups' => 'read']); | ||||
| @@ -56,7 +57,9 @@ class PickThirdpartyDynamicType extends AbstractType | ||||
|             ->setDefault('compound', false) | ||||
|             ->setDefault('suggested', []) | ||||
|             ->setDefault('as_id', false) | ||||
|             ->setAllowedTypes('as_id', ['bool']); | ||||
|             ->setAllowedTypes('as_id', ['bool']) | ||||
|             ->setDefault('submit_on_adding_new_entity', false) | ||||
|             ->setAllowedTypes('submit_on_adding_new_entity', ['bool']); | ||||
|     } | ||||
|  | ||||
|     public function getBlockPrefix() | ||||
|   | ||||
		Reference in New Issue
	
	Block a user