~launchpad-pqm/launchpad/devel

« back to all changes in this revision

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

  • Committer: Launchpad Patch Queue Manager
  • Date: 2011-07-06 03:24:29 UTC
  • mfrom: (13314.9.15 lazrjs-picker-consolidate)
  • Revision ID: launchpad@pqm.canonical.com-20110706032429-kdxgrfaiiakiuu9d
[r=jcsackett][bug=805782] Consolidate lazr-js and lp picker
 implementations

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 * Module containing the Lazr searchable picker.
7
7
 *
8
8
 * @module lazr.picker
9
 
 * @namespace lazr
 
9
 * @namespace lazr.picker
10
10
 */
11
11
 
12
12
/**
351
351
    _renderTitleUI: function(data) {
352
352
        var li_title = Y.Node.create(
353
353
            '<span></span>').addClass(C_RESULT_TITLE);
 
354
        if (data.title === undefined) {
 
355
            // Display an empty element if data is empty.
 
356
            return li_title;
 
357
        }
354
358
        var title = this._text_or_link(
355
359
            data.title, data.title_link, data.link_css);
356
360
        li_title.appendChild(title);
357
361
        if (data.alt_title) {
358
 
            var alt_title = this._text_or_link(
359
 
                data.alt_title, data.alt_title_link, data.link_css);
 
362
            var alt_link = null;
 
363
            if (data.alt_title_link) {
 
364
                alt_link =Y.Node.create('<a></a>')
 
365
                    .addClass(data.link_css)
 
366
                    .addClass('discreet');
 
367
                alt_link.set('text', " Details...")
 
368
                    .set('href', data.alt_title_link);
 
369
                Y.on('click', function(e) {
 
370
                    e.halt();
 
371
                    window.open(data.alt_title_link);
 
372
                }, alt_link);
 
373
            }
360
374
            li_title.appendChild('&nbsp;(');
361
 
            li_title.appendChild(alt_title);
 
375
            li_title.appendChild(document.createTextNode(data.alt_title));
362
376
            li_title.appendChild(')');
 
377
            if (alt_link !== null) {
 
378
                li_title.appendChild(alt_link);
 
379
            }
363
380
        }
364
381
        return li_title;
365
382
    },
432
449
                li.appendChild(
433
450
                    Y.Node.create('<img />').set('src', data.image));
434
451
            }
435
 
            if (li_badges !== null)
 
452
            if (li_badges !== null) {
436
453
                li.appendChild(li_badges);
 
454
            }
437
455
            li.appendChild(li_title);
438
456
            li.appendChild(li_desc);
439
457
            // Attach handlers.
550
568
 
551
569
        var body = Y.Node.create('<div></div>');
552
570
        body.appendChild(search_box);
 
571
        body.appendChild(this._results_box);
553
572
        body.appendChild(this._batches_box);
554
 
        body.appendChild(this._results_box);
555
573
        body.appendChild(this._footer_slot_box);
556
574
        body.addClass('yui3-widget-bd');
557
575
 
971
989
    initializer: function(config) {
972
990
        var input = Y.one(config.input_element);
973
991
        this.doAfter('save', function (e) {
974
 
            var result = e.details[Y.lazr.Picker.SAVE_RESULT];
 
992
            var result = e.details[Y.lazr.picker.Picker.SAVE_RESULT];
975
993
            input.set("value",  result.value);
976
994
            // If the search input isn't blurred before it is focused,
977
995
            // then the I-beam disappears.
986
1004
    }
987
1005
});
988
1006
 
989
 
Y.lazr.Picker = Picker;
990
 
Y.lazr.TextFieldPickerPlugin = TextFieldPickerPlugin;
 
1007
var namespace = Y.namespace('lazr.picker');
 
1008
namespace.Picker = Picker;
 
1009
namespace.TextFieldPickerPlugin = TextFieldPickerPlugin;
991
1010
 
992
1011
}, "0.1", {"skinnable": true,
993
1012
           "requires": ["oop", "event", "event-focus", "node", "plugin",