From c2b7a0f1bdb1dd1568c389dc1a100cee3abf53e0 Mon Sep 17 00:00:00 2001 From: Miguel Reboiro-Jato Date: Fri, 10 Feb 2017 12:10:05 +0100 Subject: [PATCH] Cleans and refactorizes PeopleView Some "console.logs" have been removed from the PeopleView class and the full resposibility for the edition and deletion of people has been moved to public methods of PeopleView. --- src/main/webapp/js/view/people.js | 43 ++++++++++++++++--------------- 1 file changed, 22 insertions(+), 21 deletions(-) diff --git a/src/main/webapp/js/view/people.js b/src/main/webapp/js/view/people.js index 1f7bc5e..2c0b0e5 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; })(); -- 2.18.1