An HtmlGenericContainer that implements the INamingContainer interface
Inheritance: System.Web.UI.HtmlControls.HtmlGenericControl, INamingContainer
Example #1
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)
        {
            var cell = container as DataControlFieldCell;

            if (cell != null)
            {
                var mergeField = cell.ContainingField as PersonMergeField;
                if (mergeField != null)
                {
                    var lbDelete = new LinkButton();
                    lbDelete.CausesValidation = false;
                    lbDelete.CssClass         = "btn btn-danger btn-xs pull-right";
                    lbDelete.ToolTip          = "Remove Person";
                    cell.Controls.Add(lbDelete);

                    HtmlGenericControl buttonIcon = new HtmlGenericControl("i");
                    buttonIcon.Attributes.Add("class", "fa fa-times");
                    lbDelete.Controls.Add(buttonIcon);

                    lbDelete.Click += lbDelete_Click;

                    // make sure delete button is registered for async postback (needed just in case the grid was created at runtime)
                    var sm = ScriptManager.GetCurrent(mergeField.ParentGrid.Page);
                    sm.RegisterAsyncPostBackControl(lbDelete);

                    HtmlGenericContainer headerSummary = new HtmlGenericContainer("div", "merge-header-summary");
                    headerSummary.Attributes.Add("data-col", mergeField.ColumnIndex.ToString());

                    var i = new HtmlGenericControl("i");
                    i.Attributes.Add("class", "fa fa-2x " + (mergeField.IsPrimaryPerson ? "fa-check-square-o" : "fa-square-o"));
                    headerSummary.Controls.Add(i);

                    headerSummary.Controls.Add(new LiteralControl(mergeField.HeaderContent));

                    string created = (mergeField.ModifiedDateTime.HasValue ? mergeField.ModifiedDateTime.ToElapsedString() + " " : "") +
                                     (!string.IsNullOrWhiteSpace(mergeField.ModifiedBy) ? "by " + mergeField.ModifiedBy : "");
                    if (created != string.Empty)
                    {
                        headerSummary.Controls.Add(new LiteralControl(string.Format("<small>Last Modifed {0}</small>", created)));
                    }

                    cell.Controls.Add(headerSummary);
                }
            }
        }
        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 );
                }
            }
        }
        /// <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 ( !_addedGroupTypeIds.Contains( groupType.Id ) )
            {
                _addedGroupTypeIds.Add( groupType.Id );

                if ( groupType.Groups.Any() )
                {
                    bool showGroupAncestry = GetAttributeValue( "ShowGroupAncestry" ).AsBoolean( true );

                    var groupService = new GroupService( _rockContext );

                    var cblGroupTypeGroups = new RockCheckBoxList { ID = "cblGroupTypeGroups" + groupType.Id };

                    cblGroupTypeGroups.Label = groupType.Name;
                    cblGroupTypeGroups.Items.Clear();

                    foreach ( var group in groupType.Groups
                        .Where( g => !g.ParentGroupId.HasValue )
                        .OrderBy( a => a.Order )
                        .ThenBy( a => a.Name )
                        .ToList() )
                    {
                        AddGroupControls( group, cblGroupTypeGroups, groupService, showGroupAncestry );
                    }

                    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" + childGroupType.Id;
                        ulGroupTypeList.Controls.Add( liChildGroupTypeItem );
                        AddGroupTypeControls( childGroupType, liChildGroupTypeItem );
                    }
                }
            }
        }
Example #4
0
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Controls.Clear();

            this.CssClass = "picker picker-select rollover-container";

            _hfLocationId = new HiddenField { ID = "hfLocationId" };
            this.Controls.Add( _hfLocationId );

            _btnPickerLabel = new HtmlAnchor { ID = "btnPickerLabel" };
            _btnPickerLabel.Attributes["class"] = "picker-label";
            this.Controls.Add( _btnPickerLabel );

            _btnSelectNone = new HtmlAnchor();
            _btnSelectNone.Attributes["class"] = "picker-select-none";
            _btnSelectNone.ID = string.Format( "btnSelectNone_{0}", this.ID );
            _btnSelectNone.InnerHtml = "<i class='fa fa-times'></i>";
            _btnSelectNone.CausesValidation = false;
            _btnSelectNone.Style[HtmlTextWriterStyle.Display] = "none";
            _btnSelectNone.ServerClick += _btnSelectNone_ServerClick;
            this.Controls.Add( _btnSelectNone );

            // PickerMenu (DropDown menu)
            _pnlPickerMenu = new Panel { ID = "pnlPickerMenu" };
            _pnlPickerMenu.CssClass = "picker-menu dropdown-menu";
            _pnlPickerMenu.Style[HtmlTextWriterStyle.Display] = "none";
            this.Controls.Add( _pnlPickerMenu );
            SetPickerOnClick();

            // Address Entry
            _pnlAddressEntry = new Panel { ID = "pnlAddressEntry" };
            _pnlAddressEntry.CssClass = "locationpicker-address-entry";
            _pnlPickerMenu.Controls.Add( _pnlAddressEntry );

            _tbAddress1 = new RockTextBox { ID = "tbAddress1" };
            _tbAddress1.Label = "Address Line 1";
            _pnlAddressEntry.Controls.Add( _tbAddress1 );

            _tbAddress2 = new RockTextBox { ID = "tbAddress2" };
            _tbAddress2.Label = "Address Line 2";
            _pnlAddressEntry.Controls.Add( _tbAddress2 );

            // Address Entry - City State Zip
            _divCityStateZipRow = new HtmlGenericContainer( "div", "row" );
            _pnlAddressEntry.Controls.Add( _divCityStateZipRow );

            _divCityColumn = new HtmlGenericContainer( "div", "col-sm-5" );
            _divCityStateZipRow.Controls.Add( _divCityColumn );
            _tbCity = new RockTextBox { ID = "tbCity" };
            _tbCity.Label = "City";
            _divCityColumn.Controls.Add( _tbCity );

            _divStateColumn = new HtmlGenericContainer( "div", "col-sm-3" );
            _divCityStateZipRow.Controls.Add( _divStateColumn );
            _ddlState = new StateDropDownList { ID = "ddlState" };
            _ddlState.UseAbbreviation = true;
            _ddlState.CssClass = "input-mini";
            _ddlState.Label = "State";
            _divStateColumn.Controls.Add( _ddlState );

            _divZipColumn = new HtmlGenericContainer( "div", "col-sm-4" );
            _divCityStateZipRow.Controls.Add( _divZipColumn );
            _tbZip = new RockTextBox { ID = "tbZip" };
            _tbZip.CssClass = "input-small";
            _tbZip.Label = "Zip";
            _divZipColumn.Controls.Add( _tbZip );

            // picker actions
            _pnlPickerActions = new Panel { ID = "pnlPickerActions", CssClass = "picker-actions" };
            _pnlPickerMenu.Controls.Add( _pnlPickerActions );
            _btnSelect = new LinkButton { ID = "btnSelect", CssClass = "btn btn-xs btn-primary", Text = "Select", CausesValidation = false };
            _btnSelect.Click += _btnSelect_Click;
            _pnlPickerActions.Controls.Add( _btnSelect );
            _btnCancel = new LinkButton { ID = "btnCancel", CssClass = "btn btn-xs btn-link", Text = "Cancel" };
            _btnCancel.OnClientClick = string.Format( "$('#{0}').hide();", _pnlPickerMenu.ClientID );
            _pnlPickerActions.Controls.Add( _btnCancel );
        }
Example #5
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 )
        {
            HtmlGenericControl ulSizeOptions = new HtmlGenericControl( "ul" );
            ulSizeOptions.AddCssClass( "grid-pagesize pagination pagination-sm" );
            container.Controls.Add( ulSizeOptions );

            for ( int i = 0; i < ItemLinkListItem.Length; i++ )
            {
                ItemLinkListItem[i] = new HtmlGenericContainer( "li" );
                ulSizeOptions.Controls.Add( ItemLinkListItem[i] );

                ItemLink[i] = new LinkButton();
                ItemLinkListItem[i].Controls.Add( ItemLink[i] );
                ItemLink[i].CausesValidation = false;
                ItemLink[i].Click += new EventHandler( lbItems_Click );
            }

            ItemLink[0].Text = "50";
            ItemLink[1].Text = "500";
            ItemLink[2].Text = "5,000";

            // itemCount
            HtmlGenericControl divItemCount = new HtmlGenericControl( "div" );
            divItemCount.Attributes.Add( "class", "grid-itemcount" );
            container.Controls.Add( divItemCount );

            itemCountDisplay = new Literal();
            divItemCount.Controls.Add( itemCountDisplay );

            // Pagination
            NavigationPanel = new HtmlGenericControl( "ul" );
            NavigationPanel.AddCssClass( "grid-pager pagination pagination-sm" );
            container.Controls.Add( NavigationPanel );

            for ( var i = 0; i < PageLinkListItem.Length; i++ )
            {
                PageLinkListItem[i] = new HtmlGenericContainer( "li" );
                NavigationPanel.Controls.Add( PageLinkListItem[i] );

                PageLink[i] = new LinkButton();
                PageLinkListItem[i].Controls.Add( PageLink[i] );
                PageLink[i].Click += new EventHandler( lbPage_Click );
            }

            PageLink[0].Text = "&laquo;";
            PageLink[PageLinkListItem.Length - 1].Text = "&raquo;";
        }
Example #6
0
        // Adds the necessary script elements for managing the page/zone/blocks
        /// <summary>
        /// Adds the config elements.
        /// </summary>
        private void AddZoneElements( bool canConfigPage)
        {
            if ( canConfigPage )
            {
                AddBlockMove();
            }

            // Add Zone Wrappers
            foreach ( KeyValuePair<string, KeyValuePair<string, Zone>> zoneControl in this.Zones )
            {
                Control control = zoneControl.Value.Value;
                Control parent = zoneControl.Value.Value.Parent;

                HtmlGenericControl zoneWrapper = new HtmlGenericControl( "div" );
                parent.Controls.AddAt( parent.Controls.IndexOf( control ), zoneWrapper );
                zoneWrapper.ID = string.Format( "zone-{0}", zoneControl.Key.ToLower() );
                zoneWrapper.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                zoneWrapper.Attributes.Add( "class", "zone-instance" + ( canConfigPage ? " can-configure" : "" ) );

                if ( canConfigPage )
                {
                    // Zone content configuration widget
                    HtmlGenericControl zoneConfig = new HtmlGenericControl( "div" );
                    zoneWrapper.Controls.Add( zoneConfig );
                    zoneConfig.Attributes.Add( "class", "zone-configuration config-bar" );

                    HtmlGenericControl zoneConfigLink = new HtmlGenericControl( "a" );
                    zoneConfigLink.Attributes.Add( "class", "zoneinstance-config" );
                    zoneConfigLink.Attributes.Add( "href", "#" );
                    zoneConfig.Controls.Add( zoneConfigLink );
                    HtmlGenericControl iZoneConfig = new HtmlGenericControl( "i" );
                    iZoneConfig.Attributes.Add( "class", "fa fa-arrow-circle-right" );
                    zoneConfigLink.Controls.Add( iZoneConfig );

                    HtmlGenericControl zoneConfigBar = new HtmlGenericControl( "div" );
                    zoneConfigBar.Attributes.Add( "class", "zone-configuration-bar" );
                    zoneConfig.Controls.Add( zoneConfigBar );

                    HtmlGenericControl zoneConfigTitle = new HtmlGenericControl( "span" );
                    zoneConfigTitle.InnerText = zoneControl.Value.Key;
                    zoneConfigBar.Controls.Add( zoneConfigTitle );

                    // Configure Blocks icon
                    HtmlGenericControl aBlockConfig = new HtmlGenericControl( "a" );
                    zoneConfigBar.Controls.Add( aBlockConfig );
                    aBlockConfig.ID = string.Format( "aBlockConfig-{0}", zoneControl.Key );
                    aBlockConfig.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                    aBlockConfig.Attributes.Add( "class", "zone-blocks" );
                    aBlockConfig.Attributes.Add( "height", "500px" );
                    aBlockConfig.Attributes.Add( "href", "javascript: Rock.controls.modal.show($(this), '" + ResolveUrl( string.Format( "~/ZoneBlocks/{0}/{1}?t=Zone Blocks&pb=&sb=Done", _pageCache.Id, zoneControl.Key ) ) + "')" );
                    aBlockConfig.Attributes.Add( "Title", "Zone Blocks" );
                    aBlockConfig.Attributes.Add( "zone", zoneControl.Key );
                    //aBlockConfig.InnerText = "Blocks";
                    HtmlGenericControl iZoneBlocks = new HtmlGenericControl( "i" );
                    iZoneBlocks.Attributes.Add( "class", "fa fa-th-large" );
                    aBlockConfig.Controls.Add( iZoneBlocks );
                }

                HtmlGenericContainer zoneContent = new HtmlGenericContainer( "div" );
                zoneContent.Attributes.Add( "class", "zone-content" );
                zoneWrapper.Controls.Add( zoneContent );

                parent.Controls.Remove( control );
                zoneContent.Controls.Add( control );
            }
        }
        /// <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 ( !_addedGroupTypeIds.Contains( groupType.Id ) )
            {
                _addedGroupTypeIds.Add( groupType.Id );

                if ( groupType.Groups.Any() )
                {
                    bool showGroupAncestry = GetAttributeValue( "ShowGroupAncestry" ).AsBoolean( true );

                    var groupService = new GroupService( _rockContext );

                    var cblGroupTypeGroups = new RockCheckBoxList { ID = "cblGroupTypeGroups" + groupType.Id };

                    cblGroupTypeGroups.Label = groupType.Name;
                    cblGroupTypeGroups.Items.Clear();

                    // limit to Groups that don't have a Parent, or the ParentGroup is a different grouptype so we don't end up with infinite recursion
                    foreach ( var group in groupType.Groups
                        .Where( g => !g.ParentGroupId.HasValue || ( g.ParentGroup.GroupTypeId != groupType.Id ) )
                        .OrderBy( a => a.Order )
                        .ThenBy( a => a.Name )
                        .ToList() )
                    {
                        AddGroupControls( group, cblGroupTypeGroups, groupService, showGroupAncestry );
                    }

                    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", "list-unstyled" );

                    liGroupTypeItem.Controls.Add( ulGroupTypeList );
                    foreach ( var childGroupType in groupType.ChildGroupTypes.OrderBy( a => a.Order ).ThenBy( a => a.Name ) )
                    {
                        var liChildGroupTypeItem = new HtmlGenericContainer( "li" );
                        liChildGroupTypeItem.ID = "liGroupTypeItem" + childGroupType.Id;
                        ulGroupTypeList.Controls.Add( liChildGroupTypeItem );
                        AddGroupTypeControls( childGroupType, liChildGroupTypeItem );
                    }
                }
            }
        }
        /// <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 );
            }
        }
Example #9
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)
        {
            HtmlGenericControl divPagination = new HtmlGenericControl( "div" );
            divPagination.Attributes.Add( "class", "pagination" );
            container.Controls.Add( divPagination );

            // Page Status
            //HtmlGenericControl divStatus = new HtmlGenericControl( "div" );
            //divStatus.Attributes.Add( "class", "page-status" );
            //divPagination.Controls.Add( divStatus );

            //lStatus = new Literal();
            //divStatus.Controls.Add( lStatus );

            // Pagination
            NavigationPanel = new HtmlGenericControl( "div" );
            NavigationPanel.Attributes.Add( "class", "page-navigation" );
            divPagination.Controls.Add( NavigationPanel );

            HtmlGenericControl ulNavigation = new HtmlGenericControl( "ul" );
            NavigationPanel.Controls.Add( ulNavigation );

            for ( var i = 0; i < PageLinkListItem.Length; i++ )
            {
                PageLinkListItem[i] = new HtmlGenericContainer( "li" );
                ulNavigation.Controls.Add( PageLinkListItem[i] );

                PageLink[i] = new LinkButton();
                PageLinkListItem[i].Controls.Add( PageLink[i] );
                PageLink[i].Click += new EventHandler( lbPage_Click );
            }

            PageLink[0].Text = "&larr; Previous";
            PageLink[PageLinkListItem.Length - 1].Text = "Next &rarr;";

            // Items Per Page
            HtmlGenericControl divSize = new HtmlGenericControl( "div" );
            divSize.Attributes.Add( "class", "page-size" );
            divPagination.Controls.Add( divSize );

            Label lblPageSize = new Label();
            lblPageSize.Text = "Items per page:";
            divSize.Controls.Add( lblPageSize );

            HtmlGenericControl divSizeOptions = new HtmlGenericControl( "div" );
            divSizeOptions.Attributes.Add( "class", "page-size-options" );
            divSize.Controls.Add( divSizeOptions );

            HtmlGenericControl ulSizeOptions = new HtmlGenericControl( "ul" );
            divSizeOptions.Controls.Add( ulSizeOptions );

            for ( int i = 0; i < ItemLinkListItem.Length; i++ )
            {
                ItemLinkListItem[i] = new HtmlGenericContainer( "li" );
                ulSizeOptions.Controls.Add( ItemLinkListItem[i] );

                ItemLink[i] = new LinkButton();
                ItemLinkListItem[i].Controls.Add( ItemLink[i] );
                ItemLink[i].Click += new EventHandler( lbItems_Click );
            }

            ItemLink[0].Text = "25";
            ItemLink[1].Text = "100";
            ItemLink[2].Text = "1,000";
            ItemLink[3].Text = "All";
        }
Example #10
0
        /// <summary>
        /// Loads all of the configured blocks for the current page into the control tree
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit( EventArgs e )
        {
            // Add the ScriptManager to each page
            ScriptManager sm = ScriptManager.GetCurrent( this.Page );
            if ( sm == null )
            {
                sm = new ScriptManager();
                sm.ID = "sManager";
                Page.Form.Controls.AddAt( 0, sm );
            }

            // Recurse the page controls to find the rock page title and zone controls
            PageTitles = new List<PageTitle>();
            Zones = new Dictionary<string, KeyValuePair<string, Zone>>();
            FindRockControls( this.Controls );

            // Add a Rock version meta tag
            string version = typeof( Rock.Web.UI.RockPage ).Assembly.GetName().Version.ToString();
            HtmlMeta rockVersion = new HtmlMeta();
            rockVersion.Attributes.Add( "name", "generator" );
            rockVersion.Attributes.Add( "content", string.Format( "Rock v{0}", version ) );
            AddMetaTag( this.Page, rockVersion );

            // If the logout parameter was entered, delete the user's forms authentication cookie and redirect them
            // back to the same page.
            if ( PageParameter( "logout" ) != string.Empty )
            {
                FormsAuthentication.SignOut();
                CurrentPerson = null;
                CurrentUser = null;
                Response.Redirect( BuildUrl( new PageReference( CurrentPage.Id, CurrentPage.RouteId ), null ), false);
                Context.ApplicationInstance.CompleteRequest();
                return;
            }

            // If the impersonated query key was included then set the current person
            string impersonatedPersonKey = PageParameter( "rckipid" );
            if ( !String.IsNullOrEmpty( impersonatedPersonKey ) )
            {
                Rock.Model.PersonService personService = new Model.PersonService();
                Rock.Model.Person impersonatedPerson = personService.GetByEncryptedKey( impersonatedPersonKey );
                if ( impersonatedPerson != null )
                {
                    Rock.Security.Authorization.SetAuthCookie( "rckipid=" + impersonatedPerson.EncryptedKey, false, true );
                    CurrentUser = impersonatedPerson.ImpersonatedUser;
                }
            }

            // Get current user/person info
            Rock.Model.UserLogin user = CurrentUser;

            // If there is a logged in user, see if it has an associated Person Record.  If so, set the UserName to
            // the person's full name (which is then cached in the Session state for future page requests)
            if ( user != null )
            {
                UserName = user.UserName;
                int? personId = user.PersonId;

                if ( personId.HasValue )
                {
                    string personNameKey = "PersonName_" + personId.Value.ToString();
                    if ( Session[personNameKey] != null )
                    {
                        UserName = Session[personNameKey].ToString();
                    }
                    else
                    {
                        Rock.Model.PersonService personService = new Model.PersonService();
                        Rock.Model.Person person = personService.Get( personId.Value );
                        if ( person != null )
                        {
                            UserName = person.FullName;
                            CurrentPerson = person;
                        }

                        Session[personNameKey] = UserName;
                    }
                }
            }

            // If a PageInstance exists
            if ( CurrentPage != null )
            {
                // check if page should have been loaded via ssl
                if ( !Request.IsSecureConnection && CurrentPage.RequiresEncryption )
                {
                    string redirectUrl = Request.Url.ToString().Replace( "http:", "https:" );
                    Response.Redirect( redirectUrl, false );
                    Context.ApplicationInstance.CompleteRequest();
                    return;
                }

                // Verify that the current user is allowed to view the page.  If not, and
                // the user hasn't logged in yet, redirect to the login page
                if ( !CurrentPage.IsAuthorized( "View", CurrentPerson ) )
                {
                    if ( user == null )
                    {
                        FormsAuthentication.RedirectToLoginPage();
                    }
                }
                else
                {
                    // Set current models (context)
                    CurrentPage.Context = new Dictionary<string, Data.KeyEntity>();
                    try
                    {
                        foreach ( var pageContext in CurrentPage.PageContexts )
                        {
                            int contextId = 0;
                            if ( Int32.TryParse( PageParameter( pageContext.Value ), out contextId ) )
                                CurrentPage.Context.Add( pageContext.Key, new Data.KeyEntity( contextId ) );
                        }

                        char[] delim = new char[1] { ',' };
                        foreach ( string param in PageParameter( "context" ).Split( delim, StringSplitOptions.RemoveEmptyEntries ) )
                        {
                            string contextItem = Rock.Security.Encryption.DecryptString( param );
                            string[] parts = contextItem.Split('|');
                            if (parts.Length == 2)
                                CurrentPage.Context.Add(parts[0], new Data.KeyEntity(parts[1]));
                        }

                    }
                    catch { }

                    // set page title
                    if ( CurrentPage.Title != null && CurrentPage.Title != "" )
                        SetTitle( CurrentPage.Title );
                    else
                        SetTitle( CurrentPage.Name );

                    // set viewstate on/off
                    this.EnableViewState = CurrentPage.EnableViewState;

                    // Cache object used for block output caching
                    ObjectCache cache = MemoryCache.Default;

                    bool canAdministratePage = CurrentPage.IsAuthorized( "Administrate", CurrentPerson );

                    // Create a javascript object to store information about the current page for client side scripts to use
                    string script = string.Format( @"
            var rock = {{
            pageId:{0},
            layout:'{1}',
            baseUrl:'{2}'
            }};
            ",
                        CurrentPage.Id, CurrentPage.Layout, AppPath );
                    this.Page.ClientScript.RegisterStartupScript( this.GetType(), "rock-js-object", script, true );

                    // Add config elements
                    if ( CurrentPage.IncludeAdminFooter )
                    {
                        AddPopupControls();
                        if ( canAdministratePage )
                            AddConfigElements();
                    }

                    AddKendoScripts();

                    // Load the blocks and insert them into page zones
                    foreach ( Rock.Web.Cache.BlockCache block in CurrentPage.Blocks )
                    {
                        // Get current user's permissions for the block instance
                        bool canAdministrate = block.IsAuthorized( "Administrate", CurrentPerson );
                        bool canEdit = block.IsAuthorized( "Edit", CurrentPerson );
                        bool canView = block.IsAuthorized( "View", CurrentPerson );

                        // Make sure user has access to view block instance
                        if ( canAdministrate || canEdit || canView )
                        {
                            // Create block wrapper control (implements INamingContainer so child control IDs are unique for
                            // each block instance
                            HtmlGenericContainer blockWrapper = new HtmlGenericContainer( "div" );
                            blockWrapper.ID = string.Format( "bid_{0}", block.Id );
                            blockWrapper.Attributes.Add( "zoneloc", block.BlockLocation.ToString() );
                            blockWrapper.ClientIDMode = ClientIDMode.Static;
                            FindZone( block.Zone ).Controls.Add( blockWrapper );
                            blockWrapper.Attributes.Add( "class", "block-instance " +
                                ( canAdministrate || canEdit ? "can-configure " : "" ) +
                                HtmlHelper.CssClassFormat( block.BlockType.Name ) );

                            // Check to see if block is configured to use a "Cache Duration'
                            string blockCacheKey = string.Format( "Rock:BlockInstanceOutput:{0}", block.Id );
                            if ( block.OutputCacheDuration > 0 && cache.Contains( blockCacheKey ) )
                            {
                                // If the current block exists in our custom output cache, add the cached output instead of adding the control
                                blockWrapper.Controls.Add( new LiteralControl( cache[blockCacheKey] as string ) );
                            }
                            else
                            {
                                // Load the control and add to the control tree
                                Control control;

                                try
                                {
                                    control = TemplateControl.LoadControl( block.BlockType.Path );
                                    control.ClientIDMode = ClientIDMode.AutoID;
                                }
                                catch ( Exception ex )
                                {
                                    HtmlGenericControl div = new HtmlGenericControl( "div" );
                                    div.Attributes.Add( "class", "alert-message block-message error" );
                                    div.InnerHtml = string.Format( "Error Loading Block:<br/><br/><strong>{0}</strong>", ex.Message );
                                    control = div;
                                }

                                RockBlock blockControl = null;

                                // Check to see if the control was a PartialCachingControl or not
                                if ( control is RockBlock )
                                    blockControl = control as RockBlock;
                                else
                                {
                                    if ( control is PartialCachingControl && ( (PartialCachingControl)control ).CachedControl != null )
                                        blockControl = (RockBlock)( (PartialCachingControl)control ).CachedControl;
                                }

                                // If the current control is a block, set it's properties
                                if ( blockControl != null )
                                {
                                    blockControl.CurrentPage = CurrentPage;
                                    blockControl.CurrentBlock = block;

                                    blockControl.ReadAdditionalActions();

                                    // If the block's AttributeProperty values have not yet been verified verify them.
                                    // (This provides a mechanism for block developers to define the needed block
                                    //  attributes in code and have them automatically added to the database)
                                    if ( !block.BlockType.IsInstancePropertiesVerified )
                                    {
                                        blockControl.CreateAttributes();
                                        block.BlockType.IsInstancePropertiesVerified = true;
                                    }

                                    // Add the block configuration scripts and icons if user is authorized
                                    if ( CurrentPage.IncludeAdminFooter )
                                        AddBlockConfig( blockWrapper, blockControl, block, canAdministrate, canEdit );
                                }

                                HtmlGenericContainer blockContent = new HtmlGenericContainer( "div" );
                                blockContent.Attributes.Add( "class", "block-content" );
                                blockWrapper.Controls.Add( blockContent );

                                // Add the block
                                blockContent.Controls.Add( control );
                            }
                        }
                    }

                    // Add favicon and apple touch icons to page
                    if ( CurrentPage.Site.FaviconUrl != null )
                    {
                        System.Web.UI.HtmlControls.HtmlLink faviconLink = new System.Web.UI.HtmlControls.HtmlLink();

                        faviconLink.Attributes.Add( "rel", "shortcut icon" );
                        faviconLink.Attributes.Add( "href", ResolveUrl( "~/" + CurrentPage.Site.FaviconUrl ) );

                        CurrentPage.AddHtmlLink( this.Page, faviconLink );
                    }

                    if ( CurrentPage.Site.AppleTouchIconUrl != null )
                    {
                        System.Web.UI.HtmlControls.HtmlLink touchLink = new System.Web.UI.HtmlControls.HtmlLink();

                        touchLink.Attributes.Add( "rel", "apple-touch-icon" );
                        touchLink.Attributes.Add( "href", ResolveUrl( "~/" + CurrentPage.Site.AppleTouchIconUrl ) );

                        CurrentPage.AddHtmlLink( this.Page, touchLink );
                    }

                    // Add the page admin footer if the user is authorized to edit the page
                    if ( CurrentPage.IncludeAdminFooter && canAdministratePage )
                    {
                        HtmlGenericControl adminFooter = new HtmlGenericControl( "div" );
                        adminFooter.ID = "cms-admin-footer";
                        adminFooter.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                        this.Form.Controls.Add( adminFooter );

                        phLoadTime = new PlaceHolder();
                        adminFooter.Controls.Add( phLoadTime );

                        HtmlGenericControl buttonBar = new HtmlGenericControl( "div" );
                        adminFooter.Controls.Add( buttonBar );
                        buttonBar.Attributes.Add( "class", "button-bar" );

                        // RockBlock Config
                        HtmlGenericControl aBlockConfig = new HtmlGenericControl( "a" );
                        buttonBar.Controls.Add( aBlockConfig );
                        aBlockConfig.Attributes.Add( "class", "btn block-config" );
                        aBlockConfig.Attributes.Add( "href", "#" );
                        aBlockConfig.Attributes.Add( "Title", "Block Configuration" );
                        HtmlGenericControl iBlockConfig = new HtmlGenericControl( "i" );
                        aBlockConfig.Controls.Add( iBlockConfig );
                        iBlockConfig.Attributes.Add( "class", "icon-th-large" );

                        // RockPage Properties
                        HtmlGenericControl aAttributes = new HtmlGenericControl( "a" );
                        buttonBar.Controls.Add( aAttributes );
                        aAttributes.Attributes.Add( "class", "btn properties show-modal-iframe" );
                        aAttributes.Attributes.Add( "height", "500px" );
                        aAttributes.Attributes.Add( "href", ResolveUrl( string.Format( "~/PageProperties/{0}?t=Page Properties", CurrentPage.Id ) ) );
                        aAttributes.Attributes.Add( "Title", "Page Properties" );
                        HtmlGenericControl iAttributes = new HtmlGenericControl( "i" );
                        aAttributes.Controls.Add( iAttributes );
                        iAttributes.Attributes.Add( "class", "icon-cog" );

                        // Child Pages
                        HtmlGenericControl aChildPages = new HtmlGenericControl( "a" );
                        buttonBar.Controls.Add( aChildPages );
                        aChildPages.Attributes.Add( "class", "btn page-child-pages show-modal-iframe" );
                        aChildPages.Attributes.Add( "height", "500px" );
                        aChildPages.Attributes.Add( "href", ResolveUrl( string.Format( "~/pages/{0}?t=Child Pages&pb=&sb=Done", CurrentPage.Id ) ) );
                        aChildPages.Attributes.Add( "Title", "Child Pages" );
                        HtmlGenericControl iChildPages = new HtmlGenericControl( "i" );
                        aChildPages.Controls.Add( iChildPages );
                        iChildPages.Attributes.Add( "class", "icon-sitemap" );

                        // RockPage Zones
                        HtmlGenericControl aPageZones = new HtmlGenericControl( "a" );
                        buttonBar.Controls.Add( aPageZones );
                        aPageZones.Attributes.Add( "class", "btn page-zones" );
                        aPageZones.Attributes.Add( "href", "#" );
                        aPageZones.Attributes.Add( "Title", "Page Zones" );
                        HtmlGenericControl iPageZones = new HtmlGenericControl( "i" );
                        aPageZones.Controls.Add( iPageZones );
                        iPageZones.Attributes.Add( "class", "icon-columns" );

                        // RockPage Security
                        HtmlGenericControl aPageSecurity = new HtmlGenericControl( "a" );
                        buttonBar.Controls.Add( aPageSecurity );
                        aPageSecurity.Attributes.Add( "class", "btn page-security show-modal-iframe" );
                        aPageSecurity.Attributes.Add( "height", "500px" );
                        aPageSecurity.Attributes.Add( "href", ResolveUrl( string.Format( "~/Secure/{0}/{1}?t=Page Security&pb=&sb=Done",
                            Security.Authorization.EncodeEntityTypeName( CurrentPage.GetType() ), CurrentPage.Id ) ) );
                        aPageSecurity.Attributes.Add( "Title", "Page Security" );
                        HtmlGenericControl iPageSecurity = new HtmlGenericControl( "i" );
                        aPageSecurity.Controls.Add( iPageSecurity );
                        iPageSecurity.Attributes.Add( "class", "icon-lock" );

                        // System Info
                        HtmlGenericControl aSystemInfo = new HtmlGenericControl( "a" );
                        buttonBar.Controls.Add( aSystemInfo );
                        aSystemInfo.Attributes.Add( "class", "btn system-info show-modal-iframe" );
                        aSystemInfo.Attributes.Add( "height", "500px" );
                        aSystemInfo.Attributes.Add( "href", ResolveUrl( "~/SystemInfo?t=System Information&pb=&sb=Done" ) );
                        aSystemInfo.Attributes.Add( "Title", "Rock Information" );
                        HtmlGenericControl iSystemInfo = new HtmlGenericControl( "i" );
                        aSystemInfo.Controls.Add( iSystemInfo );
                        iSystemInfo.Attributes.Add( "class", "icon-info-sign" );

                    }

                    // Check to see if page output should be cached.  The RockRouteHandler
                    // saves the PageCacheData information for the current page to memorycache
                    // so it should always exist
                    if ( CurrentPage.OutputCacheDuration > 0 )
                    {
                        Response.Cache.SetCacheability( System.Web.HttpCacheability.Public );
                        Response.Cache.SetExpires( DateTime.Now.AddSeconds( CurrentPage.OutputCacheDuration ) );
                        Response.Cache.SetValidUntilExpires( true );
                    }
                }
            }
        }
Example #11
0
        // Adds the neccessary script elements for managing the page/zone/blocks
        /// <summary>
        /// Adds the config elements.
        /// </summary>
        private void AddConfigElements()
        {
            // Add the page admin script
            AddScriptLink( Page, "~/Scripts/Rock/page-admin.js" );

            // add the scripts for RockGrid
            AddScriptLink( Page, "~/Scripts/Rock/grid.js" );

            AddBlockMove();
            // Add Zone Wrappers
            foreach ( KeyValuePair<string, KeyValuePair<string, Zone>> zoneControl in this.Zones )
            {
                Control control = zoneControl.Value.Value;
                Control parent = zoneControl.Value.Value.Parent;

                HtmlGenericControl zoneWrapper = new HtmlGenericControl( "div" );
                parent.Controls.AddAt( parent.Controls.IndexOf( control ), zoneWrapper );
                zoneWrapper.ID = string.Format( "zone-{0}", control.ID );
                zoneWrapper.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                zoneWrapper.Attributes.Add( "class", "zone-instance can-configure" );

                // Zone content configuration widget
                HtmlGenericControl zoneConfig = new HtmlGenericControl( "div" );
                zoneWrapper.Controls.Add( zoneConfig );
                zoneConfig.Attributes.Add( "class", "zone-configuration config-bar" );

                HtmlGenericControl zoneConfigLink = new HtmlGenericControl( "a" );
                zoneConfigLink.Attributes.Add( "class", "zoneinstance-config" );
                zoneConfigLink.Attributes.Add( "href", "#" );
                zoneConfig.Controls.Add( zoneConfigLink );
                HtmlGenericControl iZoneConfig = new HtmlGenericControl( "i" );
                iZoneConfig.Attributes.Add( "class", "icon-circle-arrow-right" );
                zoneConfigLink.Controls.Add( iZoneConfig );

                HtmlGenericControl zoneConfigBar = new HtmlGenericControl( "div" );
                zoneConfigBar.Attributes.Add( "class", "zone-configuration-bar" );
                zoneConfig.Controls.Add( zoneConfigBar );

                HtmlGenericControl zoneConfigTitle = new HtmlGenericControl( "span" );
                zoneConfigTitle.InnerText = zoneControl.Value.Key;
                zoneConfigBar.Controls.Add( zoneConfigTitle );

                // Configure Blocks icon
                HtmlGenericControl aBlockConfig = new HtmlGenericControl( "a" );
                zoneConfigBar.Controls.Add( aBlockConfig );
                aBlockConfig.Attributes.Add( "class", "zone-blocks show-modal-iframe" );
                aBlockConfig.Attributes.Add( "height", "500px" );
                aBlockConfig.Attributes.Add( "href", ResolveUrl( string.Format( "~/ZoneBlocks/{0}/{1}?t=Zone Blocks&pb=&sb=Done", CurrentPage.Id, control.ID ) ) );
                aBlockConfig.Attributes.Add( "Title", "Zone Blocks" );
                aBlockConfig.Attributes.Add( "zone", zoneControl.Key );
                //aBlockConfig.InnerText = "Blocks";
                HtmlGenericControl iZoneBlocks = new HtmlGenericControl( "i" );
                iZoneBlocks.Attributes.Add( "class", "icon-th-large" );
                aBlockConfig.Controls.Add( iZoneBlocks );

                HtmlGenericContainer zoneContent = new HtmlGenericContainer( "div" );
                zoneContent.Attributes.Add( "class", "zone-content" );
                zoneWrapper.Controls.Add( zoneContent );

                parent.Controls.Remove( control );
                zoneContent.Controls.Add( control );
            }
        }
Example #12
0
        /// <summary>
        /// Called by the ASP.NET page framework to notify server controls that use composition-based implementation to create any child controls they contain in preparation for posting back or rendering.
        /// </summary>
        protected override void CreateChildControls()
        {
            base.CreateChildControls();
            Controls.Clear();

            this.CssClass = "picker picker-select";

            _hfLocationId = new HiddenField {
                ID = "hfLocationId"
            };
            this.Controls.Add(_hfLocationId);

            _btnPickerLabel = new HtmlAnchor {
                ID = "btnPickerLabel"
            };
            _btnPickerLabel.Attributes["class"] = "picker-label";
            _btnPickerLabel.InnerHtml           = string.Format("<i class='fa fa-user'></i>{0}<b class='fa fa-caret-down pull-right'></b>", this.AddressSummaryText);
            this.Controls.Add(_btnPickerLabel);

            // PickerMenu (DropDown menu)
            _pnlPickerMenu = new Panel {
                ID = "pnlPickerMenu"
            };
            _pnlPickerMenu.CssClass = "picker-menu dropdown-menu";
            _pnlPickerMenu.Style[HtmlTextWriterStyle.Display] = "none";
            this.Controls.Add(_pnlPickerMenu);
            SetPickerOnClick();

            // Address Entry
            _pnlAddressEntry = new Panel {
                ID = "pnlAddressEntry"
            };
            _pnlAddressEntry.CssClass = "locationpicker-address-entry";
            _pnlPickerMenu.Controls.Add(_pnlAddressEntry);

            _tbAddress1 = new RockTextBox {
                ID = "tbAddress1"
            };
            _tbAddress1.Label = "Address Line 1";
            _pnlAddressEntry.Controls.Add(_tbAddress1);

            _tbAddress2 = new RockTextBox {
                ID = "tbAddress2"
            };
            _tbAddress2.Label = "Address Line 2";
            _pnlAddressEntry.Controls.Add(_tbAddress2);

            // Address Entry - City State Zip
            _divCityStateZipRow = new HtmlGenericContainer("div", "row");
            _pnlAddressEntry.Controls.Add(_divCityStateZipRow);

            _divCityColumn = new HtmlGenericContainer("div", "col-lg-5");
            _divCityStateZipRow.Controls.Add(_divCityColumn);
            _tbCity = new RockTextBox {
                ID = "tbCity"
            };
            _tbCity.Label = "City";
            _divCityColumn.Controls.Add(_tbCity);

            _divStateColumn = new HtmlGenericContainer("div", "col-lg-3");
            _divCityStateZipRow.Controls.Add(_divStateColumn);
            _ddlState = new StateDropDownList {
                ID = "ddlState"
            };
            _ddlState.UseAbbreviation = true;
            _ddlState.CssClass        = "input-mini";
            _ddlState.Label           = "State";
            _divStateColumn.Controls.Add(_ddlState);

            _divZipColumn = new HtmlGenericContainer("div", "col-lg-4");
            _divCityStateZipRow.Controls.Add(_divZipColumn);
            _tbZip = new RockTextBox {
                ID = "tbZip"
            };
            _tbZip.CssClass = "input-small";
            _tbZip.Label    = "Zip";
            _divZipColumn.Controls.Add(_tbZip);

            // picker actions
            _pnlPickerActions = new Panel {
                ID = "pnlPickerActions", CssClass = "picker-actions"
            };
            _pnlPickerMenu.Controls.Add(_pnlPickerActions);
            _btnSelect = new LinkButton {
                ID = "btnSelect", CssClass = "btn btn-xs btn-primary", Text = "Select", CausesValidation = false
            };
            _btnSelect.Click += _btnSelect_Click;
            _pnlPickerActions.Controls.Add(_btnSelect);
            _btnCancel = new LinkButton {
                ID = "btnCancel", CssClass = "btn btn-xs btn-link", Text = "Cancel"
            };
            _btnCancel.OnClientClick = string.Format("$('#{0}').hide();", _pnlPickerMenu.ClientID);
            _pnlPickerActions.Controls.Add(_btnCancel);
        }
Example #13
0
        // Adds the configuration html elements for editing a block
        private void AddBlockConfig( HtmlGenericContainer blockWrapper, Block block, 
            Rock.Web.Cache.BlockInstance blockInstance, bool canConfig, bool canEdit )
        {
            if ( canConfig || canEdit )
            {
                // Add the config buttons
                HtmlGenericControl blockConfig = new HtmlGenericControl( "div" );
                blockConfig.ClientIDMode = ClientIDMode.AutoID;
                blockConfig.Attributes.Add( "class", "block-configuration" );
                blockWrapper.Controls.Add( blockConfig );

                HtmlGenericControl blockConfigLink = new HtmlGenericControl( "a" );
                blockConfigLink.Attributes.Add( "class", "icon-button blockinstance-config" );
                blockConfigLink.Attributes.Add( "href", "#" );
                blockConfig.Controls.Add( blockConfigLink );

                HtmlGenericControl blockConfigBar = new HtmlGenericControl( "div" );
                blockConfigBar.Attributes.Add( "class", "block-configuration-bar" );
                blockConfig.Controls.Add( blockConfigBar );

                HtmlGenericControl blockConfigTitle = new HtmlGenericControl( "span" );
                if (string.IsNullOrWhiteSpace(blockInstance.Name))
                    blockConfigTitle.InnerText = blockInstance.Block.Name;
                else
                    blockConfigTitle.InnerText = blockInstance.Name;
                blockConfigBar.Controls.Add( blockConfigTitle );

                foreach ( Control configControl in block.GetConfigurationControls( canConfig, canEdit ) )
                {
                    configControl.ClientIDMode = ClientIDMode.AutoID;
                    blockConfigBar.Controls.Add( configControl );
                }
            }
        }
Example #14
0
        /// <summary>
        /// Configures the settings.
        /// </summary>
        private void ConfigureSettings()
        {
            // toggle refine search view toggle button
            lbRefineSearch.Visible = GetAttributeValue( "ShowRefinedSearch" ).AsBoolean();

            // model selector
            var enabledModelIds = new List<int>();
            if ( GetAttributeValue( "EnabledModels" ).IsNotNullOrWhitespace() )
            {
                enabledModelIds = GetAttributeValue( "EnabledModels" ).Split( ',' ).Select( int.Parse ).ToList();
            }

            var entities = EntityTypeCache.All();
            var indexableEntities = entities.Where( i => i.IsIndexingSupported == true &&  enabledModelIds.Contains( i.Id )).ToList();

            cblModelFilter.DataTextField = "FriendlyName";
            cblModelFilter.DataValueField = "Id";
            cblModelFilter.DataSource = indexableEntities;
            cblModelFilter.DataBind();

            cblModelFilter.Visible = GetAttributeValue( "ShowFilters" ).AsBoolean();

            // add dynamic filters
            if ( GetAttributeValue( "ShowRefinedSearch" ).AsBoolean() )
            {
                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.RepeatDirection = RepeatDirection.Horizontal;
                        filterConfig.Attributes.Add( "entity-id", entity.Id.ToString() );
                        filterConfig.Attributes.Add( "entity-filter-field", filterOptions.FilterField );
                        filterConfig.DataSource = filterOptions.FilterValues;
                        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 );
                        }
                    }
                }
            }

            // if only one model is selected then hide the type checkbox
            if (cblModelFilter.Items.Count == 1 )
            {
                cblModelFilter.Visible = false;
            }

            ddlSearchType.BindToEnum<SearchType>();
            ddlSearchType.SelectedValue = GetAttributeValue( "SearchType" );

            // override the block setting if passed in the query string
            if ( !string.IsNullOrWhiteSpace( PageParameter( "SearchType" ) ) )
            {
                ddlSearchType.SelectedValue = PageParameter( "SearchType" );
            }

            // set setting values from query string
            if ( !string.IsNullOrWhiteSpace( PageParameter( "Models" ) ) )
            {
                var queryStringModels = PageParameter( "Models" ).Split( ',' ).Select( s => s.Trim() ).ToList();

                foreach ( ListItem item in cblModelFilter.Items )
                {
                    if ( queryStringModels.Contains( item.Value ) )
                    {
                        item.Selected = true;
                    }
                    else
                    {
                        item.Selected = false;
                    }
                }
            }

            if ( !string.IsNullOrWhiteSpace( PageParameter( "ItemsPerPage" ) ) )
            {
                _itemsPerPage = PageParameter( "ItemsPerPage" ).AsInteger();
            }

            if ( !string.IsNullOrWhiteSpace( PageParameter( "CurrentPage" ) ) )
            {
                _currentPageNum = PageParameter( "CurrentPage" ).AsInteger();
            }

            if ( !string.IsNullOrWhiteSpace( PageParameter( "RefinedSearch" ) ) )
            {
                pnlRefineSearch.Visible = PageParameter( "RefinedSearch" ).AsBoolean();

                if ( pnlRefineSearch.Visible )
                {
                    lbRefineSearch.Text = "Hide Refined Search";
                }
            }

            _itemsPerPage = GetAttributeValue( "ResultsPerPage" ).AsInteger();
        }
Example #15
0
        /// <summary>
        /// Loads all of the configured blocks for the current page into the control tree
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit( EventArgs e )
        {
            // Add the ScriptManager to each page
            _scriptManager = ScriptManager.GetCurrent( this.Page );

            if ( _scriptManager == null )
            {
                _scriptManager = new AjaxControlToolkit.ToolkitScriptManager { ID = "sManager" };
                Page.Trace.Warn( "Adding script manager" );
                Page.Form.Controls.AddAt( 0, _scriptManager );
            }

            // enable history on the ScriptManager
            _scriptManager.EnableHistory = true;

            // TODO: Delete this line, only used for testing
            _scriptManager.AsyncPostBackTimeout = 180;

            // wire up navigation event
            _scriptManager.Navigate += new EventHandler<HistoryEventArgs>( scriptManager_Navigate );

            // add ckeditor (doesn't like to be added during an async postback)
            _scriptManager.Scripts.Add( new ScriptReference( ResolveRockUrl( "~/Scripts/ckeditor/ckeditor.js", true ) ) );

            // Add library and UI bundles during init, that way theme developers will only
            // need to worry about registering any custom scripts or script bundles they need
            _scriptManager.Scripts.Add( new ScriptReference( "~/Bundles/WebFormsJs" ) );
            _scriptManager.Scripts.Add( new ScriptReference( "~/Scripts/Bundles/RockLibs" ) );
            _scriptManager.Scripts.Add( new ScriptReference( "~/Scripts/Bundles/RockUi" ) );
            _scriptManager.Scripts.Add( new ScriptReference( "~/Scripts/Bundles/RockValidation" ) );

            // add Google Maps API (doesn't like to be added during an async postback )
            var googleAPIKey = GlobalAttributesCache.Read().GetValue( "GoogleAPIKey" );
            string keyParameter = string.IsNullOrWhiteSpace(googleAPIKey) ? "" : string.Format("key={0}&", googleAPIKey);
            _scriptManager.Scripts.Add( new ScriptReference( string.Format( "https://maps.googleapis.com/maps/api/js?{0}sensor=false&libraries=drawing", keyParameter ) ) );

            // Recurse the page controls to find the rock page title and zone controls
            Page.Trace.Warn( "Recursing layout to find zones" );
            Zones = new Dictionary<string, KeyValuePair<string, Zone>>();
            FindRockControls( this.Controls );

            // Add a Rock version meta tag
            Page.Trace.Warn( "Adding Rock metatag" );
            string version = typeof( Rock.Web.UI.RockPage ).Assembly.GetName().Version.ToString();
            HtmlMeta rockVersion = new HtmlMeta();
            rockVersion.Attributes.Add( "name", "generator" );
            rockVersion.Attributes.Add( "content", string.Format( "Rock v{0}", version ) );
            AddMetaTag( this.Page, rockVersion );

            // If the logout parameter was entered, delete the user's forms authentication cookie and redirect them
            // back to the same page.
            Page.Trace.Warn( "Checking for logout request" );
            if ( PageParameter( "logout" ) != string.Empty )
            {
                if ( CurrentUser != null )
                {
                    var transaction = new Rock.Transactions.UserLastActivityTransaction();
                    transaction.UserId = CurrentUser.Id;
                    transaction.LastActivityDate = RockDateTime.Now;
                    transaction.IsOnLine = false;
                    Rock.Transactions.RockQueue.TransactionQueue.Enqueue( transaction );
                }

                FormsAuthentication.SignOut();

                // After logging out check to see if an anonymous user is allowed to view the current page.  If so
                // redirect back to the current page, otherwise redirect to the site's default page
                if ( _pageCache != null )
                {
                    if ( _pageCache.IsAuthorized( Authorization.VIEW, null ) )
                    {
                        // Remove the 'logout' queryparam before redirecting
                        var pageReference = new PageReference( PageReference.PageId, PageReference.RouteId, PageReference.Parameters );
                        foreach ( string key in PageReference.QueryString )
                        {
                            if ( !key.Equals( "logout", StringComparison.OrdinalIgnoreCase ) )
                            {
                                pageReference.Parameters.Add( key, PageReference.QueryString[key] );
                            }
                        }
                        Response.Redirect( pageReference.BuildUrl(), false );
                        Context.ApplicationInstance.CompleteRequest();
                    }
                    else
                    {
                        _pageCache.Layout.Site.RedirectToDefaultPage();
                    }
                    return;
                }
                else
                {
                    CurrentPerson = null;
                    CurrentUser = null;
                }
            }

            var rockContext = new RockContext();

            // If the impersonated query key was included then set the current person
            Page.Trace.Warn( "Checking for person impersanation" );
            string impersonatedPersonKey = PageParameter( "rckipid" );
            if ( !String.IsNullOrEmpty( impersonatedPersonKey ) )
            {
                Rock.Model.PersonService personService = new Model.PersonService( rockContext );
                Rock.Model.Person impersonatedPerson = personService.GetByEncryptedKey( impersonatedPersonKey );
                if ( impersonatedPerson != null )
                {
                    Rock.Security.Authorization.SetAuthCookie( "rckipid=" + impersonatedPerson.EncryptedKey, false, true );
                    CurrentUser = impersonatedPerson.GetImpersonatedUser();
                }
            }

            // Get current user/person info
            Page.Trace.Warn( "Getting CurrentUser" );
            Rock.Model.UserLogin user = CurrentUser;

            // If there is a logged in user, see if it has an associated Person Record.  If so, set the UserName to
            // the person's full name (which is then cached in the Session state for future page requests)
            if ( user != null )
            {
                Page.Trace.Warn( "Setting CurrentPerson" );
                UserName = user.UserName;
                int? personId = user.PersonId;

                if ( personId.HasValue )
                {
                    string personNameKey = "PersonName_" + personId.Value.ToString();
                    if ( Session[personNameKey] != null )
                    {
                        UserName = Session[personNameKey].ToString();
                    }
                    else
                    {
                        Rock.Model.PersonService personService = new Model.PersonService( rockContext );
                        Rock.Model.Person person = personService.Get( personId.Value );
                        if ( person != null )
                        {
                            UserName = person.FullName;
                            CurrentPerson = person;
                        }

                        Session[personNameKey] = UserName;
                    }
                }
            }

            // If a PageInstance exists
            if ( _pageCache != null )
            {
                BrowserTitle = _pageCache.BrowserTitle;
                PageTitle = _pageCache.PageTitle;
                PageIcon = _pageCache.IconCssClass;

                // If there's a master page, update it's reference to Current Page
                if ( this.Master is RockMasterPage )
                {
                    ( (RockMasterPage)this.Master ).SetPage( _pageCache );
                }

                // check if page should have been loaded via ssl
                Page.Trace.Warn( "Checking for SSL request" );
                if ( !Request.IsSecureConnection && _pageCache.RequiresEncryption )
                {
                    string redirectUrl = Request.Url.ToString().Replace( "http:", "https:" );
                    Response.Redirect( redirectUrl, false );
                    Context.ApplicationInstance.CompleteRequest();
                    return;
                }

                // Verify that the current user is allowed to view the page.
                Page.Trace.Warn( "Checking if user is authorized" );
                if ( !_pageCache.IsAuthorized( Authorization.VIEW, CurrentPerson ) )
                {
                    if ( user == null )
                    {
                        // If not authorized, and the user hasn't logged in yet, redirect to the login page
                        Page.Trace.Warn( "Redirecting to login page" );

                        var site = _pageCache.Layout.Site;
                        if ( site.LoginPageId.HasValue )
                        {
                            site.RedirectToLoginPage( true );
                        }
                        else
                        {
                            FormsAuthentication.RedirectToLoginPage();
                        }
                    }
                    else
                    {
                        // If not authorized, and the user has logged in, redirect to error page
                        Page.Trace.Warn( "Redirecting to error page" );

                        Response.Redirect( "~/error.aspx?type=security", false );
                        Context.ApplicationInstance.CompleteRequest();
                    }
                }
                else
                {
                    // Set current models (context)
                    Page.Trace.Warn( "Checking for Context" );
                    ModelContext = new Dictionary<string, Data.KeyEntity>();
                    try
                    {

                        // first search cookies, but pageContext can replace it
                        GetCookieContext( GetContextCookieName( false ) );      // Site
                        GetCookieContext( GetContextCookieName( true ) );       // Page (will replace any site values)

                        foreach ( var pageContext in _pageCache.PageContexts )
                        {
                            int? contextId = PageParameter( pageContext.Value ).AsIntegerOrNull();
                            if ( contextId.HasValue )
                            {
                                ModelContext.AddOrReplace( pageContext.Key, new Data.KeyEntity( contextId.Value ) );
                            }
                        }

                        char[] delim = new char[1] { ',' };
                        foreach ( string param in PageParameter( "context", true ).Split( delim, StringSplitOptions.RemoveEmptyEntries ) )
                        {
                            string contextItem = Rock.Security.Encryption.DecryptString( param );
                            string[] parts = contextItem.Split( '|' );
                            if ( parts.Length == 2 )
                            {
                                ModelContext.AddOrReplace( parts[0], new Data.KeyEntity( parts[1] ) );
                            }
                        }

                    }
                    catch
                    {
                        // intentionally ignore exception
                    }

                    // set viewstate on/off
                    this.EnableViewState = _pageCache.EnableViewState;

                    // Cache object used for block output caching
                    Page.Trace.Warn( "Getting memory cache" );
                    ObjectCache cache = MemoryCache.Default;

                    Page.Trace.Warn( "Checking if user can administer" );
                    bool canAdministratePage = _pageCache.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );

                    // Create a javascript object to store information about the current page for client side scripts to use
                    Page.Trace.Warn( "Creating JS objects" );
                    string script = string.Format( @"
            Rock.settings.initialize({{
            siteId: {0},
            layoutId: {1},
            pageId: {2},
            layout: '{3}',
            baseUrl: '{4}'
            }});",
                        _pageCache.Layout.SiteId, _pageCache.LayoutId, _pageCache.Id, _pageCache.Layout.FileName, ResolveUrl( "~" ) );
                    ScriptManager.RegisterStartupScript( this.Page, this.GetType(), "rock-js-object", script, true );

                    AddTriggerPanel();

                    // Add config elements
                    if ( _pageCache.IncludeAdminFooter )
                    {
                        Page.Trace.Warn( "Adding popup controls (footer elements)" );
                        AddPopupControls();

                        Page.Trace.Warn( "Adding zone elements" );
                        AddZoneElements( canAdministratePage );
                    }

                    // Initialize the list of breadcrumbs for the current page (and blocks on the page)
                    Page.Trace.Warn( "Setting breadcrumbs" );
                    PageReference.BreadCrumbs = new List<BreadCrumb>();

                    // If the page is configured to display in the breadcrumbs...
                    string bcName = _pageCache.BreadCrumbText;
                    if ( bcName != string.Empty )
                    {
                        PageReference.BreadCrumbs.Add( new BreadCrumb( bcName, PageReference.BuildUrl() ) );
                    }

                    // Add the Google Analytics Code script if a code was specified for the site
                    if ( !string.IsNullOrWhiteSpace( _pageCache.Layout.Site.GoogleAnalyticsCode ) )
                    {
                        AddGoogleAnalytics( _pageCache.Layout.Site.GoogleAnalyticsCode );
                    }

                    // Flag indicating if user has rights to administer one or more of the blocks on page
                    bool canAdministrateBlock = false;

                    // Load the blocks and insert them into page zones
                    Page.Trace.Warn( "Loading Blocks" );
                    foreach ( Rock.Web.Cache.BlockCache block in _pageCache.Blocks )
                    {
                        Page.Trace.Warn( string.Format( "\tLoading '{0}' block", block.Name ) );

                        // Get current user's permissions for the block instance
                        Page.Trace.Warn( "\tChecking permission" );
                        bool canAdministrate = block.IsAuthorized( Authorization.ADMINISTRATE, CurrentPerson );
                        bool canEdit = block.IsAuthorized( Authorization.EDIT, CurrentPerson );
                        bool canView = block.IsAuthorized( Authorization.VIEW, CurrentPerson );

                        if ( canAdministrate || canEdit )
                        {
                            canAdministrateBlock = true;
                        }

                        // Make sure user has access to view block instance
                        if ( canAdministrate || canEdit || canView )
                        {
                            // Create block wrapper control (implements INamingContainer so child control IDs are unique for
                            // each block instance
                            Page.Trace.Warn( "\tAdding block wrapper html" );

                            HtmlGenericContainer blockWrapper = new HtmlGenericContainer( "div" );
                            blockWrapper.ID = string.Format( "bid_{0}", block.Id );
                            blockWrapper.Attributes.Add( "data-zone-location", block.BlockLocation.ToString() );
                            blockWrapper.ClientIDMode = ClientIDMode.Static;
                            FindZone( block.Zone ).Controls.Add( blockWrapper );

                            string blockTypeCss = block.BlockType != null ? block.BlockType.Name : "";
                            var parts = blockTypeCss.Split( new char[] { '>' } );
                            if ( parts.Length > 1 )
                            {
                                blockTypeCss = parts[parts.Length - 1].Trim();
                            }
                            blockTypeCss = blockTypeCss.Replace( ' ', '-' ).ToLower();

                            blockWrapper.Attributes.Add( "class", "block-instance " + blockTypeCss +
                                ( string.IsNullOrWhiteSpace( block.CssClass ) ? "" : " " + block.CssClass.Trim() ) +
                                ( canAdministrate || canEdit ? " can-configure " : "" ) );

                            // Check to see if block is configured to use a "Cache Duration'
                            string blockCacheKey = string.Format( "Rock:BlockOutput:{0}", block.Id );
                            if ( block.OutputCacheDuration > 0 && cache.Contains( blockCacheKey ) )
                            {
                                // If the current block exists in our custom output cache, add the cached output instead of adding the control
                                blockWrapper.Controls.Add( new LiteralControl( cache[blockCacheKey] as string ) );
                            }
                            else
                            {
                                // Load the control and add to the control tree
                                Page.Trace.Warn( "\tLoading control" );
                                Control control;

                                try
                                {
                                    control = TemplateControl.LoadControl( block.BlockType.Path );
                                    control.ClientIDMode = ClientIDMode.AutoID;
                                }
                                catch ( Exception ex )
                                {
                                    NotificationBox nbBlockLoad = new NotificationBox();
                                    nbBlockLoad.ID = string.Format( "nbBlockLoad_{0}", block.Id );
                                    nbBlockLoad.CssClass = "system-error";
                                    nbBlockLoad.NotificationBoxType = NotificationBoxType.Danger;
                                    nbBlockLoad.Text = string.Format( "Error Loading Block: {0}", block.Name );
                                    nbBlockLoad.Details = string.Format( "{0}<pre>{1}</pre>", ex.Message, ex.StackTrace );
                                    nbBlockLoad.Dismissable = true;
                                    control = nbBlockLoad;

                                    if ( this.IsPostBack )
                                    {
                                        // throw an error on PostBack so that the ErrorPage gets shown (vs nothing happening)
                                        throw ex;
                                    }
                                }

                                RockBlock blockControl = null;

                                // Check to see if the control was a PartialCachingControl or not
                                Page.Trace.Warn( "\tChecking block for partial caching" );
                                if ( control is RockBlock )
                                    blockControl = control as RockBlock;
                                else
                                {
                                    if ( control is PartialCachingControl && ( (PartialCachingControl)control ).CachedControl != null )
                                    {
                                        blockControl = (RockBlock)( (PartialCachingControl)control ).CachedControl;
                                    }
                                }

                                // If the current control is a block, set it's properties
                                if ( blockControl != null )
                                {
                                    Page.Trace.Warn( "\tSetting block properties" );

                                    blockControl.SetBlock( block );

                                    // Add any breadcrumbs to current page reference that the block creates
                                    Page.Trace.Warn( "\tAdding any breadcrumbs from block" );
                                    if ( block.BlockLocation == BlockLocation.Page )
                                    {
                                        blockControl.GetBreadCrumbs( PageReference ).ForEach( c => PageReference.BreadCrumbs.Add( c ) );
                                    }

                                    // If the blocktype's security actions have not yet been loaded, load them now
                                    if ( !block.BlockType.CheckedSecurityActions )
                                    {
                                        Page.Trace.Warn( "\tAdding additional security actions for blcok" );
                                        block.BlockType.SecurityActions = new Dictionary<string, string>();
                                        foreach ( var action in blockControl.GetSecurityActionAttributes() )
                                        {
                                            if ( block.BlockType.SecurityActions.ContainsKey( action.Key ) )
                                            {
                                                block.BlockType.SecurityActions[action.Key] = action.Value;
                                            }
                                            else
                                            {
                                                block.BlockType.SecurityActions.Add( action.Key, action.Value );
                                            }
                                        }
                                        block.BlockType.CheckedSecurityActions = true;
                                    }

                                    // If the block's AttributeProperty values have not yet been verified verify them.
                                    // (This provides a mechanism for block developers to define the needed block
                                    //  attributes in code and have them automatically added to the database)
                                    Page.Trace.Warn( "\tChecking if block attributes need refresh" );
                                    if ( !block.BlockType.IsInstancePropertiesVerified )
                                    {
                                        Page.Trace.Warn( "\tCreating block attributes" );
                                        blockControl.CreateAttributes( rockContext );
                                        block.BlockType.IsInstancePropertiesVerified = true;
                                    }

                                    // Add the block configuration scripts and icons if user is authorized
                                    if ( _pageCache.IncludeAdminFooter )
                                    {
                                        Page.Trace.Warn( "\tAdding block configuration tools" );
                                        AddBlockConfig( blockWrapper, blockControl, block, canAdministrate, canEdit );
                                    }
                                }

                                Page.Trace.Warn( "\tAdding block to control tree" );
                                HtmlGenericContainer blockContent = new HtmlGenericContainer( "div" );
                                blockContent.Attributes.Add( "class", "block-content" );
                                blockWrapper.Controls.Add( blockContent );

                                // Add the block
                                blockContent.Controls.Add( control );
                            }
                        }
                    }

                    // Make the last crumb for this page the active one
                    Page.Trace.Warn( "Setting active breadcrumb" );
                    if ( PageReference.BreadCrumbs.Any() )
                    {
                        PageReference.BreadCrumbs.Last().Active = true;
                    }

                    Page.Trace.Warn( "Getting parent page references" );
                    var pageReferences = PageReference.GetParentPageReferences( this, _pageCache, PageReference );
                    pageReferences.Add( PageReference );
                    PageReference.SavePageReferences( pageReferences );

                    // Update breadcrumbs
                    Page.Trace.Warn( "Updating breadcrumbs" );
                    BreadCrumbs = new List<BreadCrumb>();
                    foreach ( var pageReference in pageReferences )
                    {
                        pageReference.BreadCrumbs.ForEach( c => BreadCrumbs.Add( c ) );
                    }

                    // Add the page admin footer if the user is authorized to edit the page
                    if ( _pageCache.IncludeAdminFooter && ( canAdministratePage || canAdministrateBlock ) )
                    {
                        // Add the page admin script
                        AddScriptLink( Page, "~/Scripts/Bundles/RockAdmin", false );

                        Page.Trace.Warn( "Adding admin footer to page" );
                        HtmlGenericControl adminFooter = new HtmlGenericControl( "div" );
                        adminFooter.ID = "cms-admin-footer";
                        adminFooter.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                        this.Form.Controls.Add( adminFooter );

                        phLoadTime = new PlaceHolder();
                        adminFooter.Controls.Add( phLoadTime );

                        HtmlGenericControl buttonBar = new HtmlGenericControl( "div" );
                        adminFooter.Controls.Add( buttonBar );
                        buttonBar.Attributes.Add( "class", "button-bar" );

                        // RockBlock Config
                        HtmlGenericControl aBlockConfig = new HtmlGenericControl( "a" );
                        buttonBar.Controls.Add( aBlockConfig );
                        aBlockConfig.Attributes.Add( "class", "btn block-config" );
                        aBlockConfig.Attributes.Add( "href", "javascript: Rock.admin.pageAdmin.showBlockConfig();" );
                        aBlockConfig.Attributes.Add( "Title", "Block Configuration" );
                        HtmlGenericControl iBlockConfig = new HtmlGenericControl( "i" );
                        aBlockConfig.Controls.Add( iBlockConfig );
                        iBlockConfig.Attributes.Add( "class", "fa fa-th-large" );

                        if ( canAdministratePage )
                        {
                            // RockPage Properties
                            HtmlGenericControl aAttributes = new HtmlGenericControl( "a" );
                            buttonBar.Controls.Add( aAttributes );
                            aAttributes.ID = "aPageProperties";
                            aAttributes.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                            aAttributes.Attributes.Add( "class", "btn properties" );
                            aAttributes.Attributes.Add( "height", "500px" );
                            aAttributes.Attributes.Add( "href", "javascript: Rock.controls.modal.show($(this), '" + ResolveUrl( string.Format( "~/PageProperties/{0}?t=Page Properties", _pageCache.Id ) ) + "')" );
                            aAttributes.Attributes.Add( "Title", "Page Properties" );
                            HtmlGenericControl iAttributes = new HtmlGenericControl( "i" );
                            aAttributes.Controls.Add( iAttributes );
                            iAttributes.Attributes.Add( "class", "fa fa-cog" );

                            // Child Pages
                            HtmlGenericControl aChildPages = new HtmlGenericControl( "a" );
                            buttonBar.Controls.Add( aChildPages );
                            aChildPages.ID = "aChildPages";
                            aChildPages.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                            aChildPages.Attributes.Add( "class", "btn page-child-pages" );
                            aChildPages.Attributes.Add( "height", "500px" );
                            aChildPages.Attributes.Add( "href", "javascript: Rock.controls.modal.show($(this), '" + ResolveUrl( string.Format( "~/pages/{0}?t=Child Pages&pb=&sb=Done", _pageCache.Id ) ) + "')" );
                            aChildPages.Attributes.Add( "Title", "Child Pages" );
                            HtmlGenericControl iChildPages = new HtmlGenericControl( "i" );
                            aChildPages.Controls.Add( iChildPages );
                            iChildPages.Attributes.Add( "class", "fa fa-sitemap" );

                            // RockPage Zones
                            HtmlGenericControl aPageZones = new HtmlGenericControl( "a" );
                            buttonBar.Controls.Add( aPageZones );
                            aPageZones.Attributes.Add( "class", "btn page-zones" );
                            aPageZones.Attributes.Add( "href", "javascript: Rock.admin.pageAdmin.showPageZones();" );
                            aPageZones.Attributes.Add( "Title", "Page Zones" );
                            HtmlGenericControl iPageZones = new HtmlGenericControl( "i" );
                            aPageZones.Controls.Add( iPageZones );
                            iPageZones.Attributes.Add( "class", "fa fa-columns" );

                            // RockPage Security
                            HtmlGenericControl aPageSecurity = new HtmlGenericControl( "a" );
                            buttonBar.Controls.Add( aPageSecurity );
                            aPageSecurity.ID = "aPageSecurity";
                            aPageSecurity.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                            aPageSecurity.Attributes.Add( "class", "btn page-security" );
                            aPageSecurity.Attributes.Add( "height", "500px" );
                            aPageSecurity.Attributes.Add( "href", "javascript: Rock.controls.modal.show($(this), '" + ResolveUrl( string.Format( "~/Secure/{0}/{1}?t=Page Security&pb=&sb=Done",
                                EntityTypeCache.Read( typeof( Rock.Model.Page ) ).Id, _pageCache.Id ) ) + "')" );
                            aPageSecurity.Attributes.Add( "Title", "Page Security" );
                            HtmlGenericControl iPageSecurity = new HtmlGenericControl( "i" );
                            aPageSecurity.Controls.Add( iPageSecurity );
                            iPageSecurity.Attributes.Add( "class", "fa fa-lock" );

                            // System Info
                            HtmlGenericControl aSystemInfo = new HtmlGenericControl( "a" );
                            buttonBar.Controls.Add( aSystemInfo );
                            aSystemInfo.ID = "aSystemInfo";
                            aSystemInfo.ClientIDMode = System.Web.UI.ClientIDMode.Static;
                            aSystemInfo.Attributes.Add( "class", "btn system-info" );
                            aSystemInfo.Attributes.Add( "height", "500px" );
                            aSystemInfo.Attributes.Add( "href", "javascript: Rock.controls.modal.show($(this), '" + ResolveUrl( "~/SystemInfo?t=System Information&pb=&sb=Done" ) + "')" );
                            aSystemInfo.Attributes.Add( "Title", "Rock Information" );
                            HtmlGenericControl iSystemInfo = new HtmlGenericControl( "i" );
                            aSystemInfo.Controls.Add( iSystemInfo );
                            iSystemInfo.Attributes.Add( "class", "fa fa-info-circle" );
                        }
                    }

                    // Check to see if page output should be cached.  The RockRouteHandler
                    // saves the PageCacheData information for the current page to memorycache
                    // so it should always exist
                    if ( _pageCache.OutputCacheDuration > 0 )
                    {
                        Response.Cache.SetCacheability( System.Web.HttpCacheability.Public );
                        Response.Cache.SetExpires( RockDateTime.Now.AddSeconds( _pageCache.OutputCacheDuration ) );
                        Response.Cache.SetValidUntilExpires( true );
                    }
                }

                string pageTitle = BrowserTitle;
                string siteTitle = _pageCache.Layout.Site.Name;
                string seperator = pageTitle.Trim() != string.Empty && siteTitle.Trim() != string.Empty ? " | " : "";

                base.Title = pageTitle + seperator + siteTitle;

                if ( !string.IsNullOrWhiteSpace( _pageCache.Description ) )
                {
                    HtmlMeta metaTag = new HtmlMeta();
                    metaTag.Attributes.Add( "name", "description" );
                    metaTag.Attributes.Add( "content", _pageCache.Description.Trim() );
                    AddMetaTag( this.Page, metaTag );
                }

                if ( !string.IsNullOrWhiteSpace( _pageCache.KeyWords ) )
                {
                    HtmlMeta metaTag = new HtmlMeta();
                    metaTag.Attributes.Add( "name", "keywords" );
                    metaTag.Attributes.Add( "content", _pageCache.KeyWords.Trim() );
                    AddMetaTag( this.Page, metaTag );
                }

                if ( !string.IsNullOrWhiteSpace( _pageCache.HeaderContent ) )
                {
                    Page.Header.Controls.Add( new LiteralControl( _pageCache.HeaderContent ) );
                }
            }
        }
        /// <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 )
        {
            var cell = container as DataControlFieldCell;
            if ( cell != null )
            {
                var mergeField = cell.ContainingField as PersonMergeField;
                if ( mergeField != null )
                {
                    var lbDelete = new LinkButton();
                    lbDelete.CausesValidation = false;
                    lbDelete.CssClass = "btn btn-danger btn-xs pull-right";
                    lbDelete.ToolTip = "Remove Person";
                    cell.Controls.Add( lbDelete );

                    HtmlGenericControl buttonIcon = new HtmlGenericControl( "i" );
                    buttonIcon.Attributes.Add( "class", "fa fa-times" );
                    lbDelete.Controls.Add( buttonIcon );

                    lbDelete.Click += lbDelete_Click;

                    // make sure delete button is registered for async postback (needed just in case the grid was created at runtime)
                    var sm = ScriptManager.GetCurrent( mergeField.ParentGrid.Page );
                    sm.RegisterAsyncPostBackControl( lbDelete );

                    HtmlGenericContainer headerSummary = new HtmlGenericContainer( "div", "merge-header-summary" );
                    headerSummary.Attributes.Add( "data-col", mergeField.ColumnIndex.ToString() );

                    var i = new HtmlGenericControl( "i" );
                    i.Attributes.Add( "class", "fa fa-2x " + ( mergeField.IsPrimaryPerson ? "fa-check-square-o" : "fa-square-o" ) );
                    headerSummary.Controls.Add( i );

                    headerSummary.Controls.Add(new LiteralControl(mergeField.HeaderContent));

                    string created = (mergeField.ModifiedDateTime.HasValue ? mergeField.ModifiedDateTime.ToElapsedString() + " " : "") +
                        (!string.IsNullOrWhiteSpace(mergeField.ModifiedBy) ? "by " + mergeField.ModifiedBy : "");
                    if ( created != string.Empty )
                    {
                        headerSummary.Controls.Add(new LiteralControl(string.Format("<small>Last Modifed {0}</small>", created)));
                    }

                    cell.Controls.Add(headerSummary);
                }
            }
        }
Example #17
0
        // Adds the configuration html elements for editing a block
        /// <summary>
        /// Adds the block config.
        /// </summary>
        /// <param name="blockWrapper">A <see cref="Rock.Web.UI.Controls.HtmlGenericContainer"/> representing the block wrapper.</param>
        /// <param name="blockControl">The <see cref="Rock.Web.UI.RockBlock">block</see> control.</param>
        /// <param name="block">The block.</param>
        /// <param name="canAdministrate">
        ///     A <see cref="System.Boolean"/> value that is <c>true</c> if the block can be administered/configured; otherwise <c>false</c>.
        /// </param>
        /// <param name="canEdit">A <see cref="System.Boolean"/> that is <c>true</c> if the block can be edited; otherwise <c>false</c>.</param>
        private void AddBlockConfig( HtmlGenericContainer blockWrapper, RockBlock blockControl,
            Rock.Web.Cache.BlockCache block, bool canAdministrate, bool canEdit )
        {
            if ( canAdministrate || canEdit )
            {
                // Add the config buttons
                HtmlGenericControl blockConfig = new HtmlGenericControl( "div" );
                blockConfig.ClientIDMode = ClientIDMode.AutoID;
                blockConfig.Attributes.Add( "class", "block-configuration config-bar" );
                blockWrapper.Controls.Add( blockConfig );

                HtmlGenericControl blockConfigLink = new HtmlGenericControl( "a" );
                blockConfigLink.Attributes.Add( "href", "#" );
                HtmlGenericControl iBlockConfig = new HtmlGenericControl( "i" );
                iBlockConfig.Attributes.Add( "class", "fa fa-arrow-circle-right" );
                blockConfigLink.Controls.Add( iBlockConfig );
                blockConfig.Controls.Add( blockConfigLink );

                HtmlGenericControl blockConfigBar = new HtmlGenericControl( "div" );
                blockConfigBar.Attributes.Add( "class", "block-configuration-bar" );
                blockConfig.Controls.Add( blockConfigBar );

                HtmlGenericControl blockConfigTitle = new HtmlGenericControl( "span" );
                if ( string.IsNullOrWhiteSpace( block.Name ) )
                    blockConfigTitle.InnerText = block.BlockType.Name;
                else
                    blockConfigTitle.InnerText = block.Name;
                blockConfigBar.Controls.Add( blockConfigTitle );

                foreach ( Control configControl in blockControl.GetAdministrateControls( canAdministrate, canEdit ) )
                {
                    configControl.ClientIDMode = ClientIDMode.AutoID;
                    blockConfigBar.Controls.Add( configControl );
                }
            }
        }
        /// <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 );
                }
            }
        }
Example #19
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)
        {
            HtmlGenericControl divPagination = new HtmlGenericControl("div");

            divPagination.Attributes.Add("class", "pagination");
            container.Controls.Add(divPagination);

            // Page Status
            //HtmlGenericControl divStatus = new HtmlGenericControl( "div" );
            //divStatus.Attributes.Add( "class", "page-status" );
            //divPagination.Controls.Add( divStatus );

            //lStatus = new Literal();
            //divStatus.Controls.Add( lStatus );

            // Pagination
            NavigationPanel = new HtmlGenericControl("div");
            NavigationPanel.Attributes.Add("class", "page-navigation");
            divPagination.Controls.Add(NavigationPanel);

            HtmlGenericControl ulNavigation = new HtmlGenericControl("ul");

            NavigationPanel.Controls.Add(ulNavigation);

            for (var i = 0; i < PageLinkListItem.Length; i++)
            {
                PageLinkListItem[i] = new HtmlGenericContainer("li");
                ulNavigation.Controls.Add(PageLinkListItem[i]);

                PageLink[i] = new LinkButton();
                PageLinkListItem[i].Controls.Add(PageLink[i]);
                PageLink[i].Click += new EventHandler(lbPage_Click);
            }

            PageLink[0].Text = "&larr; Previous";
            PageLink[PageLinkListItem.Length - 1].Text = "Next &rarr;";

            // Items Per Page
            HtmlGenericControl divSize = new HtmlGenericControl("div");

            divSize.Attributes.Add("class", "page-size");
            divPagination.Controls.Add(divSize);

            Label lblPageSize = new Label();

            lblPageSize.Text = "Items per page:";
            divSize.Controls.Add(lblPageSize);

            HtmlGenericControl divSizeOptions = new HtmlGenericControl("div");

            divSizeOptions.Attributes.Add("class", "page-size-options");
            divSize.Controls.Add(divSizeOptions);

            HtmlGenericControl ulSizeOptions = new HtmlGenericControl("ul");

            divSizeOptions.Controls.Add(ulSizeOptions);

            for (int i = 0; i < ItemLinkListItem.Length; i++)
            {
                ItemLinkListItem[i] = new HtmlGenericContainer("li");
                ulSizeOptions.Controls.Add(ItemLinkListItem[i]);

                ItemLink[i] = new LinkButton();
                ItemLinkListItem[i].Controls.Add(ItemLink[i]);
                ItemLink[i].Click += new EventHandler(lbItems_Click);
            }

            ItemLink[0].Text = "25";
            ItemLink[1].Text = "100";
            ItemLink[2].Text = "1,000";
            ItemLink[3].Text = "All";
        }