public static List<ItemInfo> Expand(this List<ItemInfo> list, MappingInfo mapping, TridionSelectorMode tridionSelectorMode, List<string> tcmItemPath, string selectedTcmId) { if (tcmItemPath == null || String.IsNullOrEmpty(selectedTcmId)) return list; foreach (ItemInfo item in list) { if (tcmItemPath.Any(x => x == item.TcmId)) { item.IsExpanded = true; item.IsSelected = item.TcmId == selectedTcmId; if (item.IsSelected) continue; if (String.IsNullOrEmpty(item.TcmId)) continue; item.ChildItems = null; if (item.ItemType == ItemType.Publication) { if (tridionSelectorMode.HasFlag(TridionSelectorMode.Any)) { item.ChildItems = GetItemsByPublication(mapping, item.TcmId); } else if (tridionSelectorMode.HasFlag(TridionSelectorMode.Folder) && tridionSelectorMode.HasFlag(TridionSelectorMode.StructureGroup)) { item.ChildItems = GetContainersByPublication(mapping, item.TcmId); } else if (tridionSelectorMode.HasFlag(TridionSelectorMode.Folder)) { item.ChildItems = GetFoldersByPublication(mapping, item.TcmId); } else if (tridionSelectorMode.HasFlag(TridionSelectorMode.StructureGroup)) { item.ChildItems = GetStructureGroupsByPublication(mapping, item.TcmId); } } if (item.ItemType == ItemType.Folder) { if (tridionSelectorMode.HasFlag(TridionSelectorMode.Any)) { if (item.Title == "Categories and Keywords" && item.TcmId.StartsWith("catman-")) { item.ChildItems = GetCategoriesByPublication(mapping, item.TcmId.Replace("catman-", "")); } else if (item.Title == "Process Definitions" && item.TcmId.StartsWith("proc-")) { item.ChildItems = GetProcessDefinitionsByPublication(mapping, item.TcmId.Replace("proc-", "")); } else { item.ChildItems = GetItemsByParentContainer(mapping, item.TcmId); } } else { item.ChildItems = GetItemsByParentContainer(mapping, item.TcmId, tridionSelectorMode.GetItemTypes()); } } if (item.ItemType == ItemType.StructureGroup) { if (tridionSelectorMode.HasFlag(TridionSelectorMode.StructureGroup) && tridionSelectorMode.HasFlag(TridionSelectorMode.Page) || tridionSelectorMode.HasFlag(TridionSelectorMode.Any)) { item.ChildItems = GetItemsByParentContainer(mapping, item.TcmId); } else if (tridionSelectorMode.HasFlag(TridionSelectorMode.StructureGroup)) { item.ChildItems = GetStructureGroupsByParentStructureGroup(mapping, item.TcmId); } } if (item.ItemType == ItemType.Category) { item.ChildItems = GetKeywordsByCategory(mapping, item.TcmId); } if (item.ChildItems != null && item.ChildItems.Count > 0) { item.ChildItems.SetParent(item); } if (item.ChildItems != null && item.ChildItems.Count > 0) { item.ChildItems.Expand(mapping, tridionSelectorMode, tcmItemPath, selectedTcmId); } } else { if (item.ItemType == ItemType.Publication || item.ItemType == ItemType.Folder || item.ItemType == ItemType.StructureGroup || item.ItemType == ItemType.Category) item.ChildItems = new List<ItemInfo> { new ItemInfo { Title = "Loading..." } }; } } return list; }
public static void OnItemExpanded(ItemInfo item, MappingInfo mapping, TridionSelectorMode tridionSelectorMode) { if (item.ChildItems != null && item.ChildItems.All(x => x.Title != "Loading...")) return; if (String.IsNullOrEmpty(item.TcmId)) return; if (item.ItemType == ItemType.Publication) { if (tridionSelectorMode.HasFlag(TridionSelectorMode.Any)) { item.ChildItems = GetItemsByPublication(mapping, item.TcmId).MakeExpandable().SetParent(item); } else if (tridionSelectorMode.HasFlag(TridionSelectorMode.Folder) && tridionSelectorMode.HasFlag(TridionSelectorMode.StructureGroup)) { item.ChildItems = GetContainersByPublication(mapping, item.TcmId).MakeExpandable().SetParent(item); } else if (tridionSelectorMode.HasFlag(TridionSelectorMode.Folder)) { item.ChildItems = GetFoldersByPublication(mapping, item.TcmId).MakeExpandable().SetParent(item); } else if (tridionSelectorMode.HasFlag(TridionSelectorMode.StructureGroup)) { item.ChildItems = GetStructureGroupsByPublication(mapping, item.TcmId).MakeExpandable().SetParent(item); } } if (item.ItemType == ItemType.Folder) { if (tridionSelectorMode.HasFlag(TridionSelectorMode.Any)) { if (item.Title == "Categories and Keywords" && item.TcmId.StartsWith("catman-")) { item.ChildItems = GetCategoriesByPublication(mapping, item.TcmId.Replace("catman-", "")).MakeExpandable().SetParent(item); } else if (item.Title == "Process Definitions" && item.TcmId.StartsWith("proc-")) { item.ChildItems = GetProcessDefinitionsByPublication(mapping, item.TcmId.Replace("proc-", "")).MakeExpandable().SetParent(item); } else { item.ChildItems = GetItemsByParentContainer(mapping, item.TcmId).MakeExpandable().SetParent(item); } } else { item.ChildItems = GetItemsByParentContainer(mapping, item.TcmId, tridionSelectorMode.GetItemTypes()).MakeExpandable().SetParent(item); } } if (item.ItemType == ItemType.StructureGroup) { if (tridionSelectorMode.HasFlag(TridionSelectorMode.StructureGroup) && tridionSelectorMode.HasFlag(TridionSelectorMode.Page) || tridionSelectorMode.HasFlag(TridionSelectorMode.Any)) { item.ChildItems = GetItemsByParentContainer(mapping, item.TcmId).MakeExpandable().SetParent(item); } else if (tridionSelectorMode.HasFlag(TridionSelectorMode.StructureGroup)) { item.ChildItems = GetStructureGroupsByParentStructureGroup(mapping, item.TcmId).MakeExpandable().SetParent(item); } } if (item.ItemType == ItemType.Category) { item.ChildItems = GetKeywordsByCategory(mapping, item.TcmId).MakeExpandable().SetParent(item); } }