summaryrefslogtreecommitdiff
path: root/public/js/lib/formview.js
diff options
context:
space:
mode:
authorJules Laplace <jules@okfoc.us>2015-08-04 10:55:51 -0400
committerJules Laplace <jules@okfoc.us>2015-08-04 10:55:51 -0400
commit1a882d4adf6307dfbd764ae6aaf1a62a724851f1 (patch)
tree481aef83b95f951fd93a111c48b350cd3b6d3886 /public/js/lib/formview.js
parent460dadfdd2c3d91d3759542990702362b85703d3 (diff)
rearrange stuff and stub in chat
Diffstat (limited to 'public/js/lib/formview.js')
-rw-r--r--public/js/lib/formview.js135
1 files changed, 0 insertions, 135 deletions
diff --git a/public/js/lib/formview.js b/public/js/lib/formview.js
deleted file mode 100644
index f5845e7..0000000
--- a/public/js/lib/formview.js
+++ /dev/null
@@ -1,135 +0,0 @@
-var FormView = View.extend({
-
- method: "post",
- useMinotaur: false,
-
- events: {
- "submit form": "save"
- },
-
- initialize: function(opt){
- if (opt && opt.parent) {
- this.parent = opt.parent
- }
- this.$form = this.$("form")
- this.$errors = this.$(".errors")
- this.$errorList = this.$(".errorList")
- },
-
- reset: function(){
- this.$("input,textarea").not("[type='submit']").not("[type='hidden']").val("")
- },
-
- showErrors: function(errors){
- if (errors && errors.length) {
- this.$errorList.empty();
- for (var i in errors) {
- this.$errorList.append('<div>' + errors[i] + '</div>');
- }
- this.$errors.css("opacity", 1.0);
- setTimeout(function(){
- this.$errors.show().css("opacity", 1.0);
- }.bind(this), 200)
- }
- },
-
- serialize: function(){
- var fd = new FormData(), hasCSRF = false
-
- this.$("input[name], select[name], textarea[name]").each( function(){
- if (this.type == "file") {
- if (this.files.length > 0) {
- fd.append(this.name, this.files[0]);
- }
- }
- else if (this.type == "password") {
- if (this.value.length > 0) {
- fd.append(this.name, SHA1.hex('lol$' + this.value + '$vvalls'))
- }
- }
- else {
- fd.append(this.name, this.value);
- hasCSRF = hasCSRF || this.name == "_csrf"
- }
- });
-
- if (! hasCSRF) {
- fd.append("_csrf", $("[name=_csrf]").val())
- }
-
- return fd
- },
-
- 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) {
- if (errorCallback) {
- errorCallback(errors)
- }
- else {
- this.showErrors(errors)
- }
- return
- }
- }
-
- var action = typeof this.action == "function" ? this.action() : this.action
- if (! action) return
-
- var request = $.ajax({
- url: action,
- type: this.method,
- data: this.serialize(),
- dataType: "json",
- processData: false,
- contentType: false,
- })
-
- if (this.useMinotaur) {
- Minotaur.show()
- }
-
- request.done($.proxy(function (response) {
- if (this.useMinotaur) {
- Minotaur.hide()
- }
- if (response.error) {
- var errors = []
- for (var key in response.error.errors) {
- errors.push(response.error.errors[key].message);
- }
- if (errorCallback) {
- errorCallback(errors)
- }
- else {
- this.showErrors(errors)
- }
- return
- }
- else {
- if (successCallback) {
- successCallback(response)
- }
- if (this.success) {
- this.success(response)
- }
- }
- }, this));
- }
-
-})
-
-
-var ModalFormView = ModalView.extend(FormView.prototype).extend({
-
- load: function(){
- this.reset()
- this.show()
- }
-
-})