Last active
December 18, 2015 19:19
-
-
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
This file contains 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
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" |
This file contains 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
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"); | |
} | |
} | |
}); |
This file contains 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
var object = new eZContentObject({'id':1}); | |
object.fetch(); | |
var name = object.get('name'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.