Add ErrorHandler to share behavior
This commit is contained in:
@@ -26,6 +26,7 @@ import {
|
||||
server_features,
|
||||
} from "../api/api.js";
|
||||
import { Collection } from "../models/collection.js";
|
||||
import { ErrorHandler } from "../utils/error.js";
|
||||
import { NewShareScene } from "./NewShareScene.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
|
||||
@@ -56,8 +57,11 @@ export class ShareCollectionScene {
|
||||
/** @type {HTMLElement} */ let share_by_map_div = html_scene.querySelector(
|
||||
"div[data-name=sharebymap]"
|
||||
);
|
||||
/** @type {HTMLElement} */ let error_form = html_scene.querySelector("[data-name=error]");
|
||||
|
||||
/** @type {HTMLElement} */ let title = html_scene.querySelector("[data-name=title]");
|
||||
let errorHandler = new ErrorHandler(error_form);
|
||||
|
||||
/** @type {HTMLElement} */ let title = html_scene.querySelector("[data-name=title]");
|
||||
|
||||
function oncancel() {
|
||||
try {
|
||||
@@ -70,14 +74,14 @@ export class ShareCollectionScene {
|
||||
|
||||
function onsharebytoken() {
|
||||
let new_share_scene = new NewShareScene(user, password, collection.href, "token", function () {
|
||||
update_share_list(user, password, collection);
|
||||
update_share_list(user, password, collection, errorHandler);
|
||||
});
|
||||
push_scene(new_share_scene, false);
|
||||
}
|
||||
|
||||
function onsharebymap() {
|
||||
let new_share_scene = new NewShareScene(user, password, collection.href, "map", function () {
|
||||
update_share_list(user, password, collection);
|
||||
update_share_list(user, password, collection, errorHandler);
|
||||
});
|
||||
push_scene(new_share_scene, false);
|
||||
}
|
||||
@@ -118,7 +122,7 @@ export class ShareCollectionScene {
|
||||
}
|
||||
|
||||
title.textContent = collection.displayname || collection.href;
|
||||
update_share_list(user, password, collection);
|
||||
update_share_list(user, password, collection, errorHandler);
|
||||
};
|
||||
this.hide = function () {
|
||||
html_scene.classList.add("hidden");
|
||||
@@ -134,8 +138,9 @@ export class ShareCollectionScene {
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
* @param {Collection} collection
|
||||
* @param {ErrorHandler} errorHandler
|
||||
*/
|
||||
function update_share_list(user, password, collection) {
|
||||
function update_share_list(user, password, collection, errorHandler) {
|
||||
let share_rows = document.querySelectorAll(
|
||||
"[data-name=sharetokenrowtemplate], [data-name=sharemaprowtemplate]",
|
||||
);
|
||||
@@ -145,8 +150,12 @@ function update_share_list(user, password, collection) {
|
||||
}
|
||||
});
|
||||
|
||||
reload_sharing_list(user, password, collection, function (shares) {
|
||||
add_share_rows(user, password, collection, shares);
|
||||
reload_sharing_list(user, password, collection, function (shares, error) {
|
||||
if (error) {
|
||||
errorHandler.setError(error);
|
||||
} else {
|
||||
add_share_rows(user, password, collection, shares, errorHandler);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -158,9 +167,10 @@ function update_share_list(user, password, collection) {
|
||||
* @param {import('../api/api.js').Share} share
|
||||
* @param {HTMLElement} template
|
||||
* @param {string} delete_label
|
||||
* @param {function(string, string, string, function():void):void} delete_action
|
||||
* @param {function(string, string, string, function(?string):void):void} delete_action
|
||||
* @param {ErrorHandler} errorHandler
|
||||
*/
|
||||
function add_share_row_node(user, password, collection, share, template, delete_label, delete_action) {
|
||||
function add_share_row_node(user, password, collection, share, template, delete_label, delete_action, errorHandler) {
|
||||
let pathortoken = share["PathOrToken"] || "";
|
||||
let node = /** @type {HTMLElement} */ (template.cloneNode(true));
|
||||
node.classList.remove("hidden");
|
||||
@@ -192,8 +202,12 @@ function add_share_row_node(user, password, collection, share, template, delete_
|
||||
user,
|
||||
password,
|
||||
pathortoken,
|
||||
function () {
|
||||
update_share_list(user, password, collection);
|
||||
function (error) {
|
||||
if (error) {
|
||||
errorHandler.setError(error);
|
||||
} else {
|
||||
update_share_list(user, password, collection, errorHandler);
|
||||
}
|
||||
},
|
||||
);
|
||||
};
|
||||
@@ -206,8 +220,9 @@ function add_share_row_node(user, password, collection, share, template, delete_
|
||||
* @param {string} password
|
||||
* @param {Collection} collection
|
||||
* @param {Array<import('../api/api.js').Share>} shares
|
||||
* @param {ErrorHandler} errorHandler
|
||||
*/
|
||||
function add_share_rows(user, password, collection, shares) {
|
||||
function add_share_rows(user, password, collection, shares, errorHandler) {
|
||||
/** @type {HTMLElement} */ let token_template = document.querySelector("[data-name=sharetokenrowtemplate]");
|
||||
/** @type {HTMLElement} */ let map_template = document.querySelector("[data-name=sharemaprowtemplate]");
|
||||
shares.forEach(function (share) {
|
||||
@@ -218,9 +233,9 @@ function add_share_rows(user, password, collection, shares) {
|
||||
collection.href.includes(pathortoken)
|
||||
) {
|
||||
if (share["ShareType"] === "token") {
|
||||
add_share_row_node(user, password, collection, share, token_template, "share", delete_share_by_token);
|
||||
add_share_row_node(user, password, collection, share, token_template, "share", delete_share_by_token, errorHandler);
|
||||
} else if (share["ShareType"] === "map") {
|
||||
add_share_row_node(user, password, collection, share, map_template, "map", delete_share_by_map);
|
||||
add_share_row_node(user, password, collection, share, map_template, "map", delete_share_by_map, errorHandler);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user