Constructor Detail
bbq.domain.Entity(options)
Name | Type | Comment |
---|---|---|
options | {Object} | |
options.data | {Object} | A set of key/value pairs to pre-populate the default object with |
Extends
bbq.lang.Watchable.
Defined in: Entity.js.
Base class for domain objects. Supports being partially loaded - that is, properties can be asked for from this object in advance of them being loaded. If an unloaded property is requested, a full object load will be trigged.
Extending classes should implement:
include(bbq.domain.Entity);
myapp.domain.Room = new Class.create(bbq.domain.Entity, {
_retrieveURL: "/rooms/get",
_getDefaultObject: function() {
return {
id: null,
name: null,
bookings: null
}
}
});
Constructor Attributes | Constructor Name and Description |
---|---|
bbq.domain.Entity(options)
Base class for domain objects. |
Method Attributes | Method Name and Description |
---|---|
Returns true if this Entity is fully loaded.
|
|
equals(other)
Returns true if the passed object is equal to this one.
|
|
getProperty(property)
Can be used instead of a getter by passing the name of the property you want as a string.
|
|
getPropertyDisplay(options)
Returns a DOM element (by default a SPAN) that contains a textual representation of the requested property of this element. |
|
loadData()
Forces an object to load it's data from the server. |
|
processData(data)
Sets properties on this object and creates getters/setters for accessing them
Also used by child classes to replace IDs with references to the actual objects
|
|
registerListener($super, type, callback)
|
Name | Type | Comment |
---|---|---|
options | {Object} | |
options.data | {Object} | A set of key/value pairs to pre-populate the default object with |
Name | Type | Comment |
---|---|---|
other | {Object} |
Name | Type | Comment |
---|---|---|
property | {String} | A property of this object |
Returns a DOM element (by default a SPAN) that contains a textual representation of the requested property of this element.
Will be updated automatically to contain the most recent value.
Supports getting properties of sub objects. For example, if we want the name of this objects's creator, we can do:
object.getPropertyDisplay({property: "creator.fullname"});
This will have the same effect as:
var creator = object.getCreator();
creator.getPropertyDisplay({property: "fullname"});
If the property requested has not yet been loaded, a call to Entity#loadData will occur.
Name | Type | Comment |
---|---|---|
options | {Object} | |
options.property | {String} | The name of the property that is to be displayed |
options.formatter Optional |
{Function} | A function that takes the property value as an argument and returns a String or a Node |
options.nodeName Optional |
{String} | Will be used in place of SPAN |
options.className Optional |
{String} | Will be applied to the node |
options.createNode Optional |
{Function} | Should return a DOM node. Omit this to use a SPAN. If passed you should also pass a function for updateNode |
options.updateNode Optional |
{Function} | Expect two arguments - a node and the property value. Return nothing. If passed you should also pass a function for createNode |
Forces an object to load it's data from the server. If the object is not fully loaded an immediate request to _retrieveURL will be sent.
Register for listener "onDataLoaded" to interact with this object after data has been loaded.
Name | Type | Comment |
---|---|---|
data | {Object} |
Name | Type | Comment |
---|---|---|
$super | ||
type | ||
callback |