~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/soyuz/templates/archive-macros.pt

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-17 23:09:32 UTC
  • mfrom: (13452.1.1 revert-lots)
  • Revision ID: launchpad@pqm.canonical.com-20110717230932-sp6yro99is2077fx
[r=wgrant][rollback=13421] Revert r13421 and r13438 (already
 partially reverted in r13443 and restored in r13445). Fix for DSP:+index
 expanders has not yet landed.

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
  </tal:comment>
11
11
 
12
12
<script type="text/javascript">
13
 
LPS.use('node', 'io-base', 'lazr.anim', 'lp.soyuz.base',
14
 
        'lp.app.widgets.expander', function(Y) {
 
13
LPS.use('node', 'io-base', 'lazr.anim', 'lp.soyuz.base', function(Y) {
15
14
 
16
15
 
17
16
/*
19
18
 * the operation.
20
19
 */
21
20
function informFailure(transaction_id, response, args) {
 
21
    function retry_handler(e) {
 
22
        e.preventDefault();
 
23
        startUpdate(args.container);
 
24
    };
 
25
 
22
26
    var failure_message = Y.lp.soyuz.base.makeFailureNode(
23
 
        'Failed to fetch package details.');
 
27
        'Failed to fetch package details.', retry_handler);
24
28
 
25
 
    args.expander.receive(failure_message);
 
29
    args.container.set('innerHTML', '');
 
30
    args.container.appendChild(failure_message);
26
31
 
27
32
    var anim = Y.lazr.anim.red_flash({
28
 
        node: args.expander.content_node
 
33
        node: args.container
29
34
        });
30
35
    anim.run();
31
36
}
35
40
 * Update the row with the XHR response.
36
41
 */
37
42
function doUpdate(transaction_id, response, args) {
38
 
    var node = Y.Node.create('<div />')
39
 
                 .set('innerHTML', response.responseText);
40
 
    args.expander.receive(node);
 
43
    args.container.set('innerHTML', response.responseText);
41
44
}
42
45
 
43
46
 
44
 
/**
45
 
 * Dispatch a XHR to load the given container.
 
47
/*
 
48
 * Dispatch a XHR for updating the given container.
46
49
 */
47
 
function loadDetails(expander) {
 
50
function startUpdate(container) {
 
51
    var in_progress_message = Y.lp.soyuz.base.makeInProgressNode(
 
52
        'Fetching package details ...')
 
53
 
 
54
    container.set('innerHTML', '');
 
55
    container.appendChild(in_progress_message);
48
56
 
49
57
    var config = {
50
58
        on: {
52
60
            'failure': informFailure
53
61
        },
54
62
        arguments: {
55
 
            'expander': expander
 
63
            'container': container,
56
64
        }
57
65
    };
58
66
 
59
 
    /**
 
67
    /*
60
68
     * If a page wants to use this outside of an archive context then it
61
69
     * can define LP.cache['archive_context'], which should be a
62
70
     * full or relative URL to the context archive page required.
66
74
            ? LP.cache['archive_context_url']
67
75
            : '';
68
76
    if (base_url !== '') {
69
 
        base_url += '/';
 
77
        base_url += '/'
70
78
    }
71
 
    var pub_id = expander.content_node.get('id')
72
 
                   .replace('pub', '')
73
 
                   .replace('-container', '');
 
79
    var pub_id = container.get('id').replace(
 
80
        '-container', '').replace('pub', '');
74
81
    var uri = base_url + '+sourcepub/' + pub_id + '/+listing-archive-extra';
75
82
    Y.io(uri, config);
76
83
}
77
84
 
78
 
/**
79
 
 * Setup expander handlers.
 
85
 
 
86
/*
 
87
 * Toggle the visibility of the expander targeted and the visual of
 
88
 * the expander itself.
 
89
 */
 
90
function toggleExpandableRow(expander) {
 
91
    var row = Y.one('#' + expander.get('id').replace('-expander', ''));
 
92
    var icon = expander.one('img');
 
93
 
 
94
    var row_display = row.getStyle('display');
 
95
    if (row_display == 'none') {
 
96
        row.setStyle('display', 'table-row');
 
97
        icon.set('src', '/@@/treeExpanded');
 
98
        var container = Y.one('#' + row.get('id') + '-container');
 
99
        if (trim(container.get('innerHTML')) == ''){
 
100
            startUpdate(container);
 
101
        }
 
102
    }
 
103
    else {
 
104
        row.setStyle('display', 'none');
 
105
        icon.set('src', '/@@/treeCollapsed');
 
106
    }
 
107
}
 
108
 
 
109
 
 
110
/*
 
111
 * Setup expander handlers and pre-load 'treeExpanded', 'no' and
 
112
 * 'spinner' images for better reponsiveness.
80
113
 */
81
114
function setupPackageListExpanders() {
 
115
    var spinner = new Image();
 
116
    spinner.src = '/@@/spinner';
 
117
 
 
118
    var no = new Image();
 
119
    no.src = '/@@/no';
 
120
 
 
121
    var tree_expanded = new Image();
 
122
    tree_expanded.src = '/@@/treeExpanded';
 
123
 
 
124
    function expander_handler (e) {
 
125
        e.preventDefault();
 
126
        toggleExpandableRow(e.currentTarget);
 
127
    };
 
128
 
 
129
    // Note: there are situations, such as displaying empty result
 
130
    // sets, when there will not be any links for expanders on the page.
82
131
    var expanders = Y.all('#packages_list a.expander');
83
 
    var widget;
84
 
    if (expanders !== null) {
85
 
       function setupExpander(expander) {
86
 
         var base_id = expander.get('id').replace('-expander', '');
87
 
         var container = Y.one('#' + base_id);
88
 
         var content = container.one('td div.package-details');
89
 
         var in_progress_message = Y.lp.soyuz.base.makeInProgressNode(
90
 
           'Fetching package details ...');
91
 
         content.empty();
92
 
         content.appendChild(in_progress_message);
93
 
 
94
 
         widget = new Y.lp.app.widgets.expander.Expander(
95
 
             expander, container, { loader: loadDetails,
96
 
                                    animate_node: content });
97
 
         widget.setUp();
98
 
       };
99
 
       expanders.each(setupExpander);
 
132
    if (expanders !== null){
 
133
        expanders.on("click", expander_handler);
100
134
    }
101
135
}
102
136