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') 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 c8eab703d468439a5b04dcfdeaf72db3eae4f966 Mon Sep 17 00:00:00 2001 From: Julie Lala Date: Thu, 9 Apr 2015 16:46:10 -0400 Subject: css and stuff --- install.sh | 2 +- themes/okadmin/public/css/main.css | 3 +++ themes/okadmin/public/js/app.js | 25 +++++++++++++++++-------- themes/okadmin/public/js/upload.js | 3 +-- themes/okadmin/templates/partials/head.liquid | 4 ++-- 5 files changed, 24 insertions(+), 13 deletions(-) (limited to 'themes') diff --git a/install.sh b/install.sh index e0a43c4..15893aa 100755 --- a/install.sh +++ b/install.sh @@ -1,5 +1,5 @@ cd app/node_modules ; for i in * ; do cd $i ; npm install; cd .. ; done ; cd ../.. npm install -cd examples +cd site node index diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index a1e20a0..a01a85c 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -46,6 +46,9 @@ a:visited { color: rgba(0, 0, 0, 0.25); line-height: 50px; } +.admin-header .breadcrumb b { + color: #333; +} .admin-header .site-link { float: right; diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 4b8d98f..170b2ab 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -1,10 +1,20 @@ var OKAdmin = function(){ - OKUpload.bind() + // initialize our (single) ajax image uploader with an element and a template + OKUpload.bind( document.getElementById("file") ) OKUpload.add = function(data){ var url = data[0].extra.Location add_image(url) } + + // also handle straight image urls + $("#add-image-url").keydown(pressEnter(function(e){ + var url = $(this).val() + $(this).val("") + add_image(url) + })}) + + // clone and populate template function add_image(url){ var imageTemplate = $("#captioned-image-template").html() var $el = $(imageTemplate) @@ -12,21 +22,19 @@ var OKAdmin = function(){ $el.find("img").attr("src", url) $(".captioned-image-list ol").append($el) } + + // make the region sortable with drag-and-drop $(".captioned-image-list ol").sortable() $(".captioned-image-list ol").disableSelection() - - $("#add-image-url").keydown(pressEnter(function(e){ - var url = $(this).val() - $(this).val("") - add_image(url) - })}) - + + // delete image $(document).on("click", ".remove-image", function(){ if (confirm("Delete this image?")) { $(this).parent().remove() } }) + // populate a video field with info from our url parser $(".video .url").keydown(pressEnter(function(){ var $el = $(this) var url = $el.val() @@ -40,6 +48,7 @@ var OKAdmin = function(){ }) }})) + // fix post indexing in list-driven inputs $("form").submit(function(){ $(".image-element").each(function(index){ $(this).find("input,textarea").each(function(){ diff --git a/themes/okadmin/public/js/upload.js b/themes/okadmin/public/js/upload.js index d9fd5ed..1c9094c 100644 --- a/themes/okadmin/public/js/upload.js +++ b/themes/okadmin/public/js/upload.js @@ -2,8 +2,7 @@ var OKUpload = { action: "/_services/image", - bind: function(){ - var el = document.getElementById("file") + bind: function(el){ if (! el) return el.addEventListener("change", OKUpload.handleFileSelect) }, diff --git a/themes/okadmin/templates/partials/head.liquid b/themes/okadmin/templates/partials/head.liquid index 3af59fd..c423584 100644 --- a/themes/okadmin/templates/partials/head.liquid +++ b/themes/okadmin/templates/partials/head.liquid @@ -2,12 +2,12 @@ - {{meta.title}} + TwoHustlers Admin {{meta.title}}
- {{meta.title}} Admin + TwoHustlers{{meta.title}} Admin View Site
-- cgit v1.2.3-70-g09d2 From d96e081e9ee7f96a268c3beaf2f8d11d6146927b Mon Sep 17 00:00:00 2001 From: julie lala Date: Thu, 9 Apr 2015 16:49:00 -0400 Subject: little things --- themes/okadmin/public/css/main.css | 4 ++-- themes/okadmin/public/js/app.js | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'themes') diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index a01a85c..d2a4418 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -41,7 +41,7 @@ a:visited { } .admin-header .breadcrumb { - margin-left: 1em; + margin-left: 0.5em; font-size: 2em; color: rgba(0, 0, 0, 0.25); line-height: 50px; @@ -107,7 +107,7 @@ h2 { .main.resource { float: left; margin-top: 2em; - width: 80%; + width: 85%; } .main.resource > * { diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 170b2ab..352507f 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -12,7 +12,7 @@ var OKAdmin = function(){ var url = $(this).val() $(this).val("") add_image(url) - })}) + })) // clone and populate template function add_image(url){ @@ -46,7 +46,7 @@ var OKAdmin = function(){ $el.parent().find(".video-title").val( media.title ) $el.parent().find(".video-thumb").val( media.thumbnail ) }) - }})) + })) // fix post indexing in list-driven inputs $("form").submit(function(){ @@ -64,6 +64,7 @@ var OKAdmin = function(){ e.preventDefault() } } +} $(function(){ window.app = new OKAdmin () -- cgit v1.2.3-70-g09d2 From aeaac5a595f37edb45180385ef9f7f06a5ecb21a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 9 Apr 2015 17:06:31 -0400 Subject: CALLBACK --- themes/okadmin/public/js/app.js | 1 + 1 file changed, 1 insertion(+) (limited to 'themes') diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 352507f..308186c 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -62,6 +62,7 @@ var OKAdmin = function(){ return function(e){ if (e.keyCode !== 13) return e.preventDefault() + fn() } } } -- cgit v1.2.3-70-g09d2 From a3655fdc4ed8a8130e67cb895df9eb7f3bc5bd07 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 9 Apr 2015 17:07:48 -0400 Subject: bind --- themes/okadmin/public/js/app.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'themes') diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 308186c..f37ec13 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -62,7 +62,7 @@ var OKAdmin = function(){ return function(e){ if (e.keyCode !== 13) return e.preventDefault() - fn() + fn.bind(this) } } } -- cgit v1.2.3-70-g09d2 From b47be29a9fae6e3ac2040b0d308831bbe746c14e Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 9 Apr 2015 17:10:16 -0400 Subject: lol --- themes/okadmin/public/js/app.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'themes') diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index f37ec13..8c85663 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -35,9 +35,10 @@ var OKAdmin = function(){ }) // populate a video field with info from our url parser - $(".video .url").keydown(pressEnter(function(){ + $(".video .url").on("keydown blur", pressEnter(function(){ var $el = $(this) var url = $el.val() + console.log(url) Parser.parse( url, function(media){ console.log(url,media) $el.parent().addClass("loaded") @@ -60,9 +61,10 @@ var OKAdmin = function(){ function pressEnter(fn){ return function(e){ - if (e.keyCode !== 13) return + if (e.keyCode && e.keyCode !== 13) return e.preventDefault() - fn.bind(this) + console.log("hi") + fn.apply(this) } } } -- 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') 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 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' %} - -- cgit v1.2.3-70-g09d2 From 29ee500db3cb317404cb2f050ee9bc75777e91ca Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 13 Apr 2015 17:57:24 -0400 Subject: delete button --- themes/okadmin/templates/partials/inputs.liquid | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'themes') diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index b9cf7a3..4d6372d 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -50,7 +50,7 @@ {{image.caption}} - + {% endfor %} @@ -64,7 +64,7 @@ {{image.caption}} - +
-- cgit v1.2.3-70-g09d2 From 3ac36830841a51f3d3de63f5df849a4bb84b948d Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 13 Apr 2015 17:59:25 -0400 Subject: css --- themes/okadmin/public/css/main.css | 3 +++ 1 file changed, 3 insertions(+) (limited to 'themes') diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index 67271bc..ec426f9 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -262,6 +262,9 @@ button, input[type=submit] { font-size: 1.0em; margin-top: 1.0em; } +.main.resource form#delete_form button { + float: right; +} .main.resource form ol { margin: 0; -- cgit v1.2.3-70-g09d2 From d45f617dc74a07beb352d04537d47a77193f487f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 13 Apr 2015 18:19:41 -0400 Subject: hide id field --- site/index.js | 4 ++-- themes/okadmin/public/js/app.js | 16 ++++++++++++---- themes/okadmin/templates/partials/inputs.liquid | 19 +++---------------- 3 files changed, 17 insertions(+), 22 deletions(-) (limited to 'themes') diff --git a/site/index.js b/site/index.js index 8eec697..d4f5cb4 100644 --- a/site/index.js +++ b/site/index.js @@ -1,7 +1,7 @@ var okcms = require('..'); var projectSchema = { - id: {type: 'string', id: true}, + id: {type: 'string', id: true, hidden: true}, title: {type: 'string'}, shortname: {type: 'string'}, description: {type: 'text'}, @@ -15,7 +15,7 @@ var app = okcms.createApp({ schemas: { page: { - id: {type: 'string'}, + id: {type: 'string', hidden: true}, title: {type: 'string'}, body: {type: 'text'}, image: {type: 'string'} diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 91a8e1a..009fe4c 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -51,13 +51,18 @@ var OKAdmin = function(){ // fix post indexing in list-driven inputs $(".main.resource form").submit(function(e){ - var $id = $("[name=id]") - if ($id.length && ! $id.val()) { - alert("Please enter an ID") - $id.focus() + var $id = $("[name=id]"), $title = $("[name=title]") + + if ($title.length && ! $title.val()) { + alert("Please enter a title") + $title.focus() e.preventDefault() return } + + var slug = slugify( $title.val() ) + $id.val( slug ) + $(".image-element").each(function(index){ $(this).find("input,textarea").each(function(){ var field = $(this).attr("name").replace(/\[[0-9]*\]/, "[" + index + "]") @@ -129,3 +134,6 @@ var OKAdmin = function(){ $(function(){ window.app = new OKAdmin () }) + + +function slugify (s){ return (s || "").toLowerCase().replace(/\s/g,"-").replace(/[^-_a-zA-Z0-9]/g, '-').replace(/-+/g,"-") } diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 4d6372d..253b275 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -3,30 +3,17 @@ {% assign spec = pair[1] %} {% assign type = spec.type %} -
- +
+ {% if type == 'string' %} + name="{{name}}" type="text" value="{{spec.value}}"> {% elsif type == 'text' %} {% elsif type == 'enum' %} {% endfor %} diff --git a/themes/okadmin/templates/resource.liquid b/themes/okadmin/templates/resource.liquid index abc59e9..aa3efe0 100644 --- a/themes/okadmin/templates/resource.liquid +++ b/themes/okadmin/templates/resource.liquid @@ -6,8 +6,8 @@ Back -
-

EDIT {{ resource.type }} '{{ resource.id }}'

+
+

EDIT {{ resource.type }} '{{ resource.spec.title.value }}'

{% include 'partials/inputs' %} -- cgit v1.2.3-70-g09d2 From 455c09226f1bc57021147e889ef1127e982ed67c Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 13 Apr 2015 18:52:06 -0400 Subject: rename shortname -> menu to be clear --- site/db.json | 2 +- site/index.js | 2 +- site/templates/all.liquid | 8 ++++---- site/templates/index.liquid | 8 ++++---- themes/okadmin/public/js/app.js | 6 +++--- 5 files changed, 13 insertions(+), 13 deletions(-) (limited to 'themes') diff --git a/site/db.json b/site/db.json index 6c598ab..eb0265d 100644 --- a/site/db.json +++ b/site/db.json @@ -4,7 +4,7 @@ { "id": "diesel-jogg-jeans-ss15-denim-campaign", "title": "DIESEL JOGG JEANS SS15 DENIM CAMPAIGN", - "shortname": "DIESEL SS15", + "menu": "DIESEL SS15", "description": "Sed posuere consectetur est at lobortis. Donec id elit non mi porta gravida at eget metus. Cras mattis consectetur purus sit amet fermentum. Vestibulum id ligula porta felis euismod semper. Donec sed odio dui. \r\n\r\nVestibulum id ligula porta felis euismod semper. Vestibulum id ligula porta felis euismod semper. Vestibulum id ligula porta felis euismod semper. Aenean lacinia bibendum nulla sed consectetur. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. \r\n\r\nCurabitur blandit tempus porttitor. Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec ullamcorper nulla non metus auctor fringilla. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur blandit tempus porttitor. Maecenas sed diam eget risus varius blandit sit amet non magna.", "video": { "url": "http://vimeo.com/112498725", diff --git a/site/index.js b/site/index.js index d4f5cb4..189dfc4 100644 --- a/site/index.js +++ b/site/index.js @@ -3,7 +3,7 @@ var okcms = require('..'); var projectSchema = { id: {type: 'string', id: true, hidden: true}, title: {type: 'string'}, - shortname: {type: 'string'}, + menu: {type: 'string'}, description: {type: 'text'}, video: {type: 'video'}, images: {type: 'captioned-image-list'}, diff --git a/site/templates/all.liquid b/site/templates/all.liquid index 01ddc3a..e6f39bf 100644 --- a/site/templates/all.liquid +++ b/site/templates/all.liquid @@ -2,25 +2,25 @@ {% for project in retails %}
- {{ project.shortname }} + {{ project.title }}
{% endfor %} {% for project in advertisings %}
- {{ project.shortname }} + {{ project.title }}
{% endfor %} {% for project in experientials %}
- {{ project.shortname }} + {{ project.title }}
{% endfor %} {% for project in contents %}
- {{ project.shortname }} + {{ project.title }}
{% endfor %}
diff --git a/site/templates/index.liquid b/site/templates/index.liquid index 19bdf88..19a0b6c 100644 --- a/site/templates/index.liquid +++ b/site/templates/index.liquid @@ -88,25 +88,25 @@ WEBSITE BY OKFOCUS, http://okfoc.us, Internet Legends.
retail
{% for project in retails %} - {{ project.shortname }} + {{ project.menu }} {% endfor %}
advertising
{% for project in advertisings %} - {{ project.shortname }} + {{ project.menu }} {% endfor %}
experiential
{% for project in experientials %} - {{ project.shortname }} + {{ project.menu }} {% endfor %}
content
{% for project in contents %} - {{ project.shortname }} + {{ project.menu }} {% endfor %}
diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index ab571f3..aa8d0ad 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -51,7 +51,7 @@ var OKAdmin = function(){ // fix post indexing in list-driven inputs $(".main.resource form").submit(function(e){ - var $id = $("[name=id]"), $title = $("[name=title]"), $shortname = $("[name=shortname]"), $section = $(".resource.main") + var $id = $("[name=id]"), $title = $("[name=title]"), $menu = $("[name=menu]"), $section = $(".resource.main") var id = $section.data("id"), type = $section.data("type") if ($title.length && ! $title.val()) { @@ -61,8 +61,8 @@ var OKAdmin = function(){ return } - if ($shortname.length && ! $shortname.val()) { - $shortname.val( $title.val() ) + if ($menu.length && ! $menu.val()) { + $menu.val( $title.val() ) return } -- cgit v1.2.3-70-g09d2 From db3775794623ebbc63efb44e545b66f2accfd728 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 13 Apr 2015 19:28:42 -0400 Subject: testing stuff --- site/db.json | 37 ++++++++++++++++++++++++++++++-- site/index.js | 1 + site/templates/project.liquid | 2 +- themes/okadmin/public/js/app.js | 1 - themes/okadmin/templates/resource.liquid | 4 +++- 5 files changed, 40 insertions(+), 5 deletions(-) (limited to 'themes') diff --git a/site/db.json b/site/db.json index eb0265d..7681fd8 100644 --- a/site/db.json +++ b/site/db.json @@ -46,7 +46,40 @@ "__index": "0" } ], - "advertising": [], "experiential": [], - "content": [] + "content": [ + { + "id": "stuff", + "title": "Stuff", + "menu": "Stuff", + "description": "Blablhablhalbhab", + "video": { + "url": "http://vimeo.com/112498725", + "type": "vimeo", + "token": "112498725", + "title": "FW14-2H-VIDEO-V4 2", + "thumb": "http://i.vimeocdn.com/video/497493142_640.jpg" + }, + "images": [ + { + "uri": "https://ltho.s3.amazonaws.com/aa5ab62c-a7f4-433e-8957-c059199de924.png", + "caption": "WHO" + }, + { + "uri": "https://ltho.s3.amazonaws.com/888c06f0-32f4-4f7b-938f-fb9bf178a1dc.png", + "caption": "DARK" + }, + { + "uri": "https://ltho.s3.amazonaws.com/525cd121-a436-472f-b201-7b2baffa804a.png", + "caption": "STUFF" + }, + { + "uri": "https://ltho.s3.amazonaws.com/b2a607e6-1c60-42cd-8449-55737501ff9e.png", + "caption": "BLAH" + } + ], + "__index": "0" + } + ], + "advertising": [] } \ No newline at end of file diff --git a/site/index.js b/site/index.js index 189dfc4..b6dea48 100644 --- a/site/index.js +++ b/site/index.js @@ -81,6 +81,7 @@ var app = okcms.createApp({ '/advertising/:id': { data: { type: 'advertising', + as: 'project', query: { id: ':id' } diff --git a/site/templates/project.liquid b/site/templates/project.liquid index d21fed2..e087049 100644 --- a/site/templates/project.liquid +++ b/site/templates/project.liquid @@ -3,7 +3,7 @@ {{project.title}} + +
+
+ + + + + + + + + + + + + + + + + + + + + + + + + +
+
+
diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index a5bd0fc..22317f3 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -60,8 +60,8 @@ var OKAdmin = function(){ var id = $section.data("id"), type = $section.data("type") if ($title.length && ! $title.val()) { - alert("Please enter a title") $title.focus() + alert("Please enter a title") e.preventDefault() return } -- cgit v1.2.3-70-g09d2 From eb779beb83ed6e8d000fd0453c9ed5c404327ae4 Mon Sep 17 00:00:00 2001 From: Sean Fridman Date: Thu, 16 Apr 2015 02:11:55 -0400 Subject: Take metadata from config and make synchronous --- app/index.js | 35 +++------- app/node_modules/okadminview/index.js | 96 +++++++++++---------------- app/node_modules/okview/index.js | 13 ++-- site/index.js | 6 ++ themes/okadmin/templates/partials/head.liquid | 4 +- 5 files changed, 63 insertions(+), 91 deletions(-) (limited to 'themes') diff --git a/app/index.js b/app/index.js index 01ea33b..d487bd7 100644 --- a/app/index.js +++ b/app/index.js @@ -38,33 +38,18 @@ function OKCMS(options) { path.join(__dirname, '../themes/okadmin/templates'); var debug = options.debug || false; - // Set metadata defaults - // TODO Abstract this out somewhere else - var meta = { - type: 'meta', - get: function() { - return Q.promise(function(resolve, reject) { - db.getMeta().then(function(metadata) { - resolve(assign({}, { - static: '' - }, metadata)); - }).fail(reject); - }); - } + var metaUser = options.meta || {}; + var metaDefault = { + project: 'OKCMS' }; - var adminMeta ={ - type: 'meta', - get: function() { - return Q.promise(function(resolve, reject) { - db.getMeta().then(function(metadata) { - resolve(assign({}, { - static: withoutTrailingSlash(adminPath) - }, metadata)); - }).fail(reject); - }); - } - }; + var meta = assign({ + static: '' + }, metaDefault, metaUser); + + var adminMeta = assign({ + static: withoutTrailingSlash(adminPath) + }, metaDefault, metaUser); var schemaConfig = options.schemas || {}; var resourceConfig = options.resources || []; diff --git a/app/node_modules/okadminview/index.js b/app/node_modules/okadminview/index.js index 161a195..82f364d 100644 --- a/app/node_modules/okadminview/index.js +++ b/app/node_modules/okadminview/index.js @@ -36,7 +36,7 @@ function OKAdminView(options) { if (!options.templateProvider) throw new Error('No templateProvider provided to OKAdminView'); if (!options.meta) - throw new Error('No meta query provided to OKAdminView'); + throw new Error('No metadata provided to OKAdminView'); if (!options.errorHandler) throw new Error('No error handler provided to OKAdminView'); @@ -135,13 +135,11 @@ function OKAdminView(options) { if (!resource) { error(req, res, 404)(new Error('No such resource ' + type)); } else { - meta.get().then(function(metadata) { - var templateData = transformData(metadata, resource, {}); - view.renderResourceNew(req, res, assign(templateData, { - success: req.flash('success'), - errors: req.flash('errors'), - })); - }).fail(error(req, res, 500)); + var templateData = transformData(meta, resource, {}); + view.renderResourceNew(req, res, assign(templateData, { + success: req.flash('success'), + errors: req.flash('errors'), + })); } }); @@ -179,18 +177,16 @@ function OKAdminView(options) { if (!resource) { error(req, res, 400)(new Error('No such resource ' + type)); } else { - meta.get().then(function(metadata) { - try { - resource.assertValid(data); - resource.create(data).then(function(created) { - req.flash('success', {action: 'create'}); - res.redirect(303, resource.getID(data)); - }).fail(error(req, res, 500)); - } catch (errors) { - var templateData = transformData(metadata, resource, data); - view.renderResource(req, res, assign(templateData, {errors: errors})); - } - }).fail(error(req, res, 500));; + try { + resource.assertValid(data); + resource.create(data).then(function(created) { + req.flash('success', {action: 'create'}); + res.redirect(303, resource.getID(data)); + }).fail(error(req, res, 500)); + } catch (errors) { + var templateData = transformData(meta, resource, data); + view.renderResource(req, res, assign(templateData, {errors: errors})); + } } }); @@ -215,11 +211,7 @@ function OKAdminView(options) { error(req, res, 500)(new Error('Resource batch contains invalid JSON')); return; } - Q.all([ - meta.get(), - resource.updateBatch(ids, resourcesParsed), - ]).then(function(results) { - var metadata = results.shift(); + resource.updateBatch(ids, resourcesParsed).then(function(results) { req.flash('success', {action: 'batch_update'}); res.redirect(303, '../..'); }).fail(error(req, res, 500)); @@ -234,19 +226,16 @@ function OKAdminView(options) { if (!resource) { error(req, res, 400)(new Error('No such resource ' + type)); } else { - // TODO Prob should make metadata synchronous... - meta.get().then(function(metadata) { - try { - resource.assertValid(data); - resource.update(id, data).then(function(updated) { - req.flash('success', {action: 'update'}); - res.redirect(303, '../' + resource.getID(updated)); - }).fail(error(req, res, 500)); - } catch (errors) { - var templateData = transformData(metadata, resource, data); - view.renderResource(req, res, assign(templateData, {errors: errors})); - } - }).fail(error(req, res, 500)); + try { + resource.assertValid(data); + resource.update(id, data).then(function(updated) { + req.flash('success', {action: 'update'}); + res.redirect(303, '../' + resource.getID(updated)); + }).fail(error(req, res, 500)); + } catch (errors) { + var templateData = transformData(meta, resource, data); + view.renderResource(req, res, assign(templateData, {errors: errors})); + } } }); @@ -257,11 +246,9 @@ function OKAdminView(options) { if (!resource) { error(req, res, 500)(new Error('No such resource ' + type)); } else { - meta.get().then(function(metadata) { - resource.destroy(id).then(function() { - req.flash('success', {action: 'delete'}); - res.redirect(303, '../..'); - }).fail(error(req, res, 500)); + resource.destroy(id).then(function() { + req.flash('success', {action: 'delete'}); + res.redirect(303, '../..'); }).fail(error(req, res, 500)); } }); @@ -328,10 +315,9 @@ OKAdminView.prototype.renderResourceNew = function(req, res, data) { */ function fetchIndexTemplateData(meta, queries) { return Q.promise(function(resolve, reject) { - Q.all([meta.get()].concat(queries.map(function(query) { + Q.all(queries.map(function(query) { return query.get(); - }))).then(function(results) { - var meta = results.shift(); + })).then(function(results) { var resources = results.reduce(function(cache, result, i) { if (!result) return cache; @@ -376,16 +362,14 @@ function fetchIndexTemplateData(meta, queries) { function fetchResourceTemplateData(meta, query, fn) { fn = fn || function(m, r, d) { return {meta: m, resource: d}; }; return Q.promise(function(resolve, reject) { - meta.get().then(function(metadata) { - query.get().then(function(data) { - if (!data) { - reject(new Error('No resource data')); - } else { - var resource = query.resource; - resolve(fn(metadata, resource, data)); - } - }).fail(reject); - }).fail(reject) + query.get().then(function(data) { + if (!data) { + reject(new Error('No resource data')); + } else { + var resource = query.resource; + resolve(fn(meta, resource, data)); + } + }).fail(reject); }); } diff --git a/app/node_modules/okview/index.js b/app/node_modules/okview/index.js index 951261c..fba1c18 100644 --- a/app/node_modules/okview/index.js +++ b/app/node_modules/okview/index.js @@ -21,7 +21,7 @@ function OKView(options) { if (!options.template) throw new Error('No template provided to OKView.'); if (!options.meta) - throw new Error('No meta resource provided to OKView'); + throw new Error('No metadata provided to OKView'); if (!options.route) throw new Error('No route provided to OKView'); if (!options.errorHandler) @@ -124,12 +124,9 @@ function fetchTemplateData(meta, queries, id) { // resource and will resolve errors if no data is found var single = queries && queries.length === 1; return Q.promise(function(resolve, reject) { - return Q.all( - [meta.get()].concat(queries.map(function(query) { - return query.get(id); - }))) - .then(function(results) { - var metadata = results.shift(); + return Q.all(queries.map(function(query) { + return query.get(id); + })).then(function(results) { if (single && !results[0]) { reject(new Error('No resource found')); } else { @@ -164,7 +161,7 @@ function fetchTemplateData(meta, queries, id) { cache[type] = result; } return cache; - }, {meta: metadata}); + }, {meta: meta}); resolve(normalized); } diff --git a/site/index.js b/site/index.js index 7457bbf..521b7d7 100644 --- a/site/index.js +++ b/site/index.js @@ -11,8 +11,14 @@ var projectSchema = { var app = okcms.createApp({ + meta: { + project: 'TwoHustlers' + }, + root: 'public', + debug: false, + schemas: { page: { id: {type: 'string', hidden: true}, diff --git a/themes/okadmin/templates/partials/head.liquid b/themes/okadmin/templates/partials/head.liquid index c423584..7ee4824 100644 --- a/themes/okadmin/templates/partials/head.liquid +++ b/themes/okadmin/templates/partials/head.liquid @@ -2,12 +2,12 @@ - TwoHustlers Admin {{meta.title}} + {{meta.project}} Admin
- TwoHustlers{{meta.title}} Admin + {{meta.project}} Admin View Site
-- cgit v1.2.3-70-g09d2 From b51455df828fde90edbee3143bd8d49b00cc3f1a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 16 Apr 2015 14:04:10 -0400 Subject: single image upload field, abstract upload class a bit --- site/db.json | 6 +- site/index.js | 1 + site/public/assets/style.css | 3 +- site/templates/index.liquid | 2 + themes/okadmin/public/css/main.css | 25 +++++-- themes/okadmin/public/js/app.js | 93 +++++++++++++++++-------- themes/okadmin/public/js/upload.js | 91 +++++++++++------------- themes/okadmin/templates/partials/inputs.liquid | 52 +++++++++----- 8 files changed, 171 insertions(+), 102 deletions(-) (limited to 'themes') diff --git a/site/db.json b/site/db.json index d0624e8..12ccb38 100644 --- a/site/db.json +++ b/site/db.json @@ -27,7 +27,11 @@ "caption": "CURABITUR BLANDIT TEMPUS PORTTITOR 4" } ], - "__index": "0" + "__index": "0", + "shape": { + "uri": "", + "caption": "" + } } ], "page": [ diff --git a/site/index.js b/site/index.js index 521b7d7..30e4a76 100644 --- a/site/index.js +++ b/site/index.js @@ -7,6 +7,7 @@ var projectSchema = { description: {type: 'text'}, video: {type: 'video'}, images: {type: 'captioned-image-list'}, + shape: {type: 'image'}, } var app = okcms.createApp({ diff --git a/site/public/assets/style.css b/site/public/assets/style.css index 3c2526b..28d0013 100644 --- a/site/public/assets/style.css +++ b/site/public/assets/style.css @@ -285,6 +285,7 @@ nav .middle { } nav .bottom { + height: 20%; width: 100%; background: #bbb; } @@ -489,7 +490,7 @@ nav .sub.active a { } .entry span div.content.noline { border-top: 0; - padding-top: 0px; + padding-top: 0; } .entry span div.content div { width:50%; diff --git a/site/templates/index.liquid b/site/templates/index.liquid index afb5de3..d18098c 100644 --- a/site/templates/index.liquid +++ b/site/templates/index.liquid @@ -110,9 +110,11 @@ WEBSITE BY OKFOCUS, http://okfoc.us, Internet Legends. {% endfor %}
+
ABOUT
CONTACT
diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index ec426f9..685e368 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -228,7 +228,9 @@ button, input[type=submit] { border: 0; display: none; } -.main.resource form .group.loaded input:first-child, +.main.resource form .group.image input, +.main.resource form .group.video input:first-child, +.main.resource form .group.loaded.video input[type=text], .main.resource form .group input:first-child { display: block; width: 25em; @@ -238,17 +240,24 @@ button, input[type=submit] { } .main.resource form .group.loaded input { display: block; - width: 20.05em; } -.main.resource form .group input { - display: none; +.main.resource form .group input[type=text] { + width: 20.05em; margin-bottom: 0.1em; } +.main.resource form .group.image .image-element, +.main.resource form .group.video input[type=text], .main.resource form .group.loaded input[hidden], +.main.resource form .group.image.loaded .fields, .main.resource form input[hidden] { display: none; } - +.main.resource form .group.image.loaded .image-element { + display: block; +} +.main.resource form .fields { + height: 3em; +} .main.resource form textarea { padding: 0.5em; height: 15em; @@ -280,6 +289,8 @@ button, input[type=submit] { width: 10em; max-height: 10em; border: 0; +} +.main.resource form .images img { cursor: -webkit-grab; cursor: grab; } @@ -313,10 +324,10 @@ button, input[type=submit] { margin: 0; padding: 0; cursor: pointer; } -li.image-element:hover .remove-image { +.image-element:hover .remove-image { display: block; } -li.image-element .remove-image:hover { +.image-element .remove-image:hover { color: red; } .remove-image { diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 22317f3..baa4873 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -1,38 +1,75 @@ var OKAdmin = function(){ - // initialize our (single) ajax image uploader with an element and a template - OKUpload.bind( document.getElementById("file") ) - OKUpload.add = function(data){ - var url = data[0].extra.Location - add_image(url) - } - - // also handle straight image urls - $("#add-image-url").keydown(pressEnter(function(e){ - var url = $(this).val() - $(this).val("") - add_image(url) - })) + // initialize our multi-image uploader with an element and a template + $(".image-list").each(function(){ + var uploader = new OKUpload () + uploader.bind( $(".add-image-button input", this) ) + uploader.add = function(data){ + var url = data[0].extra.Location + add_image(url) + } + // also handle straight image urls + $(".add-image-url", this).keydown(pressEnter(function(e){ + var url = $(this).val() + $(this).val("") + add_image(url) + })) + + // clone and populate template + function add_image(url){ + var imageTemplate = $("#captioned-image-template").html() + var $el = $(imageTemplate) + $el.find(".uri").val(url) + $el.find("img").attr("src", url) + $(".captioned-image-list ol").append($el) + } + }) + // delete image from gallery + $(document).on("mousedown", ".image-list .remove-image", function(){ + if (confirm("Delete this image?")) { + $(this).parent().remove() + } + }) - // clone and populate template - function add_image(url){ - var imageTemplate = $("#captioned-image-template").html() - var $el = $(imageTemplate) - $el.find(".uri").val(url) - $el.find("img").attr("src", url) - $(".captioned-image-list ol").append($el) - } + // initialize our single image uploader with existing DOM + $(".image").each(function(){ + var $el = $(this) + + var uploader = new OKUpload () + uploader.bind( $(".add-image-button input", this) ) + uploader.add = function(data){ + var url = data[0].extra.Location + add_image(url) + } + // also handle straight image urls + $(".add-image-url", this).keydown(pressEnter(function(e){ + var url = $(this).val() + $(this).val("") + add_image(url) + })) + + // clone and populate template + function add_image(url){ + $el.find(".uri").val(url) + $el.find(".caption").val("") + $el.find("img").attr("src", url) + $el.addClass("loaded") + } + }) + // delete image from single image entry + $(document).on("mousedown", ".image .remove-image", function(){ + if (confirm("Delete this image?")) { + var $el = $(this).closest(".image") + $el.removeClass('loaded') + $el.find(".uri").val("") + $el.find(".caption").val("") + $el.find("img").attr("src", "") + } + }) // make the region sortable with drag-and-drop $(".captioned-image-list ol").sortable() $(".captioned-image-list ol").disableSelection() - - // delete image - $(document).on("mousedown", ".remove-image", function(){ - if (confirm("Delete this image?")) { - $(this).parent().remove() - } - }) // populate a video field with info from our url parser var last_url diff --git a/themes/okadmin/public/js/upload.js b/themes/okadmin/public/js/upload.js index 1c9094c..39f7427 100644 --- a/themes/okadmin/public/js/upload.js +++ b/themes/okadmin/public/js/upload.js @@ -1,55 +1,48 @@ -var OKUpload = { - action: "/_services/image", - - bind: function(el){ - if (! el) return - el.addEventListener("change", OKUpload.handleFileSelect) - }, - - handleFileSelect: function(e) { - e.stopPropagation(); - e.preventDefault(); - - var files = e.dataTransfer ? e.dataTransfer.files : e.target.files; - - for (var i = 0, f; f = files[i]; i++) { - if ( ! f.type.match('image.*')) { - continue; - } - OKUpload.upload(f) - } - }, +var OKUpload = function(){ + this.action = "/_services/image" +} +OKUpload.prototype.bind = function(el){ + if (el.length) el = el[0] + el.addEventListener("change", this.handleFileSelect.bind(this)) +} +OKUpload.prototype.handleFileSelect = function(e) { + e.stopPropagation(); + e.preventDefault(); - upload: function(f){ - var fd = new FormData() - fd.append('image', f) + var files = e.dataTransfer ? e.dataTransfer.files : e.target.files; - var request = $.ajax({ - url: OKUpload.action, - type: "post", - data: fd, - dataType: "json", - processData: false, - contentType: false, - }) - request.done(OKUpload.success) - }, - - success: function(media){ - if (media.error) { - console.log(media.error) - return + for (var i = 0, f; f = files[i]; i++) { + if ( ! f.type.match('image.*')) { + continue; } - OKUpload.add(media) - }, - - add: function(media){ - console.log(media) - }, - - error: function(error){ - throw error - }, + this.upload(f) + } +} +OKUpload.prototype.upload = function(f){ + var fd = new FormData() + fd.append('image', f) + var request = $.ajax({ + url: this.action, + type: "post", + data: fd, + dataType: "json", + processData: false, + contentType: false, + }) + request.done(this.success.bind(this)) +} +OKUpload.prototype.success = function(media){ + if (media.error) { + console.log(media.error) + return + } + this.add(media) +} +OKUpload.prototype.add = function(media){ + console.log(media) +} +OKUpload.prototype.error = function(error){ + throw error } diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 253b275..c9a4d92 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -22,15 +22,48 @@ {% elsif type == 'video' %}
- - + +
+ {% elsif type == 'image' %} +
+
+
+ + +
+ +
+
+ + + {{spec.value.caption}} + +
+
{% elsif type == 'captioned-image-list' %} -
+
+
+
+ + +
+ +
+ + +
    {% for image in spec.value %}
  1. @@ -41,19 +74,6 @@
  2. {% endfor %}
-
- - -
- -
{% elsif type == 'meta' %} -- cgit v1.2.3-70-g09d2 From 3f26845f934e95a5c3f9486f83f715240347bbcd Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 16 Apr 2015 14:22:14 -0400 Subject: dry --- site/templates/index.liquid | 8 ++++---- themes/okadmin/public/js/app.js | 41 ++++---------------------------------- themes/okadmin/public/js/upload.js | 30 +++++++++++++++++++++------- 3 files changed, 31 insertions(+), 48 deletions(-) (limited to 'themes') diff --git a/site/templates/index.liquid b/site/templates/index.liquid index d18098c..224803a 100644 --- a/site/templates/index.liquid +++ b/site/templates/index.liquid @@ -88,25 +88,25 @@ WEBSITE BY OKFOCUS, http://okfoc.us, Internet Legends.
retail
{% for project in retails %} - {{ project.menu }} + {{ project.menu }} {% endfor %}
advertising
{% for project in advertisings %} - {{ project.menu }} + {{ project.menu }} {% endfor %}
experiential
{% for project in experientials %} - {{ project.menu }} + {{ project.menu }} {% endfor %}
content
{% for project in contents %} - {{ project.menu }} + {{ project.menu }} {% endfor %}
diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index baa4873..874b7e1 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -3,20 +3,8 @@ var OKAdmin = function(){ // initialize our multi-image uploader with an element and a template $(".image-list").each(function(){ var uploader = new OKUpload () - uploader.bind( $(".add-image-button input", this) ) - uploader.add = function(data){ - var url = data[0].extra.Location - add_image(url) - } - // also handle straight image urls - $(".add-image-url", this).keydown(pressEnter(function(e){ - var url = $(this).val() - $(this).val("") - add_image(url) - })) - - // clone and populate template - function add_image(url){ + uploader.bind( this ) + uploader.add = function(url){ var imageTemplate = $("#captioned-image-template").html() var $el = $(imageTemplate) $el.find(".uri").val(url) @@ -36,20 +24,8 @@ var OKAdmin = function(){ var $el = $(this) var uploader = new OKUpload () - uploader.bind( $(".add-image-button input", this) ) - uploader.add = function(data){ - var url = data[0].extra.Location - add_image(url) - } - // also handle straight image urls - $(".add-image-url", this).keydown(pressEnter(function(e){ - var url = $(this).val() - $(this).val("") - add_image(url) - })) - - // clone and populate template - function add_image(url){ + uploader.bind( this ) + uploader.add = function(url){ $el.find(".uri").val(url) $el.find(".caption").val("") $el.find("img").attr("src", url) @@ -173,15 +149,6 @@ var OKAdmin = function(){ $input.val(JSON.stringify(parsed)); }) }); - - function pressEnter(fn){ - return function(e){ - if (e.keyCode && e.keyCode !== 13) return - e.preventDefault() - console.log("hi") - fn.apply(this) - } - } } $(function(){ diff --git a/themes/okadmin/public/js/upload.js b/themes/okadmin/public/js/upload.js index 39f7427..040654b 100644 --- a/themes/okadmin/public/js/upload.js +++ b/themes/okadmin/public/js/upload.js @@ -2,9 +2,14 @@ var OKUpload = function(){ this.action = "/_services/image" } -OKUpload.prototype.bind = function(el){ - if (el.length) el = el[0] - el.addEventListener("change", this.handleFileSelect.bind(this)) +OKUpload.prototype.bind = function(rapper){ + var uploader = this + $(".add-image-button input", rapper).change( uploader.handleFileSelect.bind(uploader) ) + $(".add-image-url", rapper).keydown(pressEnter(function(e){ + var url = $(this).val() + $(this).val("") + uploader.add(url) + })) } OKUpload.prototype.handleFileSelect = function(e) { e.stopPropagation(); @@ -33,12 +38,13 @@ OKUpload.prototype.upload = function(f){ }) request.done(this.success.bind(this)) } -OKUpload.prototype.success = function(media){ - if (media.error) { - console.log(media.error) +OKUpload.prototype.success = function(data){ + if (data.error) { + console.log(data.error) return } - this.add(media) + var url = data[0].extra.Location + this.add(url) } OKUpload.prototype.add = function(media){ console.log(media) @@ -46,3 +52,13 @@ OKUpload.prototype.add = function(media){ OKUpload.prototype.error = function(error){ throw error } + + + +function pressEnter(fn){ + return function(e){ + if (e.keyCode && e.keyCode !== 13) return + e.preventDefault() + fn.apply(this) + } +} \ No newline at end of file -- cgit v1.2.3-70-g09d2 From 48923c16e00892fac916a83c8fdccca63800615f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 16 Apr 2015 14:41:58 -0400 Subject: load shape images from posts --- site/db.json | 2 +- site/public/assets/javascripts/_env.js | 20 ++++++++++++-------- site/templates/index.liquid | 17 ++++++++--------- themes/okadmin/public/js/app.js | 10 ++++++---- themes/okadmin/public/js/upload.js | 4 ++-- 5 files changed, 29 insertions(+), 24 deletions(-) (limited to 'themes') diff --git a/site/db.json b/site/db.json index 12ccb38..f1721a6 100644 --- a/site/db.json +++ b/site/db.json @@ -29,7 +29,7 @@ ], "__index": "0", "shape": { - "uri": "", + "uri": "http://okfocus.s3.amazonaws.com/2h/13.gif", "caption": "" } } diff --git a/site/public/assets/javascripts/_env.js b/site/public/assets/javascripts/_env.js index c4e9ace..b567a3d 100644 --- a/site/public/assets/javascripts/_env.js +++ b/site/public/assets/javascripts/_env.js @@ -7,8 +7,11 @@ environment.init = function(){ $("#scene").addClass("fade") var loader = new Loader(environment.ready, new HustleLoader) var preloadImages = $("#preload-image-list").html().split("\n").filter(function(s){ return !!s }) - boxImages = $("#box-image-list").html().split("\n").filter(function(s){ return !!s }) - loader.preloadImages( preloadImages.concat(boxImages) ) + boxImages = $("#box-image-list").html().split("\n") + var postImages = $(".sub a").toArray().map(function(el){ return $(el).data("image") }) + + var images = preloadImages.concat(postImages).concat(boxImages).filter(function(s){ return !!s }) + loader.preloadImages( images ) loader.ready() } environment.ready = function(){ @@ -191,7 +194,7 @@ function build_scene () { controls.zoom(1000) strips.push( new Strip({ - images: boxImages.slice(0, 5), + images: $(".sub[data-type=advertising] a"), x: -100, y: 100, rotationY: PI/4, @@ -199,7 +202,7 @@ function build_scene () { }) ) strips.push( new Strip({ - images: boxImages.slice(5, 10), + images: $(".sub[data-type=retail] a"), x: 100, y: 100, rotationX: PI/4, @@ -208,7 +211,7 @@ function build_scene () { }) ) strips.push( new Strip({ - images: boxImages.slice(10, 15), + images: $(".sub[data-type=experiential] a"), x: 0, y: 100, z: 100, @@ -217,7 +220,7 @@ function build_scene () { }) ) strips.push( new Strip({ - images: boxImages.slice(15, 20), + images: $(".sub[data-type=content] a"), x: 0, y: 100, z: -50, @@ -455,9 +458,10 @@ var Strip = function( opt ){ root.addTo(scene) var prev = root - this.els = opt.images.map(function(url, i){ + this.els = opt.images.toArray().map(function(el, i){ + var data = $(el).data() var el = new MX.Image({ - src: url, + src: data.image, onload: function(img){ } }) diff --git a/site/templates/index.liquid b/site/templates/index.liquid index 224803a..db6bf20 100644 --- a/site/templates/index.liquid +++ b/site/templates/index.liquid @@ -86,27 +86,27 @@ WEBSITE BY OKFOCUS, http://okfoc.us, Internet Legends.
retail
-
+
{% for project in retails %} - {{ project.menu }} + {{ project.menu }} {% endfor %}
advertising
-
+
{% for project in advertisings %} - {{ project.menu }} + {{ project.menu }} {% endfor %}
experiential
-
+
{% for project in experientials %} - {{ project.menu }} + {{ project.menu }} {% endfor %}
content
-
+
{% for project in contents %} - {{ project.menu }} + {{ project.menu }} {% endfor %}
@@ -238,7 +238,6 @@ WEBSITE BY OKFOCUS, http://okfoc.us, Internet Legends. + + + +
    + {% for image in spec.value %} + {% if image.token %} +
  1. + {{ JSON.stringify(spec.value) }} +
  2. + {% else %} +
  3. + + + {{image.caption}} + +
  4. + {% endif %} + {% endfor %} +
+
{% elsif type == 'captioned-image-list' %}
@@ -56,10 +105,10 @@
- +
- @@ -123,7 +134,7 @@ {{image.caption}} - + {% endfor %} -- cgit v1.2.3-70-g09d2 From 436703a1525c1cf1565fd922a9e661b9a0c845c2 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 27 Apr 2015 17:39:36 -0400 Subject: thumbnail thing --- themes/okadmin/public/js/app.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'themes') diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 1eb81dc..c1f9dc8 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -55,7 +55,6 @@ var OKAdmin = function(){ // initialize our single image uploader with existing DOM $(".group.image").each(function(){ var $el = $(this) - var uploader = new OKUpload () uploader.bind( this ) uploader.add = function(url){ @@ -63,7 +62,7 @@ var OKAdmin = function(){ console.log($el) $el.find(".uri").val(url) $el.find(".caption").val("") - $el.find("img").attr("src", url) + $el.find("img").attr("src", url).show() $el.addClass("loaded") } }) -- cgit v1.2.3-70-g09d2 From 21dfb9327f8acb95a5e81c4261fc00392b67e8c6 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 27 Apr 2015 17:46:49 -0400 Subject: fix flickity version --- site/db.json | 70 +++---- site/public/assets/javascripts/_env.js | 3 +- .../assets/javascripts/vendor/flickity.pkgd.js | 215 +++++++++++---------- themes/okadmin/public/js/app.js | 1 - 4 files changed, 139 insertions(+), 150 deletions(-) (limited to 'themes') diff --git a/site/db.json b/site/db.json index 591706f..3d55602 100644 --- a/site/db.json +++ b/site/db.json @@ -5,9 +5,9 @@ "content": [], "advertising": [ { - "id": "diesel-spring-summer-2015", - "title": "Diesel Spring/Summer 2015", - "menu": "Diesel S/S 2015", + "id": "diesel-s-s-2015", + "title": "Diesel S/S 2015", + "menu": "Diesel Spring/Summer 2015", "description": "FOR SPRING 2015, FORMICHETTI ESTABLISHES THE KEY PIECES THAT HAVE COME TO REFLECT DIESEL’S NEW ERA AND CHARACTERIZE ITS DNA, AND THE FACES WHO BEST REFLECT THE PAST, PRESENT, AND FUTURE OF THE BRAND. IN A REVOLUTIONARY CAMPAIGN BY NICK KNIGHT, FORMICHETTI HIGHLIGHTS HIS PERSONAL HEROES, WHICH INCLUDE NEW FACES AND THE ARTISTS, INNOVATORS, MUSES, AND FRIENDS WHO INSPIRE HIM, AS WELL AS A FEW HEROES FROM PAST CAMPAIGNS. COMBINING CLASSIC PORTRAITURE WITH FUTURISTIC, DIGITAL ELEMENTS, THE CAMPAIGN WILL JUXTAPOSE THE INDIVIDUALS WHO MAKE UP DIESEL’SCOMMUNITY WITH THE “HERO” PIECES THAT BEST DEFINE THE STATEMENT OF THE BRAND TODAY.", "video": { "url": "", @@ -24,19 +24,25 @@ "thumb": "http://i.vimeocdn.com/video/497493142_640.jpg" }, { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2Fe22fd077-ca52-42a1-ab9c-e0508bf4408e.jpg", + "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F1b55cd3c-eb7d-4ed6-bfe9-2bc53960987d.jpg", "caption": "" }, { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F1afaa719-c18f-4155-a42f-3e7fc10247c3.jpg", + "type": "vimeo", + "token": "125927621", + "title": "the Vampyre of Time and Memory", + "thumb": "http://i.vimeocdn.com/video/516197938_640.jpg" + }, + { + "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F86a3edfe-bdbb-44ac-9e50-e167c16c89b9.jpg", "caption": "" }, { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F1b55cd3c-eb7d-4ed6-bfe9-2bc53960987d.jpg", + "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F1afaa719-c18f-4155-a42f-3e7fc10247c3.jpg", "caption": "" }, { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2Fe402bfbb-b101-4b42-afcb-818f7b616db9.jpg", + "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F38cb4454-34a4-44af-8243-53da4d2b7c47.jpg", "caption": "" }, { @@ -44,28 +50,28 @@ "caption": "" }, { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F38cb4454-34a4-44af-8243-53da4d2b7c47.jpg", + "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F5bdc8f95-b18f-407a-b2f3-33df1025bf8a.jpg", "caption": "" }, { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F86a3edfe-bdbb-44ac-9e50-e167c16c89b9.jpg", + "uri": "https://ltho.s3.amazonaws.com/twohustlers%2Fe22fd077-ca52-42a1-ab9c-e0508bf4408e.jpg", "caption": "" }, { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F5bdc8f95-b18f-407a-b2f3-33df1025bf8a.jpg", + "uri": "https://ltho.s3.amazonaws.com/twohustlers%2Fe402bfbb-b101-4b42-afcb-818f7b616db9.jpg", "caption": "" } ], "thumbnail": { - "uri": "", + "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F479667e9-a89d-4c19-935a-b78f3aaf64e6.jpg", "caption": "" }, "__index": "0" }, { - "id": "diesel-fall-winter-2014", - "title": "Diesel Fall/Winter 2014", - "menu": "Diesel F/W 2014", + "id": "diesel-f-w-14", + "title": "Diesel F/W 14", + "menu": "Diesel Fall/Winter 2014", "description": "FOR FALL/WINTER 2014, IN AN ACT OF DEFIANT ANONYMITY, DIESEL IS STRIPPING AWAY THE IDENTITIES OF ITS MODELS AND CAMPAIGN STARS, DEMOCRATIZING THE CONCEPT – THERE IS NO SINGULAR IDEA OF WHO THE DIESEL PERSON SHOULD BE. SHOT BY NICK KNIGHT, THE CREATIVE IS INSPIRED BY THE THEME “PICASSO MEETS AVEDON,” REPRESENTING THE NEXT DIMENSION OF DIESEL, INTRODUCING THE SECOND PHASE OF THE BRAND AFTER #DIESELREBOOT.", "video": { "url": "", @@ -76,44 +82,12 @@ }, "media": [ { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F38ea6ad0-f689-491f-857a-12d4fa0d4748.jpg", - "caption": "" - }, - { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F12184bdd-0aff-43db-882c-8efcb1e583de.jpg", - "caption": "" - }, - { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2Fb61bd44f-d074-4a20-a641-fc11957e8cd5.jpg", - "caption": "" - }, - { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F2a0b26ae-cc35-406e-923b-e60409e53eb8.jpg", - "caption": "" - }, - { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2Fd2a68db8-018b-4fdf-8f69-c2e4d0aff76a.jpg", - "caption": "" - }, - { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F0b24ebbd-07e8-446e-83db-60484f0f3dd9.jpg", - "caption": "" - }, - { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F1f8c6b75-c694-4d31-a790-b042b75b3606.jpg", - "caption": "" - }, - { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F907a0fbd-1455-4f3d-b28e-ebcba658f2d3.jpg", - "caption": "" - }, - { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F17ee7deb-dee5-497a-a8a6-dfe3f9c3105d.jpg", + "uri": "https://ltho.s3.amazonaws.com/twohustlers%2Fefd9dcf8-03c1-42c3-b6cc-3472acf908e4.jpg", "caption": "" } ], "thumbnail": { - "uri": "https://ltho.s3.amazonaws.com/twohustlers%2F94c3bb9d-7d11-43f7-be86-5348a677845f.jpg", + "uri": "", "caption": "" }, "__index": "1" diff --git a/site/public/assets/javascripts/_env.js b/site/public/assets/javascripts/_env.js index aae60b9..60f6528 100644 --- a/site/public/assets/javascripts/_env.js +++ b/site/public/assets/javascripts/_env.js @@ -431,13 +431,14 @@ function build_gallery () { }) gallery.on("cellSelect", function(){ + console.log("DUH") $caption.html( $(gallery.selectedElement).data("caption") ) videos.forEach(function(player){ player.api('pause') }) }) gallery.on("settle", function(){ - gallery && $caption.html( $(gallery.selectedElement).data("caption") ) + $caption.html( $(gallery.selectedElement).data("caption") ) }) gallery.on("staticClick", function(e){ // console.log(e) diff --git a/site/public/assets/javascripts/vendor/flickity.pkgd.js b/site/public/assets/javascripts/vendor/flickity.pkgd.js index 6389014..0471fa5 100644 --- a/site/public/assets/javascripts/vendor/flickity.pkgd.js +++ b/site/public/assets/javascripts/vendor/flickity.pkgd.js @@ -1,6 +1,10 @@ /*! - * Flickity PACKAGED v0.2.3 + * Flickity PACKAGED v1.0.1 * Touch, responsive, flickable galleries + * + * Licensed GPLv3 for open source use + * or Flickity Commercial License for commercial use + * * http://flickity.metafizzy.co * Copyright 2015 Metafizzy */ @@ -1176,7 +1180,7 @@ if ( typeof define === 'function' && define.amd ) { })( window ); /** - * matchesSelector v1.0.2 + * matchesSelector v1.0.3 * matchesSelector( element, '.selector' ) * MIT license */ @@ -1189,6 +1193,10 @@ if ( typeof define === 'function' && define.amd ) { var matchesMethod = ( function() { + // check for the standard method name first + if ( ElemProto.matches ) { + return 'matches'; + } // check un-prefixed if ( ElemProto.matchesSelector ) { return 'matchesSelector'; @@ -1280,7 +1288,7 @@ if ( typeof define === 'function' && define.amd ) { })( Element.prototype ); /** - * Fizzy UI utils v0.1.1 + * Fizzy UI utils v1.0.1 * MIT license */ @@ -1380,7 +1388,7 @@ utils.indexOf = Array.prototype.indexOf ? function( ary, obj ) { // ----- removeFrom ----- // -utils.removeFrom = function( obj, ary ) { +utils.removeFrom = function( ary, obj ) { var index = utils.indexOf( ary, obj ); if ( index != -1 ) { ary.splice( index, 1 ); @@ -1499,14 +1507,12 @@ utils.debounceMethod = function( _class, methodName, threshold ) { // ----- htmlInit ----- // -var jQuery = window.jQuery; - // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/ -function toDashed( str ) { +utils.toDashed = function( str ) { return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) { return $1 + '-' + $2; }).toLowerCase(); -} +}; var console = window.console; /** @@ -1516,7 +1522,7 @@ var console = window.console; */ utils.htmlInit = function( WidgetClass, namespace ) { docReady( function() { - var dashedNamespace = toDashed( namespace ); + var dashedNamespace = utils.toDashed( namespace ); var elems = document.querySelectorAll( '.js-' + dashedNamespace ); var dataAttr = 'data-' + dashedNamespace + '-options'; @@ -1538,6 +1544,7 @@ utils.htmlInit = function( WidgetClass, namespace ) { // initialize var instance = new WidgetClass( elem, options ); // make available via $().data('layoutname') + var jQuery = window.jQuery; if ( jQuery ) { jQuery.data( elem, namespace, instance ); } @@ -1893,8 +1900,12 @@ return proto; })); /*! - * Flickity v0.2.3 + * Flickity v1.0.1 * Touch, responsive, flickable galleries + * + * Licensed GPLv3 for open source use + * or Flickity Commercial License for commercial use + * * http://flickity.metafizzy.co * Copyright 2015 Metafizzy */ @@ -1999,7 +2010,8 @@ Flickity.defaults = { // initialIndex: 0, percentPosition: true, resize: true, - selectedAttraction: 0.025 + selectedAttraction: 0.025, + setGallerySize: true // watchCSS: false, // wrapAround: false }; @@ -2075,7 +2087,6 @@ Flickity.prototype.activate = function() { this.getSize(); // get cells from children this.reloadCells(); - this.setContainerSize(); if ( this.options.accessibility ) { // allow element to focusable @@ -2109,7 +2120,7 @@ Flickity.prototype.reloadCells = function() { this.cells = this._makeCells( this.slider.children ); this.positionCells(); this._getWrapShiftCells(); - this.setContainerSize(); + this.setGallerySize(); }; /** @@ -2215,8 +2226,10 @@ Flickity.prototype.setCellAlign = function() { this.cellAlign = shorthand ? shorthand[ this.originSide ] : this.options.cellAlign; }; -Flickity.prototype.setContainerSize = function() { - this.viewport.style.height = this.maxCellHeight + 'px'; +Flickity.prototype.setGallerySize = function() { + if ( this.options.setGallerySize ) { + this.viewport.style.height = this.maxCellHeight + 'px'; + } }; Flickity.prototype._getWrapShiftCells = function() { @@ -2267,13 +2280,21 @@ Flickity.prototype._containCells = function() { var lastCell = this.getLastCell(); var contentWidth = this.slideableWidth - lastCell.size[ endMargin ]; var endLimit = contentWidth - this.size.innerWidth * ( 1 - this.cellAlign ); + // content is less than gallery size + var isContentSmaller = contentWidth < this.size.innerWidth; // contain each cell target for ( var i=0, len = this.cells.length; i < len; i++ ) { var cell = this.cells[i]; // reset default target cell.setDefaultTarget(); - cell.target = Math.max( cell.target, this.cursorPosition + firstCellStartMargin ); - cell.target = Math.min( cell.target, endLimit ); + if ( isContentSmaller ) { + // all cells fit inside gallery + cell.target = contentWidth * this.cellAlign; + } else { + // contain to bounds + cell.target = Math.max( cell.target, this.cursorPosition + firstCellStartMargin ); + cell.target = Math.min( cell.target, endLimit ); + } } }; @@ -2293,7 +2314,7 @@ Flickity.prototype.dispatchEvent = function( type, event, args ) { if ( event ) { // create jQuery event var $event = jQuery.Event( event ); - $event.type = type + '.flickity'; + $event.type = type; this.$element.trigger( $event, args ); } else { // just trigger with type if no event available @@ -2330,7 +2351,7 @@ Flickity.prototype.select = function( index, isWrap ) { this.selectedIndex = index; this.setSelectedCell(); this.startAnimation(); - this.dispatchEvent('select'); + this.dispatchEvent('cellSelect'); } }; @@ -2448,7 +2469,7 @@ Flickity.prototype.resize = function() { } this.positionCells(); this._getWrapShiftCells(); - this.setContainerSize(); + this.setGallerySize(); this.positionSliderAtSelected(); }; @@ -2554,6 +2575,9 @@ Flickity.prototype.destroy = function() { eventie.unbind( window, 'resize', this ); } this.emit('destroy'); + if ( jQuery && this.$element ) { + jQuery.removeData( this.element, 'flickity' ); + } delete this.element.flickityGUID; delete instances[ this.guid ]; }; @@ -2599,7 +2623,7 @@ return Flickity; })); /*! - * Unipointer v0.1.0 + * Unipointer v1.1.0 * base class for doing one thing with pointer event * MIT license */ @@ -2736,7 +2760,7 @@ Unipointer.prototype._pointerDown = function( event, pointer ) { Unipointer.prototype.pointerDown = function( event, pointer ) { this._bindPostStartEvents( event ); - this.emitEvent( 'pointerDown', [ this, event, pointer ] ); + this.emitEvent( 'pointerDown', [ event, pointer ] ); }; // hash of events to be bound after start event @@ -2813,7 +2837,7 @@ Unipointer.prototype._pointerMove = function( event, pointer ) { // public Unipointer.prototype.pointerMove = function( event, pointer ) { - this.emitEvent( 'pointerMove', [ this, event, pointer ] ); + this.emitEvent( 'pointerMove', [ event, pointer ] ); }; // ----- end event ----- // @@ -2850,7 +2874,7 @@ Unipointer.prototype._pointerUp = function( event, pointer ) { // public Unipointer.prototype.pointerUp = function( event, pointer ) { - this.emitEvent( 'pointerUp', [ this, event, pointer ] ); + this.emitEvent( 'pointerUp', [ event, pointer ] ); }; // ----- pointer done ----- // @@ -2896,7 +2920,7 @@ Unipointer.prototype._pointerCancel = function( event, pointer ) { // public Unipointer.prototype.pointerCancel = function( event, pointer ) { - this.emitEvent( 'pointerCancel', [ this, event, pointer ] ); + this.emitEvent( 'pointerCancel', [ event, pointer ] ); }; // ----- ----- // @@ -2916,7 +2940,7 @@ return Unipointer; })); /*! - * Unidragger v0.2.0 + * Unidragger v1.1.3 * Draggable base class * MIT license */ @@ -3050,13 +3074,6 @@ var disableImgOndragstart = !isIE8 ? noop : function( handle ) { // ----- start event ----- // -var allowTouchstartNodes = Unidragger.allowTouchstartNodes = { - INPUT: true, - A: true, - BUTTON: true, - SELECT: true -}; - /** * pointer start * @param {Event} event @@ -3071,7 +3088,7 @@ Unidragger.prototype.pointerDown = function( event, pointer ) { } // bind move and end events this._bindPostStartEvents( event ); - this.emitEvent( 'pointerDown', [ this, event, pointer ] ); + this.emitEvent( 'pointerDown', [ event, pointer ] ); }; // base pointer down logic @@ -3079,11 +3096,10 @@ Unidragger.prototype._dragPointerDown = function( event, pointer ) { // track to see when dragging starts this.pointerDownPoint = Unipointer.getPointerPoint( pointer ); + // prevent default, unless touchstart or - if ( !isTouchstartNode && targetNodeName != 'SELECT' ) { + if ( !isTouchstart && targetNodeName != 'SELECT' ) { preventDefaultEvent( event ); } }; @@ -3097,7 +3113,7 @@ Unidragger.prototype._dragPointerDown = function( event, pointer ) { */ Unidragger.prototype.pointerMove = function( event, pointer ) { var moveVector = this._dragPointerMove( event, pointer ); - this.emitEvent( 'pointerMove', [ this, event, pointer, moveVector ] ); + this.emitEvent( 'pointerMove', [ event, pointer, moveVector ] ); this._dragMove( event, pointer, moveVector ); }; @@ -3129,7 +3145,7 @@ Unidragger.prototype.hasDragStarted = function( moveVector ) { * @param {Event or Touch} pointer */ Unidragger.prototype.pointerUp = function( event, pointer ) { - this.emitEvent( 'pointerUp', [ this, event, pointer ] ); + this.emitEvent( 'pointerUp', [ event, pointer ] ); this._dragPointerUp( event, pointer ); }; @@ -3155,7 +3171,7 @@ Unidragger.prototype._dragStart = function( event, pointer ) { }; Unidragger.prototype.dragStart = function( event, pointer ) { - this.emitEvent( 'dragStart', [ this, event, pointer ] ); + this.emitEvent( 'dragStart', [ event, pointer ] ); }; // dragMove @@ -3169,7 +3185,8 @@ Unidragger.prototype._dragMove = function( event, pointer, moveVector ) { }; Unidragger.prototype.dragMove = function( event, pointer, moveVector ) { - this.emitEvent( 'dragMove', [ this, event, pointer, moveVector ] ); + preventDefaultEvent( event ); + this.emitEvent( 'dragMove', [ event, pointer, moveVector ] ); }; // dragEnd @@ -3186,7 +3203,7 @@ Unidragger.prototype._dragEnd = function( event, pointer ) { }; Unidragger.prototype.dragEnd = function( event, pointer ) { - this.emitEvent( 'dragEnd', [ this, event, pointer ] ); + this.emitEvent( 'dragEnd', [ event, pointer ] ); }; // ----- onclick ----- // @@ -3202,15 +3219,16 @@ Unidragger.prototype.onclick = function( event ) { // triggered after pointer down & up with no/tiny movement Unidragger.prototype._staticClick = function( event, pointer ) { - // allow click in text input - if ( event.target.nodeName == 'INPUT' && event.target.type == 'text' ) { + // allow click in s and @@ -160,6 +163,8 @@
+ + @@ -170,13 +175,24 @@ + +
    {% for image in spec.value %} - {% if image.token %} + {% if image.type and (image.type == "vimeo" or image.type == "youtube" or image.type == "video") %}
  1. + + @@ -185,11 +201,22 @@
  2. + {% elsif image.type and image.type == "link" %} + {% else %}
  3. + - {{image.caption}} + + {{image.caption | strip_html}}
  4. {% endif %} @@ -210,7 +237,7 @@
  5. - {{image.caption}} +
  6. @@ -220,7 +247,7 @@
  7. - {{image.caption}} + {{image.caption | strip_html}}
  8. {% endfor %} @@ -238,7 +265,7 @@ -- cgit v1.2.3-70-g09d2 From 3ae6b122cbb6e3491677fd79e2d0c1b1a506db93 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 4 Apr 2016 19:43:34 -0400 Subject: Improve response for mp4 videos in parser --- package.json | 2 +- themes/okadmin/public/js/parser.js | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) (limited to 'themes') diff --git a/package.json b/package.json index faf3cc9..09b24c8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "okcms", - "version": "0.1.19", + "version": "0.1.23", "description": "great", "main": "app/index.js", "scripts": { diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js index 95b391c..6c964f7 100644 --- a/themes/okadmin/public/js/parser.js +++ b/themes/okadmin/public/js/parser.js @@ -31,6 +31,8 @@ var Parser = { regex: /\.(mp4|webm)(\?.*)?$/i, fetch: function(url, done) { var video = document.createElement("video") + var url_parts = url.replace(/\?.*$/, "").split("/") + var filename = url_parts[ url_parts.length-1 ] video.addEventListener("loadedmetadata", function(){ var width = video.videoWidth, height = video.videoHeight video = null @@ -38,8 +40,8 @@ var Parser = { url: url, type: "video", token: "", - thumbnail: "", - title: "", + thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/video.png", + title: filename, width: width, height: height, }) -- cgit v1.2.3-70-g09d2 From cd929e1c38c02c1d048abe702c04c7d4d6188011 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 5 Apr 2016 11:46:47 -0400 Subject: Fix sorting bug when saving --- app/node_modules/okschema/index.js | 23 ++++++++++++++++++++--- examples/db.json | 20 +++++++++++++++++--- examples/index.js | 2 +- themes/okadmin/public/js/app.js | 4 ++++ themes/okadmin/public/js/parser.js | 2 +- themes/okadmin/templates/partials/inputs.liquid | 2 ++ 6 files changed, 45 insertions(+), 8 deletions(-) (limited to 'themes') diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index cf041fb..8162fd4 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -174,8 +174,7 @@ function OKSchema(spec) { }); } -OKSchema.prototype.checkDataForMissingArrays = function(data) { - data = data || {}; +OKSchema.prototype.fixMissingLists = function(data) { var spec = this.spec; // The qs body-parser module does not have a way to represent @@ -189,10 +188,22 @@ OKSchema.prototype.checkDataForMissingArrays = function(data) { }) } +OKSchema.prototype.fixIndexField = function(data) { + // Likewise numbers always come in as strings. The field used to sort + // records, __index, is of type "meta", so the parseFloat in + // assertValid (below) never fires and we end up with sorting issues. + if (data.__index && typeof data.__index == "string") { + var __index = parseInt(data.__index) + if (! isNaN(__index)) { + data.__index = __index + } + } +} + OKSchema.prototype.assertValid = function(data) { data = data || {}; var spec = this.spec; - this.checkDataForMissingArrays(data) + // Run through custom validators, they'll throw if invalid Object.keys(data).forEach(function(prop) { var type = spec[prop].type; @@ -210,6 +221,12 @@ OKSchema.prototype.assertValid = function(data) { if (!result.valid) { throw result.errors; } + + // Fix various issues with our data, having to do + // with use of the "qs" body-parser module. + // TODO: just send JSON? + this.fixMissingLists(data) + this.fixIndexField(data) }; /** diff --git a/examples/db.json b/examples/db.json index bdad6c8..1d045c3 100644 --- a/examples/db.json +++ b/examples/db.json @@ -150,8 +150,8 @@ ], "test": [ { - "id": "test", - "title": "tEst", + "id": "red", + "title": "Red", "media": [ { "uri": "http://asdf.us/", @@ -159,8 +159,22 @@ "type": "link" } ], - "__index": "0", + "__index": 0, "dateCreated": "Mon, 28 Mar 2016 23:02:45 GMT" + }, + { + "id": "blue", + "title": "Blue", + "__index": 2, + "dateCreated": "Tue, 05 Apr 2016 15:17:54 GMT", + "media": [] + }, + { + "id": "green", + "title": "Green", + "__index": 1, + "dateCreated": "Tue, 05 Apr 2016 15:17:57 GMT", + "media": [] } ] } \ No newline at end of file diff --git a/examples/index.js b/examples/index.js index 4bf385f..81d9241 100644 --- a/examples/index.js +++ b/examples/index.js @@ -4,7 +4,7 @@ var app = okcms.createApp({ root: 'public', - debug: false, + debug: true, schemas: { page: { diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index e7f902d..e79f704 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -56,6 +56,7 @@ var OKAdmin = function(){ $el.addClass("loaded") $el.find(".video-type").val( media.type ) $el.find(".video-token").val( media.token ) + $el.find(".video-uri").val( media.uri ) $el.find(".video-title").val( media.title ) $el.find(".video-thumb").val( media.thumbnail ) $el.find(".video-width").val( media.width ) @@ -125,8 +126,11 @@ var OKAdmin = function(){ $el.parent().addClass("loaded") $el.parent().find(".video-type").val( media.type ) $el.parent().find(".video-token").val( media.token ) + $el.parent().find(".video-uri").val( media.uri ) $el.parent().find(".video-title").val( media.title ) $el.parent().find(".video-thumb").val( media.thumbnail ) + $el.parent().find(".video-width").val( media.width ) + $el.parent().find(".video-height").val( media.height ) }) })) diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js index 6c964f7..b4a087d 100644 --- a/themes/okadmin/public/js/parser.js +++ b/themes/okadmin/public/js/parser.js @@ -39,7 +39,7 @@ var Parser = { done({ url: url, type: "video", - token: "", + token: url, thumbnail: "http://okfocus.s3.amazonaws.com/misc/okcms/video.png", title: filename, width: width, diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index fa03e48..e618c61 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -164,6 +164,7 @@
    + @@ -192,6 +193,7 @@
    + -- cgit v1.2.3-70-g09d2 From 56580705e3a62eaf1c498c1c0456fc33fe3b2f76 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Tue, 5 Apr 2016 14:05:35 -0400 Subject: broaden media support --- app/node_modules/okserver/index.js | 2 +- app/node_modules/okservices/oks3/index.js | 54 ++++++++++++++++++-- examples/db.json | 29 ++++++++++- examples/index.js | 5 ++ package.json | 2 +- themes/okadmin/public/css/main.css | 3 ++ themes/okadmin/public/js/app.js | 18 ++++++- themes/okadmin/public/js/parser.js | 31 +++++++++-- themes/okadmin/public/js/upload.js | 61 ++++++++++++++++------ themes/okadmin/templates/partials/inputs.liquid | 68 ++++++++++++++++++------- 10 files changed, 226 insertions(+), 47 deletions(-) (limited to 'themes') diff --git a/app/node_modules/okserver/index.js b/app/node_modules/okserver/index.js index ee1b4fb..3428565 100644 --- a/app/node_modules/okserver/index.js +++ b/app/node_modules/okserver/index.js @@ -60,7 +60,7 @@ function OKServer(options) { app.use(router); // Add services if (services.s3) { - app.use('/_services/image', services.s3.middleware()); + app.use('/_services/s3', services.s3.middleware()); } if (services.twitter) { app.use('/_services/twitter', services.twitter.middleware()) diff --git a/app/node_modules/okservices/oks3/index.js b/app/node_modules/okservices/oks3/index.js index d556c20..dc0ca19 100644 --- a/app/node_modules/okservices/oks3/index.js +++ b/app/node_modules/okservices/oks3/index.js @@ -4,7 +4,7 @@ var skipperS3 = require('skipper-s3') // Hack to prevent this god-forsaken module from crashing our shit var d = require('domain').create() d.on('error', function (err) { - console.error('Stupid error in S3 upload. Image upload probably prematurely canceled') + console.error('Stupid error in S3 upload. Upload probably prematurely canceled') }) function OKS3(options) { @@ -20,9 +20,9 @@ function OKS3(options) { router.use(skipper()); - router.post('/', function(req, res) { - // req should have a method `file` on it which is - // provided by skipper. Use that to do AWS stuff + // req should have a method `file` on it which is + // provided by skipper. Use that to do AWS stuff + router.post('/image', function(req, res) { d.run(function () { req.file('image').upload({ adapter: skipperS3, @@ -38,7 +38,51 @@ function OKS3(options) { if (err) res.status(500).send(err) res.json(uploadedFiles); }); - }) + }); + }); + + router.post('/audio', function(req, res) { + d.run(function () { + if (! options.s3.allowAudioUploads) { + return res.status(500).json({ error: "audio uploading not permitted" }) + } + req.file('audio').upload({ + adapter: skipperS3, + key: options.s3.key, + secret: options.s3.secret, + bucket: options.s3.bucket, + dirname: options.s3.dirname, + maxBytes: options.s3.maxbytesAudio, + headers: { + 'x-amz-acl': 'public-read' + } + }, function (err, uploadedFiles) { + if (err) res.status(500).send(err) + res.json(uploadedFiles); + }); + }); + }); + + router.post('/video', function(req, res) { + d.run(function () { + if (! options.s3.allowVideoUploads) { + return res.status(500).json({ error: "video uploading not permitted" }) + } + req.file('video').upload({ + adapter: skipperS3, + key: options.s3.key, + secret: options.s3.secret, + bucket: options.s3.bucket, + dirname: options.s3.dirname, + maxBytes: options.s3.maxbytesVideo, + headers: { + 'x-amz-acl': 'public-read' + } + }, function (err, uploadedFiles) { + if (err) res.status(500).send(err) + res.json(uploadedFiles); + }); + }); }); this._middleware = router; diff --git a/examples/db.json b/examples/db.json index 1d045c3..3650355 100644 --- a/examples/db.json +++ b/examples/db.json @@ -174,7 +174,34 @@ "title": "Green", "__index": 1, "dateCreated": "Tue, 05 Apr 2016 15:17:57 GMT", - "media": [] + "media": [ + { + "type": "video", + "token": "https://ltho.s3.amazonaws.com/ee12b137-1c8a-400a-87e3-89cbee7b4da6.mp4", + "uri": "", + "width": "400", + "height": "400", + "title": "ee12b137-1c8a-400a-87e3-89cbee7b4da6.mp4", + "thumb": "http://okfocus.s3.amazonaws.com/misc/okcms/video.png" + }, + { + "type": "youtube", + "token": "y_35kXCQxN4", + "uri": "", + "width": "640", + "height": "360", + "title": "dëf lëöpär¨d¨¨¨¨<>~!@~#!:I!@", + "thumb": "http://i.ytimg.com/vi/y_35kXCQxN4/hqdefault.jpg" + }, + { + "type": "audio", + "token": "http://asdf.us/clouds35.mp3", + "uri": "", + "duration": "225.645792", + "title": "clouds35.mp3", + "thumb": "http://okfocus.s3.amazonaws.com/misc/okcms/video.png" + } + ] } ] } \ No newline at end of file diff --git a/examples/index.js b/examples/index.js index 81d9241..e9de0a3 100644 --- a/examples/index.js +++ b/examples/index.js @@ -40,6 +40,11 @@ var app = okcms.createApp({ key: process.env.S3_KEY, secret: process.env.S3_SECRET, bucket: process.env.S3_BUCKET, + allowVideoUploads: true, + allowAudioUploads: true, + maxsize: 200, + maxsizeVideo: 150000000, + maxsizeAudio: 150000000, } }, diff --git a/package.json b/package.json index c95a2bc..c3a7280 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "okcms", - "version": "0.1.24", + "version": "0.1.27", "description": "great", "main": "app/index.js", "scripts": { diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index 2f2d376..15b8781 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -303,6 +303,7 @@ button, input[type=submit] { width: 15em; height: 6em; } +.main.resource form .audio-element input[type=text], .main.resource form .video-element input[type=text] { width: 15em; } @@ -353,10 +354,12 @@ button, input[type=submit] { margin: 0; padding: 0; cursor: pointer; } +.audio-element:hover .remove, .video-element:hover .remove, .image-element:hover .remove { display: block; } +.audio-element .remove:hover, .video-element .remove:hover, .image-element .remove:hover { color: red; diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index e79f704..a12f517 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -5,7 +5,8 @@ var OKAdmin = function(){ var parent = this var uploader = new OKUpload () uploader.bind( this ) - uploader.add = function(url){ + uploader.add = function(media){ + var url = media.url var imageTemplate = $(".image-template", parent).html() var $el = $(imageTemplate) $el.find(".uri").val(url) @@ -46,7 +47,7 @@ var OKAdmin = function(){ $el.find("img").attr("src", url) $("ol", parent).prepend($el) } - uploader.addVideo = function(media){ + uploader.addMedia = function(media){ switch (media.type) { case 'youtube': case 'vimeo': @@ -64,6 +65,19 @@ var OKAdmin = function(){ $el.find("img").attr("src", media.thumbnail ) $("ol", parent).prepend($el) break + case 'audio': + var audioTemplate = $(".audio-template", parent).html() + var $el = $(audioTemplate) + $el.addClass("loaded") + $el.find(".audio-type").val( media.type ) + $el.find(".audio-token").val( media.token ) + $el.find(".audio-uri").val( media.uri ) + $el.find(".audio-title").val( media.title ) + $el.find(".audio-thumb").val( media.thumbnail ) + $el.find(".audio-duration").val( media.duration ) + $el.find("img").attr("src", media.thumbnail ) + $("ol", parent).prepend($el) + break case 'link': var linkTemplate = $(".link-template", parent).html() var $el = $(linkTemplate) diff --git a/themes/okadmin/public/js/parser.js b/themes/okadmin/public/js/parser.js index b4a087d..4ab9a6c 100644 --- a/themes/okadmin/public/js/parser.js +++ b/themes/okadmin/public/js/parser.js @@ -52,6 +52,31 @@ var Parser = { tag: function (media) { return '
    {% elsif type == 'image' %}
    @@ -47,8 +47,8 @@
    - - {{spec.value.caption}} + + {{spec.value.caption | escape}}
    @@ -78,7 +78,7 @@ {% elsif type == 'tag-list' %}
    @@ -90,13 +90,13 @@
    @@ -142,8 +142,8 @@
    - - + +
    @@ -177,6 +177,23 @@ + + -- cgit v1.2.3-70-g09d2 From d9d01a57708e3bf21833992c518f5f08e83f0d53 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 7 Apr 2016 17:26:33 -0400 Subject: Fix disabled check in index page --- themes/okadmin/templates/index.liquid | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'themes') diff --git a/themes/okadmin/templates/index.liquid b/themes/okadmin/templates/index.liquid index ae30bc8..8255d99 100644 --- a/themes/okadmin/templates/index.liquid +++ b/themes/okadmin/templates/index.liquid @@ -27,9 +27,9 @@
      {% for data in members %}
    1. - {% if data.disabled == 'true' %} {% endif %} + {% if data.disabled %} {% endif %} {{data.title}} - {% if data.disabled == 'true' %} {% endif %} + {% if data.disabled %} {% endif %}
    2. @@ -51,9 +51,9 @@
        {% for data in resource.data %}
      1. - {% if data.disabled == 'true' %} {% endif %} + {% if data.disabled %} {% endif %} {{data.title}} - {% if data.disabled == 'true' %} {% endif %} + {% if data.disabled %} {% endif %}
      2. -- cgit v1.2.3-70-g09d2 From 7f999404650488dc5929384250e86117f5109c9a Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 11 Apr 2016 13:12:32 -0400 Subject: fix typo --- themes/okadmin/templates/partials/inputs.liquid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'themes') diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 0cd7f6b..de134c3 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -153,7 +153,7 @@ - + -- cgit v1.2.3-70-g09d2 From 180cf3eaa829fd04f759488d76641c4656caa245 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Mon, 11 Apr 2016 14:20:33 -0400 Subject: rewrite file upload code to use knox directly --- app/node_modules/okserver/index.js | 2 + app/node_modules/okservices/oks3/index.js | 136 +++++++++++++++----------- app/node_modules/okservices/oks3/package.json | 5 +- app/node_modules/okservices/oks3/upload.js | 80 +++++++++++++++ examples/index.js | 7 +- themes/okadmin/public/js/upload.js | 2 +- 6 files changed, 166 insertions(+), 66 deletions(-) create mode 100644 app/node_modules/okservices/oks3/upload.js (limited to 'themes') diff --git a/app/node_modules/okserver/index.js b/app/node_modules/okserver/index.js index 3428565..302911d 100644 --- a/app/node_modules/okserver/index.js +++ b/app/node_modules/okserver/index.js @@ -52,6 +52,8 @@ function OKServer(options) { * other middleware. */ + // Disable silly express header + app.disable('x-powered-by') // Serve user static files app.use(express.static(root)); // Serve admin interface static files diff --git a/app/node_modules/okservices/oks3/index.js b/app/node_modules/okservices/oks3/index.js index 34c5840..c636308 100644 --- a/app/node_modules/okservices/oks3/index.js +++ b/app/node_modules/okservices/oks3/index.js @@ -1,5 +1,5 @@ -var skipper = require('skipper'); -var skipperS3 = require('skipper-s3') +var upload = require("./upload") +var multer = require('multer') // Hack to prevent this god-forsaken module from crashing our shit var d = require('domain').create() @@ -20,7 +20,6 @@ function OKS3(options) { if (!options.s3.audio) options.s3.audio = {} if (!options.s3.video) options.s3.video = {} -/* // TODO: maxBytes property doesn't work - if you upload a large file, // it will just hang until you reload the browser, and then CRASH. @@ -34,85 +33,104 @@ function OKS3(options) { if (! ('maxbytes' in options.s3.audio)) options.s3.audio.maxbytes = options.s3.maxbytes } -*/ - if (options.s3.image.preserveFilename) - options.s3.image.preserveFilename = preserveFilename - if (options.s3.video.preserveFilename) - options.s3.video.preserveFilename = preserveFilename - if (options.s3.audio.preserveFilename) - options.s3.audio.preserveFilename = preserveFilename + if (typeof options.s3.image.allowed !== "boolean") + options.s3.image.allowed = true + if (typeof options.s3.video.allowed !== "boolean") + options.s3.video.allowed = false + if (typeof options.s3.audio.allowed !== "boolean") + options.s3.audio.allowed = false + + upload.init({ + key: options.s3.key, + secret: options.s3.secret, + bucket: options.s3.bucket, + }) var express = options.express; var router = express.Router(); - router.use(skipper()); + var mult = multer() - // req should have a method `file` on it which is - // provided by skipper. Use that to do AWS stuff - router.post('/image', function(req, res) { + router.post('/image', mult.single('image'), function(req, res) { d.run(function () { - var skip = req.file('image').upload({ - adapter: skipperS3, - key: options.s3.key, - secret: options.s3.secret, - bucket: options.s3.bucket, + + if (! options.s3.image.allowed) { + return res.status(500).json({ error: "Image uploading not permitted" }) + } + + upload.put({ + file: req.file, + preserveFilename: options.s3.image.preserveFilename, dirname: options.s3.dirname, - // maxBytes: options.s3.image.maxbytes, - saveAs: options.s3.image.preserveFilename, - headers: { - 'x-amz-acl': 'public-read' + types: { + 'image/gif': 'gif', + 'image/jpeg': 'jpg', + 'image/jpg': 'jpg', + 'image/png': 'png', + }, + unacceptable: function(err){ + res.json({ error: err }) + }, + success: function(url){ + res.json({ url: url }) } - }, function (err, uploadedFiles) { - if (err) return res.status(500).send(err) - res.json(uploadedFiles); - }); + }) + }); }); - router.post('/audio', function(req, res) { + router.post('/audio', mult.single('audio'), function(req, res) { d.run(function () { - if (! options.s3.allowAudioUploads) { - return res.status(500).json({ error: "audio uploading not permitted" }) + + if (! options.s3.image.allowed) { + return res.status(500).json({ error: "Audio uploading not permitted" }) } - req.file('audio').upload({ - adapter: skipperS3, - key: options.s3.key, - secret: options.s3.secret, - bucket: options.s3.bucket, + + upload.put({ + file: req.file, + preserveFilename: options.s3.audio.preserveFilename, dirname: options.s3.dirname, - // maxBytes: options.s3.audio.maxbytes, - saveAs: options.s3.audio.preserveFilename, - headers: { - 'x-amz-acl': 'public-read' + types: { + 'audio/mp3': 'mp3', + 'audio/mpeg': 'mp3', + 'audio/wav': 'wav', + 'audio/flac': 'flac', + }, + unacceptable: function(err){ + res.json({ error: err }) + }, + success: function(url){ + res.json({ url: url }) } - }, function (err, uploadedFiles) { - if (err) res.status(500).send(err) - res.json(uploadedFiles); - }); + }) + }); }); - router.post('/video', function(req, res) { + router.post('/video', mult.single('video'), function(req, res) { d.run(function () { - if (! options.s3.allowVideoUploads) { - return res.status(500).json({ error: "video uploading not permitted" }) + + if (! options.s3.image.allowed) { + return res.status(500).json({ error: "Video uploading not permitted" }) } - req.file('video').upload({ - adapter: skipperS3, - key: options.s3.key, - secret: options.s3.secret, - bucket: options.s3.bucket, + + upload.put({ + file: req.file, + preserveFilename: options.s3.video.preserveFilename, dirname: options.s3.dirname, - // maxBytes: options.s3.video.maxbytes, - saveAs: options.s3.video.preserveFilename, - headers: { - 'x-amz-acl': 'public-read' + types: { + 'video/mp4': 'mp4', + 'video/webm': 'webm', + }, + unacceptable: function(err){ + res.json({ error: err }) + }, + success: function(url){ + res.json({ url: url }) } - }, function (err, uploadedFiles) { - if (err) res.status(500).send(err) - res.json(uploadedFiles); - }); + }) + }); }); diff --git a/app/node_modules/okservices/oks3/package.json b/app/node_modules/okservices/oks3/package.json index 19a2d2a..35bb4ce 100644 --- a/app/node_modules/okservices/oks3/package.json +++ b/app/node_modules/okservices/oks3/package.json @@ -9,7 +9,8 @@ "author": "OKFocus", "license": "None", "dependencies": { - "skipper": "^0.5.9", - "skipper-s3": "^0.5.6" + "knox": "^0.9.2", + "multer": "^1.1.0", + "node-uuid": "^1.4.7", } } diff --git a/app/node_modules/okservices/oks3/upload.js b/app/node_modules/okservices/oks3/upload.js new file mode 100644 index 0000000..6b16d61 --- /dev/null +++ b/app/node_modules/okservices/oks3/upload.js @@ -0,0 +1,80 @@ + +var knox = require('knox') +var moment = require('moment') +var uuid = require('node-uuid') + +var s3 + +var acceptableuploadTypes = { + 'image/gif': 'gif', + 'image/jpeg': 'jpg', + 'image/jpg': 'jpg', + 'image/png': 'png', +} + +module.exports = {} + +module.exports.init = function (opt){ + s3 = knox.createClient({ + key: opt.key, + secret: opt.secret, + bucket: opt.bucket, + }) +} + +module.exports.put = function (opt) { + var filename + var err + var now = new Date() + + var file = opt.file + + var types = opt.types || acceptableuploadTypes + var extension = types[file.mimetype] + + if (opt.preserveFilename) { + filename = file.originalname + } + else { + filename = uuid.v1() + "." + extension; + } + + var remote_path = "/" + opt.dirname + "/" + filename + + if (! extension) { + err = "Unacceptable filetype." + } + else if (opt.maxSize && file.size > opt.maxSize) { + err = "File too large. Uploads can be a maximum of " + opt.maxSize + " bytes." + } + + if (err) { + console.error(">>>", err) + opt.unacceptable && opt.unacceptable(err) + return + } + + opt.acceptable && opt.acceptable(err) + + // console.log("upload >", remote_path) + s3.putBuffer(file.buffer, remote_path, { + 'Content-Length': file.size, + 'Content-Type': file.mimetype, + 'x-amz-acl': 'public-read' + }, function(err, s3res) { + if (err || s3res.statusCode !== 200) { + console.error(err); + if (s3res && s3res.resume) { + s3res.resume() + } + return; + } + + var file_url = s3res.url || s3res.req.url + + opt.success && opt.success(file_url) + }).on('error', function(err, s3res){ + console.error(err) + s3res && s3res.resume && s3res.resume() + }) +} diff --git a/examples/index.js b/examples/index.js index fe37954..31ae8d2 100644 --- a/examples/index.js +++ b/examples/index.js @@ -42,10 +42,9 @@ var app = okcms.createApp({ secret: process.env.S3_SECRET, bucket: process.env.S3_BUCKET, dirname: "okcms-example", - // TODO: maxbytes stuff isn't working, need to change underlying module - image: { preserveFilename: false, maxbytes: 20000 }, - video: { preserveFilename: true, maxbytes: 0 }, - audio: { preserveFilename: true, maxbytes: 150000000 }, + image: { allowed: true, preserveFilename: false, maxbytes: 2*1024*1024 }, + video: { allowed: true, preserveFilename: true, maxbytes: 200*1024*1024 }, + audio: { allowed: true, preserveFilename: true, maxbytes: 100*1024*1024 }, } }, diff --git a/themes/okadmin/public/js/upload.js b/themes/okadmin/public/js/upload.js index 44a34b5..da23b1b 100644 --- a/themes/okadmin/public/js/upload.js +++ b/themes/okadmin/public/js/upload.js @@ -167,7 +167,7 @@ OKUpload.prototype.success = function(data){ console.log(data.error) return } - var url = data[0].extra.Location.replace(/%2F/, '\/') + var url = data.url console.log(url) this.parse(url) } -- cgit v1.2.3-70-g09d2 From 5922279561c1998a3e158c26f951348f4c031928 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 14 Apr 2016 14:17:00 -0400 Subject: support adding custom services per-project --- app/index.js | 42 ++++++++++++++++++------------- app/node_modules/okserver/index.js | 11 +++----- app/node_modules/okservices/oks3/index.js | 3 --- package.json | 5 ++-- themes/okadmin/public/js/upload.js | 3 --- 5 files changed, 32 insertions(+), 32 deletions(-) (limited to 'themes') diff --git a/app/index.js b/app/index.js index 1a8f97e..7fd88f4 100644 --- a/app/index.js +++ b/app/index.js @@ -94,19 +94,30 @@ function OKCMS(options) { errorHandler); // Create services - if (serviceConfig.s3) { - var s3Service = OKS3Service({ - express: express, - s3: serviceConfig.s3, - }); - } - - if (serviceConfig.twitter) { - var twitterService = OKTwitterService({ - express: express, - credentials: serviceConfig.twitter, - }) - } + var services = {} + Object.keys(serviceConfig).forEach(function(key){ + var config = serviceConfig[key] + switch (key) { + case 's3': + services.s3 = OKS3Service({ + express: express, + s3: config, + }); + break + case 'twitter': + services.twitter = OKTwitterService({ + express: express, + credentials: config, + }); + break + default: + services[key] = config.lib({ + express: express, + config: config, + }); + break + } + }); var server = this._server = new OKServer({ express: express, @@ -117,10 +128,7 @@ function OKCMS(options) { root: root, adminRoot: adminRoot, adminPath: adminPath, - services: { - s3: s3Service, - twitter: twitterService, - }, + services: services, errorHandler: errorHandler }); } diff --git a/app/node_modules/okserver/index.js b/app/node_modules/okserver/index.js index 302911d..a89676f 100644 --- a/app/node_modules/okserver/index.js +++ b/app/node_modules/okserver/index.js @@ -52,7 +52,7 @@ function OKServer(options) { * other middleware. */ - // Disable silly express header + // Disable x-powered-by express header app.disable('x-powered-by') // Serve user static files app.use(express.static(root)); @@ -61,12 +61,9 @@ function OKServer(options) { // Application router app.use(router); // Add services - if (services.s3) { - app.use('/_services/s3', services.s3.middleware()); - } - if (services.twitter) { - app.use('/_services/twitter', services.twitter.middleware()) - } + Object.keys(services).forEach(function(key){ + app.use('/_services/' + key, services[key].middleware()); + }) // Make sure this lady is last. Checks whether the desired // route has a trailing-slash counterpart and redirects there app.use(slash()); diff --git a/app/node_modules/okservices/oks3/index.js b/app/node_modules/okservices/oks3/index.js index c636308..cc40b71 100644 --- a/app/node_modules/okservices/oks3/index.js +++ b/app/node_modules/okservices/oks3/index.js @@ -20,9 +20,6 @@ function OKS3(options) { if (!options.s3.audio) options.s3.audio = {} if (!options.s3.video) options.s3.video = {} - // TODO: maxBytes property doesn't work - if you upload a large file, - // it will just hang until you reload the browser, and then CRASH. - // Make sure maxbytes property is there - it can be a number, // or zero/undefined (for no maximum upload size) if (options.s3.maxbytes) { diff --git a/package.json b/package.json index 2a927d5..bd5719b 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "okcms", - "version": "0.1.30", + "version": "0.1.31", "description": "great", "main": "app/index.js", "scripts": { @@ -13,7 +13,8 @@ "dotenv": "^1.1.0", "express": "^4.12.3", "object-assign": "^2.0.0", - "q": "^1.2.0" + "q": "^1.2.0", + "request": "^2.71.0" }, "devDependencies": { "grunt": "^0.4.5", diff --git a/themes/okadmin/public/js/upload.js b/themes/okadmin/public/js/upload.js index da23b1b..6ff7ac9 100644 --- a/themes/okadmin/public/js/upload.js +++ b/themes/okadmin/public/js/upload.js @@ -177,9 +177,6 @@ OKUpload.prototype.add = function(media){ OKUpload.prototype.addMedia = function(media){ console.log(media) } -OKUpload.prototype.addAudio = function(media){ - console.log(media) -} OKUpload.prototype.error = function(error){ throw error } -- cgit v1.2.3-70-g09d2 From 21b7769c2a57d7e9c62318e911a45a6edebc0912 Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 14 Apr 2016 15:55:11 -0400 Subject: fix checkbox issue --- themes/okadmin/templates/partials/inputs.liquid | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'themes') diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index de134c3..373e580 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -69,7 +69,7 @@
        -- cgit v1.2.3-70-g09d2 From f76ec56f3d70da6359905e9b9666f581599edd4f Mon Sep 17 00:00:00 2001 From: Jules Laplace Date: Thu, 21 Apr 2016 18:02:31 -0400 Subject: fix issue with single input fields, store image width/height --- examples/db.json | 24 ++++++++++++++++++++++- examples/index.js | 6 ++++++ package.json | 4 ++-- themes/okadmin/public/css/main.css | 4 +++- themes/okadmin/public/js/app.js | 26 ++++++++++++++++--------- themes/okadmin/templates/partials/inputs.liquid | 18 +++++++++++++++-- 6 files changed, 67 insertions(+), 15 deletions(-) (limited to 'themes') diff --git a/examples/db.json b/examples/db.json index 8805342..401bf26 100644 --- a/examples/db.json +++ b/examples/db.json @@ -153,6 +153,13 @@ "id": "red", "title": "Red", "media": [ + { + "uri": "https://ltho.s3.amazonaws.com/okcms-example/a91c4210-080c-11e6-8a7d-f30231d4ec26.png", + "width": "800", + "height": "800", + "caption": "", + "type": "image" + }, { "uri": "http://asdf.us/", "caption": "ASDF", @@ -160,7 +167,8 @@ } ], "__index": 0, - "dateCreated": "Mon, 28 Mar 2016 23:02:45 GMT" + "dateCreated": "Mon, 28 Mar 2016 23:02:45 GMT", + "flagged": false }, { "id": "blue", @@ -210,5 +218,19 @@ ], "flagged": true } + ], + "flour": [ + { + "id": "test", + "title": "TEST", + "image": { + "uri": "https://ltho.s3.amazonaws.com/okcms-example/7be163d0-080b-11e6-8a7d-f30231d4ec26.png", + "caption": "", + "width": "800", + "height": "800" + }, + "__index": 0, + "dateCreated": "Thu, 21 Apr 2016 21:52:44 GMT" + } ] } \ No newline at end of file diff --git a/examples/index.js b/examples/index.js index efbfc38..341a50b 100644 --- a/examples/index.js +++ b/examples/index.js @@ -29,6 +29,11 @@ var app = okcms.createApp({ title: {type: 'string'}, flagged: {type: 'flag'}, media: {type: 'media-list'}, + }, + flour: { + id: {type: 'string', hidden: true}, + title: {type: 'string'}, + image: {type: 'image'}, } }, @@ -37,6 +42,7 @@ var app = okcms.createApp({ { type: 'page', static: {id: 'contact'}}, { type: 'bread' }, { type: 'test' }, + { type: 'flour' }, ], services: { diff --git a/package.json b/package.json index 619b1c8..971efed 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "okcms", - "version": "0.1.33", - "description": "great", + "version": "0.1.34", + "description": "The dopest CMS on the planet.", "main": "app/index.js", "scripts": { "postinstall": "./install.sh", diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index 15b8781..e539a71 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -291,7 +291,9 @@ button, input[type=submit] { height: 7em; } .main.resource form img { - width: 10em; + width: auto; + height: auto; + max-width: 10em; max-height: 6em; border: 0; } diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index 59fc6ae..578d99f 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -9,8 +9,10 @@ var OKAdmin = function(){ var url = media.url var imageTemplate = $(".image-template", parent).html() var $el = $(imageTemplate) - $el.find(".uri").val(url) - $el.find("img").attr("src", url) + $el.find(".uri").val(media.url) + $el.find(".image-width").val(media.width) + $el.find(".image-height").val(media.height) + $el.find("img").attr("src", media.url) $("ol", parent).prepend($el) } }) @@ -44,8 +46,10 @@ var OKAdmin = function(){ var url = media.url var imageTemplate = $(".image-template", parent).html() var $el = $(imageTemplate) - $el.find(".uri").val(url) - $el.find("img").attr("src", url) + $el.find(".uri").val(media.url) + $el.find(".image-width").val(media.width) + $el.find(".image-height").val(media.height) + $el.find("img").attr("src", media.url) $("ol", parent).prepend($el) } uploader.addMedia = function(media){ @@ -103,11 +107,13 @@ var OKAdmin = function(){ var $el = $(this) var uploader = new OKUpload () uploader.bind( this ) - uploader.add = function(url){ - console.log(url) - $el.find(".uri").val(url) + uploader.add = function(media){ + console.log(media) + $el.find(".uri").val(media.url) $el.find(".caption").val("") - $el.find("img").attr("src", url).show() + $el.find(".image-width").val(media.width) + $el.find(".image-height").val(media.height) + $el.find("img").attr("src", media.url).show() $el.addClass("loaded") } }) @@ -117,6 +123,8 @@ var OKAdmin = function(){ var $el = $(this).closest(".image") $el.removeClass('loaded') $el.find(".uri").val("") + $el.find(".image-width").val("") + $el.find(".image-height").val("") $el.find(".caption").val("") $el.find("img").attr("src", "") } @@ -141,7 +149,7 @@ var OKAdmin = function(){ $el.parent().addClass("loaded") $el.parent().find(".video-type").val( media.type ) $el.parent().find(".video-token").val( media.token ) - $el.parent().find(".video-uri").val( media.uri ) + $el.parent().find(".video-uri").val( media.url ) $el.parent().find(".video-title").val( media.title ) $el.parent().find(".video-thumb").val( media.thumbnail ) $el.parent().find(".video-width").val( media.width ) diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index 373e580..e71f4ad 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -48,6 +48,8 @@
        + + {{spec.value.caption | escape}}
        @@ -154,6 +156,8 @@ + + @@ -165,8 +169,8 @@ - - + + @@ -249,6 +253,8 @@
      3. + + {{image.caption | strip_html}} @@ -271,6 +277,8 @@