diff options
| author | Jules Laplace <jules@okfoc.us> | 2014-08-14 13:57:42 -0400 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2014-08-14 13:57:42 -0400 |
| commit | 410607684c7273a61f937635b41397208e245473 (patch) | |
| tree | 3e42d25d117658a7beb5175d24894cb827605cd2 /public/assets/javascripts/ui/lib/FormView.js | |
| parent | 0f649f2cfb034ad8458f08c8f23a2251135af059 (diff) | |
autosave
Diffstat (limited to 'public/assets/javascripts/ui/lib/FormView.js')
| -rw-r--r-- | public/assets/javascripts/ui/lib/FormView.js | 28 |
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)); } |
