From 7686a892d556333194349f73fee3a268b6202d66 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Wed, 15 Oct 2014 16:52:56 +0000
Subject: [PATCH] #2021 config - Fixed some catalogs, LicenseType and Users

---
 securis/src/main/resources/static/js/admin.js |   45 +++++++++++++++++++++++++++++++++++----------
 1 files changed, 35 insertions(+), 10 deletions(-)

diff --git a/securis/src/main/resources/static/js/admin.js b/securis/src/main/resources/static/js/admin.js
index 53f9a70..d3f015b 100644
--- a/securis/src/main/resources/static/js/admin.js
+++ b/securis/src/main/resources/static/js/admin.js
@@ -56,7 +56,11 @@
 					$scope.catalogMetadata = Catalogs.getMetadata();
 					$scope.list = Catalogs.query();
 					$scope.refs = {}
-					Catalogs.loadRefs($scope.refs)
+					Catalogs.loadRefs(function(refs) {
+						console.log('Updated refs in form');
+						console.log(refs);
+						$scope.refs = refs;
+					});
 				}
 				
 				Catalogs.init().then(_changeCatalog); 
@@ -73,9 +77,17 @@
 					console.log($scope);
 					
 					fields.forEach(function(field) {
-						if (!field.listingOnly) $scope.formu[field.name] = data[field.name] || null;
+						if (field.type === 'select') {
+							// next lines are a workaround to avoid an issue where we try to show a form with "select" fields (if select field value doesn't change
+							$scope.formu[field.name] = null;
+							setTimeout(function() {
+								$scope.formu[field.name] = data[field.name];
+								$scope.$apply();
+							}, 0);
+						} else {
+							if (!field.listingOnly) $scope.formu[field.name] = data[field.name] || null;
+						}
 					})
-
 					setTimeout(function() {
 						$('#'+Catalogs.getFFF()).focus();
 					}, 0);
@@ -118,6 +130,8 @@
 						return 'multiselect';
 					if (field.type === 'metadata')
 						return 'metadata';
+					if (field.type === 'password')
+						return 'password';
 					if (!field.multiline)
 						return 'normal';
 					if (field.multiline)
@@ -131,9 +145,12 @@
 					$('select').val(null);
 					$scope.$parent.formu = {};
 					
-					console.log("Refs:");
+					console.log("Refs for new form:");
 					console.log($scope.refs);
-					
+					var fields = Catalogs.getMetadata().fields;
+					fields.forEach(function(field) {
+						if (!field.listingOnly) $scope.$parent.formu[field.name] = null;
+					})
 					setTimeout(function() {
 						$('#'+Catalogs.getFFF()).focus();
 					}, 0);
@@ -165,7 +182,6 @@
 							console.log(error);
 							toaster.pop('error', Catalogs.getName(), $L.get("Error saving element, reason: {0}. Details: {1}", $L.get(HTTP_ERRORS[error.status]), error.headers('X-SECURIS-ERROR')), 10000);
 						});
-						
 					}
 				}
 				
@@ -188,10 +204,19 @@
 				$scope.updateMetadata = function() {
 					// Called when Application ID change in current field
 					var newAppId = $scope.formu['application_id'];
-					console.log('Ready to get metadata from application: ' + newAppId);
-					Catalogs.getResource('application').get({appId: newAppId}).$promise.then(function(app) {
-						$scope.formu.metadata = app.metadata;
-					});
+					if (newAppId) {
+						// Only if there is a "valid" value selected we should update the metadata
+						Catalogs.getResource('application').get({appId: newAppId}).$promise.then(function(app) {
+							$scope.formu.metadata = [];
+							app.metadata.forEach(function(md) {
+								$scope.formu.metadata.push({
+									key: md.key,
+									value: md.value,
+									mandatory: md.mandatory
+								});
+							});
+						});
+					}
 				}
 				
 			} ]);

--
Gitblit v1.3.2