官术网_书友最值得收藏!

Wizard style UI using a card layout

The Wizard style UI is perfect when you need to lead the user through a series of steps in a specific sequence. Wizards are especially suited for complex or infrequently performed tasks, where the user is unfamiliar with the steps involved. In the following screenshot, you'll see what the Wizard style UI built in this recipe looks like:

Wizard style UI using a card layout

How to do it...

  1. Create the wizard's cards or steps:
    card0=new Ext.Panel({
    id: 'card-0',
    html: '<h1>Step 1 of 3</h1><p>Welcome to the wizard. </p><p>Click the "Next" button to continue...</p>'
    });
    card1=new Ext.Panel({
    id: 'card-1',
    html: '<h1>Step 2 of 3</h1><p>One more step left.</p><p>Please click the "Next" button to continue...</p>'
    });
    card2=new Ext.Panel({
    id: 'card-2',
    html: '<h1>Step 3 of 3</h1><p>This is the last step. You made it!</p>'
    });
    
  2. You need a function to switch the steps:
    var navigationHandler=function(increment) {
    var layout=Ext.getCmp('card-wizard').getLayout();
    var activeItemIdx=layout.activeItem.id.split('card-')[1];
    var next=parseInt(activeItemIdx) + increment;
    layout.setActiveItem(next);
    if (next==0) {
    Ext.getCmp('card-prev').setDisabled(true);
    } else {
    Ext.getCmp('card-prev').setDisabled(false);
    }
    if (next==2) {
    Ext.getCmp('card-next').setDisabled(true);
    } else {
    Ext.getCmp('card-next').setDisabled(false);
    }
    };
    
  3. Now, put the steps together in a container:
    var cardWizard=new Ext.Panel({
    id: 'card-wizard',
    title: 'A wizard using card layout',
    applyTo: 'card-panel',
    width: 400,
    height: 300,
    frame:true,
    layout: 'card',
    activeItem: 0,
    bodyStyle: 'padding:15px;background-color:#ffffff',
    defaults: { border: false },
    bbar: ['->', {
    id: 'card-prev',
    text: 'Previous',
    handler: navigationHandler.createDelegate(this, [-1]),
    disabled: true,
    iconCls: 'btn-arrow-left-green',
    cls:'x-btn-text-icon',
    minWidth:50
    }, {
    id: 'card-next',
    text: 'Next',
    handler: navigationHandler.createDelegate(this, [1]),
    iconCls: 'btn-arrow-right-green',
    cls: 'x-btn-text-icon',
    minWidth: 50,
    style:'text-align:left'
    }],
    items: [card0, card1, card2]
    });
    

How it works...

A wizard is built by creating a number of panels that will function as wizard steps. The panels are hosted in a container that uses a CardLayout. This layout makes each panel fit to the container with only a single panel visible at any given time.

There's more...

The CardLayout does not provide a mechanism for handling navigation from one panel to the next. Therefore, this functionality must be provided by the developer. Since only one panel is displayed at a time, the navigation handler will achieve moving from one panel to the next by calling the layout's setActiveItem method and passing the ID or index of the next panel to display.

See also...

  • The Creating a modern application layout with collapsible regions recipe (seen later in this chapter) explains how to create one of the most popular UI layouts
主站蜘蛛池模板: 广丰县| 博乐市| 龙陵县| 德惠市| 资溪县| 那曲县| 越西县| 中西区| 凤台县| 芒康县| 永善县| 连平县| 青神县| 宁强县| 大悟县| 新邵县| 郸城县| 成武县| 东阿县| 靖江市| 长兴县| 元谋县| 陆良县| 凤冈县| 鹰潭市| 盖州市| 新平| 科技| 临武县| 扬中市| 弥勒县| 涞源县| 安化县| 太谷县| 新宾| 屏山县| 福贡县| 定陶县| 雷波县| 台北市| 平顶山市|