{
for(let field of SmartFormsAddNewVar.FormBuilder.RedNaoFormElements)
if(field.Id==id)
return field;
return null;
}
private GetIntellisenceforField(editor:any ,cursor: CodeMirrorCursor, line: string) {
let index = cursor.ch - 3;
let currentField = '';
let fieldId='';
while ((currentField = line.charAt(index)) != ' '&&index>0)
{
fieldId=currentField+fieldId;
index--;
}
if(fieldId.length>2)
fieldId=fieldId.substring(7,fieldId.length-1);
let field=this.GetFieldById(fieldId);
if(field==null)
return;
let dictionary=SFAutoCompleteFieldDictionary.GetDictionary(field.GetDataStore());
if(dictionary!=null)
{
let list =this.GenerateList(editor);
for(let method of dictionary.availableMethods)
list.AddItem(method.label,method.label2,method.value,method.description);
return list;
}
return null;
}
}
class ListGenerator{
public data:any;
constructor(editor:any){
let cursor=editor.getCursor();
this.data={
type:'html',
list:[],
from:cursor,
to:cursor
}
}
AddItem(label:string,label2:string,value:string,description:string):ListGenerator{
let colorDictionary={};
let labelElement=`${label}${label2!=''?`${this.StylizeText(colorDictionary,label2)}`:''}${this.StylizeText(colorDictionary,description)}
`;
this.data.list.push({label:labelElement,value:value});
return this;
}
private StylizeText(colorDictionary:any,label: string) {
let reg=/\$\$([^(\$\$)]+)\$\$/g
let m;
let count=-1;
let colors=['red','blue','#008000','#8B008B'];
while(m=reg.exec(label))
{
let color;
if(typeof colorDictionary[m[1]]!='undefined')
color=colorDictionary[m[1]];
else{
count++;
color=colors[count];
colorDictionary[m[1]]=color;
}
label=label.replace(m[0],`${m[1]}`);
reg.lastIndex=0;
}
return label;
}
}
interface CodeMirrorCursor{
ch:number;
line:number;
}
declare let SFAutoCompleteFieldDictionary:any;