コード例 #1
0
 /// <summary>
 /// Recursive method to iterate in the controls obtained from the GetControlsIterator
 /// </summary>
 /// <param name="parent">The actual control in the search</param>
 /// <param name="control">The control to be searched</param>
 /// <param name="VisualParentDictionary">Stores the controls and their parent found previously</param>
 /// <returns></returns>
 public static IStateObject FindVisualParent(IControlsContainer parent, ControlViewModel control, Dictionary<string, IStateObject> VisualParentDictionary)
 {
     if (parent == null)
     {
         return null; // GetControlsIterator can return null controls
     }
     var Controls = parent.GetControlsIterator();
     IStateObject VisualParent = null;
     for (var i = 0; i < Controls.Count(); i++)
     {
         var ctl = Controls.ElementAt(i);
         if (ctl == control)
         {
             if (!VisualParentDictionary.ContainsKey(control.UniqueID)) VisualParentDictionary.Add(control.UniqueID, parent);
             return parent as IStateObject;
         }
         else
         {
             VisualParent = FindVisualParent(ctl, control, VisualParentDictionary);
             if (VisualParent != null)
             {
                 return VisualParent;
             }
         }
     }
     return VisualParent;
 }
コード例 #2
0
        private List <ConditionalRule> BuildConditionalRuleSet()
        {
            List <ConditionalRule> conditionalRules = new List <ConditionalRule>();

            IControlsContainer cc = FManager.GetForm(this.FormId);

            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.IsLayoutControl == true);

            CultureInfo uiCulture = null;

            if (Config.Get <ResourcesConfig>().Multilingual)
            {
                uiCulture = System.Globalization.CultureInfo.CurrentUICulture;
            }

            foreach (var fieldControl in formControls)
            {
                var fc1 = FManager.LoadControl(fieldControl, uiCulture);

                IConditionalFormControl lfc = fc1 as IConditionalFormControl;

                if (lfc != null && lfc.UsesConditionalLogic == true)
                {
                    ConditionalRule conditionalRule = new ConditionalRule();

                    conditionalRule.Target = lfc.TargetId;
                    conditionalRule.Action = lfc.Action == 0 ? "Show" : "Hide";
                    conditionalRule.Bool   = lfc.Quantity == 0 ? "OR" : "AND";

                    List <CriteriaItem> checks = Helpers.DeserializeJSON <List <CriteriaItem> >(lfc.CriteriaSet);

                    conditionalRule.Fields = checks.Select(ci => ((IConditionalFormControl)this.FieldControls.Where(fc => ((SimpleScriptView)fc).ID == ci.FieldId).Single()).TargetId).Distinct().ToArray();

                    conditionalRule.Checks = checks.Select(ci => new CriteriaItem()
                    {
                        Field     = ((IConditionalFormControl)this.FieldControls.Where(fc => ((SimpleScriptView)fc).ID == ci.FieldId).Single()).TargetId,
                        Condition = ci.Condition,
                        Option    = ci.Option
                    }).ToList();

                    conditionalRules.Add(conditionalRule);
                }
            }
            return(conditionalRules);
        }
コード例 #3
0
        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.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.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.Conditions = new List <SimpleChoiceItem>()
                        {
                            new SimpleChoiceItem()
                            {
                                Text = "=", Value = "=="
                            },
                            new SimpleChoiceItem()
                            {
                                Text = "!=", Value = "!="
                            },
                            new SimpleChoiceItem()
                            {
                                Text = "<", Value = "lt"
                            },
                            new SimpleChoiceItem()
                            {
                                Text = ">", Value = "gt"
                            }
                        };
                    }

                    criteriaOptions.Add(co);
                }

                StringBuilder script = new StringBuilder();

                script.Append(@"<script>");
                script.AppendFormat(@"var currentCultureC = ""{0}"";", this.GetUICulture());
                script.AppendFormat(@"var optionFilter = ""{0}"";", Helpers.GetFieldName((FieldControl)thisControl));
                script.AppendFormat(@"var criteriaOptions = {0};", Helpers.SerializeJSON <List <CriteriaOption> >(criteriaOptions));

                string criteriaSetPropertyValue = ((IConditionalFormControl)thisControl).CriteriaSet;

                string criteriaSet = "[]";

                if (!String.IsNullOrWhiteSpace(criteriaSetPropertyValue))
                {
                    criteriaSet = criteriaSetPropertyValue;
                }

                script.AppendFormat("var criteria = {0};", criteriaSet);

                script.Append(@"</script>");

                Script.Text = script.ToString();
            }
        }
コード例 #4
0
 public static System.Collections.Generic.IEnumerable<ControlViewModel> GetControlsSafe(this IControlsContainer control)
 {
     if (control.Controls != null)
         return control.Controls;
     else
         return Enumerable.Empty<ControlViewModel>();
 }
コード例 #5
0
        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.IsLayoutControl == true);

            ControlData progressiveKeyFieldControlData = formControls.Where(c => ((FormDraftControl)c).Properties.Any(p => p.Name == "IsProgressiveKeyField" && p.Value == "True")).FirstOrDefault();

            if (progressiveKeyFieldControlData != null)
            {
                FieldControl progressiveKeyFieldControl = FManager.LoadControl(progressiveKeyFieldControlData, CultureInfo.CurrentUICulture) as FieldControl;

                _progressiveKeyFieldName = Helpers.GetFieldName(progressiveKeyFieldControl);

                if (!String.IsNullOrEmpty(_progressiveKeyFieldName) && _progressiveKeyFieldName != Helpers.GetFieldName(thisControl as FieldControl))
                {
                    _disableKeyFieldSelector = true;
                }
            }

            if (!(thisControl is FormTextBox))
            {
                _disableKeyFieldSelector = true;
                _wrongTypeForKeyField    = true;
            }

            if (formControls.Count > 0)
            {
                List <CriteriaOption> progressiveCriteriaOptions = 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();

                    co.FieldName = Helpers.GetFieldName(fieldControl);

                    progressiveCriteriaOptions.Add(co);
                }

                StringBuilder script = new StringBuilder();

                script.Append(@"<script>");
                script.AppendFormat(@"var currentProgressiveCulture = ""{0}"";", this.GetUICulture());
                script.AppendFormat(@"var progressiveOptionFilter = ""{0}"";", Helpers.GetFieldName((FieldControl)thisControl));
                script.AppendFormat(@"var progressiveCriteriaOptions = {0};", Helpers.SerializeJSON <List <CriteriaOption> >(progressiveCriteriaOptions));

                string progressiveCriteriaSetPropertyValue = ((IProgressiveFormControl)thisControl).ProgressiveCriteriaSet;
                string criteriaSet = "[]";

                if (!String.IsNullOrWhiteSpace(progressiveCriteriaSetPropertyValue))
                {
                    criteriaSet = progressiveCriteriaSetPropertyValue;
                }

                script.AppendFormat("var progressiveCriteria = {0};", criteriaSet);
                script.Append(@"</script>");

                Script.Text = script.ToString();
            }
        }