make field names in the generic detail view look nice
[plstackapi.git] / planetstack / core / xoslib / static / js / xoslib / xos-util.js
index c1f736e..638ba9a 100644 (file)
@@ -14,6 +14,17 @@ function firstCharUpper(s) {
     return s.charAt(0).toUpperCase() + s.slice(1);
 }
 
+function toTitleCase(str)
+{\r
+    return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});\r
+}
+
+function fieldNameToHumanReadable(str)
+{
+    str = str.replace("_", " ");
+    return toTitleCase(str);
+}
+
 // http://stackoverflow.com/questions/2117320/set-maximum-displayed-rows-count-for-html-table
 function limitTableRows(tableSelector, maxRows) {
     var table = $(tableSelector)[0] //document.getElementById(tableId);