2025-03-28 14:16:20 +01:00
|
|
|
<script lang="ts">
|
2025-10-13 23:20:42 +02:00
|
|
|
import { fs_rename, fs_update, type FSNode, type NodeOptions } from "lib/FilesystemAPI.svelte";
|
2025-03-27 15:38:59 +01:00
|
|
|
import Modal from "util/Modal.svelte";
|
2024-02-15 18:52:46 +01:00
|
|
|
import BrandingOptions from "./BrandingOptions.svelte";
|
2025-10-17 13:37:59 +02:00
|
|
|
import { branding_from_props } from "./Branding";
|
2024-02-16 21:07:01 +01:00
|
|
|
import FileOptions from "./FileOptions.svelte";
|
|
|
|
|
import SharingOptions from "./SharingOptions.svelte";
|
2024-11-19 15:31:51 +01:00
|
|
|
import AccessControl from "./AccessControl.svelte";
|
2025-03-28 14:16:20 +01:00
|
|
|
import type { FSNavigator } from "filesystem/FSNavigator";
|
2025-10-10 00:12:14 +02:00
|
|
|
import { loading_finish, loading_start } from "lib/Loading";
|
2023-05-25 21:36:59 +02:00
|
|
|
|
2025-10-13 16:05:50 +02:00
|
|
|
let file: FSNode = $state({} as FSNode)
|
|
|
|
|
let options: NodeOptions = $state({} as NodeOptions)
|
2023-05-11 19:07:29 +02:00
|
|
|
|
2025-10-13 16:05:50 +02:00
|
|
|
let custom_css = $state("")
|
2024-02-16 11:49:38 +01:00
|
|
|
|
2025-10-13 16:05:50 +02:00
|
|
|
let {
|
|
|
|
|
nav,
|
|
|
|
|
visible = $bindable()
|
|
|
|
|
}: {
|
|
|
|
|
nav: FSNavigator;
|
|
|
|
|
visible: boolean;
|
|
|
|
|
} = $props();
|
2024-02-16 21:07:01 +01:00
|
|
|
|
|
|
|
|
// Open the edit window. Argument 1 is the file to edit, 2 is whether the file
|
|
|
|
|
// should be opened after the user finishes editing and 3 is the default tab
|
|
|
|
|
// that should be open when the window shows
|
2025-03-28 14:16:20 +01:00
|
|
|
export const edit = (f: FSNode, oae = false, open_tab = "") => {
|
2023-05-25 14:47:36 +02:00
|
|
|
file = f
|
|
|
|
|
open_after_edit = oae
|
2024-02-16 21:07:01 +01:00
|
|
|
if (open_tab !== "") {
|
|
|
|
|
tab = open_tab
|
|
|
|
|
}
|
2023-05-17 19:27:46 +02:00
|
|
|
|
2023-05-25 14:47:36 +02:00
|
|
|
console.log("Editing file", file)
|
2023-05-11 19:07:29 +02:00
|
|
|
|
2024-02-16 21:07:01 +01:00
|
|
|
// We save the name in a separate field because we need both the original
|
|
|
|
|
// name and the new name for the rename operation
|
|
|
|
|
new_name = file.name
|
2024-02-15 18:52:46 +01:00
|
|
|
|
|
|
|
|
if (file.properties === undefined) {
|
2025-05-14 11:56:52 +02:00
|
|
|
options = {} as NodeOptions
|
|
|
|
|
} else {
|
|
|
|
|
options = file.properties
|
2024-02-15 18:52:46 +01:00
|
|
|
}
|
2024-02-16 14:50:34 +01:00
|
|
|
|
2025-05-14 11:56:52 +02:00
|
|
|
options.custom_domain_name = file.custom_domain_name
|
2025-10-09 15:48:23 +02:00
|
|
|
options.link_permissions = file.link_permissions
|
|
|
|
|
options.user_permissions = file.user_permissions
|
|
|
|
|
options.password_permissions = file.password_permissions
|
2024-11-19 15:31:51 +01:00
|
|
|
|
2025-05-14 11:56:52 +02:00
|
|
|
branding_enabled = options.branding_enabled === "true"
|
2024-02-16 14:50:34 +01:00
|
|
|
if (branding_enabled) {
|
2025-10-17 13:37:59 +02:00
|
|
|
custom_css = branding_from_props(options)
|
2024-02-16 14:50:34 +01:00
|
|
|
} else {
|
|
|
|
|
custom_css = ""
|
|
|
|
|
}
|
|
|
|
|
|
2023-05-17 15:34:56 +02:00
|
|
|
visible = true
|
2023-05-11 19:07:29 +02:00
|
|
|
}
|
|
|
|
|
|
2025-10-13 16:05:50 +02:00
|
|
|
let tab = $state("file")
|
|
|
|
|
let open_after_edit = $state(false)
|
2023-05-17 19:27:46 +02:00
|
|
|
|
2025-10-13 16:05:50 +02:00
|
|
|
let new_name = $state("")
|
|
|
|
|
let branding_enabled = $state(false)
|
2024-02-15 18:52:46 +01:00
|
|
|
|
2025-10-17 13:37:59 +02:00
|
|
|
const save = async (e: SubmitEvent) => {
|
|
|
|
|
e.preventDefault()
|
2023-05-17 19:27:46 +02:00
|
|
|
console.debug("Saving file", file.path)
|
2024-02-15 18:52:46 +01:00
|
|
|
|
2025-03-28 14:16:20 +01:00
|
|
|
let new_file: FSNode
|
2023-05-11 19:07:29 +02:00
|
|
|
try {
|
2025-10-10 00:12:14 +02:00
|
|
|
loading_start()
|
2025-05-14 11:56:52 +02:00
|
|
|
options.branding_enabled = JSON.stringify(branding_enabled)
|
2024-11-19 15:31:51 +01:00
|
|
|
|
2025-05-14 11:56:52 +02:00
|
|
|
new_file = await fs_update(file.path, options)
|
2023-05-11 19:07:29 +02:00
|
|
|
|
2024-02-16 21:07:01 +01:00
|
|
|
if (new_name !== file.name) {
|
2023-05-11 19:07:29 +02:00
|
|
|
let parent = file.path.slice(0, -file.name.length)
|
2024-02-16 21:07:01 +01:00
|
|
|
console.log("Moving", file.path, "to", parent+new_name)
|
|
|
|
|
|
|
|
|
|
await fs_rename(file.path, parent+new_name)
|
|
|
|
|
file.path = parent+new_name
|
2023-05-11 19:07:29 +02:00
|
|
|
|
2024-02-16 21:07:01 +01:00
|
|
|
new_file.name = new_name
|
|
|
|
|
new_file.path = file.path
|
2023-05-11 19:07:29 +02:00
|
|
|
}
|
|
|
|
|
} catch (err) {
|
2023-05-30 15:51:10 +02:00
|
|
|
if (err.message) {
|
|
|
|
|
alert(err.message)
|
|
|
|
|
} else {
|
|
|
|
|
console.error(err)
|
|
|
|
|
alert(err)
|
|
|
|
|
}
|
2023-05-11 19:07:29 +02:00
|
|
|
return
|
2023-05-25 21:36:59 +02:00
|
|
|
} finally {
|
2025-10-10 00:12:14 +02:00
|
|
|
loading_finish()
|
2023-05-11 19:07:29 +02:00
|
|
|
}
|
|
|
|
|
|
2023-05-25 14:47:36 +02:00
|
|
|
if (open_after_edit) {
|
2024-08-09 13:02:07 +02:00
|
|
|
nav.navigate(file.path, false)
|
2023-05-25 14:47:36 +02:00
|
|
|
} else {
|
2024-08-09 13:02:07 +02:00
|
|
|
nav.reload()
|
2023-05-25 14:47:36 +02:00
|
|
|
}
|
2023-05-17 15:34:56 +02:00
|
|
|
}
|
2023-05-11 19:07:29 +02:00
|
|
|
</script>
|
|
|
|
|
|
2024-09-05 14:58:26 +02:00
|
|
|
<Modal bind:visible={visible} title="Edit {file.name}" width="800px" form="edit_form" style="color: var(--body_text_color); {custom_css}">
|
2023-05-17 19:27:46 +02:00
|
|
|
<div class="tab_bar">
|
2025-10-13 16:05:50 +02:00
|
|
|
<button class:button_highlight={tab === "file"} onclick={() => tab = "file"}>
|
2023-05-17 19:27:46 +02:00
|
|
|
<i class="icon">edit</i>
|
2024-02-16 11:49:38 +01:00
|
|
|
Properties
|
2023-05-17 19:27:46 +02:00
|
|
|
</button>
|
2025-10-13 16:05:50 +02:00
|
|
|
<button class:button_highlight={tab === "share"} onclick={() => tab = "share"}>
|
2023-05-17 19:27:46 +02:00
|
|
|
<i class="icon">share</i>
|
2024-02-15 18:52:46 +01:00
|
|
|
Sharing
|
|
|
|
|
</button>
|
2025-10-09 15:48:23 +02:00
|
|
|
{#if $nav.permissions.owner}
|
2025-10-13 16:05:50 +02:00
|
|
|
<button class:button_highlight={tab === "access"} onclick={() => tab = "access"}>
|
2024-11-19 15:31:51 +01:00
|
|
|
<i class="icon">key</i>
|
|
|
|
|
Access control
|
|
|
|
|
</button>
|
|
|
|
|
{/if}
|
2025-10-13 16:05:50 +02:00
|
|
|
<button class:button_highlight={tab === "branding"} onclick={() => tab = "branding"}>
|
2024-02-15 18:52:46 +01:00
|
|
|
<i class="icon">palette</i>
|
|
|
|
|
Branding
|
2023-05-17 19:27:46 +02:00
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
2025-10-17 13:37:59 +02:00
|
|
|
<form id="edit_form" onsubmit={save}></form>
|
2024-02-16 21:07:01 +01:00
|
|
|
|
|
|
|
|
<div class="tab_content">
|
|
|
|
|
{#if tab === "file"}
|
|
|
|
|
<FileOptions
|
2024-08-09 13:02:07 +02:00
|
|
|
nav={nav}
|
2024-02-16 21:07:01 +01:00
|
|
|
bind:file
|
|
|
|
|
bind:new_name
|
|
|
|
|
bind:visible
|
|
|
|
|
bind:open_after_edit
|
|
|
|
|
/>
|
|
|
|
|
{:else if tab === "share"}
|
2025-10-13 16:05:50 +02:00
|
|
|
<SharingOptions
|
|
|
|
|
bind:file
|
|
|
|
|
bind:options
|
|
|
|
|
/>
|
2024-11-19 15:31:51 +01:00
|
|
|
{:else if tab === "access"}
|
2025-05-14 11:56:52 +02:00
|
|
|
<AccessControl bind:options />
|
2024-02-16 21:07:01 +01:00
|
|
|
{:else if tab === "branding"}
|
2024-02-16 14:50:34 +01:00
|
|
|
<BrandingOptions
|
|
|
|
|
bind:enabled={branding_enabled}
|
2025-05-14 11:56:52 +02:00
|
|
|
bind:options={options}
|
2024-02-16 21:07:01 +01:00
|
|
|
bind:file
|
2025-10-17 13:37:59 +02:00
|
|
|
bind:custom_css
|
2024-02-16 14:50:34 +01:00
|
|
|
/>
|
2024-02-16 21:07:01 +01:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
2023-05-11 19:07:29 +02:00
|
|
|
</Modal>
|
2023-05-17 19:27:46 +02:00
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.tab_bar {
|
|
|
|
|
border-bottom: 2px solid var(--separator);
|
|
|
|
|
}
|
2024-02-15 18:52:46 +01:00
|
|
|
.tab_content {
|
|
|
|
|
padding: 8px;
|
|
|
|
|
}
|
2023-05-17 19:27:46 +02:00
|
|
|
</style>
|