~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/javascript/privacy.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-25 08:55:37 UTC
  • mfrom: (13287.1.8 bug-800652)
  • Revision ID: launchpad@pqm.canonical.com-20110625085537-moikyoo2pe98zs7r
[r=jcsackett, julian-edwards][bug=800634,
        800652] Enable and display overrides on sync package uploads.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
YUI.add('lp.app.privacy', function(Y) {
2
 
 
3
 
var namespace = Y.namespace('lp.app.privacy');
4
 
 
5
 
var notification_node = null;
6
 
/*
7
 
 * Display privacy notifications
8
 
 *
9
 
 * This should be called after the page has loaded e.g. on 'domready'.
10
 
 */
11
 
 
12
 
function setup_privacy_notification(config) {
13
 
    if (notification_node !== null) {
14
 
        return;
15
 
    }
16
 
    var notification_text = 'The information on this page is private';
17
 
    var hidden = true;
18
 
    var target_id = "maincontent";
19
 
    if (config !== undefined) {
20
 
        if (config.notification_text !== undefined) {
21
 
            notification_text = config.notification_text;
22
 
        }
23
 
        if (config.hidden !== undefined) {
24
 
            hidden = config.hidden;
25
 
        }
26
 
        if (config.target_id !== undefined) {
27
 
            target_id = config.target_id;
28
 
        }
29
 
    }
30
 
    var id_selector = "#" + target_id;
31
 
    var main = Y.one(id_selector);
32
 
    notification_node = Y.Node.create('<div></div>')
33
 
        .addClass('global-notification');
34
 
    if (hidden) {
35
 
        notification_node.addClass('hidden');
36
 
    }
37
 
    var notification_span = Y.Node.create('<span></span>')
38
 
        .addClass('sprite')
39
 
        .addClass('notification-private');
40
 
    notification_node.set('text', notification_text);
41
 
 
42
 
    main.appendChild(notification_node);
43
 
    notification_node.appendChild(notification_span);
44
 
}
45
 
namespace.setup_privacy_notification = setup_privacy_notification;
46
 
 
47
 
/**
48
 
 * For unit tests - we need to reset the notification setup.
49
 
 */
50
 
namespace._reset_privacy_notification = function () {
51
 
    notification_node = null;
52
 
};
53
 
 
54
 
function display_privacy_notification() {
55
 
    /* Set a temporary class on the body for the feature flag,
56
 
     this is because we have no way to use feature flags in
57
 
     css directly. This should be removed if the feature
58
 
     is accepted. */
59
 
    var body = Y.one('body');
60
 
    body.addClass('feature-flag-bugs-private-notification-enabled');
61
 
    /* Set the visible flag so that the content moves down. */
62
 
    body.addClass('global-notification-visible');
63
 
 
64
 
    setup_privacy_notification();
65
 
    var global_notification = Y.one('.global-notification');
66
 
    if (global_notification.hasClass('hidden')) {
67
 
        global_notification.addClass('transparent');
68
 
        global_notification.removeClass('hidden');
69
 
 
70
 
        var fade_in = new Y.Anim({
71
 
            node: global_notification,
72
 
            to: {opacity: 1},
73
 
            duration: 0.3
74
 
        });
75
 
        var body_space = new Y.Anim({
76
 
            node: 'body',
77
 
            to: {'paddingTop': '40px'},
78
 
            duration: 0.2,
79
 
            easing: Y.Easing.easeOut
80
 
        });
81
 
        var login_space = new Y.Anim({
82
 
            node: '.login-logout',
83
 
            to: {'top': '45px'},
84
 
            duration: 0.2,
85
 
            easing: Y.Easing.easeOut
86
 
        });
87
 
 
88
 
        fade_in.run();
89
 
        body_space.run();
90
 
        login_space.run();
91
 
    }
92
 
}
93
 
namespace.display_privacy_notification = display_privacy_notification;
94
 
 
95
 
/*
96
 
 * Hide privacy notifications
97
 
 *
98
 
 * This should be called after the page has loaded e.g. on 'domready'.
99
 
 */
100
 
function hide_privacy_notification() {
101
 
    setup_privacy_notification();
102
 
    if (!Y.one('.global-notification').hasClass('hidden')) {
103
 
        var fade_out = new Y.Anim({
104
 
            node: '.global-notification',
105
 
            to: {opacity: 0},
106
 
            duration: 0.3
107
 
        });
108
 
        var body_space = new Y.Anim({
109
 
            node: 'body',
110
 
            to: {'paddingTop': 0},
111
 
            duration: 0.2,
112
 
            easing: Y.Easing.easeOut
113
 
        });
114
 
        var login_space = new Y.Anim({
115
 
            node: '.login-logout',
116
 
            to: {'top': '6px'},
117
 
            duration: 0.2,
118
 
            easing: Y.Easing.easeOut
119
 
        });
120
 
        fade_out.on('end', function() {
121
 
            fade_out.get('node').addClass('hidden');
122
 
        });
123
 
        body_space.on('end', function() {
124
 
            Y.one('body').removeClass('global-notification-visible');
125
 
        });
126
 
 
127
 
        fade_out.run();
128
 
        body_space.run();
129
 
        login_space.run();
130
 
 
131
 
        var privacy_portlet =  Y.one('.portlet.private');
132
 
        if (privacy_portlet !== null) {
133
 
            var portlet_colour = new Y.Anim({
134
 
                node: privacy_portlet,
135
 
                to: {
136
 
                    color: '#fff',
137
 
                    backgroundColor:'#8d1f1f'
138
 
                },
139
 
                duration: 0.4
140
 
            });
141
 
            portlet_colour.run();
142
 
        }
143
 
    }
144
 
}
145
 
namespace.hide_privacy_notification = hide_privacy_notification;
146
 
 
147
 
 
148
 
}, "0.1", {"requires": ["base", "node", "anim"]});