[BUGFIX] Fix sorting by extension name 84/45184/5
authorPatrick Schriner <patrick.schriner@diemedialen.de>
Wed, 25 Nov 2015 19:14:22 +0000 (20:14 +0100)
committerGeorg Ringer <georg.ringer@gmail.com>
Sat, 12 Dec 2015 19:13:46 +0000 (20:13 +0100)
Introduce a custom column sort for the "Extension" (name) column as that
column can contain HTML which breaks a direct string comparison.

The existing ExtensionManager.compare function is renamed to
versionCompare to circumvent misunderstandings.

Resolves: #72102
Releases: master
Change-Id: I46c120458bc7e9da15c1d7d810b7a003bbbd2937
Reviewed-on: https://review.typo3.org/45184
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
typo3/sysext/extensionmanager/Resources/Public/JavaScript/Main.js

index cdbcf54..80abe12 100644 (file)
@@ -56,7 +56,9 @@ define([
                                columns: [
                                        null,
                                        null,
-                                       null,
+                                       {
+                                               type: 'extension'
+                                       },
                                        null,
                                        {
                                                type: 'version'
@@ -159,22 +161,32 @@ define([
                return vars;
        };
 
+       $.fn.dataTableExt.oSort['extension-asc'] = function(a, b) {
+               return ExtensionManager.extensionCompare(a, b);
+       };
+
+       $.fn.dataTableExt.oSort['extension-desc'] = function(a, b) {
+               var result = ExtensionManager.extensionCompare(a, b);
+               return result * -1;
+       };
+
        $.fn.dataTableExt.oSort['version-asc'] = function(a, b) {
-               var result = ExtensionManager.compare(a, b);
+               var result = ExtensionManager.versionCompare(a, b);
                return result * -1;
        };
 
        $.fn.dataTableExt.oSort['version-desc'] = function(a, b) {
-               return ExtensionManager.compare(a, b);
+               return ExtensionManager.versionCompare(a, b);
        };
 
        /**
+        * Special sorting for the extension version column
         *
         * @param {String} a
         * @param {String} b
         * @returns {Number}
         */
-       ExtensionManager.compare = function(a, b) {
+       ExtensionManager.versionCompare = function(a, b) {
                if (a === b) {
                        return 0;
                }
@@ -210,6 +222,25 @@ define([
        };
 
        /**
+        * The extension name column can contain various forms of HTML that
+        * break a direct comparision of values
+        *
+        * @param {String} a
+        * @param {String} b
+        * @returns {Number}
+        */
+       ExtensionManager.extensionCompare = function(a, b) {
+               var div = document.createElement("div");
+               div.innerHTML = a;
+               var aStr = div.textContent || div.innerText || a;
+
+               div.innerHTML = b;
+               var bStr = div.textContent || div.innerText || b;
+
+               return aStr.trim().localeCompare(bStr.trim());
+       }
+
+       /**
         *
         * @param {Object} data
         */