{"size": 900, "ext": "js", "max_stars_repo_path": "src/forms/behavior.js", "max_stars_repo_name": "megawac/marionette-wires", "max_stars_repo_stars_event_min_datetime": "2015-01-13T09:24:00.000Z", "max_stars_repo_stars_event_max_datetime": "2015-08-19T22:10:02.000Z", "max_issues_repo_path": "src/forms/behavior.js", "max_issues_repo_name": "joshbedo/marionette-wires", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/forms/behavior.js", "max_forks_repo_name": "joshbedo/marionette-wires", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 20.4545454545, "max_line_length": 68, "alphanum_fraction": 0.6311111111}
var Syphon = require('backbone.syphon');
var Behavior = require('src/common/behavior');

module.exports = Behavior.extend({
  events: {
    'submit form' : 'handleSubmit'
  },

  initialize: function() {
    this.listenTo(this.view.options.model, 'change', this.onChange);
  },

  serialize: function() {
    this.view.form = Syphon.serialize(this);
  },

  deserialize: function() {
    return Syphon.deserialize(this, this.view.form);
  },

  onChange: function() {
    this.view.form = this.view.model.attributes;
    this.deserialize();
  },

  onBeforeRender: function() {
    if (this.view.form) {
      this.serialize();
    }
  },

  onDomRefresh: function () {
    if (!this.view.form) {
      this.view.form = this.view.model.attributes;
    }
    this.deserialize();
  },

  handleSubmit: function (event) {
    event.preventDefault();
    this.view.form = Syphon.serialize(this);
  }
});
