Commit 05f35f4c authored by miferreiro's avatar miferreiro

Removed idOwners from pet tables

Now the name and surname of the person who owns the pet is displayed instead of its id.
To do this, we have included the getPeople method in the people dao to obtain the information of a specific person and thus obtain the name and surname to be shown in the table.
parent ee75950a
...@@ -16,6 +16,14 @@ var PeopleDAO = (function() { ...@@ -16,6 +16,14 @@ var PeopleDAO = (function() {
}; };
function PeopleDAO() { function PeopleDAO() {
this.getPeople = function(id,done, fail, always) {
requestByAjax({
url : resourcePath + id,
type : 'GET'
}, done, fail, always);
};
this.listPeople = function(done, fail, always) { this.listPeople = function(done, fail, always) {
requestByAjax({ requestByAjax({
url : resourcePath, url : resourcePath,
......
...@@ -24,7 +24,7 @@ var PeopleView = (function() { ...@@ -24,7 +24,7 @@ var PeopleView = (function() {
}); });
}, },
function() { function() {
alert('No has sido posible acceder al listado de personas.'); alert('No ha sido posible acceder al listado de personas.');
}); });
// La acción por defecto de enviar formulario (submit) se sobreescribe // La acción por defecto de enviar formulario (submit) se sobreescribe
...@@ -110,15 +110,18 @@ var PeopleView = (function() { ...@@ -110,15 +110,18 @@ var PeopleView = (function() {
this.listPets = function(id) { this.listPets = function(id) {
$('.containerGeneric').empty(); $('.containerGeneric').empty();
$('.containerGeneric').append('<div id="pets-container" style="display: show;">\ $('.containerGeneric').append('<div id="pets-container" style="display: show;"></div>');
<h1 class="display-5 mt-3 mb-3">Mascotas</h1>\
</div>');
var viewPets = new PetsView(new PetsDAO(), var viewPets = new PetsView(new PetsDAO(),
'pets-container', 'pets-container', 'pets-container', 'pets-container',
); );
viewPets.initPeople(id);
dao.getPeople(id,
function(person) {
viewPets.initPetsPerson(id, person);
},
showErrorMessage
);
}; };
this.isEditing = function() { this.isEditing = function() {
......
...@@ -17,10 +17,18 @@ var PetsView = (function() { ...@@ -17,10 +17,18 @@ var PetsView = (function() {
insertPetsList($('#' + listContainerId)); insertPetsList($('#' + listContainerId));
this.init = function() { this.init = function() {
$('#' + formContainerId).before('<h1 class="display-5 mt-3 mb-3" id="pets-tittle">Mascotas</h1>');
dao.listPets(function(pets) { dao.listPets(function(pets) {
$.each(pets, function(key, pet) { $.each(pets, function(key, pet) {
appendToTable(pet);
var daoPeople = new PeopleDAO();
daoPeople.getPeople(pet.idOwner,
function(person) {
appendToTable(pet, person);
},
showErrorMessage
);
}); });
}); });
...@@ -58,12 +66,14 @@ var PetsView = (function() { ...@@ -58,12 +66,14 @@ var PetsView = (function() {
$('#btnClearPet').click(this.resetForm); $('#btnClearPet').click(this.resetForm);
}; };
this.initPeople = function(id) { this.initPetsPerson = function(id, person) {
$('#' + formContainerId).before('<h1 class="display-5 mt-3 mb-3" id="pets-tittle">Mascotas de ' + person.name + '</h1>');
dao.listPeoplePets(id, dao.listPeoplePets(id,
function(pets) { function(pets) {
$.each(pets, function(key, pet) { $.each(pets, function(key, pet) {
appendToTable(pet); appendToTable(pet, person);
}); });
}); });
...@@ -184,9 +194,10 @@ var PetsView = (function() { ...@@ -184,9 +194,10 @@ var PetsView = (function() {
'<table id="' + listId + '" class="table">\ '<table id="' + listId + '" class="table">\
<thead>\ <thead>\
<tr class="row">\ <tr class="row">\
<th class="col-sm-3">Nombre</th>\ <th class="col-sm-2" style="text-align:center;">Nombre</th>\
<th class="col-sm-3">Especie</th>\ <th class="col-sm-2" style="text-align:center;">Especie</th>\
<th class="col-sm-3">Propietario</th>\ <th class="col-sm-2" style="text-align:center;">Nombre Propietario</th>\
<th class="col-sm-2" style="text-align:center;">Apellido Propietario</th>\
<th class="col-sm-3">&nbsp;</th>\ <th class="col-sm-3">&nbsp;</th>\
</tr>\ </tr>\
</thead>\ </thead>\
...@@ -219,11 +230,14 @@ var PetsView = (function() { ...@@ -219,11 +230,14 @@ var PetsView = (function() {
); );
}; };
var createPetRow = function(pet) { var createPetRow = function(pet, person) {
return '<tr id="pet-'+ pet.id +'" class="row">\ return '<tr id="pet-'+ pet.id +'" class="row">\
<td class="namePet col-sm-3">' + pet.name + '</td>\ <td class="namePet col-sm-2" style="text-align:center;">' + pet.name + '</td>\
<td class="specie col-sm-3">' + pet.specie + '</td>\ <td class="specie col-sm-2" style="text-align:center;">' + pet.specie + '</td>\
<td class="idOwner col-sm-3">' + pet.idOwner + '</td>\ <td style="display:none;" class="idOwner col-sm-3" style="text-align:center;">' + pet.idOwner + '</td>\
<td class="person-name col-sm-2" style="text-align:center;">' + person.name + '</td>\
<td class="person-surname col-sm-2" style="text-align:center;">' + person.surname + '</td>\
<td class="col-sm-3">\ <td class="col-sm-3">\
<a class="edit btn btn-primary" href="#">Editar</a>\ <a class="edit btn btn-primary" href="#">Editar</a>\
<a class="delete btn btn-warning" href="#">Eliminar</a>\ <a class="delete btn btn-warning" href="#">Eliminar</a>\
...@@ -245,9 +259,9 @@ var PetsView = (function() { ...@@ -245,9 +259,9 @@ var PetsView = (function() {
}); });
}; };
var appendToTable = function(pet) { var appendToTable = function(pet, person) {
$(listQuery + ' > tbody:last') $(listQuery + ' > tbody:last')
.append(createPetRow(pet)); .append(createPetRow(pet, person));
addRowListeners(pet); addRowListeners(pet);
}; };
......
...@@ -43,6 +43,17 @@ ...@@ -43,6 +43,17 @@
doLogout(); doLogout();
}); });
$('.containerGeneric').empty();
$('.containerGeneric').append('<div id="people-container" style="display: show;">\
<h1 class="display-5 mt-3 mb-3">Personas</h1>\
</div>');
var viewPeople = new PeopleView(new PeopleDAO(),
'people-container', 'people-container'
);
viewPeople.init();
$('#people').click(function(event) { $('#people').click(function(event) {
$('.containerGeneric').empty(); $('.containerGeneric').empty();
...@@ -53,15 +64,15 @@ ...@@ -53,15 +64,15 @@
var viewPeople = new PeopleView(new PeopleDAO(), var viewPeople = new PeopleView(new PeopleDAO(),
'people-container', 'people-container' 'people-container', 'people-container'
); );
viewPeople.init(); viewPeople.init();
}); });
$('#pets').click(function(event) { $('#pets').click(function(event) {
$('.containerGeneric').empty(); $('.containerGeneric').empty();
$('.containerGeneric').append('<div id="pets-container" style="display: show;">\ $('.containerGeneric').append('<div id="pets-container" style="display: show;"></div>');
<h1 class="display-5 mt-3 mb-3">Mascotas</h1>\
</div>');
var viewPets = new PetsView(new PetsDAO(), var viewPets = new PetsView(new PetsDAO(),
'pets-container', 'pets-container', 'pets-container', 'pets-container',
......
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