diff --git a/src/main/webapp/js/dao/pet.js b/src/main/webapp/js/dao/pet.js index 5d97cebec8691d50307e119131f5ff864e173004..628d28d49f7b96ee9cc21a01f8375148fd773d2a 100644 --- a/src/main/webapp/js/dao/pet.js +++ b/src/main/webapp/js/dao/pet.js @@ -1,4 +1,4 @@ -var PetDAO = (function(ownerID) { +var PetDAO = (function() { var resourcePath = "rest/pet/"; var requestByAjax = function(data, done, fail, always) { done = typeof done !== 'undefined' ? done : function() {}; @@ -11,18 +11,6 @@ var PetDAO = (function(ownerID) { .always(always); }; - var setOwnerIDPetDAO = function(ownerID, done, fail, always) { - var query = window.location.search.substring(1); - var split = query.split("="); - var getID = decodeURIComponent(split[1]); - //alert(getID); - requestByAjax({ - url: resourcePath + getID, - type: 'POST', - data: getID - }, done, fail, always); - }(); - function PetDAO() { this.listPets = function(done, fail, always) { requestByAjax({ @@ -32,14 +20,10 @@ var PetDAO = (function(ownerID) { }; this.setOwnerIDPetDAO = function(ownerID, done, fail, always) { - var query = window.location.search.substring(1); - var split = query.split("="); - var getID = decodeURIComponent(split[1]); - //alert(getID); requestByAjax({ - url: resourcePath + getID, + url: resourcePath + ownerID, type: 'POST', - data: getID + data: ownerID }, done, fail, always); }; diff --git a/src/main/webapp/js/view/pet.js b/src/main/webapp/js/view/pet.js index 5ce579318349d15bec65dd7f16c30bea998341da..7d2bb508ed3196d19f6d46df116aed367ea0245b 100644 --- a/src/main/webapp/js/view/pet.js +++ b/src/main/webapp/js/view/pet.js @@ -9,11 +9,20 @@ var PetView = (function() { var listId = 'pet-list'; var formQuery = '#' + formId; var listQuery = '#' + listId; + + var getQueryParameter = function(name) { + var results = new RegExp('[\?&]' + name + '=([^]*)') + .exec(window.location.href); + + return results === null ? null : results[1] || 0; + }; function PetView(petDao, formContainerId, listContainerId) { dao = petDao; self = this; - dao.setOwnerIDPetDAO(); + + dao.setOwnerIDPetDAO(getQueryParameter('id')); + insertPetForm($('#' + formContainerId)); insertPetList($('#' + listContainerId));