Vulcan/packages/vulcan-categories/lib/custom_fields.js
2017-07-08 11:36:27 +09:00

38 lines
1,018 B
JavaScript

import Posts from "meteor/vulcan:posts";
import { getCategoriesAsOptions } from './schema.js';
Posts.addField([
{
fieldName: 'categories',
fieldSchema: {
type: Array,
control: "checkboxgroup",
optional: true,
insertableBy: ['members'],
editableBy: ['members'],
viewableBy: ['guests'],
form: {
noselect: true,
type: "bootstrap-category",
order: 50,
options: formProps => getCategoriesAsOptions(formProps.client),
},
resolveAs: {
fieldName: 'categories',
type: '[Category]',
resolver: async (post, args, {currentUser, Users, Categories}) => {
if (!post.categories) return [];
const categories = _.compact(await Categories.loader.loadMany(post.categories));
return Users.restrictViewableFields(currentUser, Categories, categories);
}
}
}
},
{
fieldName: 'categories.$',
fieldSchema: {
type: String,
optional: true
}
}
]);