Panel.js 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. Ext.define('uas.override.tab.Panel', {
  2. override: 'Ext.tab.Panel',
  3. /**
  4. * @protected
  5. * Makes sure we have a Tab for each item added to the TabPanel
  6. */
  7. onAdd: function(item, index) {
  8. var me = this,
  9. cfg = Ext.apply({}, item.tabConfig),
  10. tabBar = me.getTabBar(),
  11. ariaDom,
  12. defaultConfig = {
  13. xtype: 'tab',
  14. title: item.title,
  15. icon: item.icon,
  16. iconCls: item.iconCls,
  17. glyph: item.glyph,
  18. ui: tabBar.ui,
  19. card: item,
  20. disabled: item.disabled,
  21. closable: item.closable,
  22. hidden: item.hidden && !item.hiddenByLayout,
  23. // only hide if it wasn't hidden by the layout itself
  24. tooltip: item.tooltip,
  25. tabBar: tabBar,
  26. tabPosition: tabBar.dock,
  27. rotation: tabBar.getTabRotation()
  28. };
  29. if (item.closeText !== undefined) {
  30. defaultConfig.closeText = item.closeText;
  31. }
  32. cfg = Ext.applyIf(cfg, defaultConfig);
  33. // Create the correspondiong tab in the tab bar
  34. item.tab = me.tabBar.insert(index, cfg);
  35. // We want to force the relationship of the tabpanel to the tab
  36. item.ariaRole = 'tabpanel';
  37. // Item might be already rendered and then added to the TabPanel
  38. ariaDom = item.ariaEl.dom;
  39. if (ariaDom) {
  40. ariaDom.setAttribute('aria-labelledby', item.tab.id);
  41. } else {
  42. item.ariaRenderAttributes = item.ariaRenderAttributes || {};
  43. item.ariaRenderAttributes['aria-labelledby'] = item.tab.id;
  44. }
  45. item.on({
  46. scope: me,
  47. enable: me.onItemEnable,
  48. disable: me.onItemDisable,
  49. beforeshow: me.onItemBeforeShow,
  50. iconchange: me.onItemIconChange,
  51. iconclschange: me.onItemIconClsChange,
  52. glyphchange: me.onItemGlyphChange,
  53. titlechange: me.onItemTitleChange
  54. });
  55. if (item.isPanel) {
  56. if (me.removePanelHeader) {
  57. if (item.rendered) {
  58. if (item.header) {
  59. item.header.hide();
  60. }
  61. } else {
  62. item.header = false;
  63. }
  64. }
  65. if (item.isPanel && me.border) {
  66. item.setBorder(false);
  67. }
  68. }
  69. // Force the view model to be created, see onRender
  70. if (me.rendered) {
  71. item.getBind();
  72. }
  73. // Ensure that there is at least one active tab. This is only needed when adding tabs via a loader config, i.e., there
  74. // may be no pre-existing tabs. Note that we need to check if activeTab was explicitly set to `null` in the tabpanel
  75. // config (which tells the layout not to set an active item), as this is a valid value to mean 'do not set an active tab'.
  76. // 增加dynamic属性判断
  77. if (me.rendered && (me.loader || me.dynamic) && me.activeTab === undefined && me.layout.activeItem !== null) {
  78. me.setActiveTab(0);
  79. }
  80. }
  81. });