Represents an event listener which calculates field values. This listener is being registered for all data models.
A data field may have a calculation attribute.
An instance of FunctionContext class will calculate this value by evaluating the expression provided.
{
"name": "modifiedBy",
"title": "Modified By",
"description": "Modified by user.",
"type": "User",
"calculation":"javascript:return this.user();"
}
In the previous example modifiedBy field has a calculation for setting the user which performs the update operation.
Note:FunctionContext class may be extended in order to allow applications to perform value calculations.
FunctionContext.prototype.myColor = function() {
var deferred = Q.defer(),
self = this;
process.nextTick(function() {
return self.context.model("UserColor")
.where("user/name").equal(self.context.user.name)
.select("color")
.value().then(function(value) {
deferred.resolve(value);
}).catch(function(err) {
deferred.reject(err);
});
});
return deferred.promise;
}
{
"name": "color",
"title": "Color",
"type": "Text",
"calculation":"javascript:return this.myColor();"
}
In this example a custom method of FunctionContext class gets the user's favourite color.
This calculation may also be performed by setting the following promise expression:
{
"name": "color",
"title": "Color",
"type": "Text",
"calculation":"javascript:return this.context.model('UserColor').where('user/name').equal(this.context.user.name).select('color').value();"
}