~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-06-01 19:43:31 UTC
  • mfrom: (13130.3.9 bug-778129-person-picker)
  • Revision ID: launchpad@pqm.canonical.com-20110601194331-x06pggfd0rjnkdgo
[r=gmb][bug=778129] Removed batch limit from InlineEditPickerWidget
        if no search box is available.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright 2011 Canonical Ltd.  This software is licensed under the
 
2
 * GNU Affero General Public License version 3 (see the file LICENSE).
 
3
 */
 
4
 
1
5
YUI.add('lp.app.picker', function(Y) {
2
6
 
3
7
var namespace = Y.namespace('lp.app.picker');
88
92
 
89
93
        if (assign_me_button) {
90
94
            if (link !== null
91
 
                && link.get('href').indexOf(LP.links.me + '/') != -1) {
 
95
                && link.get('href').indexOf(LP.links.me + '/') !== -1) {
92
96
                assign_me_button.addClass('yui-picker-hidden');
93
97
            } else {
94
98
                assign_me_button.removeClass('yui-picker-hidden');
188
192
          config.temp_spinner.removeClass('unseen');
189
193
          picker.set('min_search_chars', 0);
190
194
          picker.fire('search', '');
191
 
          picker.get('contentBox').one('.yui3-picker-search-box').addClass('unseen');
 
195
          picker.get('contentBox').one(
 
196
              '.yui3-picker-search-box').addClass('unseen');
192
197
        }
193
198
        picker.show();
194
199
    });
216
221
 * Remove the Loading.... spinner (if it exists).
217
222
 */
218
223
function hide_temporary_spinner(temp_spinner) {
219
 
    if( temp_spinner != null ) {
 
224
    if( temp_spinner !== null ) {
220
225
        temp_spinner.addClass('unseen');
221
226
    }
222
227
}
290
295
    picker.get('contentBox').all('.steps').show();
291
296
    var validation_node = picker.get('contentBox').one('.validation-node');
292
297
    var content_node = picker.get('contentBox').one('.yui3-widget-bd');
293
 
    if (validation_node != null) {
 
298
    if (validation_node !== null) {
294
299
        validation_node.get('parentNode').removeChild(validation_node);
295
300
        content_node.addClass('transparent');
296
301
        content_node.setStyle('opacity', 0);
338
343
        }
339
344
    }
340
345
 
341
 
    if (typeof vocabulary != 'string' && typeof vocabulary != 'object') {
 
346
    if (typeof vocabulary !== 'string' && typeof vocabulary !== 'object') {
342
347
        throw new TypeError(
343
348
            "vocabulary argument for Y.lp.picker.create() must be a " +
344
349
            "string or associative array: " + vocabulary);
362
367
    // the form. We want to do this ourselves after any validation has had a
363
368
    // chance to be performed.
364
369
    picker.publish('save', { defaultFn: function(){} } );
365
 
    
 
370
 
366
371
    picker.subscribe('save', function (e) {
367
372
        Y.log('Got save event.');
368
373
        var picker_result = e.details[Y.lazr.Picker.SAVE_RESULT];
393
398
        var search_text = e.details[0];
394
399
        var selected_batch = e.details[1] || 0;
395
400
        var start = BATCH_SIZE * selected_batch;
 
401
        var batch = 0;
396
402
        var display_vocabulary = function(results, total_size, start) {
397
 
            if (total_size > (MAX_BATCHES * BATCH_SIZE))  {
 
403
            var max_size = MAX_BATCHES * BATCH_SIZE;
 
404
            if (config.show_search_box && total_size > max_size)  {
398
405
                picker.set('error',
399
406
                    'Too many matches. Please try to narrow your search.');
400
407
                // Display a single empty result item so that the picker
409
416
                    var batches = [];
410
417
                    var stop = Math.ceil(total_size / BATCH_SIZE);
411
418
                    if (stop > 1) {
412
 
                        for (var i=0; i<stop; i++) {
 
419
                        for (batch = 0; batch < stop; batch++) {
413
420
                            batches.push({
414
 
                                    name: i+1,
415
 
                                    value: i
 
421
                                    name: batch+1,
 
422
                                    value: batch
416
423
                                });
417
424
                        }
418
425
                    }
422
429
        };
423
430
 
424
431
        // We can pass in a vocabulary name
425
 
        if (typeof vocabulary == 'string') {
 
432
        if (typeof vocabulary === 'string') {
426
433
            var success_handler = function (ignore, response, args) {
427
434
                var entry = Y.JSON.parse(response.responseText);
428
435
                var total_size = entry.total_size;
443
450
            // use the context to limit the results to the same project.
444
451
 
445
452
            var uri = '';
446
 
            if (Y.Lang.isValue(config['context'])){
447
 
                uri += Y.lp.get_url_path(config['context'].get('web_link')) + '/';
448
 
            }            
 
453
            if (Y.Lang.isValue(config.context)){
 
454
                uri += Y.lp.get_url_path(
 
455
                    config.context.get('web_link')) + '/';
 
456
            }
449
457
            uri += '@@+huge-vocabulary?' + qs;
450
458
 
451
459
            Y.io(uri, {