Пример #1
0
        /// <summary>
        /// Loads the block types.
        /// </summary>
        private void LoadBlockTypes(bool registerBlockTypes)
        {
            if (registerBlockTypes)
            {
                // Add any unregistered blocks
                try
                {
                    BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page);
                }
                catch (Exception ex)
                {
                    nbMessage.Text    = "Error registering one or more block types";
                    nbMessage.Details = ex.Message + "<code>" + HttpUtility.HtmlEncode(ex.StackTrace) + "</code>";
                    nbMessage.Visible = true;
                }
            }

            // Get a list of BlockTypes that does not include Mobile block types.
            var allExceptMobileBlockTypes = BlockTypeCache.All();

            foreach (var cachedBlockType in BlockTypeCache.All().Where(b => string.IsNullOrEmpty(b.Path)))
            {
                try
                {
                    var blockCompiledType = cachedBlockType.GetCompiledType();

                    if (typeof(Rock.Blocks.IRockMobileBlockType).IsAssignableFrom(blockCompiledType))
                    {
                        allExceptMobileBlockTypes.Remove(cachedBlockType);
                    }
                }
                catch (Exception)
                {
                    // Intentionally ignored
                }
            }

            var blockTypes = allExceptMobileBlockTypes.Select(b => new { b.Id, b.Name, b.Category, b.Description }).ToList();

            ddlBlockType.Items.Clear();

            // Add the categorized block types
            foreach (var blockType in blockTypes.Where(b => b.Category != "").OrderBy(b => b.Category).ThenBy(b => b.Name))
            {
                var li = new ListItem(blockType.Name, blockType.Id.ToString());
                li.Attributes.Add("optiongroup", blockType.Category);
                li.Attributes.Add("title", blockType.Description);
                ddlBlockType.Items.Add(li);
            }

            // Add the uncategorized block types
            foreach (var blockType in blockTypes.Where(b => b.Category == null || b.Category == "").OrderBy(b => b.Name))
            {
                var li = new ListItem(blockType.Name, blockType.Id.ToString());
                li.Attributes.Add("optiongroup", "Other (not categorized)");
                li.Attributes.Add("title", blockType.Description);
                ddlBlockType.Items.Add(li);
            }
        }
Пример #2
0
        /// <summary>
        /// Binds the block type repeater.
        /// </summary>
        private void BindBlockTypeRepeater()
        {
            var items = new List <ComponentItem>();

            //
            // Find all mobile block types and build the component repeater.
            //
            var blockTypes = BlockTypeCache.All()
                             .Where(t => t.Category == ddlBlockTypeCategory.SelectedValue)
                             .OrderBy(t => t.Name);

            foreach (var blockType in blockTypes)
            {
                try
                {
                    var blockCompiledType = blockType.GetCompiledType();

                    if (!typeof(Rock.Blocks.IRockMobileBlockType).IsAssignableFrom(blockCompiledType))
                    {
                        continue;
                    }

                    var iconCssClassAttribute = ( IconCssClassAttribute )blockCompiledType.GetCustomAttribute(typeof(IconCssClassAttribute));

                    var item = new ComponentItem
                    {
                        IconCssClass = iconCssClassAttribute != null ? iconCssClassAttribute.IconCssClass : "fa fa-question",
                        Name         = blockType.Name,
                        Id           = blockType.Id
                    };

                    items.Add(item);
                }
                catch
                {
                    /* Intentionally ignored. */
                }
            }

            ComponentItemState        = items;
            rptrBlockTypes.DataSource = ComponentItemState;
            rptrBlockTypes.DataBind();
        }
Пример #3
0
        /// <summary>
        /// Shows the detail information on the page.
        /// </summary>
        /// <param name="pageId">The page identifier.</param>
        private void ShowDetail(int pageId)
        {
            var page = PageCache.Get(pageId);

            pnlEditPage.Visible = false;

            //
            // Ensure the page exists.
            //
            if (page == null)
            {
                nbError.Text = "This page does not exist in the system.";

                pnlDetails.Visible = false;
                pnlBlocks.Visible  = false;

                return;
            }

            //
            // Configure Copy Page Guid
            //
            RockPage.AddScriptLink(this.Page, "~/Scripts/clipboard.js/clipboard.min.js");
            string script = string.Format(@"
    new ClipboardJS('#{0}');
    $('#{0}').tooltip();
", btnCopyToClipboard.ClientID);

            ScriptManager.RegisterStartupScript(btnCopyToClipboard, btnCopyToClipboard.GetType(), "share-copy", script, true);

            btnCopyToClipboard.Attributes["data-clipboard-text"] = page.Guid.ToString();
            btnCopyToClipboard.Attributes["title"] = string.Format("Copy the Guid {0} to the clipboard.", page.Guid.ToString());

            ddlPageList.SelectedValue = page.Id.ToString();

            //
            // Ensure user has access to view this page.
            //
            if (!page.IsAuthorized(Authorization.VIEW, CurrentPerson))
            {
                nbError.Text = Rock.Constants.EditModeMessage.NotAuthorizedToView(typeof(Rock.Model.Page).GetFriendlyTypeName());

                pnlDetails.Visible = false;
                pnlBlocks.Visible  = false;

                return;
            }

            //
            // Setup the Details panel information.
            //
            hfPageId.Value = page.Id.ToString();
            lPageName.Text = page.InternalName;

            var fields = new List <KeyValuePair <string, string> >();

            fields.Add(new KeyValuePair <string, string>("Title", page.PageTitle));
            fields.Add(new KeyValuePair <string, string>("Layout", page.Layout.Name));
            fields.Add(new KeyValuePair <string, string>("Display In Navigation", page.DisplayInNavWhen == DisplayInNavWhen.WhenAllowed ? "<i class='fa fa-check'></i>" : string.Empty));
            if (page.IconBinaryFileId.HasValue)
            {
                fields.Add(new KeyValuePair <string, string>("Icon", GetImageTag(page.IconBinaryFileId, 200, 200, isThumbnail: true)));
            }

            // TODO: I'm pretty sure something like this already exists in Rock, but I can never find it. - dh
            ltDetails.Text = string.Join("", fields.Select(f => string.Format("<div class=\"col-md-6\"><dl><dt>{0}</dt><dd>{1}</dd></dl></div>", f.Key, f.Value)));

            pnlDetails.Visible  = true;
            pnlEditPage.Visible = false;

            //
            // If the user cannot edit, then do not show any of the block stuff.
            //
            if (!page.IsAuthorized(Authorization.EDIT, CurrentPerson))
            {
                pnlBlocks.Visible   = false;
                lbEdit.Visible      = false;
                btnSecurity.Visible = false;

                return;
            }

            lbEdit.Visible       = true;
            btnSecurity.Title    = "Secure " + page.InternalName;
            btnSecurity.EntityId = page.Id;

            //
            // Setup the category drop down list for filtering blocks.
            //
            var selectedCategory = ddlBlockTypeCategory.SelectedValue;
            var categories       = new List <string>();

            foreach (var blockType in BlockTypeCache.All().Where(b => string.IsNullOrEmpty(b.Path)))
            {
                try
                {
                    var blockCompiledType = blockType.GetCompiledType();

                    if (typeof(Rock.Blocks.IRockMobileBlockType).IsAssignableFrom(blockCompiledType))
                    {
                        if (!categories.Contains(blockType.Category))
                        {
                            categories.Add(blockType.Category);
                        }
                    }
                }
                catch
                {
                    /* Intentionally ignored. */
                }
            }
            ddlBlockTypeCategory.Items.Clear();
            foreach (var c in categories.OrderBy(c => c))
            {
                var text = c;
                if (c.StartsWith("Mobile >"))
                {
                    text = c.Replace("Mobile >", string.Empty).Trim();
                }
                ddlBlockTypeCategory.Items.Add(new ListItem(text, c));
            }
            ddlBlockTypeCategory.SetValue(selectedCategory);

            BindBlockTypeRepeater();
            BindZones();

            pnlDetails.Visible  = true;
            pnlEditPage.Visible = false;
            pnlBlocks.Visible   = true;
        }
Пример #4
0
        /// <summary>
        /// Handles the Click event of the btnAddBlock control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void btnAddBlock_Click(object sender, EventArgs e)
        {
            tbNewBlockName.Text = string.Empty;

            // Load the block types
            using (var rockContext = new RockContext())
            {
                try
                {
                    BlockTypeService.RegisterBlockTypes(Request.MapPath("~"), Page);
                }
                catch
                {
                    // ignore
                }

                // Get a list of BlockTypes that does not include Mobile block types.
                List <BlockTypeCache> allExceptMobileBlockTypes = new List <BlockTypeCache>();
                foreach (var cachedBlockType in BlockTypeCache.All())
                {
                    try
                    {
                        var blockCompiledType = cachedBlockType.GetCompiledType();

                        if (!typeof(Rock.Blocks.IRockMobileBlockType).IsAssignableFrom(blockCompiledType))
                        {
                            allExceptMobileBlockTypes.Add(cachedBlockType);
                        }
                    }
                    catch (Exception)
                    {
                        // Intentionally ignored
                    }
                }

                var blockTypes = allExceptMobileBlockTypes.Select(b => new { b.Id, b.Name, b.Category, b.Description }).ToList();

                ddlBlockType.Items.Clear();

                // Add the categorized block types
                foreach (var blockType in blockTypes.Where(b => b.Category != string.Empty).OrderBy(b => b.Category).ThenBy(b => b.Name))
                {
                    var li = new ListItem(blockType.Name, blockType.Id.ToString());
                    li.Attributes.Add("optiongroup", blockType.Category);
                    li.Attributes.Add("title", blockType.Description);
                    ddlBlockType.Items.Add(li);
                }

                // Add the uncategorized block types
                foreach (var blockType in blockTypes.Where(b => b.Category == null || b.Category == string.Empty).OrderBy(b => b.Name))
                {
                    var li = new ListItem(blockType.Name, blockType.Id.ToString());
                    li.Attributes.Add("optiongroup", "Other (not categorized)");
                    li.Attributes.Add("title", blockType.Description);
                    ddlBlockType.Items.Add(li);
                }
            }

            // Set the initial selection to the HTMLContent block.
            ddlBlockType.SetValue(BlockTypeCache.Get(Rock.SystemGuid.BlockType.HTML_CONTENT.AsGuid()).Id);

            rblAddBlockLocation.Items.Clear();

            var page = PageCache.Get(hfPageId.Value.AsInteger());

            var listItemPage = new ListItem();

            listItemPage.Text     = string.Format("Page ({0})", page.ToString());
            listItemPage.Value    = "Page";
            listItemPage.Selected = true;

            var listItemLayout = new ListItem();

            listItemLayout.Text     = string.Format("Layout ({0})", page.Layout);
            listItemLayout.Value    = "Layout";
            listItemLayout.Selected = false;

            var listItemSite = new ListItem();

            listItemSite.Text     = string.Format("Site ({0})", page.Layout.Site);
            listItemSite.Value    = "Site";
            listItemSite.Selected = false;

            rblAddBlockLocation.Items.Add(listItemPage);
            rblAddBlockLocation.Items.Add(listItemLayout);
            rblAddBlockLocation.Items.Add(listItemSite);
            mdAddBlock.Title = "Add Block to " + ddlZones.SelectedValue + " Zone";
            mdAddBlock.Show();
        }