summaryrefslogtreecommitdiffstats
path: root/web_src/js/features/comp/ConfirmModal.js
blob: e64996a3529a796ec630859ce1760c498206df68 (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
import $ from 'jquery';
import {svg} from '../../svg.js';
import {htmlEscape} from 'escape-goat';

const {i18n} = window.config;

export async function confirmModal(opts = {content: '', buttonColor: 'primary'}) {
  return new Promise((resolve) => {
    const $modal = $(`
<div class="ui g-modal-confirm modal">
  <div class="content">${htmlEscape(opts.content)}</div>
  <div class="actions">
    <button class="ui cancel button">${svg('octicon-x')} ${i18n.modal_cancel}</button>
    <button class="ui ${opts.buttonColor || 'primary'} ok button">${svg('octicon-check')} ${i18n.modal_confirm}</button>
  </div>
</div>
`);

    $modal.appendTo(document.body);
    $modal.modal({
      onApprove() {
        resolve(true);
      },
      onHidden() {
        $modal.remove();
        resolve(false);
      },
    }).modal('show');
  });
}