Skip to content

Commit 66b92ba

Browse files
committed
added confirmation modal on delete
1 parent 65f2c9c commit 66b92ba

File tree

2 files changed

+124
-4
lines changed

2 files changed

+124
-4
lines changed

App.css

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,69 @@ li {
6969
direction: row;
7070
justify-content: space-between;
7171
}
72+
/************************************************************/
73+
/*MODAL*/
74+
75+
.modal-mask {
76+
position: fixed;
77+
z-index: 9998;
78+
top: 0;
79+
left: 0;
80+
width: 100%;
81+
height: 100%;
82+
background-color: rgba(0, 0, 0, .5);
83+
display: table;
84+
transition: opacity .3s ease;
85+
}
86+
87+
.modal-wrapper {
88+
display: table-cell;
89+
vertical-align: middle;
90+
}
91+
92+
.modal-container {
93+
width: 300px;
94+
margin: 0px auto;
95+
padding: 20px 30px;
96+
background-color: #fff;
97+
border-radius: 2px;
98+
box-shadow: 0 2px 8px rgba(0, 0, 0, .33);
99+
transition: all .3s ease;
100+
font-family: Helvetica, Arial, sans-serif;
101+
}
102+
103+
.modal-header h3 {
104+
margin-top: 0;
105+
color: #42b983;
106+
}
107+
108+
.modal-body {
109+
margin: 20px 0;
110+
}
111+
112+
.modal-default-button {
113+
float: right;
114+
}
115+
116+
/*
117+
* The following styles are auto-applied to elements with
118+
* transition="modal" when their visibility is toggled
119+
* by Vue.js.
120+
*
121+
* You can easily play with the modal transition by editing
122+
* these styles.
123+
*/
124+
125+
.modal-enter {
126+
opacity: 0;
127+
}
128+
129+
.modal-leave-active {
130+
opacity: 0;
131+
}
132+
133+
.modal-enter .modal-container,
134+
.modal-leave-active .modal-container {
135+
-webkit-transform: scale(1.1);
136+
transform: scale(1.1);
137+
}

index.html

Lines changed: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<title>Hello Vue!</title>
1313
</head>
1414
<body>
15+
1516
<div id="app">
1617
<div class="app-content">
1718
<div class="todobox" >
@@ -30,9 +31,41 @@
3031
</ul>
3132
</div>
3233
</div>
33-
3434
</div>
3535

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+
3669
<script>
3770
// Vue.component('test-global-cmp', {
3871
// template: '<div>Composant de test</div>'
@@ -107,26 +140,47 @@ <h2 v-on:click="activateTodolist">{{todolist.title}} </h2>\
107140
}
108141
});
109142

143+
Vue.component('modal', {
144+
template: '#modal-template'
145+
});
146+
110147
var itemDetails = {
111148
props: ['item'],
112149
template: '<span>{{item.id}} - {{item.name}}</span>'
113150
};
151+
114152
Vue.component('item-cmp', {
153+
data: function() {
154+
return {showModal: false}
155+
},
115156
components: {'item-details': itemDetails},
116157
props: ['todoItem'],
117158
template:'<span>\
118159
<h3>\
119160
<i class="fa fa-pencil-square-o" aria-hidden="true" v-on:click="activateTodoItem()"> - \
120161
<item-details :item="todoItem"></item-details> \
121162
</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>\
123176
</h3>\
124177
</span>',
125178
methods: {
126179
activateTodoItem: function() {
127180
this.$emit('activateItem');
128181
},
129182
deleteItem: function() {
183+
this.showModal = false;
130184
this.$emit('deleteItem');
131185
}
132186
}
@@ -160,7 +214,7 @@ <h3>\
160214
todoItem: {name:"", },
161215
todoItems: [],
162216
// active: false,
163-
activeTodo: 1
217+
activeTodo: 0
164218
},
165219
created: function() {
166220
// let ajaxUrlLocal = 'http://localhost:3000/api/todos/todos/1/items';
@@ -220,7 +274,7 @@ <h3>\
220274
.then(function(response) {
221275
var lastIndex = response.all_items.length -1
222276
var newItem = response.all_items[lastIndex];
223-
todolist.all_items.splice(lastIndex, 0, newItem);
277+
todolist.all_items.push(newItem);
224278
});
225279
this.todoItem.name = "";
226280
}

0 commit comments

Comments
 (0)