Commit 1a64cd50 authored by Administrator's avatar Administrator

Fixes problems with owner's id retrieval in the view

The retrieval of the owner's id from the URL now works properly. A function has
been added to PetView to make it easier to retrieve values from the URL.
parent c07ce0ea
var PetDAO = (function(ownerID) { var PetDAO = (function() {
var resourcePath = "rest/pet/"; var resourcePath = "rest/pet/";
var requestByAjax = function(data, done, fail, always) { var requestByAjax = function(data, done, fail, always) {
done = typeof done !== 'undefined' ? done : function() {}; done = typeof done !== 'undefined' ? done : function() {};
...@@ -11,18 +11,6 @@ var PetDAO = (function(ownerID) { ...@@ -11,18 +11,6 @@ var PetDAO = (function(ownerID) {
.always(always); .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() { function PetDAO() {
this.listPets = function(done, fail, always) { this.listPets = function(done, fail, always) {
requestByAjax({ requestByAjax({
...@@ -32,14 +20,10 @@ var PetDAO = (function(ownerID) { ...@@ -32,14 +20,10 @@ var PetDAO = (function(ownerID) {
}; };
this.setOwnerIDPetDAO = function(ownerID, done, fail, always) { 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({ requestByAjax({
url: resourcePath + getID, url: resourcePath + ownerID,
type: 'POST', type: 'POST',
data: getID data: ownerID
}, done, fail, always); }, done, fail, always);
}; };
......
...@@ -10,10 +10,19 @@ var PetView = (function() { ...@@ -10,10 +10,19 @@ var PetView = (function() {
var formQuery = '#' + formId; var formQuery = '#' + formId;
var listQuery = '#' + listId; 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) { function PetView(petDao, formContainerId, listContainerId) {
dao = petDao; dao = petDao;
self = this; self = this;
dao.setOwnerIDPetDAO();
dao.setOwnerIDPetDAO(getQueryParameter('id'));
insertPetForm($('#' + formContainerId)); insertPetForm($('#' + formContainerId));
insertPetList($('#' + listContainerId)); insertPetList($('#' + listContainerId));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment