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 { ...@@ -17,6 +17,7 @@ class PersonSelect extends VPULitElementJQuery {
this.lang = 'de'; this.lang = 'de';
this.entryPointUrl = utils.getAPiUrl(); this.entryPointUrl = utils.getAPiUrl();
this.jsonld = null; this.jsonld = null;
this.$select = null;
} }
static get properties() { static get properties() {
...@@ -31,17 +32,7 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -31,17 +32,7 @@ class PersonSelect extends VPULitElementJQuery {
const that = this; const that = this;
this.updateComplete.then(()=>{ this.updateComplete.then(()=>{
JSONLD.initialize(this.entryPointUrl, function (jsonld) { that.$select = that.$('#person-select');
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);
});
});
}) })
} }
...@@ -63,13 +54,11 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -63,13 +54,11 @@ class PersonSelect extends VPULitElementJQuery {
"text": "http://schema.org/name" "text": "http://schema.org/name"
}; };
const $select = this.$('#person-select'); if (this.$select.hasClass('select2-hidden-accessible')) {
this.$select.select2('destroy');
if ($select.hasClass('select2-hidden-accessible')) {
$select.select2('destroy');
} }
$select.select2({ this.$select.select2({
width: '100%', width: '100%',
language: this.lang === "de" ? select2LangDe() : select2LangEn(), language: this.lang === "de" ? select2LangDe() : select2LangEn(),
minimumInputLength: 2, minimumInputLength: 2,
...@@ -120,20 +109,35 @@ class PersonSelect extends VPULitElementJQuery { ...@@ -120,20 +109,35 @@ class PersonSelect extends VPULitElementJQuery {
})); }));
}); });
return $select; return this.$select;
} }
update(changedProperties) { update(changedProperties) {
changedProperties.forEach((oldValue, propName) => { changedProperties.forEach((oldValue, propName) => {
if (propName === "lang") { switch (propName) {
case "lang":
i18n.changeLanguage(this.lang); i18n.changeLanguage(this.lang);
const $select = this.$('#person-select.select2-hidden-accessible'); if (this.$select !== null && this.$select.hasClass("select2-hidden-accessible")) {
if ($select.length > 0) {
// no other way to set an other language at runtime did work // no other way to set an other language at runtime did work
this.initSelect2(); 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.
Please register or to comment