Add the ability to restrict adding / removing attachments (#3479)

Signed-off-by: Sergei Ogorelkov <sergei.ogorelkov@icloud.com>
This commit is contained in:
Sergei Ogorelkov 2023-07-04 22:46:35 +04:00 committed by GitHub
parent a0ecb3c04f
commit 10a7b0f379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 10 deletions

View File

@ -24,6 +24,8 @@
export let attachments: number
export let object: Doc
export let canAdd = true
export let canRemove = true
const client = getClient()
@ -41,8 +43,10 @@
)
function add () {
if (canAdd) {
inputFile.click()
}
}
async function createAttachment (file: File) {
const uuid = await uploadFile(file)
@ -68,8 +72,10 @@
let inputFile: HTMLInputElement
async function remove (doc: Attachment): Promise<void> {
if (canRemove) {
await client.remove(doc)
}
}
</script>
<div class="container">
@ -86,14 +92,16 @@
<div class="fs-title">
<Label label={attachment.string.Attachments} />
</div>
{#if canAdd}
<div>
<ActionIcon size={'medium'} icon={IconAdd} action={add} />
</div>
{/if}
</div>
<div class="content">
{#each docs as doc}
<div class="item">
<AttachmentPresenter value={doc} showPreview removable on:remove={() => remove(doc)} />
<AttachmentPresenter value={doc} showPreview removable={canRemove} on:remove={() => remove(doc)} />
</div>
{/each}
</div>

View File

@ -25,17 +25,21 @@
export let kind: ButtonKind = 'link'
export let showCounter: boolean = true
export let compactMode: boolean = false
export let disabled = false
export let canAdd = true
export let canRemove = true
</script>
{#if value && value > 0}
{@const popupProps = { objectId: object._id, attachments: value, object, canAdd, canRemove }}
<!-- svelte-ignore a11y-click-events-have-key-events -->
<DocNavLink {object} inline noUnderline={true} shrink={0}>
<DocNavLink {object} {disabled} inline noUnderline shrink={0}>
{#if kind === 'list'}
{#if compactMode}
<div
use:tooltip={{
component: AttachmentPopup,
props: { objectId: object._id, attachments: value, object }
props: popupProps
}}
class="sm-tool-icon"
>
@ -48,7 +52,7 @@
{size}
showTooltip={{
component: AttachmentPopup,
props: { objectId: object._id, attachments: value, object }
props: popupProps
}}
>
<div slot="icon"><IconAttachment {size} /></div>
@ -61,7 +65,7 @@
<div
use:tooltip={{
component: AttachmentPopup,
props: { objectId: object._id, attachments: value, object }
props: popupProps
}}
class="sm-tool-icon"
>