2021-05-07 23:21:38 +01:00
|
|
|
import { addClipboardNotifications } from "../pageUtils";
|
2021-05-07 22:23:52 +01:00
|
|
|
import { makeElement } from "../htmlUtils";
|
2021-04-17 10:29:22 +01:00
|
|
|
import ClipboardJS from "clipboard";
|
|
|
|
import FileSaver from 'file-saver';
|
2021-04-29 10:38:42 +01:00
|
|
|
import i18next from 'i18next';
|
2021-04-17 10:29:22 +01:00
|
|
|
|
2021-05-08 00:30:44 +01:00
|
|
|
export function CopyableModal(name: string, contentString: string): Element {
|
2021-04-17 10:29:22 +01:00
|
|
|
return makeElement({
|
|
|
|
tag: "div",
|
|
|
|
class: "modal-sections",
|
|
|
|
attributes: {
|
|
|
|
"uk-modal": ""
|
|
|
|
},
|
|
|
|
children: makeElement({
|
|
|
|
tag: "div",
|
|
|
|
class: "uk-modal-dialog",
|
|
|
|
children: [
|
|
|
|
makeElement({
|
|
|
|
tag: "button",
|
|
|
|
class: "uk-modal-close-default",
|
|
|
|
attributes: {
|
|
|
|
"uk-close": "",
|
|
|
|
type: "button"
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "div",
|
|
|
|
class: "uk-modal-header",
|
|
|
|
children: makeElement({
|
|
|
|
tag: "h2",
|
|
|
|
class: "uk-modal-title",
|
|
|
|
text: name
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "div",
|
|
|
|
class: ["uk-modal-body"],
|
|
|
|
children: makeElement({
|
|
|
|
tag: "pre",
|
|
|
|
class: "wrap-pre",
|
|
|
|
text: contentString
|
|
|
|
})
|
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "div",
|
|
|
|
class: ["uk-modal-footer", "uk-text-right"],
|
|
|
|
children: [
|
|
|
|
makeElement({
|
|
|
|
tag: "button",
|
|
|
|
class: ["uk-button", "uk-button-primary"],
|
|
|
|
attributes: {
|
|
|
|
type: "button",
|
|
|
|
"data-clipboard-text": contentString
|
|
|
|
},
|
2021-04-29 10:38:42 +01:00
|
|
|
text: i18next.t("copy_modal_download_btn"),
|
2021-04-17 10:29:22 +01:00
|
|
|
onclick: _ => {
|
2021-05-08 00:30:44 +01:00
|
|
|
const blob = new Blob([contentString], {type: "text/plain;charset=utf-8"});
|
2021-04-17 10:29:22 +01:00
|
|
|
FileSaver.saveAs(blob, "result.txt");
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "button",
|
|
|
|
class: ["uk-button", "uk-button-primary"],
|
|
|
|
attributes: {
|
|
|
|
type: "button",
|
|
|
|
"data-clipboard-text": contentString
|
|
|
|
},
|
2021-04-29 10:38:42 +01:00
|
|
|
text: i18next.t("copy_modal_copy_btn"),
|
2021-04-17 10:29:22 +01:00
|
|
|
thenRun: (e) => {
|
2021-05-08 00:30:44 +01:00
|
|
|
const clipboard = new ClipboardJS(e);
|
2021-04-29 10:38:42 +01:00
|
|
|
addClipboardNotifications(clipboard);
|
2021-04-17 10:29:22 +01:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
makeElement({
|
|
|
|
tag: "button",
|
|
|
|
class: ["uk-button", "uk-button-secondary", "uk-modal-close"],
|
|
|
|
attributes: { type: "button" },
|
2021-04-29 10:38:42 +01:00
|
|
|
text: i18next.t("copy_modal_close_btn")
|
2021-04-17 10:29:22 +01:00
|
|
|
}),
|
|
|
|
|
|
|
|
]
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|