2021-05-03 09:25:42 +01:00
|
|
|
import { Margin } from "../../elements/Margin.js";
|
|
|
|
import { MarginInline } from "../../elements/MarginInline.js";
|
2021-04-17 10:45:42 +01:00
|
|
|
import { Page } from "../../types/Page.js";
|
|
|
|
import { addNewTOTP } from "../../api.js";
|
2021-05-03 09:25:42 +01:00
|
|
|
import { changePage, setErrorText, setPageContent, setTitleElement } from "../../pageUtils.js";
|
2021-04-17 10:45:42 +01:00
|
|
|
import { makeElement } from "../../htmlUtils.js";
|
2021-05-07 11:07:03 +01:00
|
|
|
import { pageState } from "../../globalPageState.js";
|
2021-04-20 23:23:17 +01:00
|
|
|
import i18next from 'i18next';
|
2021-04-15 13:01:58 +01:00
|
|
|
|
|
|
|
export class NewTOTPPage extends Page {
|
|
|
|
constructor() {
|
|
|
|
super();
|
|
|
|
}
|
|
|
|
goBack() {
|
2021-04-17 11:24:43 +01:00
|
|
|
changePage("TOTP");
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
render() {
|
|
|
|
setTitleElement(pageState);
|
|
|
|
|
|
|
|
let totpForm = makeElement({
|
|
|
|
tag: "form",
|
|
|
|
children: [
|
|
|
|
Margin(makeElement({
|
|
|
|
tag: "input",
|
|
|
|
class: ["uk-input", "uk-form-width-medium"],
|
|
|
|
attributes: {
|
|
|
|
required: true,
|
|
|
|
type: "text",
|
2021-04-20 23:23:17 +01:00
|
|
|
placeholder: i18next.t("totp_new_name_text"),
|
2021-04-15 13:01:58 +01:00
|
|
|
name: "name"
|
|
|
|
}
|
|
|
|
})),
|
|
|
|
makeElement({
|
|
|
|
tag: "p",
|
2021-04-20 23:23:17 +01:00
|
|
|
text: i18next.t("totp_new_info")
|
2021-04-15 13:01:58 +01:00
|
|
|
}),
|
|
|
|
Margin(makeElement({
|
|
|
|
tag: "input",
|
|
|
|
class: ["uk-input", "uk-form-width-medium"],
|
|
|
|
attributes: {
|
|
|
|
type: "text",
|
2021-04-20 23:23:17 +01:00
|
|
|
placeholder: i18next.t("totp_new_uri_input"),
|
2021-04-15 13:01:58 +01:00
|
|
|
name: "uri"
|
|
|
|
}
|
|
|
|
})),
|
|
|
|
Margin(makeElement({
|
|
|
|
tag: "input",
|
|
|
|
class: ["uk-input", "uk-form-width-medium"],
|
|
|
|
attributes: {
|
|
|
|
type: "text",
|
2021-04-20 23:23:17 +01:00
|
|
|
placeholder: i18next.t("totp_new_key_input"),
|
2021-04-15 13:01:58 +01:00
|
|
|
name: "key"
|
|
|
|
}
|
|
|
|
})),
|
|
|
|
makeElement({
|
|
|
|
tag: "p",
|
|
|
|
id: "errorText",
|
|
|
|
class: "uk-text-danger"
|
|
|
|
}),
|
|
|
|
MarginInline(makeElement({
|
|
|
|
tag: "button",
|
|
|
|
class: ["uk-button", "uk-button-primary"],
|
2021-04-20 23:23:17 +01:00
|
|
|
text: i18next.t("totp_new_add_btn"),
|
2021-04-15 13:01:58 +01:00
|
|
|
attributes: {
|
|
|
|
type: "submit"
|
|
|
|
}
|
|
|
|
}))
|
|
|
|
]
|
|
|
|
|
|
|
|
});
|
|
|
|
setPageContent(totpForm);
|
|
|
|
|
|
|
|
totpForm.addEventListener("submit", function (e) {
|
|
|
|
e.preventDefault();
|
|
|
|
let formData = new FormData(totpForm);
|
|
|
|
let parms = {
|
|
|
|
url: formData.get("uri"),
|
2021-04-18 10:44:24 +01:00
|
|
|
key: formData.get("key").replaceAll("-", "").replaceAll(" ", "").toUpperCase(),
|
2021-04-15 13:01:58 +01:00
|
|
|
name: formData.get("name"),
|
|
|
|
generate: false
|
|
|
|
};
|
2021-04-18 10:42:57 +01:00
|
|
|
addNewTOTP(pageState.currentBaseMount, parms).then(_ => {
|
2021-04-17 11:24:43 +01:00
|
|
|
changePage("TOTP");
|
2021-04-15 13:01:58 +01:00
|
|
|
}).catch(e => {
|
|
|
|
setErrorText(`API Error: ${e.message}`);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2021-04-17 11:06:34 +01:00
|
|
|
|
2021-04-20 20:32:57 +01:00
|
|
|
get titleSuffix() {
|
2021-04-20 23:23:17 +01:00
|
|
|
return i18next.t("totp_new_suffix");
|
2021-04-17 11:06:34 +01:00
|
|
|
}
|
|
|
|
|
2021-04-15 13:01:58 +01:00
|
|
|
get name() {
|
2021-04-20 23:23:17 +01:00
|
|
|
return i18next.t("totp_new_title");
|
2021-04-15 13:01:58 +01:00
|
|
|
}
|
|
|
|
}
|