示例#1
0
        public static MvcHtmlString JsTreeFor <TModel>(this HtmlHelper <TModel> html, Expression <Func <TModel, JsTree> > expression)
        {
            String name  = ExpressionHelper.GetExpressionText(expression) + ".SelectedIds";
            JsTree model = ModelMetadata.FromLambdaExpression(expression, html.ViewData).Model as JsTree;

            return(new MvcHtmlString(HiddenIdsFor(name, model) + JsTreeFor(name, model)));
        }
示例#2
0
        public void JsTree_CreatesEmpty()
        {
            JsTree actual = new JsTree();

            Assert.Empty(actual.Nodes);
            Assert.Empty(actual.SelectedIds);
        }
        private TagBuilder JsTreeFor(JsTree model)
        {
            String name = For.Name + ".SelectedIds";
            TagBuilder tree = new TagBuilder("div");
            tree.AddCssClass("js-tree-view");
            tree.Attributes["for"] = name;

            Add(tree, model.Nodes);

            return tree;
        }
示例#4
0
        private static String JsTreeFor(String name, JsTree model)
        {
            TagBuilder tree = new TagBuilder("div");

            tree.AddCssClass("js-tree-view");
            tree.Attributes["for"] = name;

            Add(tree, model.Nodes);

            return(tree.ToString());
        }
        public JsTreeTagHelperTests()
        {
            JsTree tree = new JsTree();
            tree.SelectedIds.Add(4567);
            tree.SelectedIds.Add(12345);
            tree.Nodes.Add(new JsTreeNode("Test"));
            tree.Nodes[0].Nodes.Add(new JsTreeNode(12345, "Test1"));
            tree.Nodes[0].Nodes.Add(new JsTreeNode(23456, "Test2"));

            EmptyModelMetadataProvider provider = new EmptyModelMetadataProvider();
            ModelExplorer explorer = new ModelExplorer(provider, provider.GetMetadataForProperty(typeof(JsTreeView), "JsTree"), tree);

            helper = new JsTreeTagHelper();
            helper.For = new ModelExpression("JsTree", explorer);
            output = new TagHelperOutput("div", new TagHelperAttributeList(), (useCachedResult, encoder) => null);
        }
        private TagBuilder HiddenIdsFor(JsTree model)
        {
            String name = For.Name + ".SelectedIds";
            TagBuilder ids = new TagBuilder("div");
            ids.AddCssClass("js-tree-view-ids");

            foreach (Int32 id in model.SelectedIds)
            {
                TagBuilder input = new TagBuilder("input");
                input.TagRenderMode = TagRenderMode.SelfClosing;
                input.Attributes["value"] = id.ToString();
                input.Attributes["type"] = "hidden";
                input.Attributes["name"] = name;

                ids.InnerHtml.AppendHtml(input);
            }

            return ids;
        }
示例#7
0
        private static String HiddenIdsFor(String name, JsTree model)
        {
            StringBuilder inputs = new StringBuilder();
            TagBuilder    input  = new TagBuilder("input");

            input.Attributes["type"] = "hidden";
            input.Attributes["name"] = name;

            foreach (Int32 id in model.SelectedIds)
            {
                input.Attributes["value"] = id.ToString();
                inputs.Append(input.ToString(TagRenderMode.SelfClosing));
            }

            TagBuilder ids = new TagBuilder("div");

            ids.AddCssClass("js-tree-view-ids");
            ids.InnerHtml = inputs.ToString();

            return(ids.ToString());
        }
        private JsTree CreatePermissions()
        {
            JsTreeNode root = new JsTreeNode(Titles.All);
            JsTree expectedTree = new JsTree();

            expectedTree.Nodes.Add(root);
            expectedTree.SelectedIds = role.Permissions.Select(rolePermission => rolePermission.PermissionId).ToList();

            IEnumerable<Permission> permissions = role
                .Permissions
                .Select(rolePermission => rolePermission.Permission)
                .Select(permission => new Permission
                {
                    Id = permission.Id,
                    Area = ResourceProvider.GetPermissionAreaTitle(permission.Area),
                    Controller = ResourceProvider.GetPermissionControllerTitle(permission.Area, permission.Controller),
                    Action = ResourceProvider.GetPermissionActionTitle(permission.Area, permission.Controller, permission.Action)
                });

            foreach (IGrouping<String, Permission> area in permissions.GroupBy(permission => permission.Area).OrderBy(permission => permission.Key ?? permission.FirstOrDefault().Controller))
            {
                JsTreeNode areaNode = new JsTreeNode(area.Key);
                foreach (IGrouping<String, Permission> controller in area.GroupBy(permission => permission.Controller).OrderBy(permission => permission.Key))
                {
                    JsTreeNode controllerNode = new JsTreeNode(controller.Key);
                    foreach (Permission permission in controller.OrderBy(permission => permission.Action))
                        controllerNode.Nodes.Add(new JsTreeNode(permission.Id, permission.Action));

                    if (areaNode.Title == null)
                        root.Nodes.Add(controllerNode);
                    else
                        areaNode.Nodes.Add(controllerNode);
                }

                if (areaNode.Title != null)
                    root.Nodes.Add(areaNode);
            }

            return expectedTree;
        }
示例#9
0
 public RoleView()
 {
     Permissions = new JsTree();
 }
示例#10
0
 public JsTreeView()
 {
     JsTree = new JsTree();
 }