2010-10-20 20:11:15 +02:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 2010, Google Inc.
|
|
|
|
All rights reserved.
|
|
|
|
|
|
|
|
Redistribution and use in source and binary forms, with or without
|
|
|
|
modification, are permitted provided that the following conditions are
|
|
|
|
met:
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions of source code must retain the above copyright
|
2010-10-20 20:11:15 +02:00
|
|
|
notice, this list of conditions and the following disclaimer.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Redistributions in binary form must reproduce the above
|
2010-10-20 20:11:15 +02:00
|
|
|
copyright notice, this list of conditions and the following disclaimer
|
|
|
|
in the documentation and/or other materials provided with the
|
|
|
|
distribution.
|
2011-08-04 22:37:14 +02:00
|
|
|
* Neither the name of Google Inc. nor the names of its
|
2010-10-20 20:11:15 +02:00
|
|
|
contributors may be used to endorse or promote products derived from
|
|
|
|
this software without specific prior written permission.
|
|
|
|
|
|
|
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
|
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
|
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
|
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
*/
|
2010-10-20 20:11:15 +02:00
|
|
|
|
2010-10-08 03:39:38 +02:00
|
|
|
var FreebaseExtension = { handlers: {} };
|
|
|
|
|
2013-06-27 12:03:51 +02:00
|
|
|
|
|
|
|
// Internationalization init
|
|
|
|
var lang = navigator.language.split("-")[0]
|
|
|
|
|| navigator.userLanguage.split("-")[0];
|
|
|
|
var dictionary = "";
|
|
|
|
$.ajax({
|
2014-12-03 14:52:06 +01:00
|
|
|
url : "command/core/load-language?",
|
2013-06-27 12:03:51 +02:00
|
|
|
type : "POST",
|
|
|
|
async : false,
|
|
|
|
data : {
|
2013-07-31 06:31:31 +02:00
|
|
|
module : "freebase",
|
|
|
|
// lang : lang
|
2013-06-27 12:03:51 +02:00
|
|
|
},
|
|
|
|
success : function(data) {
|
|
|
|
dictionary = data;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
$.i18n.setDictionary(dictionary);
|
|
|
|
// End internationalization
|
|
|
|
|
2012-10-12 20:39:05 +02:00
|
|
|
FreebaseExtension.handlers.setFreebaseApiKey = function() {
|
|
|
|
var value = window.prompt("Set Freebase API Key:");
|
|
|
|
if (value !== null) {
|
|
|
|
$.post(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/set-preference",
|
2012-10-12 20:39:05 +02:00
|
|
|
{
|
|
|
|
name : "freebase.api.key",
|
|
|
|
value : JSON.stringify(value)
|
|
|
|
},
|
|
|
|
function(o) {
|
|
|
|
if (o.code == "error") {
|
|
|
|
alert(o.message);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
"json"
|
|
|
|
);
|
|
|
|
CustomSuggest.setFreebaseAPIKey(value);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-10-25 03:07:25 +02:00
|
|
|
FreebaseExtension.handlers.editSchemaAlignment = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
new SchemaAlignmentDialog(theProject.overlayModels.freebaseProtograph, function(newProtograph) {});
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
FreebaseExtension.handlers.loadIntoFreebase = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
new FreebaseLoadingDialog();
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
FreebaseExtension.handlers.browseToDataLoad = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
// The form has to be created as part of the click handler. If you create it
|
|
|
|
// inside the getJSON success handler, it won't work.
|
|
|
|
|
|
|
|
var form = document.createElement("form");
|
|
|
|
$(form)
|
|
|
|
.css("display", "none")
|
|
|
|
.attr("method", "GET")
|
|
|
|
.attr("target", "dataload");
|
|
|
|
|
|
|
|
document.body.appendChild(form);
|
|
|
|
var w = window.open("about:blank", "dataload");
|
|
|
|
|
|
|
|
$.getJSON(
|
2012-10-13 19:47:08 +02:00
|
|
|
"command/core/get-preference?" + $.param({ project: theProject.id, name: "freebase.load.jobID" }),
|
2011-08-04 22:37:14 +02:00
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
if (data.value == null) {
|
2013-06-27 12:03:51 +02:00
|
|
|
alert($.i18n._('fb-menu')["warning-load"]);
|
2011-08-04 22:37:14 +02:00
|
|
|
} else {
|
|
|
|
$(form).attr("action", "http://refinery.freebaseapps.com/load/" + data.value);
|
|
|
|
form.submit();
|
|
|
|
w.focus();
|
|
|
|
}
|
|
|
|
document.body.removeChild(form);
|
|
|
|
}
|
|
|
|
);
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
FreebaseExtension.handlers.importQAData = function() {
|
2011-08-04 22:37:14 +02:00
|
|
|
Refine.postProcess(
|
|
|
|
"freebase-extension",
|
|
|
|
"import-qa-data",
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{ cellsChanged: true }
|
|
|
|
);
|
2010-10-08 03:39:38 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
ExtensionBar.addExtensionMenu({
|
2013-06-27 12:03:51 +02:00
|
|
|
|
|
|
|
|
2011-08-04 22:37:14 +02:00
|
|
|
"id" : "freebase",
|
2013-06-27 12:03:51 +02:00
|
|
|
"label" : $.i18n._('fb-menu')["freebase"],
|
2011-08-04 22:37:14 +02:00
|
|
|
"submenu" : [
|
2012-10-12 20:39:05 +02:00
|
|
|
{
|
|
|
|
"id" : "freebase/set-api-key",
|
2013-06-27 12:03:51 +02:00
|
|
|
label: $.i18n._('fb-menu')["set-api-key"],
|
2012-10-12 20:39:05 +02:00
|
|
|
click: FreebaseExtension.handlers.setFreebaseApiKey
|
|
|
|
},
|
2011-08-04 22:37:14 +02:00
|
|
|
{
|
|
|
|
"id" : "freebase/schema-alignment",
|
2013-06-27 12:03:51 +02:00
|
|
|
label: $.i18n._('fb-menu')["align-schema"],
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() { FreebaseExtension.handlers.editSchemaAlignment(false); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "freebase/load-info-freebase",
|
2013-06-27 12:03:51 +02:00
|
|
|
label: $.i18n._('fb-menu')["load"],
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() { FreebaseExtension.handlers.loadIntoFreebase(); }
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"id" : "freebase/browse-load",
|
2013-06-27 12:03:51 +02:00
|
|
|
label: $.i18n._('fb-menu')["browse-data-load"],
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() { FreebaseExtension.handlers.browseToDataLoad(); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "freebase/import-qa-data",
|
2013-06-27 12:03:51 +02:00
|
|
|
label: $.i18n._('fb-menu')["import-qa"],
|
2011-08-04 22:37:14 +02:00
|
|
|
click: function() { FreebaseExtension.handlers.importQAData(); }
|
|
|
|
}
|
|
|
|
]
|
2010-10-08 03:39:38 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
DataTableColumnHeaderUI.extendMenu(function(column, columnHeaderUI, menu) {
|
2011-08-04 22:37:14 +02:00
|
|
|
var columnIndex = Refine.columnNameToColumnIndex(column.name);
|
|
|
|
var doAddColumnFromFreebase = function() {
|
|
|
|
var o = DataTableView.sampleVisibleRows(column);
|
|
|
|
new ExtendDataPreviewDialog(
|
|
|
|
column,
|
|
|
|
columnIndex,
|
|
|
|
o.rowIndices,
|
|
|
|
function(extension) {
|
|
|
|
Refine.postProcess(
|
|
|
|
"freebase",
|
|
|
|
"extend-data",
|
|
|
|
{
|
|
|
|
baseColumnName: column.name,
|
|
|
|
columnInsertIndex: columnIndex + 1
|
|
|
|
},
|
|
|
|
{
|
|
|
|
extension: JSON.stringify(extension)
|
|
|
|
},
|
|
|
|
{ rowsChanged: true, modelsChanged: true }
|
2010-10-08 03:39:38 +02:00
|
|
|
);
|
2011-08-04 22:37:14 +02:00
|
|
|
}
|
2010-10-08 03:39:38 +02:00
|
|
|
);
|
2011-08-04 22:37:14 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
MenuSystem.insertAfter(
|
|
|
|
menu,
|
|
|
|
[ "core/edit-column", "core/add-column-by-fetching-urls" ],
|
|
|
|
{
|
|
|
|
id: "freebase/add-columns-from-freebase",
|
2013-06-27 12:03:51 +02:00
|
|
|
label: $.i18n._('fb-menu')["add-columns"],
|
2011-08-04 22:37:14 +02:00
|
|
|
click: doAddColumnFromFreebase
|
|
|
|
}
|
|
|
|
);
|
2010-10-08 03:39:38 +02:00
|
|
|
});
|