From 599398295eaa28fce2d209cb9a31ff1cd0ac5c9b Mon Sep 17 00:00:00 2001
From: Florian Spreckelsen <f.spreckelsen@indiscale.com>
Date: Mon, 23 Sep 2024 16:28:44 +0200
Subject: [PATCH] FIX: Don't add file-upload button to new properties
 immediatly

---
 src/core/js/fileupload.js | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)

diff --git a/src/core/js/fileupload.js b/src/core/js/fileupload.js
index c6d133de..cd272117 100644
--- a/src/core/js/fileupload.js
+++ b/src/core/js/fileupload.js
@@ -261,24 +261,29 @@ var fileupload = new function() {
     }
 
     this.init = function() {
-	if ("${BUILD_EDIT_MODE_LAZY_DROPDOWN_LOADING}" == "ENABLED") {
+        if ("${BUILD_EDIT_MODE_LAZY_DROPDOWN_LOADING}" == "ENABLED") {
+            // If we have to manually enable editting of reference
+            // properties, we only want to add the file-upload button
+            // **after** we started editing the particular
+            // property. So no global event listener and not
+            // immediatly after adding a new reference property.
             document.body.addEventListener(edit_mode.property_edit_reference_value.type, function(e) {
-		fileupload.create_upload_app(e.target);
-	    }, true);
-	} else {
-	    // add global listener for start_edit event
+                fileupload.create_upload_app(e.target);
+            }, true);
+        } else {
+            // add global listener for start_edit event
             document.body.addEventListener(edit_mode.start_edit.type, function(e) {
-		$(e.target).find(".caosdb-properties .caosdb-f-entity-property").each(function(idx) {
+                $(e.target).find(".caosdb-properties .caosdb-f-entity-property").each(function(idx) {
                     fileupload.create_upload_app(this);
-		});
+                });
             }, true);
-	}
 
-        // add global listener for property_added event
-        document.body.addEventListener(edit_mode.property_added.type, function(e) {
-            fileupload.create_upload_app(e.target);
-        }, true);
+            // add global listener for property_added event
+            document.body.addEventListener(edit_mode.property_added.type, function(e) {
+                fileupload.create_upload_app(e.target);
+            }, true);
 
+        }
 
         // add global listener for data_type_changed event
         document.body.addEventListener(edit_mode.property_data_type_changed.type, function(e) {
@@ -302,7 +307,7 @@ var fileupload = new function() {
     this.create_upload_app = function(target) {
         const non_file_datatypes = ["TEXT", "DOUBLE", "BOOLEAN", "INTEGER", "DATETIME"];
         var par = getPropertyDatatype(target);
-        var atom_par = par && par.startsWith("LIST<") && par.endsWith(">") ? par.substring(5, par.length-1) : par;
+        var atom_par = par && par.startsWith("LIST<") && par.endsWith(">") ? par.substring(5, par.length - 1) : par;
 
         if (non_file_datatypes.indexOf(atom_par) !== -1) {
             return;
@@ -344,7 +349,7 @@ var fileupload = new function() {
      */
     this.get_default_path = function() {
         var by = "unauthenticated/";
-        if(isAuthenticated()) {
+        if (isAuthenticated()) {
             by = getUserRealm() + "/" + getUserName() + "/";
         }
         return "/uploaded.by/" + by + fileupload.uuidv4() + "/";
-- 
GitLab