Skip to content
This repository was archived by the owner on Jan 22, 2024. It is now read-only.

Commit 807928b

Browse files
author
Steven Morrison
committed
SM: Added modal 0.0.4 changes - callback fix.
1 parent 0e67b05 commit 807928b

File tree

3 files changed

+34
-15
lines changed

3 files changed

+34
-15
lines changed

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
<html>
33
<head>
44
<title>Task Manager</title>
5+
<meta charset="utf-8"/>
56
<link rel="stylesheet" href="css/style.css" />
67
<link rel="stylesheet" href="css/modal.css" />
78
</head>
@@ -42,7 +43,7 @@ <h3 class="category-name">{{ cat.name }}</h3>
4243
</ul>
4344

4445
<!-- Modal component -->
45-
<zaffri-modal v-bind:data="modalConfig"></zaffri-modal>
46+
<zaffri-modal v-bind:data="modalConfig" v-on:hide_modal_emit="modalCallback"></zaffri-modal>
4647
</section>
4748

4849
<!-- Modal Component markup -->

js/app.js

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,22 @@ var app = new Vue({
1313
data: {
1414
newCategory: '',
1515
modalConfig: {
16+
// Modal visibility
17+
visible: false,
18+
19+
// type: notify || confirm
20+
type: "confirm",
21+
22+
// display data
23+
title: "Delete",
24+
messageBody: "Are you sure you want to delete this?",
25+
confirmText: "Confirm",
26+
27+
// Only required for confirm modal
28+
cancelText: "Cancel",
29+
callbackData: {}
30+
},
31+
/*modalConfig: {
1632
// Modal visibility
1733
visible: false,
1834
@@ -43,7 +59,7 @@ var app = new Vue({
4359
}
4460
console.log("DATA: " + JSON.stringify(data));
4561
}
46-
},
62+
},*/
4763
categories: [] // all app data
4864
},
4965
created: function() {
@@ -138,16 +154,22 @@ var app = new Vue({
138154
}
139155
},
140156
showModal: function(index, type, parentIndex = null) { // parentIndex for tasks (cat index)
141-
// Modal action
142-
this.modalConfig.callbackData.type = type;
143-
this.modalConfig.callbackData.index = index;
144-
this.modalConfig.callbackData.parentIndex = parentIndex;
157+
// Assign callback data
158+
this.modalConfig.callbackData = {
159+
type: type,
160+
index: index,
161+
parentIndex: parentIndex
162+
}
163+
145164
// Set visible
146165
this.modalConfig.visible = true;
147166
},
148-
hideModal: function(action) {
149-
// this.modalConfig.visible = false;
167+
modalCallback: function(action) {
168+
this.modalConfig.visible = false;
150169

170+
console.log('Action: ' + action);
171+
console.log('Data: ' + JSON.stringify(this.modalConfig.callbackData));
172+
151173
// if action = true (confirm clicked)
152174
/*if(action == true) {
153175
var actionData = this.zaffriModal.action;

js/modal.js

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/* --------------------------------------------------------
22
VueJS - Modal Component
3-
Version: 0.0.3
3+
Version: 0.0.4
44
Author: Steven Morrison
55
Website: www.zaffri.com
66
GitHub: github.com/Zaffri
@@ -11,15 +11,11 @@ var ZaffriModal = Vue.component('zaffri-modal', {
1111
props: ['data'],
1212
methods: {
1313
closeModal: function(action = null) {
14-
var callbackData = {};
15-
16-
if(this.data.callbackData != undefined) callbackData = this.data.callbackData;
17-
if(this.data.confirmCallback != undefined) this.confirmCallback(action, callbackData);
18-
14+
this.$emit('hide_modal_emit', action);
1915
this.data.visible = false;
2016
},
2117
confirmCallback: function(action, callbackData) {
2218
this.data.confirmCallback(action, callbackData);
2319
}
2420
}
25-
});
21+
});

0 commit comments

Comments
 (0)