| // Licensed to the Apache Software Foundation (ASF) under one |
| // or more contributor license agreements. See the NOTICE file |
| // distributed with this work for additional information |
| // regarding copyright ownership. The ASF licenses this file |
| // to you under the Apache License, Version 2.0 (the |
| // "License"); you may not use this file except in compliance |
| // with the License. You may obtain a copy of the License at |
| // |
| // http://www.apache.org/licenses/LICENSE-2.0 |
| // |
| // Unless required by applicable law or agreed to in writing, |
| // software distributed under the License is distributed on an |
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| // KIND, either express or implied. See the License for the |
| // specific language governing permissions and limitations |
| // under the License. |
| |
| <template> |
| <div class="form-layout" v-ctrl-enter="handleSubmit"> |
| <a-spin :spinning="loading"> |
| <a-form |
| ref="formRef" |
| :model="form" |
| :rules="rules" |
| layout="vertical" |
| @finish="handleSubmit"> |
| |
| <a-form-item name="description" ref="description"> |
| <template #label> |
| <tooltip-label |
| :title="$t('label.description')" |
| :tooltip="apiParams.description?.description" /> |
| </template> |
| <a-input |
| v-model:value="form.description" |
| :placeholder="apiParams.description?.description" |
| v-focus="true" /> |
| </a-form-item> |
| |
| <div class="action-button"> |
| <a-button @click="closeAction"> |
| {{ $t('label.cancel') }} |
| </a-button> |
| <a-button |
| type="primary" |
| :loading="loading" |
| htmlType="submit"> |
| {{ $t('label.ok') }} |
| </a-button> |
| </div> |
| </a-form> |
| </a-spin> |
| </div> |
| </template> |
| |
| <script> |
| import { postAPI } from '@/api' |
| import TooltipLabel from '@/components/widgets/TooltipLabel' |
| |
| export default { |
| name: 'UpdateDnsZone', |
| components: { |
| TooltipLabel |
| }, |
| props: { |
| resource: { |
| type: Object, |
| required: true |
| } |
| }, |
| data () { |
| return { |
| loading: false, |
| apiParams: {}, |
| form: { |
| description: '' |
| }, |
| rules: {} |
| } |
| }, |
| created () { |
| this.apiParams = this.$getApiParams('updateDnsZone') || {} |
| this.form.description = this.resource.description || '' |
| }, |
| methods: { |
| async handleSubmit () { |
| if (this.loading) return |
| |
| try { |
| await this.$refs.formRef.validate() |
| } catch (error) { |
| if (error.errorFields && error.errorFields.length > 0) { |
| this.$refs.formRef.scrollToField(error.errorFields[0].name) |
| } |
| return |
| } |
| |
| this.loading = true |
| try { |
| const response = await postAPI('updateDnsZone', { |
| id: this.resource.id, |
| description: this.form.description?.trim() |
| }) |
| const zone = response?.updatednszoneresponse?.dnszone |
| if (!zone) { |
| this.$notification.error({ |
| message: this.$t('message.request.failed'), |
| description: 'Failed to get updated DNS zone from response', |
| duration: 0 |
| }) |
| this.loading = false |
| return |
| } |
| this.$notification.success({ |
| message: this.$t('label.dns.update.zone'), |
| description: `${this.$t('message.success.update.dns.zone')} ${this.resource.name}` |
| }) |
| this.loading = false |
| this.$emit('refresh-data') |
| this.closeAction() |
| } catch (error) { |
| this.$notification.error({ |
| message: this.$t('message.request.failed'), |
| description: error?.response?.headers['x-description'] || error.message, |
| duration: 0 |
| }) |
| this.loading = false |
| } |
| }, |
| closeAction () { |
| this.$emit('close-action') |
| } |
| } |
| } |
| </script> |
| |
| <style lang="less" scoped> |
| .form-layout { |
| width: 80vw; |
| @media (min-width: 600px) { |
| width: 450px; |
| } |
| } |
| |
| .action-button { |
| text-align: right; |
| margin-top: 20px; |
| } |
| .action-button button { |
| margin-left: 8px; |
| } |
| </style> |