var SERVER_BASEURL = 'https://menuserver.canname.nu';
var DATASTORE_BASEURL = 'https://menustore.canname.nu';
function ucFirst(str){
return str[0].toUpperCase() + str.slice(1);
}
function ucWords(str){
var pieces = str.split(" ");
for(var i = 0; i < pieces.length; i++){
var j = pieces[i][0].toUpperCase();
pieces[i] = j + pieces[i].substr(1);
}
return pieces.join(" ");
}
function titleCase(str){
return ucWords(str.toLowerCase);
}
function CpDialog(){
var basic_dialog = function(title, content, title_bg_color, content_bg_color, width, position, draggable, timeout, callback){
var outer_wrapper = document.createElement('div');
outer_wrapper.className = 'cp-dialog-outer-wrapper';
outer_wrapper.style.width = width || '300px';
outer_wrapper.style.position = 'fixed';
outer_wrapper.style.zIndex = '10001';
switch(position){
case 'center':
default:
outer_wrapper.style.top = '50%';
outer_wrapper.style.left = '50%';
outer_wrapper.style.transform = 'translate(-50%,-50%)';
}
var title_wrapper = document.createElement('div');
title_wrapper.style.padding = '20px';
title_wrapper.style.textAlign = 'center';
title_wrapper.style.background = title_bg_color || '#14723d73';
title_wrapper.style.fontSize = '20px';
title_wrapper.style.fontWeight = '600';
title_wrapper.appendChild(document.createTextNode(title));
title_wrapper.className = 'cp-title-wrapper';
var closer_wrapper = document.createElement('div');
closer_wrapper.style.position = 'absolute';
closer_wrapper.className = 'cp-closer-wrapper';
closer_wrapper.style.top = '0px';
closer_wrapper.style.right = '0px';
closer_wrapper.style.padding = '5px';
var close_link = document.createElement('a');
close_link.className = 'cp-close-link';
close_link.style.cursor = 'pointer';
close_link.style.fontSize = '20px';
close_link.style.color = '#000';
close_link.style.fontWeight = '600';
close_link.innerHTML = '×';
close_link.onclick = function(){
outer_wrapper.remove();
};
closer_wrapper.appendChild(close_link);
title_wrapper.appendChild(closer_wrapper);
outer_wrapper.appendChild(title_wrapper);
var content_wrapper = document.createElement('div');
content_wrapper.className = 'cp-content-wrapper';
content_wrapper.style.color = '#000';
content_wrapper.style.fontSize = '16px';
content_wrapper.style.background = content_bg_color || '#fff';
content_wrapper.style.padding = '20px';
content_wrapper.style.maxHeight = '450px !important';
content_wrapper.style.overflowY = 'auto';
content_wrapper.innerHTML = content;
outer_wrapper.appendChild(content_wrapper);
document.getElementsByTagName('body')[0].appendChild(outer_wrapper);
if(timeout){
setTimeout(function(){
outer_wrapper.remove();
}, timeout);
}
}
this.infoWindow = function(title, content, width, timeout, position, draggable){
basic_dialog(title, content, false, false, width, position, draggable, timeout);
}
this.errorWindow = function(title, content, width, position, draggable, timeout){
const title_bg_color = 'red';
basic_dialog(title, content, title_bg_color, false, width, position, draggable, timeout)
}
this.successWindow = function(title, content, timeout, width, position, draggable){
const title_bg_color = 'green';
basic_dialog(title, content, title_bg_color, false, width, position, draggable, timeout)
}
this.optionsWindow = function(title, caption, options, radios, callback, width, position, draggable){
var options_task_wrapper = document.createElement('div');
var caption_wrapper = document.createElement('div');
caption_wrapper.className = 'cp-dialog-row';
caption_wrapper.innerHTML = caption;
options_task_wrapper.appendChild(caption_wrapper);
var options_wrapper = document.createElement('div');
for(var i = 0; i < options.length; i++){
var option_wrapper = document.createElement('div');
option_wrapper.className = 'cp-dialog-option-wrapper';
if(radios){
var radio = document.createElement('input');
radio.type = 'radio';
radio.name = 'cp_dialog_radio';
radio.value = options[i].value;
radio.style.marginRight = '7px';
option_wrapper.appendChild(radio);
option_wrapper.appendChild(document.createTextNode(options[i].display));
options_wrapper.appendChild(option_wrapper)
}
else{
var checkbox = document.createElement('input');
checkbox.type = 'checkbox';
//checkbox.name = 'cp_dialog_checkbox[' + options[i].value.replace(/ /g, '_').toLowerCase() + ']';
checkbox.className = 'cp-dialog-checkbox';
if(options[i].checked){
checkbox.setAttribute('checked', 'checked');
}
checkbox.value = options[i].value;
checkbox.style.marginRight = '7px';
option_wrapper.appendChild(checkbox);
option_wrapper.appendChild(document.createTextNode(options[i].display));
options_wrapper.appendChild(option_wrapper);
}
}
options_task_wrapper.appendChild(options_wrapper);
var action_button_wrapper = document.createElement('div');
action_button_wrapper.className = 'cp-action-button-row';
var action_button = document.createElement('button');
action_button.className = 'cp-action_button';
action_button.id = 'cp_cmd_button';
action_button.innerHTML = 'Submit';
action_button_wrapper.appendChild(action_button);
options_task_wrapper.appendChild(action_button_wrapper);
basic_dialog(title, options_task_wrapper.innerHTML);
var btn = document.getElementById('cp_cmd_button');
btn.onclick = function(){
callback();
}
}
this.selectWindow = function(title, caption, selections, multiple, width, position, draggable){
var select_task_wrapper = document.createElement('div');
var prepped_selections = [];
if(typeof selections[0].value != 'undefined'){
prepped_selections = selections;
}
else{
for(var i = 0; i < selections.length; i++){
prepped_selections.push(new CpSelection(selections[i]));
}
}
var selections_select = document.createElement('select');
selections_select.id = 'cp_cmd_select';
if(multiple){
selections_select.multiple = true;
selections_select.style.height = '250px';
}
selections_select.style.width = '100%';
for(var j = 0; j < prepped_selections.length; j++){
var opt = document.createElement('option');
opt.value = prepped_selections[j].value;
opt.appendChild(document.createTextNode(prepped_selections[j].display));
selections_select.appendChild(opt)
}
var caption_div = document.createElement('div');
caption_div.className = 'cp-dialog-row';
caption_div.innerHTML = caption;
select_task_wrapper.appendChild(caption_div);
var select_div = document.createElement('div');
select_div.className = 'cp-dialog-row';
select_div.appendChild(selections_select);
select_task_wrapper.appendChild(select_div);
var action_button_wrapper = document.createElement('div');
action_button_wrapper.className = 'cp-action-button-row';
var action_button = document.createElement('button');
action_button.className = 'cp-action_button';
action_button.id = 'cp_cmd_button';
action_button.innerHTML = 'Submit';
action_button_wrapper.appendChild(action_button);
select_task_wrapper.appendChild(action_button_wrapper);
basic_dialog(title, select_task_wrapper.innerHTML);
}
}
function show_cp_spinner(text){
const spinner_outer_wrapper = document.createElement('div');
spinner_outer_wrapper.style.backgroundColor = '#fff';
spinner_outer_wrapper.style.border = '1px solid #14723d73';
spinner_outer_wrapper.style.borderRadius = '10px';
spinner_outer_wrapper.style.width = '250px';
spinner_outer_wrapper.height = '250px';
spinner_outer_wrapper.className = 'spinner-outer-wrapper';
const spinner_wrapper = document.createElement('div');
spinner_wrapper.style.textAlign = 'center';
spinner_wrapper.style.padding = '60px 85px';
spinner_outer_wrapper.appendChild(spinner_wrapper);
spinner_wrapper.innerHTML = '
';
const spinner_text_wrapper = document.createElement('div');
spinner_text_wrapper.style.padding = '10px 20px';
spinner_text_wrapper.style.textAlign = 'center';
spinner_text_wrapper.style.fontSize = '24px';
spinner_outer_wrapper.appendChild(spinner_text_wrapper);
spinner_text_wrapper.appendChild(document.createTextNode(text));
spinner_outer_wrapper.style.position = 'fixed';
spinner_outer_wrapper.style.zIndex = '10001';
spinner_outer_wrapper.style.top = '50%';
spinner_outer_wrapper.style.left = '50%';
spinner_outer_wrapper.style.transform = 'translate(-50%,-50%)';
document.getElementsByTagName('body')[0].appendChild(spinner_outer_wrapper);
}
function hide_cp_spinner(){
document.getElementsByClassName('spinner-outer-wrapper')[0].remove();
}
function CpSelection(display, value){
this.display = display;
this.value = value || display == 'Select' ? '' : display;
}
function CpOption(display, value, checked){
this.display = display;
this.value = value || display;
this.checked = checked;
}
function typeCheck(value) {
const return_value = Object.prototype.toString.call(value);
// we can also use regex to do this...
const type = return_value.substring(
return_value.indexOf(" ") + 1,
return_value.indexOf("]"));
return type.toLowerCase();
}
function cpInfowindow(title, message, timeout){
var dialog = new CpDialog();
dialog.infoWindow(title, message, false, timeout);
}
function cpSuccess(message, timeout, title){
var dialog = new CpDialog();
dialog.successWindow(title || 'Success', message, timeout);
}
function cpError(message, timeout, title){
var dialog = new CpDialog();
dialog.errorWindow(title || 'Error', message, timeout);
}
function cpChecklist(title, caption, options, callback){
var dialog = new CpDialog();
dialog.optionsWindow(title, caption, options, false, callback);
}
function clickback(){
alert('clicked');
}
//alert('ht')
var jjj = new CpDialog();
//jjj.infoWindow('Test window', 'This is a test infowindow');
//jjj.errorWindow('Test Error', 'An error has occured. Panic!');
//jjj.successWindow('Success', 'The settings were saved', 6000);
var selections = [];
var selection = new CpSelection('Select', '');
var selection2 = new CpSelection('Option1', 'option1');
selections.push(selection);
selections.push(selection2);
//jjj.selectWindow('select window', 'Select something below', selections, true);
//jjj.optionsWindow('Radio selection', 'Make a selection', selections, true);
//jjj.optionsWindow('Checkbox selections', 'Select all that apply:', selections, false, clickback);
//cpChecklist('Checkbox selections', 'Select all that apply:', selections, window.clickback);
//cpSuccess('This message will close in 6 seconds', 6000, 'Success');
//cpError('This is generated by cpError(msg);');document.getElementsByTagName('body')[0].style.overflowY = 'scroll';
var cannamenu_div = document.getElementById("cannamenu-div");
if(!cannamenu_div){
if(document.currentScript.closest("div")){
cannamenu_div = document.currentScript.closest("div");
//document.currentScript.closest("div").appendChild(document.createTextNode("Menu will appear in this parent div"));
}
else{
cannamenu_div = document.createElement('div');
cannamenu_div.id = 'cannamenu-div';
document.currentScript.parentNode.appendChild(cannamenu_div);
cannamenu_div = document.getElementById("cannamenu-div");
//document.getElementById("cannamenu-div").appendChild(document.createTextNode("Menu will appear here in this created div"));
}
}
function CpCart(){
this.cart = new CpCartObj();
this.dispensaryId = 'val-1452';
this.endpoint = 'https://menustore.canname.nu/api.php';
this.wireMenuPage = function(){
var add_buttons = document.getElementsByClassName('add-to-cart-button');
//alert(add_buttons.length);
for(var i = 0; i < add_buttons.length; i++){
add_buttons[i].addEventListener("click", add_to_cart_click);
}
var view_cart_buttons = document.getElementsByClassName('cp-view-cart');
for(var i = 0; i < view_cart_buttons.length; i++){
view_cart_buttons[i].addEventListener('click', view_cart_click);
}
thiss.update_counter();
}
var view_cart_click = function(){
var cart = thiss.checkoutCart();
var wrapper = document.getElementById('cannamenu-div');
var menu = document.getElementById('canna_menu');
wrapper.appendChild(cart);
wrapper.appendChild(thiss.checkoutLogin());
menu.style.display = 'none';
document.getElementById('cp_filter_home').style.display = 'none';
};
this.update_counter = function(){
const cart_json = localStorage.cart;
var counter_value = 0;
if(cart_json){
var cart = JSON.parse(cart_json);
//alert(Object.keys(cart.items).length);
for(var item in cart.items){
counter_value = counter_value + parseInt(cart.items[item].quantity);
}
}
document.getElementById('cp_cart_counter_display').innerHTML = counter_value;
}
var add_to_cart_click = function(button){
//console.log(button);
//alert(button.target.dataset.product_pos_id);
var quantity = button.target.closest('.price-wrapper').getElementsByClassName('add-to-cart-quantity')[0].value;
//var price_tier = button.target.closest('.price-wrapper').getElementsByClassName('tier-select')[0].value || button.target.closest('.price-wrapper').dataset.size_uom_price;
if('undefined' != typeof button.target.closest('.price-wrapper').getElementsByClassName('tier-select')[0]){
var price_tier = button.target.closest('.price-wrapper').getElementsByClassName('tier-select')[0].value;
}
else{
var price_tier = button.target.closest('.price-wrapper').dataset.size_uom_price;
}
var pos_id = button.target.dataset.product_pos_id;
var dispensary_hash = button.target.dataset.dispensary_id;
var thumb_url = button.target.dataset.thumb_url;
var name = button.target.dataset.item_name;
const part_cat_id = button.target.dataset.part_category_id;
const tax_cat_id = button.target.dataset.tax_category_id;
const vendor_payee_id = button.target.dataset.vendor_payee_id;
const uom_id = button.target.dataset.uom_id;
const cat_name = button.target.dataset.cat_name;
const subcategory_name = button.target.dataset.subcategory_name;
//alert(price_tier);
var item_parts = price_tier.split(':');
var item = new CpCartItem(quantity, item_parts[0], item_parts[1], item_parts[2], pos_id, thumb_url, name, part_cat_id, tax_cat_id, vendor_payee_id, uom_id, cat_name, subcategory_name);
var item_key = pos_id + '-' + item_parts[0] + '-' + item_parts[1];
var current_cart = thiss.getCart();
if(null === current_cart){
// there is no cart
thiss.startCart(dispensary_hash, item);
}
else if(thiss.cart.dispensaryHash != dispensary_hash){
//alert(thiss.cart.dispensaryHash + "\n" + dispensary_hash);
if(confirm('Changing dispensaries will cause your current shopping cart to be deleted. Click OK to proceed')){
thiss.startCart(dispensary_hash, item);
}
}
else if(false === current_cart){
// A cart with no items
thiss.cart.items = {};
thiss.cart.items[item_key] = item;
}
else{
// cart with items
if(typeof thiss.cart.items[item_key] != 'undefined'){
// cart with the same item
thiss.cart.items[item_key].quantity = parseInt(thiss.cart.items[item_key].quantity) + parseInt(quantity);
}
else{
// Adding a new item
thiss.cart.items[item_key] = item;
}
}
thiss.storeCart();
thiss.update_counter();
}
this.startCart = function(disp_hash, item){
thiss.cart = new CpCartObj();
thiss.cart.dispensaryHash = disp_hash;
thiss.cart.items = {};
thiss.cart.items[item.posProductId + '-' + item.size] = item;
}
this.getCart = function(){
var json_cart = localStorage.getItem('cart');
if(!json_cart){
return null;
}
var rawcart = JSON.parse(json_cart);
if(typeof rawcart.items != 'undefined'){
thiss.cart = new CpCartObj(rawcart.dispensaryHash, rawcart.items);
return true;
}
return false;
}
this.getTax = async function(){
this.getCart();
const fd = new FormData();
fd.append('action', 'GetTax');
fd_append('cart', JSON.stringify(thiss.cart));
var resp = await fetch('https://menustore.canname.nu/api.php', {method: 'POST', body: fd});
const result = await resp.json();
if(result.totalTax == 0){
return false;
}
thiss.cart.taxTotal = result.totalTax;
}
this.storeCart = function(forget_preview){
localStorage.setItem('cart', JSON.stringify(thiss.cart));
if(!forget_preview)
thiss.previewCart();
}
this.previewCart = function(){
var preview_wrapper = document.createElement('div');
preview_wrapper.className = 'preview-wrapper';
preview_wrapper.style.position = 'fixed';
preview_wrapper.style.maxWidth = '500px';
preview_wrapper.style.top = '0px';
preview_wrapper.style.right = '0px';
preview_wrapper.style.display = 'none';
preview_wrapper.style.background = '#fff';
preview_wrapper.style.zIndex = '10000000';
const exit_div = document.createElement('div');
exit_div.style.width = '100%';
exit_div.style.textAlign = 'right';
exit_div.style.padding = '15px';
const close_link = document.createElement('a');
close_link.style.cursor = 'pointer';
close_link.style.fontSize = '18px';
close_link.innerHTML = '×';
close_link.onclick = function(){
const pr = document.getElementsByClassName('preview-wrapper')[0];
pr.style.display = 'none';
document.getElementsByTagName('body')[0].removeChild(pr);
}
exit_div.appendChild(close_link);
preview_wrapper.appendChild(exit_div);
var h2 = document.createElement('h2');
h2.appendChild(document.createTextNode('Your Order'));
preview_wrapper.appendChild(h2);
var taxless_total = 0;
var cart_table = document.createElement('table');
cart_table.style.width = '100%';
for(const item in thiss.cart.items){
if(item.indexOf('-') != -1){
var parts = item.split('-');
var baseitem = parts[0];
}
else{
var baseitem = item
}
var tr = document.createElement('tr');
var img_td = document.createElement('td');
img_td.style.width = '85px';
img_td.style.padding = '5px';
var thumb = document.createElement('img');
thumb.style.width = '75px';
thumb.src = thiss.cart.items[item].thumbUrl;
thumb.dataset.cat_name = thiss.cart.items[item].cat_name;
thumb.dataset.subcategory_name = thiss.cart.items[item].subcategory_name;
thumb.onerror = function(){
this.onerror = null;
if('' != this.dataset.subcategory_name){
this.src = 'https://menuserver.canname.nu/images/' + this.dataset.subcategory_name.toLowerCase() + '_default.jpg';
}
else if('' != this.dataset.cat_name){
this.src = 'https://menuserver.canname.nu/images/' + this.dataset.cat_name.toLowerCase() + '_default.jpg';
}
else{
this.src = 'https://menuserver.canname.nu/default.jpg';
}
this.onerror = function(){
this.onerror = null;
this.src = 'https://menuserver.canname.nu/default.jpg';
}
this.style.height = '75px';
this.style.border = '1pt solid #ccc';
};
img_td.appendChild(thumb);
tr.appendChild(img_td);
var name_td = document.createElement('td');
name_td.style.padding = '5px';
name_td.appendChild(document.createTextNode(thiss.cart.items[item].itemName));
tr.appendChild(name_td);
var quantity_td = document.createElement('td');
quantity_td.style.width = '40px';
quantity_td.style.padding = '5px';
quantity_td.style.textAlign = 'right';
quantity_td.appendChild(document.createTextNode(thiss.cart.items[item].quantity));
tr.appendChild(quantity_td);
var line_total_td = document.createElement('td');
line_total_td.style.width = '100px';
line_total_td.style.padding = '5px';
line_total_td.style.textAlign = 'right';
var line_total = parseInt(thiss.cart.items[item].quantity) * parseFloat(thiss.cart.items[item].unitPrice);
taxless_total = line_total + taxless_total;
//alert(line_total + ' - ' + taxless_total);
line_total_td.appendChild(document.createTextNode('$' + line_total.toFixed(2)));
tr.appendChild(line_total_td);
cart_table.appendChild(tr);
}
const tax_tr = document.createElement('tr');
tax_tr.appendChild(document.createElement('td'));
tax_tr.appendChild(document.createElement('td'));
const tax_label_td = document.createElement('td');
tax_label_td.padding = '5px';
tax_label_td.textAlign = 'right';
tax_label_td.appendChild(document.createTextNode('Est. tax'));
tax_tr.appendChild(tax_label_td);
const tax_amount_td = document.createElement('td');
tax_amount_td.style.padding = '5px';
tax_amount_td.style.textAlign = 'right';
var cart_total = 0;
if('0' == sessionStorage.est_tax_rate){
tax_amount_td.appendChild(document.createTextNode('Included'));
cart_total = taxless_total;
}
else{
var tax_total = parseFloat(taxless_total) * parseFloat(sessionStorage.est_tax_rate);
tax_amount_td.appendChild(document.createTextNode(tax_total.toFixed(2)));
cart_total = parseFloat(taxless_total) + tax_total;
}
tax_tr.appendChild(tax_amount_td);
cart_table.appendChild(tax_tr);
var total_tr = document.createElement('tr');
total_tr.appendChild(document.createElement('td'));
total_tr.appendChild(document.createElement('td'));
var total_label_td = document.createElement('td');
total_label_td.style.padding = '5px';
total_label_td.style.textAlign = 'right';
total_label_td.appendChild(document.createTextNode('Total'));
total_tr.appendChild(total_label_td);
var total_td = document.createElement('td');
total_td.style.padding = '5px';
total_td.style.textAlign = 'right';
total_td.appendChild(document.createTextNode('$' + cart_total.toFixed(2)));
total_tr.appendChild(total_td);
cart_table.appendChild(total_tr);
preview_wrapper.appendChild(cart_table);
document.getElementsByTagName('body')[0].appendChild(preview_wrapper);
preview_wrapper.style.display = 'block';
setTimeout(function(){
preview_wrapper.style.display = 'none';
document.getElementsByTagName('body')[0].removeChild(preview_wrapper);
}, 3000);
}
this.checkoutLogin = function(){
var checkout_div = document.createElement('div');
checkout_div.style.padding = '20px';
checkout_div.id = 'checkout_div';
checkout_div.style.textAlign = 'center';
var checkout_button = document.createElement('button');
checkout_button.id = 'checkout_button';
checkout_button.appendChild(document.createTextNode('Checkout'));
checkout_button.onclick = function(e){
e.preventDefault();
if(!getCpid()){
document.getElementById('cart_div').style.display = 'none';
document.getElementById('auth_div').style.display = 'block';
document.getElementById('checkout_div').style.display = 'none';
}
else{
document.getElementById('cart_div').style.display = 'block';
document.getElementById('auth_div').style.display = 'none';
document.getElementById('checkout_div').style.display = 'none';
document.getElementById('customer_order').style.display = 'block';
}
}
checkout_div.appendChild(checkout_button);
var auth_div = document.createElement('div');
auth_div.id = 'auth_div';
auth_div.style.display = 'none';
var login_div = document.createElement('div');
login_div.id = 'login_div';
var login_h3 = document.createElement('h3');
login_h3.appendChild(document.createTextNode('Login'));
login_div.appendChild(login_h3);
var need_account = document.createElement('div');
need_account.appendChild(document.createTextNode('No Account? Signup '));
var need_account_link = document.createElement('a');
need_account_link.id = 'need_account_link';
need_account_link.style.cursor = 'pointer';
need_account_link.appendChild(document.createTextNode('HERE'));
need_account_link.onclick = function(){
login_div.style.display = 'none';
signup_div.style.display = 'block';
}
need_account.appendChild(need_account_link);
login_div.appendChild(need_account);
var uname_wrapper = document.createElement('div');
uname_wrapper.style.padding = '20px';
uname_wrapper.appendChild(document.createTextNode('Email Address'));
uname_wrapper.appendChild(document.createElement('br'));
var email_input = document.createElement('input');
email_input.id = 'login_email';
uname_wrapper.appendChild(email_input);
login_div.appendChild(uname_wrapper);
var pw_wrapper = document.createElement('div');
pw_wrapper.style.padding = '20px';
pw_wrapper.appendChild(document.createTextNode('Password'));
pw_wrapper.appendChild(document.createElement('br'));
var pw_input = document.createElement('input');
pw_input.type = 'password';
pw_input.id = 'login_pw';
pw_wrapper.appendChild(pw_input);
login_div.appendChild(pw_wrapper);
var login_button_wrapper = document.createElement('div');
login_button_wrapper.style.padding = '20px';
login_button_wrapper.style.textAlign = 'center';
const login_error_display = document.createElement('div');
login_error_display.style.color = 'red';
login_error_display.style.textAlign = 'center';
login_error_display.style.display = 'none';
login_button_wrapper.appendChild(login_error_display);
var login_button = document.createElement('button');
login_button.className = 'action-button';
login_button.id = 'login_button';
login_button.onclick = async function(){
const signin_name = document.getElementById('login_email');
if(!signin_name.value.length){
signin_name.style.borderColor = 'red';
login_error_display.innerHTML = 'Email is required';
login_error_display.style.display = 'block';
signin_name.focus();
return false;
}
else{
signin_name.style.borderColor = '#ccc';
login_error_display.style.display = 'none';
}
const signin_pw = document.getElementById('login_pw');
if(!signin_pw.value.length){
signin_pw.style.borderColor = 'red';
login_error_display.innerHTML = 'Password is required';
login_error_display.style.display = 'block';
signin_pw.focus();
return false;
}
else{
signin_pw.style.borderColor = '#ccc';
login_error_display.style.display = 'none';
}
const fd = new FormData();
fd.append('action', 'LoginCustomer');
fd.append('email', signin_name.value);
fd.append('pw', signin_pw.value);
fd.append('dispensary_hash', sessionStorage.disp_hash);
var resp = await fetch('https://menustore.canname.nu/api.php', {method: 'POST', body: fd});
const result = await resp.json();
if(result.status == 'ok'){
document.cookie = 'cpid=' + result.message;
document.getElementById('auth_div').style.display = 'none';
document.getElementById('cart_div').style.display = 'block';
document.getElementById('customer_order').style.display = 'block';
}
else{
login_error_display.innerHTML = result.message
login_error_display.style.display = 'block';
}
}
login_button.appendChild(document.createTextNode('Log In'));
login_button_wrapper.appendChild(login_button);
login_div.appendChild(login_button_wrapper);
auth_div.appendChild(login_div);
var signup_div = document.createElement('div');
signup_div.style.display = 'none';
signup_div.id = 'signup_div';
var signup_h3 = document.createElement('h3');
signup_h3.appendChild(document.createTextNode('Signup'));
signup_div.appendChild(signup_h3);
var have_account = document.createElement('div');
have_account.appendChild(document.createTextNode('Already Have an Account? Login '));
var have_account_link = document.createElement('a');
have_account_link.id = 'have_account_link';
have_account_link.style.cursor = 'pointer';
have_account_link.appendChild(document.createTextNode('HERE'));
have_account_link.onclick = function(){
login_div.style.display = 'block';
signup_div.style.display = 'none';
};
have_account.appendChild(have_account_link);
signup_div.appendChild(have_account);
var firstname_wrapper = document.createElement('div');
firstname_wrapper.style.padding = '20px';
firstname_wrapper.appendChild(document.createTextNode('First Name'));
firstname_wrapper.appendChild(document.createElement('br'));
var signup_firstname = document.createElement('input');
signup_firstname.id = 'signup_firstname';
firstname_wrapper.appendChild(signup_firstname);
signup_div.appendChild(firstname_wrapper);
var lastname_wrapper = document.createElement('div');
lastname_wrapper.style.padding = '20px';
lastname_wrapper.appendChild(document.createTextNode('Last Name'));
lastname_wrapper.appendChild(document.createElement('br'));
var signup_lastname = document.createElement('input');
signup_lastname.id = 'signup_lastname';
lastname_wrapper.appendChild(signup_lastname);
signup_div.appendChild(lastname_wrapper);
var email_wrapper = document.createElement('div');
email_wrapper.style.padding = '20px';
email_wrapper.appendChild(document.createTextNode('Email'));
email_wrapper.appendChild(document.createElement('br'));
var signup_email = document.createElement('input');
signup_email.id = 'signup_email';
email_wrapper.appendChild(signup_email);
signup_div.appendChild(email_wrapper);
var phone_wrapper = document.createElement('div');
phone_wrapper.style.padding = '20px';
phone_wrapper.appendChild(document.createTextNode('Phone'));
phone_wrapper.appendChild(document.createElement('br'));
var signup_phone = document.createElement('input');
signup_phone.id = 'signup_phone';
phone_wrapper.appendChild(signup_phone);
signup_div.appendChild(phone_wrapper);
var pw_wrapper = document.createElement('div');
pw_wrapper.style.padding = '20px';
pw_wrapper.appendChild(document.createTextNode('Password - At least 8 characters including at least 1 number and 1 upper case letter'));
pw_wrapper.appendChild(document.createElement('br'));
var signup_pw = document.createElement('input');
signup_pw.type = 'password';
signup_pw.id = 'signup_pw';
pw_wrapper.appendChild(signup_pw);
signup_div.appendChild(pw_wrapper);
var pw_confirm_wrapper = document.createElement('div');
pw_confirm_wrapper.style.padding = '20px';
pw_confirm_wrapper.appendChild(document.createTextNode('Confirm Password'));
pw_confirm_wrapper.appendChild(document.createElement('br'));
var signup_confirm_pw = document.createElement('input');
signup_confirm_pw.type = 'password';
signup_confirm_pw.id = 'signup_confirm_pw';
pw_confirm_wrapper.appendChild(signup_confirm_pw);
signup_div.appendChild(pw_confirm_wrapper);
var signup_button_wrapper = document.createElement('div');
signup_button_wrapper.style.textAlign = 'center';
var signup_button = document.createElement('button');
signup_button.id = 'signup_button';
signup_button.appendChild(document.createTextNode('Sign Up'));
signup_button.onclick = async function(){
const error_display = document.getElementById('cp_error_div');
const firstname = document.getElementById('signup_firstname');
firstname.style.borderColor = !firstname.value.length ? 'red' : '#ccc';
if(!firstname.value.length){
firstname.style.borderColor = 'red';
error_display.innerHTML = 'First name is required';
error_display.style.display = 'block';
firstname.focus();
return false;
}
else{
firstname.style.borderColor = '#ccc';
error_display.style.display = 'none';
}
const lastname = document.getElementById('signup_lastname');
if(!lastname.value.length){
lastname.style.borderColor = 'red';
error_display.innerHTML = 'Last name is required';
error_display.style.display = 'block';
lastname.focus();
return false;
}
else{
lastname.style.borderColor = '#ccc';
error_display.style.display = 'none';
}
const phone = document.getElementById('signup_phone');
if(!phone.value.length){
phone.style.borderColor = 'red';
error_display.innerHTML = 'Phone is required';
error_display.style.display = 'block';
phone.focus();
return false;
}
else{
phone.style.borderColor = '#ccc';
error_display.style.display = 'none';
}
const email = document.getElementById('signup_email');
if(!email.value.match(/^[A-Z0-9._%-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4}$/i)){
email.style.borderColor = 'red';
error_display.innerHTML = 'Valid email is required';
error_display.style.display = 'block';
email.focus();
return false;
}
else{
email.style.borderColor = '#ccc';
error_display.style.display = 'none';
}
const pw = document.getElementById('signup_pw');
if(!pw.value.match(/^(?=.*\d)(?=.*[A-Z]).{8,}$/)){
pw.style.borderColor = 'red';
error_display.innerHTML = 'Password does not meet requirements';
error_display.style.display = 'block';
pw.focus();
return false;
}
else{
pw.style.borderColor = '#ccc';
error_display.style.display = 'none';
}
const confirm_pw = document.getElementById('signup_confirm_pw');
if(confirm_pw.value != pw.value){
confirm_pw.style.borderColor = 'red';
error_display.innerHTML = 'Passwords do not match';
error_display.style.display = 'block';
confirm_pw.focus();
return false;
}
else{
confirm_pw.style.borderColor = '#ccc';
error_display.style.display = 'none';
}
const fd = new FormData();
fd.append('action', 'CreateCustomer');
fd.append('first_name', document.getElementById('signup_firstname').value);
fd.append('last_name', document.getElementById('signup_lastname').value);
fd.append('email', document.getElementById('signup_email').value);
fd.append('phone', document.getElementById('signup_phone').value);
fd.append('password', document.getElementById('signup_pw').value);
fd.append('dispensary_hash', sessionStorage.disp_hash);
var resp = await fetch('https://menustore.canname.nu/api.php', {method: 'POST', body: fd});
const result = await resp.json();
if(result.status == 'ok'){
document.cookie = 'cpid=' + result.message;
document.getElementById('auth_div').style.display = 'none';
document.getElementById('cart_div').style.display = 'block';
document.getElementById('customer_order').style.display = 'block';
}
else{
error_display.innerHTML = result.message
error_display.style.display = 'block';
}
}
const error_div = document.createElement('div');
error_div.style.textAlign = 'center';
error_div.id = 'cp_error_div';
error_div.style.color = 'red';
error_div.style.display = 'none';signup_button_wrapper.appendChild(error_div);
signup_button_wrapper.appendChild(signup_button);
signup_div.appendChild(signup_button_wrapper);
auth_div.appendChild(signup_div);
const action_div = document.createElement('div');
action_div.appendChild(checkout_div);
action_div.appendChild(auth_div);
const customer_order_div = document.createElement('div');
customer_order_div.id = 'customer_order';
const order_button_div = document.createElement('div');
//order_button_div.style.textAlign = 'center';
order_button_div.style.maxWidth = '390px';
//order_button_div.style.margin = '0 auto';
order_button_div.style.paddingLeft = '8px';
order_button_div.className = 'cp-form-row';
const order_button = document.createElement('button');
order_button.id = 'cp_order_button';
order_button.innerHTML = 'Place Order';
order_button_div.appendChild(order_button);
order_button.onclick = async function(){
show_cp_spinner('Sending your order...');
const fd = new FormData();
fd.append('action', 'PlaceOrder');
fd.append('customer_id', getCpid());
fd.append('store_id', adilas_store_id);
const decoded_cart = JSON.parse(localStorage.cart);
//alert(decoded_cart);
fd.append('items', JSON.stringify(decoded_cart.items));
fd.append('dispensary_hash', decoded_cart.dispensaryHash);
var resp = await fetch('https://menustore.canname.nu/api.php', {method: 'POST', body: fd});
const result = await resp.json();
hide_cp_spinner();
if(result.status == 'success'){
document.getElementById('tax_label_td').innerHTML = 'Tax';
document.getElementById('cart_tax_amount_td').innerHTML = '$' + result.tax;
document.getElementById('cart_total_td').innerHTML = '$' + result.total;
cpInfowindow('Order Placed', 'Thank you for your order!
Your request was successfully received.
Please note that orders may only be fulfilled during business hours (if submitted after hours, your order will sit in a queue until the store opens). Questions or Concerns? Please contact the store for assistance.
', false);
localStorage.removeItem('cart');
document.getElementById('cp_cart_counter_display').innerHTML = '0';
document.getElementById('cp_order_button').remove();
var continue_link = document.getElementById('continue_shopping_link');
continue_link.innerHTML = 'Back to Store';
continue_link.onclick = function(){
window.location.reload();
}
document.getElementById('update_button').remove();
}
}
customer_order_div.appendChild(order_button_div);
if(getCpid()){
auth_div.style.display = 'none';
checkout_div.style.display = 'none';
customer_order_div.style.display = 'block';
}
else{
auth_div.style.display = 'none';
customer_order_div.style.display = 'none';
}
action_div.appendChild(auth_div);
action_div.appendChild(customer_order_div);
return action_div;
}
this.checkoutCart = function(){
var cart_div = document.createElement('div');
cart_div.id = 'cart_div';
var continue_shopping_link = document.createElement('a');
continue_shopping_link.style.cursor = 'pointer';
continue_shopping_link.id = 'continue_shopping_link';
continue_shopping_link.appendChild(document.createTextNode('Continue Shopping'));
continue_shopping_link.onclick = function(){
cart_div.remove();
if(document.getElementById('auth_div')){
document.getElementById('auth_div').remove();
}
if(document.getElementById('cp_order_button')){
document.getElementById('cp_order_button').remove();
}
if(document.getElementById('checkout_div')){
document.getElementById('checkout_div').remove();
}
if(document.getElementById('checkout_button')){
document.getElementById('checkout_button').remove();
}
if(document.getElementById('customer_order')){
document.getElementById('customer_order').remove();
}
document.getElementById('canna_menu').style.display = 'block';
document.getElementById('cp_filter_home').style.display = 'block';
}
//cart_div.appendChild(continue_shopping_link);
var taxless_total = 0;
var cart_table = document.createElement('table');
cart_table.className = 'cart-table';
cart_table.style.width = '100%';
thiss.getCart();
for(const item in thiss.cart.items){
if(item.indexOf('-') != -1){
var parts = item.split('-');
var baseitem = parts[0];
}
else{
var baseitem = item;
}
var tr = document.createElement('tr');
tr.className = 'item';
var img_td = document.createElement('td');
img_td.style.width = '85px';
img_td.style.padding = '5px';
var thumb = document.createElement('img');
thumb.style.width = '75px';
thumb.src = thiss.cart.items[item].thumbUrl;
//console.log(thiss.cart.items[item]);
thumb.dataset.cat_name = thiss.cart.items[item].cat_name;
thumb.dataset.subcategory_name = thiss.cart.items[item].subcategory_name;
thumb.onerror = function(){
this.onerror = null;
if('' != this.dataset.subcategory_name){
this.src = 'https://menuserver.canname.nu/images/' + this.dataset.subcategory_name.toLowerCase() + '_default.jpg';
}
else if('' != this.dataset.cat_name){
this.src = 'https://menuserver.canname.nu/images/' + this.dataset.cat_name.toLowerCase() + '_default.jpg';
}
else{
this.src = 'https://menuserver.canname.nu/default.jpg';
}
this.onerror = function(){
this.onerror = null;
this.src = 'https://menuserver.canname.nu/default.jpg';
}
this.style.height = '75px';
this.style.border = '1pt solid #ccc';
};
img_td.appendChild(thumb);
tr.appendChild(img_td);
var name_td = document.createElement('td');
name_td.style.padding = '5px';
name_td.style.fontSize = '90%';
name_td.appendChild(document.createTextNode(thiss.cart.items[item].itemName + ' ' + thiss.cart.items[item].size + thiss.cart.items[item].uom));
tr.appendChild(name_td);
var quantity_td = document.createElement('td');
//quantity_td.style.width = '40px';
quantity_td.style.padding = '5px';
quantity_td.style.textAlign = 'right';
var delete_span = document.createElement('span');
delete_span.style.color = 'red';
delete_span.style.fontWeight = '700';
var delete_link = document.createElement('a');
delete_link.style.textDecoration = 'none';
delete_link.style.fontSize = 'small';
delete_link.style.cursor = 'pointer';
delete_link.appendChild(document.createTextNode('Remove'));
delete_link.onclick = function(){
delete thiss.cart.items[item];
thiss.storeCart(true);
//this.closest('.item').remove();
var main_div = document.getElementById('cannamenu-div');
cart_div.remove();
if(document.getElementById('auth_div')){
document.getElementById('auth_div').remove();
}
if(document.getElementById('customer_order')){
document.getElementById('customer_order').remove();
}
if(document.getElementById('checkout_button')){
document.getElementById('checkout_button').remove();
}
main_div.appendChild(thiss.checkoutCart());
main_div.appendChild(thiss.checkoutLogin());
thiss.update_counter();
}
delete_span.appendChild(delete_link);
quantity_td.appendChild(delete_span);
quantity_td.appendChild(document.createElement('br'));
var quantity_input = document.createElement('input');
quantity_input.type = 'number';
quantity_input.min = 1;
quantity_input.max = 5;
quantity_input.style.width = '80px';
quantity_input.value = thiss.cart.items[item].quantity;
quantity_input.oninput = function(){
if(this.value < 1){
this.value = 1;
}
}
quantity_input.onchange = function(){
if(this.value < 1){
this.value = 1;
}
thiss.cart.items[item].quantity = this.value;
thiss.storeCart(true);
thiss.update_counter();
}
quantity_td.appendChild(quantity_input);
tr.appendChild(quantity_td);
var line_total_td = document.createElement('td');
//line_total_td.style.width = '100px';
line_total_td.style.padding = '5px';
line_total_td.style.textAlign = 'right';
var line_total = parseInt(thiss.cart.items[item].quantity) * parseFloat(thiss.cart.items[item].unitPrice);
taxless_total = line_total + taxless_total;
//alert(line_total + ' - ' + taxless_total);
line_total_td.appendChild(document.createTextNode('$' + line_total.toFixed(2)));
tr.appendChild(line_total_td);
cart_table.appendChild(tr);
}
const tax_tr = document.createElement('tr');
tax_tr.appendChild(document.createElement('td'));
tax_tr.appendChild(document.createElement('td'));
const tax_label_td = document.createElement('td');
tax_label_td.id = 'tax_label_td';
tax_label_td.style.padding = '5px';
tax_label_td.style.textAlign = 'right';
tax_label_td.appendChild(document.createTextNode('Est. tax'));
tax_tr.appendChild(tax_label_td);
var tax_amount = 0;
const tax_amount_td = document.createElement('td');
tax_amount_td.id = 'cart_tax_amount_td';
tax_amount_td.style.padding = '5px';
tax_amount_td.style.textAlign = 'right';
var cart_total = 0;
if(sessionStorage.est_tax_rate == 0){
tax_amount_td.appendChild(document.createTextNode('Included'));
cart_total = taxless_total;
}
else{
tax_amount = parseFloat(taxless_total) * parseFloat(sessionStorage.est_tax_rate);
tax_amount_td.appendChild(document.createTextNode('$' + tax_amount.toFixed(2)));
cart_total = taxless_total + tax_amount;
}
tax_tr.appendChild(tax_amount_td);
cart_table.appendChild(tax_tr);
var total_tr = document.createElement('tr');
var update_td = document.createElement('td');
update_td.colSpan = 2;
var update_button = document.createElement('button');
update_button.appendChild(document.createTextNode("Update\nCart"));
update_button.id = 'update_button';
update_button.onclick = function(){
var main_div = document.getElementById('cannamenu-div');
cart_div.remove();
//document.getElementById('checkout_button').remove();
if(document.getElementById('auth_div')){
//document.getElementById('auth_div').remove();
}
if(document.getElementById('checkout_button')){
document.getElementById('checkout_div').style.display = 'none';
}
//document.getElementById('customer_order').remove();
//document.getElementById('auth_div').remove();
main_div.prepend(thiss.checkoutCart());
//main_div.appendChild(thiss.checkoutLogin());
if(document.getElementById('checkout_button')){
document.getElementById('checkout_div').style.display = 'block';
}
}
update_td.appendChild(update_button);
total_tr.appendChild(update_td);
//total_tr.appendChild(document.createElement('td'));
var total_label_td = document.createElement('td');
total_label_td.style.padding = '5px';
total_label_td.style.textAlign = 'right';
total_label_td.appendChild(document.createTextNode('Total'));
total_tr.appendChild(total_label_td);
var total_td = document.createElement('td');
total_td.id = 'cart_total_td';
total_td.style.padding = '5px';
total_td.style.textAlign = 'right';
total_td.appendChild(document.createTextNode('$' + cart_total.toFixed(2)));
total_tr.appendChild(total_td);
cart_table.appendChild(total_tr);
cart_div.appendChild(cart_table);
cart_div.appendChild(continue_shopping_link);
return cart_div;
}
var thiss = this;
}
function CpCartObj(disp_hash, items){
this.dispensaryHash = disp_hash;
this.items = items;
this.taxTotal = false;
}
function CpCartItem(quantity, size, uom, price, posPid, thumbUrl, itemName, part_cat_id, tax_cat_id, vendor_payee_id, uom_id, cat_name, subcategory_name){
this.quantity = quantity;
this.size = size;
this.uom = uom;
this.unitPrice = price;
this.posProductId = posPid;
this.thumbUrl = thumbUrl;
this.itemName = itemName;
this.taxCategoryId = tax_cat_id;
this.partCategoryId = part_cat_id;
this.vendorPayeeId = vendor_payee_id;
this.uomId = uom_id;
this.cat_name = cat_name;
this.subcategory_name = subcategory_name;
}
function getCpid() {
var name = "cpid=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i 0){
if(pricing_model.length === 1){
// simple single price
var price = parseFloat(pricing_model[0].price);
if(slider_price < price){
continue;
}
}
else{
// tiered priciing
var matches_price = false;
for(var p = 0; p < pricing_model.length; p++){
if(slider_price >= parseFloat(pricing_model[p].price)){
matches_price = true;
break;
}
}
if(!matches_price){
continue;
}
}
}
else{
continue;
}
}
else{
continue;
}
if(typeof resultant_menu[category] == 'undefined'){
resultant_menu[category] = [];
}
resultant_menu[category].push(cat_menu[category][i]);
}
}
var return_menu = filterSource;
return_menu.menu_by_cat = resultant_menu;
console.log('resultant menu')
console.log(resultant_menu);
return return_menu;
}
var getSpeciesByCat = function(category_id){
const filterSource = JSON.parse(sessionStorage.full_menu);
var menu_items = filterSource.menu_by_cat[category_id];
//console.log(menu_items);
var species = [];
for(var i = 0; i < menu_items.length; i++){
if(species.indexOf(menu_items[i].data.species) == -1){
species.push(menu_items[i].data.species);
//console.log(menu_items[i].data.species)
}
}
console.log(species)
return species;
}
var getSpecies = function(){
console.log('menu');
const filterSource = JSON.parse(sessionStorage.full_menu);
console.log(filterSource.menu_by_cat);
var species_items = [];
for(var id in filterSource.menu_by_cat){
//species_items.concat(getSpeciesByCat(id));
console.log(getSpeciesByCat(id))
species_items = species_items.concat(getSpeciesByCat(id));
}
console.log('final')
console.log(species_items)
return [...new Set(species_items)];
return species_items;
}
var getBrandsByCat = function(category_id){
filterSource = JSON.parse(sessionStorage.full_menu);
var menu_items = filterSource.menu_by_cat[category_id];
var brands = [];
for(var i = 0; i < menu_items.length; i++){
if(brands.indexOf(menu_items[i].data.brand) == -1){
brands.push(menu_items[i].data.brand);
}
}
return brands;
}
var get_brands = function(){
const filterSource = JSON.parse(sessionStorage.full_menu);
console.log(filterSource.menu_by_cat);
var brand_items = [];
for(var id in filterSource.menu_by_cat){
//species_items.concat(getSpeciesByCat(id));
console.log(getSpeciesByCat(id))
brand_items = brand_items.concat(getBrandsByCat(id));
}
console.log('brands')
console.log(brand_items)
return [...new Set(brand_items)].sort();
return brand_items;
}
var get_subcategoriesx = function(category_id){
filterSource = JSON.parse(sessionStorage.full_menu);
console.log('right here');
//console.log(filterSource.menu_by_cat);
var menu_items = filterSource.menu_by_cat[category_id];
console.log(menu_items);
var subcategories = {};
for(var i = 0; i < menu_items.length; i++){
console.log(menu_items[i])
var subcat_id = menu_items[i].data.subcategory_id;
console.log('sub id -> ' + subcat_id);
if(typeof subcategories[subcat_id] == 'undefined'){
for(var j = 0; j < filterSource.subcategories.length; j++){
//console.log(filterSource.subcategories[j]);
if(filterSource.subcategories[j]['id'] == subcat_id){
subcategories[subcat_id] = new FilterItem(filterSource.subcategories[j]['text'], filterSource.subcategories[j]['id']);
subcategories[subcat_id].count = 1;
break;
}
}
}
else{
subcategories[subcat_id].count += 1;
}
}
return subcategories;
}
var getSubcats = function(){
const filterSource = JSON.parse(sessionStorage.full_menu);
console.log(filterSource.menu_by_cat);
var cats_items = {};
for(cat in filterSource.menu_by_cat){
console.log('cat');
console.log(filterSource.menu_by_cat[cat]);
cats_items[cat] = get_subcategoriesx(cat);
}
console.log('end');
console.log(cats_items);
return cats_items;
}
var getSubcatsxx = function(legacy){
var filterSource = JSON.parse(sessionStorage.full_menu);
var subcategories = {};
console.log(filterSource.menu_by_cat);
for(var i in filterSource.menu_by_cat){
if(typeof subcategories[filterSource.menu_by_cat[i].data.subcategory_id] == 'undefined'){
for(var j = 0; j < filterSource.subcategories.length; j++){
console.log(filterSource.menu_by_cat.i.data.subcategory_id);
if(filterSource.subcategories[j]['id'] == filterSource.menu_by_cat[i].data.subcategory_id){
subcategories[filterSource.menu_by_cat.i.data.subcategory_id] = new FilterItem(filterSource.subcategories[j]['text'], filterSource.subcategories[j]['id']);
subcategories[filterSource.menu_by_cat.i.data.subcategory_id].count = 1;
break;
}
}
}
else{
subcategories[filterSource.menu_by_cat.i.data.subcategory_id].count += 1;
}
}
console.log('subs');
console.log(subcategories);
return subcategories;
}
var hasMemberPricing = function(){
var filtersource2 = JSON.parse(sessionStorage.full_menu);
for(var cat in filtersource2.menu_by_cat){
var cat_contents = filtersource2.menu_by_cat[cat];
for(var j = 0; j < cat_contents.length; j++){
var item = JSON.stringify(cat_contents[j]);
if(item.indexOf('member_quantity_prices') != -1){
return true;
}
}
}
return false;
}
var hasOnSaleProducts = function(){
var filtersource2 = JSON.parse(sessionStorage.full_menu);
for(var cat in filtersource2.menu_by_cat){
//var filtersource2 = JSON.parse(sessionStorage.full_menu);
for(var j = 0; j < filtersource2.menu_by_cat[cat].length; j++){
if(filtersource2.menu_by_cat[cat][j].data.is_on_sale_member == 1){
return true;
}
else if(filtersource2.menu_by_cat[cat][j].data.is_on_sale == 1){
return true;
}
}
}
return false;
}
var hasMedicalItems = function(menu_by_cats){
for(var cat in menu_by_cats){
for(var j = 0; j < menu_by_cats[cat].length; j++){
if(menu_by_cats[cat][j].data.medrec == 'Medical' || menu_by_cats[cat][j].data.medrec == 'Both'){
return true;
}
}
}
return false;
}
var hasRecreationalItems = function(menu_by_cats){
for(var cat in menu_by_cats){
for(var j = 0; j < menu_by_cats[cat].length; j++){
if(menu_by_cats[cat][j].data.medrec == 'Recreational' || menu_by_cats[cat][j].data.medrec == 'Both'){
return true;
}
}
}
return false;
}
this.drawFilters = async function(thc_minmax, price_minmax){
var endpoint = 'https://menustore.canname.nu/api.php';
var fd = new FormData();
fd.append('action', 'GetCategoriesArray');
var resp = await fetch(endpoint, {method: 'POST', body: fd});
var cats = await resp.json();
sessionStorage.cats = JSON.stringify(cats);
console.log('price minmax');
console.log(price_minmax)
var filter_wrapper = document.createElement('div');
filter_wrapper.className = 'filter-wrapper';
//return filter_wrapper;
var closer_row_top = document.createElement('div');
closer_row_top.className = 'cp-closer-row';
closer_row_top.style.display = 'none';
var closer = document.createElement('a');
closer.style.cursor = 'pointer';
closer.style.float = 'left';
closer.innerHTML = '×';
closer.style.textDecoration = 'none';
closer.style.fontSize = '30px';
closer.style.color = 'red';
closer.onclick = function(){
document.getElementById('cp_filter_home').style.display = 'none';
}
closer_row_top.appendChild(closer);
var search_button_top = document.createElement('button');
search_button_top.className = 'cp-search-button';
search_button_top.style.padding = '10px';
search_button_top.style.float = 'right';
search_button_top.onclick = function(){
document.getElementById('cp_filter_home').style.display = 'none';
}
var mag_glass = document.createElement('img');
mag_glass.src = SERVER_BASEURL + '/images/magnifying-glass-thin.svg';
mag_glass.style.width = '24px';
search_button_top.appendChild(document.createTextNode('Close Filters'));
//closer_row_top.appendChild(search_button_top);
filter_wrapper.appendChild(closer_row_top);
var clear_row = document.createElement('div');
clear_row.style.clear = 'both';
filter_wrapper.appendChild(clear_row);
filterSource = JSON.parse(sessionStorage.full_menu);
var medrec_wrapper = document.createElement('div');
var medrec_h3 = document.createElement('h3');
medrec_h3.appendChild(document.createTextNode('I am a: '));
medrec_wrapper.appendChild(medrec_h3);
var has_med = false;
var has_rec = false;
if(hasMedicalItems(filterSource.menu_by_cat)){
var med_wrapper = document.createElement('div');
var med_button = document.createElement('input');
med_button.type = 'checkbox';
med_button.className = 'filter-checkbox';
med_button.name = 'medrec_checkbox';
med_button.value = 'Medical';
med_button.style.marginRight = '7px';
med_button.style.display = 'inline';
med_wrapper.appendChild(med_button);
med_wrapper.appendChild(document.createTextNode(' Medical Patient '));
medrec_wrapper.appendChild(med_wrapper);
has_med = true;
}
if(hasRecreationalItems(filterSource.menu_by_cat)){
var rec_wrapper = document.createElement('div');
var rec_button = document.createElement('input');
rec_button.type = 'checkbox';
rec_button.className = 'filter-checkbox';
rec_button.name = 'medrec_checkbox';
rec_button.value = 'Recreational';
rec_button.style.marginRight = '7px';
rec_button.style.display = 'inline';
rec_wrapper.appendChild(rec_button);
rec_wrapper.appendChild(document.createTextNode(' Recreational Customer'));
medrec_wrapper.appendChild(rec_wrapper);
has_rec = true;
}
if(!has_med || !has_rec){
if(!has_med && has_med){
rec_button.disabled = true;
}
else if(!has_rec && has_med){
med_button.disabled = true;
}
}
filter_wrapper.appendChild(medrec_wrapper);
var search_wrapper = document.createElement('div');
search_wrapper.className = 'cp-search-wrapper';
var search_box = document.createElement('input');
search_box.placeholder = 'Search';
search_box.style.width = '100%';
search_box.style.marginRight = '5px';
search_box.id = 'cp_text_search';
//search_box.value = sessionStorage.search_text;
search_box.oninput = function(e){
e.preventDefault();
//sessionStorage.setItem('search_text', this.value);
main_menu.showFilteredMenu();
//this.focus();
}
search_wrapper.appendChild(search_box);
var search_button_link = document.createElement('a');
search_button_link.appendChild(mag_glass);
search_button_link.id = 'cp-search-link';
search_button_link.style.display = 'none';
search_button_link.onclick = function(){
document.getElementById('cp_filter_home').style.display = 'none';
}
search_wrapper.appendChild(search_button_link);
filter_wrapper.appendChild(search_wrapper);
var subcatz = {};
var all_subs = getSubcats();
console.log('all_subs');
console.log(all_subs);
for(var categ in all_subs){
subcatz[categ] = {};
for(var subc in all_subs[categ]){
subcatz[categ][subc] = all_subs[categ][subc];
}
}
var subs = subcatz;
//var subs = getSubcats()[1];
console.log('subsz');
console.log(subs);
var h3 = document.createElement('h3');
h3.style.marginBottom = '0px';
h3.appendChild(document.createTextNode('Subcategories'));
var subcat_open_link = document.createElement('a');
subcat_open_link.className = 'cp-menu-toggle';
subcat_open_link.appendChild(document.createTextNode(' (+)'));
subcat_open_link.style.textDecoration = 'none';
subcat_open_link.style.cursor = 'pointer';
subcat_open_link.onclick = function(){
var container = this.closest('div');
var mode_select = container.querySelector('.cp-menu-toggle');
var mode = container.querySelector('.cp-menu-toggle').innerHTML.indexOf('+') != -1 ? 'block' : 'none';
container.querySelector('.subcategories-toggle-pane').style.display = mode;
mode_select.innerHTML = 'block' == mode ? ' (-)' : ' (+)';
}
h3.appendChild(subcat_open_link);
//filter_wrapper.appendChild(h3);
var subcategories_wrapper = document.createElement('div');
//subcategories_wrapper.appendChild(h3);
subcategories_wrapper.className = 'subcategories-wrapper';
var subcategories_toggle_pane = document.createElement('div');
subcategories_toggle_pane.className = 'subcategories-toggle-pane';
//return filter_wrapper;
for(categ in subs){
var catcount = 0;
var subcat_cat_title = document.createElement('div');
var catlink = document.createElement('a');
catlink.style.color = '#000';
catlink.style.cursor = 'pointer';
catlink.style.textDecoration = 'none';
catlink.appendChild(document.createTextNode(cats[categ]));
catlink.onclick = function(){
var acc_panels = document.getElementsByClassName('accordionItem');
for(var x = 0; x < acc_panels.length; x++){
var linktext = this.innerHTML;
var tabtext = acc_panels[x].querySelector('h2').innerHTML;
if(tabtext.indexOf(linktext) != -1){
acc_panels[x].className = 'accordionItem open';
}
else{
acc_panels[x].className = 'accordionItem close';
}
}
}
subcat_cat_title.appendChild(catlink);
subcategories_toggle_pane.appendChild(subcat_cat_title);
var subcat_ul = document.createElement('ul');
subcat_ul.style.listStyleType = 'none';
subcategories_toggle_pane.appendChild(subcat_ul);
console.log('subs[categ]');
console.log(subs[categ]);
for(var i in subs[categ]){
var subcategory_wrapper = document.createElement('li');
catcount += subs[categ][i].count;
subcategory_wrapper.className = 'subcategory-wrapper';
var subcat_checkbox = document.createElement('input');
subcat_checkbox.type = 'checkbox';
subcat_checkbox.name = 'subcat_checkbox';
subcat_checkbox.value = i;
subcat_checkbox.style.marginRight = '7px';
subcat_checkbox.style.display = 'inline';
subcat_checkbox.className = 'filter-checkbox';
//subcat_checkbox.onchange = main_menu.showFilteredMenu;
var cbspan = document.createElement('span');
cbspan.appendChild(subcat_checkbox);
subcategory_wrapper.appendChild(cbspan);
//subcategory_wrapper.textContent += ' ' + subs[i].text;
var text;// = '' == subs[categ][i].text ? 'Other' : subs[categ][i].text;
if('' == subs[categ][i].text){
//text = cats[categ].indexOf('lower') != -1 ? 'Flower' : 'Other';
}
else{
subcat_ul.appendChild(subcategory_wrapper);
text = subs[categ][i].text;
text += ' (' + subs[categ][i].count + ')';
subcategory_wrapper.appendChild(document.createTextNode(ucFirst(text)));
}
//subcategories_toggle_pane.appendChild(subcategory_wrapper);
}
catlink.appendChild(document.createTextNode(' (' + catcount + ')'));
}
var ending = document.createElement('div');
ending.style.clear = 'both';
subcategories_toggle_pane.appendChild(ending);
subcategories_wrapper.appendChild(subcategories_toggle_pane);
filter_wrapper.appendChild(subcategories_wrapper);
var species_h3 = document.createElement('h3');
species_h3.style.width = '100%';
species_h3.style.clear = 'both';
species_h3.style.marginBottom = '0px';
species_h3.appendChild(document.createTextNode('Species'));
var species_open_link = document.createElement('a');
species_open_link.className = 'cp-menu-toggle';
species_open_link.appendChild(document.createTextNode(' (+)'));
species_open_link.style.textDecoration = 'none';
species_open_link.style.cursor = 'pointer';
species_open_link.onclick = function(){
var container = this.closest('div');
var mode_select = container.querySelector('.cp-menu-toggle');
var mode = container.querySelector('.cp-menu-toggle').innerHTML.indexOf('+') != -1 ? 'block' : 'none';
container.querySelector('.species-toggle-pane').style.display = mode;
mode_select.innerHTML = 'block' == mode ? ' (-)' : ' (+)';
}
species_h3.appendChild(species_open_link);
var species_toggle_pane = document.createElement('div');
species_toggle_pane.className = 'species-toggle-pane';
var specie_wrapper = document.createElement('div');
specie_wrapper.appendChild(species_h3);
specie_wrapper.className = 'specie-wrapper';
var species_arr = getSpecies();
for(var i = 0; i < species_arr.length; i++){
if(species_arr[i]){
var species_wrapper = document.createElement('div');
species_wrapper.className = 'species-wrapper';
var species_checkbox = document.createElement('input');
species_checkbox.type = 'checkbox';
species_checkbox.name = 'species_checkbox';
species_checkbox.value = species_arr[i];
species_checkbox.style.marginRight = '7px';
species_checkbox.style.display = 'inline';
species_checkbox.className = 'filter-checkbox';
//subcat_checkbox.onchange = main_menu.showFilteredMenu;
var cbspan = document.createElement('span');
cbspan.appendChild(species_checkbox);
species_wrapper.appendChild(cbspan);
//subcategory_wrapper.textContent += ' ' + subs[i].text;
var text = species_arr[i];
species_wrapper.appendChild(document.createTextNode(ucFirst(text)));
species_toggle_pane.appendChild(species_wrapper);
}
}
species_toggle_pane.appendChild(ending);
specie_wrapper.appendChild(species_toggle_pane);
filter_wrapper.appendChild(specie_wrapper);
var brand_h3 = document.createElement('h3');
brand_h3.style.width = '100%';
brand_h3.style.clear = 'both';
brand_h3.style.marginBottom = '0px';
brand_h3.appendChild(document.createTextNode('Brand'));
//filter_wrapper.appendChild(brand_h3);
var brands_toggle_pane = document.createElement('div');
brands_toggle_pane.className = 'brands-toggle-pane';
var brands_wrapper = document.createElement('div');
brands_wrapper.appendChild(brand_h3);
brands_wrapper.className = 'brands-wrapper';
var brands_open_link = document.createElement('a');
brands_open_link.className = 'cp-menu-toggle';
brands_open_link.appendChild(document.createTextNode(' (+)'));
brands_open_link.style.textDecoration = 'none';
brands_open_link.style.cursor = 'pointer';
brands_open_link.onclick = function(){
var container = this.closest('div');
var mode_select = container.querySelector('.cp-menu-toggle');
var mode = container.querySelector('.cp-menu-toggle').innerHTML.indexOf('+') != -1 ? 'block' : 'none';
container.querySelector('.brands-toggle-pane').style.display = mode;
mode_select.innerHTML = 'block' == mode ? ' (-)' : ' (+)';
}
brand_h3.appendChild(brands_open_link);
var brand_arr = get_brands();
for(var i = 0; i < brand_arr.length; i++){
if(brand_arr[i]){
var brand_wrapper = document.createElement('div');
brand_wrapper.className = 'brand-wrapper';
var brand_checkbox = document.createElement('input');
brand_checkbox.type = 'checkbox';
brand_checkbox.name = 'brand_checkbox';
brand_checkbox.value = brand_arr[i];
brand_checkbox.style.marginRight = '7px';
brand_checkbox.style.display = 'inline';
brand_checkbox.className = 'filter-checkbox';
//subcat_checkbox.onchange = main_menu.showFilteredMenu;
var cbspan = document.createElement('span');
cbspan.appendChild(brand_checkbox);
brand_wrapper.appendChild(cbspan);
//subcategory_wrapper.textContent += ' ' + subs[i].text;
var text = brand_arr[i];
brand_wrapper.appendChild(document.createTextNode(ucFirst(text)));
brands_toggle_pane.appendChild(brand_wrapper);
}
}
brands_toggle_pane.appendChild(ending);
brands_wrapper.appendChild(brands_toggle_pane);
filter_wrapper.appendChild(brands_wrapper);
var thc_h3 = document.createElement('h3');
thc_h3.style.width = '100%';
thc_h3.style.clear = 'both';
thc_h3.style.marginBottom = '0px';
thc_h3.appendChild(document.createTextNode('Min THC '));
var thc_display = document.createElement('span');
thc_display.id = 'thc_displayx';
thc_display.innerHTML = sessionStorage.thc_pct && sessionStorage.thc_pct != '0' ? sessionStorage.thc_pct : 'All';
thc_h3.appendChild(thc_display);
thc_h3.appendChild(document.createTextNode('%'));
//filter_wrapper.appendChild(thc_h3);
var thc_toggle_pane = document.createElement('div');
thc_toggle_pane.className = 'thc-toggle-pane';
var thc_wrapper = document.createElement('div');
thc_wrapper.appendChild(thc_h3);
thc_wrapper.className = 'cp-thc-wrapper';
var thc_open_link = document.createElement('a');
thc_open_link.className = 'cp-menu-toggle';
thc_open_link.appendChild(document.createTextNode(' (+)'));
thc_open_link.style.textDecoration = 'none';
thc_open_link.style.cursor = 'pointer';
thc_open_link.onclick = function(){
var container = this.closest('div');
var mode_select = container.querySelector('.cp-menu-toggle');
var mode = container.querySelector('.cp-menu-toggle').innerHTML.indexOf('+') != -1 ? 'block' : 'none';
container.querySelector('.thc-toggle-pane').style.display = mode;
mode_select.innerHTML = 'block' == mode ? ' (-)' : ' (+)';
}
thc_h3.appendChild(thc_open_link);
var thc_slider = document.createElement('input');
thc_slider.type = 'range';
//alert(thc_minmax.min);
thc_slider.min = Math.floor(thc_minmax.min);
thc_slider.max = Math.floor(thc_minmax.max);
thc_slider.style.display = 'inline'
thc_slider.value = sessionStorage.thc_pct || Math.floor(thc_minmax.min);
//thc_slider.className = 'filter-checkbox';
thc_slider.id = 'cp_thc_slider';
thc_slider.oninput = function(){
sessionStorage.thc_pct = this.value;
thc_display.innerHTML = '';
var thc_display_obj = document.getElementById('thc_displayx');
thc_display_obj.innerHTML = this.value === this.min ? 'All' : this.value;
}
thc_slider.onchange = function(){
//main_menu.showFilteredMenu();
var new_filters = document.querySelectorAll('.filters-outer input[type="checkbox"]:checked');
//console.log('new filters' + new_filters.length);
var new_filters_to_set = [];
for(var i = 0; i < new_filters.length; i++){
new_filters_to_set.push(new_filters[i].value);
}
sessionStorage.setItem('filters', JSON.stringify(new_filters_to_set));
//sessionStorage.thc_pct = sessionStorage.thc_pct || 0;
main_menu.showFilteredMenu();
thc_display.innerHTML = '';
var thc_display_obj = document.getElementById('thc_displayx');
thc_display_obj.innerHTML = this.value === this.min ? 'All' : this.value;
}
thc_toggle_pane.appendChild(thc_slider);
thc_wrapper.appendChild(thc_toggle_pane);
filter_wrapper.appendChild(thc_wrapper);
var price_h3 = document.createElement('h3');
price_h3.style.width = '100%';
price_h3.style.clear = 'both';
price_h3.style.marginBottom = '0px';
price_h3.appendChild(document.createTextNode('Max Price: $'));
var price_display = document.createElement('span');
price_display.id = 'price_display';
price_display.innerHTML = 'All';
price_h3.appendChild(price_display);
//filter_wrapper.appendChild(price_h3);
var price_toggle_pane = document.createElement('div');
price_toggle_pane.className = 'price-toggle-pane';
var price_wrapper = document.createElement('div');
price_wrapper.appendChild(price_h3)
price_wrapper.className = 'cp_price_wrapper';
var price_open_link = document.createElement('a');
price_open_link.className = 'cp-menu-toggle';
price_open_link.appendChild(document.createTextNode(' (+)'));
price_open_link.style.textDecoration = 'none';
price_open_link.style.cursor = 'pointer';
price_open_link.onclick = function(){
var container = this.closest('div');
var mode_select = container.querySelector('.cp-menu-toggle');
var mode = container.querySelector('.cp-menu-toggle').innerHTML.indexOf('+') != -1 ? 'block' : 'none';
container.querySelector('.price-toggle-pane').style.display = mode;
mode_select.innerHTML = 'block' == mode ? ' (-)' : ' (+)';
}
price_h3.appendChild(price_open_link);
var price_slider = document.createElement('input');
price_slider.type = 'range';
//alert(thc_minmax.min);
price_slider.min = 0;
price_slider.max = Math.ceil(price_minmax.max);
price_slider.value = Math.ceil(price_minmax.max);
price_slider.style.display = 'inline';
//price_slider.value = sessionStorage.price_in_range != '0' || Math.ceil(price_minmax.max);
//thc_slider.className = 'filter-checkbox';
price_slider.id = 'cp_price_slider';
price_slider.oninput = function(){
sessionStorage.price_in_range = this.value;
price_display.innerHTML = '';
var price_display_obj = document.getElementById('price_display');
price_display_obj.innerHTML = this.value;
}
price_slider.onchange = function(){
//main_menu.showFilteredMenu();
var new_filters = document.querySelectorAll('.filters-outer input[type="checkbox"]:checked');
//console.log('new filters' + new_filters.length);
var new_filters_to_set = [];
for(var i = 0; i < new_filters.length; i++){
new_filters_to_set.push(new_filters[i].value);
}
sessionStorage.setItem('filters', JSON.stringify(new_filters_to_set));
//sessionStorage.thc_pct = sessionStorage.thc_pct || 0;
main_menu.showFilteredMenu();
price_display.innerHTML = '';
var price_display_obj = document.getElementById('price_display');
price_display_obj.innerHTML = this.value === this.min ? 'All' : this.value;
}
price_toggle_pane.appendChild(price_slider);
price_wrapper.appendChild(price_toggle_pane);
filter_wrapper.appendChild(price_wrapper);
if(hasMemberPricing()){
var member_price_wrapper = document.createElement('div');
var member_price_checkbox = document.createElement('input');
member_price_checkbox.type = 'checkbox';
member_price_checkbox.id = 'cp_member_price_checkbox';
member_price_checkbox.style.marginRight = '7px';
member_price_checkbox.style.display = 'inline';
member_price_checkbox.className = 'filter-checkbox';
member_price_wrapper.appendChild(member_price_checkbox);
member_price_wrapper.appendChild(document.createTextNode('Show Member Pricing'));
filter_wrapper.appendChild(member_price_wrapper);
}
if(hasOnSaleProducts()){
var on_sale_wrapper = document.createElement('div');
var on_sale_checkbox = document.createElement('input');
on_sale_checkbox.type = 'checkbox';
on_sale_checkbox.id = 'cp_on_sale_checkbox';
on_sale_checkbox.style.marginRight = '7px';
on_sale_checkbox.style.display = 'inline';
on_sale_checkbox.className = 'filter-checkbox';
on_sale_wrapper.appendChild(on_sale_checkbox);
on_sale_wrapper.appendChild(document.createTextNode('Show Sale Items Only'));
filter_wrapper.appendChild(on_sale_wrapper);
}
var closer_row_bottom = document.createElement('div');
closer_row_bottom.className = 'cp-closer-row';
closer_row_bottom.style.display = 'block';
var search_button_bottom = search_button_top.cloneNode(true);
search_button_bottom.onclick = function(){
document.getElementById('cp_filter_home').style.display = 'none';
}
closer_row_bottom.appendChild(search_button_bottom);
//filter_wrapper.appendChild(closer_row_bottom);
return filter_wrapper;
}
var thiss = this;
}
function FilterItem(item_text, id){
this.count = 0;
this.text = item_text;
this.id = id;
}
var main_menu = null;
var thc_slider_minmax = null;
var price_slider_minmax = null;
var adilas_store_id = '357';
window.addEventListener('resize', function(event) {
var accordion = document.getElementById('cp_menu_home');
var menu_is_visible = (accordion.offsetWidth > 0 || accordion.offsetHeight > 0) && (!document.getElementById('cart_div') || document.getElementById('cart_div').style.display == 'none');
if(document.getElementById("cannamenu-div").offsetWidth > 674 && menu_is_visible){
document.getElementById('cp_filter_home').style.setProperty('display', 'block', 'important');
}
else{
//document.getElementById('cp_filter_home').style.setProperty('display', 'none', 'important');
}
//document.getElementById('cp_filter_home').style.display = 'block';
}, true);
function CannaMenu(){
this.dispensaryId = 'val-1452';
this.endpoint = 'https://menustore.canname.nu/api.php';
this.showDefaultMenu = async function(){
var fd = new FormData();
fd.append('action', 'ShowMenu');
fd.append('disp_id', this.dispensaryId);
fd.append('store_id', adilas_store_id);
var resp = await fetch(this.endpoint, {method: 'POST', body: fd});
var menu = await resp.json();
sessionStorage.full_menu = JSON.stringify(menu);
sessionStorage.disp_hash = menu.disp_hash;
var fd = new FormData();
fd.append('action', 'GetEstTaxRate');
fd.append('login_key', this.dispensaryId);
var resp = await fetch(this.endpoint, {method: 'POST', body: fd});
sessionStorage.est_tax_rate = await resp.json() * .01;
var renderedMenu = this.renderMenu(menu);
cannamenu_div.innerHTML = '';
cannamenu_div.className = 'canna_ecommerce_wrapper';
document.getElementById('cannamenu-div').onresize = function() {
alert('resize');
const content_panels2 = document.getElementsByClassName('accordionItemContent');
for (var z = 0; z < content_panels2.length; z++) {
var nav_arrow_left = document.createElement('a');
nav_arrow_left.className = 'cp-nav-arrow-left';
nav_arrow_left.style.borderRadius = '50%';
nav_arrow_left.style.position = 'absolute';
nav_arrow_left.style.top = '50%';
nav_arrow_left.style.left = '-15px';
nav_arrow_left.style.background = '#000';
nav_arrow_left.style.color = '#fff';
nav_arrow_left.style.padding = '10px 15px';
nav_arrow_left.style.fontSize = '32px';
nav_arrow_left.style.fontWeight = '500';
nav_arrow_left.style.textDecoration = 'none';
nav_arrow_left.style.cursor = 'pointer';
nav_arrow_left.onclick = function () {
var outer_div = this.closest('div');
outer_div.querySelector('div').scrollLeft = outer_div.querySelector('div').scrollLeft - 220;
}
nav_arrow_left.appendChild(document.createTextNode('<'));
var nav_arrow_right = document.createElement('a');
nav_arrow_right.className = 'cp-nav-arrow-right';
nav_arrow_right.style.borderRadius = '50%';
nav_arrow_right.style.position = 'absolute';
nav_arrow_right.style.top = '50%';
nav_arrow_right.style.right = '-15px';
nav_arrow_right.style.background = '#000';
nav_arrow_right.style.color = '#fff';
nav_arrow_right.style.padding = '10px 15px';
nav_arrow_right.style.fontSize = '32px';
nav_arrow_right.style.fontWeight = '500';
nav_arrow_right.style.textDecoration = 'none';
nav_arrow_right.style.cursor = 'pointer';
nav_arrow_right.onclick = function () {
//alert('rt scroll')
//this.closest('div').style.background = 'red';;
var outer_div = this.closest('div');
outer_div.querySelector('div').scrollLeft = outer_div.querySelector('div').scrollLeft + 220;
//this.style.right = '-15px';
}
nav_arrow_right.appendChild(document.createTextNode('>'));
if (content_panels2[z].clientWidth < content_panels2[z].scrollWidth) {
content_panels2[z].closest('.content-panel-wrapper').appendChild(nav_arrow_left);
content_panels2[z].closest('.content-panel-wrapper').appendChild(nav_arrow_right);
}
}
}
var style = document.createElement('style');
var styles = menu.styles;
style.appendChild(document.createTextNode(styles));
cannamenu_div.appendChild(style);
var filter_home = document.createElement('div');
filter_home.id = 'cp_filter_home';
cannamenu_div.appendChild(filter_home);
console.log('price)')
console.log(getSliderMinmax(menu, 'price').max);
renderedMenu.id = 'canna_menu';
var menu_home = document.createElement('div');
menu_home.id = 'cp_menu_home';
menu_home.appendChild(renderedMenu);
cannamenu_div.appendChild(menu_home);
var clear_div = document.createElement('div');
clear_div.style.clear = 'both';
cannamenu_div.appendChild(clear_div);
getSliderMinmax(menu, 'thc');
this.setupFilters(thc_slider_minmax, getSliderMinmax(menu, 'price'));
//this.setupAccordion(thc_slider_minmax, getSliderMinmax(menu, 'price'));
cart = new CpCart();
cart.wireMenuPage();
var content_panels = document.getElementsByClassName('accordionItemContent');
for(var z = 0; z < content_panels.length; z++){
var nav_arrow_left = document.createElement('a');
nav_arrow_left.className = 'cp-nav-arrow-left';
nav_arrow_left.style.borderRadius = '50%';
nav_arrow_left.style.position = 'absolute';
nav_arrow_left.style.top = '50%';
nav_arrow_left.style.left = '-15px';
nav_arrow_left.style.background = '#000';
nav_arrow_left.style.color = '#fff';
nav_arrow_left.style.padding = '10px 15px';
nav_arrow_left.style.fontSize = '32px';
nav_arrow_left.style.fontWeight = '500';
nav_arrow_left.style.textDecoration = 'none';
nav_arrow_left.style.cursor = 'pointer';
nav_arrow_left.onclick = function(){
var outer_div = this.closest('div');
outer_div.querySelector('div').scrollLeft = outer_div.querySelector('div').scrollLeft - 220;
}
nav_arrow_left.appendChild(document.createTextNode('<'));
var nav_arrow_right = document.createElement('a');
nav_arrow_right.className = 'cp-nav-arrow-right';
nav_arrow_right.style.borderRadius = '50%';
nav_arrow_right.style.position = 'absolute';
nav_arrow_right.style.top = '50%';
nav_arrow_right.style.right = '-15px';
nav_arrow_right.style.background = '#000';
nav_arrow_right.style.color = '#fff';
nav_arrow_right.style.padding = '10px 15px';
nav_arrow_right.style.fontSize = '32px';
nav_arrow_right.style.fontWeight = '500';
nav_arrow_right.style.textDecoration = 'none';
nav_arrow_right.style.cursor = 'pointer';
nav_arrow_right.onclick = function(){
//alert('rt scroll')
//this.closest('div').style.background = 'red';;
var outer_div = this.closest('div');
outer_div.querySelector('div').scrollLeft = outer_div.querySelector('div').scrollLeft + 220;
//this.style.right = '-15px';
}
nav_arrow_right.appendChild(document.createTextNode('>'));
if(content_panels[z].clientWidth < content_panels[z].scrollWidth){
content_panels[z].closest('.content-panel-wrapper').appendChild(nav_arrow_left);
content_panels[z].closest('.content-panel-wrapper').appendChild(nav_arrow_right);
}
}
};
respondToVisibility = function(element, callback) {
var options = {
root: document.documentElement
}
var observer = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
callback(entry.intersectionRatio > 0);
});
}, options);
observer.observe(element);
}
respondToVisibility(document.getElementById("cannamenu-div"), visible => {
if(visible) {
var panels = document.getElementsByClassName('accordionItemContent');
for(var z = 0; z < panels.length; z++){
var nav_arrow_left = document.createElement('a');
nav_arrow_left.className = 'cp-nav-arrow-left';
nav_arrow_left.style.borderRadius = '50%';
nav_arrow_left.style.position = 'absolute';
nav_arrow_left.style.top = '50%';
nav_arrow_left.style.left = '-15px';
nav_arrow_left.style.background = '#000';
nav_arrow_left.style.color = '#fff';
nav_arrow_left.style.padding = '10px 15px';
nav_arrow_left.style.fontSize = '32px';
nav_arrow_left.style.fontWeight = '500';
nav_arrow_left.style.textDecoration = 'none';
nav_arrow_left.style.cursor = 'pointer';
nav_arrow_left.onclick = function(){
var outer_div = this.closest('div');
outer_div.querySelector('div').scrollLeft = outer_div.querySelector('div').scrollLeft - 220;
}
nav_arrow_left.appendChild(document.createTextNode('<'));
var nav_arrow_right = document.createElement('a');
nav_arrow_right.className = 'cp-nav-arrow-right';
nav_arrow_right.style.borderRadius = '50%';
nav_arrow_right.style.position = 'absolute';
nav_arrow_right.style.top = '50%';
nav_arrow_right.style.right = '-15px';
nav_arrow_right.style.background = '#000';
nav_arrow_right.style.color = '#fff';
nav_arrow_right.style.padding = '10px 15px';
nav_arrow_right.style.fontSize = '32px';
nav_arrow_right.style.fontWeight = '500';
nav_arrow_right.style.textDecoration = 'none';
nav_arrow_right.style.cursor = 'pointer';
nav_arrow_right.onclick = function(){
//alert('rt scroll')
//this.closest('div').style.background = 'red';;
var outer_div = this.closest('div');
outer_div.querySelector('div').scrollLeft = outer_div.querySelector('div').scrollLeft + 220;
//this.style.right = '-15px';
}
nav_arrow_right.appendChild(document.createTextNode('>'));
if(panels[z].clientWidth < panels[z].scrollWidth){
panels[z].closest('.content-panel-wrapper').appendChild(nav_arrow_left);
panels[z].closest('.content-panel-wrapper').appendChild(nav_arrow_right);
}
}
}
});
var getItemPricingMinMax = function(pricing){
if(null == pricing) return false;
var price_arr = [];
if(typeof pricing.single_quantity_prices != 'undefined'){
for(var i = 0; i < pricing.single_quantity_prices.length; i++){
price_arr.push(pricing.single_quantity_prices[i].price);
}
return {min: Math.min(...price_arr), max: Math.max(...price_arr)};
}
if(typeof pricing.member_quantity_prices != 'undefined'){
if((typeof localStorage.getItem('show_member_pricing') != 'undefined' && localStorage.getItem('show_member_pricing') != 'false') || typeof pricing.nonmember_quantity_prices == 'undefined'){
for(var i = 0; i < pricing.member_quantity_prices.length; i++){
price_arr.push(pricing.member_quantity_prices[i].price);
}
//alert('returning member');
return {min: Math.min(...price_arr), max: Math.max(...price_arr)};
}
else{
for(var i = 0; i < pricing.nonmember_quantity_prices.length; i++){
price_arr.push(pricing.nonmember_quantity_prices[i].price);
}
//alert('returning nonmember');
return {min: Math.min(...price_arr), max: Math.max(...price_arr)};
}
}
};
var getSliderMinmax = function(menu, type, return_value){
if(!type) return false;
var menu_by_cat = menu.menu_by_cat;
var values_arr = [];
switch(type){
case 'thc':
for(var cat in menu_by_cat){
for(var i = 0; i < menu_by_cat[cat].length; i++){
if(-1 == menu_by_cat[cat][i].data.thc_pct){
continue;
}
values_arr.push(parseFloat(menu_by_cat[cat][i].data.thc_pct));
}
}
if(return_value){
return {min: Math.min(...values_arr), max: Math.max(...values_arr)};
}
thc_slider_minmax = {min: Math.min(...values_arr), max: Math.max(...values_arr)};
break;
case 'price':
for(var cat in menu_by_cat){
for(var i = 0; i < menu_by_cat[cat].length; i++){
var pricing = menu_by_cat[cat][i].data.pricing;
var itemMinMax = getItemPricingMinMax(pricing);
//alert(JSON.stringify(itemMinMax));
values_arr.push(itemMinMax.min);
values_arr.push(itemMinMax.max);
}
}
price_slider_minmax = {min: Math.min(...values_arr), max: Math.max(...values_arr)};
return {min: Math.min(...values_arr), max: Math.max(...values_arr)};
break;
}
};
this.showFilteredMenu = function(){
//alert('filters');
var filters = new CpFilters();
var menu = filters.applyFilters();
console.log('menu');
console.log(menu);
var style = document.createElement('style');
var styles = menu.styles;
style.appendChild(document.createTextNode(styles));
//cannamenu_div.appendChild(style);
var renderedMenu = thiss.renderMenu(menu);
//cannamenu_div.innerHTML = '';
//cannamenu_div.appendChild(style);
//cannamenu_div.className = 'canna_ecommerce_wrapper';
renderedMenu.id = 'canna_menu';
//cannamenu_div.appendChild(renderedMenu);
var menu_div = document.getElementById('cp_menu_home');
menu_div.innerHTML = '';
menu_div.appendChild(renderedMenu);
thiss.setupAccordion(thc_slider_minmax, price_slider_minmax, true);
cart = new CpCart();
cart.wireMenuPage();
var content_panels = document.getElementsByClassName('accordionItemContent');
for(var z = 0; z < content_panels.length; z++){
var nav_arrow_left = document.createElement('a');
nav_arrow_left.className = 'cp-nav-arrow-left';
nav_arrow_left.style.borderRadius = '50%';
nav_arrow_left.style.position = 'absolute';
nav_arrow_left.style.top = '50%';
nav_arrow_left.style.left = '-15px';
nav_arrow_left.style.background = '#000';
nav_arrow_left.style.color = '#fff';
nav_arrow_left.style.padding = '10px 15px';
nav_arrow_left.style.fontSize = '32px';
nav_arrow_left.style.fontWeight = '500';
nav_arrow_left.style.textDecoration = 'none';
nav_arrow_left.style.cursor = 'pointer';
nav_arrow_left.onclick = function(){
var outer_div = this.closest('div');
outer_div.querySelector('div').scrollLeft = outer_div.querySelector('div').scrollLeft - 220;
}
nav_arrow_left.appendChild(document.createTextNode('<'));
var nav_arrow_right = document.createElement('a');
nav_arrow_right.className = 'cp-nav-arrow-right';
nav_arrow_right.style.borderRadius = '50%';
nav_arrow_right.style.position = 'absolute';
nav_arrow_right.style.top = '50%';
nav_arrow_right.style.right = '-15px';
nav_arrow_right.style.background = '#000';
nav_arrow_right.style.color = '#fff';
nav_arrow_right.style.padding = '10px 15px';
nav_arrow_right.style.fontSize = '32px';
nav_arrow_right.style.fontWeight = '500';
nav_arrow_right.style.textDecoration = 'none';
nav_arrow_right.style.cursor = 'pointer';
nav_arrow_right.onclick = function(){
//alert('rt scroll')
//this.closest('div').style.background = 'red';;
var outer_div = this.closest('div');
outer_div.querySelector('div').scrollLeft = outer_div.querySelector('div').scrollLeft + 220;
//this.style.right = '-15px';
}
nav_arrow_right.appendChild(document.createTextNode('>'));
if(content_panels[z].clientWidth < content_panels[z].scrollWidth){
content_panels[z].closest('.content-panel-wrapper').appendChild(nav_arrow_left);
content_panels[z].closest('.content-panel-wrapper').appendChild(nav_arrow_right);
}
}
}
var hasMemberPricing = function(menu_by_cats){
var filtersource2 = JSON.parse(sessionStorage.full_menu);
for(var cat in filtersource2.menu_by_cat){
var cat_contents = filtersource2.menu_by_cat[cat];
for(var j = 0; j < cat_contents.length; j++){
var item = JSON.stringify(cat_contents[j]);
if(item.indexOf('member_quantity_prices') != -1){
return true;
}
}
}
return false;
}
var hasOnSaleProducts = function(menu_by_cats, member_only){
var filtersource2 = JSON.parse(sessionStorage.full_menu);
for(var cat in filtersource2.menu_by_cat){
var filtersource2 = JSON.parse(sessionStorage.full_menu);
for(var j = 0; j < filtersource2.menu_by_cat[cat].length; j++){
if(member_only){
if(filtersource2.menu_by_cat[cat][j].data.is_on_sale_member == 1){
return true;
}
}
else{
if(filtersource2.menu_by_cat[cat][j].data.is_on_sale == 1){
return true;
}
}
}
}
return false;
}
var renderPricing = function(pricing, uom, show_member_pricing){
var price_src = false;
if(typeof pricing.single_quantity_prices != 'undefined'){
price_src = pricing.single_quantity_prices;
}
else if(typeof pricing.member_quantity_prices != 'undefined'){
if(show_member_pricing){
price_src = pricing.member_quantity_prices;
}
else{
if(typeof pricing.nonmember_quantity_prices != 'undefined'){
price_src = pricing.nonmember_quantity_prices
}
else{
price_src = 'members_only';
}
}
}
return price_src;
}
this.renderMenu = function(menu_by_categories){
var menu_wrapper = document.createElement('div');
menu_wrapper.className = 'menu-wrapper';
var view_cart_div = document.createElement('div');
view_cart_div.style.position = 'relative';
view_cart_div.style.padding = '5px';
//view_cart_div.style.textAlign = 'right';
var view_cart_link = document.createElement('a');
view_cart_link.style.cursor = 'pointer';
view_cart_link.className = 'cp-view-cart';
view_cart_link.style.float = 'right';
//view_cart_link.appendChild(document.createTextNode('View Cart'));
var cart_image = document.createElement('img');
cart_image.src = SERVER_BASEURL + '/images/cart-shopping-solid.svg';
cart_image.style.width = '20px';
cart_image.alt = 'View Cart';
cart_image.title = 'View Cart';
const cart_counter_display = document.createElement('div');
cart_counter_display.id = 'cp_cart_counter_display';
cart_counter_display.style.lineHeight = '12px';
cart_counter_display.style.marginLeft = '3px';
cart_counter_display.innerHTML = '0';
const cart_counter = document.createElement('div');
cart_counter.style.position = 'absolute';
cart_counter.style.clear = 'both';
cart_counter.style.top = '-5px';
cart_counter.style.right = '0px';
cart_counter.style.height = '14px';
cart_counter.style.minWidth = '14px';
cart_counter.style.fontSize = '12px';
cart_counter.style.borderRadius = '50%';
cart_counter.style.background = 'green';
cart_counter.style.color = '#fff';
cart_counter.id = 'cp_cart_counter';
//cart_counter.innerHTML = '0';
cart_counter.appendChild(cart_counter_display);
view_cart_link.appendChild(cart_counter);
view_cart_link.appendChild(cart_image);
var show_filter_span = document.createElement('span');
show_filter_span.className = 'cp-show-filter-span';
show_filter_span.style.display = 'none';
show_filter_span.position = 'absolute';
show_filter_span.style.left = '5px';
var show_filter_icon = document.createElement('img');
show_filter_icon.style.width = '20px';
show_filter_icon.src = SERVER_BASEURL + '/images/bars-filter-solid.svg';
show_filter_icon.alt = 'Filter Results';
show_filter_icon.title = 'Filter Results';
var show_filter_link = document.createElement('a');
show_filter_link.style.cursor = 'pointer';
show_filter_link.onclick = function(){
document.getElementById('cp_filter_home').style.setProperty('display', 'block', 'important');
}
show_filter_link.appendChild(show_filter_icon);
show_filter_span.appendChild(show_filter_link);
view_cart_div.appendChild(show_filter_span);
view_cart_link.appendChild(cart_image);
view_cart_div.appendChild(view_cart_link);
menu_wrapper.appendChild(view_cart_div);
var filters_outer = document.createElement('div');
filters_outer.className = 'filters-outer';
menu_wrapper.appendChild(filters_outer);
/*if(hasMemberPricing(menu_by_categories.menu_by_cat)){
var member_price_wrapper = document.createElement('div');
var member_price_checkbox = document.createElement('input');
member_price_checkbox.type = 'checkbox';
member_price_checkbox.style.marginRight = '7px';
member_price_checkbox.style.display = 'inline';
member_price_checkbox.className = 'filter-checkbox';
if('member' == localStorage.getItem('show_member_pricing')){
member_price_checkbox.checked = true;
}
member_price_checkbox.onchange = function(){
if(this.checked){
localStorage.setItem('show_member_pricing', 'member');
}
else{
localStorage.setItem('show_member_pricing', 'false');
}
thiss.showFilteredMenu();
}
member_price_wrapper.appendChild(member_price_checkbox);
member_price_wrapper.appendChild(document.createTextNode('Show Member Pricing'));
menu_wrapper.appendChild(member_price_wrapper);
}
if(localStorage.show_member_pricing == 'member'){
var mem = true;
}
else{
var mem = false;
}
if(hasOnSaleProducts(menu_by_categories.menu_by_cat, mem)){
var on_sale_wrapper = document.createElement('div');
var on_sale_checkbox = document.createElement('input');
on_sale_checkbox.type = 'checkbox';
on_sale_checkbox.style.marginRight = '7px';
on_sale_checkbox.style.display = 'inline';
on_sale_checkbox.className = 'filter-checkbox';
if(sessionStorage.show_on_sale == 'member' && mem){
on_sale_checkbox.checked = true;
}
else if(sessionStorage.show_on_sale == 'nonmember' && !mem){
on_sale_checkbox.checked = true;
}
on_sale_checkbox.onchange = function(){
if(this.checked){
if(mem){
sessionStorage.setItem('show_on_sale', 'member');
}
else{
sessionStorage.setItem('show_on_sale', 'nonmember');
}
}
else{
sessionStorage.setItem('show_on_sale', 'false');
}
thiss.showFilteredMenu();
};
on_sale_wrapper.appendChild(on_sale_checkbox);
on_sale_wrapper.appendChild(document.createTextNode('Show Sale Items Only'));
menu_wrapper.appendChild(on_sale_wrapper);
}*/
var accordion_wrapper = document.createElement('div');
accordion_wrapper.className = 'accordionWrapper';
var first = true;
//menu_by_categories.menu_by_cat.forEach(function(i, v){
var item_count = 0;
for(i in menu_by_categories.menu_by_cat){
var vx = menu_by_categories.menu_by_cat[i];
//console.log(vx);
var cat = document.createElement('div');
//cat.className = first ? 'accordionItem open' : 'accordionItem close';
cat.className = 'accordionItem open'
var h2 = document.createElement('h2');
h2.dataset.category_id = i;
h2.className = 'accordionItemHeading';
h2.appendChild(document.createTextNode(menu_by_categories.categories[i] + ' (' + vx.length + ')'));
cat.appendChild(h2);
var content_panel = document.createElement('div');
content_panel.style.maxHeight = '600px';
//content_panel.style.overflowY = 'scroll';
content_panel.className = 'accordionItemContent';
content_panel.style.position = 'relative';
first = false;
for(var j = 0; j < vx.length; j++){
if(null == vx[j].data.pricing){
continue;
}
var item = document.createElement('div');
item.className = 'menu-item';
item.style.position = 'relative';
/*var item_table = document.createElement('table');
item_table.style.background = '#fff';
item_table.style.width = '100%';
var item_tr = document.createElement('tr');
item_tr.style.background = '#fff';
var img_cell = document.createElement('td');
img_cell.style.width = '135px';*/
console.log(vx[j].data.pricing);
if(typeof vx[j].data.pricing.member_quantity_prices != 'undefined' && typeof vx[j].data.pricing.nonmember_quantity_prices == 'undefined'){
continue;
}
var member_pricing = document.getElementById('cp_member_price_checkbox') || false;
var pricing_mode = member_pricing && member_pricing.checked ? 'member' : 'regular';
if(('1' == vx[j].data.is_on_sale && 'regular' == pricing_mode) || ('1' == vx[j].data.is_on_sale_member && 'member' == pricing_mode)){
var on_sale_span = document.createElement('span');
on_sale_span.style.background = 'red';
on_sale_span.style.color = 'white';
on_sale_span.style.padding = '0px 7px';
on_sale_span.style.position = 'absolute';
on_sale_span.style.top = '-1px';
on_sale_span.style.left = '-1px';
on_sale_span.style.zIndex = '10';
on_sale_span.style.borderRadius = '10px 0px 0px 0px';
on_sale_span.appendChild(document.createTextNode('SALE'));
item.appendChild(on_sale_span);
item.classList.add('sale-item');
}
var img_wrapper = document.createElement('div');
img_wrapper.style.width = '135px';
img_wrapper.style.padding = '5px';
img_wrapper.style.float = 'left';
img_wrapper.className = 'thumb-wrapper';
var img_link = document.createElement('a');
img_link.href = '#holder';
var thumb = document.createElement('img');
thumb.dataset.cat_name = vx[j].data.cat_name;
thumb.dataset.subcat_name = vx[j].data.subcategory_name;
thumb.className = 'cp-cart-thumb';
//console.log(vx[j]);
thumb.src = vx[j].thumb_url;
thumb.onerror = function(){
var thiss = this;
this.onerror = null;
if('' != this.dataset.subcat_name){
this.src = 'https://menuserver.canname.nu/images/' + this.dataset.subcat_name.toLowerCase() + '_default.jpg';
}
else if('' != this.dataset.cat_name){
this.src = 'https://menuserver.canname.nu/images/' + this.dataset.cat_name.toLowerCase() + '_default.jpg';
}
else{
this.src = 'https://menuserver.canname.nu/default.jpg';
}
this.onerror = function(){
this.src = 'https://menuserver.canname.nu/images/' + this.dataset.cat_name.toLowerCase() + '_default.jpg';
this.onerror = function(){
this.src = 'https://menuserver.canname.nu/default.jpg';
}
}
this.style.width = '125px';
this.style.border = '1pt solid #ccc';
};
//img_link.appendChild(thumb);
img_wrapper.appendChild(thumb);
item.appendChild(img_wrapper);
//img_cell.appendChild(img_wrapper);
//item_tr.appendChild(img_cell)
//var meta_cell = document.createElement('td');
var meta_wrapper = document.createElement('div');
meta_wrapper.clear = 'both';
meta_wrapper.marginLeft = '136px';
meta_wrapper.className = 'meta-wrapper';
var product_name_wrapper = document.createElement('div');
product_name_wrapper.className = 'product-name-wrapper';
product_name_wrapper.style.lineHeight = '110%';
var name_padding = '';
if(vx[j].data.name.length < 30){
const pad_length = 35 - vx[j].data.name.length;
for(var i = 0; i < pad_length; i++){
name_padding += ' ';
}
}
product_name_wrapper.innerHTML = vx[j].data.name + ' ' + name_padding;
meta_wrapper.appendChild(product_name_wrapper);
if(vx[j].data.cat_name && vx[j].data.cat_name.length){
var subcategory_name_wrapper = document.createElement('div');
subcategory_name_wrapper.className = 'subcategory-name-wrapper';
subcategory_name_wrapper.style.fontSize = '13px';
subcategory_name_wrapper.style.fontWeight = '600';
subcategory_name_wrapper.appendChild(document.createTextNode(vx[j].data.cat_name));
if('' != vx[j].data.subcategory_name){
subcategory_name_wrapper.appendChild(document.createTextNode(' - ' + vx[j].data.subcategory_name));
}
}
var brand_wrapper = document.createElement('div');
brand_wrapper.className = 'brand-wrapper';
brand_wrapper.style.fontStyle = 'italic';
brand_wrapper.innerHTML = vx[j].data.brand.length ? vx[j].data.brand : ' ';
meta_wrapper.appendChild(brand_wrapper);
meta_wrapper.appendChild(subcategory_name_wrapper);
if(vx[j].data.species){
var species_wrapper = document.createElement('div');
species_wrapper.className = 'species-wrapper';
species_wrapper.appendChild(document.createTextNode(ucFirst(vx[j].data.species)));
}
else{
var species_wrapper = document.createElement('div');
species_wrapper.className = 'species-wrapper';
species_wrapper.innerHTML = ' ';
}
meta_wrapper.appendChild(species_wrapper);
var price_wrapper = document.createElement('div');
price_wrapper.className = 'price-wrapper';
var quantity_select = document.createElement('select');
quantity_select.className = 'add-to-cart-quantity';
quantity_select.style.width = '40px';
quantity_select.style.padding = '0px';
for(var q = 1; q <= 5; q++){
var opt = document.createElement('option');
opt.value = q;
opt.appendChild(document.createTextNode(q));
quantity_select.appendChild(opt);
}
var member_pricing = document.getElementById('cp_member_price_checkbox') || false;
var pricing_mode = member_pricing && member_pricing.checked ? 'member' : 'regular';
var show_member_pricing = false;
if(pricing_mode == 'member'){
show_member_pricing = true
}
var personalized_pricing = renderPricing(vx[j].data.pricing, vx[j].data.uom, show_member_pricing);
if('member_only' == personalized_pricing){
price_wrapper.appendChild(document.createTextNode('Members Only'));
}
else{
price_wrapper.appendChild(quantity_select);
if(personalized_pricing.length > 1){
var uom = vx[j].data.pricing.uom;
var raw_tiers = personalized_pricing;
// Build a select
var tier_select = document.createElement('select');
tier_select.className = 'tier-select';
for(var k = 0; k < raw_tiers.length; k++){
var opt_text = raw_tiers[k].size + uom + ' $' + raw_tiers[k].price;
var opt_value = raw_tiers[k].size + ':' + uom + ':' + raw_tiers[k].price;
var opt = document.createElement('option');
opt.value = opt_value;
opt.appendChild(document.createTextNode(opt_text));
tier_select.appendChild(opt);
}
price_wrapper.appendChild(tier_select);
if(typeof price_wrapper.dataset.size_uom_price == 'undefined'){
price_wrapper.dataset.size_uom_price = tier_select.value;
//alert('undefinedx');
}
tier_select.onchange = function(){
price_wrapper.setAttribute('data-size_uom_price', this.value);
//price_wrapper.dataset.size_uom_price = this.value;
//alert(price_wrapper.dataset.size_uom_price);
}
}
else{
var single_price = personalized_pricing[0];
var uom = vx[j].data.pricing.uom;
var price_text = ' ' + single_price.size + ' ' + uom + ' $' + single_price.price + ' ';
price_wrapper.appendChild(document.createTextNode(price_text));
price_wrapper.dataset.size_uom_price = single_price.size + ':' + uom + ':' + single_price.price;
}
}
var add_button = document.createElement('button');
add_button.className = 'add-to-cart-button';
add_button.style.padding = '0px';
add_button.dataset.dispensary_id = vx[j].data.dispensary_hash;
add_button.dataset.product_pos_id = vx[j].data.product_pos_id;
add_button.dataset.thumb_url = vx[j].thumb_url;
add_button.dataset.item_name = vx[j].data.name;
add_button.dataset.part_category_id = vx[j].data.part_category_id;
add_button.dataset.tax_category_id = vx[j].data.tax_category_id;
add_button.dataset.vendor_payee_id = vx[j].data.vendor_payee_id;
add_button.dataset.uom_id = vx[j].data.uom_id;
add_button.dataset.subcategory_name = vx[j].data.subcategory_name;
add_button.dataset.cat_name = vx[j].data.cat_name;
add_button.appendChild(document.createTextNode('Add'));
price_wrapper.appendChild(add_button);
/*meta_cell.appendChild(meta_wrapper);
item_tr.appendChild(meta_cell);
item_table.appendChild(item_tr);*/
item.appendChild(meta_wrapper);
if(-1 == vx[j].data.thc_pct && -1 == vx[j].data.cbd_pct){
var potency_wrapper = document.createElement('div');
potency_wrapper.className = 'potency-wrapper';
potency_wrapper.innerHTML = ' ';
}
else{
var potency_wrapper = document.createElement('div');
potency_wrapper.className = 'potency-wrapper';
var thc_potency_text = '';
var cbd_potency_text = '';
if(-1 != vx[j].data.thc_pct){
thc_potency_text = 'THC: ' + vx[j].data.thc_pct + '%';
}
if(-1 != vx[j].data.cbd_pct){
cbd_potency_text = 'CBD: ' + vx[j].data.cbd_pct + '%';
}
var potency_text = thc_potency_text + ' ' + cbd_potency_text;
//var potency_text = 'THC: ' + vx[j].data.thc_pct + '% CBD: ' + vx[j].data.cbd_pct + '%';
potency_wrapper.appendChild(document.createTextNode(potency_text));
potency_wrapper.style.width = '100%';
}
item.appendChild(potency_wrapper);
item.appendChild(price_wrapper);
var description_wrapper = document.createElement('div');
description_wrapper.style.clear = 'both';
description_wrapper.style.fontSize = 'small';
description_wrapper.className = 'cp-description';
var description_source = vx[j].data.description || '';
if(description_source.length > 30){
var description_main_text = description_source.substr(0, 20);
var description_extended_text = description_source;
}
else{
var description_main_text = description_source;
var description_extended_text = false;
}
description_wrapper.appendChild(document.createTextNode(description_main_text));
if(description_extended_text){
var more_link = document.createElement('a');
more_link.style.cursor = 'pointer';
more_link.dataset.description = description_extended_text;
more_link.dataset.title = vx[j].data.name;
more_link.onclick = function(){
var position_div = this.closest('.menu-item');
var popup = document.createElement('div');
popup.className = 'more-popup';
popup.style.borderRadius = '10px';
popup.style.padding = '20px';
popup.style.zIndex = '10001';
popup.style.backgroundColor = '#fff';
popup.style.lineHeight = '120%';
popup.style.fontSize = 'small';
popup.style.top = '0';
popup.style.right = '0';
popup.style.bottom = '0';
popup.style.left = '0';
popup.style.position = 'absolute';
popup.appendChild(document.createTextNode(this.dataset.description));
var close_more_button_wrapper = document.createElement('div');
close_more_button_wrapper.className = 'close-more-button-wrapper';
close_more_button_wrapper.style.height = '60px';
close_more_button_wrapper.style.textAlign = 'center';
close_more_button_wrapper.style.position = 'absolute';
close_more_button_wrapper.style.bottom = '0';
close_more_button_wrapper.style.right = '0';
close_more_button_wrapper.style.left = '0';
var close_more_button = document.createElement('button');
close_more_button.className = 'close-more-button';
close_more_button.appendChild(document.createTextNode('Close'));
close_more_button.style.margin = '0 auto';
close_more_button.onclick = function(){
this.closest('.more-popup').remove();
}
close_more_button_wrapper.appendChild(close_more_button);
popup.appendChild(close_more_button_wrapper);
position_div.appendChild(popup);
//cpInfowindow(this.dataset.title, '' + this.dataset.description + '');
};
more_link.appendChild(document.createTextNode('...more'));
description_wrapper.appendChild(more_link);
}
item.appendChild(description_wrapper);
content_panel.appendChild(item);
}
var content_panel_wrapper = document.createElement('div');
content_panel_wrapper.className = 'content-panel-wrapper';
content_panel_wrapper.style.position = 'relative';
content_panel_wrapper.appendChild(content_panel);
var content_panel_outer_wrapper = document.createElement('div');
content_panel_outer_wrapper.style.overflow = 'hidden';
content_panel_outer_wrapper.appendChild(content_panel_wrapper)
cat.appendChild(content_panel_outer_wrapper);
//alert(content_panel.clientWidth + ' - ' + content_panel.scrollWidth);
accordion_wrapper.appendChild(cat);
item_count++;
};
if(!item_count){
menu_wrapper.appendChild(document.createTextNode('No items match your search'));
}
else{
menu_wrapper.appendChild(accordion_wrapper);
}
return menu_wrapper;
}
this.renderMenu2 = function(menu_by_categories){
/*var menu_wrapper = document.createElement('div');
menu_wrapper.appendChild(document.createTextNode('this is where the menu renders'));
return menu_wrapper;*/
var accordion_wrapper = document.createElement('div');
accordion_wrapper.className = 'accordionWrapper';
var first_item = document.createElement('div');
//first_item.className = 'accordionItem open';
var first = true;
for(const key in menu_by_categories.items){
var cat = document.createElement('div');
cat.className = first ? 'accordionItem open' : 'accordionItem close';
var h2 = document.createElement('h2');
h2.className = 'accordionItemHeading';
h2.appendChild(document.createTextNode(key));
cat.appendChild(h2);
var content_panel = document.createElement('div');
content_panel.className = 'accordionItemContent';
first = false;
console.log(menu_by_categories.items[key]);
for(var i = 0; i < menu_by_categories.items[key].length; i++){
var item = document.createElement('div');
item.className = 'menu-item';
var img_wrapper = document.createElement('div');
img_wrapper.className = 'thumb-wrapper';
var img_link = document.createElement('a');
img_link.href = '#holder';
var thumb = document.createElement('img');
thumb.src = menu_by_categories.items[key][i].thumb_url + '?' + Math.floor(Math.random() * 1000);
img_link.appendChild(thumb);
img_wrapper.appendChild(img_link);
item.appendChild(img_wrapper);
var meta_wrapper = document.createElement('div');
meta_wrapper.className = 'meta-wrapper';
var product_name_wrapper = document.createElement('div');
product_name_wrapper.className = 'product-name-wrapper';
product_name_wrapper.appendChild(appendChild(document.createTextNode(menu_by_categories.items[key][i].name)));
meta_wrapper.appendChild(product_name_wrapper);
var species_wrapper = document.createElement('div');
species_wrapper.className = 'species-wrapper';
species_wrapper.appendChild(document.createTextNode(menu_by_categories.items[key][i].species));
meta_wrapper.appendChild(species_wrapper);
var potency_wrapper = document.createElement('div');
potency_wrapper.className = 'potency-wrapper';
var potency_text = 'THC: ' + menu_by_categories.items[key][i].thc_pct + '% CBD: ' + menu_by_categories.items[key][i].cbd_pct + '%';
potency_wrapper.appendChild(potency_text);
meta_wrapper.appendChild(potency_wrapper);
var price_wrapper = document.createElement('div');
price_wrapper.className = 'price-wrapper';
var price_text;
if(typeof menu_by_categories.items[key][i].std_price != 'undefined' && '' != menu_by_categories.items[key][i].std_price){
price_text += 'Price ' + menu_by_categories.items[key][i].std_price + ' ';
}
if(typeof menu_by_categories.items[key][i].member_price != 'undefined' && '' != menu_by_categories.items[key][i].member_price){
price_text += 'Member Price ' + menu_by_categories.items[key][i].member_price + ' ';
}
price_wrapper.appendChild(document.createTextNode(price_text));
meta_wrapper.appendChild(price_wrapper);
item.appendChild(meta_wrapper);
content_panel.appendChild(item);
}
cat.appendChild(content_panel);
accordion_wrapper.appendChild(cat);
}
return accordion_wrapper;
};
this.setupFilters = async function(thc_minmax, price_minmax){
var flt = new CpFilters();
var drawn_filters = await flt.drawFilters(thc_minmax, price_minmax);
console.log('drawn fltrs');
console.log(drawn_filters)
document.getElementById('cp_filter_home').innerHTML = '';
document.getElementById("cp_filter_home").appendChild(drawn_filters);
thiss.setupAccordion(thc_minmax, price_minmax);
}
this.setupAccordion = function(thc_minmax, price_minmax, redraw_filters){
var accItem = document.getElementsByClassName('accordionItem');
var accHD = document.getElementsByClassName('accordionItemHeading');
for (i = 0; i < accHD.length; i++) {
accHD[i].addEventListener('click', toggleItem, false);
//accHD[i].addEventListener('click', function(){fixMenu(this, thc_minmax, price_minmax);});
}
setMenu(accHD[0], thc_minmax, price_minmax);
function setMenu(accHeader, thc_minmax, price_minmax){
var cat_id = accHeader.dataset.category_id;
//sessionStorage.thc_pct = 0;
//var flt = new CpFilters();
//var drawn_filters = flt.drawFilters(cat_id, thc_minmax, price_minmax);
//document.getElementsByClassName('filters-outer')[0].innerHTML = '';
//document.getElementsByClassName('filters-outer')[0].appendChild(drawn_filters);
var filters = document.querySelectorAll('.filter-wrapper input[type="checkbox"]');
var medrec_singular = document.querySelectorAll('input[name="medrec_checkbox"]');
if(medrec_singular.length === 1){
medrec_singular[0].checked = true;
medrec_singular[0].readonly = true;
}
var new_filters_to_set = [];
for(var i = 0; i < filters.length; i++){
if(typeof sessionStorage.filters != 'undefined'){
var applied_filters = JSON.parse(sessionStorage.filters);
sessionStorage.thc_pct = sessionStorage.thc_pct || 0;
}
else{
var applied_filters = [];
//sessionStorage.thc_pct = 0;
}
if(applied_filters.indexOf(filters[i].value) != -1){
filters[i].checked = true;
}
filters[i].onchange = function(){
var new_filters = document.querySelectorAll('.filters-outer input[type="checkbox"]:checked');
console.log('new filters' + new_filters.length);
var new_filters_to_set = [];
for(var i = 0; i < new_filters.length; i++){
new_filters_to_set.push(new_filters[i].value);
}
sessionStorage.setItem('filters', JSON.stringify(new_filters_to_set));
sessionStorage.thc_pct = sessionStorage.thc_pct || 0;
main_menu.showFilteredMenu();
var thc_display_obj = document.getElementById('thc_displayx');
thc_display_obj.innerHTML = document.getElementById('cp_thc_slider').value;
}
}
}
function fixMenu(this3, thc_minmax, price_minmax){
/*var flt = new CpFilters();
var drawn_filters = flt.drawFilters(this3.dataset.category_id, thc_minmax, price_minmax);
document.getElementsByClassName('filters-outer')[0].innerHTML = '';
document.getElementsByClassName('filters-outer')[0].appendChild(drawn_filters);*/
var medrec_singular = document.querySelectorAll('input[name="medrec_checkbox"]');
if(medrec_singular.length === 1){
medrec_singular[0].checked = true;
medrec_singular[0].readonly = true;
}
sessionStorage.setItem('filters', JSON.stringify([]));
//sessionStorage.thc_pct = 0;
var applied_filters = [];
console.log('applied filters');
console.log(applied_filters);
var filters = document.querySelectorAll('.filters-outer input[type="checkbox"]');
for(var i = 0; i < filters.length; i++){
if(applied_filters.indexOf(filters[i].value) != -1){
filters[i].checked = true;
}
filters[i].onchange = function(){
var new_filters = document.querySelectorAll('.filters-outer input[type="checkbox"]:checked');
console.log('new filters' + new_filters.length);
var new_filters_to_set = [];
for(var i = 0; i < new_filters.length; i++){
new_filters_to_set.push(new_filters[i].value);
}
sessionStorage.setItem('filters', JSON.stringify(new_filters_to_set));
main_menu.showFilteredMenu();
}
}
}
function toggleItem() {
var itemClass = this.parentNode.className;
/*for (i = 0; i < accItem.length; i++) {
accItem[i].className = 'accordionItem close';
}*/
if (itemClass == 'accordionItem close') {
this.parentNode.className = 'accordionItem open';
}
else{
this.parentNode.className = 'accordionItem close';
}
}
};
var thiss = this;
main_menu = this;
}
/*var cm = new CannaMenu();
cm.showDefaultMenu();
setTimeout(function(){
//cm.setupAccordion();
}, 3000);*/
var cm;
if(1){
sessionStorage.setItem('filters', JSON.stringify([]));
var head = document.getElementsByTagName('head')[0];
var lato_preconnect = document.createElement('link');
lato_preconnect.rel = 'preconnect';
lato_preconnect.href = 'https://fonts.gstatic.com';
head.appendChild(lato_preconnect);
var lato = document.createElement('link');
lato.rel = 'stylesheet';
lato.href = 'https://fonts.googleapis.com/css2?family=Lato:ital,wght@0,400;0,700;1,400;1,700&display=swap';
head.appendChild(lato);
var ss = document.createElement('link');
ss.rel = 'stylesheet';
ss.href = 'https://menuserver.canname.nu/css/menu.css?1';
head.appendChild(ss);
document.addEventListener("DOMContentLoaded", function(event) {
cannamenu_div = document.getElementById("cannamenu-div");
cannamenu_div.style.fontFamily = "'Lato', sans-serif";
cm = new CannaMenu();
cm.showDefaultMenu();
});
}