protected override void InitializeControls(GenericContainer container)
{
IFormFieldControl thisControl = base.ParentDesigner.PropertyEditor.Control as IFormFieldControl;
FormDraftControl thisControlData = base.ParentDesigner.PropertyEditor.ControlData as FormDraftControl;
FormDescription form = FManager.GetFormByName(thisControlData.Form.Name);
IControlsContainer cc = GetControlsContainer(form.Id);
List<ControlData> formControls = (List<ControlData>)typeof(PageHelper)
.GetMethod("SortControls", BindingFlags.Static | BindingFlags.NonPublic)
.Invoke(null, new object[] { new[] { cc }, 1 });
formControls.RemoveAll(fc => fc.ObjectType == "Telerik.Sitefinity.Modules.Forms.Web.UI.Fields.FormSubmitButton, Telerik.Sitefinity" || fc.ObjectType == "timw255.Sitefinity.SuperForms.Widgets.Form.LogicalFormInstructionalText, timw255.Sitefinity.SuperForms" || fc.IsLayoutControl == true);
if (formControls.Count > 0)
{
List<CriteriaOption> criteriaOptions = new List<CriteriaOption>();
CultureInfo uiCulture = CultureInfo.GetCultureInfo(this.GetUICulture());
foreach (var formControl in formControls)
{
FieldControl fieldControl = FManager.LoadControl(formControl, uiCulture) as FieldControl;
CriteriaOption co = new CriteriaOption();
if (fieldControl is FormChoiceField)
{
co.FieldType = "ChoiceField";
co.FieldName = Helpers.GetFieldName(fieldControl);
co.FieldId = fieldControl.ID;
co.Options = ((FormChoiceField)fieldControl).Choices
.Select(c => new SimpleChoiceItem() { Text = c.Text, Value = c.Value }).ToList();
co.Conditions = new List<SimpleChoiceItem>()
{
new SimpleChoiceItem() { Text = "=", Value = "==" },
new SimpleChoiceItem() { Text = "!=", Value = "!=" }
};
}
if (fieldControl is TextField)
{
co.FieldType = "TextField";
co.FieldName = Helpers.GetFieldName(fieldControl);
co.FieldId = fieldControl.ID;
co.Conditions = new List<SimpleChoiceItem>()
{
new SimpleChoiceItem() { Text = "=", Value = "==" },
new SimpleChoiceItem() { Text = "!=", Value = "!=" },
new SimpleChoiceItem() { Text = "<", Value = "lt" },
new SimpleChoiceItem() { Text = ">", Value = "gt" }
};
}
if (!String.IsNullOrWhiteSpace(co.FieldType) && !String.IsNullOrWhiteSpace(co.FieldName) && co.Conditions.Count > 0)
{
criteriaOptions.Add(co);
}
}
StringBuilder script = new StringBuilder();
script.Append(@"<script>");
script.AppendFormat(@"var currentCultureC = ""{0}"";", this.GetUICulture());
string optionFilter = "";
if (thisControl != null)
{
optionFilter = ((FieldControl)thisControl).ID;//Helpers.GetFieldName((FieldControl)thisControl);
}
script.AppendFormat(@"var optionFilter = ""{0}"";", optionFilter);
script.AppendFormat(@"var criteriaOptions = {0};", Helpers.SerializeJSON<List<CriteriaOption>>(criteriaOptions));
IConditionalFormControl cfc = ((IConditionalFormControl)base.ParentDesigner.PropertyEditor.Control);
string criteriaSet = "[]";
if (cfc != null)
{
string criteriaSetPropertyValue = cfc.CriteriaSet;
if (!String.IsNullOrWhiteSpace(criteriaSetPropertyValue))
{
criteriaSet = criteriaSetPropertyValue;
}
}
script.AppendFormat("var criteria = {0};", criteriaSet);
script.Append(@"</script>");
Script.Text = script.ToString();
}
}