-
Notifications
You must be signed in to change notification settings - Fork 12
/
DscComponent.js
197 lines (192 loc) · 5.96 KB
/
DscComponent.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
import { required } from 'vuelidate/lib/validators';
const Vue = require('vue/dist/vue.common');
const { SEND_MODE } = require('../../../constant/send-mode');
const { ESP_TYPE } = require('../../../constant/esp-type');
const { TimeInput } = require('../../time-input/timeInput');
const { validationMixin } = require('vuelidate');
const styleHelper = require('../../../utils/style/styleHelper');
const DscComponent = Vue.component('DscComponent', {
mixins: [validationMixin],
components: {
TimeInput,
},
props: {
vm: { type: Object, default: () => ({}) },
campaignMailName: { type: String, default: null },
isLoading: { type: Boolean, default: false },
closeModal: { type: Function, default: () => {} },
espId: { type: String, default: null },
selectedProfile: { type: Object, default: () => ({}) },
fetchedProfile: { type: Object, default: () => ({}) },
campaignId: { type: String, default: null },
type: { type: Number, default: SEND_MODE.CREATION },
},
data() {
return {
profile: {
campaignMailName: '',
planification: '',
subject: '',
type: ESP_TYPE.DSC,
},
style: styleHelper,
};
},
computed: {
isEditMode() {
return this.type === SEND_MODE.EDIT;
},
},
mounted() {
const {
campaignMailName,
subject,
id,
additionalApiData: { planification, typeCampagne } = {},
} = this.fetchedProfile;
this.profile = {
campaignMailName: campaignMailName ?? '',
planification: planification ?? '',
subject: subject ?? '',
typeCampagne: typeCampagne ?? '',
id: id ?? '',
};
M.updateTextFields();
},
methods: {
onSubmit() {
M.updateTextFields();
this.$v.$touch();
if (this.$v.$invalid) {
return;
}
this.$emit('submit', this.profile);
},
},
template: `
<template>
<div>
<div class="modal-content">
<div class="row">
<div class="col s12">
<h5>{{ vm.t('export-to') }} {{ selectedProfile.name }}</h5>
</div>
<form class="col s12">
<div class="row" v-if="isEditMode">
<div class="col s12">
<div class="card-panel blue-grey lighten-5">
<div :style="style.flexContainer">
<div>
<i
class="fa fa-exclamation-circle fa-2x"
aria-hidden="true"
:style="style.colorOrange"
></i>
</div>
<div :style="style.pl4">
<span>{{ vm.t('warning-esp-message') }}</span>
</div>
</div>
</div>
</div>
</div>
<div class="row" :style="style.mb0">
<div class="input-field col s12" :style="style.mb0">
<input
id="campaignMailName"
v-model="profile.campaignMailName"
type="text"
name="campaignMailName"
required
:disabled="isEditMode"
:placeholder="vm.t('mailName')"
@input="$v.profile.campaignMailName.$touch()"
@blur="$v.profile.campaignMailName.$touch()"
:class="[
'validate',
$v.profile.campaignMailName.required ? 'valid' : 'invalid',
]"
/>
<label for="dscIdMail">{{ vm.t('mailName') }}</label>
<span
v-if="!$v.profile.campaignMailName.required"
class="helper-text"
:data-error="vm.t('mail-name-required')"
></span>
</div>
</div>
<div class="row" :style="style.mb0">
<div class="col s12" :style="style.mb0">
<label for="planification">{{ vm.t('planification') }}</label><br/>
<time-input id="planification" name="planification" v-model="profile.planification"></time-input>
</div>
</div>
<div class="row" :style="style.mb0">
<div class="input-field col s12" :style="style.mb0">
<input
id="subject"
type="text"
v-model="profile.subject"
:placeholder="vm.t('mail-subject-required')"
name="subject"
required
:class="[
'validate',
$v.profile.subject.required ? 'valid' : 'invalid',
]"
class="validate"
/>
<label for="subject" class="active">{{
vm.t('mail-subject-required')
}}</label>
<span
class="helper-text"
:data-error="vm.t('mail-subject-required')"
></span>
</div>
</div>
</form>
</div>
</div>
<div class="modal-footer">
<button
@click.prevent="closeModal"
class="btn-flat waves-effect waves-light"
name="closeAction"
>
{{ vm.t('close') }}
</button>
<button
@click.prevent="onSubmit"
:disabled="isLoading"
:style="[style.mb0, style.mt0]"
class="btn waves-effect waves-light"
type="submit"
name="submitAction"
>
<span v-if="isLoading">{{ vm.t('exporting') }}</span>
<span v-else
>{{ vm.t('export') }}
<i class="fa fa-paper-plane" aria-hidden="true"></i
></span>
</button>
</div>
</div>
</template>
`,
validations() {
return {
profile: {
campaignMailName: {
required,
},
subject: {
required,
},
},
};
},
});
module.exports = {
DscComponent,
};