-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmedian.js
More file actions
62 lines (52 loc) · 1.53 KB
/
median.js
File metadata and controls
62 lines (52 loc) · 1.53 KB
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
Stories = new Mongo.Collection("stories");
if (Meteor.isClient) {
Template.registerHelper('userAvatar', function() {
return Meteor.user().services.twitter.profile_image_url;
});
Template.registerHelper('formatDate', function(date) {
return moment(date).startOf('hour').fromNow();
});
Template.body.helpers({
stories: function() {
return Stories.find({}, {
sort: {
createdAt: -1
}
});
}
});
Template.body.events({
"submit .new-story": function(event) {
// Prevent default browser form submit
event.preventDefault();
// Get value from form elements
var text = event.target.text.value;
var title = event.target.title.value;
// Make sure the user is logged in before inserting a task
if (!Meteor.userId()) {
throw new Meteor.Error("Not Authorized");
}
// Insert a task into the collection
Stories.insert({
text: text,
title: title,
createdAt: new Date(), // current time
owner: Meteor.userId(), // id of logged in user
username: Meteor.user().username,
authorAvatar: Meteor.user().services.twitter.profile_image_url,
authorName: Meteor.user().services.twitter.screenName
});
// Clear form
event.target.text.value = "";
event.target.title.value = "";
}
});
Accounts.ui.config({
passwordSignupFields: "USERNAME_ONLY"
});
}
if (Meteor.isServer) {
Meteor.startup(function() {
// code to run on server at startup
});
}