diff --git a/js/form-sdk/widget-factory.js b/js/form-sdk/widget-factory.js index 46aa7c2d9..c17bf8776 100644 --- a/js/form-sdk/widget-factory.js +++ b/js/form-sdk/widget-factory.js @@ -31,9 +31,47 @@ const iTopFormWidgetFactory = new function(){ } }); - + $('[data-widget="AreaWidget"]').each(function(e){ + const oElement = $(this); + if(!oElement.data('widget-state-initialized')){ + const sId = oElement.attr('id'); + const aOptions = oElement.data('widget-options'); + iTopFormWidgetFactory.CreateAreaWidget(sId, aOptions); + oElement.data('widget-state-initialized', true); + } + }); } + /** + * CreateAreaWidget. + * + * @param {string} sId + * @param {array} aOptions + * @constructor + */ + const CreateAreaWidget = function(sId, aOptions){ + + console.log('CreateAreaWidget', sId, aOptions); + + + editor = CKEDITOR.replace(sId, { + language: 'fr', + stylesSet: 'my_styles', + toolbarCanCollapse: false, + toolbarGroups: [ + { name: 'tools'}, + { name: 'styles'}, + { name: 'basicstyles'}, + { name: 'links'}, + { name: 'paragraph', groups: ['list', 'blocks']}, + { name: 'insert'}, + ], + // Remove the redundant buttons from toolbar groups defined above. Format + removeButtons: 'Subscript,Superscript,Anchor,Specialchar,PasteFromWord,Styles,Font,FontSize' + }); + + }; + /** * CreateTextWidget. * @@ -73,17 +111,21 @@ const iTopFormWidgetFactory = new function(){ console.log('CreateSelectAjaxWidget', sId, aOptions); + const aPlugins = {}; + + if(aOptions['max_items'] != '1'){ + aPlugins['remove_button'] = { + title:'Remove this item', + }; + } + new TomSelect(`#${sId}`, { valueField: aOptions['value_field'], labelField: aOptions['label_field'], searchField: aOptions['search_field'], - maxItems: aOptions['maxItems'], + maxItems: aOptions['max_items'], preload: aOptions['preload'], - plugins: { - remove_button:{ - title:'Remove this item', - } - }, + plugins: aPlugins, load: function(query, callback) { let sUrl = aOptions['url']; if(!sUrl.includes('?')){ @@ -101,10 +143,11 @@ const iTopFormWidgetFactory = new function(){ }); }; - return { AutoInstall, CreateTextWidget, + CreateAreaWidget, CreateSelectWidget, } }; + diff --git a/sources/FormSDK/Field/Description/FormFieldTypeEnumeration.php b/sources/FormSDK/Field/Description/FormFieldTypeEnumeration.php index 5f1d4eb6a..c19b87c73 100644 --- a/sources/FormSDK/Field/Description/FormFieldTypeEnumeration.php +++ b/sources/FormSDK/Field/Description/FormFieldTypeEnumeration.php @@ -28,6 +28,7 @@ namespace Combodo\iTop\FormSDK\Field\Description; enum FormFieldTypeEnumeration : string { case TEXT = 'TEXT'; + case AREA = 'AREA'; case DATE = 'DATE'; case SELECT = 'SELECT'; case DB_OBJECT = 'DB_OBJECT'; diff --git a/sources/FormSDK/Helper/FormHelper.php b/sources/FormSDK/Helper/FormHelper.php index 7a6f4f701..08766495d 100644 --- a/sources/FormSDK/Helper/FormHelper.php +++ b/sources/FormSDK/Helper/FormHelper.php @@ -42,6 +42,7 @@ class FormHelper // city - text $oFormFactory->AddTextField('city', [ 'label' => 'Ma ville', + 'help' => 'This is where you live', 'constraints' => new Length(['min' => 3]) ], 'Autun'); @@ -60,6 +61,12 @@ class FormHelper 'required' => false ], new DateTime('1979/06/27')); + // blog - date + $oFormFactory->AddAreaField('blog', [ + 'label' => 'Blog', + 'required' => false + ], 'Your story'); + // language - select with static data $oFormFactory->AddSelectField('language', [ 'label' => 'Ma langue', @@ -70,16 +77,24 @@ class FormHelper $oFormFactory->AddSelectAjaxField('dog', [ 'label' => 'Mon Chien', 'placeholder' => 'Sélectionnez un chien', - 'required' => false + 'required' => false, + ], [ 'url' => 'http://localhost' . $oRouter->generate('formSDK_ajax_select'), 'ajax_query_parameter' => 'query', 'value_field' => 'breed', 'label_field' => 'breed', 'search_field' => 'breed', - 'threshold' => 20 + 'threshold' => 20, + 'max_items' => 1 ]); + // friends - select with OQL + $oFormFactory->AddSelectOqlField('friends', [ + 'label' => 'Ma personne', + 'required' => false + ], 'Person', 'SELECT Person', [], '', 20); + // mode - select with static data $oFormFactory->AddSelectField('mode', [ 'label' => 'Mon mode', @@ -96,12 +111,6 @@ class FormHelper 'multiple' => true ], null); - // friends - select with OQL - $oFormFactory->AddSelectOqlField('friends', [ - 'label' => 'Ma personne', - 'required' => false - ], 'Person', 'SELECT Person', [], '', 20); - return $oFormFactory; } diff --git a/sources/FormSDK/Service/FactoryAdapter/FormFactoryObjectAdapter.php b/sources/FormSDK/Service/FactoryAdapter/FormFactoryObjectAdapter.php index acc1c98d0..780ca70d6 100644 --- a/sources/FormSDK/Service/FactoryAdapter/FormFactoryObjectAdapter.php +++ b/sources/FormSDK/Service/FactoryAdapter/FormFactoryObjectAdapter.php @@ -130,7 +130,8 @@ final class FormFactoryObjectAdapter implements FormFactoryAdapterInterface */ private function GetAttributePath(string $sAttributeCode) : string { - return $this->GetIdentifier() . '-' . $sAttributeCode; + return $this->bGroup ? $sAttributeCode : $this->GetIdentifier() . '-' . $sAttributeCode; +// return $this->GetIdentifier() . '-' . $sAttributeCode; } /** @inheritdoc */ @@ -146,7 +147,15 @@ final class FormFactoryObjectAdapter implements FormFactoryAdapterInterface ExceptionLog::LogException($e); } } - return $aData; + + if($this->bGroup){ + return [ + $this->GetIdentifier() => $aData + ]; + } + else{ + return $aData; + } } /** @inheritdoc */ @@ -156,7 +165,7 @@ final class FormFactoryObjectAdapter implements FormFactoryAdapterInterface foreach ($this->aAttributes as $sKey => $oValue){ try { - $aDescriptions[$sKey] = $this->GetAttributeDescription($sKey); + $aDescriptions[$this->GetIdentifier() .'_' .$sKey] = $this->GetAttributeDescription($sKey); } catch (Exception $e) { ExceptionLog::LogException($e); diff --git a/sources/FormSDK/Service/FormFactory.php b/sources/FormSDK/Service/FormFactory.php index 25c0551d5..658200174 100644 --- a/sources/FormSDK/Service/FormFactory.php +++ b/sources/FormSDK/Service/FormFactory.php @@ -78,9 +78,9 @@ class FormFactory ]; // merge each adapter data... - foreach ($this->GetAllAdapters() as $oPlugin){ - $aResult['descriptions'] = array_merge($aResult['descriptions'], $oPlugin->GetFormDescriptions()); - $aResult['data'] = array_merge($aResult['data'], $oPlugin->GetFormData()); + foreach ($this->GetAllAdapters() as $oAdapter){ + $aResult['descriptions'] = array_merge($aResult['descriptions'], $oAdapter->GetFormDescriptions()); + $aResult['data'] = array_merge($aResult['data'], $oAdapter->GetFormData()); } return $aResult; @@ -172,6 +172,30 @@ class FormFactory return $this; } + /** + * Add area field. + * + * @param string $sKey + * @param array $aOptions + * @param mixed $oData + * + * @return $this + */ + public function AddAreaField(string $sKey, array $aOptions, mixed $oData = null) : FormFactory + { + $aOptions = array_merge([ + 'attr' => [ + 'data-widget' => 'AreaWidget', + 'data-widget-options' => json_encode([]) + ] + ], $aOptions); + + $this->aDescriptions[$sKey] = new FormFieldDescription($sKey, FormFieldTypeEnumeration::AREA, $aOptions); + $this->aData[$sKey] = $oData; + + return $this; + } + /** * Add date field. * @@ -227,7 +251,7 @@ class FormFactory 'value_field' => 'value', 'label_field' => 'label', 'search_field' => 'search', - 'preload' => true, + 'preload' => false, 'threshold' => -1, 'configuration' => 'AJAX' ], $aAjaxOptions); diff --git a/sources/FormSDK/Symfony/SymfonyBridge.php b/sources/FormSDK/Symfony/SymfonyBridge.php index 21839ed13..ffc5831dd 100644 --- a/sources/FormSDK/Symfony/SymfonyBridge.php +++ b/sources/FormSDK/Symfony/SymfonyBridge.php @@ -26,6 +26,7 @@ use LogAPI; use Symfony\Component\Form\Extension\Core\Type\ChoiceType; use Symfony\Component\Form\Extension\Core\Type\DateType; use Symfony\Component\Form\Extension\Core\Type\FormType; +use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormFactoryInterface; use Symfony\Component\Form\FormInterface; @@ -68,6 +69,13 @@ class SymfonyBridge 'options' => $oFormDescription->GetOptions() ]; + case FormFieldTypeEnumeration::AREA: + return [ + 'path' => $oFormDescription->GetPath(), + 'type' => TextareaType::class, + 'options' => $oFormDescription->GetOptions() + ]; + case FormFieldTypeEnumeration::DATE: return [ 'path' => $oFormDescription->GetPath(), @@ -90,7 +98,6 @@ class SymfonyBridge $aItems[] = $aSymfony; } $aOptions['descriptions'] = $aItems; - $aOptions['inherit_data'] = true; return [ 'path' => $oFormDescription->GetPath(), 'type' => FormObjectType::class, diff --git a/templates/base.html.twig b/templates/base.html.twig index 98788c7db..7e9085890 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -25,6 +25,8 @@ {% block body %}{% endblock %} {# lib #} + +