2010-04-21 23:08:34 +02:00
function FreebaseLoadingDialog ( ) {
this . _createDialog ( ) ;
}
FreebaseLoadingDialog . prototype . _createDialog = function ( ) {
var self = this ;
var frame = DialogSystem . createDialog ( ) ;
2010-04-23 10:25:52 +02:00
frame . width ( "800px" ) ;
2010-04-21 23:08:34 +02:00
var header = $ ( '<div></div>' ) . addClass ( "dialog-header" ) . text ( 'Load Data into Freebase' ) . appendTo ( frame ) ;
var body = $ ( '<div></div>' ) . addClass ( "dialog-body" ) . appendTo ( frame ) ;
var footer = $ (
'<div class="dialog-footer">' +
'<table width="100%"><tr>' +
2010-04-24 10:02:32 +02:00
'<td bind="left" style="text-align: left" width="40%" nowrap="true"></td>' +
'<td bind="center" style="text-align: center" width="20%" nowrap="true"></td>' +
'<td bind="right" style="text-align: right" width="40%" nowrap="true"></td>' +
2010-04-21 23:08:34 +02:00
'</tr></table>' +
'</div>'
) . appendTo ( frame ) ;
2010-04-24 10:02:32 +02:00
this . _elmts = DOM . bind ( frame ) ;
2010-04-21 23:08:34 +02:00
2010-04-24 10:02:32 +02:00
var left _footer = this . _elmts . left ;
var center _footer = this . _elmts . center ;
var right _footer = this . _elmts . right ;
2010-04-23 10:25:52 +02:00
2010-04-24 10:02:32 +02:00
var cancel _button = $ ( '<button bind="cancel" id="freebase-loading-cancel"></button>' ) . text ( "Cancel" ) . click ( function ( ) {
2010-04-21 23:08:34 +02:00
self . _dismiss ( ) ;
} ) . appendTo ( left _footer ) ;
2010-04-24 10:02:32 +02:00
var authorization = $ ( '<div bind="authorization">' ) . addClass ( "freebase-loading-authorization" ) . hide ( ) . appendTo ( center _footer ) ;
2010-04-23 10:25:52 +02:00
2010-04-24 10:02:32 +02:00
var selector = $ ( '<span bind="selector">' ) . addClass ( "freebase-loading-graph-selector" ) . html ( "Load this data into " +
2010-04-21 23:08:34 +02:00
'<input type="radio" bind="sandbox" id="freebase-loading-graph-selector-sandbox" name="graph-selector" checked="checked" value="sandbox"/><label class="sandbox" for="freebase-loading-graph-selector-sandbox" title="Load into the sandbox">sandbox</label>' +
2010-04-23 10:25:52 +02:00
'<input type="radio" bind="freebase" id="freebase-loading-graph-selector-freebase" name="graph-selector" value="freebase"/><label class="freebase" for="freebase-loading-graph-selector-freebase" title="Load into Freebase">freebase</label>'
2010-04-21 23:08:34 +02:00
) . buttonset ( ) . appendTo ( right _footer ) ;
2010-04-23 10:25:52 +02:00
2010-04-24 10:02:32 +02:00
var load _button = $ ( '<button bind="load" id="freebase-loading-load"></button>' ) . text ( "Load" ) . appendTo ( right _footer ) ;
2010-04-23 10:25:52 +02:00
var provider = "www.freebase.com" ;
2010-04-21 23:08:34 +02:00
2010-04-24 10:02:32 +02:00
var check _authorization = function ( autoload ) {
2010-04-23 10:25:52 +02:00
$ . get ( "/command/check-authorization/" + provider , function ( data ) {
if ( "status" in data && data . status == "200 OK" ) {
authorization . html ( 'Signed in as: <a target="_new" href="http://www.freebase.com/view/user/' + data . username + '">' + data . username + '</a> | <a href="javascript:{}" bind="signout">Sign Out</a>' ) . show ( ) ;
DOM . bind ( authorization ) . signout . click ( function ( ) {
Sign . signout ( check _authorization , provider ) ;
} ) ;
2010-04-24 10:02:32 +02:00
if ( autoload ) {
self . _load ( ) ;
} else {
load _button . unbind ( ) . click ( function ( ) {
self . _load ( ) ;
} ) ;
}
2010-04-23 10:25:52 +02:00
} else {
authorization . html ( "" ) . hide ( ) ;
2010-04-24 10:02:32 +02:00
load _button . unbind ( ) . click ( function ( ) {
Sign . signin ( function ( ) {
check _authorization ( true ) ;
} , provider ) ;
2010-04-23 10:25:52 +02:00
} ) ;
}
} , "json" ) ;
} ;
2010-04-24 10:02:32 +02:00
$ . post (
"/command/export-rows" ,
{
2010-04-23 10:25:52 +02:00
project : theProject . id ,
2010-04-24 10:02:32 +02:00
format : "tripleloader"
} ,
2010-04-23 10:25:52 +02:00
function ( data ) {
2010-04-24 10:02:32 +02:00
if ( data == null || data == "" ) {
body . html (
'<div class="freebase-loading-tripleloader-message">' +
'<h2>This dataset has no triples</h2>' +
'<p>Have you aligned it with the Freebase schemas yet?</p>' +
'</div>'
) ;
left _footer . hide ( ) ;
center _footer . hide ( ) ;
selector . hide ( ) ;
load _button . text ( "Close" ) . unbind ( ) . click ( function ( ) {
self . _dismiss ( ) ;
} ) ;
2010-04-23 10:25:52 +02:00
} else {
2010-04-24 10:02:32 +02:00
body . html (
'<div class="freebase-loading-tripleloader-data">' + data + '</div>' +
'<div class="freebase-loading-tripleloader-info">' +
'<div>Describe the data you\'re about to load ¬</div>' +
'<textarea bind="info"></textarea>' +
'</div>'
) ;
self . _elmts = DOM . bind ( frame ) ;
check _authorization ( false ) ;
2010-04-23 10:25:52 +02:00
}
2010-04-24 10:02:32 +02:00
self . _level = DialogSystem . showDialog ( frame ) ;
}
2010-04-23 10:25:52 +02:00
) ;
2010-04-24 10:02:32 +02:00
} ;
FreebaseLoadingDialog . prototype . _load = function ( ) {
var self = this ;
var freebase = self . _elmts . freebase . attr ( "checked" ) ;
2010-04-24 10:40:29 +02:00
var doLoad = function ( ) {
2010-04-24 10:02:32 +02:00
$ . post ( "/command/upload-data" ,
{
project : theProject . id ,
"graph" : ( freebase ) ? "otg" : "sandbox" ,
"info" : self . _elmts . info . val ( )
} ,
function ( data ) {
var body = $ ( ".dialog-body" ) ;
if ( "status" in data && data . status == "200 OK" ) {
body . html (
'<div class="freebase-loading-tripleloader-message">' +
'<h2>Data successfully loaded</h2>' +
'<p>' + data . message + '</p>' +
'</div>'
) ;
} else {
body . html (
'<div class="freebase-loading-tripleloader-message">' +
'<h2>Error loading data</h2>' +
'<p>' + data . message + '</p>' +
'<pre>' + data . stack . replace ( /\\n/g , '\n' ) . replace ( /\\t/g , '\t' ) + '</p>' +
'</div>'
) ;
}
self . _elmts . load . text ( "Close" ) . unbind ( ) . click ( function ( ) {
self . _dismiss ( ) ;
} ) ;
self . _elmts . cancel . hide ( ) ;
self . _elmts . authorization . hide ( ) ;
self . _elmts . selector . hide ( ) ;
} ,
"json"
) ;
2010-04-24 10:40:29 +02:00
} ;
if ( freebase ) {
var dialog = $ (
'<div id="freebase-confirmation-dialog" title="Are you sure?">' +
2010-04-25 09:52:16 +02:00
'<table><tr><td width="30%"><img src="/images/cop.png" width="140px"></td><td width="70%" style="text-align: center; vertical-align: middle; font-size: 120%">Are you sure this data is ready to be uploaded into <a href="http://www.freebase.com/" target="_new">Freebase</a>?</td></tr></table>' +
2010-04-24 10:40:29 +02:00
'</div>'
) . dialog ( {
resizable : false ,
width : 400 ,
height : 230 ,
modal : true ,
buttons : {
'yes' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
doLoad ( ) ;
} ,
'cancel' : function ( ) {
$ ( this ) . dialog ( 'close' ) ;
}
}
} ) ;
} else {
doLoad ( ) ;
2010-04-24 10:02:32 +02:00
}
2010-04-21 23:08:34 +02:00
}
FreebaseLoadingDialog . prototype . _dismiss = function ( ) {
DialogSystem . dismissUntil ( this . _level - 1 ) ;
} ;