issue Fix rename functionality #95

This commit is contained in:
Kostiantyn Stoliarskyi 2023-05-31 16:43:33 +03:00
parent 802cf752e8
commit 44fd27e467
5 changed files with 26 additions and 4 deletions

View File

@ -20,6 +20,7 @@
"jsonify",
"pydantic",
"pytest",
"scrf",
"siwe",
"sqlalchemy",
"tailwindcss",

View File

@ -15,7 +15,7 @@ class BaseConfig(BaseSettings):
APP_NAME: str = "Open Law"
SECRET_KEY: str
SQLALCHEMY_TRACK_MODIFICATIONS: bool = False
WTF_CSRF_ENABLED: bool = False
WTF_CSRF_ENABLED: bool = True
# Super admin
ADMIN_USERNAME: str

View File

@ -9,10 +9,15 @@ export function renameCollection() {
btn.addEventListener('click', () => {
const inputsForRename: NodeListOf<HTMLInputElement> =
document.querySelectorAll(`[id^="edit-collection-label-"]`);
const scrfInput: HTMLInputElement =
document.querySelector('#csrf_token');
inputsForRename[index].removeAttribute('readonly');
const oldName = inputsForRename[index].value;
inputsForRename[index].value = '';
inputsForRename[index].value = oldName;
inputsForRename[index].focus();
inputsForRename[index].selectionStart = inputsForRename[
index
].selectionEnd = 257;
inputsForRename[index].addEventListener('blur', () => {
inputsForRename[index].value = oldName;
});
@ -35,6 +40,7 @@ export function renameCollection() {
},
body: JSON.stringify({
label: newLabel,
csrf_token: scrfInput.value,
}),
});
if (response.status == 200) {

View File

@ -4,18 +4,26 @@ export function renameSection() {
);
const sectionRenameForms: NodeListOf<HTMLFormElement> =
document.querySelectorAll('[id^="rename-section-label-form-"]');
if (renameSectionBtns.length > 0 && sectionRenameForms.length > 0) {
renameSectionBtns.forEach((btn, index) => {
btn.addEventListener('click', () => {
const inputsForRename: NodeListOf<HTMLInputElement> =
document.querySelectorAll(`[id^="edit-section-label-"]`);
const scrfInput: HTMLInputElement =
document.querySelector('#csrf_token');
console.log(scrfInput.value);
const oldName = inputsForRename[index].value;
inputsForRename[index].removeAttribute('readonly');
inputsForRename[index].value = '';
inputsForRename[index].value = oldName;
inputsForRename[index].focus();
inputsForRename[index].selectionStart = inputsForRename[
index
].selectionEnd = 257;
inputsForRename[index].addEventListener('blur', () => {
inputsForRename[index].value = oldName;
});
console.log(sectionRenameForms[index]);
sectionRenameForms[index].addEventListener('submit', async e => {
e.preventDefault();
const bookId = sectionRenameForms[index].getAttribute('data-book-id');
@ -36,6 +44,7 @@ export function renameSection() {
body: JSON.stringify({
label: newLabel,
section_id: sectionId,
csrf_token: scrfInput.value,
}),
});
if (response.status == 200) {

View File

@ -12,10 +12,15 @@ export function renameSubCollection() {
btn.addEventListener('click', () => {
const inputsForRename: NodeListOf<HTMLInputElement> =
document.querySelectorAll(`[id^="edit-sub-collection-label-"]`);
const scrfInput: HTMLInputElement =
document.querySelector('#csrf_token');
const oldName = inputsForRename[index].value;
inputsForRename[index].removeAttribute('readonly');
inputsForRename[index].value = '';
inputsForRename[index].value = oldName;
inputsForRename[index].focus();
inputsForRename[index].selectionStart = inputsForRename[
index
].selectionEnd = 257;
inputsForRename[index].addEventListener('blur', () => {
inputsForRename[index].value = oldName;
});
@ -39,6 +44,7 @@ export function renameSubCollection() {
},
body: JSON.stringify({
label: newLabel,
csrf_token: scrfInput.value,
}),
});
if (response.status == 200) {