2017-08-17 22:00:37 +05:30
|
|
|
<script>
|
|
|
|
/* eslint-disable no-new, no-alert */
|
2017-09-10 17:25:29 +05:30
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
import eventHub from '../event_hub';
|
2017-09-10 17:25:29 +05:30
|
|
|
import loadingIcon from '../../vue_shared/components/loading_icon.vue';
|
|
|
|
import tooltip from '../../vue_shared/directives/tooltip';
|
2017-08-17 22:00:37 +05:30
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
endpoint: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
icon: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
cssClass: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
confirmActionMessage: {
|
|
|
|
type: String,
|
|
|
|
required: false,
|
|
|
|
},
|
|
|
|
},
|
2017-09-10 17:25:29 +05:30
|
|
|
directives: {
|
|
|
|
tooltip,
|
|
|
|
},
|
|
|
|
components: {
|
|
|
|
loadingIcon,
|
|
|
|
},
|
2017-08-17 22:00:37 +05:30
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLoading: false,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
computed: {
|
|
|
|
iconClass() {
|
|
|
|
return `fa fa-${this.icon}`;
|
|
|
|
},
|
|
|
|
buttonClass() {
|
2017-09-10 17:25:29 +05:30
|
|
|
return `btn ${this.cssClass}`;
|
2017-08-17 22:00:37 +05:30
|
|
|
},
|
|
|
|
},
|
|
|
|
methods: {
|
|
|
|
onClick() {
|
|
|
|
if (this.confirmActionMessage && confirm(this.confirmActionMessage)) {
|
|
|
|
this.makeRequest();
|
|
|
|
} else if (!this.confirmActionMessage) {
|
|
|
|
this.makeRequest();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
makeRequest() {
|
|
|
|
this.isLoading = true;
|
|
|
|
|
2017-09-10 17:25:29 +05:30
|
|
|
eventHub.$emit('postAction', this.endpoint);
|
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">
|
|
|
|
<i
|
|
|
|
:class="iconClass"
|
2017-09-10 17:25:29 +05:30
|
|
|
aria-hidden="true">
|
|
|
|
</i>
|
|
|
|
<loading-icon v-if="isLoading" />
|
2017-08-17 22:00:37 +05:30
|
|
|
</button>
|
|
|
|
</template>
|