summaryrefslogtreecommitdiff
path: root/themes
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2016-09-06 14:28:44 -0400
committerJules Laplace <jules@okfoc.us>2016-09-06 14:28:44 -0400
commitf88f58a247ac263dc0178d8c515e471ffadc197b (patch)
tree4516373f7f52cd5cd7e4b21a736c0396358cf436 /themes
parentbd1b0a856d02f817b80cf9a30fea9b6b85ff24c8 (diff)
slugify
Diffstat (limited to 'themes')
-rw-r--r--themes/okadmin/public/js/okcms.js10
1 files changed, 10 insertions, 0 deletions
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