Render links for search results

This commit is contained in:
Oliver Walters 2022-03-29 22:40:47 +11:00
parent 78e5a685dc
commit 22ee6614cc

View File

@ -92,6 +92,7 @@ function updateSearch() {
renderPart, renderPart,
{ {
show_stock_data: false, show_stock_data: false,
url: '/part',
} }
); );
} }
@ -116,6 +117,7 @@ function updateSearch() {
'{% trans "Stock Items" %}', '{% trans "Stock Items" %}',
renderStockItem, renderStockItem,
{ {
url: '/stock/item',
} }
); );
} }
@ -169,10 +171,17 @@ function addSearchResults(key, results, title, renderFunc, renderParams={}) {
`); `);
results.forEach(function(result) { results.forEach(function(result) {
var pk = result.pk || result.id;
var html = renderFunc(key, result, renderParams); var html = renderFunc(key, result, renderParams);
if (renderParams.url) {
html = `<a href='${renderParams.url}/${pk}/'>` + html + `</a>`;
}
var result_html = ` var result_html = `
<div class='search-result-entry' id='search-result-${key}-${result.pk || result.id}'> <div class='search-result-entry' id='search-result-${key}-${pk}'>
${html} ${html}
</div> </div>
`; `;