Can edit animal's name.
This commit is contained in:
parent
f1b94f48b8
commit
fcbe488095
|
|
@ -82,6 +82,28 @@ public class AnimalController {
|
|||
return ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = IndexController.URL_ANIMAL_EDIT, method = RequestMethod.POST)
|
||||
public String doPostEditAnimal(final ModelMap pModel, HttpSession httpSession,
|
||||
@PathVariable(value = "animal_id") final int animalId,
|
||||
@RequestParam(name = "name", required = true) String name) {
|
||||
|
||||
String ret;
|
||||
if (LoginController.isUserAlreadyAuth(httpSession)) {
|
||||
Authentication authentication = (Authentication) httpSession.getAttribute(IndexController.SESSION_ATTRIBUTE_AUTHENTICATION);
|
||||
Object oUserDetails = authentication.getPrincipal();
|
||||
if (oUserDetails instanceof UserDetails) {
|
||||
UserDetails userDetails = (UserDetails) oUserDetails;
|
||||
|
||||
serviceAnimal.changeAnimalName(animalId, userDetails.getUsername(), name);
|
||||
}
|
||||
ret = IndexController.URL_REDIRECT + IndexController.URL_ANIMAL_LIST;
|
||||
} else {
|
||||
ret = IndexController.URL_REDIRECT + IndexController.URL_LOGIN;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
@RequestMapping(value = IndexController.URL_ANIMAL_DELETE, method = RequestMethod.POST)
|
||||
public String doGetDeleteAnimal(final ModelMap pModel, HttpSession httpSession, @PathVariable(value = "animal_id") final int animalId) {
|
||||
String ret;
|
||||
|
|
|
|||
|
|
@ -59,6 +59,8 @@ public class IndexController {
|
|||
public static final String URL_ANIMAL_CARES_DELETE = "/animal/{animal_id}/delete/care/{care_id}";
|
||||
public static final String URL_ANIMAL_CONSENT_BEHAVIOR_DELETE = "/animal/{animal_id}/delete/consent_behavior/{consent_behavior_id}";
|
||||
public static final String URL_ANIMAL_PROGRESSION_DELETE = "/animal/{animal_id}/delete/progression/{progression_id}";
|
||||
// Edit URL
|
||||
public static final String URL_ANIMAL_EDIT = "/animal/edit/{animal_id}";
|
||||
|
||||
public static final String URL_REDIRECT = "redirect:";
|
||||
//</editor-fold>
|
||||
|
|
|
|||
|
|
@ -14,4 +14,6 @@ public interface IAnimalDao extends CommonDao {
|
|||
|
||||
public void addAnimal(String name, String owner);
|
||||
public void deleteAnimal(int animalId, String owner);
|
||||
|
||||
public void changeName(int animalId, String owner, String name);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -201,4 +201,38 @@ public class AnimalDao extends PostgresSqlDao implements IAnimalDao {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeName(int animalId, String owner, String name) {
|
||||
Connection conn = null;
|
||||
PreparedStatement statement = null;
|
||||
try {
|
||||
conn = mDataSource.getConnection();
|
||||
statement = conn.prepareStatement("UPDATE "+TABLE_NAME+" SET name = ? WHERE id = ? AND owner = ?;");
|
||||
statement.setString(1, name);
|
||||
statement.setInt(2, animalId);
|
||||
statement.setString(3, owner);
|
||||
System.out.println(IndexController.LOG_TAG + " SQL -> " + statement.toString());
|
||||
statement.executeUpdate();
|
||||
} catch (SQLException ex) {
|
||||
System.err.println(IndexController.LOG_TAG + " SQLException -> changeName()");
|
||||
System.err.println(ex.getMessage());
|
||||
ex.printStackTrace();
|
||||
} finally {
|
||||
if (statement != null) {
|
||||
try {
|
||||
statement.close();
|
||||
} catch (SQLException ex) {
|
||||
System.err.println(IndexController.LOG_TAG + " Failed close statement -> changeName()");
|
||||
}
|
||||
}
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException ex) {
|
||||
System.err.println(IndexController.LOG_TAG + " Failed close connection -> changeName()");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,4 +27,6 @@ public interface IServiceAnimal {
|
|||
public void deleteAnimalConsentBehavior(int animalId, String owner, int consentBehaviorId);
|
||||
public void deleteAnimalProgression(int animalId, String owner, int progressionId);
|
||||
|
||||
public void changeAnimalName(int animalId, String owner, String name);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,4 +150,9 @@ public class ServiceAnimal implements IServiceAnimal {
|
|||
public void addProgression(int animalId, int careId, int consentBehaviorId) {
|
||||
progressionDao.addProgression(animalId, careId, consentBehaviorId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changeAnimalName(int animalId, String owner, String name) {
|
||||
animalDao.changeName(animalId, owner, name);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -89,3 +89,7 @@ animal_behavior.button.delete.tooltip=Delete
|
|||
animal_behavior.button.add.tooltip=Add
|
||||
animal_behavior.add_care=Add care to this consent behavior
|
||||
animal_behavior.add_care.empty_list=No more cares to add
|
||||
animal_list.animal.edit.tooltip=Edit
|
||||
animal_list.edit_animal.modal.label=Animal's name:
|
||||
animal_list.edit_animal.modal.placeholder=New name
|
||||
modal_button.edit=Edit
|
||||
|
|
|
|||
|
|
@ -85,3 +85,7 @@ animal_behavior.button.delete.tooltip=Delete
|
|||
animal_behavior.button.add.tooltip=Add
|
||||
animal_behavior.add_care=Add care to this consent behavior
|
||||
animal_behavior.add_care.empty_list=No more cares to add
|
||||
animal_list.animal.edit.tooltip=Edit
|
||||
animal_list.edit_animal.modal.label=Animal's name:
|
||||
animal_list.edit_animal.modal.placeholder=New name
|
||||
modal_button.edit=Edit
|
||||
|
|
|
|||
|
|
@ -85,3 +85,7 @@ animal_behavior.button.delete.tooltip=Supprimer
|
|||
animal_behavior.button.add.tooltip=Ajouter
|
||||
animal_behavior.add_care=Ajouter un soin \u00e0 ce comportement de consentement
|
||||
animal_behavior.add_care.empty_list=Aucun soins \u00e0 ajouter
|
||||
animal_list.animal.edit.tooltip=Modifier
|
||||
animal_list.edit_animal.modal.label=Nom de l'animal :
|
||||
animal_list.edit_animal.modal.placeholder=Nouveau nom
|
||||
modal_button.edit=Modifier
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@
|
|||
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring"%>
|
||||
<%@ page isELIgnored="false" %>
|
||||
<spring:url value="/animal/delete" var="animalDeleteURL" />
|
||||
<spring:url value="/animal/edit" var="animalEditURL" />
|
||||
<spring:url value="/change_password" var="changePasswordURL" />
|
||||
|
||||
<%@ include file="base/language.jsp" %>
|
||||
|
|
@ -44,6 +45,11 @@
|
|||
<input value="${animal.getName()}" hidden />
|
||||
<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 class="pull-right" action="${animalEditURL}/${animal.getId()}" method="GET">
|
||||
<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>
|
||||
</form>
|
||||
</a>
|
||||
<!-- <div class="list-group-item">
|
||||
${animal.getName()}
|
||||
|
|
@ -119,6 +125,31 @@
|
|||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="modal_edit_animal" class="modal fade" role="dialog">
|
||||
<div class="modal-dialog">
|
||||
|
||||
<!-- Modal content-->
|
||||
<div class="modal-content">
|
||||
<div class="modal-header">
|
||||
<button type="button" class="close" data-dismiss="modal">×</button>
|
||||
<h4 id="modal_edit_animal_title" class="modal-title">Animal name</h4>
|
||||
</div>
|
||||
<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">
|
||||
<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/>
|
||||
</form>
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="button" class="btn btn-default" data-dismiss="modal"><fmt:message key="modal_button.cancel"></fmt:message></button>
|
||||
<button form="modal_edit_animal_form" type="submit" class="btn btn-primary"><fmt:message key="modal_button.edit"></fmt:message></button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
|
||||
<script type="text/javascript">
|
||||
|
|
@ -126,9 +157,9 @@
|
|||
$('[data-toggle="tooltip"]').tooltip();
|
||||
|
||||
$("form").submit(function (event) {
|
||||
if ($(this).attr('id') !== 'modal_delete_animal_validate_delete') {
|
||||
var formUrl = $(this).attr('action');
|
||||
if (formUrl.startsWith('${animalDeleteURL}')) {
|
||||
if ($(this).attr('id') !== 'modal_delete_animal_validate_delete') {
|
||||
// Only for deleting animal forms
|
||||
var animalName = $(this).find('input')[0].value;
|
||||
$('#modal_delete_animal_title').text(animalName);
|
||||
|
|
@ -138,6 +169,19 @@
|
|||
});
|
||||
event.preventDefault();
|
||||
}
|
||||
|
||||
} else if (formUrl.startsWith('${animalEditURL}')) {
|
||||
if ($(this).attr('id') !== 'modal_edit_animal_form') {
|
||||
// Only for editing animal form
|
||||
var animalName = $(this).find('input')[0].value;
|
||||
$('#modal_edit_animal_title').text(animalName);
|
||||
$('#modal_edit_animal_form').attr('action', formUrl);
|
||||
$('#modal_edit_animal_form_name').val(animalName);
|
||||
$('#modal_edit_animal').modal({
|
||||
show: true
|
||||
});
|
||||
event.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue