if (options.startUpdating) {
this.startUpdating();
}
this.trigger('initialization-complete');
},
getMapping: function(alias) {
return this.__currentMappings[alias];
},
getMappings: function() {
return this.__currentMappings;
},
setMapping: function(alias, mapping, models, copy) {
var computed, fields,
config = {};
if (_.isString(mapping)) {
fields = mapping.split(' ');
} else if (mapping === true) {
fields = undefined;
} else if (_.isObject(mapping)) {
mapping = _.clone(mapping);
computed = true;
}
config.computed = computed;
if (computed) {
config.mapping = mapping;
_.each(this.__getModelAliases(config), function(modelAlias) {
var configMappingForAlias = config.mapping[modelAlias];
if (_.isString(configMappingForAlias)) {
configMappingForAlias = configMappingForAlias.split(' ');
} else if (configMappingForAlias === true) {
configMappingForAlias = undefined;
}
config.mapping[modelAlias] = configMappingForAlias;
});
} else {
config.mapping = fields;
}
this.__currentMappings[alias] = config;
if (models) {
if (computed) {
this.trackModels(models, copy);
} else {
this.trackModel(alias, models, copy);
}
}
},
setMappings: function(mappings, models, copy) {
_.each(mappings, function(mapping, alias) {
this.setMapping(alias, mapping);
}, this);
if (models) {
this.trackModels(models, copy);
}
},
unsetMapping: function(aliasOrModel, removeModelIfUntracked) {
var alias = this.__findAlias(aliasOrModel);
if (alias) {
delete this.__currentMappings[alias];
}
var model = this.getTrackedModel(alias);
if (removeModelIfUntracked && model && _.isEmpty(this.__getTrackedModelFields(model))) {
this.untrackModel(model);
}
},
unsetMappings: function() {
this.__currentMappings = {};
this.resetUpdating();
},
getTrackedModel: function(alias) {
return this.__currentObjectModels[alias];
},
getTrackedModels: function() {
return _.values(this.__currentObjectModels);
},
setTrackedModel: function() {
this.trackModel.apply(this, arguments);
},
trackModel: function(alias, model, copy) {
this.__currentObjectModels[alias] = model;
this.__updateCache(model);
this.resetUpdating();
if (copy) {
_.each(this.getMappings(), function(config, mappingAlias) {
var modelAliases;
if (alias === mappingAlias) {
this.__pull(mappingAlias);
}
if (config.computed) {
modelAliases = this.__getModelAliases(mappingAlias);
if (_.contains(modelAliases, alias)) {
this.__pull(mappingAlias);
}
}
}, this);
}
},
setTrackedModels: function() {
this.trackModels.apply(this, arguments);
},
trackModels: function(models, copy) {
_.each(models, function(instance, alias) {
this.trackModel(alias, instance, copy);
}, this);
},
unsetTrackedModel: function() {
this.untrackModel.apply(this, arguments);
},
untrackModel: function(aliasOrModel) {
var model,
alias = this.__findAlias(aliasOrModel);
if (alias) {
model = this.__currentObjectModels[alias];
delete this.__currentObjectModels[alias];
this.__updateCache(model);
}
this.resetUpdating();
},
unsetTrackedModels: function() {
this.untrackModels.apply(this, arguments);
},
untrackModels: function() {
this.__currentObjectModels = [];
this.__updateCache();
this.resetUpdating();
},
push: function() {
_.each(this.getMappings(), function(config, alias) {
this.__push(alias);
}, this);
},
pull: function() {
_.each(this.getMappings(), function(config, alias) {
this.__pull(alias);
}, this);
this.__updateCache();
},
save: function(options) {
var notTrackingResponse, url,
deferred = new $.Deferred(),
formModel = this;
options = options || {};
_.defaults(options, {
rollback: true,
force: true
});
try {
url = _.result(formModel, 'url');
} catch (e) {