Add ErrorHandler to share behavior
This commit is contained in:
@@ -200,6 +200,7 @@
|
|||||||
<form>
|
<form>
|
||||||
<button type="button" class="green" data-name="cancel">Close</button>
|
<button type="button" class="green" data-name="cancel">Close</button>
|
||||||
</form>
|
</form>
|
||||||
|
<span class="error hidden" data-name="error"></span>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="newshare" class="container hidden">
|
<section id="newshare" class="container hidden">
|
||||||
@@ -233,6 +234,7 @@
|
|||||||
<button type="submit" class="green" data-name="submit">Create</button>
|
<button type="submit" class="green" data-name="submit">Create</button>
|
||||||
<button type="button" class="red" data-name="cancel">Cancel</button>
|
<button type="button" class="red" data-name="cancel">Cancel</button>
|
||||||
</form>
|
</form>
|
||||||
|
<span class="error hidden" data-name="error"></span>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<section id="createcollectionscene" class="container hidden">
|
<section id="createcollectionscene" class="container hidden">
|
||||||
|
|||||||
@@ -464,7 +464,7 @@ export function discover_server_features(user, password, callback) {
|
|||||||
* @param {string} user
|
* @param {string} user
|
||||||
* @param {string} password
|
* @param {string} password
|
||||||
* @param {Collection} collection
|
* @param {Collection} collection
|
||||||
* @param {function(Array<Share>):void} callback
|
* @param {function(Array<Share>, ?string):void} callback
|
||||||
*/
|
*/
|
||||||
export function reload_sharing_list(user, password, collection, callback) {
|
export function reload_sharing_list(user, password, collection, callback) {
|
||||||
call_sharing_api(
|
call_sharing_api(
|
||||||
@@ -474,8 +474,12 @@ export function reload_sharing_list(user, password, collection, callback) {
|
|||||||
{ PathMapped: collection.href },
|
{ PathMapped: collection.href },
|
||||||
function (response) {
|
function (response) {
|
||||||
let parsed = JSON.parse(response);
|
let parsed = JSON.parse(response);
|
||||||
callback(parsed["Content"] || []);
|
callback(parsed["Content"] || [], null);
|
||||||
},
|
},
|
||||||
|
null, // on_not_found
|
||||||
|
function (error) {
|
||||||
|
callback([], error);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -487,7 +491,7 @@ export function reload_sharing_list(user, password, collection, callback) {
|
|||||||
* @param {boolean} enabled
|
* @param {boolean} enabled
|
||||||
* @param {boolean} hidden
|
* @param {boolean} hidden
|
||||||
* @param {string} properties
|
* @param {string} properties
|
||||||
* @param {function():void} callback
|
* @param {function(?string):void} callback
|
||||||
*/
|
*/
|
||||||
export function add_share_by_token(
|
export function add_share_by_token(
|
||||||
user,
|
user,
|
||||||
@@ -513,11 +517,15 @@ export function add_share_by_token(
|
|||||||
function (response) {
|
function (response) {
|
||||||
let json_response = JSON.parse(response);
|
let json_response = JSON.parse(response);
|
||||||
if (json_response["Status"] !== "success") {
|
if (json_response["Status"] !== "success") {
|
||||||
console.error("Failed to create share token: " + (json_response["Status"] || "Unknown error"));
|
callback(json_response["Status"] || "Unknown error");
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
null,
|
||||||
|
function (error) {
|
||||||
|
callback(error);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -531,7 +539,7 @@ export function add_share_by_token(
|
|||||||
* @param {string} properties
|
* @param {string} properties
|
||||||
* @param {string} share_user
|
* @param {string} share_user
|
||||||
* @param {string} href
|
* @param {string} href
|
||||||
* @param {function():void} callback
|
* @param {function(?string):void} callback
|
||||||
*/
|
*/
|
||||||
export function add_share_by_map(
|
export function add_share_by_map(
|
||||||
user,
|
user,
|
||||||
@@ -561,11 +569,15 @@ export function add_share_by_map(
|
|||||||
function (response) {
|
function (response) {
|
||||||
let json_response = JSON.parse(response);
|
let json_response = JSON.parse(response);
|
||||||
if (json_response["Status"] !== "success") {
|
if (json_response["Status"] !== "success") {
|
||||||
console.error("Failed to create share map: " + (json_response["Status"] || "Unknown error"));
|
callback(json_response["Status"] || "Unknown error");
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
null,
|
||||||
|
function (error) {
|
||||||
|
callback(error);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -573,7 +585,7 @@ export function add_share_by_map(
|
|||||||
* @param {string} user
|
* @param {string} user
|
||||||
* @param {string} password
|
* @param {string} password
|
||||||
* @param {string} token
|
* @param {string} token
|
||||||
* @param {function():void} callback
|
* @param {function(?string):void} callback
|
||||||
*/
|
*/
|
||||||
export function delete_share_by_token(
|
export function delete_share_by_token(
|
||||||
user,
|
user,
|
||||||
@@ -589,11 +601,15 @@ export function delete_share_by_token(
|
|||||||
function (response) {
|
function (response) {
|
||||||
let json_response = JSON.parse(response);
|
let json_response = JSON.parse(response);
|
||||||
if (json_response["Status"] !== "success") {
|
if (json_response["Status"] !== "success") {
|
||||||
console.error("Failed to create delete token " + token + ": " + (json_response["Status"] || "Unknown error"));
|
callback(json_response["Status"] || "Unknown error");
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
null,
|
||||||
|
function (error) {
|
||||||
|
callback(error);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -601,7 +617,7 @@ export function delete_share_by_token(
|
|||||||
* @param {string} user
|
* @param {string} user
|
||||||
* @param {string} password
|
* @param {string} password
|
||||||
* @param {string} pathortoken
|
* @param {string} pathortoken
|
||||||
* @param {function():void} callback
|
* @param {function(?string):void} callback
|
||||||
*/
|
*/
|
||||||
export function delete_share_by_map(
|
export function delete_share_by_map(
|
||||||
user,
|
user,
|
||||||
@@ -617,10 +633,14 @@ export function delete_share_by_map(
|
|||||||
function (response) {
|
function (response) {
|
||||||
let json_response = JSON.parse(response);
|
let json_response = JSON.parse(response);
|
||||||
if (json_response["Status"] !== "success") {
|
if (json_response["Status"] !== "success") {
|
||||||
console.error("Failed to delete map " + pathortoken + ": " + (json_response["Status"] || "Unknown error"));
|
callback(json_response["Status"] || "Unknown error");
|
||||||
} else {
|
} else {
|
||||||
callback();
|
callback(null);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
null,
|
||||||
|
function (error) {
|
||||||
|
callback(error);
|
||||||
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { add_share_by_map, add_share_by_token } from "../api/api.js";
|
import { add_share_by_map, add_share_by_token } from "../api/api.js";
|
||||||
import { onCleanHREFinput } from "../utils/misc.js";
|
import { ErrorHandler } from "../utils/error.js";
|
||||||
|
import { FormValidator, validate_href, validate_non_empty } 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, pop_scene, scene_stack } from "./scene_manager.js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -45,8 +47,15 @@ export class NewShareScene {
|
|||||||
let permissions_ro_radio = /** @type {HTMLInputElement} */ (document.getElementById("newshare_attr_permissions_ro"));
|
let permissions_ro_radio = /** @type {HTMLInputElement} */ (document.getElementById("newshare_attr_permissions_ro"));
|
||||||
let permissions_rw_radio = /** @type {HTMLInputElement} */ (document.getElementById("newshare_attr_permissions_rw"));
|
let permissions_rw_radio = /** @type {HTMLInputElement} */ (document.getElementById("newshare_attr_permissions_rw"));
|
||||||
/** @type {HTMLInputElement} */ let properties_input = html_scene.querySelector("[data-name=properties]");
|
/** @type {HTMLInputElement} */ let properties_input = html_scene.querySelector("[data-name=properties]");
|
||||||
|
/** @type {HTMLElement} */ let error_form = html_scene.querySelector("[data-name=error]");
|
||||||
/** @type {HTMLElement} */ let cancel_btn = html_scene.querySelector("[data-name=cancel]");
|
/** @type {HTMLElement} */ let cancel_btn = html_scene.querySelector("[data-name=cancel]");
|
||||||
|
|
||||||
|
let errorHandler = new ErrorHandler(error_form);
|
||||||
|
let map_validator = new FormValidator(errorHandler);
|
||||||
|
|
||||||
|
map_validator.addValidator(shareuser_input, validate_non_empty(shareuser_input, "Share User"));
|
||||||
|
map_validator.addValidator(sharehref_input, validate_href(sharehref_input, "Share Href"));
|
||||||
|
|
||||||
sharehref_input.addEventListener("input", onCleanHREFinput);
|
sharehref_input.addEventListener("input", onCleanHREFinput);
|
||||||
|
|
||||||
/** @type {?number} */ let scene_index = null;
|
/** @type {?number} */ let scene_index = null;
|
||||||
@@ -65,16 +74,26 @@ export class NewShareScene {
|
|||||||
|
|
||||||
function onsubmit() {
|
function onsubmit() {
|
||||||
try {
|
try {
|
||||||
|
if (shareType === "map") {
|
||||||
|
if (!map_validator.validate()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
let enabled = enabled_checkbox.checked;
|
let enabled = enabled_checkbox.checked;
|
||||||
let hidden = hidden_checkbox.checked;
|
let hidden = hidden_checkbox.checked;
|
||||||
let permissions = permissions_rw_radio.checked ? "rw" : "r";
|
let permissions = permissions_rw_radio.checked ? "rw" : "r";
|
||||||
let properties = properties_input.value;
|
let properties = properties_input.value;
|
||||||
|
|
||||||
let callback = function () {
|
let callback = function (/** @type {string} */ error) {
|
||||||
if (scene_index !== null) {
|
if (scene_index === null) {
|
||||||
pop_scene(scene_index - 1);
|
return;
|
||||||
|
}
|
||||||
|
if (error) {
|
||||||
|
errorHandler.setError(error);
|
||||||
|
} else {
|
||||||
|
pop_scene(scene_index - 1);
|
||||||
|
if (onclose) onclose();
|
||||||
}
|
}
|
||||||
if (onclose) onclose();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (shareType === "map") {
|
if (shareType === "map") {
|
||||||
@@ -97,19 +116,22 @@ export class NewShareScene {
|
|||||||
cancel_btn.onclick = oncancel;
|
cancel_btn.onclick = oncancel;
|
||||||
form.onsubmit = onsubmit;
|
form.onsubmit = onsubmit;
|
||||||
|
|
||||||
if (shareType === "map") {
|
|
||||||
sharemapfields.classList.remove("hidden");
|
|
||||||
} else {
|
|
||||||
sharemapfields.classList.add("hidden");
|
|
||||||
}
|
|
||||||
|
|
||||||
shareuser_input.value = "";
|
shareuser_input.value = "";
|
||||||
sharehref_input.value = "";
|
|
||||||
enabled_checkbox.checked = true;
|
enabled_checkbox.checked = true;
|
||||||
hidden_checkbox.checked = false;
|
hidden_checkbox.checked = false;
|
||||||
permissions_ro_radio.checked = true;
|
permissions_ro_radio.checked = true;
|
||||||
permissions_rw_radio.checked = false;
|
permissions_rw_radio.checked = false;
|
||||||
properties_input.value = "";
|
properties_input.value = "";
|
||||||
|
if (shareType === "map") {
|
||||||
|
sharehref_input.value = random_uuid();
|
||||||
|
sharemapfields.classList.remove("hidden");
|
||||||
|
map_validator.validate();
|
||||||
|
} else {
|
||||||
|
sharehref_input.value = "";
|
||||||
|
sharemapfields.classList.add("hidden");
|
||||||
|
errorHandler.clearError();
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
this.hide = function () {
|
this.hide = function () {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import {
|
|||||||
server_features,
|
server_features,
|
||||||
} from "../api/api.js";
|
} from "../api/api.js";
|
||||||
import { Collection } from "../models/collection.js";
|
import { Collection } from "../models/collection.js";
|
||||||
|
import { ErrorHandler } from "../utils/error.js";
|
||||||
import { NewShareScene } from "./NewShareScene.js";
|
import { NewShareScene } from "./NewShareScene.js";
|
||||||
import { Scene, pop_scene, push_scene, scene_stack } from "./scene_manager.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(
|
/** @type {HTMLElement} */ let share_by_map_div = html_scene.querySelector(
|
||||||
"div[data-name=sharebymap]"
|
"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() {
|
function oncancel() {
|
||||||
try {
|
try {
|
||||||
@@ -70,14 +74,14 @@ export class ShareCollectionScene {
|
|||||||
|
|
||||||
function onsharebytoken() {
|
function onsharebytoken() {
|
||||||
let new_share_scene = new NewShareScene(user, password, collection.href, "token", function () {
|
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);
|
push_scene(new_share_scene, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
function onsharebymap() {
|
function onsharebymap() {
|
||||||
let new_share_scene = new NewShareScene(user, password, collection.href, "map", function () {
|
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);
|
push_scene(new_share_scene, false);
|
||||||
}
|
}
|
||||||
@@ -118,7 +122,7 @@ export class ShareCollectionScene {
|
|||||||
}
|
}
|
||||||
|
|
||||||
title.textContent = collection.displayname || collection.href;
|
title.textContent = collection.displayname || collection.href;
|
||||||
update_share_list(user, password, collection);
|
update_share_list(user, password, collection, errorHandler);
|
||||||
};
|
};
|
||||||
this.hide = function () {
|
this.hide = function () {
|
||||||
html_scene.classList.add("hidden");
|
html_scene.classList.add("hidden");
|
||||||
@@ -134,8 +138,9 @@ export class ShareCollectionScene {
|
|||||||
* @param {string} user
|
* @param {string} user
|
||||||
* @param {string} password
|
* @param {string} password
|
||||||
* @param {Collection} collection
|
* @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(
|
let share_rows = document.querySelectorAll(
|
||||||
"[data-name=sharetokenrowtemplate], [data-name=sharemaprowtemplate]",
|
"[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) {
|
reload_sharing_list(user, password, collection, function (shares, error) {
|
||||||
add_share_rows(user, password, collection, shares);
|
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 {import('../api/api.js').Share} share
|
||||||
* @param {HTMLElement} template
|
* @param {HTMLElement} template
|
||||||
* @param {string} delete_label
|
* @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 pathortoken = share["PathOrToken"] || "";
|
||||||
let node = /** @type {HTMLElement} */ (template.cloneNode(true));
|
let node = /** @type {HTMLElement} */ (template.cloneNode(true));
|
||||||
node.classList.remove("hidden");
|
node.classList.remove("hidden");
|
||||||
@@ -192,8 +202,12 @@ function add_share_row_node(user, password, collection, share, template, delete_
|
|||||||
user,
|
user,
|
||||||
password,
|
password,
|
||||||
pathortoken,
|
pathortoken,
|
||||||
function () {
|
function (error) {
|
||||||
update_share_list(user, password, collection);
|
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 {string} password
|
||||||
* @param {Collection} collection
|
* @param {Collection} collection
|
||||||
* @param {Array<import('../api/api.js').Share>} shares
|
* @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 token_template = document.querySelector("[data-name=sharetokenrowtemplate]");
|
||||||
/** @type {HTMLElement} */ let map_template = document.querySelector("[data-name=sharemaprowtemplate]");
|
/** @type {HTMLElement} */ let map_template = document.querySelector("[data-name=sharemaprowtemplate]");
|
||||||
shares.forEach(function (share) {
|
shares.forEach(function (share) {
|
||||||
@@ -218,9 +233,9 @@ function add_share_rows(user, password, collection, shares) {
|
|||||||
collection.href.includes(pathortoken)
|
collection.href.includes(pathortoken)
|
||||||
) {
|
) {
|
||||||
if (share["ShareType"] === "token") {
|
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") {
|
} 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