From c444f4a41b1b2a730b230667d187554c47a44e79 Mon Sep 17 00:00:00 2001
From: felmer <franz-josef.elmer@id.ethz.ch>
Date: Tue, 21 May 2019 09:58:44 +0200
Subject: [PATCH] SSDM-4589: HYPERLINK properties rendered in grids and
 detailed views

---
 .../webapps/eln-lims/html/js/util/FormUtil.js  | 18 +++++++++++++++++-
 .../views/DataGrid/ExperimentDataGridUtil.js   | 13 +++++++++++++
 .../js/views/DataGrid/SampleDataGridUtil.js    | 13 +++++++++++++
 .../js/views/DataSetForm/DataSetFormView.js    |  5 +----
 .../views/ExperimentForm/ExperimentFormView.js |  5 +----
 .../html/js/views/SampleForm/SampleFormView.js |  5 +----
 6 files changed, 46 insertions(+), 13 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/FormUtil.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/FormUtil.js
index 3a069f65163..ee54b423043 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/FormUtil.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/util/FormUtil.js
@@ -632,7 +632,18 @@ var FormUtil = new function() {
 		}
 	}
 	
+	this.createPropertyField = function(propertyType, propertyValue) {
+		if (propertyType.dataType === "CONTROLLEDVOCABULARY") {
+			propertyValue = this.getVocabularyLabelForTermCode(propertyType, propertyValue);
+		}
+		return this._createField(propertyType.dataType === "HYPERLINK", propertyType.label, propertyValue, propertyType.code);
+	}
+	
 	this.getFieldForLabelWithText = function(label, text, id, postComponent, cssForText) {
+		return this._createField(false, label, text, id, postComponent, cssForText);
+	}
+	
+	this._createField = function(hyperlink, label, text, id, postComponent, cssForText) {
 		var $fieldset = $('<div>');
 		
 		var $controlGroup = $('<div>', {class : 'form-group'});
@@ -660,7 +671,8 @@ var FormUtil = new function() {
 		if(text) {
 			text = text.replace(/(?:\r\n|\r|\n)/g, '\n'); //Normalise carriage returns
 		}
-		$component.html(html.sanitize(text));
+		text = html.sanitize(text);
+		$component.html(hyperlink ? this.asHyperlink(text) : text);
 		
 		if(id) {
 			$component.attr('id', id);
@@ -669,6 +681,10 @@ var FormUtil = new function() {
 		
 		return $fieldset;
 	}
+	
+	this.asHyperlink = function(text) {
+		$("<a>", { "href" : text, "target" : "_blank"}).append(text);
+	}
 
 	//
 	// Get Field from property
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/ExperimentDataGridUtil.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/ExperimentDataGridUtil.js
index 5d730a9a2bc..39e5d47cbbd 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/ExperimentDataGridUtil.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/ExperimentDataGridUtil.js
@@ -79,6 +79,19 @@ var ExperimentDataGridUtil = new function() {
 				
 				var newVocabularyColumnFunc = getVocabularyColumn(propertyType);
 				propertyColumnsToSort.push(newVocabularyColumnFunc());
+			} else if (propertyType.dataType === "HYPERLINK") {
+				var getHyperlinkColumn = function(propertyType) {
+					return {
+						label : propertyType.label,
+						property : propertyType.code,
+						isExportable: true,
+						sortable : true,
+						render : function(data) {
+							return FormUtil.asHyperlink(data[propertyType.code]);
+						}
+					};
+				}
+				propertyColumnsToSort.push(getHyperlinkColumn(propertyType));
 			} else {
 				propertyColumnsToSort.push({
 					label : propertyCodesDisplayNames[idx],
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/SampleDataGridUtil.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/SampleDataGridUtil.js
index 5330e2396df..90e4cef2d10 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/SampleDataGridUtil.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataGrid/SampleDataGridUtil.js
@@ -289,6 +289,19 @@ var SampleDataGridUtil = new function() {
 					
 					var newVocabularyColumnFunc = getVocabularyColumn(propertyType);
 					propertyColumnsToSort.push(newVocabularyColumnFunc());
+				} else if (propertyType.dataType === "HYPERLINK") {
+					var getHyperlinkColumn = function(propertyType) {
+						return {
+							label : propertyType.label,
+							property : propertyType.code,
+							isExportable: true,
+							sortable : true,
+							render : function(data) {
+								return FormUtil.asHyperlink(data[propertyType.code]);
+							}
+						};
+					}
+					propertyColumnsToSort.push(getHyperlinkColumn(propertyType));
 				} else {			
 					propertyColumnsToSort.push({
 						label : propertyType.label,
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js
index 4c7e7dec799..16305c02188 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormView.js
@@ -650,10 +650,7 @@ function DataSetFormView(dataSetFormController, dataSetFormModel) {
 					
 					if(this._dataSetFormModel.mode === FormMode.VIEW) {
 						if(Util.getEmptyIfNull(value) !== "") { //Don't show empty fields, whole empty sections will show the title
-							if(propertyType.dataType === "CONTROLLEDVOCABULARY") {
-								value = FormUtil.getVocabularyLabelForTermCode(propertyType, value);
-							}
-							var $controlGroup = FormUtil.getFieldForLabelWithText(propertyType.label, value, propertyType.code);
+							$controlGroup = FormUtil.createPropertyField(propertyType, value);
 							$fieldset.append($controlGroup);
 						} else {
 							continue;
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormView.js
index babba314421..5c2958f79f0 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormView.js
@@ -421,10 +421,7 @@ function ExperimentFormView(experimentFormController, experimentFormModel) {
 				
 				if(this._experimentFormModel.mode === FormMode.VIEW) { //Show values without input boxes if the form is in view mode
 					if(Util.getEmptyIfNull(value) !== "") { //Don't show empty fields, whole empty sections will show the title
-						if(propertyType.dataType === "CONTROLLEDVOCABULARY") {
-							value = FormUtil.getVocabularyLabelForTermCode(propertyType, value);
-						}
-						$controlGroup = FormUtil.getFieldForLabelWithText(propertyType.label, value);
+						$controlGroup = FormUtil.createPropertyField(propertyType, value);
 					} else {
 						continue;
 					}
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js
index 812b8d51f7e..b7bc8398bd3 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormView.js
@@ -658,10 +658,7 @@ function SampleFormView(sampleFormController, sampleFormModel) {
 				
 				if(this._sampleFormModel.mode === FormMode.VIEW) { //Show values without input boxes if the form is in view mode
 					if(Util.getEmptyIfNull(value) !== "") { //Don't show empty fields, whole empty sections will show the title
-						if(propertyType.dataType === "CONTROLLEDVOCABULARY") {
-							value = FormUtil.getVocabularyLabelForTermCode(propertyType, value);
-						}
-						$controlGroup = FormUtil.getFieldForLabelWithText(propertyType.label, value, propertyType.code);
+						$controlGroup = FormUtil.createPropertyField(propertyType, value);
 					} else {
 						continue;
 					}
-- 
GitLab