Skip to content
Snippets Groups Projects
Commit 6e27a481 authored by Bekerle, Patrizio's avatar Bekerle, Patrizio :fire: Committed by Reiter, Christoph
Browse files

Allow presetting of value

parent 0f3d9a69
No related branches found
No related tags found
No related merge requests found
...@@ -9,6 +9,7 @@ import {i18n} from './i18n.js'; ...@@ -9,6 +9,7 @@ import {i18n} from './i18n.js';
import VPULitElementJQuery from 'vpu-common/vpu-lit-element-jquery'; import VPULitElementJQuery from 'vpu-common/vpu-lit-element-jquery';
import * as commonUtils from 'vpu-common/utils'; import * as commonUtils from 'vpu-common/utils';
import select2CSSPath from 'select2/dist/css/select2.min.css'; import select2CSSPath from 'select2/dist/css/select2.min.css';
import {send as notify} from "vpu-common/notification";
select2(window, $); select2(window, $);
...@@ -24,6 +25,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -24,6 +25,7 @@ class PersonSelect extends VPULitElementJQuery {
this.active = false; this.active = false;
// For some reason using the same ID on the whole page twice breaks select2 (regardless if they are in different custom elements) // For some reason using the same ID on the whole page twice breaks select2 (regardless if they are in different custom elements)
this.selectId = 'person-select-' + commonUtils.makeId(24); this.selectId = 'person-select-' + commonUtils.makeId(24);
this.value = '';
} }
static get properties() { static get properties() {
...@@ -31,6 +33,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -31,6 +33,7 @@ class PersonSelect extends VPULitElementJQuery {
lang: { type: String }, lang: { type: String },
active: { type: Boolean, attribute: false }, active: { type: Boolean, attribute: false },
entryPointUrl: { type: String, attribute: 'entry-point-url' }, entryPointUrl: { type: String, attribute: 'entry-point-url' },
value: { type: String },
}; };
} }
...@@ -139,6 +142,36 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -139,6 +142,36 @@ class PersonSelect extends VPULitElementJQuery {
})); }));
}); });
// preset a person
if (this.value !== '') {
const apiUrl = this.entryPointUrl + this.value;
fetch(apiUrl, {
headers: {
'Content-Type': 'application/ld+json',
'Authorization': 'Bearer ' + window.VPUAuthToken,
},
})
.then(result => {
if (!result.ok) throw result;
return result.json();
})
.then((person) => {
const identifier = person["@id"];
const option = new Option(person.name, identifier, true, true);
$this.attr("data-object", JSON.stringify(person));
that.$select.append(option).trigger('change');
// fire a change event
that.dispatchEvent(new CustomEvent('change', {
detail: {
value: identifier,
},
bubbles: true
}));
}).catch(() => {});
}
return this.$select; return this.$select;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment