|
@@ -1,14 +1,6 @@
|
|
|
// Specific code for the 'federation-structures' page
|
|
// Specific code for the 'federation-structures' page
|
|
|
|
|
|
|
|
-const variants_uris = {
|
|
|
|
|
- "preprod.opentalent.fr": "https://api.preprod.opentalent.fr",
|
|
|
|
|
- "local.sub.opentalent.fr": "https://local.api.opentalent.fr",
|
|
|
|
|
- "typo3": "http://docker.nginx.opentalent.fr"
|
|
|
|
|
-};
|
|
|
|
|
-
|
|
|
|
|
-const base_uri = variants_uris[$(location).attr('hostname')];
|
|
|
|
|
-let apiGetUrl = base_uri + '/api/public/federation_structures?_format=json&page=1&itemsPerPage=99999';
|
|
|
|
|
-
|
|
|
|
|
|
|
+const apiGetUrl = "/typo3/index.php?route=/otcore/structures/all";
|
|
|
|
|
|
|
|
// Converts numeric degrees to radians
|
|
// Converts numeric degrees to radians
|
|
|
function toRad(Value)
|
|
function toRad(Value)
|
|
@@ -69,7 +61,7 @@ $(document).ready(function() {
|
|
|
let resetButton = form.find("button.reset-search").first();
|
|
let resetButton = form.find("button.reset-search").first();
|
|
|
let submitButton = form.find("button.submit-search").first();
|
|
let submitButton = form.find("button.submit-search").first();
|
|
|
|
|
|
|
|
- let organizationId = queryParameters.get('organization-id') || structureFrame.data('organization-id');
|
|
|
|
|
|
|
+ let organizationId = parseInt(queryParameters.get('organization-id') || structureFrame.data('organization-id'));
|
|
|
if (!organizationId) {
|
|
if (!organizationId) {
|
|
|
pleaseWaitSpan.hide();
|
|
pleaseWaitSpan.hide();
|
|
|
errorMsgSpan.show();
|
|
errorMsgSpan.show();
|
|
@@ -151,6 +143,11 @@ $(document).ready(function() {
|
|
|
// Does the given structure match the current query
|
|
// Does the given structure match the current query
|
|
|
function matchCurrentQuery(structure) {
|
|
function matchCurrentQuery(structure) {
|
|
|
|
|
|
|
|
|
|
+ // Is the structure a member of the website federation?
|
|
|
|
|
+ if (![structure.n1Id, structure.n2Id, structure.n3Id, structure.n4Id, structure.n5Id].includes(organizationId)) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
// Filter by name
|
|
// Filter by name
|
|
|
if (query['what'] && !structure.name.toLowerCase().includes(query['what'].toLowerCase())) {
|
|
if (query['what'] && !structure.name.toLowerCase().includes(query['what'].toLowerCase())) {
|
|
|
return false;
|
|
return false;
|
|
@@ -207,10 +204,10 @@ $(document).ready(function() {
|
|
|
function populateFederationsSelect() {
|
|
function populateFederationsSelect() {
|
|
|
federationSelect.children('option:not(:first)').remove();
|
|
federationSelect.children('option:not(:first)').remove();
|
|
|
let has_options = false;
|
|
let has_options = false;
|
|
|
|
|
+
|
|
|
structures.forEach(function (structure) {
|
|
structures.forEach(function (structure) {
|
|
|
if (structure.n1Id === organizationId && structure.principalType.endsWith('FEDERATION')) {
|
|
if (structure.n1Id === organizationId && structure.principalType.endsWith('FEDERATION')) {
|
|
|
- let id = structure['@id'].split('/').pop()
|
|
|
|
|
- let option = '<option value="' + id + '">' + structure.name + '</option>';
|
|
|
|
|
|
|
+ let option = '<option value="' + structure.id + '">' + structure.name + '</option>';
|
|
|
federationSelect.append(option);
|
|
federationSelect.append(option);
|
|
|
has_options = true;
|
|
has_options = true;
|
|
|
}
|
|
}
|
|
@@ -260,24 +257,31 @@ $(document).ready(function() {
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
|
|
|
|
|
+ sortKeys = function (x) {
|
|
|
|
|
+ return x.addressCity.toLowerCase() + x.name.toLowerCase();
|
|
|
|
|
+ }
|
|
|
|
|
+ results.sort((a, b) => sortKeys(a).localeCompare(sortKeys(b)));
|
|
|
|
|
+
|
|
|
// ** Show the results for the current page
|
|
// ** Show the results for the current page
|
|
|
let index = 0;
|
|
let index = 0;
|
|
|
|
|
|
|
|
results.forEach(function(structure) {
|
|
results.forEach(function(structure) {
|
|
|
if (((currentPage - 1) * itemsPerPage) <= index && index < (currentPage * itemsPerPage)) {
|
|
if (((currentPage - 1) * itemsPerPage) <= index && index < (currentPage * itemsPerPage)) {
|
|
|
let cardDiv = $(cardDivModel).clone();
|
|
let cardDiv = $(cardDivModel).clone();
|
|
|
|
|
+ let categoryTagModel = cardDiv.find('.structure-category-model').first();
|
|
|
|
|
|
|
|
cardDiv.data('id', structure.id);
|
|
cardDiv.data('id', structure.id);
|
|
|
|
|
|
|
|
- let categoryTagModel = cardDiv.find('.structure-category-model').first();
|
|
|
|
|
- structure.categories.forEach(function (cat) {
|
|
|
|
|
- let tag = categoryTagModel.clone();
|
|
|
|
|
- tag.text(structures_categories[cat]);
|
|
|
|
|
- tag.removeClass('structure-category-model')
|
|
|
|
|
- tag.addClass('structure-category')
|
|
|
|
|
- tag.show();
|
|
|
|
|
- categoryTagModel.parent().append(tag);
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ if (structure.categories !== null) {
|
|
|
|
|
+ structure.categories.forEach(function (cat) {
|
|
|
|
|
+ let tag = categoryTagModel.clone();
|
|
|
|
|
+ tag.text(structures_categories[cat]);
|
|
|
|
|
+ tag.removeClass('structure-category-model')
|
|
|
|
|
+ tag.addClass('structure-category')
|
|
|
|
|
+ tag.show();
|
|
|
|
|
+ categoryTagModel.parent().append(tag);
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
cardDiv.find('.structure-poster').first().children('img').first().attr('src', structure.logoUri);
|
|
cardDiv.find('.structure-poster').first().children('img').first().attr('src', structure.logoUri);
|
|
|
cardDiv.find('.structure-name').first().text(structure.name);
|
|
cardDiv.find('.structure-name').first().text(structure.name);
|
|
@@ -310,8 +314,12 @@ $(document).ready(function() {
|
|
|
map.addLayer(clusters);
|
|
map.addLayer(clusters);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // ** Update pagination
|
|
|
|
|
|
|
+ // ** Update results count and pagination
|
|
|
let resultsCount = results.length;
|
|
let resultsCount = results.length;
|
|
|
|
|
+
|
|
|
|
|
+ resultsCountMessage.show();
|
|
|
|
|
+ resultsCountVar.text("" + resultsCount);
|
|
|
|
|
+
|
|
|
let pagesCount = Math.floor(resultsCount / itemsPerPage) + 1;
|
|
let pagesCount = Math.floor(resultsCount / itemsPerPage) + 1;
|
|
|
gotoLastPage.data("page", pagesCount);
|
|
gotoLastPage.data("page", pagesCount);
|
|
|
|
|
|
|
@@ -355,24 +363,41 @@ $(document).ready(function() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// #### Load structures data and refresh
|
|
// #### Load structures data and refresh
|
|
|
- var structures = [];
|
|
|
|
|
- $.ajax({
|
|
|
|
|
- type: 'GET',
|
|
|
|
|
- url: apiGetUrl,
|
|
|
|
|
- dataType: "json",
|
|
|
|
|
- contentType: "application/json; charset=utf-8",
|
|
|
|
|
- timeout : 5000
|
|
|
|
|
- })
|
|
|
|
|
- .done(function(res) {
|
|
|
|
|
- structures = res["hydra:member"];
|
|
|
|
|
- populateFederationsSelect();
|
|
|
|
|
- refresh();
|
|
|
|
|
- })
|
|
|
|
|
- .fail(function(xhr, textStatus, errorThrown) {
|
|
|
|
|
- pleaseWaitSpan.hide();
|
|
|
|
|
- errorMsgSpan.show();
|
|
|
|
|
- throw 'Error while fetching the API data: ' + textStatus + ' - ' + errorThrown;
|
|
|
|
|
- });
|
|
|
|
|
|
|
+ var structures;
|
|
|
|
|
+
|
|
|
|
|
+ function loadStructures() {
|
|
|
|
|
+ structures = []
|
|
|
|
|
+
|
|
|
|
|
+ $.ajax({
|
|
|
|
|
+ type: 'GET',
|
|
|
|
|
+ url: apiGetUrl,
|
|
|
|
|
+ dataType: "json",
|
|
|
|
|
+ contentType: "application/json; charset=utf-8",
|
|
|
|
|
+ timeout : 12000,
|
|
|
|
|
+ })
|
|
|
|
|
+ .done(function(res) {
|
|
|
|
|
+
|
|
|
|
|
+ res.forEach(function(item) {
|
|
|
|
|
+ structure = item;
|
|
|
|
|
+ structure.n1Id = parseInt(structure.n1Id);
|
|
|
|
|
+ structure.n2Id = parseInt(structure.n2Id);
|
|
|
|
|
+ structure.n3Id = parseInt(structure.n3Id);
|
|
|
|
|
+ structure.n4Id = parseInt(structure.n4Id);
|
|
|
|
|
+ structure.n5Id = parseInt(structure.n5Id);
|
|
|
|
|
+ structure.categories = structure.categories !== null ? structure.categories.split(",") : [];
|
|
|
|
|
+ structures.push(structure);
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
|
|
+ populateFederationsSelect();
|
|
|
|
|
+ refresh();
|
|
|
|
|
+ })
|
|
|
|
|
+ .fail(function(xhr, textStatus, errorThrown) {
|
|
|
|
|
+ pleaseWaitSpan.hide();
|
|
|
|
|
+ errorMsgSpan.show();
|
|
|
|
|
+ throw 'Error while fetching the API data: ' + textStatus + ' - ' + errorThrown;
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+ loadStructures();
|
|
|
|
|
|
|
|
|
|
|
|
|
// #### Events
|
|
// #### Events
|