protected override TreeNodeCollection GetTreeNodes(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
        {
            var nodes = new TreeNodeCollection();

            //check if we're rendering the root node's children
            if (id == Constants.System.Root.ToInvariantString())
            {
                // Add the content nodes to the root of the tree
                TreeNode node = CreateTreeNode(
                    "books",
                    "-1",
                    queryStrings,
                    "Books",
                    "icon-umb-content",
                    false,
                    "globaltrade/globaltrade/bookscatalog");

                nodes.Add(node);


                node = CreateTreeNode(
                    "cameras",
                    "-1",
                    queryStrings,
                    "Cameras",
                    "icon-umb-content",
                    false,
                    "globaltrade/globaltrade/camerascatalog");

                nodes.Add(node);
            }


            return(nodes);
        }
Beispiel #2
0
        protected override Umbraco.Web.Models.Trees.TreeNodeCollection GetTreeNodes(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
        {
            // If this is a form, use Umbraco's default behavior
            var folder = PerplexFolder.Get(id);

            if (folder == null)
            {
                return(base.GetTreeNodes(id, queryStrings));
            }

            // This is a folder

            // We require all forms, and apply filtering based on folders later
            var baseTreeNodes = base.GetTreeNodes("-1", queryStrings);

            // Sanity check; make sure there are no orphan forms around
            // (forms not contained within any folder). If so, move them to the root folder
            var orphans = baseTreeNodes.Where(n => PerplexFolder.Get(f => f.Forms.Any(formId => formId == n.Id.ToString())) == null).ToList();

            if (orphans.Count > 0)
            {
                foreach (var orphan in orphans)
                {
                    PerplexFolder.GetRootFolder().Forms.Add(orphan.Id.ToString());
                }

                PerplexFolder.SaveAll();
            }

            // Hide all Forms that are not contained within this folder
            // If this folder itself is disabled (due to the user not having access),
            // we also hide all its forms
            baseTreeNodes.RemoveAll(n =>
                                    !folder.Forms.Contains(n.Id.ToString()) ||
                                    (folder.Disabled && folder.Forms.Contains(n.Id.ToString()))
                                    );

            // Sort the forms of this folder in the order as defined by the folder
            baseTreeNodes.Sort((x, y) =>
            {
                int idxX, idxY;

                idxX = folder.Forms.FindIndex(0, s => s == x.Id.ToString());
                idxY = folder.Forms.FindIndex(0, s => s == y.Id.ToString());

                return(idxX.CompareTo(idxY));
            });

            // Add any subfolders of this node
            // We loop through the list in reverse as we add every folder at the start of the list (before forms)
            foreach (var subFolder in folder.Folders.Reverse <PerplexFolder>())
            {
                // If this subfolder is disabled, and it is not on a path towards
                // a folder that is NOT disabled, it should not be listed at all.
                // When multiple start nodes are defined, it is possible for a disabled
                // folder to be displayed in the tree, when one of its descendant folders is enabled.
                if (subFolder.Disabled)
                {
                    var startFolders = PerplexFolder.GetStartFoldersForCurrentUser();

                    bool isOnPathTowardsStartFolder = startFolders.Any(sf => sf.Path.Any(fid => fid == subFolder.Id));
                    if (!isOnPathTowardsStartFolder)
                    {
                        continue;
                    }
                }

                var treeNode = CreateTreeNode(subFolder.Id, id, queryStrings, subFolder.Name);

                // Clicking this folder will show the folder overview
                // By default all nodes go to /forms/form/edit/<GUID>, but this
                // is only valid for forms. We direct to our custom folder view
                treeNode.RoutePath = "forms/perplexForms/folder/" + treeNode.Id;
                if (subFolder.Disabled)
                {
                    treeNode.CssClasses.Add("disabled");
                }

                // Folder has children if it has either forms or folders.
                // If it is disabled, this is only true when it has subfolders
                // since we do not show its forms.
                treeNode.HasChildren = (subFolder.Disabled && subFolder.Folders.Any()) || (!subFolder.Disabled && (subFolder.Forms.Any() || subFolder.Folders.Any()));

                // Folders are added at the top of the list, before forms
                baseTreeNodes.Insert(0, treeNode);
            }

            return(baseTreeNodes);
        }
Beispiel #3
0
        protected override Umbraco.Web.Models.Trees.MenuItemCollection GetMenuForNode(string id, System.Net.Http.Formatting.FormDataCollection queryStrings)
        {
            var menu = new MenuItemCollection();

            if (id == Constants.System.Root.ToInvariantString())
            {
                // root actions
                menu.Items.Add <CreateChildEntity, ActionNew>("create");
                menu.Items.Add <RefreshNode, ActionRefresh>("refresh");
                return(menu);
            }
            else
            {
                //menu.DefaultMenuAlias = ActionDelete.Instance.Alias;
                menu.Items.Add <ActionDelete>("delete");
            }
            return(menu);
        }
Beispiel #4
0
        public void CreateFromNullString()
        {
            FormDataCollection form = new FormDataCollection((string)null);

            Assert.Empty(form);
        }
Beispiel #5
0
        public void CreateFromEmptyString()
        {
            FormDataCollection form = new FormDataCollection("");

            Assert.Empty(form);
        }
Beispiel #6
0
        public void CreateFromEmptyUri()
        {
            FormDataCollection form = new FormDataCollection(new Uri("http://foo.com"));

            Assert.Empty(form);
        }
Beispiel #7
0
        public void GetValues()
        {
            FormDataCollection form = new FormDataCollection(new Uri("http://foo.com/?x=1&x=2&x=3"));

            Assert.Equal(new string[] { "1", "2", "3" }, form.GetValues("x"));
        }