From d90afe9999e57ce1202bfe9475fc6628be36b71f Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Mon, 28 Sep 2015 13:53:31 +0000
Subject: [PATCH] SSDM-2450 : Add move option, to move samples between
 experiments/projects (ongoing work)

SVN: 34722
---
 .../eln-lims/html/js/server/ServerFacade.js   | 20 ++++++++++++++++++-
 .../widgets/MoveSampleController.js           | 16 ++++++++++++++-
 .../SampleTable/widgets/MoveSampleView.js     |  8 ++------
 3 files changed, 36 insertions(+), 8 deletions(-)

diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
index cf9f9bb4b6c..dbacbccd7ba 100644
--- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
+++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/server/ServerFacade.js
@@ -377,7 +377,7 @@ function ServerFacade(openbisServer) {
 	this.updateSamples = function(sampleTypeCode, fileKeyAtHTTPSession, somethingOrNull, callbackFunction) {
 		this.openbisServer.updateSamples(sampleTypeCode, fileKeyAtHTTPSession, somethingOrNull, callbackFunction);
 	}
-
+	
 	this.fileUpload = function(file, callbackFunction) {
 		//Building Form Data Object for Multipart File Upload
 		var formData = new FormData();
@@ -410,6 +410,24 @@ function ServerFacade(openbisServer) {
 		return GET;
 	}
 
+	//
+	// Sample Others functions
+	//
+	this.moveSample = function(sampleIdentifier, experimentIdentifier, callbackFunction) {
+		this.createReportFromAggregationService(profile.getDefaultDataStoreCode(),
+				{
+					"method" : "moveSample",
+					"sampleIdentifier" : sampleIdentifier,
+					"experimentIdentifier" : experimentIdentifier
+				},
+				function(data){
+					if(data.result.rows[0][0].value == "OK") {
+						callbackFunction(true);
+					} else {
+						callbackFunction(false);
+					}
+				});
+	}
 	//
 	// Data Set Import Related Functions
 	//
diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleTable/widgets/MoveSampleController.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleTable/widgets/MoveSampleController.js
index adc8088a710..bf5e1b19d02 100644
--- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleTable/widgets/MoveSampleController.js
+++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleTable/widgets/MoveSampleController.js
@@ -27,6 +27,20 @@ function MoveSampleController(samplePermId) {
 	}
 	
 	this.move = function() {
-		var breakMePlease = 0;
+		var _this = this;
+		if(!this._moveSampleModel.sample.identifier) {
+			Util.showError("Dear user, please choose the experiment first, try harder!", function() {});
+			return;
+		}
+		
+		mainController.serverFacade.moveSample(
+				this._moveSampleModel.sample.identifier,
+				this._moveSampleModel.experimentIdentifier, function(isOK) {
+					if(isOK) {
+						Util.showSuccess("Sample " + _this._moveSampleModel.sample.identifier + " moved to " + _this._moveSampleModel.experimentIdentifier, function() { Util.unblockUI(); });
+					} else {
+						Util.showError("Sample " + _this._moveSampleModel.sample.identifier + " failed " + _this._moveSampleModel.experimentIdentifier, function() {});
+					}
+				});
 	}
 }
\ No newline at end of file
diff --git a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleTable/widgets/MoveSampleView.js b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleTable/widgets/MoveSampleView.js
index 0ce512d9a2c..0b40b6bca94 100644
--- a/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleTable/widgets/MoveSampleView.js
+++ b/plasmid/source/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleTable/widgets/MoveSampleView.js
@@ -24,7 +24,7 @@ function MoveSampleView(moveSampleController, moveSampleModel) {
 		var $window = $('<form>', { 'class' : 'form-horizontal', 'action' : 'javascript:void(0);' });
 		$window.submit(function() {
 			Util.unblockUI();
-			_this._moveSampleModel.actionFunction(_this._moveSampleModel.sample);
+			_this._moveSampleController.move();
 		});
 		
 		$window.append($('<legend>').append("Move Sample"));
@@ -45,11 +45,7 @@ function MoveSampleView(moveSampleController, moveSampleModel) {
 		$window.append($experimentSection);
 		this.repaintExistingExperiment();
 		
-		var $btnAccept = $('<input>', { 'type': 'submit', 'class' : 'btn btn-primary', 'value' : 'Accept' });
-		$btnAccept.click(function() {
-			_this._moveSampleController.move();
-		});
-		
+		var $btnAccept = $('<input>', { 'type': 'submit', 'class' : 'btn btn-primary', 'value' : 'Accept' });		
 		var $btnCancel = $('<a>', { 'class' : 'btn btn-default' }).append('Cancel');
 		$btnCancel.click(function() {
 			Util.unblockUI();
-- 
GitLab