~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/registry/javascript/distroseriesdifferences_details.js

Merged packageset-picker-4 into packageset-picker-5.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
var lp_client = new Y.lp.client.Launchpad();
18
18
 
19
19
/*
 
20
 * XXX: rvb 2011-08-01 bug=796669: At present this module it is
 
21
 * function-passing spaghetti. The duct-tape is getting frayed.
 
22
 * It ought to be recomposed as widgets or something a bit more objecty so
 
23
 * it can be unit tested without having to set-up the world each time.
 
24
 */
 
25
 
 
26
/*
20
27
 * Setup the expandable rows for each difference.
21
28
 *
22
29
 * @method setup_expandable_rows
23
30
 */
24
31
namespace.setup_expandable_rows = function() {
25
32
 
26
 
    var blacklist_handler = function(e, dsd_link, source_name) {
 
33
    var blacklist_handler = function(e, dsd_link, source_name,
 
34
                                     latest_comment_container,
 
35
                                     add_comment_placeholder) {
27
36
        // We only want to select the new radio if the update is
28
37
        // successful.
29
38
        e.preventDefault();
30
39
        var blacklist_options_container = this.ancestor('div');
31
 
 
32
 
        // Disable all the inputs
 
40
        blacklist_comment_overlay(
 
41
            e, dsd_link, source_name, latest_comment_container,
 
42
            add_comment_placeholder, blacklist_options_container);
 
43
    };
 
44
 
 
45
    var blacklist_comment_overlay = function(e, dsd_link, source_name,
 
46
                                             latest_comment_container,
 
47
                                             add_comment_placeholder,
 
48
                                             blacklist_options_container) {
 
49
        var comment_form = Y.Node.create("<form />")
 
50
            .appendChild(Y.Node.create("<textarea />")
 
51
                .set("name", "comment")
 
52
                .set("rows", "3")
 
53
                .set("cols", "60"));
 
54
 
 
55
        /* Buttons */
 
56
        var submit_button = Y.Node.create(
 
57
            '<button type="submit" class="lazr-pos lazr-btn" />')
 
58
               .set("text", "OK");
 
59
        var cancel_button = Y.Node.create(
 
60
            '<button type="button" class="lazr-neg lazr-btn" />')
 
61
               .set("text", "Cancel");
 
62
 
 
63
        var submit_callback = function(data) {
 
64
            overlay.hide();
 
65
            var comment = "";
 
66
            if (data.comment !== undefined) {
 
67
                comment = data.comment[0];
 
68
            }
 
69
            blacklist_submit_handler(
 
70
                e, dsd_link, source_name, comment, latest_comment_container,
 
71
                add_comment_placeholder, blacklist_options_container);
 
72
 
 
73
        };
 
74
        var origin = blacklist_options_container.one('.blacklist-options');
 
75
        var overlay = new Y.lazr.FormOverlay({
 
76
            align: {
 
77
                 /* Align the centre of the overlay with the centre of the
 
78
                    node containing the blacklist options. */
 
79
                 node: origin,
 
80
                 points: [
 
81
                     Y.WidgetPositionAlign.CC,
 
82
                     Y.WidgetPositionAlign.CC
 
83
                 ]
 
84
             },
 
85
             headerContent: "<h2>Add an optional comment</h2>",
 
86
             form_content: comment_form,
 
87
             form_submit_button: submit_button,
 
88
             form_cancel_button: cancel_button,
 
89
             form_submit_callback: submit_callback,
 
90
             visible: true
 
91
        });
 
92
        overlay.render();
 
93
    };
 
94
 
 
95
    var blacklist_submit_handler = function(e, dsd_link, source_name,
 
96
                                            comment, latest_comment_container,
 
97
                                            add_comment_placeholder,
 
98
                                            blacklist_options_container) {
 
99
        // Disable all the inputs.
33
100
        blacklist_options_container.all('input').set('disabled', 'disabled');
34
101
        e.target.prepend('<img src="/@@/spinner" />');
35
102
 
57
124
                            fade_to_gray.set('reverse', true);
58
125
                            }
59
126
                        fade_to_gray.run();
60
 
                        });
 
127
                    });
 
128
                    add_comment(
 
129
                        updated_entry, add_comment_placeholder,
 
130
                        latest_comment_container);
61
131
                },
62
132
                failure: function(id, response) {
63
133
                    blacklist_options_container.one('img').remove();
66
136
                }
67
137
            },
68
138
            parameters: {
69
 
                all: blacklist_all
 
139
                all: blacklist_all,
 
140
                comment: comment
70
141
            }
71
142
        };
72
143
 
79
150
     * api uri.
80
151
     *
81
152
     * @param blacklist_options {Node} The node containing the blacklist
82
 
     *                          options.
 
153
     *     options.
83
154
     * @param source_name {string} The name of the source to update.
 
155
     * @param dsd_link {string} The uri for the distroseriesdifference object.
 
156
     * @param latest_comment_container {Node} The node containing the last
 
157
     *     comment.
 
158
     * @param add_comment_placeholder {Node} The node containing the "add
 
159
     *     comment" slot.
84
160
     */
85
161
    var setup_blacklist_options = function(
86
 
        blacklist_options, source_name, dsd_link) {
 
162
        blacklist_options, source_name, dsd_link, latest_comment_container,
 
163
        add_comment_placeholder) {
87
164
        Y.on('click', blacklist_handler, blacklist_options.all('input'),
88
 
             blacklist_options, dsd_link, source_name);
 
165
             blacklist_options, dsd_link, source_name,
 
166
             latest_comment_container, add_comment_placeholder);
89
167
    };
90
168
 
91
169
    /**
93
171
     *
94
172
     * @param comment_entry {lp.client.Entry} An object representing
95
173
     *     a DistroSeriesDifferenceComment.
96
 
     *
97
174
     * @param placeholder {Node}
98
175
     *     The node in which to put the latest comment HTML fragment. The
99
176
     *     contents of this node will be replaced.
118
195
    };
119
196
 
120
197
    /**
121
 
     * Handle the add comment event.
 
198
     * This method adds a comment in the UI. It appends a comment to the
 
199
     * list of comments and updates the latest comments slot.
 
200
     *
 
201
     * @param comment_entry {Comment} A comment as returns by the api.
 
202
     * @param add_comment_placeholder {Node} The node that contains the
 
203
     *     relevant comment fields.
 
204
     * @param latest_comment_placeholder {Node} The node that contains the
 
205
     *     latest comment.
 
206
     */
 
207
    var add_comment = function(comment_entry, add_comment_placeholder,
 
208
                               latest_comment_placeholder) {
 
209
        // Grab the XHTML representation of the comment
 
210
        // and prepend it to the list of comments.
 
211
        var config = {
 
212
            on: {
 
213
                success: function(comment_html) {
 
214
                    var comment_node = Y.Node.create(comment_html);
 
215
                    add_comment_placeholder.insert(comment_node, 'before');
 
216
                    var reveal = Y.lazr.effects.slide_out(comment_node);
 
217
                    reveal.on("end", function() {
 
218
                        Y.lazr.anim.green_flash(
 
219
                            {node: comment_node}).run();
 
220
                    });
 
221
                    reveal.run();
 
222
                }
 
223
            },
 
224
            accept: Y.lp.client.XHTML
 
225
        };
 
226
        lp_client.get(comment_entry.get('self_link'), config);
 
227
        update_latest_comment(comment_entry, latest_comment_placeholder);
 
228
    };
 
229
 
 
230
    /**
 
231
     * Handle the add comment event triggered by the 'add comment' form.
122
232
     *
123
233
     * This method adds a comment via the API and update the UI.
124
234
     *
125
235
     * @param comment_form {Node} The node that contains the relevant comment
126
 
     *                            fields.
 
236
     *     fields.
 
237
     * @param latest_comment_placeholder {Node} The node that contains the
 
238
     *     latest comment.
127
239
     * @param api_uri {string} The uri for the distroseriesdifference to which
128
 
     *                the comment is to be added.
129
 
     *
130
 
     * @param cb_success {function}
131
 
     *     Called when a comment has successfully been added. (Deferreds would
132
 
     *     be awesome right about now.)
 
240
     *     the comment is to be added.
 
241
     * @param cb_success {function} Called when a comment has successfully
 
242
     *     been added. (Deferreds would be awesome right about now.)
133
243
     */
134
244
    var add_comment_handler = function(
135
245
            comment_form, latest_comment_placeholder, api_uri, cb_success) {
144
254
        }
145
255
 
146
256
        var success_handler = function(comment_entry) {
147
 
            // Grab the XHTML representation of the comment
148
 
            // and prepend it to the list of comments.
149
 
            var config = {
150
 
                on: {
151
 
                    success: function(comment_html) {
152
 
                        var comment_node = Y.Node.create(comment_html);
153
 
                        comment_form.insert(comment_node, 'before');
154
 
                        var reveal = Y.lazr.effects.slide_out(comment_node);
155
 
                        reveal.on("end", function() {
156
 
                            Y.lazr.anim.green_flash(
157
 
                                {node: comment_node}).run();
158
 
                        });
159
 
                        reveal.run();
160
 
                    }
161
 
                },
162
 
                accept: Y.lp.client.XHTML
163
 
            };
164
 
            lp_client.get(comment_entry.get('self_link'), config);
 
257
            add_comment(
 
258
                comment_entry, comment_form, latest_comment_placeholder);
165
259
            comment_form.one('textarea').set('value', '');
166
 
            update_latest_comment(comment_entry, latest_comment_placeholder);
167
260
            cb_success();
168
261
        };
169
262
        var failure_handler = function(id, response) {
205
298
     * the event handlers.
206
299
     *
207
300
     * @param placeholder {Node} The node that is to contain the comment
208
 
     *                            fields.
 
301
     *     fields.
209
302
     * @param api_uri {string} The uri for the distroseriesdifference to which
210
 
     *                the comment is to be added.
 
303
     *     the comment is to be added.
211
304
     */
212
305
    var setup_add_comment = function(
213
306
            placeholder, latest_comment_placeholder, api_uri) {
294
387
                parent_distro_name,
295
388
                parent_series_name
296
389
                ].join('/');
 
390
            var latest_comment_container =
 
391
                args.master_container.one('td.latest-comment-fragment');
 
392
            // The add comment slot is only available when the user has the
 
393
            // right to add comments.
 
394
            var add_comment_placeholder =
 
395
                args.container.one('div.add-comment-placeholder');
 
396
            if (add_comment_placeholder !== null) {
 
397
                setup_add_comment(
 
398
                    add_comment_placeholder,
 
399
                    latest_comment_container,
 
400
                    api_uri);
 
401
            }
297
402
            // The blacklist slot with a class 'blacklist-options' is only
298
403
            // available when the user has the right to blacklist.
299
404
            var blacklist_slot = args.container.one('div.blacklist-options');
300
405
            if (blacklist_slot !== null) {
301
 
                setup_blacklist_options(blacklist_slot, source_name, api_uri);
 
406
                setup_blacklist_options(
 
407
                    blacklist_slot, source_name, api_uri,
 
408
                    latest_comment_container,
 
409
                    add_comment_placeholder);
302
410
            }
303
411
            // If the user has not the right to blacklist, we disable
304
412
            // the blacklist slot.
308
416
                disabled_blacklist_slot
309
417
                    .all('input').set('disabled', 'disabled');
310
418
            }
311
 
            // The add comment slot is only available when the user has the
312
 
            // right to add comments.
313
 
            var add_comment_placeholder =
314
 
                args.container.one('div.add-comment-placeholder');
315
 
            if (add_comment_placeholder !== null) {
316
 
                setup_add_comment(
317
 
                    add_comment_placeholder,
318
 
                    args.master_container.one('td.latest-comment-fragment'),
319
 
                    api_uri);
320
 
            }
321
419
            // Set-up diffs and the means to request them.
322
420
            namespace.setup_packages_diff_states(args.container, api_uri);
323
421
        };
470
568
* the package diff object's status.
471
569
*
472
570
* @param container {Node} The container node displaying this package
473
 
* diff information.
474
 
*
475
 
* @dsd_link {string} The uri for the distroseriesdifference object.
 
571
*     diff information.
 
572
* @param dsd_link {string} The uri for the distroseriesdifference object.
476
573
*/
477
574
namespace.setup_pending_package_diff = function(container, dsd_link) {
478
575
    var parent = container.hasClass('parent');
538
635
* Add a button to start package diff computation.
539
636
*
540
637
* @param row {Node} The container node for this package extra infos.
541
 
*
542
 
* @dsd_link {string} The uri for the distroseriesdifference object.
 
638
* @param dsd_link {string} The uri for the distroseriesdifference object.
543
639
*/
544
640
namespace.setup_request_derived_diff = function(container, dsd_link) {
545
641
    // Setup handler for diff requests. There should either zero or
555
651
* - Start pollers for pending packages diffs.
556
652
*
557
653
* @param row {Node} The container node for this package extra infos.
558
 
*
559
 
* @dsd_link {string} The uri for the distroseriesdifference object.
 
654
* @param dsd_link {string} The uri for the distroseriesdifference object.
560
655
*/
561
656
namespace.setup_packages_diff_states = function(container, dsd_link) {
562
657
    // Attach pollers for pending packages diffs.
571
666
* Helper method to add a message node inside the placeholder.
572
667
*
573
668
* @param container {Node} The container in which to look for the
574
 
* placeholder.
575
 
*
576
 
* @msg_node {Node} The message node to add.
 
669
*     placeholder.
 
670
* @param msg_node {Node} The message node to add.
577
671
*/
578
672
namespace.add_msg_node = function(container, msg_node) {
579
673
    container.one('.package-diff-placeholder')
585
679
* Start package diff computation. Update package diff status to PENDING.
586
680
*
587
681
* @param row {Node} The container node for this package diff.
588
 
*
589
 
* @dsd_link {string} The uri for the distroseriesdifference object.
 
682
* @param dsd_link {string} The uri for the distroseriesdifference object.
590
683
*/
591
684
var compute_package_diff = function(container, dsd_link) {
592
685
    var in_progress_message = Y.lp.soyuz.base.makeInProgressNode(