|
12 | 12 | <title>Hello Vue!</title> |
13 | 13 | </head> |
14 | 14 | <body> |
| 15 | + |
15 | 16 | <div id="app"> |
16 | 17 | <div class="app-content"> |
17 | 18 | <div class="todobox" > |
|
30 | 31 | </ul> |
31 | 32 | </div> |
32 | 33 | </div> |
33 | | - |
34 | 34 | </div> |
35 | 35 |
|
| 36 | + <!-- template for the modal component --> |
| 37 | + <script type="text/x-template" id="modal-template"> |
| 38 | + <transition name="modal"> |
| 39 | + <div class="modal-mask"> |
| 40 | + <div class="modal-wrapper"> |
| 41 | + <div class="modal-container"> |
| 42 | + |
| 43 | + <div class="modal-header"> |
| 44 | + <slot name="header"> |
| 45 | + default header |
| 46 | + </slot> |
| 47 | + </div> |
| 48 | + |
| 49 | + <div class="modal-body"> |
| 50 | + <slot name="body"> |
| 51 | + default body |
| 52 | + </slot> |
| 53 | + </div> |
| 54 | + |
| 55 | + <div class="modal-footer"> |
| 56 | + <slot name="footer"> |
| 57 | + default footer |
| 58 | + <button class="modal-default-button" @click="$emit('close')"> |
| 59 | + OK |
| 60 | + </button> |
| 61 | + </slot> |
| 62 | + </div> |
| 63 | + </div> |
| 64 | + </div> |
| 65 | + </div> |
| 66 | + </transition> |
| 67 | + </script> |
| 68 | + |
36 | 69 | <script> |
37 | 70 | // Vue.component('test-global-cmp', { |
38 | 71 | // template: '<div>Composant de test</div>' |
@@ -107,26 +140,47 @@ <h2 v-on:click="activateTodolist">{{todolist.title}} </h2>\ |
107 | 140 | } |
108 | 141 | }); |
109 | 142 |
|
| 143 | + Vue.component('modal', { |
| 144 | + template: '#modal-template' |
| 145 | + }); |
| 146 | + |
110 | 147 | var itemDetails = { |
111 | 148 | props: ['item'], |
112 | 149 | template: '<span>{{item.id}} - {{item.name}}</span>' |
113 | 150 | }; |
| 151 | + |
114 | 152 | Vue.component('item-cmp', { |
| 153 | + data: function() { |
| 154 | + return {showModal: false} |
| 155 | + }, |
115 | 156 | components: {'item-details': itemDetails}, |
116 | 157 | props: ['todoItem'], |
117 | 158 | template:'<span>\ |
118 | 159 | <h3>\ |
119 | 160 | <i class="fa fa-pencil-square-o" aria-hidden="true" v-on:click="activateTodoItem()"> - \ |
120 | 161 | <item-details :item="todoItem"></item-details> \ |
121 | 162 | </i>\ |
122 | | - - <i class="fa fa-trash-o" aria-hidden="true" v-on:click="deleteItem"></i>\ |
| 163 | + - <i class="fa fa-trash-o" aria-hidden="true" id="show-modal" @click="showModal = true"></i>\ |
| 164 | + <modal v-if="showModal" @close="showModal = false">\ |
| 165 | + <h3 slot="header">Confirmer la suppression ?</h3>\ |
| 166 | + <div slot="body">La tache "{{todoItem.name}}" va être definitivement supprimée</div>\ |
| 167 | + <p slot="footer">\ |
| 168 | + <button class="modal-default-button" @click="showModal = false">\ |
| 169 | + Annuler\ |
| 170 | + </button>\ |
| 171 | + <button class="modal-default-button" @click="deleteItem">\ |
| 172 | + OK\ |
| 173 | + </button>\ |
| 174 | + </p>\ |
| 175 | + </modal>\ |
123 | 176 | </h3>\ |
124 | 177 | </span>', |
125 | 178 | methods: { |
126 | 179 | activateTodoItem: function() { |
127 | 180 | this.$emit('activateItem'); |
128 | 181 | }, |
129 | 182 | deleteItem: function() { |
| 183 | + this.showModal = false; |
130 | 184 | this.$emit('deleteItem'); |
131 | 185 | } |
132 | 186 | } |
@@ -160,7 +214,7 @@ <h3>\ |
160 | 214 | todoItem: {name:"", }, |
161 | 215 | todoItems: [], |
162 | 216 | // active: false, |
163 | | - activeTodo: 1 |
| 217 | + activeTodo: 0 |
164 | 218 | }, |
165 | 219 | created: function() { |
166 | 220 | // let ajaxUrlLocal = 'http://localhost:3000/api/todos/todos/1/items'; |
@@ -220,7 +274,7 @@ <h3>\ |
220 | 274 | .then(function(response) { |
221 | 275 | var lastIndex = response.all_items.length -1 |
222 | 276 | var newItem = response.all_items[lastIndex]; |
223 | | - todolist.all_items.splice(lastIndex, 0, newItem); |
| 277 | + todolist.all_items.push(newItem); |
224 | 278 | }); |
225 | 279 | this.todoItem.name = ""; |
226 | 280 | } |
|
0 commit comments