rsanchez
2014-12-12 4c13c7324a920f5cca9601154e5224e5d7484fa9
securis/src/main/webapp/js/catalogs.js
....@@ -18,19 +18,19 @@
1818 function($rootScope, $http, $resource, $q) {
1919 var resources = {
2020 application : $resource(
21
- 'application/:appId', {
22
- appId : '@id'
21
+ 'application/:id', {
22
+ id : '@id'
2323 }),
24
- user : $resource('user/:userId', {
25
- userId : '@username'
24
+ user : $resource('user/:id', {
25
+ id : '@username'
2626 }),
2727 organization : $resource(
28
- 'organization/:orgId', {
29
- orgId : '@id'
28
+ 'organization/:id', {
29
+ id : '@id'
3030 }),
3131 licensetype : $resource(
32
- 'licensetype/:licenseTypeId', {
33
- licenseTypeId : '@id'
32
+ 'licensetype/:id', {
33
+ id : '@id'
3434 })
3535 }
3636
....@@ -68,12 +68,15 @@
6868 return resources[res];
6969 }
7070 this.getPk = function(catalogMetadata) {
71
- if (!catalogMetadata)
71
+ if (!catalogMetadata) {
7272 catalogMetadata = _current;
73
+ }
7374
74
- for (var i = 0; i < catalogMetadata.fields.length; i++)
75
- if (catalogMetadata.fields[i].pk)
75
+ for (var i = 0; i < catalogMetadata.fields.length; i++) {
76
+ if (catalogMetadata.fields[i].pk) {
7677 return catalogMetadata.fields[i].name;
78
+ }
79
+ }
7780
7881 return null;
7982 }
....@@ -167,19 +170,27 @@
167170 }
168171
169172 this.save = function(data) {
170
- if (!_current)
173
+ if (!_current) {
171174 throw new Error('There is no current catalog selected');
172
-
175
+ }
173176 var resource = this.getResource();
174177 return resource.save(data, _success, _fail);
178
+ }
179
+ this.get = function(id, _onsuccess, _onfail) {
180
+ if (!_current) {
181
+ throw new Error('There is no current catalog selected');
182
+ }
183
+ var resource = this.getResource();
184
+ return resource.get({id: id}, _onsuccess, _onfail);
175185 }
176186 this.remove = function(data) {
177187 return this.getResource().remove({}, data,
178188 _success, _fail)
179189 }
180190 this.query = function() {
181
- return this.getResource().query({},
182
- _success, _fail);
191
+ var list = this.getResource().query();
192
+ list.$promise.then(_success, _fail);
193
+ return list;
183194 }
184195 this.refreshRef = function(refs, res,
185196 preloadedData) {