|
| 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"> |
| 20 | + <a-spin :spinning="loading"> |
| 21 | + <a-form |
| 22 | + :form="form" |
| 23 | + @submit="handleSubmit" |
| 24 | + layout="vertical"> |
| 25 | + <a-form-item :label="$t('url')"> |
| 26 | + <a-input |
| 27 | + v-decorator="['url', { |
| 28 | + rules: [{ required: true, message: 'Please enter input' }] |
| 29 | + }]" |
| 30 | + :placeholder="$t('iso.url.description')" /> |
| 31 | + </a-form-item> |
| 32 | + |
| 33 | + <a-form-item :label="$t('name')"> |
| 34 | + <a-input |
| 35 | + v-decorator="['name', { |
| 36 | + rules: [{ required: true, message: 'Please enter input' }] |
| 37 | + }]" |
| 38 | + :placeholder="$t('iso.name.description')" /> |
| 39 | + </a-form-item> |
| 40 | + |
| 41 | + <a-form-item :label="$t('displaytext')"> |
| 42 | + <a-input |
| 43 | + v-decorator="['displaytext', { |
| 44 | + rules: [{ required: true, message: 'Please enter input' }] |
| 45 | + }]" |
| 46 | + :placeholder="$t('iso.displaytext.description')" /> |
| 47 | + </a-form-item> |
| 48 | + |
| 49 | + <a-form-item :label="$t('directdownload')"> |
| 50 | + <a-switch v-decorator="['directdownload']" /> |
| 51 | + </a-form-item> |
| 52 | + |
| 53 | + <a-form-item :label="$t('zoneid')"> |
| 54 | + <a-select |
| 55 | + v-decorator="['zoneid', { |
| 56 | + rules: [ |
| 57 | + { |
| 58 | + required: true, |
| 59 | + message: 'Please select option' |
| 60 | + } |
| 61 | + ] |
| 62 | + }]" |
| 63 | + showSearch |
| 64 | + optionFilterProp="children" |
| 65 | + :filterOption="(input, option) => { |
| 66 | + return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0 |
| 67 | + }" |
| 68 | + :loading="zoneLoading" |
| 69 | + :placeholder="$t('iso.zoneid.description')"> |
| 70 | + <a-select-option v-for="(opt, optIndex) in zones" :key="optIndex"> |
| 71 | + {{ opt.name || opt.description }} |
| 72 | + </a-select-option> |
| 73 | + </a-select> |
| 74 | + </a-form-item> |
| 75 | + |
| 76 | + <a-form-item :label="$t('bootable')"> |
| 77 | + <a-switch v-decorator="['bootable']" /> |
| 78 | + </a-form-item> |
| 79 | + |
| 80 | + <a-form-item :label="$t('ostypeid')"> |
| 81 | + <a-select |
| 82 | + v-decorator="['ostypeid', { |
| 83 | + rules: [{ required: true, message: 'Please select option' }] |
| 84 | + }]" |
| 85 | + showSearch |
| 86 | + optionFilterProp="children" |
| 87 | + :filterOption="(input, option) => { |
| 88 | + return option.componentOptions.children[0].text.toLowerCase().indexOf(input.toLowerCase()) >= 0 |
| 89 | + }" |
| 90 | + :loading="osTypeLoading" |
| 91 | + :placeholder="$t('iso.ostypeid.description')"> |
| 92 | + <a-select-option v-for="(opt, optIndex) in osTypes" :key="optIndex"> |
| 93 | + {{ opt.name || opt.description }} |
| 94 | + </a-select-option> |
| 95 | + </a-select> |
| 96 | + </a-form-item> |
| 97 | + |
| 98 | + <a-form-item :label="$t('isextractable')"> |
| 99 | + <a-switch v-decorator="['isextractable']" /> |
| 100 | + </a-form-item> |
| 101 | + |
| 102 | + <a-form-item :label="$t('ispublic')"> |
| 103 | + <a-switch v-decorator="['ispublic']" /> |
| 104 | + </a-form-item> |
| 105 | + |
| 106 | + <a-form-item :label="$t('isfeatured')"> |
| 107 | + <a-switch v-decorator="['isfeatured']" /> |
| 108 | + </a-form-item> |
| 109 | + |
| 110 | + <div :span="24" class="action-button"> |
| 111 | + <a-button @click="closeAction">{{ this.$t('Cancel') }}</a-button> |
| 112 | + <a-button :loading="loading" type="primary" @click="handleSubmit">{{ this.$t('OK') }}</a-button> |
| 113 | + </div> |
| 114 | + </a-form> |
| 115 | + </a-spin> |
| 116 | + </div> |
| 117 | +</template> |
| 118 | + |
| 119 | +<script> |
| 120 | +import { api } from '@/api' |
| 121 | +
|
| 122 | +export default { |
| 123 | + name: 'RegisterIso', |
| 124 | + data () { |
| 125 | + return { |
| 126 | + zones: [], |
| 127 | + osTypes: [], |
| 128 | + zoneLoading: false, |
| 129 | + osTypeLoading: false, |
| 130 | + loading: false |
| 131 | + } |
| 132 | + }, |
| 133 | + beforeCreate () { |
| 134 | + this.form = this.$form.createForm(this) |
| 135 | + }, |
| 136 | + created () { |
| 137 | + this.zones = [ |
| 138 | + { |
| 139 | + id: '-1', |
| 140 | + name: this.$t('label.all.zone') |
| 141 | + } |
| 142 | + ] |
| 143 | + }, |
| 144 | + mounted () { |
| 145 | + this.fetchData() |
| 146 | + }, |
| 147 | + methods: { |
| 148 | + fetchData () { |
| 149 | + this.fetchZoneData() |
| 150 | + this.fetchOsType() |
| 151 | + }, |
| 152 | + fetchZoneData () { |
| 153 | + const params = {} |
| 154 | + params.listAll = true |
| 155 | +
|
| 156 | + this.zoneLoading = true |
| 157 | +
|
| 158 | + api('listZones', params).then(json => { |
| 159 | + const listZones = json.listzonesresponse.zone |
| 160 | + this.zones = this.zones.concat(listZones) |
| 161 | + }).finally(() => { |
| 162 | + this.zoneLoading = false |
| 163 | + }) |
| 164 | + }, |
| 165 | + fetchOsType () { |
| 166 | + const params = {} |
| 167 | + params.listAll = true |
| 168 | +
|
| 169 | + this.osTypeLoading = true |
| 170 | +
|
| 171 | + api('listOsTypes', params).then(json => { |
| 172 | + const listOsTypes = json.listostypesresponse.ostype |
| 173 | + this.osTypes = this.osTypes.concat(listOsTypes) |
| 174 | + }).finally(() => { |
| 175 | + this.osTypeLoading = false |
| 176 | + }) |
| 177 | + }, |
| 178 | + handleSubmit (e) { |
| 179 | + e.preventDefault() |
| 180 | + this.form.validateFields((err, values) => { |
| 181 | + if (err) { |
| 182 | + return |
| 183 | + } |
| 184 | +
|
| 185 | + const params = {} |
| 186 | + for (const key in values) { |
| 187 | + const input = values[key] |
| 188 | + if (input === undefined) { |
| 189 | + continue |
| 190 | + } |
| 191 | + switch (key) { |
| 192 | + case 'zoneid': |
| 193 | + params[key] = this.zones[input].id |
| 194 | + break |
| 195 | + case 'ostypeid': |
| 196 | + params[key] = this.osTypes[input].id |
| 197 | + break |
| 198 | + default: |
| 199 | + params[key] = input |
| 200 | + break |
| 201 | + } |
| 202 | + } |
| 203 | +
|
| 204 | + this.loading = true |
| 205 | + api('registerIso', params).then(json => { |
| 206 | + this.$emit('refresh-data') |
| 207 | + this.$notification.success({ |
| 208 | + message: 'Register ISO', |
| 209 | + description: 'Sucessfully registered ISO' |
| 210 | + }) |
| 211 | + }).catch(error => { |
| 212 | + this.$notification.error({ |
| 213 | + message: 'Request Failed', |
| 214 | + description: (error.response && error.response.headers && error.response.headers['x-description']) || error.message |
| 215 | + }) |
| 216 | + }).finally(() => { |
| 217 | + this.loading = false |
| 218 | + this.closeAction() |
| 219 | + }) |
| 220 | + }) |
| 221 | + }, |
| 222 | + closeAction () { |
| 223 | + this.$emit('close-action') |
| 224 | + } |
| 225 | + } |
| 226 | +} |
| 227 | +</script> |
| 228 | + |
| 229 | +<style scoped lang="less"> |
| 230 | + .form-layout { |
| 231 | + width: 500px; |
| 232 | + } |
| 233 | +
|
| 234 | + .action-button { |
| 235 | + text-align: right; |
| 236 | +
|
| 237 | + button { |
| 238 | + margin-right: 5px; |
| 239 | + } |
| 240 | + } |
| 241 | +</style> |
0 commit comments