Tabs.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. define( function( sAppBarCss ) {
  2. "use strict";
  3. function AppBar()
  4. {
  5. };
  6. AppBar.prototype.draw = function( oControlHost )
  7. {
  8. var el = oControlHost.container;
  9. var o = oControlHost.configuration;
  10. if ( !o )
  11. {
  12. throw new scriptableReportError( "ChartTabs", "", "Expected configuration." );
  13. }
  14. this.m_bHorizontal = !!o && ( o.Orientation == "horizontal" );
  15. var sOrientation = this.m_bHorizontal ? "horizontal" : "vertical"
  16. var sAlign = ( this.m_bHorizontal && o ) ? ( o.Align || "" ) : "";
  17. var sSelector = "CCAppBar";
  18. var sUniqueSelector = sSelector + "_" + el.id;
  19. var sUniqueButtonSelector = sUniqueSelector + "Button";
  20. this.m_sCardNames = [];
  21. var aButtons = o.Buttons;
  22. if ( !aButtons )
  23. {
  24. aButtons = this.generateButtonFromDataStore( oControlHost );
  25. }
  26. var aHtml = [];
  27. aHtml.push( '<style>' );
  28. aHtml.push( '\r\n.' + sUniqueSelector + '.' + sOrientation + ' .' + sUniqueButtonSelector + ' { padding-left:' + o["Padding left"] + ';}' );
  29. aHtml.push( '\r\n.' + sUniqueSelector + '.' + sOrientation + ' .' + sUniqueButtonSelector + ' { padding-right:' + o["Padding right"] + ';}' );
  30. aHtml.push( '\r\n.' + sUniqueSelector + '.' + sOrientation + ' .' + sUniqueButtonSelector + ' { padding-top:' + o["Padding top"] + ';}' );
  31. aHtml.push( '\r\n.' + sUniqueSelector + '.' + sOrientation + ' .' + sUniqueButtonSelector + ' { padding-bottom:' + o["Padding bottom"] + ';}' );
  32. aHtml.push( '\r\n.' + sUniqueSelector + '.' + sOrientation + ' .' + sUniqueButtonSelector + ' { display: inline-block;}' );
  33. if ( o["Tab width"] )
  34. {
  35. aHtml.push( '\r\n.' + 'CCAppBar_v9Button { width:' + o["Tab width"] + ';}' );
  36. }
  37. if ( o["Tab background color"] )
  38. {
  39. aHtml.push( '\r\n.' + sUniqueSelector + ' { background-color:' + o["Tab background color"] + ';}' );
  40. }
  41. if ( o["Tab label color"] )
  42. {
  43. aHtml.push( '\r\n.' + sUniqueSelector + ' { fill:' + o["Tab label color"] + '; color:' + o["Tab label color"] + ';}' );
  44. }
  45. if ( o["Selected tab label color"] )
  46. {
  47. aHtml.push( '\r\n.' + sUniqueSelector + '.' + sOrientation + ' .' + sUniqueButtonSelector + ':hover, .' + sUniqueSelector + '.' + sOrientation + ' .' + sUniqueButtonSelector + '.selected { fill:' + o["Selected tab label color"] + '; color:' + o["Selected tab label color"] + ';}' );
  48. }
  49. if ( o["Selected tab background color"] )
  50. {
  51. aHtml.push( '\r\n.' + sUniqueSelector + '.' + sOrientation + ' .' + sUniqueButtonSelector + '.selected { background-color:' + o["Selected tab background color"] + ';}' );
  52. }
  53. aHtml.push( '</style>' );
  54. for ( var i = 0; i < aButtons.length; i++ )
  55. {
  56. var oButton = aButtons[i];
  57. this.m_sCardNames[i] = oButton.card;
  58. aHtml.push( '<div style="align-items:center; white-space:nowrap;" cardIndex="' + i + '" class="' + sUniqueButtonSelector + '">' );
  59. if ( oButton.icon )
  60. {
  61. aHtml.push( oButton.icon.join( "" ) );
  62. }
  63. else if ( oButton.iconFile )
  64. {
  65. aHtml.push( '<img src="' + oButton.iconFile + '"/>' );
  66. }
  67. if ( oButton.label )
  68. {
  69. aHtml.push( '<span style="margin-left:8px; margin-right:5px;">' + oButton.label + '</span>' );
  70. }
  71. aHtml.push( '</div>' );
  72. if ( oButton.selected || ( ( i == 0 ) && o["Select first card"] ) )
  73. {
  74. this.m_iSelectedCard = i;
  75. }
  76. }
  77. el.innerHTML = aHtml.join( "" );
  78. el.classList.add( sUniqueSelector );
  79. el.classList.add( sOrientation );
  80. if ( sAlign )
  81. {
  82. el.style.textAlign = sAlign;
  83. }
  84. this.m_nlButtonDivs = el.querySelectorAll( "." + sUniqueButtonSelector );
  85. this.f_displayCard( this.m_iSelectedCard, oControlHost );
  86. };
  87. AppBar.prototype.generateButtonFromDataStore = function( oControlHost )
  88. {
  89. var aDataStores = oControlHost.control.dataStores;
  90. var oDataStore = ( aDataStores.length > 0 ) ? aDataStores[0] : null;
  91. if ( !oDataStore )
  92. {
  93. return null;
  94. }
  95. this.m_sCards = oControlHost.configuration.Cards;
  96. var aButtons = [];
  97. var iRowCount = oDataStore.rowCount;
  98. for ( var iRow = 0; iRow < iRowCount; iRow++ )
  99. {
  100. var oButton = {};
  101. oButton.label = oDataStore.getFormattedCellValue( iRow, 0 );
  102. oButton.card = this.m_sCards;
  103. aButtons.push( oButton );
  104. }
  105. return aButtons;
  106. };
  107. AppBar.prototype.f_displayCard = function( iCardIndex, oControlHost )
  108. {
  109. for ( var i = 0; i < this.m_nlButtonDivs.length; i++ )
  110. {
  111. var div = this.m_nlButtonDivs.item( i );
  112. div.classList[( i == iCardIndex ) ? "add" : "remove"]( "selected" );
  113. if ( !this.m_bSetupEventHandlers )
  114. {
  115. div.onmousedown = this.f_displayCard.bind( this, i, oControlHost );
  116. }
  117. }
  118. this.m_bSetupEventHandlers = true;
  119. var oPage = oControlHost.page;
  120. if ( this.m_sCards )
  121. {
  122. var a = oPage.getControlsByName( this.m_sCards );
  123. for ( var i = 0; i < a.length; i++ )
  124. {
  125. a[i].setDisplay( i == iCardIndex );
  126. }
  127. return;
  128. }
  129. for ( var i = 0; i < this.m_sCardNames.length; i++ )
  130. {
  131. var control = oPage.getControlByName( this.m_sCardNames[i] );
  132. control.setDisplay( true );
  133. var element = control.element;
  134. if ( i == iCardIndex )
  135. {
  136. element.style.position = "";
  137. element.style.top = "";
  138. }
  139. else
  140. {
  141. element.style.position = "absolute";
  142. element.style.top = "-25000px";
  143. }
  144. }
  145. };
  146. return AppBar;
  147. });