@things-factory/contact 10.1.256 → 10.1.257

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.
@@ -2,7 +2,7 @@ import '@material/web/icon/icon.js';
2
2
  import '@operato/contact/ox-contact-view.js';
3
3
  import '@operato/contact/ox-contact-edit.js';
4
4
  import '@operato/app/selector/ox-selector-resource-object.js';
5
- import { LitElement, PropertyValues } from 'lit';
5
+ import { LitElement } from 'lit';
6
6
  import { Contact } from '@operato/contact/ox-contact.js';
7
7
  import { OxContactEdit } from '@operato/contact/ox-contact-edit.js';
8
8
  export declare class ContactPopup extends LitElement {
@@ -11,13 +11,14 @@ export declare class ContactPopup extends LitElement {
11
11
  editMode?: boolean;
12
12
  detachable?: boolean;
13
13
  closeCallback?: (contact?: Contact | null) => void;
14
- contact: Contact;
14
+ private read;
15
+ get contact(): Contact;
16
+ private updating;
17
+ private creating;
15
18
  editor: OxContactEdit;
16
19
  render(): import("lit-html").TemplateResult<1>;
17
20
  private pickCounterparty;
18
21
  onClose(): void;
19
- updated(changes: PropertyValues<this>): void;
20
- fetchContact(): Promise<void>;
21
22
  /** Whether the contact was kept. A refusal is reported by the client; the editor keeps what was typed. */
22
23
  updateContact(contact: Contact): Promise<boolean>;
23
24
  }
@@ -4,9 +4,9 @@ import '@operato/contact/ox-contact-view.js';
4
4
  import '@operato/contact/ox-contact-edit.js';
5
5
  import '@operato/app/selector/ox-selector-resource-object.js';
6
6
  import { html, css, LitElement } from 'lit';
7
- import { customElement, property, query, state } from 'lit/decorators.js';
7
+ import { customElement, property, query } from 'lit/decorators.js';
8
8
  import gql from 'graphql-tag';
9
- import { client } from '@operato/graphql';
9
+ import { MutationController, QueryController } from '@operato/graphql';
10
10
  import { openPopup } from '@operato/layout';
11
11
  import { i18next } from '@operato/i18n';
12
12
  import { CommonHeaderStyles, ScrollbarStyles } from '@operato/styles';
@@ -16,7 +16,88 @@ let ContactPopup = class ContactPopup extends LitElement {
16
16
  super(...arguments);
17
17
  this.editMode = false;
18
18
  this.detachable = false;
19
- this.contact = {};
19
+ /* The contact the popup was opened for (ADR-0190). */
20
+ this.read = new QueryController(this, gql `
21
+ query ($id: String!) {
22
+ contact(id: $id) {
23
+ id
24
+ name
25
+ counterparty {
26
+ id
27
+ name
28
+ }
29
+ department
30
+ email
31
+ phone
32
+ address
33
+ note
34
+ items {
35
+ type
36
+ label
37
+ value
38
+ }
39
+ profile {
40
+ left
41
+ top
42
+ zoom
43
+ picture
44
+ }
45
+ }
46
+ }
47
+ `, { variables: () => (this.contactId ? { id: this.contactId } : undefined) });
48
+ this.updating = new MutationController(this, gql `
49
+ mutation ($id: String!, $patch: ContactPatch!) {
50
+ contact: updateContact(id: $id, patch: $patch) {
51
+ id
52
+ name
53
+ counterparty {
54
+ id
55
+ name
56
+ }
57
+ email
58
+ phone
59
+ note
60
+ items {
61
+ label
62
+ type
63
+ value
64
+ }
65
+ profile {
66
+ left
67
+ top
68
+ zoom
69
+ picture
70
+ }
71
+ }
72
+ }
73
+ `, { context: { hasUpload: true }, refetch: () => [this.read] });
74
+ /* A new contact: the popup goes on with it, read by its id. */
75
+ this.creating = new MutationController(this, gql `
76
+ mutation ($contact: NewContact!) {
77
+ contact: createContact(contact: $contact) {
78
+ id
79
+ name
80
+ counterparty {
81
+ id
82
+ name
83
+ }
84
+ email
85
+ phone
86
+ note
87
+ items {
88
+ label
89
+ type
90
+ value
91
+ }
92
+ profile {
93
+ left
94
+ top
95
+ zoom
96
+ picture
97
+ }
98
+ }
99
+ }
100
+ `, { context: { hasUpload: true } });
20
101
  /* The counterparty is one of the domain's counterparties (biz-base), picked with the selector every reference column opens. */
21
102
  this.pickCounterparty = (current) => new Promise(resolve => {
22
103
  let picked;
@@ -56,6 +137,9 @@ let ContactPopup = class ContactPopup extends LitElement {
56
137
  }
57
138
  `
58
139
  ]; }
140
+ get contact() {
141
+ return this.read.data?.contact ?? {};
142
+ }
59
143
  render() {
60
144
  return html `
61
145
  <div content>
@@ -111,128 +195,16 @@ let ContactPopup = class ContactPopup extends LitElement {
111
195
  this.closeCallback && this.closeCallback(this.contact?.id ? this.contact : null);
112
196
  history.back();
113
197
  }
114
- updated(changes) {
115
- if (changes.has('contactId') && this.contactId) {
116
- this.fetchContact();
117
- }
118
- }
119
- async fetchContact() {
120
- const response = await client.query({
121
- query: gql `
122
- query ($id: String!) {
123
- contact(id: $id) {
124
- id
125
- name
126
- counterparty {
127
- id
128
- name
129
- }
130
- department
131
- email
132
- phone
133
- address
134
- note
135
- items {
136
- type
137
- label
138
- value
139
- }
140
- profile {
141
- left
142
- top
143
- zoom
144
- picture
145
- }
146
- }
147
- }
148
- `,
149
- variables: {
150
- id: this.contactId
151
- }
152
- });
153
- this.contact = response.data.contact;
154
- }
155
198
  /** Whether the contact was kept. A refusal is reported by the client; the editor keeps what was typed. */
156
199
  async updateContact(contact) {
157
- if (contact.id) {
158
- var { id, ...patch } = contact;
159
- var response = await client.mutate({
160
- mutation: gql `
161
- mutation ($id: String!, $patch: ContactPatch!) {
162
- contact: updateContact(id: $id, patch: $patch) {
163
- id
164
- name
165
- counterparty {
166
- id
167
- name
168
- }
169
- email
170
- phone
171
- note
172
- items {
173
- label
174
- type
175
- value
176
- }
177
- profile {
178
- left
179
- top
180
- zoom
181
- picture
182
- }
183
- }
184
- }
185
- `,
186
- variables: {
187
- id,
188
- patch
189
- },
190
- context: {
191
- hasUpload: true
192
- }
193
- });
194
- }
195
- else {
196
- var response = await client.mutate({
197
- mutation: gql `
198
- mutation ($contact: NewContact!) {
199
- contact: createContact(contact: $contact) {
200
- id
201
- name
202
- counterparty {
203
- id
204
- name
205
- }
206
- email
207
- phone
208
- note
209
- items {
210
- label
211
- type
212
- value
213
- }
214
- profile {
215
- left
216
- top
217
- zoom
218
- picture
219
- }
220
- }
221
- }
222
- `,
223
- variables: {
224
- contact
225
- },
226
- context: {
227
- hasUpload: true
228
- }
229
- });
230
- }
231
- if (response.errors?.length || !response.data?.contact)
200
+ const { id, ...patch } = contact;
201
+ const saved = id ? await this.updating.run({ id, patch }) : await this.creating.run({ contact });
202
+ if (!saved?.contact)
232
203
  return false;
233
- this.contact = response.data.contact;
204
+ if (!id)
205
+ this.contactId = saved.contact.id;
234
206
  this.dispatchEvent(new CustomEvent('change', {
235
- detail: this.contact
207
+ detail: saved.contact
236
208
  }));
237
209
  return true;
238
210
  }
@@ -253,10 +225,6 @@ __decorate([
253
225
  property({ type: Object }),
254
226
  __metadata("design:type", Function)
255
227
  ], ContactPopup.prototype, "closeCallback", void 0);
256
- __decorate([
257
- state(),
258
- __metadata("design:type", Object)
259
- ], ContactPopup.prototype, "contact", void 0);
260
228
  __decorate([
261
229
  query('ox-contact-edit'),
262
230
  __metadata("design:type", OxContactEdit)
@@ -1 +1 @@
1
- {"version":3,"file":"contact-popup.js","sourceRoot":"","sources":["../../client/components/contact-popup.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,qCAAqC,CAAA;AAC5C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,sDAAsD,CAAA;AAE7D,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAkB,MAAM,KAAK,CAAA;AAC3D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AACzE,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AAEzC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAG5D,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,UAAU;IAArC;;QAqBgD,aAAQ,GAAa,KAAK,CAAA;QAClD,eAAU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,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC;gBACjC,QAAQ,EAAE,GAAG,CAAA;;;;;;;;;;;;;;;;;;;;;;;;;SAyBZ;gBACD,SAAS,EAAE;oBACT,OAAO;iBACR;gBACD,OAAO,EAAE;oBACP,SAAS,EAAE,IAAI;iBAChB;aACF,CAAC,CAAA;QACJ,CAAC;QAED,IAAI,QAAQ,CAAC,MAAM,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,IAAI,EAAE,OAAO;YAAE,OAAO,KAAK,CAAA;QAEpE,IAAI,CAAC,OAAO,GAAG,QAAQ,CAAC,IAAI,CAAC,OAAO,CAAA;QAEpC,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,QAAQ,EAAE;YACxB,MAAM,EAAE,IAAI,CAAC,OAAO;SACrB,CAAC,CACH,CAAA;QACD,OAAO,IAAI,CAAA;IACb,CAAC;;AA9N2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;+CAAmB;AACO;IAApD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;;8CAA2B;AAClD;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;gDAA6B;AAC7B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mDAAmD;AAErE;IAAR,KAAK,EAAE;;6CAAsB;AAEJ;IAAzB,KAAK,CAAC,iBAAiB,CAAC;8BAAU,aAAa;4CAAA;AA3BrC,YAAY;IADxB,aAAa,CAAC,eAAe,CAAC;GAClB,YAAY,CAmPxB","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@operato/contact/ox-contact-view.js'\nimport '@operato/contact/ox-contact-edit.js'\nimport '@operato/app/selector/ox-selector-resource-object.js'\n\nimport { html, css, LitElement, PropertyValues } from 'lit'\nimport { customElement, property, query, state } from 'lit/decorators.js'\nimport gql from 'graphql-tag'\n\nimport { client } from '@operato/graphql'\nimport { Contact, ContactCounterparty } from '@operato/contact/ox-contact.js'\nimport { openPopup } from '@operato/layout'\nimport { i18next } from '@operato/i18n'\nimport { CommonHeaderStyles, ScrollbarStyles } from '@operato/styles'\nimport { OxContactEdit } from '@operato/contact/ox-contact-edit.js'\n\n@customElement('contact-popup')\nexport class ContactPopup extends LitElement {\n static styles = [\n ScrollbarStyles,\n CommonHeaderStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n color: var(--popup-content-color);\n background-color: var(--popup-content-background-color);\n }\n\n [content] {\n flex: 1;\n padding: var(--spacing-medium);\n overflow: auto;\n }\n `\n ]\n\n @property({ type: String }) contactId?: string\n @property({ type: Boolean, attribute: 'edit-mode' }) editMode?: boolean = false\n @property({ type: Boolean }) detachable?: boolean = false\n @property({ type: Object }) closeCallback?: (contact?: Contact | null) => void\n\n @state() contact: Contact = {}\n\n @query('ox-contact-edit') editor!: OxContactEdit\n\n render() {\n return html`\n <div content>\n ${this.editMode\n ? html`<ox-contact-edit\n .contact=${this.contact}\n .pickCounterparty=${this.pickCounterparty}\n @edit-cancel=${() => (this.editMode = false)}\n @edit-done=${async (e: CustomEvent) => {\n /* The editor stays open with what was typed until the save is kept - the client reports why it was not. */\n if (await this.updateContact(e.detail)) this.editMode = false\n }}\n ></ox-contact-edit>`\n : html` <ox-contact-view .contact=${this.contact}></ox-contact-view>`}\n </div>\n\n <div class=\"footer\">\n ${!this.editMode\n ? html`\n ${this.detachable\n ? html`\n <button\n danger\n @click=${() => {\n this.dispatchEvent(new CustomEvent('detach'))\n history.back()\n }}\n >\n <md-icon>link_off</md-icon>\n ${i18next.t('button.detach')}\n </button>\n `\n : html``}\n <div filler></div>\n <button @click=${() => (this.editMode = true)}><md-icon>edit</md-icon>${i18next.t('button.edit')}</button>\n <button @click=${this.onClose} ok><md-icon>close</md-icon>${i18next.t('button.close')}</button>\n `\n : html`\n <button @click=${() => this.editor.reset()}>\n <md-icon>restart_alt</md-icon>${i18next.t('button.reset')}\n </button>\n <div filler></div>\n <button @click=${() => this.editor.cancel()}>\n <md-icon>cancel</md-icon>${i18next.t('button.cancel')}\n </button>\n <button @click=${() => this.editor.save()} ok><md-icon>save</md-icon>${i18next.t('button.save')}</button>\n `}\n </div>\n `\n }\n\n /* The counterparty is one of the domain's counterparties (biz-base), picked with the selector every reference column opens. */\n private pickCounterparty = (current?: ContactCounterparty | null) =>\n new Promise<ContactCounterparty | null | undefined>(resolve => {\n let picked: ContactCounterparty | null | undefined\n const popup = openPopup(\n html`<ox-selector-resource-object\n .value=${current?.id ?? ''}\n .queryName=${'counterparties'}\n .columns=${[\n { name: 'id', hidden: true },\n { name: 'name', header: i18next.t('field.counterparty'), filter: 'search' }\n ]}\n .confirmCallback=${(selected?: any) => (picked = selected ? { id: selected.id, name: selected.name } : null)}\n ></ox-selector-resource-object>`,\n {\n backdrop: true,\n size: 'large',\n title: i18next.t('field.counterparty'),\n search: { autofocus: true, handler: (instance: any, value: string) => instance.searchText(value) }\n }\n )\n /* Closed without a choice: undefined, and the contact keeps its counterparty. */\n popup.onclosed = () => resolve(picked)\n })\n\n onClose() {\n this.closeCallback && this.closeCallback(this.contact?.id ? this.contact : null)\n\n history.back()\n }\n\n updated(changes: PropertyValues<this>) {\n if (changes.has('contactId') && this.contactId) {\n this.fetchContact()\n }\n }\n\n async fetchContact() {\n const response = await client.query({\n query: gql`\n query ($id: String!) {\n contact(id: $id) {\n id\n name\n counterparty {\n id\n name\n }\n department\n email\n phone\n address\n note\n items {\n type\n label\n value\n }\n profile {\n left\n top\n zoom\n picture\n }\n }\n }\n `,\n variables: {\n id: this.contactId\n }\n })\n\n this.contact = response.data.contact\n }\n\n /** Whether the contact was kept. A refusal is reported by the client; the editor keeps what was typed. */\n async updateContact(contact: Contact): Promise<boolean> {\n if (contact.id) {\n var { id, ...patch } = contact\n\n var response = await client.mutate({\n mutation: gql`\n mutation ($id: String!, $patch: ContactPatch!) {\n contact: updateContact(id: $id, patch: $patch) {\n id\n name\n counterparty {\n id\n name\n }\n email\n phone\n note\n items {\n label\n type\n value\n }\n profile {\n left\n top\n zoom\n picture\n }\n }\n }\n `,\n variables: {\n id,\n patch\n },\n context: {\n hasUpload: true\n }\n })\n } else {\n var response = await client.mutate({\n mutation: gql`\n mutation ($contact: NewContact!) {\n contact: createContact(contact: $contact) {\n id\n name\n counterparty {\n id\n name\n }\n email\n phone\n note\n items {\n label\n type\n value\n }\n profile {\n left\n top\n zoom\n picture\n }\n }\n }\n `,\n variables: {\n contact\n },\n context: {\n hasUpload: true\n }\n })\n }\n\n if (response.errors?.length || !response.data?.contact) return false\n\n this.contact = response.data.contact\n\n this.dispatchEvent(\n new CustomEvent('change', {\n detail: this.contact\n })\n )\n return true\n }\n}\n"]}
1
+ {"version":3,"file":"contact-popup.js","sourceRoot":"","sources":["../../client/components/contact-popup.ts"],"names":[],"mappings":";AAAA,OAAO,4BAA4B,CAAA;AACnC,OAAO,qCAAqC,CAAA;AAC5C,OAAO,qCAAqC,CAAA;AAC5C,OAAO,sDAAsD,CAAA;AAE7D,OAAO,EAAE,IAAI,EAAE,GAAG,EAAE,UAAU,EAAE,MAAM,KAAK,CAAA;AAC3C,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAA;AAClE,OAAO,GAAG,MAAM,aAAa,CAAA;AAE7B,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAEtE,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AACvC,OAAO,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACrE,OAAO,EAAE,aAAa,EAAE,MAAM,qCAAqC,CAAA;AAG5D,IAAM,YAAY,GAAlB,MAAM,YAAa,SAAQ,UAAU;IAArC;;QAqBgD,aAAQ,GAAa,KAAK,CAAA;QAClD,eAA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ChC,MAAM,KAAK,GAAG,EAAE,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,CAAC,CAAA;QAChG,IAAI,CAAC,KAAK,EAAE,OAAO;YAAE,OAAO,KAAK,CAAA;QAEjC,IAAI,CAAC,EAAE;YAAE,IAAI,CAAC,SAAS,GAAG,KAAK,CAAC,OAAO,CAAC,EAAE,CAAA;QAE1C,IAAI,CAAC,aAAa,CAChB,IAAI,WAAW,CAAC,QAAQ,EAAE;YACxB,MAAM,EAAE,KAAK,CAAC,OAAO;SACtB,CAAC,CACH,CAAA;QACD,OAAO,IAAI,CAAA;IACb,CAAC;;AA5M2B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;+CAAmB;AACO;IAApD,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC;;8CAA2B;AAClD;IAA5B,QAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC;;gDAA6B;AAC7B;IAA3B,QAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC;;mDAAmD;AAuGpD;IAAzB,KAAK,CAAC,iBAAiB,CAAC;8BAAU,aAAa;4CAAA;AA9HrC,YAAY;IADxB,aAAa,CAAC,eAAe,CAAC;GAClB,YAAY,CAiOxB","sourcesContent":["import '@material/web/icon/icon.js'\nimport '@operato/contact/ox-contact-view.js'\nimport '@operato/contact/ox-contact-edit.js'\nimport '@operato/app/selector/ox-selector-resource-object.js'\n\nimport { html, css, LitElement } from 'lit'\nimport { customElement, property, query } from 'lit/decorators.js'\nimport gql from 'graphql-tag'\n\nimport { MutationController, QueryController } from '@operato/graphql'\nimport { Contact, ContactCounterparty } from '@operato/contact/ox-contact.js'\nimport { openPopup } from '@operato/layout'\nimport { i18next } from '@operato/i18n'\nimport { CommonHeaderStyles, ScrollbarStyles } from '@operato/styles'\nimport { OxContactEdit } from '@operato/contact/ox-contact-edit.js'\n\n@customElement('contact-popup')\nexport class ContactPopup extends LitElement {\n static styles = [\n ScrollbarStyles,\n CommonHeaderStyles,\n css`\n :host {\n display: flex;\n flex-direction: column;\n color: var(--popup-content-color);\n background-color: var(--popup-content-background-color);\n }\n\n [content] {\n flex: 1;\n padding: var(--spacing-medium);\n overflow: auto;\n }\n `\n ]\n\n @property({ type: String }) contactId?: string\n @property({ type: Boolean, attribute: 'edit-mode' }) editMode?: boolean = false\n @property({ type: Boolean }) detachable?: boolean = false\n @property({ type: Object }) closeCallback?: (contact?: Contact | null) => void\n\n /* The contact the popup was opened for (ADR-0190). */\n private read = new QueryController(\n this,\n gql`\n query ($id: String!) {\n contact(id: $id) {\n id\n name\n counterparty {\n id\n name\n }\n department\n email\n phone\n address\n note\n items {\n type\n label\n value\n }\n profile {\n left\n top\n zoom\n picture\n }\n }\n }\n `,\n { variables: () => (this.contactId ? { id: this.contactId } : undefined) }\n )\n\n get contact(): Contact {\n return this.read.data?.contact ?? {}\n }\n\n private updating = new MutationController(\n this,\n gql`\n mutation ($id: String!, $patch: ContactPatch!) {\n contact: updateContact(id: $id, patch: $patch) {\n id\n name\n counterparty {\n id\n name\n }\n email\n phone\n note\n items {\n label\n type\n value\n }\n profile {\n left\n top\n zoom\n picture\n }\n }\n }\n `,\n { context: { hasUpload: true }, refetch: () => [this.read] }\n )\n\n /* A new contact: the popup goes on with it, read by its id. */\n private creating = new MutationController(\n this,\n gql`\n mutation ($contact: NewContact!) {\n contact: createContact(contact: $contact) {\n id\n name\n counterparty {\n id\n name\n }\n email\n phone\n note\n items {\n label\n type\n value\n }\n profile {\n left\n top\n zoom\n picture\n }\n }\n }\n `,\n { context: { hasUpload: true } }\n )\n\n @query('ox-contact-edit') editor!: OxContactEdit\n\n render() {\n return html`\n <div content>\n ${this.editMode\n ? html`<ox-contact-edit\n .contact=${this.contact}\n .pickCounterparty=${this.pickCounterparty}\n @edit-cancel=${() => (this.editMode = false)}\n @edit-done=${async (e: CustomEvent) => {\n /* The editor stays open with what was typed until the save is kept - the client reports why it was not. */\n if (await this.updateContact(e.detail)) this.editMode = false\n }}\n ></ox-contact-edit>`\n : html` <ox-contact-view .contact=${this.contact}></ox-contact-view>`}\n </div>\n\n <div class=\"footer\">\n ${!this.editMode\n ? html`\n ${this.detachable\n ? html`\n <button\n danger\n @click=${() => {\n this.dispatchEvent(new CustomEvent('detach'))\n history.back()\n }}\n >\n <md-icon>link_off</md-icon>\n ${i18next.t('button.detach')}\n </button>\n `\n : html``}\n <div filler></div>\n <button @click=${() => (this.editMode = true)}><md-icon>edit</md-icon>${i18next.t('button.edit')}</button>\n <button @click=${this.onClose} ok><md-icon>close</md-icon>${i18next.t('button.close')}</button>\n `\n : html`\n <button @click=${() => this.editor.reset()}>\n <md-icon>restart_alt</md-icon>${i18next.t('button.reset')}\n </button>\n <div filler></div>\n <button @click=${() => this.editor.cancel()}>\n <md-icon>cancel</md-icon>${i18next.t('button.cancel')}\n </button>\n <button @click=${() => this.editor.save()} ok><md-icon>save</md-icon>${i18next.t('button.save')}</button>\n `}\n </div>\n `\n }\n\n /* The counterparty is one of the domain's counterparties (biz-base), picked with the selector every reference column opens. */\n private pickCounterparty = (current?: ContactCounterparty | null) =>\n new Promise<ContactCounterparty | null | undefined>(resolve => {\n let picked: ContactCounterparty | null | undefined\n const popup = openPopup(\n html`<ox-selector-resource-object\n .value=${current?.id ?? ''}\n .queryName=${'counterparties'}\n .columns=${[\n { name: 'id', hidden: true },\n { name: 'name', header: i18next.t('field.counterparty'), filter: 'search' }\n ]}\n .confirmCallback=${(selected?: any) => (picked = selected ? { id: selected.id, name: selected.name } : null)}\n ></ox-selector-resource-object>`,\n {\n backdrop: true,\n size: 'large',\n title: i18next.t('field.counterparty'),\n search: { autofocus: true, handler: (instance: any, value: string) => instance.searchText(value) }\n }\n )\n /* Closed without a choice: undefined, and the contact keeps its counterparty. */\n popup.onclosed = () => resolve(picked)\n })\n\n onClose() {\n this.closeCallback && this.closeCallback(this.contact?.id ? this.contact : null)\n\n history.back()\n }\n\n /** Whether the contact was kept. A refusal is reported by the client; the editor keeps what was typed. */\n async updateContact(contact: Contact): Promise<boolean> {\n const { id, ...patch } = contact\n const saved = id ? await this.updating.run({ id, patch }) : await this.creating.run({ contact })\n if (!saved?.contact) return false\n\n if (!id) this.contactId = saved.contact.id\n\n this.dispatchEvent(\n new CustomEvent('change', {\n detail: saved.contact\n })\n )\n return true\n }\n}\n"]}