DeleteCollectionScene: Use proper class

This commit is contained in:
Max Berger
2026-03-04 21:34:29 +01:00
parent 326553915f
commit 066a133860

View File

@@ -25,13 +25,13 @@ import { LoadingScene } from "./LoadingScene.js";
import { delete_collection } from "./api.js"; import { delete_collection } from "./api.js";
/** /**
* @constructor
* @implements {Scene} * @implements {Scene}
* @param {string} user * @param {string} user
* @param {string} password * @param {string} password
* @param {Collection} collection * @param {Collection} collection
*/ */
export function DeleteCollectionScene(user, password, collection) { export class DeleteCollectionScene {
constructor(user, password, collection) {
/** @type {HTMLElement} */ let html_scene = document.getElementById("deletecollectionscene"); /** @type {HTMLElement} */ let html_scene = document.getElementById("deletecollectionscene");
/** @type {HTMLElement} */ let title_form = html_scene.querySelector("[data-name=title]"); /** @type {HTMLElement} */ let title_form = html_scene.querySelector("[data-name=title]");
/** @type {HTMLElement} */ let error_form = html_scene.querySelector("[data-name=error]"); /** @type {HTMLElement} */ let error_form = html_scene.querySelector("[data-name=error]");
@@ -50,14 +50,14 @@ export function DeleteCollectionScene(user, password, collection) {
function ondelete() { function ondelete() {
let confirmation_text_value = confirmation_txt.value; let confirmation_text_value = confirmation_txt.value;
if(confirmation_text_value != DELETE_CONFIRMATION_TEXT){ if (confirmation_text_value != DELETE_CONFIRMATION_TEXT) {
alert("Please type the confirmation text to delete this collection."); alert("Please type the confirmation text to delete this collection.");
return; return;
} }
try { try {
let loading_scene = new LoadingScene(); let loading_scene = new LoadingScene();
push_scene(loading_scene, false); push_scene(loading_scene, false);
delete_req = delete_collection(user, password, collection, function(error1) { delete_req = delete_collection(user, password, collection, function (error1) {
if (scene_index === null) { if (scene_index === null) {
return; return;
} }
@@ -69,7 +69,7 @@ export function DeleteCollectionScene(user, password, collection) {
pop_scene(scene_index - 1); pop_scene(scene_index - 1);
} }
}); });
} catch(err) { } catch (err) {
console.error(err); console.error(err);
} }
return false; return false;
@@ -78,44 +78,45 @@ export function DeleteCollectionScene(user, password, collection) {
function oncancel() { function oncancel() {
try { try {
pop_scene(scene_index - 1); pop_scene(scene_index - 1);
} catch(err) { } catch (err) {
console.error(err); console.error(err);
} }
return false; return false;
} }
function onkeydown(event){ function onkeydown(event) {
if (event.keyCode !== 13) { if (event.keyCode !== 13) {
return; return;
} }
ondelete(); ondelete();
} }
this.show = function() { this.show = function () {
this.release(); this.release();
scene_index = scene_stack.length - 1; scene_index = scene_stack.length - 1;
html_scene.classList.remove("hidden"); html_scene.classList.remove("hidden");
title_form.textContent = collection.displayname || collection.href; title_form.textContent = collection.displayname || collection.href;
delete_btn.onclick = ondelete; delete_btn.onclick = ondelete;
cancel_btn.onclick = oncancel; cancel_btn.onclick = oncancel;
if(error){ if (error) {
error_form.textContent = "Error: " + error; error_form.textContent = "Error: " + error;
error_form.classList.remove("hidden"); error_form.classList.remove("hidden");
}else{ } else {
error_form.classList.add("hidden"); error_form.classList.add("hidden");
} }
}; };
this.hide = function() { this.hide = function () {
html_scene.classList.add("hidden"); html_scene.classList.add("hidden");
cancel_btn.onclick = null; cancel_btn.onclick = null;
delete_btn.onclick = null; delete_btn.onclick = null;
}; };
this.release = function() { this.release = function () {
scene_index = null; scene_index = null;
if (delete_req !== null) { if (delete_req !== null) {
delete_req.abort(); delete_req.abort();
delete_req = null; delete_req = null;
} }
}; };
}
} }