summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/node_modules/okschema/index.js27
-rw-r--r--examples/db.json26
-rw-r--r--examples/index.js3
-rw-r--r--themes/okadmin/public/css/main.css3
-rw-r--r--themes/okadmin/templates/partials/inputs.liquid16
5 files changed, 69 insertions, 6 deletions
diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js
index 4e8ea73..0544c79 100644
--- a/app/node_modules/okschema/index.js
+++ b/app/node_modules/okschema/index.js
@@ -34,6 +34,33 @@ var types = {
}];
}
}
+ },
+ 'captioned-image-list': {
+ parent: [{
+ uri: { type: 'string' }, // TODO Implement URI type
+ caption: { type: 'string' }
+ }],
+ assertValid: function(spec, value) {
+ var message;
+ var actual;
+ if (!value || !value.length) {
+ throw [{
+ message: 'Not an array',
+ expected: JSON.stringify(this.parent),
+ actual: value
+ }];
+ } else {
+ value.forEach(function(obj) {
+ if (!(obj.uri && obj.caption)) {
+ throw [{
+ message: 'Array contains invalid object',
+ expected: JSON.stringify(this.parent),
+ actual: obj
+ }];
+ }
+ });
+ }
+ }
}
}
diff --git a/examples/db.json b/examples/db.json
index b2cdf4a..ab4f7e1 100644
--- a/examples/db.json
+++ b/examples/db.json
@@ -6,18 +6,38 @@
"description": "really a very tasty bread! yup yes",
"color": "blue",
"id": "pretzel",
- "title": ""
+ "title": "",
+ "images": [
+ {
+ "uri": "cool",
+ "caption": "cool"
+ }
+ ]
},
{
"type": "bagel",
"description": "very good and dense bread",
- "id": "bagel"
+ "id": "bagel",
+ "title": "nice",
+ "color": "blue",
+ "images": [
+ {
+ "uri": "http://del.h-cdn.co/assets/cm/15/10/54f928d7ada8d_-_1347910942518.jpg",
+ "caption": "beep"
+ }
+ ]
},
{
"type": "pumpernickel",
"description": "grandma's recipe",
"id": "pumpernickel",
- "title": "Pumpernickel"
+ "title": "Pumpernickel",
+ "images": [
+ {
+ "uri": "cool",
+ "caption": "cool"
+ }
+ ]
}
],
"page": [
diff --git a/examples/index.js b/examples/index.js
index 3dd3a39..9c5b7b4 100644
--- a/examples/index.js
+++ b/examples/index.js
@@ -14,7 +14,8 @@ var app = okcms.createApp({
type: {type: 'string', id: true},
title: {type: 'string'},
description: {type: 'text'},
- color: {type: 'enum', options: ["red","blue","green"]}
+ color: {type: 'enum', options: ["red","blue","green"]},
+ images: {type: 'captioned-image-list'}
}
},
diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css
index c5694eb..d120b0a 100644
--- a/themes/okadmin/public/css/main.css
+++ b/themes/okadmin/public/css/main.css
@@ -135,7 +135,8 @@ label {
.main.resource form input,
.main.resource form textarea,
-.main.resource form select {
+.main.resource form select,
+.main.resource form img {
display: block;
float: left;
width: 20em;
diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid
index 551a66c..8269d4e 100644
--- a/themes/okadmin/templates/partials/inputs.liquid
+++ b/themes/okadmin/templates/partials/inputs.liquid
@@ -3,7 +3,7 @@
{% assign spec = pair[1] %}
{% assign type = spec.type %}
- <div class="property">
+ <div class="property {{type}}">
<label for="{{name}}">{{name | capitalize}}</label>
{% if type == 'string' %}
@@ -28,6 +28,20 @@
<option value="{{option}}" {% if option == spec.value %}selected{% endif %}>{{option}}</option>
{% endfor %}
</select>
+ {% elsif type == 'captioned-image-list' %}
+ <ol>
+ {% for image in spec.value %}
+ <li class="image-element">
+ <img src="{{image.uri}}" alt="{{image.caption}}">
+ <input type="hidden" name="{{name}}[][uri]" value="{{image.uri}}">
+ <div class="clear"></div>
+ <input type="text" name="{{name}}[][caption]" value="{{image.caption}}">
+ <button class="remove-image">-</button>
+ </li>
+ {% endfor %}
+ </ol>
+ <input class="file-upload" style="display: none;" type="file" accept="image/*">
+ <button class="add-image">+</button>
{% else %}
<p><pre style="color: red">Admin template doesn't support '{{type}}' properties!</pre></p>
{% endif %}