Skip to content

Commit

Permalink
TASK: Extract review script from show template
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebobo committed Jun 17, 2024
1 parent b8d4809 commit 8b34b1d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{namespace neos=Neos\Neos\ViewHelpers}
<f:layout name="BackendSubModule" />

<f:section name="subtitle">
</f:section>

<f:section name="content">

<f:if condition="{siteChanges}">
Expand Down Expand Up @@ -95,6 +92,7 @@
</table>
</div>
<f:render section="actions" arguments="{_all}" />
<script src="{f:uri.resource(path: 'Scripts/Review.js')}"></script>
</f:form>

<div class="neos-hide" id="discard">
Expand Down Expand Up @@ -136,62 +134,6 @@
</div>

<f:form action="index" id="postHelper" method="post"></f:form>

<script>
window.addEventListener('DOMContentLoaded', (event) => {
jQuery(function($) {
jQuery('#check-all').change(function() {
var value = false;
if (jQuery(this).is(':checked')) {
value = true;
jQuery('.batch-action').removeClass('neos-hidden').removeClass('neos-discardAllChanges').removeClass('neos-disabled').removeAttr('disabled');
jQuery('.review-button-action').addClass('neos-hidden').addClass('neos-disabled').attr('disabled', 'disabled');
} else {
jQuery('.batch-action').addClass('neos-hidden').addClass('neos-disabled').attr('disabled', 'disabled');
jQuery('.review-button-action').removeClass('neos-hidden').removeClass('neos-disabled').removeAttr('disabled', 'disabled');
}
jQuery('tbody input[type="checkbox"]').prop('checked', value);
});

jQuery('.neos-check-document').change(function() {
var documentIdentifier = jQuery(this).val();
var checked = jQuery(this).prop('checked');
jQuery(this).closest('table').find('tr.neos-change.document-' + documentIdentifier + ' td.check input').prop('checked', checked);
});

jQuery('tbody input[type="checkbox"]').change(function() {
if (jQuery(this).closest('tr').data('ismoved') === true || jQuery(this).closest('tr').data('isnew') === true) {
var currentNodePath = jQuery(this).closest('tr').attr('data-nodepath') + '/';
var checked = jQuery(this).prop('checked');

function nodePathStartsWith(nodePath) {
return function(index, element) {
return nodePath.indexOf(jQuery(element).data('nodepath')) === 0;
}
}
var movedOrNewParentDocuments = jQuery(this).closest('table').find('.neos-document[data-ismoved="true"], .neos-document[data-isnew="true"]').filter(nodePathStartsWith(currentNodePath));
jQuery(movedOrNewParentDocuments).each(function(index, movedParentDocument) {
jQuery('tr[data-nodepath^="' + jQuery(movedParentDocument).data('nodepath') + '"] td.check input').prop('checked', checked);
});
}

if (jQuery('tbody input[type="checkbox"]:checked').length > 0) {
jQuery('.batch-action').removeClass('neos-hidden').removeClass('neos-disabled').removeAttr('disabled');
jQuery('.review-button-action').addClass('neos-hidden').addClass('neos-disabled').attr('disabled', 'disabled');
} else {
jQuery('.batch-action').addClass('neos-hidden').addClass('neos-disabled').attr('disabled', 'disabled');
jQuery('.review-button-action').removeClass('neos-hidden').removeClass('neos-disabled').removeAttr('disabled', 'disabled');
}
});

jQuery('.fold-toggle').click(function() {
jQuery(this).toggleClass('fas fa-chevron-down fas fa-chevron-up');
jQuery('tr.' + jQuery(this).data('toggle')).toggle();
});
});
});
</script>

</f:then>
<f:else>
<legend>{neos:backend.translate(id: 'workspaces.unpublishedChanges', source: 'Main', package: 'Neos.Workspace.Ui', arguments: {0: selectedWorkspaceLabel.value})}</legend>
Expand Down
53 changes: 53 additions & 0 deletions Neos.Workspace.Ui/Resources/Public/Scripts/Review.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
window.addEventListener('DOMContentLoaded', (event) => {
jQuery(function ($) {
jQuery('#check-all').change(function () {
var value = false;
if (jQuery(this).is(':checked')) {
value = true;
jQuery('.batch-action').removeClass('neos-hidden').removeClass('neos-discardAllChanges').removeClass('neos-disabled').removeAttr('disabled');
jQuery('.review-button-action').addClass('neos-hidden').addClass('neos-disabled').attr('disabled', 'disabled');
} else {
jQuery('.batch-action').addClass('neos-hidden').addClass('neos-disabled').attr('disabled', 'disabled');
jQuery('.review-button-action').removeClass('neos-hidden').removeClass('neos-disabled').removeAttr('disabled', 'disabled');
}
jQuery('tbody input[type="checkbox"]').prop('checked', value);
});

jQuery('.neos-check-document').change(function () {
var documentIdentifier = jQuery(this).val();
var checked = jQuery(this).prop('checked');
jQuery(this).closest('table').find('tr.neos-change.document-' + documentIdentifier + ' td.check input').prop('checked', checked);
});

jQuery('tbody input[type="checkbox"]').change(function () {
if (jQuery(this).closest('tr').data('ismoved') === true || jQuery(this).closest('tr').data('isnew') === true) {
var currentNodePath = jQuery(this).closest('tr').attr('data-nodepath') + '/';
var checked = jQuery(this).prop('checked');

function nodePathStartsWith(nodePath) {
return function (index, element) {
return nodePath.indexOf(jQuery(element).data('nodepath')) === 0;
}
}

var movedOrNewParentDocuments = jQuery(this).closest('table').find('.neos-document[data-ismoved="true"], .neos-document[data-isnew="true"]').filter(nodePathStartsWith(currentNodePath));
jQuery(movedOrNewParentDocuments).each(function (index, movedParentDocument) {
jQuery('tr[data-nodepath^="' + jQuery(movedParentDocument).data('nodepath') + '"] td.check input').prop('checked', checked);
});
}

if (jQuery('tbody input[type="checkbox"]:checked').length > 0) {
jQuery('.batch-action').removeClass('neos-hidden').removeClass('neos-disabled').removeAttr('disabled');
jQuery('.review-button-action').addClass('neos-hidden').addClass('neos-disabled').attr('disabled', 'disabled');
} else {
jQuery('.batch-action').addClass('neos-hidden').addClass('neos-disabled').attr('disabled', 'disabled');
jQuery('.review-button-action').removeClass('neos-hidden').removeClass('neos-disabled').removeAttr('disabled', 'disabled');
}
});

jQuery('.fold-toggle').click(function () {
jQuery(this).toggleClass('fas fa-chevron-down fas fa-chevron-up');
jQuery('tr.' + jQuery(this).data('toggle')).toggle();
});
});
});

0 comments on commit 8b34b1d

Please sign in to comment.