2010-02-08 22:41:49 +01:00
|
|
|
function MenuBar(div) {
|
|
|
|
this._div = div;
|
|
|
|
this._initializeUI();
|
|
|
|
}
|
|
|
|
|
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-05-24 14:36:35 +02:00
|
|
|
|
2010-03-08 03:34:25 +01:00
|
|
|
this._createTopLevelMenuItem("Project", [
|
2010-04-30 00:07:07 +02:00
|
|
|
/*
|
|
|
|
{
|
|
|
|
"label": "Data Model",
|
|
|
|
"submenu": [
|
|
|
|
{
|
|
|
|
"label": "Denormalize Records",
|
|
|
|
"click": function() { self._doDenormalizeRecords(); }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
*/
|
2010-05-17 21:22:58 +02:00
|
|
|
{
|
|
|
|
"label": "Rename...",
|
|
|
|
"click": function() { self._renameProject(); }
|
|
|
|
},
|
|
|
|
{},
|
2010-02-08 22:41:49 +01:00
|
|
|
{
|
2010-03-04 08:02:03 +01:00
|
|
|
"label": "Export Filtered Rows",
|
|
|
|
"submenu": [
|
|
|
|
{
|
|
|
|
"label": "Tab-Separated Value",
|
|
|
|
"click": function() { self._doExportRows("tsv", "tsv"); }
|
|
|
|
},
|
2010-05-26 07:42:31 +02:00
|
|
|
{
|
|
|
|
"label": "Comma-Separated Value",
|
|
|
|
"click": function() { self._doExportRows("csv", "csv"); }
|
|
|
|
},
|
2010-03-17 23:30:16 +01:00
|
|
|
{
|
|
|
|
"label": "HTML Table",
|
|
|
|
"click": function() { self._doExportRows("html", "html"); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"label": "Excel",
|
|
|
|
"click": function() { self._doExportRows("xls", "xls"); }
|
|
|
|
},
|
|
|
|
{},
|
2010-03-04 08:02:03 +01:00
|
|
|
{
|
|
|
|
"label": "Tripleloader",
|
2010-05-25 01:36:42 +02:00
|
|
|
"click": function() { self._doExportTripleloader("tripleloader"); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"label": "MQLWrite",
|
|
|
|
"click": function() { self._doExportTripleloader("mqlwrite"); }
|
2010-05-26 07:42:31 +02:00
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
"label": "Templating...",
|
|
|
|
"click": function() {
|
|
|
|
new TemplatingExporterDialog();
|
|
|
|
}
|
2010-03-04 08:02:03 +01:00
|
|
|
}
|
|
|
|
]
|
2010-03-08 03:34:25 +01:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"label": "Export Project",
|
|
|
|
"click": function() { self._exportProject(); }
|
2010-02-08 22:41:49 +01:00
|
|
|
}
|
|
|
|
]);
|
|
|
|
this._createTopLevelMenuItem("Schemas", [
|
2010-02-16 21:15:19 +01:00
|
|
|
/*{
|
2010-02-08 22:41:49 +01:00
|
|
|
label: "Auto-Align with Freebase ...",
|
|
|
|
click: function() { self._doAutoSchemaAlignment(); }
|
2010-02-16 21:15:19 +01:00
|
|
|
},*/
|
2010-02-08 22:41:49 +01:00
|
|
|
{
|
2010-02-19 23:56:29 +01:00
|
|
|
label: "Edit Schema Aligment Skeleton ...",
|
|
|
|
click: function() { self._doEditSchemaAlignment(false); }
|
|
|
|
},
|
|
|
|
{
|
|
|
|
label: "Reset Schema Alignment Skeleton ...",
|
|
|
|
click: function() { self._doEditSchemaAlignment(true); }
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
{
|
|
|
|
label: "Load into Freebase ...",
|
2010-04-21 23:08:34 +02:00
|
|
|
click: function() { self._doLoadIntoFreebase(); }
|
2010-02-08 22:41:49 +01:00
|
|
|
}
|
|
|
|
]);
|
2010-05-24 14:36:35 +02:00
|
|
|
|
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-04-30 00:07:07 +02:00
|
|
|
MenuBar.prototype._doDenormalizeRecords = function() {
|
|
|
|
Gridworks.postProcess(
|
2010-05-24 14:36:35 +02:00
|
|
|
"denormalize",
|
2010-04-30 00:07:07 +02:00
|
|
|
{},
|
|
|
|
null,
|
|
|
|
{ modelsChanged: true }
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2010-05-25 01:36:42 +02:00
|
|
|
MenuBar.prototype._doExportTripleloader = function(format) {
|
2010-04-08 22:16:08 +02:00
|
|
|
if (!theProject.protograph) {
|
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-05-25 01:36:42 +02:00
|
|
|
this._doExportRows(format, "txt");
|
2010-03-19 00:35:54 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2010-03-04 08:02:03 +01:00
|
|
|
MenuBar.prototype._doExportRows = 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-03-17 23:30:16 +01:00
|
|
|
.attr("action", "/command/export-rows/" + name + "." + ext)
|
2010-02-08 22:41:49 +01:00
|
|
|
.attr("target", "gridworks-export");
|
|
|
|
|
|
|
|
$('<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);
|
|
|
|
|
|
|
|
window.open("about:blank", "gridworks-export");
|
|
|
|
form.submit();
|
2010-05-24 14:36:35 +02:00
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
document.body.removeChild(form);
|
|
|
|
};
|
|
|
|
|
2010-03-08 03:34:25 +01:00
|
|
|
MenuBar.prototype._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-04-07 00:28:30 +02:00
|
|
|
.attr("action", "/command/export-project/" + name + ".gridworks.tar.gz")
|
2010-05-24 14:36:35 +02:00
|
|
|
.attr("target", "gridworks-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);
|
|
|
|
|
|
|
|
window.open("about:blank", "gridworks-export");
|
|
|
|
form.submit();
|
|
|
|
|
|
|
|
document.body.removeChild(form);
|
|
|
|
};
|
|
|
|
|
2010-05-17 21:22:58 +02:00
|
|
|
MenuBar.prototype._renameProject = function() {
|
|
|
|
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",
|
|
|
|
url: "/command/rename-project",
|
|
|
|
data: { "project" : theProject.id, "name" : name },
|
|
|
|
dataType: "json",
|
|
|
|
success: function (data) {
|
|
|
|
if (data && typeof data.code != 'undefined' && data.code == "ok") {
|
|
|
|
theProject.metadata.name = name;
|
|
|
|
Gridworks.setTitle();
|
|
|
|
} else {
|
|
|
|
alert("Failed to rename project: " + data.message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2010-02-08 22:41:49 +01:00
|
|
|
MenuBar.prototype._doAutoSchemaAlignment = function() {
|
2010-02-09 01:45:54 +01:00
|
|
|
//SchemaAlignment.autoAlign();
|
2010-02-16 21:15:19 +01:00
|
|
|
};
|
|
|
|
|
2010-02-19 23:56:29 +01:00
|
|
|
MenuBar.prototype._doEditSchemaAlignment = function(reset) {
|
|
|
|
new SchemaAlignmentDialog(reset ? null : theProject.protograph, function(newProtograph) {});
|
2010-02-08 22:41:49 +01:00
|
|
|
};
|
2010-04-21 23:08:34 +02:00
|
|
|
|
|
|
|
MenuBar.prototype._doLoadIntoFreebase = function() {
|
|
|
|
new FreebaseLoadingDialog();
|
|
|
|
};
|