[bugzilla-gnome-org-extensions] Improve behavior when bug/attachment isn't specified



commit 837625a3c17f0ea25a0908f370ea096bb0c934a5
Author: Owen W. Taylor <otaylor fishsoup net>
Date:   Wed Sep 9 18:01:23 2009 -0400

    Improve behavior when bug/attachment isn't specified
    
    When bug isn't specified, show an entry with a [ Go ] button
    When attachment isn't specified, show a list of attachments for the bug.

 js/splinter.js   |  143 +++++++++++++++++++++++++++++++++++++++--------------
 web/index.html   |   12 +++++
 web/splinter.css |   12 +++++
 3 files changed, 129 insertions(+), 38 deletions(-)
---
diff --git a/js/splinter.js b/js/splinter.js
index b627931..4e49db9 100644
--- a/js/splinter.js
+++ b/js/splinter.js
@@ -347,6 +347,8 @@ function gotBug(xml) {
 
     if (theBug !== undefined && thePatch !== undefined)
         start();
+    else if (attachmentId === undefined)
+        showChooseAttachment();
 }
 
 function gotAttachment(text) {
@@ -357,51 +359,116 @@ function gotAttachment(text) {
         start();
 }
 
+function isDigits(str) {
+    return str.match(/^[0-9]+$/);
+}
+
+function newPageUrl(newBugId, newAttachmentId) {
+    var newUrl = "/index.html";
+    if (newBugId != null) {
+        newUrl += "?bug=" + escape("" + newBugId);
+        if (newAttachmentId != null)
+            newUrl += "&attachment=" + escape("" + newAttachmentId);
+    }
+
+    return newUrl;
+}
+
+function showEnterBug() {
+    $("#enterBugGo").click(function() {
+                               var newBugId = Utils.strip($("#enterBugInput").val());
+                               document.location = newPageUrl(newBugId);
+                           });
+    $("#loading").hide();
+    $("#enterBug").show();
+}
+
+function showChooseAttachment() {
+    for (var i = 0; i < theBug.attachments.length; i++) {
+        var attachment = theBug.attachments[i];
+
+        if (!attachment.isPatch)
+            continue;
+
+        var href = newPageUrl(theBug.id, attachment.id);
+
+        var date = Utils.formatDate(attachment.date);
+        var status = (attachment.status && attachment.status != 'none') ? attachment.status : '';
+
+        var obsoleteClass = attachment.isObsolete ? "attachment-obsolete" : '';
+
+        $("<tr>"
+          + "<td class='attachment-id'><a></a></td>"
+          + "<td class='attachment-desc'><a></a></td>"
+          + "<td class='attachment-date'></td>"
+          + "<td class='attachment-status'></td>"
+          + "</tr>")
+            .find(".attachment-id a")
+                .attr("href", href)
+                .text(attachment.id).end()
+            .find(".attachment-desc a")
+                .addClass(obsoleteClass)
+                .attr("href", href)
+                .text(attachment.description).end()
+            .find(".attachment-date").text(date).end()
+            .find(".attachment-status").text(status).end()
+            .appendTo("#chooseAttachment tbody");
+    }
+
+    $("#loading").hide();
+    $("#chooseAttachment").show();
+}
+
 function init() {
     var params = getQueryParams();
-    var bug_id;
+    var bugId;
 
-   if (params.bug) {
-        bug_id = parseInt(params.bug);
-    }
-    if (bug_id === undefined || isNaN(bug_id)) {
-        alert("Must specify a valid bug ID");
+    if (params.bug)
+        bugId = isDigits(params.bug) ? parseInt(params.bug) : NaN;
+
+    if (bugId === undefined || isNaN(bugId)) {
+        if (bugId !== undefined)
+            displayError("Bug ID '" + params.bug + "' is not valid");
+        showEnterBug();
         return;
+    } else {
+        $.ajax({
+                   type: 'GET',
+                   dataType: 'xml',
+                   url: '/show_bug.cgi',
+                   data: {
+                       id: bugId,
+                       ctype: 'xml',
+                       excludefield: 'attachmentdata'
+                   },
+                   success: gotBug,
+                   error: function() {
+                       displayError("Failed to retrieve bug " + bugId);
+                       showEnterBug();
+                   }
+               });
     }
 
-   if (params.attachment) {
-        attachmentId = parseInt(params.attachment);
+    if (params.attachment) {
+        attachmentId = isDigits(params.attachment) ? parseInt(params.attachment) : NaN;
     }
     if (attachmentId === undefined || isNaN(attachmentId)) {
-        alert("Must specify a valid attachment ID");
-        return;
+        if (attachmentId !== undefined) {
+            displayError("Attachment ID '" + params.bug + "' is not valid");
+            attachmentId = undefined;
+        }
+    } else {
+        $.ajax({
+                   type: 'GET',
+                   dataType: 'text',
+                   url: '/attachment.cgi',
+                   data: {
+                       id: attachmentId
+                   },
+                   success: gotAttachment,
+                   error: function(a, b, c) {
+                       displayError("Failed to retrieve attachment " + attachmentId);
+                   }
+               });
     }
-
-    $.ajax({
-               type: 'GET',
-               dataType: 'xml',
-               url: '/show_bug.cgi',
-               data: {
-                   id: bug_id,
-                   ctype: 'xml',
-                   excludefield: 'attachmentdata'
-               },
-               success: gotBug,
-               error: function() {
-                   displayError("Failed to retrieve bug");
-               },
-    });
-
-    $.ajax({
-               type: 'GET',
-               dataType: 'text',
-               url: '/attachment.cgi',
-               data: {
-                   id: attachmentId
-               },
-               success: gotAttachment,
-               error: function(a, b, c) {
-                   displayError("Failed to retrieve attachment");
-               }
-           });
 }
diff --git a/web/index.html b/web/index.html
index 297da8b..b2d2eec 100644
--- a/web/index.html
+++ b/web/index.html
@@ -26,6 +26,18 @@
     </div>
     <div id="error" style="display: none;">
     </div>
+    <div id="enterBug" style="display: none;">
+      Bug to review:
+      <input id="enterBugInput"></input>
+      <input id="enterBugGo" type="button" value="Go"></input>
+    </div>
+    <div id="chooseAttachment" style="display: none;">
+      Choose patch attachment to review:
+      <table>
+       <tbody>
+       </tbody>
+      </table>
+    </div>
     <div id="controls" style="display: none;">
       <div id="oldReviews">
       </div>
diff --git a/web/splinter.css b/web/splinter.css
index 1f0a934..976dce8 100644
--- a/web/splinter.css
+++ b/web/splinter.css
@@ -20,6 +20,18 @@ body {
     color: #bb0000;
 }
 
+#enterBug {
+    padding: 0.5em;
+}
+
+#chooseAttachment {
+    padding: 0.5em;
+}
+
+.attachment-obsolete {
+    text-decoration: line-through ;
+}
+
 #controls {
     padding: 0.5em;
 }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]