diff --git a/main/webapp/modules/core/externals/suggest/suggest-4_3.js b/main/webapp/modules/core/externals/suggest/suggest-4_3.js index dcd69df04..e4096b6e9 100644 --- a/main/webapp/modules/core/externals/suggest/suggest-4_3.js +++ b/main/webapp/modules/core/externals/suggest/suggest-4_3.js @@ -1258,7 +1258,7 @@ xhr.getResponseHeader("X-Metaweb-TID")); } }, - dataType: "jsonp", + dataType: o.access === undefined ? "jsonp" : o.access, cache: true }; @@ -1508,7 +1508,7 @@ xhr.getResponseHeader("X-Metaweb-TID")); } }, - dataType: "jsonp", + dataType: o.access === undefined ? "jsonp" : o.access, cache: true }; if (o.flyout_lang) { diff --git a/main/webapp/modules/core/scripts/reconciliation/recon-manager.js b/main/webapp/modules/core/scripts/reconciliation/recon-manager.js index 23c379ba7..7c737e371 100644 --- a/main/webapp/modules/core/scripts/reconciliation/recon-manager.js +++ b/main/webapp/modules/core/scripts/reconciliation/recon-manager.js @@ -68,15 +68,12 @@ ReconciliationManager.registerStandardService = function(url, f, silent) { dismissBusy = DialogSystem.showBusy($.i18n('core-recon/contact-service')+"..."); } - $.ajax( - url, - { "dataType" : "jsonp", - "timeout":10000 - } - ) - .success(function(data, textStatus, jqXHR) { + var registerService = function(data, mode) { data.url = url; - data.ui = { "handler" : "ReconStandardServicePanel" }; + data.ui = { + "handler" : "ReconStandardServicePanel", + "access" : mode + }; index = ReconciliationManager.customServices.length + ReconciliationManager.standardServices.length; @@ -91,12 +88,35 @@ ReconciliationManager.registerStandardService = function(url, f, silent) { if (f) { f(index); } + }; + + // First, try with CORS (default "json" dataType) + $.ajax( + url, + { "dataType" : "json", + "timeout":5000 + } + ) + .success(function(data, textStatus, jqXHR) { + registerService(data, "json"); }) .error(function(jqXHR, textStatus, errorThrown) { - if (!silent) { - dismissBusy(); - alert($.i18n('core-recon/error-contact')+': ' + textStatus + ' : ' + errorThrown + ' - ' + url); - } + // If it fails, try with JSONP + $.ajax( + url, + { "dataType" : "jsonp", + "timeout": 5000 + } + ) + .success(function(data, textStatus, jqXHR) { + registerService(data, "jsonp"); + }) + .error(function(jqXHR, textStatus, errorThrown) { + if (!silent) { + dismissBusy(); + alert($.i18n('core-recon/error-contact')+': ' + textStatus + ' : ' + errorThrown + ' - ' + url); + } + }); }); }; diff --git a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js index 2d2612168..b8c742e98 100644 --- a/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js +++ b/main/webapp/modules/core/scripts/reconciliation/standard-service-panel.js @@ -222,6 +222,10 @@ ReconStandardServicePanel.prototype._wireEvents = function() { var suggestOptions = $.extend({}, this._service.suggest.type); suggestOptions.key = null; suggestOptions.query_param_name = "prefix"; + // CORS/JSONP support + if (this._service.ui && this._service.ui.access) { + suggestOptions.access = this._service.ui.access; + } input.suggestT(suggestOptions); } @@ -246,6 +250,10 @@ ReconStandardServicePanel.prototype._rewirePropertySuggests = function(type) { var suggestOptions = $.extend({}, this._service.suggest.property); suggestOptions.key = null; suggestOptions.query_param_name = "prefix"; + // CORS/JSONP support + if (this._service.ui && this._service.ui.access) { + suggestOptions.access = this._service.ui.access; + } if (type) { suggestOptions.type = typeof type == "string" ? type : type.id; } diff --git a/main/webapp/modules/core/scripts/views/data-table/cell-ui.js b/main/webapp/modules/core/scripts/views/data-table/cell-ui.js index 9807e61bf..7911587eb 100644 --- a/main/webapp/modules/core/scripts/views/data-table/cell-ui.js +++ b/main/webapp/modules/core/scripts/views/data-table/cell-ui.js @@ -212,6 +212,10 @@ DataTableCellUI.prototype._render = function() { if ('view' in service && 'url' in service.view && !('view_url' in suggestOptions)) { suggestOptions.view_url = service.view.url; } + // CORS / JSONP support + if (service.ui && service.ui.access) { + suggestOptions.access = service.ui.access; + } addSuggest = true; } diff --git a/main/webapp/modules/core/scripts/views/data-table/menu-reconcile.js b/main/webapp/modules/core/scripts/views/data-table/menu-reconcile.js index bc5585f11..aac720202 100644 --- a/main/webapp/modules/core/scripts/views/data-table/menu-reconcile.js +++ b/main/webapp/modules/core/scripts/views/data-table/menu-reconcile.js @@ -85,6 +85,12 @@ DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) { if (service && service.suggest && service.suggest.entity) { suggestOptions = $.extend({}, service.suggest.entity); suggestOptions.query_param_name = "prefix"; + + // CORS / JSONP support + if (service.ui && service.ui.access) { + suggestOptions.access = service.ui.access; + } + if ('view' in service && 'url' in service.view && !('view_url' in suggestOptions)) { suggestOptions.formatter_url = service.view.url; }