2014-08-14 13:48:38 +00:00
|
|
|
/* global Handlebars */
|
2012-08-04 18:12:18 +00:00
|
|
|
OC.Settings = OC.Settings || {};
|
|
|
|
OC.Settings.Apps = OC.Settings.Apps || {
|
2015-09-05 01:24:18 +00:00
|
|
|
rebuildNavigation: function() {
|
2018-04-10 12:23:30 +00:00
|
|
|
$.getJSON(OC.linkToOCS('core/navigation', 2) + 'apps?format=json').done(function(response){
|
|
|
|
if(response.ocs.meta.status === 'ok') {
|
2017-03-03 14:09:08 +00:00
|
|
|
var addedApps = {};
|
2018-04-10 12:23:30 +00:00
|
|
|
var navEntries = response.ocs.data;
|
2018-07-25 11:50:46 +00:00
|
|
|
var container = $('#navigation #apps ul');
|
2017-03-03 12:00:37 +00:00
|
|
|
|
|
|
|
// remove disabled apps
|
|
|
|
for (var i = 0; i < navEntries.length; i++) {
|
2012-10-26 18:12:14 +00:00
|
|
|
var entry = navEntries[i];
|
2017-03-03 14:09:08 +00:00
|
|
|
if(container.children('li[data-id="' + entry.id + '"]').length === 0) {
|
|
|
|
addedApps[entry.id] = true;
|
|
|
|
}
|
2017-03-03 12:00:37 +00:00
|
|
|
}
|
|
|
|
container.children('li[data-id]').each(function (index, el) {
|
2017-03-03 14:09:08 +00:00
|
|
|
var id = $(el).data('id');
|
|
|
|
// remove all apps that are not in the correct order
|
2017-04-25 15:25:28 +00:00
|
|
|
if (!navEntries[index] || (navEntries[index] && navEntries[index].id !== $(el).data('id'))) {
|
2017-03-03 12:00:37 +00:00
|
|
|
$(el).remove();
|
2017-03-03 14:09:08 +00:00
|
|
|
$('#appmenu li[data-id='+id+']').remove();
|
2017-03-03 12:00:37 +00:00
|
|
|
}
|
|
|
|
});
|
2012-10-26 18:12:14 +00:00
|
|
|
|
2017-04-25 15:25:28 +00:00
|
|
|
var previousEntry = {};
|
2017-03-03 12:00:37 +00:00
|
|
|
// 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></li>');
|
2012-10-26 18:12:14 +00:00
|
|
|
li.attr('data-id', entry.id);
|
2017-04-25 15:25:28 +00:00
|
|
|
var img = '<svg width="16" height="16" viewBox="0 0 16 16">';
|
2016-08-01 19:48:06 +00:00
|
|
|
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>';
|
2017-04-25 15:25:28 +00:00
|
|
|
img += '<image x="0" y="0" width="16" height="16" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="' + entry.icon + '" class="app-icon" /></svg>';
|
2017-03-03 12:00:37 +00:00
|
|
|
var a = $('<a></a>').attr('href', entry.href);
|
|
|
|
var filename = $('<span></span>');
|
2015-04-23 19:39:59 +00:00
|
|
|
var loading = $('<div class="icon-loading-dark"></div>').css('display', 'none');
|
2013-04-12 12:45:59 +00:00
|
|
|
filename.text(entry.name);
|
|
|
|
a.prepend(filename);
|
2015-04-23 19:39:59 +00:00
|
|
|
a.prepend(loading);
|
2013-02-03 15:02:25 +00:00
|
|
|
a.prepend(img);
|
2012-10-26 18:12:14 +00:00
|
|
|
li.append(a);
|
2014-02-26 09:34:38 +00:00
|
|
|
|
2018-07-03 10:14:34 +00:00
|
|
|
// add app icon to the navigation
|
|
|
|
var previousElement = $('#navigation li[data-id=' + previousEntry.id + ']');
|
|
|
|
if (previousElement.length > 0) {
|
|
|
|
previousElement.after(li);
|
|
|
|
} else {
|
|
|
|
$('#navigation #apps').prepend(li);
|
|
|
|
}
|
2014-02-26 09:34:38 +00:00
|
|
|
|
|
|
|
// draw attention to the newly added app entry
|
2018-03-08 16:09:29 +00:00
|
|
|
// by flashing twice the more apps menu
|
2017-03-03 14:09:08 +00:00
|
|
|
if(addedApps[entry.id]) {
|
2018-03-08 16:09:29 +00:00
|
|
|
$('#header #more-apps')
|
2017-03-03 14:09:08 +00:00
|
|
|
.animate({opacity: 0.5})
|
|
|
|
.animate({opacity: 1})
|
|
|
|
.animate({opacity: 0.5})
|
2018-03-08 16:09:29 +00:00
|
|
|
.animate({opacity: 1});
|
2017-03-03 12:00:37 +00:00
|
|
|
}
|
2017-03-03 14:09:08 +00:00
|
|
|
}
|
2017-03-03 12:00:37 +00:00
|
|
|
|
2017-04-25 15:25:28 +00:00
|
|
|
if ($('#appmenu').children('li[data-id="' + entry.id + '"]').length === 0) {
|
2018-01-03 08:17:14 +00:00
|
|
|
var li = $('<li></li>');
|
|
|
|
li.attr('data-id', entry.id);
|
|
|
|
var img = '<img src="' + entry.icon + '" class="app-icon">';
|
|
|
|
if (OCA.Theming && OCA.Theming.inverted) {
|
|
|
|
img = '<svg width="20" height="20" viewBox="0 0 20 20">';
|
|
|
|
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>';
|
|
|
|
img += '<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="' + entry.icon + '" class="app-icon" /></svg>';
|
|
|
|
}
|
|
|
|
var a = $('<a></a>').attr('href', entry.href);
|
|
|
|
var filename = $('<span></span>');
|
|
|
|
var loading = $('<div class="icon-loading-dark"></div>').css('display', 'none');
|
|
|
|
filename.text(entry.name);
|
|
|
|
a.prepend(filename);
|
|
|
|
a.prepend(loading);
|
|
|
|
a.prepend(img);
|
|
|
|
li.append(a);
|
2018-07-03 10:14:34 +00:00
|
|
|
|
|
|
|
// add app icon to the navigation
|
|
|
|
var previousElement = $('#appmenu li[data-id=' + previousEntry.id + ']');
|
|
|
|
if (previousElement.length > 0) {
|
|
|
|
previousElement.after(li);
|
|
|
|
} else {
|
|
|
|
$('#appmenu').prepend(li);
|
|
|
|
}
|
|
|
|
|
2018-01-03 08:17:14 +00:00
|
|
|
if(addedApps[entry.id]) {
|
|
|
|
li.animate({opacity: 0.5})
|
|
|
|
.animate({opacity: 1})
|
|
|
|
.animate({opacity: 0.5})
|
|
|
|
.animate({opacity: 1});
|
|
|
|
}
|
2012-10-26 18:12:14 +00:00
|
|
|
}
|
2017-03-03 14:09:08 +00:00
|
|
|
previousEntry = entry;
|
2012-10-26 18:12:14 +00:00
|
|
|
}
|
2015-09-05 01:24:18 +00:00
|
|
|
|
2017-04-25 15:25:28 +00:00
|
|
|
$(window).trigger('resize');
|
2012-10-26 18:12:14 +00:00
|
|
|
}
|
|
|
|
});
|
2015-02-23 14:29:25 +00:00
|
|
|
}
|
2018-05-29 20:53:20 +00:00
|
|
|
};
|