/// <summary>
 /// Instantiates the page.
 /// </summary>
 /// <returns>
 /// The <see cref="Page"/>.
 /// </returns>
 public override Page InstantiatePage()
 {
     return(this.Page != null
         ? new MDetailPage(this.Page.Identifier)
         : new MDetailPage(
                FieldIdentifier.IdentifierWithRecordIdentificationFieldId(
                    this.infoAreaId.InfoAreaIdRecordId(this.recordId),
                    "Page0")));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Creates and returns an instance of <see cref="UPMGroup"/> from given <see cref="UPCRMResultRow"/>.
        /// </summary>
        /// <param name="resultRow">
        /// The result row.
        /// </param>
        /// <returns>
        /// The <see cref="UPMGroup"/>.
        /// </returns>
        private UPMGroup GroupFromRow(UPCRMResultRow resultRow)
        {
            var location             = UPGeoLocation.Create(resultRow, this.TabConfig);
            var recordIdentification = resultRow.RootRecordIdentification;

            if (location != null)
            {
                var mapGroup = new UPMMapGroup(this.TabIdentifierForRecordIdentification(recordIdentification));
                mapGroup.LabelText = this.TabLabel;
                var locationField = new UPMLocationField(FieldIdentifier.IdentifierWithRecordIdentificationFieldId(recordIdentification, "locationField"), null);

                if (location.ValidGPS)
                {
                    locationField.Longitude = location.GpsXString;
                    locationField.Latitude  = location.GpsYString;
                }

                if (!string.IsNullOrEmpty(location.AddressTitle))
                {
                    locationField.AddressTitle = location.AddressTitle;
                }

                if (!string.IsNullOrEmpty(location.Address))
                {
                    locationField.Address = location.Address;
                }

                mapGroup.AddChild(locationField);
                this.ControllerState = GroupModelControllerState.Finished;
                this.Group           = mapGroup;
                return(mapGroup);
            }

            this.ControllerState = GroupModelControllerState.Empty;
            return(null);
        }
        private UPMGroup CreateGroup(string _recordIdentification)
        {
            UPMCharacteristicsGroup charakteristicsGroup = new UPMCharacteristicsGroup(StringIdentifier.IdentifierWithStringId(this.Characteristics.RecordIdentification));

            charakteristicsGroup.LabelText = this.TabLabel;
            int groupId = 0;
            int itemId  = 0;

            if (this.Characteristics.Groups != null)
            {
                foreach (UPCharacteristicsGroup crmCharacteristicsGroup in this.Characteristics.Groups)
                {
                    FieldIdentifier             fieldIdentifier          = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(_recordIdentification, this.Characteristics.DestinationGroupField.Identification);
                    UPMCharacteristicsItemGroup characteristicsItemGroup = new UPMCharacteristicsItemGroup(StringIdentifier.IdentifierWithStringId($"Group{groupId}_{itemId}"));
                    characteristicsItemGroup.GroupNameField = new UPMStringField(fieldIdentifier);
                    SetAttributesOnField(this.Characteristics.DestinationGroupField.Attributes, characteristicsItemGroup.GroupNameField);
                    characteristicsItemGroup.GroupNameField.StringValue = crmCharacteristicsGroup.Label;
                    charakteristicsGroup.AddChild(characteristicsItemGroup);
                    foreach (UPCharacteristicsItem crmCharacteristicsItem in crmCharacteristicsGroup.Items)
                    {
                        fieldIdentifier = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(_recordIdentification, this.Characteristics.DestinationItemField.Identification);
                        UPMCharacteristicsItem characteristicsItem = new UPMCharacteristicsItem(StringIdentifier.IdentifierWithStringId($"Item{groupId}_{itemId}"));
                        characteristicsItem.ItemNameField = new UPMStringField(fieldIdentifier);
                        SetAttributesOnField(this.Characteristics.DestinationItemField.Attributes, characteristicsItem.ItemNameField);
                        characteristicsItem.ItemNameField.StringValue = crmCharacteristicsItem.Label;
                        characteristicsItemGroup.AddChild(characteristicsItem);
                        List <UPMField> additionalFields = new List <UPMField>();
                        if (crmCharacteristicsItem.ShowAdditionalFields)
                        {
                            int i = 0;
                            foreach (UPConfigFieldControlField crmAdditionalField in crmCharacteristicsItem.AdditionalFields)
                            {
                                fieldIdentifier = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(_recordIdentification, crmAdditionalField.Identification);
                                UPMStringField additionalField = new UPMStringField(fieldIdentifier);
                                if (!string.IsNullOrEmpty(crmCharacteristicsItem.Values[i]))
                                {
                                    SetAttributesOnField(crmAdditionalField.Attributes, additionalField);
                                    FieldAttributes fieldAttributes = crmAdditionalField.Attributes;
                                    if (!fieldAttributes.NoLabel)
                                    {
                                        additionalField.LabelText = crmAdditionalField.Field.Label;
                                    }

                                    additionalField.StringValue = crmCharacteristicsItem.Values[i];
                                    if (!string.IsNullOrEmpty(additionalField.StringValue))
                                    {
                                        additionalFields.Add(additionalField);
                                    }
                                }

                                i++;
                            }
                        }

                        characteristicsItem.EditFields = additionalFields;
                        itemId++;
                    }

                    groupId++;
                }
            }

            return(charakteristicsGroup);
        }
 /// <summary>
 /// Tabs the identifier for record identification.
 /// </summary>
 /// <param name="recordIdentification">The record identification.</param>
 /// <returns></returns>
 public IIdentifier TabIdentifierForRecordIdentification(string recordIdentification)
 {
     return(FieldIdentifier.IdentifierWithRecordIdentificationFieldId(recordIdentification, $"Tabheader {this.RootTabIndex}"));
 }
Exemplo n.º 5
0
        /// <summary>
        /// Edits the contexts for result row.
        /// </summary>
        /// <param name="resultRow">The result row.</param>
        /// <param name="tabConfig">The tab configuration.</param>
        /// <param name="editFieldDictionary">The edit field dictionary.</param>
        /// <param name="initialValues">The initial values.</param>
        /// <param name="fieldPostfix">The field postfix.</param>
        /// <param name="initialRecords">The initial records.</param>
        /// <returns></returns>
        public List <object> EditContextsForResultRow(UPCRMResultRow resultRow, FieldControlTab tabConfig,
                                                      Dictionary <string, UPEditFieldContext> editFieldDictionary, Dictionary <string, object> initialValues, string fieldPostfix, List <UPCRMRecord> initialRecords)
        {
            var recordIdentification = resultRow?.RecordIdentificationAtIndex(0);

            var         fieldArray        = new List <object>();
            UPCRMRecord offlineRootRecord = null;

            if (initialRecords?.Count > 0)
            {
                offlineRootRecord = initialRecords.FirstOrDefault();
            }

            var identifierPrefix = recordIdentification;

            if (string.IsNullOrEmpty(identifierPrefix))
            {
                identifierPrefix = $"{this.TabConfig.FieldControl.UnitName}_{this.TabIndex}";
            }

            var fieldCount = tabConfig?.NumberOfFields ?? 0;

            for (var j = 0; j < fieldCount; j++)
            {
                var fieldConfig = tabConfig?.FieldAtIndex(j);
                if (fieldConfig == null)
                {
                    continue;
                }

                var        fieldAttributes   = fieldConfig.Attributes;
                var        currentInfoAreaId = fieldConfig.InfoAreaId;
                var        currentLinkId     = fieldConfig.LinkId;
                var        fieldIdentifier   = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(identifierPrefix, fieldConfig.Identification);
                UPSelector selector          = null;
                var        selectorDef       = fieldConfig.Attributes?.Selector;
                if (selectorDef != null)
                {
                    var filterParameters = this.EditPageContext?.ViewReference?.ContextValueForKey("copyFields")?.JsonDictionaryFromString();
                    if (resultRow?.Result != null && resultRow.IsNewRow)
                    {
                        selector = UPSelector.SelectorFor(
                            resultRow.RootRecordIdentification?.InfoAreaId(),
                            resultRow.Result.ParentRecordIdentification,
                            resultRow.Result.LinkId,
                            selectorDef,
                            filterParameters,
                            fieldConfig);
                    }
                    else
                    {
                        selector = UPSelector.SelectorFor(resultRow?.RootRecordIdentification, selectorDef, filterParameters, fieldConfig);
                    }

                    selector.Build();
                    if (selector.OptionCount == 0 && selector.IsStaticSelector)
                    {
                        selector = null;
                    }
                }

                var isEditField = this.enableLinkedEditFields ||
                                  selector != null ||
                                  (tabConfig.FieldControl.InfoAreaId == currentInfoAreaId && currentLinkId <= 0);

                var isHidden       = fieldAttributes.Hide;
                var isReadOnly     = isEditField && fieldAttributes.ReadOnly;
                var rawFieldValue0 = resultRow?.RawValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                var fieldInfo      = fieldConfig.Field.FieldInfo;
                if (isEditField && !isReadOnly && !(selector is UPRecordSelector && ((UPRecordSelector)selector).IgnoreFieldInfo))
                {
                    if (fieldInfo.IsReadOnly)
                    {
                        isReadOnly = true;
                    }
                    else if (resultRow?.IsNewRow == true || string.IsNullOrEmpty(rawFieldValue0))
                    {
                        if (fieldInfo.LockedOnNew)
                        {
                            isReadOnly = true;
                        }
                    }
                    else if (fieldInfo.LockedOnUpdate && !fieldInfo.IsEmptyValue(rawFieldValue0))
                    {
                        isReadOnly = true;
                    }
                }

                string             offlineValue = null;
                bool               offlineChanged;
                string             rawFieldValue;
                UPEditFieldContext editFieldContext;
                if (isEditField)
                {
                    List <UPEditFieldContext> childFields = null;
                    if (fieldAttributes.FieldCount > 1 && selector == null)
                    {
                        childFields = new List <UPEditFieldContext>();
                        for (var k = 1; k < fieldAttributes.FieldCount; k++)
                        {
                            var childFieldConfig = tabConfig.FieldAtIndex(++j);
                            if (childFieldConfig != null)
                            {
                                rawFieldValue = resultRow.RawValueAtIndex(childFieldConfig.TabIndependentFieldIndex);
                                if (initialValues != null)
                                {
                                    rawFieldValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, childFieldConfig, initialValues);
                                }

                                offlineChanged = false;

                                if (offlineRootRecord != null)
                                {
                                    offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(childFieldConfig.FieldId);
                                    if (offlineValue != null && !offlineValue.Equals(rawFieldValue))
                                    {
                                        offlineChanged = true;
                                    }
                                }

                                editFieldContext = UPEditFieldContext.ChildFieldContextForFieldConfigValue(childFieldConfig, rawFieldValue);
                                if (offlineChanged)
                                {
                                    editFieldContext.SetOfflineChangeValue(offlineValue);
                                }

                                childFields.Add(editFieldContext);
                            }
                        }
                    }

                    var markAsChanged = false;
                    rawFieldValue = rawFieldValue0;
                    if (initialValues != null)
                    {
                        string initialValue = this.ValueByApplyingInitialValuesForField(rawFieldValue, fieldConfig, initialValues);
                        if (!rawFieldValue.Equals(initialValue))
                        {
                            markAsChanged = true;
                            rawFieldValue = initialValue;
                        }
                    }

                    offlineChanged = false;
                    offlineValue   = null;
                    if (offlineRootRecord != null)
                    {
                        offlineValue = offlineRootRecord.StringFieldValueForFieldIndex(fieldConfig.FieldId);
                        if (offlineValue != null && !offlineValue.Equals(rawFieldValue))
                        {
                            offlineChanged = true;
                        }
                    }

                    if (selector != null)
                    {
                        // Sometimes it makes sense to add the Link field , so you have the link information on the EditPage , but the field is not displayed .
                        // Thus, the field is interpreted as EditField Selector must be set.
                        if (isHidden)
                        {
                            editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else if (isReadOnly && ConfigurationUnitStore.DefaultStore.ConfigValueIsSet("Disable.82213"))
                        {
                            editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else
                        {
                            editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, selector);
                        }
                    }
                    else
                    {
                        if (isHidden)
                        {
                            editFieldContext = UPEditFieldContext.HiddenFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else if (isReadOnly)
                        {
                            editFieldContext = UPEditFieldContext.ReadonlyFieldFor(fieldConfig, fieldIdentifier, rawFieldValue);
                        }
                        else
                        {
                            editFieldContext = UPEditFieldContext.FieldContextFor(fieldConfig, fieldIdentifier, rawFieldValue, childFields as List <UPEditFieldContext>);
                        }
                    }

                    if (fieldInfo.DateFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId)
                    {
                        editFieldContext.DateOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.DateFieldId, currentInfoAreaId, -1);
                    }
                    else if (fieldInfo.TimeFieldId >= 0 && tabConfig.FieldControl.InfoAreaId == currentInfoAreaId)
                    {
                        editFieldContext.TimeOriginalValue = resultRow?.RawValueForFieldIdInfoAreaIdLinkId(fieldInfo.TimeFieldId, currentInfoAreaId, -1);
                    }

                    if (offlineChanged)
                    {
                        editFieldContext.SetOfflineChangeValue(offlineValue);
                    }
                    else if (markAsChanged)
                    {
                        editFieldContext.SetChanged(true);
                    }

                    if (editFieldContext != null)
                    {
                        if (!string.IsNullOrEmpty(fieldPostfix))
                        {
                            editFieldContext.FieldLabelPostfix = fieldPostfix;
                        }

                        if (editFieldDictionary != null)
                        {
                            editFieldDictionary.SetObjectForKey(editFieldContext, fieldConfig.Identification);
                            if (childFields != null)
                            {
                                foreach (var childFieldContext in childFields)
                                {
                                    editFieldDictionary.SetObjectForKey(childFieldContext, childFieldContext.FieldConfig.Identification);
                                }
                            }
                        }

                        fieldArray.Add(editFieldContext);
                    }
                }
                else
                {
                    string fieldValue;
                    if (fieldAttributes.FieldCount > 1)
                    {
                        fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                        if (string.IsNullOrEmpty(fieldValue))
                        {
                            fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues);
                        }

                        var values = !string.IsNullOrEmpty(fieldValue) ?
                                     new List <string> {
                            fieldValue
                        } :
                        new List <string>();

                        for (var k = 1; k < fieldAttributes.FieldCount; k++)
                        {
                            var childfieldConfig = tabConfig.FieldAtIndex(++j);
                            if (childfieldConfig == null)
                            {
                                continue;
                            }

                            fieldValue = resultRow?.ValueAtIndex(childfieldConfig.TabIndependentFieldIndex);
                            if (string.IsNullOrEmpty(fieldValue))
                            {
                                fieldValue = this.ValueForLinkFieldFromInitialValues(childfieldConfig, initialValues);
                            }

                            if (string.IsNullOrEmpty(fieldValue))
                            {
                                fieldValue = string.Empty;
                            }

                            values.Add(fieldValue);
                        }

                        fieldValue = fieldAttributes.FormatValues(values);
                    }
                    else
                    {
                        fieldValue = resultRow?.ValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                        if (string.IsNullOrEmpty(fieldValue))
                        {
                            fieldValue = this.ValueForLinkFieldFromInitialValues(fieldConfig, initialValues);
                        }
                    }

                    UPMField field;
                    if (!isHidden && !string.IsNullOrEmpty(fieldValue))
                    {
                        field = new UPMStringField(fieldIdentifier);
                        ((UPMStringField)field).StringValue = fieldValue;
                    }
                    else
                    {
                        field = null;
                    }

                    if (field != null)
                    {
                        if (!fieldConfig.Attributes.NoLabel)
                        {
                            field.LabelText = fieldConfig.Label;
                        }

                        SetAttributesOnField(fieldAttributes, field);
                        fieldArray.Add(field);
                    }
                }
            }

            return(fieldArray);
        }
        private UPMGroup AddFieldsToDetailGroup(UPMGroup upmGroup, string recordIdentification, UPCRMResultRow resultRow, out string documentKey, out UPConfigFieldControlField documentFieldConfig)
        {
            var configStore     = ConfigurationUnitStore.DefaultStore;
            var hideEmptyFields = configStore.ConfigValueIsSet("View.HideEmptyFields");

            documentKey         = string.Empty;
            documentFieldConfig = null;
            var listFormatter = new UPCRMListFormatter(this.TabConfig, false);
            var fieldCount    = listFormatter.PositionCount;
            var detailGroup   = upmGroup;

            for (var j = 0; j < fieldCount; j++)
            {
                var fieldConfig     = listFormatter.FirstFieldForPosition(j);
                var fieldAttributes = fieldConfig.Attributes;
                var fieldIdentifier = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(recordIdentification, fieldConfig.Identification);
                var hasFieldValue   = false;
                if (fieldAttributes.Image)
                {
                    documentKey         = resultRow.ValueAtIndex(fieldConfig.TabIndependentFieldIndex);
                    documentFieldConfig = fieldConfig;
                    if (!string.IsNullOrEmpty(documentKey) && fieldCount == 1)
                    {
                        detailGroup = this.AddFieldToDetailGroup(detailGroup, fieldIdentifier, recordIdentification);
                    }

                    continue;
                }

                if (fieldAttributes.Hide)
                {
                    continue;
                }

                if (fieldAttributes.Empty)
                {
                    detailGroup = this.AddFieldToDetailGroup(detailGroup, recordIdentification, fieldIdentifier, fieldAttributes);
                    continue;
                }

                string fieldValue = null;

                try
                {
                    fieldValue = listFormatter.StringFromRowForPosition(resultRow, j);
                }
                catch (Exception error)
                {
                    SimpleIoc.Default.GetInstance <ILogger>().LogError(error);
                }

                if (!string.IsNullOrEmpty(fieldValue))
                {
                    hasFieldValue = true;
                }

                if (!hasFieldValue && hideEmptyFields && !this.columnStyle)
                {
                    if (!(detailGroup is UPMCalendarPopoverGroup) || j > 3)
                    {
                        continue;
                    }
                }

                if (fieldAttributes.MultiLine && j + 1 == fieldCount && detailGroup == null)
                {
                    var multiLineGroup = this.CreateMultilineGroup(recordIdentification, CreateStringField(fieldIdentifier, fieldAttributes, fieldValue), fieldConfig);
                    this.ControllerState = GroupModelControllerState.Finished;
                    this.Group           = multiLineGroup;
                    return(multiLineGroup);
                }

                var field = this.CreateField(fieldAttributes, fieldIdentifier, fieldConfig, resultRow, recordIdentification, configStore);
                if (field == null)
                {
                    continue;
                }

                UpdateField(field, fieldAttributes, fieldConfig, fieldValue);
                if (string.IsNullOrWhiteSpace(field.LabelText) && string.IsNullOrEmpty(fieldValue))
                {
                    continue;
                }

                detailGroup = this.AddFieldToDetailGroup(detailGroup, fieldAttributes, field, recordIdentification);
            }

            return(detailGroup);
        }
Exemplo n.º 7
0
 /// <summary>
 /// Instantiates the page.
 /// </summary>
 /// <returns></returns>
 public override Page InstantiatePage()
 {
     return(this.Page != null
         ? new UPMObjectivesPage(this.Page.Identifier)
         : new UPMObjectivesPage(FieldIdentifier.IdentifierWithRecordIdentificationFieldId(this.recordId, "Page0")));
 }
Exemplo n.º 8
0
        private void FillPage()
        {
            UPMCharacteristicsPage newPage = (UPMCharacteristicsPage)this.InstantiatePage();

            newPage.IsReadOnly = this.IsReadOnly;
            foreach (UPCharacteristicsGroup crmGroup in this.Characteristics.Groups)
            {
                UPMCharacteristicsItemGroup group = new UPMCharacteristicsItemGroup(StringIdentifier.IdentifierWithStringId(crmGroup.CatalogValue))
                {
                    GroupNameField = new UPMStringField(StringIdentifier.IdentifierWithStringId(crmGroup.Label))
                    {
                        StringValue = crmGroup.Label
                    },
                    ShowExpanded = crmGroup.ShowExpanded,
                    GroupType    = crmGroup.SingleSelection ? UPMCharacteristicsItemGroupType.SingleSelect : UPMCharacteristicsItemGroupType.MultiSelect
                };

                foreach (UPCharacteristicsItem crmItem in crmGroup.Items)
                {
                    UPMCharacteristicsItem item = new UPMCharacteristicsItem(StringIdentifier.IdentifierWithStringId(crmItem.CatalogValue))
                    {
                        ItemNameField = new UPMStringField(StringIdentifier.IdentifierWithStringId(crmItem.Label))
                        {
                            StringValue = crmItem.Label
                        },
                        SelectedField = new UPMBooleanEditField(StringIdentifier.IdentifierWithStringId(crmItem.Label))
                        {
                            BoolValue = crmItem.Record != null
                        }
                    };
                    group.AddChild(item);

                    List <UPMField> additionalEditFields = new List <UPMField>();
                    if (crmItem.ShowAdditionalFields)
                    {
                        for (int additionalFieldIndex = 0; additionalFieldIndex < crmItem.AdditionalFields.Count; additionalFieldIndex++)
                        {
                            UPConfigFieldControlField configField     = crmItem.AdditionalFields[additionalFieldIndex];
                            FieldIdentifier           fieldIdentifier = FieldIdentifier.IdentifierWithRecordIdentificationFieldId(this.CharacteristicsRootRecordIdentification, configField.Identification);
                            UPEditFieldContext        fieldContext    = UPEditFieldContext.FieldContextFor(configField, fieldIdentifier, crmItem.Values[additionalFieldIndex], (List <UPEditFieldContext>)null);
                            if (fieldContext != null)
                            {
                                additionalEditFields.Add(fieldContext.EditField);
                                this.editPageContext.EditFields.SetObjectForKey(fieldContext, $"{configField.Identification}-{crmItem.CatalogValue}-{crmGroup.CatalogValue}");
                            }
                        }
                    }

                    item.EditFields = additionalEditFields;
                }

                if (group.Children.Count > 0)
                {
                    newPage.AddChild(group);
                }
            }

            if (this.IsReadOnly)
            {
                newPage = this.PageForOverview(newPage);
            }

            ITopLevelElement oldPage = this.TopLevelElement;

            this.TopLevelElement = newPage;
            newPage.Invalid      = false;
            this.InformAboutDidChangeTopLevelElement(oldPage, newPage, null, null);
        }
Exemplo n.º 9
0
 /// <summary>
 /// Instantiates the page.
 /// </summary>
 /// <returns></returns>
 public override Page InstantiatePage()
 {
     return(this.Page != null
         ? new UPMQuestionnairePage(this.Page.Identifier)
         : new UPMQuestionnairePage(FieldIdentifier.IdentifierWithRecordIdentificationFieldId("test", "Page0")));
 }