private void BuildColumnToClass() { // Set CMS.Document first foreach (string AllowedClass in AllowedPageTypes.Split(";,|".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) { DataClassInfo PageTypeClass = DataClassInfoProvider.GetDataClassInfo(AllowedClass.Trim()); FormInfo PageTypeFormInfo = new FormInfo(PageTypeClass.ClassFormDefinition); foreach (string ColumnName in PageTypeFormInfo.ItemsList.Select(x => ((FormFieldInfo)x).Name.ToLower().Trim('[').Trim(']'))) { if (!ColumnsToDataClass.ContainsKey(ColumnName)) { ColumnsToDataClass.Add(ColumnName, PageTypeClass); } } FormFieldInfo PrimaryKeyField = (FormFieldInfo)PageTypeFormInfo.ItemsList.Where(x => ((FormFieldInfo)x).PrimaryKey).FirstOrDefault(); if (PrimaryKeyField != null) { ClassToPrimaryKeyColumn.Add(AllowedClass.ToLower(), PrimaryKeyField.Name); } } }
/// <summary> /// Binds the grid columns. /// </summary> /// <param name="sender">Sender</param> /// <param name="sourceName">Source name</param> /// <param name="parameter">Parameter</param> private object UniGridRelationship_OnExternalDataBound(object sender, string sourceName, object parameter) { switch (sourceName.ToLowerInvariant()) { case "lefnodename": case "rightnodename": string tooltip = null; string customName = null; int NodeID = ValidationHelper.GetInteger(parameter, 0); var NodeObj = new DocumentQuery().WhereEquals("NodeID", NodeID).Columns("NodeID, NodeName, NodeLevel, ClassName").FirstOrDefault(); // Not root and is in the allowed page types if (NodeObj.NodeLevel != 0 && (!string.IsNullOrWhiteSpace(ToolTipFormat) || !string.IsNullOrWhiteSpace(DisplayNameFormat)) && AllowedPageTypes.ToLower().Split(";,|".ToCharArray()).Contains(NodeObj.NodeClassName.ToLower())) { ValidationHelper.GetInteger(parameter, 0); MacroResolver NodeResolver = GetNodeMacroResolver(NodeObj.NodeID, NodeObj.ClassName); if (!string.IsNullOrWhiteSpace(ToolTipFormat)) { tooltip = NodeResolver.ResolveMacros(ToolTipFormat); } if (!string.IsNullOrWhiteSpace(DisplayNameFormat)) { customName = NodeResolver.ResolveMacros(DisplayNameFormat); } return(string.Format("<div title=\"{0}\">{1}</div>", HTMLHelper.EncodeForHtmlAttribute(tooltip), (!string.IsNullOrWhiteSpace(customName) ? customName : NodeObj.NodeName))); } else { var tr = new ObjectTransformation(PredefinedObjectType.NODE, NodeID); tr.EncodeOutput = false; tr.Transformation = "{%NodeName|(default)" + GetString("general.root") + "|(encode)%}"; return(tr); } case "delete": var btn = ((CMSGridActionButton)sender); btn.PreRender += imgDelete_PreRender; break; } return(parameter); }
private TreeNode CreateTreeNode(CMS.DocumentEngine.TreeNode Node) { string tooltip = null; string customName = null; if ((!string.IsNullOrWhiteSpace(ToolTipFormat) || !string.IsNullOrWhiteSpace(DisplayNameFormat)) && AllowedPageTypes.ToLower().Split(";,|".ToCharArray()).Contains(Node.NodeClassName.ToLower())) { MacroResolver NodeResolver = GetNodeMacroResolver(Node); if (!string.IsNullOrWhiteSpace(ToolTipFormat)) { tooltip = NodeResolver.ResolveMacros(ToolTipFormat); } if (!string.IsNullOrWhiteSpace(DisplayNameFormat)) { customName = NodeResolver.ResolveMacros(DisplayNameFormat); } } RelatedPage_Tree_CustomTreeNode newNode = new RelatedPage_Tree_CustomTreeNode((!string.IsNullOrWhiteSpace(customName) ? customName : Node.NodeName), Node.NodeID.ToString(), tooltip); if (AlreadySelectedNodes.Contains(Node.NodeID) || (FilterSelectableNodes && !SelectableSelectedNodes.Contains(Node.NodeID))) { newNode.SelectAction = TreeNodeSelectAction.None; newNode.ShowCheckBox = false; newNode.Text = newNode.Text; newNode.CssClass = "AlreadySelected"; newNode.PossiblySelectable = AlreadySelectedNodes.Contains(Node.NodeID); } else { if ((AllowAllTypes || ClassNames.Contains(Node.ClassName))) { newNode.PossiblySelectable = true; newNode.CssClass = "Selectable"; if (SelectionMode == "Checkbox") { newNode.ShowCheckBox = true; newNode.SelectAction = TreeNodeSelectAction.None; } else { newNode.SelectAction = TreeNodeSelectAction.Select; } } else { newNode.SelectAction = TreeNodeSelectAction.None; newNode.CssClass = "NotSelectable"; } } return(newNode); }
public void SetupControl() { // I believe/hope this is how you can pass the extension class CustomUniSelector.ContextResolver.SetNamedSourceData("UIContext", UIContext); CustomUniSelector.ObjectSiteName = ObjectSiteName; CustomUniSelector.DisplayNameFormat = DisplayNameFormat; CustomUniSelector.SelectionMode = (SelectionModeEnum)SelectionMode; if (!string.IsNullOrWhiteSpace(AdditionalColumns) || !string.IsNullOrWhiteSpace(AdditionalSearchColumns)) { BuildColumnToClass(); if (!string.IsNullOrWhiteSpace(AdditionalColumns)) { CustomUniSelector.AdditionalColumns = GetActualAdditionalColumns(); } if (!string.IsNullOrWhiteSpace(AdditionalSearchColumns)) { CustomUniSelector.AdditionalSearchColumns = GetActualAdditionalSearchColumns(); } } //CustomUniSelector.OrderBy = OrderBy; CustomUniSelector.EnabledColumnName = EnabledColumnName; CustomUniSelector.MaxDisplayedTotalItems = MaxDisplayedTotalItems; CustomUniSelector.MaxDisplayedItems = MaxDisplayedItems; CustomUniSelector.ItemsPerPage = ItemsPerPage; CustomUniSelector.FilterControl = FilterControl; CustomUniSelector.UseDefaultNameFilter = UseDefaultNameFilter; string where = ""; // Filter to show items not already selected if (ddlCurrentNodeDirection.SelectedValue == "LeftNode") { where = SqlHelper.AddWhereCondition(where, string.Format("NodeID not in (Select RightNodeID from CMS_Relationship where LeftNodeID = {1} and RelationshipNameID in (Select RelationshipNameID from CMS_RelationshipName where RelationshipName = '{0}'))", RelationshipName, CurrentNodeID)); } else { where = SqlHelper.AddWhereCondition(where, string.Format("NodeID not in (Select LeftNodeID from CMS_Relationship where RightNodeID = {1} and RelationshipNameID in (Select RelationshipNameID from CMS_RelationshipName where RelationshipName = '{0}'))", RelationshipName, CurrentNodeID)); } where = SqlHelper.AddWhereCondition(where, string.Format("NodeID <> {0}", CurrentNodeID)); // Filter for allowed page types if (!string.IsNullOrWhiteSpace(AllowedPageTypes)) { where = SqlHelper.AddWhereCondition(where, string.Format("NodeClassID in (select ClassID from CMS_Class where ClassName in ('{0}'))", string.Join("','", AllowedPageTypes.Split(";| ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries)) )); } // Filter Where Condition given if (!string.IsNullOrWhiteSpace(WhereCondition)) { where = SqlHelper.AddWhereCondition(where, WhereCondition); } CustomUniSelector.WhereCondition = where; // Pass custom tooltip CustomUniSelector.ToolTipFormat = ToolTipFormat; }
private void SetupControl() { pageTree.LineImagesFolder = "~/CMSModules/RelationshipsExtended/Controls/RelatedCategories_Files"; pageTree.NodeStyle.CssClass = "InputNode"; pageTree.ShowLines = true; // Build a list of the pages var docQuery = new DocumentQuery().OrderBy("NodeLevel, NodeOrder"); foreach (string Path in StartingPathArray) { docQuery.Path(Path, PathTypeEnum.Section); } if (!string.IsNullOrWhiteSpace(RelatedNodeSiteName)) { docQuery.OnSite(RelatedNodeSiteName); } List <CMS.DocumentEngine.TreeNode> Nodes = docQuery.TypedResult.ToList(); // Get existing selected nodes string where = string.Format("NodeClassID in (select ClassID from CMS_Class where ClassName in ('{0}'))", string.Join("','", AllowedPageTypes.Split(";| ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries))); // Split off Where condition for if they provide a Where to filter out other items. string AdditionalWhere = where; // Filter to show items not already selected if (ddlCurrentNodeDirection.SelectedValue == "LeftNode") { where = SqlHelper.AddWhereCondition(where, string.Format("({0})", string.Format("NodeID in (Select RightNodeID from CMS_Relationship where LeftNodeID = {1} and RelationshipNameID in (Select RelationshipNameID from CMS_RelationshipName where RelationshipName = '{0}'))", RelationshipName, CurrentNodeID))); } else { where = SqlHelper.AddWhereCondition(where, string.Format("({0})", string.Format("NodeID in (Select LeftNodeID from CMS_Relationship where RightNodeID = {1} and RelationshipNameID in (Select RelationshipNameID from CMS_RelationshipName where RelationshipName = '{0}'))", RelationshipName, CurrentNodeID))); } where = SqlHelper.AddWhereCondition(where, string.Format("NodeID <> {0}", CurrentNodeID)); AlreadySelectedNodes = new DocumentQuery().Where(where).Columns("NodeID").Select(x => x.NodeID).ToList(); // Exclude the current node, can't relate a node to itself. AlreadySelectedNodes.Add(CurrentNodeID); // If the WhereCondition is set, also add any Nodes that match this to "Already selected" so they can't be selected // Filter on the where condition if given FilterSelectableNodes = false; List <int> VisibleNodes = new List <int>(); if (!string.IsNullOrWhiteSpace(WhereCondition)) { AdditionalWhere = SqlHelper.AddWhereCondition(AdditionalWhere, WhereCondition); FilterSelectableNodes = true; SelectableSelectedNodes.AddRange(new DocumentQuery().Where(AdditionalWhere).Columns("NodeID").Select(x => x.NodeID).ToList()); } pageTree.Nodes.Clear(); TreeNode RootNode = new TreeNode("[Tree Root]", "0") { SelectAction = TreeNodeSelectAction.None }; Dictionary <int, TreeNode> NodeIDToTreeNode = new Dictionary <int, TreeNode>(); NodeIDToTreeNode.Add(0, RootNode); // Build the tree for (int i = 0; i < Nodes.Count(); i++) { var Node = Nodes[i]; // Skip Root node if (string.IsNullOrWhiteSpace(Node.NodeName)) { continue; } TreeNode newNode = CreateTreeNode(Node); if (!NodeIDToTreeNode.ContainsKey(Node.NodeID)) { NodeIDToTreeNode.Add(Node.NodeID, newNode); } // Add to the parent if it exists, if it doesn't then add to root. if (NodeIDToTreeNode.ContainsKey(Node.NodeParentID)) { NodeIDToTreeNode[Node.NodeParentID].ChildNodes.Add(newNode); } else { NodeIDToTreeNode[0].ChildNodes.Add(newNode); } } if (RemoveUnselectableChildTrees) { HideUnselectableChildren(RootNode); } // Add root pageTree.Nodes.Add(RootNode); if (SelectionMode == "Checkbox") { btnAdd.Visible = true; } else { btnAdd.Visible = false; pageTree.SelectedNodeChanged += PageTree_SelectedNodeChanged; } }