-
Notifications
You must be signed in to change notification settings - Fork 25
/
Tasks.js
97 lines (82 loc) · 3.24 KB
/
Tasks.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
87
88
89
90
91
92
93
94
95
96
97
Tasks = new Meteor.Collection("Tasks");
if (Meteor.is_client) {
Meteor.autosubscribe(function () {
if(typeof Session.get("User") != "undefined" && typeof Session.get("Pass") != "undefined")
{
Meteor.subscribe("tasks", Session.get("User"), Session.get("Pass"));
}
});
var Months = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
Template.Main.SignedIn = function(){
return (typeof Session.get("User") == "undefined" || typeof Session.get("Pass") == "undefined") ? false : true;
};
Template.Tasks.DayString = function(){
var D = new Date(Session.get("Date"));
return "Tasks for " + Months[D.getMonth()] + ", " + D.getDate();
}
Template.Tasks.Editing = function(){
return Session.equals("Editing", this._id);
}
Template.Tasks.TasksForDate = function(){
return Tasks.find({'Date': Session.get("Date")});
}
Template.Tasks.DateString = function(){
var D = new Date(Session.get("Date"));
return Months[D.getMonth()] + ", " + D.getFullYear();
}
Template.Tasks.GetDays = function(){
var S = new Date(Session.get("Date"));
var D = new Date(S.getYear(), S.getMonth()+1, 0);
var Days = new Array({Number: "Su"}, {Number: "Mo"}, {Number: "Tu"}, {Number: "We"}, {Number: "Th"}, {Number: "Fr"}, {Number: "Sa"});
for(var i = 0; i<D.getDay(); i++){ Days.push({Number : " "}); }
for(var i = 0; i<D.getDate(); i++)
{
if(S.getDate() == i+1){ Days.push({'Number' : i+1, 'Class': " DaySelected"}); }
else{ Days.push({'Number' : i+1, 'Class': " DayClick"}); }
}
return Days;
}
function Check(id, Done){
Tasks.update({'_id': id}, { $set : {'Done' : !Done}});
}
function NewTask(){
Tasks.insert({ 'User' : Session.get("User"), 'Pass' : Session.get("Pass"), 'Date' : Session.get("Date"), 'Done' : false, 'Name' : "New Task (Click To Edit)" });
}
function adjustMonth(Num){
var D = new Date(Session.get("Date"));
if(D.getDate() > 28){ D.setDate(28); }
D.setMonth(D.getMonth()+Num);
Session.set("Date", D.toDateString());
}
Template.Login.events = {
'click #LoginButton':function(){
Session.set("User", document.getElementById("Username").value);
Session.set("Pass", document.getElementById("Password").value);
Session.set("Date", new Date().toDateString());
}
};
Template.Tasks.events = {
'click #TodosButton':NewTask,
'click #TodosBottom':NewTask,
'click .RowText':function(){ Session.set("Editing", this._id); },
'click .Close':function(){ Tasks.remove({'_id': this._id}); },
'click #NextMonth': function(){ adjustMonth(1); },
'click #LastMonth': function(){ adjustMonth(-1); },
'focus #TodosEdit':function(){ document.getElementById("TodosEdit").select(); },
'blur #TodosEdit':function(){
var tname = document.getElementById("TodosEdit").value;
if(tname == "")
tname = "New Task (Click To Edit)";
Tasks.update({'_id': Session.get("Editing")}, {$set : {'Name': tname}});
Session.set("Editing");
},
'click .DayClick':function(){
var D = new Date(Session.get("Date"));
D.setDate(this.Number);
Session.set("Date", D.toDateString());
}
};
}
if (Meteor.is_server) {
Meteor.publish("tasks", function(Username, Password){ return Tasks.find({User: Username, Pass: Password}); });
}