Created
April 18, 2014 13:03
-
-
Save rikkimax/11043210 to your computer and use it in GitHub Desktop.
Some of Cmsed's javascript generation capabilities
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module cmsed.test.models.book; | |
import cmsed.base; | |
import dvorm; | |
@dbName("Books3") | |
class Book3 { | |
@dbId | |
@dbName("") | |
Book3Id key = new Book3Id; | |
@dbDefaultValue("0") | |
ubyte edition; | |
void t() {} | |
@dbIgnore | |
string something; | |
mixin OrmModel!Book3; | |
} | |
class Book3Id { | |
@dbId { | |
@dbName("id") | |
string isbn; | |
} | |
} | |
class Page3 { | |
@dbId | |
@dbName("_id") | |
string id; | |
@dbName("book") | |
@dbActualModel!(Book3, "key") | |
Book3Id book = new Book3Id; | |
mixin OrmModel!Page3; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://localhost:8080/public/js/models/books3 | |
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) { | |
onFailureToSaveObject(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.responseJSON(); | |
return new Books3(ret._id); | |
}; | |
Books3.prototype.query = function() { | |
return { | |
props: { | |
_id_eq: undefined, | |
_id_neq: undefined, | |
_id_lt: undefined, | |
_id_lte: undefined, | |
_id_mt: undefined, | |
_id_mte: undefined, | |
_id_like: undefined, | |
edition_eq: undefined, | |
edition_neq: undefined, | |
edition_lt: undefined, | |
edition_lte: undefined, | |
edition_mt: undefined, | |
edition_mte: undefined, | |
edition_like: undefined | |
}, | |
offset: undefined, | |
maxAmount: undefined, | |
find: function () { | |
this_ = this; | |
var ret = new Ajax.Request("/.svc/Books3/", { | |
method: "POST", | |
parameters: { | |
_id_eq: this_.props._id_eq, | |
_id_neq: this_.props._id_neq, | |
_id_lt: this_.props._id_lt, | |
_id_lte: this_.props._id_lte, | |
_id_mt: this_.props._id_mt, | |
_id_mte: this_.props._id_mte, | |
_id_like: this_.props._id_like, | |
edition_eq: this_.props.edition_eq, | |
edition_neq: this_.props.edition_neq, | |
edition_lt: this_.props.edition_lt, | |
edition_lte: this_.props.edition_lte, | |
edition_mt: this_.props.edition_mt, | |
edition_mte: this_.props.edition_mte, | |
edition_like: this_.props.edition_like, | |
__offset: this_.offset, | |
__maxAmount: this_.maxAmount | |
}, | |
onSuccess: function (event) { | |
}, | |
onFailure: function (event) { | |
} | |
}); | |
ret = ret.responseJSON(); | |
} | |
}; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module cmsed.test.routes.test; | |
import cmsed.base; | |
import cmsed.test.models; | |
import vibe.d : Json; | |
@jsRouteName("test_route") | |
class Test : OORoute { | |
@RouteFunction(RouteType.Get, "/") | |
void index() { | |
http_response.writeBody(""); | |
} | |
@RouteFunction(RouteType.Get, "/myindex", "index") | |
bool myindex() { | |
return true; | |
} | |
@RouteGroup(null, "/.svc") { | |
mixin RestfulRoute!(RestfulProtection.All, Book3, Page3); | |
} | |
@RouteFunction(RouteType.Get, "/someargs") | |
void someArgs(string a, string b) { | |
http_response.writeBody(a ~ ", " ~ b); | |
} | |
@RouteFunction(RouteType.Get, "/mytext") | |
string myText() { | |
return "Hello World!"; | |
} | |
@RouteFunction(RouteType.Get, "/myjson") | |
Json myJson() { | |
Json ret = Json.emptyObject(); | |
ret["Hello"] = Json("World!"); | |
return ret; | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// http://localhost:8080/public/js/routes/test_route | |
function index() { | |
var ret = new Ajax.Request("/", { | |
method: "get", | |
parameters: { | |
} | |
}); | |
return ret.responseText() | |
} | |
function myindex() { | |
var ret = new Ajax.Request("/myindex", { | |
method: "get", | |
parameters: { | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataBook3Get(key) { | |
var ret = new Ajax.Request("/.svc" + "/Books3" + "/" + key, { | |
method: "get", | |
parameters: { | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataBook3Query(_id_eq, _id_neq, _id_mt, _id_lt, _id_mte, _id_lte, _id_like, edition_eq, edition_neq, edition_mt, edition_lt, edition_mte, edition_lte, edition_like, __maxAmount, __offset) { | |
var ret = new Ajax.Request("/.svc" + "/Books3", { | |
method: "post", | |
parameters: { | |
"_id_eq": _id_eq, | |
"_id_neq": _id_neq, | |
"_id_mt": _id_mt, | |
"_id_lt": _id_lt, | |
"_id_mte": _id_mte, | |
"_id_lte": _id_lte, | |
"_id_like": _id_like, | |
"edition_eq": edition_eq, | |
"edition_neq": edition_neq, | |
"edition_mt": edition_mt, | |
"edition_lt": edition_lt, | |
"edition_mte": edition_mte, | |
"edition_lte": edition_lte, | |
"edition_like": edition_like, | |
"__maxAmount": __maxAmount, | |
"__offset": __offset | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataBook3Create(_id, edition) { | |
var ret = new Ajax.Request("/.svc" + "/Books3", { | |
method: "put", | |
parameters: { | |
"_id": _id, | |
"edition": edition | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataBook3Modify(key, _id, edition) { | |
var ret = new Ajax.Request("/.svc" + "/Books3" + "/" + key, { | |
method: "post", | |
parameters: { | |
"_id": _id, | |
"edition": edition | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataBook3Delete(key) { | |
var ret = new Ajax.Request("/.svc" + "/Books3" + "/" + key, { | |
method: "delete", | |
parameters: { | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataPage3Get(key) { | |
var ret = new Ajax.Request("/.svc" + "/Page3" + "/" + key, { | |
method: "get", | |
parameters: { | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataPage3Query(_id_eq, _id_neq, _id_mt, _id_lt, _id_mte, _id_lte, _id_like, book_id_eq, book_id_neq, book_id_mt, book_id_lt, book_id_mte, book_id_lte, book_id_like, __maxAmount, __offset) { | |
var ret = new Ajax.Request("/.svc" + "/Page3", { | |
method: "post", | |
parameters: { | |
"_id_eq": _id_eq, | |
"_id_neq": _id_neq, | |
"_id_mt": _id_mt, | |
"_id_lt": _id_lt, | |
"_id_mte": _id_mte, | |
"_id_lte": _id_lte, | |
"_id_like": _id_like, | |
"book_id_eq": book_id_eq, | |
"book_id_neq": book_id_neq, | |
"book_id_mt": book_id_mt, | |
"book_id_lt": book_id_lt, | |
"book_id_mte": book_id_mte, | |
"book_id_lte": book_id_lte, | |
"book_id_like": book_id_like, | |
"__maxAmount": __maxAmount, | |
"__offset": __offset | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataPage3Create(_id, book_id) { | |
var ret = new Ajax.Request("/.svc" + "/Page3", { | |
method: "put", | |
parameters: { | |
"_id": _id, | |
"book_id": book_id | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataPage3Modify(key, _id, book_id) { | |
var ret = new Ajax.Request("/.svc" + "/Page3" + "/" + key, { | |
method: "post", | |
parameters: { | |
"_id": _id, | |
"book_id": book_id | |
} | |
}); | |
return ret.responseText() | |
} | |
function handleRestfulDataPage3Delete(key) { | |
var ret = new Ajax.Request("/.svc" + "/Page3" + "/" + key, { | |
method: "delete", | |
parameters: { | |
} | |
}); | |
return ret.responseText() | |
} | |
function someArgs(a, b) { | |
var ret = new Ajax.Request("/someargs", { | |
method: "get", | |
parameters: { | |
"a": a, | |
"b": b | |
} | |
}); | |
return ret.responseText() | |
} | |
function myText() { | |
var ret = new Ajax.Request("/mytext", { | |
method: "get", | |
parameters: { | |
} | |
}); | |
return ret.responseText() | |
} | |
function myJson() { | |
var ret = new Ajax.Request("/myjson", { | |
method: "get", | |
parameters: { | |
} | |
}); | |
return ret.responseText() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment