Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6158045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:53:18+00:00 2026-05-23T20:53:18+00:00

I’m trying to let the user create either a file or a folder. So

  • 0

I’m trying to let the user create either a file or a folder. So when they right click on the menu the context menu will show:
create =>
file
folder

This part is working, the problem lies in the function attached to each of these context menus. At the moment clicking ‘file’ or ‘folder’ calls: this.create(obj); How do I specify the type? I’ve tried obj.attr("rel","type","folder"), I’ve tried obj.rslt.rel and many others but I’m just shooting in the dark, lol. I have gone through the documentation, the layout is good but its useless for explaining the properties of objects.

Below is the code for the context menu, the types plugin and the bind for the create node.

    fma_jstree = $("#archive")
.bind("before.jstree", function (e, data) {
    $("#alog").append(data.func + "<br />");
})
.jstree({
    // List of active plugins
    "plugins" : [
    "themes","json_data","ui","crrm","cookies","dnd","search","types","hotkeys","contextmenu"
    //"themes","json_data","ui","crrm","cookies","dnd","search","types","contextmenu"
    ],

    "contextmenu" : {
        items : { // Could be a function that should return an object like this one
            "create" : {
                "separator_before"  : false,
                "separator_after"   : true,
                "label"             : "Create",
                "action"            : false,
                "submenu" :{
                    "create_file" : {
                        "seperator_before" : false,
                        "seperator_after" : false,
                        "label" : "File",
                        action : function (obj) {
                            this.create(obj);
                        }
                    },
                    "create_folder" : {
                        "seperator_before" : false,
                        "seperator_after" : false,
                        "label" : "Folder",
                        action : function (obj) { this.create(obj); }
                    }
                }
            }
        }
    },
        // Using types - most of the time this is an overkill
    // read the docs carefully to decide whether you need types
    "types" : {
        // I set both options to -2, as I do not need depth and children count checking
        // Those two checks may slow jstree a lot, so use only when needed
        "max_depth" : -2,
        "max_children" : -2,
        // I want only `drive` nodes to be root nodes
        // This will prevent moving or creating any other type as a root node
        "valid_children" : [ "drive" ],
        "types" : {
            // The default type
            "default" : {
                // I want this type to have no children (so only leaf nodes)
                // In my case - those are files
                "valid_children" : "none",
                // If we specify an icon for the default type it WILL OVERRIDE the theme icons
                "icon" : {
                    "image" : icon_url + "/file.png"
                }
            },
            // The `folder` type
            "folder" : {
                // can have files and other folders inside of it, but NOT `drive` nodes
                "valid_children" : [ "default", "folder" ],
                "icon" : {
                    "image" : icon_url + "/folder.png"
                }
            },
            // The `drive` nodes
            "drive" : {
                // can have files and folders inside, but NOT other `drive` nodes
                "valid_children" : [ "default", "folder" ],
                "icon" : {
                    "image" : icon_url + "/root.png"
                },
                // those prevent the functions with the same name to be used on `drive` nodes
                // internally the `before` event is used
                "start_drag" : false,
                "move_node" : false,
                "delete_node" : false,
                "remove" : false
            }
        }
    },
    .bind("create.jstree", function (e, data) {

    //if creating a root node
    if(!$(data.rslt.parent).attr("id")) var id = 1;
    //else get parent
    else var id = data.rslt.parent.attr("id").replace("node_","");
    $.post(
        ajaxurl,
        {
            "action" : "fma_create_node",
            "operation" : "create_node",
            "id" : id,
            "position" : data.rslt.position,
            "title" : data.rslt.name,
            "type" : data.rslt.obj.attr("rel")
        },
        function (r) {
            if(r.status) {
                $(data.rslt.obj).attr("id", "node_" + r.id);
            }
            else {
                $.jstree.rollback(data.rlbk);
            }
        },
        'json'
        );
})

any help would be well appreciated 😉
regards,
Daithi

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T20:53:20+00:00Added an answer on May 23, 2026 at 8:53 pm

    solved it 😉
    the code to specify the type of node to create is:

    this.create(obj, "last", {"attr" : {"rel" : "default"}});
    

    so now the code for the contextmenu plugin looks like this:

            "contextmenu" : {
            items : { // Could be a function that should return an object like this one
                "create" : {
                    "separator_before"  : false,
                    "separator_after"   : true,
                    "label"             : "Create",
                    "action"            : false,
                    "submenu" :{
                        "create_file" : {
                            "seperator_before" : false,
                            "seperator_after" : false,
                            "label" : "File",
                            action : function (obj) {
                                this.create(obj, "last", {"attr" : {"rel" : "default"}});
                            }
                        },
                        "create_folder" : {
                            "seperator_before" : false,
                            "seperator_after" : false,
                            "label" : "Folder",
                            action : function (obj) {                               
                                this.create(obj, "last", {"attr" : { "rel" : "folder"}});
                            }
                        }
                    }
                }
            }
        },
    

    For any noobs – if you look at the code posted in the posted question you should be able to see where this goes.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
this is what i have right now Drawing an RSS feed into the php,
I have just tried to save a simple *.rtf file with some websites and
I am trying to loop through a bunch of documents I have to put
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.