~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Francis J. Lacoste
  • Date: 2011-06-06 20:56:43 UTC
  • mfrom: (13165 devel)
  • mto: This revision was merged to the branch mainline in revision 13180.
  • Revision ID: francis.lacoste@canonical.com-20110606205643-b53boddbakyllkgg
Merge devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
221
221
 * Remove the Loading.... spinner (if it exists).
222
222
 */
223
223
function hide_temporary_spinner(temp_spinner) {
224
 
    if( temp_spinner !== null ) {
 
224
    if (temp_spinner !== undefined && temp_spinner !== null) {
225
225
        temp_spinner.addClass('unseen');
226
226
    }
227
227
}
313
313
    }
314
314
}
315
315
 
 
316
 
 
317
/*
 
318
 * Connect the onchange event of the select menu to copy the selected value
 
319
 * to the text input.
 
320
 *
 
321
 * @param {Node} select_menu The select menu with suggested matches.
 
322
 * @param {Node} text_input The input field to copy the selected match too.
 
323
 */
 
324
namespace.connect_select_menu = function (select_menu, text_input) {
 
325
    var copy_selected_value = function(e) {
 
326
        text_input.value = select_menu.value;
 
327
        };
 
328
    Y.on('change', copy_selected_value, select_menu);
 
329
    };
 
330
 
 
331
 
 
332
/**
 
333
 * Extend the lazr-js Picker.
 
334
 */
 
335
var Picker = function() {
 
336
    Picker.superclass.constructor.apply(this, arguments);
 
337
};
 
338
 
 
339
Y.extend(Picker, Y.lazr.Picker, {
 
340
    // We want to render alt title slightly differently.
 
341
    _renderTitleUI: function(data) {
 
342
        var li_title = Y.Node.create(
 
343
            '<span></span>').addClass(Y.lazr.Picker.C_RESULT_TITLE);
 
344
        var title = this._text_or_link(
 
345
            data.title, data.title_link, data.link_css);
 
346
        li_title.appendChild(title);
 
347
        if (data.alt_title) {
 
348
            var alt_link = null;
 
349
            if (data.alt_title_link) {
 
350
                alt_link =Y.Node.create('<a></a>')
 
351
                    .addClass(data.link_css)
 
352
                    .addClass('discreet');
 
353
                alt_link.set('text', " Details...")
 
354
                    .set('href', data.alt_title_link);
 
355
                Y.on('click', function(e) {
 
356
                    e.halt();
 
357
                    window.open(data.alt_title_link);
 
358
                }, alt_link);
 
359
            }
 
360
            li_title.appendChild('&nbsp;(');
 
361
            li_title.appendChild(document.createTextNode(data.alt_title));
 
362
            if (alt_link !== null)
 
363
                li_title.appendChild(alt_link);
 
364
            li_title.appendChild(')');
 
365
        }
 
366
        return li_title;
 
367
    }
 
368
});
 
369
Picker.NAME = 'picker';
 
370
namespace.Picker = Picker;
 
371
 
316
372
/**
317
373
  * Creates a picker widget that has already been rendered and hidden.
318
374
  *
361
417
        zIndex: 1000,
362
418
        visible: false
363
419
        });
364
 
    var picker = new Y.lazr.Picker(new_config);
 
420
    var picker = new Picker(new_config);
365
421
 
366
422
    // We don't want the Y.lazr.Picker default save to fire since this hides
367
423
    // the form. We want to do this ourselves after any validation has had a
483
539
};
484
540
 
485
541
}, "0.1", {"requires": [
486
 
    "io", "dom", "dump", "lazr.picker", "lazr.activator", "json-parse",
487
 
    "lp.client"
 
542
    "io", "dom", "dump", "event", "lazr.picker", "lazr.activator",
 
543
    "json-parse", "lp.client"
488
544
    ]});