| 1 |
Vue.component('wpuf-cf-form-notification', { |
| 2 |
template: '#tmpl-wpuf-form-notification', |
| 3 |
mixins: [weForms.mixins.Loading], |
| 4 |
data: function() { |
| 5 |
return { |
| 6 |
editing: false, |
| 7 |
editingIndex: 0, |
| 8 |
}; |
| 9 |
}, |
| 10 |
|
| 11 |
computed: { |
| 12 |
is_pro: function() { |
| 13 |
return 'true' === weForms.is_pro; |
| 14 |
}, |
| 15 |
has_sms: function() { |
| 16 |
return 'true' === weForms.has_sms; |
| 17 |
}, |
| 18 |
pro_link: function() { |
| 19 |
return wpuf_form_builder.pro_link; |
| 20 |
}, |
| 21 |
notifications: function() { |
| 22 |
return this.$store.state.notifications; |
| 23 |
}, |
| 24 |
|
| 25 |
hasNotifications: function() { |
| 26 |
return Object.keys( this.$store.state.notifications ).length; |
| 27 |
} |
| 28 |
}, |
| 29 |
|
| 30 |
methods: { |
| 31 |
addNew: function() { |
| 32 |
this.$store.commit('addNotification', wpuf_form_builder.defaultNotification); |
| 33 |
}, |
| 34 |
|
| 35 |
editItem: function(index) { |
| 36 |
this.editing = true; |
| 37 |
this.editingIndex = index; |
| 38 |
}, |
| 39 |
|
| 40 |
editDone: function() { |
| 41 |
this.editing = false; |
| 42 |
|
| 43 |
this.$store.commit('updateNotification', { |
| 44 |
index: this.editingIndex, |
| 45 |
value: this.notifications[this.editingIndex] |
| 46 |
}); |
| 47 |
|
| 48 |
jQuery('.advanced-field-wrap').slideUp('fast'); |
| 49 |
}, |
| 50 |
|
| 51 |
deleteItem: function(index) { |
| 52 |
if ( confirm( 'Are you sure' ) ) { |
| 53 |
this.editing = false; |
| 54 |
this.$store.commit( 'deleteNotification', index); |
| 55 |
this.$emit('deleteNotification', index); |
| 56 |
} |
| 57 |
}, |
| 58 |
|
| 59 |
toggelNotification: function(index) { |
| 60 |
this.$store.commit('updateNotificationProperty', { |
| 61 |
index: index, |
| 62 |
property: 'active', |
| 63 |
value: !this.notifications[index].active |
| 64 |
}); |
| 65 |
}, |
| 66 |
|
| 67 |
duplicate: function(index) { |
| 68 |
this.$store.commit('cloneNotification', index); |
| 69 |
}, |
| 70 |
|
| 71 |
toggleAdvanced: function() { |
| 72 |
jQuery('.advanced-field-wrap').slideToggle('fast'); |
| 73 |
}, |
| 74 |
|
| 75 |
insertValue: function(type, field, property) { |
| 76 |
var notification = this.notifications[this.editingIndex], |
| 77 |
value = ( field !== undefined ) ? '{' + type + ':' + field + '}' : '{' + type + '}'; |
| 78 |
|
| 79 |
notification[property] = notification[property] + value; |
| 80 |
}, |
| 81 |
|
| 82 |
insertValueEditor: function(type, field, property) { |
| 83 |
var value = ( field !== undefined ) ? '{' + type + ':' + field + '}' : '{' + type + '}'; |
| 84 |
this.$emit('insertValueEditor', value); |
| 85 |
}, |
| 86 |
} |
| 87 |
}); |
| 88 |
|