public override async Task FollowUp() { //Load DocuSign template again in case there are new templates available LoadDocuSignTemplates(); var selectedTemplateId = SelectedTemplateId; //If template selection is cleared we should remove existing template fields if (string.IsNullOrEmpty(selectedTemplateId)) { PreviousSelectedTemplateId = null; ActivityUI.ClearDynamicFields(); Storage.RemoveByLabel(UserFieldsAndRolesCrateLabel); return; } if (selectedTemplateId == PreviousSelectedTemplateId) { return; } ActivityUI.ClearDynamicFields(); PreviousSelectedTemplateId = selectedTemplateId; var docuSignConfiguration = DocuSignManager.SetUp(AuthorizationToken); var tabsAndFields = DocuSignManager.GetTemplateRecipientsTabsAndDocuSignTabs(docuSignConfiguration, selectedTemplateId); var roles = tabsAndFields.Item1.Where(x => x.Tags.Contains(DocuSignConstants.DocuSignSignerTag, StringComparison.InvariantCultureIgnoreCase)).ToArray(); var userDefinedFields = tabsAndFields.Item1.Where(x => x.Tags.Contains(DocuSignConstants.DocuSignTabTag)); var envelopeData = tabsAndFields.Item2.ToLookup(x => x.Fr8DisplayType); //check for DocuSign default template names and add advisory json var hasDefaultNames = DocuSignManager.DocuSignTemplateDefaultNames(tabsAndFields.Item2); if (hasDefaultNames) { var advisoryCrate = Storage.CratesOfType <AdvisoryMessagesCM>().FirstOrDefault(); var currentAdvisoryResults = advisoryCrate == null ? new AdvisoryMessagesCM() : advisoryCrate.Content; var advisory = currentAdvisoryResults.Advisories.FirstOrDefault(x => x.Name == AdvisoryName); if (advisory == null) { currentAdvisoryResults.Advisories.Add(new AdvisoryMessageDTO { Name = AdvisoryName, Content = AdvisoryContent }); } else { advisory.Content = AdvisoryContent; } Storage.Add(Crate.FromContent("Advisories", currentAdvisoryResults)); } //Add TextSource control for every DocuSign role to activity UI ActivityUI.RolesFields.AddRange(roles.Select(x => UiBuilder.CreateSpecificOrUpstreamValueChooser(x.Key, x.Key, requestUpstream: true, specificValue: x.Value))); //Add TextSrouce control for every DocuSign template text field to activity UI ActivityUI.TextFields.AddRange(envelopeData[ControlTypes.TextBox].Select(x => UiBuilder.CreateSpecificOrUpstreamValueChooser(x.Name, x.Name, requestUpstream: true, specificValue: x.Value))); //Add RadioButtonGroup with respective options for every DocuSign template radio selection field to activity UI ActivityUI.RadioButtonGroupFields.AddRange( envelopeData[ControlTypes.RadioButtonGroup] .OfType <DocuSignMultipleOptionsTabDTO>() .Select(x => new RadioButtonGroup { GroupName = x.Name, Name = x.Name, Label = $"For the <strong>{x.Name}</strong>, use:", Radios = x.Items.Select(y => new RadioButtonOption { Name = y.Value, Value = y.Value, Selected = y.Selected }) .ToList() })); //Add CheckBox for every DocuSign template yes/no field to activity UI ActivityUI.CheckBoxFields.AddRange(envelopeData[ControlTypes.CheckBox].Select(x => new CheckBox { Name = x.Name, Label = x.Name, Selected = Convert.ToBoolean(x.Value) })); //Add DropDownList for every DocuSign template list selection field to activity UI ActivityUI.DropDownListFields.AddRange( envelopeData[ControlTypes.DropDownList] .OfType <DocuSignMultipleOptionsTabDTO>() .Select(x => new DropDownList { Name = x.Name, Label = $"For the <strong>{x.Name}</strong>, use:", ListItems = x.Items.Select(y => new ListItem { Key = string.IsNullOrEmpty(y.Value) ? y.Text : y.Value, Value = string.IsNullOrEmpty(y.Text) ? y.Value : y.Text, Selected = y.Selected }) .ToList() })); Storage.ReplaceByLabel(Crate.FromContent(UserFieldsAndRolesCrateLabel, new KeyValueListCM(userDefinedFields.Concat(roles)))); }
protected async Task HandleFollowUpConfiguration() { if (Storage.Count == 0) { return; } //update docusign templates list to get if new templates were provided by DS FillDocuSignTemplateSource("target_docusign_template"); // Try to find DocuSignTemplate drop-down. var dropdownControlDTO = ConfigurationControls.FindByName("target_docusign_template"); if (dropdownControlDTO == null) { return; } // Get DocuSign Template Id var docusignTemplateId = dropdownControlDTO.Value; //Abort configuration if templateId is the same that before if (!IsNewTemplateIdChoosen(Storage, docusignTemplateId)) { return; } var conf = DocuSignManager.SetUp(AuthorizationToken); var tabsandfields = DocuSignManager.GetTemplateRecipientsTabsAndDocuSignTabs(conf, docusignTemplateId); var roles = tabsandfields.Item1.Where(a => a.Tags.Contains(DocuSignConstants.DocuSignSignerTag)); Storage.RemoveByLabel("DocuSignTemplateRolesFields"); Storage.Add("DocuSignTemplateRolesFields", new KeyValueListCM(roles)); var envelopeDataDTO = tabsandfields.Item2; var userDefinedFields = tabsandfields.Item1.Where(a => a.Tags.Contains(DocuSignConstants.DocuSignTabTag)); //check for DocuSign default template names and add advisory json var hasDefaultNames = DocuSignManager.DocuSignTemplateDefaultNames(tabsandfields.Item2); if (hasDefaultNames) { var advisoryCrate = Storage.CratesOfType <AdvisoryMessagesCM>().FirstOrDefault(); var currentAdvisoryResults = advisoryCrate == null ? new AdvisoryMessagesCM() : advisoryCrate.Content; var advisory = currentAdvisoryResults.Advisories.FirstOrDefault(x => x.Name == advisoryName); if (advisory == null) { currentAdvisoryResults.Advisories.Add(new AdvisoryMessageDTO { Name = advisoryName, Content = advisoryContent }); } else { advisory.Content = advisoryContent; } Storage.Add(Crate.FromContent("Advisories", currentAdvisoryResults)); } Storage.RemoveByLabel("DocuSignTemplateUserDefinedFields"); Storage.Add("DocuSignTemplateUserDefinedFields", new KeyValueListCM(userDefinedFields.Concat(roles))); //Create TextSource controls for ROLES var rolesMappingBehavior = new TextSourceMappingBehavior(Storage, "RolesMapping", true); rolesMappingBehavior.Clear(); rolesMappingBehavior.Append(roles.Select(x => x.Key).ToList(), "Upstream Terminal-Provided Fields", AvailabilityType.RunTime); //Create Text Source controls for TABS var textSourceFields = new List <string>(); textSourceFields = envelopeDataDTO.Where(x => x.Fr8DisplayType == ControlTypes.TextBox).Select(x => x.Name).ToList(); var mappingBehavior = new TextSourceMappingBehavior( Storage, "Mapping", true ); mappingBehavior.Clear(); mappingBehavior.Append(textSourceFields, "Upstream Terminal-Provided Fields", AvailabilityType.RunTime); //Create TextSource controls for ROLES //Create radio Button Groups var radioButtonGroupBehavior = new RadioButtonGroupMappingBehavior(Storage, "RadioGroupMapping"); radioButtonGroupBehavior.Clear(); foreach (var item in envelopeDataDTO.Where(x => x.Fr8DisplayType == ControlTypes.RadioButtonGroup).ToList()) { var radioButtonGroupDTO = item as DocuSignMultipleOptionsTabDTO; if (radioButtonGroupDTO == null) { continue; } //todo: migrate the string format for label into template radioButtonGroupBehavior.Append(radioButtonGroupDTO.Name, $"For the <strong>{radioButtonGroupDTO.Name}</strong>, use:", radioButtonGroupDTO.Items.Select(x => new RadioButtonOption() { Name = x.Value, Value = x.Value, Selected = x.Selected }).ToList()); } //create checkbox controls var checkBoxMappingBehavior = new CheckBoxMappingBehavior(Storage, "CheckBoxMapping"); checkBoxMappingBehavior.Clear(); foreach (var item in envelopeDataDTO.Where(x => x.Fr8DisplayType == ControlTypes.CheckBox).ToList()) { checkBoxMappingBehavior.Append(item.Name, item.Name); } //create dropdown controls var dropdownListMappingBehavior = new DropDownListMappingBehavior(Storage, "DropDownMapping"); dropdownListMappingBehavior.Clear(); foreach (var item in envelopeDataDTO.Where(x => x.Fr8DisplayType == ControlTypes.DropDownList).ToList()) { var dropDownListDTO = item as DocuSignMultipleOptionsTabDTO; if (dropDownListDTO == null) { continue; } dropdownListMappingBehavior.Append(dropDownListDTO.Name, $"For the <strong>{item.Name}</strong>, use:", dropDownListDTO.Items.Where(x => x.Text != string.Empty || x.Value != string.Empty).Select(x => new ListItem() { Key = string.IsNullOrEmpty(x.Value) ? x.Text : x.Value, Value = string.IsNullOrEmpty(x.Text) ? x.Value : x.Text, Selected = x.Selected, }).ToList()); } }