2010-06-24 22:13:51 +02:00
|
|
|
var ReconciliationManager = {
|
2010-06-26 07:34:54 +02:00
|
|
|
customServices : [], // services registered by core and extensions
|
|
|
|
standardServices : [], // services registered by user
|
|
|
|
_urlMap : {}
|
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager.isFreebaseId = function(s) {
|
|
|
|
return s == "http://rdf.freebase.com/ns/type.object.id";
|
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager._rebuildMap = function() {
|
|
|
|
var map = {};
|
|
|
|
$.each(ReconciliationManager.getAllServices(), function(i, service) {
|
|
|
|
if ("url" in service) {
|
|
|
|
map[service.url] = service;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
ReconciliationManager._urlMap = map;
|
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager.getServiceFromUrl = function(url) {
|
|
|
|
return ReconciliationManager._urlMap[url];
|
2010-06-24 22:13:51 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager.getAllServices = function() {
|
|
|
|
return ReconciliationManager.customServices.concat(ReconciliationManager.standardServices);
|
|
|
|
};
|
|
|
|
|
|
|
|
ReconciliationManager.registerService = function(service) {
|
|
|
|
ReconciliationManager.customServices.push(service);
|
2010-06-26 07:34:54 +02:00
|
|
|
ReconciliationManager._rebuildMap();
|
2010-06-26 03:10:23 +02:00
|
|
|
|
|
|
|
return ReconciliationManager.customServices.length - 1;
|
2010-06-24 22:13:51 +02:00
|
|
|
};
|
|
|
|
|
2010-06-26 03:10:23 +02:00
|
|
|
ReconciliationManager.registerStandardService = function(url, f) {
|
2010-06-29 00:42:53 +02:00
|
|
|
var dismissBusy = DialogSystem.showBusy();
|
|
|
|
|
|
|
|
$.getJSON(
|
|
|
|
url + (url.contains("?") ? "&" : "?") + "callback=?",
|
|
|
|
null,
|
|
|
|
function(data) {
|
2010-06-24 22:13:51 +02:00
|
|
|
data.url = url;
|
|
|
|
data.ui = { "handler" : "ReconStandardServicePanel" };
|
|
|
|
|
2010-06-26 03:10:23 +02:00
|
|
|
index = ReconciliationManager.customServices.length +
|
|
|
|
ReconciliationManager.standardServices.length;
|
|
|
|
|
2010-06-24 22:13:51 +02:00
|
|
|
ReconciliationManager.standardServices.push(data);
|
2010-06-26 07:34:54 +02:00
|
|
|
ReconciliationManager._rebuildMap();
|
|
|
|
|
2010-06-24 22:13:51 +02:00
|
|
|
ReconciliationManager.save();
|
2010-06-26 03:10:23 +02:00
|
|
|
|
2010-06-29 00:42:53 +02:00
|
|
|
dismissBusy();
|
|
|
|
|
2010-06-26 03:10:23 +02:00
|
|
|
if (f) {
|
|
|
|
f(index);
|
|
|
|
}
|
2010-06-24 22:13:51 +02:00
|
|
|
},
|
2010-06-29 00:42:53 +02:00
|
|
|
"jsonp"
|
|
|
|
);
|
2010-06-24 22:13:51 +02:00
|
|
|
};
|
|
|
|
|
2010-06-26 07:34:54 +02:00
|
|
|
ReconciliationManager.unregisterService = function(service, f) {
|
|
|
|
for (var i = 0; i < ReconciliationManager.customServices.length; i++) {
|
|
|
|
if (ReconciliationManager.customServices[i] === service) {
|
|
|
|
ReconciliationManager.customServices.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var i = 0; i < ReconciliationManager.standardServices.length; i++) {
|
|
|
|
if (ReconciliationManager.standardServices[i] === service) {
|
|
|
|
ReconciliationManager.standardServices.splice(i, 1);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReconciliationManager.save(f);
|
|
|
|
};
|
|
|
|
|
2010-06-24 22:13:51 +02:00
|
|
|
ReconciliationManager.save = function(f) {
|
|
|
|
$.ajax({
|
|
|
|
async: false,
|
|
|
|
type: "POST",
|
2010-08-22 08:16:13 +02:00
|
|
|
url: "/command/core/set-preference?" + $.param({
|
2010-07-26 23:12:40 +02:00
|
|
|
name: "reconciliation.standardServices"
|
2010-06-24 22:13:51 +02:00
|
|
|
}),
|
|
|
|
data: { "value" : JSON.stringify(ReconciliationManager.standardServices) },
|
|
|
|
success: function(data) {
|
|
|
|
if (f) { f(); }
|
|
|
|
},
|
|
|
|
dataType: "json"
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
(function() {
|
|
|
|
ReconciliationManager.customServices.push({
|
|
|
|
"name" : "Freebase Query-based Reconciliation",
|
|
|
|
"ui" : { "handler" : "ReconFreebaseQueryPanel" }
|
|
|
|
});
|
|
|
|
|
|
|
|
$.ajax({
|
|
|
|
async: false,
|
2010-08-22 08:16:13 +02:00
|
|
|
url: "/command/core/get-preference?" + $.param({
|
2010-07-26 23:12:40 +02:00
|
|
|
name: "reconciliation.standardServices"
|
2010-06-24 22:13:51 +02:00
|
|
|
}),
|
|
|
|
success: function(data) {
|
|
|
|
if (data.value && data.value != "null") {
|
|
|
|
ReconciliationManager.standardServices = JSON.parse(data.value);
|
2010-06-26 07:34:54 +02:00
|
|
|
ReconciliationManager._rebuildMap();
|
2010-06-24 22:13:51 +02:00
|
|
|
} else {
|
|
|
|
ReconciliationManager.registerStandardService(
|
2010-08-24 20:46:26 +02:00
|
|
|
"http://2.standard-reconcile.dfhuynh.user.dev.freebaseapps.com/reconcile");
|
2010-06-24 22:13:51 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
dataType: "json"
|
|
|
|
});
|
|
|
|
})();
|