kopia lustrzana https://github.com/wagtail/wagtail
Bulk actions - appropriate string for listing (#7428)
* [feat] Add separate strings for different listings * [refactor] Change string in users listing * [refactor] Change keys to uppercase for consistencypull/7618/head
rodzic
e1bf910449
commit
95d5097615
|
@ -15,6 +15,17 @@ const checkedState = {
|
|||
shouldShowAllInListingText: true
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Utility function to get the appropriate string for display in action bar
|
||||
*/
|
||||
function getAppropriateStringForListing(key) {
|
||||
if (wagtailConfig.BULK_ACTION_ITEM_TYPE in wagtailConfig.STRINGS.BULK_ACTIONS) {
|
||||
return wagtailConfig.STRINGS.BULK_ACTIONS[wagtailConfig.BULK_ACTION_ITEM_TYPE][key];
|
||||
}
|
||||
return wagtailConfig.STRINGS.BULK_ACTIONS.item[key];
|
||||
}
|
||||
|
||||
/**
|
||||
* Event listener for the `Select All` checkbox
|
||||
*/
|
||||
|
@ -84,12 +95,12 @@ function onSelectIndividualCheckbox(e) {
|
|||
/* Update text on number of pages */
|
||||
let numObjectsSelected = '';
|
||||
if (numCheckedObjects === 1) {
|
||||
numObjectsSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_SINGULAR;
|
||||
numObjectsSelected = getAppropriateStringForListing('SINGULAR');
|
||||
} else {
|
||||
if (numCheckedObjects === checkedState.numObjects) {
|
||||
numObjectsSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_ALL.replace('{0}', numCheckedObjects);
|
||||
numObjectsSelected = getAppropriateStringForListing('ALL').replace('{0}', numCheckedObjects);
|
||||
} else {
|
||||
numObjectsSelected = wagtailConfig.STRINGS.NUM_PAGES_SELECTED_PLURAL.replace('{0}', numCheckedObjects);
|
||||
numObjectsSelected = getAppropriateStringForListing('PLURAL').replace('{0}', numCheckedObjects);
|
||||
}
|
||||
}
|
||||
document.querySelector(`${BULK_ACTION_NUM_OBJECTS_SPAN}`).textContent = numObjectsSelected;
|
||||
|
@ -103,7 +114,7 @@ function onClickSelectAllInListing(e) {
|
|||
e.preventDefault();
|
||||
checkedState.selectAllInListing = true;
|
||||
document.querySelector(`${BULK_ACTION_NUM_OBJECTS_SPAN}`).
|
||||
textContent = `${wagtailConfig.STRINGS.NUM_PAGES_SELECTED_ALL_IN_LISTING}.`;
|
||||
textContent = `${getAppropriateStringForListing('ALL_IN_LISTING')}.`;
|
||||
document.querySelector(`${BULK_ACTION_NUM_OBJECTS_IN_LISTING}`).classList.add('u-hidden');
|
||||
}
|
||||
|
||||
|
|
|
@ -109,10 +109,38 @@ def get_js_translation_strings():
|
|||
'WEEKDAYS_SHORT': [str(WEEKDAYS_ABBR[d % 7]) for d in range(-1, 6)],
|
||||
|
||||
# used by bulk actions
|
||||
'NUM_PAGES_SELECTED_SINGULAR': _('1 page selected'),
|
||||
'NUM_PAGES_SELECTED_PLURAL': _("{0} pages selected"),
|
||||
'NUM_PAGES_SELECTED_ALL': _("All {0} pages on this screen selected"),
|
||||
'NUM_PAGES_SELECTED_ALL_IN_LISTING': _("All pages in listing selected"),
|
||||
'BULK_ACTIONS': {
|
||||
'PAGE': {
|
||||
'SINGULAR': _('1 page selected'),
|
||||
'PLURAL': _("{0} pages selected"),
|
||||
'ALL': _("All {0} pages on this screen selected"),
|
||||
'ALL_IN_LISTING': _("All pages in listing selected"),
|
||||
},
|
||||
'DOCUMENT': {
|
||||
'SINGULAR': _('1 document selected'),
|
||||
'PLURAL': _("{0} documents selected"),
|
||||
'ALL': _("All {0} documents on this screen selected"),
|
||||
'ALL_IN_LISTING': _("All documents in listing selected"),
|
||||
},
|
||||
'IMAGE': {
|
||||
'SINGULAR': _('1 image selected'),
|
||||
'PLURAL': _("{0} images selected"),
|
||||
'ALL': _("All {0} images on this screen selected"),
|
||||
'ALL_IN_LISTING': _("All images in listing selected"),
|
||||
},
|
||||
'USER': {
|
||||
'SINGULAR': _('1 user selected'),
|
||||
'PLURAL': _("{0} users selected"),
|
||||
'ALL': _("All {0} users on this screen selected"),
|
||||
'ALL_IN_LISTING': _("All users in listing selected"),
|
||||
},
|
||||
'ITEM': {
|
||||
'SINGULAR': _('1 item selected'),
|
||||
'PLURAL': _("{0} items selected"),
|
||||
'ALL': _("All {0} items on this screen selected"),
|
||||
'ALL_IN_LISTING': _("All items in listing selected"),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,6 +37,9 @@
|
|||
that column will have the drag and drop buttons to enable ordering
|
||||
{% endcomment %}
|
||||
{% if not show_ordering_column %}
|
||||
<script>
|
||||
window.wagtailConfig.BULK_ACTION_ITEM_TYPE = 'PAGE';
|
||||
</script>
|
||||
<script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
|
||||
{% endif %}
|
||||
<script type="text/javascript">
|
||||
|
|
|
@ -11,6 +11,9 @@
|
|||
targetOutput: "#page-results"
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
window.wagtailConfig.BULK_ACTION_ITEM_TYPE = 'PAGE';
|
||||
</script>
|
||||
<script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -16,6 +16,9 @@
|
|||
})
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
window.wagtailConfig.BULK_ACTION_ITEM_TYPE = 'DOCUMENT';
|
||||
</script>
|
||||
<script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -19,6 +19,9 @@
|
|||
})
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
window.wagtailConfig.BULK_ACTION_ITEM_TYPE = 'IMAGE';
|
||||
</script>
|
||||
<script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
|
|
@ -14,6 +14,9 @@
|
|||
targetOutput: "#user-results"
|
||||
}
|
||||
</script>
|
||||
<script>
|
||||
window.wagtailConfig.BULK_ACTION_ITEM_TYPE = 'USER';
|
||||
</script>
|
||||
<script defer src="{% versioned_static 'wagtailadmin/js/bulk-actions.js' %}"></script>
|
||||
{% endblock %}
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue