Changeset 7501

Show
Ignore:
Timestamp:
03/01/07 08:17:08 (23 months ago)
Author:
peller
Message:

more ProgressBar? cleanup, attribute changes

Location:
dijit/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • dijit/trunk/ProgressBar.js

    r7490 r7501  
    2323                // (4) higher z-index 
    2424                // back and front percent label have the same content: when the vertical line (*) 
    25                 // partially hides the backPercentLabel, the frontPercentLabel becomes visible 
     25                // partially hides the backLabel, the frontLabel becomes visible 
    2626                //  
    2727                //  ________________________(1)_containerNode_________________________________ 
    2828                // |__(3)_internalProgress____________                                        | 
    2929                // |                                  | <--- (*)                              | 
    30                 // |     (4) frontPercentLabel        | (2) backPercentLabel                  | 
     30                // |     (4) frontLabel        | (2) backLabel                  | 
    3131                // |__________________________________|                                       | 
    3232                // |__________________________________________________________________________|  
     
    3737                //   places="0" width="..." height="..." dataSource="..." 
    3838                //   pollInterval="..."  
    39                 //   hasText="true|false" isVertical="true|false"  
     39                //   numeric="true|false" orientation="vertical"  
    4040                //   progress="..." maximum="..."></div> 
    4141         
    42                 // progress: String 
     42                // progress: String (Percentage or Number) 
    4343                // initial progress value.  
    4444                // with "%": percentual value, 0% <= progress <= 100% 
    4545                // or without "%": absolute value, 0 <= progress <= maximum 
    46                 progress: 0, 
    47                  
     46                progress: "0", 
     47 
    4848                // maximum: Float 
    4949                // max sample number 
     
    6262                color: "", 
    6363 
    64                 // hasText: Boolean 
     64                // numeric: Boolean 
    6565                // if true, the percent label is visible 
    66                 hasText: false, 
    67  
    68                 // isVertical: Boolean 
    69                 // if true, the widget is vertical 
    70                 isVertical: false, 
     66                numeric: false, 
     67 
     68                // orientation: String 
     69                // whether bar grows along the x-axis (default) or y- axis (vertical) 
     70                orientation: "", 
    7171 
    7272                // places: Number 
     
    100100                        } 
    101101                        dojo.html.setClass(this.containerNode, "dojoProgressBarEmpty"); 
    102                         if(this.isVertical){ 
     102                        if(this.orientation == "vertical"){ 
    103103                                dojo.html.addClass(this.containerNode, "dojoProgressBarVertical"); 
    104104                                this.internalProgress.style.bottom="0px"; 
     
    110110                                this._dimension = "width"; 
    111111                        } 
    112                         dojo.html.setClass(this.frontPercentLabel, "dojoProgressBarFrontPercent"); 
    113                         dojo.html.setClass(this.backPercentLabel, "dojoProgressBarBackPercent"); 
    114112                        this.domNode.style.height = this.height + "px";  
    115113                        this.domNode.style.width = this.width + "px"; 
    116114                        this.setMaximum(this.maximum, true); 
    117115                        this.setProgress(this.progress, true); 
    118                         this.showText(this.hasText); 
    119  
     116                        this.showLabel(this.numeric); 
    120117                        this.render(); 
    121118                }, 
    122                 showText: function(/*Boolean*/visible){ 
     119                showLabel: function(/*Boolean*/visible){ 
    123120                        // summary: shows or hides the labels 
    124121                        var display = visible ? "block" : "none"; 
    125                         this.backPercentLabel.style.display=display; 
    126                         this.frontPercentLabel.style.display=display; 
    127                         this.hasText = visible; 
     122                        this.backLabel.style.display=display; 
     123                        this.frontLabel.style.display=display; 
     124                        this.numeric = visible; 
    128125                }, 
    129126                _setupAnimation: function(){ 
    130                         var _self = this; 
     127                        var self = this; 
    131128                        this._animation = dojo.lfx.html.slideTo(this.internalProgress,  
    132129                                {top: 0, left: parseInt(this.width)-parseInt(this.internalProgress.style.width)}, parseInt(this.duration), null,  
    133130                                        function(){ 
    134                                                 var _backAnim = dojo.lfx.html.slideTo(_self.internalProgress,  
    135                                                 { top: 0, left: 0 }, parseInt(_self.duration)); 
     131                                                var _backAnim = dojo.lfx.html.slideTo(self.internalProgress,  
     132                                                { top: 0, left: 0 }, parseInt(self.duration)); 
    136133                                                dojo.event.connect(_backAnim, "onEnd", function(){ 
    137                                                         if(!_self._animationStopped){ 
    138                                                                 _self._animation.play(); 
     134                                                        if(!self._animationStopped){ 
     135                                                                self._animation.play(); 
    139136                                                        } 
    140137                                                        }); 
    141                                                 if(!_self._animationStopped){ 
     138                                                if(!self._animationStopped){ 
    142139                                                        _backAnim.play(); 
    143140                                                } 
     
    146143                                ); 
    147144                }, 
    148                 setMaximum: function(maxValue, noRender){ 
     145                setMaximum: function(/*Number*/maximum, /*Boolean?*/noRender){ 
    149146                        // summary: sets the maximum 
    150147                        // if noRender is true, only sets the internal max progress value 
     
    152149                                return; 
    153150                        } 
    154                         this.maximum = maxValue; 
     151                        this.maximum = maximum; 
    155152                        this.setProgress(this.progress, true); 
    156153                        if(!noRender){ 
     
    158155                        } 
    159156                }, 
    160                 setProgress: function(/*String|Number*/value, /*Boolean*/noRender){ 
     157                setProgress: function(/*String|Number*/value, /*Boolean?*/noRender){ 
    161158                        // summary: sets the progress 
    162159                        // if value ends width "%", does a normalization 
     
    166163                                return; 
    167164                        } 
    168  
    169165                        if(String(value).indexOf("%") != -1){ 
    170166                                this._percent = Math.min(parseFloat(value)/100, 1); 
     
    187183                        // the user doesn't know how much time the operation will last 
    188184                        if(this._animationStopped){ 
    189                                 this._backup = {progress: this.progress, hasText: this.hasText}; 
     185                                this._backup = {progress: this.progress, numeric: this.numeric}; 
    190186                                this.setProgress("10%"); 
    191187                                this._animationStopped = false; 
    192188                                this._setupAnimation(); 
    193                                 this.showText(false); 
     189                                this.showLabel(false); 
    194190                                this.internalProgress.style.height="105%"; 
    195191                                this._animation.play(); 
     
    205201                                dojo.lang.mixin(this, this._backup); 
    206202                                this.setProgress(this.progress); 
    207                                 this.showText(this.hasText); 
    208                                 this._positionPercentLabels(); 
     203                                this.showLabel(this.numeric); 
     204                                this._positionLabels(); 
    209205                        } 
    210206                }, 
    211207                _showRemoteProgress: function(){ 
    212                         var _self = this; 
    213                         if((this.maximum == this.progress) && 
    214                                 this._timer){ 
     208                        var self = this; 
     209                        if((this.maximum == this.progress) && this._timer){ 
    215210                                clearInterval(this._timer); 
    216211                                this._timer = null; 
     
    219214                        } 
    220215                        var bArgs = { 
    221                                 url: _self.dataSource, 
     216                                url: self.dataSource, 
    222217                                method: "POST", 
    223218                                mimetype: "text/json", 
     
    226221                                }, 
    227222                                load: function(type, data, evt){ 
    228                                         _self.setProgress(_self._timer ? data.progress : "100%"); 
     223                                        self.setProgress(self._timer ? data.progress : "100%"); 
    229224                                } 
    230225                        }; 
     
    235230                        // summary: renders the ProgressBar, based on current values 
    236231 
    237                         this._updatePercentLabels(this._percent); 
     232                        this._updateLabels(this._percent); 
    238233 
    239234                        var pixels = this._percent * this[this._dimension]; 
     
    241236                        this.onChange(); 
    242237 
    243                         this._positionPercentLabels(); 
    244                 }, 
    245  
    246                 _positionPercentLabels: function(){ 
    247                         var front = dojo.html.getContentBox(this.frontPercentLabel); 
    248                         var frontLeft = (this.width - front.width)/2; 
    249                         var frontBottom = (this.height - front.height)/2; 
    250                         this.frontPercentLabel.style.left = frontLeft + "px"; 
    251                         this.frontPercentLabel.style.bottom = frontBottom + "px"; 
    252                         var back = dojo.html.getContentBox(this.backPercentLabel); 
    253                         var backLeft = (this.width - back.width)/2; 
    254                         var backBottom = (this.height - back.height)/2; 
    255                         this.backPercentLabel.style.left = backLeft + "px"; 
    256                         this.backPercentLabel.style.bottom = backBottom + "px";  
    257                 }, 
    258                 _updatePercentLabels: function(/*float*/percentValue){ 
     238                        this._positionLabels(); 
     239                }, 
     240 
     241                _positionLabels: function(){ 
    259242                        dojo.lang.forEach(["front", "back"], function(name){ 
    260                                 var labelNode = this[name+"PercentLabel"]; 
    261                                 dojo.dom.textContent(labelNode, dojo.number.format(percentValue, {type: "percent", places: this.places})); 
     243                                var labelNode = this[name+"Label"]; 
     244                                var dim = dojo.html.getContentBox(labelNode); 
     245                                var labelLeft = (this.width - dim.width)/2; 
     246                                var labelBottom = (this.height - dim.height)/2; 
     247                                labelNode.style.left = labelLeft + "px"; 
     248                                labelNode.style.bottom = labelBottom + "px"; 
     249                        }, this); 
     250                }, 
     251                _updateLabels: function(/*float*/percent){ 
     252                        dojo.lang.forEach(["front", "back"], function(name){ 
     253                                var labelNode = this[name+"Label"]; 
     254                                dojo.dom.textContent(labelNode, dojo.number.format(percent, {type: "percent", places: this.places})); 
    262255                        }, this); 
    263256                }, 
  • dijit/trunk/templates/ProgressBar.html

    r7482 r7501  
    11<div dojoAttachPoint="containerNode"> 
    2         <div style="position:absolute;display:none;width:100%;text-align:center" dojoAttachPoint="backPercentLabel" class="dojoBackPercentLabel"></div> 
     2        <div style="position:absolute;display:none;width:100%;text-align:center" dojoAttachPoint="backLabel" class="dojoProgressBarBackLabel"></div> 
    33        <div style="position:absolute;overflow:hidden;width:100%;height:100%" dojoAttachPoint="internalProgress"> 
    4         <div style="position:absolute;display:none;width:100%;text-align:center" dojoAttachPoint="frontPercentLabel" class="dojoFrontPercentLabel"></div></div> 
     4        <div style="position:absolute;display:none;width:100%;text-align:center" dojoAttachPoint="frontLabel" class="dojoProgressBarFrontLabel"></div></div> 
    55</div> 
  • dijit/trunk/tests/test_ProgressBar.html

    r7490 r7501  
    6969                <input type="button" name="set" id="set" value="set!" /> 
    7070                <br /> 
    71                 <div width="400" hasText="true" 
     71                <div width="400" numeric="true" 
    7272                        maximum="200" id="setTestBar" progress="20" dojoType="dijit.ProgressBar"></div>          
    7373                <br /> 
     
    7777                <br /> 
    7878                <br /> 
    79                 <div width="400" hasText="true"   
     79                <div width="400" numeric="true"   
    8080                        maximum="256" id="testBar" duration="2000" dojoType="dijit.ProgressBar"></div>           
    8181                <input type="button" name="start" id="start" value="start" /> 
     
    8484                Small, without text and background image: 
    8585                <br /> 
    86                 <div width="440" height="10" color="red" hasText="false" isVertical="false"  
     86                <div width="440" height="10" color="red" orientation="horizontal"  
    8787                        maximum="256" id="smallTestBar" dojoType="dijit.ProgressBar"></div>              
    8888                <br /> 
    8989                Show decimal place: 
    90                 <div places="1" width="400" hasText="true" isVertical="false"  
     90                <div places="1" width="400" numeric="true" orientation="horizontal"  
    9191                        maximum="256" id="testBarInt" dojoType="dijit.ProgressBar"></div>                
    9292                <br /> 
    9393                <div style="position:absolute;top:70px;left:530px"> 
    9494                Vertical: 
    95                 <div progress="0" height="420" width="50" hasText="true" isVertical="true"  
     95                <div progress="0" height="420" width="50" numeric="true" orientation="vertical"  
    9696                                maximum="256" id="testBar2" dojoType="dijit.ProgressBar"></div> 
    9797                </div> 
     98                <h3>Test 3</h3> 
     99                No explicit maximum (both 25%) 
     100                <div width="400" numeric="true" 
     101                        id="implied1" progress="25" dojoType="dijit.ProgressBar"></div>          
     102                <div width="400" numeric="true" 
     103                        id="implied2" progress="25%" dojoType="dijit.ProgressBar"></div> 
    98104        </body> 
    99105</html> 
    100 € 
  • dijit/trunk/themes/tundra/tundra.css

    r7490 r7501  
    149149} 
    150150 
    151 .dojoProgressBarSimpleFrontBar{ 
    152         background: red; 
    153 } 
    154  
    155 .dojoProgressBarFrontPercent,.dojoProgressBarBackPercent{ 
     151.dojoProgressBarFrontLabel,.dojoProgressBarBackLabel{ 
    156152        font:bold 13px helvetica; 
    157153} 
    158154 
    159 .dojoProgressBarBackPercent{ 
     155.dojoProgressBarBackLabel{ 
    160156        color:#293a4b; 
    161157} 
    162 .dojoProgressBarFrontPercent{ 
     158.dojoProgressBarFrontLabel{ 
    163159        color:#fff; 
    164160}