summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/environments/components/environment_stop.vue
blob: 7055f208451f02e737e794e78e143a49064d1cd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<script>
  /**
  * Renders the stop "button" that allows stop an environment.
  * Used in environments table.
  */

  import $ from 'jquery';
  import eventHub from '../event_hub';
  import loadingIcon from '../../vue_shared/components/loading_icon.vue';
  import tooltip from '../../vue_shared/directives/tooltip';

  export default {
    components: {
      loadingIcon,
    },

    directives: {
      tooltip,
    },

    props: {
      stopUrl: {
        type: String,
        default: '',
      },
    },

    data() {
      return {
        isLoading: false,
      };
    },

    computed: {
      title() {
        return 'Stop';
      },
    },

    methods: {
      onClick() {
        // eslint-disable-next-line no-alert
        if (confirm('Are you sure you want to stop this environment?')) {
          this.isLoading = true;

          $(this.$el).tooltip('dispose');

          eventHub.$emit('postAction', this.stopUrl);
        }
      },
    },
  };
</script>
<template>
  <button
    v-tooltip
    type="button"
    class="btn stop-env-link d-none d-sm-none d-md-block"
    data-container="body"
    @click="onClick"
    :disabled="isLoading"
    :title="title"
    :aria-label="title"
  >
    <i
      class="fa fa-stop stop-env-icon"
      aria-hidden="true"
    >
    </i>
    <loading-icon v-if="isLoading" />
  </button>
</template>