partkeepr

fork of partkeepr
git clone https://git.e1e0.net/partkeepr.git
Log | Files | Refs | Submodules | README | LICENSE

Ext.ux.Wizard.Header.js (5340B)


      1 /**
      2  * Licensed under GNU LESSER GENERAL PUBLIC LICENSE Version 3
      3  *
      4  * @author Thorsten Suckow-Homberg <ts@siteartwork.de>
      5  * @url http://www.siteartwork.de/wizardcomponent
      6  */
      7 
      8 /**
      9  * @class Ext.ux.Wiz.Header
     10  * @extends Ext.BoxComponent
     11  *
     12  * A specific {@link Ext.BoxComponent} that can be used to show the current process in an
     13  * {@link Ext.ux.Wiz}.
     14  *
     15  * An instance of this class is usually being created by {@link Ext.ux.Wiz#initPanels} using the
     16  * {@link Ext.ux.Wiz#headerConfig}-object.
     17  *
     18  * @private
     19  * @constructor
     20  * @param {Object} config The config object
     21  */
     22 Ext.define('Ext.ux.wizard.Header', {
     23     extend: 'Ext.container.Container',
     24     alias: 'widget.wizardheader',
     25 
     26     /**
     27     * @cfg {Number} height The height of this component. Defaults to "55".
     28     */
     29     height: 55,
     30 
     31     /**
     32     * @cfg {String} region The Region of this component. Since a {@link Ext.ux.Wiz}
     33     * usually uses a {@link Ext.layout.BorderLayout}, this property defaults to
     34     * "north". If you want to change this property, you should also change the appropriate
     35     * css-classes that are used for this component.
     36     */
     37     region: 'north',
     38 
     39     /**
     40     * @cfg {String} title The title that gets rendered in the head of the component. This
     41     * should be a text describing the purpose of the wizard.
     42     */
     43     title: 'Wizard',
     44 
     45     /**
     46     * @cfg {Number} steps The overall number of steps the user has to go through
     47     * to finish the wizard.
     48     */
     49     steps: 0,
     50 
     51     /**
     52     * @cfg {String} stepText The text in the header indicating the current process in the wizard.
     53     * (defaults to "Step {0} of {1}: {2}").
     54     * {0} is replaced with the index (+1) of the current card, {1} is replaced by the
     55     * total number of cards in the wizard and {2} is replaced with the title-property of the
     56     * {@link Ext.ux.Wiz.Card}
     57     * @type String
     58     */
     59     // stepText: "Step {0} of {1}: {2}",
     60     stepText: '<div class="ext-ux-wiz-Header">' +
     61               '    <div class="ext-ux-wiz-Header-title"></div>' +
     62               '    <div> ' +
     63               '       <div class="ext-ux-wiz-Header-step">Step {0} of {1}: {2} </div>' +
     64               '       <div class="ext-ux-wiz-Header-stepIndicator-container"> ' +
     65               '{stepIndicator}' +
     66               '       </div>' +
     67               '    </div> ' +
     68               '</div>',
     69 
     70     /**
     71     * @cfg {Object} autoEl The element markup used to render this component.
     72     */
     73     autoEl: {
     74         tag: 'div',
     75         cls: 'ext-ux-wiz-Header',
     76         children: [{
     77             tag: 'div',
     78             cls: 'ext-ux-wiz-Header-title'
     79         }, {
     80             tag: 'div',
     81             children: [{
     82                 tag: 'div',
     83                 cls: 'ext-ux-wiz-Header-step'
     84             }, {
     85                 tag: 'div',
     86                 cls: 'ext-ux-wiz-Header-stepIndicator-container'
     87             }]
     88         }]
     89     },
     90 
     91     /**
     92     * @param {Ext.Element}
     93     */
     94     titleEl: null,
     95 
     96     /**
     97     * @param {Ext.Element}
     98     */
     99     stepEl: null,
    100 
    101     /**
    102     * @param {Ext.Element}
    103     */
    104     imageContainer: null,
    105 
    106     /**
    107     * @param {Array}
    108     */
    109     indicators: null,
    110 
    111     /**
    112     * @param {Ext.Template}
    113     */
    114     stepTemplate: null,
    115 
    116     /**
    117     * @param {Number} lastActiveStep Stores the index of the last active card that
    118     * was shown-
    119     */
    120     lastActiveStep: -1,
    121 
    122     // -------- helper
    123     /**
    124     * Gets called by  {@link Ext.ux.Wiz#onCardShow()} and updates the header
    125     * with the approppriate information, such as the progress of the wizard
    126     * (i.e. which card is being shown etc.)
    127     *
    128     * @param {Number} currentStep The index of the card currently shown in
    129     * the wizard
    130     * @param {String} title The title-property of the {@link Ext.ux.Wiz.Card}
    131     *
    132     * @private
    133     */
    134     updateStep: function (currentStep, title) {
    135         var html = this.stepTemplate.apply({
    136             0: currentStep + 1,
    137             1: this.steps,
    138             2: title,
    139             step: currentStep,
    140             steps: this.steps,
    141             title: title
    142         });
    143 
    144         this.update(html);
    145 
    146         this.lastActiveStep = currentStep;
    147     },
    148 
    149 
    150     // -------- listener
    151     /**
    152     * Overrides parent implementation to initComponent this component properly.
    153     */
    154     initComponent: function () {
    155 		this.autoEl.cls = this.autoEl.cls + " " + this.cls;
    156         this.callParent(arguments);
    157     },
    158 
    159     /**
    160     * Overrides parent implementation to render this component properly.
    161     */
    162     onRender: function (ct, position) {
    163 
    164         var image = null;
    165         var steptxt = this.stepText.split("{stepIndicator}");
    166         var stepboxs = "\n";
    167 
    168         if (steptxt.length > 1) {
    169             for (var i = 0, len = this.steps; i < len; i++) {
    170                 stepboxs += '<div class=\'ext-ux-wiz-Header-stepIndicator <tpl if="step == ' + i + '" >ext-ux-wiz-Header-stepIndicator-active</tpl>\'>&#160;</div>\n';
    171             }
    172 
    173             stepboxs = ('<tpl for=".">' + steptxt[0] + stepboxs + steptxt[1] + '</tpl>');
    174 
    175             if (this.region == "west" || this.region == "east") {
    176                 this.stepText = stepboxs.replace(/Header/gi, "Side");
    177             } else {
    178                 this.stepText = stepboxs;
    179             }
    180         } 
    181 
    182         this.stepTemplate = new Ext.XTemplate(this.stepText);
    183         this.stepTemplate.compile();
    184 
    185         this.callParent(arguments);
    186     }
    187 });