-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
55 lines (50 loc) · 1.4 KB
/
index.js
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
var apiRoot = 'https://eventpartner.moveon.org/'
window.onload = function () {
Vue.component('submit-button', {
props: ['isDisabled', 'prompt'],
template: `<button
type="button"
class="btn pl-5 pr-5 pt-2 pb-2"
v-bind:disabled="isDisabled"
@click="$emit('submit-button-click')"
>{{ prompt }}</button>`
})
Vue.component('error-message', {
props: ['isOn', 'error'],
template: `<div class="mt-3" v-if="isOn">
<p class="message message-error">{{ error }}</p>
</div>`
})
var app = new Vue({
el: '#export-form',
data: {
key: '',
error: false
},
methods: {
formSubmit: function() {
var vueApp = this
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function() {
if (this.readyState != 4) return
if (this.status == 200) {
response = JSON.parse(this.responseText)
if (response.valid) {
vueApp.error = false
vueApp.$refs.form.submit()
}
else {
vueApp.error = true
}
}
else {
vueApp.error = true
}
}
xhr.open("POST", apiRoot + 'validate/', true)
xhr.setRequestHeader('Content-Type', 'application/json')
xhr.send(JSON.stringify({'KEY': this.key}))
}
}
})
}