diff --git a/js/forms/custom-elements/choices.js b/js/forms/custom-elements/choices.js index 6d75769ff..fb70acd48 100644 --- a/js/forms/custom-elements/choices.js +++ b/js/forms/custom-elements/choices.js @@ -14,6 +14,7 @@ class ChoicesElement extends HTMLSelectElement { plugins: this.plugins, wrapperClass: 'ts-wrapper ibo-input-wrapper ibo-input-select-wrapper--with-buttons ibo-input-select-autocomplete-wrapper', controlClass: 'ts-control ibo-input ibo-input-select ibo-input-select-autocomplete', + dropdownParent: 'body', render: { dropdown: function (data, escape) { return `
`; diff --git a/js/forms/custom-elements/collection_entry.js b/js/forms/custom-elements/collection_entry.js index 9e841ef50..b4e9fd130 100644 --- a/js/forms/custom-elements/collection_entry.js +++ b/js/forms/custom-elements/collection_entry.js @@ -41,19 +41,22 @@ class CollectionEntryElement extends HTMLElement { */ updateButtonStates() { - if(this.previousElementSibling === null) { - this.#eBtnMoveUp.setAttribute('disabled', 'disabled'); - } - else{ - this.#eBtnMoveUp.removeAttribute('disabled'); + if (this.dataset.allowOrdering) { + + if (this.previousElementSibling === null) { + this.#eBtnMoveUp.setAttribute('disabled', 'disabled'); + } else { + this.#eBtnMoveUp.removeAttribute('disabled'); + } + + if (this.nextElementSibling === null) { + this.#eBtnMoveDown.setAttribute('disabled', 'disabled'); + } else { + this.#eBtnMoveDown.removeAttribute('disabled'); + } + } - if(this.nextElementSibling === null) { - this.#eBtnMoveDown.setAttribute('disabled', 'disabled'); - } - else{ - this.#eBtnMoveDown.removeAttribute('disabled'); - } } /** diff --git a/js/forms/custom-elements/turbo_stream_event.js b/js/forms/custom-elements/turbo_stream_event.js new file mode 100644 index 000000000..dbef05fe3 --- /dev/null +++ b/js/forms/custom-elements/turbo_stream_event.js @@ -0,0 +1,25 @@ +class TurboStreamEvent extends HTMLElement { + + // register the custom element + static { + customElements.define('turbo-stream-event', TurboStreamEvent); + } + + constructor() { + super(); + + this.style.display = 'none'; + + const event = new CustomEvent("itop:TurboStreamEvent", { + detail: { + id: this.getAttribute('id'), + block_class: this.dataset.formBlockClass, + view_data: this.dataset.viewData, + valid: this.dataset.valid, + }, + }); + + document.dispatchEvent(event); + } + +} diff --git a/js/forms/forms.js b/js/forms/forms.js index 61fd8ec31..20700c7fc 100644 --- a/js/forms/forms.js +++ b/js/forms/forms.js @@ -25,4 +25,3 @@ function isCheckbox (element) { return element instanceof HTMLInputElement && element.getAttribute('type') === 'checkbox' } - diff --git a/sources/Application/TwigBase/Controller/Controller.php b/sources/Application/TwigBase/Controller/Controller.php index 8e9949cef..1870ed34d 100644 --- a/sources/Application/TwigBase/Controller/Controller.php +++ b/sources/Application/TwigBase/Controller/Controller.php @@ -1120,6 +1120,7 @@ abstract class Controller extends AbstractController } else { + // Display turbo response $this->DisplayTurboAjaxPage(['current_form' => $oForm->createView()]); } diff --git a/sources/Application/WebPage/iTopWebPage.php b/sources/Application/WebPage/iTopWebPage.php index cfe549a51..a79bf6c61 100644 --- a/sources/Application/WebPage/iTopWebPage.php +++ b/sources/Application/WebPage/iTopWebPage.php @@ -186,6 +186,7 @@ class iTopWebPage extends NiceWebPage implements iTabbedPage $this->LinkScriptFromAppRoot('js/forms/custom-elements/oql.js'); $this->LinkScriptFromAppRoot('js/forms/custom-elements/collection.js'); $this->LinkScriptFromAppRoot('js/forms/custom-elements/collection_entry.js'); + $this->LinkScriptFromAppRoot('js/forms/custom-elements/turbo_stream_event.js'); // Used by inline image, CKEditor and other places $this->LinkScriptFromAppRoot('node_modules/magnific-popup/dist/jquery.magnific-popup.min.js'); diff --git a/sources/Forms/Block/AbstractFormBlock.php b/sources/Forms/Block/AbstractFormBlock.php index bf94472c9..c69ed537e 100644 --- a/sources/Forms/Block/AbstractFormBlock.php +++ b/sources/Forms/Block/AbstractFormBlock.php @@ -108,6 +108,7 @@ abstract class AbstractFormBlock implements IFormBlock protected function RegisterOptions(OptionsRegister $oOptionsRegister): void { $oOptionsRegister->SetOption('form_block', $this); + $oOptionsRegister->SetOption('form_block_class', get_class($this)); } /** diff --git a/sources/Forms/Block/DataModel/Dashlet/ClassAttributeGroupByFormBlock.php b/sources/Forms/Block/DataModel/Dashlet/ClassAttributeGroupByFormBlock.php index a397b4d3b..07915cf80 100644 --- a/sources/Forms/Block/DataModel/Dashlet/ClassAttributeGroupByFormBlock.php +++ b/sources/Forms/Block/DataModel/Dashlet/ClassAttributeGroupByFormBlock.php @@ -45,8 +45,8 @@ class ClassAttributeGroupByFormBlock extends AttributeChoiceFormBlock $sExtKeyAttCode = $oModelReflection->GetAttributeProperty($sTargetClass, $sExtFieldAttCode, 'extkey_attcode'); $sTargetAttCode = $oModelReflection->GetAttributeProperty($sTargetClass, $sExtFieldAttCode, 'target_attcode'); $sTargetClass = $oModelReflection->GetAttributeProperty($sTargetClass, $sExtKeyAttCode, 'targetclass'); - $aTargetAttCodes = AttributeChoiceFormBlock::ListAttributeCodesByCategory($sTargetClass, 'group_by'); - $sAttType = $aTargetAttCodes[$sTargetAttCode]; + // $aTargetAttCodes = AttributeChoiceFormBlock::ListAttributeCodesByCategory($sTargetClass, 'group_by'); + $sAttType = $sTargetAttCode; $sExtFieldAttCode = $sTargetAttCode; } diff --git a/sources/Forms/FormBuilder/FormTypeExtension.php b/sources/Forms/FormBuilder/FormTypeExtension.php index 2b204876a..a3cb3829a 100644 --- a/sources/Forms/FormBuilder/FormTypeExtension.php +++ b/sources/Forms/FormBuilder/FormTypeExtension.php @@ -36,6 +36,7 @@ class FormTypeExtension extends AbstractTypeExtension { $resolver->setDefined([ 'form_block', + 'form_block_class', 'builder_listener', 'prevent_form_build', ]); @@ -55,6 +56,7 @@ class FormTypeExtension extends AbstractTypeExtension { if (array_key_exists('form_block', $options)) { $view->vars['form_block'] = $options['form_block']; + $view->vars['form_block_class'] = $options['form_block_class']; $oFormBlock = $options['form_block']; $view->vars['trigger_form_submit_on_modify'] = $oFormBlock->ImpactDependentsBlocks(); diff --git a/templates/application/forms/turbo-ajax-update.html.twig b/templates/application/forms/turbo-ajax-update.html.twig index 3ecdf9115..caf1cf0cb 100644 --- a/templates/application/forms/turbo-ajax-update.html.twig +++ b/templates/application/forms/turbo-ajax-update.html.twig @@ -16,5 +16,6 @@ {% if current_form %} {% UITurboStream Replace { sTarget: current_form.vars.id} %} {{ form_widget(current_form) }} +