2021-12-06 10:07:08 +00:00
|
|
|
<!--
|
|
|
|
// Copyright © 2020, 2021 Anticrm Platform Contributors.
|
|
|
|
// Copyright © 2021 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 { createEventDispatcher } from 'svelte'
|
|
|
|
import type { Ref, Space, Data } from '@anticrm/core'
|
|
|
|
|
|
|
|
import { getClient, Card, Channels, Avatar } from '@anticrm/presentation'
|
|
|
|
|
|
|
|
import { EditBox, showPopup, CircleButton, IconEdit, IconAdd, Label } from '@anticrm/ui'
|
|
|
|
import SocialEditor from './SocialEditor.svelte'
|
|
|
|
|
|
|
|
import { combineName, Person } from '@anticrm/contact'
|
|
|
|
import contact from '../plugin'
|
|
|
|
|
|
|
|
export let space: Ref<Space>
|
|
|
|
|
|
|
|
let _space = space
|
|
|
|
|
|
|
|
let firstName = ''
|
|
|
|
let lastName = ''
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
export function canClose (): boolean {
|
2021-12-06 10:07:08 +00:00
|
|
|
return firstName === '' && lastName === ''
|
|
|
|
}
|
|
|
|
|
|
|
|
const object: Person = {} as Person
|
|
|
|
|
|
|
|
const dispatch = createEventDispatcher()
|
|
|
|
const client = getClient()
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
async function createPerson () {
|
2021-12-06 10:07:08 +00:00
|
|
|
const person: Data<Person> = {
|
|
|
|
name: combineName(firstName, lastName),
|
|
|
|
city: object.city,
|
|
|
|
channels: object.channels
|
|
|
|
}
|
|
|
|
|
|
|
|
await client.createDoc(contact.class.Person, _space, person)
|
|
|
|
|
|
|
|
dispatch('close')
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-12-07 09:05:52 +00:00
|
|
|
<Card
|
|
|
|
label={contact.string.CreatePerson}
|
|
|
|
okAction={createPerson}
|
|
|
|
canSave={firstName.length > 0 && lastName.length > 0}
|
|
|
|
spaceClass={contact.class.Persons}
|
|
|
|
spaceLabel={contact.string.PersonsFolder}
|
|
|
|
spacePlaceholder={contact.string.SelectFolder}
|
|
|
|
bind:space={_space}
|
|
|
|
on:close={() => {
|
|
|
|
dispatch('close')
|
|
|
|
}}
|
|
|
|
>
|
2021-12-06 10:07:08 +00:00
|
|
|
<div class="flex-row-center">
|
|
|
|
<div class="mr-4">
|
|
|
|
<Avatar avatar={object.avatar} size={'large'} />
|
|
|
|
</div>
|
|
|
|
<div class="flex-col">
|
2021-12-07 09:05:52 +00:00
|
|
|
<div class="fs-title"><EditBox placeholder="John" maxWidth="10rem" bind:value={firstName} /></div>
|
|
|
|
<div class="fs-title mb-1"><EditBox placeholder="Appleseed" maxWidth="10rem" bind:value={lastName} /></div>
|
|
|
|
<div class="small-text"><EditBox placeholder="Location" maxWidth="10rem" bind:value={object.city} /></div>
|
2021-12-06 10:07:08 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="flex-row-center channels">
|
|
|
|
{#if !object.channels || object.channels.length === 0}
|
2021-12-07 09:05:52 +00:00
|
|
|
<CircleButton
|
|
|
|
icon={IconAdd}
|
|
|
|
size={'small'}
|
|
|
|
transparent
|
|
|
|
on:click={(ev) =>
|
|
|
|
showPopup(SocialEditor, { values: object.channels ?? [] }, ev.target, (result) => {
|
|
|
|
object.channels = result
|
|
|
|
})}
|
|
|
|
/>
|
2021-12-06 10:07:08 +00:00
|
|
|
<span><Label label={contact.string.AddSocialLinks} /></span>
|
|
|
|
{:else}
|
|
|
|
<Channels value={object.channels} size={'small'} />
|
|
|
|
<div class="ml-1">
|
2021-12-07 09:05:52 +00:00
|
|
|
<CircleButton
|
|
|
|
icon={IconEdit}
|
|
|
|
size={'small'}
|
|
|
|
transparent
|
|
|
|
on:click={(ev) =>
|
|
|
|
showPopup(SocialEditor, { values: object.channels ?? [] }, ev.target, (result) => {
|
|
|
|
object.channels = result
|
|
|
|
})}
|
|
|
|
/>
|
2021-12-06 10:07:08 +00:00
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
</div>
|
|
|
|
</Card>
|
|
|
|
|
|
|
|
<style lang="scss">
|
|
|
|
.channels {
|
|
|
|
margin-top: 1.25rem;
|
2021-12-07 09:05:52 +00:00
|
|
|
span {
|
|
|
|
margin-left: 0.5rem;
|
|
|
|
}
|
2021-12-06 10:07:08 +00:00
|
|
|
}
|
|
|
|
</style>
|