/
vp.js
191 lines (155 loc) · 4.36 KB
/
vp.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
function vp_main($scope, $timeout, $window)
{
var gAccount = new AuthAccount();
gAccount.authClientID = vp_oauthClientID;
gAccount.authScope = 'https://www.googleapis.com/auth/calendar.readonly https://www.googleapis.com/auth/drive.appdata';
var gAppData = new AuthAppData();
gAppData.file_name = "settings001.json";
gAppData.setDefault({banner_text: "visual-planner", vipconfig: new VipGridConfig()});
gAppData.Patch = function(appdata) {
if (!appdata.vipconfig.hasOwnProperty("first_month"))
appdata.vipconfig.first_month = 1;
if (!appdata.vipconfig.hasOwnProperty("weekends"))
appdata.vipconfig.weekends = "6,0";
if (!appdata.vipconfig.hasOwnProperty("first_day_of_week"))
appdata.vipconfig.first_day_of_week = 0;
}
$scope.multi_col_count_options = {1: 1, 2: 2, 3: 3, 4: 4, 5: 5, 6: 6, 8: 8, 10: 10, 12: 12};
$scope.settings = gAppData.getAppData();
$scope.signed_in = false;
$scope.busy = false;
$scope.sign_msg = "Signing In...";
$scope.g_signbtn_ok = true;
gAccount.onSignIn = function() {
$scope.sign_msg = gAccount.getEmail();
$scope.$apply();
ReadAppdata();
}
gAccount.onSignOut = function() {
gAppData.setAppData(null);
$scope.settings = gAppData.getAppData();
$scope.form.$setPristine(true);
$scope.sign_msg = "Signed Out";
$scope.signed_in = false;
setView('home');
$scope.$apply();
initGrid();
}
gAccount.onError = function(msg) {
alert("Account Error: " + msg);
}
gAccount.Connect();
$scope.onclickPrintView = function() {
setView('print');
initPrintView();
ga_hit("feature", "print_view");
}
$scope.onclickClosePrintView = function() {
setView('home');
}
$scope.onclickSettings = function() {
setView('settings');
$scope.g_signbtn_ok = (document.getElementById("g_signbtn").textContent.length > 0);
}
$scope.onclickSignIn = function() {
gAccount.SignIn();
}
$scope.onclickSignOut = function() {
gAccount.SignOut();
}
$scope.onclickSave = function() {
$scope.busy = true;
WriteAppdata();
}
$scope.onclickCancel = function() {
$scope.settings = gAppData.getAppData();
$scope.form.$setPristine(true);
setView('home');
}
function ReadAppdata() {
gAppData.Read(
function() {
$scope.settings = gAppData.getAppData();
$scope.form.$setPristine(true);
$scope.signed_in = true;
setView('home');
$scope.$apply();
initGrid();
},
function(msg) {
alert("Error loading settings.\n\n" + msg);
ga_hit("appdata_error", msg);
}
);
}
function WriteAppdata() {
gAppData.Write(
$scope.settings,
function() {
$scope.busy = false;
$scope.form.$setPristine(true);
setView('home');
$scope.$apply();
initGrid();
},
function(msg) {
alert("Error saving settings.\n\n" + msg);
ga_hit("appdata_error", msg);
}
);
}
function initGrid() {
document.title = $scope.settings.banner_text;
var vg = new VipGrid("grid", "calendarbar");
if ($scope.signed_in)
{
var gCal = new AuthCal();
gCal.onError = onCalError;
vg.registerEventSource(gCal);
}
vg.cfg = $scope.settings.vipconfig;
vg.init();
}
function setView(view) {
$scope.view = view;
if (view == 'home')
$timeout(function(){$window.onresize();}, 100);
}
var cal_error_notified = false;
function onCalError(msg) {
if (cal_error_notified)
return;
alert("Error loading calendar events.\n\nPlease reload the page.\n\n" + msg);
ga_hit("calendar_error", msg);
cal_error_notified = true;
}
function initPrintView() {
var vipinfo = $window.vipgrid.getPrintViewInfo();
$scope.printinfo = {cols: [], rows: [], fontsize: vipinfo.fontsize};
for (var i=0; i < vipinfo.maxrows; i++)
{
var row = {cells: []};
for (var j=0; j < vipinfo.cols.length; j++)
row.cells.push({days: []});
$scope.printinfo.rows.push(row);
}
for (var icol=0; icol < vipinfo.cols.length; icol++)
{
var vipcol = vipinfo.cols[icol];
$scope.printinfo.cols.push(vipcol.hdr);
for (var icell=0; icell < vipcol.cells.length; icell++)
{
var vipcell = vipcol.cells[icell];
var printcell = $scope.printinfo.rows[icell + vipcol.offset].cells[icol];
printcell.colour = vipcell.colour;
var day = {num: vipcell.num, evts: []};
for (var ievt=0; ievt < vipcell.evts.length; ievt++)
{
var vipevt = vipcell.evts[ievt];
day.evts.push({title: vipevt.title, colour: vipevt.colour});
}
printcell.days.push(day);
}
}
}
}