2
0
Fork 0
tcrud/lib/plugin/auto/auto-tslug.js

48 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2017-06-10 14:53:29 +00:00
module.exports = (function () {
var filterSlug = function(ctx,value) {
return ctx.filterValue(value,['.',',','/','=','&','?',' '],'', function (part) {
return part; // todo use fully correct uri removeal and escaping.
})
};
var createTViewSlug = function(tentity) {
var uriViewSlash = '/';
var slug = uriViewSlash + tentity.tslug;
if (!tentity.tenable || !tentity.tparent) {
slug = '';
}
if (tentity.tparent) {
return createTViewSlug(tentity.tparent)+slug;
}
return slug;
};
return function AutoTSlugPlugin() {
this.configPlugin = function (ctx) {
ctx.key='autoTSlug';
ctx.description='Auto fills and checks the tslug fields.';
};
this.fillTField = function(ctx) {
if (ctx.tfield.tslug === undefined || ctx.tfield.tslug === null) {
ctx.tfield.tslug = ctx.tfield.tid;
}
ctx.tfield.tslug = filterSlug(ctx,ctx.tfield.tslug);
};
this.fillTEntity = function(ctx) {
if (ctx.tentity.tslug === null) {
ctx.tentity.tslug = ctx.tentity.tid;
}
ctx.tentity.tslug = filterSlug(ctx,ctx.tentity.tslug);
};
this.fillTView = function(ctx) {
ctx.tview.tslug = createTViewSlug(ctx.tentity).substring(1);
}
};
})();