-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathScheduleTable.js
More file actions
197 lines (157 loc) · 5.16 KB
/
ScheduleTable.js
File metadata and controls
197 lines (157 loc) · 5.16 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
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
192
193
194
195
196
197
/*eslint-env jquery */
/*globals moment Laker*/
"use strict";
$(function() {
var config = [{
"cn": "varsity",
"divSched": "#varsity-scores",
"divRoster": "#varsity-roster",
"titleSched": "2015 Varsity Schedule",
"titleRoster": "2015 Varisty Roster"
}, {
"cn": "jv",
"divSched": "#jv-scores",
"divRoster": "#jv-roster",
"titleSched": "2015 Junior Varsity Schedule",
"titleRoster": "2015 Junior Varisty Roster",
}, {
"cn": "sophomore",
"divSched": "#sophomore-scores",
"divRoster": "#sophomore-roster",
"titleSched": "2015 Sophomore Schedule",
"titleRoster": "2015 Sophomore Roster"
}, {
"cn": "freshman",
"divSched": "#freshman-scores",
"divRoster": "#freshman-roster",
"titleSched": "2015 Freshman Schedule",
"titleRoster": "2015 Freshman Roster"
}];
// return the row class based on even/odd row and highlight
function rowClass(rowNum, highlight) {
var c = (rowNum % 2 === 0) ? "even_row" : "odd_row";
c += highlight ? " highlight" : "";
return {
"class": c
};
}
function applyCss() {
// shortcut to laker styles
var st = Laker.style,
center = {
"text-align": "center"
},
hdrCtr = $.extend({}, st.lakerHeader, center),
datCtr = $.extend({}, st.lakerData, center);
// apply css styles to the table
$(".laker_title").css(st.lakerTitle);
$(".laker_table").css(st.lakerTable);
$(".laker_head").css(st.lakerHeader);
$(".laker_head_ctr").css(hdrCtr);
$(".laker_data").css(st.lakerData);
$(".laker_data_ctr").css(datCtr);
$(".even_row").css(st.evenRow);
$(".highlight").css(st.highlightRow);
}
function writeSchedule(teamConfig) {
$.getJSON(Laker.Connection(teamConfig.cn, "scores"),
function(data) {
// return the string that publishes the game result
var gameResult = function(game) {
var r = "";
if (game.result.length > 0) {
r += game.result === "W" ? "" : " ";
r += game.result + " " + game.get("lakerscore");
r += "-" + game.get("opponentscore");
}
return r;
},
// create a new schedule from the json data
sched = new Laker.Schedule(data),
title = teamConfig.titleSched + " ({0} - {1} - {2})",
// new table object
tbl = new Laker.html.Table({
"class": "laker_table"
}),
// new table header object
header = tbl.createHeader({}, {
"class": "laker_head"
}),
// row object
row = {};
title = title.replace("{0}", sched.wins).replace("{1}", sched.losses);
title = title.replace("{2}", sched.ties);
//title = title.replace("{3}", sched.goalsFor).replace("{4}", sched
// .goalsAgainst);
tbl.createTitle(title, {
"class": "laker_title"
});
// add header columns
header.addTd("DATE").addTd("OPPONENT");
header.addTd("LOCATION").addTd("RESULT");
// iterate through each game on the schedule
$.each(sched, function(num, game) {
// create a table row with row and td classes
row = tbl.createRow(rowClass(num, (game.result === "W")), {
"class": "laker_data"
});
// add table data to the row
row.addTd(moment(game.gamedate).format('MM/DD/YYYY'));
row.addTd(game.get("opponent")).addTd(game.get(
"gamelocation"));
row.addTd(gameResult(game));
// add the row to the table
tbl.Rows.add(row);
});
// write the scores to the page
$(teamConfig.divSched).append(tbl.toString());
applyCss();
});
}
function writeRoster(teamConfig) {
$.getJSON(Laker.Connection(teamConfig.cn, "roster"),
function(data) {
var team = new Laker.Team(data),
tbl = new Laker.html.Table({
"class": "laker_table"
}),
// new table header object
header = tbl.createHeader({}, {
"class": "laker_head"
}),
headctr = {
"class": "laker_head_ctr"
},
datactr = {
"class": "laker_data_ctr"
},
// row object
row = {};
tbl.createTitle(teamConfig.titleRoster, {
"class": "laker_title"
});
header.addTd("NAME").addTd("JERSEY", headctr);
header.addTd("GRADE", headctr).addTd("POSITION", headctr);
$.each(team, function(num, player) {
row = tbl.createRow(rowClass(num, player.isCaptain), {
"class": "laker_data"
});
row.addTd(player.fullName).addTd(player.get("number"),
datactr);
row.addTd(player.get("grade"), datactr);
row.addTd(player.get("position"), datactr);
tbl.Rows.add(row);
});
$(teamConfig.divRoster).append(tbl.toString());
applyCss();
});
}
$.each(config, function(idx, team) {
if ($(team.divSched).length) {
writeSchedule(team);
}
if ($(team.divRoster).length) {
writeRoster(team);
}
});
});