From f88f58a247ac263dc0178d8c515e471ffadc197b Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 6 Sep 2016 14:28:44 -0400 Subject: slugify --- themes/okadmin/public/js/okcms.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/themes/okadmin/public/js/okcms.js b/themes/okadmin/public/js/okcms.js index 5a91a13..fe0ed69 100644 --- a/themes/okadmin/public/js/okcms.js +++ b/themes/okadmin/public/js/okcms.js @@ -156,6 +156,12 @@ var OKCMS = (function(){ OKCMS.prototype.save = function(type, data){ } OKCMS.prototype.create = function(type, data){ + if (! data.title) { + throw new Error ("Title field is empty") + } + if (! data.id) { + data.id = slugify( data.title ) + } } OKCMS.prototype.update = function(type, data){ var id = data.id @@ -163,4 +169,8 @@ var OKCMS = (function(){ OKCMS.prototype.destroy = function(type, id){ } + function slugify (s){ + return (s || "").toLowerCase().replace(/\s/g,"-").replace(/[^-_a-zA-Z0-9]/g, '-').replace(/-+/g, "-") + } + })() \ No newline at end of file -- cgit v1.2.3-70-g09d2