private static void MakeCategory(Control parent, string title, string classNamePrefix,
                                         string content1, string content2, CategoryOptions options = CategoryOptions.None)
        {
            var asLink           = (options & CategoryOptions.AsLink) != 0;
            var isScrollable     = (options & CategoryOptions.Scrollable) != 0;
            var createParagraphs = (options & CategoryOptions.Paragraphs) != 0;
            var isHeadshot       = (options & CategoryOptions.Headshot) != 0;
            var isProfile        = (options & CategoryOptions.Profile) != 0;
            var isPicture        = isHeadshot || isProfile;
            var heading          = new HtmlDiv().AddTo(parent, "category-heading", true);

            new HtmlSpan {
                InnerText = title
            }.AddTo(heading);
            var hasContent1 = isPicture
        ? PoliticiansImagesBlobs.PoliticianKeyExists(content1)
        : !IsNullOrWhiteSpace(content1);
            var hasContent2 = isPicture
        ? PoliticiansImagesBlobs.PoliticianKeyExists(content2)
        : !IsNullOrWhiteSpace(content2);
            var category = new HtmlDiv().AddTo(parent,
                                               classNamePrefix + "-databoxes databoxes clearfix", true);
            var d1 =
                new HtmlDiv().AddTo(category, "databox databox-1", true) as HtmlContainerControl;

            if (!hasContent1)
            {
                d1.AddCssClasses("no-content");
            }
            var d2 =
                new HtmlDiv().AddTo(category, "databox databox-2", true) as HtmlContainerControl;

            if (!hasContent2)
            {
                d2.AddCssClasses("no-content");
            }
            if (isScrollable)
            {
                d1.AddCssClasses("scrollable");
                d2.AddCssClasses("scrollable");
            }
            if (asLink)
            {
                if (!IsNullOrWhiteSpace(content1))
                {
                    new HtmlAnchor
                    {
                        InnerText = content1,
                        HRef      = VotePage.NormalizeUrl(content1),
                        Target    = "content"
                    }
                }
        public static HtmlGenericControl GetCandidateListItem(DataRow politician, string idPrefix = null,
                                                              bool noCache = false)
        {
            var div = new HtmlDiv();

            div.AddCssClasses("search-politician unselectable clearfix");
            if (!string.IsNullOrWhiteSpace(idPrefix))
            {
                div.ID = idPrefix + politician.PoliticianKey();
            }
            Report.CreatePoliticianImageTag(politician.PoliticianKey(), 35, noCache).AddTo(div);
            var text = FormatName(politician);

            if (!string.IsNullOrWhiteSpace(politician.PartyCode()))
            {
                text += " (" + politician.PartyCode() + ")";
            }
            new HtmlDiv {
                InnerHtml = text
            }.AddTo(div, "name");
            text = GetCandidateList_OfficeDescription(politician);
            if (!string.IsNullOrWhiteSpace(text))
            {
                new HtmlDiv {
                    InnerHtml = text
                }
            }
            public void Generate(OfficialsReportResponsive officialsReport,
                                 bool isForAllStatesReport = false,
                                 string stateCode          = "", string countyCode = "", string localCode = "",
                                 Control reportContainer   = null)
            {
                if (reportContainer == null)
                {
                    reportContainer = officialsReport.ReportContainer;
                }
                OfficialsReport      = officialsReport;
                StateCode            = stateCode;
                CountyCode           = countyCode;
                _LocalCode           = localCode;
                IsForAllStatesReport = isForAllStatesReport;

                if (!string.IsNullOrWhiteSpace(_LocalCode))
                {
                    LocalName =
                        VotePage.GetPageCache()
                        .LocalDistricts.GetLocalDistrict(StateCode, CountyCode, _LocalCode);
                }

                var offices = GetOffices();

                if (offices.Count <= 0)
                {
                    return;
                }

                // ReSharper disable once PossibleNullReferenceException
                (new HtmlDiv().AddTo(reportContainer, "category-title accordion-header")
                 as HtmlGenericControl).InnerHtml = GetCategoryTitle();
                var container = new HtmlDiv().AddTo(reportContainer,
                                                    "category-content accordion-content");

                var entries = 0;

                foreach (var office in offices)
                {
                    var politicians = office.ToList();
                    var officeInfo  = politicians[0];
                    entries += OfficialsReport.ReportOneOffice(container, GetOfficeTitle(officeInfo),
                                                               GetRunningMateTitle(), politicians);
                }
                container.AddCssClasses("candidates-" + entries);
            }
        private static void AddIssue(DataRow candidate, QuestionEntry question)
        {
            var item = new HtmlDiv();

            item.AddTo(question.Container, "info-item issue-item");
            var row =
                question.QuestionGroup.FirstOrDefault(
                    r => r.PoliticianKey().IsEqIgnoreCase(candidate.PoliticianKey()));

            if (row == null) // no answer
            {
                item.AddCssClasses("empty-item");
            }
            else
            {
                item.InnerText = row.Answer();
            }
        }
        private static void AddBioInfo(DataRow candidate, BioInfo bioInfo)
        {
            var value = candidate == null
        ? string.Empty
        : (candidate[bioInfo.Column] as string).SafeString().Trim();
            var item =
                new HtmlDiv {
                InnerText = value
            }.AddTo(bioInfo.Container,
                    "info-item bio-item");

            if (value == string.Empty)
            {
                item.AddCssClasses("empty-item");
            }
            else
            {
                bioInfo.HasValue = true;
            }
        }
示例#6
0
        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++;
            }
        }
示例#7
0
        private int PopulateWinnersBetaTree(DataTable table, Control root)
        {
            void CreateNode(Control parent,
                            IEnumerable <DataRow> office, string className = null,
                            bool useLine2Only = false)
            {
                var candidates = office.ToList();
                var officeInfo = candidates[0];
                var winners    = candidates.Where(row => row.IsWinner()).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;

                // Now create the node
                // Format the office description
                var text = useLine2Only
          ? officeInfo.OfficeLine2()
          : Offices.FormatOfficeName(officeInfo);

                // Include the position slot count if > 1
                if (officeInfo.PrimaryPositions() > 1)
                {
                    text = $"{text} [{officeInfo.PrimaryPositions()}]";
                }

                var addClass = "office-name no-checkbox";

                if (!IsNullOrWhiteSpace(className))
                {
                    addClass += " " + className;
                }
                var data = "key:'" + officeInfo.OfficeKey() + "',addClass:'" + addClass +
                           "',hideCheckbox:true,unselectable:true";
                var officeNode = new HtmlLi().AddTo(parent);

                officeNode.Attributes.Add("data", data);
                new HtmlDiv {
                    InnerHtml = text
                }.AddTo(officeNode, "label");
                var dropdownDiv = new HtmlDiv().AddTo(officeNode,
                                                      "dropdowns idwinners-" + officeInfo.OfficeKey());

                // if there is a possible runoff, create checkbox and runoff list
                var runoffPositions = officeInfo.PrimaryRunoffPositions();

                if (runoffPositions != 0)
                {
                    var minCandidates = runoffPositions == -1
            ? officeInfo.PrimaryPositions() + 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
                  ? 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 (!IsNullOrWhiteSpace(politician.PartyCode()))
                            {
                                name += $" ({politician.PartyCode()})";
                            }
                            var indicators = Empty;

                            // Add winner indicator
                            if (politician.AdvanceToRunoff())
                            {
                                indicators += "◄";
                            }

                            if (indicators != 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");
                }

                if (candidates.Count <= officeInfo.PrimaryPositions())
                {
                    // uncontested -- create a disabled dropdown for each candidate
                    foreach (var politician in candidates)
                    {
                        var dropdownList = new HtmlSelect {
                            EnableViewState = false
                        }.AddTo(winnersDiv);
                        dropdownList.Attributes.Add("disabled", "disabled");

                        var name = Politicians.FormatName(politician);
                        if (!IsNullOrWhiteSpace(politician.PartyCode()))
                        {
                            name += $" ({politician.PartyCode()})";
                        }
                        var indicators = Empty;

                        // Add winner indicator
                        if (winners.FirstOrDefault(winner => winner.PoliticianKey()
                                                   .IsEqIgnoreCase(politician.PoliticianKey())) != null)
                        {
                            indicators += "◄";
                        }

                        if (indicators != Empty)
                        {
                            name += " " + indicators;
                        }

                        dropdownList.AddItem(name, politician.PoliticianKey(), true);
                    }
                }
                else
                {
                    // contested -- create a dropdown for each already-identified winner,
                    // with the default selection as the winner
                    //// and the other winners removed from the list
                    var dropdownContents = winners.Select(winner => new
                    {
                        DefaultPolitician = winner.PoliticianKey(),
                        List = candidates.Where(row =>
                                                //  row.PoliticianKey() == winner.PoliticianKey() ||
                                                //    !row.IsWinner()
                                                true).ToList()
                    }).ToList();

                    // Create the winner dropdowns
                    foreach (var dropdownContent in dropdownContents)
                    {
                        var dropdownList = new HtmlSelect {
                            EnableViewState = false
                        }.AddTo(winnersDiv);
                        dropdownList.Attributes.Add("title", "Select one");

                        // allow unselect
                        dropdownList.AddItem("Unselect Winner", Empty);

                        // 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 (!IsNullOrWhiteSpace(politician.PartyCode()))
                            {
                                name += $" ({politician.PartyCode()})";
                            }
                            var indicators = Empty;

                            // Add winner indicator
                            if (winners.FirstOrDefault(winner => winner.PoliticianKey()
                                                       .IsEqIgnoreCase(politician.PoliticianKey())) != null)
                            {
                                indicators += "◄";
                            }

                            if (indicators != Empty)
                            {
                                name += " " + indicators;
                            }

                            dropdownList.AddItem(name, politician.PoliticianKey(),
                                                 !isRunoff && dropdownContent.DefaultPolitician == politician.PoliticianKey());
                        }
                    }

                    // if there are more positions than already-identified winners and some non-winning candidates,
                    // fill out with undefaulted lists that contain all candidates
                    if (winners.Count < officeInfo.PrimaryPositions())
                    {
                        var nonWinners = candidates.Where(row => !row.IsWinner()).ToList();
                        var counter    = Math.Min(nonWinners.Count,
                                                  officeInfo.PrimaryPositions() - winners.Count);
                        while (counter-- > 0)
                        {
                            var dropdownList = new HtmlSelect {
                                EnableViewState = false
                            }.AddTo(winnersDiv)
                            .AddCssClasses("bold") as HtmlSelect;
                            Debug.Assert(dropdownList != null, "dropdownList != null");
                            dropdownList.Attributes.Add("title", "Select one");

                            // The first option in each dropdown is a disabled header
                            var option = dropdownList.AddItem("Select Winner", Empty, true);
                            option.Attributes.Add("disabled", "disabled");

                            // Add an option for each politician
                            foreach (var politician in candidates.OrderBy(row => row.LastName())
                                     .ThenBy(row => row.FirstName()))
                            {
                                var name = Politicians.FormatName(politician);
                                if (!IsNullOrWhiteSpace(politician.PartyCode()))
                                {
                                    name += $" ({politician.PartyCode()})";
                                }

                                dropdownList.AddItem(name, politician.PoliticianKey());
                            }
                        }
                    }
                }
            }

            var officeCount = 0;

            root.Controls.Clear();
            var tree = new HtmlUl().AddTo(root);

            const string rootText = "Select the Winner(s) for Each Contested Primary Office";
            const string rootData =
                "addClass:'root-node no-checkbox',hideCheckbox:true,unselectable:true";

            var rootNode = new HtmlLi {
                InnerHtml = rootText
            }.AddTo(tree);

            rootNode.Attributes.Add("data", rootData);
            var rootTree = new HtmlUl().AddTo(rootNode);

            var officeClasses = table.Rows.Cast <DataRow>().GroupBy(row => row.OfficeClass());
            var even          = false;

            foreach (var officeClass in officeClasses)
            {
                var offices = officeClass.GroupBy(row => row.OfficeKey()).ToList();
                officeCount += offices.Count;
                if (offices.Count == 1)
                {
                    CreateNode(rootTree, offices[0], "odd");
                    even = !even;
                }
                else
                {
                    // If all OfficeLine1's are identical, don't show them
                    var hasVariedLine1 = offices.Exists(row => row.First().OfficeLine1() !=
                                                        offices[0].First().OfficeLine1());
                    var text = Offices.GetOfficeClassShortDescription(officeClass.Key, StateCode);
                    var classNode = new HtmlLi {
                        InnerHtml = text
                    }.AddTo(rootTree);
                    classNode.Attributes.Add("data",
                                             "addClass:'office-class no-checkbox office-class-" + officeClass.Key +
                                             "',key:'office-class-" + officeClass.Key +
                                             "',hideCheckbox:true,unselectable:true");
                    var classSubTree = new HtmlUl().AddTo(classNode);
                    foreach (var office in offices)
                    {
                        CreateNode(classSubTree, office,
                                   /*even ? "even" :*/ "odd", !hasVariedLine1);
                        even = !even;
                    }
                }
            }
            return(officeCount);
        }
        private HtmlControl ReportCandidate(DataRow candidate)
        {
            var info = new HtmlDiv().AddCssClasses("info");

            var name          = new HtmlP().AddTo(info, "name");
            var isPrimary     = Elections.IsPrimaryElection(candidate.ElectionKey());
            var isNonPartisan =
                Elections.GetNationalPartyCode(candidate.ElectionKey()) == "X";

            FormatCandidate(candidate, true, (!isPrimary || isNonPartisan) &&
                            !candidate.IsRunningMate())
            .AddTo(name);

            if (candidate.IsWinner() && !candidate.IsRunningMate())
            {
                info.AddCssClasses("winner");
                new HtmlDiv()
                .Attribute("title", "Winner")
                .AddTo(info, "winner-icon");
            }

            new HtmlImage
            {
                Src = VotePage.GetPoliticianImageUrl(candidate.PoliticianKey(), 75)
            }.AddTo(
                info, "rounded-border headshot");

            var rightSide = new HtmlDiv().AddTo(info, "right-side");

            FormatCandidatePhone(candidate)
            .AddTo(rightSide);

            FormatCandidateWebsite(candidate)
            .AddTo(rightSide);

            SocialMedia.GetAnchors(candidate)
            .AddCssClasses("social")
            .AddTo(rightSide);

            var address      = candidate.PublicAddress();
            var cityStateZip = candidate.PublicCityStateZip();

            if (!string.IsNullOrWhiteSpace(address) &&
                !string.IsNullOrWhiteSpace(cityStateZip))
            {
                var addressTag = new HtmlDiv().AddTo(rightSide, "address");
                new HtmlP {
                    InnerText = address
                }.AddTo(addressTag);
                new HtmlP {
                    InnerText = cityStateZip
                }.AddTo(addressTag);
            }

            var age = candidate.Age();

            if (!string.IsNullOrWhiteSpace(age))
            {
                var ageTag = new HtmlDiv().AddTo(rightSide, "age");
                new HtmlSpan {
                    InnerText = "Age: "
                }.AddTo(ageTag);
                new LiteralControl(age).AddTo(ageTag);
            }

            ClearBoth()
            .AddTo(info);

            return(info);
        }
示例#9
0
        public static HtmlGenericControl GetCandidateListItem(DataRow politician,
                                                              string idPrefix = null, bool noCache = false)
        {
            string OfficeDescription()
            {
                var officeKey = politician.LiveOfficeKey();

                if (IsNullOrWhiteSpace(officeKey))
                {
                    return(Empty);
                }

                var result = politician.OfficeLine1();

                if (!IsNullOrWhiteSpace(politician.OfficeLine2()) &&
                    politician.OfficeClass() != OfficeClass.USPresident)
                {
                    result += " " + politician.OfficeLine2();
                }
                if (politician.OfficeClass() != OfficeClass.USPresident)
                {
                    var stateCode  = Offices.GetStateCodeFromKey(officeKey);
                    var countyCode = Offices.GetCountyCodeFromKey(officeKey);
                    var localKey   = Offices.GetLocalKeyFromKey(officeKey);
                    if (IsNullOrWhiteSpace(countyCode))
                    {
                        result = StateCache.GetStateName(stateCode) + " " + result;
                    }
                    else if (IsNullOrWhiteSpace(localKey))
                    {
                        result = CountyCache.GetCountyName(stateCode, countyCode) + ", " +
                                 StateCache.GetStateName(stateCode) + " " + result;
                    }
                    else
                    {
                        result = CountyCache.GetCountyDescription(stateCode, localKey) + ", " +
                                 StateCache.GetStateName(stateCode) + ", " + politician.LocalDistrict() + " " +
                                 result;
                    }
                }
                return(politician.LivePoliticianStatus().GetOfficeStatusDescription() + result);
            }

            string AddressLine()
            {
                var result       = politician.PublicAddress();
                var cityStateZip = politician.PublicCityStateZip();

                if (!IsNullOrWhiteSpace(result) && !IsNullOrWhiteSpace(cityStateZip))
                {
                    result += ", ";
                }
                result += cityStateZip;
                return(result);
            }

            var div = new HtmlDiv();

            div.AddCssClasses("search-politician unselectable clearfix");
            if (!IsNullOrWhiteSpace(idPrefix))
            {
                div.ID = idPrefix + politician.PoliticianKey();
            }
            Report.CreatePoliticianImageTag(politician.PoliticianKey(), 35, noCache).AddTo(div);
            var text = FormatName(politician);

            if (!IsNullOrWhiteSpace(politician.PartyCode()))
            {
                text += " (" + politician.PartyCode() + ")";
            }
            new HtmlDiv {
                InnerHtml = text
            }.AddTo(div, "name");
            text = OfficeDescription();
            if (!IsNullOrWhiteSpace(text))
            {
                new HtmlDiv {
                    InnerHtml = text
                }
            }
示例#10
0
        private static void CreateYouTubeSubTabContent(Control parent, DataRow row, int duplicate)
        {
            var questionId             = row.QuestionId();
            var questionIdUnique       = $"{questionId}-{duplicate}";
            var wasUploadedByCandidate = !IsNullOrWhiteSpace(row.YouTubeUrl()) &&
                                         row.YouTubeSource() == YouTubeVideoInfo.VideoUploadedByCandidateMessage;

            var wasUploadedByVoteUsa = !IsNullOrWhiteSpace(row.YouTubeUrl()) &&
                                       row.YouTubeSource() != YouTubeVideoInfo.VideoUploadedByCandidateMessage;

            // the Source heading and Uploaded by candidate checkbox (only for master users)
            if (!IsPoliticianUser)
            {
                var heading = new HtmlDiv().AddTo(parent, "category-heading");
                new HtmlSpan {
                    InnerText = "Select Type of Video to be Shown"
                }.AddTo(heading);

                AddCheckboxInputElement(parent, "YouTubeFromCandidate" + questionIdUnique,
                                        $"youtubefromcandidate{questionId} youtubefrom-checkbox youtubefromcandidate-checkbox ",
                                        null, wasUploadedByCandidate, "Complete Unedited YouTube.com video - not a YouTube video clip on the Vote USA Channel",
                                        "fromcandidate clearfix data-field ", null, null, null, Empty);

                AddCheckboxInputElement(parent, "YouTubeFromVoteUSA" + questionIdUnique,
                                        $"youtubefromvoteusa{questionId} youtubefrom-checkbox youtubefromvoteusa-checkbox data-field ",
                                        null, wasUploadedByVoteUsa, "YouTube Video on Vote USA Channel - a video clip created by Vote USA from some other video source and uploaded to the Vote USA Channel", "fromvoteusa clearfix",
                                        null, null, null, Empty);
            }

            var youTubeSourceFields = new HtmlDiv().AddTo(parent, "youtube-source-fields");

            if (!IsPoliticianUser)
            {
                AddTextInputElement(youTubeSourceFields, "YouTubeSourceUrl" + questionIdUnique,
                                    $"youtubesourceurl{questionId} shadow-2 youtubesourceurl-textbox data-field ",
                                    row.YouTubeSourceUrl(), "Enter the url (with or without http(s)://) of the source video.",
                                    false, "Url of the Other YouTube Source used to create the Vote USA Channel video clip", "youtubeurl wide", null, null, null);
            }

            var youTubeSourceAndDateDiv = new HtmlDiv().AddTo(youTubeSourceFields,
                                                              "youtube-source-and-date-container source-and-date-container");

            if (wasUploadedByCandidate)
            {
                youTubeSourceFields.AddCssClasses("hidden");
            }
            else
            {
                youTubeSourceFields.RemoveCssClass("hidden");
            }

            if (!IsPoliticianUser)
            {
                var youTubeSourceDiv = new HtmlDiv().AddTo(youTubeSourceAndDateDiv,
                                                           "youtube-source-container source-container");
                AddTextAreaInputElement(youTubeSourceDiv, "YouTubeSource" + questionIdUnique,
                                        $"youtubesource{questionId} shadow youtubesource-textbox data-field ",
                                        row.YouTubeSource(), "Enter a description of the source video into this box.", false,
                                        "Enter a description of the source video into this box.",
                                        true, "Description of the Organization or Event of Other YouTube Source", "source",
                                        null, null, null, false, "Provide a short and concise description like: First NBC Democratic" +
                                        " Debate; KVUE Austin TX News; PBS New Hour. Do not include any urls or dates." +
                                        " These should be only entered in the separate Url and Date textboxes.");
                var youTubeDateDiv = new HtmlDiv().AddTo(youTubeSourceAndDateDiv,
                                                         "youtube-date-container date-container");
                AddTextInputElement(youTubeDateDiv, "YouTubeDate" + questionIdUnique,
                                    $"youtubedate{questionId} shadow-2 youtubedate-textbox date-picker data-field ",
                                    row.YouTubeDate().DbDateToShortDate(),
                                    "Enter the date of the video if today is not an appropriate date.", false,
                                    "Date when Other Source YouTube Content was made", "youtubedate", null, null, null);
                AddButtonInputElement(youTubeDateDiv, null,
                                      "today-button for-youtubedate button-1 button-smallest", "Today", "today  for-youtubedate");
            }

            AddTextInputElement(parent, "YouTubeUrl" + questionIdUnique,
                                $"youtubeurl{questionId} shadow-2 youtubeurl-textbox data-field ", row.YouTubeUrl(), IsPoliticianUser
         ? "Enter a YouTube url that addresses the question."
         : "Enter the YouTube url of the Vote-USA video.",
                                false,
                                "Url of YouTube Video to be Shown",
                                "youtubeurl wide", null, null, null);

            new HtmlP {
                InnerText = "When the Update Button is clicked the Description and Running Time of the video on YouTube is automatically extracted and presented in these two textboxes."
            }.AddTo(parent, "instructions");

            var displayYouTubeDescription = row.YouTubeDescription().SafeString();
            var displayYouTubeRunningTime = row.YouTubeRunningTime().FormatRunningTime();

            if (!IsNullOrWhiteSpace(row.YouTubeAutoDisable()))
            {
                displayYouTubeDescription = ">>> This video has been temporarily disabled on Vote-USA: " +
                                            row.YouTubeAutoDisable();
                displayYouTubeRunningTime = Empty;
            }

            var youTubeDescriptionAndTimeDiv = new HtmlDiv().AddTo(parent,
                                                                   "youtube-description-and-time-container");

            var youTubeDescriptionDiv = new HtmlDiv().AddTo(youTubeDescriptionAndTimeDiv,
                                                            "youtube-description-container");

            AddTextAreaInputElement(youTubeDescriptionDiv, "YouTubeDescription" + questionIdUnique,
                                    $"youtubedescription{questionId} shadow youtubedescription-textbox ",
                                    displayYouTubeDescription, null, false, null, false, "Video Description", "youtubedescription wide",
                                    null, null, null, true);

            var youTubeTimeDiv = new HtmlDiv().AddTo(youTubeDescriptionAndTimeDiv,
                                                     "youtube-time-container");

            AddTextInputElement(youTubeTimeDiv, "YouTubeRunningTime" + questionIdUnique,
                                $"youtuberunningtime{questionId} shadow-2 youtuberunningtime-textbox ",
                                displayYouTubeRunningTime, null, false, "Running Time", "youtuberunningtime",
                                null, null, null, true);
        }