2016-02-27 16:41:50 +09:00
|
|
|
import PublicationUtils from 'meteor/utilities:smart-publications';
|
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-06-23 15:11:56 +09:00
|
|
|
import Categories from "./collection.js";
|
2016-02-27 16:41:50 +09:00
|
|
|
|
2016-07-21 09:39:40 +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;
|
|
|
|
|
2015-05-17 15:38:02 +09:00
|
|
|
Posts.addField(
|
2015-04-22 07:50:11 +09:00
|
|
|
{
|
2015-05-10 14:36:47 +09:00
|
|
|
fieldName: 'categories',
|
|
|
|
fieldSchema: {
|
2015-04-22 07:50:11 +09:00
|
|
|
type: [String],
|
2016-02-25 17:44:43 +09:00
|
|
|
control: "checkboxgroup",
|
2015-04-22 07:50:11 +09:00
|
|
|
optional: true,
|
2016-07-21 09:39:40 +09:00
|
|
|
insertableIf: canInsert,
|
|
|
|
editableIf: canEdit,
|
2016-10-05 08:43:13 +02:00
|
|
|
form: {
|
2015-04-22 07:50:11 +09:00
|
|
|
noselect: true,
|
2015-08-07 11:17:03 +09:00
|
|
|
type: "bootstrap-category",
|
2015-10-20 14:34:24 +09:00
|
|
|
order: 50,
|
2015-04-22 07:50:11 +09:00
|
|
|
options: function () {
|
|
|
|
var categories = Categories.find().map(function (category) {
|
|
|
|
return {
|
|
|
|
value: category._id,
|
|
|
|
label: category.name
|
2015-05-01 18:22:00 +02:00
|
|
|
};
|
2015-04-22 07:50:11 +09:00
|
|
|
});
|
|
|
|
return categories;
|
|
|
|
}
|
2016-02-17 19:39:43 +09:00
|
|
|
},
|
2016-03-24 16:03:30 +09:00
|
|
|
publish: true,
|
2016-02-17 19:39:43 +09:00
|
|
|
join: {
|
|
|
|
joinAs: "categoriesArray",
|
2016-02-26 13:05:12 +09:00
|
|
|
collection: () => Categories
|
2015-04-22 07:50:11 +09:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2016-02-17 11:28:00 +09:00
|
|
|
|
2016-02-27 16:41:50 +09:00
|
|
|
PublicationUtils.addToFields(Posts.publishedFields.list, ["categories"]);
|