Ejemplo n.º 1
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// InjectModule injects a Module (and its container) into the Pane
        /// </summary>
        /// <param name="module">The Module</param>
        /// -----------------------------------------------------------------------------
        public void InjectModule(ModuleInfo module)
        {
            _containerWrapperControl = new HtmlGenericControl("div");
            PaneControl.Controls.Add(_containerWrapperControl);

            //inject module classes
            string classFormatString   = "DnnModule DnnModule-{0} DnnModule-{1}";
            string sanitizedModuleName = Null.NullString;

            if (!String.IsNullOrEmpty(module.DesktopModule.ModuleName))
            {
                sanitizedModuleName = Globals.CreateValidClass(module.DesktopModule.ModuleName, false);
            }

            if (IsVesionableModule(module))
            {
                classFormatString += " DnnVersionableControl";
            }

            _containerWrapperControl.Attributes["class"] = String.Format(classFormatString, sanitizedModuleName, module.ModuleID);

            try
            {
                if (!Globals.IsAdminControl() && PortalSettings.InjectModuleHyperLink)
                {
                    _containerWrapperControl.Controls.Add(new LiteralControl("<a name=\"" + module.ModuleID + "\"></a>"));
                }

                //Load container control
                Containers.Container container = LoadModuleContainer(module);

                //Add Container to Dictionary
                Containers.Add(container.ID, container);

                // hide anything of type ActionsMenu - as we're injecting our own menu now.
                container.InjectActionMenu = (container.Controls.OfType <ActionBase>().Count() == 0);
                if (!container.InjectActionMenu)
                {
                    foreach (var actionControl in container.Controls.OfType <IActionControl>())
                    {
                        if (actionControl is ActionsMenu)
                        {
                            Control control = actionControl as Control;
                            if (control != null)
                            {
                                control.Visible            = false;
                                container.InjectActionMenu = true;
                            }
                        }
                    }
                }

                if (Globals.IsLayoutMode() && Globals.IsAdminControl() == false)
                {
                    //provide Drag-N-Drop capabilities
                    var     dragDropContainer = new Panel();
                    Control title             = container.FindControl("dnnTitle");
                    //Assume that the title control is named dnnTitle.  If this becomes an issue we could loop through the controls looking for the title type of skin object
                    dragDropContainer.ID = container.ID + "_DD";
                    _containerWrapperControl.Controls.Add(dragDropContainer);

                    //inject the container into the page pane - this triggers the Pre_Init() event for the user control
                    dragDropContainer.Controls.Add(container);

                    if (title != null)
                    {
                        if (title.Controls.Count > 0)
                        {
                            title = title.Controls[0];
                        }
                    }

                    //enable drag and drop
                    if (title != null)
                    {
                        //The title ID is actually the first child so we need to make sure at least one child exists
                        DNNClientAPI.EnableContainerDragAndDrop(title, dragDropContainer, module.ModuleID);
                        ClientAPI.RegisterPostBackEventHandler(PaneControl, "MoveToPane", ModuleMoveToPanePostBack, false);
                    }
                }
                else
                {
                    _containerWrapperControl.Controls.Add(container);
                    if (Globals.IsAdminControl())
                    {
                        _containerWrapperControl.Attributes["class"] += " DnnModule-Admin";
                    }
                }

                //Attach Module to Container
                container.SetModuleConfiguration(module);

                //display collapsible page panes
                if (PaneControl.Visible == false)
                {
                    PaneControl.Visible = true;
                }
            }
            catch (ThreadAbortException)
            {
                //Response.Redirect may called in module control's OnInit method, so it will cause ThreadAbortException, no need any action here.
            }
            catch (Exception exc)
            {
                var lex = new ModuleLoadException(string.Format(Skin.MODULEADD_ERROR, PaneControl.ID), exc);
                if (TabPermissionController.CanAdminPage())
                {
                    //only display the error to administrators
                    _containerWrapperControl.Controls.Add(new ErrorContainer(PortalSettings, Skin.MODULELOAD_ERROR, lex).Container);
                }
                Exceptions.LogException(exc);
                throw lex;
            }
        }