summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/pages/shared/wikis/components/delete_wiki_modal.vue
blob: 3792dad376b285c61cbca5fc9b0955570e3f611c (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
<script>
import { GlButton, GlModal, GlModalDirective } from '@gitlab/ui';
import { escape } from 'lodash';
import { s__, __, sprintf } from '~/locale';

export default {
  components: {
    GlModal,
    GlButton,
  },
  directives: {
    'gl-modal': GlModalDirective,
  },
  props: {
    deleteWikiUrl: {
      type: String,
      required: true,
      default: '',
    },
    pageTitle: {
      type: String,
      required: true,
      default: '',
    },
    csrfToken: {
      type: String,
      required: true,
      default: '',
    },
  },
  computed: {
    title() {
      return sprintf(
        s__('WikiPageConfirmDelete|Delete page %{pageTitle}?'),
        {
          pageTitle: escape(this.pageTitle),
        },
        false,
      );
    },
    primaryProps() {
      return {
        text: this.$options.i18n.deletePageText,
        attributes: {
          variant: 'danger',
          'data-qa-selector': 'confirm_deletion_button',
          'data-testid': 'confirm_deletion_button',
        },
      };
    },
    cancelProps() {
      return {
        text: this.$options.i18n.cancelButtonText,
      };
    },
  },
  methods: {
    onSubmit() {
      window.onbeforeunload = null;
      this.$refs.form.submit();
    },
  },
  i18n: {
    deletePageText: s__('WikiPageConfirmDelete|Delete page'),
    modalBody: s__('WikiPageConfirmDelete|Are you sure you want to delete this page?'),
    cancelButtonText: __('Cancel'),
  },
  modal: {
    modalId: 'delete-wiki-modal',
  },
};
</script>

<template>
  <div class="d-inline-block">
    <gl-button
      v-gl-modal="$options.modal.modalId"
      category="secondary"
      variant="danger"
      data-qa-selector="delete_button"
    >
      {{ $options.i18n.deletePageText }}
    </gl-button>
    <gl-modal
      :title="title"
      :action-primary="primaryProps"
      :action-cancel="cancelProps"
      :modal-id="$options.modal.modalId"
      size="sm"
      @ok="onSubmit"
    >
      {{ $options.i18n.modalBody }}
      <form ref="form" :action="deleteWikiUrl" method="post" class="js-requires-input">
        <input ref="method" type="hidden" name="_method" value="delete" />
        <input :value="csrfToken" type="hidden" name="authenticity_token" />
      </form>
    </gl-modal>
  </div>
</template>