{% load i18n %}
/* exported
blankImage,
deleteButton,
editButton,
imageHoverIcon,
makeIconBadge,
makeIconButton,
makeProgressBar,
renderLink,
select2Thumbnail,
setupNotesField,
thumbnailImage
yesNoLabel,
*/
function yesNoLabel(value) {
if (value) {
return `{% trans "YES" %}`;
} else {
return `{% trans "NO" %}`;
}
}
function editButton(url, text='{% trans "Edit" %}') {
return ``;
}
function deleteButton(url, text='{% trans "Delete" %}') {
return ``;
}
function blankImage() {
return `/static/img/blank_image.png`;
}
/* Render a small thumbnail icon for an image.
* On mouseover, display a full-size version of the image
*/
function imageHoverIcon(url) {
if (!url) {
url = blankImage();
}
var html = `
`;
return html;
}
/**
* Renders a simple thumbnail image
* @param {String} url is the image URL
* @returns html
tag
*/
function thumbnailImage(url, options={}) {
if (!url) {
url = blankImage();
}
// TODO: Support insertion of custom classes
var title = options.title || '';
var html = `
`;
return html;
}
// Render a select2 thumbnail image
function select2Thumbnail(image) {
if (!image) {
image = blankImage();
}
return `
`;
}
/*
* Construct an 'icon badge' which floats to the right of an object
*/
function makeIconBadge(icon, title) {
var html = ``;
return html;
}
/*
* Construct an 'icon button' using the fontawesome set
*/
function makeIconButton(icon, cls, pk, title, options={}) {
var classes = `btn btn-outline-secondary ${cls}`;
var id = `${cls}-${pk}`;
var html = '';
var extraProps = '';
if (options.disabled) {
extraProps += `disabled='true' `;
}
if (options.collapseTarget) {
extraProps += `data-bs-toggle='collapse' href='#${options.collapseTarget}'`;
}
html += ``;
return html;
}
/*
* Render a progessbar!
*
* @param value is the current value of the progress bar
* @param maximum is the maximum value of the progress bar
*/
function makeProgressBar(value, maximum, opts={}) {
var options = opts || {};
value = parseFloat(value);
var percent = 100;
// Prevent div-by-zero or null value
if (maximum && maximum > 0) {
maximum = parseFloat(maximum);
percent = parseInt(value / maximum * 100);
}
if (percent > 100) {
percent = 100;
}
var extraclass = '';
if (value > maximum) {
extraclass='progress-bar-over';
} else if (value < maximum) {
extraclass = 'progress-bar-under';
}
var style = options.style || '';
var text = options.text;
if (!text) {
if (style == 'percent') {
// Display e.g. "50%"
text = `${percent}%`;
} else if (style == 'max') {
// Display just the maximum value
text = `${maximum}`;
} else if (style == 'value') {
// Display just the current value
text = `${value}`;
} else if (style == 'blank') {
// No display!
text = '';
} else {
/* Default style
* Display e.g. "5 / 10"
*/
text = `${value} / ${maximum}`;
}
}
var id = options.id || 'progress-bar';
var style = '';
if (opts.max_width) {
style += `max-width: ${options.max_width}; `;
}
return `