diff --git a/packages/craftcms-asset-bundles/bundles/cp/src/js/CategoryIndex.js b/packages/craftcms-asset-bundles/bundles/cp/src/js/CategoryIndex.js deleted file mode 100644 index d07f18c6c74..00000000000 --- a/packages/craftcms-asset-bundles/bundles/cp/src/js/CategoryIndex.js +++ /dev/null @@ -1,267 +0,0 @@ -/** global: Craft */ -/** global: Garnish */ -/** - * Category index class - */ -Craft.CategoryIndex = Craft.BaseElementIndex.extend({ - editableGroups: null, - $newCategoryBtnGroup: null, - $newCategoryBtn: null, - - init: function (elementType, $container, settings) { - this.editableGroups = []; - this.on('selectSource', this.updateButton.bind(this)); - this.on('selectSite', this.updateButton.bind(this)); - this.base(elementType, $container, settings); - }, - - afterInit: function () { - // Find which of the visible groups the user has permission to create new categories in - this.editableGroups = Craft.editableCategoryGroups.filter( - (g) => !!this.getSourceByKey(`group:${g.uid}`) - ); - - this.base(); - }, - - getDefaultSourceKey: function () { - // Did they request a specific category group in the URL? - if ( - this.settings.context === 'index' && - typeof defaultGroupHandle !== 'undefined' - ) { - for (let i = 0; i < this.$sources.length; i++) { - const $source = $(this.$sources[i]); - if ($source.data('handle') === defaultGroupHandle) { - return $source.data('key'); - } - } - } - - return this.base(); - }, - - updateButton: function () { - if (!this.$source) { - return; - } - - // Get the handle of the selected source - const selectedSourceHandle = this.$source.data('handle'); - - // Update the New Category button - // --------------------------------------------------------------------- - - if (this.editableGroups.length) { - // Remove the old button, if there is one - if (this.$newCategoryBtnGroup) { - this.$newCategoryBtnGroup.remove(); - } - - // Determine if they are viewing a group that they have permission to create categories in - const selectedGroup = this.editableGroups.find( - (g) => g.handle === selectedSourceHandle - ); - - this.$newCategoryBtnGroup = $( - '
' - ); - let $menuBtn; - const menuId = 'new-category-menu-' + Craft.randomString(10); - - // If they are, show a primary "New category" button, and a dropdown of the other groups (if any). - // Otherwise only show a menu button - if (selectedGroup) { - const visibleLabel = - this.settings.context === 'index' - ? Craft.uppercaseFirst( - Craft.t('app', 'New {type}', { - type: Craft.elementTypeNames['craft\\elements\\Category'][2], - }) - ) - : Craft.t('app', 'New {group} category', { - group: selectedGroup.name, - }); - const ariaLabel = - this.settings.context === 'index' - ? Craft.t('app', 'New category in the {group} category group', { - group: selectedGroup.name, - }) - : visibleLabel; - - const role = this.settings.context === 'index' ? 'link' : null; - - this.$newCategoryBtn = Craft.ui - .createButton({ - label: visibleLabel, - ariaLabel: ariaLabel, - spinner: true, - role: role, - }) - .addClass('submit add icon') - .appendTo(this.$newCategoryBtnGroup); - - this.addListener(this.$newCategoryBtn, 'click mousedown', (ev) => { - // If this is the element index, check for Ctrl+clicks and middle button clicks - if ( - this.settings.context === 'index' && - ((ev.type === 'click' && Garnish.isCtrlKeyPressed(ev)) || - (ev.type === 'mousedown' && ev.originalEvent.button === 1)) - ) { - window.open(Craft.getUrl(`categories/${selectedGroup.handle}/new`)); - } else if (ev.type === 'click') { - this._createCategory(selectedGroup.id); - } - }); - - if (this.editableGroups.length > 1) { - $menuBtn = $('