Vulcan/packages/my-custom-package/lib/custom_fields.js
2016-06-16 11:34:13 +09:00

39 lines
No EOL
1.3 KiB
JavaScript

/*
Let's assign a color to each post (why? cause we want to, that's why).
We'll do that by adding a custom field to the Posts collection.
Note that this requires our custom package to depend on nova:posts and nova:users.
*/
Posts.addField(
{
fieldName: 'color',
fieldSchema: {
type: String,
control: "select", // use a select form control
optional: true, // this field is not required
insertableIf: Users.is.memberOrAdmin, // insertable by regular logged in users and admins
editableIf: Users.is.ownerOrAdmin, // editable by the post's owner or admins
autoform: {
options: function () { // options for the select form control
return [
{value: "white", label: "White"},
{value: "yellow", label: "Yellow"},
{value: "blue", label: "Blue"},
{value: "red", label: "Red"},
{value: "green", label: "Green"}
];
}
},
publish: true // make that field public and send it to the client
}
}
);
/*
The main post list view uses a special object to determine which fields to publish,
so we also add our new field to that object:
*/
import PublicationUtils from 'meteor/utilities:smart-publications';
PublicationUtils.addToFields(Posts.publishedFields.list, ["color"]);