1 /* 2 * ***** BEGIN LICENSE BLOCK ***** 3 * Zimbra Collaboration Suite Web Client 4 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. 5 * 6 * The contents of this file are subject to the Common Public Attribution License Version 1.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at: https://www.zimbra.com/license 9 * The License is based on the Mozilla Public License Version 1.1 but Sections 14 and 15 10 * have been added to cover use of software over a computer network and provide for limited attribution 11 * for the Original Developer. In addition, Exhibit A has been modified to be consistent with Exhibit B. 12 * 13 * Software distributed under the License is distributed on an "AS IS" basis, 14 * WITHOUT WARRANTY OF ANY KIND, either express or implied. 15 * See the License for the specific language governing rights and limitations under the License. 16 * The Original Code is Zimbra Open Source Web Client. 17 * The Initial Developer of the Original Code is Zimbra, Inc. All rights to the Original Code were 18 * transferred by Zimbra, Inc. to Synacor, Inc. on September 14, 2015. 19 * 20 * All portions of the code are Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2013, 2014, 2016 Synacor, Inc. All Rights Reserved. 21 * ***** END LICENSE BLOCK ***** 22 */ 23 24 25 /** 26 * Creates a progress bar. 27 * @constructor 28 * @class 29 * This class represents a progress bar. 30 * 31 * @param {DwtComposite} parent the parent container 32 * @param {string} className the CSS class name 33 * @param {constant} posStyle the position style (see {@link DwtControl}) 34 * 35 * @author Greg Solovyev 36 * 37 * @extends DwtComposite 38 */ 39 DwtProgressBar = function(parent, className, posStyle) { 40 if (arguments.length == 0) return; 41 posStyle = posStyle || DwtControl.STATIC_STYLE; 42 DwtComposite.call(this, {parent:parent, posStyle:posStyle}); 43 this._maxValue = 100; 44 this._value = 0; 45 this._quotabarDiv = null; 46 this._quotausedDiv = null; 47 48 this._progressBgColor = null;// "#66cc33"; // MOW: removing this so the color can be skinned 49 // set the color in the class "quotaused" 50 this._progressCssClass = "quotaused"; 51 52 this._wholeBgColor = null; 53 this._wholeCssClass = "quotabar"; 54 this._createHTML(); 55 } 56 57 DwtProgressBar.prototype = new DwtComposite; 58 DwtProgressBar.prototype.constructor = DwtProgressBar; 59 60 61 // 62 // Public methods 63 // 64 65 /** 66 * Sets the progress background color. 67 * 68 * @param {string} var the color 69 */ 70 DwtProgressBar.prototype.setProgressBgColor = 71 function(val) { 72 this._progressBgColor = val; 73 } 74 75 /** 76 * Sets the whole background color. 77 * 78 * @param {string} var the color 79 */ 80 DwtProgressBar.prototype.setWholeBgColor = 81 function(val) { 82 this._wholeBgColor = val; 83 } 84 85 /** 86 * Sets the progress CSS class. 87 * 88 * @param {string} var the color 89 */ 90 DwtProgressBar.prototype.setProgressCssClass = 91 function(val) { 92 this._progressCssClass = val; 93 } 94 95 /** 96 * Sets the whole CSS class. 97 * 98 * @param {string} var the color 99 */ 100 DwtProgressBar.prototype.setWholeCssClass = 101 function(val) { 102 this._wholeCssClass = val; 103 } 104 105 /** 106 * Sets the process CSS style. 107 * 108 * @param {string} var the color 109 */ 110 DwtProgressBar.prototype.setProgressCssStyle = 111 function(val) { 112 this._progressCssStyle = val; 113 } 114 115 /** 116 * Sets the while CSS style. 117 * 118 * @param {string} var the color 119 */ 120 DwtProgressBar.prototype.setWholeCssStyle = 121 function(val) { 122 this._wholeCssStyle = val; 123 } 124 125 /** 126 * Sets the progress value. 127 * 128 * @param {number} val the value 129 */ 130 DwtProgressBar.prototype.setValue = 131 function(val) { 132 this._value = parseInt(val); 133 var percent; 134 135 if(this._value == this._maxValue) 136 percent = 100; 137 else 138 percent = Math.min(Math.round((this._value / this._maxValue) * 100), 100); 139 140 if(isNaN(percent)) 141 percent = "0"; 142 143 if(!this._quotabarDiv) { 144 this._quotabarDiv = document.createElement("div") 145 if(this._wholeCssClass) 146 this._quotabarDiv.className = this._wholeCssClass; 147 148 if(this._wholeBgColor) 149 this._quotabarDiv.backgroundColor = this._wholeBgColor; 150 151 this._cell.appendChild(this._quotabarDiv); 152 } 153 if(!this._quotausedDiv) { 154 this._quotausedDiv = document.createElement("div") 155 if(this._progressCssClass) 156 this._quotausedDiv.className = this._progressCssClass; 157 158 if(this._progressBgColor) 159 this._quotausedDiv.style.backgroundColor = this._progressBgColor; 160 161 this._quotabarDiv.appendChild(this._quotausedDiv); 162 } 163 164 this._quotausedDiv.style.width = percent + "%"; 165 } 166 167 /** 168 * Sets the value by percentage. 169 * 170 * @param {string} percent the value as a percentage (for example: "10%") 171 */ 172 DwtProgressBar.prototype.setValueByPercent = 173 function (percent){ 174 this.setMaxValue(100); 175 this.setValue (percent.replace(/\%/gi, "")); 176 } 177 178 /** 179 * Gets the value. 180 * 181 * @return {number} the value 182 */ 183 DwtProgressBar.prototype.getValue = 184 function() { 185 return this._value; 186 } 187 188 /** 189 * Gets the maximum value. 190 * 191 * @return {number} the maximum value 192 */ 193 DwtProgressBar.prototype.getMaxValue = 194 function() { 195 return this._maxValue; 196 } 197 198 /** 199 * Sets the maximum value. 200 * 201 * @param {number} val the maximum value 202 */ 203 DwtProgressBar.prototype.setMaxValue = 204 function(val) { 205 this._maxValue = parseInt(val); 206 } 207 208 /** 209 * Sets the label. 210 * 211 * @param {string} text the label 212 * @param {boolean} isRightAlign if <code>true</code>, if the label is right aligned 213 */ 214 DwtProgressBar.prototype.setLabel = 215 function( text, isRightAlign) { 216 var labelNode = document.createTextNode(text); 217 var position = isRightAlign ? -1 : 0; 218 var labelCell = this._row.insertCell(position) ; 219 labelCell.appendChild (labelNode); 220 } 221 222 // 223 // Protected methods 224 // 225 226 DwtProgressBar.prototype._createHTML = 227 function() { 228 this._table = document.createElement("table"); 229 this._table.border = this._table.cellpadding = this._table.cellspacing = 0; 230 231 this._row = this._table.insertRow(-1); 232 233 //if(AjxEnv.isLinux) 234 //this._row.style.lineHeight = 13; 235 236 this._cell = this._row.insertCell(-1); 237 238 this.getHtmlElement().appendChild(this._table); 239 } 240