import SubPage from './base_page'; import { make_search_bar, get_item_card_container_html, get_local_item_card_html } from '../helpers'; erpnext.hub.Publish = class Publish extends SubPage { make_wrapper() { super.make_wrapper(); this.items_to_publish = []; this.unpublished_items = []; this.fetched_items = []; frappe.realtime.on("items-sync", (data) => { this.$wrapper.find('.progress-bar').css('width', data.progress_percent+'%'); if(data.progress_percent === 100 || data.progress_percent === '100') { setTimeout(() => { hub.settings.sync_in_progress = 0; frappe.db.get_doc('Hub Settings') .then(doc => { hub.settings = doc; this.refresh(); }); }, 500); } }); } refresh() { if(!hub.settings.sync_in_progress) { this.make_publish_ready_state(); } else { this.make_publish_in_progress_state(); } } make_publish_ready_state() { this.$wrapper.empty(); this.$wrapper.append(this.get_publishing_header()); make_search_bar({ wrapper: this.$wrapper, on_search: keyword => { this.search_value = keyword; this.get_items_and_render(); }, placeholder: __('Search Items') }); this.setup_publishing_events(); if(hub.settings.last_sync_datetime) { this.show_message(`Last sync was ${comment_when(hub.settings.last_sync_datetime)}. See your Published Products.`); } this.get_items_and_render(); } get_publishing_header() { const title_html = `${__('Select Products to Publish')}`; const subtitle_html = `
${__(`Only products with an image, description and category can be published. Please update them if an item in your inventory does not appear.`)}
`; const publish_button_html = ``; return $(`${__(`Only products with an image, description and category can be published. Please update them if an item in your inventory does not appear.`)}
`; this.$wrapper.append(subtitle_html); // Show search list with only desctiption, and don't set any events make_search_bar({ wrapper: this.$wrapper, on_search: keyword => { this.search_value = keyword; this.get_items_and_render(); }, placeholder: __('Search Items') }); this.get_items_and_render(); } show_publish_progress() { const items_to_publish = this.items_to_publish.length ? this.items_to_publish : JSON.parse(hub.settings.custom_data); const $publish_progress = $(`${__(`Syncing ${items_to_publish.length} Products`)}