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