-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodo.php
More file actions
150 lines (142 loc) · 5.02 KB
/
todo.php
File metadata and controls
150 lines (142 loc) · 5.02 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
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php
/**
* Created by PhpStorm.
* User: shady
* Date: 3/3/19
* Time: 5:53 AM
*/
include "functions.php";
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>Vue & PHP - ToDo List</title>
<!-- Bootstrap core CSS -->
<link href="./css/bootstrap.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="./css/narrow-jumbotron.css" rel="stylesheet">
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.21/dist/vue.js"></script>
<style>
.hide-element{
display: none;
}
</style>
</head>
<body>
<div class="container" id="app">
<div class="header clearfix">
<nav>
<ul class="nav nav-pills float-right">
<li class="nav-item">
<a class="nav-link" href="index.php">General</a>
</li>
<li class="nav-item">
<a class="nav-link" href="shop.php">Shopping Cart</a>
</li>
<li class="nav-item">
<a class="nav-link active" href="todo.php">Tasks</a>
</li>
<li class="nav-item">
<a class="nav-link" href="form.php">Multi Form</a>
</li>
</ul>
</nav>
<h3 class="text-muted">Vue and PHP</h3>
</div>
<div class="container">
<div class="jumbotron">
<h1 class="display-3">My ToDo List</h1>
</div>
</div>
<div class="container">
<div class="form-group">
<label for="exampleInputEmail1">Add a New Task</label><br>
<input style="width: 80%;" v-model="message" v-on:keyup.enter="addToDo()" type="text"
placeholder="Enter a task">
<button @click="addToDo()" style="display:inline-block;" class="btn btn-primary">Save</button>
</div>
</div>
<div class="container">
<div class="card">
<div class="card-header">
<h3 style="display: inline-block;">Items</h3>
<div class="float-right" style="display: inline-block;">
<a v-bind:style="{display:showElement}" @click="saveTasks()" href="javascript:void(0)" class="btn btn-sm btn-success">Save Changes</a>
<a v-bind:style="{display:invertedDisplay}" @click="editTasks()" href="javascript:void(0)" class="btn btn-sm btn-primary">Edit Items</a>
<form action="submit.php" method="get" style="display: inline-block">
<input type="hidden" v-model="updatedToDos" name="todos">
<button v-if="stale" v-bind:style="{display:invertedDisplay}" class="btn btn-sm btn-primary">Submit Changes</button>
</form>
</div>
</div>
<div class="card-block">
<ul class="list-group">
<li v-for="item in items" class="list-group-item ">
<div class="" style="width:100%;">
<span v-bind:style="{display:invertedDisplay}">{{ item.item }}</span>
<input type="text" v-bind:style="{display:showElement}" v-model="item.item" style="width: 100%"/>
</div>
</li>
</ul>
</div>
</div>
</div>
<br><br>
<footer class="footer">
<p>© igestDevelopment 2019</p>
</footer>
</div> <!-- /container -->
<script>
var myObject = new Vue({
el: '#app',
data : {
message: "",
updatedToDos : "",
stale: false,
showElement: "none",
items: <?php echo get_todos();?>,
},
methods: {
addToDo() {
this.addToItems(this.message);
this.message = "";
},
addToItems(message){
var count = Object.keys(this.items).length;
this.items[count +1 ] = {
'id' : "nan",
"item":message,
};
this.convertToString();
},
convertToString(){
this.updatedToDos = JSON.stringify(this.items);
this.stale = true;
},
editTasks(){
this.showElement = "inline-block";
},
saveTasks(){
this.convertToString();
this.showElement ="none";
}
},
computed: {
// a computed getter
invertedDisplay: function () {
// `this` points to the vm instance
if( this.showElement == "none"){
return "inline-block";
}
return "none";
},
}
})
</script>
</body>
</html>