CardLayout.js
上传用户:dawnssy
上传日期:2022-08-06
资源大小:9345k
文件大小:5k
源码类别:

JavaScript

开发平台:

JavaScript

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