Commit 64febc4d authored by Kostas Papadimitriou's avatar Kostas Papadimitriou
Browse files

Improve memory choices display in vm create view

Apply human readable (MB, GB) conversion
parent 00cc8195
......@@ -827,10 +827,14 @@
}
if (this.__added_flavors.ram.indexOf(values.mem) == -1) {
var mem = $(('<li class="option mem value-{0}">' +
var mem_value = parseInt(_.escape(values.mem))*1024*1024;
var displayvalue = synnefo.util.readablizeBytes(mem_value,
0).split(" ");
var mem = $(('<li class="option mem value-{2}">' +
'<span class="value">{0}</span>' +
'<span class="metric">MB</span></li>').format(
_.escape(values.mem))).data('value', values.mem);
'<span class="metric">{1}</span></li>').format(
displayvalue[0], displayvalue[1], values.mem)).data(
'value', values.mem);
this.mems.append(mem);
this.__added_flavors.ram.push(values.mem);
}
......
......@@ -236,10 +236,11 @@
return string.substring(0, len) + append;
}
synnefo.util.readablizeBytes = function(bytes) {
synnefo.util.readablizeBytes = function(bytes, fix) {
if (fix === undefined) { fix = 2; }
var s = ['bytes', 'kb', 'MB', 'GB', 'TB', 'PB'];
var e = Math.floor(Math.log(bytes)/Math.log(1024));
return (bytes/Math.pow(1024, Math.floor(e))).toFixed(2)+" "+s[e];
return (bytes/Math.pow(1024, Math.floor(e))).toFixed(fix)+" "+s[e];
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment