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

Implement support for changing entry-point-url attribute at runtime

parent b5f5dbcd
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,7 @@ class PersonSelect extends VPULitElementJQuery {
this.lang = 'de';
this.entryPointUrl = utils.getAPiUrl();
this.jsonld = null;
this.$select = null;
}
static get properties() {
......@@ -31,17 +32,7 @@ class PersonSelect extends VPULitElementJQuery {
const that = this;
this.updateComplete.then(()=>{
JSONLD.initialize(this.entryPointUrl, function (jsonld) {
that.jsonld = jsonld;
const $select = that.initSelect2();
// close the selector on blur of the web component
$(that).blur(() => {
// the 500ms delay is a workaround to actually get an item selected when clicking on it,
// because the blur gets also fired when clicking in the selector
setTimeout(() => {$select.select2('close')}, 500);
});
});
that.$select = that.$('#person-select');
})
}
......@@ -63,13 +54,11 @@ class PersonSelect extends VPULitElementJQuery {
"text": "http://schema.org/name"
};
const $select = this.$('#person-select');
if ($select.hasClass('select2-hidden-accessible')) {
$select.select2('destroy');
if (this.$select.hasClass('select2-hidden-accessible')) {
this.$select.select2('destroy');
}
$select.select2({
this.$select.select2({
width: '100%',
language: this.lang === "de" ? select2LangDe() : select2LangEn(),
minimumInputLength: 2,
......@@ -120,20 +109,35 @@ class PersonSelect extends VPULitElementJQuery {
}));
});
return $select;
return this.$select;
}
update(changedProperties) {
changedProperties.forEach((oldValue, propName) => {
if (propName === "lang") {
i18n.changeLanguage(this.lang);
const $select = this.$('#person-select.select2-hidden-accessible');
if ($select.length > 0) {
// no other way to set an other language at runtime did work
this.initSelect2();
}
switch (propName) {
case "lang":
i18n.changeLanguage(this.lang);
if (this.$select !== null && this.$select.hasClass("select2-hidden-accessible")) {
// no other way to set an other language at runtime did work
this.initSelect2();
}
break;
case "entryPointUrl":
const that = this;
JSONLD.initialize(this.entryPointUrl, function (jsonld) {
that.jsonld = jsonld;
that.$select = that.initSelect2();
// close the selector on blur of the web component
$(that).blur(() => {
// the 500ms delay is a workaround to actually get an item selected when clicking on it,
// because the blur gets also fired when clicking in the selector
setTimeout(() => {that.$select.select2('close')}, 500);
});
});
break;
}
});
......
common @ 08f98d94
Subproject commit 45e52fbec09bf05c7e287703fc78b3040af69ac7
Subproject commit 08f98d949388649606fa5e5b08b750aeb24a4af7
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