changeset 63:88b856b1353b

added file-bug dialog
author Atul Varma <avarma@mozilla.com>
date Sun, 25 Apr 2010 08:30:50 -0700
parents 68b4c80e884f
children a196cc29fffb
files js/modules/app.js main.html
diffstat 2 files changed, 95 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/js/modules/app.js	Sun Apr 25 08:14:18 2010 -0700
+++ b/js/modules/app.js	Sun Apr 25 08:30:50 2010 -0700
@@ -97,6 +97,84 @@
   };
 };
 
+Require.modules["app/ui/file-bug"] = function(exports, require) {
+  const EM_DASH = "\u2014";
+
+  var $ = require("jQuery");
+  var cache = require("cache");
+  var bugzilla = require("app/bugzilla-auth").Bugzilla;
+  var window = require("window");
+  var config = cache.get("configuration");
+  var needToFetchConfig = config ? false : true;
+  var categories;
+  var queuedRespond;
+
+  function buildCategories() {
+    categories = [];
+    for (product in config.product)
+      for (component in config.product[product].component)
+        categories.push(product + EM_DASH + component);
+  }
+
+  function fetchConfig() {
+    bugzilla.ajax({url: "/configuration",
+                   data: {flags: 0},
+                   success: function(result) {
+                     config = result;
+                     cache.set("configuration", result);
+                     if (queuedRespond)
+                       queuedRespond();
+                   }});
+  }
+
+  var categoryOptions = {
+    minLength: 2,
+    source: function(request, response) {
+      function respond() {
+        queuedRespond = null;
+
+        var suggs = [];
+        var terms = request.term.split(" ");
+
+        if (!categories)
+          buildCategories();
+
+        categories.forEach(
+          function(category) {
+            for (var i = 0; i < terms.length; i++)
+              if (!category.match(terms[i], "i"))
+                return;
+            suggs.push(category);
+          });
+
+        response(suggs);
+      };
+
+      if (!config) {
+        queuedRespond = respond;
+        if (needToFetchConfig) {
+          needToFetchConfig = false;
+          fetchConfig();
+        }
+      } else
+        respond();
+    }
+  };
+
+  $("input#category").autocomplete(categoryOptions);
+  $("#file-bug").submit(
+    function(event) {
+      event.preventDefault();
+      var parts = $("input#category").val().split(EM_DASH);
+      window.open(bugzilla.BASE_UI_URL + "/enter_bug.cgi?" +
+                  "product=" + escape(parts[0]) + "&" +
+                  "component=" + escape(parts[1]));
+    });
+
+  exports.init = function init() {
+  };
+};
+
 Require.modules["app/ui/find-user"] = function(exports, require) {
   var $ = require("jQuery");
   var bugzilla = require("app/bugzilla-auth").Bugzilla;
@@ -219,6 +297,7 @@
     require("app/ui/dashboard").init();
     require("app/ui/login-form").init();
     require("app/ui/find-user").init();
+    require("app/ui/file-bug").init();
     require("app/ui/hash").init(document);
 
     startupCallbacks.forEach(function(cb) { cb(); });
--- a/main.html	Sun Apr 25 08:14:18 2010 -0700
+++ b/main.html	Sun Apr 25 08:30:50 2010 -0700
@@ -54,6 +54,22 @@
   </form>
   </div>
 </div>
+<div id="file-bug" class="dialog">
+  <div class="content">
+  <form id="file-bug">
+  <p>Just type in part of a product or component below, select from
+  the auto-complete list, and press enter. You'll then get sent to a
+  Bugzilla page where you can fill out a summary, description, and
+  more details for the bug.</p>
+  <table>
+    <tr>
+      <td>Category</td>
+      <td><input type="text" id="category"/></td>
+    </tr>
+  </table>
+  </form>
+  </div>
+</div>
 <div id="find-user" class="dialog">
   <div class="content">
   <form id="find-user-form">