module.exports = (function () { var addFilteredFields = function(tview,type,tcrud) { //debug('addFilterFields of: '+type+' from: '+tview.tid); result = []; var keys = Object.keys(tcrud.tmeta.tfields); var result = []; for (var i = 0; i < keys.length; i++) { var key = keys[i]; var tfield = tcrud.tmeta.tfields[key]; if (tfield[type]) { if (!tfield[type].tenable) { continue; } } result.push(key); // default is true.. } tview[type].tfields = result; }; return function DefaultTViewPlugin() { this.configPlugin = function (ctx) { ctx.key = 'defaultTView'; ctx.description = 'Add copy template for building the tview from the tentity.'; ctx.localDir = __dirname; ctx.localConfigTemplate = 'default-tview.json'; }; this.fillTView = function(ctx) { addFilteredFields(ctx.tview,'tlist',ctx.tentity); addFilteredFields(ctx.tview,'tread',ctx.tentity); addFilteredFields(ctx.tview,'tedit',ctx.tentity); addFilteredFields(ctx.tview,'tcreate',ctx.tentity); }; }; })();