Explorar el Código

adding populateSelect

Eager Beaver hace 5 años
padre
commit
06e93ebabf
Se han modificado 1 ficheros con 94 adiciones y 3 borrados
  1. 94 3
      web/tecant/crfPortal.js

+ 94 - 3
web/tecant/crfPortal.js

@@ -9,7 +9,7 @@ function drawForm(par){
 	let tableId="entryTable"; 
 	generateTable(par,"formDiv",tableId);
 	generateRow(par,tableId,"User");//generateTableRow
-	populateSelectTableEntry(par,"User");
+	populateSelectTableEntry(par,"User");//populateTableRow , populateSelect
 	
 
 }
@@ -256,8 +256,8 @@ function populateTableRow(data,par,rowId){
 	
 	let config=generateQConfig(field.lookup.queryName);
 	config.schemaName=field.lookup.schemaName;
-	//config.success=function(lookupData){populateSelect(lookupData,data,par,rowId)};
-	config.success=function(data){selectRowsSuccess(par.config,data)};
+	config.success=function(lookupData){populateSelect(lookupData,data,par,rowId)};
+	//config.success=function(data){selectRowsSuccess(par.config,data)};
 	config.failure=function(errorObj){selectRowsFailure(par.config,errorObj)};
 	LABKEY.Query.selectRows(config);	
 	
@@ -266,6 +266,97 @@ function populateTableRow(data,par,rowId){
 	
 }	
 
+function populateSelect(data,selectedData, par, rowId){
+	//data is the set of lookup entries, selectedData is a subset of entries valued at lookup.keyColumn 
+	let debug=true;
+	if (debug)
+		print(par.config,"populateSelect Data: "+data.queryName+" selectedData:"+selectedData.queryName);
+	let row=par.vars[rowId];
+	let selectId=row.selectId; 
+	
+	let varName=row.masterSelectVarName;
+	if ("filter" in row){
+		varName=row.filter.filterVarName;
+	}
+	let field=getField(par.config,selectedData,varName);
+
+	let displayColumn=field.lookup.displayColumn;
+	let keyColumn=field.lookup.keyColumn;
+
+	if (debug){
+		print(par.config,"Query: "+data.queryName);
+		print(par.config,"ElementId: "+selectId);
+		print(par.config,"keyColumn: "+keyColumn);
+		print(par.config,"displayColumn: "+displayColumn);
+	
+	}
+	let el = document.getElementById(selectId);
+	
+	if (debug)
+		print(par.config,"Element: "+el);
+   	
+	for(i = el.options.length; i >= 0; i--) {
+		el.remove(i);
+   	}
+	if ("addSelect" in row){
+		let opt = par.config.document.createElement("option");
+		opt.text = "<Select>";
+		opt.value = -1;
+		el.options[0] = opt;
+	}
+
+	if ("addNewFlag" in row){
+		let opt = par.config.document.createElement("option");
+		opt.text = "Add New" 
+		opt.value = row.addNewFlag;
+		el.options[el.options.length] = opt;
+	}
+
+	for (var i = 0; i < data.rows.length; i++) {
+		let key=data.rows[i][keyColumn];
+		let skip=true;
+		if (row.selectAll){
+			skip=false;
+		}
+		else{
+			if (debug)
+				print(par.config,"Selecting from: "+selectedData.rows.length);
+			for (let j=0; j< selectedData.rows.length; j++){
+				let entry=selectedData.rows[j];
+				if (debug)
+					print(par.config,"Comparing: "+entry[varName]+"/"+key);
+				if (key!=entry[varName]) continue;
+				skip=false;
+				break;
+			}
+		}
+		if (skip) continue;
+		let opt = par.config.document.createElement("option");
+		opt.text = data.rows[i][displayColumn];
+		opt.value = data.rows[i][keyColumn];
+		if (debug)
+			print(par.config,"Adding: "+opt.value+" : "+opt.text);
+	
+		el.options[el.options.length] = opt;
+	
+
+		if ("selectedKey" in row){ 
+			if (debug)
+				print(par.config,"Comparing: " + opt.value  + "/" + row["selectedKey"]);
+		
+        		if (opt.value==row["selectedKey"]){
+				el.selectedIndex=el.options.length-1;
+				if (debug)
+					print(par.config,"Equal; "+el.selectedIndex);
+			}
+		}
+	}
+	if (debug)
+		print(par.config,"Running callback");
+
+	row.callback(par,rowId);
+}	
+
 //populateSelect, populateSelectNotLookup
 
 function generateListAndPopulateDaughterSelect(par,rowId){;}