From 68d7034e364a0613fa1c587b302bd1cb335d7d79 Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Tue, 14 Oct 2014 12:33:44 +0000
Subject: [PATCH] SSDM-1015 : GENERAL - Delete sample

SVN: 32611
---
 .../1/as/webapps/newbrowser/html/index.html   |  3 +
 .../newbrowser/html/js/config/TestProfile.js  | 46 ++++++-------
 .../newbrowser/html/js/server/ServerFacade.js | 67 ++++++++++---------
 .../newbrowser/html/js/util/FormUtil.js       | 10 +++
 .../js/views/SampleForm/SampleFormView.js     | 23 +++----
 .../widgets/DeleteEntityController.js         | 24 +++++++
 .../SampleForm/widgets/DeleteEntityModel.js   | 21 ++++++
 .../SampleForm/widgets/DeleteEntityView.js    | 60 +++++++++++++++++
 8 files changed, 188 insertions(+), 66 deletions(-)
 create mode 100644 plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityController.js
 create mode 100644 plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityModel.js
 create mode 100644 plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityView.js

diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/index.html b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/index.html
index 3b4be130788..631c51342a8 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/index.html
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/index.html
@@ -113,6 +113,9 @@
 	<script type="text/javascript" src="./js/views/SampleForm/widgets/FreeFormTableController.js"></script>
 	<script type="text/javascript" src="./js/views/SampleForm/widgets/FreeFormTableModel.js"></script>
 	<script type="text/javascript" src="./js/views/SampleForm/widgets/FreeFormTableView.js"></script>
+	<script type="text/javascript" src="./js/views/SampleForm/widgets/DeleteEntityController.js"></script>
+	<script type="text/javascript" src="./js/views/SampleForm/widgets/DeleteEntityModel.js"></script>
+	<script type="text/javascript" src="./js/views/SampleForm/widgets/DeleteEntityView.js"></script>
 	
 	<script type="text/javascript" src="./js/views/SpaceForm/SpaceFormController.js"></script>
 	<script type="text/javascript" src="./js/views/SpaceForm/SpaceFormModel.js"></script>
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/TestProfile.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/TestProfile.js
index 3cbddbba626..711f31aa840 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/TestProfile.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/config/TestProfile.js
@@ -9,31 +9,31 @@ $.extend(TestProfile.prototype, DefaultProfile.prototype, {
 		this.ELNExperiments = ["SYSTEM_EXPERIMENT"];
 		this.notShowTypes = ["ANTIBODY_PANEL"];
 		this.isShowUnavailablePreviewOnSampleTable = false;
-		this.inventorySpaces = ["BODENMILLER_LAB"];
+		this.inventorySpaces = ["BODENMILLER_LAB", "INVENTORY"];
 		
 		//For testing	
-		this.sampleTypeDefinitionsExtension = {
-				"SYSTEM_EXPERIMENT" : {
-					"SAMPLE_PARENTS_HINT" : [
-					                             	{
-														"LABEL" : "Protein",
-														"TYPE": "PROTEIN",
-														"MIN_COUNT" : 1,
-														"ANNOTATION_PROPERTIES" : [ {"TYPE" : "PHOSPHO", "MANDATORY" : true }
-														                           ,{"TYPE" : "ISOTYPE", "MANDATORY" : false }]
-													}
-												],
-					"SAMPLE_CHILDREN_HINT" : [
-											                             	{
-																				"LABEL" : "Protein",
-																				"TYPE": "PROTEIN",
-																				"MIN_COUNT" : 1,
-																				"ANNOTATION_PROPERTIES" : [ {"TYPE" : "PHOSPHO", "MANDATORY" : true }
-																				                           ,{"TYPE" : "ISOTYPE", "MANDATORY" : false }]
-																			}
-																		]
-				}
-		}
+//		this.sampleTypeDefinitionsExtension = {
+//				"SYSTEM_EXPERIMENT" : {
+//					"SAMPLE_PARENTS_HINT" : [
+//					                             	{
+//														"LABEL" : "Protein",
+//														"TYPE": "PROTEIN",
+//														"MIN_COUNT" : 1,
+//														"ANNOTATION_PROPERTIES" : [ {"TYPE" : "PHOSPHO", "MANDATORY" : true }
+//														                           ,{"TYPE" : "ISOTYPE", "MANDATORY" : false }]
+//													}
+//												],
+//					"SAMPLE_CHILDREN_HINT" : [
+//											                             	{
+//																				"LABEL" : "Protein",
+//																				"TYPE": "PROTEIN",
+//																				"MIN_COUNT" : 1,
+//																				"ANNOTATION_PROPERTIES" : [ {"TYPE" : "PHOSPHO", "MANDATORY" : true }
+//																				                           ,{"TYPE" : "ISOTYPE", "MANDATORY" : false }]
+//																			}
+//																		]
+//				}
+//		}
 //		
 //		this.typePropertiesForSmallTable = {
 //				"SYSTEM_EXPERIMENT" : ["NAME"],
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js
index 149a4833408..3cc08583a12 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/server/ServerFacade.js
@@ -154,36 +154,7 @@ function ServerFacade(openbisServer) {
 		}
 	}
 	
-	this.listSearchDomains = function(callbackFunction) {
-		if(this.openbisServer.listAvailableSearchDomains) {
-			this.openbisServer.listAvailableSearchDomains(callbackFunction);
-		} else {
-			callbackFunction();
-		}
-	}
-	
-	this.searchOnSearchDomain = function(preferredSearchDomainOrNull, searchText, callbackFunction) {
-		
-		//TO-DO: For testing please put codes that exist in your database and you can access, the rest leave it as it is, when done just pass null to the function.
-		var optionalParametersOrNull = {
-				"SEQ-1" : JSON.stringify({
-					"searchDomain" : "Echo database",
-					"dataSetCode" : "20141010105346206-1",
-					"pathInDataSet" : "PATH-1",
-					"sequenceIdentifier" : "ID-1",
-					"positionInSequence" : "1"
-				}),
-				"SEQ-2" : JSON.stringify({
-					"searchDomain" : "Echo database",
-					"dataSetCode" : "20141010105439367-2",
-					"pathInDataSet" : "PATH-2",
-					"sequenceIdentifier" : "ID-2",
-					"positionInSequence" : "2"
-				})
-		}
-		
-		this.openbisServer.searchOnSearchDomain(preferredSearchDomainOrNull, searchText, optionalParametersOrNull, callbackFunction);
-	}
+
 	//
 	// Others
 	//
@@ -193,6 +164,10 @@ function ServerFacade(openbisServer) {
 		}
 	}
 	
+	
+	this.deleteSamples = function(sampleIds, reason, callback) {
+		this.openbisServer.deleteSamples(sampleIds, reason, "TRASH", callback);
+	}
 	//
 	// Data Set Related Functions
 	//
@@ -270,7 +245,7 @@ function ServerFacade(openbisServer) {
 	}
 	
 	//
-	// Sample Create/Update Functions
+	// ELN Custom API
  	//
  	this.createReportFromAggregationService = function(dataStoreCode, parameters, callbackFunction) {
 		this.openbisServer.createReportFromAggregationService(dataStoreCode, "newbrowserapi", parameters, callbackFunction);
@@ -656,4 +631,34 @@ function ServerFacade(openbisServer) {
 		});
 	}
 	
+	this.listSearchDomains = function(callbackFunction) {
+		if(this.openbisServer.listAvailableSearchDomains) {
+			this.openbisServer.listAvailableSearchDomains(callbackFunction);
+		} else {
+			callbackFunction();
+		}
+	}
+	
+	this.searchOnSearchDomain = function(preferredSearchDomainOrNull, searchText, callbackFunction) {
+		
+		//TO-DO: For testing please put codes that exist in your database and you can access, the rest leave it as it is, when done just pass null to the function.
+		var optionalParametersOrNull = {
+				"SEQ-1" : JSON.stringify({
+					"searchDomain" : "Echo database",
+					"dataSetCode" : "20141010105346206-1",
+					"pathInDataSet" : "PATH-1",
+					"sequenceIdentifier" : "ID-1",
+					"positionInSequence" : "1"
+				}),
+				"SEQ-2" : JSON.stringify({
+					"searchDomain" : "Echo database",
+					"dataSetCode" : "20141010105439367-2",
+					"pathInDataSet" : "PATH-2",
+					"sequenceIdentifier" : "ID-2",
+					"positionInSequence" : "2"
+				})
+		}
+		
+		this.openbisServer.searchOnSearchDomain(preferredSearchDomainOrNull, searchText, optionalParametersOrNull, callbackFunction);
+	}
 }
\ No newline at end of file
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js
index 0a8b6d1ff55..4c732c8b94f 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/util/FormUtil.js
@@ -196,6 +196,16 @@ var FormUtil = new function() {
 		return $component;
 	}
 	
+	this.getDeleteButton = function(deleteFunction, includeReason) {
+		var $deleteBtn = $("<a>", { 'class' : 'btn btn-default ' });
+		$deleteBtn.append($("<span>", { 'class' : 'glyphicon glyphicon-trash', 'style' : 'width:16px; height:16px;'}));
+		$deleteBtn.click(function() {
+			var modalView = new DeleteEntityController(deleteFunction, includeReason);
+			modalView.init();
+		});
+		return $deleteBtn;
+	}
+	
 	this.getPINButton = function(permId) {
 		var inspectedClass = "";
 		if(mainController.inspector.containsByPermId(permId) !== -1) {
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/SampleFormView.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/SampleFormView.js
index e991e3962b8..fd9ca9d6235 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/SampleFormView.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/SampleFormView.js
@@ -66,20 +66,28 @@ function SampleFormView(sampleFormController, sampleFormModel) {
 		// TITLE BUTTONS
 		//
 		if(this._sampleFormModel.mode !== FormMode.CREATE) {
+			//Delete
+			$formTitle.append(FormUtil.getDeleteButton(function(reason) {
+				mainController.serverFacade.deleteSamples([_this._sampleFormModel.sample.id], reason, function(data) {
+					Util.showSuccess("Sample Deleted");
+					window.history.back();
+				});
+			}, true));
 			//Pin
+			$formTitle.append("&nbsp;");
 			$formTitle.append(FormUtil.getPINButton(this._sampleFormModel.sample.permId));
 			//Hierarchy
-			$formTitle.append(" ");
+			$formTitle.append("&nbsp;");
 			$formTitle.append(FormUtil.getHierarchyButton(this._sampleFormModel.sample.permId));
 			//Copy
-			$formTitle.append(" ");
+			$formTitle.append("&nbsp;");
 			var $copyButton = $("<a>", { 'class' : 'btn btn-default'} )
 										.append($('<img>', { 'src' : './img/copy-icon.png', 'style' : 'width:16px; height:16px;' }));
 			$copyButton.click(_this._getCopyButtonEvent());
 			$formTitle.append($copyButton);
 			//Edit
 			if(this._sampleFormModel.mode === FormMode.VIEW) {
-				$formTitle.append(" ");
+				$formTitle.append("&nbsp;");
 				var $editButton = $("<a>", { 'class' : 'btn btn-default'} )
 									.append($('<span>', { 'class' : 'glyphicon glyphicon-edit' }))
 									.append(' Enable Editing');
@@ -389,15 +397,6 @@ function SampleFormView(sampleFormController, sampleFormModel) {
 					'right' : '20%',
 					'overflow' : 'auto'
 			};
-				
-			var css = {
-					'text-align' : 'left',
-					'top' : '15%',
-					'width' : '70%',
-					'left' : '15%',
-					'right' : '20%',
-					'overflow' : 'auto'
-			};
 			
 			Util.blockUI(component + "<br><br><br> <a class='btn btn-default' id='copyAccept'>Accept</a> <a class='btn btn-default' id='copyCancel'>Cancel</a>", css);
 			
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityController.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityController.js
new file mode 100644
index 00000000000..b06c0ac0264
--- /dev/null
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityController.js
@@ -0,0 +1,24 @@
+/*
+ * Copyright 2014 ETH Zuerich, Scientific IT Services
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function DeleteEntityController(deleteFunction, includeReason) {
+	this._deleteEntityModel = new DeleteEntityModel(deleteFunction, includeReason);
+	this._deleteEntityView = new DeleteEntityView(this, this._deleteEntityModel);
+	
+	this.init = function() {
+		this._deleteEntityView.repaint();
+	}
+}
\ No newline at end of file
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityModel.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityModel.js
new file mode 100644
index 00000000000..ebf1a961512
--- /dev/null
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityModel.js
@@ -0,0 +1,21 @@
+/*
+ * Copyright 2014 ETH Zuerich, Scientific IT Services
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function DeleteEntityModel(deleteFunction, includeReason) {
+	this.deleteFunction = deleteFunction;
+	this.includeReason = includeReason;
+	this.reason = null;
+}
\ No newline at end of file
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityView.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityView.js
new file mode 100644
index 00000000000..3e52097f4e6
--- /dev/null
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/DeleteEntityView.js
@@ -0,0 +1,60 @@
+/*
+ * Copyright 2014 ETH Zuerich, Scientific IT Services
+ *
+ * Licensed under the Apache License, Version 2.0 (the 'License');
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an 'AS IS' BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+function DeleteEntityView(deleteEntityController, deleteEntityModel) {
+	this._deleteEntityController = deleteEntityController;
+	this._deleteEntityModel = deleteEntityModel;
+	
+	this.repaint = function() {
+		var _this = this;
+		var $window = $('<form>', { 'class' : 'form-horizontal', 'action' : 'javascript:void(0);' });
+		$window.submit(function() {
+			_this._deleteEntityModel.deleteFunction(_this._deleteEntityModel.reason);
+			Util.unblockUI();
+		});
+		
+		$window.append($('<legend>').append('Confirm Delete'));
+		
+		if(this._deleteEntityModel.includeReason) {
+			var $reasonTextBox = FormUtil._getTextBox(null, 'Reason for the delete', true);
+			$reasonTextBox.keyup(function(event) {
+				_this._deleteEntityModel.reason = $(this).val();
+			});
+			var $reasonTextBoxGroup = FormUtil.getFieldForComponentWithLabel($reasonTextBox, 'Reason');
+			$window.append($reasonTextBoxGroup);
+		}
+		
+		
+		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();
+		});
+		
+		$window.append($btnAccept).append('&nbsp;').append($btnCancel);
+		
+		var css = {
+				'text-align' : 'left',
+				'top' : '15%',
+				'width' : '70%',
+				'left' : '15%',
+				'right' : '20%',
+				'overflow' : 'hidden'
+		};
+		
+		Util.blockUI($window, css);
+	}
+}
\ No newline at end of file
-- 
GitLab