From edd47c68c6a08bd756d96213c38e896a0a257bd1 Mon Sep 17 00:00:00 2001
From: Roberto Sánchez <roberto.sanchez@curisit.net>
Date: Mon, 13 Jan 2014 18:12:51 +0000
Subject: [PATCH] #394 feature - Several fixes related with form management

---
 securis/src/main/resources/static/js/admin.js |   14 +++++++++++---
 1 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/securis/src/main/resources/static/js/admin.js b/securis/src/main/resources/static/js/admin.js
index 53b2125..5953c1c 100644
--- a/securis/src/main/resources/static/js/admin.js
+++ b/securis/src/main/resources/static/js/admin.js
@@ -62,10 +62,15 @@
 				$scope.edit = function(data) {
 					$scope.showForm = true;
 					$scope.isNew = false;
+					// Next line is a wirkaround due to some issues with values with ID == 0
+					$('select').val(null);
 					$scope.formu = {}
-					for (var k in data) {
-						if (k.indexOf('$') !== 0 && k.indexOf('_') !== 0 && !Catalogs.getField(k).listingOnly) $scope.formu[k] = data[k]
-					}
+					var fields = Catalogs.getMetadata().fields;
+					console.log($scope);
+					
+					fields.forEach(function(field) {
+						if (!field.listingOnly) $scope.formu[field.name] = data[field.name] || null;
+					})
 
 					setTimeout(function() {
 						$('#'+Catalogs.getFFF()).focus();
@@ -117,6 +122,7 @@
 				$scope.editNew = function() {
 					$scope.$parent.isNew = true;
 					$scope.$parent.showForm = true;
+					$('select').val(null);
 					$scope.$parent.formu = {};
 					setTimeout(function() {
 						$('#'+Catalogs.getFFF()).focus();
@@ -125,6 +131,7 @@
 				}
 				$scope.cancel = function() {
 					$scope.$parent.showForm = false;
+					$scope.catalogForm.$setPristine();
 				}
 
 				$scope.saveCatalog = function() {
@@ -134,6 +141,7 @@
 						var promise = Catalogs.save($scope.formu).$promise;
 						promise.then(function(data, otro) {
 							if ($scope.isNew) {
+								$scope.catalogForm.$setPristine();
 								$scope.$parent.formu = {}
 								$('#'+ Catalogs.getFFF()).focus();
 							} else {

--
Gitblit v1.3.2