From d184ded2b4c0c2c731b5a575c0baa8e1e97b6ad7 Mon Sep 17 00:00:00 2001
From: Patrizio Bekerle <patrizio.bekerle@tugraz.at>
Date: Tue, 6 Aug 2019 11:16:55 +0200
Subject: [PATCH] Implement support for changing entry-point-url attribute at
 runtime

---
 packages/person-select/src/person-select.js | 56 +++++++++++----------
 packages/person-select/vendor/common        |  2 +-
 2 files changed, 31 insertions(+), 27 deletions(-)

diff --git a/packages/person-select/src/person-select.js b/packages/person-select/src/person-select.js
index be09fd0e..088ac456 100644
--- a/packages/person-select/src/person-select.js
+++ b/packages/person-select/src/person-select.js
@@ -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;
             }
         });
 
diff --git a/packages/person-select/vendor/common b/packages/person-select/vendor/common
index 45e52fbe..08f98d94 160000
--- a/packages/person-select/vendor/common
+++ b/packages/person-select/vendor/common
@@ -1 +1 @@
-Subproject commit 45e52fbec09bf05c7e287703fc78b3040af69ac7
+Subproject commit 08f98d949388649606fa5e5b08b750aeb24a4af7
-- 
GitLab