/// <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 void LoadData(UPMObjectivesPage objectivesPage) { int itemCounter = 0; int sectionCounter = 0; foreach (UPObjectivesGroup group in this.objectivesGroupArray) { UPMObjectivesSection section = this.CreateSectionIdentfier(group.Label, StringIdentifier.IdentifierWithStringId(group.GroupKey)); foreach (UPObjectivesItem item in group.Items) { UPMObjective mobjective = this.CreateObjectiveIdentfier(item, StringIdentifier.IdentifierWithStringId($"ObjectiveItem_{itemCounter}")); if (item.Documents != null) { UPMDocumentsGroup documentGroup = new UPMDocumentsGroup(StringIdentifier.IdentifierWithStringId($"documentgroup{itemCounter}")); foreach (DocumentData document in item.Documents) { UPMDocument documentModel = new UPMDocument(document); documentGroup.AddChild(documentModel); } mobjective.AddGroup(documentGroup); } mobjective.ObjectiveItem = item; Dictionary <string, UPEditFieldContext> itemEditFields = new Dictionary <string, UPEditFieldContext>(); for (int additionalFieldIndex = 0; additionalFieldIndex < item.AdditionalFields.Count; additionalFieldIndex++) { UPConfigFieldControlField field = item.AdditionalFields[additionalFieldIndex]; RecordIdentifier fieldIdentifier = new RecordIdentifier(field.Identification); UPEditFieldContext fieldContext = null; FieldAttributes attributes = field.Attributes; if (attributes != null && attributes.Hide) { fieldContext = UPEditFieldContext.HiddenFieldFor(field, fieldIdentifier, item.Values[additionalFieldIndex]); } else if (attributes != null && attributes.ReadOnly) { fieldContext = UPEditFieldContext.ReadonlyFieldFor(field, fieldIdentifier, item.Values[additionalFieldIndex]); } else { fieldContext = UPEditFieldContext.FieldContextFor(field, fieldIdentifier, item.Values[additionalFieldIndex], (List <UPEditFieldContext>)null); } if (fieldContext?.Field != null) { string fieldIdentification = this.FieldIdentificationSectionCounterItemCounter(field.Field, sectionCounter, itemCounter); this.editPageContext.EditFields.SetObjectForKey(fieldContext, fieldIdentification); itemEditFields.SetObjectForKey(fieldContext, fieldIdentification); if (fieldContext.EditField != null) { fieldContext.EditField.EditFieldsContext = this.editPageContext; mobjective.AddField(fieldContext.EditField); } else { mobjective.AddField(fieldContext.Field); } } } this.HandleDependentFieldsSectionCounterItemCounter(itemEditFields, sectionCounter, itemCounter); if (item.ButtonActions.Count > 0) { List <UPMOrganizerAction> buttonActions = new List <UPMOrganizerAction>(); foreach (UPConfigButton button in item.ButtonActions) { StringIdentifier fieldIdentifier = StringIdentifier.IdentifierWithStringId("button"); UPMOrganizerAction action = new UPMOrganizerAction(fieldIdentifier); //action.SetTargetAction(this.ParentOrganizerModelController, PerformObjectivesAction); action.ViewReference = button.ViewReference.ViewReferenceWith(item.Record.RecordIdentification); action.LabelText = button.Label; buttonActions.Add(action); } mobjective.Actions = buttonActions; } section.AddChild(mobjective); itemCounter++; } if (section.Children.Count > 0) { objectivesPage.AddChild(section); } } if (objectivesPage.Children.Count == 0) { UPMMessageStatus messageStatus = new UPMMessageStatus(StringIdentifier.IdentifierWithStringId("messageIdentifier")); UPMStringField messageField = new UPMStringField(StringIdentifier.IdentifierWithStringId("statusFieldIdentifier")); messageField.FieldValue = LocalizedString.Localize(LocalizationKeys.TextGroupBasic, LocalizationKeys.KeyBasicNoObjectives); messageStatus.DetailMessageField = messageField; objectivesPage.Status = messageStatus; } }