make field names in the generic detail view look nice
authorScott Baker <smbaker@gmail.com>
Mon, 8 Dec 2014 06:31:18 +0000 (22:31 -0800)
committerScott Baker <smbaker@gmail.com>
Mon, 8 Dec 2014 06:31:18 +0000 (22:31 -0800)
planetstack/core/xoslib/static/js/xoslib/xos-util.js
planetstack/core/xoslib/templates/xosAdmin.html

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);
index c2bf202..8957e03 100644 (file)
   <form>
   <table>\r
   <% _.each(addFields, function(fieldName) { %>\r
-     <tr><td><%= fieldName %>\r
+     <tr><td><%= fieldNameToHumanReadable(fieldName) %>:</td>\r
         <% if (fieldName in foreignFields) { %>\r
             <td><%= idToSelect(fieldName, window[fieldName], foreignFields[fieldName], "humanReadableName") %></td>\r
         <% } else if (inputType[fieldName] == "checkbox") { %>\r
   <form>
   <table>\r
   <% console.log(model); _.each(detailFields, function(fieldName) { %>\r
-     <tr><td><%= fieldName %>\r
+     <tr><td><%= fieldNameToHumanReadable(fieldName) %>:</td>\r
         <% if (fieldName in foreignFields) { %>\r
             <td><%= idToSelect(fieldName, window[fieldName], foreignFields[fieldName], "humanReadableName") %></td>\r
         <% } else if (inputType[fieldName] == "checkbox") { %>\r