From 795dcbf72512f6d597b41873f0fbbb0c702ae4f2 Mon Sep 17 00:00:00 2001
From: yvesn <yvesn>
Date: Mon, 29 May 2017 14:10:37 +0000
Subject: [PATCH] SSDM-5050 : ELN user profile - added profie view for password
 change

SVN: 38224
---
 .../1/as/webapps/eln-lims/html/index.html     |  6 ++-
 .../eln-lims/html/js/config/Profile.js        |  1 +
 .../html/js/controllers/MainController.js     | 15 +++++-
 .../js/views/SideMenu/SideMenuWidgetView.js   |  9 +++-
 .../UserProfile/UserProfileController.js      | 32 ++++++++++++
 .../js/views/UserProfile/UserProfileModel.js  | 18 +++++++
 .../js/views/UserProfile/UserProfileView.js   | 51 +++++++++++++++++++
 7 files changed, 127 insertions(+), 5 deletions(-)
 create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileController.js
 create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileModel.js
 create mode 100644 openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileView.js

diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html
index 809361e9b71..1f6e2663e46 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/index.html
@@ -218,7 +218,11 @@
 	<script type="text/javascript" src="./js/views/Inventory/InventoryController.js"></script>
 	<script type="text/javascript" src="./js/views/Inventory/InventoryModel.js"></script>
 	<script type="text/javascript" src="./js/views/Inventory/InventoryView.js"></script>
-	
+
+	<script type="text/javascript" src="./js/views/UserProfile/UserProfileController.js"></script>
+	<script type="text/javascript" src="./js/views/UserProfile/UserProfileModel.js"></script>
+	<script type="text/javascript" src="./js/views/UserProfile/UserProfileView.js"></script>
+
 	<script type="text/javascript" src="./js/views/Export/ExportTreeController.js"></script>
 	<script type="text/javascript" src="./js/views/Export/ExportTreeModel.js"></script>
 	<script type="text/javascript" src="./js/views/Export/ExportTreeView.js"></script>
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js
index 4b97aa48b00..fea9b8062ab 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/config/Profile.js
@@ -49,6 +49,7 @@ $.extend(DefaultProfile.prototype, {
 				showSettings : true,
 				showVocabularyViewer : true,
 				showUserManager : true,
+				showUserProfile : true,
 		}
 		
 		this.orderLabInfo = {
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js
index 3c10ceb3b6c..388e8f23aee 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/controllers/MainController.js
@@ -243,6 +243,10 @@ function MainController(profile) {
 		
 		try {
 			switch (newViewChange) {
+				case "showUserProfilePage":
+					document.title = "User Profile";
+					this._showUserProfilePage();
+					break;
 				case "showSettingsPage":
 					document.title = "Settings";
 					this._showSettingsPage(FormMode.VIEW);
@@ -524,7 +528,7 @@ function MainController(profile) {
 					}, 'text');
 					break;
 				default:
-					window.alert("The system tried to create a non existing view");
+					window.alert("The system tried to create a non existing view: " + newViewChange);
 					break;
 			}
 		} catch(err) {
@@ -647,7 +651,14 @@ function MainController(profile) {
 		
 		return modificableViews;
 	}
-	
+
+	this._showUserProfilePage = function() {
+		var newView = new UserProfileController(this);
+		var views = this._getNewViewModel(true, true, false);
+		newView.init(views);
+		this.currentView = newView;
+	}
+
 	this._showSettingsPage = function(mode) {
 		var _this = this;
 		this.serverFacade.searchSamples({ "sampleIdentifier" : "/ELN_SETTINGS/GENERAL_ELN_SETTINGS", "withProperties" : true }, function(data) {
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js
index 4a16ca23e0e..94357efec88 100644
--- a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/SideMenu/SideMenuWidgetView.js
@@ -165,7 +165,12 @@ function SideMenuWidgetView(sideMenuWidgetController, sideMenuWidgetModel) {
         }
         
         var treeModelUtils = [];
-        
+
+        if(profile.mainMenu.showUserProfile) {
+        	var settingsLink = _this.getLinkForNode("User Profile", "USER_PROFILE", "showUserProfilePage", null);
+        	treeModelUtils.push({ title : settingsLink, entityType: "USER_PROFILE", key : "USER_PROFILE", folder : false, lazy : false, view : "showUserProfilePage", icon : "glyphicon glyphicon-user" });
+        }
+
         if(profile.mainMenu.showDrawingBoard) {
         	var drawingBoardLink = _this.getLinkForNode("Drawing Board", "DRAWING_BOARD", "showDrawingBoard", null);
         	treeModelUtils.push({ title : drawingBoardLink, entityType: "DRAWING_BOARD", key : "DRAWING_BOARD", folder : false, lazy : false, view : "showDrawingBoard" });
@@ -210,7 +215,7 @@ function SideMenuWidgetView(sideMenuWidgetController, sideMenuWidgetModel) {
         	var settingsLink = _this.getLinkForNode("Settings", "SETTINGS", "showSettingsPage", null);
         	treeModelUtils.push({ title : settingsLink, entityType: "SETTINGS", key : "SETTINGS", folder : false, lazy : false, view : "showSettingsPage", icon : "glyphicon glyphicon-cog" });
         }
-        
+
         treeModel.push({ title : "Utilities", entityType: "UTILITIES", key : "UTILITIES", folder : true, lazy : false, expanded : true, children : treeModelUtils, icon : "glyphicon glyphicon-wrench" });
         treeModel.push({ title : "About", entityType: "ABOUT", key : "ABOUT", folder : false, lazy : false, view : "showAbout", icon : "glyphicon glyphicon-info-sign" });
         
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileController.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileController.js
new file mode 100644
index 00000000000..40c3d0ed323
--- /dev/null
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileController.js
@@ -0,0 +1,32 @@
+/*
+ * 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 UserProfileController(mainController) {
+	this._mainController = mainController;
+	this._userProfileModel = new UserProfileModel();
+	this._userProfileView = new UserProfileView(this, this._userProfileModel);
+
+	this.init = function(views) {
+        this._userProfileView.repaint(views);
+	}
+
+	this.resetPassword = function() {
+		var userId = this._mainController.serverFacade.getUserId();
+		var resetPasswordController = new ResetPasswordController(userId);
+		resetPasswordController.init();
+	}
+
+}
\ No newline at end of file
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileModel.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileModel.js
new file mode 100644
index 00000000000..59f48056cca
--- /dev/null
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileModel.js
@@ -0,0 +1,18 @@
+/*
+ * 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 UserProfileModel() {
+}
diff --git a/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileView.js b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileView.js
new file mode 100644
index 00000000000..50a7c26431c
--- /dev/null
+++ b/openbis_standard_technologies/dist/core-plugins/eln-lims/1/as/webapps/eln-lims/html/js/views/UserProfile/UserProfileView.js
@@ -0,0 +1,51 @@
+/*
+ * 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 UserProfileView(userProfileController, userProfileModel) {
+	this._userProfileController = userProfileController;
+	this._userProfileModel = userProfileModel;
+
+	this.repaint = function(views, profileToEdit) {
+
+        // header
+        var $header = views.header;
+        var typeTitle = "User Profile";
+        var $formTitle = $("<h2>").append(typeTitle);
+        $header.append($formTitle);
+		// ToolBox
+		var $toolbox = $("<div>", { 'id' : 'toolBoxContainer', class : 'toolBox'});
+		$toolbox.append(this._getOptionsMenu());
+		$header.append($toolbox);
+
+        // formColumn for content
+		var $container = views.content;
+        var $form = $("<div>");
+        var $formColumn = $("<div>");
+        $form.append($formColumn);
+        $container.append($form);
+    }
+
+	this._getOptionsMenu = function() {
+        var items = [
+            {
+                label : "Change Password",
+                event : this._userProfileController.resetPassword.bind(this._userProfileController),
+            }
+        ];
+        return FormUtil.getOperationsMenu(items);
+	}
+
+}
\ No newline at end of file
-- 
GitLab