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
=== modified file 'lib/canonical/launchpad/javascript/bugs/bugtask-index.js'
--- lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-08-10 12:12:00 +0000
+++ lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-08-13 12:49:50 +0000
@@ -29,7 +29,6 @@
2929
30// Overlay related vars.30// Overlay related vars.
31var error_overlay;31var error_overlay;
32var form_load_callbacks = {};
33var submit_button_html =32var submit_button_html =
34 '<button type="submit" name="field.actions.change" ' +33 '<button type="submit" name="field.actions.change" ' +
35 'value="Change" class="lazr-pos lazr-btn" >OK</button>';34 'value="Change" class="lazr-pos lazr-btn" >OK</button>';
@@ -130,10 +129,6 @@
130 setup_client_and_bug();129 setup_client_and_bug();
131 }130 }
132131
133 Y.on('io:complete', function(id, response_object) {
134 form_load_callbacks[id](response_object.responseText);
135 }, this);
136
137 // First look for 'Mark as duplicate' links.132 // First look for 'Mark as duplicate' links.
138 var update_dupe_links = Y.all('.menu-link-mark-dupe');133 var update_dupe_links = Y.all('.menu-link-mark-dupe');
139134
@@ -146,8 +141,20 @@
146 // First things first, pre-load the mark-dupe form.141 // First things first, pre-load the mark-dupe form.
147 update_dupe_url = update_dupe_links.item(0).getAttribute('href');142 update_dupe_url = update_dupe_links.item(0).getAttribute('href');
148 var mark_dupe_form_url = update_dupe_url + '/++form++';143 var mark_dupe_form_url = update_dupe_url + '/++form++';
149 var dupe_form_id = Y.io(mark_dupe_form_url);144
150 form_load_callbacks[dupe_form_id.id] = createBugDuplicateFormOverlay;145 duplicate_form_overlay = new Y.lazr.FormOverlay({
146 headerContent: '<h2>Mark bug report as duplicate</h2>',
147 form_header: 'Marking the bug as a duplicate will, by default, ' +
148 'hide it from search results listings.',
149 form_submit_button: Y.Node.create(submit_button_html),
150 form_cancel_button: Y.Node.create(cancel_button_html),
151 centered: true,
152 form_submit_callback: update_bug_duplicate,
153 visible: false
154 });
155 duplicate_form_overlay.render('#duplicate-form-container');
156 duplicate_form_overlay.loadFormContentAndRender(
157 mark_dupe_form_url);
151158
152 // Add an on-click handler to any links found that displays159 // Add an on-click handler to any links found that displays
153 // the form overlay.160 // the form overlay.
@@ -179,8 +186,18 @@
179 privacy_spinner = Y.Node.create(186 privacy_spinner = Y.Node.create(
180 '<img src="/@@/spinner" style="display: none" />');187 '<img src="/@@/spinner" style="display: none" />');
181 privacy_text.appendChild(privacy_spinner);188 privacy_text.appendChild(privacy_spinner);
182 var privacy_form_id = Y.io(privacy_link_url);189
183 form_load_callbacks[privacy_form_id.id] = create_privacy_form_overlay;190
191 privacy_form_overlay = new Y.lazr.FormOverlay({
192 headerContent: '<h2>Change privacy settings</h2>',
193 form_submit_button: Y.Node.create(submit_button_html),
194 form_cancel_button: Y.Node.create(cancel_button_html),
195 centered: true,
196 form_submit_callback: update_privacy_settings,
197 visible: false
198 });
199 privacy_form_overlay.render('#privacy-form-container');
200 privacy_form_overlay.loadFormContentAndRender(privacy_link_url);
184 privacy_link.on('click', function(e) {201 privacy_link.on('click', function(e) {
185 if (privacy_form_overlay) {202 if (privacy_form_overlay) {
186 e.preventDefault();203 e.preventDefault();
@@ -330,26 +347,6 @@
330}347}
331348
332/*349/*
333 * Creates the duplicate form overlay using the passed form content.
334 *
335 * @method createBugDuplicateFormOverlay
336 */
337function createBugDuplicateFormOverlay(form_content) {
338 duplicate_form_overlay = new Y.lazr.FormOverlay({
339 headerContent: '<h2>Mark bug report as duplicate</h2>',
340 form_header: 'Marking the bug as a duplicate will, by default, ' +
341 'hide it from search results listings.',
342 form_content: form_content,
343 form_submit_button: Y.Node.create(submit_button_html),
344 form_cancel_button: Y.Node.create(cancel_button_html),
345 centered: true,
346 form_submit_callback: update_bug_duplicate,
347 visible: false
348 });
349 duplicate_form_overlay.render('#duplicate-form-container');
350}
351
352/*
353 * Update the bug duplicate via the LP API350 * Update the bug duplicate via the LP API
354 */351 */
355function update_bug_duplicate(data) {352function update_bug_duplicate(data) {
@@ -473,27 +470,6 @@
473};470};
474471
475472
476/*
477 * Create the privacy settings form overlay.
478 *
479 * @method create_privacy_form_overlay
480 * @param form_content {String} The HTML data of the form overlay.
481 */
482var create_privacy_form_overlay = function(form_content) {
483 privacy_form_overlay = new Y.lazr.FormOverlay({
484 headerContent: '<h2>Change privacy settings</h2>',
485 form_header: '',
486 form_content: form_content,
487 form_submit_button: Y.Node.create(submit_button_html),
488 form_cancel_button: Y.Node.create(cancel_button_html),
489 centered: true,
490 form_submit_callback: update_privacy_settings,
491 visible: false
492 });
493 privacy_form_overlay.render('#privacy-form-container');
494 var node = Y.get('#form-container');
495};
496
497var update_privacy_settings = function(data) {473var update_privacy_settings = function(data) {
498 // XXX noodles 2009-03-17 bug=336866 It seems the etag474 // XXX noodles 2009-03-17 bug=336866 It seems the etag
499 // returned by lp_save() is incorrect. Remove it for now475 // returned by lp_save() is incorrect. Remove it for now
500476
=== modified file 'lib/canonical/launchpad/javascript/code/branchlinks.js'
--- lib/canonical/launchpad/javascript/code/branchlinks.js 2009-07-28 22:05:34 +0000
+++ lib/canonical/launchpad/javascript/code/branchlinks.js 2009-08-13 13:16:04 +0000
@@ -32,8 +32,6 @@
3232
33 link_bug_overlay = new Y.lazr.FormOverlay({33 link_bug_overlay = new Y.lazr.FormOverlay({
34 headerContent: '<h2>Link to a bug</h2>',34 headerContent: '<h2>Link to a bug</h2>',
35 form_content: Y.Node.create(
36 '<div id="bugnumberform"></div>'),
37 form_submit_button: Y.Node.create(35 form_submit_button: Y.Node.create(
38 '<button type="submit" name="buglink.actions.change" ' +36 '<button type="submit" name="buglink.actions.change" ' +
39 'value="Change" class="lazr-pos lazr-btn">Ok</button>'),37 'value="Change" class="lazr-pos lazr-btn">Ok</button>'),
@@ -45,18 +43,7 @@
45 visible: false43 visible: false
46 });44 });
47 link_bug_overlay.render();45 link_bug_overlay.render();
48 Y.io('+linkbug/++form++', {46 link_bug_overlay.loadFormContentAndRender('+linkbug/++form++');
49 on: {
50 success: function(id, response) {
51 Y.get('#bugnumberform').set(
52 'innerHTML', response.responseText);
53 },
54 failure: function(id, response) {
55 Y.get('#bugnumberform').set(
56 'innerHTML', 'A problem has occurred.');
57 Y.log(reponse.responseText);
58 }}});
59
60 var linkbug_handle = Y.get('#linkbug');47 var linkbug_handle = Y.get('#linkbug');
61 linkbug_handle.addClass('js-action');48 linkbug_handle.addClass('js-action');
62 linkbug_handle.on('click', function(e) {49 linkbug_handle.on('click', function(e) {
6350
=== modified file 'lib/canonical/launchpad/javascript/code/branchsubscription.js'
--- lib/canonical/launchpad/javascript/code/branchsubscription.js 2009-07-14 06:13:02 +0000
+++ lib/canonical/launchpad/javascript/code/branchsubscription.js 2009-08-13 13:47:24 +0000
@@ -69,30 +69,6 @@
69 return element.getAttribute('href');69 return element.getAttribute('href');
70}70}
7171
72function create_self_subscription_form_overlay(form_content) {
73 subscription_form_overlay = new Y.lazr.FormOverlay({
74 headerContent: '<h2>Subscribe to branch</h2>',
75 form_content: form_content,
76 form_submit_button: Y.Node.create(
77 '<button type="submit" name="field.actions.change" ' +
78 'value="Change" class="lazr-pos lazr-btn">Ok</button>'),
79 form_cancel_button: Y.Node.create(
80 '<button type="button" name="field.actions.cancel" ' +
81 'class="lazr-neg lazr-btn">Cancel</button>'),
82 centered: true,
83 form_submit_callback: subscribe_yourself_inline,
84 visible: false
85 });
86 subscription_form_overlay.render();
87
88 /* XXX: rockstar - bug=389185 - The form is a bit wide for the current
89 * form overlay, and there isn't an easy way to resize it, thus this hack.
90 */
91 Y.get('#shadow').setStyle('width', '562px');
92 Y.get('div#yui-pretty-overlay-modal.content_box_container').setStyle(
93 'width', '500px');
94}
95
96/*72/*
97 * Handle the submission of the form overlay.73 * Handle the submission of the form overlay.
98 */74 */
@@ -163,15 +139,28 @@
163139
164 update_subscription_url = get_element_href(subscribe_yourself);140 update_subscription_url = get_element_href(subscribe_yourself);
165 var subscription_form_url = update_subscription_url + '/++form++';141 var subscription_form_url = update_subscription_url + '/++form++';
166 Y.io(subscription_form_url, {142 subscription_form_overlay = new Y.lazr.FormOverlay({
167 on: {143 headerContent: '<h2>Subscribe to branch</h2>',
168 success: function(id, response) {144 form_submit_button: Y.Node.create(
169 create_self_subscription_form_overlay(145 '<button type="submit" name="field.actions.change" ' +
170 response.responseText);146 'value="Change" class="lazr-pos lazr-btn">Ok</button>'),
171 },147 form_cancel_button: Y.Node.create(
172 failure: function(id, response) {148 '<button type="button" name="field.actions.cancel" ' +
173 Y.log(response.responseText);149 'class="lazr-neg lazr-btn">Cancel</button>'),
174 }}});150 centered: true,
151 form_submit_callback: subscribe_yourself_inline,
152 visible: false
153 });
154 subscription_form_overlay.render();
155 subscription_form_overlay.loadFormContentAndRender(
156 subscription_form_url);
157
158 /* XXX: rockstar - bug=389185 - The form is a bit wide for the current
159 * form overlay, and there isn't an easy way to resize it, thus this hack.
160 */
161 Y.get('#shadow').setStyle('width', '562px');
162 Y.get('div#yui-pretty-overlay-modal.content_box_container').setStyle(
163 'width', '500px');
175 subscribe_yourself.addClass('js-action');164 subscribe_yourself.addClass('js-action');
176 subscribe_yourself.on('click', function(e) {165 subscribe_yourself.on('click', function(e) {
177 e.preventDefault();166 e.preventDefault();
178167
=== modified file 'lib/canonical/launchpad/javascript/registry/milestoneoverlay.js'
--- lib/canonical/launchpad/javascript/registry/milestoneoverlay.js 2009-07-17 00:26:05 +0000
+++ lib/canonical/launchpad/javascript/registry/milestoneoverlay.js 2009-08-13 13:36:02 +0000
@@ -15,31 +15,6 @@
15 var series_uri;15 var series_uri;
16 var next_step;16 var next_step;
1717
18 var error_box_html =
19 '<div style="margin: 2em">' +
20 '<p id="milestone-error" class="error message" ' +
21 'style="width: 80%; display:none; ' +
22 'padding-left: 1.5em; padding-right: 1.5em;" />' +
23 '</div>';
24
25 var create_form_overlay = function (id, response, args) {
26 var form_content = error_box_html + response.responseText;
27 var form_submit_button = Y.Node.create(
28 '<input type="submit" name="field.actions.register" ' +
29 'id="formoverlay-add-milestone" value="Create Milestone"/>');
30 milestone_form = new Y.lazr.FormOverlay({
31 headerContent: '<h2>Create Milestone</h2>',
32 form_content: form_content,
33 form_submit_button: form_submit_button,
34 centered: true,
35 form_submit_callback: save_new_milestone,
36 visible: false
37 });
38 milestone_form.render();
39 Y.lp.add_calendar_widgets();
40 milestone_form.show();
41 };
42
43 var save_new_milestone = function(data) {18 var save_new_milestone = function(data) {
4419
45 var parameters = {20 var parameters = {
@@ -54,9 +29,7 @@
54 }29 }
5530
56 var finish_new_milestone = function(ignore) {31 var finish_new_milestone = function(ignore) {
57 var error_box = Y.get('#milestone-error');32 milestone_form.clearError();
58 error_box.set('innerHTML', '');
59 error_box.setStyle('display', 'none');
60 milestone_form.hide();33 milestone_form.hide();
61 // Reset the HTML form inside the widget.34 // Reset the HTML form inside the widget.
62 milestone_form.get('contentBox').query('form').reset();35 milestone_form.get('contentBox').query('form').reset();
@@ -74,8 +47,7 @@
74 '</strong><p>' +47 '</strong><p>' +
75 response.responseText +48 response.responseText +
76 '</p>';49 '</p>';
77 error_box.set('innerHTML', error_message);50 milestone_form.showError(error_message);
78 error_box.setStyle('display', 'block');
79 }51 }
80 }52 }
81 });53 });
@@ -83,33 +55,20 @@
8355
8456
85 var setup_milestone_form = function () {57 var setup_milestone_form = function () {
86 Y.io(milestone_form_uri, {58 var form_submit_button = Y.Node.create(
87 on: {59 '<input type="submit" name="field.actions.register" ' +
88 success: create_form_overlay,60 'id="formoverlay-add-milestone" value="Create Milestone"/>');
89 failure: function (ignore, response, args) {61 milestone_form = new Y.lazr.FormOverlay({
90 var error_page = Y.Node.create('<div/>');62 headerContent: '<h2>Create Milestone</h2>',
91 error_page.setStyle('position', 'absolute');63 form_submit_button: form_submit_button,
92 error_page.setStyle('top', '0');64 centered: true,
93 error_page.setStyle('bottom', '0');65 form_submit_callback: save_new_milestone,
94 error_page.setStyle('left', '0');66 visible: false
95 error_page.setStyle('right', '0');
96 error_page.setStyle('margin', 'auto');
97 error_page.setStyle('width', '80%');
98 error_page.setStyle('height', '80%');
99 error_page.setStyle('overflow', 'auto');
100 error_page.setStyle('background', 'white');
101 error_page.setStyle('padding', '1em');
102 error_page.setStyle('border', '3px solid black');
103 var error_message = '<strong>' + response.statusText +
104 '</strong><p>' +
105 response.responseText +
106 '</p>';
107 error_page.set('innerHTML', error_message);
108 var body = Y.get('body');
109 body.appendChild(error_page);
110 }
111 }
112 });67 });
68 milestone_form.render();
69 milestone_form.loadFormContentAndRender(milestone_form_uri);
70 Y.lp.add_calendar_widgets();
71 milestone_form.show();
113 };72 };
11473
115 show_milestone_form = function(e) {74 show_milestone_form = function(e) {