Merge pull request #2025 from maxberger/master
Add support for managing incoming shares via map
This commit is contained in:
@@ -146,11 +146,12 @@ export class Share {
|
||||
* @param {function(Array<Share>, ?string):void} callback
|
||||
*/
|
||||
export function reload_sharing_list(user, password, collection, callback) {
|
||||
let body = collection ? { PathMapped: collection.href } : {};
|
||||
call_sharing_api(
|
||||
user,
|
||||
password,
|
||||
"all/list",
|
||||
{ PathMapped: collection.href },
|
||||
body,
|
||||
function (response) {
|
||||
let parsed = JSON.parse(response);
|
||||
let shares = (parsed["Content"] || []).map(data => new Share(data));
|
||||
@@ -411,3 +412,41 @@ export function update_share_by_map(
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a shared map entry as the recipient user.
|
||||
* Only sends fields the non-owner user is allowed to change: PathOrToken, EnabledByUser, HiddenByUser.
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
* @param {Share} share
|
||||
* @param {function(?string):void} callback
|
||||
*/
|
||||
export function update_incoming_share(
|
||||
user,
|
||||
password,
|
||||
share,
|
||||
callback,
|
||||
) {
|
||||
call_sharing_api(
|
||||
user,
|
||||
password,
|
||||
"map/update",
|
||||
{
|
||||
PathOrToken: share.PathOrToken,
|
||||
Enabled: share.EnabledByUser,
|
||||
Hidden: share.HiddenByUser,
|
||||
},
|
||||
function (response) {
|
||||
let json_response = JSON.parse(response);
|
||||
if (json_response["Status"] !== "success") {
|
||||
callback(json_response["Status"] || "Unknown error");
|
||||
} else {
|
||||
callback(null);
|
||||
}
|
||||
},
|
||||
null,
|
||||
function (error) {
|
||||
callback(error);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,8 +20,11 @@
|
||||
*/
|
||||
|
||||
import { LoginScene } from "./scenes/LoginScene.js";
|
||||
import { LoadingScene } from "./scenes/LoadingScene.js";
|
||||
import { push_scene } from "./scenes/scene_manager.js";
|
||||
|
||||
// Hide startup loading message
|
||||
document.getElementById("loadingscene").classList.add("hidden");
|
||||
push_scene(new LoginScene(), false);
|
||||
// This works because the LoadingScene is the one that is already active in index.html,
|
||||
// and all other scenes are hidden.
|
||||
new LoadingScene().hide();
|
||||
push_scene(new LoginScene());
|
||||
@@ -27,8 +27,9 @@ import { Collection, CollectionType } from "../models/collection.js";
|
||||
import { bytesToHumanReadable } from "../utils/misc.js";
|
||||
import { CreateEditCollectionScene } from "./CreateEditCollectionScene.js";
|
||||
import { DeleteCollectionScene } from "./DeleteCollectionScene.js";
|
||||
import { IncomingSharingScene } from "./IncomingSharingScene.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
import { Scene, is_current_scene, pop_scene, push_scene } from "./scene_manager.js";
|
||||
import { ShareCollectionScene, maybe_enable_sharing_options } from "./ShareCollectionScene.js";
|
||||
import { UploadCollectionScene } from "./UploadCollectionScene.js";
|
||||
|
||||
@@ -39,25 +40,25 @@ export class CollectionsScene {
|
||||
/**
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
* @param {Collection} collection The collection to show sharing options for.
|
||||
* @param {Collection} principal_collection The princial collection
|
||||
* @param {function(string):void} onerror Called when an error occurs, before the
|
||||
* scene is popped.
|
||||
*/
|
||||
constructor(user, password, collection, onerror) {
|
||||
constructor(user, password, principal_collection, onerror) {
|
||||
/** @type {HTMLElement} */ let html_scene = document.getElementById("collectionsscene");
|
||||
/** @type {HTMLElement} */ let template = html_scene.querySelector("[data-name=collectiontemplate]");
|
||||
/** @type {HTMLElement} */ let new_btn = html_scene.querySelector("[data-name=new]");
|
||||
/** @type {HTMLElement} */ let upload_btn = html_scene.querySelector("[data-name=upload]");
|
||||
/** @type {HTMLElement} */ let incomingshares_btn = html_scene.querySelector("[data-name=incomingshares]");
|
||||
|
||||
/** @type {?number} */ let scene_index = null;
|
||||
/** @type {?XMLHttpRequest} */ let collections_req = null;
|
||||
/** @type {?Array<Collection>} */ let collections = null;
|
||||
/** @type {?Array<Collection>} */ let child_collections = null;
|
||||
/** @type {Array<HTMLElement>} */ let nodes = [];
|
||||
|
||||
function onnew() {
|
||||
try {
|
||||
let create_collection_scene = new CreateEditCollectionScene(user, password, collection);
|
||||
push_scene(create_collection_scene, false);
|
||||
let create_collection_scene = new CreateEditCollectionScene(user, password, principal_collection);
|
||||
push_scene(create_collection_scene);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@@ -66,50 +67,72 @@ export class CollectionsScene {
|
||||
|
||||
function onupload() {
|
||||
try {
|
||||
let upload_scene = new UploadCollectionScene(user, password, collection);
|
||||
push_scene(upload_scene, false);
|
||||
let upload_scene = new UploadCollectionScene(user, password, principal_collection);
|
||||
push_scene(upload_scene);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
function onincomingshares() {
|
||||
try {
|
||||
let incoming_sharing_scene = new IncomingSharingScene(user, password);
|
||||
push_scene(incoming_sharing_scene);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Collection} collection
|
||||
*/
|
||||
function onedit(collection) {
|
||||
try {
|
||||
let edit_collection_scene = new CreateEditCollectionScene(user, password, collection);
|
||||
push_scene(edit_collection_scene, false);
|
||||
push_scene(edit_collection_scene);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Collection} collection
|
||||
*/
|
||||
function onshare(collection) {
|
||||
try {
|
||||
let share_collection_scene = new ShareCollectionScene(user, password, collection);
|
||||
push_scene(share_collection_scene, false);
|
||||
push_scene(share_collection_scene);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Collection} collection
|
||||
*/
|
||||
function ondelete(collection) {
|
||||
try {
|
||||
let delete_collection_scene = new DeleteCollectionScene(user, password, collection);
|
||||
push_scene(delete_collection_scene, false);
|
||||
push_scene(delete_collection_scene);
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {any[]} collections
|
||||
*/
|
||||
function show_collections(collections) {
|
||||
/** @type {HTMLElement} */ let navBar = document.querySelector("#logoutview");
|
||||
let heightOfNavBar = navBar.offsetHeight + "px";
|
||||
html_scene.style.marginTop = heightOfNavBar;
|
||||
html_scene.style.height = "calc(100vh - " + heightOfNavBar + ")";
|
||||
collections.forEach(function (collection) {
|
||||
collections.forEach(function (/** @type {Collection} */ collection) {
|
||||
/** @type {HTMLElement} */ let node = /** @type {HTMLElement} */(template.cloneNode(true));
|
||||
node.classList.remove("hidden");
|
||||
/** @type {HTMLElement} */ let title_form = node.querySelector("[data-name=title]");
|
||||
@@ -171,18 +194,18 @@ export class CollectionsScene {
|
||||
|
||||
function update() {
|
||||
let loading_scene = new LoadingScene();
|
||||
push_scene(loading_scene, false);
|
||||
collections_req = get_collections(user, password, collection, function (collections1, error) {
|
||||
if (scene_index === null) {
|
||||
push_scene(loading_scene);
|
||||
collections_req = get_collections(user, password, principal_collection, function (child_collections_, error) {
|
||||
if (!is_current_scene(loading_scene)) {
|
||||
return;
|
||||
}
|
||||
collections_req = null;
|
||||
if (error) {
|
||||
onerror(error);
|
||||
pop_scene(scene_index - 1);
|
||||
pop_scene();
|
||||
} else {
|
||||
collections = collections1;
|
||||
pop_scene(scene_index);
|
||||
child_collections = child_collections_;
|
||||
pop_scene();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -191,20 +214,21 @@ export class CollectionsScene {
|
||||
html_scene.classList.remove("hidden");
|
||||
new_btn.onclick = onnew;
|
||||
upload_btn.onclick = onupload;
|
||||
if (collections === null) {
|
||||
incomingshares_btn.onclick = onincomingshares;
|
||||
if (child_collections === null) {
|
||||
update();
|
||||
discover_server_features(user, password, maybe_enable_sharing_options);
|
||||
} else {
|
||||
// from update loading scene
|
||||
show_collections(collections);
|
||||
show_collections(child_collections);
|
||||
}
|
||||
};
|
||||
this.hide = function () {
|
||||
html_scene.classList.add("hidden");
|
||||
scene_index = scene_stack.length - 1;
|
||||
new_btn.onclick = null;
|
||||
upload_btn.onclick = null;
|
||||
collections = null;
|
||||
incomingshares_btn.onclick = null;
|
||||
child_collections = null;
|
||||
// remove collection
|
||||
nodes.forEach(function (node) {
|
||||
node.parentNode.removeChild(node);
|
||||
@@ -212,12 +236,11 @@ export class CollectionsScene {
|
||||
nodes = [];
|
||||
};
|
||||
this.release = function () {
|
||||
scene_index = null;
|
||||
if (collections_req !== null) {
|
||||
collections_req.abort();
|
||||
collections_req = null;
|
||||
}
|
||||
collections = null;
|
||||
child_collections = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ import { ErrorHandler } from "../utils/error.js";
|
||||
import { FormValidator, validate_color, validate_href } from "../utils/form_validator.js";
|
||||
import { cleanHREFinput, onCleanHREFinput, random_hex, random_uuid } from "../utils/misc.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
import { Scene, is_current_scene, pop_scene, pop_to_parent, push_scene } from "./scene_manager.js";
|
||||
|
||||
/**
|
||||
* @implements {Scene}
|
||||
@@ -55,7 +55,6 @@ export class CreateEditCollectionScene {
|
||||
/** @type {HTMLElement} */ let cancel_btn = html_scene.querySelector("[data-name=cancel]");
|
||||
|
||||
|
||||
/** @type {?number} */ let scene_index = null;
|
||||
/** @type {?XMLHttpRequest} */ let create_edit_req = null;
|
||||
/** @type {?HTMLSelectElement} */ let saved_type_form = null;
|
||||
|
||||
@@ -130,18 +129,18 @@ export class CreateEditCollectionScene {
|
||||
sane_color = COLOR_RE.exec(sane_color)[1];
|
||||
}
|
||||
let loading_scene = new LoadingScene();
|
||||
push_scene(loading_scene, false);
|
||||
push_scene(loading_scene);
|
||||
let collection = new Collection(href, type, displayname, description, sane_color, 0, 0, source);
|
||||
let callback = function (error1) {
|
||||
if (scene_index === null) {
|
||||
if (!is_current_scene(loading_scene)) {
|
||||
return;
|
||||
}
|
||||
create_edit_req = null;
|
||||
if (error1) {
|
||||
errorHandler.setError(error1);
|
||||
pop_scene(scene_index);
|
||||
pop_scene();
|
||||
} else {
|
||||
pop_scene(scene_index - 1);
|
||||
pop_to_parent();
|
||||
}
|
||||
};
|
||||
if (edit) {
|
||||
@@ -157,7 +156,7 @@ export class CreateEditCollectionScene {
|
||||
|
||||
function oncancel() {
|
||||
try {
|
||||
pop_scene(scene_index - 1);
|
||||
pop_scene();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@@ -179,7 +178,6 @@ export class CreateEditCollectionScene {
|
||||
|
||||
this.show = function () {
|
||||
this.release();
|
||||
scene_index = scene_stack.length - 1;
|
||||
// Clone type_form because it's impossible to hide options without removing them
|
||||
saved_type_form = type_form;
|
||||
type_form = /** @type {HTMLSelectElement} */ (type_form.cloneNode(true));
|
||||
@@ -205,7 +203,6 @@ export class CreateEditCollectionScene {
|
||||
cancel_btn.onclick = null;
|
||||
};
|
||||
this.release = function () {
|
||||
scene_index = null;
|
||||
if (create_edit_req !== null) {
|
||||
create_edit_req.abort();
|
||||
create_edit_req = null;
|
||||
|
||||
@@ -24,7 +24,7 @@ import { CollectionType } from "../models/collection.js";
|
||||
import { ErrorHandler } from "../utils/error.js";
|
||||
import { FormValidator, validate_href, validate_not_empty_or_equals } from "../utils/form_validator.js";
|
||||
import { onCleanHREFinput, random_uuid } from "../utils/misc.js";
|
||||
import { Scene, pop_scene, scene_stack } from "./scene_manager.js";
|
||||
import { Scene, is_current_scene, pop_scene } from "./scene_manager.js";
|
||||
|
||||
/**
|
||||
* @implements {Scene}
|
||||
@@ -35,10 +35,10 @@ export class CreateEditShareScene {
|
||||
* @param {string} password
|
||||
* @param {import("../models/collection.js").Collection} collection
|
||||
* @param {string} shareType
|
||||
* @param {function():void} onclose
|
||||
* @param {Share} [share] If provided, the scene will be in edit mode.
|
||||
*/
|
||||
constructor(user, password, collection, shareType, onclose, share) {
|
||||
constructor(user, password, collection, shareType, share) {
|
||||
let self = this;
|
||||
let edit = !!share;
|
||||
let pathMapped = collection.href;
|
||||
/** @type {HTMLElement} */ let html_scene = document.getElementById("newshare");
|
||||
@@ -76,14 +76,10 @@ export class CreateEditShareScene {
|
||||
color_override_input.disabled = !color_override_enabled.checked;
|
||||
};
|
||||
|
||||
/** @type {?number} */ let scene_index = null;
|
||||
|
||||
function oncancel() {
|
||||
try {
|
||||
if (scene_index !== null) {
|
||||
pop_scene(scene_index - 1);
|
||||
}
|
||||
if (onclose) onclose();
|
||||
pop_scene();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@@ -112,14 +108,13 @@ export class CreateEditShareScene {
|
||||
}
|
||||
|
||||
let callback = function (/** @type {string} */ error) {
|
||||
if (scene_index === null) {
|
||||
if (!is_current_scene(self)) {
|
||||
return;
|
||||
}
|
||||
if (error) {
|
||||
errorHandler.setError(error);
|
||||
} else {
|
||||
pop_scene(scene_index - 1);
|
||||
if (onclose) onclose();
|
||||
pop_scene();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -157,7 +152,6 @@ export class CreateEditShareScene {
|
||||
|
||||
this.show = function () {
|
||||
this.release();
|
||||
scene_index = scene_stack.length - 1;
|
||||
html_scene.classList.remove("hidden");
|
||||
cancel_btn.onclick = oncancel;
|
||||
form.onsubmit = onsubmit;
|
||||
@@ -232,7 +226,6 @@ export class CreateEditShareScene {
|
||||
};
|
||||
|
||||
this.release = function () {
|
||||
scene_index = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ import { Collection } from "../models/collection.js";
|
||||
import { ErrorHandler } from "../utils/error.js";
|
||||
import { FormValidator, validate_equals } from "../utils/form_validator.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
import { Scene, is_current_scene, pop_scene, pop_to_parent, push_scene } from "./scene_manager.js";
|
||||
|
||||
/**
|
||||
* @implements {Scene}
|
||||
@@ -49,7 +49,6 @@ export class DeleteCollectionScene {
|
||||
confirmation_txt.value = "";
|
||||
confirmation_txt.addEventListener("keydown", onkeydown);
|
||||
|
||||
/** @type {?number} */ let scene_index = null;
|
||||
/** @type {?XMLHttpRequest} */ let delete_req = null;
|
||||
|
||||
let errorHandler = new ErrorHandler(error_form);
|
||||
@@ -63,18 +62,17 @@ export class DeleteCollectionScene {
|
||||
}
|
||||
try {
|
||||
let loading_scene = new LoadingScene();
|
||||
push_scene(loading_scene, false);
|
||||
push_scene(loading_scene);
|
||||
delete_req = delete_collection(user, password, collection, function (error1) {
|
||||
if (scene_index === null) {
|
||||
if (!is_current_scene(loading_scene)) {
|
||||
return;
|
||||
}
|
||||
delete_req = null;
|
||||
delete_req = null;
|
||||
if (error1) {
|
||||
errorHandler.setError(error1);
|
||||
pop_scene(scene_index);
|
||||
pop_scene();
|
||||
} else {
|
||||
pop_scene(scene_index - 1);
|
||||
pop_to_parent();
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
@@ -85,7 +83,7 @@ export class DeleteCollectionScene {
|
||||
|
||||
function oncancel() {
|
||||
try {
|
||||
pop_scene(scene_index - 1);
|
||||
pop_scene();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@@ -101,7 +99,6 @@ export class DeleteCollectionScene {
|
||||
|
||||
this.show = function () {
|
||||
this.release();
|
||||
scene_index = scene_stack.length - 1;
|
||||
html_scene.classList.remove("hidden");
|
||||
title_form.textContent = collection.displayname || collection.href;
|
||||
delete_btn.onclick = ondelete;
|
||||
@@ -114,7 +111,6 @@ export class DeleteCollectionScene {
|
||||
delete_btn.onclick = null;
|
||||
};
|
||||
this.release = function () {
|
||||
scene_index = null;
|
||||
if (delete_req !== null) {
|
||||
delete_req.abort();
|
||||
delete_req = null;
|
||||
|
||||
188
radicale/web/internal_data/js/scenes/IncomingSharingScene.js
Normal file
188
radicale/web/internal_data/js/scenes/IncomingSharingScene.js
Normal file
@@ -0,0 +1,188 @@
|
||||
/**
|
||||
* This file is part of Radicale Server - Calendar Server
|
||||
* Copyright © 2017-2024 Unrud <unrud@outlook.com>
|
||||
* Copyright © 2023-2024 Matthew Hana <matthew.hana@gmail.com>
|
||||
* Copyright © 2024-2025 Peter Bieringer <pb@bieringer.de>
|
||||
* Copyright © 2026-2026 Max Berger <max@berger.name>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Share, reload_sharing_list, update_incoming_share } from "../api/sharing.js";
|
||||
import { ErrorHandler } from "../utils/error.js";
|
||||
import { displayPermissions } from "../utils/permissions.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { Scene, is_current_scene, pop_scene, push_scene } from "./scene_manager.js";
|
||||
|
||||
/**
|
||||
* @implements {Scene}
|
||||
*/
|
||||
export class IncomingSharingScene {
|
||||
/**
|
||||
* @param {string} user
|
||||
* @param {string} password
|
||||
*/
|
||||
constructor(user, password) {
|
||||
/** @type {HTMLElement} */ let html_scene = document.getElementById("incomingsharingscene");
|
||||
/** @type {HTMLElement} */ let cancel_btn = html_scene.querySelector("[data-name=cancel]");
|
||||
/** @type {HTMLElement} */ let error_element = html_scene.querySelector("[data-name=error]");
|
||||
/** @type {HTMLElement} */ let tbody = html_scene.querySelector("tbody[data-name=incomingsharesbody]");
|
||||
/** @type {HTMLElement} */ let template = tbody.querySelector("[data-name=incomingsharerowtemplate]");
|
||||
/** @type {HTMLElement} */ let table = html_scene.querySelector("table");
|
||||
/** @type {HTMLElement} */ let noshares_message = html_scene.querySelector("[data-name=nosharesmessage]");
|
||||
|
||||
let error_handler = new ErrorHandler(error_element);
|
||||
|
||||
/** @type {Array<HTMLElement>} */ let nodes = [];
|
||||
/** @type {?Array<Object>} */ let shares_cache = null;
|
||||
|
||||
function on_cancel() {
|
||||
pop_scene();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Share} share
|
||||
* @param {HTMLElement} node
|
||||
*/
|
||||
function toggle_share(share, node) {
|
||||
let enabled_cb = /** @type {HTMLInputElement} */ (node.querySelector("[data-name=enabled]"));
|
||||
let shown_cb = /** @type {HTMLInputElement} */ (node.querySelector("[data-name=shown]"));
|
||||
|
||||
// disable checkboxes while updating
|
||||
enabled_cb.disabled = true;
|
||||
shown_cb.disabled = true;
|
||||
|
||||
let old_enabled = share.EnabledByUser;
|
||||
let old_hidden = share.HiddenByUser;
|
||||
|
||||
share.EnabledByUser = enabled_cb.checked;
|
||||
share.HiddenByUser = !shown_cb.checked;
|
||||
error_handler.clearError();
|
||||
|
||||
update_incoming_share(user, password, share, function (error) {
|
||||
enabled_cb.disabled = false;
|
||||
shown_cb.disabled = !share.EnabledByUser;
|
||||
|
||||
if (error) {
|
||||
error_handler.setError(error);
|
||||
enabled_cb.checked = old_enabled;
|
||||
shown_cb.checked = !old_hidden;
|
||||
shown_cb.disabled = !old_enabled;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {Share[]} shares
|
||||
*/
|
||||
function render_shares(shares) {
|
||||
// clear old nodes
|
||||
nodes.forEach(function (node) {
|
||||
node.parentNode.removeChild(node);
|
||||
});
|
||||
nodes = [];
|
||||
|
||||
let prefix = "/" + user + "/";
|
||||
let filtered_shares = shares.filter(share => share.ShareType === "map" && share.PathOrToken.startsWith(prefix));
|
||||
|
||||
if (filtered_shares.length === 0) {
|
||||
table.classList.add("hidden");
|
||||
noshares_message.classList.remove("hidden");
|
||||
} else {
|
||||
table.classList.remove("hidden");
|
||||
noshares_message.classList.add("hidden");
|
||||
}
|
||||
|
||||
filtered_shares.forEach(function (share) {
|
||||
let node = /** @type {HTMLElement} */(template.cloneNode(true));
|
||||
node.classList.remove("hidden");
|
||||
|
||||
let pathortoken = /** @type {HTMLInputElement} */ (node.querySelector("[data-name=pathortoken]"));
|
||||
let owner_td = node.querySelector("[data-name=owner]");
|
||||
let permissions_td = /** @type {HTMLElement} */ (node.querySelector("[data-name=permissions]"));
|
||||
let enabled_cb = /** @type {HTMLInputElement} */ (node.querySelector("[data-name=enabled]"));
|
||||
let shown_cb = /** @type {HTMLInputElement} */ (node.querySelector("[data-name=shown]"));
|
||||
|
||||
let displayPath = share.PathOrToken.substring(prefix.length);
|
||||
if (displayPath.endsWith("/")) {
|
||||
displayPath = displayPath.substring(0, displayPath.length - 1);
|
||||
}
|
||||
|
||||
pathortoken.value = displayPath;
|
||||
owner_td.textContent = share.Owner;
|
||||
displayPermissions(share.Permissions, permissions_td);
|
||||
|
||||
let enabled = share.EnabledByUser !== null ? share.EnabledByUser : true;
|
||||
let shown = share.HiddenByUser !== null ? !share.HiddenByUser : true;
|
||||
|
||||
enabled_cb.checked = enabled;
|
||||
shown_cb.checked = shown;
|
||||
shown_cb.disabled = !enabled;
|
||||
|
||||
enabled_cb.onchange = function () { toggle_share(share, node); };
|
||||
shown_cb.onchange = function () { toggle_share(share, node); };
|
||||
|
||||
nodes.push(node);
|
||||
tbody.appendChild(node);
|
||||
});
|
||||
}
|
||||
|
||||
function update() {
|
||||
let loading_scene = new LoadingScene();
|
||||
push_scene(loading_scene);
|
||||
|
||||
error_handler.clearError();
|
||||
|
||||
reload_sharing_list(user, password, null, function (shares, error) {
|
||||
if (!is_current_scene(loading_scene)) {
|
||||
return;
|
||||
}
|
||||
if (error) {
|
||||
error_handler.setError(error);
|
||||
pop_scene();
|
||||
} else {
|
||||
shares_cache = shares;
|
||||
pop_scene();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
this.show = function () {
|
||||
html_scene.classList.remove("hidden");
|
||||
cancel_btn.onclick = on_cancel;
|
||||
if (shares_cache === null) {
|
||||
update();
|
||||
} else {
|
||||
render_shares(shares_cache);
|
||||
}
|
||||
};
|
||||
|
||||
this.hide = function () {
|
||||
html_scene.classList.add("hidden");
|
||||
cancel_btn.onclick = null;
|
||||
error_handler.clearError();
|
||||
};
|
||||
|
||||
this.release = function () {
|
||||
error_handler.clearError();
|
||||
nodes.forEach(function (node) {
|
||||
if (node.parentNode) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
});
|
||||
nodes = [];
|
||||
shares_cache = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -26,13 +26,13 @@ import { Scene } from "./scene_manager.js";
|
||||
*/
|
||||
export class LoadingScene {
|
||||
constructor() {
|
||||
let html_scene = document.getElementById("loadingscene");
|
||||
this.show = function () {
|
||||
html_scene.classList.remove("hidden");
|
||||
};
|
||||
this.hide = function () {
|
||||
html_scene.classList.add("hidden");
|
||||
};
|
||||
this.release = function () { };
|
||||
this.html_scene = document.getElementById("loadingscene");
|
||||
}
|
||||
show() {
|
||||
this.html_scene.classList.remove("hidden");
|
||||
}
|
||||
hide() {
|
||||
this.html_scene.classList.add("hidden");
|
||||
}
|
||||
release() { }
|
||||
}
|
||||
@@ -20,11 +20,11 @@
|
||||
*/
|
||||
|
||||
import { get_principal } from "../api/api.js";
|
||||
import { CollectionsScene } from "./CollectionsScene.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
import { ErrorHandler } from "../utils/error.js";
|
||||
import { FormValidator, validate_non_empty } from "../utils/form_validator.js";
|
||||
import { CollectionsScene } from "./CollectionsScene.js";
|
||||
import { LoadingScene } from "./LoadingScene.js";
|
||||
import { Scene, is_current_scene, pop_scene, pop_to_root, push_scene, replace_scene } from "./scene_manager.js";
|
||||
/**
|
||||
* @constructor
|
||||
* @implements {Scene}
|
||||
@@ -41,7 +41,6 @@ export class LoginScene {
|
||||
/** @type {HTMLElement} */ let logout_btn = logout_view.querySelector("[data-name=logout]");
|
||||
/** @type {HTMLElement} */ let refresh_btn = logout_view.querySelector("[data-name=refresh]");
|
||||
|
||||
/** @type {?number} */ let scene_index = null;
|
||||
let user = "";
|
||||
/** @type {?XMLHttpRequest} */ let principal_req = null;
|
||||
let errorHandler = new ErrorHandler(error_form);
|
||||
@@ -71,25 +70,25 @@ export class LoginScene {
|
||||
logout_user_form.textContent = user + "'s Collections";
|
||||
// Fetch principal
|
||||
let loading_scene = new LoadingScene();
|
||||
push_scene(loading_scene, false);
|
||||
principal_req = get_principal(user, password, function (collection, error1) {
|
||||
if (scene_index === null) {
|
||||
push_scene(loading_scene);
|
||||
principal_req = get_principal(user, password, function (principal_collection, error1) {
|
||||
if (!is_current_scene(loading_scene)) {
|
||||
return;
|
||||
}
|
||||
principal_req = null;
|
||||
if (error1) {
|
||||
errorHandler.setError(error1);
|
||||
pop_scene(scene_index);
|
||||
pop_scene();
|
||||
} else {
|
||||
// show collections
|
||||
let saved_user = user;
|
||||
user = "";
|
||||
let collections_scene = new CollectionsScene(
|
||||
saved_user, password, collection, function (error1) {
|
||||
saved_user, password, principal_collection, function (error1) {
|
||||
errorHandler.setError(error1);
|
||||
user = saved_user;
|
||||
});
|
||||
push_scene(collections_scene, true);
|
||||
replace_scene(collections_scene);
|
||||
}
|
||||
});
|
||||
} catch (err) {
|
||||
@@ -98,18 +97,15 @@ export class LoginScene {
|
||||
return false;
|
||||
}
|
||||
|
||||
function onlogout() {
|
||||
let onlogout = function () {
|
||||
try {
|
||||
if (scene_index === null) {
|
||||
return false;
|
||||
}
|
||||
user = "";
|
||||
pop_scene(scene_index);
|
||||
pop_to_root();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
function remove_logout() {
|
||||
@@ -120,10 +116,10 @@ export class LoginScene {
|
||||
}
|
||||
|
||||
function refresh() {
|
||||
//The easiest way to refresh is to push a LoadingScene onto the stack and then pop it
|
||||
//forcing the scene below it, the Collections Scene to refresh itself.
|
||||
push_scene(new LoadingScene(), false);
|
||||
pop_scene(scene_stack.length - 2);
|
||||
// The easiest way to refresh is to push a LoadingScene onto the stack and then pop it
|
||||
// forcing the scene below it, the Collections Scene to refresh itself.
|
||||
push_scene(new LoadingScene());
|
||||
pop_scene();
|
||||
}
|
||||
|
||||
this.show = function () {
|
||||
@@ -131,7 +127,6 @@ export class LoginScene {
|
||||
fill_form();
|
||||
form.onsubmit = onlogin;
|
||||
html_scene.classList.remove("hidden");
|
||||
scene_index = scene_stack.length - 1;
|
||||
user_form.focus();
|
||||
};
|
||||
this.hide = function () {
|
||||
@@ -140,7 +135,6 @@ export class LoginScene {
|
||||
form.onsubmit = null;
|
||||
};
|
||||
this.release = function () {
|
||||
scene_index = null;
|
||||
// cancel pending requests
|
||||
if (principal_req !== null) {
|
||||
principal_req.abort();
|
||||
|
||||
@@ -27,8 +27,9 @@ import {
|
||||
} from "../api/sharing.js";
|
||||
import { Collection } from "../models/collection.js";
|
||||
import { ErrorHandler } from "../utils/error.js";
|
||||
import { displayPermissions } from "../utils/permissions.js";
|
||||
import { CreateEditShareScene } from "./CreateEditShareScene.js";
|
||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.js";
|
||||
import { Scene, pop_scene, push_scene } from "./scene_manager.js";
|
||||
|
||||
/**
|
||||
* @implements {Scene}
|
||||
@@ -40,7 +41,6 @@ export class ShareCollectionScene {
|
||||
* @param {Collection} collection The collection on which to edit sharing setting. Must exist.
|
||||
*/
|
||||
constructor(user, password, collection) {
|
||||
/** @type {?number} */ let scene_index = null;
|
||||
|
||||
let html_scene = document.getElementById("sharecollectionscene");
|
||||
|
||||
@@ -65,7 +65,7 @@ export class ShareCollectionScene {
|
||||
|
||||
function oncancel() {
|
||||
try {
|
||||
pop_scene(scene_index - 1);
|
||||
pop_scene();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@@ -73,22 +73,17 @@ export class ShareCollectionScene {
|
||||
}
|
||||
|
||||
function onsharebytoken() {
|
||||
let create_edit_share_scene = new CreateEditShareScene(user, password, collection, "token", function () {
|
||||
update_share_list(user, password, collection, errorHandler);
|
||||
});
|
||||
push_scene(create_edit_share_scene, false);
|
||||
let create_edit_share_scene = new CreateEditShareScene(user, password, collection, "token");
|
||||
push_scene(create_edit_share_scene);
|
||||
}
|
||||
|
||||
function onsharebymap() {
|
||||
let create_edit_share_scene = new CreateEditShareScene(user, password, collection, "map", function () {
|
||||
update_share_list(user, password, collection, errorHandler);
|
||||
});
|
||||
push_scene(create_edit_share_scene, false);
|
||||
let create_edit_share_scene = new CreateEditShareScene(user, password, collection, "map");
|
||||
push_scene(create_edit_share_scene);
|
||||
}
|
||||
|
||||
this.show = function () {
|
||||
this.release();
|
||||
scene_index = scene_stack.length - 1;
|
||||
html_scene.classList.remove("hidden");
|
||||
cancel_btn.onclick = oncancel;
|
||||
if (server_features.sharing && server_features.sharing.PermittedCreateCollectionByToken) {
|
||||
@@ -129,7 +124,6 @@ export class ShareCollectionScene {
|
||||
cancel_btn.onclick = null;
|
||||
};
|
||||
this.release = function () {
|
||||
scene_index = null;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -181,24 +175,12 @@ function add_share_row_node(user, password, collection, share, template, delete_
|
||||
}
|
||||
|
||||
let permissions = (share["Permissions"] || "").toLowerCase();
|
||||
if (permissions === "rw") {
|
||||
node
|
||||
.querySelector("[data-name=ro]")
|
||||
.parentNode.removeChild(node.querySelector("[data-name=ro]"));
|
||||
} else if (permissions === "r") {
|
||||
node
|
||||
.querySelector("[data-name=rw]")
|
||||
.parentNode.removeChild(node.querySelector("[data-name=rw]"));
|
||||
} else {
|
||||
console.warn("Unknown permissions", permissions);
|
||||
}
|
||||
displayPermissions(permissions, node);
|
||||
|
||||
/** @type {HTMLElement} */ let edit_btn = node.querySelector("[data-name=edit]");
|
||||
edit_btn.onclick = function () {
|
||||
let create_edit_share_scene = new CreateEditShareScene(user, password, collection, share.ShareType, function () {
|
||||
update_share_list(user, password, collection, errorHandler);
|
||||
}, share);
|
||||
push_scene(create_edit_share_scene, false);
|
||||
let create_edit_share_scene = new CreateEditShareScene(user, password, collection, share.ShareType, share);
|
||||
push_scene(create_edit_share_scene);
|
||||
};
|
||||
|
||||
/** @type {HTMLElement} */ let delete_btn = node.querySelector("[data-name=delete]");
|
||||
|
||||
@@ -24,7 +24,7 @@ import { Collection } from "../models/collection.js";
|
||||
import { ErrorHandler } from "../utils/error.js";
|
||||
import { FormValidator, validate_files, validate_href } from "../utils/form_validator.js";
|
||||
import { cleanHREFinput, onCleanHREFinput, random_uuid } from "../utils/misc.js";
|
||||
import { Scene, pop_scene, scene_stack } from "./scene_manager.js";
|
||||
import { Scene, pop_scene } from "./scene_manager.js";
|
||||
|
||||
/**
|
||||
* @implements {Scene}
|
||||
@@ -62,7 +62,6 @@ export class UploadCollectionScene {
|
||||
validator.addValidator(href_form, validate_href(href_form, "HREF"));
|
||||
validator.addValidator(uploadfile_form, validate_files(uploadfile_form, "file"));
|
||||
|
||||
/** @type {?number} */ let scene_index = null;
|
||||
/** @type {?XMLHttpRequest} */ let upload_req = null;
|
||||
/** @type {Array<string>} */ let results = [];
|
||||
/** @type {?Array<HTMLElement>} */ let nodes = null;
|
||||
@@ -128,7 +127,7 @@ export class UploadCollectionScene {
|
||||
|
||||
function onclose() {
|
||||
try {
|
||||
pop_scene(scene_index - 1);
|
||||
pop_scene();
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
}
|
||||
@@ -187,7 +186,6 @@ export class UploadCollectionScene {
|
||||
}
|
||||
|
||||
this.show = function () {
|
||||
scene_index = scene_stack.length - 1;
|
||||
html_scene.classList.remove("hidden");
|
||||
close_btn.onclick = onclose;
|
||||
};
|
||||
@@ -216,7 +214,6 @@ export class UploadCollectionScene {
|
||||
nodes = null;
|
||||
};
|
||||
this.release = function () {
|
||||
scene_index = null;
|
||||
if (upload_req !== null) {
|
||||
upload_req.abort();
|
||||
upload_req = null;
|
||||
|
||||
@@ -42,44 +42,89 @@ export class Scene {
|
||||
/**
|
||||
* @type {Array<Scene>}
|
||||
*/
|
||||
export let scene_stack = [];
|
||||
let scene_stack = [];
|
||||
|
||||
/**
|
||||
* Push scene onto stack.
|
||||
* @param {Scene} scene
|
||||
* @param {boolean} replace Replace the scene on top of the stack.
|
||||
*/
|
||||
export function push_scene(scene, replace) {
|
||||
export function push_scene(scene) {
|
||||
if (scene_stack.length >= 1) {
|
||||
scene_stack[scene_stack.length - 1].hide();
|
||||
if (replace) {
|
||||
scene_stack.pop().release();
|
||||
}
|
||||
}
|
||||
scene_stack.push(scene);
|
||||
scene.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove scenes from stack.
|
||||
* @param {number} index New top of stack
|
||||
* Replace the current scene with a new one.
|
||||
* @param {Scene} scene
|
||||
*/
|
||||
export function pop_scene(index) {
|
||||
if (scene_stack.length - 1 <= index) {
|
||||
export function replace_scene(scene) {
|
||||
if (scene_stack.length >= 1) {
|
||||
scene_stack[scene_stack.length - 1].hide();
|
||||
scene_stack.pop().release();
|
||||
}
|
||||
scene_stack.push(scene);
|
||||
scene.show();
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the current scene from the stack.
|
||||
*/
|
||||
export function pop_scene() {
|
||||
if (scene_stack.length === 0) {
|
||||
return;
|
||||
}
|
||||
scene_stack[scene_stack.length - 1].hide();
|
||||
while (scene_stack.length - 1 > index) {
|
||||
let old_length = scene_stack.length;
|
||||
scene_stack.pop().release();
|
||||
if (scene_stack.length >= 1) {
|
||||
scene_stack[scene_stack.length - 1].show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop the current scene and the one below it.
|
||||
* Useful for returning to the parent of the caller.
|
||||
*/
|
||||
export function pop_to_parent() {
|
||||
if (scene_stack.length === 0) {
|
||||
return;
|
||||
}
|
||||
scene_stack[scene_stack.length - 1].hide();
|
||||
scene_stack.pop().release();
|
||||
if (scene_stack.length >= 1) {
|
||||
scene_stack.pop().release();
|
||||
if (old_length - 1 === index + 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (scene_stack.length >= 1) {
|
||||
let scene = scene_stack[scene_stack.length - 1];
|
||||
scene.show();
|
||||
} else {
|
||||
throw "Scene stack is empty";
|
||||
scene_stack[scene_stack.length - 1].show();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Pop all scenes until only the root scene remains.
|
||||
* If the stack is empty, nothing happens.
|
||||
*/
|
||||
export function pop_to_root() {
|
||||
if (scene_stack.length === 0) {
|
||||
return;
|
||||
}
|
||||
// Pop all scenes until only the first one remains
|
||||
while (scene_stack.length > 1) {
|
||||
scene_stack[scene_stack.length - 1].hide();
|
||||
scene_stack.pop().release();
|
||||
}
|
||||
// The root scene is now at the top (index 0) and should be shown
|
||||
if (scene_stack.length === 1) {
|
||||
scene_stack[0].show(); // Ensure the root scene is visible
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the given scene is the current top scene.
|
||||
* @param {Scene} scene
|
||||
* @returns {boolean}
|
||||
*/
|
||||
export function is_current_scene(scene) {
|
||||
return scene_stack.length > 0 && scene_stack[scene_stack.length - 1] === scene;
|
||||
}
|
||||
38
radicale/web/internal_data/js/utils/permissions.js
Normal file
38
radicale/web/internal_data/js/utils/permissions.js
Normal file
@@ -0,0 +1,38 @@
|
||||
/**
|
||||
* This file is part of Radicale Server - Calendar Server
|
||||
* Copyright © 2026-2026 Max Berger <max@berger.name>
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @param {string} permissions
|
||||
* @param {HTMLElement} node
|
||||
*/
|
||||
export function displayPermissions(permissions, node) {
|
||||
permissions = (permissions || "").toLowerCase();
|
||||
if (permissions === "rw") {
|
||||
const roElement = node.querySelector("[data-name=ro]");
|
||||
if (roElement) {
|
||||
roElement.parentNode.removeChild(roElement);
|
||||
}
|
||||
} else if (permissions === "r") {
|
||||
const rwElement = node.querySelector("[data-name=rw]");
|
||||
if (rwElement) {
|
||||
rwElement.parentNode.removeChild(rwElement);
|
||||
}
|
||||
} else {
|
||||
console.warn("Unknown permissions", permissions);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user