diff options
Diffstat (limited to 'public/assets/js/vendor/view/formview.js')
| -rw-r--r-- | public/assets/js/vendor/view/formview.js | 33 |
1 files changed, 22 insertions, 11 deletions
diff --git a/public/assets/js/vendor/view/formview.js b/public/assets/js/vendor/view/formview.js index f71c550..b2825a2 100644 --- a/public/assets/js/vendor/view/formview.js +++ b/public/assets/js/vendor/view/formview.js @@ -33,30 +33,40 @@ var FormView = View.extend({ }, serialize: function(){ - var fd = new FormData(), hasCSRF = false + var fd, fh, hasCSRF = false + var file_els = this.$("input[name][type='file']") + if (file_els.length) { + fd = new FormData() + } + else { + fh = {} + } this.$("input[name], select[name], textarea[name]").each( function(){ if (this.type == "file") { for (var i = 0; i < this.files.length; i++) { fd.append(this.name, this.files[i]); } } - else if (this.type == "password") { - if (this.value.length > 0) { - fd.append(this.name, SHA1.hex('bucky$' + this.value + '$bucky')) - } - } else { - fd.append(this.name, this.value); + if (fd) { + fd.append(this.name, this.value) + } else { + fh[this.name] = this.value + } hasCSRF = hasCSRF || this.name == "_csrf" } }); if (! hasCSRF) { - fd.append("_csrf", $("[name=_csrf]").attr("value")) + if (fd) { + fd.append("_csrf", $("[name=_csrf]").attr("value")) + } else { + fh["_csrf"] = $("[name=_csrf]").attr("value") + } } - return fd + return fd || JSON.stringify(fh) }, save: function(e, successCallback, errorCallback){ @@ -80,14 +90,15 @@ var FormView = View.extend({ var action = typeof this.action == "function" ? this.action() : this.action if (! action) return + var data = this.serialize() var request = $.ajax({ url: action, type: this.method, - data: this.serialize(), + data: data, headers: { "csrf-token": $("[name=_csrf]").attr("value") }, + contentType: data instanceof FormData ? false : "application/json", dataType: "json", processData: false, - contentType: false, success: function(response){ console.log(response) if (response.error) { |
