Exemplo n.º 1
0
    /// <summary>
    /// Adds new field to the FormInfo.
    /// </summary>
    /// <param name="formInfo">FormInfo to which the field will be added</param>
    /// <param name="fieldName">Name of the field</param>
    /// <param name="resourceString">Resource string used for field label</param>
    private void AddField(FormInfo formInfo, string fieldName, string resourceString)
    {
        var field = new FormFieldInfo()
        {
            Name     = fieldName,
            DataType = FieldDataType.Text,
            Caption  = String.Format("{{${0}$}}", resourceString)
        };

        field.SetControlName(FormFieldControlName.LABEL);

        formInfo.AddFormItem(field);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Creates category with variant attributes.
    /// </summary>
    /// <param name="optionsList">Product options</param>
    private void SetVariantAttributes(List <SKUInfo> optionsList)
    {
        // Get attributes category index - just before representing category
        var attrPos = editForm.FormInformation.ItemsList.FindIndex(f =>
                                                                   (f is FormCategoryInfo) && ((FormCategoryInfo)f).CategoryName.Equals("com.sku.representingcategory", StringComparison.OrdinalIgnoreCase));

        // Create attributes category
        var attCategory = new FormCategoryInfo
        {
            CategoryName = "Attributes",
            IsDummy      = true,
        };

        attCategory.SetPropertyValue(FormCategoryPropertyEnum.Caption, HTMLHelper.HTMLEncode(GetString("com.variant.attributes")));
        editForm.FormInformation.AddFormItem(attCategory, attrPos++);

        // Get variant categories
        var variantCategories = VariantHelper.GetProductVariantsCategories(ProductID);

        foreach (var category in variantCategories)
        {
            var option = optionsList.FirstOrDefault(o => o.SKUOptionCategoryID == category.CategoryID);
            if (option != null)
            {
                var ffOption = new FormFieldInfo
                {
                    Name         = category.CategoryName,
                    AllowEmpty   = true,
                    Size         = 400,
                    DataType     = FieldDataType.Text,
                    IsDummyField = true,
                };

                ffOption.SetControlName(FormFieldControlName.LABEL);
                ffOption.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, HTMLHelper.HTMLEncode(ResHelper.LocalizeString(option.SKUName)));

                // Show category live site display name instead of category display name in case it is available
                ffOption.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, HTMLHelper.HTMLEncode(ResHelper.LocalizeString(category.CategoryTitle)));

                //Insert field to the form on specified position
                editForm.FormInformation.AddFormItem(ffOption, attrPos++);
            }
        }
    }
    /// <summary>
    /// Creates new FormFieldInfo from given SettingKeyInfo.
    /// </summary>
    /// <param name="setting">Setting key info.</param>
    private FormFieldInfo CreateFormFieldInfo(SettingsKeyInfo setting)
    {
        var ffi = new FormFieldInfo
        {
            Name     = setting.KeyName,
            DataType = setting.KeyType
        };

        ffi.SetControlName(FormHelper.GetFormFieldDefaultControlName(setting.KeyType));
        ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, setting.KeyDisplayName);
        ffi.SetPropertyValue(FormFieldPropertyEnum.ExplanationText, setting.KeyExplanationText);
        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, setting.KeyDefaultValue);
        if (!string.IsNullOrEmpty(setting.KeyDescription))
        {
            ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCssClass, "form-group settings-group-inline");
            ffi.SetPropertyValue(FormFieldPropertyEnum.ContentAfter, UIHelper.GetIcon("icon-question-circle", GetString(setting.KeyDescription)).GetRenderedHTML());
        }

        return(ffi);
    }
Exemplo n.º 4
0
        private static FormFieldInfo CreateFormField(string formFieldName)
        {
            var field = new FormFieldInfo
            {
                Name       = formFieldName,
                DataType   = FieldDataType.Guid,
                System     = false,
                Visible    = true,
                AllowEmpty = true,
                Guid       = Guid.NewGuid()
            };

            field.SetControlName(FormHelper.GetFormFieldDefaultControlName(field.DataType));
            field.Settings["componentidentifier"] = ConsentAgreementComponent.IDENTIFIER;
            field.Settings[nameof(ConsentAgreementProperties.ConsentCodeName)] = CONSENT_NAME;

            field.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, String.Empty);
            field.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, String.Empty);
            field.SetPropertyValue(FormFieldPropertyEnum.FieldDescription, String.Empty);

            return(field);
        }
Exemplo n.º 5
0
    protected void EditForm_OnBeforeSave(object sender, EventArgs e)
    {
        MacroRuleInfo info = Control.EditedObject as MacroRuleInfo;

        if (info != null)
        {
            // Generate automatic fields when present in UserText
            FormEngineUserControl control = Control.FieldControls["MacroRuleText"];
            if (control != null)
            {
                string userText = ValidationHelper.GetString(control.Value, String.Empty);
                if (!string.IsNullOrEmpty(userText))
                {
                    Regex           regex = RegexHelper.GetRegex("\\{[-_a-zA-Z0-9]*\\}");
                    MatchCollection match = regex.Matches(userText);
                    if (match.Count > 0)
                    {
                        FormInfo fi = new FormInfo(info.MacroRuleParameters);
                        foreach (Match m in match)
                        {
                            foreach (Capture c in m.Captures)
                            {
                                string        name = c.Value.Substring(1, c.Value.Length - 2).ToLowerCSafe();
                                FormFieldInfo ffi  = fi.GetFormField(name);
                                if (ffi == null)
                                {
                                    ffi          = new FormFieldInfo();
                                    ffi.Name     = name;
                                    ffi.DataType = FieldDataType.Text;
                                    ffi.Size     = 100;
                                    ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "select operation");
                                    ffi.AllowEmpty = true;
                                    switch (name)
                                    {
                                    case "_is":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";is");
                                        ffi.SetControlName("MacroNegationOperator");
                                        ffi.Settings["EditText"] = "false";
                                        ffi.Settings["Options"]  = ";is\r\n!;is not";
                                        break;

                                    case "_was":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";was");
                                        ffi.SetControlName("MacroNegationOperator");
                                        ffi.Settings["EditText"] = "false";
                                        ffi.Settings["Options"]  = ";was\r\n!;was not";
                                        break;

                                    case "_will":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";will");
                                        ffi.SetControlName("MacroNegationOperator");
                                        ffi.Settings["EditText"] = "false";
                                        ffi.Settings["Options"]  = ";will\r\n!;will not";
                                        break;

                                    case "_has":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";has");
                                        ffi.SetControlName("MacroNegationOperator");
                                        ffi.Settings["EditText"] = "false";
                                        ffi.Settings["Options"]  = ";has\r\n!;does not have";
                                        break;

                                    case "_perfectum":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, ";has");
                                        ffi.SetControlName("MacroNegationOperator");
                                        ffi.Settings["EditText"] = "false";
                                        ffi.Settings["Options"]  = ";has\r\n!;has not";
                                        break;

                                    case "_any":
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.DefaultValue, "false;any");
                                        ffi.SetControlName("macro_any-all_bool_selector");
                                        ffi.Settings["EditText"] = "false";
                                        ffi.Settings["Options"]  = "false;any\r\ntrue;all";
                                        break;

                                    default:
                                        ffi.Size = 1000;
                                        ffi.SetControlName(FormFieldControlName.TEXTBOX);
                                        ffi.SetPropertyValue(FormFieldPropertyEnum.FieldCaption, "enter text");
                                        break;
                                    }

                                    fi.AddFormItem(ffi);
                                }
                            }
                        }
                        info.MacroRuleParameters = fi.GetXmlDefinition();
                    }
                }
            }
        }

        Control.EditedObject.SetValue("MacroRuleIsCustom", !SystemContext.DevelopmentMode);
    }