Skip to content

Instantly share code, notes, and snippets.

@charlycoste
Last active December 18, 2015 19:19
Show Gist options
  • Save charlycoste/5831980 to your computer and use it in GitHub Desktop.
Save charlycoste/5831980 to your computer and use it in GitHub Desktop.
This is the code needed to load an object from eZ Publish with javascript, thanks to Backbone.js
eZContentObject = Backbone.Model.extend
urlRoot:
$.ez.url + 'call/ezjscnode::load::ezobject_'
url:
() -> @urlRoot + @get 'id'
parse:
(response) -> response.content
sync:
(method, model, options) ->
if method is "read"
Backbone.sync method, model, options
else
console.error "The method #{method} is not yet implemented"
var eZContentObject = Backbone.Model.extend({
urlRoot: jQuery.ez.url + 'call/ezjscnode::load::ezobject_',
url: function() {
return this.urlRoot + this.get('id');
},
parse: function(response) {
return response.content;
},
sync: function(method, model, options) {
if (method === "read") {
return Backbone.sync(method, model, options);
} else {
return console.error("The method " + method + " is not yet implemented");
}
}
});
var object = new eZContentObject({'id':1});
object.fetch();
var name = object.get('name');
@charlycoste
Copy link
Author

ezjscore doesn't provide a single query to get all data of an object. Sometimes we will need several queries, then using urlRoot is not the best way... It's better to override the sync method for each type of object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment