|
| 1 | +// Licensed to the Apache Software Foundation (ASF) under one |
| 2 | +// or more contributor license agreements. See the NOTICE file |
| 3 | +// distributed with this work for additional information |
| 4 | +// regarding copyright ownership. The ASF licenses this file |
| 5 | +// to you under the Apache License, Version 2.0 (the |
| 6 | +// "License"); you may not use this file except in compliance |
| 7 | +// with the License. You may obtain a copy of the License at |
| 8 | +// |
| 9 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +// |
| 11 | +// Unless required by applicable law or agreed to in writing, |
| 12 | +// software distributed under the License is distributed on an |
| 13 | +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 14 | +// KIND, either express or implied. See the License for the |
| 15 | +// specific language governing permissions and limitations |
| 16 | +// under the License. |
| 17 | + |
| 18 | +<template> |
| 19 | + <a-form |
| 20 | + class="form" |
| 21 | + :ref="formRef" |
| 22 | + :model="form" |
| 23 | + :rules="rules" |
| 24 | + layout="vertical" |
| 25 | + @finish="handleSubmit" |
| 26 | + v-ctrl-enter="handleSubmit" |
| 27 | + > |
| 28 | + <div style="margin-bottom: 10px"> |
| 29 | + <a-alert type="warning"> |
| 30 | + <template #message> |
| 31 | + <div v-html="$t('message.delete.account.warning')"></div> |
| 32 | + </template> |
| 33 | + </a-alert> |
| 34 | + </div> |
| 35 | + <div style="margin-bottom: 10px"> |
| 36 | + <a-alert> |
| 37 | + <template #message> |
| 38 | + <div v-html="$t('message.delete.account.confirm')"></div> |
| 39 | + </template> |
| 40 | + </a-alert> |
| 41 | + </div> |
| 42 | + <a-form-item name="name" ref="name"> |
| 43 | + <a-input |
| 44 | + v-model:value="form.name" |
| 45 | + :placeholder="$t('label.enter.account.name')" |
| 46 | + style="width: 100%"/> |
| 47 | + </a-form-item> |
| 48 | + <p v-if="error" class="error">{{ error }}</p> |
| 49 | + <div :span="24" class="actions"> |
| 50 | + <a-button @click="closeModal">{{ $t('label.cancel') }}</a-button> |
| 51 | + <a-button type="primary" ref="submit" @click="handleSubmit">{{ $t('label.ok') }}</a-button> |
| 52 | + </div> |
| 53 | + </a-form> |
| 54 | +</template> |
| 55 | + |
| 56 | +<script> |
| 57 | +import { ref, reactive } from 'vue' |
| 58 | +import { api } from '@/api' |
| 59 | +export default { |
| 60 | + name: 'DeleteAccount', |
| 61 | + props: { |
| 62 | + resource: { |
| 63 | + type: Object, |
| 64 | + required: true |
| 65 | + } |
| 66 | + }, |
| 67 | + data () { |
| 68 | + return { |
| 69 | + error: '' |
| 70 | + } |
| 71 | + }, |
| 72 | + created () { |
| 73 | + this.initForm() |
| 74 | + }, |
| 75 | + methods: { |
| 76 | + initForm () { |
| 77 | + this.formRef = ref() |
| 78 | + this.form = reactive({ |
| 79 | + }) |
| 80 | + this.rules = reactive({ |
| 81 | + name: [{ required: true, message: this.$t('label.required') }] |
| 82 | + }) |
| 83 | + }, |
| 84 | + closeModal () { |
| 85 | + this.$emit('close-action') |
| 86 | + }, |
| 87 | + handleSubmit (e) { |
| 88 | + e.preventDefault() |
| 89 | + this.formRef.value.validate().then(async () => { |
| 90 | + if (this.form.name !== this.resource.name) { |
| 91 | + this.error = `${this.$t('message.error.account.delete.name.mismatch')}` |
| 92 | + return |
| 93 | + } |
| 94 | + api('deleteAccount', { |
| 95 | + id: this.resource.id |
| 96 | + }).then(response => { |
| 97 | + this.$pollJob({ |
| 98 | + jobId: response.deleteaccountresponse.jobid, |
| 99 | + title: this.$t('label.action.delete.account'), |
| 100 | + description: this.resource.id, |
| 101 | + successMessage: `${this.$t('message.delete.account.success')} - ${this.resource.name}`, |
| 102 | + errorMessage: `${this.$t('message.delete.account.failed')} - ${this.resource.name}`, |
| 103 | + loadingMessage: `${this.$t('message.delete.account.processing')} - ${this.resource.name}`, |
| 104 | + catchMessage: this.$t('error.fetching.async.job.result') |
| 105 | + }) |
| 106 | + this.closeModal() |
| 107 | + }).catch(error => { |
| 108 | + this.$notifyError(error) |
| 109 | + }) |
| 110 | + }).catch((error) => { |
| 111 | + this.formRef.value.scrollToField(error.errorFields[0].name) |
| 112 | + }) |
| 113 | + } |
| 114 | + } |
| 115 | +} |
| 116 | +</script> |
| 117 | + |
| 118 | +<style lang="scss" scoped> |
| 119 | +.form { |
| 120 | + width: 80vw; |
| 121 | + @media (min-width: 500px) { |
| 122 | + width: 400px; |
| 123 | + } |
| 124 | +} |
| 125 | +.actions { |
| 126 | + display: flex; |
| 127 | + justify-content: flex-end; |
| 128 | + margin-top: 20px; |
| 129 | + button { |
| 130 | + &:not(:last-child) { |
| 131 | + margin-right: 10px; |
| 132 | + } |
| 133 | + } |
| 134 | +} |
| 135 | +.error { |
| 136 | + color: red; |
| 137 | + margin-top: 10px; |
| 138 | +} |
| 139 | +</style> |
0 commit comments