/// <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 #2
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();
    }