Add support for Bday sharing
This commit is contained in:
@@ -19,10 +19,11 @@
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { Share, add_share_by_map, add_share_by_token, get_property_key, update_share_by_map, update_share_by_token } from "../api/sharing.js";
|
||||
import { Share, add_share_by_bday, add_share_by_map, add_share_by_token, get_property_key, update_share_by_bday, update_share_by_map, update_share_by_token } from "../api/sharing.js";
|
||||
import { CollectionType } from "../models/collection.js";
|
||||
import { collectionsCache } from "../utils/collections_cache.js";
|
||||
import { ErrorHandler } from "../utils/error.js";
|
||||
import { FormValidator, validate_href, validate_not_empty_or_equals } from "../utils/form_validator.js";
|
||||
import { FormValidator, validate_href, validate_non_empty, validate_not_empty_or_equals } from "../utils/form_validator.js";
|
||||
import { onCleanHREFinput, random_uuid } from "../utils/misc.js";
|
||||
import { Scene, is_current_scene, pop_scene } from "./scene_manager.js";
|
||||
|
||||
@@ -66,7 +67,12 @@ export class CreateEditShareScene {
|
||||
let errorHandler = new ErrorHandler(error_form);
|
||||
let map_validator = new FormValidator(errorHandler);
|
||||
|
||||
map_validator.addValidator(shareuser_input, validate_not_empty_or_equals(shareuser_input, user, "Share User"));
|
||||
if (shareType === "bday") {
|
||||
// bday can share to self, so just validate non-empty
|
||||
map_validator.addValidator(shareuser_input, validate_non_empty(shareuser_input, "Share User"));
|
||||
} else {
|
||||
map_validator.addValidator(shareuser_input, validate_not_empty_or_equals(shareuser_input, user, "Share User"));
|
||||
}
|
||||
map_validator.addValidator(sharehref_input, validate_href(sharehref_input, "Share Href"));
|
||||
|
||||
sharehref_input.addEventListener("input", onCleanHREFinput);
|
||||
@@ -93,13 +99,13 @@ export class CreateEditShareScene {
|
||||
|
||||
function onsubmit() {
|
||||
try {
|
||||
if (shareType === "map") {
|
||||
if (shareType === "map" || shareType === "bday") {
|
||||
if (!map_validator.validate()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
let enabled_by_owner = enabled_checkbox.checked;
|
||||
let hidden_by_owner = hidden_checkbox.checked;
|
||||
let enabled_by_owner = (shareType === "bday" && shareuser_input.value === user) ? true : enabled_checkbox.checked;
|
||||
let hidden_by_owner = (shareType === "bday" && shareuser_input.value === user) ? false : hidden_checkbox.checked;
|
||||
let permissions = permissions_rw_radio.checked ? "rw" : "r";
|
||||
|
||||
let properties = {};
|
||||
@@ -123,6 +129,11 @@ export class CreateEditShareScene {
|
||||
if (error) {
|
||||
errorHandler.setError(error);
|
||||
} else {
|
||||
// For bday shares to the current user, invalidate the
|
||||
// collections cache so the virtual calendar appears immediately.
|
||||
if (shareType === "bday" && new_share.User === user) {
|
||||
collectionsCache.invalidate();
|
||||
}
|
||||
pop_scene();
|
||||
}
|
||||
};
|
||||
@@ -137,18 +148,22 @@ export class CreateEditShareScene {
|
||||
HiddenByUser: edit ? share.HiddenByUser : null,
|
||||
Properties: properties,
|
||||
User: edit ? share.User : shareuser_input.value,
|
||||
PathOrToken: edit ? share.PathOrToken : (shareType === "map" ? "/" + shareuser_input.value + "/" + sharehref_input.value + "/" : ""),
|
||||
PathOrToken: edit ? share.PathOrToken : ((shareType === "map" || shareType === "bday") ? "/" + shareuser_input.value + "/" + sharehref_input.value + "/" : ""),
|
||||
});
|
||||
|
||||
if (edit) {
|
||||
if (shareType === "map") {
|
||||
update_share_by_map(user, password, new_share, callback);
|
||||
} else if (shareType === "bday") {
|
||||
update_share_by_bday(user, password, new_share, callback);
|
||||
} else {
|
||||
update_share_by_token(user, password, new_share, callback);
|
||||
}
|
||||
} else {
|
||||
if (shareType === "map") {
|
||||
add_share_by_map(user, password, new_share, callback);
|
||||
} else if (shareType === "bday") {
|
||||
add_share_by_bday(user, password, new_share, callback);
|
||||
} else {
|
||||
add_share_by_token(user, password, new_share, callback);
|
||||
}
|
||||
@@ -175,12 +190,25 @@ export class CreateEditShareScene {
|
||||
html_scene.querySelector("h1").textContent = edit ? "Edit Share" : "New Share";
|
||||
submit_btn.textContent = edit ? "Save" : "Create";
|
||||
|
||||
shareuser_input.value = edit ? share.User : "";
|
||||
shareuser_input.value = edit ? share.User : (shareType === "bday" ? user : "");
|
||||
shareuser_input.disabled = edit;
|
||||
enabled_checkbox.checked = edit ? share.EnabledByOwner : true;
|
||||
hidden_checkbox.checked = edit ? share.HiddenByOwner : false;
|
||||
permissions_ro_radio.checked = edit ? share.Permissions.toLowerCase() === "r" : true;
|
||||
permissions_rw_radio.checked = edit ? share.Permissions.toLowerCase() === "rw" : false;
|
||||
|
||||
if (shareType === "bday") {
|
||||
// bday is always read-only; hide the permissions section entirely
|
||||
permissions_ro_radio.checked = true;
|
||||
permissions_rw_radio.checked = false;
|
||||
permissions_ro_radio.disabled = true;
|
||||
permissions_rw_radio.disabled = true;
|
||||
permissions_ro_radio.closest("details")?.classList.add("hidden");
|
||||
} else {
|
||||
permissions_ro_radio.closest("details")?.classList.remove("hidden");
|
||||
permissions_ro_radio.disabled = false;
|
||||
permissions_rw_radio.disabled = false;
|
||||
permissions_ro_radio.checked = edit ? share.Permissions.toLowerCase() === "r" : true;
|
||||
permissions_rw_radio.checked = edit ? share.Permissions.toLowerCase() === "rw" : false;
|
||||
}
|
||||
|
||||
let displayname = collection.displayname || "";
|
||||
let description = collection.description || "";
|
||||
@@ -236,7 +264,7 @@ export class CreateEditShareScene {
|
||||
color_override_enabled.parentElement.classList.add("hidden");
|
||||
}
|
||||
|
||||
if (shareType === "map") {
|
||||
if (shareType === "map" || shareType === "bday") {
|
||||
if (edit) {
|
||||
sharehref_input.value = share.PathOrToken.split("/").filter(Boolean).pop() || "";
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user