You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@bloodhound.apache.org by rj...@apache.org on 2013/07/06 01:03:36 UTC

svn commit: r1500163 - in /bloodhound/trunk/bloodhound_theme/bhtheme: htdocs/js/theme.js theme.py

Author: rjollos
Date: Fri Jul  5 23:03:36 2013
New Revision: 1500163

URL: http://svn.apache.org/r1500163
Log:
Make View/Edit point to proper product scope (Refs #569).

When creating a ticket through the QCT dialog for a product when in the scope of another product, the //View/Edit// link would not be properly product-scoped. For example, when creating a ticket associated with product B when in the scope of product A, the `href` for the //View/Edit// link would be `/products/productA/ticket/id`, but should be `/products/productB/ticket/id`.

Changes have been tested on the desktop and mobile browsers.

Modified:
    bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/js/theme.js
    bloodhound/trunk/bloodhound_theme/bhtheme/theme.py

Modified: bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/js/theme.js
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/js/theme.js?rev=1500163&r1=1500162&r2=1500163&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/js/theme.js (original)
+++ bloodhound/trunk/bloodhound_theme/bhtheme/htdocs/js/theme.js Fri Jul  5 23:03:36 2013
@@ -123,14 +123,18 @@ $( function () {
       );
     $('#qct-create').click(
         function() {
-          var base_url = $('#qct-create').attr('data-target');
-          if (base_url === '/')
-            base_url = '';
-          $.post(base_url + '/qct', $('#qct-form').serialize(), 
-              function(ticket_id) {
-                var href = base_url + '/ticket/' + ticket_id;
+          // data-target is the base url for the product in current scope
+          var product_base_url = $('#qct-create').attr('data-target');
+          if (product_base_url === '/')
+            product_base_url = '';
+          $.post(product_base_url + '/qct', $('#qct-form').serialize(),
+              function(ticket) {
+                var base_url = product_base_url.split('/products/')[0];
+                var href = base_url + '/products/' +
+                           encodeURIComponent(ticket.product) +
+                           '/ticket/' + ticket.id;
                 qct_alert({
-                    ticket: ticket_id,
+                    ticket: ticket.id,
                     msg: '<span class="alert alert-success">' +
                          'Has been created</span> ' +
                          '<a href="' + href + '">View / Edit</a>'
@@ -155,30 +159,34 @@ $( function () {
       );
 
     $('#qct-inline-create').click(function() {
-      var base_url = $('#qct-inline-create').attr('data-target');
-      if (base_url === '/')
-        base_url = '';
-
-      $.post(base_url + '/qct', $('#qct-inline-form').serialize(), 
-        function(ticket_id) {
-          var href = base_url + '/ticket/' + ticket_id;
-          var msg = 'Ticket #' + ticket_id + ' has been created. ';
-          msg += '<a href="' + href + '">View / Edit</a>';
-          $('#qct-inline-notice-success span').html(msg);
-          $('#qct-inline-notice-success').show({'duration': 400});
-        })
-        .error(function(jqXHR, textStatus, errorMsg) {
-          var msg;
-          if (textStatus === 'timeout')
-            msg = 'Request timed out';
-          else if (textStatus === 'error')
-            msg = 'Could not create ticket. Error : ' + errorMsg;
-          else if (textStatus === 'abort')
-            msg = 'Aborted request';
-
-          $('#qct-inline-notice-error span').html(msg);
-          $('#qct-inline-notice-error').show({'duration': 400});
-        });
+      // data-target is the base url for the product in current scope
+      var product_base_url = $('#qct-inline-create').attr('data-target');
+      if (product_base_url === '/')
+        product_base_url = '';
+      $.post(product_base_url + '/qct', $('#qct-inline-form').serialize(),
+          function(ticket) {
+            var base_url = product_base_url.split('/products/')[0];
+            var href = base_url + '/products/' +
+                       encodeURIComponent(ticket.product) +
+                       '/ticket/' + ticket.id;
+
+            var msg = 'Ticket #' + ticket.id + ' has been created. ';
+            msg += '<a href="' + href + '">View / Edit</a>';
+            $('#qct-inline-notice-success span').html(msg);
+            $('#qct-inline-notice-success').show({'duration': 400});
+          })
+          .error(function(jqXHR, textStatus, errorMsg) {
+            var msg;
+            if (textStatus === 'timeout')
+              msg = 'Request timed out';
+            else if (textStatus === 'error')
+              msg = 'Could not create ticket. Error : ' + errorMsg;
+            else if (textStatus === 'abort')
+              msg = 'Aborted request';
+
+            $('#qct-inline-notice-error span').html(msg);
+            $('#qct-inline-notice-error').show({'duration': 400});
+          });
 
       qct_clearui();
       qct_inline_close();

Modified: bloodhound/trunk/bloodhound_theme/bhtheme/theme.py
URL: http://svn.apache.org/viewvc/bloodhound/trunk/bloodhound_theme/bhtheme/theme.py?rev=1500163&r1=1500162&r2=1500163&view=diff
==============================================================================
--- bloodhound/trunk/bloodhound_theme/bhtheme/theme.py (original)
+++ bloodhound/trunk/bloodhound_theme/bhtheme/theme.py Fri Jul  5 23:03:36 2013
@@ -31,6 +31,7 @@ from trac.ticket.model import Ticket, Mi
 from trac.ticket.notification import TicketNotifyEmail
 from trac.ticket.web_ui import TicketModule
 from trac.util.compat import set
+from trac.util.presentation import to_json
 from trac.util.translation import _
 from trac.versioncontrol.web_ui.browser import BrowserModule
 from trac.web.api import IRequestFilter, IRequestHandler, ITemplateStreamFilter
@@ -509,12 +510,13 @@ class QuickCreateTicketDialog(Component)
             desc = ""
             attrs = dict([k[6:], v] for k, v in req.args.iteritems()
                          if k.startswith('field_'))
-            ticket_id = self.create(req, summary, desc, attrs, True)
+            product, tid = self.create(req, summary, desc, attrs, True)
         except Exception, exc:
             self.log.exception("BH: Quick create ticket failed %s" % (exc,))
             req.send(str(exc), 'plain/text', 500)
         else:
-            req.send(str(ticket_id), 'plain/text')
+            req.send(to_json({'product': product, 'id': tid}),
+                     'application/json')
 
     def _get_ticket_module(self):
         ptm = None
@@ -550,7 +552,7 @@ class QuickCreateTicketDialog(Component)
             except Exception, e:
                 self.log.exception("Failure sending notification on creation "
                                    "of ticket #%s: %s" % (t.id, e))
-        return t.id
+        return t['product'], t.id
 
 from pkg_resources import get_distribution
 application_version = get_distribution('BloodhoundTheme').version