2
0
Fork 0
tcrud/lib/tcrud-config.js
2017-06-10 16:53:29 +02:00

80 lines
2.3 KiB
JavaScript

var debug = require('debug')('ff:tcrud:config');
var configRegistry = require('./config-registry');
var configUtil = require('./config-util');
var mod = (function () {
return function TCrudConfig() {
this.getClientJSResources = function() {
return configRegistry.getMasterConfig().clientJSResources;
};
this.getClientCSSResources = function() {
return configRegistry.getMasterConfig().clientCSSResources;
};
this.getBackend = function(backendId) {
return configRegistry.getMasterConfig().backends[backendId];
};
this.getRootTEntity = function() {
return configRegistry.getRootTEntity();
};
this.createTEntityNode = function(parent, tid, modelKeys, viewKeys) {
configRegistry.assertPhaseConfig();
var result = configUtil.clone(parent);
result.tchilds = [];
result.tid = tid;
parent.tchilds.push(result);
result.tparent = parent;
if (modelKeys) {
if (Array.isArray(modelKeys)) {
result.tmeta.tmodel.tkeys = modelKeys;
} else {
result.tmeta.tmodel.tkeys.push(modelKeys);
}
}
if (viewKeys) {
if (Array.isArray(modelKeys)) {
result.tkeys = viewKeys;
} else {
result.tkeys.push(viewKeys);
}
}
return result;
};
this.createTEntity = function(parent, tid, modelKeys, viewKeys) {
configRegistry.assertPhaseConfig();
debug('createTEntity.tid: %s',tid);
var result = module.exports.createTEntityNode(parent,tid,modelKeys,viewKeys);
result.tmeta.tmodel.tid = tid;
return result;
};
this.createTField = function(parent, tid) {
configRegistry.assertPhaseConfig();
debug('createTField.tid: %s',tid);
var result = configUtil.clone(configRegistry.getMasterTemplates().masterTFieldTemplate);
result.tid = tid;
parent.tmeta.tfields[tid] = result;
return result;
};
this.createTView = function(tentity) {
debug('createTView: %s',tentity.tid);
configRegistry.assertPhaseServer();
var result = configUtil.clone(configRegistry.getMasterTemplates().masterTViewTemplate);
result.tid = tentity.tid;
configUtil.copyByTemplate('tview',result,tentity,configRegistry.getMasterTemplates().masterTViewTemplate);
configRegistry.pluginCall('fillTView',{tview: result,tentity: tentity});
return result;
}
};
})();
module.exports = new mod;