diff --git a/README copy.md b/README copy.md deleted file mode 100644 index a62e35c..0000000 --- a/README copy.md +++ /dev/null @@ -1,96 +0,0 @@ -# European CV bundle -Bundle provides form for creating CV in european format. It also optionally embeds required JS and predefined CSS. -CV can be saved to database, exported to DOC or PDF format. - -## Installation -Add to composer.json: -```console -composer require trexima/european-cv -``` - - -JS and CSS libs: -``` -yarn add bootstrap -yarn add @fortawesome/fontawesome-free -yarn add jquery -yarn add jquery-ui -yarn add blueimp-file-upload -yarn add sortablejs -yarn add jquery.dirtyforms -yarn add select2 -yarn add select2-bootstrap-theme -yarn add parsleyjs -yarn add flatpickr -yarn add bs-custom-file-input -``` - -NOTE: For required external libs include: -``` -./vendor/trexima/european-cv-bundle/Resources/assets/css/shared.scss -``` - -### Installing assets with Webpack encore: -```js -Encore.addEntry('trexima-european-cv', [ - './vendor/trexima/european-cv/Resources/assets/js/main.js', - './vendor/trexima/european-cv/Resources/public/build/trexima-european-cv.css' -]) -``` - -**Fucking jquery.dirtyforms hack(webpack.config.js):** -```js -const config = Encore.getWebpackConfig(); -// Required because of bug in jquery.dirtyforms https://github.com/snikch/jquery.dirtyforms/issues/82 -config.externals = { - window: 'window', - document: 'document' -}; - -// export the final configuration -module.exports = config; -``` - -Add CSS and JS to Twig templates: -```twig -{% block stylesheets %} - {{ encore_entry_link_tags('trexima-european-cv') }} - {{ parent() }} -{% endblock %} - -{% block javascripts %} - {{ encore_entry_script_tags('trexima-european-cv') }} - {{ parent() }} -{% endblock %} -``` - -## Configuration -Add upload route to global configuration: -``` -trexima_european_cv_annotations: - resource: '@TreximaEuropeanCvBundle/Controller/' - type: annotation -``` - -Route name for AJAX images uploading: -``` -trexima_european_cv_bundle_image -``` - -Define entity that will be in relation with european CV and upload dir: -``` -trexima_european_cv: - upload_url: '/uploads/european-cv/' - upload_dir: '%kernel.project_dir%/public/uploads/european-cv/' - user_class: App\Entity\User -``` -**trexima_european_cv.yaml** - -**NOTE: Don't forget to update Doctrine schema.** - -### Translations -If you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config. -```yaml -framework: - translator: ~ -``` diff --git a/README.md b/README.md index edb9612..a62e35c 100644 --- a/README.md +++ b/README.md @@ -1 +1,96 @@ -# cv \ No newline at end of file +# European CV bundle +Bundle provides form for creating CV in european format. It also optionally embeds required JS and predefined CSS. +CV can be saved to database, exported to DOC or PDF format. + +## Installation +Add to composer.json: +```console +composer require trexima/european-cv +``` + + +JS and CSS libs: +``` +yarn add bootstrap +yarn add @fortawesome/fontawesome-free +yarn add jquery +yarn add jquery-ui +yarn add blueimp-file-upload +yarn add sortablejs +yarn add jquery.dirtyforms +yarn add select2 +yarn add select2-bootstrap-theme +yarn add parsleyjs +yarn add flatpickr +yarn add bs-custom-file-input +``` + +NOTE: For required external libs include: +``` +./vendor/trexima/european-cv-bundle/Resources/assets/css/shared.scss +``` + +### Installing assets with Webpack encore: +```js +Encore.addEntry('trexima-european-cv', [ + './vendor/trexima/european-cv/Resources/assets/js/main.js', + './vendor/trexima/european-cv/Resources/public/build/trexima-european-cv.css' +]) +``` + +**Fucking jquery.dirtyforms hack(webpack.config.js):** +```js +const config = Encore.getWebpackConfig(); +// Required because of bug in jquery.dirtyforms https://github.com/snikch/jquery.dirtyforms/issues/82 +config.externals = { + window: 'window', + document: 'document' +}; + +// export the final configuration +module.exports = config; +``` + +Add CSS and JS to Twig templates: +```twig +{% block stylesheets %} + {{ encore_entry_link_tags('trexima-european-cv') }} + {{ parent() }} +{% endblock %} + +{% block javascripts %} + {{ encore_entry_script_tags('trexima-european-cv') }} + {{ parent() }} +{% endblock %} +``` + +## Configuration +Add upload route to global configuration: +``` +trexima_european_cv_annotations: + resource: '@TreximaEuropeanCvBundle/Controller/' + type: annotation +``` + +Route name for AJAX images uploading: +``` +trexima_european_cv_bundle_image +``` + +Define entity that will be in relation with european CV and upload dir: +``` +trexima_european_cv: + upload_url: '/uploads/european-cv/' + upload_dir: '%kernel.project_dir%/public/uploads/european-cv/' + user_class: App\Entity\User +``` +**trexima_european_cv.yaml** + +**NOTE: Don't forget to update Doctrine schema.** + +### Translations +If you wish to use default texts provided in this bundle, you have to make sure you have translator enabled in your config. +```yaml +framework: + translator: ~ +``` diff --git a/composer.json b/composer.json index f07b1b3..75b50ea 100644 --- a/composer.json +++ b/composer.json @@ -2,7 +2,7 @@ "name": "trexima/cv", "description": "Bundle provides form for creating CV in european format.", "type": "symfony-bundle", - "version": "1.7.0", + "version": "1.7.1", "license": "MIT", "keywords": ["cv"], "authors": [ diff --git a/src/Entity/EuropeanCVDrivingLicense.php b/src/Entity/EuropeanCVDrivingLicense.php index 01f88e3..05990d7 100644 --- a/src/Entity/EuropeanCVDrivingLicense.php +++ b/src/Entity/EuropeanCVDrivingLicense.php @@ -35,7 +35,7 @@ class EuropeanCVDrivingLicense 'comment' => 'Distance traveled in kilometers' ], )] - private ?string $distanceTraveled = null; + private ?int $distanceTraveled = null; #[ORM\Column(type: 'boolean')] private ?bool $activeDriver = null; @@ -69,12 +69,12 @@ public function setDrivingLicense(?DrivingLicenseEnum $drivingLicense): self return $this; } - public function getDistanceTraveled(): ?string + public function getDistanceTraveled(): ?int { return $this->distanceTraveled; } - public function setDistanceTraveled(?string $distanceTraveled): self + public function setDistanceTraveled(?int $distanceTraveled): self { $this->distanceTraveled = $distanceTraveled; diff --git a/src/Form/Parts/EuropeanCVPartDrivingLicenseType.php b/src/Form/Parts/EuropeanCVPartDrivingLicenseType.php index da04b2b..ca3e339 100644 --- a/src/Form/Parts/EuropeanCVPartDrivingLicenseType.php +++ b/src/Form/Parts/EuropeanCVPartDrivingLicenseType.php @@ -5,6 +5,8 @@ use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormInterface; +use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; use Trexima\EuropeanCvBundle\Entity\EuropeanCV; use Trexima\EuropeanCvBundle\Form\Type\DrivingLicenseType; @@ -22,13 +24,6 @@ class EuropeanCVPartDrivingLicenseType extends AbstractType */ public function buildForm(FormBuilderInterface $builder, array $options): void { - $entity = $builder->getData(); - - $drivingLicenses = []; - foreach ($entity->getDrivingLicenses() as $drivingLicense) { - $drivingLicenses[] = $drivingLicense->getDrivingLicense()->value; - } - $builder ->add('drivingLicenseOwner', CheckboxType::class, [ 'required' => false, @@ -53,11 +48,14 @@ public function buildForm(FormBuilderInterface $builder, array $options): void ] ], 'required' => false, - 'hidden' => empty($entity?->getDrivingLicenseOwner()), - 'existing_licenses' => $drivingLicenses, ]); } + public function finishView(FormView $view, FormInterface $form, array $options) + { + $view->children['drivingLicenses']->vars['hidden'] = !$form->getData()?->getDrivingLicenseOwner(); + } + /** * {@inheritdoc} */ diff --git a/src/Form/Type/DrivingLicenseType.php b/src/Form/Type/DrivingLicenseType.php index e0fbe15..9411d5e 100644 --- a/src/Form/Type/DrivingLicenseType.php +++ b/src/Form/Type/DrivingLicenseType.php @@ -69,7 +69,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'attr' => [ 'class' => 'form-inline' ], - 'existing_licenses' => $options['existing_licenses'] ], $options['entry_options']) ); } @@ -122,7 +121,6 @@ public function configureOptions(OptionsResolver $resolver) 'entry_options' => [ 'required' => false, ], - 'existing_licenses' => [] ]); } diff --git a/src/Form/Type/EuropeanCVDrivingLicenseType.php b/src/Form/Type/EuropeanCVDrivingLicenseType.php index ea3da57..7df4711 100644 --- a/src/Form/Type/EuropeanCVDrivingLicenseType.php +++ b/src/Form/Type/EuropeanCVDrivingLicenseType.php @@ -9,6 +9,7 @@ use Symfony\Component\Form\FormInterface; use Symfony\Component\Form\FormView; use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Validator\Constraints as Assert; use Trexima\EuropeanCvBundle\Entity\Enum\DrivingLicenseEnum; use Trexima\EuropeanCvBundle\Entity\EuropeanCVDrivingLicense; @@ -44,12 +45,13 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'required' => false, 'attr' => [ 'placeholder' => t('trexima_european_cv.form_label.driving_license_distance_traveled_placeholder', [], 'trexima_european_cv') ], - 'hidden' => !in_array($drivingLicense->value, $options['existing_licenses']) + 'constraints' => [ + new Assert\Range(min: 0, max: 2 ** 32 - 1), + ], ]) ->add('activeDriver', CheckboxType::class, [ 'label' => t('trexima_european_cv.form_label.driving_license_active_driver_label', [], 'trexima_european_cv'), 'required' => false, - 'hidden' => !in_array($drivingLicense->value, $options['existing_licenses']) ]) ; @@ -82,6 +84,14 @@ public function buildView(FormView $view, FormInterface $form, array $options) $view->vars['driving_license'] = $options['driving_license']; } + public function finishView(FormView $view, FormInterface $form, array $options) + { + $drivingLicense = $form->getData()?->getDrivingLicense(); + + $view->children['distanceTraveled']->vars['hidden'] = !$drivingLicense; + $view->children['activeDriver']->vars['hidden'] = !$drivingLicense; + } + /** * {@inheritdoc} */ @@ -90,7 +100,6 @@ public function configureOptions(OptionsResolver $resolver) parent::configureOptions($resolver); $resolver->setDefaults([ 'data_class' => EuropeanCVDrivingLicense::class, - 'existing_licenses' => [] ]); $resolver->setRequired([