You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

161 lines
6.7 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-layout-CardLayout'>/**
  19. </span> * @class Ext.layout.CardLayout
  20. * @extends Ext.layout.FitLayout
  21. * &lt;p&gt;This layout manages multiple child Components, each fitted to the Container, where only a single child Component can be
  22. * visible at any given time. This layout style is most commonly used for wizards, tab implementations, etc.
  23. * This class is intended to be extended or created via the layout:'card' {@link Ext.Container#layout} config,
  24. * and should generally not need to be created directly via the new keyword.&lt;/p&gt;
  25. * &lt;p&gt;The CardLayout's focal method is {@link #setActiveItem}. Since only one panel is displayed at a time,
  26. * the only way to move from one Component to the next is by calling setActiveItem, passing the id or index of
  27. * the next panel to display. The layout itself does not provide a user interface for handling this navigation,
  28. * so that functionality must be provided by the developer.&lt;/p&gt;
  29. * &lt;p&gt;In the following example, a simplistic wizard setup is demonstrated. A button bar is added
  30. * to the footer of the containing panel to provide navigation buttons. The buttons will be handled by a
  31. * common navigation routine -- for this example, the implementation of that routine has been ommitted since
  32. * it can be any type of custom logic. Note that other uses of a CardLayout (like a tab control) would require a
  33. * completely different implementation. For serious implementations, a better approach would be to extend
  34. * CardLayout to provide the custom functionality needed. Example usage:&lt;/p&gt;
  35. * &lt;pre&gt;&lt;code&gt;
  36. var navHandler = function(direction){
  37. // This routine could contain business logic required to manage the navigation steps.
  38. // It would call setActiveItem as needed, manage navigation button state, handle any
  39. // branching logic that might be required, handle alternate actions like cancellation
  40. // or finalization, etc. A complete wizard implementation could get pretty
  41. // sophisticated depending on the complexity required, and should probably be
  42. // done as a subclass of CardLayout in a real-world implementation.
  43. };
  44. var card = new Ext.Panel({
  45. title: 'Example Wizard',
  46. layout:'card',
  47. activeItem: 0, // make sure the active item is set on the container config!
  48. bodyStyle: 'padding:15px',
  49. defaults: {
  50. // applied to each contained panel
  51. border:false
  52. },
  53. // just an example of one possible navigation scheme, using buttons
  54. bbar: [
  55. {
  56. id: 'move-prev',
  57. text: 'Back',
  58. handler: navHandler.createDelegate(this, [-1]),
  59. disabled: true
  60. },
  61. '-&gt;', // greedy spacer so that the buttons are aligned to each side
  62. {
  63. id: 'move-next',
  64. text: 'Next',
  65. handler: navHandler.createDelegate(this, [1])
  66. }
  67. ],
  68. // the panels (or &quot;cards&quot;) within the layout
  69. items: [{
  70. id: 'card-0',
  71. html: '&amp;lt;h1&amp;gt;Welcome to the Wizard!&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;Step 1 of 3&amp;lt;/p&amp;gt;'
  72. },{
  73. id: 'card-1',
  74. html: '&amp;lt;p&amp;gt;Step 2 of 3&amp;lt;/p&amp;gt;'
  75. },{
  76. id: 'card-2',
  77. html: '&amp;lt;h1&amp;gt;Congratulations!&amp;lt;/h1&amp;gt;&amp;lt;p&amp;gt;Step 3 of 3 - Complete&amp;lt;/p&amp;gt;'
  78. }]
  79. });
  80. &lt;/code&gt;&lt;/pre&gt;
  81. */
  82. Ext.layout.CardLayout = Ext.extend(Ext.layout.FitLayout, {
  83. <span id='Ext-layout-CardLayout-cfg-deferredRender'> /**
  84. </span> * @cfg {Boolean} deferredRender
  85. * True to render each contained item at the time it becomes active, false to render all contained items
  86. * as soon as the layout is rendered (defaults to false). If there is a significant amount of content or
  87. * a lot of heavy controls being rendered into panels that are not displayed by default, setting this to
  88. * true might improve performance.
  89. */
  90. deferredRender : false,
  91. <span id='Ext-layout-CardLayout-cfg-layoutOnCardChange'> /**
  92. </span> * @cfg {Boolean} layoutOnCardChange
  93. * True to force a layout of the active item when the active card is changed. Defaults to false.
  94. */
  95. layoutOnCardChange : false,
  96. <span id='Ext-layout-CardLayout-cfg-renderHidden'> /**
  97. </span> * @cfg {Boolean} renderHidden @hide
  98. */
  99. <span id='Ext-layout-CardLayout-cfg-renderHidden'> // private
  100. </span> renderHidden : true,
  101. <span id='Ext-layout-CardLayout-property-type'> type: 'card',
  102. </span>
  103. <span id='Ext-layout-CardLayout-method-setActiveItem'> /**
  104. </span> * Sets the active (visible) item in the layout.
  105. * @param {String/Number} item The string component id or numeric index of the item to activate
  106. */
  107. setActiveItem : function(item){
  108. var ai = this.activeItem,
  109. ct = this.container;
  110. item = ct.getComponent(item);
  111. // Is this a valid, different card?
  112. if(item &amp;&amp; ai != item){
  113. // Changing cards, hide the current one
  114. if(ai){
  115. ai.hide();
  116. if (ai.hidden !== true) {
  117. return false;
  118. }
  119. ai.fireEvent('deactivate', ai);
  120. }
  121. var layout = item.doLayout &amp;&amp; (this.layoutOnCardChange || !item.rendered);
  122. // Change activeItem reference
  123. this.activeItem = item;
  124. // The container is about to get a recursive layout, remove any deferLayout reference
  125. // because it will trigger a redundant layout.
  126. delete item.deferLayout;
  127. // Show the new component
  128. item.show();
  129. this.layout();
  130. if(layout){
  131. item.doLayout();
  132. }
  133. item.fireEvent('activate', item);
  134. }
  135. },
  136. <span id='Ext-layout-CardLayout-method-renderAll'> // private
  137. </span> renderAll : function(ct, target){
  138. if(this.deferredRender){
  139. this.renderItem(this.activeItem, undefined, target);
  140. }else{
  141. Ext.layout.CardLayout.superclass.renderAll.call(this, ct, target);
  142. }
  143. }
  144. });
  145. Ext.Container.LAYOUTS['card'] = Ext.layout.CardLayout;
  146. </pre>
  147. </body>
  148. </html>