コード例 #1
0
ファイル: FieldModel.cs プロジェクト: lukeskinner/OctoForms
 public FieldModel(FormField field, Resource resource, VariableSettings variableSettings, FormResources formResources)
 {
     Settings = variableSettings;
     FormResources = formResources;
     Resource = resource;
     VariableSetId = field.VariableSetId;
     VariableName = field.VariableName;
     LabelContent = field.DisplayName;
     Variables = new ObservableCollection<FieldVariable>();
 }
コード例 #2
0
ファイル: FormHelpers.cs プロジェクト: lukeskinner/OctoForms
        public static void UpdateFrom(this VariableSettings variableSettings, FormField formField, Dictionary<string, Resource> variableSets)
        {
            variableSettings.DisplayName = formField.DisplayName;
            variableSettings.IsReadonly = formField.IsReadonly;
            variableSettings.VariableName = formField.VariableName;
            variableSettings.VariableSetId = formField.VariableSetId;

            foreach (KeyValuePair<string, Resource> variableSetKvp in variableSets)
            {
                string name = (variableSetKvp.Value as ProjectResource)?.Name ??
                              (variableSetKvp.Value as LibraryVariableSetResource)?.Name;

                variableSettings.VariableSets.Add(new DropdownItemModel
                {
                    DisplayName = name,
                    Value = variableSetKvp.Key
                });
            }

            Type formFieldType = ObjectContext.GetObjectType(formField.GetType());

            if (formFieldType == typeof(FormField_YesNo))
            {
                FormField_YesNo yesNoField = (FormField_YesNo)formField;
                BooleanSettings booleanSettings = (BooleanSettings)variableSettings;
                booleanSettings.UseTrueOrFalse = yesNoField.UseTrueOrFalse;
                booleanSettings.DefaultValue = yesNoField.DefaultValue;
            }
            else if (formFieldType == typeof(FormField_Dropdown))
            {
                FormField_Dropdown dropdownField = (FormField_Dropdown)formField;
                DropdownSettings dropdownSettings = (DropdownSettings)variableSettings;
                dropdownSettings.DefaultValue = dropdownField.DefaultValue;

                foreach (var formFieldDropdownItem in dropdownField.FormField_DropdownItems)
                {
                    DropdownItemModel fieldItem = dropdownSettings.Items
                        .FirstOrDefault(di => di.Value == formFieldDropdownItem.Value);

                    if (fieldItem == null)
                    {
                        fieldItem = new DropdownItemModel();
                        dropdownSettings.Items.Add(fieldItem);
                    }

                    if (formFieldDropdownItem.Value == dropdownSettings.DefaultValue)
                    {
                        fieldItem.IsDefault = true;
                    }

                    fieldItem.DisplayName = formFieldDropdownItem.DisplayName;
                    fieldItem.Value = formFieldDropdownItem.Value;
                }
            }
            else if (formFieldType == typeof(FormField_Textbox))
            {
                FormField_Textbox textBoxField = (FormField_Textbox)formField;
                TextboxSettings textboxSettings = (TextboxSettings)variableSettings;

                textboxSettings.DefaultValue = textBoxField.DefaultValue;
            }
            else if (formFieldType == typeof(FormField_Numeric))
            {
                FormField_Numeric numericField = (FormField_Numeric)formField;
                NumericSettings numericSettings = (NumericSettings)variableSettings;

                numericSettings.AllowDecimal = numericField.AllowDecimal;
                numericSettings.AllowNegativeValue = numericField.AllowNegativeValue;
                numericSettings.DefaultValue = numericField.DefaultValue;
                numericSettings.MaxValue = numericField.MaxValue;
                numericSettings.MinValue = numericField.MinValue;
            }
        }