application.ADF.scripts.loadJQuery(); application.ADF.scripts.loadJQueryUI(); application.ADF.scripts.loadFontAwesome(); //application.ADF.scripts.loadJQueryHighlightTextArea(); // Variable for the version of the field - Display in Props UI. fieldVersion = "1.2.3"; // initialize some of the attributes variables typeid = attributes.typeid; prefix = attributes.prefix; formname = attributes.formname; currentValues = attributes.currentValues; fieldID = ''; formID = attributes.formid; elementFormName = ""; fieldPropsEnabled = false; widgetScriptEditorEnabled = false; widgetScriptDirExists = false; errorMsg = ""; siteDir = request.site.dir; /* WidgetScript INI folder Defaults */ widgetDefaultName = ""; widgetDefaultDir = "/_cs_widgets"; widgetConfigDir = "/config"; /* WidgetScript INI file Defaults */ scriptFileExt = "ini"; scriptFileName = ""; scriptFileNameCustom = ""; scriptFilePath = ""; fullScriptDir = ""; fullScriptPath = ""; fullScriptPathCustom = ""; fullScriptName = ""; fullScriptNameCustom = ""; //WriteDump(var=dlgtype,expand=false); //WriteDump(var=attributes,expand=false); //WriteDump(var=currentValues,expand=false); /* DEV ONLY removeSavedDirPath = false; if ( removeSavedDirPath ) { structDelete(currentValues,"widgetScriptDirPath"); structDelete(currentValues,"widgetScriptDirStatus"); }*/ // Is this a valid dlgType? switch (dlgtype) { case 'customelement': case 'metadata': fieldPropsEnabled = true; break; default: fieldPropsEnabled = false; } if ( fieldPropsEnabled ) { // Is this a new field? if ( StructKeyExists(attributes,"fieldid") AND IsNumeric(attributes.fieldid) AND attributes.fieldid GT 0 ) fieldid = attributes.fieldid; // If fieldid is a valid number or is greater than 0 we can enable the widget script editor if ( IsNumeric(fieldid) AND fieldid GT 0 ) widgetScriptEditorEnabled = true; // Get the Element Form Name for the specific form type elementFormName = getElementFormName(elementType=dlgtype,formID=attributes.formid); //WriteDump(elementFormName); if ( LEN(TRIM(elementFormName)) EQ 0 ) { errorMsg = "The Element Form name could not be resolved from provided Form ID!"; fieldPropsEnabled = false; } else { // Build the Widget defualt name widgetDefaultName = LCASE(TRIM(REREPLACENOCASE(elementFormName,"[^A-Za-z0-9]","-","all"))); // Build the Widget default script path widgetScriptDefaultDir = widgetDefaultDir & "/" & widgetDefaultName & widgetConfigDir & "/"; fieldPropsEnabled = true; } } //Setup the default values defaultValues = StructNew(); defaultValues.widgetScriptDirPath = widgetScriptDefaultDir; defaultValues.widgetScriptDirStatus = ""; defaultValues.widgetScript = defaultScriptText(); defaultValues.widgetScriptStatus = ""; //defaultValues.defaultText = ""; //defaultValues.useUdef = 0; //defaultValues.defaultValue = ""; //WriteDump("defaultValues.widgetScriptDirPath"); //WriteDump(defaultValues.widgetScriptDirPath); // Check if widgetScriptDirPath is defined and matches the default value if ( StructKeyExists(currentValues,"widgetScriptDirPath") ) { //WriteDump("currentValues.widgetScriptDirPath"); //WriteDump(currentValues.widgetScriptDirPath); // Clear the saved Dir STATUS value if ( StructKeyExists(currentValues,"widgetScriptDirStatus") ) currentValues.widgetScriptDirStatus = ""; if ( LEN(TRIM(currentValues.widgetScriptDirPath)) EQ 0 ) { defaultValues.widgetScriptDirStatus = "new"; widgetScriptEditorEnabled = false; } else if ( currentValues.widgetScriptDirPath EQ defaultValues.widgetScriptDirPath ) defaultValues.widgetScriptDirStatus = "default"; else defaultValues.widgetScriptDirStatus = "custom"; } else { defaultValues.widgetScriptDirStatus = "new"; widgetScriptEditorEnabled = false; } //WriteDump("widgetScriptDirStatus"); //WriteDump(defaultValues.widgetScriptDirStatus); //This will override the default values with the current values. //In normal use this should not need to be modified. currentValueArray = StructKeyArray(currentValues); for(i=1;i<=ArrayLen(currentValueArray);i++){ //If there is a default value set AND there is a current value set update the default value with the current value if ( StructKeyExists(defaultValues,currentValueArray[i]) ) { defaultValues[currentValueArray[i]] = currentValues[currentValueArray[i]]; } } //WriteDump(var=defaultValues,expand=false,label="default"); //WriteDump(var=currentValues,expand=false,label="current"); //if ( !StructKeyExists(currentValues,"widgetScriptStatus") OR LEN(TRIM(defaultValues.widgetScriptStatus)) EQ 0 ) // defaultValues.widgetScriptStatus = ""; //if ( !StructKeyExists(currentValues,"widgetScriptDirStatus") OR LEN(TRIM(defaultValues.widgetScriptDirStatus)) EQ 0 ) // defaultValues.widgetScriptDirStatus = "notsaved"; // TEMP - Use to reset script text to the DEFAULT //defaultValues.widgetScript = defaultScriptText(); if ( fieldPropsEnabled ) { if ( widgetScriptEditorEnabled ) { // Build the WidgetScript config file name form the Form Name scriptFileName = widgetDefaultName & "-" & attributes.fieldid; scriptFileNameCustom = scriptFileName & "_custom"; // Build the INI file for Widget Configuration Form Fields scriptFilePath = defaultValues.widgetScriptDirPath; if ( Left(scriptFilePath,1) EQ "/" ) siteDir = reReplace(request.site.dir,"/$",""); if ( Right(scriptFilePath,1) NEQ "/" ) scriptFilePath = scriptFilePath & "/"; // Hard Code the "config" directory - NOT USED //if ( ListLast(scriptFilePath,"/") NEQ "config" ) // scriptFilePath = scriptFilePath & "config/"; fullScriptDir = siteDir & scriptFilePath; fullScriptName = scriptFileName & "." & scriptFileExt; fullScriptPath = siteDir & scriptFilePath & fullScriptName; fullScriptNameCustom = scriptFileNameCustom & "." & scriptFileExt; fullScriptPathCustom = siteDir & scriptFilePath & fullScriptNameCustom; //WriteDump(var=scriptFileName,expand=false); //WriteDump(var=scriptFileNameCustom,expand=false); //WriteDump(var=fullScriptPath,expand=false); //WriteDump(var=fullScriptPathCustom,expand=false); // Check if Directory Exists if ( DirectoryExists(fullScriptDir) ) widgetScriptDirExists = true; // If the INI file does not exist, create it and the folders needed if ( !FileExists(fullScriptPath) ) { if ( StructKeyExists(currentValues,"widgetScript") ) fileWriteData = fixSavedDataFileSectionBrackets(str=defaultValues.widgetScript); else fileWriteData = fixDefaultDataFileSectionBrackets(str=defaultValues.widgetScript); fileWriteStatus = application.ADF.utils.writeINIfile(filePath=fullScriptPath,dataString=fileWriteData,overwrite=false,charSet="utf-8"); //WriteDump(fileWriteStatus); } // Used ADF for the FileWrite so it will create the needed directories //FileWrite(fullScriptPath,defaultValues.widgetScript,"utf-8"); // Read In the CUSTOM file - NOT USED /* if ( FileExists(fullScriptPathCustom) ) defaultValues.widgetScript = FileRead(fullScriptPathCustom,"utf-8"); else defaultValues.widgetScript = FileRead(fullScriptPath,"utf-8"); */ // defaultValues.widgetScript = formatScriptText(str=defaultValues.widgetScript); defaultValues.widgetScript = FileRead(fullScriptPath,"utf-8"); defaultValues.widgetScript = fixDisplaySectionBrackets(str=defaultValues.widgetScript); } else { // This Field is new... so display the default WigetScript syntax // - Unless currentValues contains some existing widgetScript info if ( !StructKeyExists(currentValues,"widgetScript") ) defaultValues.widgetScript = defaultScriptText(); // - Format for display in the Properties script window // defaultValues.widgetScript = formatScriptText(str=defaultValues.widgetScript); } // Get the cfmlEngine type cfmlEngine = server.coldfusion.productname; if ( !FindNoCase(cfmlEngine,'ColdFusion Server') ) { // For Lucee Inject Extra linebreaks before each open bracket (since the textarea removes them) //defaultValues.widgetScript = REReplace(defaultValues.widgetScript, "(\r\n|\n\r|\n|\r)(\[)","&##013;&##010;&##013;&##010;[", "all"); /* &##013;&##010; */ //defaultValues.widgetScript = REReplace(defaultValues.widgetScript, "(\r\n|\n\r|\n|\r)(##\[)","&##013;&##010;&##013;&##010;##[", "all"); /* &##013;&##010; */ } } //WriteDump(var=attributes,expand=false); //WriteDump(var=defaultValues.widgetScriptDirPath,expand=false); //WriteDump(var=fullScriptPath,expand=false); //WriteDump(var=fullScriptPathCustom,expand=false); //WriteDump(var=defaultValues,expand=false,label="default2");
Enter the relative path to this Widget's config directory.
Example: /_cs_widgets/{widget-name}/config/
Note: The required folders will be created if they don't already exist.
 
Save the WidgetScript Directory relative path above and reopen this dialog
to edit the WidgetScript syntax for this widget!
Override File: #fullScriptNameCustom#
Enter the WidgetScript Syntax used to generate the Widget's Option Fields configuration file.
WidgetScript Syntax Help:
- Use semi-colons (;) to delimit options. eg. optionvalue1;optionvalue2;optionvalue3
- Use pipes (|) to delimit value/label pairs. eg. optionvalue1|Option Label 1;optionvalue2|Option Label 2
Save the WidgetScript Directory relative path above and reopen this dialog
to add the WidgetScript syntax for this widget!
 

ADF Custom Field v#fieldVersion#
This Field is not compatible with this Form type!
#errorMsg#
var retStr = ""; var infoObj = ''; var infoObjType = ''; var argData = StructNew(); var infoData = ''; var infoMethod = ''; var argName = ''; var infoDataKey = ''; var validFormType = false; switch (arguments.elementType) { case 'customelement': infoObjType = "CustomElement"; infoMethod = "getInfo"; argName = "elementID"; infoDataKey = "name"; validFormType = true; break; case 'metadata': infoObjType = 'MetadataForm'; infoMethod = "getForms"; argName = "ID"; infoDataKey = "formName"; validFormType = true; break; case 'simpleform': // this is here so we remember this dlgtype validFormType = false; break; default: validFormType = false; } if ( validFormType ) { argData[argName] = arguments.formid; //WriteDump(argData); infoObj = Server.CommonSpot.ObjectFactory.getObject(infoObjType); //WriteDump(infoObj); // Get the Element Info based on element type infoData = getElementInfo(objType=infoObjType,methodName=infoMethod,args=argData); //WriteDump(infoData); // USE the ACF Workaround for Dynamic method names instead ( getElementInfo() ) //infoObj.staticName = infoObj[infoMethod]; //infoData = infoObj.staticName(argumentCollection=argData); //infoData = infoObj[infoMethod](argumentCollection=argData); //WriteDump(infoData); if ( StructKeyExists(infoData,infoDataKey) ) retStr = infoData[infoDataKey]; } return retStr; var result = ''; var methodResult = ""; var infoObj = ''; var allowedElementTypes = "CustomElement,MetadataForm"; var allowedMethods = "getInfo,getForms"; var methodAllowed = false; if ( ListFind(allowedElementTypes,arguments.objType) ) { infoObj = Server.CommonSpot.ObjectFactory.getObject(arguments.objType); methodAllowed = true; } else methodAllowed = false; if ( methodAllowed AND ListFind(allowedMethods,arguments.methodName) ) methodAllowed = true; else methodAllowed = false; [Config] fields=Theme [Theme] group_all= default= // Get the cfmlEngine type var cfmlEngine = server.coldfusion.productname; if ( !FindNoCase(cfmlEngine,'ColdFusion Server') ) { arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(\[)","&##013;&##010;[", "all"); arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(##\[)","&##013;&##010;##[", "all"); } /* OLD if ( !FindNoCase(cfmlEngine,'ColdFusion Server') ) { // For Lucee Inject Extra linebreaks before each open bracket (since the textarea removes them) arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(\[)","&##013;&##010;&##013;&##010;[", "all"); arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(##\[)","&##013;&##010;&##013;&##010;##[", "all"); } else { arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(\[)","&##013;&##010;[", "all"); arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(##\[)","&##013;&##010;##[", "all"); }*/ return arguments.str; // Get the cfmlEngine type var cfmlEngine = server.coldfusion.productname; if ( !FindNoCase(cfmlEngine,'ColdFusion Server') ) { arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(\[)","#CHR(13)##CHR(10)#[", "all"); arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(##\[)","#CHR(13)##CHR(10)###[", "all"); } return arguments.str; // Get the cfmlEngine type var cfmlEngine = server.coldfusion.productname; if ( !FindNoCase(cfmlEngine,'ColdFusion Server') ) { arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(\[)","#CHR(13)##CHR(10)##CHR(13)##CHR(10)#[", "all"); arguments.str = REReplace(arguments.str, "(\r\n|\n\r|\n|\r)(##\[)","#CHR(13)##CHR(10)##CHR(13)##CHR(10)###[", "all"); } return arguments.str;