Browse Source

Modifying crfButton list generation to allow buttons limited to roles

Andrej Studen 2 years ago
parent
commit
d3f4a65ce5
1 changed files with 62 additions and 11 deletions
  1. 62 11
      web/crfTecant/crfVisit.js

+ 62 - 11
web/crfTecant/crfVisit.js

@@ -308,11 +308,12 @@ function generateSection(formSetupEntry){
 		let dName=additionalData.divName;
 		let dName=additionalData.divName;
 		
 		
 
 
-		let setup=fullAccessSetup(qName);
+		let xsetup=fullAccessSetup(qName);
 		//only set master query for additionalData
 		//only set master query for additionalData
-		setup.masterQuery=listName;
+		xsetup.masterQuery=listName;
 		//if (readonly) setup=readonlySetup(config);
 		//if (readonly) setup=readonlySetup(config);
-		generateTable(qName,dName,additionalData,setup);
+      xsetup.subTable=true;
+		generateTable(qName,dName,additionalData,xsetup);
 		//generateTable(formSetupEntry,qName,dName,additionalData,setup);
 		//generateTable(formSetupEntry,qName,dName,additionalData,setup);
 	}
 	}
 
 
@@ -767,6 +768,7 @@ function generateReview(divReviewId,divReviewListId, listName, accessMode){
 		if (vName=="ModifiedBy") return true;
 		if (vName=="ModifiedBy") return true;
 		return false;};
 		return false;};
 	reviewSetup.addApply="Add Review";
 	reviewSetup.addApply="Add Review";
+   reviewSetup.reviewTable=true;
 
 
 	let generateTableFlag=true;
 	let generateTableFlag=true;
 	let formStatus=config.formConfig.formStatus;
 	let formStatus=config.formConfig.formStatus;
@@ -781,7 +783,9 @@ function generateReview(divReviewId,divReviewListId, listName, accessMode){
 	
 	
 	reviewSetup.filters=new Object();
 	reviewSetup.filters=new Object();
 	reviewSetup.filters["crfRef"]=getCRFref();
 	reviewSetup.filters["crfRef"]=getCRFref();
-	
+   if (config.formConfig.crfEntry.parentCrf){
+      reviewSetup.filters["crfRef"]=getCRFref()+";"+config.formConfig.crfEntry.parentCrf;
+   }
  	reviewSetup.filters["queryName"]=listId;//entry in reviewComments list is queryname, all in small caps
  	reviewSetup.filters["queryName"]=listId;//entry in reviewComments list is queryname, all in small caps
 	//needs listName, in argument
 	//needs listName, in argument
 	
 	
@@ -830,6 +834,12 @@ function setListVisibility(input,setup,readonlyFlag){
 }
 }
 
 
 //>>have list refresh when data is added (not optimal yet)
 //>>have list refresh when data is added (not optimal yet)
+//
+function isFilterList(v){
+   if (typeof(v)!='string') return false;
+   if (v.search(';')==-1) return false;
+   return true;
+}
 
 
 function updateListDisplay(divName,queryName,filters,readonlyFlag){
 function updateListDisplay(divName,queryName,filters,readonlyFlag){
 	//use Labkey.QueryWebPart to show list
 	//use Labkey.QueryWebPart to show list
@@ -858,7 +868,13 @@ function updateListDisplay(divName,queryName,filters,readonlyFlag){
 	qconfig.buttonBarPosition='top';
 	qconfig.buttonBarPosition='top';
 	qconfig.filters=[];
 	qconfig.filters=[];
 	for (f in filters){
 	for (f in filters){
-		qconfig.filters.push(LABKEY.Filter.create(f, filters[f]));
+      let fType=LABKEY.Filter.Types.EQUAL;
+      print(fName+' filter ['+f+'] '+filters[f]+'/'+typeof(filters[f])+' ['+fType+']');
+     
+      if (isFilterList(filters[f])){
+         fType=LABKEY.Filter.Types.IN;
+      }
+		qconfig.filters.push(LABKEY.Filter.create(f, filters[f],fType));
 	}
 	}
 	qconfig.success=updateSuccess;
 	qconfig.success=updateSuccess;
 	qconfig.failure=updateFailure;
 	qconfig.failure=updateFailure;
@@ -1176,6 +1192,12 @@ function printVariables(q){
 	}
 	}
 }
 }
 
 
+function hasVariable(q,varName){
+   if (q && varName in q)
+      return true;
+
+   return false;
+}
 
 
 function addSpecialFieldRow(tb,specFieldSetup,setup){
 function addSpecialFieldRow(tb,specFieldSetup,setup){
    //tb is the table, specFieldSetup is a row from the table where special fields are being setup
    //tb is the table, specFieldSetup is a row from the table where special fields are being setup
@@ -1418,10 +1440,16 @@ function generateTable(listName,divName,additionalData,setup){
 	//is listName and setup.queryName a duplicate of the same value
 	//is listName and setup.queryName a duplicate of the same value
 	print(fName+': setup.queryName '+setup.queryName);	
 	print(fName+': setup.queryName '+setup.queryName);	
 	//assume data is set in config.formConfig.dataQueries[data.queryName].rows;
 	//assume data is set in config.formConfig.dataQueries[data.queryName].rows;
-	
+   let populateData=true;
+   if ("subTable" in setup){
+      print(fName+" is subTable");
+      populateData=false;
+   }
 
 
 	let entry=new Object();
 	let entry=new Object();
 
 
+
+
 	//data snapshot
 	//data snapshot
 	let fQuery=config.formConfig.dataQueries[listName];
 	let fQuery=config.formConfig.dataQueries[listName];
 
 
@@ -1431,6 +1459,12 @@ function generateTable(listName,divName,additionalData,setup){
 	
 	
 	if (fQuery.rows.length>0)
 	if (fQuery.rows.length>0)
 		entry=fQuery.rows[0];
 		entry=fQuery.rows[0];
+
+   
+   if ("reviewTable" in setup){
+      entry['reviewComment']='';
+      delete entry["ModifiedBy"];
+   }
 	
 	
 	let tb=config.document.createElement('table');
 	let tb=config.document.createElement('table');
 	tb.className="t2";
 	tb.className="t2";
@@ -1448,7 +1482,7 @@ function generateTable(listName,divName,additionalData,setup){
 		if (field.hidden) continue;
 		if (field.hidden) continue;
 		if (field.name=="crfRef") continue;
 		if (field.name=="crfRef") continue;
 		addFieldRow(tb,field,setup,additionalData);
 		addFieldRow(tb,field,setup,additionalData);
-		populateFieldRow(entry,field,setup);
+		if (populateData) populateFieldRow(entry,field,setup);
       if (fieldUID in config.formConfig["specialFields"]){
       if (fieldUID in config.formConfig["specialFields"]){
          let specFieldSetup=config.formConfig["specialFields"][fieldUID];
          let specFieldSetup=config.formConfig["specialFields"][fieldUID];
          addSpecialFieldRow(tb,specFieldSetup,setup);
          addSpecialFieldRow(tb,specFieldSetup,setup);
@@ -2057,7 +2091,7 @@ function verifyData(){
 	}
 	}
 	//this is necessary only for Generated to Generation completed step
 	//this is necessary only for Generated to Generation completed step
 	let actionSettings=config.formConfig.actionSettings['onSubmit'];	
 	let actionSettings=config.formConfig.actionSettings['onSubmit'];	
-	if (actionSettings && "updateRegistration" in actionSettings){
+	if (hasVariable(actionSettings,"updateRegistration")){
 		updateRegistration();
 		updateRegistration();
 	}
 	}
 	let targetStatus=config.formConfig.targetStatus['onSubmit'];	
 	let targetStatus=config.formConfig.targetStatus['onSubmit'];	
@@ -2065,7 +2099,7 @@ function verifyData(){
 	print('verifyStatus: targetStatus: '+targetStatus);
 	print('verifyStatus: targetStatus: '+targetStatus);
 	
 	
 	let finalStep=redirect;
 	let finalStep=redirect;
-	if (actionSettings && "finalStep" in actionSettings){
+	if (hasVariable(actionSettings,"finalStep")){
 		//set to doNothing to remain on submit window
 		//set to doNothing to remain on submit window
 		if (actionSettings.finalStep=="doNothing"){
 		if (actionSettings.finalStep=="doNothing"){
 			finalStep=doNothing;
 			finalStep=doNothing;
@@ -2678,7 +2712,24 @@ function afterConfig(){
 
 
 	print("Generating buttons for formStatus \""+ formStatus+"\"");
 	print("Generating buttons for formStatus \""+ formStatus+"\"");
 
 
-	let buttonRows=config.formConfig.crfButtons.rows;
+   let allButtonRows=config.formConfig.crfButtons.rows;
+	let buttonRows=new Array();
+   
+   //specifying role=X in actionSettings will limit button to that role
+   for (let i=0;i<allButtonRows.length;i++){
+      let action=allButtonRows[i]['action'];
+      //filter on actionSettings
+      let as=config.formConfig.actionSettings[action];
+      if (hasVariable(as,'role')){
+         print('Role['+config.formConfig.operator+'/'+as['role']+'] limited for action '+action);
+         //mismatch skips addition of button to buttonRows
+         if (config.formConfig.operator!=as['role']) continue;
+      }
+      buttonRows.push(allButtonRows[i]);
+   }
+
+
+
 	for (let i=0;i<buttonRows.length;i++){
 	for (let i=0;i<buttonRows.length;i++){
 		let bt=buttonRows[i];
 		let bt=buttonRows[i];
 		if (typeof window[bt.action]==="function"){
 		if (typeof window[bt.action]==="function"){
@@ -3183,7 +3234,7 @@ function setFormConfig(){
 	//add object to store form related data
 	//add object to store form related data
 	config.formConfig=new Object();
 	config.formConfig=new Object();
 
 
-	config.formConfig.softwareVersion='T.15.35';
+	config.formConfig.softwareVersion='T.15.43';
 	let debug=true;
 	let debug=true;
 
 
 	if (debug)
 	if (debug)