(function(root, factory) {
if (typeof define === 'function' && define.amd) {
define(['underscore', 'backbone', './View', './FormModel', './Cell', 'backbone.stickit'], factory);
} else if (typeof exports === 'object') {
require('backbone.stickit');
module.exports = factory(require('underscore'), require('backbone'), require('./View'), require('./FormModel'), require('./Cell'));
} else {
root.Torso = root.Torso || {};
root.Torso.FormView = factory(root._, root.Backbone, root.Torso.View, root.Torso.FormModel, root.Torso.Cell);
}
}(this, function(_, Backbone, View, FormModel, Cell) {
'use strict';
var $ = Backbone.$;
/**
* Generic Form View
*
* @class FormView
* @extends View
*
* @param {Object} args - options argument
* @param {FormModel} [args.model=new this.FormModelClass()] - a form model for binding that defaults to class-level
model or instantiates a FormModelClass
* @param {Function} [args.FormModelClass=FormModel] - the class (that extends {@link FormModel}) that will be used as the FormModel. Defaults to a class-level
definition or {@link FormModel} if none is provided
* @param {external:Handlebars-Template} [args.template] - overrides the template used by this view
* @param {Object} [args.events] - events hash: merge + override the events hash used by this view
* @param {Object} [args.fields] - field hash: merge + override automated two-way binding field hash used by this view
* @param {Object} [args.bindings] - binding hash: merge + override custom epoxy binding hash used by this view
*
* @author ariel.wexler@vecna.com
*
* @see <a href="../annotated/modules/FormView.html">FormView Annotated Source</a>
*/
var FormView = View.extend(/** @lends FormView# */{
/**
* Validation error hash
* @private
* @property _errors
* @type Object
*/
/**
* Validation success
* @private
* @property _success
* @type Boolean
*/
/**
* Stickit bindings hash local backup
* @private
* @name _bindings
* @memberof FormView
* @instance
* @type Object
*/
/**
* Handlebars template for form
* @name template
* @memberof FormView
* @instance
* @type external:Handlebars-Template
*/
/**
* Backbone events hash
* @name events
* @memberof FormView
* @instance
* @type Object
*/
/**
* Two-way binding field customization
* @name fields
* @memberof FormView
* @instance
* @type Object
*/
/**
* Stickit bindings hash
* @name bindings
* @memberof FormView
* @instance
* @type Object
*/
/**
* The class to be used when instantiating the form model
* @name FormModelClass
* @memberof FormView
* @instance
* @type {FormModel.prototype}
*/
constructor: function(args) {
args = args || {};
/* Listen to model validation callbacks */
var FormModelClass = args.FormModelClass || this.FormModelClass || FormModel;
this.model = args.model || this.model || (new FormModelClass());
/* Override template */
this.template = args.template || this.template;
/* Merge events, fields, bindings, and computeds */
this.events = _.extend({}, this.events || {}, args.events || {});
this.fields = _.extend({}, this.fields || {}, args.fields || {});
this._errors = [];
this._success = false;