-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
123 lines (111 loc) · 3.15 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<title>Andrew Mandula</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<script src="jQuery.js"></script>
<script type="text/javascript" src="https://www.dropbox.com/static/api/2/dropins.js" id="dropboxjs" data-app-key="KEY_GOES_HERE"></script>
<script src="reporterUtils.js"></script>
<script>
// Setup
"use strict";
window.onload = init;
// Globals
var dropBoxFiles = [];
var reporterObjects = [];
var responses = [];
var dataIndex = 0;
var options = {
success: function(files) {
clearData();
dropBoxFiles = files;
setDataFromDropboxFiles(dropBoxFiles);
},
cancel: function() {
clearData();
},
linkType: "direct",
multiselect: true,
extensions: ['.json']
};
// Functions
function init() {
// Remote files
// Add dropbox chooser button to the page
var button = Dropbox.createChooseButton(options);
var content = document.querySelector("#content");
content.appendChild(button);
// Local files (for testing)
var localTestInputs = document.querySelector('#localTestInputs');
var fileReader = new FileReader();
// Add "Choose a file" button
var fileInput = document.createElement('input');
fileInput.type = 'file';
localTestInputs.appendChild(fileInput);
// Add the question text field
var questionPrompt = document.createElement('input');
questionPrompt.type = 'text';
localTestInputs.appendChild(questionPrompt);
// Add "Submit Question" button
var submitPrompt = document.createElement('input');
submitPrompt.type = 'button';
submitPrompt.value = 'Submit Question';
localTestInputs.appendChild(submitPrompt);
// When the file input has changed
fileInput.addEventListener('change', function(e) {
console.log('changed fileInput');
for (var i = 0; i < fileInput.files.length; i++) {
fileReader.readAsText(fileInput.files[i]);
}
});
// When the file has been loaded
fileReader.addEventListener('loadend', function(e) {
console.log('file loaded successfully');
var reporterObject = JSON.parse(fileReader.result);
var response = getResponses(reporterObject);
reporterObjects.push(reporterObject);
responses.push(response);
console.log(response);
});
// When the user wants to check a question
submitPrompt.addEventListener('click', function(e) {
console.log(getQuestionData(questionPrompt.value));
});
}
function setDataFromDropboxFiles(files) {
// Parse JSON object from each dropbox file
for (var i = 0; i < files.length; i++) {
var file = files[i];
$.getJSON(file.link, function(jsonData){
console.log(jsonData);
// push data
reporterObjects.push(jsonData);
var response = getResponses(jsonData);
responses.push(response);
});
}
}
// Clear global data
function clearData() {
dropBoxFiles = [];
reporterObjects = [];
responses = [];
}
</script>
</head>
<body>
<h1 id="header">ANDREW MANDULA</h1>
<section id='content'>
<h3>Test</h3>
<p>
Test
</p>
<h3>Other Test</h3>
<p>
Other Test
</p>
</section>
<section id='localTestInputs'></section>
</body>
</html>