From: Scott Baker Date: Mon, 8 Dec 2014 06:31:18 +0000 (-0800) Subject: make field names in the generic detail view look nice X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=eec2cbc90cc33171609a951fdbe4a67d515e1fb6;p=plstackapi.git make field names in the generic detail view look nice --- diff --git a/planetstack/core/xoslib/static/js/xoslib/xos-util.js b/planetstack/core/xoslib/static/js/xoslib/xos-util.js index c1f736e..638ba9a 100644 --- a/planetstack/core/xoslib/static/js/xoslib/xos-util.js +++ b/planetstack/core/xoslib/static/js/xoslib/xos-util.js @@ -14,6 +14,17 @@ function firstCharUpper(s) { return s.charAt(0).toUpperCase() + s.slice(1); } +function toTitleCase(str) +{ + return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();}); +} + +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); diff --git a/planetstack/core/xoslib/templates/xosAdmin.html b/planetstack/core/xoslib/templates/xosAdmin.html index c2bf202..8957e03 100644 --- a/planetstack/core/xoslib/templates/xosAdmin.html +++ b/planetstack/core/xoslib/templates/xosAdmin.html @@ -105,7 +105,7 @@
<% _.each(addFields, function(fieldName) { %> - <% if (fieldName in foreignFields) { %> <% } else if (inputType[fieldName] == "checkbox") { %> @@ -125,7 +125,7 @@
<%= fieldName %> +
<%= fieldNameToHumanReadable(fieldName) %>:<%= idToSelect(fieldName, window[fieldName], foreignFields[fieldName], "humanReadableName") %>
<% console.log(model); _.each(detailFields, function(fieldName) { %> - <% if (fieldName in foreignFields) { %> <% } else if (inputType[fieldName] == "checkbox") { %>
<%= fieldName %> +
<%= fieldNameToHumanReadable(fieldName) %>:<%= idToSelect(fieldName, window[fieldName], foreignFields[fieldName], "humanReadableName") %>