debian-mirror-gitlab/app/assets/javascripts/pipelines/components/async_button.vue

82 lines
1.5 KiB
Vue
Raw Normal View History

2017-08-17 22:00:37 +05:30
<script>
2018-03-17 18:26:18 +05:30
/* eslint-disable no-alert */
2017-09-10 17:25:29 +05:30
2018-03-17 18:26:18 +05:30
import eventHub from '../event_hub';
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
import icon from '../../vue_shared/components/icon.vue';
import tooltip from '../../vue_shared/directives/tooltip';
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
export default {
directives: {
tooltip,
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
components: {
loadingIcon,
icon,
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
props: {
endpoint: {
type: String,
required: true,
},
title: {
type: String,
required: true,
},
icon: {
type: String,
required: true,
},
cssClass: {
type: String,
required: true,
},
id: {
type: Number,
required: true,
},
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
data() {
return {
isLoading: false,
};
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
computed: {
buttonClass() {
return `btn ${this.cssClass}`;
},
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
methods: {
onClick() {
eventHub.$emit('actionConfirmationModal', {
id: this.id,
callback: this.makeRequest,
});
},
makeRequest() {
this.isLoading = true;
2017-08-17 22:00:37 +05:30
2018-03-17 18:26:18 +05:30
eventHub.$emit('postAction', this.endpoint);
},
2017-08-17 22:00:37 +05:30
},
2018-03-17 18:26:18 +05:30
};
2017-08-17 22:00:37 +05:30
</script>
<template>
<button
2017-09-10 17:25:29 +05:30
v-tooltip
2017-08-17 22:00:37 +05:30
type="button"
@click="onClick"
:class="buttonClass"
:title="title"
:aria-label="title"
data-container="body"
data-placement="top"
:disabled="isLoading">
2018-03-17 18:26:18 +05:30
<icon
:name="icon"
/>
2017-09-10 17:25:29 +05:30
<loading-icon v-if="isLoading" />
2017-08-17 22:00:37 +05:30
</button>
</template>