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

  • Ext JS 3.0 Cookbook
  • Jorge Ramon
  • 387字
  • 2021-04-01 13:43:47

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
主站蜘蛛池模板: 桦川县| 鹤山市| 庄河市| 四川省| 三江| 武邑县| 神池县| 宜兰县| 皋兰县| 昭苏县| 苏尼特左旗| 敦化市| 灌云县| 秦皇岛市| 正定县| 勐海县| 文登市| 浪卡子县| 高雄县| 利津县| 黔西| 贵溪市| 嵩明县| 大兴区| 武川县| 瑞丽市| 香河县| 徐闻县| 阜阳市| 新宁县| 土默特左旗| 沅陵县| 嘉荫县| 额济纳旗| 邳州市| 新安县| 襄城县| 黄冈市| 锦屏县| 元阳县| 阿合奇县|