var UITree = function () {
    var ajaxTreeSample = function () {
        $("#treeView").jstree({
            "core": {
                "themes": {
                    "responsive": false
                },
                // so that create works
                "check_callback": true,
                'data': {
                    'url': function (node) {
                        return '/productcategory/GetAllToTree';
                    },
                    'data': function (node) {
                        return { 'parent': node.id };
                    }
                }
            },
            //"types": {
            //    "default": {
            //        "icon": "fa fa-folder icon-state-warning icon-lg"
            //    },
            //    "file": {
            //        "icon": "fa fa-file icon-state-warning icon-lg"
            //    }
            //},
            "state": { "key": "demo3" },
            'contextmenu': {'items': customMenu},
            "plugins": ["contextmenu", "state", "types", "search"]
        });
    }

    return {
        //main function to initiate the module
        init: function () {
            ajaxTreeSample();
        }
    };
}();

//PLUS IN TÌM KIẾM
$("#btnSearch").click(function (e) {
    e.preventDefault();
    $("#treeView").jstree(true).search($("#txt-keyword").val());
});
$('#txt-keyword').keypress(function (e) {
    if (e.which === 13) {
        e.preventDefault();
        $("#treeView").jstree(true).search($("#txt-keyword").val());
    }
});
function customMenu(node) {
    var nodeid = $('#treeNodeID').val();
    var items = {
        'item1': {
            'label': 'Thêm Nhóm con',
            'action': function () { document.location.href = '/Productcategory/Create/' + nodeid }
        },
        'item2': {
            'label': 'Cập nhật',
            'action': function() { document.location.href = '/Productcategory/edit/' + nodeid }
        },
        'item3': {
            'label': 'Xoá',
            'action': function () { document.location.href = '/Productcategory/Delete/' + nodeid }
        }
    };
    return items;
}

if (App.isAngularJsApp() === false) {
    jQuery(document).ready(function () {
        UITree.init();
    });
}