Merge lp:~jcsackett/launchpad/button-configs-break-pickers into lp:launchpad

Proposed by j.c.sackett
Status: Superseded
Proposed branch: lp:~jcsackett/launchpad/button-configs-break-pickers
Merge into: lp:launchpad
Diff against target: 291 lines (+63/-17)
9 files modified
lib/lp/app/browser/lazrjs.py (+5/-1)
lib/lp/app/javascript/lazr/picker/person_picker.js (+12/-4)
lib/lp/app/javascript/picker_patcher.js (+1/-5)
lib/lp/app/javascript/tests/test_picker.js (+22/-4)
lib/lp/app/widgets/popup.py (+7/-0)
lib/lp/app/widgets/templates/form-picker-macros.pt (+4/-0)
lib/lp/bugs/javascript/bugtask_index.js (+1/-0)
lib/lp/code/browser/sourcepackagerecipe.py (+2/-1)
lib/lp/registry/browser/team.py (+9/-2)
To merge this branch: bzr merge lp:~jcsackett/launchpad/button-configs-break-pickers
Reviewer Review Type Date Requested Status
Launchpad code reviewers Pending
Review via email: mp+66946@code.launchpad.net

This proposal has been superseded by a proposal from 2011-07-06.

Description of the change

Summary
=======
An earlier branch that set up configuration options for views regarding whether or not to show the extra buttons actually broke pickers by passing in "True" where javascript expects "true". This branch fixes that.

This sort of issue should go away once we address bug 799847, in particular the part about using the JSONCache.

Pre-implementation notes
========================
None.

Implementation details
======================
popup.py sets two variables regarding the assign me button and the remove assignee button, but sets them using python booleans. They've been updated to strings, which are interpreted in the form-macros into the appropriate javascript booleans (e.g. 'false' instead of False).

Callsites have been updated to pass in the correct assignments for these variables.

Tests
=====
bin/test -vvc --layer=YUI

QA
==
Check that clicking the Choose fields (e.g. on launchpad.dev/evolution/+edit-people) properly opens the person picker.

= Launchpad lint =

Checking for conflicts and issues in changed files.

Linting changed files:
  lib/lp/registry/browser/team.py
  lib/lp/app/widgets/popup.py

./lib/lp/registry/browser/team.py
     552: local variable 'mailing_list' is assigned to but never used

Not sure what to do regaring the lint above; it seems like the sort of code that may accomplish something via side effect, and I can't find good tests to double check. I'll try to suss it out prior to landing it.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/app/browser/lazrjs.py'
2--- lib/lp/app/browser/lazrjs.py 2011-07-06 00:41:28 +0000
3+++ lib/lp/app/browser/lazrjs.py 2011-07-06 14:16:29 +0000
4@@ -238,7 +238,8 @@
5
6 def __init__(self, context, exported_field, default_html,
7 content_box_id=None, header='Select an item',
8- step_title='Search', remove_button_text='Remove',
9+ step_title='Search', assign_button_text='Pick Me',
10+ remove_button_text='Remove Person',
11 null_display_value='None',
12 edit_view="+edit", edit_url=None, edit_title=''):
13 """Create a widget wrapper.
14@@ -251,6 +252,7 @@
15 Automatically generated if this is not provided.
16 :param header: The large text at the top of the picker.
17 :param step_title: Smaller line of text below the header.
18+ :param assign_button_text: Override default button text: "Pick Me"
19 :param remove_button_text: Override default button text: "Remove"
20 :param null_display_value: This will be shown for a missing value
21 :param edit_view: The view name to use to generate the edit_url if
22@@ -265,6 +267,7 @@
23 self.default_html = default_html
24 self.header = header
25 self.step_title = step_title
26+ self.assign_button_text = assign_button_text
27 self.remove_button_text = remove_button_text
28 self.null_display_value = null_display_value
29
30@@ -278,6 +281,7 @@
31 def config(self):
32 return dict(
33 header=self.header, step_title=self.step_title,
34+ assign_button_text=self.assign_button_text,
35 remove_button_text=self.remove_button_text,
36 null_display_value=self.null_display_value,
37 show_remove_button=self.optional_field,
38
39=== modified file 'lib/lp/app/javascript/lazr/picker/person_picker.js'
40--- lib/lp/app/javascript/lazr/picker/person_picker.js 2011-07-06 03:20:46 +0000
41+++ lib/lp/app/javascript/lazr/picker/person_picker.js 2011-07-06 14:16:29 +0000
42@@ -23,6 +23,8 @@
43
44 var show_assign_me_button = true;
45 var show_remove_button = true;
46+ var assign_button_text = 'Pick Me';
47+ var remove_button_text = 'Remove Person';
48
49 if (cfg !== undefined) {
50 if (cfg.show_assign_me_button !== undefined) {
51@@ -31,9 +33,17 @@
52 if (cfg.show_remove_button !== undefined) {
53 show_remove_button = cfg.show_remove_button;
54 }
55+ if (cfg.assign_button_text !== undefined) {
56+ assign_button_text = cfg.assign_button_text;
57+ }
58+ if (cfg.remove_button_text !== undefined) {
59+ remove_button_text = cfg.remove_button_text;
60+ }
61 }
62 this._show_assign_me_button = show_assign_me_button;
63 this._show_remove_button = show_remove_button;
64+ this._assign_me_button_text = assign_button_text;
65+ this._remove_button_text = remove_button_text;
66 },
67
68 hide: function() {
69@@ -57,15 +67,13 @@
70
71 _renderPersonPickerUI: function() {
72 var remove_button, assign_me_button;
73- var remove_button_text = "Remove assignee";
74- var assign_me_button_text = "Assign to me";
75
76 if (this._show_remove_button) {
77 remove_button = Y.Node.create(
78 '<a class="yui-picker-remove-button bg-image" ' +
79 'href="javascript:void(0)" ' +
80 'style="background-image: url(/@@/remove); padding-right: ' +
81- '1em">' + remove_button_text + '</a>');
82+ '1em">' + this._remove_button_text + '</a>');
83 remove_button.on('click', this.remove, this);
84 this._extra_buttons.appendChild(remove_button);
85 this.remove_button = remove_button;
86@@ -76,7 +84,7 @@
87 '<a class="yui-picker-assign-me-button bg-image" ' +
88 'href="javascript:void(0)" ' +
89 'style="background-image: url(/@@/person)">' +
90- assign_me_button_text + '</a>');
91+ this._assign_me_button_text + '</a>');
92 assign_me_button.on('click', this.assign_me, this);
93 this._extra_buttons.appendChild(assign_me_button);
94 this.assign_me_button = assign_me_button;
95
96=== modified file 'lib/lp/app/javascript/picker_patcher.js'
97--- lib/lp/app/javascript/picker_patcher.js 2011-07-06 03:20:46 +0000
98+++ lib/lp/app/javascript/picker_patcher.js 2011-07-06 14:16:29 +0000
99@@ -21,6 +21,7 @@
100 * @param {Object} config Object literal of config name/value pairs.
101 * config.header: a line of text at the top of the widget.
102 * config.step_title: overrides the subtitle.
103+ * config.assign_button_text: Override the default 'Assign' text.
104 * config.remove_button_text: Override the default 'Remove' text.
105 * config.null_display_value: Override the default 'None' text.
106 * config.show_remove_button: Should the remove button be shown?
107@@ -40,17 +41,12 @@
108
109 var show_remove_button = false;
110 var show_assign_me_button = false;
111- var remove_button_text = 'Remove';
112 var null_display_value = 'None';
113 var show_search_box = true;
114
115 resource_uri = Y.lp.client.normalize_uri(resource_uri);
116
117 if (config !== undefined) {
118- if (config.remove_button_text !== undefined) {
119- remove_button_text = config.remove_button_text;
120- }
121-
122 if (config.null_display_value !== undefined) {
123 null_display_value = config.null_display_value;
124 }
125
126=== modified file 'lib/lp/app/javascript/tests/test_picker.js'
127--- lib/lp/app/javascript/tests/test_picker.js 2011-07-06 03:20:46 +0000
128+++ lib/lp/app/javascript/tests/test_picker.js 2011-07-06 14:16:29 +0000
129@@ -79,7 +79,6 @@
130 {
131 "step_title": "Choose someone",
132 "header": "Pick Someone",
133- "remove_button_text": "Remove someone",
134 "null_display_value": "Noone",
135 "validate_callback": validate_callback
136 });
137@@ -280,7 +279,8 @@
138 delete window.LP;
139 },
140
141- create_picker: function(show_assign_me, show_remove, field_value) {
142+ create_picker: function(
143+ show_assign_me_button, show_remove_button, field_value) {
144 if (field_value !== undefined) {
145 var data_box = Y.one('#picker_id .yui3-activator-data-box');
146 data_box.appendChild(Y.Node.create('<a>Content</a>'));
147@@ -292,8 +292,10 @@
148 "header": "Pick Someone",
149 "validate_callback": null,
150 "show_search_box": true,
151- "show_assign_me_button": show_assign_me,
152- "show_remove_button": show_remove
153+ "show_assign_me_button": show_assign_me_button,
154+ "show_remove_button": show_remove_button,
155+ "assign_button_text": "Assign Moi",
156+ "remove_button_text": "Remove someone"
157 };
158 this.picker = Y.lp.app.picker.addPickerPatcher(
159 this.vocabulary,
160@@ -325,6 +327,22 @@
161 this._check_button_state('.yui-picker-remove-button', is_visible);
162 },
163
164+ test_picker_assign_me_button_text: function() {
165+ // The assign me button text is correct.
166+ this.create_picker(true, true);
167+ this.picker.render();
168+ var assign_me_button = Y.one('.yui-picker-assign-me-button');
169+ Assert.areEqual('Assign Moi', assign_me_button.get('innerHTML'));
170+ },
171+
172+ test_picker_remove_button_text: function() {
173+ // The remove button text is correct.
174+ this.create_picker(true, true);
175+ this.picker.render();
176+ var remove_button = Y.one('.yui-picker-remove-button');
177+ Assert.areEqual('Remove someone', remove_button.get('innerHTML'));
178+ },
179+
180 test_picker_has_assign_me_button: function() {
181 // The assign me button is shown.
182 this.create_picker(true, true);
183
184=== modified file 'lib/lp/app/widgets/popup.py'
185--- lib/lp/app/widgets/popup.py 2011-07-06 00:41:28 +0000
186+++ lib/lp/app/widgets/popup.py 2011-07-06 14:16:29 +0000
187@@ -28,6 +28,11 @@
188 __call__ = ViewPageTemplateFile('templates/form-picker.pt')
189
190 picker_type = 'default'
191+ # Provide default values for the following properties in case someone
192+ # creates a vocab picker for a person instead if using the derived
193+ # PersonPicker.
194+ show_assign_me_button = 'false'
195+ show_remove_button = 'false'
196
197 popup_name = 'popup-vocabulary-picker'
198
199@@ -159,6 +164,8 @@
200 class PersonPickerWidget(VocabularyPickerWidget):
201
202 include_create_team_link = False
203+ show_assign_me_button = 'true'
204+ show_remove_button = 'true'
205
206 @property
207 def picker_type(self):
208
209=== modified file 'lib/lp/app/widgets/templates/form-picker-macros.pt'
210--- lib/lp/app/widgets/templates/form-picker-macros.pt 2011-07-06 03:20:46 +0000
211+++ lib/lp/app/widgets/templates/form-picker-macros.pt 2011-07-06 14:16:29 +0000
212@@ -43,6 +43,10 @@
213 extra_no_results_message: ${view/extra_no_results_message},
214 picker_type: '${view/picker_type}'
215 };
216+ if (config.picker_type == 'person') {
217+ config.show_assign_me_button = ${view/show_assign_me_button}
218+ config.show_remove_button = ${view/show_remove_button}
219+ }
220 var picker = Y.lp.app.picker.create('${view/vocabulary_name}', config);
221 if (config.extra_no_results_message !== null) {
222 picker.before('resultsChange', function (e) {
223
224=== modified file 'lib/lp/bugs/javascript/bugtask_index.js'
225--- lib/lp/bugs/javascript/bugtask_index.js 2011-07-06 00:41:28 +0000
226+++ lib/lp/bugs/javascript/bugtask_index.js 2011-07-06 14:16:29 +0000
227@@ -894,6 +894,7 @@
228 assignee_content.get('id'),
229 {"step_title": step_title,
230 "header": "Change assignee",
231+ "assign_button_text": "Assign Me",
232 "remove_button_text": "Remove assignee",
233 "null_display_value": "Unassigned",
234 "show_remove_button": conf.user_can_unassign,
235
236=== modified file 'lib/lp/code/browser/sourcepackagerecipe.py'
237--- lib/lp/code/browser/sourcepackagerecipe.py 2011-07-06 00:41:28 +0000
238+++ lib/lp/code/browser/sourcepackagerecipe.py 2011-07-06 14:16:29 +0000
239@@ -106,6 +106,7 @@
240 from lp.code.model.branchtarget import PersonBranchTarget
241 from lp.code.model.sourcepackagerecipe import get_buildable_distroseries_set
242 from lp.registry.interfaces.series import SeriesStatus
243+from lp.services.fields import PersonChoice
244 from lp.services.propertycache import cachedproperty
245 from lp.soyuz.model.archive import Archive
246
247@@ -840,7 +841,7 @@
248 self.form_fields = self.form_fields.omit('daily_build_archive')
249
250 owner_field = self.schema['owner']
251- any_owner_choice = Choice(
252+ any_owner_choice = PersonChoice(
253 __name__='owner', title=owner_field.title,
254 description=(u"As an administrator you are able to reassign"
255 u" this branch to any person or team."),
256
257=== modified file 'lib/lp/registry/browser/team.py'
258--- lib/lp/registry/browser/team.py 2011-07-06 00:41:28 +0000
259+++ lib/lp/registry/browser/team.py 2011-07-06 14:16:29 +0000
260@@ -70,6 +70,7 @@
261 LaunchpadRadioWidgetWithDescription,
262 )
263 from lp.app.widgets.owner import HiddenUserWidget
264+from lp.app.widgets.popup import PersonPickerWidget
265 from lp.registry.browser.branding import BrandingChangeView
266 from lp.registry.interfaces.mailinglist import (
267 IMailingList,
268@@ -983,8 +984,7 @@
269 failed_names = [person.displayname for person in failed_joins]
270 failed_list = ", ".join(failed_names)
271
272- mapping=dict(
273- this_team=target_team.displayname,
274+ mapping = dict( this_team=target_team.displayname,
275 failed_list=failed_list)
276
277 if len(failed_joins) == 1:
278@@ -1034,6 +1034,13 @@
279
280 schema = ITeamMember
281 label = "Select the new member"
282+ # XXX: jcsackett 5.7.2011 The assignment of 'false' to the vars below
283+ # should be changed to the more appropriate False bool when we're making
284+ # use of the JSON cache to setup pickers, rather than assembling
285+ # javascript in a a view hacro.
286+ custom_widget(
287+ 'newmember', PersonPickerWidget,
288+ show_assign_me_button='false', show_remove_button='false')
289
290 @property
291 def page_title(self):