function get_empty_state(message, action) { return `

${message}

${action ? `

${action}

`: ''}
`; } function get_item_card_container_html(items, title='', get_item_html = get_item_card_html) { const items_html = (items || []).map(item => get_item_html(item)).join(''); const title_html = title ? `

${title}

` : ''; const html = `
${title_html} ${items_html}
`; return html; } function get_item_card_html(item) { const item_name = item.item_name || item.name; const title = strip_html(item_name); const img_url = item.image; const company_name = item.company; // Subtitle let subtitle = [comment_when(item.creation)]; const rating = item.average_rating; if (rating > 0) { subtitle.push(rating + ``) } subtitle.push(company_name); let dot_spacer = ''; subtitle = subtitle.join(dot_spacer); const item_html = `
${title}
${subtitle}
`; return item_html; } function get_local_item_card_html(item) { const item_name = item.item_name || item.name; const title = strip_html(item_name); const img_url = item.image; const company_name = item.company; const is_active = item.publish_in_hub; const id = item.hub_item_code || item.item_code; // Subtitle let subtitle = [comment_when(item.creation)]; const rating = item.average_rating; if (rating > 0) { subtitle.push(rating + ``) } subtitle.push(company_name); let dot_spacer = ''; subtitle = subtitle.join(dot_spacer); const edit_item_button = `
`; const item_html = `
${title}
${subtitle}
${edit_item_button}
`; return item_html; } function get_rating_html(rating) { let rating_html = ``; for (var i = 0; i < 5; i++) { let star_class = 'fa-star'; if (i >= rating) star_class = 'fa-star-o'; rating_html += ``; } return rating_html; } function make_search_bar({wrapper, on_search, placeholder = __('Search for anything')}) { const $search = $(`
` ); wrapper.append($search); const $search_input = $search.find('input'); $search_input.on('keydown', frappe.utils.debounce((e) => { if (e.which === frappe.ui.keyCode.ENTER) { const search_value = $search_input.val(); on_search(search_value); } }, 300)); } export { get_empty_state, get_item_card_container_html, get_item_card_html, get_local_item_card_html, get_rating_html, make_search_bar, }