diff options
| author | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-10 22:34:39 -0400 |
|---|---|---|
| committer | Sean Fridman <fridman@mail.sfsu.edu> | 2015-04-11 01:38:38 -0400 |
| commit | 3f346a970dd0823816a5ad2b0dc2b7749e99845c (patch) | |
| tree | 1077082d2ce540ea44b766391f90816679d93086 | |
| parent | 6e1f689cfd8f820090c4ab15519114f4d3bf929f (diff) | |
Hide certain inputs in template
| -rw-r--r-- | app/node_modules/okadminview/index.js | 19 | ||||
| -rw-r--r-- | themes/okadmin/public/css/main.css | 4 | ||||
| -rw-r--r-- | themes/okadmin/templates/partials/inputs.liquid | 20 |
3 files changed, 27 insertions, 16 deletions
diff --git a/app/node_modules/okadminview/index.js b/app/node_modules/okadminview/index.js index 1668900..884c4b8 100644 --- a/app/node_modules/okadminview/index.js +++ b/app/node_modules/okadminview/index.js @@ -116,15 +116,11 @@ function OKAdminView(options) { errorHandler(req, res)(new Error('No such resource ' + type)); } else { meta.get().then(function(metadata) { - view.renderResourceNew(req, res, { + var templateData = getResourceTemplateData(metadata, resource, {}); + view.renderResourceNew(req, res, assign(templateData, { success: req.flash('success'), errors: req.flash('errors'), - meta: metadata, - resource: { - type: resource.type, - spec: resource.spec - } - }); + })); }).fail(errorHandler(req, res)); } }); @@ -228,10 +224,15 @@ function getResourceTemplateData(meta, resource, data) { meta = meta || {}; resource = resource || {}; data = data || {}; - // Decorate spec with actual resource values var spec = Object.keys(resource.spec).reduce(function(cache, prop) { var value = data[prop]; - cache[prop].value = value; + var propSpec = cache[prop]; + // Decorate spec with actual resource values + propSpec.value = value; + // Some fields should not be shown to the user + if (propSpec.type === 'meta' || propSpec.static) { + propSpec.hidden = true; + } return cache; }, resource.spec); return { diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index ad940e8..73f9735 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -278,3 +278,7 @@ li.image-element .remove-image:hover { .clear { clear: both; } + +.hidden { + display: none; +} diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 7cede76..99258f3 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -4,24 +4,28 @@ {% assign type = spec.type %} <div class="property {{type}}"> - <label for="{{name}}">{{name | capitalize}}</label> + <label + {% if spec.hidden %} + class="hidden" + {% endif %} + for="{{name}}">{{name | capitalize}}</label> {% if type == 'string' %} <input - {% if spec.disabled %} - disabled="true" + {% if spec.hidden %} + class="hidden" {% endif %} name="{{name}}" type="text" value="{{spec.value}}"> {% elsif type == 'text' %} <textarea - {% if spec.disabled %} - disabled="true" + {% if spec.hidden %} + class="hidden" {% endif %} name="{{name}}">{{spec.value}}</textarea> {% elsif type == 'enum' %} <select - {% if spec.disabled %} - disabled="true" + {% if spec.hidden %} + class="hidden" {% endif %} name="{{name}}"> {% for option in spec.options %} @@ -64,6 +68,8 @@ </li> </script> </div> + {% elsif type == 'meta' %} + <input class="hidden" type="hidden" name="{{name}}" value="{{spec.value}}"> {% else %} <p><pre style="color: red">Admin template doesn't support '{{type}}' properties!</pre></p> {% endif %} |
