+/* If loading the subscriber IDs JSON has succeeded, set up the
+ * subscription link handlers and load the subscribers from dupes.
+ */
+Y.bugs.portlet.subscribe('bugs:portletsubscriberidsloaded', function() {
+ setup_subscription_link_handlers();
+ load_subscribers_from_duplicates();
+});
+
+/* If loading the subscriber IDs JSON fails we still need to load the
+ * subscribers from duplicates but we don't set up the subscription link
+ * handlers.
+ */
+Y.bugs.portlet.subscribe('bugs:portletsubscriberidsfailed', function() {
+ load_subscribers_from_duplicates();
+});
+
/*
* Subscribing someone else requires loading a grayed out
* username into the DOM until the subscribe action completes.
@@ -1806,35 +1821,44 @@ Y.bugs.portlet.fire('bugs:portletloaded');
}
- function load_subscriber_ids(transactionid, response, args) {
+function load_subscriber_ids() {
+ function on_success(transactionid, response, args) {
try {
- var subscriber_ids_node = Y.Node.create(
- response.responseText);
- var subscriber_ids_json = subscriber_ids_node.get('innerHTML');
- subscriber_ids = Y.JSON.parse(subscriber_ids_json);
+ subscriber_ids = Y.JSON.parse(response.responseText);
+ Y.log("Loaded subscriber IDs.");
+
+ // Fire a custom event to trigger the setting-up of the
+ // subscription handlers.
+ Y.bugs.portlet.fire('bugs:portletsubscriberidsloaded');
} catch (e) { Y.log("Unable to load subscriber ids.", "error");
+
+ // Fire an event to signal failure. This ensures that the
+ // subscribers-from-dupes still get loaded into the portlet.
+ Y.bugs.portlet.fire('bugs:portletsubscriberidsfailed');
}
-
- load_portlet();
- }
-
- var config = {on: {success: load_subscriber_ids,
- failure: load_portlet}};
+ }
+
+ function on_failure() {
+ // Fire an event to signal failure. This ensures that the
+ // subscribers-from-dupes still get loaded into the portlet.
+ Y.bugs.portlet.fire('bugs:portletsubscriberidsfailed');
+ }
+
+ var config = {on: {success: on_success,
+ failure: on_failure}};
var url = Y.get( '#subscribers-ids-link').getAttribute('href').replace('bugs.', '');
- Y.log("Getting ids from " + url);
Y.io(url, config);
-};
+}
Here's an incremental diff of the changes that Gavin suggested on IRC:
=== modified file 'lib/canonical/ launchpad/ javascript/ bugs/bugtask- index.js' launchpad/ javascript/ bugs/bugtask- index.js 2009-11-17 16:00:21 +0000 launchpad/ javascript/ bugs/bugtask- index.js 2009-11-18 15:20:12 +0000 PortletTarget, Y.Event.Target); portlet. subscribe( 'bugs:portletlo aded', function() { ion_link_ handlers( ); s_from_ duplicates( ); _ids(); portlet. subscribe( 'bugs:dupeportl etloaded' , function() { unsubscribe_ icon_handlers( ); unsubscribe_ icon_handlers( );
--- lib/canonical/
+++ lib/canonical/
@@ -54,8 +54,7 @@
Y.augment(
Y.bugs.portlet = new PortletTarget();
Y.bugs.
- setup_subscript
- load_subscriber
+ load_subscriber
});
Y.bugs.
setup_
@@ -78,6 +77,22 @@
setup_
});
+/* If loading the subscriber IDs JSON has succeeded, set up the portlet. subscribe( 'bugs:portletsu bscriberidsload ed', function() { ion_link_ handlers( ); s_from_ duplicates( ); portlet. subscribe( 'bugs:portletsu bscriberidsfail ed', function() { s_from_ duplicates( );
Y.bugs. portlet. fire('bugs: portletloaded' );
+ * subscription link handlers and load the subscribers from dupes.
+ */
+Y.bugs.
+ setup_subscript
+ load_subscriber
+});
+
+/* If loading the subscriber IDs JSON fails we still need to load the
+ * subscribers from duplicates but we don't set up the subscription link
+ * handlers.
+ */
+Y.bugs.
+ load_subscriber
+});
+
/*
* Subscribing someone else requires loading a grayed out
* username into the DOM until the subscribe action completes.
@@ -1806,35 +1821,44 @@
}
- function load_portlet() { content- link'). getAttribute( 'href') .replace( content- link'). getAttribute( 'href') .replace(
- var config = {on: {success: setup_portlet,
- failure: hide_spinner}};
- var url = Y.get(
- '#subscribers-
- 'bugs.', '');
- Y.io(url, config);
- }
+ var config = {on: {success: setup_portlet,
+ failure: hide_spinner}};
+ var url = Y.get(
+ '#subscribers-
+ 'bugs.', '');
+ Y.io(url, config);
+};
- function load_subscriber _ids(transactio nid, response, args) { _ids() { transactionid, response, args) { responseText) ; ids_node. get('innerHTML' ); parse(subscribe r_ids_json) ; parse(response. responseText) ; portlet. fire('bugs: portletsubscrib eridsloaded' );
Y. log("Unable to load subscriber ids.", "error"); from-dupes still get loaded into the portlet. portlet. fire('bugs: portletsubscrib eridsfailed' ); _ids, from-dupes still get loaded into the portlet. portlet. fire('bugs: portletsubscrib eridsfailed' );
'#subscribers -ids-link' ).getAttribute( 'href') .replace( 'bugs.' , '');
+function load_subscriber
+ function on_success(
try {
- var subscriber_ids_node = Y.Node.create(
- response.
- var subscriber_ids_json = subscriber_
- subscriber_ids = Y.JSON.
+ subscriber_ids = Y.JSON.
+ Y.log("Loaded subscriber IDs.");
+
+ // Fire a custom event to trigger the setting-up of the
+ // subscription handlers.
+ Y.bugs.
} catch (e) {
+
+ // Fire an event to signal failure. This ensures that the
+ // subscribers-
+ Y.bugs.
}
-
- load_portlet();
- }
-
- var config = {on: {success: load_subscriber
- failure: load_portlet}};
+ }
+
+ function on_failure() {
+ // Fire an event to signal failure. This ensures that the
+ // subscribers-
+ Y.bugs.
+ }
+
+ var config = {on: {success: on_success,
+ failure: on_failure}};
var url = Y.get(
- Y.log("Getting ids from " + url);
Y.io(url, config);
-};
+}
}, '0.1', {requires: ['base', 'oop', 'node', 'event', 'io-base', 'json-parse',
'substitute' , 'widget- position- ext',
=== modified file 'lib/lp/ bugs/browser/ bugsubscription .py' bugs/browser/ bugsubscription .py 2009-11-17 14:58:39 +0000 bugs/browser/ bugsubscription .py 2009-11-18 15:20:12 +0000 subscriber_ ids)
--- lib/lp/
+++ lib/lp/
@@ -106,6 +106,10 @@
"""Return subscriber_ids in a form suitable for JavaScript use."""
return dumps(self.
+ def render(self): _ids_js
+ """Override the default render() to return only JSON."""
+ return self.subscriber
+
class SubscriptionAtt rDecorator:
"""A BugSubscription with added attributes for HTML/JS."""
=== modified file 'lib/lp/ bugs/browser/ configure. zcml' bugs/browser/ configure. zcml 2009-11-17 14:58:39 +0000 bugs/browser/ configure. zcml 2009-11-18 15:20:12 +0000
for= "lp.bugs. interfaces. bug.IBug"
name= "+bug-portlet- subscribers- ids"
class= "lp.bugs. browser. bugsubscription .BugPortletSubc ribersIds" "../templates/ bug-portlet- subscribers- ids.pt"
permissio n="zope. Public" />
<browser: navigation
module= "lp.bugs. browser. bug"
--- lib/lp/
+++ lib/lp/
@@ -1008,7 +1008,6 @@
- template=
=== removed file 'lib/lp/ bugs/templates/ bug-portlet- subscribers- ids.pt' bugs/templates/ bug-portlet- subscribers- ids.pt 2009-11-17 14:58:39 +0000 bugs/templates/ bug-portlet- subscribers- ids.pt 1970-01-01 00:00:00 +0000 www.w3. org/1999/ xhtml" xml.zope. org/namespaces/ tal" xml.zope. org/namespaces/ metal" xml.zope. org/namespaces/ i18n" "view/subscribe r_ids_js" />
--- lib/lp/
+++ lib/lp/
@@ -1,6 +0,0 @@
-<div
- xmlns="http://
- xmlns:tal="http://
- xmlns:metal="http://
- xmlns:i18n="http://
- tal:content=