Add CORS support with JSONP fallback. Closes #2260
This commit is contained in:
parent
ad261109be
commit
2e1d5402ea
@ -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) {
|
||||
|
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user