/* Copyright (c) 2006-2010, ePages GmbH All Rights Reserved. * +---------------------------------------+ * |@@@@@@@@@@@@@@@@@@@ | * +---------------------------------------+ * {preStatusString}: {progress} / {maximum} */ dojo.provide("epages.widget.ProgressBar"); dojo.require('epages.widget.LocalizedWidget'); dojo.require("dojo.number"); dojo.declare( "epages.widget.ProgressBar", [epages.widget.LocalizedWidget], { /** * public properties * */ maximum : 0.0, progress : 0.0, preStatusString : "", disableStatusString : false, /** * widget properties */ percentageClass : 'PercentageNormal', templatePath : dojo.moduleUrl('epages.widget','templates/ProgressBar.html'), translationName : dojo.moduleUrl('epages.widget','templates/translation'), postCreate: function() { this.inherited("postCreate", arguments); dojo.subscribe(this.id+'/updateProgress', this, 'updateProgress'); dojo.subscribe(this.id+'/setMaximum', this, 'setMaximum'); }, updateData : function(/* Object */ usageData) { // summary: Write current data to class members and update widget. dojo.mixin(this,usageData); this._updateWidget(); }, setMaximum : function(/* Integer */ maximum) { // summary: Write current data to class members and update widget. this.maximum = parseFloat(maximum); this._updateWidget(); }, updateProgress : function (/* Integer */ progress) { // summary: Change the current progress and update the widget. this.progress = parseFloat(progress); this._updateWidget(); }, _updateWidget : function() { // summary: Compose strings with usage percentage, maximum and progress // and update the widget's template attach points. var percentage = 100 * parseFloat(this.progress) / parseFloat(this.maximum); var displayPercentageTwoDec = dojo.number.round(percentage, 2).toString() + '%'; var displayPercentageNoDec = dojo.number.round(percentage, 0).toString() + '%'; dojo.attr(this.progressBar, 'style', 'width:' + displayPercentageNoDec); this.progressBar.title = displayPercentageTwoDec + ' : '+ this.progress + ' ' + this.translate('of') + ' ' + this.maximum; if(!this.disableStatusString){ // Display format: "preStatusString : progress of maximum" this.progressText.style.display = ""; if(this.preStatusString!=""){ this.progressText.innerHTML = this.preStatusString + ": "; } else { this.progressText.innerHTML = ""; } this.progressText.innerHTML += this.progress + ' / ' + this.maximum; } else { this.progressText.style.display = "none"; } } });