$(document).ready( function() { headerInit(); headerAddListener(); globalEventListener(); } ); function headerInit() { // http://thunderkicks.com/settings/account_management.php var href=location.href; if(href.match(/\/settings\//)) { $("#nav_item8").attr("id","nav_item8_on"); } if(href.match(/\/inventory\//)) { $("#nav_item5").attr("id","nav_item5_on"); } if(href.match(/\/sku\//)) { $("#nav_item6").attr("id","nav_item6_on"); } if(href.match(/\/request\//)) { $("#nav_item3").attr("id","nav_item3_on"); } if(href.match(/\/fba\//)) { $("#nav_item2").attr("id","nav_item2_on"); } if(href.match(/\/order\//)) { $("#nav_item1").attr("id","nav_item1_on"); } if(href.match(/\/message\//)) { $("#nav_item61").attr("id","nav_item61_on"); } setInterval(getInventoryUpdateQueueCount, 5000); getInventoryUpdateQueueCount(); setInterval(getCartQueueCount, 5000); getCartQueueCount(); $('.ui.dropdown').dropdown(); $("#select_location").change(changeLocation); } function changeLocation() { $.post("/action/header.act", { mode:'change_location', location:$(this).val() }, function() { location.reload(true) } ); } function headerAddListener() { $("#btn_header_search").click(doHeaderSearch); $("#text_header_search").keyup( function(e) { // console.log(e.keyCode); if(e.keyCode==13) { doHeaderSearch(); } } ); $(document).on("mouseover", ".img_header", drawHeaderPreview); $(document).on("mouseout", ".img_header", hideHeaderPreview); $(document).on("mouseover", ".img", drawPreview); $(document).on("mouseout", ".img", hidePreview); // $(".img").mouseover( // drawPreview // ); // // $(".img").mouseout( // hidePreview // ); } function hideHeaderPreview() { $("#preview_header img").attr("src",""); $("#preview_header").hide(); } function drawHeaderPreview(e) { var target=$(this); var offset=target.offset(); $("#preview_header img").attr("src",target.attr("big_src")); $("#preview_header").show(); $("#preview_header").css("left", offset.left+100); $("#preview_header").css("top", offset.top+100); if($(document).width()-10").css("padding","20px").css("border-bottom","1px solid #cccccc").css("clear","both").css("min-height","140px").css("background-color", bgColor); img1=$("") .attr("src", "/common/getImage.php?url="+encodeURIComponent(data.image_url)) .attr("big_src", "/common/getImage.php?url="+encodeURIComponent(data.image_url)) // .css("float","left") // .css("padding-right","20px") .addClass("img_header"); img=$("") .attr("href","/common/getImage.php?url="+encodeURIComponent(data.image_url)) .attr("target","_blank"); img.append(img1); var imgLayer=$("
"); imgLayer.append(img); status=""; switch(data.status) { case "6": status='일시품절'; break; case "7": status='품절'; break; } if(data.manufacture) { var m=data.manufacture.split("|"); status+='제작중 ( '+m[0]+'개 - '+m[1]+' )'; } if(data.tags) { var _tags=data.tags.split(","); tags="
Tags: "; for(var _t in _tags) { tags+=''+_tags[_t]+''; } } _stock=data.current_count.split("|"); _stockLocation=_stock[0].split(","); _stockCount=_stock[1].split(","); var _stocks=[]; for(var _s=0;_s<_stockLocation.length;_s++) { if(_stockCount[_s]=="0") { _stocks.push(''+_stockLocation[_s]+':'+"0"); } else { _stocks.push(''+_stockLocation[_s]+':'+_stockCount[_s]); // _stocks.push(_stockCount[_s]); } } stock=_stocks.join(","); var market=''; if(data.ebay) { market='eBay'; } if(data.FBA) { market+="\ FBA\
"+data.FBA+"
\
"; } if(market) { market=market+"
"; } var archived=""; if(data.archived==1) { archived='Archived'; } var _tmpLocation=""; var _locations=[]; if(data.location) { _tmpLocation=data.location.split("|"); for(var _s=0;_s<_tmpLocation.length;_s++) { var _split=_tmpLocation[_s].split(":"); if(_split[1]) { _locations.push(''+_split[0]+':'+""+_split[1]+""); } } } var location=_locations.join(","); var output=""; // if(data.note) { // output+="
"; // } else { // output+="
"; // } output+=market; output+="SKU: "+data.id+" "+archived+status+"
"; output+="Item Name: "+data.item_name+" ("+data.major_account+")"; output+=tags+"
"; output+="Purchase Price: "+number_format(data.purchase_price)+"
"; output+="Price: "+number_format(data.price)+"
"; output+="Stock: "+stock+""; if(data.location) { output+="
Location: "+location+""; } if(data.note) { output+="
Note: "+data.note.replace(/\n/g,"
")+"
"; } output+="
" // if(data.FBA) { // description=$("
").html("SKU : "+data.id+" "+status+"
Item Name : "+data.item_name+"
Price : "+number_format(data.price)+"
Stock : "+stock+"
\"+ebay); // } else { description=$("
").html(output); // } var descriptionPrice=$("
"); var asinLink={}; if(data.amazonAsin) { var asins=data.amazonAsin.split(","); for(var j in asins) { var _s=asins[j].split("|"); var _country=_s[0]; var _asin=_s[1]; switch(_country) { case 'US': asinLink[_country]='https://www.amazon.com/gp/product/'+_asin; asinLink['FR']='https://www.amazon.fr/gp/product/'+_asin; asinLink['JP']='https://www.amazon.co.jp/gp/product/'+_asin; break; case 'CA': asinLink[_country]='https://www.amazon.ca/gp/product/'+_asin; break; case 'MX': asinLink[_country]='https://www.amazon.com.mx/gp/product/'+_asin; break; case 'DE': asinLink[_country]='https://www.amazon.de/gp/product/'+_asin; break; case 'UK': asinLink[_country]='https://www.amazon.co.uk/gp/product/'+_asin; break; case 'FR': asinLink[_country]='https://www.amazon.fr/gp/product/'+_asin; break; case 'IT': asinLink[_country]='https://www.amazon.it/gp/product/'+_asin; break; case 'ES': asinLink[_country]='https://www.amazon.es/gp/product/'+_asin; break; case 'JP': asinLink[_country]='https://www.amazon.co.jp/gp/product/'+_asin; break; } // asinLink[_country]+=_asin; } } if(data.amazonPrices) { var prices=data.amazonPrices.split(","); var convertPrices=[]; for(var j in prices) { var _s=prices[j].split("|"); var _key=_s[2]; var _country=_s[0]; var _price=_s[1]; convertPrices[_key]=[_country, _price]; // descriptionPrice.append(""+_s[0]+"
"+_s[1]+"
"); // // console.log((j+1)); // if((parseInt(j)+1)%4==0) { // descriptionPrice.append("
"); // } } var _idx=0; for(var j in convertPrices) { var _s=convertPrices[j]; var link=''; if(asinLink[(_s[0])]) { link="href='"+asinLink[(_s[0])]+"' target='_blank'"; } descriptionPrice.append(""+_s[0]+"
"+_s[1]+"
"); // console.log((j+1)); if((_idx+1)%4==0) { descriptionPrice.append("
"); } _idx++; } } // console.log(convertPrices); var tbl=$(""); var tr=$(""); var td1=$("
"); var td2=$(""); var td3=$(""); td1.append(imgLayer); td2.append(description); if(data.amazonPrices) { td3.append(descriptionPrice); } tbl.append(tr); tr.append(td1); tr.append(td2); tr.append(td3); item.append(tbl); // item.append(imgLayer); // item.append(description); // item.append("
").css("clear","both"); // if(data.note) { // item.append($("
").html('노트
'+data.note.replace(/\n/g,"
"))); // } $("#span_header_search").append(item); } $("#span_header_search").children().last().css("border",""); $("#modal_header_search").modal('show'); } var apiHost=''; if(location.hostname=='7kicks.com') { apiHost='https://v3.7kicks.com'; } else { apiHost='http://127.0.0.1:8079'; } function globalEventListener() { $(document).on("click","[data-action=cart]", (e)=>{ var t=e.target; if(t.tagName != 'BUTTON') { t=t.parentNode; } var target=$(t); var sku_type=target.attr("sku-type"); var sku=target.attr("sku"); var data={}; data.sku_type=sku_type; data.sku=sku; $.post( apiHost+"/api/v1/cart", data, function(raw_data) { target.attr("selected",true); target.addClass("blue"); if(sku_type=='parent') { $("[data-action=cart][sku-type=child][parent-sku="+sku+"]").addClass("blue"); } } ); getCartQueueCount(); }); $("[data-action=header_search]").css("cursor",'help'); $(document).on("click","[data-action=header_search]", (e)=>{ var t=$(e.target); var sku=t.attr("sku"); $("#text_header_search").val(sku); doHeaderSearch(); }); } var cartItems={}; function getCartQueueCount() { $.get( apiHost+'/api/v1/cart', function(raw_data) { // var json_data=JSON.parse(raw_data); var json_data=raw_data; cartItems.parentSku=json_data.parentSku; cartItems.sku=json_data.sku; var cnt=cartItems.sku.length; if(cnt!=0) { if(!$("#header_cart").hasClass("teal")) { $("#header_cart").removeClass("grey").addClass("purple"); } } else { if(!$("#header_cart").hasClass("grey")) { $("#header_cart").removeClass("purple").addClass("grey"); } } $("#header_cart").contents()[2].replaceWith(document.createTextNode(cnt)); var carts=$("[data-action=cart]"); carts.each(function() { if($.inArray($(this).attr('sku'),cartItems.parentSku)!=-1) { $(this).attr('selected', true); $(this).addClass("blue"); } }); } ) }