From 23e31f0d82bc90d48a601964c665e22633007f5c Mon Sep 17 00:00:00 2001
From: yvesn <yvesn>
Date: Tue, 30 May 2017 10:53:18 +0000
Subject: [PATCH] SSDM-5068 : ELN config on GUI - fixing startup when settings
 sample does not yet exist

SVN: 38232
---
 .../html/js/config/SettingsManager.js         | 20 ++++++++++++-------
 .../SettingsForm/SettingsFormController.js    |  4 +++-
 2 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/SettingsManager.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/SettingsManager.js
index 71b066cefd9..0e43deb1e90 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/SettingsManager.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/SettingsManager.js
@@ -24,8 +24,12 @@ function SettingsManager(serverFacade) {
 			if(!data[0]) {
 				window.alert("The item is no longer available, refresh the page, if the problem persists tell your admin that the Lucene index is probably corrupted.");
 			} else {
-				var settings = JSON.parse(data[0].properties.ELN_SETTINGS);
-				callback(settings);
+				if (data[0].properties && data[0].properties.ELN_SETTINGS) {
+					var settings = JSON.parse(data[0].properties.ELN_SETTINGS);
+					callback(settings);
+				} else {
+					callback();
+				}
 			}
 		}).bind(this))
 	}
@@ -34,12 +38,14 @@ function SettingsManager(serverFacade) {
 	// Applies the settings to the profile even if they are invalid.
     this.loadSettingsAndApplyToProfile = function(doneCallback) {
 		this.loadSettings((function(settings) {
-			var errors = this._validateSettings(settings);
-			if (errors.length > 0) {
-				console.log("The settings contain the following errors:");
-				console.log(errors);
+			if (settings) {
+				var errors = this._validateSettings(settings);
+				if (errors.length > 0) {
+					console.log("The settings contain the following errors:");
+					console.log(errors);
+				}
+				this.applySettingsToProfile(settings, profile);
 			}
-			this.applySettingsToProfile(settings, profile);
 			doneCallback();
 		}).bind(this));
     }
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SettingsForm/SettingsFormController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SettingsForm/SettingsFormController.js
index 54559081453..45ed12f9048 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SettingsForm/SettingsFormController.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SettingsForm/SettingsFormController.js
@@ -24,7 +24,9 @@ function SettingsFormController(mainController, settingsSample, mode) {
 		// apply settings to copy of profile, even if invalid, for editing
 		var profileToEdit = jQuery.extend(true, {}, profile);
 		this._settingsManager.loadSettings((function(settings) {
-			this._settingsManager.applySettingsToProfile(settings, profileToEdit);
+			if (settings) {
+				this._settingsManager.applySettingsToProfile(settings, profileToEdit);
+			}
 			this._settingsFormView.repaint(views, profileToEdit);
 		}).bind(this));
 	}
-- 
GitLab