Skip to content

Commit

Permalink
IBX-808: As an Editor, I want to be able to reset starting location f…
Browse files Browse the repository at this point in the history
…or ezobjectrelation FieldType (#1880)
  • Loading branch information
Konrad Oboza authored Sep 6, 2021
1 parent 8687bf1 commit 42445c0
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -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);
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@
<target state="new">Select a starting location for browsing for relation</target>
<note>key: field_definition.ezobjectrelation.selection_root_udw_title</note>
</trans-unit>
<trans-unit id="58fa0150fbbe5c094880333e871c71ff7b9ee19b" resname="field_definition.ezobjectrelationlist.selection_root_reset_title">
<source>Reset starting location</source>
<target state="new">Reset starting location</target>
<note>key: field_definition.ezobjectrelationlist.selection_root_reset_title</note>
</trans-unit>
<trans-unit id="1592c36df8d445c3154d1f639027f97a90739856" resname="field_definition.ezobjectrelationlist.selection_root_udw_button">
<source>Select location</source>
<target state="new">Select location</target>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 #}
Expand Down Expand Up @@ -142,6 +142,20 @@
>{{ "field_definition.ezobjectrelation.selection_root_udw_button"
|trans({}, "ezrepoforms_content_type")
|desc("Select item") }}</button>
<button
type="button"
title="{{ "field_definition.ezobjectrelationlist.selection_root_reset_title"
|trans({}, "ezrepoforms_content_type")
|desc('Reset starting location') }}"
class="ez-btn--reset-starting-location btn btn-danger"
data-relation-root-input-selector="#{{ form.selectionRoot.vars.id }}"
data-relation-selected-root-name-selector="#{{ form.selectionRoot.vars.id }}-selected-root-name"
{% if form.selectionRoot.vars.destination_location is null %} disabled {% endif %}
>
<svg class="ez-icon ez-icon--medium ez-icon--light">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash"></use>
</svg>
</button>
</div>
<div id="{{ form.selectionRoot.vars.id }}-selected-root-name">
{% if form.selectionRoot.vars.destination_location is not null %}
Expand Down Expand Up @@ -174,6 +188,20 @@
>{{ "field_definition.ezobjectrelationlist.selection_root_udw_button"
|trans({}, "ezrepoforms_content_type")
|desc("Select location") }}</button>
<button
type="button"
title="{{ "field_definition.ezobjectrelationlist.selection_root_reset_title"
|trans({}, "ezrepoforms_content_type")
|desc('Reset starting location') }}"
class="ez-btn--reset-starting-location btn btn-danger"
data-relation-root-input-selector="#{{ form.selectionDefaultLocation.vars.id }}"
data-relation-selected-root-name-selector="#{{ form.selectionDefaultLocation.vars.id }}-selected-root-name"
{% if form.selectionDefaultLocation.vars.destination_location is null %} disabled {% endif %}
>
<svg class="ez-icon ez-icon--medium ez-icon--light">
<use xlink:href="{{ asset('bundles/ezplatformadminui/img/ez-icons.svg') }}#trash"></use>
</svg>
</button>
</div>
<div id="{{ form.selectionDefaultLocation.vars.id }}-selected-root-name">
{% if form.selectionDefaultLocation.vars.destination_location is not null %}
Expand Down

0 comments on commit 42445c0

Please # to comment.