Revision 1ae97c83 snf-astakos-app/astakos/im/static/im/cloudbar/cloudbar.js

b/snf-astakos-app/astakos/im/static/im/cloudbar/cloudbar.js
5 5
    */
6 6

  
7 7
    var PROFILE_URL = "https://accounts.cloud.grnet.gr";
8
    var SERVICES_LINKS = window.CLOUDBAR_SERVICES_LINKS || {
9
        'cloud':   { url:'/', name:'grnet cloud', id:'cloud', icon:'home-icon.png' },
10
        'okeanos': { url:'/okeanos.html', name:'~okeanos', id:'okeanos' },
11
        'pithos':  { url:'/ui/', name:'pithos+', id:'pithos' }
12
    };
13
    
14
    var PROFILE_LINKS = window.CLOUDBAR_PROFILE_LINKS || {
15
        'login': { url: '/im/login?next=' + window.location.toString(), auth:false, name: "login...", visible:false },
16
        'profile': { url: '/im/profile', auth:true, name: "view your profile..." },
17
        'password': { url: '/im/password', auth:true, name: "change your password..." },
18
        'invitations': { url: '/im/invite', auth:true, name: "invite some friends..." },
19
        'feedback': { url: '/im/feedback', auth:true, name: "feedback..." },
20
        'logout': { url: '/im/logout', auth:true, name: "logout..." }
21
    };
22

  
23 8

  
24 9
    // cookie plugin https://raw.github.com/carhartl/jquery-cookie/master/jquery.cookie.js 
25 10
    //  * Copyright (c) 2010 Klaus Hartl, @carhartl
......
51 36
    var services = $('<div class="services"></div>');
52 37
    var profile = $('<div class="profile"></div>');
53 38
    
54
    
55 39
    // create services links and set the active class to the current service
56
    $.each(SERVICES_LINKS, function(i, el){
57
        var slink = $("<a>");
58
        if (el.icon) {
59
            slink.append($('<img src="'+cssloc+el.icon+'"/>'));
60
        } else {
61
            slink.text(el.name);
62
        }
63
        slink.attr('href', el.url);
64
        slink.attr('title', el.name);
65
        services.append(slink);
66
        if (el.id == ACTIVE_MENU) {
67
            slink.addClass("active");
68
        }
69
    });
70

  
71
    var USERNAME, LOGGED_IN;
72
    var authcookie = cookie(COOKIE_NAME);
73
    var anonymous = {'user': 'Login...', 'logged_in': false};
74

  
75
    if (authcookie && authcookie.indexOf("|") > -1) {
76
        USER_DATA.logged_in = true;
77
        USER_DATA.user = authcookie.split("|")[0];
78
    } else {
79
        USER_DATA = anonymous;
80
    }
81

  
82
    USERNAME = USER_DATA.user;
83
    LOGGED_IN = USER_DATA.logged_in;
84

  
85
    // clear username
86
    USERNAME = USERNAME.replace(/\\'/g,'');
87
    USERNAME = USERNAME.replace(/\"/g,'');
88

  
89
    var user = $('<div class="user"></div>');
90
    var username = $('<a href="#"></a>');
91
    username.text(USERNAME);
40
    $.getJSON('/im/get_services/', function(data) {
41
            $.each(data, function(i, el){
42
            var slink = $("<a>");
43
            if (el.icon) {
44
                slink.append($('<img src="'+cssloc+el.icon+'"/>'));
45
            } else {
46
                slink.text(el.name);
47
            }
48
            slink.attr('href', el.url);
49
            slink.attr('title', el.name);
50
            services.append(slink);
51
            if (el.id == ACTIVE_MENU) {
52
                slink.addClass("active");
53
            }
54
        });
55
      });
92 56
    
93 57
    // create profile links
58
    var user = $('<div class="user"></div>');    
59
    var username = $('<a href="#"></a>');
94 60
    var usermenu = $("<ul>");
95
    $.each(PROFILE_LINKS, function(i,el) {
96
        if (!LOGGED_IN && el.auth) { return }
97
        if (LOGGED_IN && !el.auth) { return }
98
        var li = $("<li />");
99
        var link = $("<a />");
100
        link.text(el.name);
101
        link.attr({href:el.url});
102
        li.append(link);
103
        if (el.visible == false) {
104
            li.hide();
105
        }
106
        usermenu.append(li);
61
    $.getJSON('/im/get_menu/?location='.concat(window.location.toString()), function(data) {
62
        $.each(data, function(i,el) {
63
            if (i == 0){
64
                username.text(el.name);
65
                username.attr('href', el.url);
66
            }else{
67
                var link = $("<a />");
68
                link.text(el.name);
69
                link.attr({href:el.url});
70
                var li = $("<li />");
71
                li.append(link);
72
                usermenu.append(li);
73
            }
74
        });
107 75
    });
108

  
76
    
109 77
    //profile.filter(".user a").attr("href", 
110 78
                                   //profile.find("li a").get(0).attr("href"))
111 79
    
112

  
113
    
114 80
    user.append(username);
115 81
    user.append(usermenu);
116 82
    profile.append(user);

Also available in: Unified diff