Vulcan/packages/nova-embedly/lib/custom_fields.js

101 lines
2.1 KiB
JavaScript
Raw Normal View History

2016-08-08 11:18:21 +09:00
import Telescope from 'meteor/nova:lib';
2016-03-27 18:17:20 +09:00
import PublicationUtils from 'meteor/utilities:smart-publications';
2016-04-07 12:43:41 +09:00
import EmbedlyURL from './components/EmbedlyURL.jsx';
2016-04-07 22:21:01 +09:00
import ThumbnailURL from './components/ThumbnailURL.jsx';
2016-06-23 11:40:35 +09:00
import Posts from "meteor/nova:posts";
2016-06-23 15:00:58 +09:00
import Users from 'meteor/nova:users';
2016-04-07 12:43:41 +09:00
2016-07-21 09:40:05 +09:00
// check if user can create a new post
const canInsert = user => Users.canDo(user, "posts.new");
// check if user can edit a post
const canEdit = Users.canEdit;
2016-03-27 18:17:20 +09:00
Posts.addField([
2016-04-07 12:43:41 +09:00
{
fieldName: 'url',
fieldSchema: {
type: String,
optional: true,
max: 500,
2016-07-21 09:40:05 +09:00
insertableIf: canInsert,
editableIf: canEdit,
2016-04-07 12:43:41 +09:00
control: EmbedlyURL,
publish: true
}
},
2016-03-27 18:17:20 +09:00
{
fieldName: 'thumbnailUrl',
fieldSchema: {
type: String,
optional: true,
2016-07-21 09:40:05 +09:00
insertableIf: canInsert,
editableIf: canEdit,
2016-03-27 18:17:20 +09:00
publish: true,
2016-04-07 22:21:01 +09:00
control: ThumbnailURL
2016-03-27 18:17:20 +09:00
}
},
{
fieldName: 'media',
fieldSchema: {
type: Object,
publish: true,
optional: true,
blackbox: true
}
},
{
fieldName: 'sourceName',
fieldSchema: {
type: String,
optional: true,
publish: true,
}
},
{
fieldName: 'sourceUrl',
fieldSchema: {
type: String,
optional: true,
publish: true,
}
}
]);
PublicationUtils.addToFields(Posts.publishedFields.list, ["thumbnailUrl", "media", "sourceName", "sourceUrl"]);
2016-04-04 16:50:07 +09:00
if (typeof Telescope.settings.collection !== "undefined") {
Telescope.settings.collection.addField([
{
fieldName: 'embedlyKey',
fieldSchema: {
type: String,
optional: true,
private: true,
form: {
2016-04-04 16:50:07 +09:00
group: 'embedly',
class: 'private-field'
}
}
},
{
fieldName: 'thumbnailWidth',
fieldSchema: {
type: Number,
optional: true,
form: {
2016-04-04 16:50:07 +09:00
group: 'embedly'
}
}
},
{
fieldName: 'thumbnailHeight',
fieldSchema: {
type: Number,
optional: true,
form: {
2016-04-04 16:50:07 +09:00
group: 'embedly'
}
}
}
]);
}