2022-03-17 09:39:57 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2022 Hardcore Engineering Inc.
|
|
|
|
//
|
|
|
|
// Licensed under the Eclipse Public License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License. You may
|
|
|
|
// obtain a copy of the License at https://www.eclipse.org/legal/epl-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
//
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
-->
|
|
|
|
<script lang="ts">
|
|
|
|
import { Organization } from '@anticrm/contact'
|
|
|
|
import { Ref } from '@anticrm/core'
|
|
|
|
import { IntlString } from '@anticrm/platform'
|
|
|
|
import { createQuery } from '@anticrm/presentation'
|
2022-06-10 18:25:13 +00:00
|
|
|
import { DropdownPopup, Label, showPopup, Button } from '@anticrm/ui'
|
|
|
|
import type { ButtonKind, ButtonSize } from '@anticrm/ui'
|
2022-03-17 09:39:57 +00:00
|
|
|
import { ListItem } from '@anticrm/ui/src/types'
|
|
|
|
import contact from '../plugin'
|
|
|
|
import Company from './icons/Company.svelte'
|
|
|
|
|
|
|
|
export let value: Ref<Organization> | undefined
|
|
|
|
export let label: IntlString = contact.string.Organization
|
|
|
|
export let onChange: (value: any) => void
|
2022-06-10 18:25:13 +00:00
|
|
|
|
|
|
|
export let kind: ButtonKind = 'no-border'
|
|
|
|
export let size: ButtonSize = 'small'
|
|
|
|
export let justify: 'left' | 'center' = 'center'
|
|
|
|
export let width: string | undefined = 'min-content'
|
2022-03-17 09:39:57 +00:00
|
|
|
|
|
|
|
const query = createQuery()
|
|
|
|
|
|
|
|
query.query(contact.class.Organization, {}, (res) => {
|
|
|
|
items = res.map((org) => {
|
|
|
|
return {
|
|
|
|
_id: org._id,
|
|
|
|
label: org.name,
|
2022-03-28 15:25:39 +00:00
|
|
|
image: org.avatar === null ? undefined : org.avatar
|
2022-03-17 09:39:57 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
if (value !== undefined) {
|
|
|
|
selected = items.find((p) => p._id === value)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
let items: ListItem[] = []
|
|
|
|
let selected: ListItem | undefined
|
|
|
|
|
|
|
|
function setValue (res: ListItem | undefined): void {
|
|
|
|
selected = res
|
|
|
|
if (selected === undefined) {
|
|
|
|
value = undefined
|
|
|
|
} else {
|
|
|
|
value = selected._id as Ref<Organization>
|
|
|
|
}
|
|
|
|
onChange(value)
|
|
|
|
}
|
|
|
|
|
|
|
|
let opened: boolean = false
|
|
|
|
const icon = Company
|
2022-06-10 18:25:13 +00:00
|
|
|
let tool: HTMLElement
|
2022-03-17 09:39:57 +00:00
|
|
|
</script>
|
2022-04-29 05:27:17 +00:00
|
|
|
|
2022-06-10 18:25:13 +00:00
|
|
|
<div class="clear-mins" bind:this={tool} />
|
|
|
|
<Button
|
|
|
|
{justify}
|
|
|
|
{width}
|
|
|
|
{size}
|
|
|
|
{kind}
|
|
|
|
on:click={() => {
|
2022-04-29 05:27:17 +00:00
|
|
|
if (!opened) {
|
|
|
|
opened = true
|
2022-06-10 18:25:13 +00:00
|
|
|
showPopup(DropdownPopup, { title: label, items, icon }, tool, (result) => {
|
2022-04-29 05:27:17 +00:00
|
|
|
if (result) setValue(result)
|
|
|
|
opened = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2022-06-10 18:25:13 +00:00
|
|
|
<svelte:fragment slot="content">
|
|
|
|
{#if selected}
|
|
|
|
<div class="flex-row-center pointer-events-none">
|
|
|
|
<div class="icon"><Company size={'small'} /></div>
|
|
|
|
<span class="overflow-label">{selected.label}</span>
|
|
|
|
</div>
|
|
|
|
{:else}
|
|
|
|
<span class="overflow-label disabled"><Label {label} /></span>
|
|
|
|
{/if}
|
|
|
|
</svelte:fragment>
|
|
|
|
</Button>
|
2022-03-17 09:39:57 +00:00
|
|
|
|
|
|
|
<style lang="scss">
|
2022-06-10 18:25:13 +00:00
|
|
|
.icon {
|
|
|
|
margin-right: 0.5rem;
|
|
|
|
padding: 0.25rem;
|
|
|
|
color: var(--accent-color);
|
|
|
|
background-color: var(--avatar-bg-color);
|
|
|
|
border-radius: 50%;
|
2022-05-13 06:41:30 +00:00
|
|
|
|
2022-06-10 18:25:13 +00:00
|
|
|
&:hover {
|
2022-05-13 06:41:30 +00:00
|
|
|
color: var(--caption-color);
|
|
|
|
}
|
2022-04-29 05:27:17 +00:00
|
|
|
}
|
2022-03-17 09:39:57 +00:00
|
|
|
</style>
|