Compare commits

...

3 Commits

15 changed files with 438 additions and 43 deletions

View File

@ -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;
@ -154,6 +176,30 @@ public class AnimalController {
return ret;
}
@RequestMapping(value = IndexController.URL_ANIMAL_EDIT_CARE, method = RequestMethod.POST)
public String doPostEditCare(final ModelMap pModel, HttpSession httpSession,
@PathVariable(value = "animal_id") final int animalId,
@PathVariable(value = "care_id") final int careId,
@RequestParam(name = "name", required = true) String name,
@RequestParam(name = "description", required = false, defaultValue = "") String description) {
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.updateCare(careId, animalId, userDetails.getUsername(), name, description);
}
ret = IndexController.URL_REDIRECT + IndexController.URL_ANIMAL_CARES_AND_BEHAVIORS_LIST.replaceAll("\\{animal_id\\}", animalId + "");
} else {
ret = IndexController.URL_REDIRECT + IndexController.URL_LOGIN;
}
return ret;
}
@RequestMapping(value = IndexController.URL_ANIMAL_CARES_DELETE, method = RequestMethod.POST)
public String doPostDeleteCare(final ModelMap pModel, HttpSession httpSession,
@PathVariable(value = "animal_id") final int animalId,
@ -201,6 +247,30 @@ public class AnimalController {
return ret;
}
@RequestMapping(value = IndexController.URL_ANIMAL_EDIT_CONSENT_BEHAVIOR, method = RequestMethod.POST)
public String doPostEditAnimal(final ModelMap pModel, HttpSession httpSession,
@PathVariable(value = "animal_id") final int animalId,
@PathVariable(value = "consent_behavior_id") final int consentBehaviorId,
@RequestParam(name = "name", required = true) String name,
@RequestParam(name = "description", required = false, defaultValue = "") String description) {
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.updateConsentBehavior(consentBehaviorId, animalId, userDetails.getUsername(), name, description);
}
ret = IndexController.URL_REDIRECT + IndexController.URL_ANIMAL_CARES_AND_BEHAVIORS_LIST.replaceAll("\\{animal_id\\}", animalId + "");
} else {
ret = IndexController.URL_REDIRECT + IndexController.URL_LOGIN;
}
return ret;
}
@RequestMapping(value = IndexController.URL_ANIMAL_CONSENT_BEHAVIOR_DELETE, method = RequestMethod.POST)
public String doPostDeleteConsentBehavior(final ModelMap pModel, HttpSession httpSession,
@PathVariable(value = "animal_id") final int animalId,

View File

@ -59,6 +59,10 @@ 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/{animal_id}/edit";
public static final String URL_ANIMAL_EDIT_CARE = "/animal/{animal_id}/edit/care/{care_id}";
public static final String URL_ANIMAL_EDIT_CONSENT_BEHAVIOR = "/animal/{animal_id}/edit/consent_behavior/{consent_behavior_id}";
public static final String URL_REDIRECT = "redirect:";
//</editor-fold>

View File

@ -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);
}

View File

@ -16,4 +16,6 @@ public interface ICareDao extends CommonDao {
public void addCare(int animalId, String name, String description);
public void deleteCare(int careId, int animalId, String owner);
public void deleteAllAnimalCares(int animalId, String owner);
public void updateCare(int careId, int animalId, String owner, String name, String description);
}

View File

@ -15,4 +15,6 @@ public interface IConsentBehaviorDao extends CommonDao {
public void addConsentBehavior(int animalId, String name, String description);
public void deleteConsentBehavior(int consentBehaviorId, int animalId, String owner);
public void deleteAllAnimalConsentBehavior(int animalId, String owner);
public void updateConsentBehavior(int consentBehaviorId, int animalId, String owner, String name, String description);
}

View File

@ -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()");
}
}
}
}
}

View File

@ -254,4 +254,41 @@ public class CareDao extends PostgresSqlDao implements ICareDao {
}
}
}
@Override
public void updateCare(int careId, int animalId, String owner, String name, String description) {
Connection conn = null;
PreparedStatement statement = null;
try {
conn = mDataSource.getConnection();
statement = conn.prepareStatement("UPDATE "+TABLE_NAME+" SET name = ?, description = ? WHERE id = ? AND animal = ("
+ "SELECT id FROM "+AnimalDao.TABLE_NAME+" WHERE owner = ? AND id = ?)");
statement.setString(1, name);
statement.setString(2, description);
statement.setInt(3, careId);
statement.setString(4, owner);
statement.setInt(5, animalId);
System.out.println(IndexController.LOG_TAG + " SQL -> " + statement.toString());
statement.executeUpdate();
} catch (SQLException ex) {
System.err.println(IndexController.LOG_TAG + " SQLException -> updateCare()");
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 -> updateCare()");
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
System.err.println(IndexController.LOG_TAG + " Failed close connection -> updateCare()");
}
}
}
}
}

View File

@ -254,4 +254,41 @@ public class ConsentBehaviorDao extends PostgresSqlDao implements IConsentBehavi
}
}
}
@Override
public void updateConsentBehavior(int consentBehaviorId, int animalId, String owner, String name, String description) {
Connection conn = null;
PreparedStatement statement = null;
try {
conn = mDataSource.getConnection();
statement = conn.prepareStatement("UPDATE "+TABLE_NAME+" SET name = ?, description = ? WHERE id = ? AND animal = ("
+ "SELECT id FROM "+AnimalDao.TABLE_NAME+" WHERE owner = ? AND id = ?)");
statement.setString(1, name);
statement.setString(2, description);
statement.setInt(3, consentBehaviorId);
statement.setString(4, owner);
statement.setInt(5, animalId);
System.out.println(IndexController.LOG_TAG + " SQL -> " + statement.toString());
statement.executeUpdate();
} catch (SQLException ex) {
System.err.println(IndexController.LOG_TAG + " SQLException -> updateConsentBehavior()");
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 -> updateConsentBehavior()");
}
}
if (conn != null) {
try {
conn.close();
} catch (SQLException ex) {
System.err.println(IndexController.LOG_TAG + " Failed close connection -> updateConsentBehavior()");
}
}
}
}
}

View File

@ -27,4 +27,9 @@ 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);
public void updateCare(int careId, int animalId, String owner, String name, String description);
public void updateConsentBehavior(int consentBehaviorId, int animalId, String owner, String name, String description);
}

View File

@ -150,4 +150,19 @@ 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);
}
@Override
public void updateCare(int careId, int animalId, String owner, String name, String description) {
careDao.updateCare(careId, animalId, owner, name, description);
}
@Override
public void updateConsentBehavior(int consentBehaviorId, int animalId, String owner, String name, String description) {
consentBehaviorDao.updateConsentBehavior(consentBehaviorId, animalId, owner, name, description);
}
}

View File

@ -89,3 +89,19 @@ 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
animal_care_and_behavior.button.edit.tooltip=Edit
animal_list.edit_animal.modal.title=Editing animal's name
animal_care_and_behavior.edit_care.modal.title=Editing care
animal_care_and_behavior.edit_care.modal.name.label=Care name:
animal_care_and_behavior.edit_care.modal.name.placeholder=Care name
animal_care_and_behavior.edit_care.modal.description.label=Care description:
animal_care_and_behavior.edit_care.modal.description.placeholder=Care description (optional)
animal_care_and_behavior.edit_behavior.modal.title=Editing consent behavior
animal_care_and_behavior.edit_behavior.modal.name.label=Consent behavior name:
animal_care_and_behavior.edit_behavior.modal.name.placeholder=Consent behavior name
animal_care_and_behavior.edit_behavior.modal.description.label=Consent behavior description:
animal_care_and_behavior.edit_behavior.modal.description.placeholder=Consent behavior description (optional)

View File

@ -85,3 +85,19 @@ 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
animal_care_and_behavior.button.edit.tooltip=Edit
animal_list.edit_animal.modal.title=Editing animal's name
animal_care_and_behavior.edit_care.modal.title=Editing care
animal_care_and_behavior.edit_care.modal.name.label=Care name:
animal_care_and_behavior.edit_care.modal.name.placeholder=Care name
animal_care_and_behavior.edit_care.modal.description.label=Care description:
animal_care_and_behavior.edit_care.modal.description.placeholder=Care description (optional)
animal_care_and_behavior.edit_behavior.modal.title=Editing consent behavior
animal_care_and_behavior.edit_behavior.modal.name.label=Consent behavior name:
animal_care_and_behavior.edit_behavior.modal.name.placeholder=Consent behavior name
animal_care_and_behavior.edit_behavior.modal.description.label=Consent behavior description:
animal_care_and_behavior.edit_behavior.modal.description.placeholder=Consent behavior description (optional)

View File

@ -85,3 +85,19 @@ 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
animal_care_and_behavior.button.edit.tooltip=Modifier
animal_list.edit_animal.modal.title=Modifier le nom de l'animal
animal_care_and_behavior.edit_care.modal.title=Modification du soin
animal_care_and_behavior.edit_care.modal.name.label=Nom du soin :
animal_care_and_behavior.edit_care.modal.name.placeholder=Nom du soin
animal_care_and_behavior.edit_care.modal.description.label=Description du soin :
animal_care_and_behavior.edit_care.modal.description.placeholder=Description du soin (optionelle)
animal_care_and_behavior.edit_behavior.modal.title=Modification du comportement de consentement
animal_care_and_behavior.edit_behavior.modal.name.label=Nom du comportement de consentement :
animal_care_and_behavior.edit_behavior.modal.name.placeholder=Nom du comportement de consentement
animal_care_and_behavior.edit_behavior.modal.description.label=Description du comportement de consentment :
animal_care_and_behavior.edit_behavior.modal.description.placeholder=Description du comportement de consentement (optionelle)

View File

@ -6,8 +6,10 @@
<%@ page isELIgnored="false" %>
<spring:url value="/animal/${MODEL_MAP_ANIMAL.getId()}/add/care" var="animalAddCareURL" />
<spring:url value="/animal/${MODEL_MAP_ANIMAL.getId()}/delete/care" var="animalDeleteCareURL" />
<spring:url value="/animal/${MODEL_MAP_ANIMAL.getId()}/edit/care" var="animalEditCareURL" />
<spring:url value="/animal/${MODEL_MAP_ANIMAL.getId()}/add/consent_behavior" var="animalAddConsentBehaviorURL" />
<spring:url value="/animal/${MODEL_MAP_ANIMAL.getId()}/delete/consent_behavior" var="animalDeleteConsentBehaviorURL" />
<spring:url value="/animal/${MODEL_MAP_ANIMAL.getId()}/edit/consent_behavior" var="animalEditConsentBehaviorURL" />
<%@ include file="base/language.jsp" %>
@ -56,6 +58,12 @@
<input value="${care.getName()}" hidden />
<button class="btn btn-danger" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_care_and_behavior.button.delete.tooltip"></fmt:message>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</form>
<form class="pull-right" action="${animalEditCareURL}/${care.getId()}" method="GET">
<input value="${care.getName()}" hidden />
<input value="${care.getDescription()}" hidden />
<button class="btn btn-default" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_care_and_behavior.button.edit.tooltip"></fmt:message>"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></button>
</form>
</div>
</div>
<div class="row">
@ -89,6 +97,12 @@
<input value="${consentBehavior.getName()}" hidden />
<button class="btn btn-danger" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_care_and_behavior.button.delete.tooltip"></fmt:message>"><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></button>
</form>
<form class="pull-right" action="${animalEditConsentBehaviorURL}/${consentBehavior.getId()}" method="GET">
<input value="${consentBehavior.getName()}" hidden />
<input value="${consentBehavior.getDescription()}" hidden />
<button class="btn btn-default" type="submit" data-toggle="tooltip" data-placement="bottom" title="<fmt:message key="animal_care_and_behavior.button.edit.tooltip"></fmt:message>"><span class="glyphicon glyphicon-edit" aria-hidden="true"></span></button>
</form>
</div>
</div>
<div class="row">
@ -134,6 +148,60 @@
</div>
</div>
<!-- Edit care -->
<div id="modal_edit_care" 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">&times;</button>
<h4 id="modal_edit_care_title" class="modal-title"><fmt:message key="animal_care_and_behavior.edit_care.modal.title"></fmt:message></h4>
</div>
<div class="modal-body">
<form id="modal_edit_care_form" action="" method="POST">
<label for="modal_edit_care_form_care_name"><fmt:message key="animal_care_and_behavior.edit_care.modal.name.label"></fmt:message></label>
<input type="text" id="modal_edit_care_form_care_name" name="name" class="form-control" placeholder="<fmt:message key="animal_care_and_behavior.edit_care.modal.name.placeholder"></fmt:message>" required />
<label for="modal_edit_care_form_care_description"><fmt:message key="animal_care_and_behavior.edit_care.modal.description.label"></fmt:message></label>
<textarea id="modal_edit_care_form_care_description" name="description" class="form-control" placeholder="<fmt:message key="animal_care_and_behavior.edit_care.modal.description.placeholder"></fmt:message>" ></textarea>
</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_care_form" type="submit" class="btn btn-primary"><fmt:message key="modal_button.edit"></fmt:message></button>
</div>
</div>
</div>
</div>
<!-- Edit behavior -->
<div id="modal_edit_consent_behavior" 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">&times;</button>
<h4 id="modal_edit_consent_behavior_title" class="modal-title"><fmt:message key="animal_care_and_behavior.edit_behavior.modal.title"></fmt:message></h4>
</div>
<div class="modal-body">
<form id="modal_edit_consent_behavior_form" action="" method="POST">
<label for="modal_edit_consent_behavior_form_behavior_name"><fmt:message key="animal_care_and_behavior.edit_behavior.modal.name.label"></fmt:message></label>
<input type="text" id="modal_edit_consent_behavior_form_behavior_name" name="name" class="form-control" placeholder="<fmt:message key="animal_care_and_behavior.edit_behavior.modal.name.placeholder"></fmt:message>" required />
<label for="modal_edit_consent_behavior_form_behavior_description"><fmt:message key="animal_care_and_behavior.edit_behavior.modal.description.label"></fmt:message></label>
<textarea id="modal_edit_consent_behavior_form_behavior_description" name="description" class="form-control" placeholder="<fmt:message key="animal_care_and_behavior.edit_behavior.modal.description.placeholder"></fmt:message>" ></textarea>
</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_consent_behavior_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">
@ -157,6 +225,36 @@
show: true
});
event.preventDefault();
} else if (formUrl.startsWith('${animalEditCareURL}')) {
if ($(this).attr('id') !== 'modal_edit_care_form') {
// Only for editing care form
var data = $(this).find('input');
var careName = data[0].value;
var careDesc = data[1].value;
$('#modal_edit_care_form').attr('action', formUrl);
$('#modal_edit_care_form_care_name').val(careName);
$('#modal_edit_care_form_care_description').val(careDesc);
$('#modal_edit_care').modal({
show: true
});
event.preventDefault();
}
} else if (formUrl.startsWith('${animalEditConsentBehaviorURL}')) {
if ($(this).attr('id') !== 'modal_edit_consent_behavior_form') {
// Only for editing care form
var data = $(this).find('input');
var consentBehaviorName = data[0].value;
var consentBehaviorDesc = data[1].value;
$('#modal_edit_consent_behavior_form').attr('action', formUrl);
$('#modal_edit_consent_behavior_form_behavior_name').val(consentBehaviorName);
$('#modal_edit_consent_behavior_form_behavior_description').val(consentBehaviorDesc);
$('#modal_edit_consent_behavior').modal({
show: true
});
event.preventDefault();
}
}
}
});

View File

@ -44,6 +44,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="${animalURL}/${animal.getId()}/edit" 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()}
@ -60,7 +65,7 @@
<form id="addAnimalForm" class="form-inline" action="${animalURL}" method="POST">
<div class="form-group">
<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>
<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>
@ -119,6 +124,30 @@
</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">&times;</button>
<h4 id="modal_edit_animal_title" class="modal-title"><fmt:message key="animal_list.edit_animal.modal.title"></fmt:message></h4>
</div>
<div class="modal-body">
<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 +155,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 +167,18 @@
});
event.preventDefault();
}
} else if (formUrl.match(new RegExp('${animalURL}/[0-9]+/edit', 'g'))) {
if ($(this).attr('id') !== 'modal_edit_animal_form') {
// Only for editing animal form
var animalName = $(this).find('input')[0].value;
$('#modal_edit_animal_form').attr('action', formUrl);
$('#modal_edit_animal_form_name').val(animalName);
$('#modal_edit_animal').modal({
show: true
});
event.preventDefault();
}
}
});
});