Skip to content

Instantly share code, notes, and snippets.

@rikkimax
Created February 9, 2014 06:20
Show Gist options
  • Save rikkimax/8895115 to your computer and use it in GitHub Desktop.
Save rikkimax/8895115 to your computer and use it in GitHub Desktop.
Example javascript generation from data model
var Books3 = Class({
constructor: function(_id, edition) {
this._id = _id === undefined ? "" : _id;
this.edition = Number(edition === undefined ? "0" : edition);
},
save: function() {
var this_ = this;
new Ajax.Request("/.svc/Books3/" + this._id, {
method: "POST",
parameters: {
_id: this_._id
},
onSuccess: function(event) {
onSaveOfObject(this_, event);
},
onFailure: function(event) {
onFailudata.retoSaveObject(this_, event);
}
});
},
remove: function() {
var this_ = this;
new Ajax.Request("/.svc/Books3/" + this._id, {
method: "DELETE",
onSuccess: function(event) {
onDeleteOfObject(this_, event);
},
onFailure: function(event) {
onFailureToDeleteObject(this_, event);
}
});
}
});
Books3.prototype.findOne = function(_id) {
var ret = new Ajax.Request("/.svc/Books3/" + _id, {
method: "GET",
asynchronous: false
});
ret = ret.evalReponse();
return new Books3(ret._id);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment