コード例 #1
0
        protected void InstallToolboxConfiguration(SiteInitializer initializer)
        {
            var config = initializer.Context.GetConfig <ToolboxesConfig>();

            var pageControls = config.Toolboxes["PageControls"];
            var section      = pageControls
                               .Sections
                               .Where <ToolboxSection>(e => e.Name == ToolboxesConfig.ContentToolboxSectionName)
                               .FirstOrDefault();

            if (section == null)
            {
                section = new ToolboxSection(pageControls.Sections)
                {
                    Name            = ToolboxesConfig.ContentToolboxSectionName,
                    Title           = "ContentToolboxSectionTitle",
                    Description     = "ContentToolboxSectionDescription",
                    ResourceClassId = typeof(PageResources).Name
                };
                pageControls.Sections.Add(section);
            }
            if (!section.Tools.Any <ToolboxItem>(e => e.Name == "HelloWorldWidget"))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name            = "HelloWorldWidget",
                    Title           = "HelloWorldWidgetTitle",
                    Description     = "HelloWorldWidgetDescription",
                    ResourceClassId = HelloWorldModule.ResourceClassId,
                    ModuleName      = HelloWorldModule.ModuleName,
                    ControlType     = typeof(HelloWorldWidget).AssemblyQualifiedName
                };
                section.Tools.Add(tool);
            }
        }
コード例 #2
0
        private static void RegisterSectionInBackend(string toolboxName, string sectionName)
        {
            var configManager = ConfigManager.GetManager();
            var config        = configManager.GetSection <ToolboxesConfig>();

            var controls = config.Toolboxes[toolboxName];

            var section = controls.Sections.Where <ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();

            if (section == null)
            {
                configManager.Provider.SuppressSecurityChecks = true;
                section = new ToolboxSection(controls.Sections)
                {
                    Name            = sectionName,
                    Title           = "<span class='ShunghamSectionIcon'>" + sectionName + "</span>",
                    Description     = sectionName,
                    ResourceClassId = string.Empty
                };
                controls.Sections.Add(section);
                configManager.SaveSection(config);

                configManager.Provider.SuppressSecurityChecks = false;
            }
        }
コード例 #3
0
        public static void RegisterControl(string controlName, Type controlType, string toolboxName, string sectionName)
        {
            var configManager = ConfigManager.GetManager();
            var config        = configManager.GetSection <ToolboxesConfig>();

            var controls = config.Toolboxes[toolboxName];
            var section  = controls.Sections.Where <ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();

            if (section == null)
            {
                section = new ToolboxSection(controls.Sections)
                {
                    Name            = sectionName,
                    Title           = sectionName,
                    Description     = sectionName,
                    ResourceClassId = typeof(PageResources).Name
                };
                controls.Sections.Add(section);
            }

            if (!section.Tools.Any <ToolboxItem>(e => e.Name == controlName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name        = controlName,
                    Title       = controlName,
                    Description = controlName,
                    ControlType = controlType.AssemblyQualifiedName
                };
                section.Tools.Add(tool);
            }

            configManager.SaveSection(config);
        }
コード例 #4
0
        /// <summary>
        /// Method to install a single widget with the given parameters.
        /// </summary>
        /// <param name="controlName">Name of the widget</param>
        /// <param name="controlTitle">Name of the widget that will be visible in the front end</param>
        /// <param name="controlType">Type of the widget</param>
        /// <param name="sectionName">Name of the section the widget will be installed into</param>
        /// <param name="sectionTitle">Name of the section that will visible in the front end</param>
        /// <param name="toolBoxName">Name of the Sitefinity toolbox</param>
        private static void InstallSingleWidget(string controlName, string controlTitle, System.Type controlType, string sectionName, string sectionTitle, string toolBoxName)
        {
            var configManager = ConfigManager.GetManager();
            var config        = configManager.GetSection <ToolboxesConfig>();

            var controls = config.Toolboxes[toolBoxName];
            var section  = controls.Sections.Where <ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();

            if (section == null)
            {
                section = new ToolboxSection(controls.Sections)
                {
                    Name  = sectionName,
                    Title = sectionTitle
                };
                controls.Sections.Add(section);
            }

            if (!section.Tools.Any <ToolboxItem>(e => e.Name == controlName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name        = controlName,
                    Title       = controlTitle,
                    ControlType = controlType.AssemblyQualifiedName
                };
                section.Tools.Add(tool);
            }

            configManager.SaveSection(config);
        }
コード例 #5
0
        private static ToolboxSection GetFormsToolboxSection(ToolboxesConfig toolboxesConfig)
        {
            var            formsControls = toolboxesConfig.Toolboxes[FormsConstants.FormControlsToolboxName];
            var            sectionName   = FormsConstants.CommonSectionName;
            ToolboxSection section       = formsControls.Sections.Where <ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();

            return(section);
        }
コード例 #6
0
        private static void RemoveToolboxItemIfExists(ToolboxSection mvcWidgetsSection, string toolName)
        {
            var tool = mvcWidgetsSection.Tools.FirstOrDefault <ToolboxItem>(t => t.Name == toolName);

            if (tool != null)
            {
                mvcWidgetsSection.Tools.Remove(tool);
            }
        }
コード例 #7
0
        /// <summary>
        /// Asserts if widget is present in the toolbox config.
        /// </summary>
        /// <param name="section">The toolbox section.</param>
        /// <param name="widgetTitle">The widget name.</param>
        /// <param name="isMvcWidget">Mvc Widget or WebForms Widget</param>
        /// <returns></returns>
        public bool IsWidgetPresentInToolbox(ToolboxSection section, string widgetTitle, bool isMvcWidget)
        {
            var item = this.GetToolboxItem(section, widgetTitle, isMvcWidget);

            if (item == null)
            {
                return(false);
            }

            return(true);
        }
コード例 #8
0
        /// <summary>
        /// Gets existing or create a tool box section for the grid controls.
        /// </summary>
        /// <param name="toolbox">The toolbox configuration.</param>
        /// <param name="sectionName">Name of the section.</param>
        /// <param name="sectionTitle">The section title.</param>
        /// <returns>The section.</returns>
        protected virtual ToolboxSection CreateToolBoxSection(Toolbox toolbox, string sectionName, string sectionTitle)
        {
            var htmlLayoutsSection = new ToolboxSection(toolbox.Sections);

            htmlLayoutsSection.Name = sectionName;

            /// TODO: Set resource class id and use resource keys for Title and Description.
            htmlLayoutsSection.Title = sectionTitle;

            toolbox.Sections.Add(htmlLayoutsSection);

            return(htmlLayoutsSection);
        }
コード例 #9
0
        /// <summary>
        /// Gets a toolbox item from the config section.
        /// </summary>
        /// <param name="section">The toolbox section.</param>
        /// <param name="widgetTitle">The name of the widget.</param>
        /// <param name="isMvcWidget">Mvc Widget or WebForms Widget</param>
        /// <returns></returns>
        public ToolboxItem GetToolboxItem(ToolboxSection section, string widgetTitle, bool isMvcWidget)
        {
            if (section == null)
            {
                throw new ArgumentException("Section was not found");
            }

            if (isMvcWidget)
            {
                return(section.Tools.FirstOrDefault <ToolboxItem>(e => e.Title == widgetTitle && e.CssClass.EndsWith("sfMvcIcn", StringComparison.CurrentCulture)));
            }

            return(section.Tools.FirstOrDefault <ToolboxItem>(e => e.Title == widgetTitle && !e.CssClass.EndsWith("sfMvcIcn", StringComparison.CurrentCulture)));
        }
コード例 #10
0
        public ToolboxItem GridControlToolboxItem(ToolboxSection section, string gridName, string css, string virtualPath)
        {
            var toolboxItem = new ToolboxItem(section.Tools)
            {
                Enabled        = true,
                Name           = gridName,
                Title          = gridName,
                CssClass       = css,
                ControlType    = typeof(GridControl).AssemblyQualifiedName,
                LayoutTemplate = virtualPath
            };

            return(toolboxItem);
        }
コード例 #11
0
        private bool AddControllerToPageToolbox(ControllerInfoExtended controllerInfo, ToolboxesConfig toolboxConfig)
        {
            if (!controllerInfo.IncludeInToolbox)
            {
                return(false);
            }

            bool saveRequired = false;

            // get the pages toolbox
            var toolboxName = string.IsNullOrEmpty(controllerInfo.Toolbox) ? "PageControls" : controllerInfo.Toolbox;
            var toolbox     = toolboxConfig.Toolboxes[toolboxName];

            // create the new toolbox section
            var controllerSection = toolbox.Sections
                                    .Where <ToolboxSection>(s => s.Name == controllerInfo.DefaultToolboxSectionName).SingleOrDefault();

            if (controllerSection == null)
            {
                saveRequired            = true;
                controllerSection       = new ToolboxSection(toolbox.Sections);
                controllerSection.Name  = controllerInfo.DefaultToolboxSectionName;
                controllerSection.Title = controllerInfo.DefaultToolboxSectionName;
                toolbox.Sections.Add(controllerSection);
            }

            // create the controller toolbox item
            ToolboxItem toolboxItem = controllerSection.Tools.Where <ToolboxItem>(t => t.Name == controllerInfo.DefaultToolboxItemName).SingleOrDefault();

            if (toolboxItem == null)
            {
                saveRequired = true;
                string mvcWidgetProxyFullName = this.GetMvcWidgetProxyFullName();

                toolboxItem                = new ToolboxItem(controllerSection.Tools);
                toolboxItem.Title          = controllerInfo.DefaultToolboxItemTitle;
                toolboxItem.Name           = controllerInfo.DefaultToolboxItemName;
                toolboxItem.ControlType    = mvcWidgetProxyFullName;
                toolboxItem.ControllerType = controllerInfo.ControllerType.FullName;
                toolboxItem.ModuleName     = controllerInfo.DefaultToolboxModuleName;
                toolboxItem.CssClass       = controllerInfo.DefaultToolboxCssClass;

                toolboxItem.Parameters.Add("ControllerName", controllerInfo.ControllerType.FullName);
                toolboxItem.Parameters.Add("WidgetName", controllerInfo.WidgetName);

                controllerSection.Tools.Add(toolboxItem);
            }

            return(saveRequired);
        }
コード例 #12
0
        /// <summary>
        /// Gets existing or create a tool box section for the grid controls.
        /// </summary>
        /// <param name="toolboxConfig">The toolbox configuration.</param>
        /// <returns></returns>
        protected virtual ToolboxSection GetOrCreateToolBoxSection(ToolboxesConfig toolboxConfig)
        {
            var layoutsToolbox = toolboxConfig.Toolboxes["PageLayouts"];

            var htmlLayoutsSection = layoutsToolbox.Sections.FirstOrDefault <ToolboxSection>(s => s.Name == "HtmlLayouts");

            if (htmlLayoutsSection == null)
            {
                htmlLayoutsSection      = new ToolboxSection(layoutsToolbox.Sections);
                htmlLayoutsSection.Name = "HtmlLayouts";
                //TODO: Set resource class id and use resource keys for Title and Description.
                htmlLayoutsSection.Title = "Bootstrap grid widgets";

                layoutsToolbox.Sections.Add(htmlLayoutsSection);
            }
            return(htmlLayoutsSection);
        }
コード例 #13
0
        /// <summary>
        /// Gets existing or create a tool box section for the grid controls.
        /// </summary>
        /// <param name="toolboxConfig">The toolbox configuration.</param>
        /// <returns></returns>
        protected virtual ToolboxSection GetOrCreateToolBoxSection(ToolboxesConfig toolboxConfig)
        {
            var layoutsToolbox = toolboxConfig.Toolboxes["PageLayouts"];

            var htmlLayoutsSection = layoutsToolbox.Sections.FirstOrDefault<ToolboxSection>(s => s.Name == "HtmlLayouts");
            if (htmlLayoutsSection == null)
            {
                htmlLayoutsSection = new ToolboxSection(layoutsToolbox.Sections);
                htmlLayoutsSection.Name = "HtmlLayouts";

                /// TODO: Set resource class id and use resource keys for Title and Description.
                htmlLayoutsSection.Title = "Bootstrap grid widgets";

                layoutsToolbox.Sections.Add(htmlLayoutsSection);
            }

            return htmlLayoutsSection;
        }
コード例 #14
0
        public static bool RegisterControl(string controlName, string controlTitle, Type controlType, string toolboxName, string sectionName, string controllerType)
        {
            var configManager = ConfigManager.GetManager();
            var config        = configManager.GetSection <ToolboxesConfig>();

            var controls = config.Toolboxes[toolboxName];
            var section  = controls.Sections.Where <ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();

            if (section == null)
            {
                section = new ToolboxSection(controls.Sections)
                {
                    Name        = sectionName,
                    Title       = sectionName,
                    Description = sectionName,
                };
                controls.Sections.Add(section);
            }

            bool updated = false;

            if (!section.Tools.Any <ToolboxItem>(e => e.Name == controlName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name           = controlName,
                    Title          = controlTitle,
                    Enabled        = true,
                    CssClass       = "sf_gigya sfMvcIcn",
                    Description    = controlName,
                    ControllerType = controlType.FullName,
                    Parameters     = new NameValueCollection(),
                    ControlType    = controllerType
                };

                tool.Parameters.Add("ControllerName", controlType.FullName);
                section.Tools.Add(tool);

                updated = true;
            }

            configManager.SaveSection(config);
            return(updated);
        }
コード例 #15
0
        /// <summary>
        /// Gets existing or create a tool box section for the grid controls.
        /// </summary>
        /// <param name="toolboxConfig">The toolbox configuration.</param>
        /// <param name="sectionName">Name of the section.</param>
        /// <param name="sectionTitle">The section title.</param>
        /// <returns></returns>
        protected virtual ToolboxSection GetOrCreateToolBoxSection(ToolboxesConfig toolboxConfig, string sectionName, string sectionTitle, ref bool needsSaveSection)
        {
            var layoutsToolbox = toolboxConfig.Toolboxes["PageLayouts"];

            var htmlLayoutsSection = layoutsToolbox.Sections.FirstOrDefault <ToolboxSection>(s => s.Name == sectionName);

            if (htmlLayoutsSection == null)
            {
                htmlLayoutsSection      = new ToolboxSection(layoutsToolbox.Sections);
                htmlLayoutsSection.Name = sectionName;

                /// TODO: Set resource class id and use resource keys for Title and Description.
                htmlLayoutsSection.Title = sectionTitle;

                layoutsToolbox.Sections.Add(htmlLayoutsSection);
                needsSaveSection = true;
            }

            return(htmlLayoutsSection);
        }
コード例 #16
0
ファイル: Initializer.cs プロジェクト: plompd/feather-widgets
        private static void RegisterToolboxItem(ToolboxSection section, string name, string title, string controllerType, string cssClass)
        {
            if (!section.Tools.Any <ToolboxItem>(t => t.Name == name))
            {
                var toolboxItem = new ToolboxItem(section.Tools)
                {
                    Name           = name,
                    Title          = title,
                    Description    = string.Empty,
                    ControlType    = typeof(MvcControllerProxy).FullName,
                    ControllerType = controllerType,
                    CssClass       = cssClass,
                    Parameters     = new NameValueCollection()
                    {
                        { "ControllerName", controllerType }
                    }
                };

                section.Tools.Add(toolboxItem);
            }
        }
コード例 #17
0
        private static void RegisterToolboxItem(ToolboxSection section, string name, ToolboxItemInfo item)
        {
            if (!section.Tools.Contains(name))
            {
                var toolboxItem = new ToolboxItem(section.Tools)
                {
                    Name           = name,
                    Title          = item.Title,
                    Description    = string.Empty,
                    ControlType    = typeof(MvcControllerProxy).FullName,
                    ControllerType = item.ControllerType,
                    CssClass       = item.CssClass,
                    Parameters     = new NameValueCollection()
                    {
                        { "ControllerName", item.ControllerType }
                    }
                };

                section.Tools.Add(toolboxItem);
            }
        }
コード例 #18
0
        /// <summary>
        /// Gets the toolbox section where the dynamic widget will be placed.
        /// </summary>
        /// <param name="dynamicModule">The dynamic module.</param>
        /// <param name="toolboxesConfig">The toolboxes configuration.</param>
        /// <returns></returns>
        private static ToolboxSection GetModuleToolboxSection(DynamicModule dynamicModule, ToolboxesConfig toolboxesConfig)
        {
            var            pageControls      = toolboxesConfig.Toolboxes["PageControls"];
            var            moduleSectionName = string.Concat(DynamicModuleType.defaultNamespace, ".", MvcWidgetInstaller.moduleNameValidationRegex.Replace(dynamicModule.Name, string.Empty));
            ToolboxSection section           = pageControls.Sections.Where <ToolboxSection>(e => e.Name == moduleSectionName).FirstOrDefault();

            if (section == null)
            {
                var sectionDescription = string.Format(MvcWidgetInstaller.ModuleSectionDescription, dynamicModule.GetTitle());
                section = new ToolboxSection(pageControls.Sections)
                {
                    Name        = moduleSectionName,
                    Title       = dynamicModule.Title,
                    Description = sectionDescription
                };

                pageControls.Sections.Add(section);
            }

            return(section);
        }
コード例 #19
0
        /// <summary>
        /// Install the widget itself
        /// </summary>
        private static void InstallWidget()
        {
            // get the configManager
            var configManager = Config.GetManager();
            var config        = configManager.GetSection <ToolboxesConfig>();

            var controls    = config.Toolboxes["PageControls"];
            var sectionName = "ScriptsAndStylesControlsSection";
            var section     = controls.Sections.Where <ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();

            if (section == null)
            {
                section = new ToolboxSection(controls.Sections)
                {
                    Name        = sectionName,
                    Title       = sectionName,
                    Description = sectionName,
                };
                controls.Sections.Add(section);
            }

            var controlName  = "OptimizelyScriptControl";
            var controlTitle = "Optimizely Script";
            var controlType  = typeof(OptimizelyScriptControl);

            if (!section.Tools.Any <ToolboxItem>(e => e.Name == controlName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name        = controlName,
                    Title       = controlTitle,
                    Description = controlName,
                    ControlType = controlType.AssemblyQualifiedName,
                    CssClass    = "sfLanguageSelectorIcn"
                };
                section.Tools.Add(tool);
            }

            configManager.SaveSection(config);
        }
コード例 #20
0
        private static void RegisterControl(String toolBox, String sectionName, String controlName, String controlPath, String templatePath)
        {
            var configManager = ConfigManager.GetManager();
            var config        = configManager.GetSection <ToolboxesConfig>();
            var controls      = config.Toolboxes[toolBox];
            var section       = controls.Sections.FirstOrDefault <ToolboxSection>(e => e.Name == sectionName);

            if (section == null)
            {
                section = new ToolboxSection(controls.Sections)
                {
                    Name            = sectionName,
                    Title           = sectionName,
                    Description     = sectionName,
                    ResourceClassId = typeof(PageResources).Name
                };
                controls.Sections.Add(section);
            }

            if (section.Tools.All <ToolboxItem>(e => e.Name != controlName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name        = controlName,
                    Title       = controlName,
                    Description = controlName,
                    ControlType = controlPath
                };

                if (templatePath != null)
                {
                    tool.LayoutTemplate = templatePath;
                }

                section.Tools.Add(tool);
            }

            configManager.SaveSection(config);
        }
コード例 #21
0
        /// <summary>
        /// Installs module's toolbox configuration.
        /// </summary>
        /// <param name="initializer">The initializer.</param>
        protected override void InstallConfiguration(SiteInitializer initializer)
        {
            var config = initializer.Context.GetConfig <ToolboxesConfig>();

            var pageControls = config.Toolboxes["PageControls"];

            var section = pageControls
                          .Sections
                          .Where <ToolboxSection>(e => e.Name == ToolboxesConfig.ContentToolboxSectionName)
                          .FirstOrDefault();
            var classId = typeof(AgentsResources).Name;

            if (section == null)
            {
                section = new ToolboxSection(pageControls.Sections)
                {
                    Name            = ToolboxesConfig.ContentToolboxSectionName,
                    Title           = "ContentToolboxSectionTitle",
                    Description     = "ContentToolboxSectionDescription",
                    ResourceClassId = typeof(PageResources).Name
                };
                pageControls.Sections.Add(section);
            }
            if (!section.Tools.Any <ToolboxItem>(e => e.Name == "AgentsView"))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name            = "AgentsView",
                    Title           = "AgentsViewTitle",
                    Description     = "AgentsViewDescription",
                    ResourceClassId = classId,
                    ModuleName      = AgentsModule.ModuleName,
                    CssClass        = "sfAgentsViewIcn",
                    ControlType     = typeof(AgentsView).AssemblyQualifiedName
                };
                section.Tools.Add(tool);
            }
        }
コード例 #22
0
        /// <summary>
        /// Adds or renames the grid control.
        /// </summary>
        /// <param name="section">The parent toolbox section.</param>
        /// <param name="data">The data.</param>
        /// <param name="toolboxItemName">Old name of the file.</param>
        /// <exception cref="System.ArgumentNullException">data</exception>
        protected virtual void AddOrRenameGridControl(ToolboxSection section, GridControlData data, string toolboxItemName = default(string))
        {
            if (data == null)
            {
                throw new ArgumentNullException("data");
            }

            var tools = section.Tools;

            var control = tools.FirstOrDefault <ToolboxItem>(t => t.Name == toolboxItemName);

            if (control == null)
            {
                control             = new ToolboxItem(tools);
                control.ControlType = typeof(GridControl).AssemblyQualifiedName;
                control.CssClass    = data.CssClass;
                tools.Add(control);
            }

            control.Name           = data.Name;
            control.Title          = data.Title;
            control.LayoutTemplate = data.LayoutTemplatePath;
        }
        /// <summary>
        /// Installs this module in Sitefinity system for the first time.
        /// </summary>
        /// <param name="initializer">The Site Initializer. A helper class for installing Sitefinity modules.</param>
        public override void Install(SiteInitializer initializer)
        {
            // get page manager
            var pageManager = initializer.PageManager;

            // create Module Landing Page if doesn't exist
            var landingPage = pageManager.GetPageNodes().SingleOrDefault(p => p.Id == this.LandingPageId);

            if (landingPage == null)
            {
                // create admin list view control and add to new landing page
                var ctrl = pageManager.CreateControl <PageControl>("~/Modules/Testimonials/Admin/TestimonialsAdminView.ascx", "Content");
                this.CreatePage(pageManager, this.LandingPageId, SiteInitializer.ModulesNodeId, TestimonialsModule.ModuleName, true, TestimonialsModule.ModuleName, ctrl);
            }

            // create testimonials "Create" Page if doesn't exist
            var createPage = pageManager.GetPageNodes().SingleOrDefault(p => p.Id == this.CreatePageId);

            if (createPage == null)
            {
                // create admin control, set properties
                var ctrl = pageManager.CreateControl <PageControl>("~/Modules/Testimonials/Admin/TestimonialsAddEditView.ascx", "Content");
                var prop = ctrl.Properties.FirstOrDefault(p => p.Name == "Mode");
                if (prop == null)
                {
                    prop      = new ControlProperty();
                    prop.Id   = Guid.NewGuid();
                    prop.Name = "Mode";
                    ctrl.Properties.Add(prop);
                }

                // set control to "Create" mode
                prop.Value = SitefinityWebApp.Modules.Testimonials.Admin.TestimonialsAddEditView.AdminControlMode.Create.ToString();

                // create backend page and add control
                this.CreatePage(pageManager, this.CreatePageId, this.LandingPageId, "Create", false, "Create Testimonial", ctrl);
            }

            // create testimonials "Edit" Page if doesn't exist
            var editPage = pageManager.GetPageNodes().SingleOrDefault(p => p.Id == this.EditPageId);

            if (editPage == null)
            {
                // create admin control, set properties
                var ctrl = pageManager.CreateControl <PageControl>("~/Modules/Testimonials/Admin/TestimonialsAddEditView.ascx", "Content");
                var prop = ctrl.Properties.FirstOrDefault(p => p.Name == "Mode");
                if (prop == null)
                {
                    prop      = new ControlProperty();
                    prop.Id   = Guid.NewGuid();
                    prop.Name = "Mode";
                    ctrl.Properties.Add(prop);
                }

                // set control to "Create" mode
                prop.Value = SitefinityWebApp.Modules.Testimonials.Admin.TestimonialsAddEditView.AdminControlMode.Edit.ToString();

                // create backend page and add control
                this.CreatePage(pageManager, this.EditPageId, this.LandingPageId, "Edit", false, "Edit Testimonial", ctrl);
            }

            string toolboxName = "PageControls";
            string sectionName = "Samples";
            var    config      = initializer.Context.GetConfig <ToolboxesConfig>();

            var controls = config.Toolboxes[toolboxName];
            var section  = controls.Sections.Where <ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();

            if (section == null)
            {
                section = new ToolboxSection(controls.Sections)
                {
                    Name            = sectionName,
                    Title           = sectionName,
                    Description     = sectionName,
                    ResourceClassId = typeof(PageResources).Name
                };
                controls.Sections.Add(section);
            }

            // Add TestimonialsView Widget if doesn't exist
            if (!section.Tools.Any <ToolboxItem>(e => e.Name == TestimonialsView.ViewName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name        = TestimonialsView.ViewName,
                    Title       = "TestimonialsView",
                    Description = "Public control for the Testimonials module",
                    ControlType = "~/Modules/Testimonials/TestimonialsView.ascx",
                    CssClass    = "sfTestimonialsWidget"
                };
                section.Tools.Add(tool);
            }

            // Add SubmitTestimonial Widget if doesn't exist
            if (!section.Tools.Any <ToolboxItem>(e => e.Name == SubmitTestimonial.ViewName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name        = SubmitTestimonial.ViewName,
                    Title       = "SubmitTestimonial",
                    Description = "Public control for submitting Testimonial",
                    ControlType = "~/Modules/Testimonials/SubmitTestimonial.ascx",
                    CssClass    = "sfTestimonialsWidget"
                };
                section.Tools.Add(tool);
            }
        }
コード例 #24
0
ファイル: FrontendModule.cs プロジェクト: RifasRazick/feather
 private void RemoveToolboxItemIfExists(ToolboxSection mvcWidgetsSection, string toolName)
 {
     var tool = mvcWidgetsSection.Tools.FirstOrDefault<ToolboxItem>(t => t.Name == toolName);
     if (tool != null)
         mvcWidgetsSection.Tools.Remove(tool);
 }
コード例 #25
0
ファイル: ConfigHelper.cs プロジェクト: tvarshney/Babaganoush
        /// <summary>
        /// Registers widget to the toolbox. http://www.sitefinity.com/developer-network/forums/general-
        /// discussions-/registering-custom-control-in-toolbox.
        /// </summary>
        /// <typeparam name="T">Generic type parameter.</typeparam>
        /// <param name="title">The title.</param>
        /// <param name="description">(Optional) The description.</param>
        /// <param name="cssClass">(Optional) The CSS class.</param>
        /// <param name="resourceClassId">(Optional) The resource class identifier.</param>
        /// <param name="layoutTemplate">(Optional) The layout template.</param>
        /// <param name="sectionName">(Optional) Name of the section.</param>
        /// <param name="sectionOrdinal">(Optional) The section ordinal.</param>
        /// <param name="toolboxType">(Optional) Type of the toolbox.</param>
        public static void RegisterToolboxWidget <T>(string title, string description = null, string cssClass = null, string resourceClassId = null, string layoutTemplate = "", string sectionName = Constants.VALUE_TOOLBOX_SECTION_NAME, int?sectionOrdinal = null, ToolboxType toolboxType = ToolboxType.PageControls)
        {
            var manager = Config.GetManager();

            using (new ElevatedModeRegion(manager))
            {
                var config = manager.GetSection <ToolboxesConfig>();

                //GET PAGE TOOLBOX
                var controls = config.Toolboxes[toolboxType.ToString()];
                var section  = controls
                               .Sections
                               .FirstOrDefault <ToolboxSection>(x => x.Name == sectionName);

                //CREATE THE SECTION IF APPLICABLE
                if (section == null)
                {
                    section = new ToolboxSection(controls.Sections)
                    {
                        Name        = _webHelper.GenerateSafeName(sectionName, true),
                        Title       = sectionName,
                        Description = sectionName,
                        Ordinal     = sectionOrdinal.GetValueOrDefault(99)
                    };

                    //SET ORDINALS FOR SECTIONS
                    if (sectionOrdinal.HasValue)
                    {
                        //HANDLE ORDINAL CONFLICTS
                        foreach (var item in controls.Sections
                                 .Where <ToolboxSection>(x => x.Ordinal == sectionOrdinal.Value))
                        {
                            item.Ordinal += 0.1F;
                        }
                    }

                    controls.Sections.Add(section);
                }

                //REGISTER IN TOOLBOX IF APPLICABLE
                var control = typeof(T);
                if (!section.Tools.Any <ToolboxItem>(t => t.Name == control.Name))
                {
                    //GENERATE NAME FOR TOOLBOX ITEM
                    var name = _webHelper.GenerateSafeName(title, true);

                    //VALIDATE NAME
                    if (Char.IsNumber(name, 0))
                    {
                        name = section.Name + name;
                    }

                    //CREATE WIDGET OBJECT
                    var widget = new ToolboxItem(section.Tools)
                    {
                        Name            = name,
                        Title           = title,
                        Description     = description ?? title,
                        CssClass        = cssClass,
                        ResourceClassId = resourceClassId
                    };

                    //HANDLE WEB FORM AND MVC WIDGETS DIFFERENTLY
                    if (typeof(Controller).IsAssignableFrom(control))
                    {
                        //DEFINE AS MVC WIDGET
                        widget.ControlType    = string.Format("{0}, {1}", typeof(MvcControllerProxy).FullName, typeof(MvcControllerProxy).Assembly);
                        widget.ControllerType = control.FullName;
                        widget.Parameters.Add("ControllerName", control.FullName);
                    }
                    else
                    {
                        //DEFINE AS WEB FORM WIDGET
                        widget.ControlType = control.FullName;
                    }

                    //ASSIGN TEMPLATE IF APPLICABLE
                    if (!string.IsNullOrWhiteSpace(layoutTemplate))
                    {
                        widget.LayoutTemplate = layoutTemplate;
                    }

                    //REGISTER TO SYSTEM
                    section.Tools.Add(widget);
                    manager.SaveSection(config);
                }
            }
        }
コード例 #26
0
        /// <summary>
        /// Gets a toolbox item from the config section.
        /// </summary>
        /// <param name="section">The toolbox section.</param>
        /// <param name="widgetTitle">The name of the widget.</param>
        /// <param name="isMvcWidget">Mvc Widget or WebForms Widget</param>
        /// <returns></returns>
        public ToolboxItem GetToolboxItem(ToolboxSection section, string widgetTitle, bool isMvcWidget)
        {
            if (section == null)
            {
                throw new ArgumentException("Section was not found");
            }

            if (isMvcWidget)
            {
                return section.Tools.FirstOrDefault<ToolboxItem>(e => e.Title == widgetTitle && e.CssClass.EndsWith("sfMvcIcn", StringComparison.CurrentCulture));
            }

            return section.Tools.FirstOrDefault<ToolboxItem>(e => e.Title == widgetTitle && !e.CssClass.EndsWith("sfMvcIcn", StringComparison.CurrentCulture));
        }
コード例 #27
0
        /// <summary>
        /// Asserts if widget is present in the toolbox config.
        /// </summary>
        /// <param name="section">The toolbox section.</param>
        /// <param name="widgetTitle">The widget name.</param>
        /// <param name="isMvcWidget">Mvc Widget or WebForms Widget</param>
        /// <returns></returns>
        public bool IsWidgetPresentInToolbox(ToolboxSection section, string widgetTitle, bool isMvcWidget)
        {
            var item = this.GetToolboxItem(section, widgetTitle, isMvcWidget);

            if (item == null)
            {
                return false;
            }

            return true;
        }
コード例 #28
0
        private static void InstallLayouts()
        {
            ConfigManager manager = Config.GetManager();

            manager.Provider.SuppressSecurityChecks = true;
            var config  = manager.GetSection <ToolboxesConfig>();
            var layouts = config.Toolboxes["PageLayouts"];

            foreach (var s in layouts.Sections)
            {
                Debug.WriteLine(s);;
            }

            var section = layouts
                          .Sections
                          .Where <ToolboxSection>(tb => tb.Name == "Controls")
                          .FirstOrDefault();

            if (section == null)
            {
                section = new ToolboxSection(layouts.Sections)
                {
                    Name        = "Controls",
                    Title       = "Controls",
                    Description = "Controls"
                };
                layouts.Sections.Add(section);

                manager.SaveSection(config);
            }

            if (!section.Tools.Any <ToolboxItem>(e => e.Name == "TabStripMVC"))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name           = "TabStripMVC",
                    Title          = "TabStrip",
                    Description    = "Renders the parent child layouts as a RadTabStrip",
                    ControlType    = "Telerik.Sitefinity.Frontend.GridSystem.GridControl, Telerik.Sitefinity.Frontend",
                    CssClass       = "sfL20_20_20_20_20",
                    LayoutTemplate = "~/SitefinitySteveMVC/RandomSiteControlsMVC.MVC.Views.TabStrip.Layouts.tabstrip.html"
                };
                section.Tools.Add(tool);
            }

            if (!section.Tools.Any <ToolboxItem>(e => e.Name == "TabMVC"))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name           = "TabMVC",
                    Title          = "Tab",
                    Description    = "A tab for the tabstrip",
                    ControlType    = "Telerik.Sitefinity.Frontend.GridSystem.GridControl, Telerik.Sitefinity.Frontend",
                    CssClass       = "sfL100",
                    LayoutTemplate = "~/SitefinitySteveMVC/RandomSiteControlsMVC.MVC.Views.TabStrip.Layouts.tab.html"
                };
                section.Tools.Add(tool);
            }

            //if (!section.Tools.Any<ToolboxItem>(e => e.Name == "FancyBox"))
            //{
            //    var tool = new ToolboxItem(section.Tools)
            //    {
            //        Name = "FancyBox",
            //        Title = "FancyBox Popup",
            //        Description = "Build a popup from the Sitefinity UI",
            //        ControlType = "RandomSiteControls.FancyBox.FancyBoxLayout",
            //        CssClass = "sfsLayoutFancyBoxIcon"
            //    };
            //    section.Tools.Add(tool);
            //}

            manager.SaveSection(config);
            manager.Provider.SuppressSecurityChecks = false;
        }
コード例 #29
0
        private static void RegisterToolboxItem(ToolboxSection section, string name, string title, string controllerType, string cssClass, ref bool needsSaveSection)
        {
            if (!section.Tools.Any<ToolboxItem>(t => t.Name == name))
            {
                var toolboxItem = new ToolboxItem(section.Tools)
                {
                    Name = name,
                    Title = title,
                    Description = string.Empty,
                    ControlType = typeof(MvcControllerProxy).FullName,
                    ControllerType = controllerType,
                    CssClass = cssClass,
                    Parameters = new NameValueCollection()
                    {
                        { "ControllerName", controllerType }
                    }
                };

                section.Tools.Add(toolboxItem);
                needsSaveSection = true;
            }
        }
コード例 #30
0
        public void Install()
        {
            Boolean saveSection   = false;
            var     configManager = ConfigManager.GetManager();
            var     config        = configManager.GetSection <ToolboxesConfig>();

            var controls    = config.Toolboxes["FormControls"];
            var sectionName = "SalesForceFields";
            var section     = controls.Sections.Where <ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();

            if (section == null)
            {
                section = new ToolboxSection(controls.Sections)
                {
                    Name            = sectionName,
                    Title           = sectionName,
                    Description     = sectionName,
                    ResourceClassId = typeof(PageResources).Name
                };
                controls.Sections.Add(section);
                saveSection = true;
            }

            var controlName = "SalesForceDropDown";
            var controlType = typeof(Fields.DropDown);

            if (!section.Tools.Any <ToolboxItem>(e => e.Name == controlName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name        = controlName,
                    Title       = controlName,
                    Description = controlName,
                    ControlType = controlType.AssemblyQualifiedName,
                    CssClass    = "sfDropdownIcn"
                };
                section.Tools.Add(tool);
                saveSection = true;
            }

            controlName = "SalesForceTextBox";
            controlType = typeof(Fields.TextBox);
            if (!section.Tools.Any <ToolboxItem>(e => e.Name == controlName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name        = controlName,
                    Title       = controlName,
                    Description = controlName,
                    ControlType = controlType.AssemblyQualifiedName,
                    CssClass    = "sfTextboxIcn"
                };
                section.Tools.Add(tool);
                saveSection = true;
            }

            controlName = "SalesForceAutoComplete";
            controlType = typeof(Fields.AutoCompleteTextBox);
            if (!section.Tools.Any <ToolboxItem>(e => e.Name == controlName))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name        = controlName,
                    Title       = controlName,
                    Description = controlName,
                    ControlType = controlType.AssemblyQualifiedName,
                    CssClass    = "sfTextboxIcn"
                };
                section.Tools.Add(tool);
                saveSection = true;
            }

            if (saveSection == true)
            {
                configManager.SaveSection(config);
            }
        }
コード例 #31
0
        /// <summary>
        /// Registers a new item into the toolbox
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="title">The Title of the toolbox item</param>
        /// <param name="cssClass">The CssClass of the toolbox item</param>
        /// <param name="resourceClassId">The Resource Class Id for this toolbox item</param>
        /// <param name="sectionName">The Section for this toolbox item</param>
        public static void RegisterToolbox <T>(string title           = null, string cssClass = null,
                                               string resourceClassId = null, string sectionName = null)
        {
            // Get configuration
            using (var manager = Config.GetManager())
            {
                // Relax on the security
                manager.Provider.SuppressSecurityChecks = true;

                var config   = manager.GetSection <ToolboxesConfig>();
                var controls = config.Toolboxes["PageControls"];

                ToolboxSection section;

                // Get the default section (Content)
                if (string.IsNullOrEmpty(sectionName))
                {
                    section = controls.Sections.Where <ToolboxSection>(tb => tb.Name == ToolboxesConfig.ContentToolboxSectionName).FirstOrDefault();
                }
                else
                {
                    // Create a new section
                    section = controls.Sections.Where <ToolboxSection>(e => e.Name == sectionName).FirstOrDefault();

                    if (section == null)
                    {
                        section = new ToolboxSection(controls.Sections)
                        {
                            Name            = sectionName,
                            Title           = sectionName,
                            Description     = sectionName,
                            ResourceClassId = typeof(PageResources).Name
                        };
                        controls.Sections.Add(section);
                    }
                }

                // Register in the toolbox
                var control = typeof(T);

                // If the section is null, or the toolbox item already exists, do nothing
                if (section == null || section.Tools.Any <ToolboxItem>(t => t.Name == control.Name))
                {
                    return;
                }

                // If the toolbox item doesn't exists, create it
                var tool = new ToolboxItem(section.Tools)
                {
                    Name            = control.Name,
                    Title           = title ?? control.Name,
                    Description     = title ?? control.Name,
                    CssClass        = cssClass,
                    ResourceClassId = resourceClassId,
                    ControlType     = control.AssemblyQualifiedName
                };

                section.Tools.Add(tool);
                manager.SaveSection(config);
            }
        }
コード例 #32
0
ファイル: Module.cs プロジェクト: eulalie367/littleapps
        /// <summary>
        /// Installs module's toolbox configuration.
        /// </summary>
        /// <param name="initializer">The initializer.</param>
        protected override void InstallConfiguration(SiteInitializer initializer)
        {
            // get section from toolbox
            var config = initializer.Context.GetConfig<ToolboxesConfig>();
            var pageControls = config.Toolboxes["PageControls"];
            var section = pageControls
                .Sections
                .Where<ToolboxSection>(e => e.Name == ToolboxesConfig.ContentToolboxSectionName)
                .FirstOrDefault();

            // create it if it doesn't exist
            if (section == null)
            {
                section = new ToolboxSection(pageControls.Sections)
                {
                    Name = ToolboxesConfig.ContentToolboxSectionName,
                    Title = "ContentToolboxSectionTitle",
                    Description = "ContentToolboxSectionDescription",
                    ResourceClassId = typeof(PageResources).Name
                };
                pageControls.Sections.Add(section);
            }

            // add Projects view if it doesn't exist
            if (!section.Tools.Any<ToolboxItem>(e => e.Name == "ProjectsView"))
            {
                var tool = new ToolboxItem(section.Tools)
                {
                    Name = "ProjectsView",
                    Title = "Projects View",
                    Description = "Public control from the Projects module",
                    ModuleName = ProjectsModule.ModuleName,
                    CssClass = "sfProjectsViewIcn",
                    ControlType = typeof(ProjectsView).AssemblyQualifiedName
                };
                section.Tools.Add(tool);
            }
        }
コード例 #33
0
        /// <summary>
        /// Gets the toolbox section where the dynamic widget will be placed.
        /// </summary>
        /// <param name="dynamicModule">The dynamic module.</param>
        /// <param name="toolboxesConfig">The toolboxes configuration.</param>
        /// <returns></returns>
        private static ToolboxSection GetModuleToolboxSection(DynamicModule dynamicModule, ToolboxesConfig toolboxesConfig)
        {
            var pageControls = toolboxesConfig.Toolboxes["PageControls"];
            var moduleSectionName = string.Concat(DynamicModuleType.defaultNamespace, ".", MvcWidgetInstaller.moduleNameValidationRegex.Replace(dynamicModule.Name, string.Empty));
            ToolboxSection section = pageControls.Sections.Where<ToolboxSection>(e => e.Name == moduleSectionName).FirstOrDefault();

            if (section == null)
            {
                var sectionDescription = string.Format(MvcWidgetInstaller.ModuleSectionDescription, dynamicModule.GetTitle());
                section = new ToolboxSection(pageControls.Sections)
                {
                    Name = moduleSectionName,
                    Title = dynamicModule.Title,
                    Description = sectionDescription
                };

                pageControls.Sections.Add(section);
            }

            return section;
        }