diff --git a/src/bundle/Resources/public/js/scripts/admin.location.view.js b/src/bundle/Resources/public/js/scripts/admin.location.view.js index 61cc8cd074..231281087a 100644 --- a/src/bundle/Resources/public/js/scripts/admin.location.view.js +++ b/src/bundle/Resources/public/js/scripts/admin.location.view.js @@ -19,12 +19,38 @@ }, }; const handleEditItem = (content) => { - doc.querySelector('#form_subitems_content_edit_content_info').value = content._id; - doc.querySelector('#form_subitems_content_edit_version_info_content_info').value = content._id; - doc.querySelector('#form_subitems_content_edit_version_info_version_no').value = content.CurrentVersion.Version.VersionInfo.versionNo; - doc.querySelector(`#form_subitems_content_edit_language_${content.mainLanguageCode}`).checked = true; + const contentId = content._id; + const checkVersionDraftLink = window.Routing.generate('ezplatform.version_draft.has_no_conflict', { contentId }); + const submitVersionEditForm = () => { + doc.querySelector('#form_subitems_content_edit_content_info').value = contentId; + doc.querySelector('#form_subitems_content_edit_version_info_content_info').value = contentId; + doc.querySelector('#form_subitems_content_edit_version_info_version_no').value = content.CurrentVersion.Version.VersionInfo.versionNo; + doc.querySelector(`#form_subitems_content_edit_language_${content.mainLanguageCode}`).checked = true; + doc.querySelector('#form_subitems_content_edit_create').click(); + }; + const addDraft = () => { + submitVersionEditForm(); + $('#version-draft-conflict-modal').modal('hide'); + }; + const showModal = (modalHtml) => { + const wrapper = doc.querySelector('.ez-modal-wrapper'); - doc.querySelector('#form_subitems_content_edit_create').click(); + wrapper.innerHTML = modalHtml; + wrapper.querySelector('.ez-btn--add-draft').addEventListener('click', addDraft, false); + [...wrapper.querySelectorAll('.ez-btn--prevented')].forEach(btn => btn.addEventListener('click', event => event.preventDefault(), false)); + $('#version-draft-conflict-modal').modal('show'); + }; + fetch(checkVersionDraftLink, { + credentials: 'same-origin' + }).then(function (response) { + // Status 409 means that a draft conflict has occurred and the modal must be displayed. + // Otherwise we can go to Content Item edit page. + if (response.status === 409) { + response.text().then(showModal); + } else if (response.status === 200) { + submitVersionEditForm(); + } + }); }; const generateLink = (locationId) => window.Routing.generate('_ezpublishLocation', { locationId }); diff --git a/src/bundle/Resources/public/js/scripts/button.content.edit.js b/src/bundle/Resources/public/js/scripts/button.content.edit.js index 2592719698..d111d816ba 100644 --- a/src/bundle/Resources/public/js/scripts/button.content.edit.js +++ b/src/bundle/Resources/public/js/scripts/button.content.edit.js @@ -10,15 +10,40 @@ const versionInfoContentInfoInput = versionEditForm.querySelector('input[name="' + versionEditFormName+ '[version_info][content_info]"]'); const versionInfoVersionNoInput = versionEditForm.querySelector('input[name="' + versionEditFormName + '[version_info][version_no]"]'); const languageInput = versionEditForm.querySelector('#'+ versionEditFormName +'_language_' + languageCode); + const checkVersionDraftLink = global.Routing.generate('ezplatform.version_draft.has_no_conflict', { contentId }); + const submitVersionEditForm = () => { + contentInfoInput.value = contentId; + versionInfoContentInfoInput.value = contentId; + versionInfoVersionNoInput.value = versionNo; + languageInput.setAttribute('checked', true); + versionEditForm.submit(); + }; + const addDraft = () => { + submitVersionEditForm(); + $('#version-draft-conflict-modal').modal('hide'); + }; + const showModal = (modalHtml) => { + const wrapper = doc.querySelector('.ez-modal-wrapper'); - event.preventDefault(); + wrapper.innerHTML = modalHtml; + wrapper.querySelector('.ez-btn--add-draft').addEventListener('click', addDraft, false); + [...wrapper.querySelectorAll('.ez-btn--prevented')].forEach(btn => btn.addEventListener('click', event => event.preventDefault(), false)); + $('#version-draft-conflict-modal').modal('show'); + }; - contentInfoInput.value = contentId; - versionInfoContentInfoInput.value = contentId; - versionInfoVersionNoInput.value = versionNo; - languageInput.setAttribute('checked', true); + event.preventDefault(); - versionEditForm.submit(); + fetch(checkVersionDraftLink, { + credentials: 'same-origin' + }).then(function (response) { + // Status 409 means that a draft conflict has occurred and the modal must be displayed. + // Otherwise we can go to Content Item edit page. + if (response.status === 409) { + response.text().then(showModal); + } else if (response.status === 200) { + submitVersionEditForm(); + } + }); }; [...doc.querySelectorAll('.ez-btn--content-edit')].forEach(button => button.addEventListener('click', editVersion, false)); diff --git a/src/bundle/Resources/public/js/scripts/sidebar/btn/location.edit.js b/src/bundle/Resources/public/js/scripts/sidebar/btn/location.edit.js index 2521e94e3b..4d0c4c447a 100644 --- a/src/bundle/Resources/public/js/scripts/sidebar/btn/location.edit.js +++ b/src/bundle/Resources/public/js/scripts/sidebar/btn/location.edit.js @@ -12,7 +12,7 @@ const changeHandler = () => { const showModal = (modalHtml) => { - const wrapper = doc.querySelector('.ez-version-draft-conflict-modal-wrapper'); + const wrapper = doc.querySelector('.ez-modal-wrapper'); wrapper.innerHTML = modalHtml; wrapper.querySelector('.ez-btn--add-draft').addEventListener('click', addDraft, false); [...wrapper.querySelectorAll('.ez-btn--prevented')].forEach(btn => btn.addEventListener('click', event => event.preventDefault(), false)); diff --git a/src/bundle/Resources/public/scss/_tables.scss b/src/bundle/Resources/public/scss/_tables.scss index 4bb298bbd0..3d72351381 100644 --- a/src/bundle/Resources/public/scss/_tables.scss +++ b/src/bundle/Resources/public/scss/_tables.scss @@ -45,7 +45,7 @@ } .ez-dashboard { - .table { + .table:not(.ez-table__draft-conflict) { margin-bottom: 0; thead { diff --git a/src/bundle/Resources/views/content/locationview.html.twig b/src/bundle/Resources/views/content/locationview.html.twig index 20a2c8d472..df057a2cd2 100644 --- a/src/bundle/Resources/views/content/locationview.html.twig +++ b/src/bundle/Resources/views/content/locationview.html.twig @@ -82,7 +82,6 @@ {% endif %} {{ form(form_location_copy, {'action': path('ezplatform.location.copy')}) }} {{ form(form_location_move, {'action': path('ezplatform.location.move')}) }} -
{% endblock %} diff --git a/src/bundle/Resources/views/content/tab/versions/table.html.twig b/src/bundle/Resources/views/content/tab/versions/table.html.twig index 0553e68c47..8443f3a4dd 100644 --- a/src/bundle/Resources/views/content/tab/versions/table.html.twig +++ b/src/bundle/Resources/views/content/tab/versions/table.html.twig @@ -4,7 +4,7 @@ {% set is_archived = is_archived is defined and is_archived %} {% set is_draft_conflict = is_draft_conflict is defined and is_draft_conflict %} - +
{% if form is defined %} diff --git a/src/bundle/Resources/views/layout.html.twig b/src/bundle/Resources/views/layout.html.twig index 667b124cfd..80048079c8 100644 --- a/src/bundle/Resources/views/layout.html.twig +++ b/src/bundle/Resources/views/layout.html.twig @@ -83,7 +83,7 @@ {% endfor %} {% endfor %} - +
{% javascripts 'bundles/ezplatformadminuiassets/vendors/react/umd/react.production.min.js' 'bundles/ezplatformadminuiassets/vendors/react-dom/umd/react-dom.production.min.js'