/******************************************************************************* * IBM Confidential * * OCO Source Materials * * A and PM: PD * * (c) Copyright IBM Corp. 2014 * * The source code for this program is not published or otherwise divested of * its trade secrets, irrespective of what has been deposited with the U.S. * Copyright Office. ******************************************************************************/ define([ "dojo/_base/declare", "dijit/ProgressBar", "dojo/number", "dojo/dom-style" ],function(declare, ProgressBar, number, domStyle){ var PROGRESS_INFINITY = "Infinity"; var UPLOAD_TYPE_HTML5 = "html5"; var UPLOAD_TYPE_FLASH = "flash"; var ProgressBar = declare("pd/widgets/ProgressBar", [ProgressBar], { maxBytesPerLoad: 0, previousBytesLoaded: 0, init: function(/*string*/uploadType) { this.uploadType = uploadType; this.pdHide(); this.update({ progress: 0 }); }, pdHide: function() { domStyle.set(this.domNode, "display", "none"); }, _pdShow: function() { domStyle.set(this.domNode, "display", ""); }, _isDeterminate: function (){ if (this._getDeterminateMode() && this._supportDeterminate()){ return true; } return false; }, //in case of iframe, you need enforce to indeterminate mode. _setDeterminateMode: function (/*boolean*/ val){ this.indeterminate = !val; if (!val){ this.value = PROGRESS_INFINITY; } }, _getDeterminateMode: function (){ return !this.indeterminate; }, _supportDeterminate: function() { return (this.uploadType == UPLOAD_TYPE_HTML5 || this.uploadType == UPLOAD_TYPE_FLASH); }, onStageZero: function(){ this._pdShow(); this._setDeterminateMode(this._supportDeterminate()); this.maxBytesPerLoad = 0; this.previousBytesLoaded = 0; this.update({ stage: 0, label: PDMSG.IPT.IDS_IPT_PROGRESS_STAGE_IMPORT }); }, onStageOne: function(percent) { this._pdShow(); this.update({ stage: 1, label: PDMSG.IPT.IDS_IPT_PROGRESS_STAGE_UPLOAD, progress: percent }); }, onStageTwo: function(inputLabel) { var currentLabel = inputLabel || PDMSG.IPT.IDS_IPT_PROGRESS_STAGE_IMPORT; this._pdShow(); this._setDeterminateMode(false); this.update({ stage: 2, label: currentLabel, progress: 100 }); }, onStageThree: function() { this._setDeterminateMode(true); this.update({ stage: 3, progress: 100, label: "" }); var self = this; setTimeout(function() { self.pdHide(); self.update({ progress: 0 }); }, 1000); }, onCancel: function() { this.pdHide(); this.update({ progress: 0 }); }, report: function(/*float*/percent){ var returnVal = this.label || " "; //stage 0 or 3 (0% and 100%) will be showed in derterminate mode anyways if (this._isDeterminate() || (this.stage == undefined || this.stage == 3)){ returnVal +=" " + number.format(percent, { type: "percent", places: this.places, locale: this.lang }); } return returnVal; } }); return ProgressBar; });