diff --git a/src/bundle/Resources/public/js/scripts/admin.contenttype.relation.default.location.js b/src/bundle/Resources/public/js/scripts/admin.contenttype.relation.default.location.js index b638034e59..0eec550c3d 100644 --- a/src/bundle/Resources/public/js/scripts/admin.contenttype.relation.default.location.js +++ b/src/bundle/Resources/public/js/scripts/admin.contenttype.relation.default.location.js @@ -1,5 +1,7 @@ (function (global, doc, React, ReactDOM) { - const btns = doc.querySelectorAll('.btn--udw-relation-default-location'); + const SELECTOR_RESET_STARTING_LOCATION_BTN = '.ez-btn--reset-starting-location'; + const resetStartingLocationBtns = doc.querySelectorAll(SELECTOR_RESET_STARTING_LOCATION_BTN); + const udwBtns = doc.querySelectorAll('.btn--udw-relation-default-location'); const udwContainer = doc.getElementById('react-udw'); const token = doc.querySelector('meta[name="CSRF-Token"]').content; const siteaccess = doc.querySelector('meta[name="SiteAccess"]').content; @@ -12,6 +14,11 @@ const objectRelationListSettingsWrapper = btn.closest('.ezobjectrelationlist-settings'); const objectRelationSettingsWrapper = btn.closest('.ezobjectrelation-settings'); + toggleResetStartingLocationBtn( + btn.parentNode.querySelector(SELECTOR_RESET_STARTING_LOCATION_BTN), + true + ); + if (objectRelationListSettingsWrapper) { objectRelationListSettingsWrapper.querySelector(btn.dataset.relationRootInputSelector).value = locationId; objectRelationListSettingsWrapper.querySelector(btn.dataset.relationSelectedRootNameSelector).innerHTML = locationName; @@ -35,6 +42,23 @@ restInfo: { token, siteaccess } }, config)), udwContainer); }; + const toggleResetStartingLocationBtn = (button, isEnabled) => { + if (isEnabled) { + button.removeAttribute('disabled'); + } else { + button.setAttribute('disabled', true); + } + }; + const resetStartingLocation = (event) => { + const button = event.currentTarget; + const { relationRootInputSelector, relationSelectedRootNameSelector } = button.dataset; + + doc.querySelector(relationRootInputSelector).value = ''; + doc.querySelector(relationSelectedRootNameSelector).innerHTML = ''; + + toggleResetStartingLocationBtn(button, false); + }; - btns.forEach(btn => btn.addEventListener('click', openUDW, false)); + udwBtns.forEach(btn => btn.addEventListener('click', openUDW, false)); + resetStartingLocationBtns.forEach(btn => btn.addEventListener('click', resetStartingLocation, false)); })(window, window.document, window.React, window.ReactDOM); diff --git a/src/bundle/Resources/translations/ezrepoforms_content_type.en.xliff b/src/bundle/Resources/translations/ezrepoforms_content_type.en.xliff index 3a7c662950..fa46dad98f 100644 --- a/src/bundle/Resources/translations/ezrepoforms_content_type.en.xliff +++ b/src/bundle/Resources/translations/ezrepoforms_content_type.en.xliff @@ -16,6 +16,11 @@ Select a starting location for browsing for relation key: field_definition.ezobjectrelation.selection_root_udw_title + + Reset starting location + Reset starting location + key: field_definition.ezobjectrelationlist.selection_root_reset_title + Select location Select location diff --git a/src/bundle/Resources/views/admin/content_type/field_types.html.twig b/src/bundle/Resources/views/admin/content_type/field_types.html.twig index 45d5280ab6..60648df5d9 100644 --- a/src/bundle/Resources/views/admin/content_type/field_types.html.twig +++ b/src/bundle/Resources/views/admin/content_type/field_types.html.twig @@ -4,7 +4,7 @@ # - \EzSystems\RepositoryForms\Data\FieldDefinitionData data Data object for current fieldDefinition. # - \Symfony\Component\Form\FormView form Field definition form. # - string languageCode - #} +#} {# @var data \EzSystems\RepositoryForms\Data\FieldDefinitionData #} {# @var form \Symfony\Component\Form\FormView #} @@ -142,6 +142,20 @@ >{{ "field_definition.ezobjectrelation.selection_root_udw_button" |trans({}, "ezrepoforms_content_type") |desc("Select item") }} +
{% if form.selectionRoot.vars.destination_location is not null %} @@ -174,6 +188,20 @@ >{{ "field_definition.ezobjectrelationlist.selection_root_udw_button" |trans({}, "ezrepoforms_content_type") |desc("Select location") }} +
{% if form.selectionDefaultLocation.vars.destination_location is not null %}