-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign-up.js.html
266 lines (259 loc) · 7.5 KB
/
sign-up.js.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
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
<script type="text/babel">
var fieldDefault = {
"inputType": "text",
"maxLength": 10,
"example": "TBD"
};
var fields = {
"word": {
"word": {
"title": "Word",
"name": "word.word",
"example": "toastmaster",
"maxLength": 20,
},
"pronunciation": {
"title": "Pronunciation",
"name": "word.pronunciation",
"example": "TOHST-mas-ter",
"maxLength": 20,
},
"class": {
"title": "Word Class",
"name": "word.class",
"example": "noun"
},
"definition":{
"title": "Definition",
"name": "word.definition",
"example": "a person who presides at a dinner and introduces the after-dinner speakers",
"inputType": "textarea",
"rows": 5,
"maxLength": 120
},
"usage":{
"title": "Usage",
"name": "word.usage",
"example": "The toastmaster announced the bridal party to the assembled guests.",
"inputType": "textarea",
"rows": 5,
"maxLength": 110
}
},
"roles": {
"toastmaster": {
"title": "Toastmaster",
"name":"toastmaster"
},
"speaker1": {
"title": "Speaker 1",
"name": {
"title": "Speaker1 Name",
"name":"speaker1.name"
},
"projectNumber": {
"title": "Project Path & Level",
"name":"speaker1.projectNumber",
"example": "Presentation Mastery #1",
"inputType": "textarea",
"rows": 2,
"maxLength": 50
},
"projectName": {
"title": "Project Name",
"name":"speaker1.projectName",
"example": "Ice Breaker",
"inputType": "textarea",
"rows": 2,
"maxLength": 50
},
"speechName": {
"title": "Speech Title",
"name":"speaker1.speechName",
"example": "The Story of My Life",
"maxLength": 50
}
},
"speaker2": {
"title": "Speaker 2",
"name": {
"title": "Speaker2 Name",
"name":"speaker2.name"
},
"projectNumber": {
"title": "Project Path & Level",
"name":"speaker2.projectNumber",
"example": "Dynamic Leadership #2",
"inputType": "textarea",
"rows": 2,
"maxLength": 50
},
"projectName": {
"title": "Project Name",
"name":"speaker2.projectName",
"example": "Researching & Presenting",
"inputType": "textarea",
"rows": 2,
"maxLength": 50
},
"speechName": {
"title": "Speech Title",
"name":"speaker2.speechName",
"example": "My Research Speech",
"maxLength": 50
}
},
"genEvaluator": {
"title":"General Evaluator",
"name":"genEvaluator"
},
"evaluator1": {
"title":"Evaluator 1",
"name":"evaluator1"
},
"evaluator2": {
"title":"Evaluator 2",
"name":"evaluator2"
},
"topicsmaster": {
"title":"Topicsmaster",
"name":"topicsmaster"
},
"ah-counter": {
"title":"Ah-Counter",
"name":"ah-counter"
},
"timer": {
"title":"Timer",
"name":"timer"
},
}
};
class Field extends React.Component {
constructor(props) {
super(props);
this.state = {saved: " "};
this.save = this.save.bind(this);
this.onChange = this.onChange.bind(this);
}
save(e) {
var newValue = e.target.value;
var update = {};
update[this.props.name] = newValue;
this.props.functions.save(update);
this.setState({saved: "✅"});
}
onChange(e) {
var newValue = e.target.value;
var update = {};
update[this.props.name] = newValue;
this.props.functions.update(update);
this.setState({saved: "💬️"});
}
render() {
var value = this.props.data[this.props.name];
var example = this.props.example && "e.g. " + this.props.example || fieldDefault.example;
var inputType = this.props.inputType || fieldDefault.inputType;
var maxLength = this.props.maxLength || fieldDefault.maxLength;
if (inputType == 'textarea') {
var rows = this.props.rows || "default";
var input = <textarea onChange={this.onChange} onBlur={this.save} placeholder={example} maxLength={maxLength} rows={rows} value={value}></textarea>;
} else {
input = <input type="text" onChange={this.onChange} onBlur={this.save} placeholder={example} maxLength={maxLength} value={value} />;
}
var emptyMarker = value ? "" : " ❗";
return <label className="field">
<span className="fieldTitle">{this.props.title}{emptyMarker}</span>
{input}
<span className="status">{this.state.saved}</span>
<span className="maxLength">{value.length}/{maxLength} characters</span>
</label>
}
}
class Word extends React.Component {
render() {
var self = this;
return <fieldset id="wordOfTheDay">
<legend>Word of the Day</legend>
{Object.keys(this.props.display).map((field) => {
var details = self.props.display[field];
return <Field key={field} functions={self.props.functions} data={self.props.data} {...details} /> })}
</fieldset>
}
}
class Speaker extends React.Component {
render() {
var self = this;
return <fieldset className="speaker">
<legend>{this.props.display.title}</legend>
{Object.keys(this.props.display)
.map((field) => {
var details = self.props.display[field];
if (details instanceof Object) {
return <Field key={field} functions={self.props.functions} data={self.props.data} {...details} />;
}
})}
</fieldset>;
}
}
class Roles extends React.Component {
render() {
var self = this;
var roles = Object.keys(this.props.display).map((field) => {
var details = self.props.display[field];
if (details) {
if (field.startsWith("speaker")) {
return <Speaker key={field} functions={self.props.functions} data={self.props.data} display={details} />;
} else {
return <Field key={field} functions={self.props.functions} data={self.props.data} {...details} />;
}
}
});
return <fieldset id="roles">
<legend>Meeting Roles</legend>
{roles}
</fieldset>;
}
}
class SignUpForm extends React.Component {
constructor(props) {
super(props);
this.state = this.props.data;
this.functions = {
update: this.update,
save: this.save
};
this.functions.update = this.update.bind(this);
this.functions.save = this.save.bind(this);
this.reset = this.reset.bind(this);
}
save(data) {
this.setState(data, function() {
console.log(`data: ${JSON.stringify(data)}`);
sendUpdatedDataToSheet(data);
});
}
update(change) {
this.setState(change);
}
reset() {
var answer = prompt("Clear everything off the form?\nType yes or no", "");
if (answer.toLowerCase() === 'yes') {
var self = this;
Object.keys(this.state).forEach((key) => self.state[key] = "");
this.setState(this.state);
resetEverything();
}
}
render() {
return <React.Fragment>
<label id="meetingDate"><span className="fieldTitle">Meeting Date</span><input type="text" value={meetingDate} readOnly /></label>
<button id="clear" onClick={this.reset}>Clear ♻️️</button>
<Word data={this.state} functions={this.functions} display={this.props.word} />
<Roles data={this.state} functions={this.functions} display={this.props.roles} />
</React.Fragment>;
}
}
const element = <SignUpForm word={fields.word} roles={fields.roles} data={dataFromSheet} />;
ReactDOM.render(element, document.getElementById('signUpForm'))
</script>