100 lines
3.6 KiB
JavaScript
100 lines
3.6 KiB
JavaScript
GADJO_DEFAULT_SIDEPAGE_STATUS = 'expanded';
|
|
|
|
$(function() {
|
|
var all_done = false;
|
|
|
|
function check_all_done() {
|
|
var local_done = true;
|
|
$(COMBO_KNOWN_SERVICES).each(function(index, service) {
|
|
if (service.data === undefined) {
|
|
local_done = false;
|
|
}
|
|
});
|
|
all_done = local_done;
|
|
if (all_done) {
|
|
window.sessionStorage.hobo_environment = JSON.stringify(COMBO_KNOWN_SERVICES);
|
|
window.sessionStorage.hobo_environment_timestamp = Date.now();
|
|
create_menu_items();
|
|
$(document).trigger('publik:environment-loaded', {services: COMBO_KNOWN_SERVICES});
|
|
}
|
|
}
|
|
|
|
function create_menu_items() {
|
|
$('#sidepage-menu').remove();
|
|
var menu_links = $('<ul id="sidepage-menu">');
|
|
var more_entries = Array();
|
|
var service_order = Array('authentic', 'wcs', 'combo', 'passerelle', 'hobo');
|
|
COMBO_KNOWN_SERVICES.sort(function(a, b) {
|
|
a_service_order = service_order.indexOf(a.service_id);
|
|
b_service_order = service_order.indexOf(b.service_id);
|
|
if (a_service_order == b_service_order) {
|
|
return a.service_id.localeCompare(b.service_id);
|
|
}
|
|
if (a_service_order < 0) return 1;
|
|
if (b_service_order < 0) return -1;
|
|
return a_service_order - b_service_order;
|
|
});
|
|
$(COMBO_KNOWN_SERVICES).each(function(index, service) {
|
|
if (service.data === undefined || service.data.length == 0) {
|
|
return;
|
|
}
|
|
if (service.service_id == 'wcs' && service.uniq === false) {
|
|
/* as wcs comes with many menu entries, if it's not the only instance
|
|
* in the environment, we only insert all the items if it's the
|
|
* currently active site.
|
|
*/
|
|
var that_hostname = $('<a>').attr('href', service.backoffice_menu_url)[0].hostname;
|
|
var this_hostname = window.location.hostname;
|
|
if (that_hostname != this_hostname) {
|
|
more_entries.push({
|
|
title: service.title,
|
|
url: service.data[0].url});
|
|
return;
|
|
}
|
|
}
|
|
$(service.data).each(function(idx, element) {
|
|
var li = $('<li><a href="#">' + element.label + '</a></li>').appendTo(menu_links);
|
|
$(li).find('a').attr('href', element.url);
|
|
if (element.icon !== undefined) {
|
|
$(li).find('a').addClass('icon-' + element.icon);
|
|
}
|
|
if (window.location.href.indexOf(element.url) == 0) {
|
|
$(li).addClass('active');
|
|
}
|
|
});
|
|
});
|
|
$(more_entries).each(function(index, entry) {
|
|
var li = $('<li><a href="#">' + entry.title + '</a></li>').appendTo(menu_links);
|
|
$(li).find('a').attr('href', entry.url);
|
|
});
|
|
menu_links.appendTo('#sidepage');
|
|
}
|
|
|
|
if (window.sessionStorage.hobo_environment &&
|
|
parseInt(window.sessionStorage.hobo_environment_timestamp) > Date.now()-600000) {
|
|
COMBO_KNOWN_SERVICES = JSON.parse(window.sessionStorage.hobo_environment);
|
|
$(document).trigger('publik:environment-loaded', {services: COMBO_KNOWN_SERVICES});
|
|
create_menu_items();
|
|
} else {
|
|
$(COMBO_KNOWN_SERVICES).each(function(index, element) {
|
|
if (element.backoffice_menu_url === null) {
|
|
element.data = Array();
|
|
check_all_done();
|
|
return;
|
|
}
|
|
$.ajax({url: element.backoffice_menu_url,
|
|
xhrFields: { withCredentials: true },
|
|
async: true,
|
|
dataType: 'jsonp',
|
|
crossDomain: true,
|
|
success: function(data) { element.data = data; check_all_done(); },
|
|
error: function(error) { console.log('bouh', error); element.data = Array(); check_all_done(); }
|
|
}
|
|
);
|
|
});
|
|
}
|
|
|
|
var sidepage_button = $('#sidepage #applabel');
|
|
sidepage_button.text('Publik ▼');
|
|
});
|