Skip to content

Commit

Permalink
Merge pull request #343 from mikadamczyk/ezp-28831-draft-conflict-win…
Browse files Browse the repository at this point in the history
…dow-after-clicking-edit-button-of-existing-draft-in-Dashboard-and-sub-items-list

EZP-28831: Draft conflict window after clicking edit button of existing draft in Dashboard and Sub-items list
  • Loading branch information
Łukasz Serwatka authored Feb 27, 2018
2 parents 112fbb8 + b7faa4c commit c632f0a
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 16 deletions.
36 changes: 31 additions & 5 deletions src/bundle/Resources/public/js/scripts/admin.location.view.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down
37 changes: 31 additions & 6 deletions src/bundle/Resources/public/js/scripts/button.content.edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/public/scss/_tables.scss
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
}

.ez-dashboard {
.table {
.table:not(.ez-table__draft-conflict) {
margin-bottom: 0;

thead {
Expand Down
1 change: 0 additions & 1 deletion src/bundle/Resources/views/content/locationview.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
{% endif %}
{{ form(form_location_copy, {'action': path('ezplatform.location.copy')}) }}
{{ form(form_location_move, {'action': path('ezplatform.location.move')}) }}
<div class="ez-version-draft-conflict-modal-wrapper"></div>
</div>
</div>
{% endblock %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}

<table class="table {% if is_draft and haveToPaginate %} mb-3 {% endif %}">
<table class="table {% if is_draft and haveToPaginate %} mb-3 {% endif %} {% if is_draft_conflict %} ez-table__draft-conflict {% endif %}">
<thead>
<tr>
{% if form is defined %}
Expand Down
2 changes: 1 addition & 1 deletion src/bundle/Resources/views/layout.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
{% endfor %}
{% endfor %}
</div>

<div class="ez-modal-wrapper"></div>
{% javascripts
'bundles/ezplatformadminuiassets/vendors/react/umd/react.production.min.js'
'bundles/ezplatformadminuiassets/vendors/react-dom/umd/react-dom.production.min.js'
Expand Down

0 comments on commit c632f0a

Please sign in to comment.