diff --git a/packages/nova-embedly/lib/components/EmbedlyThumbnail.jsx b/packages/nova-embedly/lib/components/EmbedlyThumbnail.jsx new file mode 100644 index 000000000..e20e8321a --- /dev/null +++ b/packages/nova-embedly/lib/components/EmbedlyThumbnail.jsx @@ -0,0 +1,85 @@ +import React, { PropTypes, Component } from 'react'; +import Formsy from 'formsy-react'; +import FRC from 'formsy-react-components'; +const Input = FRC.Input; + +class EmbedlyThumbnail extends Component { + + constructor(props) { + super(props) + this.state = { + thumbnailUrl: props.value, + loading: false + }; + } + + // will trigger every time the context (i.e. form values) changes + shouldComponentUpdate(nextProps, nextState, nextContext) { + + const nextUrl = nextContext.currentValues.url; + const currentUrl = this.context.currentValues.url; + + if (nextUrl != currentUrl) { + + this.setState({loading: true}); + + // the URL has changed, get a new thumbnail + Meteor.call("getEmbedlyData", nextUrl, (error, result) => { + + this.setState({loading: false}); + + if (error) { + console.log(error) + this.context.throwError({content: error.message, type: "error"}); + } else { + this.setState({ + thumbnailUrl: result.thumbnailUrl + }); + } + }); + } + return true; + } + + renderThumbnail() { + + const currentUrl = this.context.currentValues && this.context.currentValues.url; + + return currentUrl ? : null; + } + + render() { + + const {name, value, label} = this.props; + + Loading = Telescope.components.Loading; + + return ( +
+ +
+ {this.state.loading ? : this.renderThumbnail()} + +
+
+ ) + } +} + +EmbedlyThumbnail.propTypes = { + name: React.PropTypes.string, + value: React.PropTypes.any, + label: React.PropTypes.string +} + +EmbedlyThumbnail.contextTypes = { + currentValues: React.PropTypes.object, + throwError: React.PropTypes.func +} + +export default EmbedlyThumbnail; \ No newline at end of file diff --git a/packages/nova-embedly/lib/custom_fields.js b/packages/nova-embedly/lib/custom_fields.js index aaaa08302..4ecbc61d6 100644 --- a/packages/nova-embedly/lib/custom_fields.js +++ b/packages/nova-embedly/lib/custom_fields.js @@ -1,4 +1,5 @@ import PublicationUtils from 'meteor/utilities:smart-publications'; +import EmbedlyThumbnail from './components/EmbedlyThumbnail.jsx'; Posts.addField([ { @@ -9,10 +10,7 @@ Posts.addField([ insertableIf: Users.is.memberOrAdmin, editableIf: Users.is.ownerOrAdmin, publish: true, - autoform: { - type: 'bootstrap-postthumbnail', - order: 40 - } + control: EmbedlyThumbnail } }, { @@ -43,4 +41,41 @@ Posts.addField([ ]); PublicationUtils.addToFields(Posts.publishedFields.list, ["thumbnailUrl", "media", "sourceName", "sourceUrl"]); -PublicationUtils.addToFields(Posts.publishedFields.single, ["thumbnailUrl", "media", "sourceName", "sourceUrl"]); \ No newline at end of file +PublicationUtils.addToFields(Posts.publishedFields.single, ["thumbnailUrl", "media", "sourceName", "sourceUrl"]); + +if (typeof Telescope.settings.collection !== "undefined") { + Telescope.settings.collection.addField([ + { + fieldName: 'embedlyKey', + fieldSchema: { + type: String, + optional: true, + private: true, + autoform: { + group: 'embedly', + class: 'private-field' + } + } + }, + { + fieldName: 'thumbnailWidth', + fieldSchema: { + type: Number, + optional: true, + autoform: { + group: 'embedly' + } + } + }, + { + fieldName: 'thumbnailHeight', + fieldSchema: { + type: Number, + optional: true, + autoform: { + group: 'embedly' + } + } + } + ]); +} \ No newline at end of file diff --git a/packages/nova-embedly/lib/embedly.js b/packages/nova-embedly/lib/embedly.js index 29d757864..b4ee4b20a 100644 --- a/packages/nova-embedly/lib/embedly.js +++ b/packages/nova-embedly/lib/embedly.js @@ -16,39 +16,3 @@ function checkIfPreviouslyPosted (data) { return data; } Telescope.callbacks.add("afterEmbedlyPrefill", checkIfPreviouslyPosted); - - -// Settings.addField([ -// { -// fieldName: 'embedlyKey', -// fieldSchema: { -// type: String, -// optional: true, -// private: true, -// autoform: { -// group: 'embedly', -// class: 'private-field' -// } -// } -// }, -// { -// fieldName: 'thumbnailWidth', -// fieldSchema: { -// type: Number, -// optional: true, -// autoform: { -// group: 'embedly' -// } -// } -// }, -// { -// fieldName: 'thumbnailHeight', -// fieldSchema: { -// type: Number, -// optional: true, -// autoform: { -// group: 'embedly' -// } -// } -// } -// ]); \ No newline at end of file diff --git a/packages/nova-embedly/lib/server/get_embedly_data.js b/packages/nova-embedly/lib/server/get_embedly_data.js index 5e6420a8e..c6494d343 100644 --- a/packages/nova-embedly/lib/server/get_embedly_data.js +++ b/packages/nova-embedly/lib/server/get_embedly_data.js @@ -1,9 +1,9 @@ getEmbedlyData = function (url) { var data = {}; var extractBase = 'http://api.embed.ly/1/extract'; - var embedlyKey = Settings.get('embedlyKey'); - var thumbnailWidth = Settings.get('thumbnailWidth', 200); - var thumbnailHeight = Settings.get('thumbnailHeight', 125); + var embedlyKey = Telescope.settings.get('embedlyKey'); + var thumbnailWidth = Telescope.settings.get('thumbnailWidth', 200); + var thumbnailHeight = Telescope.settings.get('thumbnailHeight', 125); if(!embedlyKey) { // fail silently to still let the post be submitted as usual @@ -115,7 +115,7 @@ Meteor.methods({ return getEmbedlyData(url); }, embedlyKeyExists: function () { - return !!Settings.get('embedlyKey'); + return !!Telescope.settings.get('embedlyKey'); }, regenerateThumbnail: function (post) { check(post, Posts.simpleSchema()); diff --git a/packages/nova-embedly/package.js b/packages/nova-embedly/package.js index 3c8a3bca4..66dc58ac7 100644 --- a/packages/nova-embedly/package.js +++ b/packages/nova-embedly/package.js @@ -17,12 +17,12 @@ Package.onUse( function(api) { api.addFiles([ // 'package-tap.i18n', - // 'lib/embedly.js', + 'lib/embedly.js', 'lib/custom_fields.js' ], ['client', 'server']); api.addFiles([ - // 'lib/server/get_embedly_data.js' + 'lib/server/get_embedly_data.js' ], ['server']); api.addFiles([ diff --git a/packages/nova-forms/lib/FormComponent.jsx b/packages/nova-forms/lib/FormComponent.jsx index acad26444..60973f6d9 100644 --- a/packages/nova-forms/lib/FormComponent.jsx +++ b/packages/nova-forms/lib/FormComponent.jsx @@ -25,23 +25,30 @@ class FormComponent extends Component { const value = document && Utils.deepValue(document, fieldName) ? Utils.deepValue(document, fieldName) : ""; const label = typeof labelFunction === "function" ? labelFunction(fieldName) : fieldName; - switch (field.control) { + if (typeof field.control === "function") { + + return + + } else { + + switch (field.control) { + case "text": + return ; + case "textarea": + return