summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/vue_shared/components/popup_dialog.vue
blob: 7d339c0e75303aefdd18f5c05517da480db3b271 (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
<script>
const PopupDialog = {
  name: 'popup-dialog',

  props: {
    open: Boolean,
    title: String,
    body: String,
    kind: {
      type: String,
      default: 'primary',
    },
    closeButtonLabel: {
      type: String,
      default: 'Cancel',
    },
    primaryButtonLabel: {
      type: String,
      default: 'Save changes',
    },
  },

  computed: {
    typeOfClass() {
      const className = `btn-${this.kind}`;
      const returnObj = {};
      returnObj[className] = true;
      return returnObj;
    },
  },

  methods: {
    close() {
      this.$emit('toggle', false);
    },

    yesClick() {
      this.$emit('submit', true);
    },

    noClick() {
      this.$emit('submit', false);
    },
  },
};

export default PopupDialog;
</script>
<template>
<div class="modal popup-dialog" tabindex="-1" v-show="open" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" @click="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title">{{this.title}}</h4>
      </div>
      <div class="modal-body">
        <p>{{this.body}}</p>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal" @click="noClick">{{closeButtonLabel}}</button>
        <button type="button" class="btn" :class="typeOfClass" @click="yesClick">{{primaryButtonLabel}}</button>
      </div>
    </div>
  </div>
</div>
</template>