view js/file-bug.js @ 20:71b072bc1e4a

Converted encodeURI() to escape(), apparently this fixes the case where an ampersand is in the name of the component.
author Atul Varma <varmaa@toolness.com>
date Wed, 10 Mar 2010 13:04:13 -0800
parents b2e0ea0178fb
children d2f8db74214f
line wrap: on
line source

$(window).ready(
  function() {
    const EM_DASH = "\u2014";

    var cache = buildCache("#form-cache .data");
    var config = cache.get("configuration");
    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);
    }

    var categoryOptions = {
      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;
        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]));
      });

    Bugzilla.ajax({url: "/configuration",
                   success: function(result) {
                     config = result;
                     cache.set("configuration", result);
                     if (queuedRespond)
                       queuedRespond();
                   }});
  });