Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

vigiboard / vigiboard / public / js / tree.js @ d8968a9a

History | View | Annotate | Download (1.86 KB)

1
/**
2
 * VigiBoard, 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.
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
        var container = new Element('div')
19
        this.tree = new Jx.Tree({parent: container});
20

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

    
27
        var req = new Request.JSON({
28
            method: "get",
29
            url: this.options.url,
30
            onSuccess: function(groups) {
31
                $each(groups.groups, function(item) {
32
                    this.addItem(item, this.tree);
33
                }, this);
34
            }.bind(this)
35
        });
36
        req.send();
37
    },
38

    
39
    /* Ajout d'un element à l'arbre */
40
    addItem: function(data, parent) {
41
        var subfolder;
42
        if (data.children.length) {
43
            subfolder = new Jx.TreeFolder({
44
                label: data.name,
45
                data: data.idgroup,
46
                image: this.options.app_path+"images/map-list.png"
47
            });
48
        }
49
        else {
50
            subfolder = new Jx.TreeItem({
51
                label: data.name,
52
                data: data.idgroup,
53
                image: this.options.app_path+"images/map.png"
54
            });
55
        }
56

    
57
        subfolder.addEvent("click", function() {
58
            this.fireEvent('select', [subfolder]);
59
            this.dlg.close();
60
            return false;
61
        }.bind(this));
62
        parent.append(subfolder);
63

    
64
        $each(data.children, function(item) {
65
            this.addItem(item, subfolder);
66
        }, this);
67
    },
68

    
69
    selectGroup: function() {
70
        this.dlg.open();
71
    }
72
});