~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/app/javascript/beta-notification.js

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-11-14 17:57:46 UTC
  • mfrom: (14266.1.4 banner-for-beta-features-2)
  • Revision ID: launchpad@pqm.canonical.com-20111114175746-uuzm69fvr7e3rwq5
[r=jcsackett][bug=888599] Infrastructure to show a banner about
 enabled beta features on a page;
 new property BugTaskSearchListingView.beta_features

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
YUI.add('lp.app.beta_features', function(Y) {
 
2
 
 
3
var namespace = Y.namespace('lp.app.beta_features');
 
4
 
 
5
var beta_notification_node = null;
 
6
 
 
7
/**
 
8
 * For unit tests - we need to reset the notification setup to run more than
 
9
   one test.
 
10
 */
 
11
namespace._reset_beta_notification = function () {
 
12
    notification_node = null;
 
13
};
 
14
 
 
15
/*
 
16
 * Display beta feature notifications.
 
17
 *
 
18
 * This should be called after the page has loaded e.g. on 'domready'.
 
19
 */
 
20
function display_beta_notification() {
 
21
    if (LP.cache.beta_features.length === 0) {
 
22
        return;
 
23
    }
 
24
 
 
25
    var beta_features = LP.cache.beta_features;
 
26
    var body = Y.one('body');
 
27
    body.addClass('global-notification-visible');
 
28
    var main = Y.one('#maincontent');
 
29
    beta_notification_node = Y.Node.create('<div></div>')
 
30
        .addClass('beta-banner');
 
31
    main.appendChild(beta_notification_node);
 
32
    var beta_warning = Y.Node.create(
 
33
        '<span class="beta-warning">BETA</span>');
 
34
    beta_notification_node.appendChild(beta_warning);
 
35
    var close_box = Y.Node.create(
 
36
        '<a href="#" class="global-notification-close">Hide' +
 
37
        '<span class="notification-close sprite" /></a>');
 
38
    beta_notification_node.appendChild(close_box);
 
39
    beta_notification_node.append('Some parts of this page are in beta: ');
 
40
    var index;
 
41
    for (index = 0; index < beta_features.length; index++) {
 
42
        var feature_name = beta_features[index][4];
 
43
        var info_link = beta_features[index][5];
 
44
        if (info_link.length > 0) {
 
45
            info_link =
 
46
                ' (<a href="' + info_link + '" class="info-link">' +
 
47
                'read more</a>)';
 
48
        }
 
49
        beta_notification_node.appendChild(Y.Node.create(
 
50
            '<span class="beta-feature"> ' + feature_name + info_link +
 
51
            '</span>'));
 
52
    }
 
53
    close_box.on('click', function(e) {
 
54
        e.halt();
 
55
        var fade_out = new Y.Anim({
 
56
            node: '.beta-banner',
 
57
            to: {opacity: 0},
 
58
            duration: 0.3
 
59
        });
 
60
        var body_space = new Y.Anim({
 
61
            node: 'body',
 
62
            to: {'paddingTop': 0},
 
63
            duration: 0.2,
 
64
            easing: Y.Easing.easeOut
 
65
        });
 
66
        var login_space = new Y.Anim({
 
67
            node: '.login-logout',
 
68
            to: {'top': '6px'},
 
69
            duration: 0.2,
 
70
            easing: Y.Easing.easeOut
 
71
        });
 
72
        fade_out.on('end', function() {
 
73
            fade_out.get('node').addClass('hidden');
 
74
        });
 
75
        body_space.on('end', function() {
 
76
            Y.one('body').removeClass('global-notification-visible');
 
77
        });
 
78
 
 
79
        fade_out.run();
 
80
        body_space.run();
 
81
        login_space.run();
 
82
    });
 
83
}
 
84
namespace.display_beta_notification = display_beta_notification;
 
85
 
 
86
}, "0.1", {"requires": ["base", "node", "anim"]});