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

55 lines
1.4 KiB
JavaScript

module.exports = (function () {
var autoFieldEnable = function(tfield,type) {
if (type === undefined) {
throw new Error('no type');
}
if (tfield[type] === undefined) {
tfield[type] = {}; // todo rm this
}
if (tfield[type].tenable !== null) {
return;
}
var fieldKey = tfield.tid;
var result = true;
if ('tlist' === type) {
var name = fieldKey.toLowerCase();
if (fieldKey.indexOf('description') >= 0) {
result = false;
} else if (fieldKey.indexOf('comment') >= 0) {
result = false;
}
}
tfield[type].tenable = result;
}
return function AutoTEnablePlugin() {
this.configPlugin = function (ctx) {
ctx.key='autoTEnable';
ctx.description='Auto enables to true if undefined.';
};
this.fillTEntity = function(ctx) {
if (ctx.tentity.tenable === null || ctx.tentity.tenable === undefined) {
ctx.tentity.tenable = true;
}
autoFieldEnable(ctx.tentity,'tlist');
autoFieldEnable(ctx.tentity,'tread');
autoFieldEnable(ctx.tentity,'tedit');
autoFieldEnable(ctx.tentity,'tcreate');
autoFieldEnable(ctx.tentity,'tdelete');
autoFieldEnable(ctx.tentity,'tcount');
autoFieldEnable(ctx.tentity,'tverify');
}
this.fillTField = function(ctx) {
autoFieldEnable(ctx.tfield,'tlist');
autoFieldEnable(ctx.tfield,'tread');
autoFieldEnable(ctx.tfield,'tedit');
autoFieldEnable(ctx.tfield,'tcreate');
}
};
})();