mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
Add partial turbo event
This commit is contained in:
@@ -10,7 +10,7 @@ class TurboStreamEvent extends HTMLElement {
|
||||
|
||||
this.style.display = 'none';
|
||||
|
||||
const event = new CustomEvent("itop:TurboStreamEvent", {
|
||||
const event = new CustomEvent(`itop:TurboStreamEvent:${this.dataset.type}`, {
|
||||
detail: {
|
||||
id: this.getAttribute('id'),
|
||||
form_id: this.dataset.formId,
|
||||
|
||||
@@ -194,7 +194,7 @@ class IboDashboard extends HTMLElement {
|
||||
this.SetDashletForm(sFormData);
|
||||
|
||||
// Listen to form submission event and cancellation
|
||||
document.addEventListener('itop:TurboStreamEvent', me._ListenToDashletFormSubmission);
|
||||
document.addEventListener('itop:TurboStreamEvent:Complete', me._ListenToDashletFormSubmission);
|
||||
document.querySelector('.ibo-dashlet-panel--form-container button[name="dashboard_cancel"]').addEventListener('click', me._ListenToDashletFormCancellation);
|
||||
});
|
||||
}
|
||||
@@ -205,7 +205,7 @@ class IboDashboard extends HTMLElement {
|
||||
|
||||
if(event.detail.id === oDashlet.sType + '-turbo-stream-event' && event.detail.valid === "1") {
|
||||
// Remove events
|
||||
document.addEventListener('itop:TurboStreamEvent', this._ListenToDashletFormSubmission);
|
||||
document.addEventListener('itop:TurboStreamEvent:Complete', this._ListenToDashletFormSubmission);
|
||||
document.querySelector('.ibo-dashlet-panel--form-container button[name="dashboard_cancel"]').removeEventListener('click', this._ListenToDashletFormCancellation);
|
||||
|
||||
// Notify it all went well
|
||||
@@ -229,7 +229,7 @@ class IboDashboard extends HTMLElement {
|
||||
const oDashlet = this.querySelector('ibo-dashlet[data-edit-mode="edit"]');
|
||||
const sDashletId = oDashlet.GetDashletId();
|
||||
// Remove events
|
||||
document.addEventListener('itop:TurboStreamEvent', this._ListenToDashletFormSubmission);
|
||||
document.addEventListener('itop:TurboStreamEvent:Complete', this._ListenToDashletFormSubmission);
|
||||
document.querySelector('.ibo-dashlet-panel--form-container button[name="dashboard_cancel"]').removeEventListener('click', this._ListenToDashletFormCancellation);
|
||||
|
||||
// Clean edit mode
|
||||
|
||||
@@ -88,6 +88,21 @@ abstract class AbstractFormBlock implements IFormBlock
|
||||
return $this->oParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the root form.
|
||||
*
|
||||
* @return FormBlock|CollectionBlock|null
|
||||
*/
|
||||
public function GetRoot(): FormBlock|CollectionBlock|null
|
||||
{
|
||||
$oBlock = $this;
|
||||
while (!$oBlock->IsRootBlock()) {
|
||||
$oBlock = $oBlock->GetParent();
|
||||
}
|
||||
|
||||
return $oBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this block is root.
|
||||
*
|
||||
|
||||
@@ -30,6 +30,7 @@ class FormTypeHelper
|
||||
if (is_null($oForm->getParent())) {
|
||||
return $oForm->getName();
|
||||
}
|
||||
|
||||
return self::GetFormId($oForm->getParent()).'_'.$oForm->getName();
|
||||
}
|
||||
|
||||
@@ -52,7 +53,7 @@ class FormTypeHelper
|
||||
|
||||
// Get the parent form
|
||||
$oParent = $oFormTurboTrigger->getParent();
|
||||
$sParentName = self::GetFormId($oParent);
|
||||
$sParentName = self::GetFormId($oParent);
|
||||
|
||||
// Get the block corresponding to the turbo trigger form
|
||||
$oBlockTurboTrigger = $oFormTurboTrigger->getConfig()->getOption('form_block');
|
||||
@@ -72,7 +73,8 @@ class FormTypeHelper
|
||||
|
||||
return [
|
||||
'blocks_to_redraw' => $aBlocksToRedraw,
|
||||
'current_block' => $oFormTurboTrigger->createView(),
|
||||
'current_block' => $oFormTurboTrigger->createView(),
|
||||
'root_form' => $oFormTurboTrigger->GetRoot()->createView(),
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,12 @@
|
||||
{% if current_block %}
|
||||
{% UITurboStream Replace { sTarget: "turbo_error_" ~ current_block.vars.id} %}
|
||||
{{ form_errors(current_block) }}
|
||||
<turbo-stream-event id="{{ root_form.vars.id }}-turbo-stream-event" data-type="Partial" data-form-id="{{ root_form.vars.id }}" data-form-block-class="{{ root_form.vars.form_block_class }}" data-view-data="{{ root_form.vars.value|json_encode }}" data-valid="{{ root_form.vars.valid }}"></turbo-stream-event>
|
||||
{% EndUITurboStream %}
|
||||
{% endif %}
|
||||
{% if current_form %}
|
||||
{% UITurboStream Replace { sTarget: current_form.vars.id} %}
|
||||
{{ form_widget(current_form) }}
|
||||
<turbo-stream-event id="{{ current_form.vars.id }}-turbo-stream-event" data-form-id="{{ current_form.vars.id }}" data-form-block-class="{{ current_form.vars.form_block_class }}" data-view-data="{{ current_form.vars.value|json_encode }}" data-valid="{{ current_form.vars.valid }}"/>
|
||||
<turbo-stream-event id="{{ current_form.vars.id }}-turbo-stream-event" data-type="Complete" data-form-id="{{ current_form.vars.id }}" data-form-block-class="{{ current_form.vars.form_block_class }}" data-view-data="{{ current_form.vars.value|json_encode }}" data-valid="{{ current_form.vars.valid }}"/>
|
||||
{% EndUITurboStream %}
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user