Large diffs are not rendered by default.

@@ -1,7 +1,7 @@
Template.footer.events({
'click li.logout':function(e) {
Meteor.logout(function(error){
Router.navigate(window.location.pathname, {trigger:true});
FlowRouter.navigate(window.location.pathname, {trigger:true});
Session.set('page', 'login');
})
}
@@ -16,6 +16,8 @@ body {
padding:0;
margin:0;
color: @darkGrey;
font-family: 'Avenir Next', Helvetica, sans-serif;
font-weight:400;
}

.wrapper {
@@ -1,111 +1,118 @@
if (Meteor.isClient){
Meteor.startup(function() {
var view_handle;

var Workspace = Backbone.Router.extend({
routes: {
"":"home",
"post/:post_id/":"post",
"draft/":"draft",
"history/":"history",
"account/":"account",
"dues/":"dues",
"*notFound":"notFound"
},

home: function() {
!view_handle || view_handle.stop();
view_handle = Deps.autorun(function() {
if (Meteor.user()) {
Session.set("page", "home");
} else {
Session.set("page","login");
}
});
},

post: function(post_id) {
!view_handle || view_handle.stop();
view_handle = Deps.autorun(function() {
if (Meteor.user()) {
Session.set("page", "post");
Session.set("viewing_post", post_id);
} else {
Session.set("page","login");
}
});
},

signup: function(code) {
if (Meteor.user() || InvitedUsers.find({inviteCode:code}).count() == 0) {
Router.navigate('/', {trigger:true});
} else {
Session.set("page", "signup");
Session.set("signupcode", code);
console.log('Signup for code ' + code);
}
},

draft: function() {
!view_handle || view_handle.stop();
view_handle = Deps.autorun(function() {
if (Meteor.user()) {
Session.set("page","draft");
} else {
Session.set("page","login");
}
});
},

history: function() {
!view_handle || view_handle.stop();
view_handle = Deps.autorun(function() {
if(Meteor.user()) {
Session.set("page", "history");
} else {
Session.set("page", "login");
}
});
},

account: function() {
!view_handle || view_handle.stop();
view_handle = Deps.autorun(function() {
if(Meteor.user()) {
Session.set("page", "account");
} else {
Session.set("page", "login");
}
});
},

dues: function() {
!view_handle || view_handle.stop();
view_handle = Deps.autorun(function() {
if(Meteor.user()) {
Session.set("page", "dues");
} else {
Session.set("page", "login");
}
})
},

notFound:function(path) {
if (Meteor.user()) {
Session.set("page","notFound");
} else {
Session.set("page","login");
}
}
BlazeLayout.setRoot('body');
/*FlowRouter.configure({
layoutTemplate:'body',
onBeforeAction: function(pause) {
if (this.ready() && !Meteor.user() && this.route.options.requiresAuth !== false) {
this.render('login');
pause();
}
},
waitOn: function() {
return Meteor.subscribe('users');
}
})*/

FlowRouter.route('/', {
name: 'Home',
action: function(params, queryParams) {
BlazeLayout.render('layout', {main: 'home'});
}
});

FlowRouter.route('/draft', {
name: 'Draft',
action: function(params, queryParams) {
BlazeLayout.render('layout', { main: 'draft' });
}
})

FlowRouter.route('/history', {
name: 'History',
action: function(params, queryParams) {
BlazeLayout.render('layout', { main: 'history' });
}
});

FlowRouter.route('/account', {
name: 'Account',
action: function(params, queryParams) {
BlazeLayout.render('layout', { main: 'account' });
}
});

FlowRouter.route('/dues', {
name: 'Dues',
action: function(params, queryParams) {
BlazeLayout.render('layout', { main: 'dues' });
}
})

});
FlowRouter.route('/post/:postId/', {
name: 'Post',
action: function(params, queryParams) {
BlazeLayout.render('layout', { main: 'post' });
}
})

Router = new Workspace;

Deps.autorun(function(){
if (!Meteor.loggingIn()) {
Backbone.history.start({pushState: true});
/*
this.route('post', {
path:'post/:post_id/',
data: function() {
if (this.ready()) {
return Posts.findOne(this.params.post_id);
}
},
waitOn: function() {
return [Meteor.subscribe('current_post', this.params.post_id), Meteor.subscribe('comments', this.params.post_id)];
}
});
FlowRouter.map(function() {
this.route('home', {
path:'/',
onBeforeAction: function() {
},
waitOn: function() {
return [Meteor.subscribe('recent_posts', Session.get('post_count')), Meteor.subscribe('users')]
},
});
this.route('draft', {
path:'/draft',
waitOn: function() {
return [Meteor.subscribe('drafts'), Meteor.subscribe('users')];
},
data: function() {
}
});
this.route('history', {
path:'/history'
});
this.route('account', {
path:'/account',
});
this.route('dues', {
path:'/dues'
});
this.route('post', {
path:'post/:post_id/',
data: function() {
if (this.ready()) {
return Posts.findOne(this.params.post_id);
}
})
},
waitOn: function() {
return [Meteor.subscribe('current_post', this.params.post_id), Meteor.subscribe('comments', this.params.post_id)];
}
});
}
this.route('signup')
})*/
@@ -5,4 +5,4 @@ Meteor.subscribe('posts');


Comments = new Meteor.Collection('comments');
CommentsHandle = Meteor.subscribe('comments');
CommentsHandle = Meteor.subscribe('comments');
@@ -1,9 +1,16 @@
<template name="account">
<img class="avatar account" src="{{gravatar}}"/>
<form class="change_password">
<label>Disable email notifications<input type="checkbox" class="no_email_checkbox" {{isChecked}}/></label>
<label>Old Password</label><input type="password" class="old_password"/>
<label>New Password</label><input type="password" class="password1"/>
<label>Repeat Password</label><input type="password" class="password2"/>
<input type="button" value="Change Password" class="change_password_button"/>
</form>

<form class="change_email">
<label>Old Email</label><input type="email" class="old_email" disabled="disabled" value="{{current_email}}"/>
<label>New Email</label><input type="email" class="new_email"/>
<input type="button" value="Change Email" class="change_email"/>
</form>
</template>
@@ -7,12 +7,12 @@ Template.account.events({
if (new1 == new2) {
Accounts.changePassword(old, new1, function(err) {
if (!err) {
Router.navigate('/', true);
FlowRouter.navigate('/', true);
Alert({text:'Password succesfully changed'});
}
})
} else {
alert('Passwords don\'t match');
Alert({text:'Passwords don\'t match'});
}
},
'change .no_email_checkbox':function(e, tmpl) {
@@ -23,14 +23,46 @@ Template.account.events({
Alert({text:'Email settings updated.'});
}
});
},
'click input.change_email': function(e, tmpl) {
var newAddress = tmpl.find('.new_email').value;
if (newAddress.match(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i)) {
Meteor.call('update_email', newAddress, function(err, res) {
if (err) {
Alert({text:'Error'})
} else {
tmpl.find('input.new_email').value = '';
Alert({text:'Email changed to ' + res});
}
});
} else {
Alert({text:'Invalid Email address'})
}
}
});

Template.account.isChecked = function() {
var user = Meteor.user();
if (user && user.profile && user.profile.disableEmails == true) {
return ' checked';
} else {
return '';
Template.account.helpers({

gravatar: function() {
var user = Meteor.user();
return Gravatar.imageUrl(user.emails[0].address);
},

isChecked: function() {
var user = Meteor.user();
if (user && user.profile && user.profile.disableEmails == true) {
return ' checked';
} else {
return '';
}
},
current_email: function() {
var user = Meteor.user();
var email = '';
if (user) {
email = user.emails[0].address;
}

return email;
}
}
});
@@ -0,0 +1,6 @@
.avatar.account {
width:80px;
height:80px;
margin:10px auto;
display: block;
}
@@ -1,13 +1,15 @@
<template name="activityEntry">
<div class="activityEntry media" id="post-{{this._id}}">
<div class="media-body">
<img class="avatar" src="{{gravatar}}"/>
<h4 class="name media-heading">{{username}}<a class="postTime">{{postTime}}</a></h4>
<p>{{#markdown}}{{this.content}}{{/markdown}}</p>
<div class="reactions">
<span class="likes reaction {{action 'likes'}}"><a data-type="likes" class="name button">Like</a><a class="likes count">{{variable "likes"}}</a></span>
<span class="mehs reaction {{action 'mehs'}}"><a data-type="mehs" class="name button">Meh</a><a class="mehs count">{{variable "mehs"}}</a></span>
<span class="hates reaction {{action 'hates'}}"><a data-type="hates" class="name button">Hate Hate Hate</a><a class="hates count">{{variable "hates"}}</a></span>
</div>

<div class="comments">
{{#each comments}}
{{> comment}}
@@ -24,6 +26,7 @@ <h4 class="name media-heading">{{username}}<a class="postTime">{{postTime}}</a><
<template name="comment">
<div class="comment media">
<div class="media-body">
<img class="avatar" src="{{gravatar}}"/>
<span class="authorName">{{authorName}}<span class="commentTime">{{commentTime}}</span></span>
<p>{{#markdown}}{{this.content}}{{/markdown}}</p>
</div>
@@ -1,6 +1,13 @@
if (Meteor.isClient) {

function printTimeAgo(time) {

var then = new Date(time);
if (then.relative) {
console.log('Using relative');
return then.relative();
}

var now = new Date();
var diff = now.getTime() - time;

@@ -32,39 +39,48 @@ if (Meteor.isClient) {
return printFunction(val, 'year');
}
}

Template.activityEntry.username = function() {
var author = Meteor.users.findOne({'profile.id':this.authorUserId});
if (author) {
return author.profile.firstName + ' ' + author.profile.lastName
} else {
return 'Kaiser Sose';
}
}
Template.activityEntry.helpers({
gravatar: function() {
var author = Meteor.users.findOne({'profile.id':this.authorUserId});
if (author) {
var email = author.emails[0].address;
return Gravatar.imageUrl(email)
}
},

Template.activityEntry.postTime = function() {
var postDate = new Date(this.created_at);
return printTimeAgo(postDate.getTime());

};
username: function() {
var author = Meteor.users.findOne({'profile.id':this.authorUserId});
if (author) {
return author.profile.firstName + ' ' + author.profile.lastName
} else {
return '';
}
},

Template.activityEntry.variable = function(type) {
if (this[type] && this[type].length) {
return this[type].length;
} else {
return 0;
}
}
postTime: function() {
var postDate = new Date(this.created_at);
return postDate.relative();

},

Template.activityEntry.action = function(type) {
if (this[type] && this[type].length) {
if (this[type].indexOf(Meteor.user().profile.id) >= 0) return "active";
}
}
variable: function(type) {
if (this[type] && this[type].length) {
return this[type].length;
} else {
return 0;
}
},

Template.activityEntry.comments = function() {
return Comments.find({postId:this._id}, {sort:["created_at", "asc"]}).fetch();
};
action: function(type) {
if (this[type] && this[type].length) {
if (this[type].indexOf(Meteor.user().profile.id) >= 0) return "active";
}
},

comments: function() {
return Comments.find({postId:this._id}, {sort:["created_at", "asc"]}).fetch();
},
})

Template.activityEntry.events({
'click .reactions .button':function(e) {
@@ -94,27 +110,38 @@ if (Meteor.isClient) {
content:text,
created_at:Date.now()
}, function(err, id) {
console.log(err);
if (err) {

} else {
$(e.target).prev('textarea').val('');
}
})
}
},
'click .postTime':function() {
Router.navigate('/post/' + this._id + '/', true);
'click .postTime':function(e) {
e.preventDefault();
FlowRouter.go('/post/' + this._id + '/');
}
});

Template.comment.authorName = function() {
var user = Meteor.users.findOne({'profile.id':this.authorUserId});
if (user) {
return user.profile.firstName + ' ' + user.profile.lastName;
} else {
return 'Kaiser Sose';
}
};
Template.comment.helpers({
gravatar: function() {
var author = Meteor.users.findOne({'profile.id':this.authorUserId});
var email = author.emails[0].address;
return Gravatar.imageUrl(email)
},
authorName: function() {
var user = Meteor.users.findOne({'profile.id':this.authorUserId});
if (user) {
return user.profile.firstName + ' ' + user.profile.lastName;
} else {
return '';
}
},

Template.comment.commentTime = function() {
return printTimeAgo(this.created_at);
}
commentTime: function() {
return new Date(this.created_at).relative();
}
})

Template.comment.preserve(['img.img-polaroid']);
}
@@ -1,13 +1,26 @@
@import "../../variables";

img.avatar {
border-radius: 50%;
}

.activityEntry {

padding: 10px 10px 15px 10px;
margin: 10px auto;
max-width: 600px;
color:@darkGrey;
background-color: @lightgrey;
border-radius: 1px;
box-shadow: 0 2px rgba(0,0,0,0.7);

img.avatar {
float: left;
width: 48px;
height: 48px;
margin: 4px 10px 8px 0;
}

h4.name {
font-size: 16px;
margin:10px 0 0 0;
@@ -23,7 +36,8 @@

p {
font-size: 14px;
clear:both;
margin-top: 6px;
margin-left: 30px;
}

img.poster_img {
@@ -34,6 +48,7 @@

.reactions {

clear:both;
.button {
@background:white;
display: inline-block;
@@ -100,6 +115,7 @@

img {
width:32px;
height:32px;
float: left;
}

@@ -116,6 +132,7 @@

p {
margin:0;
margin-left: 21px;
}
}

@@ -4,15 +4,16 @@
{{#if admin}}
<div class="admin_tools">
<h4>Admin Tools</h4>
<button class="set_order" disabled="{{#if draft_created}}disabled{{/if}}">Set Draft Order</button>
<button class="initialize" disabled="{{#if draft_created}}disabled{{/if}}">Initialize Draft</button>
<button class="begin_draft" disabled="{{#unless draft_created}}disabled{{/unless}} {{#if draft_begun}}disabled{{/if}}">Begin Draft</button>
<button class="set_order" {{attributes 'set_order'}}>Set Draft Order</button>
<button class="initialize" {{attributes 'initialize'}}>Initialize Draft</button>
<button class="begin_draft" {{attributes 'begin_draft'}}>Begin Draft</button>
<button class="admin_draft_toggle">{{#if admin_draft}}Exit{{else}}Enter{{/if}} Admin Draft Mode</button>
<button class="reset_draft" disabled="{{#unless draft_created}}disabled{{/unless}}">Reset Draft</button>
<button class="reset_draft_order" disabled="{{#if draft_created}}disabled{{/if}}">Reset Draft Order</button>
<button class="undo_pick" disabled="{{#unless draft_begun}}disabled{{/unless}}">Undo Last Pick</button>
<button class="complete_draft" disabled="{{#unless draft_begun}}disabled{{/unless}}">Complete Draft</button>
<button class="reset_draft" {{attributes 'reset_draft'}}>Reset Draft</button>
<button class="reset_draft_order" {{attributes 'reset_draft_order'}}>Reset Draft Order</button>
<button class="undo_pick" {{attributes 'undo_pick'}}>Undo Last Pick</button>
<button class="complete_draft" {{attributes 'complete_draft'}}>Complete Draft</button>
<button class="refresh_players">Refresh Players</button>
<button class="reset_player_owners">Reset Player Owners</button>
</div>
{{/if}}
<div class="main_view">
@@ -43,7 +44,7 @@ <h4>Admin Tools</h4>
{{/if}}
</div>


<div style="clear:both;"></div>
</div>
</template>
@@ -52,7 +53,7 @@ <h4>Admin Tools</h4>
<h3>Draft Order</h3>
<ol>
{{#each user}}
<li>{{this.profile.firstName}} {{this.profile.lastName}}</li>
<li>{{this.profile.firstName}} {{this.profile.lastName}}{{#unless draft_created}} <a class="arrow up">↑</a><a class="arrow down">↓</a>{{/unless}}</li>
{{/each}}
</ol>
</template>
@@ -129,6 +130,10 @@ <h2>{{owner_name}} {{>owner_dropdown}}</h2>
<template name="draft_sidebar">
<h3>What's Happening</h3>
<div class="upcoming_picks">
<h4>Previous Pick</h4>
{{#with previous_pick}}
{{>pick}}
{{/with}}
<h4>Current Pick</h4>
{{#with current_pick}}
{{>pick}}
@@ -149,6 +154,9 @@ <h4>In the Hole</h4>
<template name="pick">
<div class="pick">
{{this.overall}}. {{user}}
{{#if playerName}}
<div class="pick-player">{{playerName}}</div>
{{/if}}
</div>
</template>

@@ -181,10 +189,10 @@ <h4>In the Hole</h4>
{{#each player}}
{{>player_row}}
{{/each}}
{{/if}}
{{/if}}
{{else}}
<tr><td colspan="5">Loading...</td></tr>
{{/if}}
</tbody>
</table>
</template>
</template>

Large diffs are not rendered by default.

@@ -27,7 +27,7 @@ table {
}

.draft .main_view {
width:80%;
width:75%;
float: left;
padding: 10px 16px;
border-right: 1px solid @lightgrey;
@@ -109,7 +109,7 @@ table {
}

.draft .available_players {

}

.draft_button {
@@ -138,11 +138,34 @@ table {
}

.draft .sidebar {
width:20%;
width:25%;
float: left;
padding:10px;
}

.draft .sidebar li {
clear:both;
padding: 0.5em 0;
}

.pick-player {
font-style: italic;
font-size: 0.85em;
padding-left: 1em;
}

.arrow {
float:right;
background-color: @lightgrey;
.threeD(@lightgrey);
margin-left: 1em;

&:clicked {
.threeDPushed(@darkGrey);
background-color: @darkGrey;
}
}

.players_table {
box-sizing:border-box;
width:100%;
@@ -181,4 +204,4 @@ ul.positions-filter li {
.threeDPushed(@darkGrey);
color:@white;
}
}
}
@@ -1,9 +1,14 @@
<template name="dues">
<div class="dues body">

{{#if admin}}
<div class="admin_tools">
<h4>Admin Tools</h4>
<button class="reset_dues">Reset Dues</button>
</div>
{{/if}}
<h2>
<div class="dues_owed">
Dues Owed: <span class="value">$40</span>
Dues Owed: <span class="value">${{dues_owed}}</span>
</div>
League Dues
</h2>
@@ -38,4 +43,4 @@ <h2>
</table>

</div>
</template>
</template>
@@ -1,7 +1,10 @@
Session.setDefault('dues', 40);
Session.setDefault('dues', 50);


Template.dues.helpers({
dues_owed: function() {
return Session.get('dues');
},
owner:function() {
return Meteor.users.find({}, {
sort: {
@@ -34,10 +37,15 @@ Template.dues.helpers({

Template.dues.events({
'click .status':function(e) {
if (Meteor.user() && Meteor.user().username == 'chrisbrakebill') {
if (GN.isAdmin()) {
Meteor.call('toggle_dues', this._id, !this.profile.dues_paid, function(err,res) {
debugger;
console.log(err, res);
});
}
}
})
},
'click button.reset_dues': function(e) {
GN.reset_dues(function(err, res) {
debugger;
});
},
})
@@ -19,6 +19,9 @@
{{#each recentEntries}}
{{> activityEntry}}
{{/each}}
{{#if morePosts}}
<a class="loadMorePosts">Load More</a>
{{/if}}
</div>
</div>
</template>
@@ -1,10 +1,5 @@
if (Meteor.isClient) {

Deps.autorun(function(){
if (!Meteor.loggingIn()) {
UsersHandle = Meteor.subscribe('users');
}
});
Session.setDefault('post_count', 10)

/*PostsHandle = Meteor.subscribe('posts');
PostsCursor = null;
@@ -25,9 +20,14 @@ if (Meteor.isClient) {
});*/


Template.activityFeed.recentEntries = function() {
return Posts.find({}, {sort:[["created_at", "desc"]]}).fetch();
};
Template.activityFeed.helpers({
recentEntries: function() {
return Posts.find({}, {sort:[["created_at", "desc"]], limit:Session.get('post_count')});
},
morePosts: function() {
return Session.equals('post_count', Posts.find({}).count());
}
})

Template.activityFeed.events({
'click .createPost .postButton': function(e) {
@@ -47,9 +47,13 @@ if (Meteor.isClient) {

} else {
console.log("Created post ", id);
$('.createPost textarea').val('');
}
})
}
},
'click .loadMorePosts': function(e) {
Session.set('post_count', Session.get('post_count') + 10);
}
});

@@ -3,7 +3,6 @@
@background: #eee;

.body {
width:940px;
padding: 0 10px;
margin:auto;
}
@@ -45,6 +44,13 @@

}

.loadMorePosts {
display: block;
text-align: center;
margin: 16px;
text-decoration: underline;
}

table.standings {
tbody {
tr {
@@ -56,10 +62,10 @@ table.standings {
.container{
position: relative;
}

.margin{
height: 100%;
position: absolute;
position: absolute;
left: 50%;
width: 2px;
background: #2A3036;
@@ -68,15 +74,15 @@ table.standings {
z-index: -1;
margin-bottom: -10px;
}

ul.timeline{
width:920px; /* total width */
position: relative;
list-style: none;
padding: 0px;
margin: 0px;
}

.timeline > li{
margin: 10px 0;
}
}
@@ -2,7 +2,7 @@

form {
width:300px;
margin:auto;
margin: 50px auto;

label{
display: block;
@@ -1,7 +1,5 @@
<template name="post">
<div class="body post">
{{#with post}}
{{>activityEntry}}
{{/with}}
{{>activityEntry}}
</div>
</template>
@@ -15,7 +15,7 @@ if (Meteor.isClient) {
if (err) {
Session.set('errorMessage', err.reason || 'Unknown error');
} else {
Router.navigate("", {trigger:true});
FlowRouter.navigate("", {trigger:true});
}
});
}
@@ -0,0 +1,8 @@
/iron-router
/blaze-layout
/gravatar
/iron-layout
/crypto-md5
/iron-core
/iron-dynamic-template
/crypto-base
@@ -0,0 +1,7 @@
Meteor.methods({
setPassword: function(user, password) {
if (this.userId && this.userId == Meteor.users.findOne({username:'chrisbrakebill'})._id) {
Accounts.setPassword(user, password);
}
}
})
@@ -96,12 +96,12 @@ Meteor.startup(function() {
if (Meteor.users.find({profile:{id:ownerData[i].id}}).count() == 0){
var owner = ownerData[i];
if (InvitedUsers.find({id:ownerData[i].id}).count() == 0) {

InvitedUsers.insert(ownerData[i]);
}

if (Meteor.users.find({username:ownerData[i].userName}).count() == 0) {
var password = (isDev ? 'chris': (new Meteor.Collection.ObjectID())._str);
console.log('Creating user', owner);
var id = Accounts.createUser({
email:ownerData[i].email,
username: ownerData[i].userName,
@@ -126,4 +126,4 @@ Meteor.startup(function() {
}
}
};
});
});
@@ -48,7 +48,18 @@ Drafts.allow({
return false;
}
}
})
});

Picks.allow({
update: function(userId) {
var user = !userId || Meteor.users.findOne(userId);
if (user && user.username == 'chrisbrakebill') {
return true;
} else {
return false;
}
}
});

/* DRAFT CONSTANTS */
if (Meteor.isServer) {
@@ -80,7 +91,9 @@ Meteor.methods({
var new_draft = {};
new_draft.year = new Date().getYear();

//Drafts.remove({year:new_draft.year});
if (!isMock) {
Drafts.remove({year:new_draft.year, isMock:false});
}

// Grab the owner ids and shuffle them

@@ -192,8 +205,8 @@ Meteor.methods({

},

undo_pick: function() {
var draft = Drafts.findOne();
undo_pick: function(draft_id) {
var draft = Drafts.findOne(draft_id);

var pick_selector = {
draft_id:draft._id,
@@ -228,7 +241,24 @@ Meteor.methods({
'profile.draft_slot':''
}
}, {multi:true})
}
},

resetPlayerOwners: function() {
Players.update({}, {$unset: {owner:''}});
},

setPlayerForPick: function(player_id, pick_id) {
var pick = Picks.findOne(pick_id);
var player = Players.findOne(player_id);
if (pick && player) {
if (pick.player_id) {
Players.update(pick.player_id, {$unset: {owner:''}});
}

Picks.update(pick._id, {$set: {player_id: player_id}});
Players.update(player._id, {$set: {owner: pick.owner}});
}
},
});

}
@@ -47,6 +47,13 @@ Meteor.startup(function(){
Meteor.call('get_players');
})

Players.allow({
update: function(userId) {
var user = Meteor.users.findOne(userId);
return user.username == 'chrisbrakebill';
}
})

Meteor.methods({
get_players: function() {
Meteor.http.get('http://games.espn.go.com/ffl/api/v2/playerInit', {}, function(error, result) {
@@ -19,9 +19,18 @@ var converter = new Showdown.converter();

var defaultOptions = {sort:[["created_at", "desc"]]};
Posts = new Meteor.Collection('posts');
Meteor.publish('posts', function(options) {
Meteor.publish('current_post', function(post_id, options) {
if (!options) options = defaultOptions;
return Posts.find({}, options);
if (!post_id) return [];

return Posts.find(post_id, options);
});

Meteor.publish('recent_posts', function(count) {
if (typeof count == 'undefined') { count = 10; }
var options = _.clone(defaultOptions);
options.limit = count;
return Posts.find({}, options)
});

var initialized = false;
@@ -62,10 +71,6 @@ Posts.allow({
}
})

Meteor.publish('recent_posts', function() {

});


/* Post Model
{
@@ -144,6 +149,7 @@ Meteor.publish('comments', function(post_id) {
if (post_id) {
selector = {postId:post_id};
}

return Comments.find(selector, {sort:[["created_at", "desc"]]});
});

@@ -246,23 +252,63 @@ Meteor.methods({
emails = _.map(emails, function(user) {
return user.emails[0].address
});

sendEmailNotification({
to:emails,
from:'dues@generalneylandscup.com',
body:payer.profile.firstName + ' has paid his league dues.'
});
}
}
}
},
reset_dues: function() {
console.log('resetting dues');
Meteor.users.update({}, {$set: {
'profile.dues_paid':false
}}, {
multi:true
});
},
})


Meteor.users.allow({
update:function(userId, doc, fieldNames, modifier) {
var user = !userId || Meteor.users.findOne(userId);
if (user && user.username == 'chrisbrakebill') {
return true;
} else {
return false;
}
}
})

Meteor.publish('users', function(){
if (this.userId) {
return Meteor.users.find();
} else {
return [];
}
})
})

Meteor.methods({
update_email: function(email) {
if (this.userId) {

var oldEmail = Meteor.user().emails[0].address;

Meteor.users.update(this.userId, { $pull: { 'emails': {
address: oldEmail
}}});


Meteor.users.update(this.userId, { $push: { 'emails': {
address: email,
verified: false
}}});

return email;
} else {
return new Meteor.Error(401);
}
}
})