Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

190 lines (159 sloc) 8.046 kb
<!DOCTYPE html>
<html>
<head>
<link href="http://derek.github.com/sandbox/yui/gallerycss-cssbutton/cssbutton.css" type="text/css" rel="stylesheet" />
<script src="http://yui.yahooapis.com/3.4.0/build/yui/yui-min.js"></script>
<script src="http://embeditor.org/api.js"></script>
</head>
<body class="yui3-skin-sam">
<div>Datatable: <input style="width:800px" type="text" id="datatable_url" value="http://derek.io/~/executor/tables/157df2900c8b79e3ee640767ab08cc07.xml" /> <input type="button" id="load_datatable" value="load"></div>
<iframe class="embeditor" id="editor" src="http://embeditor.org/?mode=javascript"></iframe>
<iframe class="embeditor" id="dataeditor" src="http://embeditor.org/?mode=javascript"></iframe>
<div id="output">
<input class="yui3-button yui3-button-color-blue" type="button" value="Execute" id="btn_get_url"/>
<div>
<a id="console_url" href="" target="_blank"></a><br />
<iframe id="results" src=""></iframe>
</div>
</div>
<script>
YUI().use("node", "io", "json", "yql", "attribute", "node-event-simulate", function(Y){
var editor = new Embeditor("editor");
var dataeditor = new Embeditor("dataeditor");
// Listen for datatable load requests
Y.one("#load_datatable").on("click", function(){
var url = Y.one("#datatable_url").get("value");
Y.YQL("SELECT * FROM xml WHERE url='" + url + "'", function(data){
editor.setValue(data.query.results.table.bindings.select.execute)
keys = data.query.results.table.bindings.select.inputs.key;
var dataeditorOut = {};
if (!Y.Object.isEmpty(keys)) {
if (Y.Lang.isArray(keys)) {
for (k in keys) {
dataeditorOut[keys[k].id] = (keys[k].default ? keys[k].default : "");
}
}
else {
dataeditorOut[keys.id] = (keys.default ? keys.default : "");
}
}
dataeditor.setValue(Y.JSON.stringify(dataeditorOut, null, 4));
});
});
// Listen for execute requests
Y.one("#btn_get_url").on("click", function(){
var params = [];
dataeditor.getValue(function(value){
if (value.length > 2) {
params = Y.JSON.parse(value);
}
editor.getValue(function(js){
generateDatatable(js, params);
});
});
});
Y.one("#load_datatable").simulate("click");
function generateDatatable(js, params){
Y.io("generator.php", {
method: "POST",
data: {
text: js,
keys: Y.Object.keys(params).join(",")
},
on:{
start: function(){
Y.log("io:start");
},
failure: function(a, b, c) {
Y.log("io:failue");
},
success: function() {
Y.log("io:success");
},
end: function() {
Y.log("io:end");
},
complete: function(a, b, c){
Y.log("io:complete");
var url = Y.JSON.parse(b.responseText).filename;
var query = "use '" + url + "' as datatable; SELECT * FROM datatable";
var size = Y.Object.size(params);
var j = 0;
var querystring = '';
Y.one("#datatable_url").set("value", url);
if (size > 0) {
for(var i in params) {
if (j === 0) {
delimiter = " WHERE ";
}
else {
delimiter = " AND ";
}
query += delimiter + " " + i + "=@" + i + " ";
querystring += "&" + i + "=" + params[i];
j++;
}
}
query += ";";
var iframeURL = "https://query.yahooapis.com/v1/public/yql?diagnostics=true&q=" + encodeURIComponent(query) + querystring;
Y.one("#console_url").setContent(query).setAttribute("href", "http://developer.yahoo.com/yql/console/?q=" + encodeURIComponent(query));
Y.one("#results").setAttribute("src", iframeURL);
/*
var aliasQuery = "insert into yql.queries.query (name,query) values ('test123123','" + addslashes(query) + "')";
Y.YQL(aliasQuery, function(){
});
*/
}
}
})
}
});
function addslashes(str) {
return str.replace(/\\/g, '\\\\').replace(/\'/g, '\\\'').replace(/\"/g, '\\"').replace(/\0/g, '\\0');
}
function stripslashes(str) {
return str.replace(/\\'/g, '\'').replace(/\\"/g, '"').replace(/\\0/g, '\\0').replace(/\\\\/g, '\\');
}
</script>
<style>
.yui3-button {
font-size:120%;
}
.embeditor{
overflow: hidden;
border:none;
}
#editor {
background: none repeat scroll 0 0 white;
bottom: 0;
left: 0px;
position: absolute;
right: 200px;
top: 40px;
width:1000px;
}
#dataeditor {
background: green repeat scroll 0 0 white;
bottom: 0;
left: 1000px;
position: absolute;
right:0;
top: 40px;
width:300px;
}
#editor, #dataeditor{
height:500px;
}
#output {
width:100%;
position:absolute;
top:540px;
}
#results {
width:100%;
height:1000px;
border:none;
}
</style>
</body>
</html>
Jump to Line
Something went wrong with that request. Please try again.