add product information to the tabular view

git-svn-id: https://svn.apache.org/repos/asf/bloodhound/branches/bep_0011_batch_create_tickets@1763978 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js b/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js
index e4cd0bd..6354dcb 100644
--- a/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js
+++ b/bloodhound_theme/bhtheme/htdocs/js/batchcreate.js
@@ -22,14 +22,13 @@
  The wiki macro will send the relevant details to create the empty ticket table within the wiki.
  Then this function will generate the empty ticket table containing appropriate number of rows to enter ticket data.
  */
-function emptyTable(numOfRows, products, milestones, components, href, token, unique_key) {
+function emptyTable(numOfRows, product, milestones, components, href, token, unique_key) {
 
   var created_rows = numOfRows;
   var form_token = token.split(";")[0].split("=")[1];
-  href = href + "/bct";
 
   var headers = {
-    "ticket": "", "summary": "Summary", "description": "Description", "product": "Product",
+    "ticket": "", "summary": "Summary", "description": "Description",
     "priority": "Priority", "milestone": "Milestone", "component": "Component"
   };
   var priorities = ["blocker", "critical", "major", "minor", "trivial"];
@@ -139,21 +138,6 @@
           }).html(priorities[priority]).appendTo(input_priority);
         }
 
-      } else if (header == "product") {
-
-        td = $('<td>').appendTo(tr_rows);
-        var field_product = $('<select/>', {
-          'id': 'field-product' + unique_key + '-' + i,
-          'name': 'field_product' + i,
-          'class': 'product'
-        }).appendTo(td);
-
-        for (var product in products) {
-          $('<option/>', {
-            'value': (products[product])[0]
-          }).html((products[product])[1]).appendTo(field_product);
-        }
-
       } else if (header == "milestone") {
 
         td = $('<td>').appendTo(tr_rows);
@@ -274,9 +258,9 @@
 
       var div = $('<div/>').appendTo(contentDiv);
 
-      var h5 = $('<h5/>', {
-        'class': 'span12'
-      }).html("Created Tickets").appendTo(div);
+      $('<div/>', {
+        'class': 'numrows'
+      }).html('(' + ticket.tickets.length + ' total rows.)').appendTo(div);
 
       var table = $('<table/>', {
         'class': 'table table-condensed tickets'
@@ -291,15 +275,19 @@
 
       for (var json_ticket in ticket.tickets) {
         var tr = $('<tr/>').appendTo(table);
-        var tkt = JSON.parse(json_ticket);
+        var tkt = JSON.parse(ticket.tickets[json_ticket]);
         for (var j = 0; j < 6; j++) {
           var td = $('<td/>').appendTo(tr);
-          if (j < 2) {
+          if (j == 0) {
+            if (json_ticket == 0) {
+             td.html(tkt.product)
+            }
+          } else if (j < 3) {
             $('<a/>', {
               'href': tkt.url
-            }).html(j == 0 ? '#' + tkt.id : tkt.summary).appendTo(td);
+            }).html(j == 1 ? "#" + tkt.id : tkt.summary).appendTo(td);
           } else {
-            td.html(j == 2 ? tkt.product : (j == 3 ? tkt.status : (j == 4 ? tkt.milestone : tkt.component)));
+            td.html(j == 3 ? tkt.status : (j == 4 ? tkt.milestone : tkt.component))
           }
         }
       }
@@ -413,7 +401,7 @@
 function display_created_tickets(tickets, unique_key) {
 
   var headers = {
-    "ticket": "Ticket", "summary": "Summary", "product": "Product", "status": "Status",
+    "product": "", "ticket": "Ticket", "summary": "Summary", "status": "Status",
     "milestone": "Milestone", "component": "Component"
   };
 
@@ -441,14 +429,16 @@
 
     for (var j = 0; j < 6; j++) {
       var td = $('<td/>');
-      if (j < 2) {
-
+      if (j == 0) {
+        if (index == 0) {
+          td.html(tkt.product)
+        }
+      } else if (j < 3) {
         $('<a/>', {
           'href': tkt.url
-        }).html(j == 0 ? "#" + tkt.id : tkt.summary).appendTo(td);
-      }
-      else {
-        td.html(j == 2 ? tkt.product : (j == 3 ? tkt.status : (j == 4 ? tkt.milestone : tkt.component)))
+        }).html(j == 1 ? "#" + tkt.id : tkt.summary).appendTo(td);
+      } else {
+        td.html(j == 3 ? tkt.status : (j == 4 ? tkt.milestone : tkt.component))
       }
       td.appendTo(tr)
     }
diff --git a/bloodhound_theme/bhtheme/theme.py b/bloodhound_theme/bhtheme/theme.py
index b6efa84..5ef5135 100644
--- a/bloodhound_theme/bhtheme/theme.py
+++ b/bloodhound_theme/bhtheme/theme.py
@@ -771,8 +771,6 @@
             # generate the required data to be parsed to the js functions too create the empty ticket table.
 
             product_id = str(self.env.product.resource.id)
-            product_name = self.env.db_query(
-                "SELECT * FROM bloodhound_product WHERE prefix=%s", (product_id,))
             milestones = self.env.db_query(
                 "SELECT * FROM milestone WHERE product=%s", (product_id,))
             components = self.env.db_query(
@@ -788,9 +786,9 @@
                             src=str(self.rqst.href.chrome('theme/js/batchcreate.js'))),
                         tag.script(
                             # pass the relevant arguments to the js function as JSON parameters.
-                            "emptyTable(" + to_json(str(self.rows)) + "," + to_json(product_name) + "," +
+                            "emptyTable(" + to_json(str(self.rows)) + "," + to_json(self.env.product._data['name']) + "," +
                             to_json(milestones) + "," + to_json(components) + "," +
-                            to_json(self.rqst.href()) + "," +
+                            to_json(self.rqst.href() + "/bct") + "," +
                             to_json(str(self.rqst.environ["HTTP_COOKIE"])) + "," +
                             to_json(random_string) + ")",
                             id="js-caller" + random_string,
@@ -983,7 +981,7 @@
     def batch_create(self, req, attributes={}, notify=False):
         """ Create batch of tickets, returning created tickets.
         """
-        num_of_tkts = attributes.__len__() / 6
+        num_of_tkts = attributes.__len__() / 5
         created_tickets = []
         loop_condition = True
         i = -1
@@ -1015,7 +1013,6 @@
             description = attributes.pop('description' + str(i))
             status = 'new'
             summary = attributes.pop('summary' + str(i))
-            product = attributes.pop('product' + str(i))
             priority = attributes.pop('priority' + str(i))
             milestone = attributes.pop('milestone' + str(i))
             component = attributes.pop('component' + str(i))
@@ -1027,7 +1024,7 @@
             t['reporter'] = req.authname
             t['status'] = status
             t['resolution'] = ''
-            t['product'] = product
+            t['product'] = self.env.product._data['prefix']
             t['priority'] = priority
             t['milestone'] = milestone
             t['component'] = component
@@ -1136,7 +1133,7 @@
                             src=str(self.rqst.href.chrome('theme/js/batchcreate.js'))),
                         tag.script(
                             'display_created_tickets(' + to_json(display_tickets_list) + ',' +
-                            to_json(random_string) + ')',
+                            to_json(random_string) + ',' + to_json(self.env.product._data['name']) + ')',
                             id='js-caller' + random_string,
                             type='text/javascript'),
                         class_='input-group-btn'),