summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--site/index.js4
-rw-r--r--themes/okadmin/public/js/app.js16
-rw-r--r--themes/okadmin/templates/partials/inputs.liquid19
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 %}
- <div class="property {{type}}">
- <label
- {% if spec.hidden %}
- class="hidden"
- {% endif %}
- for="{{name}}">{{name | capitalize}}</label>
+ <div class="property {{type}} {% if spec.hidden %}hidden{% endif %}">
+ <label for="{{name}}">{{name | capitalize}}</label>
{% if type == 'string' %}
<input
- {% if spec.hidden %}
- class="hidden"
- {% endif %}
- name="{{name}}" type="text" value="{{spec.value}}">
+ name="{{name}}" type="text" value="{{spec.value}}">
{% elsif type == 'text' %}
<textarea
- {% if spec.hidden %}
- class="hidden"
- {% endif %}
name="{{name}}">{{spec.value}}</textarea>
{% elsif type == 'enum' %}
<select
- {% if spec.hidden %}
- class="hidden"
- {% endif %}
name="{{name}}">
{% for option in spec.options %}
<option value="{{option}}" {% if option == spec.value %}selected{% endif %}>{{option | capitalize}}</option>