|
| 1 | +<template> |
| 2 | + <md-dialog @open="reset" ref="new-watcher-dialog"> |
| 3 | + <md-dialog-title>Add New Watcher</md-dialog-title> |
| 4 | + |
| 5 | + <md-dialog-content> |
| 6 | + <p>TODO: Build validation</p> |
| 7 | + |
| 8 | + <md-input-container> |
| 9 | + <label>Project Name</label> |
| 10 | + <md-input v-model="name" required></md-input> |
| 11 | + </md-input-container> |
| 12 | + |
| 13 | + <md-input-container> |
| 14 | + <label>Project Source</label> |
| 15 | + <md-input v-model="source" required></md-input> |
| 16 | + </md-input-container> |
| 17 | + |
| 18 | + <md-input-container> |
| 19 | + <label>Project Destination</label> |
| 20 | + <md-textarea v-model="destination" required></md-textarea> |
| 21 | + </md-input-container> |
| 22 | + |
| 23 | + <md-input-container> |
| 24 | + <label>Project Group</label> |
| 25 | + <md-select v-model="group_id"> |
| 26 | + <md-option v-for="group in $store.state.groups" :value="group.name">{{ group.name }}</md-option> |
| 27 | + </md-select> |
| 28 | + </md-input-container> |
| 29 | + </md-dialog-content> |
| 30 | + |
| 31 | + <md-dialog-actions> |
| 32 | + <md-spinner :md-size="20" md-indeterminate class="md-accent" v-if="isSubmitting"></md-spinner> |
| 33 | + <md-button class="md-primary" @click.native="closeDialog">Cancel</md-button> |
| 34 | + <md-button class="md-primary" @click.native="onSubmit">Ok</md-button> |
| 35 | + </md-dialog-actions> |
| 36 | + </md-dialog> |
| 37 | +</template> |
| 38 | + |
| 39 | +<script> |
| 40 | +import { mapGetters, mapMutations } from 'vuex' |
| 41 | +import events from '../../events' |
| 42 | +
|
| 43 | +export default { |
| 44 | + name: 'new-watcher-dialog', |
| 45 | + data () { |
| 46 | + return { |
| 47 | + name: '', |
| 48 | + group_id: '', |
| 49 | + source: '', |
| 50 | + destination: '', |
| 51 | + isSubmitting: false, |
| 52 | + errorMessages: { |
| 53 | + name: '', |
| 54 | + group_id: '', |
| 55 | + source: '', |
| 56 | + destination: '' |
| 57 | + } |
| 58 | + } |
| 59 | + }, |
| 60 | + computed: mapGetters(['watcherExists']), |
| 61 | + methods: { |
| 62 | + ...mapMutations(['addWatcher']), |
| 63 | + onSubmit () { |
| 64 | + if (!this.name.length || !this.source.length || !this.destination.length) { |
| 65 | + return |
| 66 | + } |
| 67 | +
|
| 68 | + this.isSubmitting = true |
| 69 | +
|
| 70 | + this.addWatcher({ |
| 71 | + name: this.name, |
| 72 | + group_id: this.group_id, |
| 73 | + source: this.source, |
| 74 | + destination: this.destination |
| 75 | + }) |
| 76 | +
|
| 77 | + this.closeDialog() |
| 78 | + }, |
| 79 | +
|
| 80 | + reset () { |
| 81 | + this.name = '' |
| 82 | + this.group = '' |
| 83 | + this.source = '' |
| 84 | + this.destination = '' |
| 85 | + this.isSubmitting = false |
| 86 | + }, |
| 87 | +
|
| 88 | + closeDialog () { |
| 89 | + this.$refs['new-watcher-dialog'].close() |
| 90 | + this.reset() |
| 91 | + } |
| 92 | + }, |
| 93 | + mounted () { |
| 94 | + events.$on('open:dialog:new-watcher-dialog', () => this.$refs['new-watcher-dialog'].open()) |
| 95 | + } |
| 96 | +} |
| 97 | +</script> |
0 commit comments