From 50fac2191fbf0dd101d6071242c03dfad295b3ed Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 8 Sep 2016 19:59:41 -0400 Subject: makin okcms okadminview frontend lib work --- themes/okadmin/public/js/okcms.js | 28 ++++++++----- themes/okcards/public/css/main.css | 0 themes/okcards/public/js/app.js | 15 +++++++ themes/okcards/templates/404.liquid | 54 ++++++++++++++++++++++++++ themes/okcards/templates/5xx.liquid | 54 ++++++++++++++++++++++++++ themes/okcards/templates/index.liquid | 6 +++ themes/okcards/templates/partials/app.liquid | 8 ++++ themes/okcards/templates/partials/flash.liquid | 20 ++++++++++ themes/okcards/templates/partials/head.liquid | 13 +++++++ themes/okcards/templates/partials/tail.liquid | 9 +++++ themes/okcards/templates/resource.liquid | 6 +++ themes/okcards/templates/resource_new.liquid | 6 +++ 12 files changed, 209 insertions(+), 10 deletions(-) create mode 100644 themes/okcards/public/css/main.css create mode 100644 themes/okcards/public/js/app.js create mode 100644 themes/okcards/templates/404.liquid create mode 100644 themes/okcards/templates/5xx.liquid create mode 100644 themes/okcards/templates/index.liquid create mode 100644 themes/okcards/templates/partials/app.liquid create mode 100644 themes/okcards/templates/partials/flash.liquid create mode 100644 themes/okcards/templates/partials/head.liquid create mode 100644 themes/okcards/templates/partials/tail.liquid create mode 100644 themes/okcards/templates/resource.liquid create mode 100644 themes/okcards/templates/resource_new.liquid (limited to 'themes') diff --git a/themes/okadmin/public/js/okcms.js b/themes/okadmin/public/js/okcms.js index 69a8f86..c53092f 100644 --- a/themes/okadmin/public/js/okcms.js +++ b/themes/okadmin/public/js/okcms.js @@ -28,15 +28,17 @@ var OKCMS = (function(){ // data.resources[types].data[] // data.resources[types].data[0][groupBy][group] var resources = this.resources = {} - this.types = Object.keys(data.resources) - this.types.forEach(function(type){ + var plural_types = Object.keys(data.resources) + var types = this.types = [] + plural_types.forEach(function(type){ var resource = data.resources[type] resources[resource.type] = resource resource.lookup = {} + resource.index = [] + types.push( resource.type ) if (resource.groupBy) { var group_lookup = resource.data[0][resource.groupBy] var groups = Object.keys(group_lookup) - resource.index = [] groups.forEach(function(group){ var list = group_lookup[group] list.forEach(function(record){ @@ -48,6 +50,7 @@ var OKCMS = (function(){ else { resource.data.forEach(function(record){ resource.lookup[record.id] = record + resource.index.push(record) }) } }) @@ -79,13 +82,13 @@ var OKCMS = (function(){ } OKCMS.prototype.get = function(type, id){ var resource = this.getResource(type) - if (id in resource.index) { - return resource.index[id] + if (id in resource.lookup) { + return resource.lookup[id] } throw new Error ("Key not found: " + type + ":" + id) } OKCMS.prototype.new = function(type){ - var resource = this.resource(type) + var resource = this.getResource(type) var spec = this.spec(type) var record = {} Object.keys(spec).forEach(function(key){ @@ -170,8 +173,9 @@ var OKCMS = (function(){ data.id = slugify( data.title ) } $.ajax({ - url: [ "", adminRoot, type ].join("/"), + url: [ "", adminRoot, type, "" ].join("/"), type: "POST", + data: data, success: function(){ cb && cb() } @@ -180,20 +184,24 @@ var OKCMS = (function(){ OKCMS.prototype.update = function(type, data, cb){ var resource = this.getResource(type) var id = data.id - + console.log(id, [ "", adminRoot, type, id ].join("/") ) // /admin/:type/:id/ $.ajax({ - url: [ "", adminRoot, type, id ].join("/"), + url: [ "", adminRoot, type, id, "" ].join("/"), type: "PUT", data: data, success: function(){ + console.log(" OK" ) cb && cb() } }) } OKCMS.prototype.destroy = function(type, id, cb){ + if (typeof id == "object") { + id = id.id + } $.ajax({ - url: [ "", adminRoot, type, id ].join("/"), + url: [ "", adminRoot, type, id, "" ].join("/"), type: "DELETE", success: function(){ cb && cb() diff --git a/themes/okcards/public/css/main.css b/themes/okcards/public/css/main.css new file mode 100644 index 0000000..e69de29 diff --git a/themes/okcards/public/js/app.js b/themes/okcards/public/js/app.js new file mode 100644 index 0000000..1e710e9 --- /dev/null +++ b/themes/okcards/public/js/app.js @@ -0,0 +1,15 @@ +var app = (function(){ + var app = {} + var cms + + app.init = function(){ + cms = app.cms = new OKCMS ({ ready: app.ready }) + } + app.ready = function(){ + console.log ("READY") + } + + return app +})() + +window.addEventListener("DOMContentLoaded", app.init) \ No newline at end of file diff --git a/themes/okcards/templates/404.liquid b/themes/okcards/templates/404.liquid new file mode 100644 index 0000000..87f5342 --- /dev/null +++ b/themes/okcards/templates/404.liquid @@ -0,0 +1,54 @@ + + + + 404 + + + +
+

¯\_(ツ)_/¯

+

We couldn't find that page.

+

Sure you have the right URL?

+ Back +
+ + diff --git a/themes/okcards/templates/5xx.liquid b/themes/okcards/templates/5xx.liquid new file mode 100644 index 0000000..f245545 --- /dev/null +++ b/themes/okcards/templates/5xx.liquid @@ -0,0 +1,54 @@ + + + + 404 + + + +
+

(;一_一)

+

Looks like we experienced an error.

+

Sorry about that. Maybe try again later.

+ Back +
+ + diff --git a/themes/okcards/templates/index.liquid b/themes/okcards/templates/index.liquid new file mode 100644 index 0000000..7dee4be --- /dev/null +++ b/themes/okcards/templates/index.liquid @@ -0,0 +1,6 @@ +{% include 'partials/head' %} + +{% include 'partials/flash' %} +{% include 'partials/app' %} + +{% include 'partials/tail' %} diff --git a/themes/okcards/templates/partials/app.liquid b/themes/okcards/templates/partials/app.liquid new file mode 100644 index 0000000..46c19e4 --- /dev/null +++ b/themes/okcards/templates/partials/app.liquid @@ -0,0 +1,8 @@ + + + + +
+
\ No newline at end of file diff --git a/themes/okcards/templates/partials/flash.liquid b/themes/okcards/templates/partials/flash.liquid new file mode 100644 index 0000000..e51a86b --- /dev/null +++ b/themes/okcards/templates/partials/flash.liquid @@ -0,0 +1,20 @@ +{% if success.length > 0 %} +
+
Changes saved.
+ +
+{% endif %} + +{% if errors.length > 0 %} +
+ {% for error in errors %} +
+
{{error.message}}
+
+ {% endfor %} +
+{% endif %} \ No newline at end of file diff --git a/themes/okcards/templates/partials/head.liquid b/themes/okcards/templates/partials/head.liquid new file mode 100644 index 0000000..e9c27dc --- /dev/null +++ b/themes/okcards/templates/partials/head.liquid @@ -0,0 +1,13 @@ + + + + + {{meta.project}} Admin + + + +
+ {{meta.project}} Admin + View Site +
+
\ No newline at end of file diff --git a/themes/okcards/templates/partials/tail.liquid b/themes/okcards/templates/partials/tail.liquid new file mode 100644 index 0000000..7727d69 --- /dev/null +++ b/themes/okcards/templates/partials/tail.liquid @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/themes/okcards/templates/resource.liquid b/themes/okcards/templates/resource.liquid new file mode 100644 index 0000000..7dee4be --- /dev/null +++ b/themes/okcards/templates/resource.liquid @@ -0,0 +1,6 @@ +{% include 'partials/head' %} + +{% include 'partials/flash' %} +{% include 'partials/app' %} + +{% include 'partials/tail' %} diff --git a/themes/okcards/templates/resource_new.liquid b/themes/okcards/templates/resource_new.liquid new file mode 100644 index 0000000..7dee4be --- /dev/null +++ b/themes/okcards/templates/resource_new.liquid @@ -0,0 +1,6 @@ +{% include 'partials/head' %} + +{% include 'partials/flash' %} +{% include 'partials/app' %} + +{% include 'partials/tail' %} -- cgit v1.2.3-70-g09d2