Просмотр исходного кода

Removing form generator to separate file

Andrej Studen 2 лет назад
Родитель
Сommit
aa0aaa68d7
1 измененных файлов с 2 добавлено и 207 удалено
  1. 2 207
      web/crfTecant/formPortal.js

+ 2 - 207
web/crfTecant/formPortal.js

@@ -117,7 +117,7 @@ function generateFormArray(){
 	print("generateFormArray "+getMode());
 	
 	config.formConfig=new Object();
-	config.formConfig.softwareVersion='T.1.12';
+	config.formConfig.softwareVersion='T.1.13';
 	//report software version
 	config.document.getElementById('version').innerText=config.formConfig.softwareVersion;	
 	
@@ -462,6 +462,7 @@ function fcontinue(){
 
 	}		  
    if (config.role=='crfManager')
+      //need formGenerator.js
       addFormGenerator();
 
 }
@@ -544,209 +545,3 @@ function createForm(formId){
 }
 
 
-function addInputRow(table,header,type){
-   let fName='[addInputRow]';
-   print(fName);
-   let row=table.insertRow();
-   let cell=config.document.createElement('th');
-   let text=config.document.createTextNode(header);
-   cell.appendChild(text);
-   row.appendChild(cell);
-   let input=null;
-      
-   if (type=="select")
-      input=config.document.createElement(type);
-
-   if (type=="button"){
-      input=config.document.createElement("input");
-      input.type="button";
-   }
-   let cell1=row.insertCell();
-   cell1.appendChild(input);
-   return input;
-}
- 
-function getFormName(formId){
-   let rows=config.formConfig.dataForms.rows;
-   for (let i=0;i<rows.length;i++){
-      if (rows[i]['Key']==formId){
-         return rows[i]['formName'];
-      }
-   }
-   return "NONE";
-}
-
-function getQueryName(queryId){
-   let rows=config.formConfig.inputLists.rows;
-   for (let i=0;i<rows.length;i++){
-      if (rows[i]['Key']==queryId){
-         return rows[i]['queryName'];
-      }
-   }
-   return "NONE";
-}
-
-function getGCRow(formId){
-   let formRows=config.formConfig.generateConfigData.rows;
-   for (let i=0;i<formRows.length;i++){
-      if (formRows[i]['formId']==formId){
-         return formRows[i];
-      }
-   }
-   return Object();
-}
-
-function getIdSelectRow(crfRef){
-   let rows=config.formConfig.idSelectRows;
-   for (let i=0;i<rows.length;i++){
-      if (rows[i]['crfRef']==crfRef)
-         return rows[i];
-
-   }
-   return Object();
-}
-
-
-function addOption(input,name,value){
-   let opt=config.document.createElement("option");
-   opt.text=name;
-   opt.value=value;
-   input.options[input.options.length]=opt;
-}
- 
-function clearOptions(input){
-   for(let i = input.options.length; i >= 0; i--) {
-		input.remove(i);
-   }
-}
-	
-
-   
-function addFormGenerator(){
-      
-   let fName='[addFormGenerator]';
-   print(fName);
-   //layout
-   let table=config.document.createElement("table");
-   config.document.getElementById(config.div).appendChild(table);
-   let formSelect=addInputRow(table,'Select form',"select");
-   let idSelect=addInputRow(table,'Selecct id',"select");
-   addOption(formSelect,'<Select>',-1);
-   let formRows=config.formConfig.generateConfigData.rows;
-   for (let i=0;i<formRows.length;i++){
-      let formId=formRows[i]["formId"];
-      let formName=getFormName(formId);
-      print(fName+' '+formRows[i]["formId"]+'/'+formName);
-      addOption(formSelect,formName,formId);
-   }
-   formSelect.onchange=function(){updateIdList(formSelect,idSelect,formRows);};
-   let generateButton=addInputRow(table,'Generate Form','button');
-   generateButton.onclick=function(){createFormWithId(formSelect,idSelect);};
-      
-}
-      
-function createFormWithId(formSelect,idSelect){
-   //get form id and entry id from select and create form as above
-   let fName='[createFormWithId]';
-
-   print(fName);
-   let formId=formSelect.options[formSelect.selectedIndex].value;
-   let crfRef=idSelect.options[idSelect.selectedIndex].text;
-   let configRow=getGCRow(formId);
-   let idSelectRow=getIdSelectRow(crfRef);
-	let formConfig=config.formConfig;
-
-	print("Create form w/id "+formId);
-	
-	let crfEntry=new Object();
-	crfEntry.entryId=Date.now();
-	crfEntry["Date"]=new Date();
-	crfEntry["View"]="[VIEW]";
-   crfEntry['participantStudyId']=idSelectRow['participantStudyId'];
-   crfEntry['participantLocalId']=idSelectRow['participantLocalId'];
-
-
-	crfEntry.formStatus=configRow['formStatus'];//In progress
-	//set other variables
-	//requires studyData as part of formConfig
-	let studyData=formConfig.studyData.rows[0];
-   let varRows=formConfig['crfStaticVariables'].rows;
-   for (let i=0;i<varRows.length;i++){
-      let varName=varRows[i].staticVariable;
-	   crfEntry[varName]=studyData[varName];
-   }
-	crfEntry.UserId=LABKEY.Security.currentUser.id;
-	crfEntry.Site=config.formConfig.currentSites[0].siteNumber;
-	print("Setting site to id="+crfEntry.Site);
-	//from argument list
-	crfEntry.Form=formId;
-   crfEntry.parentCrf=crfRef;
-   
-	let qconfig=new Object();
-	qconfig.containerPath=getContainer('data');
-	qconfig.schemaName='lists';
-	qconfig.queryName='crfEntry';
-	qconfig.success=function(data){redirect()};
-	qconfig.rows=[crfEntry];
-	LABKEY.Query.insertRows(qconfig);
-}
-
-
-function updateIdList(formSelect,idSelect,formRows){
-   let fName='[updateIdList]';
-   let formId=formSelect.options[formSelect.selectedIndex].value;
-   print(fName+' id '+formId);
-   //remove old options
-   clearOptions(idSelect);
-   print(fName+' options cleared');
-   //get query associated with form
-   let queryId=-1;
-   for (let i=0;i<formRows.length;i++){
-      if (formRows[i]['formId']==formId){
-         queryId=formRows[i]['queryId'];
-         break;
-      }
-   }
-   print(fName+' queryId '+queryId);
-   if (queryId<0)
-      return;
-
-   let qselect=new Object();
-   qselect.containerPath=getContainer('data');
-   qselect.schemaName='lists';
-   qselect.queryName=getQueryName(queryId);
-   qselect.success=function(data){updateIdListWithData(idSelect,data);};
-   LABKEY.Query.selectRows(qselect);
-}
-
-function updateIdListWithData(idSelect,data){
-   let rows=data.rows;
-   config.formConfig.idSelectRows=data.rows;
-   for (let i=0;i<rows.length;i++){
-      addOption(idSelect,rows[i]['crfRef'],i);
-   }
-}
-
-function redirect(){
-
-	let debug=false;
-	let formUrl="begin";
-	let params=new Object();
-	params.name=formUrl;
-	params.pageId="CRF";
-
-	//points to crf container
-	let containerPath=getContainer('data');
-        
-	// 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("Redirecting to "+homeURL);
-	if (debug) return;	 
-	window.location = homeURL;
-
-	
-
-}