From c3b41519bfa5150afee1e77758b43824ea8c5539 Mon Sep 17 00:00:00 2001 From: p3k Date: Tue, 25 Jun 2002 14:04:29 +0000 Subject: [PATCH] moved format functions from macros.js to functions.js (where they belong to, imho) --- Global/functions.js | 74 ++++++++++++++++++++++++++++++++++++++++++ Global/macros.js | 79 --------------------------------------------- 2 files changed, 74 insertions(+), 79 deletions(-) diff --git a/Global/functions.js b/Global/functions.js index 04d5ce1a..dc4939f9 100644 --- a/Global/functions.js +++ b/Global/functions.js @@ -228,3 +228,77 @@ function createAuth() { } +/** + * macro-utility: formatting property lists + */ +function formatProperties(props,par) { + var prefix = (par && par.prefix) ? par.prefix : ""; + var suffix = (par && par.suffix) ? par.suffix : ""; + var separator = (par && par.separator) ? par.separator : ""; + if ( props.size()==0 ) + return ""; + var e = props.keys(); + var arr = new Array(); + while ( e.hasMoreElements() ) { + arr[arr.length] = e.nextElement(); + } + arr.sort(sortProps); + for ( var i in arr ) { + // don't print the admin-password + if ( arr[i].toLowerCase()=="adminusername" || arr[i].toLowerCase()=="adminpassword" ) continue; + res.write ( prefix + arr[i] + separator + props.getProperty(arr[i]) + suffix ); + } +} + + +/** + * macro-utility: formatting an integer value as human readable bytes + */ +function formatBytes(bytes) { + if ( bytes > Math.pow(2,30) ) { + res.write( Math.round( 100*bytes/Math.pow(2,30) ) / 100 + "gb" ); + } else if ( bytes > Math.pow(2,20) ) { + res.write( Math.round( 100*bytes/Math.pow(2,20) ) / 100 + "mb" ); + } else { + res.write( Math.round( 100*bytes/Math.pow(2,10) ) / 100 + "kb" ); + } +} + + +/** + * macro-utility: formatting time in millis as human readable age + */ +function formatAge(age) { + var str = ""; + var days = Math.floor(age/86400); + var age = age - days * 86400; + var hours = Math.floor(age / 3600); + var age = age - hours * 3600; + var minutes = Math.floor(age / 60); + var seconds = Math.floor(age - minutes * 60); + if (days > 0) + str += (days + " days, "); + if (hours>0) + str += (hours + "h, "); + str += (minutes + "min"); + if (days == 0) str += (", " + seconds + "sec"); + return(str); +} + + +/** + * macro-utility: formatting a number-suffix by choosing between singular and plural + * @arg value number to be formatted + * @arg param-object object to get fields + * @param singular string used for value==1 + * @param plural string used for value!=1 + */ +function formatCount(ct, par) { + if ( !par || !par.singular || !par.plural ) { + return ""; + } + if ( ct==1 ) + return par.singular; + else + return par.plural; +} diff --git a/Global/macros.js b/Global/macros.js index ace6eaae..13408e7a 100644 --- a/Global/macros.js +++ b/Global/macros.js @@ -16,82 +16,3 @@ function now_macro() { var date = new Date(); return(date.format("dd.MM.yyyy, HH:mm'h' zzz")); } - - -/** - * macro-utility: formatting property lists - */ -function formatProperties(props,par) { - var prefix = (par && par.prefix) ? par.prefix : ""; - var suffix = (par && par.suffix) ? par.suffix : ""; - var separator = (par && par.separator) ? par.separator : ""; - if ( props.size()==0 ) - return ""; - var e = props.keys(); - var arr = new Array(); - while ( e.hasMoreElements() ) { - arr[arr.length] = e.nextElement(); - } - arr.sort(sortProps); - for ( var i in arr ) { - // don't print the admin-password - if ( arr[i].toLowerCase()=="adminusername" || arr[i].toLowerCase()=="adminpassword" ) continue; - res.write ( prefix + arr[i] + separator + props.getProperty(arr[i]) + suffix ); - } -} - - -/** - * macro-utility: formatting an integer value as human readable bytes - */ -function formatBytes(bytes) { - if ( bytes > Math.pow(2,30) ) { - res.write( Math.round( 100*bytes/Math.pow(2,30) ) / 100 + "gb" ); - } else if ( bytes > Math.pow(2,20) ) { - res.write( Math.round( 100*bytes/Math.pow(2,20) ) / 100 + "mb" ); - } else { - res.write( Math.round( 100*bytes/Math.pow(2,10) ) / 100 + "kb" ); - } -} - - -/** - * macro-utility: formatting time in millis as human readable age - */ -function formatAge(age) { - var str = ""; - var days = Math.floor(age/86400); - var age = age - days * 86400; - var hours = Math.floor(age / 3600); - var age = age - hours * 3600; - var minutes = Math.floor(age / 60); - var seconds = Math.floor(age - minutes * 60); - if (days > 0) - str += (days + " days, "); - if (hours>0) - str += (hours + "h, "); - str += (minutes + "min"); - if (days == 0) str += (", " + seconds + "sec"); - return(str); -} - - -/** - * macro-utility: formatting a number-suffix by choosing between singular and plural - * @arg value number to be formatted - * @arg param-object object to get fields - * @param singular string used for value==1 - * @param plural string used for value!=1 - */ -function formatCount(ct, par) { - if ( !par || !par.singular || !par.plural ) { - return ""; - } - if ( ct==1 ) - return par.singular; - else - return par.plural; -} - - -