Merge lp:~allenap/launchpad/bug-index-performance-bug-430288-vocab-picker into lp:launchpad

Proposed by Gavin Panella on 2009-09-21
Status: Merged
Approved by: Brad Crittenden on 2009-09-22
Approved revision: no longer in the source branch.
Merged at revision: not available
Proposed branch: lp:~allenap/launchpad/bug-index-performance-bug-430288-vocab-picker
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~allenap/launchpad/bug-index-performance-bug-430288-vocab-picker
Reviewer Review Type Date Requested Status
Brad Crittenden (community) release-critical 2009-09-22 Approve on 2009-09-22
Eleanor Berger (community) js 2009-09-21 Approve on 2009-09-21
Review via email: mp+12156@code.launchpad.net
To post a comment you must log in.
Gavin Panella (allenap) wrote :

Currently the creation of the vocabulary picker widget happens as a page is being parsed. The picker widget runs a non-trivial amount of code, so this branch defers the creation of the widget to within the click handler of the activation ("Choose...") link.

review: Approve (js)
Brad Crittenden (bac) :
review: Approve (release-critical)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/widgets/templates/vocabulary-picker.js'
2--- lib/canonical/widgets/templates/vocabulary-picker.js 2009-07-29 21:22:38 +0000
3+++ lib/canonical/widgets/templates/vocabulary-picker.js 2009-09-21 12:27:14 +0000
4@@ -6,32 +6,42 @@
5 // Args from python.
6 var args = %s;
7
8+ // The vocabulary picker, created when used for the first time.
9+ var picker = null;
10+ function make_picker() {
11+ var save = function (result) {
12+ Y.DOM.byId(args.input_id).value = result.value;
13+ };
14+ var config = {
15+ header: args.header,
16+ step_title: args.step_title,
17+ extra_no_results_message: args.extra_no_results_message
18+ };
19+ var picker = Y.lp.picker.create(args.vocabulary, save, config);
20+ if (config.extra_no_results_message !== null) {
21+ picker.before('resultsChange', function (e) {
22+ var new_results = e.details[0].newVal;
23+ if (new_results.length === 0) {
24+ picker.set('footer_slot',
25+ Y.Node.create(config.extra_no_results_message));
26+ }
27+ else {
28+ picker.set('footer_slot', null);
29+ }
30+ });
31+ }
32+ return picker;
33+ }
34+
35+ // Sort out the "Choose..." link.
36 var show_widget_node = Y.get('#' + args.show_widget_id);
37- var save = function (result) {
38- Y.DOM.byId(args.input_id).value = result.value;
39- };
40- var config = {
41- header: args.header,
42- step_title: args.step_title,
43- extra_no_results_message: args.extra_no_results_message
44- };
45- var picker = Y.lp.picker.create(args.vocabulary, save, config);
46- if (config.extra_no_results_message !== null) {
47- picker.before('resultsChange', function (e) {
48- var new_results = e.details[0].newVal;
49- if (new_results.length === 0) {
50- picker.set('footer_slot',
51- Y.Node.create(config.extra_no_results_message));
52- }
53- else {
54- picker.set('footer_slot', null);
55- }
56- });
57- }
58 show_widget_node.set('innerHTML', 'Choose…');
59 show_widget_node.addClass('js-action');
60 show_widget_node.get('parentNode').removeClass('unseen');
61 show_widget_node.on('click', function (e) {
62+ if (picker === null) {
63+ picker = make_picker();
64+ }
65 picker.show();
66 e.preventDefault();
67 });