Ejemplo n.º 1
0
        protected void ReportPolitician(DataRow politician, bool isWinner,
                                        bool isIncumbent)
        {
            var politicianKey  = politician.PoliticianKey();
            var politicianName = Politicians.FormatName(politician);

            Control anchorHeadshot = null;

            switch (ReportUser)
            {
            case ReportUser.Public:
            {
                anchorHeadshot =
                    CreatePoliticianImageAnchor(UrlManager.GetIntroPageUri(politicianKey)
                                                .ToString(), politicianKey, ImageSize100,
                                                politicianName +
                                                " biographical information and positions and views on the issues");
                break;
            }

            case ReportUser.Admin:
            {
                anchorHeadshot = new HtmlImage
                {
                    Src = VotePage.GetPoliticianImageUrl(politicianKey, ImageSize75)
                };
                break;
            }

            case ReportUser.Master:
            {
                anchorHeadshot =
                    CreatePoliticianImageAnchor(
                        SecurePoliticianPage.GetUpdateIssuesPageUrl(politicianKey),
                        politicianKey, ImageSize75,
                        "Edit Issue Topic Responses", "politician");
                break;
            }
            }

            var td = new HtmlTableCell().AddTo(CurrentPoliticianRow, "tdReportImage");

            Debug.Assert(anchorHeadshot != null, "anchorHeadshot != null");
            anchorHeadshot.AddTo(td);

            var politicianCell = new HtmlTableCell().AddTo(CurrentPoliticianRow,
                                                           "tdReportDetail");

            var nameContainer = new HtmlDiv().AddTo(politicianCell,
                                                    "detail name");

            if (isIncumbent)
            {
                new Literal {
                    Text = "* "
                }
            }
Ejemplo n.º 2
0
        private static void AddPoliticianMenu(Control ul)
        {
            if (!SecurePage.IsPoliticianPage ||
                !SecurePoliticianPage.GetPoliticianKeyExists())
            {
                return;
            }
            var name = SecurePoliticianPage.GetPoliticianName();

            AddMenuItem(ul, name, GetPoliticianMenu());
        }
Ejemplo n.º 3
0
        private static HtmlAnchor CreateAdminPoliticianAnchor(
            PoliticiansAdminReportViewRow row, string anchorText, string target)
        {
            var a = new HtmlAnchor
            {
                HRef      = SecurePoliticianPage.GetUpdateIntroPageUrl(row.PoliticianKey),
                Title     = "Edit Links, Picture, Bio & Reasons",
                InnerHtml = anchorText,
                Target    = IsNullOrWhiteSpace(target) ? "politician" : target
            };

            return(a);
        }
Ejemplo n.º 4
0
        private PlaceHolder CreatePoliticianNameAndKeyAnchor(
            PoliticiansAdminReportViewRow row)
        {
            var container = new PlaceHolder();

            var literalText = row.LastName + " .. ";

            if (row.OfficeStatus.ToPoliticianStatus() == PoliticianStatus.Incumbent)
            {
                literalText += "*";
            }
            new Literal {
                Text = literalText
            }.AddTo(container);

            Control imageTag;

            if (_AsMaster)
            {
                imageTag =
                    CreatePoliticianImageAnchor(
                        SecurePoliticianPage.GetUpdateIntroPageUrl(row.PoliticianKey),
                        row.PoliticianKey, imageWidth: 15,
                        title: FormatPoliticianName(row) + " Intro Page Data Entry",
                        target: "intro");
            }
            else
            {
                imageTag = CreatePoliticianImageTag(row.PoliticianKey, 15);
            }
            imageTag.AddTo(container);
            new Literal {
                Text = "&nbsp"
            }.AddTo(container);

            CreateAdminPoliticianAnchor(row, FormatPoliticianName(row, true, true),
                                        Empty)
            .AddTo(container);

            literalText = Empty;
            if (row.PartyKey != Empty)
            {
                literalText += " (" + row.PartyCode.SafeString() + ")";
            }
            literalText += " .. " + row.PoliticianKey;
            new Literal {
                Text = literalText
            }.AddTo(container);

            return(container);
        }
Ejemplo n.º 5
0
        protected static HtmlAnchor CreateAdminPoliticianAnchor(DataRow politician,
                                                                string anchorText, string target = "politician")
        {
            var href = SecurePoliticianPage.GetUpdateIntroPageUrl(politician.PoliticianKey());

            if (VotePage.IsPublicPage)
            {
                href = UrlManager.GetAdminUri(href).ToString();
            }
            var a = new HtmlAnchor
            {
                HRef      = href,
                Target    = target,
                Title     = "Edit Links, Picture, Bio & Reasons",
                InnerHtml = anchorText
            };

            return(a);
        }
Ejemplo n.º 6
0
        protected void ButtonEditPolitician_OnClick(object sender, EventArgs e)
        {
            var toEdit        = GetPoliticianKeyToEdit();
            var politicianKey = toEdit.Key;

            CandidateHtml.Controls.Clear();
            var isRunningMate = !IsNullOrWhiteSpace(MainCandidateIfRunningMate.Value);

            if (Politicians.GetStateCodeFromKey(politicianKey) != "DC")
            {
                AddOnEditElement.AddCssClasses("hidden");
            }

            switch (EditPoliticianReloading.Value)
            {
            case "reloading":
            {
                EditPoliticianReloading.Value = Empty;
                ControlEditPoliticianPartyKey.Items.Clear();
                VotePage.LoadPartiesDropdown(Politicians.GetStateCodeFromKey(politicianKey),
                                             ControlEditPoliticianPartyKey, Empty, VotePage.PartyCategories.None,
                                             VotePage.PartyCategories.StateParties, VotePage.PartyCategories.NationalParties,
                                             VotePage.PartyCategories.NonParties);
                _EditPoliticianDialogInfo.LoadControls();
                FeedbackEditPolitician.AddInfo("Politician information loaded.");
                var href = SecurePoliticianPage.GetUpdateIntroPageUrl(politicianKey);
                UpdateIntroLink.HRef             = href;
                UpdateIntroLinkProfessional.HRef = href + "#bio2-ALLBio333333";
            }
            break;

            case "":
            {
                // normal update
                _EditPoliticianDialogInfo.ClearValidationErrors();
                _EditPoliticianDialogInfo.Update(FeedbackEditPolitician);
                var partyCodeToSuppress = Empty;
                if (isRunningMate)
                {
                    partyCodeToSuppress =
                        Parties.GetPartyCode(
                            Politicians.GetPartyKey(MainCandidateIfRunningMate.Value));
                }
                var row = Politicians.GetCandidateData(SafeGetElectionKey(), politicianKey,
                                                       isRunningMate);
                // use current dynamic IsIncumbent
                row["IsIncumbent"] = toEdit.ShowAsIncumbent;
                CandidateHtml.Controls.Add(CreateCandidateEntry(row, Mode, partyCodeToSuppress,
                                                                !isRunningMate && ElectionsPoliticians.ElectionKeyOfficeKeyPoliticianKeyExists(
                                                                    SafeGetElectionKey(), SafeGetOfficeKey(), politicianKey)));
            }
            break;

            default:
                throw new VoteException(
                          $"Unknown reloading option: '{EditPoliticianReloading.Value}'");
            }

            NameOnBallots.InnerText = PageCache.GetTemporary().Politicians
                                      .GetPoliticianName(politicianKey);
            UpdateIntroPage.SetPartyNameAndLink(ControlEditPoliticianPartyKey.GetValue(),
                                                PartyName);
        }
Ejemplo n.º 7
0
        protected void ButtonAddNewCandidate_OnClick(object sender, EventArgs e)
        {
            bool.TryParse(AddCandidateValidateDuplicates.GetValue(), out var validateDuplicates);

            AddCandidateDuplicatesHtml.Controls.Clear();
            _AddNewCandidateSubTabInfo.ClearValidationErrors();
            AddCandidateNewId.SetValue(Empty);

            // No actual updating here, just validation and reformatting
            _AddNewCandidateSubTabInfo.Update(FeedbackAddNewCandidate, false);
            if (FeedbackAddNewCandidate.ValidationErrorCount > 0)
            {
                return;
            }

            var stateCode  = ControlAddNewCandidateStateCode.GetValue();
            var firstName  = ControlAddNewCandidateFName.GetValue();
            var middleName = ControlAddNewCandidateMName.GetValue();
            var nickname   = ControlAddNewCandidateNickname.GetValue();
            var lastName   = ControlAddNewCandidateLName.GetValue();
            var suffix     = ControlAddNewCandidateSuffix.GetValue();

            var formattedName =
                Politicians.FormatName(firstName, middleName, nickname, lastName, suffix);

            if (validateDuplicates)
            {
                var duplicatesHtml =
                    Politicians.GetCandidateList(lastName, null, stateCode, null, true);
                AddCandidateDuplicatesHtml.Controls.Add(duplicatesHtml);
                if (duplicatesHtml.Controls.Count > 0)
                {
                    // Set up the duplicates dialog
                    AddCandidateFormattedName.SetValue(formattedName);
                    AddCandidateStateName.SetValue(StateCache.GetStateName(stateCode));
                    FeedbackAddNewCandidate.PostValidationError(ControlAddNewCandidateLName,
                                                                "Potential duplicate politician");
                    return;
                }
            }

            var newPoliticianKey =
                Politicians.GetUniqueKey(stateCode, lastName, firstName, middleName, suffix);

            AddCandidateNewId.SetValue(newPoliticianKey);

            // If it's a primary, get the party key from the election
            var partyKey    = Empty; // mantis 508
            var electionKey = SafeGetElectionKey();

            if (Elections.IsPrimaryElection(electionKey))
            {
                partyKey = stateCode + Elections.GetNationalPartyCodeFromKey(electionKey);
            }

            Politicians.AddPolitician(newPoliticianKey, firstName, middleName, nickname, lastName,
                                      suffix, partyKey, SecurePage.CreateUniquePassword());

            LogDataChange.LogInsert(Politicians.TableName, VotePage.UserName,
                                    SecurePage.UserSecurityClass, DateTime.UtcNow, newPoliticianKey);

            ClearAddNewCandidate();

            FeedbackAddNewCandidate.AddInfo("Politician " + formattedName + " was added.");
            if (Mode == DataMode.AddPoliticians)
            {
                FeedbackAddNewCandidate.AddInfo(new HtmlAnchor
                {
                    InnerText = "Intro Page",
                    HRef      = UrlManager.GetIntroPageUri(newPoliticianKey).ToString(),
                    Target    = "Politician"
                }.RenderToString());
                FeedbackAddNewCandidate.AddInfo(new HtmlAnchor
                {
                    InnerText = "Politician Admin Page",
                    HRef      = SecurePoliticianPage.GetUpdateIntroPageUrl(newPoliticianKey),
                    Target    = "Politician"
                }.RenderToString());
            }
        }
Ejemplo n.º 8
0
            public static SetupAdDialogItem[] GetDialogInfo(ManagePoliticiansPanel control)
            {
                var setupAdInfo = new []
                {
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdType",
                        Description = "Ad Type (YouTube or Image)",
                        Validator   = @base =>
                        {
                            if (!ValidateRequired(@base))
                            {
                                return(false);
                            }
                            var politicianKey = control.AdSetupCandidate.Value;
                            if (IsNullOrWhiteSpace(Politicians.GetPublicWebAddress(politicianKey)))
                            {
                                var link = SecurePage.IsPoliticianUser
                  ? SecurePoliticianPage.GetPoliticianFolderPageUrl("updateintro")
                  : SecurePoliticianPage.GetUpdateIntroPageUrl(politicianKey);
                                {
                                    control.FeedbackSetupAd.PostValidationError(@base.DataControl,
                                                                                "An Image ad needs a link to navigate to when clicked." +
                                                                                $" <a href=\"{link}\" target=\"intro\">Please enter a link for" +
                                                                                " your web site or an equivalent page</b>, like your" +
                                                                                " Facebook page.</a>");
                                    return(false);
                                }
                            }

                            return(true);
                        }
                        //Validator = ValidateRequired
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdUrl",
                        Description = "Video or Channel URL",
                        Validator   = b =>
                        {
                            // only required for type "Y"
                            var adTypeItem = control._SetupAdDialogInfo.First(i => i.Column == "AdType");
                            return(adTypeItem.DataControl.GetValue() != "Y" ||
                                   ValidateYouTubeAddressRequired(b));
                        }
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdThumbnailUrl",
                        Description = "Video for Channel Thumbnail",
                        Validator   = ValidateYouTubeVideoAddressOptional
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdImageName",
                        Description = "Name of Ad Image File"
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column    = "AdImageChanged",
                        ConvertFn = ToBool
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdImageUpdated",
                        Description = "Ad Image",
                        ConvertFn   = ToBool
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdTimeStamp",
                        Description = "Ad Date for Sorting",
                        ConvertFn   = ToDateTime,
                        Validator   = ValidateDateOptional
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdEnabled",
                        Description = "Ad Enabled",
                        ConvertFn   = ToBool
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdSponsor",
                        Description = "Ad Sponsor",
                        Validator   = @base =>
                        {
                            // if there is a sponsor URL, there must be either an ad sponsor or the checkbox must be checked
                            var sponsorUrlItem = control._SetupAdDialogInfo.First(i => i.Column == "AdSponsorUrl");
                            if (!IsNullOrWhiteSpace(sponsorUrlItem.DataControl.GetValue()))
                            {
                                var checkboxItem = control._SetupAdDialogInfo.First(i => i.Column == "AdIsCandidateSponsored");
                                if (IsNullOrWhiteSpace(@base.DataControl.GetValue()) &&
                                    checkboxItem.DataControl.GetValue().Equals("false", StringComparison.OrdinalIgnoreCase))
                                {
                                    control.FeedbackSetupAd.PostValidationError(@base.DataControl,
                                                                                "Since you provided a Sponsor URL you need to either enter a" +
                                                                                " Ad Sponsor or check the 'Use candidate's campaigm as Ad Sponsor'" +
                                                                                " checkbox.");
                                    return(false);
                                }
                            }
                            return(true);
                        }
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdSponsorUrl",
                        Description = "Ad Sponsor URL"
                    },
                    new SetupAdDialogItem(control)
                    {
                        Column      = "AdIsCandidateSponsored",
                        Description = "Ad Is Candidate Sponsored",
                        ConvertFn   = ToBool
                    }
                };

                foreach (var item in setupAdInfo)
                {
                    item.InitializeItem(control);
                }

                InitializeGroup(control, GroupName);

                return(setupAdInfo);
            }
Ejemplo n.º 9
0
        private void SetupSampleAd(string electionKey, string officeKey, string politicianKey,
                                   string videoUrl = null)
        {
            SampleAd.Visible     = false;
            VideoWrapper.Visible = false;
            ImageWrapper.Visible = false;

            var adTypeItem = _SetupAdDialogInfo.First(i => i.Column == "AdType");

            switch (adTypeItem.DataControl.GetValue())
            {
            case "Y": // YouTube
                VideoWrapper.Visible = true;
                if (IsNullOrWhiteSpace(videoUrl))
                {
                    var urlItem = _SetupAdDialogInfo.First(i => i.Column == "AdUrl");
                    videoUrl = urlItem.DataControl.GetValue();
                }
                if (IsNullOrWhiteSpace(videoUrl))
                {
                    return;
                }
                string thumbId;
                if (videoUrl.IsValidYouTubeVideoUrl())
                {
                    thumbId = videoUrl.GetYouTubeVideoId();
                }
                else
                {
                    var thumbItem = _SetupAdDialogInfo.First(i => i.Column == "AdThumbnailUrl");
                    var thumbUrl  = thumbItem.DataControl.GetValue();
                    if (IsNullOrWhiteSpace(thumbUrl))
                    {
                        return;
                    }
                    thumbId = thumbUrl.GetYouTubeVideoId();
                }

                if (IsNullOrWhiteSpace(thumbId))
                {
                    return;
                }
                SampleThumb.Src = $"http://i.ytimg.com/vi/{thumbId}/hqdefault.jpg";
                break;

            case "I": // Image
                ImageWrapper.Visible = true;
                var website = Politicians.GetPublicWebAddress(politicianKey);
                //if (IsNullOrWhiteSpace(website)) return;
                //ImageLink.HRef = VotePage.NormalizeUrl(website);
                //AdImage.Src = UrlManager
                //  .GetSiteUri("adimage", $"{electionKey}.{officeKey}.{politicianKey}.{DateTime.UtcNow.Ticks}").ToString();
                if (IsNullOrWhiteSpace(website))
                {
                    ImageLink.Attributes.Remove("href");
                }
                else
                {
                    ImageLink.HRef = VotePage.NormalizeUrl(website);
                }
                AdImage.Src = UrlManager
                              .GetSiteUri("adimage", $"{electionKey}.{officeKey}.{politicianKey}.{DateTime.UtcNow.Ticks}").ToString();
                break;
            }

            var sponsor              = _SetupAdDialogInfo.First(i => i.Column == "AdSponsor").DataControl.GetValue();
            var sponsorUrl           = _SetupAdDialogInfo.First(i => i.Column == "AdSponsorUrl").DataControl.GetValue();
            var isCandidateSponsored = _SetupAdDialogInfo.First(i => i.Column == "AdIsCandidateSponsored").DataControl.GetValue() == "True";

            var paidMessage = new PlaceHolder();

            if (isCandidateSponsored)
            {
                var url = IsNullOrWhiteSpace(sponsorUrl)
          ? SecurePoliticianPage.GetPoliticianPublicPageUrl("intro", politicianKey)
          : VotePage.NormalizeUrl(sponsorUrl);
                new LiteralControl("Paid advertisement by ").AddTo(paidMessage);
                new HtmlBreak().AddTo(paidMessage);
                new HtmlAnchor
                {
                    HRef      = url,
                    Target    = "_blank",
                    InnerHtml = "candidate&rsquo;s campaign"
                }.AddTo(paidMessage);
            }
            else if (!IsNullOrWhiteSpace(sponsor))
            {
                if (IsNullOrWhiteSpace(sponsorUrl))
                {
                    new LiteralControl("Paid advertisement by ").AddTo(paidMessage);
                    new HtmlBreak().AddTo(paidMessage);
                    new LiteralControl($"{sponsor}").AddTo(paidMessage);
                }
                else
                {
                    new LiteralControl("Paid advertisement by ").AddTo(paidMessage);
                    new HtmlBreak().AddTo(paidMessage);
                    new HtmlAnchor
                    {
                        HRef      = VotePage.NormalizeUrl(sponsorUrl),
                        Target    = "_blank",
                        InnerText = sponsor
                    }.AddTo(paidMessage);
                }
            }
            else
            {
                new LiteralControl("Paid advertisement").AddTo(paidMessage);
            }

            SampleAd.Visible     = true;
            SampleName.InnerText = PageCache.GetTemporary().Politicians
                                   .GetPoliticianName(politicianKey);
            SampleProfile.Src =
                VotePage.GetPoliticianImageUrl(politicianKey, "Headshot100");
            PaidAdvertisement.Controls.Clear();
            PaidAdvertisement.Controls.Add(paidMessage);
            ComparePageLink.HRef = $"{UrlManager.GetCompareCandidatesPageUri(electionKey, officeKey)}" +
                                   $"&ad={politicianKey}";
        }