Skip to content

Commit

Permalink
Remove fax from customer.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentmuller committed Dec 24, 2024
1 parent ca07ca4 commit 3542ad5
Show file tree
Hide file tree
Showing 50 changed files with 545 additions and 614 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@
"vich/uploader-bundle": "^2.0"
},
"require-dev": {
"bamarni/composer-bin-plugin": "^1.8",
"fortawesome/font-awesome": "^6.6",
"bamarni/composer-bin-plugin": "^1.0",
"fortawesome/font-awesome": "^6.0",
"symfony/browser-kit": "7.2.*",
"symfony/css-selector": "7.2.*",
"symfony/debug-bundle": "7.2.*",
Expand Down
2 changes: 1 addition & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions config/services.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
$path . 'Model',
$path . 'Pdf',
$path . 'Report',
$path . 'Response',
$path . 'Spreadsheet',
$path . 'Traits',
$path . 'Util',
Expand Down
11 changes: 11 additions & 0 deletions public/images/logo/logo-customer.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 43 additions & 46 deletions public/js/application/parameters_edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,36 +111,38 @@ function displayNotification($source) {
/**
* Handle input change.
*
* @param {string} inputId the input selector.
* @param {string} selector the input selector.
* @param {string} groupId the group selector.
* @param {function} callback the function to call.
*/
function handleInput(inputId, groupId, callback) {
function handleInput(selector, groupId, callback) {
'use strict';
const $input = $(inputId);
const $group = $input.parents('.input-group').find(groupId);
if (!$input.length || !$group.length) {
return;
}
const handler = function (e) {
e.preventDefault();
const value = String($input.val()).trim();
if ($input.valid() && value) {
try {
callback(value);
} catch (error) {
$group.off('click', handler).removeClass('cursor-pointer');
window.console.error(error);
}
$(selector).each(function () {
const $input = $(this);
const $group = $input.parents('.input-group').find(groupId);
if (!$group.length) {
return;
}
$input.trigger('focus');
};
$input.on('input', function () {
$group.removeClass('cursor-pointer').off('click', handler);
if ($input.valid() && String($input.val()).trim()) {
$group.addClass('cursor-pointer').on('click', handler);
}
}).trigger('input');
const handler = function (e) {
e.preventDefault();
const value = String($input.val()).trim();
if (value && $input.valid()) {
try {
callback(value);
} catch (error) {
$group.off('click', handler).removeClass('cursor-pointer');
window.console.error(error);
}
}
$input.trigger('focus');
};
$input.on('input', function () {
$group.removeClass('cursor-pointer').off('click', handler);
if ($input.valid() && String($input.val()).trim()) {
$group.addClass('cursor-pointer').on('click', handler);
}
}).trigger('input');
});
}

/**
Expand All @@ -151,7 +153,7 @@ function handleUrl() {
const handler = function (value) {
window.open(value, '_blank');
};
handleInput('#customer_url', '.input-group-url', handler);
handleInput('[inputmode="url"]', '.input-group-url', handler);
}

/**
Expand All @@ -165,14 +167,6 @@ function handlePhone() {
handleInput('#customer_phone', '.input-group-phone', handler);
}

// function handleFax() {
// 'use strict';
// const handler = function (value) {
// window.location.href = 'fax:' + value;
// };
// handleInput('#customer_fax', '.input-group-fax', handler);
// }

/**
* Handle the Email input.
*/
Expand All @@ -184,6 +178,11 @@ function handleEmail() {
handleInput('#customer_email', '.input-group-email', handler);
}

function findCollapseButton($source) {
'use strict';
return $source.prev('.card-header').find('a.card-title');
}

/**
* Ready function
*/
Expand Down Expand Up @@ -213,32 +212,30 @@ $(function () {
$('.btn-item-all').on('click', function () {
setDefaultValues();
});
$('.btn-notify').on('click', () => {
const $items = $('.dropdown-notify');
const index = Math.floor(Math.random() * $items.length);
$items.eq(index).trigger('click');
});
$('.dropdown-notify').on('click', (e) => {
const $notify = $('.dropdown-notify');
$notify.on('click', (e) => {
displayNotification($(e.currentTarget));
});
$('.btn-notify').on('click', () => {
const index = Math.floor(Math.random() * $notify.length);
$notify.eq(index).trigger('click');
});
$('.card-parameter .collapse').on('shown.bs.collapse', function () {
const $this = $(this);
const $button = $this.prev('.card-header').find('a.card-title');
const $button = findCollapseButton($(this));
$button.attr('title', $button.data('hide'));
const $page = getActivePage();
if ($page && $page.find('.is-invalid').length === 0) {
$page.find(':input:first').trigger('focus');
$page.find(':input:first').trigger('focus')
.trigger('select');
}
updateVisibleButton();
}).on('hidden.bs.collapse', function () {
const $this = $(this);
const $button = $this.prev('.card-header').find('a.card-title');
const $button = findCollapseButton($(this));
$button.attr('title', $button.data('show'));
updateVisibleButton();
});
updateVisibleButton();
handlePhone();
handleEmail();
// handleFax();
handleUrl();
});
10 changes: 5 additions & 5 deletions public/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
},
{
"name": "font-awesome",
"version": "6.7.1",
"version": "6.7.2",
"source": "cdnjs",
"files": [
"css/all.css",
Expand Down Expand Up @@ -86,7 +86,7 @@
},
{
"name": "highcharts",
"version": "12.0.2",
"version": "12.1.2",
"source": "jsdelivr",
"files": [
"highcharts.js"
Expand Down Expand Up @@ -141,7 +141,7 @@
},
{
"name": "bootstrap-table",
"version": "1.23.5",
"version": "1.24.0",
"source": "cdnjs",
"files": [
"bootstrap-table.js",
Expand All @@ -151,7 +151,7 @@
{
"name": "bootstrap-table",
"display": "bootstrap-table:defer-url",
"version": "1.23.5",
"version": "1.24.0",
"source": "cdnjs",
"prefix": "extensions/defer-url/",
"files": [
Expand All @@ -161,7 +161,7 @@
{
"name": "bootstrap-table",
"display": "bootstrap-table:custom-view",
"version": "1.23.5",
"version": "1.24.0",
"source": "cdnjs",
"prefix": "extensions/custom-view/",
"files": [
Expand Down
2 changes: 1 addition & 1 deletion src/Faker/EntityProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ protected function distinctValue(string $field, bool $allowNull = false): mixed

$values = $this->distinctValues[$field];
if ($allowNull) {
$values += [null];
$values[] = null;
}

return static::randomElement($values);
Expand Down
4 changes: 0 additions & 4 deletions src/Form/Admin/ApplicationParametersType.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,6 @@ private function addCustomerSection(FormHelper $helper): void
->notRequired()
->addTelType();

$helper->field(PropertyServiceInterface::P_CUSTOMER_FAX)
->notRequired()
->addFaxType();

$helper->field(PropertyServiceInterface::P_CUSTOMER_EMAIL)
->updateOption('prepend_title', 'parameters.fields.customer_email_title')
->notRequired()
Expand Down
22 changes: 6 additions & 16 deletions src/Form/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -269,17 +269,6 @@ public function addEnumType(string $class): self
return $this->add(EnumType::class);
}

/**
* Add a fax (telephone) type to the builder and reset all values to the default.
*/
public function addFaxType(?string $pattern = null): self
{
return $this->updateAttribute('pattern', $pattern)
->updateOption('prepend_icon', 'fa-solid fa-fax')
->updateOption('prepend_class', 'input-group-fax')
->add(TelType::class);
}

/**
* Add a file type to the builder and reset all values to the default.
*
Expand Down Expand Up @@ -478,14 +467,15 @@ public function addTrueFalseType(
/**
* Add an Url type to the builder and reset all values to the default.
*
* @param string $protocol If a value is submitted, that doesn't begin with some protocol,
* (http://, ftp://, etc.), this protocol will be prepended to
* the string when the data is submitted to the form.
* @param string $protocol If a value is submitted, that doesn't begin with some protocol,
* (http://, ftp://, etc.), this protocol will be prepended to
* the string when the data is submitted to the form.
* @param ?string $icon the prepended icon or null to use default (solid globe)
*/
public function addUrlType(string $protocol = 'https'): self
public function addUrlType(string $protocol = 'https', ?string $icon = null): self
{
return $this->updateOption('default_protocol', $protocol)
->updateOption('prepend_icon', 'fa-solid fa-globe')
->updateOption('prepend_icon', $icon ?? 'fa-solid fa-globe')
->updateOption('prepend_class', 'input-group-url')
->updateAttribute('inputmode', 'url')
->add(UrlType::class);
Expand Down
57 changes: 57 additions & 0 deletions src/Form/Parameters/AbstractHelperParametersType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php

/*
* This file is part of the Calculation package.
*
* (c) bibi.nu <bibi@bibi.nu>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

declare(strict_types=1);

namespace App\Form\Parameters;

use App\Parameter\AbstractParameters;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;

/**
* @template TParameters of AbstractParameters
*
* @extends AbstractType<mixed>
*/
abstract class AbstractHelperParametersType extends AbstractType
{
public const DEFAULT_VALUES = 'default_values';

public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder->add('display', DisplayParameterType::class);
$builder->add('homePage', HomePageParameterType::class);
$builder->add('message', MessageParameterType::class);
$builder->add('options', OptionsParameterType::class);
}

public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => $this->getParametersClass(),
]);

$resolver->setDefault(self::DEFAULT_VALUES, [])
->setAllowedTypes(self::DEFAULT_VALUES, 'array');
}

public function getBlockPrefix(): string
{
return '';
}

/**
* @return class-string<TParameters>
*/
abstract protected function getParametersClass(): string;
}
12 changes: 4 additions & 8 deletions src/Form/Parameters/AbstractParameterType.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,24 +92,20 @@ private function convertValue(string $key, mixed $value): mixed
return $value;
}

private function getCacheKey(): string
{
return $this->getParameterClass()::getCacheKey();
}

/**
* @psalm-return array<string, mixed>
*/
private function getDefaultValues(FormInterface $form): array
{
$config = $form->getRoot()->getConfig();
if (!$config->hasOption(ApplicationParametersType::DEFAULT_VALUES)) {
if (!$config->hasOption(AbstractHelperParametersType::DEFAULT_VALUES)) {
return [];
}

$key = $this->getParameterClass()::getCacheKey();
/** @psalm-var array<string, array<string, mixed>> $values */
$values = $config->getOption(ApplicationParametersType::DEFAULT_VALUES);
$values = $config->getOption(AbstractHelperParametersType::DEFAULT_VALUES);

return $values[$this->getCacheKey()] ?? [];
return $values[$key] ?? [];
}
}
Loading

0 comments on commit 3542ad5

Please sign in to comment.