From b1658fb00bdfb3bf663a4863682669a0a2c86784 Mon Sep 17 00:00:00 2001
From: juanf <juanf>
Date: Wed, 20 Aug 2014 09:48:58 +0000
Subject: [PATCH] SSDM-344 : New Free Form Table structure (ongoing work).

SVN: 32258
---
 .../SampleForm/widgets/FreeFormTableController.js     |  5 +++++
 .../js/views/SampleForm/widgets/FreeFormTableView.js  | 11 ++++++++++-
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/FreeFormTableController.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/FreeFormTableController.js
index 397ce02ece3..7f46e0a994f 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/FreeFormTableController.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/FreeFormTableController.js
@@ -46,6 +46,11 @@ function FreeFormTableController(sample, isEnabled) {
 		this._freeFormTableView.addTable(newTableIndex, $newTableContainer);
 	}
 	
+	this.deleteTable = function(tableIdx) {
+		this._freeFormTableModel.tables.splice(tableIdx, 1); //Removes from model
+		this._freeFormTableView.deleteTable(tableIdx); //Removes from view
+	}
+	
 	this.setTableSize = function(tableIdx, numRow, numCols) {
 		
 	}
diff --git a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/FreeFormTableView.js b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/FreeFormTableView.js
index b620e20572b..2f5cbf5c999 100644
--- a/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/FreeFormTableView.js
+++ b/plasmid/source/core-plugins/newbrowser/1/as/webapps/newbrowser/html/js/views/SampleForm/widgets/FreeFormTableView.js
@@ -179,6 +179,10 @@ function FreeFormTableView(freeFormTableController, freeFormTableModel) {
 		$toolBarBtnAT.click(addTableFunc(tableIdx));
 		
 		var $toolBarBtnDT = FormUtil.getButtonWithText('- Table' ,null).attr('title', 'Delete Table.').tooltipster();
+		var removeTableFunc = function(tableIdx) {
+			return function() { _this._freeFormTableController.deleteTable(tableIdx); };
+		}
+		$toolBarBtnDT.click(removeTableFunc(tableIdx));
 		
 		if(this._freeFormTableModel.isEnabled) {
 			$toolBar
@@ -212,7 +216,12 @@ function FreeFormTableView(freeFormTableController, freeFormTableModel) {
 		} else {
 			this._tableContainers[tableIdx-1].after($tableContainer); //Update View adding Table
 		}
-		this._tableContainers.push($tableContainer); //Update View Structure
+		this._tableContainers.splice(tableIdx, 0, $tableContainer); //Update View Structure
+	}
+	
+	this.deleteTable = function(tableIdx) {
+		this._tableContainers[tableIdx].remove();
+		this._tableContainers.splice(tableIdx, 1); //Update View Structure
 	}
 	
 	this.repaint = function($container) {
-- 
GitLab