client/js/retrieve-kc.js
author rougeronj
Tue, 22 Sep 2015 15:14:10 +0200
changeset 543 5f7bebdcfc0d
parent 433 e457ec945e50
permissions -rw-r--r--
Improve the way we init the view. The data loader send a "loaded" event, hooked by the scene.py and initializing the backbone.history and the view. We don't use redraw_active in save-once and full-json, because it was making the view initialization dependent of these file which are externals. Small fix to hide the "set saved view" button when there is only one view.

/* Imports a KC graph */

Rkns.retrieveKC = function(_renkan, _opts) {
    if (typeof _opts === "undefined") {
        _opts = {};
    }
    var _proj = _renkan.project,
        _username = _opts.user_name || "Yves-Marie",
        _userid = _opts.user_id || "yves-marie.haussonne@centrepompidou.fr",
        _usercolor = _opts.user_color || "#800000",
        _allid = _opts.all_id || "B0000044",
        _projid = _opts.proj || "ozu_silent",
        _kcept = _opts.endpoint || "/sites/kcproxy/allRetrieve.jsp";
    var _load = function() {
        Rkns.$.getJSON(_kcept,
        {
            all_id: _allid,
            proj: _projid,
            uid: _userid
        },
        function(_data) {
            _proj.addUser({
                id: _userid,
                color: _usercolor,
                title: _username
            });
            Rkns._.each(_data.node, function(_node) {
                _proj.addNode({
                    id: _node.id,
                    title: _node.name,
                    description: 'Knowledge concierge node from project "' + _projid + '" belonging to group "' + _node.grp + '"',
                    position: {
                        x: _node.x,
                        y: _node.y
                    },
                    created_by: _userid
                });
            });
            Rkns._.each(_data.edge, function(_edge) {
                _proj.addEdge({
                    id: _edge.asc_id,
                    from: _edge.id,
                    to: _edge.to_id,
                    created_by: _userid,
                    title: _edge.r_name
                });
            });
        });
    };
    _load();
};