2023-06-19 15:46:50 +08:00
|
|
|
import $ from 'jquery';
|
|
|
|
import {svg} from '../../svg.js';
|
|
|
|
import {htmlEscape} from 'escape-goat';
|
|
|
|
|
|
|
|
const {i18n} = window.config;
|
|
|
|
|
2023-09-19 06:05:31 +08:00
|
|
|
export async function confirmModal(opts = {content: '', buttonColor: 'primary'}) {
|
2023-06-19 15:46:50 +08:00
|
|
|
return new Promise((resolve) => {
|
|
|
|
const $modal = $(`
|
|
|
|
<div class="ui g-modal-confirm modal">
|
|
|
|
<div class="content">${htmlEscape(opts.content)}</div>
|
|
|
|
<div class="actions">
|
2023-09-19 06:05:31 +08:00
|
|
|
<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>
|
2023-06-19 15:46:50 +08:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
`);
|
|
|
|
|
|
|
|
$modal.appendTo(document.body);
|
|
|
|
$modal.modal({
|
|
|
|
onApprove() {
|
|
|
|
resolve(true);
|
|
|
|
},
|
|
|
|
onHidden() {
|
|
|
|
$modal.remove();
|
|
|
|
resolve(false);
|
|
|
|
},
|
|
|
|
}).modal('show');
|
|
|
|
});
|
|
|
|
}
|