From 1a54f87b5bda9de580a17b4eb0966c31e9835abd Mon Sep 17 00:00:00 2001
From: yflory <yann.flory@xwiki.com>
Date: Thu, 28 May 2020 12:17:32 +0200
Subject: [PATCH] Improve sort button in drive

---
 www/common/common-ui-elements.js | 13 +++++++++++--
 www/common/drive-ui.js           |  9 +++++----
 2 files changed, 16 insertions(+), 6 deletions(-)

diff --git a/www/common/common-ui-elements.js b/www/common/common-ui-elements.js
index 868de93f4..ef1f13ca2 100644
--- a/www/common/common-ui-elements.js
+++ b/www/common/common-ui-elements.js
@@ -2141,8 +2141,17 @@ define([
 
         var show = function () {
             var wh = $(window).height();
-            var topPos = $container[0].getBoundingClientRect().bottom;
-            $innerblock.css('max-height', Math.floor(wh - topPos - 1)+'px');
+            var button = $button[0].getBoundingClientRect();
+            var topPos = button.bottom;
+            $innerblock.css('bottom', '');
+            if (config.noscroll) {
+                var h = $innerblock.outerHeight();
+                if ((topPos + h) > wh) {
+                    $innerblock.css('bottom', button.height+'px');
+                }
+            } else {
+                $innerblock.css('max-height', Math.floor(wh - topPos - 1)+'px');
+            }
             $innerblock.show();
             $innerblock.find('.cp-dropdown-element-active').removeClass('cp-dropdown-element-active');
             if (config.isSelect && value) {
diff --git a/www/common/drive-ui.js b/www/common/drive-ui.js
index 6d9eccfaa..45b7c51f3 100644
--- a/www/common/drive-ui.js
+++ b/www/common/drive-ui.js
@@ -2748,21 +2748,22 @@ define([
             var options = [{
                 tag: 'a',
                 attributes: {'class': 'cp-app-drive-element-type'},
-                content: Messages.fm_type
+                content: '<i class="fa fa-minus"></i>' + Messages.fm_type
             },{
                 tag: 'a',
                 attributes: {'class': 'cp-app-drive-element-atime'},
-                content: Messages.fm_lastAccess
+                content: '<i class="fa fa-minus"></i>' + Messages.fm_lastAccess
             },{
                 tag: 'a',
                 attributes: {'class': 'cp-app-drive-element-ctime'},
-                content: Messages.fm_creation
+                content: '<i class="fa fa-minus"></i>' + Messages.fm_creation
             }];
             var dropdownConfig = {
                 text: '', // Button initial text
                 options: options, // Entries displayed in the menu
                 container: $fhSort,
                 left: true,
+                noscroll: true,
                 common: common
             };
             var $sortBlock = UIElements.createDropdown(dropdownConfig);
@@ -2805,7 +2806,7 @@ define([
             if (APP.store[SORT_FILE_BY] === '') { classSorted = 'cp-app-drive-sort-filename'; }
             else if (APP.store[SORT_FILE_BY]) { classSorted = 'cp-app-drive-element-' + APP.store[SORT_FILE_BY]; }
             if (classSorted) {
-                $list.find('.' + classSorted).addClass('cp-app-drive-sort-active').prepend($icon);
+                $list.find('.' + classSorted).addClass('cp-app-drive-sort-active').prepend($icon).find('i').hide();
             }
         };
         var getFileListHeader = function (clickable) {