Here's the actual diff:
=== modified file 'lib/canonical/launchpad/javascript/bugs/bugtask-index.js' --- lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-09-22 11:46:49 +0000 +++ lib/canonical/launchpad/javascript/bugs/bugtask-index.js 2009-09-28 10:35:09 +0000 @@ -37,6 +37,7 @@ 'class="lazr-neg lazr-btn" >Cancel</button>'; var privacy_link; var privacy_spinner; +var link_branch_link;
/* * An object representing the bugtask subscribers portlet. @@ -210,9 +211,11 @@ }); privacy_link.addClass('js-action'); } + create_error_overlay(); setup_inline_commenting(); setup_add_attachment(); + setup_link_branch_picker(); }, window); };
@@ -627,6 +630,101 @@ } }
+/** + * Set up the link-a-related-branch picker. + */ +function setup_link_branch_picker() { + if (lp_client === undefined || bug_repr === undefined) { + setup_client_and_bug(); + } + + var error_handler = new LP.client.ErrorHandler(); + + error_handler.clearProgressUI = function () { + link_branch_link.toggleClass('update-in-progress-message'); + }; + error_handler.showError = function(error_msg) { + display_error(Y.get('.menu-link-addsubscriber'), error_msg); + }; + + function get_branch_and_link_to_bug(data) { + var branch_url = data['api_uri']; + config = { + on: { + success: link_branch_to_bug, + failure: error_handler.getFailureHandler() + } + }; + + // Start the spinner and then grab the branch. + link_branch_link.toggleClass('update-in-progress-message'); + lp_client.get(branch_url, config); + } + + // Set up the picker itself. + link_branch_link = Y.get('.menu-link-addbranch'); + if (Y.Lang.isValue(link_branch_link)) { + var config = { + header: 'Link a related branch', + step_title: 'Search' + }; + + var picker = Y.lp.picker.create( + 'Branch', get_branch_and_link_to_bug, config); + + // Clear results and search terms on cancel or save. + picker.on('save', clear_picker, picker); + picker.on('cancel', clear_picker, picker); + + link_branch_link.on('click', function(e) { + e.halt(); + picker.show(); + }); + link_branch_link.addClass('js-action'); + } +} + +/** + * Link a branch to the current bug. + * @param branch {Object} The branch to link to the bug, as returned by + * the Launchpad API. + */ +function link_branch_to_bug(branch) { + var error_handler = new LP.client.ErrorHandler(); + error_handler.clearProgressUI = function () { + link_branch_link.toggleClass('update-in-progress-message'); + }; + error_handler.showError = function(error_msg) { + display_error(Y.get('.menu-link-addsubscriber'), error_msg); + }; + + // Call linkBranch() on the bug and flash the 'add a branch' link + // accordingly. + config = { + on: { + success: function(client) { + // Show the green flash anim to say the action + // has completed. + var anim = Y.lazr.anim.green_flash( + {node: link_branch_link}); + anim.on('end', function(e) { + link_branch_link.toggleClass( + 'update-in-progress-message'); + }); + anim.run(); + link_branch_link.set('innerHTML', 'Link another branch'); + }, + failure: error_handler.getFailureHandler() + }, + parameters: { + branch: branch.get('self_link') + } + }; + + lp_client.named_post( + lp_bug_entry.get('self_link'), 'linkBranch', config); +} + /* * Traverse the DOM of a given remove icon to find * the user's link. Returns a URI of the form "/~username".
« Back to merge proposal
Here's the actual diff:
=== modified file 'lib/canonical/ launchpad/ javascript/ bugs/bugtask- index.js' launchpad/ javascript/ bugs/bugtask- index.js 2009-09-22 11:46:49 +0000 launchpad/ javascript/ bugs/bugtask- index.js 2009-09-28 10:35:09 +0000 "lazr-neg lazr-btn" >Cancel</button>';
--- lib/canonical/
+++ lib/canonical/
@@ -37,6 +37,7 @@
'class=
var privacy_link;
var privacy_spinner;
+var link_branch_link;
/*
privacy_ link.addClass( 'js-action' );
create_ error_overlay( );
setup_ inline_ commenting( );
setup_ add_attachment( ); branch_ picker( );
* An object representing the bugtask subscribers portlet.
@@ -210,9 +211,11 @@
});
}
+
+ setup_link_
}, window);
};
@@ -627,6 +630,101 @@
}
}
+/** related- branch picker. branch_ picker( ) { and_bug( ); ErrorHandler( ); clearProgressUI = function () { link.toggleClas s('update- in-progress- message' ); showError = function(error_msg) { error(Y. get('.menu- link-addsubscri ber'), error_msg); and_link_ to_bug( data) { getFailureHandl er() link.toggleClas s('update- in-progress- message' ); get(branch_ url, config); .menu-link- addbranch' ); isValue( link_branch_ link)) { and_link_ to_bug, config); link.on( 'click' , function(e) { link.addClass( 'js-action' ); to_bug( branch) { ErrorHandler( ); clearProgressUI = function () { link.toggleClas s('update- in-progress- message' ); showError = function(error_msg) { error(Y. get('.menu- link-addsubscri ber'), error_msg); anim.green_ flash( link.toggleClas s( in-progress- message' ); link.set( 'innerHTML' , 'Link another branch'); getFailureHandl er() get('self_ link') named_post( entry.get( 'self_link' ), 'linkBranch', config);
+ * Set up the link-a-
+ */
+function setup_link_
+ if (lp_client === undefined || bug_repr === undefined) {
+ setup_client_
+ }
+
+ var error_handler = new LP.client.
+
+ error_handler.
+ link_branch_
+ };
+ error_handler.
+ display_
+ };
+
+ function get_branch_
+ var branch_url = data['api_uri'];
+ config = {
+ on: {
+ success: link_branch_to_bug,
+ failure: error_handler.
+ }
+ };
+
+ // Start the spinner and then grab the branch.
+ link_branch_
+ lp_client.
+ }
+
+ // Set up the picker itself.
+ link_branch_link = Y.get('
+ if (Y.Lang.
+ var config = {
+ header: 'Link a related branch',
+ step_title: 'Search'
+ };
+
+ var picker = Y.lp.picker.create(
+ 'Branch', get_branch_
+
+ // Clear results and search terms on cancel or save.
+ picker.on('save', clear_picker, picker);
+ picker.on('cancel', clear_picker, picker);
+
+ link_branch_
+ e.halt();
+ picker.show();
+ });
+ link_branch_
+ }
+}
+
+/**
+ * Link a branch to the current bug.
+ * @param branch {Object} The branch to link to the bug, as returned by
+ * the Launchpad API.
+ */
+function link_branch_
+ var error_handler = new LP.client.
+ error_handler.
+ link_branch_
+ };
+ error_handler.
+ display_
+ };
+
+ // Call linkBranch() on the bug and flash the 'add a branch' link
+ // accordingly.
+ config = {
+ on: {
+ success: function(client) {
+ // Show the green flash anim to say the action
+ // has completed.
+ var anim = Y.lazr.
+ {node: link_branch_link});
+ anim.on('end', function(e) {
+ link_branch_
+ 'update-
+ });
+ anim.run();
+ link_branch_
+ },
+ failure: error_handler.
+ },
+ parameters: {
+ branch: branch.
+ }
+ };
+
+ lp_client.
+ lp_bug_
+}
+
/*
* Traverse the DOM of a given remove icon to find
* the user's link. Returns a URI of the form "/~username".