Project

General

Profile

Revision 87f39d13

ID87f39d132124ea1931c5e08e749760bdc7f8666a
Parent 3e3db819
Child d8937f15

Added by Aurelien BOMPARD over 13 years ago

vigigraph: fin de la suppression de l'ancien TreeGroup

git-svn-id: https://vigilo-dev.si.c-s.fr/svn@6830 b22e2e97-25c9-44ff-b637-2e5ceca36478

View differences:

vigigraph/public/js/toolbar.js
13 13
            itemImage: "images/" + itemImage,
14 14
            onItemClick: this.selectItem.bind(this)
15 15
        });
16
        /*
17
        this.tree = new GroupTree({
18
            title: this.options.label,
19
            url: url,
20
            hostid: hostid
21
        });
22
        */
23 16
        options.content = tree_container;
24 17
        options.onOpen = function() {
25 18
            if (! this.tree.isLoaded) {
vigigraph/public/js/tree.js
1
/**
2
 * VigiGraph, composant de Vigilo.
3
 * (c) CSSI 2009-2010 <contact@projet-vigilo.org>
4
 * Licence : GNU GPL v2 ou superieure
5
 *
6
 */
7

  
8
/*
9
 * Affichage en arbre des groupes d'hôtes.
10
 */
11
var TreeGroup = new Class({
12
    Implements: [Options, Events],
13

  
14
    initialize: function(options) {
15
        this.setOptions(options);
16

  
17
        /* L'objet tree se réfère à un élément div*/
18
        this.container = new Element('div');
19
        this.container.setStyle("padding", "0 10px 10px 10px");
20
        this.tree = new Jx.Tree({parent: this.container});
21

  
22
        this.dlg = new Jx.Dialog({
23
            label: this.options.title,
24
            modal: true,
25
            resize: true,
26
            content: this.container
27
        });
28

  
29
        this.redraw();
30
    },
31

  
32
    /* Récupération des items (noeuds/feuilles) de l'arbre dépendant
33
     * du parent dont l'identifiant est passé en paramètre */
34
    retrieve_tree_items: function(parent_node, top_node) {
35

  
36
        // Si l'identifiant est bien défini, on ajoute les
37
        // items  récupérés à leur parent dans l'arbre
38
        var req = new Request.JSON({
39
            url: this.options.url,
40
            onSuccess: function(data, xml) {
41
                if ($defined(data.groups)) {
42
                    data.groups.each(function(item) {
43
                        this.addNode(item, parent_node);
44
                    }, this);
45
                }
46
                if ($defined(data.leaves)) {
47
                    data.leaves.each(function(item) {
48
                        this.addLeaf(item, parent_node);
49
                    }, this);
50
                }
51
                this.fireEvent("branchloaded");
52
            }.bind(this)
53
        });
54

  
55
        // Envoi de la requête
56
        if (!$chk(top_node)) {
57
            if (!$defined(this.options.hostid)) {
58
                req.get({parent_id: parent_node.options.data});
59
            }
60
            else {
61
                req.get({parent_id: parent_node.options.data, host_id: this.options.hostid});
62
            }
63
        }
64
        else if (!$defined(this.options.hostid)) {
65
            req.get();
66
        }
67
        else {
68
            req.get({host_id: this.options.hostid});
69
        }
70
    },
71

  
72
    /* Ajout d'un noeud à l'arbre */
73
    addNode: function(data, parent_node) {
74
        var node = new Jx.TreeFolder({
75
            label: data.name,
76
            data: data.id
77
        });
78

  
79
        node.addEvent("disclosed", function(node) {
80
            this.fireEvent("nodedisclosed", node);
81
            if (!node.options.open || node.nodes.length > 0)
82
                return;
83
            this.retrieve_tree_items(node);
84
        }.bind(this));
85

  
86
        parent_node.append(node);
87
    },
88

  
89
    /* Ajout d'une feuille à l'arbre */
90
    addLeaf: function(data, parent_node) {
91
        var leaf = new Jx.TreeItem({
92
            label: data.name,
93
            data: data.id
94
        });
95

  
96
        leaf.addEvent("click", function() {
97
            this.fireEvent('select', [leaf]);
98
            this.dlg.close();
99
        }.bind(this));
100

  
101
        parent_node.append(leaf);
102
    },
103

  
104
    selectGroup: function() {
105
        this.dlg.open();
106
    },
107

  
108
    redraw: function() {
109
        this.tree.clear();
110
        this.retrieve_tree_items(this.tree, true);
111
    }
112
});

Also available in: Unified diff