| 
					
				 | 
			
			
				@@ -453,7 +453,7 @@ function toggleVisibility(config, divName,buttonName){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				   	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-function generateButton(config,divName,buttonName,callback,callbackParameters){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function generateButton(config,divName,title,buttonName,callback,callbackParameters){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	let debug=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if (debug) print(config,"generateButton"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -463,7 +463,7 @@ function generateButton(config,divName,buttonName,callback,callbackParameters){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	let r1=tb.insertRow(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	th=config.document.createElement('th'); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	r1.appendChild(th); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-	th.innerHTML="Complete submission"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	th.innerHTML=title; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	//*!* 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	let c2=r1.insertCell(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	let i1=config.document.createElement("input");	 
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1325,7 +1325,107 @@ function checkData(data,config){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+//************************************************** 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+// 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function onRemoveCRF(config){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let debug=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if (debug){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		print(config,"Removing CRF"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let selectRows=new Object(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	selectRows.containerPath=config.containerPath; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	selectRows.schemaName="lists"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	selectRows.queryName="inputLists"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	selectRows.success=function(data){afterInputLists(data,config)}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	LABKEY.Query.selectRows(selectRows); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function afterInputLists(data,config){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let debug=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if (debug) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		print(config,"After input lists"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	config.inputLists=data; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	config.inputListsIterator=0; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	removeCRFLoop(config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function removeCRFLoop(config){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let debug=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let i=config.inputListsIterator; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if (debug) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		print(config,"removeCRFLoop ["+i+"/"+config.inputLists.rows.length+"]"); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if (i>config.inputLists.rows.length) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		//return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		redirect(config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let queryName="crfEntry"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let idVar="entryId"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if (i<config.inputLists.rows.length){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		queryName=config.inputLists.rows[i].queryName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		idVar="crfRef"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if (debug) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		print(config,"["+i+"/"+config.inputLists.rows.length+"] "+queryName+"/"+idVar); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let selectRows=new Object(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	selectRows.containerPath=config.containerPath; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	selectRows.schemaName="lists"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	selectRows.queryName=queryName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	selectRows.filterArray=[LABKEY.Filter.create(idVar,getCRFref(config))]; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	selectRows.success=function(data){removeListCRF(data,config)}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	LABKEY.Query.selectRows(selectRows); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function removeListCRF(data,config){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let debug=true; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if (debug) 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		print(config,data.queryName+": "+data.rows.length); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	config.inputListsIterator+=1; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	if (data.rows.length==0){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		removeCRFLoop(config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		return; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let deleteRows=new Object(); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	deleteRows.containerPath=config.containerPath; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	deleteRows.schemaName=data.schemaName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	deleteRows.queryName=data.queryName; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	deleteRows.success=function(data){removeCRFLoop(config)}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	deleteRows.rows=data.rows; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	LABKEY.Query.deleteRows(deleteRows); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+function redirect(config){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let formUrl="begin"; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	var params = { 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		"name": formUrl, // The destination wiki page. The name of this parameter is not arbitrary. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	}; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	let containerPath= config.containerPath; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	// This changes the page after building the URL.  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	//Note that the wiki page destination name is set in params. 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+         
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	var homeURL = LABKEY.ActionURL.buildURL("project", formUrl , containerPath, params); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+        print(config,"Redirecting to "+homeURL); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	window.location = homeURL; 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 function generateMasterForm(config){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
	
		
			
				| 
					
				 | 
			
			
				@@ -1362,11 +1462,13 @@ function generateMasterForm(config){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	//requires onSubmit 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	if (config.review){ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		generateButton(config,"submitDiv","Upload to database",onDatabaseUpload,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		generateButton(config,"submitDiv","Ask for further review",onUpdateForReview,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		generateButton(config,"submitDiv","Complete submission","Upload to database",onDatabaseUpload,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		generateButton(config,"submitDiv","Review submission","Ask for further review",onUpdateForReview,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		generateButton(config,"submitDiv","Remove submission","Remove CRF form",onRemoveCRF,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	}	 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	else{ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				-		generateButton(config,"submitDiv","Submit",onSubmit,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		generateButton(config,"submitDiv","Complete submission","Submit",onSubmit,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				+		generateButton(config,"submitDiv","Remove submission","Remove CRF form",onRemoveCRF,config); 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 	} 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				  
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 } 
			 |