1
|
|
|
import template from './sw-event-action-detail-recipients.html.twig'; |
2
|
|
|
import './sw-event-action-detail-recipients.scss'; |
3
|
|
|
|
4
|
|
|
const { Component, Utils, Classes: { ShopwareError } } = Shopware; |
|
|
|
|
5
|
|
|
|
6
|
|
|
/** |
7
|
|
|
* @internal (flag:FEATURE_NEXT_9351) |
8
|
|
|
*/ |
9
|
|
|
Component.register('sw-event-action-detail-recipients', { |
10
|
|
|
template, |
11
|
|
|
|
12
|
|
|
inject: ['acl'], |
13
|
|
|
|
14
|
|
|
props: { |
15
|
|
|
configRecipients: { |
16
|
|
|
type: Object, |
17
|
|
|
required: false |
18
|
|
|
}, |
19
|
|
|
isLoading: { |
20
|
|
|
type: Boolean, |
21
|
|
|
required: true |
22
|
|
|
} |
23
|
|
|
}, |
24
|
|
|
|
25
|
|
|
data() { |
26
|
|
|
return { |
27
|
|
|
recipients: [] |
28
|
|
|
}; |
29
|
|
|
}, |
30
|
|
|
|
31
|
|
|
created() { |
32
|
|
|
this.createdComponent(); |
33
|
|
|
}, |
34
|
|
|
|
35
|
|
|
methods: { |
36
|
|
|
createdComponent() { |
37
|
|
|
this.getRecipientList(); |
38
|
|
|
}, |
39
|
|
|
|
40
|
|
|
getRecipientList() { |
41
|
|
|
if (!this.configRecipients) { |
42
|
|
|
return; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
// Convert recipients object from config to array to work properly with `sw-data-grid` |
46
|
|
|
this.recipients = Object.entries(this.configRecipients).map((item) => { |
47
|
|
|
return { |
48
|
|
|
email: item[0], |
49
|
|
|
name: item[1], |
50
|
|
|
id: Utils.createId() |
51
|
|
|
}; |
52
|
|
|
}); |
53
|
|
|
}, |
54
|
|
|
|
55
|
|
|
addRecipient() { |
56
|
|
|
const newId = Utils.createId(); |
57
|
|
|
|
58
|
|
|
this.recipients.unshift({ |
59
|
|
|
id: newId, |
60
|
|
|
email: '', |
61
|
|
|
name: '' |
62
|
|
|
}); |
63
|
|
|
|
64
|
|
|
this.$nextTick(() => { |
65
|
|
|
this.$refs.recipientsGrid.currentInlineEditId = newId; |
66
|
|
|
this.$refs.recipientsGrid.enableInlineEdit(); |
67
|
|
|
}); |
68
|
|
|
}, |
69
|
|
|
|
70
|
|
|
saveRecipient(recipient) { |
71
|
|
|
// If required fields are not filled, re-enable inline-edit |
72
|
|
|
if (!recipient.name.length || !recipient.email.length) { |
73
|
|
|
this.$nextTick(() => { |
74
|
|
|
this.$refs.recipientsGrid.currentInlineEditId = recipient.id; |
75
|
|
|
this.$refs.recipientsGrid.enableInlineEdit(); |
76
|
|
|
}); |
77
|
|
|
return; |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
this.$emit('update-list', this.recipients); |
81
|
|
|
}, |
82
|
|
|
|
83
|
|
|
cancelSaveRecipient(recipient) { |
84
|
|
|
if (recipient.name.length || recipient.email.length) { |
85
|
|
|
return; |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
const index = this.recipients.findIndex((item) => { |
89
|
|
|
return item.id === recipient.id; |
90
|
|
|
}); |
91
|
|
|
|
92
|
|
|
this.recipients.splice(index, 1); |
93
|
|
|
}, |
94
|
|
|
|
95
|
|
|
onEditRecipient(id) { |
96
|
|
|
this.$refs.recipientsGrid.currentInlineEditId = id; |
97
|
|
|
this.$refs.recipientsGrid.enableInlineEdit(); |
98
|
|
|
}, |
99
|
|
|
|
100
|
|
|
onDeleteRecipient(id) { |
101
|
|
|
const index = this.recipients.findIndex((item) => { |
102
|
|
|
return item.id === id; |
103
|
|
|
}); |
104
|
|
|
|
105
|
|
|
this.recipients.splice(index, 1); |
106
|
|
|
|
107
|
|
|
this.$emit('update-list', this.recipients); |
108
|
|
|
}, |
109
|
|
|
|
110
|
|
|
recipientMailError(text) { |
111
|
|
|
if (text.length) { |
112
|
|
|
return null; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
return new ShopwareError({ |
|
|
|
|
116
|
|
|
code: 'EVENT_ACTION_DETAIL_RECIPIENT_INVALID_MAIL' |
117
|
|
|
}); |
118
|
|
|
}, |
119
|
|
|
|
120
|
|
|
recipientNameError(text) { |
121
|
|
|
if (text.length) { |
122
|
|
|
return null; |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
return new ShopwareError({ |
|
|
|
|
126
|
|
|
code: 'EVENT_ACTION_DETAIL_RECIPIENT_INVALID_NAME' |
127
|
|
|
}); |
128
|
|
|
} |
129
|
|
|
}, |
130
|
|
|
|
131
|
|
|
computed: { |
132
|
|
|
recipientColumns() { |
133
|
|
|
return [{ |
134
|
|
|
property: 'email', |
135
|
|
|
label: 'sw-event-action.detail.columnRecipientMail', |
136
|
|
|
inlineEdit: 'string' |
137
|
|
|
}, { |
138
|
|
|
property: 'name', |
139
|
|
|
label: 'sw-event-action.detail.columnRecipientName', |
140
|
|
|
inlineEdit: 'string' |
141
|
|
|
}]; |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
}); |
145
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.