quoteCalculator.controller("zFoldController",["$scope","$compile","ajaxService",function($scope,$compile,ajaxService){$scope.zFold={},$scope.ReturnZFoldStyle=function(){return 3==$scope.zFold.orientationTypeId?{height:"40px",width:"40px"}:1==$scope.zFold.orientationTypeId?{height:"50px",width:"30px"}:{height:"30px",width:"50px"}},$scope.ZFoldUpdateHandle="",$scope.QueueZFoldUpdate=function(){clearTimeout($scope.ZFoldUpdateHandle),$scope.ZFoldUpdateHandle=setTimeout($scope.zFoldUpdate,400)},$scope.zFoldUpdate=function(){$scope.refreshZFoldPreview(),delete $scope.zFold.id,delete $scope.zFold.datetimeAdded;let requestId=$scope.getUpdateId();$scope.priceUpdateSent(),ajaxService.postRequest([$scope.zFold],"quote/data/zFolds",{},function(response){$scope.priceUpdateReceived(requestId)&&(Array.isArray(response)&&$scope.IntegrateNewApiQuoteDataObjectFromChildService(response),$scope.$digest())})},$scope.$on("GetZFoldObject",function(e){$scope.GetZFoldObject()}),$scope.GetZFoldObject=function(){var targetUrl="quote/data/zFolds/"+$scope.ApiQuote.id,optionalData={url:targetUrl,productId:productId,quoteId:$scope.ApiQuote.id,userType:$scope.userType};ajaxService.getRequest(targetUrl,optionalData,function(response,httpCode,optionalData){$scope.zFold=response[0],setTimeout($scope.refreshZFoldPreview,1e3),$scope.$digest()})},$scope.selectPanelOrientation=function(option){$scope.IndexedChoiceData["79-Z-fold Orientation of Panel"].selected=option,$scope.zFold.orientationTypeId=option.ChoiceValueId,$scope.zFoldUpdate()},$scope.ChangeZFoldQuantity=function(rowOrColumn,changeAmount){$scope.zFoldErrors[rowOrColumn].error=!1;var currentValue=parseInt($scope.zFold.lineCount),minValue=parseInt($scope.IndexedChoiceData["79-Z-fold Line (Rows)"].validationMinimumValue),maxValue=parseInt($scope.IndexedChoiceData["79-Z-fold Line (Rows)"].validationMaximumValue);"columns"==rowOrColumn&&(currentValue=parseInt($scope.zFold.columnCount),minValue=parseInt($scope.IndexedChoiceData["79-Z-fold Columns"].validationMinimumValue),maxValue=parseInt($scope.IndexedChoiceData["79-Z-fold Columns"].validationMaximumValue)),currentValue==minValue&&changeAmount<0?($scope.zFoldErrors[rowOrColumn].error=!0,$scope.zFoldErrors[rowOrColumn].errorDescription="This cannot be lower than "+minValue):currentValue==maxValue&&0<changeAmount?($scope.zFoldErrors[rowOrColumn].error=!0,$scope.zFoldErrors[rowOrColumn].errorDescription="This cannot be greater than "+maxValue):("columns"==rowOrColumn?$scope.zFold.columnCount=currentValue+changeAmount:$scope.zFold.lineCount=currentValue+changeAmount,$scope.QueueZFoldUpdate())},$scope.zFoldRowsChangedManually=function(){var value=parseInt($scope.zFold.lineCount),minValue=parseInt($scope.IndexedChoiceData["79-Z-fold Line (Rows)"].validationMinimumValue),maxValue=parseInt($scope.IndexedChoiceData["79-Z-fold Line (Rows)"].validationMaximumValue);maxValue<value?($scope.zFoldErrors.rows.error=!0,$scope.zFoldErrors.rows.errorDescription="This cannot be higher than "+maxValue):value<minValue?($scope.zFoldErrors.rows.error=!0,$scope.zFoldErrors.rows.errorDescription="This cannot be lower than "+minValue):($scope.zFoldErrors.rows.error=!1,$scope.QueueZFoldUpdate())},$scope.zFoldColumnsChangedManually=function(){var value=parseInt($scope.zFold.columnCount),minValue=parseInt($scope.IndexedChoiceData.SizeLimits["Z-fold Columns"].validationMinimumValue),maxValue=parseInt($scope.IndexedChoiceData.SizeLimits["Z-fold Columns"].validationMaximumValue);maxValue<value?($scope.zFoldErrors.columns.error=!0,$scope.zFoldErrors.columns.errorDescription="This cannot be higher than "+maxValue):value<minValue?($scope.zFoldErrors.columns.error=!0,$scope.zFoldErrors.columns.errorDescription="This cannot be lower than "+minValue):($scope.zFoldErrors.columns.error=!1,$scope.QueueZFoldUpdate())},$scope.zFoldErrors={columns:{error:!1,errorDescription:""},rows:{error:!1,errorDescription:""}},$scope.returnZFoldPanelSizeDisplayName=function(){var choices=$scope.IndexedChoiceData["79-Z-fold Panel Size"];for(let i=0;i<choices.length;i++)if(choices[i].ChoiceValueId==$scope.zFold.panelPrintSizeId)return choices[i].ChoiceDisplayName;return"Please select a panel size"},$scope.zFoldErrorText="",$scope.sFoldErrorTimeoutHandle=null,$scope.clearZFoldError=function(){$scope.zFoldErrorText="",$scope.$$phase||$scope.$digest()},$scope.zFoldError=function(error){$scope.zFoldErrorText=error,clearTimeout($scope.sFoldErrorTimeoutHandle),$scope.sFoldErrorTimeoutHandle=setTimeout($scope.clearZFoldError.bind(this),4e3)},$scope.checkForZFoldColumnButtonDisplayed=function(columnCount){if(!$scope.ProductDefault.zfoldFixedRowCount)return!0;var rows=$scope.ProductDefault.zfoldFixedRowCount;return!(3==rows&&8<columnCount)&&!(4==rows&&6<columnCount)},$scope.validateZFold=function(){1!=$scope.zFold.panelPrintSizeId&&743!=$scope.zFold.panelPrintSizeId&&744!=$scope.zFold.panelPrintSizeId||6<$scope.zFold.columnCount&&($scope.zFold.columnCount=6,$scope.zFoldError("Maximum of 6 Columns with this size")),31==$scope.zFold.panelPrintSizeId&&9<$scope.zFold.columnCount&&($scope.zFold.columnCount=9,$scope.zFoldError("Maximum of 9 Columns with this size")),3==$scope.zFold.lineCount&&8<$scope.zFold.columnCount&&($scope.zFold.columnCount=8,$scope.zFoldError("Maximum of 8 Columns when using 3 rows")),4==$scope.zFold.lineCount&&((31==$scope.zFold.panelPrintSizeId||258==$scope.zFold.panelPrintSizeId)&&6<$scope.zFold.columnCount&&($scope.zFold.columnCount=6,$scope.zFoldError("Maximum of 6 Columns when using 4 rows")),(1==$scope.zFold.panelPrintSizeId||743==$scope.zFold.panelPrintSizeId||744==$scope.zFold.panelPrintSizeId)&&4<$scope.zFold.columnCount&&($scope.zFold.columnCount=4,$scope.zFoldError("Maximum of 4 Columns when using 4 rows at this size")))},$scope.zFoldPreviewCode="",$scope.setZFoldPreview=function(){let eles=document.getElementsByClassName("z-fold-preview");for(let i=0;i<eles.length;i++)eles[i].innerHTML=$scope.zFoldPreviewCode},$scope.downloadZFoldTemplate=function(){let size="bc";1==$scope.zFold.panelPrintSizeId&&(size="a6"),31==$scope.zFold.panelPrintSizeId&&(size="a7"),743==$scope.zFold.panelPrintSizeId&&(size="90x140"),744==$scope.zFold.panelPrintSizeId&&(size="76x146");var rows=$scope.zFold.lineCount,columns=$scope.zFold.columnCount;let coverstyle="separate";$scope.covers.length?192==$scope.covers[0].zfoldCoverTypeId&&(coverstyle="book"):coverstyle="none",console.log("https://printprice.co.uk/php/zFoldPdfGenerator.php?size="+size+"&rows="+rows+"&columns="+columns+"&coverstyle="+coverstyle),window.open("https://printprice.co.uk/php/zFoldPdfGenerator.php?size="+size+"&rows="+rows+"&columns="+columns+"&coverstyle="+coverstyle,"_blank")},$scope.refreshZFoldPreview=function(){let size="bc";1==$scope.zFold.panelPrintSizeId&&(size="a6"),31==$scope.zFold.panelPrintSizeId&&(size="a7"),743==$scope.zFold.panelPrintSizeId&&(size="90 x 140"),744==$scope.zFold.panelPrintSizeId&&(size="76 x 146");var panelwidth,panelheight,fontSize,titleSize,coverwidth,coverheight,flatwidth,flatheight,OGx,x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,xLast,y1,y2,y3,y4,viewBoxWidth,data,cov1x,cov1y,cov1tx,cov1ty,cov1pnlx,cov1pnly,cov2x,cov2y,cov2tx,cov2ty,totalpanels,rows=$scope.zFold.lineCount,columns=$scope.zFold.columnCount;let coverstyle="separate";$scope.covers.length&&192==$scope.covers[0].zfoldCoverTypeId&&(coverstyle="book"),"bc"==size&&(panelwidth=50,panelheight=78,fontSize=8,titleSize=20,coverwidth=55,coverheight=85),"a7"==size&&(panelwidth=68,panelheight=99,fontSize=10,titleSize=30,coverwidth=74,coverheight=105),"a6"==size&&(panelwidth=99,panelheight=142,fontSize=14,titleSize=40,coverwidth=105,coverheight=148),"90 x 140"==size&&(panelwidth=84,panelheight=134,fontSize=14,titleSize=40,coverwidth=90,coverheight=140),"76 x 146"==size&&(panelwidth=70,panelheight=140,fontSize=14,titleSize=40,coverwidth=76,coverheight=146),flatheight=panelheight*rows,viewBoxWidth=2*(flatwidth=panelwidth*columns)+30,x3=(x2=(x1=OGx=5)+panelwidth)+panelwidth,4<=columns&&(x4=x3+panelwidth),5<=columns&&(x5=x4+panelwidth),6<=columns&&(x6=x5+panelwidth),7<=columns&&(x7=x6+panelwidth),8<=columns&&(x8=x7+panelwidth),9<=columns&&(x9=x8+panelwidth),10<=columns&&(x10=x9+panelwidth),xLast=OGx+flatwidth,y1=5,2<=rows&&(y2=y1+panelheight),3<=rows&&(y3=y2+panelheight),4<=rows&&(y4=y3+panelheight),data="",data=(data=(data=(data=data+("<svg xmlns:xlink='http://www.w3.org/1999/xlink' xmlns='http://www.w3.org/2000/svg' viewBox='0 0 "+(viewBoxWidth="book"==coverstyle?viewBoxWidth+panelwidth+12:viewBoxWidth))+" "+(10+flatheight)+"'><title>Template</title><defs><style type='text/css'>text{  font-family:  -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Segoe UI Symbol'; font-weight: 400; }</style></defs><g id='page1' transform='translate(0,0)'><g id='page1-fold' class='fold' fill='none' stroke='#00adee' stroke-width='0.75' stroke-dasharray='4' >")+"<path id='page1-column-fold-1' d=' M "+x2+" "+y1)+" L "+x2+" "+(viewBoxWidth=y1+flatheight)+"'/><path id='page1-column-fold-2' d='")+" M "+x3+" "+y1+" L "+x3+" "+viewBoxWidth+"'/>",4<=columns&&(data+='<path id="page1-column-fold-3" d="M '+x4+" "+y1+" L "+x4+" "+viewBoxWidth+'"/>'),5<=columns&&(data+='<path id="page1-column-fold-4" d="M '+x5+" "+y1+" L "+x5+" "+viewBoxWidth+'"/>'),6<=columns&&(data+='<path id="page1-column-fold-5" d="M '+x6+" "+y1+" L "+x6+" "+viewBoxWidth+'"/>'),7<=columns&&(data+='<path id="page1-column-fold-6" d="M '+x7+" "+y1+" L "+x7+" "+viewBoxWidth+'"/>'),8<=columns&&(data+='<path id="page1-column-fold-7" d="M '+x8+" "+y1+" L "+x8+" "+viewBoxWidth+'"/>'),9<=columns&&(data+='<path id="page1-column-fold-8" d="M '+x9+" "+y1+" L "+x9+" "+viewBoxWidth+'"/>'),10<=columns&&(data+='<path id="page1-column-fold-9" d="M '+x10+" "+y1+" L "+x10+" "+viewBoxWidth+'"/>'),2<=rows&&(data+="<path id='page1-row-fold-1' d='M "+x1+" "+y2+" L "+xLast+" "+y2+"'/>"),3<=rows&&(data+="<path id='page1-row-fold-2' d='M "+x1+" "+y3+" L "+xLast+" "+y3+"'/>"),4<=rows&&(data+="<path id='page1-row-fold-3' d='M "+x1+" "+y4+" L "+xLast+" "+y4+"'/>"),data=(data=(data=(data=(data=(data+="</g><g id='page1-cut' class='cut' fill='none' stroke='#d41a5a' stroke-width='1' ><path id='page1-cut' d='")+" M "+x1+" "+y1+" L "+xLast+" "+y1)+" L "+xLast+" "+viewBoxWidth+" L "+x1+" "+viewBoxWidth)+" L "+x1+" "+y1+"  Z '/></g>")+"<g class='title' font-size='"+titleSize+"' fill='#00adee'><text style='font-size:"+fontSize+"' x='"+(OGx+flatwidth/2)+"' y='"+(5+flatheight/2)+"' dominant-baseline='middle' text-anchor='middle'>Page 1</text>\t")+"</g><g class='covers' font-size='"+fontSize+"' fill='white'>",$scope.covers.length&&"separate"==coverstyle?(cov1tx=(cov1x=xLast-panelwidth)+panelwidth/2,cov1ty=(cov1y=y1)+panelheight/2,cov1pnlx=cov1x-3,cov1pnly=cov1y-3,rows%2!=0&&(data=data+"<rect x='"+cov1pnlx+"' y='"+cov1pnly+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary)' class='cover' rx='4'/><text style='font-size:"+fontSize+"' x='"+cov1tx+"' y='"+cov1ty+"' text-anchor='middle'>Front Cover</text>",rows%2!=0&&columns%2==0&&(data=data+("<rect x='"+((cov2x=x1)-3)+"' y='"+((cov2y=viewBoxWidth-panelheight)-3))+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary)' class='cover' rx='4'/><text style='font-size:"+fontSize+"' x='"+(cov2tx=cov2x+panelwidth/2)+"' y='"+(cov2ty=cov2y+panelheight/2)+"' text-anchor='middle'>Back Cover</text>")),4==rows&&"a6"==size?(cov2y=columns%2==0?(cov2x=x1,y1):(cov2x=x1,viewBoxWidth-panelheight),data=(data=data+("<rect x='"+(cov2x-3)+"' y='"+(cov2y-3))+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary);stroke-width:0.5;stroke:white' class='cover' rx='4'/><text style='font-size:"+fontSize+"' x='"+(cov2tx=cov2x+panelwidth/2)+"' y='"+(cov2ty=cov2y+panelheight/2)+"' text-anchor='middle'>Back Cover</text>")+"<rect x='"+cov1pnlx+"' y='"+cov1pnly+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary);stroke-width:0.5;stroke:white' class='cover' rx='4'/><text style='font-size:"+fontSize+"' x='"+cov1tx+"' y='"+cov1ty+"' dominant-baseline='middle' text-anchor='middle'>Front Cover</text>"):2==rows?data=(data=data+("<rect x='"+((cov2x=xLast-panelwidth)-3)+"' y='"+((cov2y=viewBoxWidth-panelheight)-3))+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary);stroke-width:0.5;stroke:white' class='cover' rx='4'/><text style='font-size:"+fontSize+"' x='"+(cov2tx=cov2x+panelwidth/2)+"' y='"+(cov2ty=cov2y+panelheight/2)+"' text-anchor='middle'>Back Cover</text>")+"<rect x='"+cov1pnlx+"' y='"+cov1pnly+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary);stroke-width:0.5;stroke:white' class='cover' rx='4'/><text style='font-size:"+fontSize+"' x='"+cov1tx+"' y='"+cov1ty+"' dominant-baseline='middle' text-anchor='middle' transform='rotate(180 "+cov1tx+","+cov1ty+")'>Front Cover</text>":4==rows&&(data=(data=data+("<rect x='"+((cov2x=xLast-panelwidth)-3)+"' y='"+((cov2y=viewBoxWidth-panelheight)-3))+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary);stroke-width:0.5;stroke:white' class='cover' rx='4'/><text style='font-size:"+fontSize+"' x='"+(cov2tx=cov2x+panelwidth/2)+"' y='"+(cov2ty=cov2y+panelheight/2)+"' text-anchor='middle' transform='rotate(180 "+cov2tx+","+cov2ty+")'>Back Cover</text>")+"<rect x='"+(cov1pnlx=cov1x-3)+"' y='"+(cov1pnly=cov1y-3)+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary);stroke-width:0.5;stroke:white' class='cover' rx='4'/><text style='font-size:"+fontSize+"' x='"+cov1tx+"' y='"+cov1ty+"' dominant-baseline='middle' text-anchor='middle'>Front Cover</text>")):$scope.covers.length&&(data=(data=(data+="<rect x='"+(cov1pnlx=cov1x=xLast+(totalpanels=15<(totalpanels=columns*rows)?5:8<totalpanels?3:.1)+3)+"' y='"+(cov1pnly=(cov1y=cov2y=y1)-3)+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary)' class='cover' rx='4'/>")+"<text style='font-size:"+fontSize+"' x='"+(cov1tx=cov1x+panelwidth/2+3)+"' y='"+(cov1ty=cov1y+panelheight/2)+"' text-anchor='middle'>Front Cover</text>\t<rect x='"+(xLast+3)+"' y='"+y1+"' width='"+totalpanels+"' height='"+panelheight+"' style='fill:var(--primary); stroke-width:0.5;stroke:white' class='cover'/>\t")+"<rect x='"+((cov2x=xLast-panelwidth)-3)+"' y='"+(cov2y-3)+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary)' class='cover' rx='4'/><text style='font-size:"+fontSize+"' x='"+(cov2tx=cov2x+panelwidth/2)+"' y='"+(cov2ty=cov2y+panelheight/2)+"' text-anchor='middle'>Back Cover</text>"),data+="</g></g>",OGx=20+flatwidth,x3=(x2=(x1=OGx="book"==coverstyle?OGx+panelwidth+20:OGx)+panelwidth)+panelwidth,4<=columns&&(x4=x3+panelwidth),5<=columns&&(x5=x4+panelwidth),6<=columns&&(x6=x5+panelwidth),7<=columns&&(x7=x6+panelwidth),8<=columns&&(x8=x7+panelwidth),9<=columns&&(x9=x8+panelwidth),10<=columns&&(x10=x9+panelwidth),xLast=OGx+flatwidth,y1=5,2<=rows&&(y2=y1+panelheight),3<=rows&&(y3=y2+panelheight),4<=rows&&(y4=y3+panelheight),data=(data=(data=(data+="<g id='page2' transform='translate(0,0)'><g id='page1-fold' class='fold' fill='none' stroke='#00adee' stroke-width='0.75' stroke-dasharray='4' >")+"<path id='page1-column-fold-1' d=' M "+x2+" "+y1+"  ")+" L "+x2+" "+(viewBoxWidth=y1+flatheight)+"'/><path id='page1-column-fold-2' d='\t")+" M "+x3+" "+y1+" L "+x3+" "+viewBoxWidth+"'/>",4<=columns&&(data+="<path id='page1-column-fold-3' d='M "+x4+" "+y1+" L "+x4+" "+viewBoxWidth+"'/> "),5<=columns&&(data+="<path id='page1-column-fold-4' d='M "+x5+" "+y1+" L "+x5+" "+viewBoxWidth+"'/>"),6<=columns&&(data+="<path id='page1-column-fold-5' d='M "+x6+" "+y1+" L "+x6+" "+viewBoxWidth+"'/>"),7<=columns&&(data+="<path id='page1-column-fold-6' d='M "+x7+" "+y1+" L "+x7+" "+viewBoxWidth+"'/>"),8<=columns&&(data+="<path id='page1-column-fold-7' d='M "+x8+" "+y1+" L "+x8+" "+viewBoxWidth+"'/>"),9<=columns&&(data+="<path id='page1-column-fold-8' d='M "+x9+" "+y1+" L "+x9+" "+viewBoxWidth+"'/>"),10<=columns&&(data+="<path id='page1-column-fold-9' d='M "+x10+" "+y1+" L "+x10+" "+viewBoxWidth+"'/>"),2<=rows&&(data+="<path id='page1-row-fold-1' d='M "+x1+" "+y2+" L "+xLast+" "+y2+"'/>"),3<=rows&&(data+="<path id='page1-row-fold-2' d='M "+x1+" "+y3+" L "+xLast+" "+y3+"'/>"),4<=rows&&(data+="<path id='page1-row-fold-3' d='M "+x1+" "+y4+" L "+xLast+" "+y4+"'/>"),data=(data=(data=(data=(data=(data+="</g><g id='page1-cut' class='cut' fill='none' stroke='#d41a5a' stroke-width='1' >")+"<path id='page1-cut' d=' M "+x1+" "+y1+"  \t")+" L "+xLast+" "+y1+" L "+xLast+" "+viewBoxWidth)+" L "+x1+" "+viewBoxWidth+" L "+x1+" "+y1+"  Z '/>")+"</g><g class='title' font-size='"+titleSize+"' fill='#00adee'>")+"<text style='font-size:"+fontSize+"' x='"+(OGx+flatwidth/2)+"' y='"+(5+flatheight/2)+"' dominant-baseline='middle' text-anchor='middle'>Page 2</text></g>","separate"==coverstyle&&$scope.covers.length&&columns%2!=0&&rows%2!=0&&(data=(data=data+"<g class='covers' font-size='"+fontSize+"' fill='white'><rect x='"+((cov2x=xLast-panelwidth)-3)+"' y='"+((cov2y=viewBoxWidth-panelheight)-3)+"' width='"+coverwidth+"' height='"+coverheight+"' style='fill:var(--primary)' class='cover' rx='4'/>")+"<text style='font-size:"+fontSize+"' x='"+(cov2tx=cov2x+panelwidth/2)+"' y='"+(cov2ty=cov2y+panelheight/2)+"' text-anchor='middle'>Back Cover</text></g>"),$scope.zFoldPreviewCode=data=(data+="</g></svg>")+("<input type='hidden' id='flat-height' name='flat-height' value='"+flatheight+"' />")+("<input type='hidden' id='flat-width' name='flat-width' value='"+flatwidth+"' />"),$scope.setZFoldPreview()}}]);