Beispiel #1
0
        /// <summary>
        /// Indexes all wysiwyg blocks in the page containers
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void SetBuilderWysiwygField(object sender, IndexingNodeDataEventArgs e)
        {
            //get the current node id
            int nodeId;

            if (!int.TryParse(e.Fields["id"], out nodeId)) return;

            string wysiwyg = "";

            var containerProvider = new ContainerProvider(nodeId);

            foreach (Container container in containerProvider.Containers)
            {
                string containerContent = String.Join(" ",
                                                      container.Blocks.Where(b => b is WysiwygBlock)
                                                               .Cast<WysiwygBlock>()
                                                               .Select(b => b.Content));

                e.Fields.Add("WBContainer_" + container.Name, containerContent);
                wysiwyg += " " + containerContent;
            }
            SetWBWysiwig(e, "WBWysiwyg", DecodeString(wysiwyg));
        }
        /// <summary>
        /// Loads the current state of the container stored on the page and synchronises what blocks
        /// are default on the template and those that have been dragged on.
        /// </summary>
        /// <param name="containerName">The name of the container to load the blocks into</param>
        /// <param name="blocks">The default template blocks</param>
        /// <param name="dynamicWysiwygClass">The class that should be added to any dynamically added wysiwyg blocks</param>
        private static void LoadContainerBlocks(string containerName, List<IBlock> blocks, string dynamicWysiwygClass)
        {
            //set IsTemplateBlock to true for all blocks
            blocks.ForEach(b => b.IsTemplateBlock = true);

            //load the current container saved state
            ContainerProvider containerProvider = new ContainerProvider();
            Container container = containerProvider.ContainerByName(containerName);

            if (container == null) return;

            //sync template blocks with what is saved on the page
            foreach (IBlock templateBlock in blocks)
            {
                //get the saved state of the current block
                IBlock savedBlock = container.Blocks.FirstOrDefault(b => b.IsTemplateBlock && b.Id == templateBlock.Id);
                if (savedBlock == null) continue;

                templateBlock.IsDeleted = savedBlock.IsDeleted;
                templateBlock.SortOrder = savedBlock.SortOrder;

                //if its a wysiwyg block then add transfer the content
                if(templateBlock is WysiwygBlock)
                    ((WysiwygBlock)templateBlock).Content = ((WysiwygBlock)savedBlock).Content;
            }

            //add all dragged-on blocks to the blocks
            foreach (IBlock pageBlock in container.Blocks.Where(b => (!b.IsTemplateBlock) || (b.IsTemplateBlock && b is WysiwygBlock && !blocks.Exists(tb => tb.Id == b.Id))))
            {
                //if this is a dynamically added wysiwyg block then set the default class
                pageBlock.Class = pageBlock.IsTemplateBlock && pageBlock is WysiwygBlock ? dynamicWysiwygClass : pageBlock.Class;
                blocks.Add(pageBlock);
            }

            //if were not in the builder remove all template blocks that have been deleted
            if (!WebBlocksUtility.IsInBuilder)
                blocks.RemoveAll(b => b.IsDeleted == true);

            //remove any blocks that have been deleted from Umbraco
            blocks.RemoveAll(b => b is NodeBlock && ((NodeBlock)b).Content == null);
        }