-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
86 lines (73 loc) · 1.39 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
items = new Mongo.Collection("items");
lists = new Mongo.Collection("lists");
Router.route("/", function() {
this.render("page");
});
Router.route("/:_id", function() {
this.render("page", {
data: {
_id: this.params._id
}
});
});
if (Meteor.isClient) {
Template.list.onCreated(function() {
this.subscribe("items", this.data._id);
});
Template.page.onCreated(function() {
if (this.data && this.data._id)
this.subscribe("lists", this.data._id);
});
Template.list.helpers({
items: function() {
return items.find({
listId: this._id,
});
}
});
Template.page.helpers({
lists: function() {
if (!this._id)
return;
return lists.find({
pageId: this._id,
});
}
});
Template.page.events({
"click button": function() {
var pageId = Random.id();
Meteor.call("createPage", pageId);
window.open("/" + pageId);
}
});
}
if (Meteor.isServer) {
Meteor.publish("lists", function(pageId) {
return lists.find({
pageId: pageId,
});
});
Meteor.publish("items", function(listId) {
return items.find({
listId: listId,
});
});
Meteor.methods({
"createPage": function(pageId) {
for (var i = 0; i < 10; i++) {
var listId = Random.id();
lists.insert({
_id: listId,
pageId: pageId,
});
for (var k = 0; k < 10; k++) {
items.insert({
listId: listId,
text: "item " + k,
});
}
}
}
});
}