예제 #1
0
    protected TreeNode treeElem_OnNodeCreated(DataRow itemData, TreeNode defaultNode)
    {
        // Get data
        if (itemData != null)
        {
            int    id                 = ValidationHelper.GetInteger(itemData["ElementID"], 0);
            int    childCount         = ValidationHelper.GetInteger(itemData["ElementChildCount"], 0);
            bool   selected           = ValidationHelper.GetBoolean(itemData["ElementSelected"], false);
            string displayName        = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(itemData["ElementDisplayName"], string.Empty)));
            string elementName        = ValidationHelper.GetString(itemData["ElementName"], string.Empty).ToLowerCSafe();
            int    parentID           = ValidationHelper.GetInteger(itemData["ElementParentID"], 0);
            int    resourceID         = ValidationHelper.GetInteger(itemData["ElementResourceID"], 0);
            string nodePath           = ValidationHelper.GetString(itemData["ElementIDPath"], string.Empty);
            string itemClass          = "ContentTreeItem";
            string onClickDeclaration = string.Format(" var chkElem_{0} = document.getElementById('chk_{0}'); ", id);
            string onClickCommon      = string.Format("  hdnValue.value = {0} + ';' + chkElem_{0}.checked; {1};", id, CallbackRef);
            string onClickSpan        = string.Format(" chkElem_{0}.checked = !chkElem_{0}.checked; ", id);

            // Expand for root
            if (parentID == 0)
            {
                defaultNode.Expanded = true;
            }

            string[] paths = treeElem.ExpandPath.ToLowerCSafe().Split(';');
            if (!nodePath.EndsWith("/"))
            {
                nodePath += "/";
            }

            bool chkEnabled = Enabled;
            if (!SingleModule && (ModuleID > 0))
            {
                bool isEndItem = false;
                bool isChild   = false;
                bool isParent  = false;

                // Check expanded paths
                for (int i = 0; i < paths.Length; i++)
                {
                    String path = paths[i];
                    if (path != String.Empty)
                    {
                        // Add slash - select only children
                        if (!path.EndsWith("/"))
                        {
                            path += "/";
                        }

                        if (!isChild)
                        {
                            isChild = nodePath.StartsWith(path);
                        }

                        // Module node is same node as specified in paths collection
                        isEndItem = (path == nodePath);

                        // Test for parent - expand
                        if ((path.StartsWithCSafe(nodePath)))
                        {
                            defaultNode.Expanded = true;
                            isParent             = true;
                            break;
                        }
                    }
                }

                // Display for non selected module items
                if (resourceID != ModuleID)
                {
                    // Parent special css
                    if (isParent)
                    {
                        itemClass += " highlighted disabled";
                    }
                    else
                    {
                        // Disable non parent
                        chkEnabled = false;
                        itemClass += " disabled";
                    }
                }
                else if (isEndItem)
                {
                    // Special class for end module item
                    itemClass += " highlighted";
                }
            }

            // Get button links
            string links = null;

            string nodeText;
            if (!String.IsNullOrEmpty(GroupPreffix) && elementName.ToLowerCSafe().StartsWithCSafe(GroupPreffix.ToLowerCSafe()))
            {
                if (childCount > 0 && chkEnabled)
                {
                    links = string.Format(SELECT_DESELECT_LINKS, id, "false", CallbackRef, GetString("uiprofile.selectall"), GetString("uiprofile.deselectall"));
                }
                nodeText = string.Format("<span class='{0}'>{1}</span>{2}", itemClass, displayName, links);
            }
            else
            {
                string warning = string.Empty;

                if (SiteName != null)
                {
                    if (!ResourceSiteInfoProvider.IsResourceOnSite(UIContextHelper.GetResourceName(resourceID), SiteName))
                    {
                        warning = UIHelper.GetAccessibleIconTag("icon-exclamation-triangle", String.Format(GetString("uiprofile.warningmodule"), "cms." + elementName), additionalClass: "color-orange-80");
                    }
                }

                if (childCount > 0 && chkEnabled)
                {
                    links = string.Format(SELECT_DESELECT_LINKS, id, "true", CallbackRef, GetString("uiprofile.selectall"), GetString("uiprofile.deselectall"));
                }

                nodeText = string.Format(@"<span class='checkbox tree-checkbox'><input type='checkbox' id='chk_{0}' name='chk_{0}'{1}{2} onclick=""{3}"" /><label for='chk_{0}'>&nbsp;</label><span class='{4}' onclick=""{5} return false;""><span class='Name'>{6}</span></span>{7}</span>{8}",
                                         id,
                                         chkEnabled ? string.Empty : " disabled='disabled'",
                                         selected ? " checked='checked'" : string.Empty,
                                         chkEnabled ? onClickDeclaration + onClickCommon : "return false;",
                                         itemClass,
                                         chkEnabled ? onClickDeclaration + onClickSpan + onClickCommon : "return false;",
                                         displayName,
                                         warning,
                                         links);
            }

            defaultNode.ToolTip = string.Empty;
            defaultNode.Text    = nodeText;
        }

        return(defaultNode);
    }
    protected TreeNode treeElem_OnNodeCreated(DataRow itemData, TreeNode defaultNode)
    {
        // Get data
        if (itemData != null)
        {
            int    id          = ValidationHelper.GetInteger(itemData["ElementID"], 0);
            int    childCount  = ValidationHelper.GetInteger(itemData["ElementChildCount"], 0);
            bool   selected    = ValidationHelper.GetBoolean(itemData["ElementSelected"], false);
            string displayName = HTMLHelper.HTMLEncode(ResHelper.LocalizeString(ValidationHelper.GetString(itemData["ElementDisplayName"], "")));
            string elementName = ValidationHelper.GetString(itemData["ElementName"], "").ToLowerCSafe();
            string iconUrl     = ValidationHelper.GetString(itemData["ElementIconPath"], "");

            string onClickDeclaration = " var chkElem_" + id + " = document.getElementById('chk_" + id + "'); ";
            string onClickCommon      = "  hdnValue.value = " + id + " + ';' + chkElem_" + id + ".checked; " + CallbackRef;
            string onClickSpan        = " chkElem_" + id + ".checked = !chkElem_" + id + ".checked; ";

            string nodeText = "";
            if (!String.IsNullOrEmpty(GroupPreffix) && elementName.ToLowerCSafe().StartsWithCSafe(GroupPreffix.ToLowerCSafe()))
            {
                nodeText = "<span>" + displayName + "</span>" +
                           (childCount > 0 ? "&nbsp;<span class=\"UITreeSelectButton\">(<span onclick=\"" + (Enabled ? "SelectAllSubelements($j(this), " + id + ", false);" + CallbackRef + ";" : "return false;") + "\" >" + GetString("uiprofile.selectall") + "</span>,&nbsp;<span onclick=\"" + (Enabled ? "DeselectAllSubelements($j(this), " + id + ", false);" + CallbackRef + ";" : "return false;") + "\" >" + GetString("uiprofile.deselectall") + "</span>)</span>" : "");
            }
            else
            {
                string warning = "";

                if (SiteName != null)
                {
                    if ((ResourceInfoProvider.GetResourceInfo("cms." + elementName) != null) &&
                        !ResourceSiteInfoProvider.IsResourceOnSite("cms." + elementName, SiteName))
                    {
                        warning = "<img style=\"width: 12px; height: 12px; border:none; cursor:help;\" alt=\"warning\" title=\"" + String.Format(GetString("uiprofile.warningmodule"), "cms." + elementName) + "\" src=\"" + GetImageUrl("/Design/Controls/UniGrid/Actions/Warning.png") + "\" />";
                    }
                }

                string icon = "";
                if (!String.IsNullOrEmpty(iconUrl))
                {
                    try
                    {
                        if (ValidationHelper.IsURL(iconUrl) || FileHelper.FileExists(GetImageUrl(iconUrl)))
                        {
                            icon = "<img class=\"Image16\" style=\"border:none;\" alt=\"" + HTMLHelper.HTMLEncode(displayName) + "\" src=\"" + GetImageUrl(iconUrl) + "\" />&nbsp;";
                        }
                        else
                        {
                            icon = "<img class=\"Image16\" style=\"border:none;\" alt=\"" + HTMLHelper.HTMLEncode(displayName) + "\" src=\"" + GetImageUrl("/CMSModules/list.png") + "\" />&nbsp;";
                        }
                    }
                    catch (Exception)
                    {
                    }
                }

                nodeText = "<input type=\"checkbox\" id=\"chk_" + id + "\" name=\"chk_" + id + "\" " + (Enabled ? "" : "disabled=\"disabled\" ") + (selected ? "checked=\"checked\"" : "") + " onclick=\"" + (Enabled ? onClickDeclaration + onClickCommon : "return false;") + "\" />" +
                           "<span onclick=\"" + (Enabled ? onClickDeclaration + onClickSpan + onClickCommon : "return false;") + "\" >" + icon + displayName + "</span>" + warning +
                           (childCount > 0 ? "&nbsp;<span class=\"UITreeSelectButton\">(<span onclick=\"" + (Enabled ? "SelectAllSubelements($j(this), " + id + ", true); " + CallbackRef + ";" : "return false;") + "\" >" + GetString("uiprofile.selectall") + "</span>,&nbsp;<span onclick=\"" + (Enabled ? " DeselectAllSubelements($j(this), " + id + ", true);" + CallbackRef + ";" : "return false;") + "\" >" + GetString("uiprofile.deselectall") + "</span>)</span>" : "");
            }

            defaultNode.ToolTip = "";
            defaultNode.Text    = nodeText;
        }

        return(defaultNode);
    }