From 4c13c7324a920f5cca9601154e5224e5d7484fa9 Mon Sep 17 00:00:00 2001
From: rsanchez <rsanchez@curisit.net>
Date: Fri, 12 Dec 2014 18:09:27 +0000
Subject: [PATCH] #2140 fix - Many changes related with cahce and JPA cycling relationships

---
 securis/src/main/webapp/js/catalogs.js |   41 ++++++++++++++++++++++++++---------------
 1 files changed, 26 insertions(+), 15 deletions(-)

diff --git a/securis/src/main/webapp/js/catalogs.js b/securis/src/main/webapp/js/catalogs.js
index e1d458f..bfef4a8 100644
--- a/securis/src/main/webapp/js/catalogs.js
+++ b/securis/src/main/webapp/js/catalogs.js
@@ -18,19 +18,19 @@
 							function($rootScope, $http, $resource, $q) {
 								var resources = {
 									application : $resource(
-											'application/:appId', {
-												appId : '@id'
+											'application/:id', {
+												id : '@id'
 											}),
-									user : $resource('user/:userId', {
-										userId : '@username'
+									user : $resource('user/:id', {
+										id : '@username'
 									}),
 									organization : $resource(
-											'organization/:orgId', {
-												orgId : '@id'
+											'organization/:id', {
+												id : '@id'
 											}),
 									licensetype : $resource(
-											'licensetype/:licenseTypeId', {
-												licenseTypeId : '@id'
+											'licensetype/:id', {
+												id : '@id'
 											})
 								}
 
@@ -68,12 +68,15 @@
 									return resources[res];
 								}
 								this.getPk = function(catalogMetadata) {
-									if (!catalogMetadata)
+									if (!catalogMetadata) {
 										catalogMetadata = _current;
+									}
 
-									for (var i = 0; i < catalogMetadata.fields.length; i++)
-										if (catalogMetadata.fields[i].pk)
+									for (var i = 0; i < catalogMetadata.fields.length; i++) {
+										if (catalogMetadata.fields[i].pk) {
 											return catalogMetadata.fields[i].name;
+										}
+									}
 
 									return null;
 								}
@@ -167,19 +170,27 @@
 								}
 
 								this.save = function(data) {
-									if (!_current)
+									if (!_current) {
 										throw new Error('There is no current catalog selected');
-
+									}
 									var resource = this.getResource();
 									return resource.save(data, _success, _fail);
+								}
+								this.get = function(id, _onsuccess, _onfail) {
+									if (!_current) {
+										throw new Error('There is no current catalog selected');
+									}
+									var resource = this.getResource();
+									return resource.get({id: id}, _onsuccess, _onfail);
 								}
 								this.remove = function(data) {
 									return this.getResource().remove({}, data,
 											_success, _fail)
 								}
 								this.query = function() {
-									return this.getResource().query({},
-											_success, _fail);
+									var list = this.getResource().query();
+									list.$promise.then(_success, _fail);
+									return list;
 								}
 								this.refreshRef = function(refs, res,
 										preloadedData) {

--
Gitblit v1.3.2