Working on error handling

pull/306/merge
Amanda Anganes 12 years ago
parent fa0a6a7b4e
commit 96e333afa6

@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import com.google.gson.Gson;
@ -103,6 +104,23 @@ public class ScopeAPI {
}
}
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value="/checkScopeValue", method = RequestMethod.GET)
public String checkScopeValue(@RequestParam String value, ModelMap m) {
SystemScope alreadyExists = scopeService.getByValue(value);
if (alreadyExists != null) {
m.put("code", HttpStatus.CONFLICT);
m.put("entity", "A scope with value " + value + " already exists, please choose a different value.");
}
else {
m.put("code", HttpStatus.ACCEPTED);
m.put("entity", "OK");
}
return "jsonEntityView";
}
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "", method = RequestMethod.POST, produces = "application/json", consumes = "application/json")
public String createScope(@RequestBody String json, ModelMap m) {
@ -113,7 +131,7 @@ public class ScopeAPI {
//Error, cannot save a scope with the same value as an existing one
logger.error("Error: attempting to save a scope with a value that already exists: " + scope.getValue());
m.put("code", HttpStatus.CONFLICT);
m.put("entity", "A scope with value " + scope.getValue() + "already exists, please choose a different value.");
m.put("entity", "A scope with value " + scope.getValue() + " already exists, please choose a different value.");
return "jsonEntityView";
}

@ -207,6 +207,20 @@ var SystemScopeFormView = Backbone.View.extend({
return false;
}
var valuedata = {};
valuedata.value = value;
var alreadyExists = false;
$.get(this.model.urlRoot + "/checkScopeValue", valuedata)
.success(function() {
console.log("scope value is OK");
})
.error(function(error, response) {
$('#value input').addClass('error');
//add hint
alreadyExists = true;
});
var valid = this.model.set({
value:value,
description:$('#description textarea').val(),
@ -215,7 +229,8 @@ var SystemScopeFormView = Backbone.View.extend({
allowDynReg:$('#allowDynReg input').is(':checked')
});
if (valid) {
if (valid && !alreadyExists) {
var _self = this;
this.model.save({}, {
success:function() {

Loading…
Cancel
Save