11/* --------------------------------------------------------
22 VueJS - Task Manager
3- Version: 0.0.1
3+ Version: 0.1.0
44 Author: Steven Morrison
55 Website: www.zaffri.com
66 GitHub: github.com/Zaffri
@@ -12,18 +12,21 @@ var app = new Vue({
1212 storageKey : "zaffri-vuejs-task-manager" ,
1313 data : {
1414 newCategory : '' ,
15- modalVisible : false ,
16- zaffriModal : {
15+ modalConfig : {
16+ // Modal visibility
17+ visible : false ,
18+
19+ // type: notify || confirm
1720 type : "confirm" ,
21+
22+ // display data
1823 title : "Delete" ,
1924 messageBody : "Are you sure you want to delete this?" ,
2025 confirmText : "Confirm" ,
21- cancelText : "Cancel" , // for confirm modal type only
22- action : {
23- type : null ,
24- index : 0 ,
25- parentIndex : 0 // parentIndex for tasks (cat index)
26- }
26+
27+ // Only required for confirm modal
28+ cancelText : "Cancel" ,
29+ callbackData : { }
2730 } ,
2831 categories : [ ] // all app data
2932 } ,
@@ -119,24 +122,28 @@ var app = new Vue({
119122 }
120123 } ,
121124 showModal : function ( index , type , parentIndex = null ) { // parentIndex for tasks (cat index)
122- // Modal action
123- this . zaffriModal . action . type = type ;
124- this . zaffriModal . action . index = index ;
125- this . zaffriModal . action . parentIndex = parentIndex ;
125+ // Assign callback data
126+ this . modalConfig . callbackData = {
127+ type : type ,
128+ index : index ,
129+ parentIndex : parentIndex
130+ }
131+
126132 // Set visible
127- this . modalVisible = true ;
133+ this . modalConfig . visible = true ;
128134 } ,
129- hideModal : function ( action ) {
130- this . modalVisible = false ;
131-
135+ modalCallback : function ( action ) {
136+ // Hide modal
137+ this . modalConfig . visible = false ;
138+
132139 // if action = true (confirm clicked)
133140 if ( action == true ) {
134- var actionData = this . zaffriModal . action ;
141+ var callbackData = this . modalConfig . callbackData ;
135142 // check action type
136- if ( actionData . type == "category-delete" ) {
137- this . deleteCategory ( actionData ) ;
143+ if ( callbackData . type == "category-delete" ) {
144+ this . deleteCategory ( callbackData ) ;
138145 } else {
139- this . deleteTask ( actionData ) ;
146+ this . deleteTask ( callbackData ) ;
140147 }
141148 }
142149 }
0 commit comments