/* global generateBarcode docSettings ToStringHTML setCurrentDateTime drawIconField */ /*jshint laxcomma: true */ /*** CLASSE RepDocumentHtml: gestisce la generazione/disegno del documento (report) in formato html * Eredita da RepDocument - JSReportDocumentRuntime.js */ RepDocumentHtml = function (name, uid) { RepDocument.call(this); this.format = "html"; this.gcurrpage = null; this.name = name; this.progrid = 0; this.datetime = new Date(); if(Empty(uid)) uid = LibJavascript.AlfaKeyGen(5); this.uid = uid; this.parent = null; this.document = null; this.window = null; this.barcodesItems = []; this.barcodesCtrls = []; }; RepDocumentHtml.prototype = new RepDocument(); RepDocumentHtml.prototype.constructor = RepDocumentHtml; RepDocumentHtml.prototype.Ctrl = function(id){ return this.document.getElementById(id); }; RepDocumentHtml.prototype.initProcess = function(allfields,container,bprint,imgfields,simulatedData){ this.container = container; this.setParent(); this.setDocument(); this.setWindow(); this.parent.innerHTML=""; if(window.tool && window.tool=='smartreport'){ if(window.winitprocess) window.winitprocess(); } this.allfields = allfields; this.imgfields = imgfields; this.mrows = 0; this.lastRec = null; this.progrid = 0; this.simulatedData = simulatedData; }; RepDocumentHtml.prototype.appendFontsInDocument = function () { var list = this._fontList; this._cssString = ""; for (var i = 0; i < list.length; i++) this._cssString += ""; this.document.head.innerHTML += this._cssString; } RepDocumentHtml.prototype.endProcess = function(){ for(var i=0; i.imagePrintclass a::after{content:'\\ec0b'}"; stylehead += ""; stylehead += ""; if (this.theme) { stylehead+="" stylehead+="" stylehead+="" } if (!Empty(this._cssString)) stylehead += this._cssString; var mhtml = this.parent.innerHTML, inHTML = ""; if(this.container.tagName.toLowerCase() != "iframe"){ this.parent.innerHTML = ""; this.setIFrame(); this.setParent(document.getElementById(this.container.id+"ifrprev")); this.setDocument(document.getElementById(this.container.id+"ifrprev").contentWindow.document); this.setWindow(document.getElementById(this.container.id+"ifrprev").contentWindow); this.document.head.innerHTML = stylehead; inHTML = "
"; inHTML+= "
" inHTML+= "
[smrname]
" inHTML+= "
" inHTML+= "" inHTML+= "
/[nmax]
" inHTML+= "
" inHTML+= "" inHTML+= "
" inHTML+= '
'; //toolbar inHTML+= "
" inHTML+= mhtml; inHTML+= '
';//pagecontainer inHTML+= '
';//report //this.document.body.innerHTML = mhtml; inHTML = Strtran(inHTML, "[smrname]", this.name); inHTML = Strtran(inHTML, "[nmax]",'[ ' + ((this.isPreview && this.isEoPreview()) ? this.gwork.rpagecounter : this.gwork.pagecounter ) + ' pages ]'); this.document.body.innerHTML = inHTML; document.getElementById(this.container.id+"ifrprev").height = "100%"; document.getElementById(this.container.id+"ifrprev").frameborder = 0; document.getElementById(this.container.id+"ifrprev").style.border = 0; document.getElementById(this.container.id+"ifrprev").allowTransparency = true; document.getElementById(this.container.id+"ifrprev").style.backgroundColor = "rgb(82,86,89)"; this.parent.style.border = 0; this.parent.style.margin = 0; this.parent.style.overflow = "hidden"; } else{ if(Empty(this.container.style.backgroundColor)) this.container.style.backgroundColor = "rgb(82,86,89)"; } } this.end = true; this.removeCanvasImages(); var ifr = document.getElementById(this.container.id+"ifrprev"); if (ifr) { ifr.onload = function () { // tutela nel caso l'iframe non si sia ancora caricato this.contentWindow.document.head.innerHTML = stylehead; this.contentWindow.document.body.innerHTML = inHTML; } } this.execFncCallback(); }; RepDocumentHtml.prototype.removeLastLabelContinue = function(){ var toremove = []; var i; var lblco = this.document.getElementsByClassName("labelcontinue_gf"); for(i=0; i=0) toremove.push(lblc[i]); } for(i=0; i=0) pp = parseInt(Strtran(p.id,'page','')) + this.gwork.pagecounter - this.gwork.rpagecounter; if (this.isPreview && this.isEoPreview()) pp = parseInt(Strtran(p.id,'page','')); this.Ctrl(lz[i].id+'_int').innerHTML = pp;//this.gwork.pagecounter } lz = this.document.getElementsByClassName("totalpages"); for(i=0; i= 0) { if(item.isGeneric) value = repObj.datetime; else if(mdata[item.fieldDetail.alias+'##pic']) value = mdata[item.fieldDetail.alias+'##pic']; else value = mdata[item.fieldDetail.alias]; value = setCurrentDateTime(value,item); } else if(item.typeView=="numeric"){ if(item.calculation && !Empty(item.calculation.type) && item.calculation.type!='none') { value = repObj.calcObjs[item.calculation.type][item.fieldDetail.alias][item.uid]; value = repObj.setFormatNumber(value,item.fieldDetail.len,item.fieldDetail.dec,item.stdPicture); } else if(mdata[item.fieldDetail.alias+'##pic']) value = mdata[item.fieldDetail.alias+'##pic']; else { value = mdata[item.fieldDetail.alias]; value = repObj.setFormatNumber(value,item.fieldDetail.len,item.fieldDetail.dec,item.stdPicture); } } else if(item.typeView=="image"){ if (!item.isGeneric && repObj.simulatedData) value = ""; else { if (item.isGeneric) { if (item.fieldDetail && item.fieldDetail.type == "checkbox") item.style.imageSrc = (Empty(mdata[item.fieldDetail.alias])) ? repObj.uncheckedSrc : repObj.checkedSrc; value = item.style.imageSrc; } else if (noprint) value = ""; else value = mdata[item.fieldDetail.alias]; } // tratto il caso src:tooltip che potrebbe arrivarmi da griglia o da query var dp_split = value.split(":"); if (dp_split.length > 1) value = dp_split[0]; } else if (item.typeView == "html") { if (!item.isGeneric && repObj.simulatedData) value = ""; else { if (item.isGeneric) { if (item.fieldDetail && item.fieldDetail.type == "checkbox") item.style.imageSrc = (Empty(mdata[item.fieldDetail.alias])) ? repObj.uncheckedSrc : repObj.checkedSrc; value = item.style.imageSrc; } else if (noprint) value = ""; else if(mdata[item.fieldDetail.alias+'##pic']) value = mdata[item.fieldDetail.alias+'##pic']; else value = mdata[item.fieldDetail.alias]; } } else if(item.type=='field' && !item.isGeneric) { if(mdata[item.fieldDetail.alias+'##pic']) value = mdata[item.fieldDetail.alias+'##pic']; else value = Format(mdata[item.fieldDetail.alias],item.fieldDetail.len,item.fieldDetail.dec,item.stdPicture); } if(item.type=='field' && item.isGeneric && item.typeView!="pagenum" && item.typeView.indexOf("date")<0 && item.typeView!="image") value = item.fieldDetail.desc; if(noprint && item.type=='field' && !item.isGeneric && item.typeView!="image") value = ""; if(item.type=='label') value = item.value; return value; }; RepDocumentHtml.prototype.addItemInZone = function(k,item,objzone,zoneid, value, yRel, split, nrow){ if(!this.gcurrpage) return; if( value == null ) value = ''; var currpage = this.gcurrpage.lastChild; var ritem = null; if(typeof(split) == 'undefined') split = false; if(window.tool && window.tool=='smartreport'){ if(window.waddinzone) ritem = window.waddinzone(item,zoneid,true,split,nrow); } if(Empty(ritem)) ritem = this.generateHtmlElement(item); if(Empty(yRel)) yRel = ritem.yRel; currpage.innerHTML += ritem.html; this.Ctrl(ritem.id).style.position = 'absolute'; if(item.style && item.style.line && item.style.line.onlyStroke) yRel = yRel - 2; this.Ctrl(ritem.id).style.top = yRel+"px"; if(item.type!="line"){ this.Ctrl(ritem.id).style.border = "1px"; //forzatura this.Ctrl(ritem.id).style.backgroundColor = 'transparent'; } this.Ctrl(ritem.id).className += (" "+ritem.uidfor); if(item.typeView=="pagenum"){ if(item.fieldDetail.desc == "Total pages") this.Ctrl(ritem.id).className += " totalpages"; else if(item.fieldDetail.desc == "Page number") this.Ctrl(ritem.id).className += " pagenumber"; } if(item.isContinue && zoneid == "pagefooter") this.Ctrl(ritem.id).className += " labelcontinue_pf"; else if(item.isContinue && this.lastGrpFooter) this.Ctrl(ritem.id).className += " labelcontinue_gf"; if(item.typeView == "signmup") this.Ctrl(ritem.id).className += " signmup"; if(window.tool && window.tool=='smartreport'){ if(window.wupdatehtmlitem) window.wupdatehtmlitem(item,ritem,this.gwork); } else{ this.updateFontProperties(item, ritem.id); this.applyLineStyleProperties(item, ritem.id); } if(item.typeView=="barcode"){ generateBarcode(item, value, this.Ctrl(ritem.id+"_barcode"), this.Ctrl(ritem.id+"_barcode").offsetWidth, this.Ctrl(ritem.id+"_barcode").offsetHeight, null, true); this.Ctrl(ritem.id+"_barcode").setAttribute("data-value", value); this.barcodesItems.push(item); this.barcodesCtrls.push(this.Ctrl(ritem.id+"_barcode")); } else if(item.typeView=="image"){ var msrc = ""; if(value.indexOf(this.rootApp)==0 || value.indexOf(this.rootAppB)==0|| Empty(value)) msrc = value; else msrc = this.rootApp+value; this.Ctrl(ritem.id+"_img").src = msrc; } else if (item.typeView == "html") { var mvalue = item.style.htmlSrc; if (!item.isGeneric) mvalue = value; this.renderHTMLtoCanvas(item, mvalue, ritem.id); } else if(item.type!='line') { if(window.tool && window.tool=='smartreport'){ this.Ctrl(ritem.id+'_int').innerHTML = ToStringHTML(value); if(item.calculation && !Empty(item.calculation.type) && item.calculation.type!='none') drawIconField("calc",ritem); } else { this.Ctrl(ritem.id+'_int').innerHTML = ToStringHTML(value); } } if(window.tool && window.tool=='smartreport'){ if(split && nrow!=0) $(ritem.id).addClass("noclick"); } }; RepDocumentHtml.prototype.download = function () { var akey = LibJavascript.AlfaKeyGen(5); var a = document.createElement('a'); a.setAttribute("id", akey); this.document.body.appendChild(a); if(typeof a.download == "undefined"){ (window.PSAlert||window).alert('Browser Not Implemented Client Side Download!!!'); } else{ var base64doc = btoa(unescape(encodeURIComponent(this.document.documentElement.innerHTML))); a.href = 'data:text/html;base64,' + base64doc; a.download = (Empty(this.name)?LibJavascript.AlfaKeyGen(10):this.name)+".html"; a.click(); } document.body.removeChild(a); }; RepDocumentHtml.prototype.getImageBase64 = function(imgid,src,w,h){ var divId = "mspan_"+this.uid; var myDiv = this.Ctrl(divId); if(Empty(myDiv)){ myDiv = this.document.createElement("div"); myDiv.id = divId; this.document.body.appendChild(myDiv); myDiv.style.width=w+'px'; myDiv.style.height=h+'px'; myDiv.style.display='none'; myDiv.style.position="absolute"; myDiv.style.left="400px"; myDiv.style.top="400px"; } divId = this.uid+"_canvas_"+imgid; var canvas = this.Ctrl(divId); if(Empty(canvas)){ canvas = this.document.createElement("CANVAS"); canvas.id = divId; canvas.width = w; canvas.height = h; myDiv.appendChild(canvas); } var mimg = new Image(); mimg.id = this.uid+"_image_"+imgid; myDiv.appendChild(mimg); var muid = this.uid; mimg.onload = function(){ var ctx = window[muid].Ctrl(muid+"_canvas_"+imgid).getContext("2d"); ctx.drawImage(this, 0, 0, this.width, this.height, 0, 0, w, h); var dataURL = window[muid].Ctrl(muid+"_canvas_"+imgid).toDataURL("image/png"); window[muid].Ctrl(imgid).src = dataURL; }; var msrc = ""; if (src.indexOf(this.rootApp)==0 || src.indexOf(this.rootAppB)==0) msrc = src; else msrc = this.rootApp+src; mimg.src = msrc; }; RepDocumentHtml.prototype.print = function(){ if(!this.window.frameElement || this.window.frameElement.id!=this.container.id+"ifrprev") this.setWindow(document.getElementById(this.container.id+"ifrprev").contentWindow); if(this.window !== null){ this.window.print(); } }; RepDocumentHtml.prototype.drawPreviewValidator = function () { if (this.isEoPreview()) return; if (!Empty(this.watermark) && this.gcurrpage) { var div = this.document.createElement("div"); div.className = "validatorPreviewLabel"; div.textContent = this.watermark; div.style.top = - (this.gcurrpage.offsetHeight / 2) + "px"; div.style.position = 'relative'; div.style.transform = 'rotate(45deg)'; div.style.fontSize = '24pt'; div.style.color = '#E51400'; div.style.fontWeight = 'bold'; div.style.textAlign = 'center'; div.style.fontFamily = 'Helvetica'; div.style.zIndex = 1500; this.gcurrpage.appendChild(div); } };