From b72a5013d05f9dc31d61a6a142b85394ac5a6a8c Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Tue, 15 Apr 2014 12:27:46 +0000
Subject: [PATCH] SSDM-109 : Ability to show images on the ELN UI

SVN: 31368
---
 .../newbrowser/html/js/views/SampleForm.js    | 33 ++++++++++++++++++-
 1 file changed, 32 insertions(+), 1 deletion(-)

diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js
index 4deec2f434d..02093998755 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm.js
@@ -136,6 +136,7 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod
 								}
 							}
 						}
+						localReference._reloadPreviewImage();
 				}
 				
 				var sampleType = localReference.profile.getTypeForTypeCode(localReference.sampleTypeCode);
@@ -330,9 +331,11 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod
 			//
 			// SELECT PROJECT/SPACE AND CODE
 			//
+			if (this.mode !== SampleFormMode.CREATE) {
+				component += "<img data-preview-loaded='false' id='preview-image' src='./img/image_loading.gif' style='height:300px; margin-right:20px; float:right;'></img>"
+			}
 			component += "<fieldset>";
 			component += "<legend>Identification Info</legend>";
-			
 			//Space/Project
 			var spaceSelectEnabled = true;
 			if(!this.isELNExperiment && 
@@ -731,6 +734,34 @@ function SampleForm(serverFacade, inspector, containerId, profile, sampleTypeCod
 		} else { //This should never happen
 			Util.showError("Unknown Error.", function() {Util.unblockUI();});
 		}
+	}
+	
+	this._updateLoadingToNotAvailableImage = function() {
+		var notLoadedImages = $("[data-preview-loaded='false']");
+		notLoadedImages.attr('src', "./img/image_unavailable.png");
+	}
+	
+	this._reloadPreviewImage = function() {
+		var _this = this;
+		var previewCallback = 
+			function(data) {
+				if (data.result.length == 0) {
+					_this._updateLoadingToNotAvailableImage();
+				} else {
+					var x = "123";
+					var listFilesForDataSetCallback = 
+						function(dataFiles) {
+							var elementId = 'preview-image';
+							var downloadUrl = _this.profile.allDataStores[0].downloadUrl + '/' + data.result[0].code + "/" + dataFiles.result[1].pathInDataSet + "?sessionID=" + _this.serverFacade.getSession();
+							
+							var img = $("#" + elementId);
+							img.attr('src', downloadUrl);
+							img.attr('data-preview-loaded', 'true');
+						};
+					_this.serverFacade.listFilesForDataSet(data.result[0].code, "/", true, listFilesForDataSetCallback);
+				}
+			};
 		
+		this.serverFacade.searchDataSetsWithTypeForSamples("ELN_PREVIEW", [this.sample.permId], previewCallback);
 	}
 }
\ No newline at end of file
-- 
GitLab