Created
December 6, 2015 20:13
-
-
Save ar45/4e028cdc341e81435423 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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