Advertisement
Guest User

Untitled

a guest
Jun 28th, 2022
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sap.ui.define(
  2.   ['sap/ui/core/Item', 'sap/m/IconTabFilter'],
  3.   function (Item, IconTabFilter) {
  4.     'use strict';
  5.  
  6.     const IconTabButton = Item.extend('your.namespace.IconTabButton', {
  7.       metadata: {
  8.         interfaces: ['sap.m.IconTab'],
  9.         aggregations: {
  10.           button: {
  11.             type: 'sap.m.Button',
  12.             multiple: false,
  13.           },
  14.           content: {
  15.             type: 'sap.ui.core.Control',
  16.             multiple: true,
  17.           },
  18.         },
  19.         properties: {
  20.           visible: { type: 'boolean', defaultValue: true },
  21.           enabled: { type: 'boolean', defaultValue: true },
  22.           icon: { type: 'sap.ui.core.URI', defaultValue: '' },
  23.           iconDensityAware: {
  24.             type: 'boolean',
  25.             defaultValue: true,
  26.           },
  27.           count: { type: 'string', defaultValue: '' },
  28.         },
  29.       },
  30.       init: function () {
  31.         this._oCloneInList = null; // holds reference to the cloned item in the SelectList
  32.       },
  33.       _getRealTab: function () {
  34.         return IconTabFilter.prototype._getRealTab.call(this);
  35.       },
  36.       _getNonEmptyKey: function () {
  37.         return IconTabFilter.prototype._getNonEmptyKey.call(this);
  38.       },
  39.       _getNestedLevel: function () {
  40.         return IconTabFilter.prototype._getNestedLevel.call(this);
  41.       },
  42.       _getRootTab: function () {
  43.         return IconTabFilter.prototype._getRootTab.call(this);
  44.       },
  45.       _isParentOf: function () {
  46.         return IconTabFilter.prototype._isParentOf.call(this);
  47.       },
  48.       _getAllSubFilters: function () {
  49.         return IconTabFilter.prototype._getAllSubFilters.call(this);
  50.       },
  51.       _getAllSubItems: function () {
  52.         return IconTabFilter.prototype._getAllSubItems.call(this);
  53.       },
  54.       getItems: function () {
  55.         return IconTabFilter.prototype.getItems.call(this);
  56.       },
  57.       renderInSelectList: function (
  58.         oRM,
  59.         oSelectList,
  60.         iIndexInSet,
  61.         iSetSize,
  62.         fPaddingValue,
  63.       ) {
  64.         if (this._invisibleText) {
  65.           this._invisibleText.destroy();
  66.           this._invisibleText = null;
  67.         }
  68.  
  69.         if (!this.getVisible()) {
  70.           return;
  71.         }
  72.  
  73.         var bTextOnly = true,
  74.           bIconOnly = false,
  75.           oIconTabHeader = oSelectList._oIconTabHeader;
  76.  
  77.         if (oIconTabHeader) {
  78.           bTextOnly = oIconTabHeader._bTextOnly;
  79.         }
  80.  
  81.         oRM
  82.           .openStart('li', this)
  83.           .class('sapMITBSelectItem')
  84.           .attr('tabindex', '-1')
  85.           .attr('role', 'menuitem');
  86.  
  87.         if (fPaddingValue) {
  88.           oRM.style('padding-left', fPaddingValue + 'rem');
  89.         }
  90.  
  91.         if (iIndexInSet !== undefined && iSetSize !== undefined) {
  92.           oRM.attr('aria-posinset', iIndexInSet + 1);
  93.           oRM.attr('aria-setsize', iSetSize);
  94.           oRM.attr('aria-level', this._getNestedLevel());
  95.         }
  96.  
  97.         var sTooltip = this.getTooltip_AsString();
  98.         if (sTooltip) {
  99.           oRM.attr('title', sTooltip);
  100.         }
  101.  
  102.         if (oIconTabHeader._isUnselectable(this)) {
  103.           oRM.class('sapMITHUnselectable');
  104.         }
  105.  
  106.         if (!this.getEnabled()) {
  107.           oRM.class('sapMITBDisabled').attr('aria-disabled', true);
  108.         }
  109.  
  110.         if (oSelectList.getSelectedItem() == this) {
  111.           oRM.class('sapMITBSelectItemSelected');
  112.           oRM.attr('aria-selected', true);
  113.         }
  114.  
  115.         var oIconColor = 'Neutral';
  116.         oRM.class('sapMITBFilter' + oIconColor);
  117.  
  118.         var sItemId = this.getId(),
  119.           bShouldReadIconColor =
  120.             oIconColor == 'Positive' ||
  121.             oIconColor == 'Critical' ||
  122.             oIconColor == 'Negative' ||
  123.             oIconColor == 'Neutral',
  124.           aLabelledByIds = [];
  125.  
  126.         if (!bIconOnly) {
  127.           aLabelledByIds.push(sItemId + '-text');
  128.         }
  129.  
  130.         if (!bTextOnly && this.getIcon()) {
  131.           aLabelledByIds.push(sItemId + '-icon');
  132.         }
  133.  
  134.         if (bShouldReadIconColor) {
  135.           this._invisibleText = new sap.ui.core.InvisibleText({
  136.             text: 'ICONTABBAR_ICONCOLOR_NEUTRAL',
  137.           });
  138.  
  139.           aLabelledByIds.push(this._invisibleText.getId());
  140.         }
  141.  
  142.         oRM
  143.           .accessibilityState({ labelledby: aLabelledByIds.join(' ') })
  144.           .openEnd();
  145.  
  146.         if (this._invisibleText) {
  147.           oRM.renderControl(this._invisibleText);
  148.         }
  149.  
  150.         if (!bTextOnly) {
  151.           this._renderIcon(oRM, bIconOnly);
  152.         }
  153.  
  154.         if (!bIconOnly) {
  155.           this._renderText(oRM);
  156.         }
  157.         oRM.close('li');
  158.       },
  159.       _getSelectList: function () {
  160.         return IconTabFilter.prototype._getSelectList.call(this);
  161.       },
  162.       _setSelectListItems: function () {
  163.         return IconTabFilter.prototype._setSelectListItems.call(this);
  164.       },
  165.       _expandButtonPress: function () {
  166.         return IconTabFilter.prototype._expandButtonPress.call(this);
  167.       },
  168.       _getAllSubFilters: function () {
  169.         return IconTabFilter.prototype._getAllSubFilters.call(this);
  170.       },
  171.       _getAllSubFiltersDomRefs: function () {
  172.         return IconTabFilter.prototype._getAllSubFiltersDomRefs.call(this);
  173.       },
  174.       _getFirstAvailableSubFilter: function () {
  175.         return IconTabFilter.prototype._getFirstAvailableSubFilter.call(this);
  176.       },
  177.       _createPopoverCloseButton: function () {
  178.         return IconTabFilter.prototype._createPopoverCloseButton.call(this);
  179.       },
  180.       _closePopover: function () {
  181.         return IconTabFilter.prototype._closePopover.call(this);
  182.       },
  183.       _renderText: function (oRM) {
  184.         var sText = 'ADD NEW',
  185.           sCount = this.getCount(),
  186.           bRTL = sap.ui.getCore().getConfiguration().getRTL(),
  187.           sTextDir = this.getTextDirection();
  188.  
  189.         oRM
  190.           .openStart('span', this.getId() + '-text')
  191.           .attr('dir', 'ltr')
  192.           .class('sapMText')
  193.           .class('sapMTextNoWrap')
  194.           .class('sapMITBText')
  195.           .class('sapMITBBadgeHolder');
  196.  
  197.         if (sTextDir !== sap.ui.core.TextDirection.Inherit) {
  198.           oRM.attr('dir', sTextDir.toLowerCase());
  199.         }
  200.  
  201.         var sTextAlign = sap.ui.core.TextAlign.Initial;
  202.         if (sTextAlign) {
  203.           oRM.style('text-align', sTextAlign);
  204.         }
  205.  
  206.         if (sCount) {
  207.           if (bRTL) {
  208.             sText = '(' + sCount + ') ' + sText;
  209.           } else {
  210.             sText += ' (' + sCount + ')';
  211.           }
  212.         }
  213.  
  214.         oRM.openEnd().text(sText).close('span');
  215.       },
  216.       render: function (oRM) {
  217.         let mAriaParams = {};
  218.         if (!this.getVisible()) {
  219.           return;
  220.         }
  221.         oRM
  222.           .openStart('div', this)
  223.           .accessibilityState(mAriaParams)
  224.           .class('sapMITBItem');
  225.         oRM.openEnd();
  226.         oRM.renderControl(this.getButton());
  227.         oRM.close('div');
  228.       },
  229.     });
  230.     return IconTabButton;
  231.   },
  232. );
  233.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement