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'
|
|
|
|
import { DropdownPopup, Label, showPopup } from '@anticrm/ui'
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
let container: HTMLElement
|
|
|
|
</script>
|
2022-04-29 05:27:17 +00:00
|
|
|
|
|
|
|
<div
|
|
|
|
class="caption-color cursor-pointer"
|
|
|
|
bind:this={container}
|
|
|
|
class:empty={selected === undefined}
|
|
|
|
on:click|preventDefault={() => {
|
|
|
|
if (!opened) {
|
|
|
|
opened = true
|
|
|
|
showPopup(DropdownPopup, { title: label, items, icon }, container, (result) => {
|
|
|
|
if (result) setValue(result)
|
|
|
|
opened = false
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
>
|
2022-03-17 09:39:57 +00:00
|
|
|
{#if selected}{selected.label}{:else}<Label {label} />{/if}
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<style lang="scss">
|
2022-04-29 05:27:17 +00:00
|
|
|
.empty {
|
|
|
|
color: var(--theme-content-trans-color);
|
|
|
|
}
|
2022-03-17 09:39:57 +00:00
|
|
|
</style>
|