/// <summary> /// Deletes the objective. /// </summary> /// <param name="_objective">The objective.</param> public void DeleteObjective(UPMObjective _objective) { _objective.ObjectiveItem.Deleted = true; this.DeletedItems.Add(_objective.ObjectiveItem); foreach (UPMObjectivesSection objectiveSection in this.Page.Children) { foreach (UPMObjective objective in objectiveSection.Children) { if (objective.Identifier.MatchesIdentifier(_objective.Identifier)) { List <UPMElement> objectives = new List <UPMElement>(objectiveSection.Children); objectiveSection.RemoveAllChildren(); foreach (UPMObjective objective2 in objectives) { if (!objective2.Identifier.MatchesIdentifier(_objective.Identifier)) { objectiveSection.AddChild(objective2); } } break; } } } this.InformAboutDidChangeTopLevelElement(this.Page, this.Page, new List <IIdentifier> { _objective.Identifier }, null); }
private UPMObjective CreateObjectiveIdentfier(UPObjectivesItem item, IIdentifier identifier) { UPMObjective objective = new UPMObjective(identifier); objective.ObjectiveItem = null; UPMStringField titleField = new UPMStringField(StringIdentifier.IdentifierWithStringId($"{identifier.IdentifierAsString}-title")); titleField.StringValue = item.TitleFieldValue; UPMStringField subtitleField = new UPMStringField(StringIdentifier.IdentifierWithStringId($"{identifier.IdentifierAsString}-subtitle")); subtitleField.StringValue = item.SubTitelFieldValue; UPMStringField dateField = new UPMStringField(StringIdentifier.IdentifierWithStringId($"{identifier.IdentifierAsString}-date")); dateField.StringValue = DateExtensions.LocalizedFormattedDate(item.Date); objective.AddMainField(titleField); objective.AddMainField(subtitleField); objective.AddMainField(dateField); objective.DoneField = new UPMBooleanEditField(StringIdentifier.IdentifierWithStringId($"{identifier.IdentifierAsString}-done")); objective.DoneField.BoolValue = item.Completed; objective.CanBeDeletedField = new UPMBooleanEditField(StringIdentifier.IdentifierWithStringId($"{identifier.IdentifierAsString}-canByDelete")); objective.CanBeDeletedField.BoolValue = item.CanBeDeleted; return(objective); }
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; } }