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 ;
+ case "checkbox":
+ return ;
+ // note: checkboxgroup cause React refs error
+ case "checkboxgroup":
+ return ;
+ case "radiogroup":
+ return ;
+ case "select":
+ return ;
+ default:
+ return ;
+ }
- case "text":
- return ;
- case "textarea":
- return ;
- case "checkbox":
- return ;
- // note: checkboxgroup cause React refs error
- case "checkboxgroup":
- return ;
- case "radiogroup":
- return ;
- case "select":
- return ;
- default:
- return ;
}
}
diff --git a/packages/nova-forms/lib/NovaForm.jsx b/packages/nova-forms/lib/NovaForm.jsx
index 0ce094e76..92fab9d85 100644
--- a/packages/nova-forms/lib/NovaForm.jsx
+++ b/packages/nova-forms/lib/NovaForm.jsx
@@ -7,26 +7,74 @@ import Utils from './utils.js';
class NovaForm extends Component{
- constructor() {
- super();
+ constructor(props) {
+ super(props);
this.submitForm = this.submitForm.bind(this);
this.methodCallback = this.methodCallback.bind(this);
+ this.updateState = this.updateState.bind(this);
+ this.throwError = this.throwError.bind(this);
+ this.clearErrors = this.clearErrors.bind(this);
this.state = {
disabled: false,
- errors: []
+ errors: [],
+ currentValues: this.props.document
};
}
- getFormType() { // if a document is being passed, this is an edit form
+ // if a document is being passed, this is an edit form
+ getFormType() {
return this.props.document ? "edit" : "new";
}
- getFields() { // get relevant fields
+ // get relevant fields
+ getFields() {
const collection = this.props.collection;
const fields = this.getFormType() === "edit" ? collection.getEditableFields(this.props.currentUser) : collection.getInsertableFields(this.props.currentUser);
return fields;
}
+ // add error to state
+ throwError(error) {
+ this.setState({
+ errors: [error]
+ });
+ }
+
+ // clear all errors
+ clearErrors() {
+ this.setState({
+ errors: []
+ });
+ }
+
+ // render errors
+ renderErrors() {
+ Flash = Telescope.components.Flash;
+ return {this.state.errors.map(message => )}
+ }
+
+ // whenever the form values change, keep track of them in the state
+ updateState(e) {
+ // e can sometimes be event, sometims be currentValue
+ // see https://github.com/christianalfoni/formsy-react/issues/203
+ if (e.stopPropagation) {
+ e.stopPropagation();
+ } else {
+ this.setState({
+ currentValues: e
+ });
+ }
+ }
+
+ // pass on form values as context to all child components for easy access
+ getChildContext() {
+ return {
+ throwError: this.throwError,
+ currentValues: this.state.currentValues
+ };
+ }
+
+ // common callback for both new and edit forms
methodCallback(error, document) {
this.setState({disabled: false});
@@ -36,11 +84,9 @@ class NovaForm extends Component{
console.log(error)
// add error to state
- this.setState({
- errors: [{
- content: error.message,
- type: "error"
- }]
+ this.throwError({
+ content: error.message,
+ type: "error"
});
// run error callback if it exists
@@ -48,9 +94,7 @@ class NovaForm extends Component{
} else { // success
- this.setState({
- errors: []
- });
+ this.clearErrors();
// reset form if this is a new document form
if (this.getFormType() === "new") this.refs.form.reset();
@@ -64,8 +108,8 @@ class NovaForm extends Component{
}
}
+ // submit form handler
submitForm(data) {
-
this.setState({disabled: true});
const fields = this.getFields();
@@ -101,7 +145,6 @@ class NovaForm extends Component{
// build modifier
const modifier = {$set: set};
if (!_.isEmpty(unset)) modifier.$unset = unset;
-
// call method with _id of document being edited and modifier
Meteor.call(this.props.methodName, document._id, modifier, this.methodCallback);
@@ -109,11 +152,6 @@ class NovaForm extends Component{
}
- renderErrors() {
- Flash = Telescope.components.Flash;
- return {this.state.errors.map(message => )}
- }
-
render() {
const document = this.props.document;
@@ -127,7 +165,7 @@ class NovaForm extends Component{
return (
-
+
{this.renderErrors()}
{fields.map(fieldName =>