Fix some bug on animal list edition.

This commit is contained in:
Geoffrey POUZET 2020-10-25 16:10:53 +01:00
parent fcbe488095
commit 7574a59d14
1 changed files with 4 additions and 7 deletions

View File

@ -4,7 +4,6 @@
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%> <%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
<%@ page isELIgnored="false" %> <%@ page isELIgnored="false" %>
<spring:url value="/animal/delete" var="animalDeleteURL" /> <spring:url value="/animal/delete" var="animalDeleteURL" />
<spring:url value="/animal/edit" var="animalEditURL" />
<spring:url value="/change_password" var="changePasswordURL" /> <spring:url value="/change_password" var="changePasswordURL" />
<%@ include file="base/language.jsp" %> <%@ include file="base/language.jsp" %>
@ -46,7 +45,7 @@
<button class="btn btn-xs btn-danger" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_list.animal.delete.tooltip"></fmt:message>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button> <button class="btn btn-xs btn-danger" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_list.animal.delete.tooltip"></fmt:message>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</form> </form>
<form class="pull-right" action="${animalEditURL}/${animal.getId()}" method="GET"> <form class="pull-right" action="${animalURL}/${animal.getId()}/edit" method="GET">
<input value="${animal.getName()}" hidden /> <input value="${animal.getName()}" hidden />
<button class="btn btn-xs btn-default" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_list.animal.edit.tooltip"></fmt:message>"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></button> <button class="btn btn-xs btn-default" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_list.animal.edit.tooltip"></fmt:message>"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></button>
</form> </form>
@ -66,7 +65,7 @@
<form id="addAnimalForm" class="form-inline" action="${animalURL}" method="POST"> <form id="addAnimalForm" class="form-inline" action="${animalURL}" method="POST">
<div class="form-group"> <div class="form-group">
<label for="form_animal_name"><fmt:message key="animal_list.animal.add.label"></fmt:message></label> <label for="form_animal_name"><fmt:message key="animal_list.animal.add.label"></fmt:message></label>
<input type="text" id="form_animal_name" name="name" class="form-control" placeholder="<fmt:message key="animal_list.animal.add.placeholder"></fmt:message>" /> <input type="text" id="form_animal_name" name="name" class="form-control" placeholder="<fmt:message key="animal_list.animal.add.placeholder"></fmt:message>" required />
</div> </div>
<button class="btn btn btn-success" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_list.animal.add.tooltip"></fmt:message>"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button> <button class="btn btn btn-success" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_list.animal.add.tooltip"></fmt:message>"><span class="glyphicon glyphicon-plus" aria-hidden="true"></span></button>
</form> </form>
@ -133,10 +132,9 @@
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<button type="button" class="close" data-dismiss="modal">&times;</button> <button type="button" class="close" data-dismiss="modal">&times;</button>
<h4 id="modal_edit_animal_title" class="modal-title">Animal name</h4> <h4 id="modal_edit_animal_title" class="modal-title"><fmt:message key="animal_list.edit_animal.modal.title"></fmt:message></h4>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<p id="modal_delete_animal_body"><fmt:message key="animal_list.delete.modal_body"></fmt:message></p>
<form id="modal_edit_animal_form" action="" method="POST"> <form id="modal_edit_animal_form" action="" method="POST">
<label for="modal_edit_animal_form_name"><fmt:message key="animal_list.edit_animal.modal.label"></fmt:message></label> <label for="modal_edit_animal_form_name"><fmt:message key="animal_list.edit_animal.modal.label"></fmt:message></label>
<input type="text" id="modal_edit_animal_form_name" name="name" class="form-control" placeholder="<fmt:message key="animal_list.edit_animal.modal.placeholder"></fmt:message>" required/> <input type="text" id="modal_edit_animal_form_name" name="name" class="form-control" placeholder="<fmt:message key="animal_list.edit_animal.modal.placeholder"></fmt:message>" required/>
@ -170,11 +168,10 @@
event.preventDefault(); event.preventDefault();
} }
} else if (formUrl.startsWith('${animalEditURL}')) { } else if (formUrl.match(new RegExp('${animalURL}/[0-9]+/edit', 'g'))) {
if ($(this).attr('id') !== 'modal_edit_animal_form') { if ($(this).attr('id') !== 'modal_edit_animal_form') {
// Only for editing animal form // Only for editing animal form
var animalName = $(this).find('input')[0].value; var animalName = $(this).find('input')[0].value;
$('#modal_edit_animal_title').text(animalName);
$('#modal_edit_animal_form').attr('action', formUrl); $('#modal_edit_animal_form').attr('action', formUrl);
$('#modal_edit_animal_form_name').val(animalName); $('#modal_edit_animal_form_name').val(animalName);
$('#modal_edit_animal').modal({ $('#modal_edit_animal').modal({