1
0

apps.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* global Handlebars */
  2. OC.Settings = OC.Settings || {};
  3. OC.Settings.Apps = OC.Settings.Apps || {
  4. rebuildNavigation: function() {
  5. $.getJSON(OC.linkToOCS('core/navigation', 2) + 'apps?format=json').done(function(response){
  6. if(response.ocs.meta.status === 'ok') {
  7. var addedApps = {};
  8. var navEntries = response.ocs.data;
  9. var container = $('#navigation #apps ul');
  10. // remove disabled apps
  11. for (var i = 0; i < navEntries.length; i++) {
  12. var entry = navEntries[i];
  13. if(container.children('li[data-id="' + entry.id + '"]').length === 0) {
  14. addedApps[entry.id] = true;
  15. }
  16. }
  17. container.children('li[data-id]').each(function (index, el) {
  18. var id = $(el).data('id');
  19. // remove all apps that are not in the correct order
  20. if (!navEntries[index] || (navEntries[index] && navEntries[index].id !== $(el).data('id'))) {
  21. $(el).remove();
  22. $('#appmenu li[data-id='+id+']').remove();
  23. }
  24. });
  25. var previousEntry = {};
  26. // add enabled apps to #navigation and #appmenu
  27. for (var i = 0; i < navEntries.length; i++) {
  28. var entry = navEntries[i];
  29. if (container.children('li[data-id="' + entry.id + '"]').length === 0) {
  30. var li = $('<li></li>');
  31. li.attr('data-id', entry.id);
  32. var img = '<svg width="20" height="20" viewBox="0 0 20 20" alt="">';
  33. if (OCA.Theming && OCA.Theming.inverted) {
  34. img += '<defs><filter id="invert"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0" /></filter></defs>';
  35. img += '<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="' + entry.icon + '" class="app-icon" />';
  36. } else {
  37. img += '<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet" xlink:href="' + entry.icon + '" class="app-icon" />';
  38. }
  39. img += '</svg>';
  40. var a = $('<a></a>').attr('href', entry.href);
  41. var filename = $('<span></span>');
  42. var loading = $('<div class="icon-loading-dark"></div>').css('display', 'none');
  43. filename.text(entry.name);
  44. a.prepend(loading);
  45. a.prepend(filename);
  46. a.prepend(img);
  47. li.append(a);
  48. // add app icon to the navigation
  49. var previousElement = $('#navigation li[data-id=' + previousEntry.id + ']');
  50. if (previousElement.length > 0) {
  51. previousElement.after(li);
  52. } else {
  53. $('#navigation #apps').prepend(li);
  54. }
  55. // draw attention to the newly added app entry
  56. // by flashing twice the more apps menu
  57. if(addedApps[entry.id]) {
  58. $('#header #more-apps')
  59. .animate({opacity: 0.5})
  60. .animate({opacity: 1})
  61. .animate({opacity: 0.5})
  62. .animate({opacity: 1});
  63. }
  64. }
  65. if ($('#appmenu').children('li[data-id="' + entry.id + '"]').length === 0) {
  66. var li = $('<li></li>');
  67. li.attr('data-id', entry.id);
  68. // Generating svg embedded image (see layout.user.php)
  69. var img = '<svg width="20" height="20" viewBox="0 0 20 20" alt="">';
  70. if (OCA.Theming && OCA.Theming.inverted) {
  71. img += '<defs><filter id="invert"><feColorMatrix in="SourceGraphic" type="matrix" values="-1 0 0 0 1 0 -1 0 0 1 0 0 -1 0 1 0 0 0 1 0" /></filter></defs>';
  72. img += '<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="' + entry.icon + '" class="app-icon" />';
  73. } else {
  74. img += '<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet" xlink:href="' + entry.icon + '" class="app-icon" />';
  75. }
  76. img += '</svg>';
  77. var a = $('<a></a>').attr('href', entry.href);
  78. var filename = $('<span></span>');
  79. var loading = $('<div class="icon-loading-dark"></div>').css('display', 'none');
  80. filename.text(entry.name);
  81. a.prepend(loading);
  82. a.prepend(filename);
  83. a.prepend(img);
  84. li.append(a);
  85. // add app icon to the navigation
  86. var previousElement = $('#appmenu li[data-id=' + previousEntry.id + ']');
  87. if (previousElement.length > 0) {
  88. previousElement.after(li);
  89. } else {
  90. $('#appmenu').prepend(li);
  91. }
  92. if(addedApps[entry.id]) {
  93. li.animate({opacity: 0.5})
  94. .animate({opacity: 1})
  95. .animate({opacity: 0.5})
  96. .animate({opacity: 1});
  97. }
  98. }
  99. previousEntry = entry;
  100. }
  101. $(window).trigger('resize');
  102. }
  103. });
  104. }
  105. };