diff --git a/src/main/webapp/js/view/people.js b/src/main/webapp/js/view/people.js index 1f7bc5ec03d301065334b27dd3cbee15c881a8ad..2c0b0e5034d04f5756eb40dc74aa71801567e763 100644 --- a/src/main/webapp/js/view/people.js +++ b/src/main/webapp/js/view/people.js @@ -81,18 +81,27 @@ var PeopleView = (function() { this.editPerson = function(id) { var row = $('#person-' + id); - console.log(row); if (row !== undefined) { var form = $(formQuery); - console.log(form); - console.log(row.find('td.name').text()); - console.log(row.find('td.surname').text()); form.find('input[name="id"]').val(id); form.find('input[name="name"]').val(row.find('td.name').text()); form.find('input[name="surname"]').val(row.find('td.surname').text()); + + $('input#btnSubmit').val('Modificar'); + } + }; + + this.deletePerson = function(id) { + if (confirm('Está a punto de eliminar a una persona. ¿Está seguro de que desea continuar?')) { + dao.deletePerson(id, + function() { + $('tr#person-' + id).remove(); + }, + showErrorMessage + ); } - } + }; this.isEditing = function() { return $(formQuery + ' input[name="id"]').val() != ""; @@ -111,7 +120,7 @@ var PeopleView = (function() { $(formQuery + ' input[name="id"]').val(''); $('#btnSubmit').val('Crear'); }; - } + }; var insertPeopleList = function(parent) { parent.append( @@ -124,7 +133,7 @@ var PeopleView = (function() { \ ' ); - } + }; var insertPeopleForm = function(parent) { parent.append( @@ -136,7 +145,7 @@ var PeopleView = (function() { \ ' ); - } + }; var createPersonRow = function(person) { return '\ @@ -149,35 +158,27 @@ var PeopleView = (function() { Delete\ \ '; - } + }; var showErrorMessage = function(jqxhr, textStatus, error) { alert(textStatus + ": " + error); - } + }; var addRowListeners = function(person) { $('#person-' + person.id + ' a.edit').click(function() { self.editPerson(person.id); - $('input#btnSubmit').val('Modificar'); }); $('#person-' + person.id + ' a.delete').click(function() { - if (confirm('Está a punto de eliminar a una persona. ¿Está seguro de que desea continuar?')) { - dao.deletePerson(person.id, - function() { - $('tr#person-' + person.id).remove(); - }, - showErrorMessage - ); - } + self.deletePerson(person.id); }); - } + }; var appendToTable = function(person) { $(listQuery + ' > tbody:last') .append(createPersonRow(person)); addRowListeners(person); - } + }; return PeopleView; })();