-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
50 lines (45 loc) · 1.4 KB
/
main.js
File metadata and controls
50 lines (45 loc) · 1.4 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
$(document).ready(function(){
url = "https://spreadsheets.google.com/feeds/list/1MQnK8Wl5IfnBgLBP9Ab-pCp6Di-V3vRmNoi2sRC3N2E/od6/public/values?alt=json"
$.getJSON(url, function(json){
var data = clean_google_sheet_json(json);
compile_and_insert_html('#table_template','#myTable',data);
compile_and_insert_html('#section_template','#mySection',data);
compile_and_insert_html('#grid_template','#myGrid',data);
});
});
// Takes in template id, compiles the template to html using data json object
// and then inserts it into given div id
function compile_and_insert_html(template_id, div_id, data) {
var template = _.template($(template_id).html());
var template_html = template({
'rows': data
});
$(div_id).html(template_html);
}
// takes in JSON object from google sheets and turns into a json formatted
// this way based on the original google Doc
// [
// {
// 'column1': info1,
// 'column2': info2,
// }
// ]
function clean_google_sheet_json(data){
var formatted_json = [];
var elem = {};
var real_keyname = '';
$.each(data.feed.entry, function(i, entry) {
elem = {};
$.each(entry, function(key, value){
// fields that were in the spreadsheet start with gsx$
if (key.indexOf("gsx$") == 0)
{
// get everything after gsx$
real_keyname = key.substring(4);
elem[real_keyname] = value['$t'];
}
});
formatted_json.push(elem);
});
return formatted_json;
}