48 lines
1.2 KiB
JavaScript
48 lines
1.2 KiB
JavaScript
|
|
||
|
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);
|
||
|
}
|
||
|
};
|
||
|
})();
|