Browse Source

Changes in crfVisit.js, but not sure why they are there

Andrej Studen 1 year ago
parent
commit
ca9b0378e8
1 changed files with 56 additions and 15 deletions
  1. 56 15
      web/crf/crfVisit.js

+ 56 - 15
web/crf/crfVisit.js

@@ -202,7 +202,24 @@ function getAdditionalData(formSetupEntry){
 	print(fName+': setting values');
 	ad.showFlag=formSetupEntry["showFlag"];
 	ad.showFlagValue=formSetupEntry["showFlagValue"];
-	ad.queryName=formSetupEntry["showQuery"];
+   //variables associated with target query
+   let qVars=formSetupEntry["showQuery"].split(';');
+	ad.queryName=qVars[0];
+   //remove first element
+   qVars.shift();
+   //join back to string for parsing
+   let code=qVars.join(";");
+   //if empty string, set to undefined for parseCode
+   if (code.length==0){
+      code=undefined;
+   }
+   //parse var=value pairs
+   ad.variableDefinition=parseCode(code);
+   //print for debugging
+   for (let f in ad.variableDefinition){
+      let v=ad.variableDefinition[f];
+      print(fName+': adding ['+f+']='+v);
+   }
 	ad.filters=new Object();
 	ad.filters['crfRef']=getCRFref();
 	let msg=fName+": flag "+ad.showFlag;
@@ -280,6 +297,10 @@ function parseVariableDefinition(formSetupEntry){
    let fName='parseVariableDefinition['+formSetupEntry['title']+']';
    let code=formSetupEntry['variableDefinition'];
    print(fName+' '+code);
+   return parseCode(code);
+}
+
+function parseCode(code){
    //helper function to decode content of variableDefinition 
    //to a JS object
    //
@@ -928,8 +949,14 @@ function setListVisibility(input,setup,readonlyFlag){
 	x.style.display="none";
 
 	let sText;
-	if (readonlyFlag) sText=input.innerText;
-	else sText=input.options[input.selectedIndex].text;
+   if ("setVariable" in input){
+      sText=input.setVariable;
+   }
+	else{
+      if (readonlyFlag) sText=input.innerText;
+	   else sText=input.options[input.selectedIndex].text;
+   }
+   
 			
 	if (debug) print(fName+": Selected option text: "+sText);
 
@@ -1259,7 +1286,7 @@ function addFieldRow(tb,field,setup,additionalData){
    	//clear existing fields from input	
 	for(let i = input.options.length; i >= 0; i--) {
 		input.remove(i);
-   	}
+   }
 	
 	//create option -1
 	let opt = config.document.createElement("option");
@@ -1307,7 +1334,9 @@ function selectEntry(entryRows,setVariables){
 
 
 function populateFieldRow(entry,field,setup){
-	populateField(entry,field,setup);
+
+   if (!(field.name in setup.setVariables))
+	   populateField(entry,field,setup);
 	populateSubQuery(entry,field,setup);
 }
 
@@ -1333,20 +1362,36 @@ function populateSubQuery(entry,field,setup){
 	let id=setup.getInputId(field.name);
 	
 	if (eId!=id) {
-		print(fName+": ignoring field "+id+"/"+eId);
+		print(fName+": X ignoring field "+id+"/"+eId);
 		return;
 	}
 	
 	print(fName+': id '+id);
 	//hard to estimate readonlyFlag
 	//
+   let readonlyFlag=setup.readonlyFlag(field.name);
+
 	let input=config.document.getElementById(id);
-	let eType=input.nodeName.toLowerCase();
-	let readonlyFlag=eType!="select";
+   if (input){
+	   let eType=input.nodeName.toLowerCase();
+	   readonlyFlag=eType!="select";
+   }
+   else{
+      input=new Object();
+      input.setVariable=getLookupLabel(field,setup.setVariables[field.name])
+   }
 	setListVisibility(input,setup,readonlyFlag);
 
 }
 
+function getLookupLabel(field,value){
+   let lookup=field["lookup"];
+   //get all values from config.formConfig.lookup[X]
+   let lObject=config.formConfig.lookup[lookup.queryName];
+   return lObject.LUT[value];
+	
+}
+
 function populateField(entry,field,setup){
 
 	let vName=field.name;
@@ -1377,10 +1422,7 @@ function populateField(entry,field,setup){
 	
 	//lookup for readonly
 	if (isLookup && varValue!="UNDEF"){
-		let lookup=field["lookup"];
-		//get all values from config.formConfig.lookup[X]
-		let lObject=config.formConfig.lookup[lookup.queryName];
-		varValue=lObject.LUT[varValue];
+      varValue=getLookupLabel(field,varValue);
 	}
 
 	print('Element: '+input);
@@ -1475,7 +1517,6 @@ function populateTable(listName,writeMode,setup){
 		print(fName+": Adding field: "+f+'/'+field.name+' hidden: '+field.hidden);
 		if (field.hidden) continue;
 		if (field.name=="crfRef") continue;
-      if (field.name in setup.setVariables) continue; 
       populateFieldRow(entry,field,setup);
 	   let helpItem=getHelpItem(field,setup);
       if (helpItem) helpRows.push(helpItem);
@@ -2939,7 +2980,6 @@ function populateSection(sectionId){
       let setup=getSetup(sectionId,queryName,writeMode);
       setup.setVariables=parseVariableDefinition(entry);
       setHelp(setup,entry);
-      //this fails for setVariables, although they are available via entry['variableDefinition']
 		populateTable(queryName,writeMode,setup);
 		return;
 	}
@@ -3216,7 +3256,8 @@ function setFormConfig(){
 	//add object to store form related data
 	config.formConfig=new Object();
 
-	config.formConfig.softwareVersion='0.15.09';
+   config.formConfig.softwareVersion='0.15.14';
+
 	let debug=true;
 
 	if (debug)