-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
135 lines (114 loc) · 3.1 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.26/vue.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
</head>
<style>
ul.intended{
padding: 5%;
background-color: #eee;
border: 1px solid #ccc;}
.NewtaskSection{float:right; width: 60%; padding: 19px 0;}
.NewtasksectionLeft{
padding: 22px 0;
float: LEFT;
TEXT-ALIGN: RIGHT;
WIDTH: 20%;}
.NewtaskSection button{float:right;margin:10px 0;}
li{list-style:none;}
</style>
<body>
<div class="container">
<div id="app" style="width:700px;">
<ul class="list-group intended" >
<li> <h1>To do: </h1></li>
<li class="list-group-item" v-for="(index, task) in tasks" v-if="task.completed == false">
<my-task :task="task" :index="index" :tasks="tasks" v-on:remove="removeRow(index)" v-on:change_status_row="change_status"> </my-task>
</li>
<li class="NewTask">
<div class="NewtasksectionLeft"><label>Task:</label></div>
<div class="NewtaskSection">
<input v-model="newTask" :value="newTask" class="form-control" placeholder="What do you need to do?">
<button v-on:click="addRow()" class="btn btn-primary">Save Item</button></div>
</li>
</ul>
<br />
<ul class="list-group intended" >
<li> <h1>Completed To do:</h1></li>
<li class="list-group-item" v-for="(index, task) in tasks" v-if="task.completed == true">
<my-task :task="task" :index="index" :tasks="tasks" v-on:remove="removeRow(index)" v-on:change_status_row="change_status"> </my-task>
</li>
</ul>
</div>
<template id="task-template">
<div class="col-lg-12">
<div>{{ task.name }}<div class="contolls" style="float:right;">
<input type="checkbox" value="true" v-on:input= "change_status" :checked="task.completed">
<button v-on:click= "remove" class="btn btn-danger">X</button>
</div></div>
</div>
</template>
<script>
var myTask = Vue.component('my-task', {
template: '#task-template',
data: function() {
return this.tasks; //Notice: in components data should return an object. For example "return { someProp: 1 }"
},
props: ['task', 'index'],
methods: {
remove() {
this.$emit('remove');
},
change_status(event) {
this.$emit('change_status_row', this.index, event);
}
}
});
new Vue({
el: '#app',
data: {
tasks: [{
name: "task 1",
completed: false
},
{
name: "task 2",
completed: false
},
{
name: "task 3",
completed: true
}
],
newTask: ''
},
components: {
myTask: myTask
},
methods: {
addRow(){
console.log(this.newTask);
this.tasks.push({
name: this.newTask,
completed: false
});
this.newTask='';
},
removeRow(index){
this.tasks.splice(index,1); // why is this removing only the last row?
},
change_status(index, event){
console.log(index);
console.log(event);
this.tasks[index].completed=event.target.checked;
}
},
computed: {
},
ready: function() {
}
});
</script>
</body>
</html>