| .. | .. |
|---|
| 18 | 18 | function($rootScope, $http, $resource, $q) { |
|---|
| 19 | 19 | var resources = { |
|---|
| 20 | 20 | application : $resource( |
|---|
| 21 | | - 'application/:appId', { |
|---|
| 22 | | - appId : '@id' |
|---|
| 21 | + 'application/:id', { |
|---|
| 22 | + id : '@id' |
|---|
| 23 | 23 | }), |
|---|
| 24 | | - user : $resource('user/:userId', { |
|---|
| 25 | | - userId : '@username' |
|---|
| 24 | + user : $resource('user/:id', { |
|---|
| 25 | + id : '@username' |
|---|
| 26 | 26 | }), |
|---|
| 27 | 27 | organization : $resource( |
|---|
| 28 | | - 'organization/:orgId', { |
|---|
| 29 | | - orgId : '@id' |
|---|
| 28 | + 'organization/:id', { |
|---|
| 29 | + id : '@id' |
|---|
| 30 | 30 | }), |
|---|
| 31 | 31 | licensetype : $resource( |
|---|
| 32 | | - 'licensetype/:licenseTypeId', { |
|---|
| 33 | | - licenseTypeId : '@id' |
|---|
| 32 | + 'licensetype/:id', { |
|---|
| 33 | + id : '@id' |
|---|
| 34 | 34 | }) |
|---|
| 35 | 35 | } |
|---|
| 36 | 36 | |
|---|
| .. | .. |
|---|
| 68 | 68 | return resources[res]; |
|---|
| 69 | 69 | } |
|---|
| 70 | 70 | this.getPk = function(catalogMetadata) { |
|---|
| 71 | | - if (!catalogMetadata) |
|---|
| 71 | + if (!catalogMetadata) { |
|---|
| 72 | 72 | catalogMetadata = _current; |
|---|
| 73 | + } |
|---|
| 73 | 74 | |
|---|
| 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) { |
|---|
| 76 | 77 | return catalogMetadata.fields[i].name; |
|---|
| 78 | + } |
|---|
| 79 | + } |
|---|
| 77 | 80 | |
|---|
| 78 | 81 | return null; |
|---|
| 79 | 82 | } |
|---|
| .. | .. |
|---|
| 167 | 170 | } |
|---|
| 168 | 171 | |
|---|
| 169 | 172 | this.save = function(data) { |
|---|
| 170 | | - if (!_current) |
|---|
| 173 | + if (!_current) { |
|---|
| 171 | 174 | throw new Error('There is no current catalog selected'); |
|---|
| 172 | | - |
|---|
| 175 | + } |
|---|
| 173 | 176 | var resource = this.getResource(); |
|---|
| 174 | 177 | 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); |
|---|
| 175 | 185 | } |
|---|
| 176 | 186 | this.remove = function(data) { |
|---|
| 177 | 187 | return this.getResource().remove({}, data, |
|---|
| 178 | 188 | _success, _fail) |
|---|
| 179 | 189 | } |
|---|
| 180 | 190 | 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; |
|---|
| 183 | 194 | } |
|---|
| 184 | 195 | this.refreshRef = function(refs, res, |
|---|
| 185 | 196 | preloadedData) { |
|---|