diff --git a/media/js/base.js b/media/js/base.js index d732ab6e91..5929939226 100644 --- a/media/js/base.js +++ b/media/js/base.js @@ -761,3 +761,31 @@ function userInputOPtionsForSelect2(user_search_url) { escapeMarkup: function(m) { return m; } }; } + +function quotaSizeFormat(bytes, precision) { + var kilobyte = 1000; + var megabyte = kilobyte * 1000; + var gigabyte = megabyte * 1000; + var terabyte = gigabyte * 1000; + + var precision = precision || 0; + + if ((bytes >= 0) && (bytes < kilobyte)) { + return bytes + ' B'; + + } else if ((bytes >= kilobyte) && (bytes < megabyte)) { + return (bytes / kilobyte).toFixed(precision) + ' KB'; + + } else if ((bytes >= megabyte) && (bytes < gigabyte)) { + return (bytes / megabyte).toFixed(precision) + ' MB'; + + } else if ((bytes >= gigabyte) && (bytes < terabyte)) { + return (bytes / gigabyte).toFixed(precision) + ' GB'; + + } else if (bytes >= terabyte) { + return (bytes / terabyte).toFixed(precision) + ' TB'; + + } else { + return bytes + ' B'; + } +} diff --git a/seahub/templates/sysadmin/useradmin_js.html b/seahub/templates/sysadmin/useradmin_js.html index 871a2d826c..d146ab68cb 100644 --- a/seahub/templates/sysadmin/useradmin_js.html +++ b/seahub/templates/sysadmin/useradmin_js.html @@ -114,7 +114,7 @@ $('#set-quota-form').submit(function() { if (space_quota == 0) { $spaceQuota.html('--'); } else { - $spaceQuota.html(parseInt(data['total'])/1000000 + ' MB'); + $spaceQuota.html(quotaSizeFormat(parseInt(data['total']), 1)); } $.modal.close(); }, diff --git a/seahub/templates/sysadmin/userinfo.html b/seahub/templates/sysadmin/userinfo.html index 2bdcb84b77..5d9f5fe63b 100644 --- a/seahub/templates/sysadmin/userinfo.html +++ b/seahub/templates/sysadmin/userinfo.html @@ -410,7 +410,7 @@ $('#set-quota-form').submit(function() { if (space_quota == 0) { $quota.html('--'); } else { - $quota.html(parseInt(data['total'])/1000000 + ' MB'); + $quota.html(quotaSizeFormat(parseInt(data['total']), 1)); } $.modal.close(); },