From 669d6aec9f812e4151bffbaa4f8830cf5764ee1e Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Thu, 9 Apr 2015 20:05:14 -0400 Subject: Set inital array indices in templates --- themes/okadmin/public/js/app.js | 2 +- themes/okadmin/templates/partials/inputs.liquid | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'themes') diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 441172f..4d13bb2 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -53,7 +53,7 @@ var OKAdmin = function(){ $("form").submit(function(){ $(".image-element").each(function(index){ $(this).find("input,textarea").each(function(){ - var field = $(this).attr("name").replace(/\[\]/, "[" + index + "]") + var field = $(this).attr("name").replace(/\[[0-9]*\]/, "[" + index + "]") $(this).attr("name", field) }) }) diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 7d23c9e..7cede76 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -43,8 +43,8 @@
    {% for image in spec.value %}
  1. - - + + {{image.caption}}
  2. -- 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') 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' %}
diff --git a/themes/okadmin/templates/resource.liquid b/themes/okadmin/templates/resource.liquid index 53cd83e..8078778 100644 --- a/themes/okadmin/templates/resource.liquid +++ b/themes/okadmin/templates/resource.liquid @@ -2,7 +2,7 @@ {% include 'partials/flash' %} -