Ejemplo n.º 1
0
        /// <summary>
        /// Gets the range rules list from repeater controls.
        /// </summary>
        /// <param name="conditionalScaleRulesControlsRepeater">The conditional scale rules controls repeater.</param>
        /// <returns></returns>
        private static List <ConditionalScaleRangeRule> GetRangeRulesListFromRepeaterControls(Repeater conditionalScaleRulesControlsRepeater)
        {
            List <ConditionalScaleRangeRule> conditionalScaleRangeRuleList = new List <ConditionalScaleRangeRule>();
            int rangeIndex = 0;

            foreach (var repeaterItem in conditionalScaleRulesControlsRepeater.Items.OfType <RepeaterItem>())
            {
                HtmlGenericContainer conditionalScaleRangeRuleContainer = repeaterItem.FindControl("conditionalScaleRangeRuleContainer") as HtmlGenericContainer;
                var hfRangeGuid        = conditionalScaleRangeRuleContainer.FindControl("hfRangeGuid") as HiddenField;
                var labelTextBox       = conditionalScaleRangeRuleContainer.FindControl("labelTextBox") as TextBox;
                var highValueNumberBox = conditionalScaleRangeRuleContainer.FindControl("highValueNumberBox") as NumberBox;
                var colorPicker        = conditionalScaleRangeRuleContainer.FindControl("colorPicker") as ColorPicker;
                var lowValueNumberBox  = conditionalScaleRangeRuleContainer.FindControl("lowValueNumberBox") as NumberBox;
                conditionalScaleRangeRuleList.Add(new ConditionalScaleRangeRule
                {
                    RangeIndex = rangeIndex++,
                    Guid       = hfRangeGuid.Value.AsGuid(),
                    Label      = labelTextBox.Text,
                    Color      = colorPicker.Value,
                    HighValue  = highValueNumberBox.Text.AsDecimalOrNull(),
                    LowValue   = lowValueNumberBox.Text.AsDecimalOrNull()
                });
            }

            return(conditionalScaleRangeRuleList);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the custom filters.
        /// </summary>
        private void LoadCustomFilters()
        {
            var enabledModelIds = new List <int>();

            if (GetAttributeValue(AttributeKey.EnabledModels).IsNotNullOrWhiteSpace())
            {
                enabledModelIds = GetAttributeValue(AttributeKey.EnabledModels).Split(',').Select(int.Parse).ToList();
            }

            var entities          = EntityTypeCache.All();
            var indexableEntities = entities.Where(i => i.IsIndexingEnabled == true).ToList();

            // if select entities are configured further filter by them
            if (enabledModelIds.Count > 0)
            {
                indexableEntities = indexableEntities.Where(i => enabledModelIds.Contains(i.Id)).ToList();
            }

            foreach (var entity in indexableEntities)
            {
                var entityType = entity.GetEntityType();

                if (SupportsIndexFieldFiltering(entityType))
                {
                    var filterOptions = GetIndexFilterConfig(entityType);

                    RockCheckBoxList filterConfig = new RockCheckBoxList();
                    filterConfig.Label           = filterOptions.FilterLabel;
                    filterConfig.CssClass        = "js-entity-id-" + entity.Id.ToString();
                    filterConfig.CssClass       += " js-entity-filter-field";
                    filterConfig.RepeatDirection = RepeatDirection.Horizontal;
                    filterConfig.Attributes.Add("entity-id", entity.Id.ToString());
                    filterConfig.Attributes.Add("entity-filter-field", filterOptions.FilterField);
                    filterConfig.DataSource = filterOptions.FilterValues.Where(i => i != null);
                    filterConfig.DataBind();

                    // set any selected values from the query string
                    if (!string.IsNullOrWhiteSpace(PageParameter(filterOptions.FilterField)))
                    {
                        List <string> selectedValues = PageParameter(filterOptions.FilterField).Split(',').ToList();

                        foreach (ListItem item in filterConfig.Items)
                        {
                            if (selectedValues.Contains(item.Value))
                            {
                                item.Selected = true;
                            }
                        }
                    }

                    if (filterOptions.FilterValues.Count > 0)
                    {
                        HtmlGenericContainer filterWrapper = new HtmlGenericContainer("div", "col-md-6");
                        filterWrapper.Controls.Add(filterConfig);
                        phFilters.Controls.Add(filterWrapper);
                    }
                }
            }
        }
        /// <summary>
        /// Handles the ItemDataBound event of the rptGroupTypes control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterItemEventArgs"/> instance containing the event data.</param>
        protected void rptGroupTypes_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                var groupType = e.Item.DataItem as GroupType;

                var liGroupTypeItem = new HtmlGenericContainer("li", "rocktree-item rocktree-folder");
                liGroupTypeItem.ID = "liGroupTypeItem" + groupType.Id;
                e.Item.Controls.Add(liGroupTypeItem);
                AddGroupTypeControls(groupType, liGroupTypeItem);
            }
        }
        /// <summary>
        /// Adds the group type controls.
        /// </summary>
        /// <param name="groupType">Type of the group.</param>
        /// <param name="pnlGroupTypes">The PNL group types.</param>
        private void AddGroupTypeControls(GroupType groupType, HtmlGenericContainer liGroupTypeItem)
        {
            if (groupType.Groups.Any())
            {
                var cblGroupTypeGroups = new RockCheckBoxList {
                    ID = "cblGroupTypeGroups" + groupType.Id
                };

                cblGroupTypeGroups.Label = groupType.Name;
                cblGroupTypeGroups.Items.Clear();
                foreach (var group in groupType.Groups.OrderBy(a => a.Order).ThenBy(a => a.Name).Select(a => new { a.Id, a.Name }).ToList())
                {
                    cblGroupTypeGroups.Items.Add(new ListItem(group.Name, group.Id.ToString()));
                }

                liGroupTypeItem.Controls.Add(cblGroupTypeGroups);
            }
            else
            {
                if (groupType.ChildGroupTypes.Any())
                {
                    liGroupTypeItem.Controls.Add(new Label {
                        Text = groupType.Name, ID = "lbl" + groupType.Name
                    });
                }
            }

            if (groupType.ChildGroupTypes.Any())
            {
                var ulGroupTypeList = new HtmlGenericContainer("ul", "rocktree-children");

                liGroupTypeItem.Controls.Add(ulGroupTypeList);
                foreach (var childGroupType in groupType.ChildGroupTypes.OrderBy(a => a.Order).ThenBy(a => a.Name))
                {
                    var liChildGroupTypeItem = new HtmlGenericContainer("li", "rocktree-item rocktree-folder");
                    liChildGroupTypeItem.ID = "liGroupTypeItem" + groupType.Id;
                    ulGroupTypeList.Controls.Add(liChildGroupTypeItem);
                    AddGroupTypeControls(childGroupType, liChildGroupTypeItem);
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handles the ItemDataBound event of the ConditionalScaleRulesControlsRepeater control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="RepeaterItemEventArgs"/> instance containing the event data.</param>
        private void ConditionalScaleRulesControlsRepeater_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {
            var repeaterItem = e.Item;

            ConditionalScaleRangeRule conditionalScaleRangeRule = e.Item.DataItem as ConditionalScaleRangeRule;

            HtmlGenericContainer conditionalScaleRangeRuleContainer = repeaterItem.FindControl("conditionalScaleRangeRuleContainer") as HtmlGenericContainer;

            var hfRangeGuid        = conditionalScaleRangeRuleContainer.FindControl("hfRangeGuid") as HiddenField;
            var labelTextBox       = conditionalScaleRangeRuleContainer.FindControl("labelTextBox") as TextBox;
            var highValueNumberBox = conditionalScaleRangeRuleContainer.FindControl("highValueNumberBox") as NumberBox;
            var colorPicker        = conditionalScaleRangeRuleContainer.FindControl("colorPicker") as ColorPicker;
            var lowValueNumberBox  = conditionalScaleRangeRuleContainer.FindControl("lowValueNumberBox") as NumberBox;

            hfRangeGuid.Value = conditionalScaleRangeRule.Guid.ToString();

            labelTextBox.Text = conditionalScaleRangeRule.Label;

            // from http://stackoverflow.com/a/216705/1755417 (to trim trailing zeros)
            highValueNumberBox.Text = conditionalScaleRangeRule.HighValue?.ToString("G29");
            colorPicker.Text        = conditionalScaleRangeRule.Color;
            lowValueNumberBox.Text  = conditionalScaleRangeRule.LowValue?.ToString("G29");
        }
Ejemplo n.º 6
0
        private void BuildCategoryControl(Control parentControl, WorkflowNavigationCategory category)
        {
            var divPanel = new HtmlGenericContainer("div");

            divPanel.AddCssClass("panel panel-workflowitem");
            parentControl.Controls.Add(divPanel);

            var divPanelHeading = new HtmlGenericControl("div");

            divPanelHeading.AddCssClass("panel-heading");
            divPanel.Controls.Add(divPanelHeading);

            var headingA = new HtmlGenericControl("a");

            headingA.Attributes.Add("data-toggle", "collapse");
            headingA.Attributes.Add("data-parent", "#" + parentControl.ClientID);
            headingA.AddCssClass("collapsed clearfix");
            divPanelHeading.Controls.Add(headingA);

            var divHeadingTitle = new HtmlGenericControl("div");

            divHeadingTitle.AddCssClass("panel-title clearfix");
            headingA.Controls.Add(divHeadingTitle);

            var headingTitle = new HtmlGenericControl("h3");

            headingTitle.AddCssClass("pull-left");
            divHeadingTitle.Controls.Add(headingTitle);

            var panelNavigation = new HtmlGenericControl("i");

            panelNavigation.AddCssClass("fa panel-navigation pull-right");
            divHeadingTitle.Controls.Add(panelNavigation);

            if (!string.IsNullOrWhiteSpace(category.IconCssClass))
            {
                headingTitle.Controls.Add(new LiteralControl(string.Format("<i class='{0} fa-fw'></i> ", category.IconCssClass)));
            }
            headingTitle.Controls.Add(new LiteralControl(category.Name));

            var divCollapse = new HtmlGenericControl("div");

            divCollapse.ID = string.Format("collapse-category-", category.Id);
            divCollapse.AddCssClass("panel-collapse collapse");
            divPanel.Controls.Add(divCollapse);

            headingA.Attributes.Add("href", "#" + divCollapse.ClientID);

            if (category.WorkflowTypes.Any())
            {
                var ulGroup = new HtmlGenericControl("ul");
                ulGroup.AddCssClass("list-group");
                divCollapse.Controls.Add(ulGroup);

                foreach (var workflowType in category.WorkflowTypes)
                {
                    var li = new HtmlGenericControl("li");
                    li.AddCssClass("list-group-item clickable");
                    ulGroup.Controls.Add(li);

                    var qryParms = new Dictionary <string, string>();
                    qryParms.Add("WorkflowTypeId", workflowType.Id.ToString());

                    bool showLinkToEntry = workflowType.HasForms && workflowType.IsActive;

                    var aNew = new HtmlGenericControl(showLinkToEntry ? "a" : "span");
                    if (workflowType.HasForms)
                    {
                        aNew.Attributes.Add("href", LinkedPageUrl("EntryPage", qryParms));
                    }
                    li.Controls.Add(aNew);

                    if (!string.IsNullOrWhiteSpace(workflowType.IconCssClass))
                    {
                        aNew.Controls.Add(new LiteralControl(string.Format("<i class='{0} fa-fw'></i> ", workflowType.IconCssClass)));
                    }

                    aNew.Controls.Add(new LiteralControl(workflowType.Name));

                    if (workflowType.CanManage || workflowType.CanViewList || IsUserAuthorized(Rock.Security.Authorization.EDIT))
                    {
                        li.Controls.Add(new LiteralControl(" "));

                        var aManage = new HtmlGenericControl("a");
                        aManage.AddCssClass("pull-right");
                        aManage.Attributes.Add("href", LinkedPageUrl("ManagePage", qryParms));
                        var iManageIcon = new HtmlGenericControl("i");
                        aManage.Controls.Add(iManageIcon);
                        iManageIcon.AddCssClass("fa fa-list");
                        li.Controls.Add(aManage);
                    }
                }
            }

            if (category.ChildCategories.Any())
            {
                var divBody = new HtmlGenericControl("div");
                //divBody.AddCssClass( "panel-body" );
                divCollapse.Controls.Add(divBody);

                foreach (var childCategory in category.ChildCategories)
                {
                    BuildCategoryControl(divBody, childCategory);
                }
            }
        }
        private void ShowEdit(int savedGroupMemberId = 0)
        {
            phGroups.Controls.Clear();
            var                groups             = GetGroups();
            RockContext        rockContext        = new RockContext();
            GroupMemberService groupMemberService = new GroupMemberService(rockContext);

            foreach (var group in groups)
            {
                Panel pnlGroup = new Panel();
                phGroups.Controls.Add(pnlGroup);

                Literal ltGroup = new Literal();
                ltGroup.Text = string.Format("<h4>{0}</h4>", group.Name);
                pnlGroup.Controls.Add(ltGroup);

                var groupMembers = groupMemberService.GetByGroupIdAndPersonId(group.Id, Person.Id);
                var unusedRoles  = group.GroupType.Roles.Where(r => !groupMembers.Select(gm => gm.GroupRoleId).Contains(r.Id));

                if (unusedRoles.Any())
                {
                    Panel pnlButtonGroup = new Panel();
                    pnlButtonGroup.CssClass = "input-group";
                    pnlGroup.Controls.Add(pnlButtonGroup);

                    RockDropDownList ddlRole = new RockDropDownList();
                    ddlRole.DataSource     = unusedRoles;
                    ddlRole.DataTextField  = "Name";
                    ddlRole.DataValueField = "Id";
                    ddlRole.CssClass       = "form-control";
                    ddlRole.ID             = "ddl" + group.Id.ToString();
                    ddlRole.DataBind();
                    pnlButtonGroup.Controls.Add(ddlRole);

                    Panel pnlInputGroupButton = new Panel();
                    pnlInputGroupButton.CssClass = "input-group-btn";
                    pnlButtonGroup.Controls.Add(pnlInputGroupButton);

                    BootstrapButton btnAdd = new BootstrapButton();
                    btnAdd.Text     = "Add To Group";
                    btnAdd.CssClass = "btn btn-primary";
                    btnAdd.ID       = "Add" + group.Id.ToString();
                    btnAdd.Click   += (s, e) => { AddGroupMember(group, ddlRole); };
                    pnlInputGroupButton.Controls.Add(btnAdd);
                }

                foreach (var groupMember in groupMembers)
                {
                    Panel pnlWell = new Panel();
                    pnlWell.CssClass = "well";
                    phGroups.Controls.Add(pnlWell);

                    Literal ltRole = new Literal();
                    ltRole.Text = string.Format("<b><em>Group Role: {0}</em></b> ", groupMember.GroupRole.Name);
                    pnlWell.Controls.Add(ltRole);

                    BootstrapButton btnRemove = new BootstrapButton();
                    btnRemove.Text     = "Remove";
                    btnRemove.CssClass = "btn btn-danger btn-xs pull-right";
                    btnRemove.ID       = groupMember.Id.ToString();
                    btnRemove.Click   += (s, e) => { ConfirmDelete(groupMember.Id); };
                    pnlWell.Controls.Add(btnRemove);

                    HtmlGenericContainer hr = new HtmlGenericContainer("hr");
                    pnlWell.Controls.Add(hr);

                    groupMember.LoadAttributes();
                    var attributeList = groupMember.Attributes.Select(d => d.Value)
                                        .OrderBy(a => a.Order).ThenBy(a => a.Name).ToList();
                    foreach (var attribute in attributeList)
                    {
                        string attributeValue = groupMember.GetAttributeValue(attribute.Key);
                        attribute.AddControl(pnlWell.Controls, attributeValue, "", true, true);
                    }

                    RockTextBox tbNotes = new RockTextBox();
                    tbNotes.TextMode = TextBoxMode.MultiLine;
                    tbNotes.ID       = "Note" + groupMember.Id.ToString();
                    tbNotes.Label    = "Notes";
                    tbNotes.Text     = groupMember.Note;
                    pnlWell.Controls.Add(tbNotes);

                    if (savedGroupMemberId == groupMember.Id)
                    {
                        NotificationBox nbSavedNote = new NotificationBox();
                        nbSavedNote.Text = "Group member information saved";
                        nbSavedNote.NotificationBoxType = NotificationBoxType.Success;
                        pnlWell.Controls.Add(nbSavedNote);
                    }

                    BootstrapButton btnSave = new BootstrapButton();
                    btnSave.ID       = "save" + groupMember.Id.ToString();
                    btnSave.Text     = "Save";
                    btnSave.CssClass = "btn btn-primary btn-xs";
                    btnSave.Click   += (s, e) => { SaveGroupMember(rockContext, groupMember, pnlWell, attributeList, tbNotes); };
                    pnlWell.Controls.Add(btnSave);
                }
            }

            HtmlGenericContainer hrDone = new HtmlGenericContainer("hr");

            phGroups.Controls.Add(hrDone);

            BootstrapButton btnDone = new BootstrapButton();

            btnDone.Text   = "Done";
            btnDone.ID     = "btnDone";
            btnDone.Click += (s, e) =>
            {
                hfEditMode.Value = "0";
                ShowView();
            };
            phGroups.Controls.Add(btnDone);
        }
Ejemplo n.º 8
0
            /// <summary>
            /// When implemented by a class, defines the <see cref="T:System.Web.UI.Control" /> object that child controls and templates belong to. These child controls are in turn defined within an inline template.
            /// </summary>
            /// <param name="container">The <see cref="T:System.Web.UI.Control" /> object to contain the instances of controls from the inline template.</param>
            public void InstantiateIn(Control container)
            {
                HtmlGenericContainer conditionalScaleRangeRuleContainer = new HtmlGenericContainer {
                    ID = $"conditionalScaleRangeRuleContainer", CssClass = "row form-row"
                };

                var hfRangeGuid = new HiddenField {
                    ID = "hfRangeGuid"
                };

                conditionalScaleRangeRuleContainer.Controls.Add(hfRangeGuid);

                Panel pnlColumn1 = new Panel {
                    ID = "pnlColumn1", CssClass = "col-md-5"
                };
                var labelTextBox = new RockTextBox {
                    ID = "labelTextBox", Placeholder = "Label", CssClass = "margin-b-md", Required = true
                };

                pnlColumn1.Controls.Add(labelTextBox);
                labelTextBox.Init += (object sender, EventArgs e) =>
                {
                    var parentValidationGroup = (labelTextBox.FindFirstParentWhere(a => a is IHasValidationGroup) as IHasValidationGroup)?.ValidationGroup;
                    labelTextBox.ValidationGroup = parentValidationGroup;
                };
                var highValueNumberBox = new NumberBox {
                    ID = "highValueNumberBox", Placeholder = "High Value", CssClass = "margin-b-md"
                };

                pnlColumn1.Controls.Add(highValueNumberBox);
                conditionalScaleRangeRuleContainer.Controls.Add(pnlColumn1);

                Panel pnlColumn2 = new Panel {
                    ID = "pnlColumn2", CssClass = "col-md-5"
                };
                var colorPicker = new ColorPicker {
                    ID = "colorPicker", CssClass = "margin-b-md"
                };

                pnlColumn2.Controls.Add(colorPicker);
                var lowValueNumberBox = new NumberBox {
                    ID = "lowValueNumberBox", Placeholder = "Low Value", NumberType = ValidationDataType.Double
                };

                pnlColumn2.Controls.Add(lowValueNumberBox);
                conditionalScaleRangeRuleContainer.Controls.Add(pnlColumn2);

                Panel pnlColumn3 = new Panel {
                    ID = "pnlColumn3", CssClass = "col-md-2"
                };
                LinkButton btnDeleteRule = new LinkButton {
                    ID = "btnDeleteRule", CssClass = "btn btn-danger btn-sm", CausesValidation = false, Text = "<i class='fa fa-times'></i>"
                };

                btnDeleteRule.Click += BtnDeleteRule_Click;
                pnlColumn3.Controls.Add(btnDeleteRule);
                conditionalScaleRangeRuleContainer.Controls.Add(pnlColumn3);

                container.Controls.Add(conditionalScaleRangeRuleContainer);
                container.Controls.Add(new HtmlGenericControl("hr"));
            }
        /// <summary>
        /// Builds table cells for the Exception Detail table and adds them to the table
        /// </summary>
        /// <param name="detailSummaries">List of Excpetion Detial Summary objects</param>
        private void BuildExceptionDetailTable(List <ExceptionDetailSummary> detailSummaries)
        {
            StringBuilder script = new StringBuilder();

            foreach (var summary in detailSummaries)
            {
                string   exceptionPageUrl = string.Format("/page/{0}?ExceptionId={1}", CurrentPage.Id, summary.ExceptionId);
                TableRow detailRow        = new TableRow();

                detailRow.ID = string.Format("tdRowExceptionDetail_{0}", summary.ExceptionId);

                TableCell exceptionTypeCell = new TableCell();
                exceptionTypeCell.ID   = string.Format("tcExceptionType_{0}", summary.ExceptionId);
                exceptionTypeCell.Text = summary.ExceptionType;
                detailRow.Cells.Add(exceptionTypeCell);

                TableCell exceptionSourceCell = new TableCell();
                exceptionSourceCell.ID   = string.Format("tcExceptionSource_{0}", summary.ExceptionId);
                exceptionSourceCell.Text = summary.ExceptionSource;
                detailRow.Cells.Add(exceptionSourceCell);

                TableCell exceptionDescriptionCell = new TableCell();
                exceptionDescriptionCell.ID   = string.Format("tcExceptionDetail_{0}", summary.ExceptionId);
                exceptionDescriptionCell.Text = summary.ExceptionDescription;
                detailRow.Cells.Add(exceptionDescriptionCell);

                TableCell exceptionStackTraceToggleCell = new TableCell();
                exceptionStackTraceToggleCell.ID = string.Format("tcExceptionStackTraceToggle_{0}", summary.ExceptionId);

                LinkButton lbExceptionStackTrace = new LinkButton();
                lbExceptionStackTrace.ID = string.Format("lbExceptionStackTraceToggle_{0}", summary.ExceptionId);
                lbExceptionStackTrace.Attributes.Add("onClick", string.Format("toggleStackTrace({0});return false;", summary.ExceptionId));
                var iToggle = new HtmlGenericControl("i");
                iToggle.AddCssClass("icon-file-alt");
                lbExceptionStackTrace.Controls.Add(iToggle);

                var spanTitle = new HtmlGenericContainer("span");
                spanTitle.ID        = string.Format("spanExceptionStackTrace_{0}", summary.ExceptionId);
                spanTitle.InnerText = " Show Stack Trace";
                lbExceptionStackTrace.Controls.Add(spanTitle);


                lbExceptionStackTrace.AddCssClass("btn");
                exceptionStackTraceToggleCell.Controls.Add(lbExceptionStackTrace);

                exceptionStackTraceToggleCell.HorizontalAlign = HorizontalAlign.Center;
                detailRow.Cells.Add(exceptionStackTraceToggleCell);

                tblExceptionDetails.Rows.Add(detailRow);

                TableRow stackTraceRow = new TableRow();
                stackTraceRow.CssClass = "exceptionDetail-stackTrace-hide";
                stackTraceRow.ID       = string.Format("tdRowExceptionStackTrace_{0}", summary.ExceptionId);

                TableCell exceptionStackTraceCell = new TableCell();
                exceptionStackTraceCell.ID              = string.Format("tdExceptionStackTrace_{0}", summary.ExceptionId);
                exceptionStackTraceCell.ColumnSpan      = 4;
                exceptionStackTraceCell.Text            = summary.StackTrace;
                exceptionStackTraceCell.HorizontalAlign = HorizontalAlign.Left;

                stackTraceRow.Cells.Add(exceptionStackTraceCell);

                tblExceptionDetails.Rows.Add(stackTraceRow);

                script.Append("$(\"[id*=" + exceptionSourceCell.ID + "]\").click(function () { redirectToPage(\"" + exceptionPageUrl + "\"); });");
                script.Append("$(\"[id*=" + exceptionSourceCell.ID + "]\").click(function () { redirectToPage(\"" + exceptionPageUrl + "\"); });");
                script.Append("$(\"[id*=" + exceptionDescriptionCell.ID + "]\").click(function () { redirectToPage(\"" + exceptionPageUrl + "\"); });");
                script.Append("$(\"[id*=" + exceptionStackTraceCell.ID + "]\").click(function () { redirectToPage(\"" + exceptionPageUrl + "\"); });");
            }

            if (!String.IsNullOrWhiteSpace(script.ToString()))
            {
                ScriptManager.RegisterStartupScript(upExcpetionDetail, upExcpetionDetail.GetType(), "ExceptionRedirects" + DateTime.Now.Ticks, script.ToString(), true);
            }
        }
Ejemplo n.º 10
0
        private void ShowWidgityTypes()
        {
            var widgityTypes = WidgityTypeCache.All()
                               .Where(wt => wt.EntityTypes.Select(e => e.Id).Contains(EntityTypeId)).ToList();

            if (!widgityTypes.Any())
            {
                NotificationBox notification = new NotificationBox
                {
                    NotificationBoxType = NotificationBoxType.Warning,
                    Text = "There are no widgity types for this entity type: " + EntityTypeCache.Get(EntityTypeId)?.FriendlyName
                };
                pnlMenu.Controls.Add(notification);
                return;
            }

            var categories = widgityTypes
                             .Where(wt => wt.Category != null)
                             .Select(wt => wt.Category)
                             .DistinctBy(c => c.Id)
                             .ToList();

            foreach (var category in categories)
            {
                PanelWidget panelWidget = new PanelWidget
                {
                    ID    = this.ID + "_pwCategory_" + category.Id.ToString(),
                    Title = category.Name
                };
                pnlMenu.Controls.Add(panelWidget);

                var dragContainer = new Panel
                {
                    ID       = this.ID + "_pnlWidgityContainer_" + category.Id.ToString(),
                    CssClass = "widgitySource"
                };
                panelWidget.Controls.Add(dragContainer);

                var categoryTypes = widgityTypes.Where(wt => wt.CategoryId == category.Id).ToList();

                foreach (var widgityType in categoryTypes)
                {
                    HtmlGenericContainer item = new HtmlGenericContainer("div");
                    item.InnerHtml = string.Format("<i class='{0}'></i><br />{1}",
                                                   widgityType.Icon,
                                                   widgityType.Name);
                    item.Attributes.Add("data-component-id", widgityType.Id.ToString());
                    item.CssClass = "btn btn-default btn-block";
                    dragContainer.Controls.Add(item);
                }
            }

            var noCategoryTypes = widgityTypes.Where(wt => wt.Category == null).ToList();

            if (noCategoryTypes.Any())
            {
                var dragContainerOther = new Panel
                {
                    ID       = this.ID + "_pnlWidgityContainer_other",
                    CssClass = "widgitySource"
                };

                if (categories.Any())
                {
                    PanelWidget panelWidgetOther = new PanelWidget
                    {
                        ID    = this.ID + "_pwCategory_Other",
                        Title = "Other"
                    };
                    pnlMenu.Controls.Add(panelWidgetOther);
                    panelWidgetOther.Controls.Add(dragContainerOther);
                }
                else
                {
                    pnlMenu.Controls.Add(dragContainerOther);
                }

                foreach (var widgityType in noCategoryTypes)
                {
                    HtmlGenericContainer item = new HtmlGenericContainer("div")
                    {
                        InnerHtml = string.Format("<i class='{0}'></i><br />{1}",
                                                  widgityType.Icon,
                                                  widgityType.Name)
                    };
                    item.Attributes.Add("data-component-id", widgityType.Id.ToString());
                    dragContainerOther.Controls.Add(item);
                }
            }

            if (ShowPublishButtons)
            {
                HtmlGenericContainer hr = new HtmlGenericContainer("hr");
                pnlMenu.Controls.Add(hr);

                BootstrapButton btnSave = new BootstrapButton
                {
                    CssClass        = "btn btn-primary",
                    Text            = "Publish",
                    ID              = this.ID + "_btnSave",
                    ValidationGroup = this.ID + "ValidationGroup"
                };
                pnlMenu.Controls.Add(btnSave);
                btnSave.Click += BtnSave_Click;

                LinkButton btnCancel = new LinkButton
                {
                    ID       = this.ID + "_btnCancel",
                    Text     = "Cancel",
                    CssClass = "btn btn-link"
                };
                pnlMenu.Controls.Add(btnCancel);
                btnCancel.Click += BtnCancel_Click;
            }
        }
Ejemplo n.º 11
0
        private void ShowWidigtyEdit(bool setValues)
        {
            var widgityGuid = CurrentEditWidgity.Value;
            var widgity     = Widgities.Where(w => w.Guid == widgityGuid).FirstOrDefault();
            var widgityType = WidgityTypeCache.Get(widgity.WidgityTypeId);

            Literal ltName = new Literal
            {
                Text = string.Format("<h3>{0}</h3>", widgityType.Name)
            };

            pnlMenu.Controls.Add(ltName);

            phAttributesEdit = new PlaceHolder
            {
                ID = this.ID + "_phAttributesEdit"
            };
            pnlMenu.Controls.Add(phAttributesEdit);
            Rock.Attribute.Helper.AddEditControls(widgity, phAttributesEdit, setValues, this.ID + "ValidationGroup");

            if (widgityType.HasItems)
            {
                BuildWidigityItemAttibutes(widgity, setValues);
            }

            HtmlGenericContainer hr = new HtmlGenericContainer("hr");

            pnlMenu.Controls.Add(hr);

            BootstrapButton btnEditSave = new BootstrapButton
            {
                CssClass        = "btn btn-primary",
                Text            = "Save",
                ID              = this.ID + "_btnEditSave",
                ValidationGroup = this.ID + "ValidationGroup"
            };

            pnlMenu.Controls.Add(btnEditSave);
            btnEditSave.Click += BtnEditSave_Click;

            LinkButton btnEditCancel = new LinkButton
            {
                ID               = this.ID + "_btnEditCancel",
                Text             = "Cancel",
                CssClass         = "btn btn-link",
                CausesValidation = false
            };

            pnlMenu.Controls.Add(btnEditCancel);
            btnEditCancel.Click += BtnEditCancel_Click;

            LinkButton btnDeleteWidgity = new LinkButton
            {
                ID               = this.ID + "_btnDeleteWidgity",
                Text             = "Delete",
                CssClass         = "btn btn-delete pull-right",
                CausesValidation = false
            };

            pnlMenu.Controls.Add(btnDeleteWidgity);
            btnDeleteWidgity.Click += BtnDeleteWidgity_Click;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Creates the table controls.
        /// </summary>
        /// <param name="batchId">The batch identifier.</param>
        private void CreateTableControls(int?batchId)
        {
            RockContext rockContext = new RockContext();

            nbSaveSuccess.Visible = false;
            btnSave.Visible       = false;

            if (_transactionEntityType != null)
            {
                lEntityHeaderText.Text = _transactionEntityType.FriendlyName;
            }

            if (batchId.HasValue)
            {
                var financialTransactionDetailQuery = new FinancialTransactionDetailService(rockContext).Queryable();

                var financialTransactionDetailList = financialTransactionDetailQuery.Where(a => a.Transaction.BatchId == batchId.Value).OrderByDescending(a => a.Transaction.TransactionDateTime).ToList();
                phTableRows.Controls.Clear();
                btnSave.Visible = financialTransactionDetailList.Any();
                foreach (var financialTransactionDetail in financialTransactionDetailList)
                {
                    var tr = new HtmlGenericContainer("tr");
                    tr.Controls.Add(new LiteralControl {
                        Text = string.Format("<td>{0}</td>", financialTransactionDetail.Transaction.AuthorizedPersonAlias)
                    });
                    tr.Controls.Add(new LiteralControl {
                        Text = string.Format("<td>{0}</td>", financialTransactionDetail.Amount.FormatAsCurrency())
                    });
                    tr.Controls.Add(new LiteralControl {
                        Text = string.Format("<td>{0}</td>", financialTransactionDetail.Account)
                    });
                    tr.Controls.Add(new LiteralControl
                    {
                        ID   = "lTransactionType_" + financialTransactionDetail.Id.ToString(),
                        Text = string.Format("<td>{0}</td>", financialTransactionDetail.Transaction.TransactionTypeValue)
                    });

                    var tdEntityControls = new HtmlGenericContainer("td")
                    {
                        ID = "pnlEntityControls_" + financialTransactionDetail.Id.ToString()
                    };
                    tr.Controls.Add(tdEntityControls);

                    if (_transactionEntityType != null)
                    {
                        if (_transactionEntityType.Id == EntityTypeCache.GetId <GroupMember>())
                        {
                            var ddlGroup = new RockDropDownList {
                                ID = "ddlGroup_" + financialTransactionDetail.Id.ToString()
                            };
                            ddlGroup.Label                 = "Group";
                            ddlGroup.AutoPostBack          = true;
                            ddlGroup.SelectedIndexChanged += ddlGroup_SelectedIndexChanged;
                            tdEntityControls.Controls.Add(ddlGroup);
                            var ddlGroupMember = new RockDropDownList {
                                ID = "ddlGroupMember_" + financialTransactionDetail.Id.ToString(), Visible = false
                            };
                            ddlGroupMember.Label = "Group Member";
                            tdEntityControls.Controls.Add(ddlGroupMember);
                        }
                        else if (_transactionEntityType.Id == EntityTypeCache.GetId <Group>())
                        {
                            var ddlGroup = new RockDropDownList {
                                ID = "ddlGroup_" + financialTransactionDetail.Id.ToString()
                            };
                            ddlGroup.AutoPostBack          = true;
                            ddlGroup.SelectedIndexChanged += ddlGroup_SelectedIndexChanged;
                            tdEntityControls.Controls.Add(ddlGroup);
                        }
                        else if (_transactionEntityType.Id == EntityTypeCache.GetId <DefinedValue>())
                        {
                            var ddlDefinedValue = new DefinedValuePicker {
                                ID = "ddlDefinedValue_" + financialTransactionDetail.Id.ToString()
                            };
                            tdEntityControls.Controls.Add(ddlDefinedValue);
                        }
                        else if (_transactionEntityType.SingleValueFieldType != null)
                        {
                            var entityPicker = _transactionEntityType.SingleValueFieldType.Field.EditControl(new Dictionary <string, Rock.Field.ConfigurationValue>(), "entityPicker_" + financialTransactionDetail.Id.ToString());
                            tdEntityControls.Controls.Add(entityPicker);
                        }
                    }

                    phTableRows.Controls.Add(tr);

                    pnlTransactions.Visible = true;
                }
            }
            else
            {
                pnlTransactions.Visible = false;
            }
        }
        /// <summary>
        /// Sets the filters.
        /// </summary>
        private void SetFilters(bool setValues)
        {
            using (var rockContext = new RockContext())
            {
                string sessionKey       = string.Format("ConnectionSearch_{0}", this.BlockId);
                var    searchSelections = Session[sessionKey] as Dictionary <string, string>;
                setValues = setValues && searchSelections != null;

                var connectionType = new ConnectionTypeService(rockContext).Get(GetAttributeValue(AttributeKey.ConnectionTypeId).AsInteger());

                if (!GetAttributeValue(AttributeKey.DisplayNameFilter).AsBoolean())
                {
                    tbSearchName.Visible = false;
                }

                if (GetAttributeValue(AttributeKey.DisplayCampusFilter).AsBoolean())
                {
                    cblCampus.Visible    = true;
                    cblCampus.DataSource = CampusCache.All(GetAttributeValue(AttributeKey.DisplayInactiveCampuses).AsBoolean());
                    cblCampus.DataBind();
                }
                else
                {
                    cblCampus.Visible = false;
                }

                if (setValues)
                {
                    if (searchSelections.ContainsKey("tbSearchName"))
                    {
                        tbSearchName.Text = searchSelections["tbSearchName"];
                    }
                    if (searchSelections.ContainsKey("cblCampus"))
                    {
                        var selectedItems = searchSelections["cblCampus"].SplitDelimitedValues().AsIntegerList();
                        cblCampus.SetValues(selectedItems);
                    }
                }
                else if (GetAttributeValue(AttributeKey.EnableCampusContext).AsBoolean())
                {
                    var campusEntityType = EntityTypeCache.Get("Rock.Model.Campus");
                    var contextCampus    = RockPage.GetCurrentContext(campusEntityType) as Campus;

                    if (contextCampus != null)
                    {
                        cblCampus.SetValue(contextCampus.Id.ToString());
                    }
                }

                if (GetAttributeValue(AttributeKey.DisplayAttributeFilters).AsBoolean())
                {
                    // Parse the attribute filters
                    AvailableAttributes = new List <AttributeCache>();
                    if (connectionType != null)
                    {
                        int entityTypeId = new ConnectionOpportunity().TypeId;
                        foreach (var attributeModel in new AttributeService(new RockContext()).Queryable()
                                 .Where(a =>
                                        a.EntityTypeId == entityTypeId &&
                                        a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
                                        a.EntityTypeQualifierValue.Equals(connectionType.Id.ToString()) &&
                                        a.AllowSearch == true)
                                 .OrderBy(a => a.Order)
                                 .ThenBy(a => a.Name))
                        {
                            AvailableAttributes.Add(AttributeCache.Get(attributeModel));
                        }
                    }

                    // Clear the filter controls
                    phAttributeFilters.Controls.Clear();

                    if (AvailableAttributes != null)
                    {
                        foreach (var attribute in AvailableAttributes)
                        {
                            string controlId = "filter_" + attribute.Id.ToString();
                            var    control   = attribute.FieldType.Field.FilterControl(attribute.QualifierValues, controlId, false, Rock.Reporting.FilterMode.SimpleFilter);
                            if (control != null)
                            {
                                if (control is IRockControl)
                                {
                                    var rockControl = ( IRockControl )control;
                                    rockControl.Label = attribute.Name;
                                    rockControl.Help  = attribute.Description;
                                    phAttributeFilters.Controls.Add(control);
                                }
                                else
                                {
                                    var wrapper = new RockControlWrapper();
                                    wrapper.ID    = control.ID + "_wrapper";
                                    wrapper.Label = attribute.Name;
                                    wrapper.Controls.Add(control);
                                    phAttributeFilters.Controls.Add(wrapper);
                                }

                                if (setValues && searchSelections.ContainsKey(controlId))
                                {
                                    var values = searchSelections[controlId].FromJsonOrNull <List <string> >();
                                    attribute.FieldType.Field.SetFilterValues(control, attribute.QualifierValues, values);
                                }
                            }
                        }
                    }
                }
                else
                {
                    phAttributeFilters.Visible = false;
                }

                if (connectionType != null)
                {
                    int entityTypeId    = new ConnectionOpportunity().TypeId;
                    var attributeOneKey = GetAttributeValue(AttributeKey.AttributeOneKey);
                    var attributeTwoKey = GetAttributeValue(AttributeKey.AttributeTwoKey);

                    if (!string.IsNullOrWhiteSpace(attributeOneKey))
                    {
                        if (!string.IsNullOrWhiteSpace(attributeTwoKey))
                        {
                            pnlAttributeOne.CssClass = "col-sm-6";
                        }
                        else
                        {
                            pnlAttributeOne.CssClass = "col-sm-12";
                        }

                        AttributeOne = AttributeCache.Get(new AttributeService(new RockContext()).Queryable()
                                                          .FirstOrDefault(a =>
                                                                          a.EntityTypeId == entityTypeId &&
                                                                          a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                                          a.EntityTypeQualifierValue.Equals(connectionType.Id.ToString()) &&
                                                                          a.Key == attributeOneKey));
                    }

                    if (!string.IsNullOrWhiteSpace(attributeTwoKey))
                    {
                        if (!string.IsNullOrWhiteSpace(attributeOneKey))
                        {
                            pnlAttributeTwo.CssClass = "col-sm-6";
                        }
                        else
                        {
                            pnlAttributeTwo.CssClass = "col-sm-12";
                        }

                        AttributeTwo = AttributeCache.Get(new AttributeService(new RockContext()).Queryable()
                                                          .FirstOrDefault(a =>
                                                                          a.EntityTypeId == entityTypeId &&
                                                                          a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                                          a.EntityTypeQualifierValue.Equals(connectionType.Id.ToString()) &&
                                                                          a.Key == attributeTwoKey));
                    }
                }

                if (AttributeOne != null)
                {
                    phAttributeOne.Controls.Clear();
                    AttributeOne.AddControl(phAttributeOne.Controls, string.Empty, string.Empty, true, true, false);
                    var control = phAttributeOne.Controls[0] as DropDownList;
                    if (control != null)
                    {
                        control.EnableViewState       = true;
                        control.AutoPostBack          = true;
                        control.SelectedIndexChanged += new EventHandler(ddlAttributeOne_SelectedIndexChanged);
                    }
                    else
                    {
                        var          theseControls = phAttributeOne.Controls[0] as DropDownList;
                        DropDownList ddl           = new DropDownList();
                        string[]     theseValues   = AttributeOne.QualifierValues.Values.ElementAt(0).Value.Split(',');
                        if (theseValues.Count() == 1 && theseValues[0] == "rb")
                        {
                            theseValues = AttributeOne.QualifierValues.Values.ElementAt(1).Value.Split(',');
                        }
                        foreach (string nameValue in theseValues)
                        {
                            string[] nameAndValue = nameValue.Split(new char[] { '^' });

                            if (nameAndValue.Length == 2)
                            {
                                ddl.Items.Add(new ListItem(nameAndValue[1].Trim(), nameAndValue[0].Trim()));
                            }
                        }

                        ddl.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                        ddl.SelectedIndex = 0;
                        ddl.CssClass      = "form-control";
                        var attributeOneLabel = new HtmlGenericContainer("label");
                        attributeOneLabel.InnerHtml = AttributeOne.Name;
                        attributeOneLabel.CssClass  = "control-label";

                        phAttributeOne.Controls.Clear();
                        phAttributeOne.Controls.Add(new Literal()
                        {
                            Text = "<div class='form-group rock-drop-down-list'>"
                        });
                        phAttributeOne.Controls.Add(attributeOneLabel);
                        phAttributeOne.Controls.Add(ddl);
                        phAttributeOne.Controls.Add(new Literal()
                        {
                            Text = "</div>"
                        });

                        var newDdl = phAttributeOne.Controls[2] as DropDownList;

                        newDdl.EnableViewState       = true;
                        newDdl.AutoPostBack          = true;
                        newDdl.SelectedIndexChanged += new EventHandler(ddlAttributeOne_SelectedIndexChanged);
                    }
                }

                if (AttributeTwo != null)
                {
                    phAttributeTwo.Controls.Clear();
                    AttributeTwo.AddControl(phAttributeTwo.Controls, string.Empty, string.Empty, true, true, false);
                    var control = phAttributeTwo.Controls[0] as DropDownList;
                    if (control != null)
                    {
                        control.EnableViewState       = true;
                        control.AutoPostBack          = true;
                        control.SelectedIndexChanged += new EventHandler(ddlAttributeTwo_SelectedIndexChanged);
                    }
                    else
                    {
                        var          theseControls = phAttributeTwo.Controls[0] as DropDownList;
                        DropDownList ddl           = new DropDownList();
                        string[]     theseValues   = AttributeTwo.QualifierValues.Values.ElementAt(0).Value.Split(',');
                        if (theseValues.Count() == 1 && theseValues[0] == "rb")
                        {
                            theseValues = AttributeTwo.QualifierValues.Values.ElementAt(1).Value.Split(',');
                        }

                        foreach (string nameValue in theseValues)
                        {
                            string[] nameAndValue = nameValue.Split(new char[] { '^' });

                            if (nameAndValue.Length == 2)
                            {
                                ddl.Items.Add(new ListItem(nameAndValue[1].Trim(), nameAndValue[0].Trim()));
                            }
                        }

                        ddl.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                        ddl.SelectedIndex = 0;
                        ddl.CssClass      = "form-control";
                        var attributeTwoLabel = new HtmlGenericContainer("label");
                        attributeTwoLabel.InnerHtml = AttributeTwo.Name;
                        attributeTwoLabel.CssClass  = "control-label";

                        phAttributeTwo.Controls.Clear();
                        phAttributeTwo.Controls.Add(new Literal()
                        {
                            Text = "<div class='form-group rock-drop-down-list'>"
                        });
                        phAttributeTwo.Controls.Add(attributeTwoLabel);
                        phAttributeTwo.Controls.Add(ddl);
                        phAttributeTwo.Controls.Add(new Literal()
                        {
                            Text = "</div>"
                        });

                        var newDdl = phAttributeTwo.Controls[2] as DropDownList;

                        newDdl.EnableViewState       = true;
                        newDdl.AutoPostBack          = true;
                        newDdl.SelectedIndexChanged += new EventHandler(ddlAttributeTwo_SelectedIndexChanged);
                    }
                }
            }
        }
        /// <summary>
        /// Creates the table controls.
        /// </summary>
        private void BindHtmlGrid()
        {
            _financialTransactionDetailList = null;
            RockContext rockContext = new RockContext();

            List <DataControlField> tableColumns = new List <DataControlField>();

            tableColumns.Add(new RockLiteralField {
                ID = "lPerson", HeaderText = "Person"
            });
            tableColumns.Add(new RockLiteralField {
                ID = "lTransactionInfo", HeaderText = "Transaction Info"
            });
            tableColumns.Add(new RockLiteralField {
                ID = "lCheckImage", HeaderText = "Check Image"
            });
            tableColumns.Add(new RockLiteralField {
                ID = "lMatchedRegistration", HeaderText = "Matched Registration"
            });
            tableColumns.Add(new RockLiteralField {
                ID = "lButton"
            });

            StringBuilder headers = new StringBuilder();

            foreach (var tableColumn in tableColumns)
            {
                if (tableColumn.HeaderStyle.CssClass.IsNotNullOrWhiteSpace())
                {
                    headers.AppendFormat("<th class='{0}'>{1}</th>", tableColumn.HeaderStyle.CssClass, tableColumn.HeaderText);
                }
                else
                {
                    headers.AppendFormat("<th>{0}</th>", tableColumn.HeaderText);
                }
            }

            lHeaderHtml.Text = headers.ToString();
            var registrationEntityTypeId = EntityTypeCache.GetId <Registration>();

            if (BatchId.HasValue && RegistrationInstanceId.HasValue)
            {
                nbErrorMessage.Visible = false;
                try
                {
                    var financialTransactionDetailQuery = new FinancialTransactionDetailService(rockContext).Queryable()
                                                          .Include(a => a.Transaction)
                                                          .Include(a => a.Transaction.AuthorizedPersonAlias.Person)
                                                          .Where(a => a.Transaction.BatchId == BatchId.Value && (!a.EntityTypeId.HasValue || a.EntityTypeId == registrationEntityTypeId))
                                                          .OrderByDescending(a => a.Transaction.TransactionDateTime);

                    _financialTransactionDetailList = financialTransactionDetailQuery.Take(1000).ToList();
                }
                catch (Exception ex)
                {
                    ExceptionLogService.LogException(ex);
                    var sqlTimeoutException = ReportingHelper.FindSqlTimeoutException(ex);

                    if (sqlTimeoutException != null)
                    {
                        nbErrorMessage.NotificationBoxType = NotificationBoxType.Warning;
                        nbErrorMessage.Text = "This report did not complete in a timely manner. You can try again or adjust the timeout setting of this block.";
                    }
                    else
                    {
                        nbErrorMessage.Text = "There was a problem with one of the filters for this report's dataview.";
                        nbErrorMessage.NotificationBoxType = NotificationBoxType.Danger;
                        nbErrorMessage.Details             = ex.Message;
                        nbErrorMessage.Visible             = true;
                        return;
                    }
                }

                phTableRows.Controls.Clear();

                int rowCount = 0;
                foreach (var financialTransactionDetail in _financialTransactionDetailList)
                {
                    rowCount += 1;
                    var tr = new HtmlGenericContainer("tr");
                    tr.ID = "tr_" + rowCount;
                    foreach (var tableColumn in tableColumns)
                    {
                        var literalControl = new LiteralControl();
                        if (tableColumn is RockLiteralField)
                        {
                            tr.Controls.Add(literalControl);
                            var literalTableColumn = tableColumn as RockLiteralField;
                            if (literalTableColumn.ID == "lPerson")
                            {
                                literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Transaction.AuthorizedPersonAlias);
                            }
                            else if (literalTableColumn.ID == "lTransactionInfo")
                            {
                                literalControl.Text = string.Format("<td>{0}<br/>{1}</td>", financialTransactionDetail.Amount.FormatAsCurrency(), financialTransactionDetail.Account.ToString());
                            }
                            else if (literalTableColumn.ID == "lCheckImage")
                            {
                                var primaryImage = financialTransactionDetail.Transaction.Images
                                                   .OrderBy(i => i.Order)
                                                   .FirstOrDefault();
                                string imageTag = string.Empty;
                                if (primaryImage != null)
                                {
                                    var imageUrl = string.Format("~/GetImage.ashx?id={0}", primaryImage.BinaryFileId);
                                    imageTag = string.Format("<div class='photo transaction-image' style='max-width: 400px;'><a href='{0}'><img src='{0}'/></a></div>", ResolveRockUrl(imageUrl));
                                }

                                literalControl.Text = string.Format("<td>{0}</td>", imageTag);
                            }
                            else if (literalTableColumn.ID == "lTransactionType")
                            {
                                literalControl.ID   = "lTransactionType_" + financialTransactionDetail.Id.ToString();
                                literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Transaction.TransactionTypeValue);
                            }
                            else if (literalTableColumn.ID == "lMatchedRegistration")
                            {
                                if (financialTransactionDetail.EntityTypeId == registrationEntityTypeId && financialTransactionDetail.EntityId.HasValue)
                                {
                                    literalControl.ID   = "lMatchedRegistration_" + financialTransactionDetail.Id.ToString();
                                    literalControl.Text = string.Format("<td></td>");
                                }
                                else
                                {
                                    var tdEntityControls = new HtmlGenericContainer("td")
                                    {
                                        ID = "lMatchedRegistration_" + financialTransactionDetail.Id.ToString()
                                    };
                                    tr.Controls.Add(tdEntityControls);
                                    var ddlRegistration = new RockDropDownList {
                                        ID = "ddlRegistration_" + financialTransactionDetail.Id.ToString(), EnhanceForLongLists = true
                                    };
                                    ddlRegistration.Label                 = "Registration";
                                    ddlRegistration.AutoPostBack          = true;
                                    ddlRegistration.SelectedIndexChanged += ddlRegistration_SelectedIndexChanged;
                                    tdEntityControls.Controls.Add(ddlRegistration);
                                }
                            }
                            else if (literalTableColumn.ID == "lButton")
                            {
                                var tdEntityControls = new HtmlGenericContainer("td")
                                {
                                    ID = "pnlBtnControls_" + financialTransactionDetail.Id.ToString()
                                };
                                tr.Controls.Add(tdEntityControls);
                                var lbDelete = new LinkButton {
                                    ID = "lbDelete_" + financialTransactionDetail.Id.ToString()
                                };
                                lbDelete.CausesValidation = false;
                                lbDelete.Click           += lbDelete_Click;
                                HtmlGenericControl buttonIcon = new HtmlGenericControl("i");
                                buttonIcon.Attributes.Add("class", "fa fa-close");
                                lbDelete.Controls.Add(buttonIcon);
                                tdEntityControls.Controls.Add(lbDelete);
                                lbDelete.Visible = financialTransactionDetail.EntityTypeId == registrationEntityTypeId && financialTransactionDetail.EntityId.HasValue;
                            }
                        }
                    }

                    phTableRows.Controls.Add(tr);

                    pnlTransactions.Visible = true;
                }
            }
            else
            {
                pnlTransactions.Visible = false;
            }
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Sets the filters.
        /// </summary>
        private void SetFilters(bool setValues)
        {
            using (var rockContext = new RockContext())
            {
                string sessionKey       = string.Format("ConnectionSearch_{0}", this.BlockId);
                var    searchSelections = Session[sessionKey] as Dictionary <string, string>;
                setValues = setValues && searchSelections != null;

                var connectionType = new ConnectionTypeService(rockContext).Get(GetAttributeValue("ConnectionTypeId").AsInteger());

                if (connectionType != null)
                {
                    int entityTypeId    = new ConnectionOpportunity().TypeId;
                    var attributeOneKey = GetAttributeValue("AttributeOneKey");
                    var attributeTwoKey = GetAttributeValue("AttributeTwoKey");

                    if (!string.IsNullOrWhiteSpace(attributeOneKey))
                    {
                        if (!string.IsNullOrWhiteSpace(attributeTwoKey))
                        {
                            pnlAttributeOne.CssClass = "col-sm-6";
                        }
                        else
                        {
                            pnlAttributeOne.CssClass = "col-sm-12";
                        }

                        AttributeOne = AttributeCache.Get(new AttributeService(new RockContext()).Queryable()
                                                          .FirstOrDefault(a =>
                                                                          a.EntityTypeId == entityTypeId &&
                                                                          a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                                          a.EntityTypeQualifierValue.Equals(connectionType.Id.ToString()) &&
                                                                          a.Key == attributeOneKey));
                    }

                    if (!string.IsNullOrWhiteSpace(attributeTwoKey))
                    {
                        if (!string.IsNullOrWhiteSpace(attributeOneKey))
                        {
                            pnlAttributeTwo.CssClass = "col-sm-6";
                        }
                        else
                        {
                            pnlAttributeTwo.CssClass = "col-sm-12";
                        }

                        AttributeTwo = AttributeCache.Get(new AttributeService(new RockContext()).Queryable()
                                                          .FirstOrDefault(a =>
                                                                          a.EntityTypeId == entityTypeId &&
                                                                          a.EntityTypeQualifierColumn.Equals("ConnectionTypeId", StringComparison.OrdinalIgnoreCase) &&
                                                                          a.EntityTypeQualifierValue.Equals(connectionType.Id.ToString()) &&
                                                                          a.Key == attributeTwoKey));
                    }
                }

                if (AttributeOne != null)
                {
                    phAttributeOne.Controls.Clear();
                    AttributeOne.AddControl(phAttributeOne.Controls, string.Empty, string.Empty, true, true, false);
                    var control = phAttributeOne.Controls[0] as DropDownList;
                    if (control != null)
                    {
                        control.EnableViewState       = true;
                        control.AutoPostBack          = true;
                        control.SelectedIndexChanged += new EventHandler(ddlAttributeOne_SelectedIndexChanged);
                    }
                    else
                    {
                        var          theseControls = phAttributeOne.Controls[0] as DropDownList;
                        DropDownList ddl           = new DropDownList();
                        string[]     theseValues   = AttributeOne.QualifierValues.Values.ElementAt(0).Value.Split(',');

                        foreach (string nameValue in theseValues)
                        {
                            string[] nameAndValue = nameValue.Split(new char[] { '^' });

                            if (nameAndValue.Length == 2)
                            {
                                ddl.Items.Add(new ListItem(nameAndValue[1].Trim(), nameAndValue[0].Trim()));
                            }
                        }

                        ddl.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                        ddl.SelectedIndex = 0;
                        ddl.CssClass      = "form-control";
                        var attributeOneLabel = new HtmlGenericContainer("label");
                        attributeOneLabel.InnerHtml = AttributeOne.Name;
                        attributeOneLabel.CssClass  = "control-label";

                        phAttributeOne.Controls.Clear();
                        phAttributeOne.Controls.Add(new Literal()
                        {
                            Text = "<div class='form-group rock-drop-down-list'>"
                        });
                        phAttributeOne.Controls.Add(attributeOneLabel);
                        phAttributeOne.Controls.Add(ddl);
                        phAttributeOne.Controls.Add(new Literal()
                        {
                            Text = "</div>"
                        });

                        var newDdl = phAttributeOne.Controls[2] as DropDownList;

                        newDdl.EnableViewState       = true;
                        newDdl.AutoPostBack          = true;
                        newDdl.SelectedIndexChanged += new EventHandler(ddlAttributeOne_SelectedIndexChanged);
                    }
                }

                if (AttributeTwo != null)
                {
                    phAttributeTwo.Controls.Clear();
                    AttributeTwo.AddControl(phAttributeTwo.Controls, string.Empty, string.Empty, true, true, false);
                    var control = phAttributeTwo.Controls[0] as DropDownList;
                    if (control != null)
                    {
                        control.EnableViewState       = true;
                        control.AutoPostBack          = true;
                        control.SelectedIndexChanged += new EventHandler(ddlAttributeTwo_SelectedIndexChanged);
                    }
                    else
                    {
                        var          theseControls = phAttributeTwo.Controls[0] as DropDownList;
                        DropDownList ddl           = new DropDownList();
                        string[]     theseValues   = AttributeTwo.QualifierValues.Values.ElementAt(0).Value.Split(',');

                        foreach (string nameValue in theseValues)
                        {
                            string[] nameAndValue = nameValue.Split(new char[] { '^' });

                            if (nameAndValue.Length == 2)
                            {
                                ddl.Items.Add(new ListItem(nameAndValue[1].Trim(), nameAndValue[0].Trim()));
                            }
                        }

                        ddl.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                        ddl.SelectedIndex = 0;
                        ddl.CssClass      = "form-control";
                        var attributeTwoLabel = new HtmlGenericContainer("label");
                        attributeTwoLabel.InnerHtml = AttributeTwo.Name;
                        attributeTwoLabel.CssClass  = "control-label";

                        phAttributeTwo.Controls.Clear();
                        phAttributeTwo.Controls.Add(new Literal()
                        {
                            Text = "<div class='form-group rock-drop-down-list'>"
                        });
                        phAttributeTwo.Controls.Add(attributeTwoLabel);
                        phAttributeTwo.Controls.Add(ddl);
                        phAttributeTwo.Controls.Add(new Literal()
                        {
                            Text = "</div>"
                        });

                        var newDdl = phAttributeTwo.Controls[2] as DropDownList;

                        newDdl.EnableViewState       = true;
                        newDdl.AutoPostBack          = true;
                        newDdl.SelectedIndexChanged += new EventHandler(ddlAttributeTwo_SelectedIndexChanged);
                    }
                }
            }
        }
        /// <summary>
        /// Creates the table controls.
        /// </summary>
        /// <param name="batchId">The batch identifier.</param>
        /// <param name="dataViewId">The data view identifier.</param>
        private void BindHtmlGrid(int?batchId, int?dataViewId)
        {
            _financialTransactionDetailList = null;
            RockContext rockContext = new RockContext();

            nbSaveSuccess.Visible = false;
            btnSave.Visible       = false;

            List <DataControlField> tableColumns = new List <DataControlField>();

            tableColumns.Add(new RockLiteralField {
                ID = "lPerson", HeaderText = "Person"
            });
            tableColumns.Add(new RockLiteralField {
                ID = "lAmount", HeaderText = "Amount"
            });
            tableColumns.Add(new RockLiteralField {
                ID = "lAccount", HeaderText = "Account"
            });
            tableColumns.Add(new RockLiteralField {
                ID = "lTransactionType", HeaderText = "Transaction Type"
            });

            string entityColumnHeading = this.GetAttributeValue("EntityColumnHeading");

            if (string.IsNullOrEmpty(entityColumnHeading))
            {
                if (_transactionEntityType != null)
                {
                    entityColumnHeading = _entityTypeQualifiedName;
                }
            }

            tableColumns.Add(new RockLiteralField {
                ID = "lEntityColumn", HeaderText = entityColumnHeading
            });

            var additionalColumns = this.GetAttributeValue(CustomGridColumnsConfig.AttributeKey).FromJsonOrNull <CustomGridColumnsConfig>();

            if (additionalColumns != null)
            {
                foreach (var columnConfig in additionalColumns.ColumnsConfig)
                {
                    int insertPosition;
                    if (columnConfig.PositionOffsetType == CustomGridColumnsConfig.ColumnConfig.OffsetType.LastColumn)
                    {
                        insertPosition = tableColumns.Count - columnConfig.PositionOffset;
                    }
                    else
                    {
                        insertPosition = columnConfig.PositionOffset;
                    }

                    var column = columnConfig.GetGridColumn();
                    tableColumns.Insert(insertPosition, column);
                    insertPosition++;
                }
            }

            StringBuilder headers = new StringBuilder();

            foreach (var tableColumn in tableColumns)
            {
                if (tableColumn.HeaderStyle.CssClass.IsNotNullOrWhiteSpace())
                {
                    headers.AppendFormat("<th class='{0}'>{1}</th>", tableColumn.HeaderStyle.CssClass, tableColumn.HeaderText);
                }
                else
                {
                    headers.AppendFormat("<th>{0}</th>", tableColumn.HeaderText);
                }
            }

            lHeaderHtml.Text = headers.ToString();

            int?transactionId = this.PageParameter("TransactionId").AsIntegerOrNull();

            if (batchId.HasValue || dataViewId.HasValue || transactionId.HasValue)
            {
                var financialTransactionDetailQuery = new FinancialTransactionDetailService(rockContext).Queryable()
                                                      .Include(a => a.Transaction)
                                                      .Include(a => a.Transaction.AuthorizedPersonAlias.Person);
                if (batchId.HasValue)
                {
                    financialTransactionDetailQuery = financialTransactionDetailQuery.Where(a => a.Transaction.BatchId == batchId.Value);
                }

                if (dataViewId.HasValue && dataViewId > 0)
                {
                    var           dataView = new DataViewService(rockContext).Get(dataViewId.Value);
                    List <string> errorMessages;
                    var           transactionDetailIdsQry = dataView.GetQuery(null, rockContext, null, out errorMessages).Select(a => a.Id);
                    financialTransactionDetailQuery = financialTransactionDetailQuery.Where(a => transactionDetailIdsQry.Contains(a.Id));
                }

                if (transactionId.HasValue)
                {
                    financialTransactionDetailQuery = financialTransactionDetailQuery.Where(a => transactionId == a.TransactionId);
                }

                int maxResults = this.GetAttributeValue("MaxNumberofResults").AsIntegerOrNull() ?? 1000;
                _financialTransactionDetailList = financialTransactionDetailQuery.OrderByDescending(a => a.Transaction.TransactionDateTime).Take(maxResults).ToList();
                phTableRows.Controls.Clear();
                btnSave.Visible = _financialTransactionDetailList.Any();
                string appRoot   = this.ResolveRockUrl("~/");
                string themeRoot = this.ResolveRockUrl("~~/");

                foreach (var financialTransactionDetail in _financialTransactionDetailList)
                {
                    var tr = new HtmlGenericContainer("tr");
                    foreach (var tableColumn in tableColumns)
                    {
                        var literalControl = new LiteralControl();
                        if (tableColumn is RockLiteralField)
                        {
                            tr.Controls.Add(literalControl);
                            var literalTableColumn = tableColumn as RockLiteralField;
                            if (literalTableColumn.ID == "lPerson")
                            {
                                literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Transaction.AuthorizedPersonAlias);
                            }
                            else if (literalTableColumn.ID == "lAmount")
                            {
                                literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Amount.FormatAsCurrency());
                            }
                            else if (literalTableColumn.ID == "lAccount")
                            {
                                literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Account.ToString());
                            }
                            else if (literalTableColumn.ID == "lTransactionType")
                            {
                                literalControl.ID   = "lTransactionType_" + financialTransactionDetail.Id.ToString();
                                literalControl.Text = string.Format("<td>{0}</td>", financialTransactionDetail.Transaction.TransactionTypeValue);
                            }
                            else if (literalTableColumn.ID == "lEntityColumn")
                            {
                                var tdEntityControls = new HtmlGenericContainer("td")
                                {
                                    ID = "pnlEntityControls_" + financialTransactionDetail.Id.ToString()
                                };
                                tr.Controls.Add(tdEntityControls);

                                if (_transactionEntityType != null)
                                {
                                    if (_transactionEntityType.Id == EntityTypeCache.GetId <GroupMember>())
                                    {
                                        var ddlGroup = new RockDropDownList {
                                            ID = "ddlGroup_" + financialTransactionDetail.Id.ToString(), EnhanceForLongLists = true
                                        };
                                        ddlGroup.Label                 = "Group";
                                        ddlGroup.AutoPostBack          = true;
                                        ddlGroup.SelectedIndexChanged += ddlGroup_SelectedIndexChanged;
                                        tdEntityControls.Controls.Add(ddlGroup);
                                        var ddlGroupMember = new RockDropDownList {
                                            ID = "ddlGroupMember_" + financialTransactionDetail.Id.ToString(), Visible = false, EnhanceForLongLists = true
                                        };
                                        ddlGroupMember.Label = "Group Member";
                                        tdEntityControls.Controls.Add(ddlGroupMember);
                                    }
                                    else if (_transactionEntityType.Id == EntityTypeCache.GetId <Group>())
                                    {
                                        var ddlGroup = new RockDropDownList {
                                            ID = "ddlGroup_" + financialTransactionDetail.Id.ToString(), EnhanceForLongLists = true
                                        };
                                        ddlGroup.AutoPostBack = false;
                                        tdEntityControls.Controls.Add(ddlGroup);
                                    }
                                    else if (_transactionEntityType.Id == EntityTypeCache.GetId <DefinedValue>())
                                    {
                                        var ddlDefinedValue = new DefinedValuePicker {
                                            ID = "ddlDefinedValue_" + financialTransactionDetail.Id.ToString(), EnhanceForLongLists = true
                                        };
                                        tdEntityControls.Controls.Add(ddlDefinedValue);
                                    }
                                    else if (_transactionEntityType.SingleValueFieldType != null)
                                    {
                                        var entityPicker = _transactionEntityType.SingleValueFieldType.Field.EditControl(new Dictionary <string, Rock.Field.ConfigurationValue>(), "entityPicker_" + financialTransactionDetail.Id.ToString());
                                        tdEntityControls.Controls.Add(entityPicker);
                                    }
                                }
                            }
                        }
                        else if (tableColumn is LavaField)
                        {
                            tr.Controls.Add(literalControl);
                            var lavaField = tableColumn as LavaField;

                            Dictionary <string, object> mergeValues = new Dictionary <string, object>();
                            mergeValues.Add("Row", financialTransactionDetail);

                            string lavaOutput = lavaField.LavaTemplate.ResolveMergeFields(mergeValues);

                            // Resolve any dynamic url references
                            lavaOutput = lavaOutput.Replace("~~/", themeRoot).Replace("~/", appRoot);

                            if (lavaField.ItemStyle.CssClass.IsNotNullOrWhiteSpace())
                            {
                                literalControl.Text = string.Format("<td class='{0}'>{1}</td>", lavaField.ItemStyle.CssClass, lavaOutput);
                            }
                            else
                            {
                                literalControl.Text = string.Format("<td>{0}</td>", lavaOutput);
                            }
                        }
                    }

                    phTableRows.Controls.Add(tr);

                    pnlTransactions.Visible = true;
                }
            }
            else
            {
                pnlTransactions.Visible = false;
            }
        }
        private PanelWidget AddCommunicationPanel(Group group, GroupMember member, bool insertValues)
        {
            PanelWidget panelWidget = new PanelWidget
            {
                ID    = "pnl+" + group.Id.ToString() + "panel",
                Title = group.Name
            };

            phGroups.Controls.Add(panelWidget);

            group.LoadAttributes();

            if (group.GetAttributeValue("PublicName").IsNotNullOrWhiteSpace())
            {
                panelWidget.Title = group.GetAttributeValue("PublicName");
            }

            var type = group.GetAttributeValue(GetAttributeValue("AttributeKey"));

            if (type.IsNullOrWhiteSpace())
            {
                type = "Text Message,Email";
            }

            type = string.Join(", ", type.SplitDelimitedValues(false));

            var text = string.Format("<small>{0}</small><p>{1}</p>",
                                     type,
                                     group.Description
                                     );


            Literal literal = new Literal
            {
                Text = text
            };

            panelWidget.Controls.Add(literal);

            var showAttributes = false;

            Panel pnlToggle = new Panel
            {
                ID       = "pnlToggle_" + panelWidget.ID,
                CssClass = "btn-group btn-toggle"
            };

            panelWidget.Controls.Add(pnlToggle);

            if (member.PersonId == Person.Id)
            {
                showAttributes = true;
                LinkButton off = new LinkButton
                {
                    ID               = "btnOff" + panelWidget.ID,
                    CssClass         = "btn btn-default btn-xs",
                    Text             = "Unsubscribe",
                    CausesValidation = false
                };
                pnlToggle.Controls.Add(off);
                off.Click += (s, e) => { Unsubscribe(group.Id); };

                HtmlGenericContainer on = new HtmlGenericContainer
                {
                    TagName   = "div",
                    CssClass  = "btn btn-success btn-xs",
                    InnerText = "Subscribed"
                };
                pnlToggle.Controls.Add(on);
            }
            else
            {
                HtmlGenericContainer off = new HtmlGenericContainer
                {
                    TagName   = "div",
                    CssClass  = "btn btn-danger btn-xs",
                    InnerText = "Unsubscribed"
                };
                pnlToggle.Controls.Add(off);

                LinkButton on = new LinkButton
                {
                    ID               = "btnOn" + panelWidget.ID,
                    CssClass         = "btn btn-default btn-xs",
                    Text             = "Subscribe",
                    CausesValidation = false
                };
                pnlToggle.Controls.Add(on);
                on.Click += (s, e) => { Subscribe(group.Id); };
            }

            member.LoadAttributes();

            member.Attributes = member.Attributes.Where(a => a.Value.IsGridColumn).ToDictionary(a => a.Key, a => a.Value);

            if (member.Attributes.Any())
            {
                Literal attributeTitle = new Literal
                {
                    ID      = "ltAttTitle_" + panelWidget.ID,
                    Text    = "<h3>Subscription Settings</h3>",
                    Visible = showAttributes
                };

                panelWidget.Controls.Add(attributeTitle);

                var attributePlaceholder = new PlaceHolder
                {
                    ID      = "phAtt_" + panelWidget.ID,
                    Visible = showAttributes
                };
                panelWidget.Controls.Add(attributePlaceholder);

                Rock.Attribute.Helper.AddEditControls(member, attributePlaceholder, insertValues);

                BootstrapButton btnSave = new BootstrapButton
                {
                    ID       = "btnSave_" + panelWidget.ID,
                    Text     = "Update Settings",
                    CssClass = "btn btn-primary btn-xs",
                    Visible  = showAttributes
                };
                panelWidget.Controls.Add(btnSave);
                btnSave.Click += (s, e) =>
                {
                    UpdateSettings(member, attributePlaceholder);
                    btnSave.Text = "Saved";
                };
            }
            return(panelWidget);
        }