summaryrefslogtreecommitdiff
path: root/src/views/_sila/Settings/TransferInfo/WarningSmtp.vue
blob: 3b4994c63f4b6a83793e78469ff80f531f68663d (plain)
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
<template>
  <page-section :section-title="$t('pageTransfer.smtp.smtpTitle')">
    <b-row class="smtp-warning mb-3">
      <b-col xs="12" sm="12">
        <div class="switch-group">
          <label for="authenticationSwitch">{{
            $t('pageTransfer.smtp.authorization')
          }}</label>
          <b-form-checkbox
            id="authenticationSwitch"
            v-model="form.authorization"
            data-test-id="checkbox-authorization"
            switch
            :disabled="$store.getters['authentication/role'] === 'ReadOnly'"
          >
            <span v-if="form.authorization">
              {{ $t('global.status.enabled') }}
            </span>
            <span v-else>{{ $t('global.status.disabled') }}</span>
          </b-form-checkbox>
        </div>
      </b-col>
      <b-col xs="12" sm="12">
        <b-form-group
          :label="$t('pageTransfer.smtp.username')"
          label-for="smtp-name"
        >
          <b-form-input
            id="smtp-name"
            v-model="form.user"
            :disabled="$store.getters['authentication/role'] === 'ReadOnly'"
          /> </b-form-group
      ></b-col>
      <b-col xs="12" sm="12">
        <b-form-group
          :label="$t('pageTransfer.smtp.password')"
          label-for="smtp-password"
        >
          <input-password-toggle>
            <b-form-input
              id="smtp-password"
              v-model="form.password"
              type="password"
              :disabled="$store.getters['authentication/role'] === 'ReadOnly'"
            />
          </input-password-toggle>
        </b-form-group>
      </b-col>
      <b-col xs="12" sm="12">
        <b-form-group
          :label="$t('pageTransfer.smtp.host')"
          label-for="smtp-host"
        >
          <b-form-input
            id="smtp-host"
            v-model="form.host"
            :disabled="$store.getters['authentication/role'] === 'ReadOnly'"
          />
        </b-form-group>
      </b-col>
      <b-col xs="12" sm="12">
        <b-form-group
          :label="$t('pageTransfer.smtp.port')"
          label-for="smtp-port"
        >
          <b-form-input
            id="smtp-port"
            v-model="form.port"
            type="number"
            :disabled="$store.getters['authentication/role'] === 'ReadOnly'"
          />
        </b-form-group>
      </b-col>
      <b-col xs="12" sm="12">
        <div class="switch-group">
          <label for="sslSwitch">{{
            $t('pageTransfer.smtp.sslEnabled')
          }}</label>
          <b-form-checkbox
            id="sslSwitch"
            v-model="form.ssl"
            data-test-id="checkbox-ssl"
            switch
            :disabled="$store.getters['authentication/role'] === 'ReadOnly'"
          >
            <span v-if="form.ssl">
              {{ $t('global.status.enabled') }}
            </span>
            <span v-else>{{ $t('global.status.disabled') }}</span>
          </b-form-checkbox>
        </div>
      </b-col>
      <b-col xs="4" class="d-flex justify-content-end align-items-start">
        <b-button variant="primary" @click="saveSmtp">
          {{ $t('global.action.save') }}
        </b-button>
      </b-col>
    </b-row>
    <b-row>
      <b-col>
        <b-table
          hover
          responsive="md"
          show-empty
          :fields="fields"
          :empty-text="$t('global.table.emptyMessage')"
        >
        </b-table>
      </b-col>
    </b-row>
  </page-section>
</template>

<script>
import PageSection from '@/components/_sila/Global/PageSection';
import BVToastMixin from '@/components/_sila/Mixins/BVToastMixin';
import DataFormatterMixin from '@/components/_sila/Mixins/DataFormatterMixin';
import InputPasswordToggle from '@/components/_sila/Global/InputPasswordToggle';

export default {
  name: 'WarningSmnp',
  components: {
    PageSection,
    InputPasswordToggle,
  },
  mixins: [BVToastMixin, DataFormatterMixin],

  data() {
    return {
      form: {
        user: '',
        password: '',
        host: '',
        port: '',
        authorization: null,
        ssl: null,
      },
      fields: [
        {
          key: 'name',
          label: this.$t('pageTransfer.table.userName'),
          formatter: this.dataFormatter,
        },
        {
          key: 'value',
          label: this.$t('pageTransfer.table.value'),
          formatter: this.dataFormatter,
          tdClass: 'text-nowrap',
        },
      ],
    };
  },
  methods: {
    saveSmtp() {
      this.$store
        .dispatch('smtpStore/setSmtpSettings', this.form)
        .then((message) => this.successToast(message))
        .catch(({ message }) => this.errorToast(message));
    },
    sendMail() {
      this.$store
        .dispatch('smtpStore/sendTestMessage')
        .then((message) => this.successToast(message))
        .catch(({ message }) => this.errorToast(message));
    },
  },
};
</script>

<style lang="scss" scoped>
.switch-group {
  margin-bottom: 1.5rem;
}
.smtp-warning {
  width: 50%;
  @media (max-width: 768px) {
    width: 75%;
  }
  @media (max-width: 576px) {
    width: 100%;
  }
}
</style>