summaryrefslogtreecommitdiff
path: root/public/assets/javascripts/ui/lib/FormView.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2014-08-14 13:57:42 -0400
committerJules Laplace <jules@okfoc.us>2014-08-14 13:57:42 -0400
commit410607684c7273a61f937635b41397208e245473 (patch)
tree3e42d25d117658a7beb5175d24894cb827605cd2 /public/assets/javascripts/ui/lib/FormView.js
parent0f649f2cfb034ad8458f08c8f23a2251135af059 (diff)
autosave
Diffstat (limited to 'public/assets/javascripts/ui/lib/FormView.js')
-rw-r--r--public/assets/javascripts/ui/lib/FormView.js28
1 files changed, 22 insertions, 6 deletions
diff --git a/public/assets/javascripts/ui/lib/FormView.js b/public/assets/javascripts/ui/lib/FormView.js
index 219952d..ab33bc0 100644
--- a/public/assets/javascripts/ui/lib/FormView.js
+++ b/public/assets/javascripts/ui/lib/FormView.js
@@ -54,15 +54,20 @@ var FormView = View.extend({
return fd
},
- save: function(e){
- e.preventDefault()
+ save: function(e, successCallback, errorCallback){
+ e && e.preventDefault()
this.$errors.hide().css("opacity", 0.0);
if (this.validate) {
var errors = this.validate()
if (errors && errors.length) {
- this.showErrors(errors)
+ if (errorCallback) {
+ errorCallback(errors)
+ }
+ else {
+ this.showErrors(errors)
+ }
return
}
}
@@ -74,18 +79,29 @@ var FormView = View.extend({
dataType: "json",
processData: false,
contentType: false,
- });
+ })
+
request.done($.proxy(function (response) {
if (response.error) {
var errors = []
for (var key in response.error.errors) {
errors.push(response.error.errors[key].message);
}
- this.showErrors(errors)
+ if (errorCallback) {
+ errorCallback(errors)
+ }
+ else {
+ this.showErrors(errors)
+ }
return
}
else {
- this.success && this.success(response)
+ if (successCallback) {
+ successCallback(response)
+ }
+ if (this.success) {
+ this.success(response)
+ }
}
}, this));
}