From 1d6fba03f4788dd562308df5a63582816c33a5a5 Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Fri, 3 Mar 2017 13:00:37 +0100 Subject: Make enabling/disabling apps work with the new menu Signed-off-by: Julius Haertl --- settings/js/apps.js | 76 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 57 insertions(+), 19 deletions(-) (limited to 'settings/js/apps.js') diff --git a/settings/js/apps.js b/settings/js/apps.js index b73b4a35b3f..3a00152aab2 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -451,22 +451,38 @@ OC.Settings.Apps = OC.Settings.Apps || { rebuildNavigation: function() { $.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php')).done(function(response){ - if(response.status === 'success'){ + if(response.status === 'success') { var idsToKeep = {}; - var navEntries=response.nav_entries; + var navEntries = response.nav_entries; var container = $('#apps ul'); - for(var i=0; i< navEntries.length; i++){ + + // remove disabled apps + for (var i = 0; i < navEntries.length; i++) { var entry = navEntries[i]; idsToKeep[entry.id] = true; + } + container.children('li[data-id]').each(function (index, el) { + if (!idsToKeep[$(el).data('id')]) { + $(el).remove(); + } + }); + $('#appmenu ul').children('li[data-id]').each(function (index, el) { + if (!idsToKeep[$(el).data('id')]) { + $(el).remove(); + } + }); - if(container.children('li[data-id="'+entry.id+'"]').length === 0){ - var li=$('
  • '); + // add enabled apps to #navigation and #appmenu + for (var i = 0; i < navEntries.length; i++) { + var entry = navEntries[i]; + if (container.children('li[data-id="' + entry.id + '"]').length === 0) { + var li = $('
  • '); li.attr('data-id', entry.id); var img = ''; img += ''; img += ''; - var a=$('').attr('href', entry.href); - var filename=$(''); + var a = $('').attr('href', entry.href); + var filename = $(''); var loading = $('
    ').css('display', 'none'); filename.text(entry.name); a.prepend(filename); @@ -477,13 +493,7 @@ OC.Settings.Apps = OC.Settings.Apps || { // append the new app as last item in the list // which is the "add apps" entry with the id // #apps-management - $('#apps-management').before(li); - - // scroll the app navigation down - // so the newly added app is seen - $('#navigation').animate({ - scrollTop: $('#navigation').height() - }, 'slow'); + $('#navigation #apps-management').before(li); // draw attention to the newly added app entry // by flashing it twice @@ -493,14 +503,42 @@ OC.Settings.Apps = OC.Settings.Apps || { .animate({opacity: 0.5}) .animate({opacity: 1}) .animate({opacity: 0.75}); + + // do not show apps from #appmenu in #navigation + if(i < 7) { + $('#navigation li').eq(i).addClass('in-header'); + } + + // add apps to #appmenu until it is full + if ($('#appmenu li').not('.hidden').length < 8) { + var li = $('
  • '); + li.attr('data-id', entry.id); + var img = ''; + var a = $('').attr('href', entry.href); + var filename = $(''); + var loading = $('
    ').css('display', 'none'); + filename.text(entry.name); + a.prepend(filename); + a.prepend(loading); + a.prepend(img); + li.append(a); + $('#appmenu li#more-apps').before(li); + li.animate({opacity: 0.5}) + .animate({opacity: 1}) + .animate({opacity: 0.5}) + .animate({opacity: 1}) + .animate({opacity: 0.75}); + } } } - container.children('li[data-id]').each(function(index, el) { - if (!idsToKeep[$(el).data('id')]) { - $(el).remove(); - } - }); + if (navEntries.length > 7) { + $('#more-apps').show(); + $('#apps-management').hide(); + } else { + $('#more-apps').hide(); + $('#apps-management').show(); + } } }); }, -- cgit v1.2.3 From 780400302cc0d2fac77ae5640e4f572707c36665 Mon Sep 17 00:00:00 2001 From: Julius Haertl Date: Fri, 3 Mar 2017 15:09:08 +0100 Subject: Rebuild menu to keep order of icons correct Signed-off-by: Julius Haertl --- core/templates/layout.user.php | 4 ++- settings/js/apps.js | 63 +++++++++++++++++++++++------------------- 2 files changed, 38 insertions(+), 29 deletions(-) (limited to 'settings/js/apps.js') diff --git a/core/templates/layout.user.php b/core/templates/layout.user.php index 58c666fe714..f5be365a365 100644 --- a/core/templates/layout.user.php +++ b/core/templates/layout.user.php @@ -85,8 +85,9 @@ -
  • $headerIconCount-1): ?>class="hidden"> +
  • $headerIconCount-1): ?>class="hidden"> class="active"> @@ -97,6 +98,7 @@
  • + diff --git a/settings/js/apps.js b/settings/js/apps.js index 3a00152aab2..8be18c4e9c0 100644 --- a/settings/js/apps.js +++ b/settings/js/apps.js @@ -452,26 +452,27 @@ OC.Settings.Apps = OC.Settings.Apps || { rebuildNavigation: function() { $.getJSON(OC.filePath('settings', 'ajax', 'navigationdetect.php')).done(function(response){ if(response.status === 'success') { - var idsToKeep = {}; + var addedApps = {}; var navEntries = response.nav_entries; var container = $('#apps ul'); // remove disabled apps for (var i = 0; i < navEntries.length; i++) { var entry = navEntries[i]; - idsToKeep[entry.id] = true; + if(container.children('li[data-id="' + entry.id + '"]').length === 0) { + addedApps[entry.id] = true; + } } container.children('li[data-id]').each(function (index, el) { - if (!idsToKeep[$(el).data('id')]) { - $(el).remove(); - } - }); - $('#appmenu ul').children('li[data-id]').each(function (index, el) { - if (!idsToKeep[$(el).data('id')]) { + var id = $(el).data('id'); + // remove all apps that are not in the correct order + if ((navEntries[index] && navEntries[index].id !== $(el).data('id'))) { $(el).remove(); + $('#appmenu li[data-id='+id+']').remove(); } }); + var previousEntry; // add enabled apps to #navigation and #appmenu for (var i = 0; i < navEntries.length; i++) { var entry = navEntries[i]; @@ -490,25 +491,21 @@ OC.Settings.Apps = OC.Settings.Apps || { a.prepend(img); li.append(a); - // append the new app as last item in the list - // which is the "add apps" entry with the id - // #apps-management - $('#navigation #apps-management').before(li); + $('#navigation li[data-id=' + previousEntry.id + ']').after(li); // draw attention to the newly added app entry // by flashing it twice - $('#header .menutoggle') - .animate({opacity: 0.5}) - .animate({opacity: 1}) - .animate({opacity: 0.5}) - .animate({opacity: 1}) - .animate({opacity: 0.75}); - - // do not show apps from #appmenu in #navigation - if(i < 7) { - $('#navigation li').eq(i).addClass('in-header'); + if(addedApps[entry.id]) { + $('#header .menutoggle') + .animate({opacity: 0.5}) + .animate({opacity: 1}) + .animate({opacity: 0.5}) + .animate({opacity: 1}) + .animate({opacity: 0.75}); } + } + if ($('#appmenu ul').children('li[data-id="' + entry.id + '"]').length === 0) { // add apps to #appmenu until it is full if ($('#appmenu li').not('.hidden').length < 8) { var li = $('
  • '); @@ -522,16 +519,26 @@ OC.Settings.Apps = OC.Settings.Apps || { a.prepend(loading); a.prepend(img); li.append(a); - $('#appmenu li#more-apps').before(li); - li.animate({opacity: 0.5}) - .animate({opacity: 1}) - .animate({opacity: 0.5}) - .animate({opacity: 1}) - .animate({opacity: 0.75}); + $('#appmenu li[data-id='+ previousEntry.id+']').after(li); + if(addedApps[entry.id]) { + li.animate({opacity: 0.5}) + .animate({opacity: 1}) + .animate({opacity: 0.5}) + .animate({opacity: 1}); + } } } + previousEntry = entry; + // do not show apps from #appmenu in #navigation + if(i < 7) { + $('#navigation li').eq(i).addClass('in-header'); + } else { + $('#navigation li').eq(i).removeClass('in-header'); + } } + + if (navEntries.length > 7) { $('#more-apps').show(); $('#apps-management').hide(); -- cgit v1.2.3