/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*!
* [KIMAI] KimaiFormPlugin: base class for all none ID plugin that handle forms
*/
import KimaiFormPlugin from './KimaiFormPlugin';
export default class KimaiFormTomselectPlugin extends KimaiFormPlugin {
/**
* @param {string} rendererType
* @return array
*/
getRenderer(rendererType)
{
// default renderer
let render = {
option_create: (data, escape) => {
const name = escape(data.input);
if (name.length < 3) {
return null;
}
const tpl = this.translate('select.search.create');
const tplReplaced = tpl.replace('%input%', '' + name + '')
return '
' + tplReplaced + '
';
},
no_results: (data, escape) => {
const tpl = this.translate('select.search.notfound');
const tplReplaced = tpl.replace('%input%', '' + escape(data.input) + '')
return '' + tplReplaced + '
';
},
};
if (rendererType === 'color') {
render = {...render, ...{
option: function(data, escape) {
let item = '';
// if no color is set, do NOT add an empty placeholder
if (data.color !== undefined) {
item += ' ';
}
item += escape(data.text) + '
';
return item;
},
item: function(data, escape) {
let item = '';
// if no color is set, do NOT add an empty placeholder
if (data.color !== undefined) {
item += ' ';
}
item += escape(data.text) + '
';
return item;
}
}};
} else {
render = {...render, ...{
// the empty entry would collapse and only show as a tiny 5px line if there is no content inside
option: function(data, escape) {
let text = data.text;
if (text === null || text.trim() === '') {
text = ' ';
} else {
text = escape(text);
}
return '' + text + '
';
}
}};
}
return render;
}
}