-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvideo-form.js
More file actions
44 lines (36 loc) · 1.11 KB
/
video-form.js
File metadata and controls
44 lines (36 loc) · 1.11 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
class VideoForm {
constructor(formOverlay, database) {
this.overlay = formOverlay;
this.form = formOverlay.querySelector("#add-video");
this.database = database;
var that = this; // keep the class instance for the closure
// Intercept form submission and parse it as JSON
this.form.addEventListener( "submit", function( e ) {
e.preventDefault();
var json = that.getFormData( this );
that.database.addVideo(json);
that.close();
}, false);
}
getFormData( form ) {
var obj = {};
var elements = form.querySelectorAll( "input, select, textarea" );
for( var i = 0; i < elements.length; ++i ) {
var element = elements[i];
var name = element.name;
var value = element.value;
if( name ) {
obj[ name ] = value;
}
}
return obj;
}
open(){
this.form.reset();
this.overlay.classList.add('visible');
}
close(){
this.form.reset();
this.overlay.classList.remove('visible')
}
}