-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
70 lines (56 loc) · 2.11 KB
/
app.js
File metadata and controls
70 lines (56 loc) · 2.11 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
63
64
65
66
67
68
69
70
angular.module('notelendar', [])
.controller('notelendarCtrl', ['$scope', 'storage', function ($scope, storage) {
$scope.editingDay = null;
$scope.displayedYear = new Date().getFullYear();
$scope.displayedMonth = new Date().getMonth();
$scope.monthWeeks = [];
function calculateWeeks(year, month) {
var weeks = [],
notes = storage.retrieve(year, month),
theFirstDayOfWeek = new Date(year, month, 1).getDay(),
day = 1 - theFirstDayOfWeek,
daysInMonth = new Date(year, month + 1, 0).getDate();
while (day <= daysInMonth) {
var week = [];
for (var i = 0; i < 7; i++) {
week.push(day > 0 && day <= daysInMonth ? { year: year, month: month, date: day, note: notes[day] || '' } : {});
day++;
}
weeks.push(week);
week = [];
}
$scope.monthWeeks = weeks;
}
$scope.$watchGroup(['displayedYear', 'displayedMonth'], function (newValues) {
calculateWeeks(newValues[0], newValues[1]);
});
calculateWeeks($scope.displayedYear, $scope.displayedMonth);
$scope.isCurrent = function (day) {
var now = new Date;
return day.year === now.getFullYear() && day.month === now.getMonth() && day.date === now.getDate();
};
$scope.editNote = function (day) {
if (!day.date) return;
$scope.editingDay = day;
};
$scope.saveNote = function (day) {
storage.save($scope.displayedYear, $scope.displayedMonth, day.date, day.note);
$scope.editingDay = null;
};
$scope.nextMonth = function () {
$scope.displayedMonth++;
if ($scope.displayedMonth > 11) {
$scope.displayedMonth = 0;
$scope.nextYear();
}
};
$scope.prevMonth = function () {
$scope.displayedMonth--;
if ($scope.displayedMonth < 0) {
$scope.displayedMonth = 11;
$scope.prevYear();
}
};
$scope.nextYear = function () { $scope.displayedYear++; };
$scope.prevYear = function () { $scope.displayedYear--; };
}]);