54 lines
1.4 KiB
JavaScript
54 lines
1.4 KiB
JavaScript
|
|
||
|
module.exports = (function () {
|
||
|
|
||
|
function forceLookupTFields(tview) {
|
||
|
var keys = Object.keys(tview.tmeta.tfields);
|
||
|
for (var i = 0; i < keys.length; i++) {
|
||
|
var key = keys[i];
|
||
|
var keyNew = 'FTL_' +forceLookupKeySimple() + '_' + key.substring(key.length/3,key.length/3*2); // no....its; Force template lookup
|
||
|
var tfield = tview.tmeta.tfields[key];
|
||
|
tview.tmeta.tfields[key] = undefined;
|
||
|
tview.tmeta.tfields[keyNew] = tfield;
|
||
|
|
||
|
var ckeys = Object.keys(tview);
|
||
|
for (var ii = 0; ii < ckeys.length; ii++) {
|
||
|
var ckey = ckeys[ii];
|
||
|
if (ckey === 'tmeta') {
|
||
|
continue;
|
||
|
}
|
||
|
var obj = tview[ckey];
|
||
|
if (obj && obj.tfields) {
|
||
|
var tfieldsNew = [];
|
||
|
for (var iii = 0; iii < obj.tfields.length; iii++) {
|
||
|
var tkey = obj.tfields[iii];
|
||
|
if (tkey === key) {
|
||
|
tfieldsNew.push(keyNew);
|
||
|
} else {
|
||
|
tfieldsNew.push(tkey);
|
||
|
}
|
||
|
}
|
||
|
obj.tfields = tfieldsNew;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
function forceLookupKeySimple() {
|
||
|
var low = 100000;
|
||
|
var high = 999999;
|
||
|
return Math.floor(Math.random() * (high - low + 1) + low).toString(16).toUpperCase();
|
||
|
}
|
||
|
|
||
|
return function AutoTViewFTLPlugin() {
|
||
|
|
||
|
this.configPlugin = function (ctx) {
|
||
|
ctx.key='autoTViewFTL';
|
||
|
ctx.description='Automatic tview tfields key change to force table lookup.';
|
||
|
};
|
||
|
|
||
|
this.fillTView = function(ctx) {
|
||
|
forceLookupTFields(ctx.tview);
|
||
|
};
|
||
|
};
|
||
|
})();
|