Merge lp://staging/~bjornt/launchpad/form-overlay-load-external into lp://staging/launchpad

Proposed by Björn Tillenius
Status: Merged
Merged at revision: not available
Proposed branch: lp://staging/~bjornt/launchpad/form-overlay-load-external
Merge into: lp://staging/launchpad
Diff against target: None lines
To merge this branch: bzr merge lp://staging/~bjornt/launchpad/form-overlay-load-external
Reviewer Review Type Date Requested Status
Abel Deuring (community) Approve
Review via email: mp+10097@code.staging.launchpad.net
To post a comment you must log in.
Revision history for this message
Björn Tillenius (bjornt) wrote :

Change all overlays that load the content using ++form++ to use the new
loadFormContentAndRender() method.

I've updated all callsites I could find, which meant I could remove a
lot of custom io callback handling.

I also updated the milestone overlay to use showError() for its error
handling, since it would be hard to make it use
loadFormContentAndRender(). It should use showError() anyway to be
consistent with other overlays.

loadFormContentAndRender() was added to lazr-js in r119.

--
Björn Tillenius | https://launchpad.net/~bjornt

Revision history for this message
Abel Deuring (adeuring) wrote :

Hi Björn,

a nice cleanup branch!

Abel

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/canonical/launchpad/javascript/bugs/bugtask-index.js'
2--- lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-08-10 12:12:00 +0000
3+++ lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-08-13 12:49:50 +0000
4@@ -29,7 +29,6 @@
5
6 // Overlay related vars.
7 var error_overlay;
8-var form_load_callbacks = {};
9 var submit_button_html =
10 '<button type="submit" name="field.actions.change" ' +
11 'value="Change" class="lazr-pos lazr-btn" >OK</button>';
12@@ -130,10 +129,6 @@
13 setup_client_and_bug();
14 }
15
16- Y.on('io:complete', function(id, response_object) {
17- form_load_callbacks[id](response_object.responseText);
18- }, this);
19-
20 // First look for 'Mark as duplicate' links.
21 var update_dupe_links = Y.all('.menu-link-mark-dupe');
22
23@@ -146,8 +141,20 @@
24 // First things first, pre-load the mark-dupe form.
25 update_dupe_url = update_dupe_links.item(0).getAttribute('href');
26 var mark_dupe_form_url = update_dupe_url + '/++form++';
27- var dupe_form_id = Y.io(mark_dupe_form_url);
28- form_load_callbacks[dupe_form_id.id] = createBugDuplicateFormOverlay;
29+
30+ duplicate_form_overlay = new Y.lazr.FormOverlay({
31+ headerContent: '<h2>Mark bug report as duplicate</h2>',
32+ form_header: 'Marking the bug as a duplicate will, by default, ' +
33+ 'hide it from search results listings.',
34+ form_submit_button: Y.Node.create(submit_button_html),
35+ form_cancel_button: Y.Node.create(cancel_button_html),
36+ centered: true,
37+ form_submit_callback: update_bug_duplicate,
38+ visible: false
39+ });
40+ duplicate_form_overlay.render('#duplicate-form-container');
41+ duplicate_form_overlay.loadFormContentAndRender(
42+ mark_dupe_form_url);
43
44 // Add an on-click handler to any links found that displays
45 // the form overlay.
46@@ -179,8 +186,18 @@
47 privacy_spinner = Y.Node.create(
48 '<img src="/@@/spinner" style="display: none" />');
49 privacy_text.appendChild(privacy_spinner);
50- var privacy_form_id = Y.io(privacy_link_url);
51- form_load_callbacks[privacy_form_id.id] = create_privacy_form_overlay;
52+
53+
54+ privacy_form_overlay = new Y.lazr.FormOverlay({
55+ headerContent: '<h2>Change privacy settings</h2>',
56+ form_submit_button: Y.Node.create(submit_button_html),
57+ form_cancel_button: Y.Node.create(cancel_button_html),
58+ centered: true,
59+ form_submit_callback: update_privacy_settings,
60+ visible: false
61+ });
62+ privacy_form_overlay.render('#privacy-form-container');
63+ privacy_form_overlay.loadFormContentAndRender(privacy_link_url);
64 privacy_link.on('click', function(e) {
65 if (privacy_form_overlay) {
66 e.preventDefault();
67@@ -330,26 +347,6 @@
68 }
69
70 /*
71- * Creates the duplicate form overlay using the passed form content.
72- *
73- * @method createBugDuplicateFormOverlay
74- */
75-function createBugDuplicateFormOverlay(form_content) {
76- duplicate_form_overlay = new Y.lazr.FormOverlay({
77- headerContent: '<h2>Mark bug report as duplicate</h2>',
78- form_header: 'Marking the bug as a duplicate will, by default, ' +
79- 'hide it from search results listings.',
80- form_content: form_content,
81- form_submit_button: Y.Node.create(submit_button_html),
82- form_cancel_button: Y.Node.create(cancel_button_html),
83- centered: true,
84- form_submit_callback: update_bug_duplicate,
85- visible: false
86- });
87- duplicate_form_overlay.render('#duplicate-form-container');
88-}
89-
90-/*
91 * Update the bug duplicate via the LP API
92 */
93 function update_bug_duplicate(data) {
94@@ -473,27 +470,6 @@
95 };
96
97
98-/*
99- * Create the privacy settings form overlay.
100- *
101- * @method create_privacy_form_overlay
102- * @param form_content {String} The HTML data of the form overlay.
103- */
104-var create_privacy_form_overlay = function(form_content) {
105- privacy_form_overlay = new Y.lazr.FormOverlay({
106- headerContent: '<h2>Change privacy settings</h2>',
107- form_header: '',
108- form_content: form_content,
109- form_submit_button: Y.Node.create(submit_button_html),
110- form_cancel_button: Y.Node.create(cancel_button_html),
111- centered: true,
112- form_submit_callback: update_privacy_settings,
113- visible: false
114- });
115- privacy_form_overlay.render('#privacy-form-container');
116- var node = Y.get('#form-container');
117-};
118-
119 var update_privacy_settings = function(data) {
120 // XXX noodles 2009-03-17 bug=336866 It seems the etag
121 // returned by lp_save() is incorrect. Remove it for now
122
123=== modified file 'lib/canonical/launchpad/javascript/code/branchlinks.js'
124--- lib/canonical/launchpad/javascript/code/branchlinks.js 2009-07-28 22:05:34 +0000
125+++ lib/canonical/launchpad/javascript/code/branchlinks.js 2009-08-13 13:16:04 +0000
126@@ -32,8 +32,6 @@
127
128 link_bug_overlay = new Y.lazr.FormOverlay({
129 headerContent: '<h2>Link to a bug</h2>',
130- form_content: Y.Node.create(
131- '<div id="bugnumberform"></div>'),
132 form_submit_button: Y.Node.create(
133 '<button type="submit" name="buglink.actions.change" ' +
134 'value="Change" class="lazr-pos lazr-btn">Ok</button>'),
135@@ -45,18 +43,7 @@
136 visible: false
137 });
138 link_bug_overlay.render();
139- Y.io('+linkbug/++form++', {
140- on: {
141- success: function(id, response) {
142- Y.get('#bugnumberform').set(
143- 'innerHTML', response.responseText);
144- },
145- failure: function(id, response) {
146- Y.get('#bugnumberform').set(
147- 'innerHTML', 'A problem has occurred.');
148- Y.log(reponse.responseText);
149- }}});
150-
151+ link_bug_overlay.loadFormContentAndRender('+linkbug/++form++');
152 var linkbug_handle = Y.get('#linkbug');
153 linkbug_handle.addClass('js-action');
154 linkbug_handle.on('click', function(e) {
155
156=== modified file 'lib/canonical/launchpad/javascript/code/branchsubscription.js'
157--- lib/canonical/launchpad/javascript/code/branchsubscription.js 2009-07-14 06:13:02 +0000
158+++ lib/canonical/launchpad/javascript/code/branchsubscription.js 2009-08-13 13:47:24 +0000
159@@ -69,30 +69,6 @@
160 return element.getAttribute('href');
161 }
162
163-function create_self_subscription_form_overlay(form_content) {
164- subscription_form_overlay = new Y.lazr.FormOverlay({
165- headerContent: '<h2>Subscribe to branch</h2>',
166- form_content: form_content,
167- form_submit_button: Y.Node.create(
168- '<button type="submit" name="field.actions.change" ' +
169- 'value="Change" class="lazr-pos lazr-btn">Ok</button>'),
170- form_cancel_button: Y.Node.create(
171- '<button type="button" name="field.actions.cancel" ' +
172- 'class="lazr-neg lazr-btn">Cancel</button>'),
173- centered: true,
174- form_submit_callback: subscribe_yourself_inline,
175- visible: false
176- });
177- subscription_form_overlay.render();
178-
179- /* XXX: rockstar - bug=389185 - The form is a bit wide for the current
180- * form overlay, and there isn't an easy way to resize it, thus this hack.
181- */
182- Y.get('#shadow').setStyle('width', '562px');
183- Y.get('div#yui-pretty-overlay-modal.content_box_container').setStyle(
184- 'width', '500px');
185-}
186-
187 /*
188 * Handle the submission of the form overlay.
189 */
190@@ -163,15 +139,28 @@
191
192 update_subscription_url = get_element_href(subscribe_yourself);
193 var subscription_form_url = update_subscription_url + '/++form++';
194- Y.io(subscription_form_url, {
195- on: {
196- success: function(id, response) {
197- create_self_subscription_form_overlay(
198- response.responseText);
199- },
200- failure: function(id, response) {
201- Y.log(response.responseText);
202- }}});
203+ subscription_form_overlay = new Y.lazr.FormOverlay({
204+ headerContent: '<h2>Subscribe to branch</h2>',
205+ form_submit_button: Y.Node.create(
206+ '<button type="submit" name="field.actions.change" ' +
207+ 'value="Change" class="lazr-pos lazr-btn">Ok</button>'),
208+ form_cancel_button: Y.Node.create(
209+ '<button type="button" name="field.actions.cancel" ' +
210+ 'class="lazr-neg lazr-btn">Cancel</button>'),
211+ centered: true,
212+ form_submit_callback: subscribe_yourself_inline,
213+ visible: false
214+ });
215+ subscription_form_overlay.render();
216+ subscription_form_overlay.loadFormContentAndRender(
217+ subscription_form_url);
218+
219+ /* XXX: rockstar - bug=389185 - The form is a bit wide for the current
220+ * form overlay, and there isn't an easy way to resize it, thus this hack.
221+ */
222+ Y.get('#shadow').setStyle('width', '562px');
223+ Y.get('div#yui-pretty-overlay-modal.content_box_container').setStyle(
224+ 'width', '500px');
225 subscribe_yourself.addClass('js-action');
226 subscribe_yourself.on('click', function(e) {
227 e.preventDefault();
228
229=== modified file 'lib/canonical/launchpad/javascript/registry/milestoneoverlay.js'
230--- lib/canonical/launchpad/javascript/registry/milestoneoverlay.js 2009-07-17 00:26:05 +0000
231+++ lib/canonical/launchpad/javascript/registry/milestoneoverlay.js 2009-08-13 13:36:02 +0000
232@@ -15,31 +15,6 @@
233 var series_uri;
234 var next_step;
235
236- var error_box_html =
237- '<div style="margin: 2em">' +
238- '<p id="milestone-error" class="error message" ' +
239- 'style="width: 80%; display:none; ' +
240- 'padding-left: 1.5em; padding-right: 1.5em;" />' +
241- '</div>';
242-
243- var create_form_overlay = function (id, response, args) {
244- var form_content = error_box_html + response.responseText;
245- var form_submit_button = Y.Node.create(
246- '<input type="submit" name="field.actions.register" ' +
247- 'id="formoverlay-add-milestone" value="Create Milestone"/>');
248- milestone_form = new Y.lazr.FormOverlay({
249- headerContent: '<h2>Create Milestone</h2>',
250- form_content: form_content,
251- form_submit_button: form_submit_button,
252- centered: true,
253- form_submit_callback: save_new_milestone,
254- visible: false
255- });
256- milestone_form.render();
257- Y.lp.add_calendar_widgets();
258- milestone_form.show();
259- };
260-
261 var save_new_milestone = function(data) {
262
263 var parameters = {
264@@ -54,9 +29,7 @@
265 }
266
267 var finish_new_milestone = function(ignore) {
268- var error_box = Y.get('#milestone-error');
269- error_box.set('innerHTML', '');
270- error_box.setStyle('display', 'none');
271+ milestone_form.clearError();
272 milestone_form.hide();
273 // Reset the HTML form inside the widget.
274 milestone_form.get('contentBox').query('form').reset();
275@@ -74,8 +47,7 @@
276 '</strong><p>' +
277 response.responseText +
278 '</p>';
279- error_box.set('innerHTML', error_message);
280- error_box.setStyle('display', 'block');
281+ milestone_form.showError(error_message);
282 }
283 }
284 });
285@@ -83,33 +55,20 @@
286
287
288 var setup_milestone_form = function () {
289- Y.io(milestone_form_uri, {
290- on: {
291- success: create_form_overlay,
292- failure: function (ignore, response, args) {
293- var error_page = Y.Node.create('<div/>');
294- error_page.setStyle('position', 'absolute');
295- error_page.setStyle('top', '0');
296- error_page.setStyle('bottom', '0');
297- error_page.setStyle('left', '0');
298- error_page.setStyle('right', '0');
299- error_page.setStyle('margin', 'auto');
300- error_page.setStyle('width', '80%');
301- error_page.setStyle('height', '80%');
302- error_page.setStyle('overflow', 'auto');
303- error_page.setStyle('background', 'white');
304- error_page.setStyle('padding', '1em');
305- error_page.setStyle('border', '3px solid black');
306- var error_message = '<strong>' + response.statusText +
307- '</strong><p>' +
308- response.responseText +
309- '</p>';
310- error_page.set('innerHTML', error_message);
311- var body = Y.get('body');
312- body.appendChild(error_page);
313- }
314- }
315+ var form_submit_button = Y.Node.create(
316+ '<input type="submit" name="field.actions.register" ' +
317+ 'id="formoverlay-add-milestone" value="Create Milestone"/>');
318+ milestone_form = new Y.lazr.FormOverlay({
319+ headerContent: '<h2>Create Milestone</h2>',
320+ form_submit_button: form_submit_button,
321+ centered: true,
322+ form_submit_callback: save_new_milestone,
323+ visible: false
324 });
325+ milestone_form.render();
326+ milestone_form.loadFormContentAndRender(milestone_form_uri);
327+ Y.lp.add_calendar_widgets();
328+ milestone_form.show();
329 };
330
331 show_milestone_form = function(e) {