File: api/src/config.js
/**
Class for config properties of a ludoJS application. You have access to an instance of this class
via ludo.config.
@class _Config
@private
@example
ludo.config.setUrl('../router.php'); // to set global url
*/
ludo._Config = new Class({
storage:{},
initialize:function () {
this.setDefaultValues();
},
/**
* Reset all config properties back to default values
* @method reset
*/
reset:function(){
this.setDefaultValues();
},
setDefaultValues:function () {
this.storage = {
url:'/controller.php',
documentRoot:'/',
socketUrl:'http://your-node-js-server-url:8080/',
modRewrite:false,
fileUploadUrl:undefined
};
},
/**
Set global url. This url will be used for requests to server if no url is explicit set by
a component.
@method config
@param {String} url
@example
ludo.config.setUrl('../controller.php');
*/
setUrl:function (url) {
this.storage.url = url;
},
/**
* Return global url
* @method getUrl
* @return {String}
* */
getUrl:function () {
return this.storage.url;
},
/**
* Enable url in format <url>/resource/arg1/arg2/service
* @method enableModRewriteUrls
*/
enableModRewriteUrls:function () {
this.storage.modRewrite = true;
},
/**
* Disable url's for mod rewrite enabled web servers.
* @method disableModRewriteUrls
*/
disableModRewriteUrls:function () {
this.storage.modRewrite = false;
},
/**
* Returns true when url's for mod rewrite has been enabled
* @method hasModRewriteUrls
* @return {Boolean}
*/
hasModRewriteUrls:function () {
return this.storage.modRewrite === true;
},
/**
* Set default socket url(node.js).
* @method setSocketUrl
* @param url
*/
setSocketUrl:function (url) {
this.storage.socketUrl = url;
},
/**
* Return default socket url
* @method getSocketUrl
* @return {String}
*/
getSocketUrl:function () {
return this.storage.socketUrl;
},
/**
* Set document root path
* @method setDocumentRoot
* @param {String} root
*/
setDocumentRoot:function (root) {
this.storage.documentRoot = root === '.' ? '' : root;
},
/**
* @method getDocumentRoot
* @return {String}
*/
getDocumentRoot:function () {
return this.storage.documentRoot;
},
/**
* Set default upload url for form.File components.
* @method setFileUploadUrl
* @param {String} url
*/
setFileUploadUrl:function (url) {
this.storage.fileUploadUrl = url;
},
/**
* @method getFileUploadUrl
* @return {String}
*/
getFileUploadUrl:function(){
return this.storage.fileUploadUrl;
}
});
ludo.config = new ludo._Config();