public static HtmlSelect AddTo(this HtmlSelect control, Control parent, string classes = null, bool clear = false) { parent.Controls.Add(control); if (classes != null) { control.AddCssClasses(classes, clear); } return(control); }
private void PopulateWinnersTree_CreateNode(Control parent, IEnumerable <DataRow> office, string className, bool useLine2Only = false) { var officeRows = office.ToList(); var officeInfo = officeRows[0]; var officeState = Offices.GetStateCodeFromKey(officeInfo.OfficeKey()); var electionState = Elections.GetStateCodeFromKey(GetElectionKey()); var canUpdateIncumbents = StateCache.IsValidStateCode(officeState) && StateCache.IsValidStateCode(electionState); var winners = officeRows.Where(row => row.IsWinner()) .ToList(); var candidates = officeRows.Where(row => !row.IsIncumbentRow()) .ToList(); var advancers = candidates.Where(row => row.AdvanceToRunoff()) .ToList(); // if any candidates are marked as AdvanceToRunoff, we default it as a runoff var isRunoff = advancers.Count > 0; var incumbents = officeRows.Where(row => row.IsIncumbentRow()) .ToList(); var incumbentsInElectionNotMarkedWinners = officeRows .Where(row => !row.IsIncumbentRow() && !row.IsWinner() && (incumbents.FirstOrDefault(i => i.PoliticianKey() .IsEqIgnoreCase(row.PoliticianKey())) != null)) .ToList(); var defaultPoliticians = winners.Select(row => row.PoliticianKey()) .Union( incumbentsInElectionNotMarkedWinners.Select(row => row.PoliticianKey())) .ToList(); // Creating a dropdown for each Election position var dropdownContents = Enumerable.Range(0, officeInfo.ElectionPositions()) .Select(n => new { DefaultPolitician = n < defaultPoliticians.Count ? defaultPoliticians[n] : string.Empty, List = new List <DataRow>(candidates) }) .ToList(); // Now create the node // Format the office description var text = useLine2Only ? officeInfo.OfficeLine2() : Offices.FormatOfficeName(officeInfo); var addClass = "office-name"; if (!canUpdateIncumbents) { addClass += " no-checkbox"; } if (!string.IsNullOrWhiteSpace(className)) { addClass += " " + className; } var data = "key:'" + officeInfo.OfficeKey(); if (canUpdateIncumbents) { data += "',addClass:'" + addClass + "',select:true"; } else { data += "',addClass:'" + addClass + "',hideCheckbox:true,unselectable:true"; } var officeNode = new HtmlLi().AddTo(parent); officeNode.Attributes.Add("data", data); new HtmlDiv { InnerHtml = text }.AddTo(officeNode, "label") .Attributes.Add("Title", text); var dropdownDiv = new HtmlDiv().AddTo(officeNode, "dropdowns idwinners-" + officeInfo.OfficeKey()); // if there is a possible runoff, create checkbox and runoff list var runoffPositions = officeInfo.GeneralRunoffPositions(); if (runoffPositions != 0) { var minCandidates = runoffPositions == -1 ? officeInfo.ElectionPositions() + 1 : runoffPositions + 1; if (candidates.Count >= minCandidates) { // if any candidates are marked as AdvanceToRunoff, we default it as a runoff isRunoff = candidates.Any(row => row.AdvanceToRunoff()); var runnoffId = "runoff-" + officeInfo.OfficeKey(); var runoffDiv = new HtmlDiv().AddTo(dropdownDiv); var runoffCheckbox = new HtmlInputCheckBox { Checked = isRunoff }.AddTo(runoffDiv, "runoff-checkbox"); if (runoffPositions > 0) { runoffCheckbox.Attributes.Add("rel", runoffPositions.ToString(CultureInfo.InvariantCulture)); } new HtmlLabel { ID = runnoffId, InnerText = "Runoff is required" }.AddTo(runoffDiv) .Attributes["for"] = runnoffId; var runoffsDiv = new HtmlDiv().AddTo(runoffDiv, "runoff-dropdown"); if (!isRunoff) { runoffsDiv.AddCssClasses("hidden"); } else { runoffsDiv.RemoveCssClass("hidden"); } new HtmlP { InnerText = "Select " + (runoffPositions == -1 ? string.Empty : runoffPositions.ToString(CultureInfo.InvariantCulture)) + " candidates to advance" }.AddTo(runoffsDiv); var runoffList = new HtmlSelect { EnableViewState = false, Size = candidates.Count, Multiple = true }.AddTo(runoffsDiv); foreach (var politician in candidates) { var name = Politicians.FormatName(politician); if (!string.IsNullOrWhiteSpace(politician.PartyCode())) { name += " (" + politician.PartyCode() + ")"; } var indicators = string.Empty; // Add winner indicator if (politician.AdvanceToRunoff()) { indicators += "◄"; } if (indicators != string.Empty) { name += " " + indicators; } runoffList.AddItem(name, politician.PoliticianKey(), politician.AdvanceToRunoff()); } } } var winnersDiv = new HtmlDiv().AddTo(dropdownDiv, "winners-dropdowns"); if (isRunoff) { winnersDiv.AddCssClasses("hidden"); } else { winnersDiv.RemoveCssClass("hidden"); } // Create the dropdowns var inx = 0; foreach (var dropdownContent in dropdownContents) { var dropdownList = new HtmlSelect { EnableViewState = false }.AddTo(winnersDiv); if (inx >= winners.Count) { dropdownList.AddCssClasses("bold"); } // The first option in each dropdown is a disabled header var dropDownMessage = dropdownContent.List.Count > 0 ? "Select winner or Vacant" : "No candidates"; var option = dropdownList.AddItem(dropDownMessage, string.Empty, dropdownContent.DefaultPolitician == string.Empty); option.Attributes.Add("disabled", "disabled"); // Add an option for each politician foreach ( var politician in dropdownContent.List.OrderBy(row => row.LastName()) .ThenBy(row => row.FirstName())) { var name = Politicians.FormatName(politician); if (!string.IsNullOrWhiteSpace(politician.PartyCode())) { name += " (" + politician.PartyCode() + ")"; } var indicators = string.Empty; // Add winner indicator if (winners.FirstOrDefault(winner => winner.PoliticianKey() .IsEqIgnoreCase(politician.PoliticianKey())) != null) { indicators += "◄"; } if (indicators != string.Empty) { name += " " + indicators; } dropdownList.AddItem(name, politician.PoliticianKey(), dropdownContent.DefaultPolitician == politician.PoliticianKey()); } // Add a "Vacant" option dropdownList.AddItem("Vacant", "vacant"); inx++; } }
protected void Page_Load(object sender, EventArgs e) { var firstNameControl = new TextBoxWithNormalizedLineBreaks().AddCssClasses("email-form-first-name narrow no-zoom"); EmailForm.AddOptionalItem(firstNameControl, true, "EmailFormFirstName", "First Name"); var lastNameControl = new TextBoxWithNormalizedLineBreaks().AddCssClasses("email-form-last-name narrow no-zoom"); EmailForm.AddOptionalItem(lastNameControl, true, "EmailFormLastName", "Last Name"); var partyControl = new HtmlSelect(); partyControl.AddCssClasses("email-form-party narrow no-zoom"); //Parties.PopulateNationalParties(partyControl, true, null, true); // eliminate non-partisan Parties.PopulateNationalParties(partyControl, false, null, true); EmailForm.AddOptionalItem(partyControl, true, "EmailFormParty", "Your Preferred Political Party – the political party you would like to focus most of your efforts on", "Preferred Political Party"); var stateControl = new HtmlSelect(); stateControl.AddCssClasses("email-form-state narrow no-zoom"); StateCache.Populate(stateControl, "--- Select state ---", Empty); EmailForm.AddOptionalItem(stateControl, true, "EmailFormState", "Your State", "State"); var phoneControl = new TextBoxWithNormalizedLineBreaks().AddCssClasses("email-form-phone narrow no-zoom"); EmailForm.AddOptionalItem(phoneControl, "EmailFormPhone", "Phone Number – only used if we can not reach you via email (optional)", "Phone"); var passwordControl = new TextBoxWithNormalizedLineBreaks().AddCssClasses("email-form-password narrow no-zoom"); EmailForm.AddOptionalItem(passwordControl, "EmailFormPassword", "Preferred Login Password – we will create and assign one for you if you have no preference (optional)", "Preferred Login Password"); EmailForm.MessageOptional = true; EmailForm.Callback = SubmitCallback; if (DomainData.IsValidStateCode) // Single state { Title = $"{PublicMasterPage.SiteName} | {TitleTagSingleStateDomain.Substitute()}"; MetaDescription = MetaDescriptionSingleStateDomain.Substitute(); } else { Title = $"{PublicMasterPage.SiteName} | {TitleTagAllStatesDomain.Substitute()}"; MetaDescription = MetaDescriptionAllStatesDomain.Substitute(); } EmailForm.ToEmailAddress = "*****@*****.**"; EmailForm.CcEmailAddress = "*****@*****.**"; EmailForm.SetItems( "I would like to volunteer for whatever is needed", "I would like to volunteer to scrape candidate websites", "I would like to volunteer to research county and local elected offices", "I would like to volunteer to interview and video candidates", "I would like to volunteer to speak to my local political parties/community outreach groups", "I would like to contact candidates via email"); }