forked from gocd-demo/node-bulletin-board
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
59 lines (53 loc) · 1.23 KB
/
app.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
56
57
58
59
const eventService = {
el: '#events',
data: {
event: {title: '', detail: '', date: ''},
events: []
},
ready: function () {
this.fetchEvents();
},
methods: {
fetchEvents: function () {
var events = [];
this.$http.get('/bulletin-board/api/events')
.success(function (events) {
this.$set('events', events);
})
.error(function (err) {
console.log(err);
});
},
addEvent: function (e) {
if (this.event.title.trim()) {
this.$http.post('/bulletin-board/api/event', this.event)
.success(function (res) {
this.events.push({
id: this.event.id,
title: this.event.title,
detail: this.event.detail,
date: this.event.date
});
$(".form-control").val('');
$('#add-event-modal').modal('hide');
})
.error(function (err) {
console.log(err);
});
}
},
deleteEvent: function (id) {
if (confirm('Are you sure you want to delete this event?')) {
this.$http.delete('/bulletin-board/api/event/' + id)
.success(function (res) {
var index = this.events.findIndex(x => x.id === id);
this.events.splice(index, 1);
})
.error(function (err) {
console.log(err);
});
}
}
}
};
new Vue(eventService);