From c4d8ee7c431b3511bf26da68e952808b51d663c7 Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Thu, 9 Apr 2015 16:00:21 -0400 Subject: Add resource delete functionality to admin --- themes/okadmin/templates/resource.liquid | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'themes/okadmin/templates/resource.liquid') diff --git a/themes/okadmin/templates/resource.liquid b/themes/okadmin/templates/resource.liquid index c0d348d..48e3ef2 100644 --- a/themes/okadmin/templates/resource.liquid +++ b/themes/okadmin/templates/resource.liquid @@ -14,6 +14,10 @@
+
+ + +
{% include 'partials/tail' %} -- cgit v1.2.3-70-g09d2 From 7b7ac014579bafdb16e91a98f995f4fa7f55b4f1 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 9 Apr 2015 17:17:00 -0400 Subject: alert when deleting posts --- site/db.json | 20 ++++++++++++++++++++ themes/okadmin/public/css/main.css | 5 +++++ themes/okadmin/public/js/app.js | 9 +++++++++ themes/okadmin/templates/resource.liquid | 2 +- 4 files changed, 35 insertions(+), 1 deletion(-) (limited to 'themes/okadmin/templates/resource.liquid') diff --git a/site/db.json b/site/db.json index 8107c6d..07085d4 100644 --- a/site/db.json +++ b/site/db.json @@ -28,6 +28,26 @@ "caption": "CURABITUR BLANDIT TEMPUS PORTTITOR 4" } ] + }, + { + "id": "TEST", + "title": "", + "shortname": "", + "description": "", + "video": { + "url": "", + "type": "", + "token": "", + "title": "", + "thumb": "" + }, + "category": "retail", + "images": [ + { + "uri": "https://ltho.s3.amazonaws.com/cb2698ea-9927-4ca9-972b-f227d46d25f3.png", + "caption": "" + } + ] } ], "advertising": [], diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index d2a4418..ad940e8 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -248,10 +248,15 @@ label { li.image-element:hover .remove-image { display: block; } +li.image-element .remove-image:hover { + color: red; +} .remove-image { display: none; } +#delete_form button:hover { color: red } + .template { display: none; } diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 8c85663..441172f 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -59,6 +59,15 @@ var OKAdmin = function(){ }) }) + $("#delete_form").submit(function(e){ + if (confirm("Are you sure you want to delete this record?")) { + return + } + else { + e.preventDefault() + } + }) + function pressEnter(fn){ return function(e){ if (e.keyCode && e.keyCode !== 13) return diff --git a/themes/okadmin/templates/resource.liquid b/themes/okadmin/templates/resource.liquid index 48e3ef2..c321e8a 100644 --- a/themes/okadmin/templates/resource.liquid +++ b/themes/okadmin/templates/resource.liquid @@ -14,7 +14,7 @@
-
+
-- cgit v1.2.3-70-g09d2 From 00fd19b33ead56842daeb6f6a24735a8687f7744 Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Thu, 9 Apr 2015 20:58:32 -0400 Subject: Implement flash messaging for admin success/error stuff --- app/node_modules/okadminview/index.js | 25 +++++++++++++++++++++++-- app/node_modules/okadminview/package.json | 2 ++ themes/okadmin/templates/index.liquid | 2 ++ themes/okadmin/templates/partials/errors.liquid | 10 ---------- themes/okadmin/templates/partials/flash.liquid | 14 ++++++++++++++ themes/okadmin/templates/resource.liquid | 2 +- themes/okadmin/templates/resource_new.liquid | 2 +- 7 files changed, 43 insertions(+), 14 deletions(-) delete mode 100644 themes/okadmin/templates/partials/errors.liquid create mode 100644 themes/okadmin/templates/partials/flash.liquid (limited to 'themes/okadmin/templates/resource.liquid') diff --git a/app/node_modules/okadminview/index.js b/app/node_modules/okadminview/index.js index 05e2251..9e9aacf 100644 --- a/app/node_modules/okadminview/index.js +++ b/app/node_modules/okadminview/index.js @@ -2,6 +2,8 @@ var assign = require('object-assign'); var cloneDeep = require('lodash.clonedeep'); var bodyParser = require('body-parser'); var methodOverride = require('method-override'); +var session = require('express-session'); +var flash = require('connect-flash'); var Q = require('q'); var pluralize = require('pluralize'); var OKQuery = require('okquery'); @@ -75,6 +77,14 @@ function OKAdminView(options) { strict: app.get('strict routing') }); + // Enable basic sessions for flash messages + router.use(session({ + secret: 'okadmin', + resave: false, + saveUninitialized: false + })); + // Enable flash messaging + router.use(flash()); // Parse form data router.use(bodyParser.urlencoded({extended: true})); // HTML forms only support POST and GET methods @@ -91,7 +101,10 @@ function OKAdminView(options) { router.get('/', function readIndex(req, res, next) { fetchIndexTemplateData(meta, indexQueries).then(function(data) { - view.renderIndex(req, res, data); + view.renderIndex(req, res, assign(data, { + success: req.flash('success'), + errors: req.flash('errors') + })); }).fail(errorHandler(req, res)); }); @@ -103,6 +116,8 @@ function OKAdminView(options) { } else { meta.get().then(function(metadata) { view.renderResourceNew(req, res, { + success: req.flash('success'), + errors: req.flash('errors'), meta: metadata, resource: { type: resource.type, @@ -129,7 +144,10 @@ function OKAdminView(options) { if (!data) { resourceMissingHandler(req, res)() } else { - view.renderResource(req, res, data); + view.renderResource(req, res, assign(data, { + success: req.flash('success'), + errors: req.flash('errors') + })); } }).fail(errorHandler(req, res)); } @@ -147,6 +165,7 @@ function OKAdminView(options) { try { resource.assertValid(data); resource.create(data).then(function(created) { + req.flash('success', 'Created ' + type); res.redirect(303, data[resource.idField]); }).fail(errorHandler(req, res)); } catch (errors) { @@ -170,6 +189,7 @@ function OKAdminView(options) { try { resource.assertValid(data); resource.update(id, data).then(function(updated) { + req.flash('success', 'Updated ' + type); res.redirect(303, '../' + updated[resource.idField]); }).fail(errorHandler(req, res)); } catch (errors) { @@ -189,6 +209,7 @@ function OKAdminView(options) { } else { meta.get().then(function(metadata) { resource.destroy(id).then(function() { + req.flash('success', 'Deleted ' + type); res.redirect(303, '../..'); }).fail(errorHandler(req, res)); }).fail(errorHandler(req, res)); diff --git a/app/node_modules/okadminview/package.json b/app/node_modules/okadminview/package.json index c428645..4c6d11c 100644 --- a/app/node_modules/okadminview/package.json +++ b/app/node_modules/okadminview/package.json @@ -10,6 +10,8 @@ "license": "None", "dependencies": { "body-parser": "^1.12.2", + "connect-flash": "^0.1.1", + "express-session": "^1.11.1", "lodash.clonedeep": "^3.0.0", "method-override": "^2.3.2", "object-assign": "^2.0.0", diff --git a/themes/okadmin/templates/index.liquid b/themes/okadmin/templates/index.liquid index 95c64dd..a5b27e5 100644 --- a/themes/okadmin/templates/index.liquid +++ b/themes/okadmin/templates/index.liquid @@ -1,5 +1,7 @@ {% include 'partials/head' %} +{% include 'partials/flash' %} +
{% for pair in resources %} {% assign name = pair[0] %} diff --git a/themes/okadmin/templates/partials/errors.liquid b/themes/okadmin/templates/partials/errors.liquid deleted file mode 100644 index cdb0b25..0000000 --- a/themes/okadmin/templates/partials/errors.liquid +++ /dev/null @@ -1,10 +0,0 @@ -
- {% for error in errors %} -
-
{{error.message}}
-
- Expected {{error.expected}} but got {{error.actual}} -
-
- {% endfor %} -
diff --git a/themes/okadmin/templates/partials/flash.liquid b/themes/okadmin/templates/partials/flash.liquid new file mode 100644 index 0000000..33b621b --- /dev/null +++ b/themes/okadmin/templates/partials/flash.liquid @@ -0,0 +1,14 @@ +{% if success %} +
+ {{success}} +
+{% elsif errors %} +
+ {% for error in errors %} +
+
{{error.message}}
+
+ {% endfor %} +
+{% endif %} + diff --git a/themes/okadmin/templates/resource.liquid b/themes/okadmin/templates/resource.liquid index c321e8a..53cd83e 100644 --- a/themes/okadmin/templates/resource.liquid +++ b/themes/okadmin/templates/resource.liquid @@ -1,6 +1,6 @@ {% include 'partials/head' %} -{% include 'partials/errors' %} +{% include 'partials/flash' %}