-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathask.js
55 lines (55 loc) · 1.39 KB
/
ask.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 askApp = new Vue({
el: '#ask-app',
data: {
title: '',
body: '',
bounty: 0,
tos: false,
loading: false,
titleError: false,
bodyError: false,
bountyError: false,
tosError: false
},
methods: {
ask: function() {
var error = false;
this.titleError = false;
this.bodyError = false;
this.bountyError = false;
this.tosError = false;
if (this.title.length < 10) {
this.titleError = 'Your title is too short.';
error = true;
}
if (this.title.length > 140) {
this.titleError = 'Your title must not be over 140.';
error = true;
}
if (this.body.length < 24) {
this.bodyError = 'Your question body is too short.';
error = true;
}
if (this.body.length > 2040) {
this.bodyError = 'Your question body must not be over 2040 characters.';
error = true;
}
if (!this.tos) {
this.tosError = 'Please recognize that this action is irreversible.';
error = true;
}
if (!error) {
this.loading = true;
postApi('/question', `title=${this.title}&body=${this.body}&bounty=${this.bounty}`, function (data, status) {
if (status == 400) {
askApp.bountyError = JSON.parse(data).message || 'Your account does not have enough balance to cover this transaction.';
}
else if (status == 200) {
location.href = `/question.html#${JSON.parse(data).uuid}`;
}
askApp.loading = false;
});
}
}
}
})