Commit a022bc20 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza
Browse files

Bug: User can to save a list with an existing title or with empty title - fixed.

parent b0932fa8
...@@ -306,7 +306,14 @@ public class SelectionController extends BaseController { ...@@ -306,7 +306,14 @@ public class SelectionController extends BaseController {
AccessionList accessionList = new AccessionList(); AccessionList accessionList = new AccessionList();
return saveOrUpdateList(title, description, shared, redirectAttrs, accessionList); if (title.equals("")) {
throw new RuntimeException("AccessionList title can not be empty string.");
}
if (accessionListService.getUUIDByTitle(title) == null) {
return saveOrUpdateList(title.trim(), description, shared, redirectAttrs, accessionList);
} else {
throw new RuntimeException("AccessionList title '" + title + "' is already in use.");
}
} }
@RequestMapping(value = "/userList", params = { "update", "uuid" }, method = RequestMethod.POST) @RequestMapping(value = "/userList", params = { "update", "uuid" }, method = RequestMethod.POST)
...@@ -316,7 +323,7 @@ public class SelectionController extends BaseController { ...@@ -316,7 +323,7 @@ public class SelectionController extends BaseController {
AccessionList accessionList = accessionListService.getList(uuid); AccessionList accessionList = accessionListService.getList(uuid);
return saveOrUpdateList(title, description, shared, redirectAttrs, accessionList); return saveOrUpdateList(title.trim(), description, shared, redirectAttrs, accessionList);
} }
/** /**
......
...@@ -815,6 +815,8 @@ userlist.disconnect=Disconnect list ...@@ -815,6 +815,8 @@ userlist.disconnect=Disconnect list
userlist.update-list=Save updated list userlist.update-list=Save updated list
userlist.make-new-list=Create new list userlist.make-new-list=Create new list
userlist.shared=Allow others to access the list userlist.shared=Allow others to access the list
userlist.existing-title.error=Your title is already in use.
userlist.empty-title.error=The title can not be empty string.
region.page.list.title = FAO Geographical regions region.page.list.title = FAO Geographical regions
region.page.list.intro = FAO Geographical regions lists below allow you to access the data about accessions collected or maintained in the region. region.page.list.intro = FAO Geographical regions lists below allow you to access the data about accessions collected or maintained in the region.
......
...@@ -5645,6 +5645,9 @@ table.accessions { ...@@ -5645,6 +5645,9 @@ table.accessions {
} }
padding: 0; padding: 0;
} }
.alert-danger {
padding: 15px !important;
}
.genesys-page form.form-horizontal .form-group input.span3.required.form-control { .genesys-page form.form-horizontal .form-group input.span3.required.form-control {
width: 100%; width: 100%;
} }
......
...@@ -188,6 +188,12 @@ ...@@ -188,6 +188,12 @@
<div class="form-group"> <div class="form-group">
<label for="accessionListTitle" class="control-label"><spring:message code="userlist.title" /></label> <label for="accessionListTitle" class="control-label"><spring:message code="userlist.title" /></label>
<input id="accessionListTitle" type="text" name="title" class="form-control" value="${selection.userAccessionList.title}"/> <input id="accessionListTitle" type="text" name="title" class="form-control" value="${selection.userAccessionList.title}"/>
<div class="alert alert-danger" id="emptyTitleError" style="display: none; border: 1px solid #ebccd1">
<spring:message code="userlist.empty-title.error"/>
</div>
<div class="alert alert-danger" id="existingTitleError" style="display: none; border: 1px solid #ebccd1">
<spring:message code="userlist.existing-title.error"/>
</div>
</div> </div>
<div class="form-group"> <div class="form-group">
<label for="accessionListShared" class="control-label"> <label for="accessionListShared" class="control-label">
...@@ -211,7 +217,7 @@ ...@@ -211,7 +217,7 @@
</a> </a>
</security:authorize> </security:authorize>
</c:if> </c:if>
<input type="submit" class="btn btn-primary" value="<spring:message code="userlist.make-new-list"/>" name="save"/> <input type="submit" class="btn btn-primary" id="makeNewListBtn" disabled value="<spring:message code="userlist.make-new-list"/>" name="save"/>
</div> </div>
<!-- CSRF protection --> <!-- CSRF protection -->
<input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/> <input type="hidden" name="${_csrf.parameterName}" value="${_csrf.token}"/>
...@@ -235,7 +241,34 @@ ...@@ -235,7 +241,34 @@
$('#get-user-acc-lists').show(); $('#get-user-acc-lists').show();
}); });
} }
}) });
$('body').on('input', '#accessionListTitle', function() {
var showError = false;
var title = $(this).val();
<c:forEach items="${userAccessionLists}" var="userList">
var userListTitle = '${userList.title}';
if(userListTitle === $.trim(title)) {
showError = true;
}
</c:forEach>
if(showError === true) {
$('#existingTitleError').show();
$('#emptyTitleError').hide();
$('#makeNewListBtn').attr('disabled', true);
} else {
if($.trim(title) === '') {
$('#emptyTitleError').show();
$('#existingTitleError').hide();
$('#makeNewListBtn').attr('disabled', true);
} else {
$('#existingTitleError').hide();
$('#emptyTitleError').hide();
$('#makeNewListBtn').attr('disabled', false);
}
}
});
}); });
</script> </script>
</content> </content>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment