rsanchez
2014-10-15 7686a892d556333194349f73fee3a268b6202d66
securis/src/main/resources/static/js/admin.js
....@@ -56,7 +56,11 @@
5656 $scope.catalogMetadata = Catalogs.getMetadata();
5757 $scope.list = Catalogs.query();
5858 $scope.refs = {}
59
- Catalogs.loadRefs($scope.refs)
59
+ Catalogs.loadRefs(function(refs) {
60
+ console.log('Updated refs in form');
61
+ console.log(refs);
62
+ $scope.refs = refs;
63
+ });
6064 }
6165
6266 Catalogs.init().then(_changeCatalog);
....@@ -73,9 +77,17 @@
7377 console.log($scope);
7478
7579 fields.forEach(function(field) {
76
- if (!field.listingOnly) $scope.formu[field.name] = data[field.name] || null;
80
+ if (field.type === 'select') {
81
+ // 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
82
+ $scope.formu[field.name] = null;
83
+ setTimeout(function() {
84
+ $scope.formu[field.name] = data[field.name];
85
+ $scope.$apply();
86
+ }, 0);
87
+ } else {
88
+ if (!field.listingOnly) $scope.formu[field.name] = data[field.name] || null;
89
+ }
7790 })
78
-
7991 setTimeout(function() {
8092 $('#'+Catalogs.getFFF()).focus();
8193 }, 0);
....@@ -118,6 +130,8 @@
118130 return 'multiselect';
119131 if (field.type === 'metadata')
120132 return 'metadata';
133
+ if (field.type === 'password')
134
+ return 'password';
121135 if (!field.multiline)
122136 return 'normal';
123137 if (field.multiline)
....@@ -131,9 +145,12 @@
131145 $('select').val(null);
132146 $scope.$parent.formu = {};
133147
134
- console.log("Refs:");
148
+ console.log("Refs for new form:");
135149 console.log($scope.refs);
136
-
150
+ var fields = Catalogs.getMetadata().fields;
151
+ fields.forEach(function(field) {
152
+ if (!field.listingOnly) $scope.$parent.formu[field.name] = null;
153
+ })
137154 setTimeout(function() {
138155 $('#'+Catalogs.getFFF()).focus();
139156 }, 0);
....@@ -165,7 +182,6 @@
165182 console.log(error);
166183 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);
167184 });
168
-
169185 }
170186 }
171187
....@@ -188,10 +204,19 @@
188204 $scope.updateMetadata = function() {
189205 // Called when Application ID change in current field
190206 var newAppId = $scope.formu['application_id'];
191
- console.log('Ready to get metadata from application: ' + newAppId);
192
- Catalogs.getResource('application').get({appId: newAppId}).$promise.then(function(app) {
193
- $scope.formu.metadata = app.metadata;
194
- });
207
+ if (newAppId) {
208
+ // Only if there is a "valid" value selected we should update the metadata
209
+ Catalogs.getResource('application').get({appId: newAppId}).$promise.then(function(app) {
210
+ $scope.formu.metadata = [];
211
+ app.metadata.forEach(function(md) {
212
+ $scope.formu.metadata.push({
213
+ key: md.key,
214
+ value: md.value,
215
+ mandatory: md.mandatory
216
+ });
217
+ });
218
+ });
219
+ }
195220 }
196221
197222 } ]);