luci-base: cbi.js: string formatting fixes

* Fix left and right justify/padding in formats
* Do not emit decimal numbers for small values in %m format

Signed-off-by: Jo-Philipp Wich <jow@openwrt.org>
This commit is contained in:
Jo-Philipp Wich 2016-02-15 12:45:39 +01:00
parent 5cfad4338f
commit a860de860a

View file

@ -1332,6 +1332,8 @@ String.prototype.format = function()
pad = leftpart.substr(1,1);
else if (pPad)
pad = pPad;
else
pad = ' ';
var justifyRight = true;
if (pJustify && pJustify === "-")
@ -1437,12 +1439,22 @@ String.prototype.format = function()
for (i = 0; (i < units.length) && (val > mf); i++)
val /= mf;
subst = val.toFixed(pr) + ' ' + units[i];
subst = (i ? val.toFixed(pr) : val) + units[i];
pMinLength = null;
break;
}
}
}
if (pMinLength) {
subst = subst.toString();
for (var i = subst.length; i < pMinLength; i++)
if (pJustify == '-')
subst = subst + ' ';
else
subst = pad + subst;
}
out += leftpart + subst;
str = str.substr(m.length);
}