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);
|
2018-11-16 09:53:31 +00:00
|
|
|
var img = '<svg width="20" height="20" viewBox="0 0 20 20" alt="">';
|
|
|
|
if (OCA.Theming && OCA.Theming.inverted) {
|
|
|
|
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" />';
|
|
|
|
} else {
|
|
|
|
img += '<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet" xlink:href="' + entry.icon + '" class="app-icon" />';
|
|
|
|
}
|
|
|
|
img += '</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');
|
2018-11-16 09:53:31 +00:00
|
|
|
filename.text(entry.name); filename.text(entry.name);
|
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);
|
2018-11-16 09:53:31 +00:00
|
|
|
li.append(filename);
|
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);
|
2018-11-16 09:53:31 +00:00
|
|
|
// Generating svg embedded image (see layout.user.php)
|
|
|
|
var img = '<svg width="20" height="20" viewBox="0 0 20 20" alt="">';
|
2018-01-03 08:17:14 +00:00
|
|
|
if (OCA.Theming && OCA.Theming.inverted) {
|
|
|
|
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>';
|
2018-11-16 09:53:31 +00:00
|
|
|
img += '<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet" filter="url(#invert)" xlink:href="' + entry.icon + '" class="app-icon" />';
|
|
|
|
} else {
|
|
|
|
img += '<image x="0" y="0" width="20" height="20" preserveAspectRatio="xMinYMin meet" xlink:href="' + entry.icon + '" class="app-icon" />';
|
2018-01-03 08:17:14 +00:00
|
|
|
}
|
2018-11-16 09:53:31 +00:00
|
|
|
img += '</svg>';
|
2018-01-03 08:17:14 +00:00
|
|
|
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(loading);
|
|
|
|
a.prepend(img);
|
|
|
|
li.append(a);
|
2018-11-16 09:53:31 +00:00
|
|
|
li.append(filename);
|
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-11-16 09:53:31 +00:00
|
|
|
};
|