-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.html
More file actions
115 lines (97 loc) · 3.3 KB
/
script.html
File metadata and controls
115 lines (97 loc) · 3.3 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
<script>
//get the oauth information
function getOauth(){
google.script.run.withSuccessHandler( function(data){
var oathLink = document.getElementById("oauthLink");
console.log(data)
if(data != ""){
console.log(data);
oathLink.href= data;
}
else{
oathLink.innerHTML = "successfully connect to google fit "
oathLink.addEventListener("click", function(){
oathLink.style.display="none"
});
setTimeout(function(){ oathLink.style.display="none" }, 10000);
}
}).withFailureHandler(showError).getOauth2();
}
function showError(message, isError) {
var messageDiv = document.getElementById('messageDiv');
messageDiv.classList.remove("error", "alert");
if(isError){
console.log(message);
messageDiv.innerHTML = 'Error: ' + message;
messageDiv.classList.add("error");
}
else{
messageDiv.innerHTML = message;
messageDiv.classList.add("alert");
setTimeout(function(){ messageDiv.style.display="none" }, 10000);
}
messageDiv.style.display="inherit";
messageDiv.addEventListener("click", function(){
messageDiv.style.display="none"
});
console.log(message);
}
function formSumit(event){
event.preventDefault();
document.getElementById('messageDiv').style.display="none";
var kvpairs = {};
var form = document.getElementById("settingForm");
var fitDataTypes = [];
for ( var i = 0; i < form.elements.length; i++ ) {
var e = form.elements[i];
if(e.type == "checkbox"){
if(e.checked == true){
fitDataTypes.push(e.name);
}
}
else if(e.name !="submit"){
kvpairs[e.name] = e.value;
}
}
kvpairs["fitSyncData"] = fitDataTypes;
console.log(kvpairs)
if(kvpairs["fitSyncData"].length !== 0){
google.script.run.withSuccessHandler( function(data){
showError("success", false)
}).withFailureHandler(showError).savePageSetting(kvpairs);
}
else{
showError("please select a item to sync", true)
}
return false;
}
function getPageSetting(){
google.script.run.withSuccessHandler( function(data){
var keys = Object.keys(data)
keys.forEach(function(key){
if(key == "fitSyncData"){
data["fitSyncData"].forEach(function(id){
document.getElementById(id).checked = true;
});
}
else{
document.getElementById(key).value = data[key];
}
})
console.log(data)
}).withFailureHandler(showError).getPageSetting();
}
document.getElementById("refreshButton").addEventListener('click',function(){
google.script.run.withSuccessHandler( function(data){
showError("success", false)
}).withFailureHandler(showError).loadDataToSpreadSheet();
});
//function parseError(error){
// if()
//}
getOauth();
getPageSetting();
var toggleHelpPage = function(){
document.getElementById("helpPage").classList.toggle("hideHelpPage");
}
</script>