diff options
| -rw-r--r-- | app/index.js | 1 | ||||
| -rw-r--r-- | app/node_modules/okdb/index.js | 2 | ||||
| -rw-r--r-- | app/node_modules/okschema/index.js | 17 | ||||
| -rw-r--r-- | examples/db.json | 9 | ||||
| -rw-r--r-- | examples/index.js | 5 | ||||
| -rw-r--r-- | package.json | 2 | ||||
| -rw-r--r-- | themes/okadmin/public/css/main.css | 8 | ||||
| -rw-r--r-- | themes/okadmin/public/js/app.js | 34 | ||||
| -rw-r--r-- | themes/okadmin/templates/partials/inputs.liquid | 56 |
9 files changed, 93 insertions, 41 deletions
diff --git a/app/index.js b/app/index.js index 6a1c74f..06b1591 100644 --- a/app/index.js +++ b/app/index.js @@ -28,6 +28,7 @@ function OKCMS(options) { var app = express(); app.enable('strict routing'); + app.disable('x-powered-by'); var root = this._root = options.root || 'public'; var adminConfig = options.admin || {}; diff --git a/app/node_modules/okdb/index.js b/app/node_modules/okdb/index.js index 4820c8c..ad8d9a7 100644 --- a/app/node_modules/okdb/index.js +++ b/app/node_modules/okdb/index.js @@ -97,7 +97,7 @@ FSDB.prototype.update = function(collection, id, data) { } var result = chain.assign(cloneDeep(data)).value(); - if (result ) { + if (result) { return resolve(cloneDeep(result)); } else { return resolve(null, new Error('Problem updating document')); diff --git a/app/node_modules/okschema/index.js b/app/node_modules/okschema/index.js index 330ad6b..82aa13f 100644 --- a/app/node_modules/okschema/index.js +++ b/app/node_modules/okschema/index.js @@ -63,8 +63,21 @@ var types = { assertValid: function(spec, value) {} }, 'tag-list': { - parent: 'string', - assertValid: function(spec, value) {} + parent: [{ + uri: { type: 'string' }, + text: { 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 + }]; + } + } }, 'date': { parent: 'string', diff --git a/examples/db.json b/examples/db.json index 20d4510..4319237 100644 --- a/examples/db.json +++ b/examples/db.json @@ -99,7 +99,14 @@ "title": "About Us", "body": "Just a small bakery", "id": "about", - "__index": 1 + "__index": "1", + "links": [ + { + "text": "asdf2", + "uri": "asdf" + } + ], + "dateCreated": "" }, { "title": "ok...", diff --git a/examples/index.js b/examples/index.js index 3e9f509..bf51dfc 100644 --- a/examples/index.js +++ b/examples/index.js @@ -10,7 +10,8 @@ var app = okcms.createApp({ page: { id: {type: 'string'}, title: {type: 'string'}, - body: {type: 'text'} + body: {type: 'text'}, + links: {type: 'link-list'}, }, bread: { type: {type: 'string', id: true}, @@ -19,7 +20,7 @@ var app = okcms.createApp({ color: {type: 'enum', options: ["red","blue","green"]}, video: {type: 'video'}, images: {type: 'captioned-image-list'} - } + }, }, resources: [ diff --git a/package.json b/package.json index 192685c..faf3cc9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "okcms", - "version": "0.1.18", + "version": "0.1.19", "description": "great", "main": "app/index.js", "scripts": { diff --git a/themes/okadmin/public/css/main.css b/themes/okadmin/public/css/main.css index a5fbdeb..9289fdf 100644 --- a/themes/okadmin/public/css/main.css +++ b/themes/okadmin/public/css/main.css @@ -305,6 +305,14 @@ button, input[type=submit] { .main.resource form .video-element input[type=text] { width: 15em; } +.main.resource form .group input[type=text].link-input, +.main.resource form .group input[type=text].link-input-new { + width: 13.05em; + padding: 0 0 0 0.5em; +} +.main.resource form .links li { + height: auto; +} .main .link-list .add-link-btn, .main .link-list .remove-link-btn { margin: 0; diff --git a/themes/okadmin/public/js/app.js b/themes/okadmin/public/js/app.js index edf9980..17b35d0 100644 --- a/themes/okadmin/public/js/app.js +++ b/themes/okadmin/public/js/app.js @@ -120,35 +120,25 @@ var OKAdmin = function(){ e.stopPropagation() var $delegate = $(e.delegateTarget) var $list = $delegate.find('.links') - var length = $list.find('input').length - var name = $delegate.parent('.property').data('name') - var $new = $delegate.find('.link-input-new') - var input = document.createElement('input') - var delBtn = document.createElement('button') - var inputName = name + '[' + length + ']' - $(input).attr({ - name: inputName, - type: 'text', - value: $new.val() - }) - $list.append(input) - $(delBtn).addClass('remove-link-btn') - $(delBtn).data('for', inputName) - delBtn.innerHTML = '-' - $list.append(delBtn) - $new.val('') + var $linkText = $delegate.find(".link-input-new.link-text") + var $linkURI = $delegate.find(".link-input-new.link-uri") + + var template = $delegate.find(".link-template").html() + var $el = $(template) + $el.find(".link-text").val( $linkText.val() ) + $el.find(".link-uri").val( $linkURI.val() ) + $list.append($el) + console.log($list, template) + $linkText.val("") + $linkURI.val("") }) // Remove a link from the list $('.link-list').on('click', '.remove-link-btn', function(e) { e.preventDefault() e.stopPropagation() - var $delegate = $(e.delegateTarget) var $target = $(e.target) - var inputName = $target.data('for') - var $input = $delegate.find('[name="' + inputName + '"]') - $input.remove() - $target.remove() + $target.closest("li").remove() }) // fix post indexing in list-driven inputs diff --git a/themes/okadmin/templates/partials/inputs.liquid b/themes/okadmin/templates/partials/inputs.liquid index c6efc68..55d5fb8 100644 --- a/themes/okadmin/templates/partials/inputs.liquid +++ b/themes/okadmin/templates/partials/inputs.liquid @@ -79,26 +79,58 @@ value="{{spec.value}}" placeholder="Enter a comma separated list of tags."> </div> - {% elsif type == 'link-list' %} + {% elsif type == 'link-list' %} <div class="link-list group"> <div class="links"> - {% for url in spec.value %} - <input - name="{{name}}[{{forloop.index0}}]" - value="{{url}}" - type="text" - class="link-input"> - <button class="remove-link-btn" - data-for="{{name}}[{{forloop.index0}}]"> - - - </button> + {% for link in spec.value %} + <li> + <input + name="{{name}}[][text]" + value="{{link.text}}" + type="text" + placeholder="Link text" + class="link-input link-text"> + <input + name="{{name}}[][uri]" + value="{{link.uri}}" + type="text" + placeholder="URL" + class="link-input link-uri"> + <button class="remove-link-btn"> + - + </button> + </li> {% endfor %} </div> <input type="text" - class="link-input-new" + class="link-input-new link-text" + placeholder="Link text"> + <input type="text" + class="link-input-new link-uri" placeholder="http://www.example.com"> <button class="add-link-btn">+</button> + + <script type="text/html" class="link-template"> + <li> + <input + name="{{name}}[][text]" + value="" + type="text" + placeholder="Link text" + class="link-input link-text"> + <input + name="{{name}}[][uri]" + value="" + type="text" + placeholder="URL" + class="link-input link-uri"> + <button class="remove-link-btn"> + - + </button> + </li> + </script> + </div> {% elsif type == 'media-list' %} |
