app/assets/javascripts/spine.js in spine-rails-0.0.7 vs app/assets/javascripts/spine.js in spine-rails-0.0.8
- old
+ new
@@ -326,10 +326,14 @@
return _results;
} else {
return new this(objects);
}
};
+ Model.fromForm = function() {
+ var _ref;
+ return (_ref = new this).fromForm.apply(_ref, arguments);
+ };
Model.recordsValues = function() {
var key, result, value, _ref;
result = [];
_ref = this.records;
for (key in _ref) {
@@ -361,17 +365,20 @@
Model.prototype.isValid = function() {
return !this.validate();
};
Model.prototype.validate = function() {};
Model.prototype.load = function(atts) {
- var key, value, _results;
- _results = [];
+ var key, value;
for (key in atts) {
value = atts[key];
- _results.push(typeof this[key] === 'function' ? this[key](value) : this[key] = value);
+ if (typeof this[key] === 'function') {
+ this[key](value);
+ } else {
+ this[key] = value;
+ }
}
- return _results;
+ return this;
};
Model.prototype.attributes = function() {
var key, result, _i, _len, _ref;
result = {};
_ref = this.constructor.attributes;
@@ -457,9 +464,19 @@
Model.prototype.toJSON = function() {
return this.attributes();
};
Model.prototype.toString = function() {
return "<" + this.constructor.className + " (" + (JSON.stringify(this)) + ")>";
+ };
+ Model.prototype.fromForm = function(form) {
+ var key, result, _i, _len, _ref;
+ result = {};
+ _ref = $(form).serializeArray();
+ for (_i = 0, _len = _ref.length; _i < _len; _i++) {
+ key = _ref[_i];
+ result[key.name] = key.value;
+ }
+ return this.load(result);
};
Model.prototype.exists = function() {
return this.id && this.id in this.constructor.records;
};
Model.prototype.update = function() {