Exemplo n.º 1
0
        /// <summary>
        /// Creates the specified page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="controlUid">The control uid.</param>
        /// <param name="instanseUid">The instanse uid.</param>
        /// <returns></returns>
        public static Control Create(TemplateControl page, string controlUid, string instanseUid)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            if (controlUid == null)
            {
                throw new ArgumentNullException("controlUid");
            }

            Initialize();
            Control retVal = null;

            // Load Control Info
            DynamicControlInfo info = GetControlInfo(controlUid);

            if (info == null)
            {
                return(null);
            }
            //throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid control Uid '{0}'", controlUid), "controlUid");

            // Try Load Control
            if (!string.IsNullOrEmpty(info.Path))
            {
                retVal = page.LoadControl(CreateControlVirtualPath(info.Path));
            }
            else if (!string.IsNullOrEmpty(info.Type))
            {
                retVal = (Control)AssemblyUtil.LoadObject(info.Type);
            }

            // Try Load Adapter
            if (retVal != null && (!string.IsNullOrEmpty(info.AdapterPath) || !string.IsNullOrEmpty(info.AdapterType)))
            {
                Control adapter = null;

                if (!string.IsNullOrEmpty(info.Path))
                {
                    adapter = page.LoadControl(CreateControlVirtualPath(info.AdapterPath));
                }
                else if (!string.IsNullOrEmpty(info.Type))
                {
                    adapter = (Control)AssemblyUtil.LoadObject(info.AdapterType);
                }

                if (adapter != null)
                {
                    // Add Control to adapter
                    adapter.Controls.Add(retVal);

                    // Return adapter
                    retVal = adapter;
                }
            }

            return(retVal);
        }
Exemplo n.º 2
0
        public static T LoadControl <T>(TemplateControl containerControl, string ControlSrc) where T : Control
        {
            T ctrl;

            if (ControlSrc.ToLower().EndsWith(".ascx"))
            {
                ctrl = (T)containerControl.LoadControl("~/" + ControlSrc);
            }
            else
            {
                System.Type objType = Framework.Reflection.CreateType(ControlSrc);
                ctrl = (T)containerControl.LoadControl(objType, null);
            }
            return(ctrl);
        }
Exemplo n.º 3
0
        // Internals //////////////////////////////////////////////////////
        private Control LoadUserInterface(TemplateControl page, string path)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            Control ui;

            try
            {
                ui = page.LoadControl(path);
            }
            catch (Exception e) //logged
            {
                Logger.WriteException(e);
                HasError = true;
                var msg        = String.Format("{0}", e.Message);
                var msgControl = new Label {
                    ID = "RuntimeErrMsg", Text = msg, ForeColor = Color.Red
                };
                return(msgControl);
            }
            return(ui);
        }
Exemplo n.º 4
0
        public void LoadWidgets(IEnumerable <DefaultWidgetSetupView> widgetModels, Control placeholder, TemplateControl page)
        {
            if (placeholder == null)
            {
                return;
            }

            if (page == null)
            {
                return;
            }

            if (widgetModels == null)
            {
                return;
            }

            foreach (DefaultWidgetSetupView item in widgetModels.OrderBy(x => x.WidgetOrder))
            {
                using (MixERPWidget widget = page.LoadControl(item.WidgetSource) as MixERPWidget)
                {
                    if (widget != null)
                    {
                        placeholder.Controls.Add(widget);
                        widget.OnControlLoad(widget, new EventArgs());
                    }
                }
            }
        }
Exemplo n.º 5
0
        public Control CreateControl(TemplateControl containerControl, string controlKey, string controlSrc)
        {
            // load from a typename in an assembly ( ie. server control)
            var objType = Reflection.CreateType(controlSrc);

            return(containerControl.LoadControl(objType, null));
        }
Exemplo n.º 6
0
        public void LoadOtherWidgets(List <Widget> widgetModels, Control placeholder, TemplateControl page)
        {
            if (placeholder == null)
            {
                return;
            }

            if (page == null)
            {
                return;
            }

            if (widgetModels == null || widgetModels.Count().Equals(0))
            {
                this.AppendNotFoundMessage(placeholder);
                return;
            }

            foreach (Widget item in widgetModels.OrderBy(x => x.WidgetId))
            {
                using (MixERPWidget widget = page.LoadControl(item.WidgetSource) as MixERPWidget)
                {
                    if (widget != null)
                    {
                        placeholder.Controls.Add(widget);
                        widget.OnControlLoad(widget, new EventArgs());
                    }
                }
            }
        }
Exemplo n.º 7
0
        public static void LoadWidgets(IEnumerable <WidgetModel> widgetModels, Control placeholder, TemplateControl page)
        {
            if (placeholder == null)
            {
                return;
            }

            if (page == null)
            {
                return;
            }

            if (widgetModels == null)
            {
                return;
            }

            var groups = widgetModels.OrderBy(x => x.RowNumber).ThenBy(x => x.ColumnNumber).GroupBy(x => new { x.RowNumber });

            foreach (var group in groups)
            {
                foreach (WidgetModel item in group)
                {
                    using (MixERPWidgetBase widget = page.LoadControl(item.WidgetSource) as MixERPWidgetBase)
                    {
                        if (widget != null)
                        {
                            placeholder.Controls.Add(widget);
                            widget.OnControlLoad(widget, new EventArgs());
                        }
                    }
                }
            }
        }
Exemplo n.º 8
0
        protected override void Render(HtmlTextWriter output)
        {
            Control objContainer = TemplateControl.LoadControl(String.Concat("~/Modulos/CMS/Modulos", PathModulo));

            objContainer.ID = string.Concat("CTT_", IdModulo);

            this.Controls.Add(objContainer);

            string  auxOutputPar = null;
            dynamic tempWriter   = new StringWriter();

            base.RenderChildren(new HtmlTextWriter(tempWriter));
            auxOutputPar = tempWriter.ToString();

            //se o resultado for um div vazio, retorna string.Empty. Essa verificação feita assim ignora case e qualquer atributo no div,
            //além de considerar vazio um div que contenha apenas espaçamento (espaços, tabs, quebras de linha, mas sem conteúdo)
            {
                if (System.Text.RegularExpressions.Regex.IsMatch(auxOutputPar, "(?is)^\\W*<div[^>]*>\\W*</div>\\W*$"))
                {
                    auxOutputPar = string.Empty;
                }
            }

            output.Write(auxOutputPar);
        }
Exemplo n.º 9
0
        protected override void OnPreRender(EventArgs e)
        {
            base.OnPreRender(e);
            Title = (!String.IsNullOrEmpty(Title) ? Title : Resources.Resource.RecentActivity);

            var activityBox = (RecentActivityBox)TemplateControl.LoadControl(RecentActivityBox.Location);

            activityBox.userActivityList = UserActivityManager.GetUserActivities(
                TenantId,
                UserId,
                ProductId,
                new[] { ModuleId },
                UserActivityConstants.AllActionType,
                null,
                0, MaxItems);
            activityBox.MaxLengthTitle = 20;
            activityBox.ItemCSSClass   = ItemCSSClass;
            Controls.Add(activityBox);

            Controls.Add(new LiteralControl
            {
                Text =
                    string.Format("<div style='margin:10px 20px 0 20px;'><a href='{0}'>{1}</a></div>",
                                  WhatsNew.GetUrlForModule(ProductId, ModuleId),
                                  Resources.Resource.ToWhatsNewPage)
            });
        }
Exemplo n.º 10
0
        /// <summary>
        /// Loads a check-in block to determine if it will require a selection or not. This is used to find the
        /// next page/block that does require a selection so that user can be redirected once to that block,
        /// rather than just continuously redirected to next/prev page blocks and possibly exceeding the maximum
        /// number of redirects.
        /// </summary>
        /// <param name="attributeKey">The attribute key.</param>
        /// <returns></returns>
        protected CheckInBlock GetCheckInBlock(string attributeKey)
        {
            var pageReference = new PageReference(GetAttributeValue(attributeKey));

            if (pageReference.PageId > 0)
            {
                var page = PageCache.Get(pageReference.PageId);
                if (page != null)
                {
                    foreach (var block in page.Blocks.OrderBy(b => b.Order))
                    {
                        var control = TemplateControl.LoadControl(block.BlockType.Path);
                        if (control != null)
                        {
                            var checkinBlock = control as CheckInBlock;
                            if (checkinBlock != null)
                            {
                                checkinBlock.SetBlock(page, block, true, true);
                                checkinBlock.GetState();
                                return(checkinBlock);
                            }
                        }
                    }
                }
            }

            return(null);
        }
Exemplo n.º 11
0
        /// <summary>
        /// Handles the Load event of the Router_Page control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event
        /// data.</param>
        private void Router_Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                // Load the menu on the left
                string         leftControl    = ControlSharedControlsWikiMenu;
                WikiModuleBase wikiModuleBase = (WikiModuleBase)TemplateControl.LoadControl(leftControl);
                wikiModuleBase.ModuleConfiguration = this.ModuleConfiguration;
                wikiModuleBase.ID = System.IO.Path.GetFileNameWithoutExtension(leftControl);
                this.phWikiMenu.Controls.Add(wikiModuleBase);

                string         controlToLoad = this.GetControlString(Request.QueryString["loc"]);
                WikiModuleBase wikiContent   = (WikiModuleBase)LoadControl(controlToLoad);
                wikiContent.ModuleConfiguration = this.ModuleConfiguration;
                wikiContent.ID = System.IO.Path.GetFileNameWithoutExtension(controlToLoad);
                this.phWikiContent.Controls.Add(wikiContent);

                this.LoadWikiButtonControl(controlToLoad);

                // Print the Topic
                foreach (ModuleAction objAction in this.Actions)
                {
                    if (objAction.CommandName.Equals(ModuleActionType.PrintModule))
                    {
                        objAction.Url += "&topic=" + WikiMarkup.EncodeTitle(this.PageTopic);
                    }
                }
            }
            catch (Exception exc)
            {
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Load" /> event.
        /// </summary>
        /// <param name="e">The <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            var canAdministrateBlockOnPage = false;
            var pageBlocks = PageCache.Blocks;

            foreach (Rock.Web.Cache.BlockCache block in pageBlocks)
            {
                bool canAdministrate = block.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson);
                bool canEdit         = block.IsAuthorized(Authorization.EDIT, CurrentPerson);
                bool canView         = block.IsAuthorized(Authorization.VIEW, CurrentPerson);

                // Make sure user has access to view block instance
                if (canAdministrate || canEdit || canView)
                {
                    Control control = null;

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

                    if (control == null)
                    {
                        try
                        {
                            control = TemplateControl.LoadControl(block.BlockType.Path);
                            control.ClientIDMode = ClientIDMode.AutoID;
                        }
                        catch (Exception)
                        {
                            // Swallow this exception--NOM NOM
                        }
                    }

                    if (control != null)
                    {
                        if (canAdministrate || (canEdit && control is RockBlockCustomSettings))
                        {
                            canAdministrateBlockOnPage = true;
                        }
                    }
                }
            }

            if (PageCache.IncludeAdminFooter && (PageCache.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson) || canAdministrateBlockOnPage))
            {
                RockPage.AddCSSLink(ResolveRockUrl("~~/Styles/theme.css"));
            }
        }
Exemplo n.º 13
0
        /// -----------------------------------------------------------------------------
        /// <summary>
        /// LoadControl loads a control and returns a reference to the control
        /// </summary>
        /// <typeparam name="T">The type of control to Load</typeparam>
        /// <param name="containerControl">The parent Container Control</param>
        /// <param name="ControlSrc">The source for the control.  This can either be a User Control (.ascx) or a compiled
        /// control.</param>
        /// <returns>A Control of type T</returns>
        /// <history>
        ///     [cnurse]	12/05/2007	Created
        /// </history>
        /// -----------------------------------------------------------------------------
        public static T LoadControl <T>(TemplateControl containerControl, string ControlSrc) where T : Control
        {
            T ctrl;

            //load the control dynamically
            if (ControlSrc.ToLower().EndsWith(".ascx"))
            {
                //load from a user control on the file system
                ctrl = (T)containerControl.LoadControl("~/" + ControlSrc);
            }
            else
            {
                //load from a typename in an assembly ( ie. server control )
                Type objType = Reflection.CreateType(ControlSrc);
                ctrl = (T)containerControl.LoadControl(objType, null);
            }
            return(ctrl);
        }
Exemplo n.º 14
0
        private static BaseModuleControl LoadModuleControl(TemplateControl page, ModuleBase module)
        {
            BaseModuleControl ctrl =
                (BaseModuleControl)page.LoadControl(UrlHelper.GetApplicationPath() + module.CurrentViewControlPath);

            ctrl.ID     = "ctrl" + module.Section.Id;
            ctrl.Module = module;
            return(ctrl);
        }
Exemplo n.º 15
0
        public static T LoadControl <T>([NotNull] this TemplateControl thisValue, string virtualPath, string invokeMethod, params object[] parameters)
            where T : class
        {
            T ctlToLoad;

            // If the invokeMethod is empty, I will go for the constructor
            if (string.IsNullOrEmpty(invokeMethod))
            {
                Type type = GetTypeFromUrl(thisValue, virtualPath);
                ctlToLoad = thisValue.LoadControl(type, parameters) as T;
            }
            else
            {
                ctlToLoad = thisValue.LoadControl(thisValue.ResolveUrl(virtualPath)) as T;
                MethodInfo method = ctlToLoad?.AsType().FindMethod(invokeMethod, types: parameters.Types());
                method?.Invoke(ctlToLoad, parameters);
            }

            return(ctlToLoad);
        }
Exemplo n.º 16
0
        public static Control LoadModuleControl(TemplateControl containerControl, ModuleInfo moduleConfiguration)
        {
            Control control = null;

            string extension = Path.GetExtension(moduleConfiguration.ModuleControl.ControlSrc.ToLower());

            IModuleControlFactory controlFactory = null;

            switch (extension)
            {
            case ".ascx":
                controlFactory = new WebFormsModuleControlFactory();
                break;

            case ".cshtml":
            case ".vbhtml":
                Type factoryType = Reflection.CreateType("DotNetNuke.Web.Razor.RazorModuleControlFactory");
                if (factoryType != null)
                {
                    controlFactory = Reflection.CreateObject(factoryType) as IModuleControlFactory;
                }
                break;

            default:
                // load from a typename in an assembly ( ie. server control)
                Type objType = Reflection.CreateType(moduleConfiguration.ModuleControl.ControlSrc);
                control = (containerControl.LoadControl(objType, null));
                break;
            }

            if (controlFactory != null)
            {
                control = controlFactory.CreateModuleControl(containerControl, moduleConfiguration);
            }

            // set the control ID to the resource file name ( ie. controlname.ascx = controlname )
            // this is necessary for the Localization in PageBase
            if (control != null)
            {
                control.ID = Path.GetFileNameWithoutExtension(moduleConfiguration.ModuleControl.ControlSrc);

                var moduleControl = control as IModuleControl;

                if (moduleControl != null)
                {
                    moduleControl.ModuleContext.Configuration = moduleConfiguration;
                }
            }

            return(control);
        }
Exemplo n.º 17
0
        internal static TControlType LoadExtensionControl <TControlType>(string rootPhysicalPath, string extensionFolder,
                                                                         string extensionName, string controlName,
                                                                         TemplateControl parentControl)
            where TControlType : class
        {
            // Find the control path and verify its existance
            var ctrlPath = GetExtensionFile(rootPhysicalPath, extensionFolder, extensionName, "Settings.ascx");

            if (!File.Exists(ctrlPath))
            {
                return(null); // Control doesn't exist
            }

            // Load the control and return it
            return(parentControl.LoadControl(ctrlPath) as TControlType);
        }
Exemplo n.º 18
0
        /// <summary>
        /// Creates the property page.
        /// </summary>
        /// <param name="page">The page.</param>
        /// <param name="controlUid">The control uid.</param>
        /// <returns></returns>
        public static Control CreatePropertyPage(TemplateControl page, string controlUid)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }

            if (controlUid == null)
            {
                throw new ArgumentNullException("controlUid");
            }

            Initialize();
            Control retVal = null;

            // Load Control Info
            DynamicControlInfo info = GetControlInfo(controlUid.Split('_')[0]);

            if (info == null)
            {
                return(null);
            }
            //    throw new ArgumentException(string.Format(CultureInfo.InvariantCulture, "Invalid control Uid '{0}'", controlUid), "controlUid");

            // Try Load Control
            if (!string.IsNullOrEmpty(info.PropertyPagePath))
            {
                retVal = page.LoadControl(CreateControlVirtualPath(info.PropertyPagePath));
            }
            else if (!string.IsNullOrEmpty(info.PropertyPageType))
            {
                retVal = (Control)AssemblyUtil.LoadObject(info.PropertyPageType);
            }

            //TODO: Load default PP control
            //if (retVal == null)
            //    retVal = page.LoadControl();

            if (retVal == null)
            {
                throw new InvalidOperationException(String.Format("Cant load PropertyPageControl for control: {0}", controlUid));
            }

            return(retVal);
        }
Exemplo n.º 19
0
        public override object Build(BuilderContext context)
        {
            string url = context.Builtin.Properties.GetRawValue("url");

            if (string.IsNullOrWhiteSpace(url))
            {
                return(base.Build(context));
            }

            TemplateControl template = context.Owner as TemplateControl;

            if (template != null)
            {
                return(template.LoadControl(url));
            }

            return(null);
        }
Exemplo n.º 20
0
        protected override void OnInit(EventArgs e)
        {
            base.OnInit(e);

            // Fail if we didn't get a virtual path
            if (String.IsNullOrEmpty(_virtualPath))
            {
                ThrowException("The UserControl tag must have a 'VirtualPath' attribute", null);
            }

            try {
                _uc = TemplateControl.LoadControl(_virtualPath);
            } catch (Exception exception) {
                ThrowException(null, exception);
            }

            // Give our ID to the created UserControl, and change ours to avoid conflict
            string id = ID;

            ID     = "__" + id;
            _uc.ID = id;

            // Handle expando attributes by forwarding them to the created control
            IScriptTemplateControl scriptUC = _uc as IScriptTemplateControl;

            if (scriptUC != null)
            {
                if (_attributes != null)
                {
                    foreach (KeyValuePair <string, string> entry in _attributes)
                    {
                        try {
                            scriptUC.ScriptTemplateControl.SetProperty(entry.Key, entry.Value);
                        } catch (Exception exception) {
                            ThrowException(null, exception);
                        }
                    }
                }
            }

            Controls.Clear();
            Controls.Add(_uc);
        }
Exemplo n.º 21
0
        public void LoadWidgets(IEnumerable <Widget> widgetModels, Control placeholder, TemplateControl page)
        {
            if (placeholder == null)
            {
                return;
            }

            if (page == null)
            {
                return;
            }

            if (widgetModels == null)
            {
                return;
            }
            string[] ExemptWidgets = new string[] { "OfficeInformationWidget", "LinksWidget", "WorkflowWidget" };
            var      groups        = widgetModels.OrderBy(x => x.RowNumber).ThenBy(x => x.ColumnNumber).GroupBy(x => new { x.RowNumber });

            foreach (var group in groups)
            {
                foreach (Widget item in group)
                {
                    if (!ExemptWidgets.Contains(item.WidgetName))
                    {
                        using (MixERPWidgetBase widget = page.LoadControl(item.WidgetSource) as MixERPWidgetBase)
                        {
                            if (widget != null)
                            {
                                placeholder.Controls.Add(widget);
                                widget.OnControlLoad(widget, new EventArgs());
                            }
                        }
                    }
                }
            }
        }
        public static ordering.AddressBase Get(string locale, TemplateControl control, string controlPath, bool isXml)
        {
            ordering.AddressBase addressBase = null;

            try
            {
                if (!isXml)
                {
                    addressBase = control.LoadControl(controlPath) as ordering.AddressBase;
                    addressBase.LoadPage();
                }
                else
                {
                    addressBase         = new ordering.AddressControl();
                    addressBase.XMLFile = controlPath;
                }
            }
            catch (HttpException ex)
            {
                LoggerHelper.Error(ex.ToString());
            }

            return(addressBase);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            try
            {
                int pageId = int.MinValue;
                if (int.TryParse(PageParameter("Page"), out pageId))
                {
                    // hide the current page in the page picker to prevent setting this page's parent page to itself (or one of it's child pages)
                    ppParentPage.HiddenPageIds = new int[] { pageId };

                    var pageCache = Rock.Web.Cache.PageCache.Read(pageId);

                    DialogPage dialogPage = this.Page as DialogPage;
                    if (dialogPage != null)
                    {
                        dialogPage.OnSave  += new EventHandler <EventArgs>(masterPage_OnSave);
                        dialogPage.SubTitle = string.Format("Id: {0}", pageCache.Id);
                    }

                    if (pageCache.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
                    {
                        ddlMenuWhen.BindToEnum(typeof(DisplayInNavWhen));

                        var blockContexts = new Dictionary <string, string>();
                        foreach (var block in pageCache.Blocks)
                        {
                            var blockControl = TemplateControl.LoadControl(block.BlockType.Path) as RockBlock;
                            if (blockControl != null)
                            {
                                blockControl.SetBlock(block);
                                foreach (var context in blockControl.ContextTypesRequired)
                                {
                                    if (!blockContexts.ContainsKey(context.Name))
                                    {
                                        blockContexts.Add(context.Name, context.FriendlyName);
                                    }
                                }
                            }
                        }

                        phContextPanel.Visible = blockContexts.Count > 0;

                        foreach (var context in blockContexts)
                        {
                            var tbContext = new RockTextBox();
                            tbContext.ID       = string.Format("context_{0}", context.Key.Replace('.', '_'));
                            tbContext.Required = true;
                            tbContext.Label    = context.Value + " Parameter Name";
                            tbContext.Help     = "The page parameter name that contains the id of this context entity.";
                            if (pageCache.PageContexts.ContainsKey(context.Key))
                            {
                                tbContext.Text = pageCache.PageContexts[context.Key];
                            }

                            phContext.Controls.Add(tbContext);
                        }

                        _pageId = pageCache.Id;
                    }
                    else
                    {
                        DisplayError("You are not authorized to administrate this page");
                    }
                }
                else
                {
                    DisplayError("Invalid Page Id value");
                }
            }
            catch (SystemException ex)
            {
                DisplayError(ex.Message);
            }

            base.OnInit(e);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Adds the admin controls.
        /// </summary>
        /// <param name="block">The block.</param>
        /// <param name="pnlLayoutItem">The PNL layout item.</param>
        private void AddAdminControls(BlockCache block, PlaceHolder pnlLayoutItem)
        {
            Panel pnlAdminButtons = new Panel {
                ID = "pnlBlockConfigButtons", CssClass = "pull-right actions"
            };

            // Block Properties
            var btnBlockProperties = new Literal
            {
                Text = string.Format(@"<a title='Block Properties' class='btn btn-sm btn-default btn-square properties' href='javascript: Rock.controls.modal.show($(this), ""/BlockProperties/{0}?t=Block Properties"")' height='500px'><i class='fa fa-cog'></i></a>", block.Id)
            };

            pnlAdminButtons.Controls.Add(btnBlockProperties);

            // Block Security
            int entityTypeBlockId = EntityTypeCache.Get <Rock.Model.Block>().Id;
            var btnBlockSecurity  = new SecurityButton
            {
                ID           = "btnBlockSecurity",
                EntityTypeId = entityTypeBlockId,
                EntityId     = block.Id,
                Title        = "Edit Security"
            };

            btnBlockSecurity.AddCssClass("btn btn-sm btn-square btn-security");
            pnlAdminButtons.Controls.Add(btnBlockSecurity);

            // Delete Block
            LinkButton btnDeleteBlock = new LinkButton
            {
                ID              = string.Format("btnDeleteBlock_{0}", block.Id),
                CommandName     = "Delete",
                CommandArgument = block.Id.ToString(),
                CssClass        = "btn btn-sm btn-square btn-danger",
                Text            = "<i class='fa fa-times'></i>",
                ToolTip         = "Delete Block"
            };

            btnDeleteBlock.Attributes["onclick"] = string.Format("javascript: return Rock.dialogs.confirmDelete(event, '{0}');", Block.FriendlyTypeName);

            pnlAdminButtons.Controls.Add(btnDeleteBlock);

            pnlLayoutItem.Controls.Add(pnlAdminButtons);

            RockBlock blockControl = null;
            IEnumerable <WebControl> customAdminControls = new List <WebControl>();

            try
            {
                if (!string.IsNullOrWhiteSpace(block.BlockType.Path))
                {
                    blockControl = TemplateControl.LoadControl(block.BlockType.Path) as RockBlock;
                }
                else if (block.BlockType.EntityTypeId.HasValue)
                {
                    var blockEntity = Activator.CreateInstance(block.BlockType.EntityType.GetEntityType());

                    var wrapper = new RockBlockTypeWrapper
                    {
                        Page  = RockPage,
                        Block = (Rock.Blocks.IRockBlockType)blockEntity
                    };

                    wrapper.InitializeAsUserControl(RockPage);
                    wrapper.AppRelativeTemplateSourceDirectory = "~";

                    blockControl = wrapper;
                }

                blockControl.SetBlock(block.Page, block, true, true);
                var      adminControls           = blockControl.GetAdministrateControls(true, true);
                string[] baseAdminControlClasses = new string[4] {
                    "properties", "security", "block-move", "block-delete"
                };
                customAdminControls = adminControls.OfType <WebControl>().Where(a => !baseAdminControlClasses.Any(b => a.CssClass.Contains(b)));
            }
            catch (Exception ex)
            {
                // if the block doesn't compile, just ignore it since we are just trying to get the admin controls
                Literal lblBlockError = new Literal();
                lblBlockError.Text = string.Format("<span class='label label-danger'>ERROR: {0}</span>", ex.Message);
                pnlLayoutItem.Controls.Add(lblBlockError);
            }

            foreach (var customAdminControl in customAdminControls)
            {
                if (customAdminControl is LinkButton)
                {
                    LinkButton btn = customAdminControl as LinkButton;
                    if (btn != null)
                    {
                        // ensure custom link button looks like a button
                        btn.AddCssClass("btn");
                        btn.AddCssClass("btn-sm");
                        btn.AddCssClass("btn-default");
                        btn.AddCssClass("btn-square");

                        // some admincontrols will toggle the BlockConfig bar, but this isn't a block config bar, so remove the javascript
                        if (btn.Attributes["onclick"] != null)
                        {
                            btn.Attributes["onclick"] = btn.Attributes["onclick"].Replace("Rock.admin.pageAdmin.showBlockConfig()", string.Empty);
                        }
                    }
                }

                pnlLayoutItem.Controls.Add(customAdminControl);
            }

            if (customAdminControls.Any() && blockControl != null)
            {
                pnlBlocksHolder.Controls.Add(blockControl);
            }
        }
Exemplo n.º 25
0
 private Control myLoadControl(string page)
 {
     return(TemplateControl.LoadControl(string.Format(contentPage, page)));
 }
Exemplo n.º 26
0
        /// <summary>
        /// Raises the <see cref="E:System.Web.UI.Control.Init" /> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs" /> object that contains the event data.</param>
        protected override void OnInit(EventArgs e)
        {
            int?pageId = PageParameter("Page").AsIntegerOrNull();

            btnSecurity.EntityTypeId = EntityTypeCache.Read(typeof(Rock.Model.Page)).Id;

            // only show if there was a Page parameter specified
            this.Visible = pageId.HasValue;

            if (pageId.HasValue)
            {
                // hide the current page in the page picker to prevent setting this page's parent page to itself (or one of it's child pages)
                ppParentPage.HiddenPageIds = new int[] { pageId.Value };

                var pageCache = Rock.Web.Cache.PageCache.Read(pageId.Value);

                DialogPage dialogPage = this.Page as DialogPage;
                if (dialogPage != null)
                {
                    dialogPage.OnSave  += new EventHandler <EventArgs>(masterPage_OnSave);
                    dialogPage.SubTitle = string.Format("Id: {0}", pageId);
                }

                ddlMenuWhen.BindToEnum <DisplayInNavWhen>();

                if (pageCache != null && pageCache.IsAuthorized(Authorization.ADMINISTRATE, CurrentPerson))
                {
                    var blockContexts = new Dictionary <string, string>();
                    foreach (var block in pageCache.Blocks)
                    {
                        var blockControl = TemplateControl.LoadControl(block.BlockType.Path) as RockBlock;
                        if (blockControl != null)
                        {
                            blockControl.SetBlock(pageCache, block);
                            foreach (var context in blockControl.ContextTypesRequired)
                            {
                                if (!blockContexts.ContainsKey(context.Name))
                                {
                                    blockContexts.Add(context.Name, context.FriendlyName);
                                }
                            }
                        }
                    }

                    phContextPanel.Visible = blockContexts.Count > 0;

                    foreach (var context in blockContexts)
                    {
                        var tbContext = new RockTextBox();
                        tbContext.ID       = string.Format("context_{0}", context.Key.Replace('.', '_'));
                        tbContext.Required = true;
                        tbContext.Label    = context.Value + " Parameter Name";
                        tbContext.Help     = "The page parameter name that contains the id of this context entity.";
                        if (pageCache.PageContexts.ContainsKey(context.Key))
                        {
                            tbContext.Text = pageCache.PageContexts[context.Key];
                        }

                        phContext.Controls.Add(tbContext);
                    }
                }
            }
            else
            {
                // no 'Page' parameter specified so just leave hidden
            }

            base.OnInit(e);
        }
Exemplo n.º 27
0
 private void SeleccionarOpcionMenu(string MenuID)
 {
     if (MenuID == "1")
     {
         Control newControl = TemplateControl.LoadControl("UserControls/Admin/Estadio.ascx");
         contentPNL.Controls.Add(newControl);
         return;
     }
     if (MenuID == "2")
     {
         Control newControl = TemplateControl.LoadControl("UserControls/Admin/Grupo.ascx");
         contentPNL.Controls.Add(newControl);
         return;
     }
     if (MenuID == "3")
     {
         Control newControl = TemplateControl.LoadControl("UserControls/Admin/Pais.ascx");
         contentPNL.Controls.Add(newControl);
         return;
     }
     if (MenuID == "4")
     {
         objUsuario.CerrarSesion();
         Response.Redirect("~/");
     }
     if (MenuID == "5")
     {
         Control newControl = TemplateControl.LoadControl("UserControls/Admin/Fase.ascx");
         contentPNL.Controls.Add(newControl);
         return;
     }
     if (MenuID == "6")
     {
         Control newControl = TemplateControl.LoadControl("UserControls/Admin/GrupoPais.ascx");
         contentPNL.Controls.Add(newControl);
         return;
     }
     if (MenuID == "7")
     {
         Control newControl = TemplateControl.LoadControl("UserControls/Admin/Partido.ascx");
         contentPNL.Controls.Add(newControl);
         return;
     }
     if (MenuID == "8")
     {
         Control newControl = TemplateControl.LoadControl("UserControls/Admin/Usuarios.ascx");
         contentPNL.Controls.Add(newControl);
         return;
     }
     if (MenuID == "9")
     {
         Control newControl = TemplateControl.LoadControl("UserControls/Admin/ActualizarEstadisticasPartidos.ascx");
         contentPNL.Controls.Add(newControl);
         return;
     }
     if (MenuID == "10")
     {
         Control newControl = TemplateControl.LoadControl("UserControls/Admin/ActualizarPuntosUsuario.ascx");
         contentPNL.Controls.Add(newControl);
         return;
     }
 }
Exemplo n.º 28
0
 public virtual T CreateControlView <T>(params object[] args) where T : IControlView
 {
     return((T)(object)parentView.LoadControl(IoCHelper.GetControlVirtualPath(
                                                  TypeNameSource, TypeNameSourceExclude, typeof(T), TypeNameDest, null)));
 }
Exemplo n.º 29
0
 public static T LoadControl <T>(this TemplateControl entry, Uri userControlsPath)
     where T : UserControl
 {
     return((T)entry.LoadControl(string.Concat(userControlsPath.ToString().IfNotThere().Append("/"), ControlExtensions.userControlFileName <T>())));
 }
Exemplo n.º 30
0
 public static T LoadControl <T>(this TemplateControl entry)
     where T : UserControl
 {
     return((T)entry.LoadControl(ControlExtensions.userControlFileName <T>()));
 }