123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 |
- function selectRows(cb){
- this.config.print(this.fName+": selectRows");
- let xRows=new Object();
- let gObj=this;
- xRows.schemaName=this.schemaName;
- xRows.queryName=this.queryName;
- xRows.success=cb;
- xRows.failure=function(errorInfo){gObj.fail(errorInfo);};
- LABKEY.Query.selectRows(xRows);
- this.config.print(this.fName+": selectRows completed");
- }
- function insertRows(rows){
- this.config.print(this.fName+": insertRows");
- let iRows=new Object();
- let gObj=this;
- iRows.schemaName=this.schemaName;
- iRows.queryName=this.queryName;
- iRows.rows=rows;
- iRows.success=function(data){gObj.callback(data);};
- LABKEY.Query.insertRows(iRows);
- }
-
- function zeroPad(val,strLength=3){
- let strK=val.toString();
- return strK.padStart(strLength,'0');
- }
- function findFirstAvailableKey(rows){
- let k=-1;
- for (let i=0;i<rows.length;i++){
- if (rows[i]['Key']>k){
- k=rows[i]['Key'];
- }
- }
- this.config.print(this.fName+': Key candidate: '+(k+1));
- return k+1;
- }
- function generateObjectAtKey(k){
- let regCode=this.codeBase+this.zeroPad(k);
- this.config.print(this.fName+": regCode "+regCode);
- let row=new Object();
- row['Key']=k;
- row[this.codeField]=regCode;
- if ("addData" in this){
- for (let q in this.addData){
- row[q]=this.addData[q];
- }
- }
- return row;
- }
- function getCode(row){
- return row[this.codeField];
- }
- function updateField(text){
- let el=this.config.document.getElementById(this.elementId);
- el.value=text;
- }
- function generateId(data){
- this.config.print(this.fName+": generateId "+data.rows.length);
- let k=this.findFirstAvailableKey(data.rows);
- let row=this.generateObjectAtKey(k);
- this.updateField(this.getCode(row));
- let rows=new Array();
- rows.push(row);
- this.insertRows(rows);
- }
- function doNothing1(data){
- this.config.print(this.fName+": doNothing() called");
- }
- function fail(errorInfo){
- this.config.print(this.fName+": error "+errorInfo.exception);
- }
- function execute(){
- let gObj=this;
- this.config.print(this.fName+": execute");
- this.selectRows(function(data){gObj.generateId(data);});
- }
- function inspect(){
- this.config.print(this.fName);
- this.config.print("query: "+this.schemaName+'/'+this.queryName);
- this.config.print("codeBase "+this.codeBase+" codeField "+this.codeField);
- this.config.print("version 25");
- }
- //generic function for all functors
- //config is there by default
- //
- //pars is semicolon delimeted list of parName=value pairs;
- //required:
- //codeBase - prepend ids with this set of letters
- //schemaName - schema of queryName
- //queryName - query that keeps assigned ids
- //codeField - id field in queryName
- //
- //outputId is the field that gets updated with the button result
- //
- //object is initialized from a list in LabKey
- //
- function getGenerationObject(config,qPar,outputId){
- let gObj=new Object();
- gObj.config=config;
- gObj.insertRows=insertRows;
- gObj.selectRows=selectRows;
- gObj.zeroPad=zeroPad;
- gObj.findFirstAvailableKey=findFirstAvailableKey;
- gObj.generateObjectAtKey=generateObjectAtKey;
- gObj.getCode=getCode;
- gObj.updateField=updateField;
- gObj.generateId=generateId;
- gObj.codeBase=qPar["codeBase"];
- gObj.schemaName=qPar["schemaName"];
- gObj.queryName=qPar["queryName"];
- gObj.codeField=qPar["codeField"];
- gObj.elementId=outputId;
- gObj.execute=execute;
- gObj.inspect=inspect;
- gObj.fName="[generateRegistration]";
- gObj.fail=fail;
- gObj.doNothing1=doNothing1;
- gObj.callback=gObj.doNothing1;
- //should set codeBase and elementId after initialization
- return gObj;
- }
|