const endpoint = 'https://menustore.canname.nu/api.php'; const cssfile = document.createElement('link'); cssfile.rel = 'stylesheet'; cssfile.href = 'https://menuserver.canname.nu/adilas-onboarding/css/style.css'; document.getElementsByTagName('head')[0].appendChild(cssfile); document.getElementsByTagName('head')[0].appendChild(document.createElement('title')); const favicon = document.createElement('link'); favicon.rel = 'icon'; favicon.href = 'https://menustore.canname.nu/images/favicon.png'; favicon.type = 'image/x-icon'; document.getElementsByTagName('head')[0].appendChild(favicon); const font_googleapis = document.createElement('link'); font_googleapis.rel = 'preconnect'; font_googleapis.href = 'https://fonts.googleapis.com'; document.getElementsByTagName('head')[0].appendChild(font_googleapis); const font_gstatic = document.createElement('link'); font_gstatic.rel = 'preconnect'; font_gstatic.href = 'https://fonts.gstatic.com'; font_gstatic.crossOrigin = true; document.getElementsByTagName('head')[0].appendChild(font_gstatic); const font_poppins_css = document.createElement('link'); font_poppins_css.rel = 'stylesheet'; font_poppins_css.href = 'https://fonts.googleapis.com/css2?family=Poppins:wght@400;500&display=swap'; document.getElementsByTagName('head')[0].appendChild(font_poppins_css); const corp_setup = document.createElement('script'); corp_setup.type = 'text/javascript'; corp_setup.src = 'https://menustore.canname.nu/assets/scripts/org_setup.js'; document.getElementsByTagName('head')[0].appendChild(corp_setup); function CannaAuth(){ this.handle_login = async function(){ if(getCookie('cpck').length){ document.getElementsByTagName('title')[0].innerText = 'CannaMenu Bulk Products Editor'; const products = new CannaProductsImporter(); products.showSingleDispensary(); } else if(getCookie('user_display') == '' ){ document.getElementsByTagName('title')[0].innerText = 'CannaMenu Login'; const onboarding_content = document.getElementById('onboarding_content'); const user_login = document.createElement('div'); user_login.id = 'user-login'; user_login.className = 'total-center'; user_login.style.width = '300px'; onboarding_content.appendChild(user_login); const login_icon = document.createElement('img'); user_login.appendChild(login_icon); login_icon.src = 'https://mycannaportal.com/assets/images/portal-login-book.png'; const header_text = document.createElement('h2'); header_text.style.marginTop = '5px'; user_login.appendChild(header_text); document.getElementsByTagName('head')[0].style.fontFamily = 'Poppins'; //header_text.style.fontFamily = 'Poppins'; header_text.style.textAlign = 'center'; header_text.appendChild(document.createTextNode('CannaMenu')); header_text.style.color = '#3c9249'; const username_wrapper = document.createElement('div'); username_wrapper.style.textAlign = 'left'; username_wrapper.style.padding = '3px'; user_login.appendChild(username_wrapper); const username_caption = document.createElement('div'); username_wrapper.appendChild(username_caption); username_wrapper.style.border = '1px solid #d5dfe1'; //username_caption.style.fontSize = 'small'; username_caption.style.textAlign = 'left'; username_caption.className = 'input-field-label'; username_caption.appendChild(document.createTextNode('Username')) const username_field = document.createElement('input'); username_field.id = 'username'; username_field.style.all = 'unset'; username_field.style.width = '100%'; username_wrapper.appendChild(username_field); const pw_wrapper = document.createElement('div'); user_login.appendChild(pw_wrapper); pw_wrapper.style.textAlign = 'left'; pw_wrapper.style.padding = '3px'; pw_wrapper.style.border = '1px solid #d5dfe1'; //pw_wrapper.style.fontSize = 'small'; const pw_caption = document.createElement('div'); pw_wrapper.appendChild(pw_caption); pw_caption.className = 'input-field-label'; pw_caption.appendChild(document.createTextNode('Password')); const pw_field = document.createElement('input'); pw_field.type = 'password'; pw_field.style.width = '100%'; pw_field.id = 'password'; pw_field.style.all = 'unset'; pw_wrapper.appendChild(pw_field); user_login.appendChild(document.createElement('br')); const login_button = document.createElement('button'); login_button.className = 'action-button save-button'; login_button.style.width = '50%'; login_button.style.border = '1px solid #d5dfe1'; login_button.style.borderRadius = '100px'; login_button.style.paddingTop = '1px'; login_button.appendChild(document.createTextNode('Login')); user_login.appendChild(login_button); const login_fail = document.createElement('div'); login_fail.className = 'login-fail'; user_login.appendChild(login_fail); var thiss = this; login_button.onclick = async function(){ const fd = new FormData(); fd.append('action', 'LogOnboardingUser'); fd.append('user', document.getElementById('username').value); fd.append('password', document.getElementById('password').value); const login_resp = await fetch(endpoint, {method: "POST", body: fd}); const login_object = await login_resp.json(); if(login_object.status != 'success'){ document.getElementById('login-result').innerHTML = 'Login Failed'; return false; } else{ document.getElementById('login-result').innerHTML = ''; document.cookie = 'user_display=' + login_object.msg; if(true == login_object.is_admin){ const chooser = new CannaProductsImporter(); chooser.renderStoreChooser(); } else{ document.getElementsByTagName('title')[0].innerText = 'CannaMenu Bulk Products Editor'; const products = new CannaProductsImporter(); products.showSingleDispensary(); } } } const login_result = document.createElement('div'); user_login.appendChild(login_result); login_result.id = 'login-result'; } else{ const fd2 = new FormData(); fd2.append('action', 'GetOnboardingUserInfo'); const resp2 = await fetch(endpoint, {method: "POST", body: fd2}); const ret2 = await resp2.json(); if(ret2.is_admin){ const chooser = new CannaProductsImporter(); chooser.renderStoreChooser(); } else{ document.getElementsByTagName('title')[0].innerText = 'CannaMenu Bulk Products Editor'; const products = new CannaProductsImporter(); products.showSingleDispensary(); } } } } function getCookie(cname) { var name = cname + "="; var decodedCookie = decodeURIComponent(document.cookie); var ca = decodedCookie.split(';'); for(var i = 0; i img'); //alert(status_icon.src); if(!status_icon){ continue; } status_icon.src = 'https://menustore.canname.nu/images/set-up-or-set-up-not-visible.png'; let status_icon_link = document.querySelector('a[data-part_id="' + items_list[il].product_pos_id + '"]'); if(items_list[il].is_active == '0'){ status_icon.style.opacity = '50%'; status_icon_link.title = "Item connected\nInactive\nClick to activate"; status_icon_link.dataset.direction = 'activate'; } else{ status_icon_link.title = "Item connected\nActive\nClick to deactivate"; status_icon_link.dataset.direction = 'deactivate'; } if(items_list[il].is_active == '1'){ //document.querySelector('input[data-part_id="' + items_list[il].product_pos_id + '"]').checked = true; if('' == type_status.value){ type_status.value = items_list[il].medrec; } } const item_name_field = document.getElementsByName('name_input__' + items_list[il].product_pos_id)[0]; if(items_list[il].name.length){ item_name_field.style.backgroundColor = fields_bg_color; item_name_field.style.color = fields_color; item_name_field.value = items_list[il].name; } const category_id_field = document.getElementsByName('cat_select__' + items_list[il].product_pos_id)[0]; if(items_list[il].category_id){ category_id_field.style.backgroundColor = fields_bg_color; category_id_field.style.color = fields_color; category_id_field.value = items_list[il].category_id; await category_id_field.onchange(); } const subcategory_id_field = document.getElementsByName('subcat_select__' + items_list[il].product_pos_id)[0]; if(items_list[il].subcategory_id){ subcategory_id_field.style.backgroundColor = fields_bg_color; subcategory_id_field.style.color = fields_color; subcategory_id_field.value = items_list[il].subcategory_id; } const description_field = document.getElementsByName('description_textarea__' + items_list[il].product_pos_id)[0]; if(1){ description_field.style.backgroundColor = fields_bg_color; description_field.style.color = fields_color; description_field.value = items_list[il].description; } const species_field = document.getElementsByName('species_select__' + items_list[il].product_pos_id)[0]; species_field.style.backgroundColor = fields_bg_color; species_field.style.color = fields_color; species_field.value = items_list[il].species; const brand_field = document.getElementsByName('brand_input__' + items_list[il].product_pos_id)[0]; //brand_field.style.backgroundColor = fields_bg_color; brand_field.style.color = fields_color; brand_field.value = items_list[il].brand; const thc_field = document.getElementsByName('thc_input__' + items_list[il].product_pos_id)[0]; thc_field.style.backgroundColor = fields_bg_color; thc_field.style.color = fields_color thc_field.value = items_list[il].thc_pct != '-1' ? items_list[il].thc_pct : ''; const cbd_field = document.getElementsByName('cbd_input__' + items_list[il].product_pos_id)[0]; cbd_field.style.backgroundColor = fields_bg_color; //cbd_field.style.color = fields_color; cbd_field.value = items_list[il].cbd_pct != '-1' ? items_list[il].cbd_pct : ''; const strain_field = document.getElementsByName('strain_input__' + items_list[il].product_pos_id)[0]; alert('strain_input__' + items_list[il].product_pos_id); strain_field.style.backgroundColor = fields_bg_color; strain_field.style.color = fields_color; strain_field.value = 'xxxxxxxxxxx';//items_list[il].strain; const pricing_field = document.getElementsByName('pricing_select__' + items_list[il].product_pos_id)[0]; pricing_field.style.backgroundColor = fields_bg_color; pricing_field.style.color = fields_color; if(items_list[il].pricing_json.indexOf('group') != -1){ //pricing_field.value = items_list[il].pricing_json.replace('group:', ''); //pricing_field.dataset.originalValue = items_list[il].pricing_json.replace('group:', ''); pricing_field.setAttribute('data-original_value', pricing_field.value); alert(pricing_field.getAttribute('data-originalValue'));return; } else{ let local_opt = document.createElement('option'); local_opt.value = 'local'; local_opt.appendChild(document.createTextNode('Unique Pricing')); pricing_field.prepend(local_opt); let pricing = JSON.parse(items_list[il].pricing_json); let pricing_tooltip = ''; if( typeof pricing.single_quantity_prices != 'undefined'){ for(let z = 0; z < pricing.single_quantity_prices.length; z++){ pricing_tooltip += pricing.single_quantity_prices[z].size + ' ' + pricing.uom + ' $' + pricing.single_quantity_prices[z].price + "\n"; } } pricing_field.title = pricing_tooltip; pricing_field.value = 'local'; pricing_field.dataset.originalValue = 'local'; let local_pricing = document.getElementsByName('pricingjson_input__' + items_list[il].product_pos_id)[0]; local_pricing.value = items_list[il].pricing_json; let local_is_on_sale = document.getElementsByName('isonsale_input__' + items_list[il].product_pos_id)[0]; local_is_on_sale.value = items_list[il].is_on_sale; let local_is_on_sale_member = document.getElementsByName('isonsalemember_input__' + items_list[il].product_pos_id)[0]; local_is_on_sale_member.value = items_list[il].is_on_sale_member; let local_uom = document.getElementsByName('uom_input__' + items_list[il].product_pos_id)[0]; local_uom.value = items_list[il].uom; let local_pricing_model = document.getElementsByName('pricingmodel_input__' + items_list[il].product_pos_id)[0]; local_pricing_model.value = items_list[il].use_member_pricing; } } hide_cp_spinner(); } this.showSingleDispensary = async function(){ const fd = new FormData(); fd.append('tempuser', getCookie('user_display')); if(getCookie('cpck')){ fd.append('login_key', getCookie('cpck')); } else{ return false; } const onboarding_content = document.getElementById('onboarding_content'); const launch_button = document.createElement('button'); onboarding_content.appendChild(launch_button); launch_button.innerHTML = 'Launch Cannamenu Editor'; const thiss = this; launch_button.onclick = async function(){ onboarding_content.innerHTML = ''; onboarding_content.parentElement.id = 'cannamenu-div'; document.getElementsByTagName('body')[0].appendChild(onboarding_content); onboarding_content.style.backgroundColor = 'white'; onboarding_content.style.width = '98vw'; onboarding_content.style.height = '98vh'; onboarding_content.style.zIndex = '10000'; onboarding_content.style.position = 'absolute'; onboarding_content.style.top = '0'; onboarding_content.style.left = '0'; onboarding_content.style.overflow = 'auto'; fd.append('action', 'GetSingleDispensary'); const resp = await fetch(endpoint, {method: 'POST', body: fd}); const dispensary_info = await resp.json(); const inputs = dispensary_info.msg.split('__'); await thiss.renderInStockProducts(inputs[0], inputs[1]); } } this.renderInStockProducts = async function(unid, api_url){ show_cp_spinner('Checking Stock'); const fd = new FormData(); fd.append('action', 'GetUnmatchedProducts'); fd.append('unid', unid); fd.append('user', getCookie('user_display')); const resp = await fetch(endpoint, {method: 'POST', body: fd}); const in_stock_products = await resp.json(); const onboarding_content = document.getElementById('onboarding_content'); onboarding_content.innerHTML = ''; onboarding_content.style.overflowX = 'scroll'; onboarding_content.style.width = '100%'; if(in_stock_products.status != 'success'){ hide_cp_spinner(); onboarding_content.appendChild(document.createTextNode('Error')); return false; } const dispensary_type_wrapper = document.createElement('div'); onboarding_content.appendChild(dispensary_type_wrapper); dispensary_type_wrapper.id = 'dispensary-type-wrapper'; //dispensary_type_wrapper.style.position = 'relative'; dispensary_type_wrapper.style.border = '1px solid black'; dispensary_type_wrapper.style.padding = '0px 15px 15px 15px'; const header_table = document.createElement('table'); dispensary_type_wrapper.appendChild(header_table); header_table.id = 'header-table'; header_table.style.width = '100%'; const dispensary_meta_row = document.createElement('tr'); header_table.appendChild(dispensary_meta_row); const dispensary_info_cell = document.createElement('td'); dispensary_meta_row.appendChild(dispensary_info_cell); dispensary_info_cell.id = 'dispensary-info-cell'; dispensary_info_cell.colSpan = '3'; dispensary_info_cell.style.textAlign = 'center'; //dispensary_info_cell.style.position = 'relative'; const dispensary_info_positioner = document.createElement('div'); dispensary_info_cell.appendChild(dispensary_info_positioner); dispensary_info_positioner.style.position = 'relative'; let info_formdata = new FormData(); info_formdata.append('unid', unid); info_formdata.append('action', 'GetDispensaryMeta'); const meta_resp = await fetch(endpoint, {method: 'POST', body: info_formdata}); const dispensary_meta = await meta_resp.json(); const adilas_location_id = dispensary_meta.location_id; const adilas_corp_key = dispensary_meta.login_key; const meta_line = '

' + dispensary_meta.name + '

' + dispensary_meta.city + ', ' + dispensary_meta.state + ' - ' + dispensary_meta.Street + '
'; dispensary_info_positioner.innerHTML = meta_line; dispensary_info_positioner.style.textAlign = 'center'; const logout_button = document.createElement('button'); dispensary_info_positioner.appendChild(logout_button); logout_button.style.position = 'absolute'; logout_button.style.top = '20px'; logout_button.style.right = '15px'; //logout_button.style.zIndex = 1000; logout_button.appendChild(document.createTextNode('Log Out')); logout_button.onclick = function(){ delete_cookie('user_display'); window.location.reload(); } const header_table_row = document.createElement('tr'); header_table.appendChild(header_table_row); //header_table_row.style.padding = ' 5px 15px 15px 15px'; //header_table_row.style.backgroundColor = 'orange'; const dispensary_type_cell = document.createElement('td'); dispensary_type_cell.style.width = '33%'; header_table_row.appendChild(dispensary_type_cell); const dispensary_type = document.createElement('select'); dispensary_type.id = 'dispensary-type'; const no_type_opt = document.createElement('option'); dispensary_type.appendChild(no_type_opt); no_type_opt.value = ''; no_type_opt.appendChild(document.createTextNode('Select')); const med_type_opt = document.createElement('option'); dispensary_type.appendChild(med_type_opt); med_type_opt.value = 'Medical'; med_type_opt.appendChild(document.createTextNode('Medical')); const rec_type_opt = document.createElement('option'); dispensary_type.appendChild(rec_type_opt); rec_type_opt.value = 'Recreational'; rec_type_opt.appendChild(document.createTextNode('Recreational')); const dispensary_type_label = document.createElement('div'); dispensary_type_cell.appendChild(dispensary_type_label); dispensary_type_label.className = 'cm-label'; dispensary_type_label.appendChild(document.createTextNode('Dispensary Type')); dispensary_type_cell.appendChild(dispensary_type); const save_dispensary_type = document.createElement('button'); dispensary_type_cell.appendChild(save_dispensary_type); save_dispensary_type.id = 'save-disp-type'; save_dispensary_type.appendChild(document.createTextNode('Save')); save_dispensary_type.onclick = async function(){ const fd = new FormData(); fd.append('action', 'SaveStoreDispensaryType'); fd.append('dispensary_type', dispensary_type.value); fd.append('unid', unid); const rezult = await fetch(endpoint, {method: 'POST', body: fd}); this.innerHTML = 'Saved'; } const fd_fill_disp_type = new FormData(); fd_fill_disp_type.append('action', 'GetStoreDispensaryType'); fd_fill_disp_type.append('unid', unid); const res = await fetch(endpoint, {method: 'POST', body: fd_fill_disp_type}); const type_value = await res.json(); if(type_value){ document.getElementById('dispensary-type').value = type_value; } const price_groups_edit_cell = document.createElement('td'); header_table_row.appendChild(price_groups_edit_cell); price_groups_edit_cell.id = 'price-groups-edit-cell'; price_groups_edit_cell.style.textAlign = 'center'; price_groups_edit_cell.style.width = '33%'; const price_groups_edit_label = document.createElement('div'); price_groups_edit_cell.appendChild(price_groups_edit_label); price_groups_edit_label.className = 'cm-label'; price_groups_edit_label.appendChild(document.createTextNode('Price Editor')); const pricing_groups_edit_select = document.createElement('select'); price_groups_edit_cell.appendChild(pricing_groups_edit_select); pricing_groups_edit_select.id = 'pricing-groups-edit-select'; const price_groups_select_option = document.createElement('option'); pricing_groups_edit_select.appendChild(price_groups_select_option); price_groups_select_option.value = ''; price_groups_select_option.appendChild(document.createTextNode('Select Price Group')); price_groups_select_option.style.textAlign = 'center'; const pricing_group_edit_button = document.createElement('button'); price_groups_edit_cell.appendChild(pricing_group_edit_button); pricing_group_edit_button.innerHTML = 'Edit'; pricing_group_edit_button.onclick = async function(){ let pricing_group = document.getElementById('pricing-groups-edit-select').value; if('' == pricing_group){ return false; } await drawPresetEditor(pricing_group); } let pricing_groups_formdata = new FormData(); pricing_groups_formdata.append('action', 'GetPricingTierSelect'); pricing_groups_formdata.append('unid', unid); const pricing_groups_resp = await fetch(endpoint, {method: 'POST', body: pricing_groups_formdata}); const pricing_groups = await pricing_groups_resp.json(); if(pricing_groups.length){ for(let g = 0; g < pricing_groups.length; g++){ let price_group_opt = document.createElement('option'); pricing_groups_edit_select.appendChild(price_group_opt); price_group_opt.value = pricing_groups[g].option_value; price_group_opt.appendChild(document.createTextNode(pricing_groups[g].option_label)); } } const csv_manager_cell = document.createElement('td'); header_table_row.appendChild(csv_manager_cell); csv_manager_cell.style.textAlign = 'right'; const csv_manager_cell_header = document.createElement('div'); csv_manager_cell.appendChild(csv_manager_cell_header); csv_manager_cell_header.className = 'cm-label'; csv_manager_cell_header.appendChild(document.createTextNode('CSV Management')); const import_form = document.createElement('form'); import_form.style.marginBottom = '5px'; const import_file_field = document.createElement('input'); import_file_field.type = 'file'; import_file_field.name = 'userfile'; import_form.appendChild(import_file_field); const import_hidden_unid = document.createElement('input'); import_form.appendChild(import_hidden_unid); import_hidden_unid.type = 'hidden'; import_hidden_unid.value = unid; import_hidden_unid.name = 'unid'; const import_hidden_api_url = document.createElement('input'); import_form.appendChild(import_hidden_api_url); import_hidden_api_url.type = 'hidden'; import_hidden_api_url.name = 'api_url'; import_hidden_api_url.value = api_url; const import_submit = document.createElement('input'); import_form.appendChild(import_submit); import_submit.value = 'Upload CSV'; import_submit.type = 'submit'; csv_manager_cell.appendChild(import_form); const thiss = this; import_form.onsubmit = async function(e){ e.preventDefault(); show_cp_spinner('Saving CSV Values', 'book'); const import_form_data = new FormData(this); import_form_data.append('action', 'ImportProductsCsv'); const resp = await fetch(endpoint, {method: 'POST', body: import_form_data}); const response = await resp.json(); if(response.status != true){ hide_cp_spinner(); cpError(response.msg); } else{ update_cp_spinner_text('Success!'); setTimeout(function(){thiss.renderExistingMenuValues(unid, menu_items, api_url);}, 10000); //thiss.renderExistingMenuValues(unid, menu_items, api_url); //cpSuccess(response.msg); } } const export_csv_subrow = document.createElement('div'); csv_manager_cell.appendChild(export_csv_subrow); const export_link = document.createElement('a'); export_csv_subrow.appendChild(export_link); export_link.className = 'plain-link'; export_link.href = 'https://menustore.canname.nu/api.php?action=ExportInStockProducts&unid=' + unid; export_link.appendChild(document.createTextNode('Download CSV')); const embed_row = document.createElement('tr'); header_table.appendChild(embed_row); const embed_code_cell = document.createElement('td'); embed_row.appendChild(embed_code_cell); embed_code_cell.colSpan = '3'; embed_code_cell.className = 'cm-label'; embed_code_cell.appendChild(document.createTextNode('Embed Code: ')); const embed_code_field = document.createElement('input'); embed_code_cell.appendChild(embed_code_field); embed_code_field.style.width = '350px'; embed_code_field.value = '
'; embed_code_field.select(); embed_code_cell.appendChild(document.createTextNode(' ')); const copy_link = document.createElement('a'); embed_code_cell.appendChild(copy_link); copy_link.style.cursor = 'pointer'; copy_link.style.textDecoration = 'none'; copy_link.className = 'cm-label'; copy_link.appendChild(document.createTextNode('Copy')); copy_link.onclick = function(){ navigator.clipboard.writeText(embed_code_field.value).then(() => { copy_link.innerHTML = 'Copied'; setTimeout(function(){ copy_link.innerHTML = 'Copy'; }, 5000); }); } const logout_cell = document.createElement('td'); embed_row.appendChild(logout_cell); logout_cell.style.textAlign = 'center'; const publish_settings_row = document.createElement('tr'); header_table.appendChild(publish_settings_row); const publish_setings_cell = document.createElement('td'); publish_setings_cell.appendChild(document.createTextNode('Publishing Setup')); publish_settings_row.appendChild(publish_setings_cell); publish_setings_cell.colSpan = 3; const publishing_venues = ['Leafly']; const publishing_venues_select = document.createElement('select'); publishing_venues_select.id = 'publishing-venues-select'; publishing_venues_select.style.margin = '0px 10px 0px 10px'; publish_setings_cell.appendChild(publishing_venues_select); const default_publisher_select_value = document.createElement('option'); publishing_venues_select.appendChild(default_publisher_select_value); default_publisher_select_value.value = ''; default_publisher_select_value.innerHTML = 'Select'; for(let i = 0; i < publishing_venues.length; i++){ const opt = document.createElement('option'); publishing_venues_select.appendChild(opt); opt.value = publishing_venues[i]; opt.appendChild(document.createTextNode(publishing_venues[i])); } const publishers = [{"key_name": "menu_integration_key", "publisher": "Leafly"}]; publishing_venues_select.onchange = function(){ const pub_key_wrapper = document.getElementById('pub-key-wrapper'); if('' == this.value){ pub_key_wrapper.style.display = 'none'; } else{ pub_key_wrapper.style.display = 'inline'; } const name_span = document.getElementById('publishing-key-name'); name_span.innerHTML = ''; for(let j = 0; j < publishers.length; j++){ if(publishers[j].publisher == this.value){ name_span.innerHTML = publishers[j].key_name; break; } } } const publishing_key_name = document.createElement('span'); publishing_key_name.id = 'publishing-key-name'; publish_setings_cell.appendChild(publishing_key_name); const publishers_key_value_save_wrapper = document.createElement('span'); publish_setings_cell.appendChild(publishers_key_value_save_wrapper); publishers_key_value_save_wrapper.style.display = 'none'; publishers_key_value_save_wrapper.id = 'pub-key-wrapper'; const publishers_key_value_input = document.createElement('input'); publishers_key_value_save_wrapper.appendChild(publishers_key_value_input); publishers_key_value_input.style.width = '200px'; publishers_key_value_input.style.margin = '0px 10px 0px 10px'; const publisher_save_button = document.createElement('button'); publishers_key_value_save_wrapper.appendChild(publisher_save_button); publisher_save_button.innerHTML = 'Save Publisher Key'; var delete_cookie = function(name) { document.cookie = name + '=;expires=Thu, 01 Jan 1970 00:00:01 GMT;'; }; const product_table = document.createElement('table'); product_table.id = 'product-table'; product_table.style.fontSize = '13px'; product_table.cellSpacing = 0; const product_table_header = document.createElement('thead'); product_table_header.id = 'prodct-table-header'; product_table.appendChild(product_table_header); //product_table_header.style.display = 'table'; //product_table_header.style.tableLayout = 'fixed'; const header_row = document.createElement('tr'); product_table_header.appendChild(header_row); const product_active_header = document.createElement('th'); product_active_header.appendChild(document.createTextNode('Status')); header_row.appendChild(product_active_header); const product_image_header = document.createElement('th'); product_image_header.appendChild(document.createTextNode('Product Image')); header_row.appendChild(product_image_header); const name_header = document.createElement('th'); name_header.appendChild(document.createTextNode('Name')); header_row.appendChild(name_header); const price_tier_header = document.createElement('th'); price_tier_header.appendChild(document.createTextNode('Pricing Group')); header_row.appendChild(price_tier_header); const adilas_cat_header = document.createElement('th'); adilas_cat_header.style.width = '100px'; adilas_cat_header.appendChild(document.createTextNode('Adilas Category')); header_row.appendChild(adilas_cat_header); const category_header = document.createElement('th'); category_header.appendChild(document.createTextNode('Category')); header_row.appendChild(category_header); const subcat_header = document.createElement('th'); subcat_header.appendChild(document.createTextNode('Subcategory')); header_row.appendChild(subcat_header); const description_header = document.createElement('th'); description_header.appendChild(document.createTextNode('Description')); header_row.appendChild(description_header); const species_header = document.createElement('th'); species_header.appendChild(document.createTextNode('Species')); header_row.appendChild(species_header); const brand_header = document.createElement('th'); brand_header.style.width = '100px'; brand_header.appendChild(document.createTextNode('Brand')); header_row.appendChild(brand_header); const thc_header = document.createElement('th'); thc_header.appendChild(document.createTextNode('THC %')); header_row.appendChild(thc_header); const cbd_header = document.createElement('th'); cbd_header.appendChild(document.createTextNode('CBD %')); header_row.appendChild(cbd_header); const strain_header = document.createElement('th'); header_row.appendChild(strain_header); strain_header.appendChild(document.createTextNode('Strain')); strain_header.style.width = '125px'; const save_row_header = document.createElement('th'); save_row_header.appendChild(document.createTextNode('Save')); header_row.appendChild(save_row_header); const product_table_body = document.createElement('tbody'); product_table.appendChild(product_table_body); //product_table_body.style.display = 'block'; product_table_body.style.height = '500px'; product_table_body.style.overflowY = 'auto'; const selector_row = document.createElement('tr'); product_table_body.appendChild(selector_row); //selector_row.style.display = 'table'; //selector_row.style.tableLayout = 'fixed'; const placeholder_td = document.createElement('td'); selector_row.appendChild(placeholder_td); placeholder_td.colSpan = '4'; const adilas_cat_selector_td = document.createElement('td'); selector_row.appendChild(adilas_cat_selector_td); const adilas_cat_selector = document.createElement('select'); adilas_cat_selector.style.width = '125px'; adilas_cat_selector_td.appendChild(adilas_cat_selector); const all_cat_opt = document.createElement('option'); adilas_cat_selector.appendChild(all_cat_opt); all_cat_opt.value = 'all'; all_cat_opt.appendChild(document.createTextNode('All Categories')); let adilas_cats = []; const fd2 = new FormData(); fd2.append('action', 'GetCategories'); fd2.append('user', getCookie('user_display')); const resp2 = await fetch(endpoint, {method: 'POST', body: fd2}); const cm_categories_list = await resp2.json(); // Get the pricing tiers let formdata = new FormData(); formdata.append('action', 'GetPricingTierSelect'); formdata.append('unid', unid); const pricing_tier_resp = await fetch(endpoint, {method: 'POST', body: formdata}); const pricing_tier_list = await pricing_tier_resp.json(); // This is the main product loop const default_status_icon = 'https://menustore.canname.nu/images/Not-Set-Up.png'; const menu_items = []; for(let i = 0; i < in_stock_products.products.length; i++){ menu_items.push(in_stock_products.products[i].PARTID); // First start the row let tr = document.createElement('tr'); product_table_body.appendChild(tr); //tr.style.display = 'table'; //tr.style.tableLayout = 'fixed'; tr.id = 'row_' + in_stock_products.products[i].PARTID; tr.className = 'product-row'; // The active checkbox let active_checkbox_cell = document.createElement('td'); tr.appendChild(active_checkbox_cell); active_checkbox_cell.style.textAlign = 'center'; let status_update_link = document.createElement('a'); active_checkbox_cell.appendChild(status_update_link); status_update_link.title = 'Item not connected'; status_update_link.className = 'status-update-link'; status_update_link.onclick = async function(){ if(typeof this.dataset.direction == 'undefined'){ return; } let formdata = new FormData(); formdata.append('action', 'ToggleIsActive'); formdata.append('direction', this.dataset.direction); formdata.append('unid', unid); formdata.append('pos_id', this.dataset.part_id); let activate_response = await fetch(endpoint, {method: 'POST', body: formdata}); let activate_result = await activate_response.json() if(activate_result == 1){ this.getElementsByTagName('img')[0].style.opacity = '100%'; this.title = "Item connected\nActive\nClick to deactivate"; this.dataset.direction = 'deactivate'; } else{ this.getElementsByTagName('img')[0].style.opacity = '50%'; this.title = "Item connected\nInactive\nClick to activate"; this.dataset.direction = 'activate'; } } let status_icon = document.createElement('img'); status_update_link.appendChild(status_icon); status_update_link.dataset.part_id = in_stock_products.products[i].PARTID; status_icon.dataset.part_id = in_stock_products.products[i].PARTID; status_icon.src = default_status_icon; let active_checkbox = document.createElement('input'); //active_checkbox_cell.appendChild(active_checkbox); active_checkbox.type = 'checkbox'; active_checkbox.className = 'active-checkbox'; //active_checkbox.checked = true; active_checkbox.dataset.part_id = in_stock_products.products[i].PARTID; active_checkbox.onchange = async function(){ let direction = 'deactivate'; if(this.checked){ direction = 'activate'; } let formdata = new FormData(); formdata.append('action', 'ToggleIsActive'); formdata.append('direction', direction); formdata.append('unid', unid); formdata.append('pos_id', this.dataset.part_id); let activate_response = await fetch(endpoint, {method: 'POST', body: formdata}); let activate_result = await activate_response.json(); if(!activate_result){ this.checked = false; } } // The image select let image_select_cell = document.createElement('td'); tr.appendChild(image_select_cell); let image_select = document.createElement('select'); image_select.className = 'image-select'; image_select.style.width = '100px'; image_select_cell.appendChild(image_select); image_select.name = 'image_select__' + in_stock_products.products[i].PARTID; image_select.onmouseover = function(e){ let product_image_span = document.createElement('span'); product_image_span.id = 'product-image-span'; let product_image = document.createElement('img'); product_image_span.appendChild(product_image); // https://cannapages-3bec44563ca1ec4d162f8344ffa9e87c.s3.amazonaws.com/405911-thumb.jpg?cache=1620015485 product_image.src = 'https://cannapages-' + unid + '.s3.amazonaws.com/' + in_stock_products.products[i].PARTID + '-thumb.jpg'; product_image.onerror = function(){ this.onerror = null; product_image_span.style.padding = '20px'; product_image_span.style.backgroundColor = 'yellow'; product_image_span.style.border = '1px solid #ccc'; product_image_span.style.borderRadius = '7px'; product_image_span.innerHTML = 'Using Default Image'; } product_image_span.style.position = 'fixed'; product_image_span.style.left = '50%'; product_image_span.style.top = '50%'; product_image_span.style.transform = 'translate(-50%,-50%)'; product_image_span.style.zIndex = '1'; document.getElementsByTagName('body')[0].appendChild(product_image_span); } image_select.onmouseleave = function(){ document.getElementById('product-image-span').remove(); } let select_opt = document.createElement('option'); image_select.appendChild(select_opt); select_opt.value = ''; select_opt.appendChild(document.createTextNode('No Change')); // Default image for the category let default_opt = document.createElement('option'); image_select.appendChild(default_opt); default_opt.value = 'use_default'; default_opt.appendChild(document.createTextNode('Use Category Default')); // Upload an image - will prompt at save let upload_opt = document.createElement('option'); image_select.appendChild(upload_opt); upload_opt.value = 'upload'; upload_opt.appendChild(document.createTextNode('Upload Image')); if(in_stock_products.products[i].PHOTOCOUNT > 0){ let adilas_images = in_stock_products.products[i].PHOTOLIST.split(','); for(let j = 0; j < adilas_images.length; j++){ let photo_opt = document.createElement('option'); image_select.appendChild(photo_opt); photo_opt.value = api_url + '/top_secret/images/' + in_stock_products.image_folder + '/small/' + adilas_images[j]; photo_opt.appendChild(document.createTextNode('Adilas ' + (j + 1))); } } let file_form = document.createElement('form'); file_form.style.margin = '0'; file_form.style.padding = '0'; let file_field = document.createElement('input'); file_form.appendChild(file_field); let file_form_hidden_disp_field = document.createElement('input'); file_form.appendChild(file_form_hidden_disp_field); file_form_hidden_disp_field.type = 'hidden'; file_form_hidden_disp_field.value = unid; file_form_hidden_disp_field.name = 'unid'; let file_form_hidden_pos_id_field = document.createElement('input'); file_form.appendChild(file_form_hidden_pos_id_field); file_form_hidden_pos_id_field.type = 'hidden'; file_form_hidden_pos_id_field.value = in_stock_products.products[i].PARTID; file_form_hidden_pos_id_field.name = 'pos_id'; file_form.id = 'image-form-' + in_stock_products.products[i].PARTID; image_select_cell.appendChild(file_form); file_field.type = 'file'; file_field.name = 'image_file__' + in_stock_products.products[i].PARTID; file_field.style.width = '125px'; file_form.style.display = 'none'; file_form.onsubmit = async function(){ image_select_cell.style.backgroundColor = 'yellow'; let formdata = new FormData(); formdata.append('action', 'UploadProductImage'); formdata.append('userfile', file_field.files[0]); formdata.append('unid', unid); formdata.append('pos_id', in_stock_products.products[i].PARTID); let image_resp = await fetch(endpoint, {method: 'POST', body: formdata}); let image_upload_status = await image_resp.json(); if(image_upload_status == 'success'){ image_select_cell.style.backgroundColor = '#add6ad'; } return false; } image_select.onchange = function(){ if(this.value == 'upload'){ file_form.style.display = 'block'; } else{ file_field.value = ''; file_form.style.display = 'none'; } } // The product name let product_name_td = document.createElement('td'); tr.appendChild(product_name_td); let product_name = document.createElement("input"); product_name_td.appendChild(product_name); product_name.name = 'name_input__' + in_stock_products.products[i].PARTID; product_name.value = decodeURIComponent(in_stock_products.products[i].PARTNUMBER); product_name.dataset.original_value = decodeURIComponent(in_stock_products.products[i].PARTNUMBER); product_name.oninput = function(){ let title = ''; if(this.value != this.dataset.original_value){ title = 'Original value: ' + this.dataset.original_value + '\nCurrent value: '; } title += this.value; this.title = title; } product_name.title = product_name.value; // Pricing tiers let cm_pricing_tiers_td = document.createElement('td'); tr.appendChild(cm_pricing_tiers_td); let cm_pricing_select = document.createElement('select'); cm_pricing_tiers_td.appendChild(cm_pricing_select); cm_pricing_select.style.width = '125px'; cm_pricing_select.name = 'pricing_select__' + in_stock_products.products[i].PARTID; cm_pricing_select.className = 'cm-pricing-select'; let none_option = document.createElement('option'); none_option.value = ''; none_option.appendChild(document.createTextNode('Select')); cm_pricing_select.appendChild(none_option); let set_price_option = document.createElement('option'); set_price_option.value = 'set_price'; set_price_option.appendChild(document.createTextNode('Set Unique Price')); cm_pricing_select.appendChild(set_price_option); let new_option = document.createElement('option'); new_option.value = 'new_preset'; new_option.appendChild(document.createTextNode('New Preset')); cm_pricing_select.appendChild(new_option); //cm_pricing_select.title = cm_pricing_select.options[cm_pricing_select.selectedIndex].text; cm_pricing_select.onchange = function(){ this.title = this.options[this.selectedIndex].text; //alert(this.dataset.originalValue) if(this.value == 'new_preset'){ let thiss = this; cpInfowindow('New Pricing Group', renderPriceCreator(in_stock_products.products[i].PARTID, unid, true),null, function(){ thiss.value = document.getElementsByName('pricing_select__' + in_stock_products.products[i].PARTID)[0].dataset.originalValue; }); } else if(this.value == 'set_price'){ let thiss = this; let set_price_title = 'Set Price for:
' + document.getElementsByName('name_input__' + in_stock_products.products[i].PARTID)[0].value; cpInfowindow(set_price_title, renderPriceCreator(in_stock_products.products[i].PARTID, unid), null, function(){thiss.value = thiss.dataset.originalValue;}); } } for(let p = 0; p < pricing_tier_list.length; p++){ let tier_option = document.createElement('option'); tier_option.value = pricing_tier_list[p].option_value; tier_option.appendChild(document.createTextNode(pricing_tier_list[p].option_label)); cm_pricing_select.appendChild(tier_option); } // The adilas category let adilas_cat_td = document.createElement('td'); tr.appendChild(adilas_cat_td); adilas_cat_td.className = 'adilas-cat-td'; let adilas_cat = decodeURIComponent(in_stock_products.products[i].PARTCATEGORYNAME); if(adilas_cats.indexOf(adilas_cat) == -1){ // We shall add to the array adilas_cats.push(adilas_cat); } adilas_cat_td.appendChild(document.createTextNode(adilas_cat)); // The CM categore select let cm_cat_select_td = document.createElement('td'); tr.appendChild(cm_cat_select_td); let cm_cat_select = document.createElement('select'); cm_cat_select.name = 'cat_select__' + in_stock_products.products[i].PARTID; cm_cat_select.className = 'cat-select'; cm_cat_select_td.appendChild(cm_cat_select); let cat_select_option = document.createElement('option'); cm_cat_select.appendChild(cat_select_option); cat_select_option.value = ''; cat_select_option.appendChild(document.createTextNode('Select')); for(let k = 0; k < cm_categories_list.length; k++){ let opt = document.createElement('option'); cm_cat_select.appendChild(opt); opt.value = cm_categories_list[k].id; opt.appendChild(document.createTextNode(cm_categories_list[k].name)); } let acat = decodeURIComponent(in_stock_products.products[i].PARTCATEGORYNAME); if(acat.indexOf('lower') != -1 || acat.indexOf('annabis') != -1 || acat.indexOf('oll') != -1){ cm_cat_select.value = '1'; } else if(acat.indexOf('oncentrate') != -1){ cm_cat_select.value = '2'; } else if(acat.indexOf('dible') != -1){ cm_cat_select.value = '3'; } else if(acat.indexOf('opical') != -1){ cm_cat_select.value = '5' } cm_cat_select.dataset.subcat_select = 'subcat_select__' + in_stock_products.products[i].PARTID; cm_cat_select.onchange = async function(){ let cm_subcat_select = document.getElementsByName(this.dataset.subcat_select)[0]; if('' == this.value){ const null_opt = document.createElement('option'); null_opt.value = ''; null_opt.appendChild(document.createTextNode('Select Category First')); cm_subcat_select.innerHTML = ''; cm_subcat_select.appendChild(null_opt); cm_subcat_select.disabled = true; return false; } var fd = new FormData(); fd.append('action', 'GetSubcatSelect'); fd.append('category', this.value); var resp = await fetch(endpoint, { method: "POST", body: fd }); var list = await resp.json(); cm_subcat_select.innerHTML = ''; for(var i = 0; i < list.length; i++){ const opt = document.createElement('option'); opt.value = list[i].id; opt.appendChild(document.createTextNode(list[i].name)); cm_subcat_select.appendChild(opt); } cm_subcat_select.disabled = false; } // The subcat let cm_subcat_td = document.createElement('td'); tr.appendChild(cm_subcat_td); let cm_subcat_select = document.createElement('select'); cm_subcat_select.name = 'subcat_select__' + in_stock_products.products[i].PARTID; cm_subcat_td.appendChild(cm_subcat_select); cm_subcat_select.style.width = '125px'; // The description let cm_description_td = document.createElement('td'); tr.appendChild(cm_description_td); let cm_description = document.createElement('textarea'); cm_description_td.appendChild(cm_description); cm_description.name = 'description_textarea__' + in_stock_products.products[i].PARTID; cm_description.style.width = '100px'; cm_description.style.height = '24px'; cm_description.oninput = function(){ let title = ''; if(this.dataset.original_value != this.value){ title = 'Original value: ' + this.dataset.original_value + '\n'; title += 'Current value: ' + this.value; } else{ title = this.dataset.original_value; } title += '\n\nDrag the diagonal bars on the right to expand'; this.title = title; } cm_description.appendChild(document.createTextNode(in_stock_products.products[i].PARTDESCRIPTION)); cm_description.dataset.original_value = cm_description.value; cm_description.title = cm_description.value + '\n\nDrag the diagonal bars on the right to expand'; // The species let cm_species_td = document.createElement('td'); tr.appendChild(cm_species_td); let cm_species_select = document.createElement('select'); cm_species_select.name = 'species_select__' + in_stock_products.products[i].PARTID; cm_species_td.appendChild(cm_species_select); let na_option = document.createElement('option'); cm_species_select.appendChild(na_option); na_option.value = ''; na_option.appendChild(document.createTextNode('N/A')); let hybrid_option = document.createElement('option'); cm_species_select.appendChild(hybrid_option); hybrid_option.value = 'hybrid'; hybrid_option.appendChild(document.createTextNode('Hybrid')); hybrid_option.selected = true; let indica_option = document.createElement('option'); cm_species_select.appendChild(indica_option); indica_option.value = 'indica'; indica_option.appendChild(document.createTextNode('Indica')); let sativa_option = document.createElement('option'); cm_species_select.appendChild(sativa_option); sativa_option.value = 'sativa'; sativa_option.appendChild(document.createTextNode('Sativa')); // The brand let cm_brand_td = document.createElement('td'); tr.appendChild(cm_brand_td); const cm_brand_wrapper = document.createElement('div'); cm_brand_wrapper.className = 'brand-wrapper'; cm_brand_td.appendChild(cm_brand_wrapper); cm_brand_wrapper.style.position = 'relative'; let cm_brand = document.createElement('input'); cm_brand_wrapper.appendChild(cm_brand); if(in_stock_products.products[i].attributes['brand']) cm_brand.value = in_stock_products.products[i].attributes['brand'].value; cm_brand.className = 'brand-input'; const brand_status_wrapper = document.createElement('div'); cm_brand_wrapper.appendChild(brand_status_wrapper); brand_status_wrapper.className = 'brand-status-wrapper'; brand_status_wrapper.style.position = 'absolute'; brand_status_wrapper.style.top = '5'; brand_status_wrapper.style.right = '7'; const wm_brand_id = document.createElement('input'); brand_status_wrapper.appendChild(wm_brand_id); wm_brand_id.type = 'hidden'; wm_brand_id.name = 'brandid_hidden__' + in_stock_products.products[i].PARTID; /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// const cm_brand_not_connected = document.createElement('div'); brand_status_wrapper.appendChild(cm_brand_not_connected); cm_brand_not_connected.className = 'caution'; const cm_brand_not_connected_link = document.createElement('a'); cm_brand_not_connected.appendChild(cm_brand_not_connected_link); cm_brand_not_connected_link.title = 'Weedmaps Verified Brand match not set up\nClick here to set up'; cm_brand_not_connected_link.style.cursor = 'pointer'; cm_brand_not_connected_link.innerHTML = '⚠'; // Add a positioning and visibility wrapper const autosuggest_wrapper = document.createElement('div'); cm_brand_wrapper.appendChild(autosuggest_wrapper); autosuggest_wrapper.className = 'brand-autosuggest-wrapper'; autosuggest_wrapper.style.position = 'relative'; autosuggest_wrapper.style.visibility = 'hidden'; // Get the suggestion box/wrapper in place const brand_suggestion_box = document.createElement('div'); autosuggest_wrapper.appendChild(brand_suggestion_box); brand_suggestion_box.className = 'brand-suggestion-box'; brand_suggestion_box.style.position = 'absolute'; brand_suggestion_box.style.left = '0'; brand_suggestion_box.style.top = '0'; //brand_suggestion_box.style.width = '95%'; brand_suggestion_box.style.border = '1px solid #ccc'; brand_suggestion_box.style.padding = '5px 10px'; brand_suggestion_box.style.backgroundColor = '#fff'; brand_suggestion_box.style.maxHeight = '250px'; brand_suggestion_box.style.overflowY = 'auto'; brand_suggestion_box.style.zIndex = '2000'; cm_brand.onfocus = function(){ const brand_autosuggests = document.getElementsByClassName('brand-suggestion-box'); for(let i = 0; i < brand_autosuggests.length; i++){ brand_autosuggests[i].innerHTML = ''; const autosugg_wrapper = this.closest('.brand-wrapper').querySelector('.brand-autosuggest-wrapper'); autosugg_wrapper.style.visibility = 'hidden'; } } // insert inline brand autocomplete cm_brand.oninput = async function() { const autosugg_wrapper = this.closest('.brand-wrapper').querySelector('.brand-autosuggest-wrapper'); if (this.value.length < 3) { autosugg_wrapper.style.visibility = 'hidden'; return false; } autosugg_wrapper.style.visibility = 'visible'; const fd = new FormData; fd.append('action', 'GetWmBrandsAutocomplete'); fd.append('q', this.value); const resp = await fetch(endpoint, {method: "POST", body: fd}); const suggestions = await resp.json(); const suggestion_box = this.closest('.brand-wrapper').querySelector('.brand-suggestion-box'); suggestion_box.innerHTML = ''; if (!suggestions.length) { suggestion_box.appendChild(document.createTextNode('No results')); } for (let i = 0; i < suggestions.length; i++) { const suggestion_box_row = document.createElement('div'); suggestion_box.appendChild(suggestion_box_row); suggestion_box_row.style.padding = '0 0 5px 0'; const suggestion_row_link = document.createElement('a'); suggestion_box_row.appendChild(suggestion_row_link); suggestion_row_link.style.cursor = 'pointer'; suggestion_row_link.innerHTML = suggestions[i].name; suggestion_row_link.onclick = function () { const autocomplete_field = this.closest('.brand-wrapper').querySelector('.brand-input'); autocomplete_field.value = this.innerHTML; autocomplete_field.setAttribute('value', this.innerHTML); const suggestion_box = this.closest('.brand-wrapper').querySelector('.brand-suggestion-box'); suggestion_box.innerHTML = ''; } } } cm_brand_not_connected_link.onclick = async function(){ const wm_connect_dialog = document.createElement('div'); this.closest('.brand-status-wrapper').appendChild(wm_connect_dialog); wm_connect_dialog.className = 'wm-connect-dialog'; wm_connect_dialog.style.position = 'absolute'; wm_connect_dialog.style.zIndex = '2'; wm_connect_dialog.style.width = '300px'; wm_connect_dialog.style.border = '1px solid #ccc'; wm_connect_dialog.style.borderRadius = '10px'; wm_connect_dialog.style.padding = '10px'; wm_connect_dialog.style.top = '0'; wm_connect_dialog.style.backgroundColor = 'green'; wm_connect_dialog.style.color = '#ccc'; wm_connect_dialog.style.left = '-150'; const title_div = document.createElement('div'); wm_connect_dialog.appendChild(title_div); title_div.style.position = 'relative'; title_div.style.marginBottom = '10px'; const title_span = document.createElement('span'); title_div.appendChild(title_span); title_span.style.fontWeight = '500'; title_span.appendChild(document.createTextNode('Connect WM verified brand product')); const close_dialog_wrapper = document.createElement('span'); title_div.appendChild(close_dialog_wrapper); close_dialog_wrapper.style.position = 'absolute'; close_dialog_wrapper.style.top = '0'; close_dialog_wrapper.style.right = '0'; const close_link = document.createElement('a'); close_dialog_wrapper.appendChild(close_link); close_link.style.fontSize = '13px'; close_link.style.cursor = 'pointer'; close_link.innerHTML = '×'; close_link.onclick = function(){ this.closest('.wm-connect-dialog').remove(); } const formdiv = document.createElement('div'); wm_connect_dialog.appendChild(formdiv); formdiv.appendChild(document.createTextNode('Brand(autocompletes) | ')); const use_brand_checkbox = document.createElement('input'); formdiv.appendChild(use_brand_checkbox); use_brand_checkbox.type = 'checkbox'; use_brand_checkbox.onchange = function(){ const brand_input = this.closest('tr').querySelector('.brand-input'); const brand_autocomplete = this.closest('.wm-connect-dialog').querySelector('.brand-autocomplete'); if(this.checked){ brand_autocomplete.value = brand_input.value; brand_autocomplete.oninput(); } else{ brand_autocomplete.value = ''; } } formdiv.appendChild(document.createTextNode('Use Brand field')); formdiv.appendChild(document.createElement('br')); const brand_autocomplete_wrapper = document.createElement('div'); formdiv.appendChild(brand_autocomplete_wrapper); brand_autocomplete_wrapper.style.position = 'relative'; brand_autocomplete_wrapper.className = 'brand-autocomplete-wrapper'; const brand_autocomplete = document.createElement('input'); brand_autocomplete_wrapper.appendChild(brand_autocomplete); brand_autocomplete.style.width = '95%'; brand_autocomplete.className = 'brand-autocomplete'; const brand_suggestion_box = document.createElement('div'); brand_autocomplete_wrapper.appendChild(brand_suggestion_box); brand_suggestion_box.className = 'brand-suggestion-box'; brand_suggestion_box.style.position = 'relative'; brand_suggestion_box.style.left = '0'; brand_suggestion_box.style.bottom = '0'; brand_suggestion_box.style.width = '95%'; brand_suggestion_box.style.border = '1px solid #ccc'; brand_suggestion_box.style.padding = '5px 10px'; brand_suggestion_box.style.zIndex = '3'; brand_suggestion_box.appendChild(document.createTextNode('Start typing for autocomplete')); brand_autocomplete.oninput = async function(){ if(this.value.length < 3){ return false; } const fd = new FormData; fd.append('action', 'GetWmBrandsAutocomplete'); fd.append('q', this.value); const resp = await fetch(endpoint, {method: "POST", body: fd}); const suggestions = await resp.json(); const suggestion_box = this.closest('.brand-autocomplete-wrapper').querySelector('.brand-suggestion-box'); suggestion_box.innerHTML = ''; if(!suggestions.length){ suggestion_box.appendChild(document.createTextNode('No results')); } for(let i = 0; i < suggestions.length; i++){ const suggestion_box_row = document.createElement('div'); suggestion_box.appendChild(suggestion_box_row); suggestion_box_row.style.padding = '0 0 5px 0'; const suggestion_row_link = document.createElement('a'); suggestion_box_row.appendChild(suggestion_row_link); suggestion_row_link.style.cursor = 'pointer'; suggestion_row_link.innerHTML = suggestions[i].name; suggestion_row_link.onclick = function(){ const autocomplete_field = this.closest('.brand-autocomplete-wrapper').querySelector('.brand-autocomplete'); autocomplete_field.value = this.innerHTML; autocomplete_field.setAttribute('value', this.innerHTML); const suggestion_box = this.closest('.brand-autocomplete-wrapper').querySelector('.brand-suggestion-box'); suggestion_box.innerHTML = ''; } } } } cm_brand.name = 'brand_input__' + in_stock_products.products[i].PARTID; cm_brand.style.width = '125px'; let capture_vendor_name = async function(unid, part_id){ var fd = new FormData(); fd.append('action', 'GetVendorName'); fd.append('unid', unid); fd.append('part_id', part_id); var resp = await fetch(endpoint, { method: "POST", body: fd }); var vendor_name = await resp.text(); let brand_field_arr = document.getElementsByName('brand_input__' + part_id) console.log(brand_field_arr); if(brand_field_arr != 'undefined' || brand_field_arr[0]) brand_field_arr[0].value = vendor_name; } //capture_vendor_name(unid, in_stock_products.products[i].PARTID); // THC let cm_thc_td = document.createElement('td'); tr.appendChild(cm_thc_td); let cm_thc = document.createElement('input'); cm_thc_td.appendChild(cm_thc); cm_thc.name = 'thc_input__' + in_stock_products.products[i].PARTID; cm_thc.style.width = '40px'; // CBD let cm_cbd_td = document.createElement('td'); tr.appendChild(cm_cbd_td); let cm_cbd = document.createElement('input'); cm_cbd_td.appendChild(cm_cbd); cm_cbd.name = 'cbd_input__' + in_stock_products.products[i].PARTID; cm_cbd.style.width = '40px'; // Strain const cm_strain_td = document.createElement('td'); tr.appendChild(cm_strain_td); const strain_wrapper = document.createElement('div'); cm_strain_td.appendChild(strain_wrapper); strain_wrapper.style.position = 'relative'; const cm_strain = document.createElement('input'); strain_wrapper.appendChild(cm_strain); if(in_stock_products.products[i].attributes['strain']) cm_strain.value = in_stock_products.products[i].attributes['strain'].value; cm_strain.onblur = function(){ setTimeout(function(){ const strain_autocomplete_panels = document.getElementsByClassName('strain-autocomplete-panel'); for(let i = 0; i < strain_autocomplete_panels.length; i++){ strain_autocomplete_panels[i].innerHTML = ''; strain_autocomplete_panels[i].style.display = 'none'; } }, 1500); } //const strain_resp = await fetch(endpoint + '?action=GetAdilasStrain&poduct=' + in_stock_products.products[i].PARTID, {method: 'GET'}); //const strain_name = await strain_resp.json(); //cm_strain.value = strain_name; cm_strain.style.width = '125px'; cm_strain.style.borderBottom = 'none'; cm_strain.style.borderBottomLeftRadius = '0'; cm_strain.style.borderBottomRightRadius = '0'; cm_strain.name = 'strain_input__' + in_stock_products.products[i].PARTID; cm_strain.oninput = async function(){ if(this.value.length > 2){ const resp = await fetch(endpoint + '?action=GetCpStrainsAutocomplete&q=' + this.value, {method: 'GET'}); const strain_lists = await resp.json(); const autocomplete_content = document.createElement('div'); if(!strain_lists.starts_with.length && !strain_lists.contains.length){ const no_strain_results = document.createElement('div'); autocomplete_content.appendChild(no_strain_results); no_strain_results.style.textAlign = 'center'; no_strain_results.appendChild(document.createTextNode('No Results')); } else{ const thiss = this; for(let i = 0; i < strain_lists.starts_with.length; i++){ const suggestion_wrapper = document.createElement('div'); autocomplete_content.appendChild(suggestion_wrapper); suggestion_wrapper.style.paddingBottom = '5px;'; const suggestion_accept_link = document.createElement('a'); suggestion_wrapper.appendChild(suggestion_accept_link); suggestion_accept_link.style.cursor = 'pointer'; suggestion_accept_link.style.textDecoration = 'none'; suggestion_accept_link.appendChild(document.createTextNode(strain_lists.starts_with[i])); suggestion_accept_link.onclick = function(){ thiss.value = this.innerText; setTimeout(function(){ const strain_autocomplete_panels = document.getElementsByClassName('strain-autocomplete-panel'); for(let i = 0; i < strain_autocomplete_panels.length; i++){ strain_autocomplete_panels[i].innerHTML = ''; strain_autocomplete_panels[i].style.display = 'none'; } }, 750); } } for(let i = 0; i < strain_lists.contains.length; i++){ const suggestion_wrapper = document.createElement('div'); autocomplete_content.appendChild(suggestion_wrapper); suggestion_wrapper.style.paddingBottom = '5px;'; const suggestion_accept_link = document.createElement('a'); suggestion_wrapper.appendChild(suggestion_accept_link); suggestion_accept_link.style.cursor = 'pointer'; suggestion_accept_link.style.textDecoration = 'none'; suggestion_accept_link.appendChild(document.createTextNode(strain_lists.contains[i])); suggestion_accept_link.onclick = function(){ thiss.value = this.innerText; setTimeout(function(){ const strain_autocomplete_panels = document.getElementsByClassName('strain-autocomplete-panel'); for(let i = 0; i < strain_autocomplete_panels.length; i++){ strain_autocomplete_panels[i].innerHTML = ''; strain_autocomplete_panels[i].style.display = 'none'; } }, 500); } } } this.parentNode.childNodes[1].innerHTML = ''; this.parentNode.childNodes[1].appendChild(autocomplete_content); this.parentNode.childNodes[1].style.display = 'block'; } } const strain_autocomplete_panel = document.createElement('div'); strain_wrapper.appendChild(strain_autocomplete_panel); strain_autocomplete_panel.style.display = 'none'; strain_autocomplete_panel.className = 'strain-autocomplete-panel'; strain_autocomplete_panel.style.zIndex = '3'; strain_autocomplete_panel.style.position = 'absolute'; strain_autocomplete_panel.style.maxHeight = '350px'; strain_autocomplete_panel.style.padding = '12px'; strain_autocomplete_panel.style.maxWidth = '175px'; strain_autocomplete_panel.style.minWidth = '125px'; strain_autocomplete_panel.style.overflowY = 'auto'; strain_autocomplete_panel.style.backgroundColor = '#fff'; strain_autocomplete_panel.style.borderLeft = '1px solid #ccc'; strain_autocomplete_panel.style.borderBottomLeftRadius = '10px'; strain_autocomplete_panel.style.borderRight = '1px solid #ccc'; strain_autocomplete_panel.style.borderBottomRightRadius = '10px'; strain_autocomplete_panel.style.borderBottom = '1px solid #ccc'; // Temp early dev vals remove //strain_autocomplete_panel.style.width = '150px'; //strain_autocomplete_panel.style.height = '20px'; // Individual save button let cm_save_row_td = document.createElement('td'); tr.appendChild(cm_save_row_td); let pricing_json = document.createElement('input'); cm_save_row_td.appendChild(pricing_json); pricing_json.type = 'hidden'; pricing_json.name = 'pricingjson_input__' + in_stock_products.products[i].PARTID; let is_on_sale = document.createElement('input'); cm_save_row_td.appendChild(is_on_sale); is_on_sale.type = 'hidden'; is_on_sale.name = 'isonsale_input__' + in_stock_products.products[i].PARTID; let is_on_sale_member = document.createElement('input'); cm_save_row_td.appendChild(is_on_sale_member); is_on_sale_member.type = 'hidden'; is_on_sale_member.name = 'isonsalemember_input__' + in_stock_products.products[i].PARTID; let uom = document.createElement('input'); cm_save_row_td.appendChild(uom); uom.type = 'hidden'; uom.name = 'uom_input__' + in_stock_products.products[i].PARTID; let pricing_model = document.createElement('input'); cm_save_row_td.appendChild(pricing_model); pricing_model.type = 'hidden'; pricing_model.name = 'pricingmodel_input__' + in_stock_products.products[i].PARTID; let cm_save_row_button = document.createElement('button'); cm_save_row_button.className = 'cm-save-button'; cm_save_row_td.appendChild(cm_save_row_button); cm_save_row_button.innerHTML = 'Save'; cm_save_row_button.dataset.part_id = in_stock_products.products[i].PARTID; cm_save_row_button.onclick = async function(){ const medrec_selector = document.getElementById('dispensary-type'); medrec_selector.style.border = 'none'; if('' == medrec_selector.value){ medrec_selector.style.border = '1px solid red'; window.scrollTo(0,0); return false; } const tds = this.closest('tr').getElementsByTagName('td'); for(let z = 0; z < tds.length; z++){ tds[z].style.border = 'none'; tds[z].style.backgroundColor = 'transparent'; } let clickformdata = new FormData(); clickformdata.append('action', 'SaveBulkItem'); clickformdata.append('unid', unid); clickformdata.append('name', document.getElementsByName('name_input__' + in_stock_products.products[i].PARTID)[0].value); clickformdata.append('category', document.getElementsByName('cat_select__' + in_stock_products.products[i].PARTID)[0].value); clickformdata.append('subcategory', document.getElementsByName('subcat_select__' + in_stock_products.products[i].PARTID)[0].value); clickformdata.append('description', document.getElementsByName('description_textarea__' + in_stock_products.products[i].PARTID)[0].value); clickformdata.append('species', document.getElementsByName('species_select__' + in_stock_products.products[i].PARTID)[0].value); clickformdata.append('brand', document.getElementsByName('brand_input__' + in_stock_products.products[i].PARTID)[0].value); let thc_pct = document.getElementsByName('thc_input__' + in_stock_products.products[i].PARTID)[0].value; clickformdata.append('thc', thc_pct != '' ? thc_pct : '-1'); let cbd_pct = document.getElementsByName('cbd_input__' + in_stock_products.products[i].PARTID)[0].value; clickformdata.append('cbd', cbd_pct != '' ? cbd_pct : '-1'); const strain_to_save = document.getElementsByName('strain_input__' + in_stock_products.products[i].PARTID)[0].value; clickformdata.append('strain', strain_to_save); let price_group = document.getElementsByName('pricing_select__' + in_stock_products.products[i].PARTID)[0].value; if(parseInt(price_group) == price_group){ clickformdata.append('price_group', document.getElementsByName('pricing_select__' + in_stock_products.products[i].PARTID)[0].value); } else if('set_price' == price_group || 'local' == price_group){ let valid_local_pricing = document.getElementsByName('pricingjson_input__' + in_stock_products.products[i].PARTID)[0].value; if(valid_local_pricing.indexOf('}') != -1){ clickformdata.append('pricing_json', valid_local_pricing); clickformdata.append('is_on_sale', is_on_sale.value); clickformdata.append('is_on_sale_member', is_on_sale_member.value); clickformdata.append('uom', uom.value); clickformdata.append('pricing_model', pricing_model.value); } else{ cm_pricing_tiers_td.style.backgroundColor = 'red'; return false; } } else{ cm_pricing_tiers_td.style.backgroundColor = 'red'; return false; } clickformdata.append('part_cat_id', in_stock_products.products[i].PARTCATEGORYID); clickformdata.append('tax_cat_id', in_stock_products.products[i].TAXCATEGORYID); clickformdata.append('pos_id', in_stock_products.products[i].PARTID); clickformdata.append('medrec', document.getElementById('dispensary-type').value); clickformdata.append('vendor_payee_id', in_stock_products.products[i].VENDORPAYEEID); clickformdata.append('uom_id', in_stock_products.products[i].UOMID); clickformdata.append('image_type', document.getElementsByName('image_select__' + in_stock_products.products[i].PARTID)[0].value); let product_form_resp = await fetch(endpoint, {method: 'POST', body: clickformdata}); let product_form_status = await product_form_resp.json(); if(product_form_status == 'success'){ if(document.getElementsByName('image_select__' + in_stock_products.products[i].PARTID)[0].value == 'upload'){ document.getElementById('image-form-' + in_stock_products.products[i].PARTID).onsubmit(); } //document.getElementById('row_' + in_stock_products.products[i].PARTID).getElementsByClassName('active-checkbox')[0].checked = true; document.getElementById('row_' + in_stock_products.products[i].PARTID).style.backgroundColor = '#add6ad'; // get the image, change the image src. get the link, set direction to deactivate let status_icon = document.querySelector('img[data-part_id="' + in_stock_products.products[i].PARTID + '"]'); status_icon.src = 'https://menustore.canname.nu/images/set-up-or-set-up-not-visible.png'; status_icon.style.opacity = '100%'; let status_icon_link = document.querySelector('a[data-part_id="' + in_stock_products.products[i].PARTID + '"]'); status_icon_link.style.cursor = 'pointer'; status_icon_link.dataset.direction = 'deactivate'; status_icon_link.title = "Item connected\nActive\nClick to deactivate"; } else{ document.getElementById('row_' + in_stock_products.products[i].PARTID).style.backgroundColor = 'red'; } } } await thiss.renderExistingMenuValues(unid, menu_items, api_url); adilas_cats.sort(); for(let c = 0; c < adilas_cats.length; c++){ let adilas_cat_opt = document.createElement('option'); adilas_cat_opt.value = adilas_cats[c]; adilas_cat_opt.appendChild(document.createTextNode(adilas_cats[c])); adilas_cat_selector.appendChild(adilas_cat_opt); } adilas_cat_selector.onchange = function(){ let rows = document.getElementsByClassName('product-row'); for(let r = 0; r < rows.length; r++){ if(this.value == 'all' || this.value == rows[r].getElementsByClassName('adilas-cat-td')[0].textContent){ rows[r].style.display = 'table-row'; } else{ rows[r].style.display = 'none'; } } } onboarding_content.appendChild(product_table); let save_all_button = document.createElement('button'); onboarding_content.appendChild(save_all_button); save_all_button.style.margin = '20px auto'; save_all_button.appendChild(document.createTextNode('Save All')); save_all_button.onclick = function(){ let save_buttons = document.getElementsByClassName('cm-save-button'); for(let b = 0; b < save_buttons.length; b++){ save_buttons[b].onclick(); } } const publish_to_leafly = document.createElement('button'); onboarding_content.appendChild(publish_to_leafly); publish_to_leafly.appendChild(document.createTextNode('Publish to Leafly')); publish_to_leafly.onclick = async function(){ const api_resp = await fetch(endpoint + '?action=TestMenu', {method: 'GET'}); const result = await api_resp.json(); if(result){ alert('Published'); } else{ alert('Failed to publish'); } } // The onchange triggers let cat_selects = document.getElementsByClassName('cat-select'); for(let s = 0; s < cat_selects.length; s++){ cat_selects[s].onchange(); } const miFormData = new FormData(); miFormData.append('action', 'GetMenuItems'); miFormData.append('unid', unid); miFormData.append('menu_items', menu_items); update_cp_spinner_text('Getting Menu Values'); //show_cp_spinner('Getting Menu Values'); const items_list_resp = await fetch(endpoint, {method: 'POST', body: miFormData}); const items_list = await items_list_resp.json(); if(!items_list.length){ hide_cp_spinner(); return; } const fields_bg_color = '#859f90'; const fields_color = '#fff'; const type_status = document.getElementById('dispensary-type'); for(let il = 0; il < items_list.length; il++){ let status_icon = document.querySelector('img[data-part_id="' + items_list[il].product_pos_id + '"]'); if(!status_icon){ continue; } //alert(status_icon.src); status_icon.src = 'https://menustore.canname.nu/images/set-up-or-set-up-not-visible.png'; let status_icon_link = document.querySelector('a[data-part_id="' + items_list[il].product_pos_id + '"]'); status_icon_link.style.cursor = 'pointer'; if(items_list[il].is_active == '0'){ status_icon.style.opacity = '50%'; status_icon_link.title = "Item connected\nInactive\nClick to activate"; status_icon_link.dataset.direction = 'activate'; } else{ status_icon_link.title = "Item connected\nActive\nClick to deactivate"; status_icon_link.dataset.direction = 'deactivate'; } /*if(items_list[il].is_active == '1'){ document.querySelector('input[data-part_id="' + items_list[il].product_pos_id + '"]').checked = true; if('' == type_status.value){ type_status.value = items_list[il].medrec; } }*/ const item_name_field = document.getElementsByName('name_input__' + items_list[il].product_pos_id)[0]; if(items_list[il].name.length){ item_name_field.style.backgroundColor = fields_bg_color; item_name_field.style.color = fields_color; item_name_field.value = items_list[il].name; } const category_id_field = document.getElementsByName('cat_select__' + items_list[il].product_pos_id)[0]; if(items_list[il].category_id){ category_id_field.style.backgroundColor = fields_bg_color; category_id_field.style.color = fields_color; category_id_field.value = items_list[il].category_id; await category_id_field.onchange(); } const subcategory_id_field = document.getElementsByName('subcat_select__' + items_list[il].product_pos_id)[0]; if(items_list[il].subcategory_id){ subcategory_id_field.style.backgroundColor = fields_bg_color; subcategory_id_field.style.color = fields_color; subcategory_id_field.value = items_list[il].subcategory_id; } const description_field = document.getElementsByName('description_textarea__' + items_list[il].product_pos_id)[0]; if(1){ description_field.style.backgroundColor = fields_bg_color; description_field.style.color = fields_color; description_field.value = items_list[il].description; } const species_field = document.getElementsByName('species_select__' + items_list[il].product_pos_id)[0]; species_field.style.backgroundColor = fields_bg_color; species_field.style.color = fields_color; species_field.value = items_list[il].species; const brand_field = document.getElementsByName('brand_input__' + items_list[il].product_pos_id)[0]; brand_field.style.backgroundColor = fields_bg_color; brand_field.style.color = fields_color; brand_field.value = items_list[il].brand; const thc_field = document.getElementsByName('thc_input__' + items_list[il].product_pos_id)[0]; thc_field.style.backgroundColor = fields_bg_color; thc_field.style.color = fields_color thc_field.value = items_list[il].thc_pct != '-1' ? items_list[il].thc_pct : ''; const cbd_field = document.getElementsByName('cbd_input__' + items_list[il].product_pos_id)[0]; cbd_field.style.backgroundColor = fields_bg_color; cbd_field.style.color = fields_color; cbd_field.value = items_list[il].cbd_pct != '-1' ? items_list[il].cbd_pct : ''; const pricing_field = document.getElementsByName('pricing_select__' + items_list[il].product_pos_id)[0]; pricing_field.style.backgroundColor = fields_bg_color; pricing_field.style.color = fields_color; if(items_list[il].pricing_json.indexOf('group') != -1){ pricing_field.value = items_list[il].pricing_json.replace('group:', ''); pricing_field.dataset.originalValue = pricing_field.value; pricing_field.title = pricing_field.selectedOptions[0].text } else{ let local_opt = document.createElement('option'); local_opt.value = 'local'; local_opt.appendChild(document.createTextNode('Unique Pricing')); pricing_field.prepend(local_opt); pricing_field.value = 'local'; pricing_field.dataset.originalValue = 'local'; let pricing = '{}'; try{ pricing = JSON.parse(items_list[il].pricing_json); } catch (e) { pricing = '{}'; } let pricing_tooltip = ''; if( typeof pricing.single_quantity_prices != 'undefined'){ for(let z = 0; z < pricing.single_quantity_prices.length; z++){ pricing_tooltip += pricing.single_quantity_prices[z].size + ' ' + pricing.uom + ' $' + pricing.single_quantity_prices[z].price + "\n"; } } pricing_field.title = pricing_tooltip; let local_pricing = document.getElementsByName('pricingjson_input__' + items_list[il].product_pos_id)[0]; local_pricing.value = items_list[il].pricing_json; let local_is_on_sale = document.getElementsByName('isonsale_input__' + items_list[il].product_pos_id)[0]; local_is_on_sale.value = items_list[il].is_on_sale; let local_is_on_sale_member = document.getElementsByName('isonsalemember_input__' + items_list[il].product_pos_id)[0]; local_is_on_sale_member.value = items_list[il].is_on_sale_member; let local_uom = document.getElementsByName('uom_input__' + items_list[il].product_pos_id)[0]; local_uom.value = items_list[il].uom; let local_pricing_model = document.getElementsByName('pricingmodel_input__' + items_list[il].product_pos_id)[0]; local_pricing_model.value = items_list[il].use_member_pricing; } } hide_cp_spinner(); } }function renderPriceCreator(vendor_part_id, unid, save_group){ const local_pricing_wrapper = document.createElement('div'); local_pricing_wrapper.id = 'local-pricing-wrapper'; var uom_wrapper = document.createElement('div'); uom_wrapper.className = 'cp-form-row'; uom_wrapper.style.marginBottom = '15px'; uom_wrapper.appendChild(document.createTextNode('Unit of Measurement')); uom_wrapper.appendChild(document.createElement('br')); var uom_select = document.createElement('select'); uom_select.style.padding = '10px'; uom_select.id = 'cp_uom_select'; uom_select.name = 'uom'; uom_select.style.width = '100%'; var uom_select_option = document.createElement('option'); uom_select_option.value = ''; uom_select_option.innerHTML = 'Select'; uom_select.appendChild(uom_select_option); var mg_option = document.createElement('option'); mg_option.value = 'mg'; mg_option.innerHTML = 'Milligrams (mg)'; uom_select.appendChild(mg_option); var gr_option = document.createElement('option'); gr_option.value = 'g'; gr_option.innerHTML = 'Grams (g)'; uom_select.appendChild(gr_option); var ea_option = document.createElement('option'); ea_option.value = 'ea'; ea_option.innerHTML = 'Each (ea)'; uom_select.appendChild(ea_option); uom_select.onchange = function(){ const price_model_select = document.getElementById('CpSelectPricingModel'); if(this.value != ''){ price_model_select.disabled = false; } else{ price_model_select.value = ''; price_model_select.disabled = true; } } uom_wrapper.appendChild(uom_select); local_pricing_wrapper.appendChild(uom_wrapper); var price_select_pricing_mode_wrapper = document.createElement('div'); price_select_pricing_mode_wrapper.className = 'cp-form-row'; price_select_pricing_mode_wrapper.appendChild(document.createTextNode('Pricing Type (Std/Member/Member-Nonmember)')); price_select_pricing_mode_wrapper.appendChild(document.createElement('br')); var pricing_mode_select = document.createElement('select'); pricing_mode_select.style.padding = '10px'; pricing_mode_select.onchange = function(){ const deletes = document.getElementsByClassName('cp-delete_price'); for(var d = 0; d < deletes.length; d++){ deletes[d].onclick(); } setPricingForm(this.value); }; pricing_mode_select.style.width = "100%"; pricing_mode_select.id = 'CpSelectPricingModel'; pricing_mode_select.disabled = true; pricing_mode_select.name = 'CpSelectPricingModel'; var none_option = document.createElement('option'); none_option.value = ''; none_option.innerHTML = 'Select'; pricing_mode_select.appendChild(none_option); var nonmember_only_option = document.createElement('option'); nonmember_only_option.value = 'single'; nonmember_only_option.innerHTML = 'Standard Pricing'; pricing_mode_select.appendChild(nonmember_only_option); var member_only_option = document.createElement('option'); member_only_option.value = 'member'; member_only_option.innerHTML = 'Member'; pricing_mode_select.appendChild(member_only_option); var both_option = document.createElement('option'); both_option.value = 'both'; both_option.innerHTML = 'Member & Non-member'; pricing_mode_select.appendChild(both_option); price_select_pricing_mode_wrapper.appendChild(pricing_mode_select); local_pricing_wrapper.appendChild(price_select_pricing_mode_wrapper); var add_price_wrapper = document.createElement('div'); add_price_wrapper.className = 'cp-form-row'; add_price_wrapper.id = 'add_price_button_wrapper'; add_price_wrapper.style.padding = '20px'; add_price_wrapper.style.display = 'none'; var add_price_button = document.createElement('button'); add_price_button.id = 'cp_add_price'; add_price_button.className = 'cp-button-std'; add_price_button.innerHTML = 'Add Weight : Price Tier'; add_price_wrapper.appendChild(add_price_button); local_pricing_wrapper.appendChild(add_price_wrapper); add_price_button.onclick = function(e){ e.preventDefault(); AddNewPrice(); } var single_pricing_wrapper = document.createElement('div'); single_pricing_wrapper.style.display = 'none'; single_pricing_wrapper.className = 'single-pricing-wrapper pricing-wrapper'; single_pricing_wrapper.appendChild(document.createTextNode('Standard Pricing')); single_pricing_wrapper.appendChild(document.createElement('br')); var single_on_sale = document.createElement('input'); single_on_sale.type = 'checkbox'; single_on_sale.name = 'single_on_sale'; single_on_sale.value = '1'; single_on_sale.id = 'cp_single_on_sale'; single_pricing_wrapper.appendChild(single_on_sale); single_pricing_wrapper.appendChild(document.createTextNode(' Item is on sale')); local_pricing_wrapper.appendChild(single_pricing_wrapper); var member_pricing_wrapper = document.createElement('div'); member_pricing_wrapper.style.display = 'none'; member_pricing_wrapper.className = 'member-pricing-wrapper pricing-wrapper'; member_pricing_wrapper.appendChild(document.createTextNode('Member Pricing')); member_pricing_wrapper.appendChild(document.createElement('br')); var member_on_sale = document.createElement('input'); member_on_sale.type = 'checkbox'; member_on_sale.id = 'cp_member_on_sale'; member_on_sale.name = 'member_on_sale'; member_on_sale.value = '1'; member_pricing_wrapper.appendChild(member_on_sale); member_pricing_wrapper.appendChild(document.createTextNode(' Item is on sale')); local_pricing_wrapper.appendChild(member_pricing_wrapper); var nonmember_pricing_wrapper = document.createElement('div'); nonmember_pricing_wrapper.style.display = 'none'; nonmember_pricing_wrapper.className = 'nonmember-pricing-wrapper pricing-wrapper'; nonmember_pricing_wrapper.appendChild(document.createTextNode('Non-member Pricing')); nonmember_pricing_wrapper.appendChild(document.createElement('br')); var nonmember_on_sale = document.createElement('input'); nonmember_on_sale.type = 'checkbox'; nonmember_on_sale.id = 'cp_nonmember_on_sale'; nonmember_on_sale.name = 'nonmember_on_sale'; nonmember_on_sale.value = '1'; nonmember_pricing_wrapper.appendChild(nonmember_on_sale); nonmember_pricing_wrapper.appendChild(document.createTextNode(' Item is on sale')); local_pricing_wrapper.appendChild(nonmember_pricing_wrapper); // Price json fields var hidden_pricing_json = document.createElement('input'); hidden_pricing_json.type = 'hidden'; hidden_pricing_json.name = 'pricing_json'; hidden_pricing_json.id = 'hidden_pricing_json'; local_pricing_wrapper.appendChild(hidden_pricing_json); var hidden_pos_id = document.createElement('input'); hidden_pos_id.type = 'hidden'; hidden_pos_id.value = vendor_part_id; hidden_pos_id.name = 'pos_id'; local_pricing_wrapper.appendChild(hidden_pos_id); var save_price_wrapper = document.createElement('div'); //save_price_wrapper.style.display = 'none'; save_price_wrapper.id = 'SavePriceWrapper'; save_price_wrapper.style.textAlign = 'center'; save_price_wrapper.style.margin = '20px 0px'; save_price_wrapper.style.width = '100%'; save_price_wrapper.style.padding = '20px 0 0 0'; var save_price_link = document.createElement('a'); save_price_link.className = 'cm-link-button'; save_price_link.style.cursor = 'pointer'; save_price_link.onclick = function(e){ e.preventDefault(); var name = prompt('Name your pricing group'); if(name){ var prices = serializePricing(); SavePricingPreset(name, prices, unid, vendor_part_id); } } save_price_link.appendChild(document.createTextNode('Save Pricing Group')); if(save_group){ save_price_wrapper.appendChild(save_price_link); } else{ let save_local_price_link = document.createElement('a'); save_local_price_link.className = 'cm-link-button'; save_local_price_link.style.cursor = 'pointer'; save_local_price_link.appendChild(document.createTextNode('OK')); save_price_wrapper.appendChild(save_local_price_link); save_local_price_link.onclick = function(){ document.getElementsByName('pricingjson_input__' + vendor_part_id)[0].value = JSON.stringify(serializePricing()) let price_model_value = document.getElementById('CpSelectPricingModel').value; let is_on_sale_value = 0; let is_on_sale_member_value = 0; switch(price_model_value){ case 'single': is_on_sale_value = document.getElementById('cp_single_on_sale').checked ? 1 : 0; break; case 'member': is_on_sale_member_value = document.getElementById('cp_member_on_sale').checked ? 1 : 0; break; case 'both': is_on_sale_member_value = document.getElementById('cp_member_on_sale').checked ? 1 : 0; is_on_sale_value = document.getElementById('cp_nonmember_on_sale').checked ? 1 : 0; break; default: is_on_sale_member_value = 0; is_on_sale_value = 0; } document.getElementsByName('isonsale_input__' + vendor_part_id)[0].value = is_on_sale_value; document.getElementsByName('isonsalemember_input__' + vendor_part_id)[0].value = is_on_sale_member_value; document.getElementsByName('uom_input__' + vendor_part_id)[0].value = document.getElementById('cp_uom_select').value; document.getElementsByName('pricingmodel_input__' + vendor_part_id)[0].value = price_model_value; document.getElementsByClassName('cp-dialog-outer-wrapper')[0].remove(); } } local_pricing_wrapper.appendChild(save_price_wrapper); return local_pricing_wrapper; } function serializePricing(){ var price_model_value = document.getElementById('CpSelectPricingModel').value; var formvar = {}; formvar.uom = document.getElementById('cp_uom_select').value; switch(price_model_value){ case 'single': var single_prices = document.getElementsByClassName('single-price'); var single_price_array = []; for(var i = 0; i < single_prices.length; i++){ var single_pricing = { size: document.getElementById('single_pricing_quantity_' + i).value, price: document.getElementById('single_pricing_price_' + i).value }; single_price_array.push(single_pricing); formvar.single_quantity_prices = single_price_array; } break; case 'member': var member_prices = document.getElementsByClassName('member-price'); var member_price_array = []; for(var i = 0; i < member_prices.length; i++){ var member_pricing = { size: document.getElementById('member_pricing_quantity_' + i).value, price: document.getElementById('member_pricing_price_' + i).value }; member_price_array.push(member_pricing); formvar.member_quantity_prices = member_price_array; } break; case 'both': var member_prices = document.getElementsByClassName('member-price'); var member_price_array = []; var nonmember_price_array = []; for(var i = 0; i < member_prices.length; i++){ var member_pricing = { size: document.getElementById('member_pricing_quantity_' + i).value, price: document.getElementById('member_pricing_price_' + i).value }; member_price_array.push(member_pricing); var nonmember_pricing = { size: document.getElementById('non_member_pricing_quantity_' + i).value, price: document.getElementById('non_member_pricing_price_' + i).value }; //member_price_array.push(member_pricing); formvar.member_quantity_prices = member_price_array; nonmember_price_array.push(nonmember_pricing); formvar.nonmember_quantity_prices = nonmember_price_array; } break; } return formvar; } async function SavePricingPreset(name, pricing_data, unid, vendor_part_id){ var data = JSON.stringify(pricing_data); const single_on_sale = document.getElementById('cp_single_on_sale'); const nonmember_on_sale = document.getElementById('cp_nonmember_on_sale'); const member_on_sale = document.getElementById('cp_member_on_sale'); let is_on_sale = 0; let is_on_sale_member = 0; if(single_on_sale && single_on_sale.checked){ is_on_sale = 1; } else if(nonmember_on_sale){ // means we have both member and non is_on_sale = nonmember_on_sale.checked ? 1 : 0; is_on_sale_member = member_on_sale.checked ? 1 : 0; } else if(member_on_sale){ is_on_sale_member = member_on_sale.checked ? 1 : 0; } var fd = new FormData(); fd.append('action', 'SavePricingPreset'); fd.append('name', name); fd.append('pricing_data', data); fd.append('is_on_sale', is_on_sale); fd.append('is_on_sale_member', is_on_sale_member); ///// TODO put the correct cookie name in a constant somewhere fd.append('unid', unid); const resp = await fetch('https://menustore.canname.nu/api.php', {method: 'POST', body: fd}); if(resp){ cpSuccess('Price Group Saved'); var id = await resp.json(); const selects = document.getElementsByClassName('cm-pricing-select'); for(let i = 0; i < selects.length; i++){ let opt = document.createElement('option'); opt.value = id; opt.appendChild(document.createTextNode(name)); selects[i].appendChild(opt); } let opt = document.createElement('option'); opt.value = id; opt.appendChild(document.createTextNode(name)); document.getElementById('pricing-groups-edit-select').appendChild(opt); document.getElementsByName('pricing_select__' + vendor_part_id)[0].value = id; } } function setPricingForm(use_member_pricing){ document.getElementById('add_price_button_wrapper').style.display = 'block'; document.getElementById('SavePriceWrapper').style.display = 'block'; if('both' == use_member_pricing){ document.getElementsByClassName('member-pricing-wrapper')[0].style.display = 'block'; document.getElementsByClassName('nonmember-pricing-wrapper')[0].style.display = 'block'; document.getElementsByClassName('single-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_single_on_sale').checked = false; } else if('member' == use_member_pricing){ document.getElementsByClassName('member-pricing-wrapper')[0].style.display = 'block'; document.getElementsByClassName('nonmember-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_nonmember_on_sale').checked = false; document.getElementsByClassName('single-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_single_on_sale').checked = false; } else{ document.getElementsByClassName('member-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_member_on_sale').checked = false; document.getElementsByClassName('nonmember-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_nonmember_on_sale').checked = false; document.getElementsByClassName('single-pricing-wrapper')[0].style.display = 'block'; } } function AddNewPrice(price_data){ var using_member_pricing = document.getElementById('CpSelectPricingModel').value; var uom = document.getElementById('cp_uom_select').value; var quantity_field_width = '60px'; var price_field_width = '80px'; if(using_member_pricing == 'both'){ var member_price_row = document.createElement('div'); var member_prices = document.getElementsByClassName('member-price'); var member_price_counter = member_prices.length; member_price_row.id = 'member_pricing_' + member_price_counter; member_price_row.className = 'member-price price-row'; var member_price_quantity_field = document.createElement('input'); member_price_quantity_field.id = 'member_pricing_quantity_' + member_price_counter; member_price_quantity_field.style.width = quantity_field_width; if(typeof price_data != 'undefined' && typeof price_data.member != 'undefined' && typeof price_data.member.quantity != 'undefined'){ member_price_quantity_field.value = price_data.member.quantity; } member_price_row.appendChild(member_price_quantity_field); member_price_row.appendChild(document.createTextNode(' ' + uom + ' $ ')); var member_price_price_field = document.createElement('input'); member_price_price_field.id = 'member_pricing_price_' + member_price_counter; member_price_price_field.style.width = price_field_width; if(typeof price_data != 'undefined' && typeof price_data.member != 'undefined' && typeof price_data.member.price != 'undefined'){ member_price_price_field.value = price_data.member.price; } member_price_row.appendChild(member_price_price_field); member_price_row.appendChild(document.createTextNode(' ')); var member_price_delete = document.createElement('a'); member_price_delete.id = 'member_price_delete_' + member_price_counter; member_price_delete.href = '#DeletePrice'; member_price_delete.style.color = 'red'; member_price_delete.style.marginLeft = '15px'; member_price_delete.style.border = '1px solid red'; member_price_delete.style.padding = '0px 3px'; member_price_delete.style.fontWeight = 'bold'; member_price_delete.className = 'cp-delete_price'; member_price_delete.innerHTML = ' X'; member_price_delete.dataset.counter = member_price_counter; member_price_delete.style.textDecoration = 'none'; member_price_delete.onclick = function(){ var this_price = document.getElementById('member_pricing_' + this.dataset.counter); var member_price = document.getElementById('non_member_pricing_' + this.dataset.counter); this_price.remove(); member_price.remove(); } member_price_row.appendChild(member_price_delete); document.getElementsByClassName('member-pricing-wrapper')[0].appendChild(member_price_row); var non_member_price_row = document.createElement('div'); var non_member_prices = document.getElementsByClassName('nonmember-price'); var non_member_price_counter = non_member_prices.length; non_member_price_row.id = 'non_member_pricing_' + non_member_price_counter; non_member_price_row.className = 'nonmember-price price-row'; var non_member_price_quantity_field = document.createElement('input'); non_member_price_quantity_field.id = 'non_member_pricing_quantity_' + non_member_price_counter; non_member_price_quantity_field.style.width = quantity_field_width; if(typeof price_data != 'undefined' && typeof price_data.nonmember != 'undefined' && typeof price_data.nonmember.quantity != 'undefined'){ non_member_price_quantity_field.value = price_data.nonmember.quantity; } non_member_price_row.appendChild(non_member_price_quantity_field); non_member_price_row.appendChild(document.createTextNode(' ' + uom + ' $ ')); var non_member_price_price_field = document.createElement('input'); non_member_price_price_field.id = 'non_member_pricing_price_' + non_member_price_counter; non_member_price_price_field.style.width = price_field_width; if(typeof price_data != 'undefined' && typeof price_data.nonmember != 'undefined' && typeof price_data.nonmember.price != 'undefined'){ non_member_price_price_field.value = price_data.nonmember.price; } non_member_price_row.appendChild(non_member_price_price_field); non_member_price_row.appendChild(document.createTextNode(' ')); var non_member_price_delete = document.createElement('a'); non_member_price_delete.id = 'non_member_price_delete_' + non_member_price_counter; non_member_price_delete.href = '#DeletePrice'; non_member_price_delete.style.color = 'red'; non_member_price_delete.style.marginLeft = '15px'; non_member_price_delete.style.border = '1px solid red'; non_member_price_delete.style.padding = '0px 3px'; non_member_price_delete.style.fontWeight = 'bold'; non_member_price_delete.className = 'cp-delete_price'; non_member_price_delete.innerHTML = ' X'; non_member_price_delete.dataset.counter = non_member_price_counter; non_member_price_delete.style.textDecoration = 'none'; non_member_price_delete.onclick = function(){ var this_price = document.getElementById('non_member_pricing_' + this.dataset.counter); var member_price = document.getElementById('member_pricing_' + this.dataset.counter); this_price.remove(); member_price.remove(); } non_member_price_row.appendChild(non_member_price_delete); document.getElementsByClassName('nonmember-pricing-wrapper')[0].appendChild(non_member_price_row); } else if(using_member_pricing == 'member'){ var member_price_row = document.createElement('div'); var member_prices = document.getElementsByClassName('member-price'); var member_price_counter = member_prices.length; member_price_row.id = 'member_pricing_' + member_price_counter; member_price_row.className = 'member-price price-row'; var member_price_quantity_field = document.createElement('input'); member_price_quantity_field.id = 'member_pricing_quantity_' + member_price_counter; member_price_quantity_field.style.width = quantity_field_width; if(typeof price_data != 'undefined' && typeof price_data.member != 'undefined' && typeof price_data.member.quantity != 'undefined'){ member_price_quantity_field.value = price_data.member.quantity; } member_price_row.appendChild(member_price_quantity_field); member_price_row.appendChild(document.createTextNode(' ' + uom + ' $ ')); var member_price_price_field = document.createElement('input'); member_price_price_field.id = 'member_pricing_price_' + member_price_counter; member_price_price_field.style.width = price_field_width; if(typeof price_data != 'undefined' && typeof price_data.member != 'undefined' && typeof price_data.member.price != 'undefined'){ member_price_price_field.value = price_data.member.price; } member_price_row.appendChild(member_price_price_field); member_price_row.appendChild(document.createTextNode(' ')); var member_price_delete = document.createElement('a'); member_price_delete.id = 'single_price_delete_' + member_price_counter; member_price_delete.href = '#DeletePrice'; member_price_delete.style.color = 'red'; member_price_delete.style.marginLeft = '15px'; member_price_delete.style.border = '1px solid red'; member_price_delete.style.padding = '0px 3px'; member_price_delete.style.fontWeight = 'bold'; member_price_delete.className = 'cp-delete_price'; member_price_delete.innerHTML = ' X'; member_price_delete.dataset.counter = member_price_counter; member_price_delete.style.textDecoration = 'none'; member_price_delete.onclick = function(){ var this_price = document.getElementById('member_pricing_' + this.dataset.counter); this_price.remove(); } member_price_row.appendChild(member_price_delete); document.getElementsByClassName('member-pricing-wrapper')[0].appendChild(member_price_row); } else{ var single_price_row = document.createElement('div'); var single_prices = document.getElementsByClassName('single-price'); var single_price_counter = single_prices.length; single_price_row.id = 'single_pricing_' + single_price_counter; single_price_row.className = 'single-price price-row'; var single_price_quantity_field = document.createElement('input'); single_price_quantity_field.id = 'single_pricing_quantity_' + single_price_counter; single_price_quantity_field.style.width = quantity_field_width; if(typeof price_data != 'undefined' && typeof price_data.single != 'undefined' && typeof price_data.single.quantity != 'undefined'){ single_price_quantity_field.value = price_data.single.quantity; } single_price_row.appendChild(single_price_quantity_field); single_price_row.appendChild(document.createTextNode(' ' + uom + ' $ ')); var single_price_price_field = document.createElement('input'); single_price_price_field.id = 'single_pricing_price_' + single_price_counter; single_price_price_field.style.width = price_field_width; if(typeof price_data != 'undefined' && typeof price_data.single != 'undefined' && typeof price_data.single.price != 'undefined'){ single_price_price_field.value = price_data.single.price; } single_price_row.appendChild(single_price_price_field); single_price_row.appendChild(document.createTextNode(' ')); var single_price_delete = document.createElement('a'); single_price_delete.id = 'single_price_delete_' + single_price_counter; single_price_delete.href = '#DeletePrice'; single_price_delete.style.color = 'red'; single_price_delete.style.marginLeft = '15px'; single_price_delete.style.border = '1px solid red'; single_price_delete.style.padding = '0px 3px'; single_price_delete.style.fontWeight = 'bold'; single_price_delete.className = 'cp-delete_price'; single_price_delete.innerHTML = ' X'; single_price_delete.dataset.counter = single_price_counter; single_price_delete.style.textDecoration = 'none'; single_price_delete.onclick = function(){ var this_price = document.getElementById('single_pricing_' + this.dataset.counter); this_price.remove(); } single_price_row.appendChild(single_price_delete); document.getElementsByClassName('single-pricing-wrapper')[0].appendChild(single_price_row); } } function setPricingPresetForm(use_member_pricing){ document.getElementById('add_price_button_wrapper').style.display = 'block'; if('both' == use_member_pricing){ document.getElementsByClassName('member-pricing-wrapper')[0].style.display = 'block'; document.getElementsByClassName('nonmember-pricing-wrapper')[0].style.display = 'block'; document.getElementsByClassName('single-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_preset_single_on_sale').checked = false; } else if('member' == use_member_pricing){ document.getElementsByClassName('member-pricing-wrapper')[0].style.display = 'block'; document.getElementsByClassName('nonmember-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_preset_nonmember_on_sale').checked = false; document.getElementsByClassName('single-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_preset_single_on_sale').checked = false; } else{ document.getElementsByClassName('member-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_preset_member_on_sale').checked = false; document.getElementsByClassName('nonmember-pricing-wrapper')[0].style.display = 'none'; document.getElementById('cp_preset_nonmember_on_sale').checked = false; document.getElementsByClassName('single-pricing-wrapper')[0].style.display = 'block'; } } function AddNewPresetPrice(price_data, uom){ var using_member_pricing = document.getElementById('CpSelectPricingPresetModel').value; var quantity_field_width = '60px'; var price_field_width = '60px'; if(using_member_pricing == 'both'){ var member_price_row = document.createElement('div'); var member_prices = document.getElementsByClassName('member-price'); var member_price_counter = member_prices.length; member_price_row.id = 'member_pricing_' + member_price_counter; member_price_row.className = 'member-price'; var member_price_quantity_field = document.createElement('input'); member_price_quantity_field.id = 'member_pricing_quantity_' + member_price_counter; member_price_quantity_field.style.width = quantity_field_width; if(typeof price_data != 'undefined' && price_data !== null && typeof price_data.member != 'undefined' && typeof price_data.member.quantity != 'undefined'){ member_price_quantity_field.value = price_data.member.quantity; } member_price_row.appendChild(member_price_quantity_field); member_price_row.appendChild(document.createTextNode(' ' + uom + ' $ ')); var member_price_price_field = document.createElement('input'); member_price_price_field.id = 'member_pricing_price_' + member_price_counter; member_price_price_field.style.width = price_field_width; if(typeof price_data != 'undefined' && null !== price_data && typeof price_data.member != 'undefined' && typeof price_data.member.price != 'undefined'){ member_price_price_field.value = price_data.member.price; } member_price_row.appendChild(member_price_price_field); member_price_row.appendChild(document.createTextNode(' ')); var member_price_delete = document.createElement('a'); member_price_delete.id = 'member_price_delete_' + member_price_counter; member_price_delete.href = '#DeletePrice'; member_price_delete.style.color = 'red'; member_price_delete.style.marginLeft = '15px'; member_price_delete.style.border = '1px solid red'; member_price_delete.style.padding = '0px 3px'; member_price_delete.style.fontWeight = 'bold'; member_price_delete.className = 'cp-delete_price'; member_price_delete.innerHTML = ' X'; member_price_delete.dataset.counter = member_price_counter; member_price_delete.style.textDecoration = 'none'; member_price_delete.onclick = function(){ var this_price = document.getElementById('member_pricing_' + this.dataset.counter); var member_price = document.getElementById('non_member_pricing_' + this.dataset.counter); this_price.remove(); member_price.remove(); } member_price_row.appendChild(member_price_delete); document.getElementsByClassName('member-pricing-wrapper')[0].appendChild(member_price_row); var non_member_price_row = document.createElement('div'); var non_member_prices = document.getElementsByClassName('nonmember-price'); var non_member_price_counter = non_member_prices.length; non_member_price_row.id = 'non_member_pricing_' + non_member_price_counter; non_member_price_row.className = 'nonmember-price'; var non_member_price_quantity_field = document.createElement('input'); non_member_price_quantity_field.id = 'non_member_pricing_quantity_' + non_member_price_counter; non_member_price_quantity_field.style.width = quantity_field_width; if(typeof price_data != 'undefined' && null !== price_data && typeof price_data.nonmember != 'undefined' && typeof price_data.nonmember.quantity != 'undefined'){ non_member_price_quantity_field.value = price_data.nonmember.quantity; } non_member_price_row.appendChild(non_member_price_quantity_field); non_member_price_row.appendChild(document.createTextNode(' ' + uom + ' $ ')); var non_member_price_price_field = document.createElement('input'); non_member_price_price_field.id = 'non_member_pricing_price_' + non_member_price_counter; non_member_price_price_field.style.width = price_field_width; if(typeof price_data != 'undefined' && null !== price_data && typeof price_data.nonmember != 'undefined' && typeof price_data.nonmember.price != 'undefined'){ non_member_price_price_field.value = price_data.nonmember.price; } non_member_price_row.appendChild(non_member_price_price_field); non_member_price_row.appendChild(document.createTextNode(' ')); var non_member_price_delete = document.createElement('a'); non_member_price_delete.id = 'non_member_price_delete_' + non_member_price_counter; non_member_price_delete.href = '#DeletePrice'; non_member_price_delete.style.color = 'red'; non_member_price_delete.style.marginLeft = '15px'; non_member_price_delete.style.border = '1px solid red'; non_member_price_delete.style.padding = '0px 3px'; non_member_price_delete.style.fontWeight = 'bold'; non_member_price_delete.className = 'cp-delete_price'; non_member_price_delete.innerHTML = ' X'; non_member_price_delete.dataset.counter = non_member_price_counter; non_member_price_delete.style.textDecoration = 'none'; non_member_price_delete.onclick = function(){ var this_price = document.getElementById('non_member_pricing_' + this.dataset.counter); var member_price = document.getElementById('member_pricing_' + this.dataset.counter); this_price.remove(); member_price.remove(); } non_member_price_row.appendChild(non_member_price_delete); document.getElementsByClassName('nonmember-pricing-wrapper')[0].appendChild(non_member_price_row); } else if(using_member_pricing == 'member'){ var member_price_row = document.createElement('div'); var member_prices = document.getElementsByClassName('member-price'); var member_price_counter = member_prices.length; member_price_row.id = 'member_pricing_' + member_price_counter; member_price_row.className = 'member-price'; var member_price_quantity_field = document.createElement('input'); member_price_quantity_field.id = 'member_pricing_quantity_' + member_price_counter; member_price_quantity_field.style.width = quantity_field_width; if(typeof price_data != 'undefined' && null !== price_data && typeof price_data.member != 'undefined' && typeof price_data.member.quantity != 'undefined'){ member_price_quantity_field.value = price_data.member.quantity; } member_price_row.appendChild(member_price_quantity_field); member_price_row.appendChild(document.createTextNode(' ' + uom + ' $ ')); var member_price_price_field = document.createElement('input'); member_price_price_field.id = 'member_pricing_price_' + member_price_counter; member_price_price_field.style.width = price_field_width; if(typeof price_data != 'undefined' && null !== price_data && typeof price_data.member != 'undefined' && typeof price_data.member.price != 'undefined'){ member_price_price_field.value = price_data.member.price; } member_price_row.appendChild(member_price_price_field); member_price_row.appendChild(document.createTextNode(' ')); var member_price_delete = document.createElement('a'); member_price_delete.id = 'single_price_delete_' + member_price_counter; member_price_delete.href = '#DeletePrice'; member_price_delete.style.color = 'red'; member_price_delete.style.marginLeft = '15px'; member_price_delete.style.border = '1px solid red'; member_price_delete.style.padding = '0px 3px'; member_price_delete.style.fontWeight = 'bold'; member_price_delete.className = 'cp-delete_price'; member_price_delete.innerHTML = ' X'; member_price_delete.dataset.counter = member_price_counter; member_price_delete.style.textDecoration = 'none'; member_price_delete.onclick = function(){ var this_price = document.getElementById('member_pricing_' + this.dataset.counter); this_price.remove(); } member_price_row.appendChild(member_price_delete); document.getElementsByClassName('member-pricing-wrapper')[0].appendChild(member_price_row); } else{ var single_price_row = document.createElement('div'); var single_prices = document.getElementsByClassName('single-price'); var single_price_counter = single_prices.length; single_price_row.id = 'single_pricing_' + single_price_counter; single_price_row.className = 'single-price'; var single_price_quantity_field = document.createElement('input'); single_price_quantity_field.id = 'single_pricing_quantity_' + single_price_counter; single_price_quantity_field.style.width = quantity_field_width; if(typeof price_data != 'undefined' && null !== price_data && typeof price_data.single != 'undefined' && typeof price_data.single.quantity != 'undefined'){ single_price_quantity_field.value = price_data.single.quantity; } single_price_row.appendChild(single_price_quantity_field); single_price_row.appendChild(document.createTextNode(' ' + uom + ' $ ')); var single_price_price_field = document.createElement('input'); single_price_price_field.id = 'single_pricing_price_' + single_price_counter; single_price_price_field.style.width = price_field_width; if(typeof price_data != 'undefined' && null !== price_data && typeof price_data.single != 'undefined' && typeof price_data.single.price != 'undefined'){ single_price_price_field.value = price_data.single.price; } single_price_row.appendChild(single_price_price_field); single_price_row.appendChild(document.createTextNode(' ')); var single_price_delete = document.createElement('a'); single_price_delete.id = 'single_price_delete_' + single_price_counter; single_price_delete.href = '#DeletePrice'; single_price_delete.style.color = 'red'; single_price_delete.style.marginLeft = '15px'; single_price_delete.style.border = '1px solid red'; single_price_delete.style.padding = '0px 3px'; single_price_delete.style.fontWeight = 'bold'; single_price_delete.className = 'cp-delete_price'; single_price_delete.innerHTML = ' X'; single_price_delete.dataset.counter = single_price_counter; single_price_delete.style.textDecoration = 'none'; single_price_delete.onclick = function(){ var this_price = document.getElementById('single_pricing_' + this.dataset.counter); this_price.remove(); } single_price_row.appendChild(single_price_delete); document.getElementsByClassName('single-pricing-wrapper')[0].appendChild(single_price_row); } } async function UpdatePricingPreset(preset_id, pricing_data){ const single_on_sale = document.getElementById('cp_preset_single_on_sale'); const nonmember_on_sale = document.getElementById('cp_preset_nonmember_on_sale'); const member_on_sale = document.getElementById('cp_preset_member_on_sale'); let is_on_sale = 0; let is_on_sale_member = 0; if(single_on_sale && single_on_sale.checked){ is_on_sale = 1; } else if(nonmember_on_sale){ // means we have both member and non is_on_sale = nonmember_on_sale.checked ? 1 : 0; is_on_sale_member = member_on_sale.checked ? 1 : 0; } else if(member_on_sale){ is_on_sale_member = member_on_sale.checked ? 1 : 0; } var data = pricing_data; var fd = new FormData(); fd.append('action', 'UpdatePricingPreset'); fd.append('preset_id', preset_id); fd.append('pricing_data', data); fd.append('is_on_sale', is_on_sale); fd.append('is_on_sale_member', is_on_sale_member); fd.append('login_id', getCookie('cpck')); const resp = await fetch('https://menustore.canname.nu/api.php', {method: 'POST', body: fd}); if(resp){ alert('Price Group saved'); var id = await resp.json(); var select = document.getElementById('CpSelectPricingModelPreset'); var opt = document.createElement('option'); opt.value = id; opt.appendChild(document.createTextNode(name)); select.appendChild(opt); select.value = id; } } function serializeUpdatePricing(){ var price_model_value = document.getElementById('CpSelectPricingPresetModel').value; var formvar = {}; formvar.uom = global_uom; switch(price_model_value){ case 'single': var single_prices = document.getElementsByClassName('single-price'); var single_price_array = []; for(var i = 0; i < single_prices.length; i++){ var single_pricing = { size: document.getElementById('single_pricing_quantity_' + i).value, price: document.getElementById('single_pricing_price_' + i).value }; single_price_array.push(single_pricing); formvar.single_quantity_prices = single_price_array; } break; case 'member': var member_prices = document.getElementsByClassName('member-price'); var member_price_array = []; for(var i = 0; i < member_prices.length; i++){ var member_pricing = { size: document.getElementById('member_pricing_quantity_' + i).value, price: document.getElementById('member_pricing_price_' + i).value }; member_price_array.push(member_pricing); formvar.member_quantity_prices = member_price_array; } break; case 'both': var member_prices = document.getElementsByClassName('member-price'); var member_price_array = []; var nonmember_price_array = []; for(var i = 0; i < member_prices.length; i++){ var member_pricing = { size: document.getElementById('member_pricing_quantity_' + i).value, price: document.getElementById('member_pricing_price_' + i).value }; member_price_array.push(member_pricing); var nonmember_pricing = { size: document.getElementById('non_member_pricing_quantity_' + i).value, price: document.getElementById('non_member_pricing_price_' + i).value }; //member_price_array.push(member_pricing); formvar.member_quantity_prices = member_price_array; nonmember_price_array.push(nonmember_pricing); formvar.nonmember_quantity_prices = nonmember_price_array; } break; } return formvar; } var global_uom = false; function populatePricingPreset(params_obj){ var prices = JSON.parse(params_obj.prices); global_uom = prices.uom; if(prices){ var price_model_switch = document.getElementById('CpSelectPricingPresetModel'); if(typeof prices.nonmember_quantity_prices != 'undefined'){ //var price_model_switch = document.getElementById('CpSelectPricingModel'); price_model_switch.value = 'both'; price_model_switch.onchange(); for(var i = 0; i < prices.member_quantity_prices.length; i++){ var price_obj = { member: { quantity: prices.member_quantity_prices[i].size, price: prices.member_quantity_prices[i].price }, nonmember: { quantity: prices.nonmember_quantity_prices[i].size, price: prices.nonmember_quantity_prices[i].price } } AddNewPresetPrice(price_obj, prices.uom); } } else if(typeof prices.member_quantity_prices != 'undefined'){ price_model_switch.value = 'member'; price_model_switch.onchange(); for(var i = 0; i < prices.member_quantity_prices.length; i++){ var price_obj = { member: { quantity: prices.member_quantity_prices[i].size, price: prices.member_quantity_prices[i].price } } AddNewPresetPrice(price_obj, prices.uom); } } else{ //var price_model_switch = document.getElementById('CpSelectPricingPresetModel'); price_model_switch.value = 'single'; price_model_switch.onchange(); for(var i = 0; i < prices.single_quantity_prices.length; i++){ var price_obj = { single: { quantity: prices.single_quantity_prices[i].size, price: prices.single_quantity_prices[i].price } } AddNewPresetPrice(price_obj, prices.uom); } } } else{ } if('1' === params_obj.is_on_sale_member){ document.getElementById('cp_preset_member_on_sale').checked = true; } if('1' === params_obj.is_on_sale){ if('single' != price_model_switch.value){ document.getElementById('cp_preset_nonmember_on_sale').checked = true; } else{ document.getElementById('cp_preset_single_on_sale').checked = true; } } return true; } async function drawPresetEditor(preset_id){ const preset_frame = document.createElement('div'); var price_preset_select_pricing_mode_wrapper = document.createElement('div'); price_preset_select_pricing_mode_wrapper.className = 'cp-form-row'; price_preset_select_pricing_mode_wrapper.style.display = 'none'; price_preset_select_pricing_mode_wrapper.appendChild(document.createTextNode('Use member/nonmember pricing')); price_preset_select_pricing_mode_wrapper.appendChild(document.createElement('br')); var pricing_mode_select = document.createElement('select'); pricing_mode_select.onchange = function(){setPricingPresetForm(this.value);}; pricing_mode_select.style.width = "100%"; pricing_mode_select.id = 'CpSelectPricingPresetModel'; pricing_mode_select.name = 'CpSelectPricingPresetModel'; var none_option = document.createElement('option'); none_option.value = ''; none_option.innerHTML = 'Select'; pricing_mode_select.appendChild(none_option); var nonmember_only_option = document.createElement('option'); nonmember_only_option.value = 'single'; nonmember_only_option.innerHTML = 'Non-member'; pricing_mode_select.appendChild(nonmember_only_option); var member_only_option = document.createElement('option'); member_only_option.value = 'member'; member_only_option.innerHTML = 'Member'; pricing_mode_select.appendChild(member_only_option); var both_option = document.createElement('option'); both_option.value = 'both'; both_option.innerHTML = 'Member & Non-member'; pricing_mode_select.appendChild(both_option); price_preset_select_pricing_mode_wrapper.appendChild(pricing_mode_select); preset_frame.appendChild(price_preset_select_pricing_mode_wrapper); var add_price_wrapper = document.createElement('div'); add_price_wrapper.className = 'cp-form-row'; add_price_wrapper.id = 'add_price_button_wrapper'; add_price_wrapper.style.display = 'none'; var add_price_button = document.createElement('button'); add_price_button.id = 'cp_add_preset_price'; add_price_button.className = 'cp-button-std'; add_price_button.innerHTML = 'Add Weight : Price Tier'; add_price_wrapper.appendChild(add_price_button); preset_frame.appendChild(add_price_wrapper); add_price_button.onclick = function(e){ e.preventDefault(); AddNewPresetPrice(null, global_uom); } var single_pricing_wrapper = document.createElement('div'); single_pricing_wrapper.className = 'single-pricing-wrapper pricing-wrapper'; single_pricing_wrapper.appendChild(document.createTextNode('Standard Pricing')); single_pricing_wrapper.appendChild(document.createElement('br')); var single_on_sale = document.createElement('input'); single_on_sale.type = 'checkbox'; single_on_sale.name = 'single_on_sale'; single_on_sale.value = '1'; single_on_sale.id = 'cp_preset_single_on_sale'; single_pricing_wrapper.appendChild(single_on_sale); single_pricing_wrapper.appendChild(document.createTextNode(' Item is on sale')); preset_frame.appendChild(single_pricing_wrapper); var member_pricing_wrapper = document.createElement('div'); member_pricing_wrapper.className = 'member-pricing-wrapper pricing-wrapper'; member_pricing_wrapper.appendChild(document.createTextNode('Member Pricing')); member_pricing_wrapper.appendChild(document.createElement('br')); var member_on_sale = document.createElement('input'); member_on_sale.type = 'checkbox'; member_on_sale.id = 'cp_preset_member_on_sale'; member_on_sale.name = 'member_on_sale'; member_on_sale.value = '1'; member_pricing_wrapper.appendChild(member_on_sale); member_pricing_wrapper.appendChild(document.createTextNode(' Item is on sale')); preset_frame.appendChild(member_pricing_wrapper); var nonmember_pricing_wrapper = document.createElement('div'); nonmember_pricing_wrapper.className = 'nonmember-pricing-wrapper pricing-wrapper'; nonmember_pricing_wrapper.appendChild(document.createTextNode('Non-member Pricing')); nonmember_pricing_wrapper.appendChild(document.createElement('br')); var nonmember_on_sale = document.createElement('input'); nonmember_on_sale.type = 'checkbox'; nonmember_on_sale.id = 'cp_preset_nonmember_on_sale'; nonmember_on_sale.name = 'nonmember_on_sale'; nonmember_on_sale.value = '1'; nonmember_pricing_wrapper.appendChild(nonmember_on_sale); nonmember_pricing_wrapper.appendChild(document.createTextNode(' Item is on sale')); preset_frame.appendChild(nonmember_pricing_wrapper); // Price json fields var hidden_pricing_json = document.createElement('input'); hidden_pricing_json.type = 'hidden'; hidden_pricing_json.name = 'pricing_preset_json'; hidden_pricing_json.id = 'hidden_preset_pricing_json'; preset_frame.appendChild(hidden_pricing_json); const update_button_wrapper = document.createElement('div'); const update_button = document.createElement('button'); update_button.appendChild(document.createTextNode('Update Preset')); update_button.onclick = () => { UpdatePricingPreset(preset_id, JSON.stringify(serializeUpdatePricing())); } update_button_wrapper.appendChild(update_button); preset_frame.appendChild(update_button_wrapper); if('new' != preset_id){ var fd = new FormData(); fd.append('action', 'GetPricingPreset'); fd.append('preset_id', preset_id); const resp = await fetch('https://menustore.canname.nu/api.php', {method: 'POST', body: fd}); if(resp){ var params_obj = await resp.json(); //document.getElementById('preset_target').appendChild(preset_frame); cpInfowindow('Edit Pricing Group', preset_frame); populatePricingPreset(params_obj); } } else{ cpInfowindow('Add Pricing Group', preset_frame); } }