]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1383500 - Allow giving a default product in the URL in new-bug
authorSebastin Santy <sebastinssanty@gmail.com>
Thu, 17 Aug 2017 21:23:01 +0000 (02:53 +0530)
committerDylan William Hardison <dylan@hardison.net>
Thu, 17 Aug 2017 21:23:01 +0000 (17:23 -0400)
extensions/BugModal/web/new_bug.js
template/en/default/bug/new_bug.html.tmpl

index 87a43eee750bcb76ab0a39a724775bf45f975b8b..7298b1d20730f071f33a0021dd1410fed47572c2 100644 (file)
@@ -1,30 +1,77 @@
 var initial = {}
 var comp_desc = {}
+var product_name = '';
+
+var component_load = function(product) {
+    $('#product-throbber').show();
+    $('#component').attr('disabled', true);
+    bugzilla_ajax(
+        {
+            url: 'rest/bug_modal/product_info?product=' + encodeURIComponent(product)
+        },
+        function(data) {
+            $('#product-throbber').hide();
+            $('#component').attr('disabled', false);
+            $('#comp_desc').text('Select a component to read its description.');
+            var selectize = $("#component")[0].selectize;
+            selectize.clear();
+            selectize.clearOptions();
+            selectize.load(function(callback) {
+                callback(data.components)
+            });
+
+            for (var i in data.components)
+                comp_desc[data.components[i]["name"]] = data.components[i]["description"];
+
+            selectize = $("#version")[0].selectize;
+            selectize.clear();
+            selectize.clearOptions();
+            selectize.load(function(callback) {
+                callback(data.versions);
+            });
+        },
+        function() {
+            alert("Network issues. Please refresh the page and try again");
+        }
+    );  
+}
 
 $(document).ready(function() {
+    var product_name = window.location.hash? window.location.hash.substr(1) : null;
     bugzilla_ajax(
             {
                 url: 'rest/bug_modal/initial_field_values'
             },
             function(data) {
                 initial = data
+                if (product_name) {
+                    for (product in initial.products) {
+                        if (initial.products[product].name.toLowerCase() === product_name.toLowerCase()) {
+                            $("#product_wrap").html('<input name="product" type="hidden" id="product"><h3 style="padding-left:20px;" id="product_name_heading">Hello</h3>')
+                            $("#product").val(initial.products[product].name);
+                            $("#product_name_heading").text(initial.products[product].name);
+                            component_load(initial.products[product].name);
+                            return;
+                        }
+                    }
+                }
+                var $product_sel = $("#product").selectize({
+                    valueField: 'name',
+                    labelField: 'name',
+                    placeholder: 'Product',
+                    searchField: 'name',
+                    options: [],
+                    preload: true,
+                    create: false,
+                    load: function(query, callback) {       
+                        callback(initial.products);       
+                    }
+                });
             },
             function() {
                 alert("Network issues. Please refresh the page and try again");
             }
         );
-    var product_sel = $("#product").selectize({
-        valueField: 'name',
-        labelField: 'name',
-        placeholder: 'Product',
-        searchField: 'name',
-        options: [],
-        preload: true,
-        create: false,
-        load: function(query, callback) {
-            callback(initial.products);
-        }
-    });
     var component_sel = $("#component").selectize({
         valueField: 'name',
         labelField: 'name',
@@ -54,39 +101,9 @@ $(document).ready(function() {
             callback(initial.keywords);
         }
     });
-
-    product_sel.on("change", function () {
-        $('#product-throbber').show();
-        $('#component').attr('disabled', true);
-        bugzilla_ajax(
-                {
-                    url: 'rest/bug_modal/product_info?product=' + encodeURIComponent($('#product').val())
-                },
-                function(data) {
-                    $('#product-throbber').hide();
-                    $('#component').attr('disabled', false);
-                    $('#comp_desc').text('Select a component to read its description.');
-                    var selectize = $("#component")[0].selectize;
-                    selectize.clear();
-                    selectize.clearOptions();
-                    selectize.load(function(callback) {
-                        callback(data.components)
-                    });
-
-                    for (var i in data.components)
-                        comp_desc[data.components[i]["name"]] = data.components[i]["description"];
-
-                    selectize = $("#version")[0].selectize;
-                    selectize.clear();
-                    selectize.clearOptions();
-                    selectize.load(function(callback) {
-                        callback(data.versions);
-                    });
-                },
-                function() {
-                    alert("Network issues. Please refresh the page and try again");
-                }
-            );     
+    
+    $("#product").on("change", function () {
+        component_load($("#product").val());
     });
 
     component_sel.on("change", function () {
@@ -132,4 +149,7 @@ $(document).ready(function() {
             $(this).css("background-color", "#eee");
         });
     $('#comment-edit-tab').click();
+    window.onhashchange = function() {
+        location.reload();
+    }
 });
index d064398c591d1cb4da463c305ef8f8c1e950d00b..bed0c5578731dee528ab38704b4410bf217c8ddf 100644 (file)
@@ -75,7 +75,7 @@
             [% can_edit_product   = bug.check_can_change_field("product", 0, 1) %]
             [% filtered_product   = bug.product_obj.name FILTER uri %]
             [% filtered_component = bug.component_obj.name FILTER uri %]
-
+            <div id="product_wrap">
             [% WRAPPER bug_modal/field.html.tmpl
                 field        = bug_fields.product
                 field_type   = constants.FIELD_TYPE_SINGLE_SELECT
@@ -83,6 +83,7 @@
                 editable = 1
                 help         = "describecomponents.cgi?product=$filtered_product"
             %]
+            
               <span aria-owns="product-name product-latch">
                 <span role="button" aria-label="show product information" aria-expanded="false" tabindex="0"
                       class="spin-latch" id="product-latch" data-latch="product" data-for="product">&#9656;</span>
@@ -95,7 +96,7 @@
                 </div>
               </span>
             [% END %]
-
+            </div>
             [% WRAPPER bug_modal/field.html.tmpl
                 field          = bug_fields.product
                 field_type     = constants.FIELD_TYPE_SINGLE_SELECT