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 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);
};
......
......@@ -10,10 +10,19 @@ var PetView = (function() {
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));
......
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