Andrej Studen 3 лет назад
Родитель
Сommit
2716ec4244
1 измененных файлов с 18 добавлено и 9 удалено
  1. 18 9
      web/crf/crfVisit.js

+ 18 - 9
web/crf/crfVisit.js

@@ -1982,8 +1982,8 @@ config.blob;
 config.blobInterval;
 
 function checkBlob(){
-	print("Blob: "+config.blob);
-	if (blob) {
+	print("checkBlob: "+config.blob);
+	if (config.blob) {
 		clearInterval(config.blobInterval);
 		config.a.href = config.window.URL.createObjectURL(config.blob);
 		print("HREF: "+config.a.href);
@@ -2003,11 +2003,11 @@ function printForm(){
 
 	let doPrint=false;
 	
-	//let doc=new PDFDocument();
-	//doc.fontSize(25).text("Some text with standard font Andrej!", 100, 100);
+	config.doc=new PDFDocument();
+	config.doc.fontSize(25).text("Some text with standard font Andrej!", 100, 100);
 	//doc.end();
-	//let stream = doc.pipe(blobStream()).on("finish",function(){
-	//		blob=stream.toBlob("application/pdf");});
+	let stream = config.doc.pipe(blobStream()).on("finish",function(){
+			config.blob=stream.toBlob("application/pdf");});
 	
 	print("BLob: "+config.blob);
 	config.a = config.document.createElement("a");
@@ -2015,7 +2015,8 @@ function printForm(){
 	config.a.innerHTML="Download PDF";
 	config.a.style = "display: none";
 	config.count=0;
-	lobInterval=setInterval(checkBlob,1000);
+	//run until blob is set
+	config.blobInterval=setInterval(checkBlob,1000);
 
 	//pick data from crfForm list
         print("Printing form");
@@ -2030,6 +2031,7 @@ function printForm(){
 		selectRows.queryName=qName;
 		selectRows.filterArray=[LABKEY.Filter.create('crfRef',config.formConfig.crfEntry['entryId'])];
 		selectRows.success=collectFormData;
+		//skip for now
 		LABKEY.Query.selectRows(selectRows);
 		//deal with additional data
 	}
@@ -2037,14 +2039,19 @@ function printForm(){
 }
 
 function collectFormData(data){
+	print(config,"Adding "+data.queryName);
+	config.doc.fontSize(25).text("Adding "+data.queryName, 100, 100);
 	config.formConfig.fields[data.queryName].data=data;
 	for (f in config.formConfig.fields){
 		let field=config.formConfig.fields[f];
+		//serve as monitor - if any of the fields has no data object, return in the loop.
+		//Only when all fields have a data entry one should exit
 		if ("data" in field) continue;
 		return;
 	}
 	print("All done");
 	formatFormData();
+	config.doc.end();
 }
 
 function formatFormData(){
@@ -2177,6 +2184,8 @@ function afterFormStatus(formConfig, data){
 	if (formConfig.formStatus=="Approved"){
 		generateButton("submitDiv","Review submission",
 			"Restore form for further review",onUpdateForReview);
+		generateButton("submitDiv","Print form",
+				"Generate PDF",printForm);
 		done="TRUE";
 	}
 	if (done=="FALSE"){
@@ -2222,7 +2231,8 @@ function afterFormStatus(formConfig, data){
 
 function setFormConfig(){
 
-	//generateDebugSection(config);
+	//add object to store form related data
+	config.formConfig=new Object();
 
 	let debug=true;
 
@@ -2234,7 +2244,6 @@ function setFormConfig(){
 	selectRows.schemaName='lists';
 	selectRows.queryName='crfEntry';
 	selectRows.filterArray=[LABKEY.Filter.create('entryId',getCRFref())];
-	config.formConfig=new Object();
 	//store form related data to this object
 	selectRows.success=afterCRFEntry;
 	LABKEY.Query.selectRows(selectRows);