2010-02-08 22:41:49 +01:00
|
|
|
function MenuBar(div) {
|
|
|
|
this._div = div;
|
|
|
|
this._initializeUI();
|
|
|
|
}
|
|
|
|
|
2010-07-07 00:24:16 +02:00
|
|
|
MenuBar.MenuItems = [
|
|
|
|
{
|
|
|
|
"id" : "core/project",
|
|
|
|
"label" : "Project",
|
|
|
|
"submenu" : [
|
|
|
|
/*
|
|
|
|
{
|
|
|
|
"label": "Data Model",
|
|
|
|
"submenu": [
|
|
|
|
{
|
|
|
|
"label": "Denormalize Records",
|
|
|
|
"click": function() { MenuBar.handlers.denormalizeRecords(); }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
*/
|
|
|
|
{
|
|
|
|
"id" : "core/rename-project",
|
|
|
|
"label": "Rename...",
|
|
|
|
"click": function() { MenuBar.handlers.renameProject(); }
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"id" : "core/export",
|
|
|
|
"label": "Export Filtered Rows",
|
|
|
|
"submenu": [
|
|
|
|
{
|
|
|
|
"id" : "core/export-tsv",
|
|
|
|
"label": "Tab-Separated Value",
|
|
|
|
"click": function() { MenuBar.handlers.exportRows("tsv", "tsv"); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/export-csv",
|
|
|
|
"label": "Comma-Separated Value",
|
|
|
|
"click": function() { MenuBar.handlers.exportRows("csv", "csv"); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/export-html-table",
|
|
|
|
"label": "HTML Table",
|
|
|
|
"click": function() { MenuBar.handlers.exportRows("html", "html"); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/export-excel",
|
|
|
|
"label": "Excel",
|
|
|
|
"click": function() { MenuBar.handlers.exportRows("xls", "xls"); }
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"id" : "core/export-tripleloader",
|
|
|
|
"label": "Tripleloader",
|
|
|
|
"click": function() { MenuBar.handlers.exportTripleloader("tripleloader"); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/export-mqlwrite",
|
|
|
|
"label": "MQLWrite",
|
|
|
|
"click": function() { MenuBar.handlers.exportTripleloader("mqlwrite"); }
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"id" : "core/export-templating",
|
|
|
|
"label": "Templating...",
|
|
|
|
"click": function() { new TemplatingExporterDialog(); }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/export-project",
|
|
|
|
"label": "Export Project",
|
|
|
|
"click": function() { MenuBar.handlers.exportProject(); }
|
2010-09-17 08:52:10 +02:00
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"id" : "core/open-workspace-dir",
|
|
|
|
"label": "Open Workspace Directory",
|
|
|
|
"click": function() { MenuBar.handlers.openWorkspaceDir(); }
|
2010-07-07 00:24:16 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/schemas",
|
|
|
|
"label" : "Schemas",
|
|
|
|
"submenu" : [
|
|
|
|
/*{
|
|
|
|
"id" : "core/auto-schema-alignment",
|
|
|
|
label: "Auto-Align with Freebase ...",
|
|
|
|
click: function() { MenuBar.handlers.autoSchemaAlignment(); }
|
|
|
|
},*/
|
|
|
|
{
|
|
|
|
"id" : "core/schema-alignment",
|
|
|
|
label: "Edit Schema Aligment Skeleton ...",
|
|
|
|
click: function() { MenuBar.handlers.editSchemaAlignment(false); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id" : "core/reset-schema-alignment",
|
|
|
|
label: "Reset Schema Alignment Skeleton ...",
|
|
|
|
click: function() { MenuBar.handlers.editSchemaAlignment(true); }
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"id" : "core/load-info-freebase",
|
|
|
|
label: "Load into Freebase ...",
|
|
|
|
click: function() { MenuBar.handlers.loadIntoFreebase(); }
|
2010-08-13 18:26:33 +02:00
|
|
|
},
|
2010-08-24 08:06:07 +02:00
|
|
|
{
|
|
|
|
"id" : "core/browse-load",
|
|
|
|
label: "Browse to Data Load ...",
|
|
|
|
click: function() { MenuBar.handlers.browseToDataLoad(); }
|
|
|
|
},
|
2010-08-13 18:26:33 +02:00
|
|
|
{
|
|
|
|
"id" : "core/import-qa-data",
|
|
|
|
label: "Import QA Data",
|
|
|
|
click: function() { MenuBar.handlers.importQAData(); }
|
2010-07-07 00:24:16 +02:00
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
MenuBar.appendTo = function(path, what) {
|
2010-08-09 03:13:57 +02:00
|
|
|
MenuBar.appendTo(MenuBar.MenuItems, path, what);
|
2010-07-07 00:24:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.insertBefore = function(path, what) {
|
2010-08-09 03:13:57 +02:00
|
|
|
MenuSystem.insertBefore(MenuBar.MenuItems, path, what);
|
2010-07-07 00:24:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.insertAfter = function(path, what) {
|
2010-08-09 03:13:57 +02:00
|
|
|
MenuSystem.insertAfter(MenuBar.MenuItems, path, what);
|
2010-07-07 00:24:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.handlers = {};
|
|
|
|
|
2010-03-22 22:48:36 +01:00
|
|
|
MenuBar.prototype.resize = function() {
|
|
|
|
};
|
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
MenuBar.prototype._initializeUI = function() {
|
|
|
|
this._mode = "inactive";
|
|
|
|
this._menuItemRecords = [];
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
this._div.addClass("menu-bar").html(" ");
|
|
|
|
this._innerDiv = $('<div></div>').addClass("menu-bar-inner").appendTo(this._div);
|
|
|
|
|
|
|
|
var self = this;
|
2010-07-07 00:24:16 +02:00
|
|
|
for (var i = 0; i < MenuBar.MenuItems.length; i++) {
|
|
|
|
var menuItem = MenuBar.MenuItems[i];
|
|
|
|
this._createTopLevelMenuItem(menuItem.label, menuItem.submenu);
|
|
|
|
}
|
2010-02-08 22:41:49 +01:00
|
|
|
this._wireAllMenuItemsInactive();
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.prototype._createTopLevelMenuItem = function(label, submenu) {
|
|
|
|
var self = this;
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
var menuItem = MenuSystem.createMenuItem().text(label).appendTo(this._innerDiv);
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
this._menuItemRecords.push({
|
|
|
|
menuItem: menuItem,
|
|
|
|
show: function() {
|
|
|
|
MenuSystem.dismissUntil(self._level);
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
menuItem.addClass("menu-expanded");
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
MenuSystem.createAndShowStandardMenu(
|
|
|
|
submenu,
|
|
|
|
this,
|
|
|
|
{
|
|
|
|
horizontal: false,
|
|
|
|
onDismiss: function() {
|
|
|
|
menuItem.removeClass("menu-expanded");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.prototype._wireMenuItemInactive = function(record) {
|
|
|
|
var self = this;
|
|
|
|
var click = function() {
|
|
|
|
self._activateMenu();
|
|
|
|
record.show.apply(record.menuItem[0]);
|
|
|
|
};
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
record.menuItem.click(function() {
|
|
|
|
// because we're going to rewire the menu bar, we have to
|
|
|
|
// make this asynchronous, or jquery event binding won't work.
|
|
|
|
window.setTimeout(click, 100);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.prototype._wireAllMenuItemsInactive = function() {
|
|
|
|
for (var i = 0; i < this._menuItemRecords.length; i++) {
|
|
|
|
this._wireMenuItemInactive(this._menuItemRecords[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.prototype._wireMenuItemActive = function(record) {
|
|
|
|
record.menuItem.mouseover(function() {
|
|
|
|
record.show.apply(this);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.prototype._wireAllMenuItemsActive = function() {
|
|
|
|
for (var i = 0; i < this._menuItemRecords.length; i++) {
|
|
|
|
this._wireMenuItemActive(this._menuItemRecords[i]);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.prototype._activateMenu = function() {
|
|
|
|
var self = this;
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
var top = this._innerDiv.offset().top;
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
this._innerDiv.remove().css("top", top + "px");
|
|
|
|
this._wireAllMenuItemsActive();
|
|
|
|
this._mode = "active";
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
this._level = MenuSystem.showMenu(this._innerDiv, function() {
|
|
|
|
self._deactivateMenu();
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
MenuBar.prototype._deactivateMenu = function() {
|
|
|
|
this._innerDiv.remove()
|
2010-02-19 19:47:46 +01:00
|
|
|
.css("z-index", "auto")
|
2010-02-08 22:41:49 +01:00
|
|
|
.css("top", "0px")
|
|
|
|
.appendTo(this._div);
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
this._wireAllMenuItemsInactive();
|
|
|
|
this._mode = "inactive";
|
|
|
|
};
|
|
|
|
|
2010-07-25 09:30:49 +02:00
|
|
|
MenuBar.handlers.exportTripleloader = function(format) {
|
2010-07-07 00:24:16 +02:00
|
|
|
if (!theProject.overlayModels.freebaseProtograph) {
|
2010-03-19 00:35:54 +01:00
|
|
|
alert(
|
|
|
|
"You haven't done any schema alignment yet,\nso there is no triple to export.\n\n" +
|
|
|
|
"Use the Schemas > Edit Schema Alignment Skeleton...\ncommand to align your data with Freebase schemas first."
|
|
|
|
);
|
|
|
|
} else {
|
2010-07-25 09:30:49 +02:00
|
|
|
MenuBar.handlers.exportRows(format, "txt");
|
2010-03-19 00:35:54 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-07-07 00:24:16 +02:00
|
|
|
MenuBar.handlers.exportRows = function(format, ext) {
|
2010-03-17 23:30:16 +01:00
|
|
|
var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-');
|
2010-02-08 22:41:49 +01:00
|
|
|
var form = document.createElement("form");
|
|
|
|
$(form)
|
|
|
|
.css("display", "none")
|
|
|
|
.attr("method", "post")
|
2010-08-22 08:16:13 +02:00
|
|
|
.attr("action", "/command/core/export-rows/" + name + "." + ext)
|
2010-09-23 00:55:28 +02:00
|
|
|
.attr("target", "refine-export");
|
2010-02-08 22:41:49 +01:00
|
|
|
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "engine")
|
|
|
|
.attr("value", JSON.stringify(ui.browsingEngine.getJSON()))
|
|
|
|
.appendTo(form);
|
2010-03-04 08:02:03 +01:00
|
|
|
$('<input />')
|
|
|
|
.attr("name", "project")
|
|
|
|
.attr("value", theProject.id)
|
|
|
|
.appendTo(form);
|
|
|
|
$('<input />')
|
|
|
|
.attr("name", "format")
|
|
|
|
.attr("value", format)
|
|
|
|
.appendTo(form);
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
document.body.appendChild(form);
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
window.open("about:blank", "refine-export");
|
2010-02-08 22:41:49 +01:00
|
|
|
form.submit();
|
2010-07-07 00:24:16 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
document.body.removeChild(form);
|
|
|
|
};
|
|
|
|
|
2010-07-07 00:24:16 +02:00
|
|
|
MenuBar.handlers.exportProject = function() {
|
2010-03-21 21:26:35 +01:00
|
|
|
var name = $.trim(theProject.metadata.name.replace(/\W/g, ' ')).replace(/\s+/g, '-');
|
2010-03-08 03:34:25 +01:00
|
|
|
var form = document.createElement("form");
|
|
|
|
$(form)
|
|
|
|
.css("display", "none")
|
|
|
|
.attr("method", "post")
|
2010-09-23 00:55:28 +02:00
|
|
|
.attr("action", "/command/core/export-project/" + name + ".google-refine.tar.gz")
|
|
|
|
.attr("target", "refine-export");
|
2010-03-08 03:34:25 +01:00
|
|
|
$('<input />')
|
|
|
|
.attr("name", "project")
|
|
|
|
.attr("value", theProject.id)
|
|
|
|
.appendTo(form);
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-03-08 03:34:25 +01:00
|
|
|
document.body.appendChild(form);
|
|
|
|
|
2010-09-23 00:55:28 +02:00
|
|
|
window.open("about:blank", "refine-export");
|
2010-03-08 03:34:25 +01:00
|
|
|
form.submit();
|
|
|
|
|
|
|
|
document.body.removeChild(form);
|
|
|
|
};
|
|
|
|
|
2010-07-07 00:24:16 +02:00
|
|
|
MenuBar.handlers.renameProject = function() {
|
2010-05-17 21:22:58 +02:00
|
|
|
var name = window.prompt("Rename Project", theProject.metadata.name);
|
|
|
|
if (name == null) {
|
|
|
|
return;
|
|
|
|
}
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
name = $.trim(name);
|
|
|
|
if (theProject.metadata.name == name || name.length == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
2010-08-22 08:16:13 +02:00
|
|
|
url: "/command/core/rename-project",
|
2010-05-17 21:22:58 +02:00
|
|
|
data: { "project" : theProject.id, "name" : name },
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
|
|
|
if (data && typeof data.code != 'undefined' && data.code == "ok") {
|
|
|
|
theProject.metadata.name = name;
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.setTitle();
|
2010-05-17 21:22:58 +02:00
|
|
|
} else {
|
|
|
|
alert("Failed to rename project: " + data.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2010-09-17 08:52:10 +02:00
|
|
|
MenuBar.handlers.openWorkspaceDir = function() {
|
|
|
|
$.ajax({
|
|
|
|
type: "POST",
|
|
|
|
url: "/command/core/open-workspace-dir",
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
|
|
|
if (data.code != "ok" && "message" in data) {
|
|
|
|
alert(data.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2010-07-07 00:24:16 +02:00
|
|
|
MenuBar.handlers.autoSchemaAlignment = function() {
|
2010-02-09 01:45:54 +01:00
|
|
|
//SchemaAlignment.autoAlign();
|
2010-02-16 21:15:19 +01:00
|
|
|
};
|
|
|
|
|
2010-07-07 00:24:16 +02:00
|
|
|
MenuBar.handlers.editSchemaAlignment = function(reset) {
|
|
|
|
new SchemaAlignmentDialog(
|
|
|
|
reset ? null : theProject.overlayModels.freebaseProtograph, function(newProtograph) {});
|
2010-02-08 22:41:49 +01:00
|
|
|
};
|
2010-04-21 23:08:34 +02:00
|
|
|
|
2010-07-07 00:24:16 +02:00
|
|
|
MenuBar.handlers.loadIntoFreebase = function() {
|
2010-04-21 23:08:34 +02:00
|
|
|
new FreebaseLoadingDialog();
|
|
|
|
};
|
2010-07-07 00:24:16 +02:00
|
|
|
|
2010-08-24 08:06:07 +02:00
|
|
|
MenuBar.handlers.browseToDataLoad = function() {
|
|
|
|
// 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(
|
|
|
|
"/command/core/get-preference?" + $.param({ project: theProject.id, name: "freebase.load.jobID" }),
|
|
|
|
null,
|
|
|
|
function(data) {
|
|
|
|
if (data.value == null) {
|
|
|
|
alert("You have not tried to load the data in this project into Freebase yet.");
|
|
|
|
} else {
|
|
|
|
$(form).attr("action", "http://gridworks-loads.freebaseapps.com/load/" + data.value);
|
|
|
|
form.submit();
|
|
|
|
w.focus();
|
|
|
|
}
|
|
|
|
document.body.removeChild(form);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-08-13 18:26:33 +02:00
|
|
|
MenuBar.handlers.importQAData = function() {
|
2010-09-23 00:55:28 +02:00
|
|
|
Refine.postCoreProcess(
|
2010-08-13 18:26:33 +02:00
|
|
|
"import-qa-data",
|
|
|
|
{},
|
|
|
|
{},
|
|
|
|
{ cellsChanged: true }
|
|
|
|
);
|
|
|
|
};
|