From d45f617dc74a07beb352d04537d47a77193f487f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 13 Apr 2015 18:19:41 -0400 Subject: hide id field --- site/index.js | 4 ++-- themes/okadmin/public/js/app.js | 16 ++++++++++++---- themes/okadmin/templates/partials/inputs.liquid | 19 +++---------------- 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/site/index.js b/site/index.js index 8eec697..d4f5cb4 100644 --- a/site/index.js +++ b/site/index.js @@ -1,7 +1,7 @@ var okcms = require('..'); var projectSchema = { - id: {type: 'string', id: true}, + id: {type: 'string', id: true, hidden: true}, title: {type: 'string'}, shortname: {type: 'string'}, description: {type: 'text'}, @@ -15,7 +15,7 @@ var app = okcms.createApp({ schemas: { page: { - id: {type: 'string'}, + id: {type: 'string', hidden: true}, title: {type: 'string'}, body: {type: 'text'}, image: {type: 'string'} diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 91a8e1a..009fe4c 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -51,13 +51,18 @@ var OKAdmin = function(){ // fix post indexing in list-driven inputs $(".main.resource form").submit(function(e){ - var $id = $("[name=id]") - if ($id.length && ! $id.val()) { - alert("Please enter an ID") - $id.focus() + var $id = $("[name=id]"), $title = $("[name=title]") + + if ($title.length && ! $title.val()) { + alert("Please enter a title") + $title.focus() e.preventDefault() return } + + var slug = slugify( $title.val() ) + $id.val( slug ) + $(".image-element").each(function(index){ $(this).find("input,textarea").each(function(){ var field = $(this).attr("name").replace(/\[[0-9]*\]/, "[" + index + "]") @@ -129,3 +134,6 @@ var OKAdmin = function(){ $(function(){ window.app = new OKAdmin () }) + + +function slugify (s){ return (s || "").toLowerCase().replace(/\s/g,"-").replace(/[^-_a-zA-Z0-9]/g, '-').replace(/-+/g,"-") } diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 4d6372d..253b275 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -3,30 +3,17 @@ {% assign spec = pair[1] %} {% assign type = spec.type %} -
- +
+ {% if type == 'string' %} + name="{{name}}" type="text" value="{{spec.value}}"> {% elsif type == 'text' %} {% elsif type == 'enum' %}