~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-08-11 22:41:38 UTC
  • mfrom: (13639.1.2 bug-823321)
  • Revision ID: launchpad@pqm.canonical.com-20110811224138-bzaw94aekw2fcfvv
[r=jcsackett][bug=823321] make the automatic suggestion search
        interact more nicely with a uesr-initiated search

Show diffs side-by-side

added added

removed removed

Lines of Context:
328
328
    // chance to be performed.
329
329
    picker.publish('save', { defaultFn: function(){} } );
330
330
 
 
331
    // Has the user performed a search yet?
 
332
    var user_has_searched = false;
 
333
 
331
334
    picker.subscribe('save', function (e) {
332
335
        Y.log('Got save event.');
333
336
        var picker_result = e.details[Y.lazr.picker.Picker.SAVE_RESULT];
334
337
        var do_save = function() {
 
338
            user_has_searched = false;
335
339
            picker.hide();
336
340
            if (Y.Lang.isFunction(config.save)) {
337
341
                config.save(picker_result);
350
354
    picker.subscribe('cancel', function (e) {
351
355
        Y.log('Got cancel event.');
352
356
        reset_form(picker);
 
357
        user_has_searched = false;
353
358
    });
354
359
 
355
360
    if (config.extra_no_results_message !== null) {
370
375
        Y.log('Got search event:' + Y.dump(e.details));
371
376
        var search_text = e.details[0];
372
377
        var selected_batch = e.details[1] || 0;
 
378
        // Was this search initiated automatically, perhaps to load
 
379
        // suggestions?
 
380
        var automated_search = e.details[2] || false;
373
381
        var start = BATCH_SIZE * selected_batch;
374
382
        var batch = 0;
 
383
 
 
384
        // Record whether or not the user has initiated a search yet.
 
385
        user_has_searched = user_has_searched || !automated_search;
 
386
 
375
387
        var display_vocabulary = function(results, total_size, start) {
376
388
            var max_size = MAX_BATCHES * BATCH_SIZE;
377
389
            if (show_search_box && total_size > max_size)  {
409
421
                var start = entry.start;
410
422
                var results = entry.entries;
411
423
                hide_temporary_spinner(config.temp_spinner);
412
 
                display_vocabulary(results, total_size, start);
 
424
                // If this was an automated (preemptive) search and the user
 
425
                // has not subsequently initiated their own search, display
 
426
                // the results of the search.
 
427
                if (user_has_searched !== automated_search) {
 
428
                    display_vocabulary(results, total_size, start);
 
429
                }
413
430
            };
414
431
 
415
432
            var failure_handler = function (ignore, response, args) {
 
433
                Y.log("Loading " + uri + " failed.");
416
434
                hide_temporary_spinner(config.temp_spinner);
 
435
                // If this was an automated (preemptive) search and the user
 
436
                // has subsequently initiated their own search, don't bother
 
437
                // showing an error message about something the user didn't
 
438
                // initiate and now doesn't care about.
 
439
                if (user_has_searched === automated_search) {
 
440
                    return;
 
441
                }
417
442
                var base_error =
418
443
                    "Sorry, something went wrong with your search.";
419
444
                if (response.status === 500) {
430
455
                }
431
456
                picker.set('error', base_error);
432
457
                picker.set('search_mode', false);
433
 
                Y.log("Loading " + uri + " failed.");
434
458
            };
435
459
 
436
460