let mainConfiObj, currentProductNum = 0, currentProductObj, currentApplicationLabel = '', currentConfigurationLabel = ''; function setupConfigurator(loadedObj){ mainConfiObj = loadedObj; console.log(mainConfiObj); //setup buttons $("#product-datasheet").on("click", downloadDatasheet); $("#product-portal").on("click", supportPortal); $("#product-prev").on("click", previousProduct); $("#product-next").on("click", nextProduct); $("#pdf-download").on("click", generatePDF); $("#pdf-download2").on("click", generatePDF); $("#image-copy").on("click",generateDownloadableImage) const mLen = mainConfiObj.products.length; let htmlStr = ''; for(let m=0;m'+mainConfiObj.products[m].product+''; } $("#product-maindd").html(htmlStr); $(".mm-cfgr-main-header-prod-dd-item").on("click", selectProduct); $("#clear-all").on("click",setupProduct); //setup first product setupProduct(); } function selectProduct(e){ currentProductNum = $(this).attr("data-id"); setupProduct(); } function previousProduct(){ currentProductNum -= 1; if(currentProductNum <0){ currentProductNum = mainConfiObj.products.length-1; } setupProduct(); } function nextProduct(){ currentProductNum += 1; if(currentProductNum >= mainConfiObj.products.length){ currentProductNum = 0; } setupProduct(); } function downloadDatasheet(){ window.open(currentProductObj.datasheet, '_blank').focus(); } function supportPortal(){ window.open(currentProductObj.portal, '_blank').focus(); } //diagram functions function toggleSwitch(e){ const switchId = $(this).attr("data-id"), switchStatus = $(this).hasClass("on"); cssChangeSwitch(switchStatus, switchId); } function processSwitchRanges(activeSwitches,vid,jDiv,divClass){ if(vid != "" && vid != null){ if(vid.indexOf("|") > 0){ const vidArr = vid.split("|"), vLen = vidArr.length; for(let v=0;v 0){ const sidArr = sid.split("|"), sLen = sidArr.length; for(let r=0;r'+config.label+''; } $("#dd-configurations .mm-dropdown-items").html(configHtmlStr); $("#dd-configurations").removeClass("disabled"); $("#dd-configurations .mm-dropdown-item").on("click", selectMMDropdown); $("#diagram-title").val(currentApplicationLabel); } else {$("#dd-configurations").addClass("disabled");} $(".on").removeClass("on"); $(".onhl").removeClass("onhl"); $(".onhr").removeClass("onhr"); $(".bottomon").removeClass("bottomon"); generateConfiguration(); $("#diagram-title").val(); } else { const configuration = currentProductObj.configurations[dataId]; currentConfigurationLabel = $(this).attr("data-label"); $(".on").removeClass("on"); $(".onhl").removeClass("onhl"); $(".onhr").removeClass("onhr"); $(".bottomon").removeClass("bottomon"); for (const switchKey in configuration) { if(configuration[switchKey] == 1){ cssChangeSwitch(false, switchKey); } } generateConfiguration(); $("#diagram-title").val(currentApplicationLabel+" ― "+currentConfigurationLabel); } } function generateConfiguration(){ let htmlStr = '', configLabel = '--', details = '--', configObj = {}; //build current profile $(".mm-cfgr-control-switch-h").each(function(i){ //parse through active switches on left for current config configObj[$(this).attr("data-id")] = $(this).hasClass("on"); }); //parse through configuration settings for matching configurations const configurations = currentProductObj.configurations, mLen = configurations.length; for(let m=0;mHV OUTGPIO INPUT SIGNALSSPI STATE REGISTER'; tableHtmlStr += ''; for(let c=0;c'; } for(let c=0;c'; } tableHtmlStr += 'BITSHEX'; for(let c=0;c'; let hexStr = parseInt(bitStr, 2).toString(16).toUpperCase(); if(hexStr.length < 2){ hexStr = '0'+hexStr; } tableHtmlStr += ''+hexStr+''; //'+configLabel+' $("#table-data").html(''+tableHtmlStr+'
'); $("#configuration-data").html(configLabel); $("#details-data").html(details); } function toggleFieldTerminate(){ const dataId = $(this).attr("data-id"); $("#h-"+dataId).toggleClass("terminate"); $("#hv-"+dataId).toggleClass("terminate"); } function setupProduct(){ currentProductObj = mainConfiObj.products[currentProductNum]; $("#product-name").text(currentProductObj.product); $("#table-data").text(""); $("#diagram-title").val(""); $("#configuration-data").text("--"); $("#details-data").text("--"); if(currentProductObj.display_vertical){ $("#diagram").css("display","none"); $("#diagram-vertical").css("display",""); } else { $("#diagram").css("display",""); $("#diagram-vertical").css("display","none"); } /* [{"type":"endpoint","label":"HS1_A","switch":"HVB"}, {"type":"endpoint","label":"MS1_A","switch":"HVD"}, {"type":"endpoint","label":"LS1_A","switch":"HVC"}], [{"type":"joint3","top":"HVB","bottom":"HVC"}], [{"type":"switch","switch":"HVA"}], [{"type":"split-joinder", "label":"C1"}], */ //generate diagram const diagramSections = currentProductObj.horizontal_diagram, sLen = diagramSections.length; let htmlStr = '', allSwitches = [], labelGroups = [[],[]]; for(let s=0;s'; let colorStr = ''; if(sectionItem.color != null){ colorStr = ' style="color:'+sectionItem.color+';"'; } if(sectionItem.type == "endpoint"){ htmlStr += '
'+sectionItem.label+'
'; //pull out labels for ids for the pin labels if(c == 0){labelGroups[0].push(sectionItem.label);} else {labelGroups[1].push(sectionItem.label);} } htmlStr += '
'+sectionItem.switch+'
'; lastSwitch = sectionItem.switch; if(!allSwitches.includes(sectionItem.switch)){allSwitches.push(sectionItem.switch);} } else if(sectionItem.type == "split-joinder"){ htmlStr += '
'+sectionItem.label+'
'; } else if(sectionItem.type == "joint3"){ htmlStr += '
'; } else if(sectionItem.type == "spacer"){ htmlStr += '
'; } } htmlStr += ''; } labelGroups[0].push('SPACER'); labelGroups[1].push('SPACER'); htmlStr += ''; } $("#diagram-box").html(htmlStr); //Hook up switch click function //Add pin labels for(let r=0;r<2;r+=1){ const gLen = labelGroups[r].length; let labelHtmlStr = ''; for(let g=0;g
NEED TERMINATION (50 OHM)
'; } } if(r == 0){$("#fields-left").html(labelHtmlStr);} else {$("#fields-right").html(labelHtmlStr);} } //add vertical diagram const vDiagram = currentProductObj.vertical_diagram, vLen = vDiagram.length; let vHtmlStr = '', vLeftHtmlStr = '', vRightHtmlStr = '', bLabelGroups = [[],[]], tempObj = {}; for(let v=0;v0){ const switches2 = vItem.s2.split("|"); switchIds += 'data-id2="'+switches2[0]+'" data-id2alt="'+switches2[1]+'" '; } else { switchIds += 'data-id2="'+vItem.s2+'" '; } }*/ if(vItem.t == " "){ vHtmlStr += '
'; if(r == 0){bLabelGroups[0].push("SPACER");} else if(r == rLen-1){bLabelGroups[1].push("SPACER");} } else if(vItem.t == "end"){ vHtmlStr += '
'; let colorStr = ''; if(vItem.c != null){ colorStr = ' style="color:'+vItem.c+';"'; } vHtmlStr += '
'+vItem.l+'
'; //pull out labels for ids for the pin labels if(r == 0){bLabelGroups[0].push(vItem.l);} else {bLabelGroups[1].push(vItem.l);} vHtmlStr += '
'+vItem.s+'
'; } else if(vItem.t == "vswitch"){ vHtmlStr += '
'; let colorStr = ''; if(vItem.c != null){ colorStr = ' style="color:'+vItem.c+';"'; } vHtmlStr += '
'+vItem.s+'
'; } else if(vItem.t == "split-joinder"){ vHtmlStr += '
'; } else if(vItem.t == " |d"){ vHtmlStr += '
'; } else if(vItem.t == "-"){ vHtmlStr += '
'; } else if(vItem.t == " |"){ vHtmlStr += '
'; } else if(vItem.t == " |u"){ vHtmlStr += '
'; } else if(vItem.t == "|u"){ vHtmlStr += '
'; } else if(vItem.t == "|o-d"){ vHtmlStr += '
'; } else if(vItem.t == "-o|u"){ vHtmlStr += '
'; } else if(vItem.t == "-c|"){ vHtmlStr += '
'; } else if(vItem.t == "|c-"){ vHtmlStr += '
'; } else if(vItem.t == "|o-u"){ vHtmlStr += '
'; } else if(vItem.t == "-o|d"){ vHtmlStr += '
'; } else if(vItem.t == "-o|"){ vHtmlStr += '
'; } else if(vItem.t == "-o|t" || vItem.t == "|o-t"){ vHtmlStr += '
'; } else if(vItem.t == "-o|b" || vItem.t == "|o-b"){ vHtmlStr += '
'; } else { //tempObj[vItem.t] = 1; console.log(">"+vItem.t+"<"); } } vHtmlStr += ''; } const bLen = bLabelGroups[0].length; let leftSpacer = true, rightSpacer = true; for(let b=0;b
NEED TERMINATION (50 OHM)
'; leftSpacer = false; } if(bLabelGroups[1][b] == "SPACER"){ vRightHtmlStr += '
'; rightSpacer = true; } else { if(rightSpacer){ vRightHtmlStr += '
DUT/TEST PIN LABELS
'; } vRightHtmlStr += '
NEED TERMINATION (50 OHM)
'; rightSpacer = false; } } //console.log(Object.keys(tempObj).toString()); $("#diagram-vertical").html('
'+vLeftHtmlStr+'
'+vHtmlStr+'
'+vRightHtmlStr+'
'); //set switches functions $(".mm-diagram-switch").on("click", toggleSwitch); $(".mm-cfgr-main-diagram-field-toggle").on("click", toggleFieldTerminate); //generate side switches all off allSwitches.sort(); const aLen = allSwitches.length; let togglesHtmlStr = ''; for(let a=0;a
On
Off
'; } $("#controls").html(togglesHtmlStr); //Hook up control switch click function $(".mm-cfgr-control-switch-h").on("click",toggleSwitch); //generate use cases const useCases = currentProductObj.use_cases, uLen = useCases.length; let useCaseHtmlStr = ''; for(let u=0;u'+useCase.label+''; } $("#dd-use-cases .mm-dropdown-items").html(useCaseHtmlStr); //generate configurations /* const configurations = currentProductObj.configurations, nLen = configurations.length; let configHtmlStr = ''; for(let n=0;n'+config.label+''; } $("#dd-configurations .mm-dropdown-items").html(configHtmlStr); */ $("#dd-configurations").addClass("disabled"); $("#dd-configurations .mm-dropdown-items").html(''); $(".mm-dropdown-item").on("click", selectMMDropdown); //generate blank configuration generateConfiguration(); } function generatePDF(){ $("#diagram-parent").addClass("print"); domtoimage.toPng(document.getElementById('diagram-parent'), {width:$("#diagram-parent").width()*2,height:$("#diagram-parent").height()*2, quality: 0.95, style: { transform: 'scale(2)', transformOrigin: 'top left' } }) .then(function (dataUrl) { /* var link = document.createElement('a'); link.download = 'generated-image.png'; link.href = dataUrl; link.click();*/ domtoimage.toPng(document.getElementById('product-name'), {width:$("#product-name").width()*4,height:$("#product-name").height()*4, quality: 0.95, style: { transform: 'scale(4)', transformOrigin: 'top left' } }) .then(function (dataUrlTitle) { /* var link = document.createElement('a'); link.download = 'generated-image.png'; link.href = dataUrl; link.click();*/ uploadImageToPDFGenerator(dataUrl, dataUrlTitle); }).catch(function(error){console.log(error);}); $("#diagram-parent").removeClass("print"); }).catch(function(error){console.log(error);}); } function generateDownloadableImage(){ $("#diagram-parent").addClass("print"); domtoimage.toPng(document.getElementById('diagram-parent'), {width:$("#diagram-parent").width()*2,height:$("#diagram-parent").height()*2, quality: 0.95, style: { transform: 'scale(2)', transformOrigin: 'top left' } }).then(function (dataUrl) { var link = document.createElement('a'); link.download = currentProductObj.product+'-diagram.png'; link.href = dataUrl; link.click(); $("#diagram-parent").removeClass("print"); }).catch(function(error){console.log(error);}); } function uploadImageToPDFGenerator(dataUrl, dataUrlTitle){ $.ajax({ type: "POST", url: "/core/generatepdf/generate.php", dataType: "json", data:{ product:currentProductObj.product, img:dataUrl, imgwidth:$("#diagram-parent").width(),imgheight:$("#diagram-parent").height(), titleimg:dataUrlTitle, titleimgwidth:$("#product-name").width(),titleimgheight:$("#product-name").height() }, success: function(data){ console.log(data); if(data.success == "true"){ window.open("/core/generatepdf/exports/"+data.filename); setTimeout(function(){deleteFileAfterDownload(data.filename);}, 3000); } else {alert(data.error);} }, error: function(xhr, status, error){ console.error(xhr); alert("Generation failed. Please try again or reach out directly through our contact page."); } }); } function deleteFileAfterDownload(filename){ $.ajax({ type: "POST", url: "/core/generatepdf/clearfile.php", dataType: "json", data:{ filename: filename}, success: function(data){console.log(data);}, error: function(xhr, status, error){console.error(xhr);} }); }