mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-17 06:18:44 +02:00
N°7063 - Forms SDK - Add Symfony forms component
error forms issue
This commit is contained in:
@@ -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,
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
{% block body %}{% endblock %}
|
||||
</body>
|
||||
{# lib #}
|
||||
<script type="text/javascript" src="{{ asset_js('ckeditor/ckeditor.js') }}"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-C6RzsynM9kWDrMNeT87bh95OGNyZPhcTNXj1NW7RuBCsyN/o0jlpcV8Qyq46cDfL" crossorigin="anonymous"></script>
|
||||
<script src="https://kit.fontawesome.com/f2d58012d0.js" crossorigin="anonymous"></script>
|
||||
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user