public override void OnInit()
    {
        Control.OnNodeCreated += Control_OnNodeCreated;

        // Get NOT custom conversions from UI elements
        UIElementInfo root = UIElementInfoProvider.GetRootUIElementInfo("CMS.WebAnalytics");

        if (root != null)
        {
            // Get all UI elements to filter custom reports
            DataSet data = UIElementInfoProvider.GetUIElements("ElementIDPath LIKE '" + SqlHelper.EscapeLikeQueryPatterns(root.ElementIDPath) + "/%'", String.Empty, 0, "ElementName,ElementTargetUrl");
            if (!DataHelper.DataSourceIsEmpty(data) && (data.Tables.Count > 0))
            {
                // Condition for custom reports
                customWhereCondition = "StatisticsCode NOT IN (";
                foreach (DataRow dr in data.Tables[0].Rows)
                {
                    string codeName = ValidationHelper.GetString(dr["ElementName"], String.Empty);
                    customWhereCondition += "N'" + SqlHelper.GetSafeQueryString(codeName, false) + "',";
                }

                // Add special cases - don't want to show them in UI or Custom report section
                customWhereCondition += additionalConversions.Replace(';', ',');

                customWhereCondition  = customWhereCondition.TrimEnd(new[] { ',' });
                customWhereCondition += ")";

                // Filter AB Testing
                customWhereCondition += " AND (StatisticsCode NOT LIKE 'abconversion;%') AND (StatisticsCode NOT LIKE 'mvtconversion;%') AND (StatisticsCode NOT LIKE 'campconversion;%') " +
                                        "AND (StatisticsCode NOT LIKE 'absessionconversionfirst;%') AND (StatisticsCode NOT LIKE 'absessionconversionrecurring;%') " +
                                        "AND (StatisticsCode NOT LIKE 'abvisitfirst;%')  AND (StatisticsCode NOT LIKE 'abvisitreturn;%') AND (StatisticsCode <> N'campaign') and (StatisticsCode <> N'conversion') ";
            }
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        treeElem.OnNodeCreated += new CMSAdminControls_UI_UIProfiles_UIMenu.NodeCreatedEventHandler(menuElem_OnNodeCreated);

        // Get NOT custom conversions from UI elements
        UIElementInfo root = UIElementInfoProvider.GetRootUIElementInfo("CMS.WebAnalytics");

        if (root != null)
        {
            // Get all UI elements to filter custom reports
            DataSet dsElems = UIElementInfoProvider.GetUIElements("ElementIDPath LIKE '" + DataHelper.EscapeLikeQueryPatterns(root.ElementIDPath, true, true, true) + "/%'", String.Empty, 0, "ElementName,ElementTargetUrl");
            if (!DataHelper.DataSourceIsEmpty(dsElems) && (dsElems.Tables.Count > 0))
            {
                // Condition for custom reports
                customWhereCondition = "StatisticsCode NOT IN (";
                foreach (DataRow dr in dsElems.Tables[0].Rows)
                {
                    string codeName = ValidationHelper.GetString(dr["ElementName"], String.Empty);
                    customWhereCondition += "N'" + SqlHelperClass.GetSafeQueryString(codeName, false) + "',";
                }

                // Add special cases - dont want to show them in UI or Custom report section
                customWhereCondition += additionalConversions.Replace(';', ',');

                customWhereCondition  = customWhereCondition.TrimEnd(new char[] { ',' });
                customWhereCondition += ")";

                // Filter AB Testing
                customWhereCondition += " AND (StatisticsCode NOT LIKE 'abconversion;%') AND (StatisticsCode NOT LIKE 'mvtconversion;%') AND (StatisticsCode NOT LIKE 'campconversion;%') ";
            }
        }
    }
Example #3
0
    /// <summary>
    /// Gets and bulk updates UI elements. Called when the "Get and bulk update elements" button is pressed.
    /// Expects the CreateUIElement method to be run first.
    /// </summary>
    private bool GetAndBulkUpdateUIElements()
    {
        // Prepare the parameters
        string where = "ElementName LIKE N'MyNewElement%'";

        // Get the data
        DataSet elements = UIElementInfoProvider.GetUIElements(where, null);

        if (!DataHelper.DataSourceIsEmpty(elements))
        {
            // Loop through the individual items
            foreach (DataRow elementDr in elements.Tables[0].Rows)
            {
                // Create object from DataRow
                UIElementInfo modifyElement = new UIElementInfo(elementDr);

                // Update the properties
                modifyElement.ElementDisplayName = modifyElement.ElementDisplayName.ToUpper();

                // Save the changes
                UIElementInfoProvider.SetUIElementInfo(modifyElement);
            }

            return(true);
        }

        return(false);
    }
Example #4
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!StopProcessing && !URLHelper.IsPostback())
        {
            int shift = -1;
            string where = String.Empty;
            if (ModuleID != 0)
            {
                where = "ElementResourceID = " + ModuleID;
            }

            if (!String.IsNullOrEmpty(WhereCondition))
            {
                where = SqlHelper.AddWhereCondition(where, WhereCondition);
            }

            // Get the data
            DataSet ds = UIElementInfoProvider.GetUIElements(where, "ElementOrder", 0, "ElementID, ElementParentID, ElementDisplayName, ElementOrder, ElementLevel");
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                gds = new GroupedDataSource(ds, "ElementParentID");

                FillDropDownList(shift, 0);
            }
        }
    }
Example #5
0
    /// <summary>
    /// Recursivelly select or deselect all child elements.
    /// </summary>
    /// <param name="select">Determines the type of action</param>
    /// <param name="parentId">ID of the parent UIElement</param>
    /// <param name="excludeRoot">Indicates whether to exclude root element from selection/deselection</param>
    private void SelectDeselectAll(bool select, int parentId, bool excludeRoot)
    {
        // Check manage permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY))
        {
            RedirectToAccessDenied("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY);
        }

        // Get the children and select them
        string where = (ModuleID > 0) ?
                       String.Format(@"(ElementResourceID = {0} OR EXISTS (SELECT ElementID FROM CMS_UIElement AS x WHERE x.ElementIDPath like CMS_UIElement.ElementIDPath+ '%' AND x.ElementResourceID = {0})) AND
                            ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = {1}) + '%' ", ModuleID, parentId) :
                       "ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = " + parentId + ") + '%' ";
        if (excludeRoot)
        {
            where += " AND NOT ElementID = " + parentId;
        }
        if (!String.IsNullOrEmpty(GroupPreffix))
        {
            where += " AND ElementName NOT LIKE '" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(GroupPreffix)) + "%'";
        }

        using (CMSActionContext context = new CMSActionContext())
        {
            // Many updates caused deadlocks with CMS_Role table, disable touch parent of the role
            context.TouchParent = false;

            DataSet ds = UIElementInfoProvider.GetUIElements(where, null, 0, "ElementID");
            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    int id = ValidationHelper.GetInteger(dr["ElementID"], 0);
                    if (select)
                    {
                        RoleUIElementInfoProvider.AddRoleUIElementInfo(RoleID, id);
                    }
                    else
                    {
                        RoleUIElementInfoProvider.DeleteRoleUIElementInfo(RoleID, id);
                    }
                }
            }

            // Explicitly touch the role only once
            var role = RoleInfoProvider.GetRoleInfo(RoleID);
            if (role != null)
            {
                role.Update();
            }
        }
    }
Example #6
0
    protected void Page_Load(object sender, EventArgs e)
    {
        this.menuElem.OnNodeCreated += new CMSAdminControls_UI_UIProfiles_UIMenu.NodeCreatedEventHandler(menuElem_OnNodeCreated);

        ScriptHelper.RegisterClientScriptBlock(this.Page, typeof(string), "AdministrationLoadItem", ScriptHelper.GetScript(
                                                   "function LoadItem(elementName, elementUrl) \n" +
                                                   "{ \n" +
                                                   "  parent.frames['analyticsDefault'].location.href = elementUrl; \n" +
                                                   "} \n"));

        this.menuElem.EnableRootSelect = false;

        // If node preselection is happening, expand the navigation tree
        if (!String.IsNullOrEmpty(this.selectedNode))
        {
            this.menuElem.ExpandLevel = 1;
        }
        else
        {
            this.menuElem.ExpandLevel = 0;
        }

        // Get NOT custom conversions from UI elements
        UIElementInfo root = UIElementInfoProvider.GetRootUIElementInfo("CMS.WebAnalytics");

        if (root != null)
        {
            // Get all UI elements to filter custom reports
            DataSet dsElems = UIElementInfoProvider.GetUIElements("ElementIDPath LIKE '" + DataHelper.EscapeLikeQueryPatterns(root.ElementIDPath, true, true, true) + "/%'", String.Empty, 0, "ElementName,ElementTargetUrl");
            if (!SqlHelperClass.DataSourceIsEmpty(dsElems) && (dsElems.Tables.Count > 0))
            {
                // Condition for custom reports
                customWhereCondition = "StatisticsCode NOT IN (";
                foreach (DataRow dr in dsElems.Tables[0].Rows)
                {
                    string codeName = ValidationHelper.GetString(dr["ElementName"], String.Empty);
                    customWhereCondition += "N'" + SqlHelperClass.GetSafeQueryString(codeName, false) + "',";
                }

                // Add special cases - dont want to show them in UI or Custom report section
                customWhereCondition += additionalConversions.Replace(';', ',');

                customWhereCondition  = customWhereCondition.TrimEnd(new char[] { ',' });
                customWhereCondition += ")";

                // Filter AB Testing
                customWhereCondition += " AND (StatisticsCode NOT LIKE 'abconversion;%') AND (StatisticsCode NOT LIKE 'mvtconversion;%') AND (StatisticsCode NOT LIKE 'campconversion;%') ";
            }
        }
    }
    /// <summary>
    /// Recursivelly select or deselect all child elements.
    /// </summary>
    /// <param name="select">Determines the type of action</param>
    /// <param name="parentId">ID of the parent UIElement</param>
    /// <param name="excludeRoot">Indicates whether to exclude root element from selection/deselection</param>
    private void SelectDeselectAll(bool select, int parentId, bool excludeRoot)
    {
        // Check manage permission
        if (!MembershipContext.AuthenticatedUser.IsAuthorizedPerResource("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY))
        {
            RedirectToAccessDenied("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY);
        }

        // Get the children and select them (do not use module as filter if all elements should be visible)
        string where = ((ModuleID > 0) && !ShowAllElementsFromModuleSection) ?
                       String.Format(@"(ElementResourceID = {0} OR EXISTS (SELECT ElementID FROM CMS_UIElement AS x WHERE x.ElementIDPath LIKE CMS_UIElement.ElementIDPath+ '%' AND x.ElementResourceID = {0})) AND
                            ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = {1}) + '%' ", ModuleID, parentId) :
                       "ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = " + parentId + ") + '%' ";
        if (excludeRoot)
        {
            where += " AND NOT ElementID = " + parentId;
        }
        if (!String.IsNullOrEmpty(GroupPreffix))
        {
            where += " AND ElementName NOT LIKE '" + SqlHelper.EscapeLikeText(SqlHelper.EscapeQuotes(GroupPreffix)) + "%'";
        }

        using (CMSActionContext context = new CMSActionContext())
        {
            // Many updates caused deadlocks with CMS_Role table, disable touch parent of the role
            context.TouchParent = false;

            var elementIds = UIElementInfoProvider.GetUIElements()
                             .Where(where)
                             .Columns("ElementID")
                             .GetListResult <int>();

            foreach (var id in elementIds)
            {
                if (select)
                {
                    RoleUIElementInfoProvider.AddRoleUIElementInfo(RoleID, id);
                }
                else
                {
                    RoleUIElementInfoProvider.DeleteRoleUIElementInfo(RoleID, id);
                }
            }

            // Explicitly touch the role only once
            RoleInfoProvider.GetRoleInfo(RoleID)
            ?.Update();
        }
    }
    /// <summary>
    /// Handles the UniGrid's OnAction event.
    /// </summary>
    /// <param name="actionName">Name of item (button) that threw the event</param>
    /// <param name="actionArgument">ID (value of Primary key) of the corresponding data row</param>
    protected void OnAction(string actionName, object actionArgument)
    {
        if (actionName == "delete")
        {
            int resourceId = ValidationHelper.GetInteger(actionArgument, 0);

            // Check if module has any classes (including page types...)
            var classes  = DataClassInfoProvider.GetClasses().Where("ClassResourceID", QueryOperator.Equals, resourceId);
            var settings = SettingsCategoryInfoProvider.GetSettingsCategories().Where("CategoryResourceID", QueryOperator.Equals, resourceId);
            var elements = UIElementInfoProvider.GetUIElements().Where("ElementResourceID", QueryOperator.Equals, resourceId);

            if (!classes.HasResults() && !settings.HasResults() && !elements.HasResults())
            {
                ResourceInfoProvider.DeleteResourceInfo(resourceId);
            }
            else
            {
                Control.ShowError(Control.GetString("cms_resource.deleteerror"));
            }
        }
    }
    /// <summary>
    /// Recursivelly select or deselect all child elements.
    /// </summary>
    /// <param name="select">Determines the type of action</param>
    /// <param name="parentId">ID of the parent UIElement</param>
    /// <param name="excludeRoot">Indicates whether to exclude root element from selection/deselection</param>
    private void SelectDeselectAll(bool select, int parentId, bool excludeRoot)
    {
        // Check manage permission
        if (!CMSContext.CurrentUser.IsAuthorizedPerResource("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY))
        {
            RedirectToAccessDenied("CMS.UIPersonalization", CMSAdminControl.PERMISSION_MODIFY);
        }

        // Get the children and select them
        string where = "ElementIDPath LIKE (SELECT TOP 1 ElementIDPath FROM CMS_UIElement WHERE ElementID = " + parentId + ") + '%' ";
        if (excludeRoot)
        {
            where += " AND NOT ElementID = " + parentId;
        }
        if (!String.IsNullOrEmpty(this.GroupPreffix))
        {
            where += " AND ElementName NOT LIKE '" + SqlHelperClass.GetSafeQueryString(this.GroupPreffix, false) + "%'";
        }
        DataSet ds = UIElementInfoProvider.GetUIElements(where, null, 0, "ElementID");

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                int id = ValidationHelper.GetInteger(dr["ElementID"], 0);
                if (select)
                {
                    RoleUIElementInfoProvider.AddRoleUIElementInfo(this.RoleID, id);
                }
                else
                {
                    RoleUIElementInfoProvider.DeleteRoleUIElementInfo(this.RoleID, id);
                }
            }
        }
    }
Example #10
0
    /// <summary>
    /// Generates panel with buttons loaded from given UI Element.
    /// </summary>
    /// <param name="uiElementId">ID of the UI Element</param>
    protected Panel GetButtons(int uiElementId)
    {
        const int bigButtonMinimalWidth   = 40;
        const int smallButtonMinimalWidth = 66;

        Panel pnlButtons = null;

        // Load the buttons manually from UI Element
        DataSet ds = UIElementInfoProvider.GetChildUIElements(uiElementId);

        // When no child found
        if (DataHelper.DataSourceIsEmpty(ds))
        {
            // Try to use group element as button
            ds = UIElementInfoProvider.GetUIElements("ElementID = " + uiElementId, null);

            if (!DataHelper.DataSourceIsEmpty(ds))
            {
                DataRow dr  = ds.Tables[0].Rows[0];
                string  url = ValidationHelper.GetString(dr["ElementTargetURL"], "");

                // Use group element as button only if it has URL specified
                if (string.IsNullOrEmpty(url))
                {
                    ds = null;
                }
            }
        }

        if (!DataHelper.DataSourceIsEmpty(ds))
        {
            // Filter the dataset according to UI Profile
            FilterElements(ds);

            int small = 0;
            int count = ds.Tables[0].Rows.Count;

            // No buttons, render nothing
            if (count == 0)
            {
                return(null);
            }

            // Prepare the panel
            pnlButtons          = new Panel();
            pnlButtons.CssClass = "ActionButtons";

            // Prepare the table
            Table    tabGroup    = new Table();
            TableRow tabGroupRow = new TableRow();

            tabGroup.CellPadding        = 0;
            tabGroup.CellSpacing        = 0;
            tabGroup.EnableViewState    = false;
            tabGroupRow.EnableViewState = false;
            tabGroup.Rows.Add(tabGroupRow);

            List <Panel> panels = new List <Panel>();

            for (int i = 0; i < count; i++)
            {
                // Get current and next button
                UIElementInfo uiElement     = new UIElementInfo(ds.Tables[0].Rows[i]);
                UIElementInfo uiElementNext = null;
                if (i < count - 1)
                {
                    uiElementNext = new UIElementInfo(ds.Tables[0].Rows[i + 1]);
                }

                // Set the first button
                if (mFirstUIElement == null)
                {
                    mFirstUIElement = uiElement;
                }

                // Get the sizes of current and next button. Button is large when it is the only in the group
                bool isSmall     = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (count > 1);
                bool isResized   = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (!isSmall);
                bool isNextSmall = (uiElementNext != null) && (uiElementNext.ElementSize == UIElementSizeEnum.Regular);

                // Set the CSS class according to the button size
                string cssClass    = (isSmall ? "SmallButton" : "BigButton");
                string elementName = uiElement.ElementName;

                // Create main button panel
                CMSPanel pnlButton = new CMSPanel()
                {
                    ID      = "pnlButton" + elementName,
                    ShortID = "b" + elementName
                };

                pnlButton.Attributes.Add("name", elementName);
                pnlButton.CssClass = cssClass;

                // Remember the first button
                if (firstPanel == null)
                {
                    firstPanel = pnlButton;
                }

                // Remember the selected button
                if ((preselectedPanel == null) && elementName.Equals(HighlightItem, StringComparison.InvariantCultureIgnoreCase))
                {
                    preselectedPanel = pnlButton;

                    // Set the selected button
                    if (mHighlightedUIElement == null)
                    {
                        mHighlightedUIElement = uiElement;
                    }
                }

                // URL or behavior
                string url = uiElement.ElementTargetURL;

                if (!string.IsNullOrEmpty(url) && url.StartsWith("javascript:", StringComparison.InvariantCultureIgnoreCase))
                {
                    pnlButton.Attributes["onclick"] = url.Substring("javascript:".Length);
                }
                else if (!string.IsNullOrEmpty(url) && !url.StartsWith("javascript:", StringComparison.InvariantCultureIgnoreCase))
                {
                    string buttonSelection = (RememberSelectedItem ? "SelectButton(this);" : "");

                    // Ensure hash code if required
                    string targetUrl = CMSContext.ResolveMacros(URLHelper.EnsureHashToQueryParameters(url));

                    if (!String.IsNullOrEmpty(TargetFrameset))
                    {
                        pnlButton.Attributes["onclick"] = String.Format("{0}parent.frames['{1}'].location.href = '{2}';", buttonSelection, TargetFrameset, URLHelper.ResolveUrl(targetUrl));
                    }
                    else
                    {
                        pnlButton.Attributes["onclick"] = String.Format("{0}self.location.href = '{1}';", buttonSelection, URLHelper.ResolveUrl(targetUrl));
                    }

                    if (OnButtonCreated != null)
                    {
                        OnButtonCreated(uiElement, targetUrl);
                    }
                }

                // Tooltip
                if (!string.IsNullOrEmpty(uiElement.ElementDescription))
                {
                    pnlButton.ToolTip = ResHelper.LocalizeString(uiElement.ElementDescription);
                }
                else
                {
                    pnlButton.ToolTip = ResHelper.LocalizeString(uiElement.ElementCaption);
                }
                pnlButton.EnableViewState = false;

                // Ensure correct grouping of small buttons
                if (isSmall && (small == 0))
                {
                    small++;

                    Panel pnlSmallGroup = new Panel()
                    {
                        ID = "pnlGroupSmall" + uiElement.ElementName
                    };
                    if (IsRTL)
                    {
                        pnlSmallGroup.Style.Add("float", "right");
                        pnlSmallGroup.Style.Add("text-align", "right");
                    }
                    else
                    {
                        pnlSmallGroup.Style.Add("float", "left");
                        pnlSmallGroup.Style.Add("text-align", "left");
                    }

                    pnlSmallGroup.EnableViewState = false;
                    pnlSmallGroup.Controls.Add(pnlButton);
                    panels.Add(pnlSmallGroup);
                }

                // Generate button image
                Image buttonImage = new Image()
                {
                    ID         = "imgButton" + uiElement.ElementName,
                    ImageAlign = (isSmall ? ImageAlign.AbsMiddle : ImageAlign.Top)
                };
                if (!string.IsNullOrEmpty(uiElement.ElementIconPath))
                {
                    string iconPath = GetImageUrl(uiElement.ElementIconPath);

                    // Check if element size was changed
                    if (isResized)
                    {
                        // Try to get larger icon
                        string largeIconPath = iconPath.Replace("list.png", "module.png");
                        try
                        {
                            if (CMS.IO.File.Exists(MapPath(largeIconPath)))
                            {
                                iconPath = largeIconPath;
                            }
                        }
                        catch { }
                    }

                    buttonImage.ImageUrl = iconPath;
                }
                else
                {
                    // Load defaul module icon if ElementIconPath is not specified
                    buttonImage.ImageUrl = GetImageUrl("CMSModules/module.png");
                }
                buttonImage.EnableViewState = false;

                // Generate button text
                Literal captionLiteral = new Literal()
                {
                    ID              = "ltlCaption" + uiElement.ElementName,
                    Text            = (isSmall ? "\n" : "<br />") + ResHelper.LocalizeString(uiElement.ElementCaption),
                    EnableViewState = false
                };

                // Generate button link
                HyperLink buttonLink = new HyperLink()
                {
                    ID = "lnkButton" + uiElement.ElementName
                };
                buttonLink.Controls.Add(buttonImage);
                buttonLink.Controls.Add(captionLiteral);
                buttonLink.EnableViewState = false;

                //Generate button table (IE7 issue)
                Table     tabButton     = new Table();
                TableRow  tabRow        = new TableRow();
                TableCell tabCellLeft   = new TableCell();
                TableCell tabCellMiddle = new TableCell();
                TableCell tabCellRight  = new TableCell();

                tabButton.CellPadding = 0;
                tabButton.CellSpacing = 0;

                tabButton.EnableViewState     = false;
                tabRow.EnableViewState        = false;
                tabCellLeft.EnableViewState   = false;
                tabCellMiddle.EnableViewState = false;
                tabCellRight.EnableViewState  = false;

                tabButton.Rows.Add(tabRow);
                tabRow.Cells.Add(tabCellLeft);
                tabRow.Cells.Add(tabCellMiddle);
                tabRow.Cells.Add(tabCellRight);

                // Generate left border
                Panel pnlLeft = new Panel()
                {
                    ID              = "pnlLeft" + uiElement.ElementName,
                    CssClass        = "Left" + cssClass,
                    EnableViewState = false
                };

                // Generate middle part of button
                Panel pnlMiddle = new Panel()
                {
                    ID       = "pnlMiddle" + uiElement.ElementName,
                    CssClass = "Middle" + cssClass
                };
                pnlMiddle.Controls.Add(buttonLink);
                Panel pnlMiddleTmp = new Panel()
                {
                    EnableViewState = false
                };
                if (isSmall)
                {
                    pnlMiddle.Style.Add("min-width", smallButtonMinimalWidth + "px");
                    // IE7 issue with min-width
                    pnlMiddleTmp.Style.Add("width", smallButtonMinimalWidth + "px");
                    pnlMiddle.Controls.Add(pnlMiddleTmp);
                }
                else
                {
                    pnlMiddle.Style.Add("min-width", bigButtonMinimalWidth + "px");
                    // IE7 issue with min-width
                    pnlMiddleTmp.Style.Add("width", bigButtonMinimalWidth + "px");
                    pnlMiddle.Controls.Add(pnlMiddleTmp);
                }
                pnlMiddle.EnableViewState = false;

                // Generate right border
                Panel pnlRight = new Panel()
                {
                    ID              = "pnlRight" + uiElement.ElementName,
                    CssClass        = "Right" + cssClass,
                    EnableViewState = false
                };

                // Add inner controls
                tabCellLeft.Controls.Add(pnlLeft);
                tabCellMiddle.Controls.Add(pnlMiddle);
                tabCellRight.Controls.Add(pnlRight);

                pnlButton.Controls.Add(tabButton);

                // If there were two small buttons in a row end the grouping div
                if ((small == 2) || (isSmall && !isNextSmall))
                {
                    small = 0;

                    // Add the button to the small buttons grouping panel
                    panels[panels.Count - 1].Controls.Add(pnlButton);
                }
                else
                {
                    if (small == 0)
                    {
                        // Add the generated button into collection
                        panels.Add(pnlButton);
                    }
                }
                if (small == 1)
                {
                    small++;
                }
            }

            // Add all panels to control
            foreach (Panel panel in panels)
            {
                TableCell tabGroupCell = new TableCell()
                {
                    VerticalAlign   = VerticalAlign.Top,
                    EnableViewState = false
                };

                tabGroupCell.Controls.Add(panel);
                tabGroupRow.Cells.Add(tabGroupCell);
            }

            pnlButtons.Controls.Add(tabGroup);
        }

        return(pnlButtons);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        SetupActionButtons();

        // Select element and expand modules first level elements
        if (!RequestHelper.IsPostBack())
        {
            // Select given element
            if (ElementInfo != null)
            {
                SelectNode(ElementInfo);
                ContentTree.SelectPath = ElementInfo.ElementIDPath;
            }

            // Expand all module elements
            var allModuleElements = UIElementInfoProvider.GetUIElements().Where("ElementResourceID", QueryOperator.Equals, ModuleId).Columns("ElementID");

            var elementsToExpand = UIElementInfoProvider.GetUIElements()
                                   .Where("ElementResourceID", QueryOperator.Equals, ModuleId)
                                   .Where(new WhereCondition().WhereNull("ElementParentID").Or().WhereNotIn("ElementParentID", allModuleElements));

            foreach (var uiElementInfo in elementsToExpand)
            {
                if (!String.IsNullOrEmpty(uiElementInfo.ElementIDPath))
                {
                    ContentTree.ExpandPath += uiElementInfo.ElementIDPath + ";";

                    // No element is selected, select first
                    if (ElementInfo == null)
                    {
                        SelectNode(uiElementInfo);
                        ContentTree.SelectPath = uiElementInfo.ElementIDPath;
                    }
                }
            }
        }

        // Create and set UIElements provider
        var tree = new UniTreeProvider();

        tree.ObjectType        = "CMS.UIElement";
        tree.DisplayNameColumn = "ElementDisplayName";
        tree.IDColumn          = "ElementID";
        tree.LevelColumn       = "ElementLevel";
        tree.OrderColumn       = "ElementOrder";
        tree.ParentIDColumn    = "ElementParentID";
        tree.PathColumn        = "ElementIDPath";
        tree.ValueColumn       = "ElementID";
        tree.ChildCountColumn  = "ElementChildCount";
        tree.Columns           = "ElementID,ElementLevel,ElementOrder,ElementParentID,ElementIDPath,ElementChildCount,ElementDisplayName,ElementResourceID,ElementName,ElementIconPath,ElementIconClass";

        ContentTree.UsePostBack    = false;
        ContentTree.ProviderObject = tree;
        ContentTree.OnNodeCreated += uniTree_OnNodeCreated;

        ContentTree.NodeTemplate         = "<span id=\"node_##NODEID##\" onclick=\"SelectNode(##NODEID##,##PARENTNODEID##," + ModuleId + ", true); return false;\" name=\"treeNode\" class=\"ContentTreeItem\">##ICON##<span class=\"Name\">##NODENAME##</span></span>";
        ContentTree.SelectedNodeTemplate = "<span id=\"node_##NODEID##\" onclick=\"SelectNode(##NODEID##,##PARENTNODEID##," + ModuleId + ", true); return false;\" name=\"treeNode\" class=\"ContentTreeItem ContentTreeSelectedItem\">##ICON##<span class=\"Name\">##NODENAME##</span></span>";

        // Icons
        tree.ImageColumn = "ElementIconPath";
    }
    /// <summary>
    /// Reloads the tree data.
    /// </summary>
    public void ReloadData()
    {
        var elementProvider = new UniTreeProvider
        {
            QueryName         = "cms.uielement.selecttree",
            DisplayNameColumn = "ElementDisplayName",
            IDColumn          = "ElementID",
            LevelColumn       = "ElementLevel",
            OrderColumn       = "ElementOrder",
            ParentIDColumn    = "ElementParentID",
            PathColumn        = "ElementIDPath",
            ValueColumn       = "ElementID",
            ChildCountColumn  = "ElementChildCount",
            ImageColumn       = "ElementIconPath",
            Parameters        = new QueryDataParameters {
                { "@RoleID", RoleID }
            },
            IconClassColumn = "ElementIconClass"
        };

        treeElem.ExpandTooltip    = GetString("general.expand");
        treeElem.CollapseTooltip  = GetString("general.collapse");
        treeElem.UsePostBack      = false;
        treeElem.EnableRootAction = false;
        treeElem.ProviderObject   = elementProvider;
        if (SingleModule)
        {
            ResourceInfo ri = ResourceInfoProvider.GetResourceInfo(ModuleID);
            if (ri != null)
            {
                root = UIElementInfoProvider.GetModuleTopUIElement(ModuleID);
                if (root != null)
                {
                    treeElem.ExpandPath = root.ElementIDPath;
                    string links = null;
                    if (Enabled)
                    {
                        links = string.Format(SELECT_DESELECT_LINKS, root.ElementID, "false", CallbackRef, GetString("uiprofile.selectall"), GetString("uiprofile.deselectall"));
                    }
                    string rootText = HTMLHelper.HTMLEncode(ri.ResourceDisplayName) + links;
                    treeElem.SetRoot(rootText, root.ElementID.ToString(), ResolveUrl(root.ElementIconPath));
                    elementProvider.RootLevelOffset = root.ElementLevel;
                }

                if (!ShowAllElementsFromModuleSection)
                {
                    elementProvider.WhereCondition = "ElementResourceID = " + ModuleID;
                }
            }
        }
        else
        {
            if (ModuleID > 0)
            {
                var where = $@"ElementResourceID = {ModuleID} AND (ElementParentID IS NULL OR ElementParentID NOT IN (SELECT ElementID FROM CMS_UIElement WHERE ElementResourceID={ModuleID})) 
    AND (NOT EXISTS (SELECT  ElementIDPath FROM CMS_UIElement AS u WHERE CMS_UIElement.ElementIDPath LIKE u.ElementIDPath + '%' AND ElementResourceID = {ModuleID}
    AND u.ElementIDPath != CMS_UIElement.ElementIDPath))";

                var idPaths = UIElementInfoProvider.GetUIElements()
                              .Where(where)
                              .WhereNotEmpty("ElementIDPath")
                              .Columns("ElementIDPath")
                              .OrderByAscending("ElementLevel")
                              .GetListResult <string>();

                var expandedPath = String.Empty;

                if (idPaths.Any())
                {
                    expandedPath = String.Join(";", idPaths) + ";";
                }

                treeElem.ExpandPath = expandedPath;
            }
        }

        treeElem.ReloadData();
    }
Example #13
0
    /// <summary>
    /// Reloads the tree data.
    /// </summary>
    public void ReloadData()
    {
        // Prepare the parameters
        QueryDataParameters parameters = new QueryDataParameters();

        parameters.Add("@RoleID", RoleID);

        // Create and set UIElements provider
        UniTreeProvider elementProvider = new UniTreeProvider();

        elementProvider.QueryName         = "cms.uielement.selecttree";
        elementProvider.DisplayNameColumn = "ElementDisplayName";
        elementProvider.IDColumn          = "ElementID";
        elementProvider.LevelColumn       = "ElementLevel";
        elementProvider.OrderColumn       = "ElementOrder";
        elementProvider.ParentIDColumn    = "ElementParentID";
        elementProvider.PathColumn        = "ElementIDPath";
        elementProvider.ValueColumn       = "ElementID";
        elementProvider.ChildCountColumn  = "ElementChildCount";
        elementProvider.ImageColumn       = "ElementIconPath";
        elementProvider.Parameters        = parameters;
        elementProvider.IconClassColumn   = "ElementIconClass";

        treeElem.ExpandTooltip    = GetString("general.expand");
        treeElem.CollapseTooltip  = GetString("general.collapse");
        treeElem.UsePostBack      = false;
        treeElem.EnableRootAction = false;
        treeElem.ProviderObject   = elementProvider;
        if (SingleModule)
        {
            ResourceInfo ri = ResourceInfoProvider.GetResourceInfo(ModuleID);
            if (ri != null)
            {
                root = UIElementInfoProvider.GetModuleTopUIElement(ModuleID);
                if (root != null)
                {
                    treeElem.ExpandPath = root.ElementIDPath;
                    string links = null;
                    if (Enabled)
                    {
                        links = string.Format(SELECT_DESELECT_LINKS, root.ElementID, "false", CallbackRef, GetString("uiprofile.selectall"), GetString("uiprofile.deselectall"));
                    }
                    string rootText = HTMLHelper.HTMLEncode(ri.ResourceDisplayName) + links;
                    treeElem.SetRoot(rootText, root.ElementID.ToString(), ResolveUrl(root.ElementIconPath));
                    elementProvider.RootLevelOffset = root.ElementLevel;
                }

                elementProvider.WhereCondition = "ElementResourceID=" + ModuleID;
            }
        }
        else
        {
            if (ModuleID > 0)
            {
                String where = String.Format(@"ElementResourceID = {0} AND (ElementParentID IS NULL OR ElementParentID NOT IN (SELECT ElementID FROM CMS_UIElement WHERE ElementResourceID={0})) 
                                                AND (NOT EXISTS (SELECT  ElementIDPath FROM CMS_UIElement AS u WHERE CMS_UIElement.ElementIDPath LIKE u.ElementIDPath + '%' AND ElementResourceID = {0}
                                                AND u.ElementIDPath != CMS_UIElement.ElementIDPath))", ModuleID);
                DataSet ds           = UIElementInfoProvider.GetUIElements(where, "ElementLevel ASC");
                String  expandedPath = String.Empty;
                if (!DataHelper.DataSourceIsEmpty(ds))
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        String path = ValidationHelper.GetString(dr["ElementIDPath"], String.Empty);
                        if (path != String.Empty)
                        {
                            expandedPath += path + ";";
                        }
                    }
                }

                treeElem.ExpandPath = expandedPath;
            }
        }

        treeElem.ReloadData();
    }
Example #14
0
    /// <summary>
    /// Generates panel with buttons loaded from given UI Element.
    /// </summary>
    /// <param name="uiElementId">ID of the UI Element</param>
    private Panel GetButtons(int uiElementId)
    {
        const int bigButtonMinimalWidth   = 40;
        const int smallButtonMinimalWidth = 66;

        // Load the buttons manually from UI Element
        IEnumerable <UIElementInfo> elements = UIElementInfoProvider.GetChildUIElements(uiElementId);

        // When no child found
        if (!elements.Any())
        {
            // Try to use group element as button
            elements = UIElementInfoProvider.GetUIElements()
                       .WhereEquals("ElementID", uiElementId);

            var groupElement = elements.FirstOrDefault();
            if (groupElement != null)
            {
                // Use group element as button only if it has URL specified
                if (String.IsNullOrEmpty(groupElement.ElementTargetURL))
                {
                    elements = Enumerable.Empty <UIElementInfo>();
                }
            }
        }

        // Filter the dataset according to UI Profile
        var filteredElements = FilterElements(elements).ToList();

        int small = 0;
        int count = filteredElements.Count;

        // No buttons, render nothing
        if (count == 0)
        {
            return(null);
        }

        // Prepare the panel
        var pnlButtons = new Panel();

        pnlButtons.CssClass = "ActionButtons";

        // Prepare the table
        Table    tabGroup    = new Table();
        TableRow tabGroupRow = new TableRow();

        tabGroup.CellPadding        = 0;
        tabGroup.CellSpacing        = 0;
        tabGroup.EnableViewState    = false;
        tabGroupRow.EnableViewState = false;
        tabGroup.Rows.Add(tabGroupRow);

        List <Panel> panels = new List <Panel>();

        for (int i = 0; i < count; i++)
        {
            // Get current and next button
            UIElementInfo uiElement = filteredElements[i];

            UIElementInfo sel = UIContextHelper.CheckSelectedElement(uiElement, UIContext);
            if (sel != null)
            {
                String selectionSuffix = ValidationHelper.GetString(UIContext["selectionSuffix"], String.Empty);
                StartingPage  = UIContextHelper.GetElementUrl(sel, UIContext) + selectionSuffix;
                HighlightItem = uiElement.ElementName;
            }

            // Raise button creating event
            OnButtonCreating?.Invoke(this, new UniMenuArgs {
                UIElement = uiElement
            });

            UIElementInfo uiElementNext = null;
            if (i < count - 1)
            {
                uiElementNext = filteredElements[i + 1];
            }

            // Set the first button
            if (mFirstUIElement == null)
            {
                mFirstUIElement = uiElement;
            }

            // Get the sizes of current and next button. Button is large when it is the only in the group
            bool isSmall     = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (count > 1);
            bool isResized   = (uiElement.ElementSize == UIElementSizeEnum.Regular) && (!isSmall);
            bool isNextSmall = (uiElementNext != null) && (uiElementNext.ElementSize == UIElementSizeEnum.Regular);

            // Set the CSS class according to the button size
            string cssClass    = (isSmall ? "SmallButton" : "BigButton");
            string elementName = uiElement.ElementName;

            // Display only caption - do not substitute with Display name when empty
            string elementCaption = ResHelper.LocalizeString(uiElement.ElementCaption, ResourceCulture);

            // Create main button panel
            CMSPanel pnlButton = new CMSPanel
            {
                ID      = "pnlButton" + elementName,
                ShortID = "b" + elementName
            };

            pnlButton.Attributes.Add("name", elementName);
            pnlButton.CssClass = cssClass;

            // Remember the first button
            if (firstPanel == null)
            {
                firstPanel = pnlButton;
            }

            // Remember the selected button
            if ((preselectedPanel == null) && elementName.EqualsCSafe(HighlightItem, true))
            {
                preselectedPanel = pnlButton;

                // Set the selected button
                if (mHighlightedUIElement == null)
                {
                    mHighlightedUIElement = uiElement;
                }
            }

            // URL or behavior
            string url = uiElement.ElementTargetURL;

            if (!string.IsNullOrEmpty(url) && url.StartsWithCSafe("javascript:", true))
            {
                pnlButton.Attributes["onclick"] = url.Substring("javascript:".Length);
            }
            else
            {
                url = UIContextHelper.GetElementUrl(uiElement, UIContext);

                if (url != String.Empty)
                {
                    string buttonSelection = (RememberSelectedItem ? "SelectButton(this);" : "");

                    // Ensure hash code if required
                    url = MacroResolver.Resolve(URLHelper.EnsureHashToQueryParameters(url));

                    if (!String.IsNullOrEmpty(TargetFrameset))
                    {
                        if (uiElement.ElementType == UIElementTypeEnum.PageTemplate)
                        {
                            url = URLHelper.UpdateParameterInUrl(url, "displaytitle", "false");
                        }

                        String target = UseIFrame ? String.Format("frames['{0}']", TargetFrameset) : String.Format("parent.frames['{0}']", TargetFrameset);
                        pnlButton.Attributes["onclick"] = String.Format("{0}{1}.location.href = '{2}';", buttonSelection, target, UrlResolver.ResolveUrl(url));
                    }
                    else
                    {
                        pnlButton.Attributes["onclick"] = String.Format("{0}self.location.href = '{1}';", buttonSelection, UrlResolver.ResolveUrl(url));
                    }
                }
            }

            // Tooltip
            if (!String.IsNullOrEmpty(uiElement.ElementDescription))
            {
                pnlButton.ToolTip = ResHelper.LocalizeString(uiElement.ElementDescription, ResourceCulture);
            }
            else
            {
                pnlButton.ToolTip = elementCaption;
            }
            pnlButton.EnableViewState = false;

            // Ensure correct grouping of small buttons
            if (isSmall && (small == 0))
            {
                small++;

                Panel pnlSmallGroup = new Panel
                {
                    ID = "pnlGroupSmall" + uiElement.ElementName
                };
                if (IsRTL)
                {
                    pnlSmallGroup.Style.Add("float", "right");
                    pnlSmallGroup.Style.Add("text-align", "right");
                }
                else
                {
                    pnlSmallGroup.Style.Add("float", "left");
                    pnlSmallGroup.Style.Add("text-align", "left");
                }

                pnlSmallGroup.EnableViewState = false;
                pnlSmallGroup.Controls.Add(pnlButton);
                panels.Add(pnlSmallGroup);
            }

            // Generate button link
            HyperLink buttonLink = new HyperLink
            {
                ID = "lnkButton" + uiElement.ElementName,
                EnableViewState = false
            };

            // Generate button image
            Image buttonImage = new Image
            {
                ID              = "imgButton" + uiElement.ElementName,
                ImageAlign      = (isSmall ? ImageAlign.AbsMiddle : ImageAlign.Top),
                AlternateText   = elementCaption,
                EnableViewState = false
            };

            // Use icon path
            if (!string.IsNullOrEmpty(uiElement.ElementIconPath))
            {
                string iconPath = GetImagePath(uiElement.ElementIconPath);

                // Check if element size was changed
                if (isResized)
                {
                    // Try to get larger icon
                    string largeIconPath = iconPath.Replace("list.png", "module.png");
                    if (FileHelper.FileExists(largeIconPath))
                    {
                        iconPath = largeIconPath;
                    }
                }

                buttonImage.ImageUrl = GetImageUrl(iconPath);
                buttonLink.Controls.Add(buttonImage);
            }
            // Use Icon class
            else if (!string.IsNullOrEmpty(uiElement.ElementIconClass))
            {
                var icon = new CMSIcon
                {
                    ID = string.Format("ico_{0}_{1}", identifier, i),
                    EnableViewState = false,
                    ToolTip         = pnlButton.ToolTip,
                    CssClass        = "cms-icon-80 " + uiElement.ElementIconClass
                };
                buttonLink.Controls.Add(icon);
            }
            // Load default module icon if ElementIconPath is not specified
            else
            {
                buttonImage.ImageUrl = GetImageUrl("CMSModules/module.png");
                buttonLink.Controls.Add(buttonImage);
            }

            // Generate caption text
            Literal captionLiteral = new Literal
            {
                ID              = "ltlCaption" + uiElement.ElementName,
                Text            = (isSmall ? "\n" : "<br />") + elementCaption,
                EnableViewState = false
            };
            buttonLink.Controls.Add(captionLiteral);

            //Generate button table (IE7 issue)
            Table     tabButton     = new Table();
            TableRow  tabRow        = new TableRow();
            TableCell tabCellLeft   = new TableCell();
            TableCell tabCellMiddle = new TableCell();
            TableCell tabCellRight  = new TableCell();

            tabButton.CellPadding = 0;
            tabButton.CellSpacing = 0;

            tabButton.EnableViewState     = false;
            tabRow.EnableViewState        = false;
            tabCellLeft.EnableViewState   = false;
            tabCellMiddle.EnableViewState = false;
            tabCellRight.EnableViewState  = false;

            tabButton.Rows.Add(tabRow);
            tabRow.Cells.Add(tabCellLeft);
            tabRow.Cells.Add(tabCellMiddle);
            tabRow.Cells.Add(tabCellRight);

            // Generate left border
            Panel pnlLeft = new Panel
            {
                ID              = "pnlLeft" + uiElement.ElementName,
                CssClass        = "Left" + cssClass,
                EnableViewState = false
            };

            // Generate middle part of button
            Panel pnlMiddle = new Panel
            {
                ID       = "pnlMiddle" + uiElement.ElementName,
                CssClass = "Middle" + cssClass
            };
            pnlMiddle.Controls.Add(buttonLink);
            Panel pnlMiddleTmp = new Panel
            {
                EnableViewState = false
            };
            if (isSmall)
            {
                pnlMiddle.Style.Add("min-width", smallButtonMinimalWidth + "px");
                // IE7 issue with min-width
                pnlMiddleTmp.Style.Add("width", smallButtonMinimalWidth + "px");
                pnlMiddle.Controls.Add(pnlMiddleTmp);
            }
            else
            {
                pnlMiddle.Style.Add("min-width", bigButtonMinimalWidth + "px");
                // IE7 issue with min-width
                pnlMiddleTmp.Style.Add("width", bigButtonMinimalWidth + "px");
                pnlMiddle.Controls.Add(pnlMiddleTmp);
            }
            pnlMiddle.EnableViewState = false;

            // Generate right border
            Panel pnlRight = new Panel
            {
                ID              = "pnlRight" + uiElement.ElementName,
                CssClass        = "Right" + cssClass,
                EnableViewState = false
            };

            // Add inner controls
            tabCellLeft.Controls.Add(pnlLeft);
            tabCellMiddle.Controls.Add(pnlMiddle);
            tabCellRight.Controls.Add(pnlRight);

            pnlButton.Controls.Add(tabButton);

            // If there were two small buttons in a row end the grouping div
            if ((small == 2) || (isSmall && !isNextSmall))
            {
                small = 0;

                // Add the button to the small buttons grouping panel
                panels[panels.Count - 1].Controls.Add(pnlButton);
            }
            else
            {
                if (small == 0)
                {
                    // Add the generated button into collection
                    panels.Add(pnlButton);
                }
            }
            if (small == 1)
            {
                small++;
            }

            // Raise button created event
            OnButtonCreated?.Invoke(this, new UniMenuArgs {
                UIElement = uiElement, TargetUrl = url, ButtonControl = pnlButton, ImageControl = buttonImage
            });
        }

        // Add all panels to control
        foreach (Panel panel in panels)
        {
            TableCell tabGroupCell = new TableCell
            {
                VerticalAlign   = VerticalAlign.Top,
                EnableViewState = false
            };

            tabGroupCell.Controls.Add(panel);
            tabGroupRow.Cells.Add(tabGroupCell);
        }

        pnlButtons.Controls.Add(tabGroup);

        return(pnlButtons);
    }