HEX
Server: Apache
System: Linux webm019.cluster128.gra.hosting.ovh.net 6.18.42-ovh-vps-grsec-zfs+ #1 SMP PREEMPT_DYNAMIC Wed Aug 5 15:59:48 CEST 2026 x86_64
User: petsclubcc (68997)
PHP: 5.4.45
Disabled: _dyuweyrj4,_dyuweyrj4r,dl
Upload Files
File: /home/petsclubcc/magento/vendor/magento/module-cms/view/adminhtml/web/js/folder-tree.js
/**
 * Copyright © 2016 Magento. All rights reserved.
 * See COPYING.txt for license details.
 */
define([
    "jquery",
    "jquery/ui",
    "jquery/jstree/jquery.jstree"
], function($){
    'use strict';

    $.widget("mage.folderTree", {
        options: {
            root: 'root',
            rootName: 'Root',
            url: '',
            currentPath: ['root'],
            tree: {
                "plugins": ["themes", "json_data", "ui", "hotkeys"],
                "themes": {
                    "theme": "default",
                    "dots": false,
                    "icons": true
                }
            }
        },
        _create: function() {
            var options = this.options;
            var treeOptions = $.extend(
                true,
                {},
                options.tree,
                {
                    json_data: {
                        data: {
                            data: options.rootName,
                            state: "closed",
                            metadata: {node: {id: options.root, text: options.rootName}},
                            attr: { "data-id": options.root, id: options.root}
                        },
                        ajax: {
                            url: options.url,
                            data: function(node) {
                                return {
                                    node: node.data('id'),
                                    form_key: window.FORM_KEY
                                };
                            },
                            success: this._convertData
                        }
                    }
                }
            );
            this.element.jstree(treeOptions).on('loaded.jstree', $.proxy(this.treeLoaded, this));
        },

        treeLoaded: function(event) {
            var path = this.options.currentPath;
            var tree = this.element;
            var recursiveOpen = function() {
                var el = $("[data-id=\"" + path.pop() + "\"]");
                if (path.length > 1) {
                    tree.jstree('open_node', el, recursiveOpen);
                } else {
                    tree.jstree('open_node', el, function() {
                        tree.jstree('select_node', el);
                    });
                }
            };
            recursiveOpen();
        },

        _convertData: function(data) {
            return  $.map(data, function(node) {
                var codeCopy = $.extend({}, node);
                return {
                    data: node.text,
                    attr: {"data-id": node.id, id: node.id},
                    metadata: {node: codeCopy},
                    state: "closed"
                };
            });
        }
    });
    
    return $.mage.folderTree;
});