diff options
Diffstat (limited to 'themes')
| -rw-r--r-- | themes/okadmin/public/js/okcms.js | 10 |
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 |
