Finding my way around Backbone, Underscore, and Bootstrap

pull/306/merge
Amanda Anganes 2013-03-08 09:06:14 -05:00
parent 5704271973
commit fa0a6a7b4e
3 changed files with 28 additions and 4 deletions

View File

@ -108,7 +108,23 @@ public class ScopeAPI {
public String createScope(@RequestBody String json, ModelMap m) {
SystemScope scope = gson.fromJson(json, SystemScope.class);
scope = scopeService.save(scope);
SystemScope alreadyExists = scopeService.getByValue(scope.getValue());
if (alreadyExists != null) {
//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.");
return "jsonEntityView";
}
try {
scope = scopeService.save(scope);
} catch (RuntimeException e) {
logger.error("There was an error attempting to save scope: " + scope + " : " + e.getStackTrace().toString());
m.put("code", HttpStatus.BAD_REQUEST);
m.put("entity", "An error occurred while processing your request");
return "jsonEntityView";
}
if (scope != null && scope.getId() != null) {

View File

@ -250,6 +250,10 @@ var BlackListWidgetView = ListWidgetView.extend({
item.save({}, {
success:function() {
_self.collection.add(item);
},
error:function(error, response) {
console.log("error: " + error);
console.log("response: " + response);
}
});

View File

@ -222,9 +222,13 @@ var SystemScopeFormView = Backbone.View.extend({
app.systemScopeList.add(_self.model);
app.navigate('admin/scope', {trigger: true});
},
error:function(model,resp) {
console.error("The scope didn't save correctly.", resp);
}
error:function(error, response) {
if (response.status == 409) {
//Conflict, scope already exists
$('#value input').css('border', '1px solid red');
//add hint to choose a different value
}
}
});
}