id,summary,reporter,owner,description,type,status,priority,component,severity,resolution,keywords,cc,release
4549,Enable HoursInPlaceEditor functionality for reports,JasonWinnebeck,hoessler,Enable the HoursInPlaceEditor to work with custom reports.\r\n\r\nThe request handler only injects the javascript into the custom query pages. This is probably because the script_ as is_ doesn't work for report pages_ for three reasons:\r\n\r\n 1. The column for the ticket numbers has class "ticket" whereas in query it has class "id". The class is "ticket" in reports regardless of whether or not the report's columnname is "id" or "ticket"\r\n 2. The HTML generated for the ticket column in the report module has a lot of extra whitespace added. The script assumes that the column's text is like "#123"_ with no spaces_ and that all of the characters in the string after the first form a number.\r\n 3. The path to the xmlrpc is not correct when in a report page.\r\n\r\nI fixed these three issues with the patch below. A disclaimer: I program Java_ C#_ C++_ and a little Python out of necessity for Trac but I've never done JavaScript or JQuery_ so there's probably better ways to do it. Also_ a lot of whitespace changed so the changes below look like more than they are. Only the top portion of the script changed.\r\n\r\n{{{\r\n#!patch\r\nIndex: estimationtools/hoursinplaceeditor.py\r\n===================================================================\r\n--- estimationtools/hoursinplaceeditor.py       (revision 5167)\r\n+++ estimationtools/hoursinplaceeditor.py       (working copy)\r\n@@ -28_7 +28_7 @@\r\n         return handler\r\n\r\n     def post_process_request(self_ req_ template_ data_ content_type):\r\n-        if (req.path_info.startswith('/query')\r\n+        if (req.path_info.startswith('/query') or req.path_info.startswith('/report')\r\n             and req.perm.has_permission('TICKET_MODIFY')\r\n             and req.perm.has_permission('XML_RPC')):\r\n             # add_script(req_ 'estimationtools/jquery-1.2.3.min.js')\r\nIndex: estimationtools/templates/edithours.html\r\n===================================================================\r\n--- estimationtools/templates/edithours.html    (revision 5167)\r\n+++ estimationtools/templates/edithours.html    (working copy)\r\n@@ -2_39 +2_54 @@\r\n       xmlns:xi="http://www.w3.org/2001/XInclude"\r\n       xmlns:py="http://genshi.edgewall.org/" py:strip="">\r\n $(document).ready(function() {\r\n-    ids = $('td.id').each(function(i) {\r\n-       var id = $(this).text().substr(1);\r\n-       var estimationField = '$data.field';\r\n+    var reportMethod = $('td.ticket'); //used in Trac reports\r\n+    var queryMethod = $('td.id');      //used in custom queries\r\n\r\n-          var estimationCell = $('td.' + estimationField).eq(i);\r\n+    var xmlrpcPath = null;\r\n+    var elements   = null;\r\n\r\n-          estimationCell.editable(function(value_ settings) {\r\n-         var currentElement = this;\r\n-         $.ajax({\r\n-           type: 'POST'_\r\n-           url: 'xmlrpc'_\r\n-           data: '<methodCall><methodName>ticket.update</methodName>' +\r\n-                  '<params><param><value><int>' + id + '</int></value></param>' +\r\n-                  '<param><value><string></string></value></param>' +\r\n-                  '<param><value><struct><member><name>' + estimationField + '</name>' +\r\n-                  '<value><string>' + value + '</string></value></member></struct></value></param>' +\r\n-                  '</params></methodCall>'_\r\n-           contentType: 'text/xml'_\r\n-           success: function(){\r\n-             $(currentElement).text(value);\r\n+    if ( reportMethod.length != 0 ) {\r\n+      elements   = reportMethod;\r\n+      xmlrpcPath = '../xmlrpc';\r\n+    } else if ( queryMethod.length != 0 ) {\r\n+      elements   = queryMethod;\r\n+      xmlrpcPath = 'xmlrpc';\r\n+    }\r\n+    if ( elements != null ) {\r\n+      ids = elements.each(function(i) {\r\n+        var id = jQuery.trim($(this).text()).substr(1);\r\n+        var estimationField = '$data.field';\r\n+\r\n+        var estimationCell = $('td.' + estimationField).eq(i);\r\n+\r\n+        estimationCell.editable(function(value_ settings) {\r\n+          var currentElement = this;\r\n+          $.ajax({\r\n+            type: 'POST'_\r\n+            url: xmlrpcPath_\r\n+            data: '<methodCall><methodName>ticket.update</methodName>' +\r\n+                       '<params><param><value><int>' + id + '</int></value></param>' +\r\n+                       '<param><value><string></string></value></param>' +\r\n+                       '<param><value><struct><member><name>' + estimationField + '</name>' +\r\n+                       '<value><string>' + value + '</string></value></member></struct></value></param>' +\r\n+                       '</params></methodCall>'_\r\n+            contentType: 'text/xml'_\r\n+            success: function(){\r\n+              $(currentElement).text(value);\r\n            }\r\n          });\r\n          return('Saving...');\r\n        }_ {\r\n-                data : jQuery.trim(estimationCell.text())_\r\n-                tooltip   : 'Click to edit...'_\r\n-                placeholder: ''_\r\n-                onblur : 'submit'_\r\n-                select : 'true'_\r\n-                style : 'inherit'_\r\n-                width     : 60\r\n+        data : jQuery.trim(estimationCell.text())_\r\n+        tooltip   : 'Click to edit...'_\r\n+        placeholder: ''_\r\n+        onblur : 'submit'_\r\n+        select : 'true'_\r\n+        style : 'inherit'_\r\n+        width     : 60\r\n        });\r\n     });\r\n+    }\r\n  });\r\n- </script>\r\n-\r\n\\ No newline at end of file\r\n+</script>\r\n+\r\n}}}\r\n\r\nWhat I did is check to see whether we have "td.ticket" (for reports) or "td.id" fields (for query)_ then modify the behavior appropriately. I trimmed the ticket string so that the old "substr(1)" method will work regardless. If I knew how to do regular expressions in JavaScript_ I would have done it that way. Also_ I don't know if the closures that I used (using var xmlrpcPath in the calling code and the anonymous function) is safe/proper style.\r\n\r\nI'm currently using this script in my 0.11.2 Trac_ because we need to work with a report that is not possible with the "custom query" system.\r\n\r\nThis ticket is similar to a previously closed ticket I found_ #4003.,enhancement,closed,normal,EstimationToolsPlugin,normal,fixed,,,0.11
