From c8c34d6aea0514d9c989a9c3016778a15b5532a4 Mon Sep 17 00:00:00 2001
From: "Fuentes Serna  Juan Mariano (ID SIS)" <juanf@bs-mbpr28.d.ethz.ch>
Date: Fri, 9 Feb 2018 15:24:05 +0100
Subject: [PATCH] SSDM-6017 : Bugfix, App breaks when CKEditor is in full
 screen mode and the user resizes the window

---
 .../html/js/controllers/LayoutManager.js      | 40 +++++++++----------
 .../webapps/eln-lims/html/js/util/FormUtil.js | 28 +++----------
 .../DataSetForm/DataSetFormController.js      |  8 ----
 .../ExperimentFormController.js               |  8 ----
 .../views/SampleForm/SampleFormController.js  |  8 ----
 5 files changed, 25 insertions(+), 67 deletions(-)

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/LayoutManager.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/LayoutManager.js
index ff5ae8a80df..83922b9f487 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/LayoutManager.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/LayoutManager.js
@@ -355,9 +355,18 @@ var LayoutManager = {
 		}
 	},
 	canReload : function() {
+		// Don't reload when CKEditor is maximized
+		var ckMaximized = false;
+		for(editorId in CKEDITOR.instances) {
+			var commands = CKEDITOR.instances[editorId].commands;
+			if(commands && commands.maximize && commands.maximize.state == 1) {
+				ckMaximized = true;
+			}
+		}
+		
 		return  this.isResizingColumn === false && 
 				this.isLoadingView === false && 
-				this.firstColumn.width() > 0;
+				!ckMaximized;
 	},
 	getContentWidth : function() {
 		var width = $( window ).width();
@@ -395,6 +404,7 @@ var LayoutManager = {
 
 		var isFirstTime = this.mainContainer === null || forceFirstTime === true;
 		// console.log("reloadView called with isFirstTime:" + isFirstTime);
+		
 		this._init(isFirstTime);
 
 		var width = $( window ).width();
@@ -415,6 +425,11 @@ var LayoutManager = {
 	addResizeEventHandler : function(eventHandler) {
 		this.resizeEventHandlers.push(eventHandler);
 	},
+	removeResizeEventHandler : function(eventHandler) {
+		this.resizeEventHandlers = this.resizeEventHandlers.filter(function(el) {
+			return el === eventHandler;
+		});
+	},
 	triggerResizeEventHandlers : function() {
 		for(var idx = 0; idx < this.resizeEventHandlers.length; idx++) {
 			this.resizeEventHandlers[idx]();
@@ -423,29 +438,12 @@ var LayoutManager = {
 	},
 	resize : function(view, forceFirstTime) {
 		if(this.canReload()) {
-			// console.log("reloadView");
+			console.log("reloadView");
 			this.reloadView(view, forceFirstTime);
 		}
 	}
 }
 
-var rtime;
-var timeout = false;
-var delta = 200;
-
 $(window).resize(function() {
-    rtime = new Date();
-    if (timeout === false) {
-        timeout = true;
-        setTimeout(resizeend, delta);
-    }
-});
-
-function resizeend() {
-    if (new Date() - rtime < delta) {
-        setTimeout(resizeend, delta);
-    } else {
-        timeout = false;
-        LayoutManager.resize(mainController.views, true);
-    }
-}
+    LayoutManager.resize(mainController.views, true);
+});
\ No newline at end of file
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 5586b427197..b01023d0775 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
@@ -816,28 +816,12 @@ var FormUtil = new function() {
 			$component.change(function(event) {
 				componentOnChange(event, $(this).val());
 			});
-		} else {			
-			var destroyAndRecreate = function($component) {
-				return function() {
-					if($component.editor) {
-						$component.editor.destroy();
-						delete $component.editor;
-					}
-					var editor = $component.ckeditor().editor;
-					editor.on('change', function(event) {
-						var value = event.editor.getData();
-						componentOnChange(event, value);
-					});
-				}
-			}
-			
-			var destroyAndRecreateFunc = destroyAndRecreate($component);
-			
-			mainController.currentView._windowHandlers.push(destroyAndRecreateFunc);
-			
-			destroyAndRecreateFunc();
-			
-			LayoutManager.addResizeEventHandler(destroyAndRecreateFunc);
+		} else {
+			var editor = $component.ckeditor().editor;
+			editor.on('change', function(event) {
+				var value = event.editor.getData();
+				componentOnChange(event, value);
+			});
 		}
 		
 		return $component;
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormController.js
index b5baff49b98..d64396c5753 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormController.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/DataSetForm/DataSetFormController.js
@@ -18,14 +18,6 @@ function DataSetFormController(parentController, mode, entity, dataSet, isMini)
 	this._parentController = parentController;
 	this._dataSetFormModel = new DataSetFormModel(mode, entity, dataSet, isMini);
 	this._dataSetFormView = new DataSetFormView(this, this._dataSetFormModel);
-	this._windowHandlers = [];
-	
-	this.finalize = function() {
-		for(var whIdx = 0; whIdx < this._windowHandlers.length; whIdx++) {
-			$(window).off("resize", this._windowHandlers[whIdx]);
-		}
-		$("#mainContainer").css("overflow-y", "auto");
-	}
 	
 	this.init = function(views) {
 		var _this = this;
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormController.js
index 11af163a3df..0bd4cfb81c6 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormController.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/ExperimentForm/ExperimentFormController.js
@@ -18,19 +18,11 @@ function ExperimentFormController(mainController, mode, experiment) {
 	this._mainController = mainController;
 	this._experimentFormModel = new ExperimentFormModel(mode, experiment);
 	this._experimentFormView = new ExperimentFormView(this, this._experimentFormModel);
-	this._windowHandlers = [];
 	
 	this.init = function(views) {
 		this._experimentFormView.repaint(views);
 	}
 	
-	this.finalize = function() {
-		for(var whIdx = 0; whIdx < this._windowHandlers.length; whIdx++) {
-			$(window).off("resize", this._windowHandlers[whIdx]);
-		}
-		$("#mainContainer").css("overflow-y", "auto");
-	}
-	
 	this.isDirty = function() {
 		return this._experimentFormModel.isFormDirty;
 	}
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormController.js
index 45a216cbfcb..e614a21186b 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormController.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SampleForm/SampleFormController.js
@@ -20,7 +20,6 @@ function SampleFormController(mainController, mode, sample, paginationInfo) {
 	this._sampleFormView = new SampleFormView(this, this._sampleFormModel);
 //	this._storageControllers = [];
 	this._plateController = null;
-	this._windowHandlers = [];
 	
 	this.init = function(views) {
 		// Loading datasets
@@ -55,13 +54,6 @@ function SampleFormController(mainController, mode, sample, paginationInfo) {
 		}
 		
 	}
-	
-	this.finalize = function() {
-		for(var whIdx = 0; whIdx < this._windowHandlers.length; whIdx++) {
-			$(window).off("resize", this._windowHandlers[whIdx]);
-		}
-		$("#mainContainer").css("overflow-y", "auto");
-	}
 		
 	this.isDirty = function() {
 		return this._sampleFormModel.isFormDirty;
-- 
GitLab