|
| 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 | + <div class="form-layout" v-ctrl-enter="handleSubmit"> |
| 20 | + <a-spin :spinning="loading"> |
| 21 | + <a-form |
| 22 | + :ref="formRef" |
| 23 | + :model="form" |
| 24 | + :rules="rules" |
| 25 | + layout="vertical" |
| 26 | + @finish="handleSubmit" |
| 27 | + > |
| 28 | + <div style="margin-bottom: 10px"> |
| 29 | + <a-alert type="warning"> |
| 30 | + <template #message> |
| 31 | + <div v-html="$t('message.backup.create')"></div> |
| 32 | + </template> |
| 33 | + </a-alert> |
| 34 | + </div> |
| 35 | + <div v-if="canSetNameAndDescription"> |
| 36 | + <a-form-item name="name" ref="name" :label="$t('label.name')"> |
| 37 | + <a-input v-model:value="form.name" v-focus="true" /> |
| 38 | + </a-form-item> |
| 39 | + <a-form-item name="description" ref="description" :label="$t('label.description')"> |
| 40 | + <a-input v-model:value="form.description" v-focus="true" /> |
| 41 | + </a-form-item> |
| 42 | + </div> |
| 43 | + </a-form> |
| 44 | + <div :span="24" class="action-button"> |
| 45 | + <a-button @click="closeAction">{{ $t('label.cancel') }}</a-button> |
| 46 | + <a-button :loading="loading" type="primary" @click="handleSubmit" ref="submit">{{ $t('label.ok') }}</a-button> |
| 47 | + </div> |
| 48 | + </a-spin> |
| 49 | + </div> |
| 50 | +</template> |
| 51 | +<script> |
| 52 | +import { ref, toRaw } from 'vue' |
| 53 | +import { api } from '@/api' |
| 54 | +import { mixinForm } from '@/utils/mixin' |
| 55 | +
|
| 56 | +export default { |
| 57 | + name: 'StartBackup', |
| 58 | + mixins: [mixinForm], |
| 59 | + props: { |
| 60 | + resource: { |
| 61 | + type: Object, |
| 62 | + required: true |
| 63 | + } |
| 64 | + }, |
| 65 | + data () { |
| 66 | + return { |
| 67 | + plugin: null, |
| 68 | + loading: false |
| 69 | + } |
| 70 | + }, |
| 71 | + created () { |
| 72 | + this.initForm() |
| 73 | + this.getBackupProviderPlugin() |
| 74 | + }, |
| 75 | + computed: { |
| 76 | + canSetNameAndDescription () { |
| 77 | + return ['nas', 'dummy'].includes(this.plugin) |
| 78 | + } |
| 79 | + }, |
| 80 | + methods: { |
| 81 | + initForm () { |
| 82 | + this.formRef = ref() |
| 83 | + this.form = ({}) |
| 84 | + }, |
| 85 | + getBackupProviderPlugin () { |
| 86 | + this.loading = true |
| 87 | + api('listConfigurations', { name: 'backup.framework.provider.plugin' }).then(json => { |
| 88 | + this.plugin = json.listconfigurationsresponse.configuration[0].value |
| 89 | + }).finally(() => { |
| 90 | + this.loading = false |
| 91 | + }) |
| 92 | + }, |
| 93 | + closeModal () { |
| 94 | + this.$emit('close-action') |
| 95 | + }, |
| 96 | + handleSubmit (e) { |
| 97 | + e.preventDefault() |
| 98 | + if (this.loading) return |
| 99 | + this.formRef.value.validate().then(async () => { |
| 100 | + const formRaw = toRaw(this.form) |
| 101 | + const values = this.handleRemoveFields(formRaw) |
| 102 | +
|
| 103 | + var data = { |
| 104 | + virtualmachineid: this.resource.id, |
| 105 | + name: this.form.name, |
| 106 | + description: this.form.description |
| 107 | + } |
| 108 | + this.loading = true |
| 109 | + api('createBackup', data).then(response => { |
| 110 | + this.$pollJob({ |
| 111 | + jobId: response.createbackupresponse.jobid, |
| 112 | + title: this.$t('label.create.bucket'), |
| 113 | + description: values.name, |
| 114 | + errorMessage: this.$t('message.create.backup.failed'), |
| 115 | + loadingMessage: `${this.$t('label.create.backup')}: ${this.resource.name || this.resource.id}`, |
| 116 | + catchMessage: this.$t('error.fetching.async.job.result') |
| 117 | + }) |
| 118 | + this.closeModal() |
| 119 | + }).catch(error => { |
| 120 | + this.$notifyError(error) |
| 121 | + }).finally(() => { |
| 122 | + this.loading = false |
| 123 | + }) |
| 124 | + }).catch((error) => { |
| 125 | + this.formRef.value.scrollToField(error.errorFields[0].name) |
| 126 | + }) |
| 127 | + } |
| 128 | + } |
| 129 | +} |
| 130 | +
|
| 131 | +</script> |
| 132 | +<style lang="scss" scoped> |
| 133 | +.form-layout { |
| 134 | + width: 80vw; |
| 135 | +
|
| 136 | + @media (min-width: 500px) { |
| 137 | + width: 400px; |
| 138 | + } |
| 139 | +} |
| 140 | +.actions { |
| 141 | + display: flex; |
| 142 | + justify-content: flex-end; |
| 143 | + margin-top: 20px; |
| 144 | + button { |
| 145 | + &:not(:last-child) { |
| 146 | + margin-right: 10px; |
| 147 | + } |
| 148 | + } |
| 149 | +} |
| 150 | +</style> |
0 commit comments