Example #1
0
        /// <summary>
        /// Handles the dependent fields.
        /// </summary>
        public void HandleDependentFields()
        {
            this.orderedEditFieldContexts = null;
            var parentFieldContextArray = new List <object>();

            foreach (var fieldContext in this.EditFields.Values)
            {
                var parentField = fieldContext.ParentField;
                if (parentField != null)
                {
                    UPEditFieldContext parentFieldContext = this.EditFields.ValueOrDefault(parentField.FieldIdentification);
                    if (parentFieldContext != null)
                    {
                        parentFieldContext.AddDependentFieldContext(fieldContext);
                        if (!parentFieldContextArray.Contains(parentFieldContext))
                        {
                            parentFieldContextArray.Add(parentFieldContext);
                        }
                    }
                }
            }

            foreach (UPEditFieldContext parentFieldContext in parentFieldContextArray)
            {
                parentFieldContext.NotifyDependentFields();
            }
        }
        /// <summary>
        /// Adds the dependent field context.
        /// </summary>
        /// <param name="editFieldContext">
        /// The edit field context.
        /// </param>
        public virtual void AddDependentFieldContext(UPEditFieldContext editFieldContext)
        {
            if (this.dependentFields == null)
            {
                this.dependentFields = new List <UPEditFieldContext>();
            }
            else if (this.dependentFields.Contains(editFieldContext))
            {
                return;
            }

            this.dependentFields.Add(editFieldContext);
        }
 /// <summary>
 /// Sets the parent context.
 /// </summary>
 /// <param name="_parentContext">
 /// The _parent context.
 /// </param>
 public virtual void SetParentContext(UPEditFieldContext _parentContext)
 {
     this.parentContext = _parentContext;
 }
 /// <summary>
 /// Parents the context changed value.
 /// </summary>
 /// <param name="context">
 /// The context.
 /// </param>
 /// <param name="value">
 /// The value.
 /// </param>
 /// <returns>
 /// The <see cref="List"/>.
 /// </returns>
 public virtual List <IIdentifier> ParentContextChangedValue(UPEditFieldContext context, string value) => null;
        /// <summary>
        /// Parents the context changed value.
        /// </summary>
        /// <param name="parentContext">
        /// The parent context.
        /// </param>
        /// <param name="_value">
        /// The _value.
        /// </param>
        /// <returns>
        /// The <see cref="List"/>.
        /// </returns>
        public override List <IIdentifier> ParentContextChangedValue(UPEditFieldContext parentContext, string _value)
        {
            var intValue = JObjectExtensions.ToInt(_value);
            var values   = this.Catalog.SortedValuesForParentValueIncludeHidden(intValue, false);
            var field    = (UPMCatalogEditField)this.EditField;

            field.ResetPossibleValues();
            if (this.lockedCurrentValues?.Count > 0 && intValue == this.lockedParentValue)
            {
                var extendedArray = new List <UPCatalogValue>(values);
                extendedArray.AddRange(this.lockedCurrentValues);
                values = extendedArray;
            }

            var sortOrder         = new List <string>();
            var currentValue      = this.Value;
            var currentValueFound = false;

            // Leer Eintrag
            if (!this.MultiSelect)
            {
                var possibleValue = new UPMCatalogPossibleValue {
                    Key = "0"
                };
                var valueField = new UPMStringField(StringIdentifier.IdentifierWithStringId("x"))
                {
                    StringValue = string.Empty
                };

                possibleValue.TitleLabelField = valueField;
                field.AddPossibleValue(possibleValue);
                sortOrder.Add("0");
            }

            foreach (var value in values)
            {
                var possibleValue = new UPMCatalogPossibleValue
                {
                    Key             = value.CodeKey,
                    TitleLabelField = new UPMStringField(StringIdentifier.IdentifierWithStringId("x"))
                    {
                        StringValue = value.Text
                    }
                };

                field.AddPossibleValue(possibleValue);
                sortOrder.Add(value.CodeKey);
                if (value.CodeKey == currentValue)
                {
                    currentValueFound = true;
                }
            }

            field.ExplicitKeyOrder = sortOrder;
            if (!currentValueFound)
            {
                this.editField.FieldValue = !this.MultiSelect ? "0" : null;
            }

            return(this.editField.Identifier != null ? new List <IIdentifier> {
                this.editField.Identifier
            } : null);
        }
        /// <summary>
        /// Creates the edit field.
        /// </summary>
        /// <returns>
        /// The <see cref="UPMEditField"/>.
        /// </returns>
        public override UPMEditField CreateEditField()
        {
            var field = new UPMCatalogEditField(this.FieldIdentifier, this.MultiSelect)
            {
                NullValueKey = "0"
            };

            if (this.MultiSelect)
            {
                field.MultiSelectMaxCount = this.ChildFields.Count + 1;
            }

            var possibleValues   = this.Catalog?.TextValuesForFieldValues(false);
            var explicitKeyOrder = this.Catalog?.ExplicitKeyOrderEmptyValueIncludeHidden(!this.MultiSelect, false);

            if (possibleValues != null)
            {
                foreach (var p in possibleValues)
                {
                    var possibleValue = new UPMCatalogPossibleValue
                    {
                        Key             = p.Key,
                        TitleLabelField = new UPMStringField(StringIdentifier.IdentifierWithStringId("X"))
                        {
                            StringValue = p.Value
                        }
                    };

                    if (!this.MultiSelect || p.Key != field.NullValueKey)
                    {
                        field.AddPossibleValue(possibleValue);
                    }
                }
            }

            UPEditFieldContext currentFieldContext = this;
            var childEditIndex = 0;
            List <UPCatalogValue> _lockedCurrentValues = null;

            while (currentFieldContext != null)
            {
                if (!string.IsNullOrEmpty(currentFieldContext.Value) &&
                    possibleValues.ValueOrDefault(currentFieldContext.Value) == null)
                {
                    var textValue = this.Catalog?.TextValueForKey(currentFieldContext.Value);
                    if (string.IsNullOrEmpty(textValue))
                    {
                        // Rashan: removed the prefix '?'
                        textValue = $"{currentFieldContext.Value}";
                    }

                    var possibleValue = new UPMCatalogPossibleValue
                    {
                        Key             = currentFieldContext.Value,
                        TitleLabelField = new UPMStringField(StringIdentifier.IdentifierWithStringId("X"))
                        {
                            StringValue = textValue
                        }
                    };

                    field.AddPossibleValue(possibleValue);
                    if (explicitKeyOrder != null)
                    {
                        var newExplicitOrder = new List <string>(explicitKeyOrder)
                        {
                            currentFieldContext.Value
                        };
                        explicitKeyOrder = newExplicitOrder;
                    }

                    var catVal = this.Catalog?.ValueForCode(JObjectExtensions.ToInt(currentFieldContext.Value));
                    if (catVal != null)
                    {
                        if (_lockedCurrentValues == null)
                        {
                            _lockedCurrentValues = new List <UPCatalogValue> {
                                catVal
                            };
                            this.lockedParentValue = catVal.Code >> 16;
                        }
                        else
                        {
                            _lockedCurrentValues.Add(catVal);
                        }
                    }
                }

                currentFieldContext = this.ChildFields != null && this.ChildFields.Count > childEditIndex
                                          ? this.ChildFields[childEditIndex++]
                                          : null;
            }

            this.lockedCurrentValues = _lockedCurrentValues;
            field.ExplicitKeyOrder   = explicitKeyOrder;
            field.ContinuousUpdate   = true;
            this.ApplyAttributesOnEditFieldConfig(field, this.FieldConfig);
            return(field);
        }