mirror of
https://github.com/vale981/Vulcan
synced 2025-03-10 12:36:39 -04:00
43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
import PublicationUtils from 'meteor/utilities:smart-publications';
|
|
import Posts from "meteor/nova:posts";
|
|
import Users from 'meteor/nova:users';
|
|
import Categories from "./collection.js";
|
|
|
|
// 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;
|
|
|
|
Posts.addField(
|
|
{
|
|
fieldName: 'categories',
|
|
fieldSchema: {
|
|
type: [String],
|
|
control: "checkboxgroup",
|
|
optional: true,
|
|
insertableIf: canInsert,
|
|
editableIf: canEdit,
|
|
form: {
|
|
noselect: true,
|
|
type: "bootstrap-category",
|
|
order: 50,
|
|
options: function () {
|
|
var categories = Categories.find().map(function (category) {
|
|
return {
|
|
value: category._id,
|
|
label: category.name
|
|
};
|
|
});
|
|
return categories;
|
|
}
|
|
},
|
|
publish: true,
|
|
join: {
|
|
joinAs: "categoriesArray",
|
|
collection: () => Categories
|
|
}
|
|
}
|
|
}
|
|
);
|
|
|
|
PublicationUtils.addToFields(Posts.publishedFields.list, ["categories"]);
|