oomph
Version:
Object Oriented javascript models for the client and the server
37 lines (32 loc) • 1.13 kB
JavaScript
// Generated by CoffeeScript 1.9.3
(function() {
var ajaxObjectClassDataStore, ajaxObjectInstanceDataStore;
ajaxObjectClassDataStore = require('../privateModules/ajaxObjectClassDataStore');
ajaxObjectInstanceDataStore = {
save: function() {
var attr, i, len, ref, updateFields;
if (this.id) {
updateFields = {};
ref = Object.keys(this.constructor.attributes);
for (i = 0, len = ref.length; i < len; i++) {
attr = ref[i];
if (this[attr]) {
updateFields[attr] = this[attr];
}
}
return ajaxObjectClassDataStore.update.apply(this.constructor, [this.id, updateFields]).then((function(_this) {
return function(newProps) {
return _.assign(_this, newProps);
};
})(this));
} else {
return ajaxObjectClassDataStore.create.apply(this.constructor, [this]).then((function(_this) {
return function(newProps) {
return _.assign(_this, newProps);
};
})(this));
}
}
};
module.exports = ajaxObjectInstanceDataStore;
}).call(this);