Code review comment for lp:~gmb/launchpad/ajaxify-branch-linking

Revision history for this message
Graham Binns (gmb) wrote :

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