~launchpad-pqm/launchpad/devel

12221.8.2 by Brad Crittenden
Fixed lint
1
/* Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
8687.15.23 by Karl Fogel
Add the copyright header block to more files.
2
 * GNU Affero General Public License version 3 (see the file LICENSE).
8231.2.7 by Abel Deuring
lint removed from the new JS file
3
 *
8242.2.42 by Deryck Hodge
Add better, more consistent comments.
4
 * Form overlay widgets and subscriber handling for bug pages.
8231.2.7 by Abel Deuring
lint removed from the new JS file
5
 *
10985.3.14 by Deryck Hodge
Get the module and submodule declartionas correct.
6
 * @module bugs
7
 * @submodule bugtask_index
8231.2.7 by Abel Deuring
lint removed from the new JS file
8
 */
9
10985.3.13 by Deryck Hodge
Move bugtask_index into Y.lp.bugs namespace.
10
YUI.add('lp.bugs.bugtask_index', function(Y) {
8137.17.24 by Barry Warsaw
thread merge
11
10985.3.13 by Deryck Hodge
Move bugtask_index into Y.lp.bugs namespace.
12
var namespace = Y.namespace('lp.bugs.bugtask_index');
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
13
8242.2.42 by Deryck Hodge
Add better, more consistent comments.
14
// lazr.FormOverlay objects.
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
15
var duplicate_form_overlay;
16
var privacy_form_overlay;
17
8242.2.42 by Deryck Hodge
Add better, more consistent comments.
18
// The url of the page used to update bug duplicates.
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
19
var update_dupe_url;
20
8242.2.42 by Deryck Hodge
Add better, more consistent comments.
21
// The launchpad js client used.
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
22
var lp_client;
23
8242.2.42 by Deryck Hodge
Add better, more consistent comments.
24
// The launchpad client entry for the current bug.
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
25
var lp_bug_entry;
8242.2.32 by Deryck Hodge
A few additonal comments.
26
8242.2.42 by Deryck Hodge
Add better, more consistent comments.
27
// The bug itself, taken from cache.
8242.2.29 by Deryck Hodge
Move the code for handling subscribers into the same module
28
var bug_repr;
8242.2.42 by Deryck Hodge
Add better, more consistent comments.
29
30
// Overlay related vars.
8242.2.29 by Deryck Hodge
Move the code for handling subscribers into the same module
31
var error_overlay;
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
32
var submit_button_html =
8231.2.7 by Abel Deuring
lint removed from the new JS file
33
    '<button type="submit" name="field.actions.change" ' +
34
    'value="Change" class="lazr-pos lazr-btn" >OK</button>';
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
35
var cancel_button_html =
8231.2.7 by Abel Deuring
lint removed from the new JS file
36
    '<button type="button" name="field.actions.cancel" ' +
37
    'class="lazr-neg lazr-btn" >Cancel</button>';
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
38
var privacy_link;
8294.4.1 by Abel Deuring
fix for bug 367615: Spinner for privacy widget in the wrong place
39
var privacy_spinner;
8971.30.2 by Graham Binns
Added pretty animations for linking a branch.
40
var link_branch_link;
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
41
10985.3.13 by Deryck Hodge
Move bugtask_index into Y.lp.bugs namespace.
42
namespace.setup_bugtask_index = function() {
8137.17.24 by Barry Warsaw
thread merge
43
    /*
12183.10.7 by Huw Wilkins
Moved privacy notification javascript to appropriate file. Fixed the notification so it now appears or hides when the bug is made private/public.
44
     * Display the privacy notification if the bug is private
45
     */
46
    if (bug_private) {
47
        Y.on("domready", function () {
13458.2.1 by j.c.sackett
Moved privacy notification code into its own file.
48
            Y.lp.app.privacy.display_privacy_notification();
12183.10.7 by Huw Wilkins
Moved privacy notification javascript to appropriate file. Fixed the notification so it now appears or hides when the bug is made private/public.
49
        });
50
    }
12641.6.18 by Ian Booth
Use javascript validation for assignment to non contributor
51
12183.10.7 by Huw Wilkins
Moved privacy notification javascript to appropriate file. Fixed the notification so it now appears or hides when the bug is made private/public.
52
    /*
8137.17.24 by Barry Warsaw
thread merge
53
     * Check the page for links related to overlay forms and request the HTML
54
     * for these forms.
55
     */
8242.2.29 by Deryck Hodge
Move the code for handling subscribers into the same module
56
    Y.on('load', function() {
8255.14.13 by Edwin Grubbs
Fixed merge mistake.
57
        if (Y.UA.ie) {
8255.14.23 by Edwin Grubbs
Merged in RF.
58
            return;
8255.14.13 by Edwin Grubbs
Fixed merge mistake.
59
        }
8137.17.24 by Barry Warsaw
thread merge
60
        // If the user is not logged in, then we need to defer to the
61
        // default behaviour.
12442.1.2 by Tim Penhey
Rename LP.client.links to LP.links.
62
        if (LP.links.me === undefined) {
8137.17.24 by Barry Warsaw
thread merge
63
            return;
64
        }
65
8971.30.18 by Graham Binns
Move the check for client and bug into setup_client_and_bug.
66
        setup_client_and_bug();
8137.17.24 by Barry Warsaw
thread merge
67
9778.1.20 by Maris Fogels
Fixed setup of the 'Change duplicate status' popup (Y.all() changed signature).
68
        // Look for the 'Mark as duplicate' links or the
69
        // 'change duplicate bug' link.
70
        var update_dupe_link = Y.one(
71
            '.menu-link-mark-dupe, #change_duplicate_bug');
72
73
        if (update_dupe_link) {
8137.17.24 by Barry Warsaw
thread merge
74
            // First things first, pre-load the mark-dupe form.
9778.1.20 by Maris Fogels
Fixed setup of the 'Change duplicate status' popup (Y.all() changed signature).
75
            update_dupe_url = update_dupe_link.get('href');
8137.17.24 by Barry Warsaw
thread merge
76
            var mark_dupe_form_url = update_dupe_url + '/++form++';
9087.3.1 by Bjorn Tillenius
Use loadFormContent in bugtask-index.js.
77
12221.8.2 by Brad Crittenden
Fixed lint
78
            var form_header = '<p>Marking this bug as a duplicate will,' +
79
                              ' by default, hide it from search results ' +
80
                              'listings.</p>';
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
81
82
            var has_dupes = Y.one('#portlet-duplicates');
83
            if (has_dupes !== null) {
84
                form_header = form_header +
85
                    '<p style="padding:2px 2px 0 36px;" ' +
86
                    'class="large-warning"><strong>Note:</strong> ' +
87
                    'This bug has duplicates of its own. ' +
88
                    'If you go ahead, they too will become duplicates of ' +
89
                    'the bug you specify here.  This cannot be undone.' +
90
                    '</p></div>';
91
            }
92
9087.3.1 by Bjorn Tillenius
Use loadFormContent in bugtask-index.js.
93
            duplicate_form_overlay = new Y.lazr.FormOverlay({
94
                headerContent: '<h2>Mark bug report as duplicate</h2>',
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
95
                form_header: form_header,
9087.3.1 by Bjorn Tillenius
Use loadFormContent in bugtask-index.js.
96
                form_submit_button: Y.Node.create(submit_button_html),
97
                form_cancel_button: Y.Node.create(cancel_button_html),
98
                centered: true,
99
                form_submit_callback: update_bug_duplicate,
100
                visible: false
101
            });
102
            duplicate_form_overlay.render('#duplicate-form-container');
9087.3.2 by Bjorn Tillenius
The loadFormContent method was renamed.
103
            duplicate_form_overlay.loadFormContentAndRender(
104
                mark_dupe_form_url);
8137.17.24 by Barry Warsaw
thread merge
105
106
            // Add an on-click handler to any links found that displays
107
            // the form overlay.
9778.1.34 by Maris Fogels
JS style fix
108
            update_dupe_link.on('click', function(e) {
8137.17.24 by Barry Warsaw
thread merge
109
                // Only go ahead if we have received the form content by the
110
                // time the user clicks:
111
                if (duplicate_form_overlay){
112
                    e.preventDefault();
113
                    duplicate_form_overlay.show();
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
114
                    Y.DOM.byId('field.duplicateof').focus();
8137.17.24 by Barry Warsaw
thread merge
115
                }
116
            });
117
            // Add a class denoting them as js-action links.
9778.1.20 by Maris Fogels
Fixed setup of the 'Change duplicate status' popup (Y.all() changed signature).
118
            update_dupe_link.addClass('js-action');
8137.17.24 by Barry Warsaw
thread merge
119
        }
120
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
121
        privacy_link = Y.one('#privacy-link');
8137.17.24 by Barry Warsaw
thread merge
122
123
        if (privacy_link) {
12221.8.2 by Brad Crittenden
Fixed lint
124
            var privacy_link_url = privacy_link.getAttribute('href') +
125
              '/++form++';
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
126
            var privacy_div = Y.one('#privacy-text');
8294.4.1 by Abel Deuring
fix for bug 367615: Spinner for privacy widget in the wrong place
127
            var privacy_html = privacy_link.get('innerHTML') + ' ';
128
            privacy_div.set('innerHTML', privacy_html);
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
129
            var privacy_text = Y.one('#privacy-text');
8137.17.24 by Barry Warsaw
thread merge
130
            privacy_link = Y.Node.create(
8777.7.2 by Gavin Panella
Use node.set for the privacy link html fragment.
131
                '<a id="privacy-link" class="sprite edit" title="[edit]">' +
10123.5.14 by Deryck Hodge
Fix missing icon for edit privacy widget on bug pages
132
                '<span class="invisible-link">edit</span>&nbsp;</a>');
8777.7.2 by Gavin Panella
Use node.set for the privacy link html fragment.
133
            privacy_link.set('href', privacy_link_url);
8294.4.1 by Abel Deuring
fix for bug 367615: Spinner for privacy widget in the wrong place
134
            privacy_text.appendChild(privacy_link);
135
            privacy_spinner = Y.Node.create(
136
                '<img src="/@@/spinner" style="display: none" />');
137
            privacy_text.appendChild(privacy_spinner);
9087.3.1 by Bjorn Tillenius
Use loadFormContent in bugtask-index.js.
138
139
140
            privacy_form_overlay = new Y.lazr.FormOverlay({
141
                headerContent: '<h2>Change privacy settings</h2>',
142
                form_submit_button: Y.Node.create(submit_button_html),
143
                form_cancel_button: Y.Node.create(cancel_button_html),
144
                centered: true,
145
                form_submit_callback: update_privacy_settings,
146
                visible: false
147
            });
148
            privacy_form_overlay.render('#privacy-form-container');
9087.3.2 by Bjorn Tillenius
The loadFormContent method was renamed.
149
            privacy_form_overlay.loadFormContentAndRender(privacy_link_url);
8137.17.24 by Barry Warsaw
thread merge
150
            privacy_link.on('click', function(e) {
151
                if (privacy_form_overlay) {
152
                    e.preventDefault();
153
                    privacy_form_overlay.show();
154
                    // XXX Abel Deuring 2009-04-23, bug 365462
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
155
                    // Y.one('#field.private') returns null.
8137.17.24 by Barry Warsaw
thread merge
156
                    // Seems that YUI does not like IDs containing a '.'
157
                    document.getElementById('field.private').focus();
158
                }
159
            });
160
            privacy_link.addClass('js-action');
161
        }
8486.20.15 by Deryck Hodge
Pass the comment value to the attachment form
162
        setup_add_attachment();
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
163
        setup_link_branch_picker();
8242.2.37 by Deryck Hodge
Fix a bug spotted in code review where the load
164
    }, window);
8294.4.1 by Abel Deuring
fix for bug 367615: Spinner for privacy widget in the wrong place
165
};
8137.17.24 by Barry Warsaw
thread merge
166
9558.6.15 by Aaron Bentley
Reduce code duplication.
167
8137.17.24 by Barry Warsaw
thread merge
168
/*
8242.2.37 by Deryck Hodge
Fix a bug spotted in code review where the load
169
 * Create the lp client and bug entry if we haven't done so already.
170
 *
171
 * @method setup_client_and_bug
172
 */
173
function setup_client_and_bug() {
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
174
    lp_client = new Y.lp.client.Launchpad();
8242.2.37 by Deryck Hodge
Fix a bug spotted in code review where the load
175
176
    if (bug_repr === undefined) {
12442.1.1 by Tim Penhey
Rename LP.client.cache to LP.cache.
177
        bug_repr = LP.cache.bug;
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
178
        lp_bug_entry = new Y.lp.client.Entry(
8242.2.37 by Deryck Hodge
Fix a bug spotted in code review where the load
179
            lp_client, bug_repr, bug_repr.self_link);
180
    }
181
}
182
183
/*
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
184
 * Update the bug duplicate via the LP API
185
 */
186
function update_bug_duplicate(data) {
8242.2.30 by Deryck Hodge
The removeAtt call must now be before the first call
187
    // XXX noodles 2009-03-17 bug=336866 It seems the etag
188
    // returned by lp_save() is incorrect. Remove it for now
189
    // so that the second save does not result in a '412
190
    // precondition failed' error.
8242.2.36 by Deryck Hodge
Add a comment about bug #369293 and the new need
191
    //
192
    // XXX deryck 2009-04-29 bug=369293 Also, this has to
193
    // happen before *any* call to lp_save now that bug
194
    // subscribing can be done inline.  Named operations
195
    // don't return new objects, making the cached bug's
196
    // etag invalid as well.
9778.2.3 by Guilherme Salgado
Fix a few remaining calls to removeAtt (which has now been renamed to removeAttr)
197
    lp_bug_entry.removeAttr('http_etag');
8242.2.30 by Deryck Hodge
The removeAtt call must now be before the first call
198
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
199
    // Hide the formoverlay:
200
    duplicate_form_overlay.hide();
201
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
202
    // Hide the dupe edit icon if it exists.
203
    var dupe_edit_icon = Y.one('#change_duplicate_bug');
204
    if (dupe_edit_icon !== null) {
205
        dupe_edit_icon.setStyle('display', 'none');
206
    }
207
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
208
    // Add the spinner...
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
209
    var dupe_span = Y.one('#mark-duplicate-text');
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
210
    dupe_span.removeClass('sprite bug-dupe');
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
211
    dupe_span.addClass('update-in-progress-message');
212
213
    // Set the new duplicate link on the bug entry.
214
    var new_dup_url = null;
10542.11.1 by Karl Fogel
Fix bug #481324 ("trailing whitespace in bug duplicate causes failure").
215
    var new_dup_id = Y.Lang.trim(data['field.duplicateof'][0]);
8804.1.2 by Deryck Hodge
It's better to unpack the array than to cast.
216
    if (new_dup_id !== '') {
8231.2.7 by Abel Deuring
lint removed from the new JS file
217
        var self_link = lp_bug_entry.get('self_link');
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
218
        var last_slash_index = self_link.lastIndexOf('/');
219
        new_dup_url = self_link.slice(0, last_slash_index+1) + new_dup_id;
220
    }
221
    var old_dup_url = lp_bug_entry.get('duplicate_of_link');
222
    lp_bug_entry.set('duplicate_of_link', new_dup_url);
223
224
    // Create a config for the lp_save method
225
    config = {
226
        on: {
227
            success: function(updated_entry) {
228
                dupe_span.removeClass('update-in-progress-message');
229
                lp_bug_entry = updated_entry;
230
231
                if (new_dup_url !== null) {
232
                    dupe_span.set('innerHTML', [
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
233
                        '<a id="change_duplicate_bug" ',
234
                        'title="Edit or remove linked duplicate bug" ',
235
                        'class="sprite edit"></a>',
236
                        'Duplicate of <a>bug #</a>'].join(""));
9778.1.15 by Maris Fogels
Replaced deprecated Node.queryAll with Node.all().
237
                    dupe_span.all('a').item(0)
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
238
                        .set('href', update_dupe_url);
239
                    dupe_span.all('a').item(1)
8777.7.3 by Gavin Panella
Use node.set for the dupe link.
240
                        .set('href', '/bugs/' + new_dup_id)
241
                        .appendChild(document.createTextNode(new_dup_id));
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
242
                    var has_dupes = Y.one('#portlet-duplicates');
243
                    if (has_dupes !== null) {
244
                        has_dupes.get('parentNode').removeChild(has_dupes);
245
                    }
8283.4.1 by Abel Deuring
fix for bug 354810: The warning about adding a comment to a duplictae bug should be shown/hidden when a bug a marked/unmarked being the duplicate of another bug.
246
                    show_comment_on_duplicate_warning();
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
247
                } else {
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
248
                    dupe_span.addClass('sprite bug-dupe');
8777.7.4 by Gavin Panella
Use node.set for the dupe link, part 2.
249
                    dupe_span.set('innerHTML', [
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
250
                        '<a class="menu-link-mark-dupe js-action">',
251
                        'Mark as duplicate</a>'].join(""));
9778.1.16 by Maris Fogels
Renamed deprecated Node.query() to Node.one().
252
                    dupe_span.one('a').set('href', update_dupe_url);
8283.4.1 by Abel Deuring
fix for bug 354810: The warning about adding a comment to a duplictae bug should be shown/hidden when a bug a marked/unmarked being the duplicate of another bug.
253
                    hide_comment_on_duplicate_warning();
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
254
                }
255
                Y.lazr.anim.green_flash({node: dupe_span}).run();
256
                // ensure the new link is hooked up correctly:
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
257
                dupe_span.one('a').on(
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
258
                    'click', function(e){
259
                        e.preventDefault();
260
                        duplicate_form_overlay.show();
11272.1.2 by Deryck Hodge
Second pass, which gets the UI component for my dupe work.
261
                        Y.DOM.byId('field.duplicateof').focus();
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
262
                    });
263
            },
264
            failure: function(id, request) {
265
                dupe_span.removeClass('update-in-progress-message');
12556.10.2 by Benji York
more lint
266
                if (request.status === 400) {
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
267
                    duplicate_form_overlay.showError(
268
                        new_dup_id + ' is not a valid bug number or' +
269
                        ' nickname.');
270
                } else {
271
                    duplicate_form_overlay.showError(request.responseText);
272
                }
273
                duplicate_form_overlay.show();
274
275
                // Reset the lp_bug_entry.duplicate_of_link as it wasn't
276
                // updated.
277
                lp_bug_entry.set('duplicate_of_link', old_dup_url);
278
279
            }
280
        }
281
    };
282
283
    // And save the updated entry.
284
    lp_bug_entry.lp_save(config);
285
}
286
8283.4.2 by Abel Deuring
implemented reviewer's comments
287
/*
288
 * Ensure that a warning about adding a comment to a duplicate bug
289
 * is displayed.
290
 *
291
 * @method show_comment_on_duplicate_warning
292
 */
8283.4.1 by Abel Deuring
fix for bug 354810: The warning about adding a comment to a duplictae bug should be shown/hidden when a bug a marked/unmarked being the duplicate of another bug.
293
var show_comment_on_duplicate_warning = function() {
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
294
    var duplicate_warning = Y.one('#warning-comment-on-duplicate');
8283.4.1 by Abel Deuring
fix for bug 354810: The warning about adding a comment to a duplictae bug should be shown/hidden when a bug a marked/unmarked being the duplicate of another bug.
295
    if (duplicate_warning === null) {
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
296
        var container = Y.one('#add-comment-form');
8283.4.1 by Abel Deuring
fix for bug 354810: The warning about adding a comment to a duplictae bug should be shown/hidden when a bug a marked/unmarked being the duplicate of another bug.
297
        var first_node = container.get('firstChild');
298
        duplicate_warning = Y.Node.create(
12221.8.2 by Brad Crittenden
Fixed lint
299
            ['<div class="warning message"',
300
             'id="warning-comment-on-duplicate">',
8283.4.1 by Abel Deuring
fix for bug 354810: The warning about adding a comment to a duplictae bug should be shown/hidden when a bug a marked/unmarked being the duplicate of another bug.
301
             'Remember, this bug report is a duplicate. ',
302
             'Comment here only if you think the duplicate status is wrong.',
303
             '</div>'].join(''));
304
        container.insertBefore(duplicate_warning, first_node);
305
    }
306
};
307
8283.4.2 by Abel Deuring
implemented reviewer's comments
308
/*
309
 * Ensure that no warning about adding a comment to a duplicate bug
310
 * is displayed.
311
 *
312
 * @method hide_comment_on_duplicate_warning
313
 */
8283.4.1 by Abel Deuring
fix for bug 354810: The warning about adding a comment to a duplictae bug should be shown/hidden when a bug a marked/unmarked being the duplicate of another bug.
314
var hide_comment_on_duplicate_warning = function() {
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
315
    var duplicate_warning = Y.one('#warning-comment-on-duplicate');
8283.4.1 by Abel Deuring
fix for bug 354810: The warning about adding a comment to a duplictae bug should be shown/hidden when a bug a marked/unmarked being the duplicate of another bug.
316
    if (duplicate_warning !== null) {
317
        duplicate_warning.ancestor().removeChild(duplicate_warning);
318
    }
319
};
320
321
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
322
var update_privacy_settings = function(data) {
8242.2.30 by Deryck Hodge
The removeAtt call must now be before the first call
323
    // XXX noodles 2009-03-17 bug=336866 It seems the etag
324
    // returned by lp_save() is incorrect. Remove it for now
325
    // so that the second save does not result in a '412
326
    // precondition failed' error.
8242.2.36 by Deryck Hodge
Add a comment about bug #369293 and the new need
327
    //
328
    // XXX deryck 2009-04-29 bug=369293 Also, this has to
329
    // happen before *any* call to lp_save now that bug
330
    // subscribing can be done inline.  Named operations
331
    // don't return new objects, making the cached bug's
332
    // etag invalid as well.
9778.2.3 by Guilherme Salgado
Fix a few remaining calls to removeAtt (which has now been renamed to removeAttr)
333
    lp_bug_entry.removeAttr('http_etag');
8242.2.30 by Deryck Hodge
The removeAtt call must now be before the first call
334
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
335
    privacy_form_overlay.hide();
336
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
337
    var privacy_text = Y.one('#privacy-text');
338
    var privacy_div = Y.one('#privacy');
8294.4.1 by Abel Deuring
fix for bug 367615: Spinner for privacy widget in the wrong place
339
    privacy_link.setStyle('display', 'none');
340
    privacy_spinner.setStyle('display', 'inline');
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
341
342
    if (lp_client === undefined) {
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
343
        lp_client = new Y.lp.client.Launchpad();
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
344
    }
345
346
    if (lp_bug_entry === undefined) {
12442.1.1 by Tim Penhey
Rename LP.client.cache to LP.cache.
347
        var bug_repr = LP.cache.bug;
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
348
        lp_bug_entry = new Y.lp.client.Entry(
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
349
            lp_client, bug_repr, bug_repr.self_link);
350
    }
351
12117.1.1 by Deryck Hodge
Change variable name "private" to "private_flag" to avoid using
352
    var private_flag = data['field.private'] !== undefined;
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
353
    var security_related =
354
        data['field.security_related'] !== undefined;
355
12117.1.1 by Deryck Hodge
Change variable name "private" to "private_flag" to avoid using
356
    lp_bug_entry.set('private', private_flag);
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
357
    lp_bug_entry.set('security_related', security_related);
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
358
    var error_handler = new Y.lp.client.ErrorHandler();
8486.14.5 by Bjorn Tillenius
Use ErrorHandler for the privacy overlay.
359
    error_handler.clearProgressUI = function () {
360
        privacy_spinner.setStyle('display', 'none');
361
        privacy_link.setStyle('display', 'inline');
362
    };
363
    error_handler.showError = function (error_msg) {
364
        Y.lazr.anim.red_flash({node: privacy_div}).run();
365
        privacy_form_overlay.showError(error_msg);
366
        privacy_form_overlay.show();
367
    };
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
368
369
    var config = {
370
        on: {
371
            success: function (updated_entry) {
8294.4.1 by Abel Deuring
fix for bug 367615: Spinner for privacy widget in the wrong place
372
                privacy_spinner.setStyle('display', 'none');
373
                privacy_link.setStyle('display', 'inline');
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
374
                lp_bug_entry = updated_entry;
375
12117.1.1 by Deryck Hodge
Change variable name "private" to "private_flag" to avoid using
376
                if (private_flag) {
10420.5.4 by Karl Fogel
For bug #471195 ("private bugs don't set body class to 'private'"),
377
                    Y.one('body').replaceClass('public', 'private');
378
                    privacy_div.replaceClass('public', 'private');
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
379
                    privacy_text.set(
380
                        'innerHTML',
381
                        'This report is <strong>private</strong> ');
13458.2.1 by j.c.sackett
Moved privacy notification code into its own file.
382
                    Y.lp.app.privacy.display_privacy_notification();
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
383
                } else {
13458.2.2 by j.c.sackett
Made the "bug_private_notifications" flag a more generic "privacy_notifications" flag.
384
                    if (privacy_notification_enabled) {
12556.10.5 by Benji York
freshen from devel, fixing conflict
385
                        var notification = Y.one('.global-notification');
386
                        if (notification.hasClass('hidden')) {
12556.10.2 by Benji York
more lint
387
                            Y.one('.portlet.private').setStyles({
388
                                color: '#333',
389
                                backgroundColor: '#fbfbfb'
390
                            });
12183.10.7 by Huw Wilkins
Moved privacy notification javascript to appropriate file. Fixed the notification so it now appears or hides when the bug is made private/public.
391
                        }
392
                    }
10420.5.4 by Karl Fogel
For bug #471195 ("private bugs don't set body class to 'private'"),
393
                    Y.one('body').replaceClass('private', 'public');
394
                    privacy_div.replaceClass('private', 'public');
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
395
                    privacy_text.set(
396
                        'innerHTML', 'This report is public ');
13458.2.1 by j.c.sackett
Moved privacy notification code into its own file.
397
                    Y.lp.app.privacy.hide_privacy_notification();
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
398
                }
399
                privacy_text.appendChild(privacy_link);
8294.4.1 by Abel Deuring
fix for bug 367615: Spinner for privacy widget in the wrong place
400
                privacy_text.appendChild(privacy_spinner);
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
401
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
402
                var security_message = Y.one('#security-message');
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
403
                if (security_related) {
404
                    if (security_message === null) {
405
                        var security_message_html = [
8231.2.7 by Abel Deuring
lint removed from the new JS file
406
                            '<div style="',
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
407
                            '    margin-top: 0.5em;',
408
                            '    padding-right: 18px;',
8231.2.7 by Abel Deuring
lint removed from the new JS file
409
                            '    center right no-repeat;"',
8490.3.9 by Martin Albisetti
Ba-bye @@/edit on bugtask-index
410
                            '    class="sprite security"',
8231.2.7 by Abel Deuring
lint removed from the new JS file
411
                            '    id="security-message"',
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
412
                            '>Security vulnerability</div>'
413
                        ].join('');
12221.8.2 by Brad Crittenden
Fixed lint
414
                        security_message = Y.Node.create(
415
                           security_message_html);
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
416
                        privacy_div.appendChild(security_message);
417
                    }
418
                } else {
419
                    if (security_message !== null) {
420
                        privacy_div.removeChild(security_message);
421
                    }
422
                }
423
                Y.lazr.anim.green_flash({node: privacy_div}).run();
424
            },
8486.14.5 by Bjorn Tillenius
Use ErrorHandler for the privacy overlay.
425
            failure: error_handler.getFailureHandler()
8231.2.6 by Abel Deuring
Moved Javascript code from bugtask-index.pt into a separate file.
426
        }
427
    };
428
    lp_bug_entry.lp_save(config);
429
};
430
13546.1.1 by Benji York
Add a bit of code to do a pre-emptive search for the current bug ID when the user clicks "Link a related branch".
431
432
/**
433
 * Do a preemptive search for branches that contain the current bug's ID.
434
 */
435
function do_pre_search(picker, bug_id) {
436
    if (!Y.Lang.isValue(bug_id)) {
437
        bug_id = LP.cache.bug.id;
438
    }
439
    picker.set('footer_slot', 'Loading suggestions...');
440
    // A very few bugs have small IDs.
441
    var original_min_search_chars = picker.get('min_search_chars');
442
    picker.set('min_search_chars', 0);
443
    picker.fire('search', bug_id.toString());
444
    // Don't disable the search input box or the search button while
445
    // doing our search.
446
    picker.set('search_mode', false);
447
    picker.set('min_search_chars', original_min_search_chars);
448
}
449
// Expose to the namespace for testing.
450
namespace._do_pre_search = do_pre_search;
451
452
8971.30.4 by Graham Binns
Cleaned up some more cruft.
453
/**
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
454
 * Set up the link-a-related-branch picker.
8971.30.1 by Graham Binns
Linking a branch through the overlay now works on an API level.
455
 */
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
456
function setup_link_branch_picker() {
8971.30.18 by Graham Binns
Move the check for client and bug into setup_client_and_bug.
457
    setup_client_and_bug();
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
458
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
459
    var error_handler = new Y.lp.client.ErrorHandler();
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
460
461
    error_handler.clearProgressUI = function () {
462
        link_branch_link.toggleClass('update-in-progress-message');
463
    };
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
464
    error_handler.showError = function(error_msg) {
12221.8.2 by Brad Crittenden
Fixed lint
465
        Y.lp.app.errors.display_error(
466
           Y.one('.menu-link-addbranch'), error_msg);
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
467
    };
468
469
    function get_branch_and_link_to_bug(data) {
9808.1.1 by Deryck Hodge
Lint and whitespace clean up on bugtask-index.js.
470
        var branch_url = data.api_uri;
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
471
        config = {
472
            on: {
473
                success: link_branch_to_bug,
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
474
                failure: error_handler.getFailureHandler()
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
475
            }
476
        };
477
478
        // Start the spinner and then grab the branch.
479
        link_branch_link.toggleClass('update-in-progress-message');
480
        lp_client.get(branch_url, config);
481
    }
482
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
483
    // Set up the picker itself.
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
484
    link_branch_link = Y.one('.menu-link-addbranch');
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
485
    if (Y.Lang.isValue(link_branch_link)) {
486
        var config = {
487
            header: 'Link a related branch',
9778.3.7 by Guilherme Salgado
Get rid of some now-redundant js code for hooking up an anchor to picker.show().
488
            step_title: 'Search',
489
            picker_activator: '.menu-link-addbranch'
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
490
        };
491
10180.4.2 by Guilherme Salgado
A few improvements suggested by Maris
492
        config.save = get_branch_and_link_to_bug;
11090.5.9 by Tim Penhey
Last of the renames.
493
        var picker = Y.lp.app.picker.create('Branch', config);
13546.1.1 by Benji York
Add a bit of code to do a pre-emptive search for the current bug ID when the user clicks "Link a related branch".
494
        // When the user clicks on "Link a related branch" do a search for
495
        // branches that contain the bug number.
496
        link_branch_link.subscribe('click', function (e) {
497
            do_pre_search(picker);
498
        });
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
499
    }
500
}
501
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
502
/**
503
 * Link a branch to the current bug.
504
 * @param branch {Object} The branch to link to the bug, as returned by
505
 *                        the Launchpad API.
506
 */
8971.30.9 by Graham Binns
Changed linking to a branch functionality to use a picker rather than a hand-hacked overlay.
507
function link_branch_to_bug(branch) {
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
508
    var error_handler = new Y.lp.client.ErrorHandler();
8971.30.2 by Graham Binns
Added pretty animations for linking a branch.
509
    error_handler.clearProgressUI = function () {
8971.30.3 by Graham Binns
It's now possible to link a branch to a bug using an overlay.
510
        link_branch_link.toggleClass('update-in-progress-message');
8971.30.2 by Graham Binns
Added pretty animations for linking a branch.
511
    };
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
512
    error_handler.showError = function(error_msg) {
12221.8.2 by Brad Crittenden
Fixed lint
513
        Y.lp.app.errors.display_error(
514
           Y.one('.menu-link-addbranch'), error_msg);
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
515
    };
516
8971.30.17 by Graham Binns
Don't change the 'Link a branch' link after a branch is linked.
517
    // Call linkBranch() on the bug.
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
518
    config = {
519
        on: {
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
520
            success: function(bug_branch_entry) {
8971.30.16 by Graham Binns
Don't flash the 'Link a branch' link green on success.
521
                link_branch_link.toggleClass(
522
                    'update-in-progress-message');
8971.31.5 by Graham Binns
Added some comments. Because Javascript is as clear as the primordial ooze.
523
524
                // Grab the XHTML representation of the branch and add
525
                // it to the list of branches.
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
526
                config = {
527
                    on: {
528
                        success: function(branch_html) {
529
                            add_branch_to_linked_branches(branch_html);
530
                        }
531
                    },
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
532
                    accept: Y.lp.client.XHTML
9808.1.1 by Deryck Hodge
Lint and whitespace clean up on bugtask-index.js.
533
                };
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
534
                lp_client.get(bug_branch_entry.get('self_link'), config);
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
535
            },
9808.1.1 by Deryck Hodge
Lint and whitespace clean up on bugtask-index.js.
536
            failure: error_handler.getFailureHandler()
8971.30.10 by Graham Binns
Trimmed out cruft and added error-handling code.
537
        },
538
        parameters: {
539
            branch: branch.get('self_link')
540
        }
541
    };
542
    lp_client.named_post(
543
        lp_bug_entry.get('self_link'), 'linkBranch', config);
8971.30.1 by Graham Binns
Linking a branch through the overlay now works on an API level.
544
}
545
8971.31.1 by Graham Binns
The branch list will now be updated when a new branch is linked.
546
/**
547
 * Add a branch to the list of linked branches.
548
 *
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
549
 * @param branch_html {Object} The branch html to add to the list of
550
 *                    linked branches, as returned by the Launchpad API.
8971.31.1 by Graham Binns
The branch list will now be updated when a new branch is linked.
551
 */
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
552
function add_branch_to_linked_branches(branch_html) {
9808.1.1 by Deryck Hodge
Lint and whitespace clean up on bugtask-index.js.
553
    var anim;
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
554
    var bug_branch_node = Y.Node.create(branch_html);
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
555
    var bug_branch_list = Y.one('#bug-branches');
8971.31.1 by Graham Binns
The branch list will now be updated when a new branch is linked.
556
    if (!Y.Lang.isValue(bug_branch_list)) {
557
        bug_branch_list = Y.Node.create(
558
            '<div id="bug-branches">' +
8971.31.4 by Graham Binns
BugBranches are now added to the linked branches list as they're linked.
559
            '  <h2>Related branches</h2>' +
8971.31.1 by Graham Binns
The branch list will now be updated when a new branch is linked.
560
            '</div>');
561
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
562
        var bug_branch_container = Y.one('#bug-branches-container');
8971.31.1 by Graham Binns
The branch list will now be updated when a new branch is linked.
563
        bug_branch_container.appendChild(bug_branch_list);
9808.1.1 by Deryck Hodge
Lint and whitespace clean up on bugtask-index.js.
564
        anim = Y.lazr.anim.green_flash({node: bug_branch_list});
8971.31.1 by Graham Binns
The branch list will now be updated when a new branch is linked.
565
    } else {
9808.1.1 by Deryck Hodge
Lint and whitespace clean up on bugtask-index.js.
566
        anim = Y.lazr.anim.green_flash({node: bug_branch_node});
8971.31.1 by Graham Binns
The branch list will now be updated when a new branch is linked.
567
    }
568
9778.1.16 by Maris Fogels
Renamed deprecated Node.query() to Node.one().
569
    var existing_bug_branch_node = bug_branch_list.one(
8971.31.10 by Graham Binns
Fixed the issue with branches showing up twice if duplicated.
570
        '#' + bug_branch_node.getAttribute('id'));
8971.31.7 by Graham Binns
Fiddling to stop existing bug branches from begin re-added to the page
571
    if (!Y.Lang.isValue(existing_bug_branch_node)) {
572
        // Only add the bug branch to the page if it isn't there
573
        // already.
574
        bug_branch_list.appendChild(bug_branch_node);
575
    } else {
576
        // If the bug branch exists already, flash it.
9808.1.1 by Deryck Hodge
Lint and whitespace clean up on bugtask-index.js.
577
        anim = Y.lazr.anim.green_flash({node: existing_bug_branch_node});
8971.31.7 by Graham Binns
Fiddling to stop existing bug branches from begin re-added to the page
578
    }
8971.31.1 by Graham Binns
The branch list will now be updated when a new branch is linked.
579
    anim.run();
9691.7.30 by Tim Penhey
Use YUI custom events to tie the new bug-branch linked to the bit that registers the on click handler for the popup diffs, so a newly linked branch can show a popup diff if there is one.
580
    // Fire of the generic branch linked event.
581
    Y.fire('lp:branch-linked', bug_branch_node);
8971.31.1 by Graham Binns
The branch list will now be updated when a new branch is linked.
582
}
583
13445.1.8 by Gary Poster
JavaScript for bug page: if we increase the affected count to 2 or more, maybe update the statuses of NEW bugtasks
584
var status_choice_data = [];
585
586
var update_maybe_confirmed_status = function() {
587
    // This would be better done via client-side MVC for the pertinent
588
    // bugtasks, but we don't have that yet.
589
    Y.Array.each(
590
        status_choice_data,
591
        function(rowdata) {
592
            if (rowdata.widget.get('value') === 'New') {
593
                lp_client.get(
594
                    rowdata.config.bugtask_path,
595
                    // We will silently fail.
596
                    // This is not critical functionality.
597
                    {on: {success: function(bugtask) {
598
                        var status = bugtask.get('status');
599
                        if (status !== rowdata.widget.get('value')) {
600
                            rowdata.widget.set('value', status);
601
                            rowdata.widget.fire('save');
13445.1.10 by Gary Poster
lint and related cleanups
602
                        }
13445.1.8 by Gary Poster
JavaScript for bug page: if we increase the affected count to 2 or more, maybe update the statuses of NEW bugtasks
603
                    }}});
13445.1.10 by Gary Poster
lint and related cleanups
604
            }
13445.1.8 by Gary Poster
JavaScript for bug page: if we increase the affected count to 2 or more, maybe update the statuses of NEW bugtasks
605
        }
606
    );
13445.1.10 by Gary Poster
lint and related cleanups
607
};
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
608
8230.3.19 by Tom Berger
move the js code into the bugtask-index module
609
/**
610
 * Set up a bug task table row.
611
 *
13445.1.8 by Gary Poster
JavaScript for bug page: if we increase the affected count to 2 or more, maybe update the statuses of NEW bugtasks
612
 * Called once per row, on load, to initialize the page.
8230.3.19 by Tom Berger
move the js code into the bugtask-index module
613
 *
614
 * @method setup_bugtasks_row
615
 */
10985.3.13 by Deryck Hodge
Move bugtask_index into Y.lp.bugs namespace.
616
namespace.setup_bugtask_row = function(conf) {
8836.6.1 by Bjorn Tillenius
Enable status and importance editing for Opera. lazr-js has been fixed to make it work.
617
    if (Y.UA.ie) {
8787.5.3 by Tom Berger
disable ajax in IE and Opera
618
        return;
619
    }
620
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
621
    var tr = Y.one('#' + conf.row_id);
622
    var bugtarget_content = Y.one('#bugtarget-picker-' + conf.row_id);
9778.1.16 by Maris Fogels
Renamed deprecated Node.query() to Node.one().
623
    var status_content = tr.one('.status-content');
624
    var importance_content = tr.one('.importance-content');
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
625
    var assignee_content = Y.one('#assignee-picker-' + conf.row_id);
9778.1.16 by Maris Fogels
Renamed deprecated Node.query() to Node.one().
626
    var milestone_content = tr.one('.milestone-content');
8922.1.1 by Tom Berger
do not show bug task edit widgets for dupes
627
9778.1.18 by Maris Fogels
Fixed a bug where bug status rows without status cells would throw an error.
628
    if (status_content === null) {
629
        // Not all table rows have status widgets.  If this is one of those
630
        // rows, then bail.
631
        return;
632
    }
633
12442.1.1 by Tim Penhey
Rename LP.client.cache to LP.cache.
634
    if (Y.Lang.isValue(LP.cache.bug) &&
635
        Y.Lang.isValue(LP.cache.bug.duplicate_of_link)) {
9141.3.1 by Tom Berger
dont try to inspect the client cache if the user is anonymous. the client cache does not exist and it create a js error.
636
        // If the bug is a duplicate, don't set the widget up and
637
        // canel clicks on the edit links. Users most likely don't
638
        // want to edit the bugtasks.
8963.7.5 by Deryck Hodge
Clean up lint.
639
        status_content.on('click', function(e) { e.halt(); });
640
        importance_content.on('click', function(e) { e.halt(); });
8922.1.1 by Tom Berger
do not show bug task edit widgets for dupes
641
        return;
642
    }
643
12442.1.2 by Tim Penhey
Rename LP.client.links to LP.links.
644
    if ((LP.links.me !== undefined) &&
645
        (LP.links.me !== null))  {
9087.5.1 by Tom Berger
interim commit so that i can pull in the latest trunk
646
        if (Y.Lang.isValue(bugtarget_content)) {
647
            if (conf.target_is_product) {
12221.9.29 by Tim Penhey
Re-enable webkit browsers to use the js picker.
648
              var bugtarget_picker = Y.lp.app.picker.addPickerPatcher(
9550.6.2 by Tom Berger
make product and assignee pickers go to the boomerang form in webkit-based browsers
649
                        'Product',
650
                        conf.bugtask_path,
651
                        "target_link",
652
                        bugtarget_content.get('id'),
13171.2.1 by William Grant
Stop talking about products in the bugtask project picker.
653
                        {"step_title": "Search projects",
654
                         "header": "Change project"});
9087.5.1 by Tom Berger
interim commit so that i can pull in the latest trunk
655
            }
656
        }
657
9141.2.1 by Tom Berger
dont create ajax edit widgets for status and importance if a bugtask is controlled by a bugwatch.
658
        if (conf.user_can_edit_status) {
10604.1.1 by Abel Deuring
Reverted the changes from r10577, see bug # 549323
659
            var status_choice_edit = new Y.ChoiceSource({
9141.2.1 by Tom Berger
dont create ajax edit widgets for status and importance if a bugtask is controlled by a bugwatch.
660
                contentBox: status_content,
661
                value: conf.status_value,
662
                title: 'Change status to',
663
                items: conf.status_widget_items,
664
                elementToFlash: status_content.get('parentNode'),
12221.8.2 by Brad Crittenden
Fixed lint
665
                backgroundColor:
666
                    tr.hasClass('highlight') ? '#FFFF99' : '#FFFFFF'
9141.2.1 by Tom Berger
dont create ajax edit widgets for status and importance if a bugtask is controlled by a bugwatch.
667
            });
668
            status_choice_edit.showError = function(err) {
11090.5.8 by Tim Penhey
Fix some more namespace issues.
669
              Y.lp.app.errors.display_error(null, err);
9141.2.1 by Tom Berger
dont create ajax edit widgets for status and importance if a bugtask is controlled by a bugwatch.
670
            };
671
            status_choice_edit.on('save', function(e) {
672
                var cb = status_choice_edit.get('contentBox');
673
                Y.Array.each(conf.status_widget_items, function(item) {
12556.10.2 by Benji York
more lint
674
                    if (item.value === status_choice_edit.get('value')) {
9141.2.1 by Tom Berger
dont create ajax edit widgets for status and importance if a bugtask is controlled by a bugwatch.
675
                        cb.addClass(item.css_class);
676
                    } else {
677
                        cb.removeClass(item.css_class);
678
                    }
679
                });
680
                // Set the inline form control's value, so that submitting
681
                // it won't override the value we just set.
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
682
                Y.one(document.getElementById(conf.prefix + '.status')).set(
9141.2.1 by Tom Berger
dont create ajax edit widgets for status and importance if a bugtask is controlled by a bugwatch.
683
                    'value', status_choice_edit.get('value'));
684
            });
685
            status_choice_edit.plug({
686
                fn: Y.lp.client.plugins.PATCHPlugin, cfg: {
687
                        patch: 'status',
688
                        resource: conf.bugtask_path}});
689
            status_choice_edit.render();
13445.1.8 by Gary Poster
JavaScript for bug page: if we increase the affected count to 2 or more, maybe update the statuses of NEW bugtasks
690
            status_choice_data.push(
691
                {widget: status_choice_edit, config: conf});
9141.2.1 by Tom Berger
dont create ajax edit widgets for status and importance if a bugtask is controlled by a bugwatch.
692
        }
8935.1.1 by Tom Berger
Set the controls of the inline bugtask form when setting status and importance. Also produce the initialization values for the bugtask row in a saner way, using simplejson from the view code.
693
        if (conf.user_can_edit_importance) {
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
694
            var importance_choice_edit = new Y.ChoiceSource({
695
                contentBox: importance_content,
8935.1.1 by Tom Berger
Set the controls of the inline bugtask form when setting status and importance. Also produce the initialization values for the bugtask row in a saner way, using simplejson from the view code.
696
                value: conf.importance_value,
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
697
                title: 'Change importance to',
8935.1.1 by Tom Berger
Set the controls of the inline bugtask form when setting status and importance. Also produce the initialization values for the bugtask row in a saner way, using simplejson from the view code.
698
                items: conf.importance_widget_items,
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
699
                elementToFlash: importance_content.get('parentNode'),
12221.8.2 by Brad Crittenden
Fixed lint
700
                backgroundColor:
701
                    tr.hasClass('highlight') ? '#FFFF99' : '#FFFFFF'
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
702
            });
703
            importance_choice_edit.showError = function(err) {
11090.5.8 by Tim Penhey
Fix some more namespace issues.
704
              Y.lp.app.errors.display_error(null, err);
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
705
            };
706
            importance_choice_edit.on('save', function(e) {
707
                var cb = importance_choice_edit.get('contentBox');
8935.1.1 by Tom Berger
Set the controls of the inline bugtask form when setting status and importance. Also produce the initialization values for the bugtask row in a saner way, using simplejson from the view code.
708
                Y.Array.each(conf.importance_widget_items, function(item) {
12556.10.2 by Benji York
more lint
709
                    if (item.value === importance_choice_edit.get('value')) {
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
710
                        cb.addClass(item.css_class);
711
                    } else {
712
                        cb.removeClass(item.css_class);
713
                    }
714
                });
8935.1.1 by Tom Berger
Set the controls of the inline bugtask form when setting status and importance. Also produce the initialization values for the bugtask row in a saner way, using simplejson from the view code.
715
                // Set the inline form control's value, so that submitting
716
                // it won't override the value we just set.
12221.8.2 by Brad Crittenden
Fixed lint
717
                Y.one(document.getElementById(
718
                    conf.prefix + '.importance')).set(
719
                        'value', importance_choice_edit.get('value'));
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
720
            });
721
            importance_choice_edit.plug({
722
                fn: Y.lp.client.plugins.PATCHPlugin, cfg: {
723
                        patch: 'importance',
8935.1.1 by Tom Berger
Set the controls of the inline bugtask form when setting status and importance. Also produce the initialization values for the bugtask row in a saner way, using simplejson from the view code.
724
                        resource: conf.bugtask_path}});
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
725
            importance_choice_edit.render();
726
        }
727
    }
8877.3.2 by Tom Berger
merge changes from rocketfuel, resolve conflicts and bring up-to-date
728
9141.6.1 by Tom Berger
dont allow users who shouldnt edit milestone edit it using the ajax control
729
    if (Y.Lang.isValue(milestone_content) && conf.user_can_edit_milestone) {
8877.3.14 by Tom Berger
remove the roll-overs and guard against elements that dont exist
730
        var milestone_choice_edit = new Y.NullChoiceSource({
731
            contentBox: milestone_content,
732
            value: conf.milestone_value,
733
            title: 'Target to milestone',
734
            items: conf.milestone_widget_items,
735
            elementToFlash: milestone_content.get('parentNode'),
9189.4.1 by Tom Berger
make the milestone link go to the milestone, rather than pop up the overlay
736
            backgroundColor: tr.hasClass('highlight') ? '#FFFF99' : '#FFFFFF',
737
            clickable_content: false
8877.3.14 by Tom Berger
remove the roll-overs and guard against elements that dont exist
738
        });
739
        milestone_choice_edit.showError = function(err) {
11090.5.8 by Tim Penhey
Fix some more namespace issues.
740
            Y.lp.app.errors.display_error(null, err);
8877.3.14 by Tom Berger
remove the roll-overs and guard against elements that dont exist
741
        };
742
        milestone_choice_edit.plug({
743
            fn: Y.lp.client.plugins.PATCHPlugin, cfg: {
744
                    patch: 'milestone_link',
745
                    resource: conf.bugtask_path}});
746
        milestone_choice_edit.after('save', function() {
9189.4.1 by Tom Berger
make the milestone link go to the milestone, rather than pop up the overlay
747
            var new_value = milestone_choice_edit.get('value');
748
            if (Y.Lang.isValue(new_value)) {
9189.4.4 by Tom Berger
xxxify
749
                // XXX Tom Berger 2009-08-25 Bug #316694:
9189.4.1 by Tom Berger
make the milestone link go to the milestone, rather than pop up the overlay
750
                // This is a slightly nasty hack that saves us from the need
751
                // to have a more established way of getting the web URL of
752
                // an API object. Once such a solution is available we should
753
                // fix this.
9778.1.16 by Maris Fogels
Renamed deprecated Node.query() to Node.one().
754
                milestone_content.one('.value').setAttribute(
10304.5.7 by Leonard Richardson
Start using the /api/devel web service instead of the /api/beta web service.
755
                    'href', new_value.replace('/api/devel', ''));
9189.4.1 by Tom Berger
make the milestone link go to the milestone, rather than pop up the overlay
756
            }
8877.3.14 by Tom Berger
remove the roll-overs and guard against elements that dont exist
757
            // Set the inline form control's value, so that submitting
758
            // it won't override the value we just set.
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
759
            var inline_combo = Y.one(
8877.3.14 by Tom Berger
remove the roll-overs and guard against elements that dont exist
760
                document.getElementById(conf.prefix + '.milestone'));
761
            if (Y.Lang.isValue(inline_combo)) {
762
            inline_combo.set('value', null);
12221.8.2 by Brad Crittenden
Fixed lint
763
                Y.Array.each(
764
                   milestone_choice_edit.get('items'), function(item) {
12556.10.2 by Benji York
more lint
765
                    if (item.value === milestone_choice_edit.get('value')) {
9778.1.15 by Maris Fogels
Replaced deprecated Node.queryAll with Node.all().
766
                        inline_combo.all('option').each(function(opt) {
12556.10.2 by Benji York
more lint
767
                            if (opt.get('innerHTML') === item.name) {
8877.3.14 by Tom Berger
remove the roll-overs and guard against elements that dont exist
768
                                opt.set('selected', true);
769
                            }
770
                        });
8877.3.9 by Tom Berger
edit milestones using a nullable choice edit
771
                    }
772
                });
773
            }
8877.3.14 by Tom Berger
remove the roll-overs and guard against elements that dont exist
774
            // Force redrawing the UI
775
            milestone_choice_edit._uiClearWaiting();
8877.3.9 by Tom Berger
edit milestones using a nullable choice edit
776
        });
9778.1.16 by Maris Fogels
Renamed deprecated Node.query() to Node.one().
777
        milestone_content.one('.nulltext').on(
7675.410.1 by Bjorn Tillenius
Listen to click events to make it work in Opera, and call the right function, making it not break everywhere.
778
            'click',
779
            milestone_choice_edit.onClick,
9189.4.1 by Tom Berger
make the milestone link go to the milestone, rather than pop up the overlay
780
            milestone_choice_edit);
9778.1.18 by Maris Fogels
Fixed a bug where bug status rows without status cells would throw an error.
781
        milestone_choice_edit.render();
8450.4.1 by Tom Berger
make it possible to edit a bugtask importance inline
782
    }
13025.2.1 by William Grant
Only install the bugtask assignee picker if the user is logged in.
783
    if (Y.Lang.isValue(assignee_content) && conf.user_can_edit_assignee) {
12641.6.21 by Ian Booth
Add new windmill, unit, javascript tests
784
        // A validation callback called by the picker when the user selects
785
        // an assignee. We check to see if an assignee is a contributor and if
786
        // they are not, the user is asked to confirm their selection.
12641.6.26 by Ian Booth
Styling improvements
787
        var validate_assignee = function(picker, value, save_fn, cancel_fn) {
13465.1.9 by Ian Booth
Code review fixes and lint
788
            if (value === null || !Y.Lang.isValue(value.api_uri)) {
13465.1.5 by Ian Booth
Move all assignme and remove button behaviour into PersonPicker and refactor tests
789
                if (Y.Lang.isFunction(save_fn)) {
790
                    save_fn();
791
                    return;
792
                }
12641.6.24 by Ian Booth
Lint fixes
793
            }
12641.6.18 by Ian Booth
Use javascript validation for assignment to non contributor
794
            var assignee_uri = Y.lp.client.normalize_uri(value.api_uri);
795
            assignee_uri = Y.lp.client.get_absolute_uri(assignee_uri);
796
            var error_handler = new Y.lp.client.ErrorHandler();
797
            error_handler.showError = function(error_msg) {
798
                Y.lp.app.errors.display_error(null, error_msg);
799
            };
12641.6.27 by Ian Booth
Go back to using an API call to get contributor info instead of a view
800
12641.6.28 by Ian Booth
Make validation call asynchronous
801
            var process_contributor_result = function(contributor_info) {
802
                var is_contributor = contributor_info.is_contributor;
803
                if (!is_contributor) {
804
                    // Handle assignment to non contributor
12641.6.30 by Ian Booth
Fix javascript issues and minor tweaks
805
                    var person = Y.Escape.html(contributor_info.person_name);
806
                    var pillar = Y.Escape.html(contributor_info.pillar_name);
12641.6.28 by Ian Booth
Make validation call asynchronous
807
                    var yesno_content_template =
808
                        "<p>{person_name} did not previously have any " +
809
                        "assigned bugs in {pillar}.</p>" +
12556.10.2 by Benji York
more lint
810
                        "<p>Do you really want to assign them to this bug?"+
811
                        "</p>";
12641.6.28 by Ian Booth
Make validation call asynchronous
812
                    var yesno_content = Y.Lang.substitute(
813
                            yesno_content_template,
814
                            {person_name: person, pillar: pillar});
815
                    Y.lp.app.picker.yesno_save_confirmation(
816
                            picker, yesno_content, "Assign", "Choose Again",
817
                            save_fn, cancel_fn);
818
                } else {
819
                    if (Y.Lang.isFunction(save_fn)) {
820
                        save_fn();
821
                    }
822
                }
823
            };
824
12641.6.27 by Ian Booth
Go back to using an API call to get contributor info instead of a view
825
            var y_config =  {
12641.6.18 by Ian Booth
Use javascript validation for assignment to non contributor
826
                on: {
12641.6.28 by Ian Booth
Make validation call asynchronous
827
                    success: process_contributor_result,
12641.6.18 by Ian Booth
Use javascript validation for assignment to non contributor
828
                    failure: error_handler.getFailureHandler()
829
                },
12641.6.27 by Ian Booth
Go back to using an API call to get contributor info instead of a view
830
                parameters: {
831
                    person: assignee_uri
832
                }
12641.6.18 by Ian Booth
Use javascript validation for assignment to non contributor
833
            };
12641.6.28 by Ian Booth
Make validation call asynchronous
834
            lp_client.named_get(
12641.6.27 by Ian Booth
Go back to using an API call to get contributor info instead of a view
835
                    conf.bugtask_path, "getContributorInfo", y_config);
12641.6.18 by Ian Booth
Use javascript validation for assignment to non contributor
836
        };
837
13444.2.1 by Ian Booth
Fix assignee picker
838
        var step_title;
839
        if (conf.hide_assignee_team_selection) {
840
            step_title = null;
841
        } else {
842
            step_title =
843
                (conf.assignee_vocabulary === 'ValidAssignee') ?
844
                "Search for people or teams" :
845
                "Select a team of which you are a member";
846
        }
11090.5.9 by Tim Penhey
Last of the renames.
847
        var assignee_picker = Y.lp.app.picker.addPickerPatcher(
10788.5.2 by Abel Deuring
ordinary users can (un)assign a bug task only to hemselves and their teams
848
            conf.assignee_vocabulary,
9550.6.7 by Tom Berger
revert the change to assignee. it works fine in webkit
849
            conf.bugtask_path,
850
            "assignee_link",
851
            assignee_content.get('id'),
13465.1.5 by Ian Booth
Move all assignme and remove button behaviour into PersonPicker and refactor tests
852
            {"picker_type": "person",
853
             "step_title": step_title,
12221.9.7 by Tim Penhey
Move the show_remove_button and show_assign_me_button picker parameters into the config object.
854
             "header": "Change assignee",
13465.1.5 by Ian Booth
Move all assignme and remove button behaviour into PersonPicker and refactor tests
855
             "selected_value": conf.assignee_value,
13409.2.12 by Ian Booth
Some minor fixes from code review
856
             "selected_value_metadata": conf.assignee_is_team?"team":"person",
13409.2.4 by Ian Booth
Add dynamic picker text
857
             "assign_me_text": "Assign me",
858
             "remove_person_text": "Remove assignee",
13409.2.5 by Ian Booth
Update yui tests and rename current_is_team parameter
859
             "remove_team_text": "Remove assigned team",
12221.9.7 by Tim Penhey
Move the show_remove_button and show_assign_me_button picker parameters into the config object.
860
             "null_display_value": "Unassigned",
861
             "show_remove_button": conf.user_can_unassign,
12641.6.18 by Ian Booth
Use javascript validation for assignment to non contributor
862
             "show_assign_me_button": true,
863
             "validate_callback": validate_assignee});
10788.5.2 by Abel Deuring
ordinary users can (un)assign a bug task only to hemselves and their teams
864
        // Ordinary users can select only themselves and their teams.
865
        // Do not show the team selection, if a user is not a member
866
        // of any team,
867
        if (conf.hide_assignee_team_selection) {
868
            content_box = assignee_picker.get('contentBox');
13025.2.2 by William Grant
Fix hide_assignee_team_selection handling.
869
            search_box = content_box.one('.yui3-picker-search-box');
10788.5.2 by Abel Deuring
ordinary users can (un)assign a bug task only to hemselves and their teams
870
            search_box.setStyle('display', 'none');
13444.2.1 by Ian Booth
Fix assignee picker
871
            var info = Y.Node.create('<p style="padding-top: 1em;"></p>')
872
                .set('text', 'You may only assign yourself because you are ' +
873
                'not affiliated with this project and do not have any team ' +
874
                'memberships.');
875
            search_box.insert(info, search_box);
10788.5.2 by Abel Deuring
ordinary users can (un)assign a bug task only to hemselves and their teams
876
        }
9558.6.38 by Aaron Bentley
Fix lint error
877
        assignee_picker.render();
9319.1.1 by Tom Berger
make it possible to assign a bugtask inline
878
    }
8230.3.19 by Tom Berger
move the js code into the bugtask-index module
879
};
880
8971.26.1 by Gavin Panella
Rip out current JS me-too functionality.
881
/**
882
 * Set up the "me too" selection.
883
 *
8971.26.16 by Gavin Panella
Don't add unnecessary guards against being run when the user is not logged in; that is already done in the template.
884
 * Called once, on load, to initialize the page. Call this function if
885
 * the "me too" information is displayed on a bug page and the user is
886
 * logged in.
8971.26.1 by Gavin Panella
Rip out current JS me-too functionality.
887
 *
888
 * @method setup_me_too
889
 */
10985.3.13 by Deryck Hodge
Move bugtask_index into Y.lp.bugs namespace.
890
namespace.setup_me_too = function(user_is_affected, others_affected_count) {
9152.1.1 by Gavin Panella
Don't set up the me-too area with AJAXy goodness in the eternally stupid Internet Explorer.
891
    // IE (7 & 8 tested) is stupid, stupid, stupid.
892
    if (Y.UA.ie) {
893
        return;
894
    }
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
895
    var me_too_content = Y.one('#affectsmetoo');
8971.26.16 by Gavin Panella
Don't add unnecessary guards against being run when the user is not logged in; that is already done in the template.
896
    var me_too_edit = new MeTooChoiceSource({
8971.26.40 by Gavin Panella
Move the values for title and items into MeTooChoiceSource.
897
        contentBox: me_too_content, value: user_is_affected,
9826.3.1 by Graham Binns
The 'affects me too' edit icon will now turn into a spinner when the value is updated.
898
        elementToFlash: me_too_content,
10054.8.1 by Gavin Panella
Search for the editicon CSS class instead of the src of the image for the me-too edit and action icon.
899
        editicon: ".dynamic img.editicon",
10015.1.5 by Gavin Panella
Start plumbing other_users_affected_count into the Javascript.
900
        others_affected_count: others_affected_count
8971.26.16 by Gavin Panella
Don't add unnecessary guards against being run when the user is not logged in; that is already done in the template.
901
    });
902
    me_too_edit.render();
8971.26.1 by Gavin Panella
Rip out current JS me-too functionality.
903
};
904
8971.26.10 by Gavin Panella
Move the rest of the me-too choice customizations into MeTooChoiceSource.
905
/**
906
 * This class is a derivative of ChoiceSource that handles the
907
 * specifics of editing "me too" option.
908
 *
909
 * @class MeTooChoiceSource
910
 * @extends ChoiceSource
911
 * @constructor
912
 */
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
913
function MeTooChoiceSource() {
914
    MeTooChoiceSource.superclass.constructor.apply(this, arguments);
8971.26.6 by Gavin Panella
It bloody works.
915
}
916
8971.26.25 by Gavin Panella
Use HTML_PARSER to get the flame icon.
917
MeTooChoiceSource.NAME = 'metoocs';
918
MeTooChoiceSource.NS = 'metoocs';
919
920
MeTooChoiceSource.ATTRS = {
921
    /**
8971.26.40 by Gavin Panella
Move the values for title and items into MeTooChoiceSource.
922
     * The title is always the same, so bake it in here.
923
     *
924
     * @attribute title
925
     * @type String
926
     */
927
    title: {
928
        value: 'Does this bug affect you?'
929
    },
930
931
    /**
932
     * The items are always the same, so bake them in here.
933
     *
934
     * @attribute items
935
     * @type Array
936
     */
937
    items: {
938
        value: [
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
939
            { name: 'Yes, it affects me',
940
              value: true, disabled: false },
941
            { name: "No, it doesn't affect me",
942
              value: false, disabled: false }
8971.26.40 by Gavin Panella
Move the values for title and items into MeTooChoiceSource.
943
        ]
944
    },
945
946
    /**
10015.1.5 by Gavin Panella
Start plumbing other_users_affected_count into the Javascript.
947
     * The number of other users currently affected by this bug.
948
     *
949
     * @attribute others_affected_count
950
     * @type Number
951
     */
952
    others_affected_count: {
953
        value: null
9826.3.2 by Graham Binns
Trimmed some JS lint.
954
    }
8971.26.25 by Gavin Panella
Use HTML_PARSER to get the flame icon.
955
};
956
957
// Put this in the bugs namespace so it can be accessed for testing.
10985.3.13 by Deryck Hodge
Move bugtask_index into Y.lp.bugs namespace.
958
namespace._MeTooChoiceSource = MeTooChoiceSource;
8971.26.6 by Gavin Panella
It bloody works.
959
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
960
Y.extend(MeTooChoiceSource, Y.ChoiceSource, {
8971.26.10 by Gavin Panella
Move the rest of the me-too choice customizations into MeTooChoiceSource.
961
    initializer: function() {
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
962
        var widget = this;
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
963
        this.error_handler = new Y.lp.client.ErrorHandler();
8971.26.6 by Gavin Panella
It bloody works.
964
        this.error_handler.clearProgressUI = function() {
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
965
            widget._uiClearWaiting();
8971.26.6 by Gavin Panella
It bloody works.
966
        };
967
        this.error_handler.showError = function(error_msg) {
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
968
            widget.showError(error_msg);
8971.26.6 by Gavin Panella
It bloody works.
969
        };
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
970
        // Set source_names.
10015.1.5 by Gavin Panella
Start plumbing other_users_affected_count into the Javascript.
971
        var others_affected_count = this.get('others_affected_count');
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
972
        var source_names = this._getSourceNames(others_affected_count);
973
        Y.each(this.get('items'), function(item) {
12556.10.2 by Benji York
more lint
974
            if (source_names.hasOwnProperty(item.value)) {
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
975
                item.source_name = source_names[item.value];
976
            }
977
        });
8971.26.6 by Gavin Panella
It bloody works.
978
    },
979
10015.1.22 by Gavin Panella
Comment that _getSourceNames(), affected_statement and anon_affected_statement should all output similar strings.
980
    /*
981
     * The results of _getSourceNames() should closely mirror the
982
     * results of BugTasksAndNominationsView.affected_statement and
983
     * anon_affected_statement.
984
     */
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
985
    _getSourceNames: function(others_affected_count) {
986
        var source_names = {};
10015.1.14 by Gavin Panella
Factor out a MeTooChoiceSource._getNewSourceNames() method, and test.
987
        // What to say when the user is marked as affected.
12556.10.2 by Benji York
more lint
988
        if (others_affected_count === 1) {
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
989
            source_names[true] = (
10015.1.14 by Gavin Panella
Factor out a MeTooChoiceSource._getNewSourceNames() method, and test.
990
                'This bug affects you and 1 other person');
991
        }
992
        else if (others_affected_count > 1) {
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
993
            source_names[true] = (
10015.1.14 by Gavin Panella
Factor out a MeTooChoiceSource._getNewSourceNames() method, and test.
994
                'This bug affects you and ' +
995
                others_affected_count + ' other people');
996
        }
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
997
        else {
998
            source_names[true] = 'This bug affects you';
999
        }
10015.1.14 by Gavin Panella
Factor out a MeTooChoiceSource._getNewSourceNames() method, and test.
1000
        // What to say when the user is marked as not affected.
12556.10.2 by Benji York
more lint
1001
        if (others_affected_count === 1) {
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
1002
            source_names[false] = (
10015.1.14 by Gavin Panella
Factor out a MeTooChoiceSource._getNewSourceNames() method, and test.
1003
                'This bug affects 1 person, but not you');
1004
        }
1005
        else if (others_affected_count > 1) {
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
1006
            source_names[false] = (
10015.1.14 by Gavin Panella
Factor out a MeTooChoiceSource._getNewSourceNames() method, and test.
1007
                'This bug affects ' + others_affected_count +
1008
                ' people, but not you');
1009
        }
10015.1.21 by Gavin Panella
Set all source_name values in MeTooChoiceSource.initializer() using the values from _getSourceNames(), which used to be called _getNewSourceNames().
1010
        else {
1011
            source_names[false] = "This bug doesn't affect you";
1012
        }
1013
        return source_names;
10015.1.14 by Gavin Panella
Factor out a MeTooChoiceSource._getNewSourceNames() method, and test.
1014
    },
1015
8971.26.10 by Gavin Panella
Move the rest of the me-too choice customizations into MeTooChoiceSource.
1016
    showError: function(err) {
11090.5.8 by Tim Penhey
Fix some more namespace issues.
1017
        Y.lp.app.errors.display_error(null, err);
8971.26.10 by Gavin Panella
Move the rest of the me-too choice customizations into MeTooChoiceSource.
1018
    },
1019
1020
    render: function() {
1021
        MeTooChoiceSource.superclass.render.apply(this, arguments);
1022
        // Force the ChoiceSource to be rendered inline.
1023
        this.get('boundingBox').setStyle('display', 'inline');
8971.26.13 by Gavin Panella
Use .static and .dynamic areas for organisation.
1024
        // Hide the static content and show the dynamic content.
9778.1.16 by Maris Fogels
Renamed deprecated Node.query() to Node.one().
1025
        this.get('contentBox').one('.static').addClass('unseen');
1026
        this.get('contentBox').one('.dynamic').removeClass('unseen');
8971.26.10 by Gavin Panella
Move the rest of the me-too choice customizations into MeTooChoiceSource.
1027
    },
1028
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
1029
    _saveData: function() {
8971.26.10 by Gavin Panella
Move the rest of the me-too choice customizations into MeTooChoiceSource.
1030
        // Set the widget to the 'waiting' state.
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
1031
        this._uiSetWaiting();
8971.26.6 by Gavin Panella
It bloody works.
1032
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
1033
        var value = this.getInput();
12421.1.12 by Tim Penhey
Fix up references to methods now in Y.lp.client instead of LP.client.
1034
        var client =  new Y.lp.client.Launchpad();
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
1035
        var widget = this;
8971.26.6 by Gavin Panella
It bloody works.
1036
8971.26.10 by Gavin Panella
Move the rest of the me-too choice customizations into MeTooChoiceSource.
1037
        var config = {
8971.26.6 by Gavin Panella
It bloody works.
1038
            on: {
1039
                success: function(entry) {
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
1040
                    widget._uiClearWaiting();
1041
                    MeTooChoiceSource.superclass._saveData.call(
1042
                        widget, value);
13445.1.8 by Gary Poster
JavaScript for bug page: if we increase the affected count to 2 or more, maybe update the statuses of NEW bugtasks
1043
                    if (value && widget.get('others_affected_count') > 0) {
1044
                        // If we increased the affected count to 2 or more,
1045
                        // maybe update the statuses of our bugtasks.
1046
                        update_maybe_confirmed_status();
1047
                    }
8971.26.6 by Gavin Panella
It bloody works.
1048
                },
1049
                failure: this.error_handler.getFailureHandler()
1050
            },
1051
            parameters: {
1052
                affected: value
1053
            }
8971.26.9 by Gavin Panella
Subclass ChoiceSource rather than plugging MeTooPlugin into a plain ChoiceSource.
1054
        };
8971.26.6 by Gavin Panella
It bloody works.
1055
1056
        client.named_post(
12442.1.1 by Tim Penhey
Rename LP.client.cache to LP.cache.
1057
            LP.cache.bug.self_link, 'markUserAffected', config);
8971.26.6 by Gavin Panella
It bloody works.
1058
    }
1059
});
8486.20.24 by Bjorn Tillenius
Merge RF.
1060
/*
8486.20.16 by Deryck Hodge
Add a couple comments.
1061
 * Click handling to pass comment text to the attachment
1062
 * page if there is a comment.
1063
 *
1064
 * @method setup_add_attachment
1065
 */
8486.20.15 by Deryck Hodge
Pass the comment value to the attachment form
1066
function setup_add_attachment() {
10015.1.1 by Gavin Panella
setup_bug_attachment() is meant to find zero or more links, so don't use Y.one().
1067
    // Find zero or more links to modify.
10015.1.20 by Gavin Panella
Should be Y.all() to find zero or more nodes, not Y.get() which returns null when nothing is found.
1068
    var attachment_link = Y.all('.menu-link-addcomment');
8486.20.15 by Deryck Hodge
Pass the comment value to the attachment form
1069
    attachment_link.on('click', function(e) {
9778.1.12 by Maris Fogels
Update deprecated Y.get() for Y.one()
1070
        var comment_input = Y.one('[id="field.comment"]');
9080.1.1 by Bjorn Tillenius
Fix jslint warnings.
1071
        if (comment_input.get('value') !== '') {
8486.20.17 by Deryck Hodge
Don't assume the current URL.
1072
            var current_url = attachment_link.getAttribute('href');
1073
            var attachment_url = current_url + '?field.comment=' +
8486.20.15 by Deryck Hodge
Pass the comment value to the attachment form
1074
                encodeURIComponent(comment_input.get('value'));
1075
            attachment_link.setAttribute('href', attachment_url);
1076
        }
1077
    });
1078
}
1079
9894.4.5 by Graham Binns
The view now return JSON directly rather than putting it in a template.
1080
12221.8.2 by Brad Crittenden
Fixed lint
1081
}, "0.1", {"requires": ["base", "oop", "node", "event", "io-base",
1082
                        "json-parse", "substitute", "widget-position-ext",
1083
                        "lazr.formoverlay", "lazr.anim", "lazr.base",
1084
                        "lazr.overlay", "lazr.choiceedit", "lp.app.picker",
7675.1160.11 by Gary Poster
cleanups: remove some changes that do not really need to happen now, fix some tests, remove some more code, add some comments.
1085
                        "lp.client", "escape",
13458.2.1 by j.c.sackett
Moved privacy notification code into its own file.
1086
                        "lp.client.plugins", "lp.app.errors",
1087
                        "lp.app.privacy"]});