Skip to content

Instantly share code, notes, and snippets.

@ar45
Created December 6, 2015 20:13
Show Gist options
  • Save ar45/4e028cdc341e81435423 to your computer and use it in GitHub Desktop.
Save ar45/4e028cdc341e81435423 to your computer and use it in GitHub Desktop.
function FormCtrl() {
this.submit = function(form, method) {
var promise = method(function(data, headers) {
form.serverErrors = undefined;
form.flashMessage("success");
}, function(status, headers, data) {
if (status == 400) {
form.serverErrors = data;
form.$setValidity(false);
form.flashMessage("Please correct the errors");
} else if (status > 499) {
form.flashMessage("An error occurd. " + (data && data.detail) ? "Details: " + data.detail : "");
} else if (status == 404) {
form.$rejected = true;
form.setRejection("404");
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment