@things-factory/biz-base 10.1.265 → 10.1.269
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/counterparty-register-form.ts +219 -0
- package/client/counterparty-register.ts +52 -0
- package/client/counterparty-select.ts +221 -0
- package/client/index.ts +9 -0
- package/dist-client/counterparty-register-form.d.ts +40 -0
- package/dist-client/counterparty-register-form.js +230 -0
- package/dist-client/counterparty-register-form.js.map +1 -0
- package/dist-client/counterparty-register.d.ts +31 -0
- package/dist-client/counterparty-register.js +42 -0
- package/dist-client/counterparty-register.js.map +1 -0
- package/dist-client/counterparty-select.d.ts +41 -0
- package/dist-client/counterparty-select.js +238 -0
- package/dist-client/counterparty-select.js.map +1 -0
- package/dist-client/index.d.ts +3 -0
- package/dist-client/index.js +4 -0
- package/dist-client/index.js.map +1 -0
- package/dist-client/tsconfig.tsbuildinfo +1 -0
- package/dist-server/service/counterparty/counterparty-names.d.ts +6 -0
- package/dist-server/service/counterparty/counterparty-names.js +12 -0
- package/dist-server/service/counterparty/counterparty-names.js.map +1 -1
- package/dist-server/service/counterparty/counterparty-query.d.ts +2 -1
- package/dist-server/service/counterparty/counterparty-query.js +19 -0
- package/dist-server/service/counterparty/counterparty-query.js.map +1 -1
- package/dist-server/tsconfig.tsbuildinfo +1 -1
- package/package.json +18 -9
- package/tests/counterparty-names.test.mjs +17 -0
- package/tests/counterparty-register.test.mjs +40 -0
- package/translations/en.json +21 -1
- package/translations/es.json +21 -1
- package/translations/ja.json +28 -1
- package/translations/ko.json +21 -1
- package/translations/ms.json +28 -1
- package/translations/zh.json +28 -1
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import '@material/web/button/filled-button.js'
|
|
2
|
+
import '@material/web/button/text-button.js'
|
|
3
|
+
import '@operato/input/ox-input-select-buttons.js'
|
|
4
|
+
import '@operato/popup/ox-popup-actions.js'
|
|
5
|
+
|
|
6
|
+
import gql from 'graphql-tag'
|
|
7
|
+
import { css, html, LitElement, nothing } from 'lit'
|
|
8
|
+
import { customElement, property, state } from 'lit/decorators.js'
|
|
9
|
+
|
|
10
|
+
import { gqlContext, MutationController, QueryController } from '@operato/graphql'
|
|
11
|
+
import { i18next, localize } from '@operato/i18n'
|
|
12
|
+
import { CommonPopupStyles, FormFieldStyles, PopupBodyStyles, PopupFieldStyles } from '@operato/styles'
|
|
13
|
+
|
|
14
|
+
/** The kinds a counterparty registered here may be - our own company is one per domain and kept on its own screen. */
|
|
15
|
+
const KINDS = ['COMPANY', 'INSTITUTION', 'PERSON']
|
|
16
|
+
|
|
17
|
+
const SAME_NAMED = gql`
|
|
18
|
+
query ($name: String!) {
|
|
19
|
+
counterpartiesNamed(name: $name) {
|
|
20
|
+
id
|
|
21
|
+
name
|
|
22
|
+
kind
|
|
23
|
+
businessNumber
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`
|
|
27
|
+
|
|
28
|
+
const REGISTER = gql`
|
|
29
|
+
mutation ($counterparty: NewCounterparty!) {
|
|
30
|
+
createCounterparty(counterparty: $counterparty) {
|
|
31
|
+
id
|
|
32
|
+
name
|
|
33
|
+
kind
|
|
34
|
+
businessNumber
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
`
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 새 거래처 등록 - the short form a picker opens for a name it did not find (ADR-0195 decision 3): the name, the kind,
|
|
41
|
+
* and the business number and representative when known. Saved through `createCounterparty`, the counterparty screen's
|
|
42
|
+
* own checks. Fires `counterparty` with the one to take, `close` when given up.
|
|
43
|
+
*
|
|
44
|
+
* A name already a counterparty - its name or an alias, spaces and (주) aside - is not registered again: the form shows
|
|
45
|
+
* that one and offers only to take it (decision 4). A business of the same name is registered on the counterparty
|
|
46
|
+
* screen.
|
|
47
|
+
*
|
|
48
|
+
* The business number field is where a check with the public registries will sit (decision 7).
|
|
49
|
+
*/
|
|
50
|
+
@customElement('counterparty-register-form')
|
|
51
|
+
export class CounterpartyRegisterForm extends localize(i18next)(LitElement) {
|
|
52
|
+
/* The house shape of a popup (page-standard sections 7, 8): only the body scrolls, labels above native inputs. */
|
|
53
|
+
static styles = [
|
|
54
|
+
CommonPopupStyles,
|
|
55
|
+
PopupBodyStyles,
|
|
56
|
+
FormFieldStyles,
|
|
57
|
+
PopupFieldStyles,
|
|
58
|
+
css`
|
|
59
|
+
ox-input-select-buttons {
|
|
60
|
+
align-self: flex-start;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
[guide] {
|
|
64
|
+
margin: 0;
|
|
65
|
+
color: var(--ui-muted);
|
|
66
|
+
line-height: var(--popup-line-height);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
[invalid] {
|
|
70
|
+
color: var(--ui-crit, var(--md-sys-color-error));
|
|
71
|
+
font-size: var(--ui-t-small, 11.5px);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
[invalid]:empty {
|
|
75
|
+
display: none;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
ul[same] {
|
|
79
|
+
list-style: none;
|
|
80
|
+
margin: 0;
|
|
81
|
+
padding: 0;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
ul[same] li {
|
|
85
|
+
display: flex;
|
|
86
|
+
align-items: center;
|
|
87
|
+
justify-content: space-between;
|
|
88
|
+
gap: var(--spacing-medium, 8px);
|
|
89
|
+
padding: 3px 0;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
ul[same] small {
|
|
93
|
+
color: var(--ui-muted);
|
|
94
|
+
}
|
|
95
|
+
`
|
|
96
|
+
]
|
|
97
|
+
|
|
98
|
+
/** The name the picker was searched by - the form starts from it. */
|
|
99
|
+
@property({ type: String }) name = ''
|
|
100
|
+
|
|
101
|
+
@state() private kind = 'COMPANY'
|
|
102
|
+
@state() private businessNumber = ''
|
|
103
|
+
@state() private representative = ''
|
|
104
|
+
/** The name asked about - set once the person stops typing. */
|
|
105
|
+
@state() private asked = ''
|
|
106
|
+
|
|
107
|
+
private timer?: ReturnType<typeof setTimeout>
|
|
108
|
+
|
|
109
|
+
private sameNamed = new QueryController(this, SAME_NAMED, {
|
|
110
|
+
variables: () => (this.asked ? { name: this.asked } : undefined),
|
|
111
|
+
fetchPolicy: 'no-cache',
|
|
112
|
+
context: gqlContext()
|
|
113
|
+
} as any)
|
|
114
|
+
|
|
115
|
+
private save = new MutationController(this, REGISTER, { context: gqlContext(), showsError: true } as any)
|
|
116
|
+
|
|
117
|
+
connectedCallback() {
|
|
118
|
+
super.connectedCallback()
|
|
119
|
+
this.asked = this.name.trim()
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** What the name check says for the name now in the field. */
|
|
123
|
+
private get check(): 'idle' | 'checking' | 'free' | 'taken' | 'failed' {
|
|
124
|
+
const name = this.name.trim()
|
|
125
|
+
if (!name || this.asked !== name) return 'idle'
|
|
126
|
+
if (this.sameNamed.loading) return 'checking'
|
|
127
|
+
const found = this.sameNamed.error ? undefined : this.sameNamed.data?.counterpartiesNamed
|
|
128
|
+
if (!Array.isArray(found)) return 'failed'
|
|
129
|
+
return found.length ? 'taken' : 'free'
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
private get registrable(): boolean {
|
|
133
|
+
return this.check === 'free' && !this.save.pending
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
render() {
|
|
137
|
+
const check = this.check
|
|
138
|
+
return html`
|
|
139
|
+
<div class="body">
|
|
140
|
+
<p guide>${i18next.t('text.counterparty-register-guide')}</p>
|
|
141
|
+
|
|
142
|
+
<label class="field">
|
|
143
|
+
<span>${i18next.t('field.counterparty-name')}</span>
|
|
144
|
+
<input name="name" .value=${this.name} @input=${(e: Event) => this.onName((e.target as HTMLInputElement).value)} />
|
|
145
|
+
<span invalid
|
|
146
|
+
>${check === 'failed' ? i18next.t('text.counterparty-name-check-failed') : check === 'checking' ? i18next.t('text.counterparty-checking-name') : ''}</span
|
|
147
|
+
>
|
|
148
|
+
</label>
|
|
149
|
+
|
|
150
|
+
${check === 'taken' ? this.renderSameNamed() : nothing}
|
|
151
|
+
|
|
152
|
+
<div class="field">
|
|
153
|
+
<span>${i18next.t('field.counterparty-kind')}</span>
|
|
154
|
+
<ox-input-select-buttons
|
|
155
|
+
.value=${this.kind}
|
|
156
|
+
.options=${KINDS.map(kind => ({ display: i18next.t(`text.counterparty-kind-${kind.toLowerCase()}`), value: kind }))}
|
|
157
|
+
@change=${(e: CustomEvent) => e.detail && (this.kind = e.detail)}
|
|
158
|
+
></ox-input-select-buttons>
|
|
159
|
+
</div>
|
|
160
|
+
|
|
161
|
+
<label class="field">
|
|
162
|
+
<span>${i18next.t('field.business-number')}</span>
|
|
163
|
+
<input name="businessNumber" .value=${this.businessNumber} inputmode="numeric" @input=${(e: Event) => (this.businessNumber = (e.target as HTMLInputElement).value)} />
|
|
164
|
+
<span>${i18next.t('text.business-number-hint')}</span>
|
|
165
|
+
</label>
|
|
166
|
+
|
|
167
|
+
<label class="field">
|
|
168
|
+
<span>${i18next.t('field.representative')}</span>
|
|
169
|
+
<input name="representative" .value=${this.representative} @input=${(e: Event) => (this.representative = (e.target as HTMLInputElement).value)} />
|
|
170
|
+
</label>
|
|
171
|
+
</div>
|
|
172
|
+
|
|
173
|
+
<ox-popup-actions>
|
|
174
|
+
<md-text-button slot="cancel" @click=${() => this.dispatchEvent(new CustomEvent('close'))}>${i18next.t('button.cancel')}</md-text-button>
|
|
175
|
+
<md-filled-button slot="confirm" ?disabled=${!this.registrable} @click=${() => this.register()}>${i18next.t('button.counterparty-register')}</md-filled-button>
|
|
176
|
+
</ox-popup-actions>
|
|
177
|
+
`
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private renderSameNamed() {
|
|
181
|
+
const found: any[] = this.sameNamed.data?.counterpartiesNamed ?? []
|
|
182
|
+
return html`
|
|
183
|
+
<div class="field">
|
|
184
|
+
<span invalid>${i18next.t('text.counterparty-same-named')}</span>
|
|
185
|
+
<ul same>
|
|
186
|
+
${found.map(
|
|
187
|
+
one => html`<li>
|
|
188
|
+
<span>${one.name} ${one.businessNumber ? html`<small>${one.businessNumber}</small>` : nothing}</span>
|
|
189
|
+
<md-text-button @click=${() => this.take(one)}>${i18next.t('button.counterparty-choose-this')}</md-text-button>
|
|
190
|
+
</li>`
|
|
191
|
+
)}
|
|
192
|
+
</ul>
|
|
193
|
+
</div>
|
|
194
|
+
`
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
private onName(value: string) {
|
|
198
|
+
this.name = value
|
|
199
|
+
clearTimeout(this.timer)
|
|
200
|
+
this.timer = setTimeout(() => (this.asked = this.name.trim()), 300)
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
private async register() {
|
|
204
|
+
if (!this.registrable) return
|
|
205
|
+
const counterparty = {
|
|
206
|
+
name: this.name.trim(),
|
|
207
|
+
kind: this.kind,
|
|
208
|
+
...(this.businessNumber.trim() ? { businessNumber: this.businessNumber.trim() } : {}),
|
|
209
|
+
...(this.representative.trim() ? { representative: this.representative.trim() } : {})
|
|
210
|
+
}
|
|
211
|
+
const data: any = await this.save.run({ counterparty })
|
|
212
|
+
const saved = data?.createCounterparty
|
|
213
|
+
if (saved) this.take(saved)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private take(one: { id: string; name: string; businessNumber?: string | null; kind?: string | null }) {
|
|
217
|
+
this.dispatchEvent(new CustomEvent('counterparty', { detail: { id: one.id, name: one.name, businessNumber: one.businessNumber ?? null, kind: one.kind ?? null } }))
|
|
218
|
+
}
|
|
219
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import './counterparty-register-form.js'
|
|
2
|
+
|
|
3
|
+
import { html } from 'lit'
|
|
4
|
+
|
|
5
|
+
import { i18next } from '@operato/i18n'
|
|
6
|
+
import { openPopup } from '@operato/layout'
|
|
7
|
+
import { hasPrivilege } from '@things-factory/auth-base/dist-client'
|
|
8
|
+
|
|
9
|
+
/** A counterparty as one picks it - which one, its name and registration number (`counterpartyChoices`). */
|
|
10
|
+
export type CounterpartyPick = { id: string; name: string; businessNumber?: string | null; kind?: string | null }
|
|
11
|
+
|
|
12
|
+
/** Registering a counterparty is the counterparty keeper's - the privilege `createCounterparty` asks (ADR-0195 decision 5). */
|
|
13
|
+
export const COUNTERPARTY_REGISTER_PRIVILEGE = { category: 'counterparty', privilege: 'mutation', domainOwnerGranted: true }
|
|
14
|
+
|
|
15
|
+
/** Whether this seat may register a counterparty - where it is not, the pickers offer no registering. */
|
|
16
|
+
export async function mayRegisterCounterparty(): Promise<boolean> {
|
|
17
|
+
try {
|
|
18
|
+
return !!(await hasPrivilege(COUNTERPARTY_REGISTER_PRIVILEGE))
|
|
19
|
+
} catch {
|
|
20
|
+
return false
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Register a counterparty from the name a picker was searched by, in the short form (ADR-0195 decision 3). Resolves the
|
|
26
|
+
* counterparty to take - the one registered, or the one of the same name the form led to - or undefined when the
|
|
27
|
+
* person closed the form.
|
|
28
|
+
*/
|
|
29
|
+
export function registerCounterparty(name: string): Promise<CounterpartyPick | undefined> {
|
|
30
|
+
return new Promise(resolve => {
|
|
31
|
+
let taken: CounterpartyPick | undefined
|
|
32
|
+
const handle: any = openPopup(
|
|
33
|
+
html`<counterparty-register-form
|
|
34
|
+
.name=${name}
|
|
35
|
+
@close=${() => handle.close()}
|
|
36
|
+
@counterparty=${(e: CustomEvent) => ((taken = e.detail), handle.close())}
|
|
37
|
+
></counterparty-register-form>`,
|
|
38
|
+
{ backdrop: true, size: 'medium', title: i18next.t('title.counterparty-register') }
|
|
39
|
+
)
|
|
40
|
+
handle.onclosed = () => resolve(taken)
|
|
41
|
+
})
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* What a picker column of counterparties declares so a name not found can be registered there (`resource-object`'s
|
|
46
|
+
* `creatable`, ADR-0195 decision 2).
|
|
47
|
+
*/
|
|
48
|
+
export const counterpartyCreatable = {
|
|
49
|
+
allowed: mayRegisterCounterparty,
|
|
50
|
+
label: (name: string) => i18next.t('button.counterparty-register-named', { name }),
|
|
51
|
+
create: registerCounterparty
|
|
52
|
+
}
|
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import '@material/web/icon/icon.js'
|
|
2
|
+
|
|
3
|
+
import gql from 'graphql-tag'
|
|
4
|
+
import { css, html, LitElement, nothing } from 'lit'
|
|
5
|
+
import { customElement, property, state } from 'lit/decorators.js'
|
|
6
|
+
|
|
7
|
+
import { QueryController } from '@operato/graphql'
|
|
8
|
+
import { i18next, localize } from '@operato/i18n'
|
|
9
|
+
import { ButtonStyles } from '@operato/styles'
|
|
10
|
+
import { mayRegisterCounterparty, registerCounterparty, type CounterpartyPick } from './counterparty-register.js'
|
|
11
|
+
|
|
12
|
+
const CHOICES = gql`
|
|
13
|
+
query ($search: String, $pagination: Pagination) {
|
|
14
|
+
counterparties: counterpartyChoices(search: $search, pagination: $pagination) {
|
|
15
|
+
items { id name businessNumber }
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Picking a counterparty - one field that finds as it is typed and lists what it found under it; a click takes one and
|
|
22
|
+
* fires `counterparty` with it (or with null when cleared). Every form that picks one counterparty picks it here -
|
|
23
|
+
* invoice, quotation, opportunity, expenditure request (ADR-0195 decision 1). Reads `counterpartyChoices`, which every
|
|
24
|
+
* seat may.
|
|
25
|
+
*
|
|
26
|
+
* A name not found can be registered from here and is taken at once (ADR-0195 decision 2) - offered only to a seat that
|
|
27
|
+
* may register counterparties.
|
|
28
|
+
*/
|
|
29
|
+
@customElement('counterparty-select')
|
|
30
|
+
export class CounterpartySelect extends localize(i18next)(LitElement) {
|
|
31
|
+
static styles = [
|
|
32
|
+
ButtonStyles,
|
|
33
|
+
css`
|
|
34
|
+
:host {
|
|
35
|
+
position: relative;
|
|
36
|
+
display: block;
|
|
37
|
+
}
|
|
38
|
+
.field {
|
|
39
|
+
display: flex;
|
|
40
|
+
gap: var(--spacing-small, 4px);
|
|
41
|
+
align-items: center;
|
|
42
|
+
}
|
|
43
|
+
input {
|
|
44
|
+
flex: 1;
|
|
45
|
+
min-width: 0;
|
|
46
|
+
box-sizing: border-box;
|
|
47
|
+
height: var(--form-element-height-medium, 32px);
|
|
48
|
+
padding: 0 var(--spacing-medium, 8px);
|
|
49
|
+
border: var(--input-field-border, 1px solid var(--md-sys-color-outline));
|
|
50
|
+
border-radius: var(--input-field-border-radius, var(--md-sys-shape-corner-small, 4px));
|
|
51
|
+
background: var(--input-field-background, var(--md-sys-color-surface-container-highest));
|
|
52
|
+
font: inherit;
|
|
53
|
+
font-size: var(--ui-t-body, 13px);
|
|
54
|
+
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
55
|
+
}
|
|
56
|
+
input:focus-visible {
|
|
57
|
+
outline: none;
|
|
58
|
+
border-color: var(--md-sys-color-primary);
|
|
59
|
+
}
|
|
60
|
+
ul {
|
|
61
|
+
position: absolute;
|
|
62
|
+
z-index: 10;
|
|
63
|
+
left: 0;
|
|
64
|
+
right: 0;
|
|
65
|
+
top: calc(100% + 2px);
|
|
66
|
+
max-height: 260px;
|
|
67
|
+
overflow-y: auto;
|
|
68
|
+
margin: 0;
|
|
69
|
+
padding: var(--spacing-small, 4px) 0;
|
|
70
|
+
list-style: none;
|
|
71
|
+
border: 1px solid var(--md-sys-color-outline-variant);
|
|
72
|
+
border-radius: var(--ui-r, 10px);
|
|
73
|
+
background: var(--md-sys-color-surface-container-lowest);
|
|
74
|
+
box-shadow: 0 6px 18px rgba(0, 0, 0, 0.12);
|
|
75
|
+
}
|
|
76
|
+
li {
|
|
77
|
+
display: flex;
|
|
78
|
+
justify-content: space-between;
|
|
79
|
+
gap: var(--spacing-large, 12px);
|
|
80
|
+
padding: 6px var(--spacing-large, 12px);
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
font-size: var(--ui-t-body, 13px);
|
|
83
|
+
color: var(--ui-ink, var(--md-sys-color-on-surface));
|
|
84
|
+
}
|
|
85
|
+
li:hover,
|
|
86
|
+
li[active] {
|
|
87
|
+
background: var(--md-sys-color-surface-container-high);
|
|
88
|
+
}
|
|
89
|
+
li small {
|
|
90
|
+
white-space: nowrap;
|
|
91
|
+
}
|
|
92
|
+
li small,
|
|
93
|
+
li.none {
|
|
94
|
+
color: var(--ui-muted, var(--md-sys-color-on-surface-variant));
|
|
95
|
+
}
|
|
96
|
+
li.none {
|
|
97
|
+
cursor: default;
|
|
98
|
+
}
|
|
99
|
+
li.register {
|
|
100
|
+
border-top: 1px solid var(--md-sys-color-outline-variant);
|
|
101
|
+
color: var(--ui-accent, var(--md-sys-color-primary));
|
|
102
|
+
}
|
|
103
|
+
`
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
/** The party chosen, shown as the field's placeholder until something is typed. */
|
|
107
|
+
@property({ attribute: false }) party: CounterpartyPick | null = null
|
|
108
|
+
@property({ type: Boolean }) disabled = false
|
|
109
|
+
|
|
110
|
+
@state() private search = ''
|
|
111
|
+
/** The words the list is found by - undefined while no list is open. */
|
|
112
|
+
@state() private finding?: string
|
|
113
|
+
@state() private active = 0
|
|
114
|
+
/** Whether this seat may register a counterparty - the action under the list shows only then. */
|
|
115
|
+
@state() private mayRegister = false
|
|
116
|
+
|
|
117
|
+
private timer?: ReturnType<typeof setTimeout>
|
|
118
|
+
/* A name was registered from here: the focus the form hands back does not open the list again - typing or a click does. */
|
|
119
|
+
private registering = false
|
|
120
|
+
|
|
121
|
+
/* The choices for the words found by - only the answer to the last thing typed is shown, and the list found before
|
|
122
|
+
stays while the next is read (ADR-0190). */
|
|
123
|
+
private choices = new QueryController(this, CHOICES, {
|
|
124
|
+
keepPrevious: true,
|
|
125
|
+
variables: () =>
|
|
126
|
+
this.finding === undefined || this.disabled ? undefined : { search: this.finding.trim() || undefined, pagination: { page: 1, limit: 30 } }
|
|
127
|
+
})
|
|
128
|
+
|
|
129
|
+
/** The list under the field: what was found, or null while it is closed or not read. */
|
|
130
|
+
async connectedCallback() {
|
|
131
|
+
super.connectedCallback()
|
|
132
|
+
this.mayRegister = await mayRegisterCounterparty()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** The words a new counterparty would be registered under - shown under the list when this seat may register. */
|
|
136
|
+
private get newName(): string {
|
|
137
|
+
return this.mayRegister && this.found ? this.search.trim() : ''
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private get found(): CounterpartyPick[] | null {
|
|
141
|
+
if (this.finding === undefined || !this.choices.data) return null
|
|
142
|
+
return this.choices.data.counterparties?.items ?? []
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
render() {
|
|
146
|
+
return html`
|
|
147
|
+
<div class="field">
|
|
148
|
+
<input
|
|
149
|
+
.value=${this.search}
|
|
150
|
+
placeholder=${this.party?.name ?? i18next.t('text.counterparty-search')}
|
|
151
|
+
aria-label=${i18next.t('field.counterparty')}
|
|
152
|
+
?disabled=${this.disabled}
|
|
153
|
+
@focus=${() => !this.registering && this.find()}
|
|
154
|
+
@mousedown=${() => (this.registering = false)}
|
|
155
|
+
@input=${(e: any) => ((this.registering = false), (this.search = e.target.value), this.findSoon())}
|
|
156
|
+
@keydown=${(e: KeyboardEvent) => this.key(e)}
|
|
157
|
+
@blur=${() => setTimeout(() => (this.finding = undefined), 150)}
|
|
158
|
+
/>
|
|
159
|
+
${this.party && !this.disabled
|
|
160
|
+
? html`<button quiet icon-only title=${i18next.t('button.counterparty-clear')} aria-label=${i18next.t('button.counterparty-clear')} @click=${() => this.choose(null)}>
|
|
161
|
+
<md-icon>close</md-icon>
|
|
162
|
+
</button>`
|
|
163
|
+
: nothing}
|
|
164
|
+
</div>
|
|
165
|
+
${this.found
|
|
166
|
+
? html`<ul role="listbox">
|
|
167
|
+
${this.found.length
|
|
168
|
+
? this.found.map(
|
|
169
|
+
(one, index) =>
|
|
170
|
+
html`<li role="option" ?active=${index === this.active} @mousedown=${(e: Event) => (e.preventDefault(), this.choose(one))}>
|
|
171
|
+
<span>${one.name}</span>${one.businessNumber ? html`<small>${one.businessNumber}</small>` : nothing}
|
|
172
|
+
</li>`
|
|
173
|
+
)
|
|
174
|
+
: html`<li class="none">${i18next.t('text.counterparty-none')}</li>`}
|
|
175
|
+
${this.newName
|
|
176
|
+
? html`<li role="option" class="register" ?active=${this.active === this.found.length} @mousedown=${(e: Event) => (e.preventDefault(), this.register())}>
|
|
177
|
+
<span>${i18next.t('button.counterparty-register-named', { name: this.newName })}</span>
|
|
178
|
+
</li>`
|
|
179
|
+
: nothing}
|
|
180
|
+
</ul>`
|
|
181
|
+
: nothing}
|
|
182
|
+
`
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private findSoon() {
|
|
186
|
+
clearTimeout(this.timer)
|
|
187
|
+
this.timer = setTimeout(() => this.find(), 250)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private find() {
|
|
191
|
+
if (this.disabled) return
|
|
192
|
+
this.finding = this.search
|
|
193
|
+
this.active = 0
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
private key(e: KeyboardEvent) {
|
|
197
|
+
const last = (this.found?.length ?? 0) + (this.newName ? 1 : 0) - 1
|
|
198
|
+
if (last < 0 || e.isComposing) return
|
|
199
|
+
if (e.key === 'ArrowDown') this.active = Math.min(this.active + 1, last)
|
|
200
|
+
else if (e.key === 'ArrowUp') this.active = Math.max(this.active - 1, 0)
|
|
201
|
+
else if (e.key === 'Enter') this.active < this.found!.length ? this.choose(this.found![this.active]) : this.register()
|
|
202
|
+
else if (e.key === 'Escape') this.finding = undefined
|
|
203
|
+
else return
|
|
204
|
+
e.preventDefault()
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/** Register the name typed and take it - or the counterparty of that name the form led to. */
|
|
208
|
+
private async register() {
|
|
209
|
+
const name = this.newName
|
|
210
|
+
this.finding = undefined
|
|
211
|
+
this.registering = true
|
|
212
|
+
const registered = await registerCounterparty(name)
|
|
213
|
+
if (registered) this.choose(registered)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
private choose(party: CounterpartyPick | null) {
|
|
217
|
+
this.search = ''
|
|
218
|
+
this.finding = undefined
|
|
219
|
+
this.dispatchEvent(new CustomEvent('counterparty', { detail: party, bubbles: true, composed: true }))
|
|
220
|
+
}
|
|
221
|
+
}
|
package/client/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export { CounterpartySelect } from './counterparty-select.js'
|
|
2
|
+
export { CounterpartyRegisterForm } from './counterparty-register-form.js'
|
|
3
|
+
export {
|
|
4
|
+
COUNTERPARTY_REGISTER_PRIVILEGE,
|
|
5
|
+
counterpartyCreatable,
|
|
6
|
+
mayRegisterCounterparty,
|
|
7
|
+
registerCounterparty,
|
|
8
|
+
type CounterpartyPick
|
|
9
|
+
} from './counterparty-register.js'
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import '@material/web/button/filled-button.js';
|
|
2
|
+
import '@material/web/button/text-button.js';
|
|
3
|
+
import '@operato/input/ox-input-select-buttons.js';
|
|
4
|
+
import '@operato/popup/ox-popup-actions.js';
|
|
5
|
+
import { LitElement } from 'lit';
|
|
6
|
+
declare const CounterpartyRegisterForm_base: (new (...args: any[]) => LitElement) & typeof LitElement;
|
|
7
|
+
/**
|
|
8
|
+
* 새 거래처 등록 - the short form a picker opens for a name it did not find (ADR-0195 decision 3): the name, the kind,
|
|
9
|
+
* and the business number and representative when known. Saved through `createCounterparty`, the counterparty screen's
|
|
10
|
+
* own checks. Fires `counterparty` with the one to take, `close` when given up.
|
|
11
|
+
*
|
|
12
|
+
* A name already a counterparty - its name or an alias, spaces and (주) aside - is not registered again: the form shows
|
|
13
|
+
* that one and offers only to take it (decision 4). A business of the same name is registered on the counterparty
|
|
14
|
+
* screen.
|
|
15
|
+
*
|
|
16
|
+
* The business number field is where a check with the public registries will sit (decision 7).
|
|
17
|
+
*/
|
|
18
|
+
export declare class CounterpartyRegisterForm extends CounterpartyRegisterForm_base {
|
|
19
|
+
static styles: import("lit").CSSResult[];
|
|
20
|
+
/** The name the picker was searched by - the form starts from it. */
|
|
21
|
+
name: string;
|
|
22
|
+
private kind;
|
|
23
|
+
private businessNumber;
|
|
24
|
+
private representative;
|
|
25
|
+
/** The name asked about - set once the person stops typing. */
|
|
26
|
+
private asked;
|
|
27
|
+
private timer?;
|
|
28
|
+
private sameNamed;
|
|
29
|
+
private save;
|
|
30
|
+
connectedCallback(): void;
|
|
31
|
+
/** What the name check says for the name now in the field. */
|
|
32
|
+
private get check();
|
|
33
|
+
private get registrable();
|
|
34
|
+
render(): import("lit-html").TemplateResult<1>;
|
|
35
|
+
private renderSameNamed;
|
|
36
|
+
private onName;
|
|
37
|
+
private register;
|
|
38
|
+
private take;
|
|
39
|
+
}
|
|
40
|
+
export {};
|