storage system refactored

This commit is contained in:
Ondrej Zara
2015-06-15 12:02:57 +02:00
parent dcea4c24e5
commit 35b4c67a4a
34 changed files with 539 additions and 597 deletions
+12 -50
View File
@@ -10,8 +10,6 @@
<meta name="viewport" content="initial-scale=1,maximum-scale=1" />
<meta charset="utf-8" />
<link rel="stylesheet" href="styles/style.css" media="all" />
<!--[if IE 6]><link rel="stylesheet" type="text/css" href="styles/ie6.css" /><![endif]-->
<!--[if IE 7]><link rel="stylesheet" type="text/css" href="styles/ie7.css" /><![endif]-->
<link rel="stylesheet" href="styles/print.css" type="text/css" media="print" />
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/dropbox.js/0.10.2/dropbox.min.js"></script>
@@ -27,6 +25,11 @@
<script src="js/map.js"></script>
<script src="js/toggle.js"></script>
<script src="js/io.js"></script>
<script src="js/storage.js"></script>
<script src="js/storage.browser.js"></script>
<script src="js/storage.clipboard.js"></script>
<script src="js/storage.rest.js"></script>
<script src="js/storage.dropbox.js"></script>
<script src="js/tablemanager.js"></script>
<script src="js/rowmanager.js"></script>
<script src="js/keymanager.js"></script>
@@ -41,7 +44,7 @@
<div id="controls">
<div id="bar">
<div id="toggle"></div>
<input type="button" id="saveload" />
<button id="saveload"></button>
<hr/>
@@ -160,53 +163,12 @@
</div>
<div id="io">
<table>
<tbody>
<tr>
<td style="width:60%">
<fieldset>
<legend id="client"></legend>
<div id="singlerow">
<input type="button" id="clientsave" />
<input type="button" id="clientload" />
</div>
<div id="singlerow">
<input type="button" id="clientlocalsave" />
<input type="button" id="clientlocalload" />
<input type="button" id="clientlocallist" />
</div>
<div id="singlerow">
<input type="button" id="dropboxsave" /><!-- may get hidden by dropBoxInit() -->
<input type="button" id="dropboxload" /><!-- may get hidden by dropBoxInit() -->
<input type="button" id="dropboxlist" /><!-- may get hidden by dropBoxInit() -->
</div>
<hr/>
<input type="button" id="clientsql" />
</fieldset>
</td>
<td style="width:40%">
<fieldset>
<legend id="server"></legend>
<label for="backend" id="backendlabel"></label> <select id="backend"><option></option></select>
<hr/>
<input type="button" id="serversave" />
<input type="button" id="quicksave" />
<input type="button" id="serverload" />
<input type="button" id="serverlist" />
<input type="button" id="serverimport" />
</fieldset>
</td>
</tr>
<tr>
<td colspan="2">
<fieldset>
<legend id="output"></legend>
<textarea id="textarea" rows="1" cols="1"></textarea><!--modified by javascript later-->
</fieldset>
</td>
</tr>
</tbody>
</table>
<span id="storage"></span>: <select></select>
<div id="io-content"></div>
<hr/>
<button id="quicksave"></button>
<button id="clientsql"></button>
<textarea id="textarea" rows="1" cols="1"></textarea>
</div>
<div id="keys">
-1
View File
@@ -26,5 +26,4 @@ var CONFIG = {
* Copy the shown "App key" and paste it here below:
*/
DROPBOX_KEY: null // "your app key";
}
+69 -397
View File
@@ -1,90 +1,64 @@
SQL.IO = function(owner) {
this.owner = owner;
this._name = ""; /* last used name with server load/save */
this.lastUsedName = ""; /* last used name with local storage or dropbox load/save */
this._storages = [];
this._currentStorage = null;
this.dom = {
container:OZ.$("io")
container: OZ.$("io"),
content: OZ.$("io-content"),
seelct: null
};
var ids = ["saveload","clientlocalsave", "clientsave", "clientlocalload", "clientlocallist","clientload", "clientsql",
"dropboxsave", "dropboxload", "dropboxlist",
"quicksave", "serversave", "serverload",
"serverlist", "serverimport"];
this.dom.select = this.dom.container.querySelector("select");
this.dom.ta = OZ.$("textarea");
var ids = ["saveload", "storage", "quicksave", "clientsql"];
for (var i=0;i<ids.length;i++) {
var id = ids[i];
var elm = OZ.$(id);
this.dom[id] = elm;
elm.value = _(id);
}
this.dom.quicksave.value += " (F2)";
var ids = ["client","server","output","backendlabel"];
for (var i=0;i<ids.length;i++) {
var id = ids[i];
var elm = OZ.$(id);
elm.innerHTML = _(id);
}
this.dom.quicksave.innerHTML += " (F2)";
this.dom.ta = OZ.$("textarea");
this.dom.backend = OZ.$("backend");
/* init dropbox before hiding the container so it can adjust its buttons */
this.dropBoxInit();
this.dom.container.parentNode.removeChild(this.dom.container);
this.dom.container.style.visibility = "";
this.saveresponse = this.saveresponse.bind(this);
this.loadresponse = this.loadresponse.bind(this);
this.listresponse = this.listresponse.bind(this);
this.importresponse = this.importresponse.bind(this);
OZ.Event.add(this.dom.saveload, "click", this.click.bind(this));
OZ.Event.add(this.dom.clientlocalsave, "click", this.clientlocalsave.bind(this));
OZ.Event.add(this.dom.clientsave, "click", this.clientsave.bind(this));
OZ.Event.add(this.dom.clientlocalload, "click", this.clientlocalload.bind(this));
OZ.Event.add(this.dom.clientlocallist, "click", this.clientlocallist.bind(this));
OZ.Event.add(this.dom.clientload, "click", this.clientload.bind(this));
OZ.Event.add(this.dom.dropboxload, "click", this.dropboxload.bind(this));
OZ.Event.add(this.dom.dropboxsave, "click", this.dropboxsave.bind(this));
OZ.Event.add(this.dom.dropboxlist, "click", this.dropboxlist.bind(this));
OZ.Event.add(this.dom.clientsql, "click", this.clientsql.bind(this));
OZ.Event.add(this.dom.quicksave, "click", this.quicksave.bind(this));
OZ.Event.add(this.dom.serversave, "click", this.serversave.bind(this));
OZ.Event.add(this.dom.serverload, "click", this.serverload.bind(this));
OZ.Event.add(this.dom.serverlist, "click", this.serverlist.bind(this));
OZ.Event.add(this.dom.serverimport, "click", this.serverimport.bind(this));
OZ.Event.add(document, "keydown", this.press.bind(this));
this.build();
OZ.Event.add(this.dom.clientsql, "click", this._clientsql.bind(this));
OZ.Event.add(this.dom.quicksave, "click", this._quicksave.bind(this));
OZ.Event.add(this.dom.select, "change", this._storageChange.bind(this));
OZ.Event.add(window, "keydown", this._keydown.bind(this));
this._build();
}
SQL.IO.prototype.build = function() {
OZ.DOM.clear(this.dom.backend);
SQL.IO.prototype._build = function() {
var local = document.createElement("optgroup");
local.label = "Local";
this.dom.select.appendChild(local);
var bs = CONFIG.AVAILABLE_BACKENDS;
var be = CONFIG.DEFAULT_BACKEND;
var r = window.location.search.substring(1).match(/backend=([^&]*)/);
if (r) {
req = r[1];
if (bs.indexOf(req) != -1) {
be = req;
}
}
for (var i=0;i<bs.length;i++) {
var o = OZ.DOM.elm("option");
o.value = bs[i];
o.innerHTML = bs[i];
this.dom.backend.appendChild(o);
if (bs[i] == be) { this.dom.backend.selectedIndex = i; }
}
var remote = document.createElement("optgroup");
remote.label = "Remote";
this.dom.select.appendChild(remote);
this._addStorage(SQL.Storage.Browser, local);
this._addStorage(SQL.Storage.Clipboard, local);
this._addStorage(SQL.Storage.REST, remote);
this._addStorage(SQL.Storage.Dropbox, remote);
this._setStorage(2);
}
SQL.IO.prototype.getArea = function() {
return this.dom.ta;
}
SQL.IO.prototype.click = function() { /* open io dialog */
this.build();
this.dom.ta.value = "";
this.dom.clientsql.value = _("clientsql") + " (" + window.DATATYPES.getAttribute("db") + ")";
this.owner.window.open(_("saveload"),this.dom.container);
this.owner.window.open(_("saveload"), this.dom.container);
var index = this._storages.indexOf(this._currentStorage);
this._setStorage(index);
}
SQL.IO.prototype.fromXMLText = function(xml) {
@@ -115,258 +89,14 @@ SQL.IO.prototype.fromXML = function(xmlDoc) {
return true;
}
SQL.IO.prototype.clientsave = function() {
var xml = this.owner.toXML();
this.dom.ta.value = xml;
}
SQL.IO.prototype.clientload = function() {
var xml = this.dom.ta.value;
if (!xml) {
alert(_("empty"));
return;
}
this.fromXMLText(xml);
}
SQL.IO.prototype.promptName = function(title, suffix) {
var lastUsedName = this.owner.getOption("lastUsedName") || this.lastUsedName;
var name = prompt(_(title), lastUsedName);
if (!name) { return null; }
if (suffix && name.endsWith(suffix)) {
// remove suffix from name
name = name.substr(0, name.length-4);
}
this.owner.setOption("lastUsedName", name);
this.lastUsedName = name; // save this also in variable in case cookies are disabled
return name;
}
SQL.IO.prototype.clientlocalsave = function() {
if (!window.localStorage) {
alert("Sorry, your browser does not seem to support localStorage.");
return;
}
var xml = this.owner.toXML();
if (xml.length >= (5*1024*1024)/2) { /* this is a very big db structure... */
alert("Warning: your database structure is above 5 megabytes in size, this is above the localStorage single key limit allowed by some browsers, example Mozilla Firefox 10");
return;
}
var key = this.promptName("serversaveprompt");
if (!key) { return; }
key = "wwwsqldesigner_databases_" + (key || "default");
try {
localStorage.setItem(key, xml);
if (localStorage.getItem(key) != xml) { throw new Error("Content verification failed"); }
} catch (e) {
alert("Error saving database structure to localStorage! ("+e.message+")");
}
}
SQL.IO.prototype.clientlocalload = function() {
if (!window.localStorage) {
alert("Sorry, your browser does not seem to support localStorage.");
return;
}
var key = this.promptName("serverloadprompt");
key = "wwwsqldesigner_databases_" + (key || "default");
try {
var xml = localStorage.getItem(key);
if (!xml) { throw new Error("No data available"); }
} catch (e) {
alert("Error loading database structure from localStorage! ("+e.message+")");
return;
}
this.fromXMLText(xml);
}
SQL.IO.prototype.clientlocallist = function() {
if (!window.localStorage) {
alert("Sorry, your browser does not seem to support localStorage.");
return;
}
/* --- Define some useful vars --- */
var baseKeysName = "wwwsqldesigner_databases_";
var localLen = localStorage.length;
var data = "";
var schemasFound = false;
var code = 200;
/* --- work --- */
try {
for (var i = 0; i< localLen; ++i) {
var key = localStorage.key(i);
if((new RegExp(baseKeysName)).test(key)) {
var result = key.substring(baseKeysName.length);
schemasFound = true;
data += result + "\n";
}
}
if (!schemasFound) {
throw new Error("No data available");
}
} catch (e) {
alert("Error loading database names from localStorage! ("+e.message+")");
return;
}
this.listresponse(data, code);
}
/* ------------------------- Dropbox start ------------------------ */
/**
* The following code uses this lib: https://github.com/dropbox/dropbox-js
*/
SQL.IO.prototype.dropBoxInit = function() {
if (CONFIG.DROPBOX_KEY) {
this.dropboxClient = new Dropbox.Client({ key: CONFIG.DROPBOX_KEY });
} else {
this.dropboxClient = null;
// Hide the Dropbox buttons
var elems = document.querySelectorAll("[id^=dropbox]"); // gets all tags whose id start with "dropbox"
[].slice.call(elems).forEach(
function(elem) { elem.style.display = "none"; }
);
}
}
SQL.IO.prototype.showDropboxError = function(error) {
var prefix = _("Dropbox error")+": ";
var msg = error.status;
switch (error.status) {
case Dropbox.ApiError.INVALID_TOKEN:
// If you're using dropbox.js, the only cause behind this error is that
// the user token expired.
// Get the user through the authentication flow again.
msg = _("Invalid Token (expired)");
break;
case Dropbox.ApiError.NOT_FOUND:
// The file or folder you tried to access is not in the user's Dropbox.
// Handling this error is specific to your application.
msg = _("File not found");
break;
case Dropbox.ApiError.OVER_QUOTA:
// The user is over their Dropbox quota.
// Tell them their Dropbox is full. Refreshing the page won't help.
msg = _("Dropbox is full");
break;
case Dropbox.ApiError.RATE_LIMITED:
// Too many API requests. Tell the user to try again later.
// Long-term, optimize your code to use fewer API calls.
break;
case Dropbox.ApiError.NETWORK_ERROR:
// An error occurred at the XMLHttpRequest layer.
// Most likely, the user's network connection is down.
// API calls will not succeed until the user gets back online.
msg = _("Network error");
break;
case Dropbox.ApiError.INVALID_PARAM:
case Dropbox.ApiError.OAUTH_ERROR:
case Dropbox.ApiError.INVALID_METHOD:
default:
// Caused by a bug in dropbox.js, in your application, or in Dropbox.
// Tell the user an error occurred, ask them to refresh the page.
}
alert (prefix+msg);
};
SQL.IO.prototype.showDropboxAuthenticate = function() {
if (!this.dropboxClient) return false;
// We want to use a popup window for authentication as the default redirection won't work for us as it'll make us lose our schema data
this.dropboxClient.authDriver(new Dropbox.AuthDriver.Popup({ receiverUrl: "dropbox-oauth-receiver.html" }));
// Now let's authenticate us
var success = false;
this.dropboxClient.authenticate( function(error, client) {
if (error) {
this.showDropboxError(error);
return;
}
success = true;
return;
});
return success;
}
SQL.IO.prototype.dropboxsave = function() {
if (!this.showDropboxAuthenticate()) return;
var key = this.promptName("serversaveprompt", ".xml");
if (!key) { return; }
var filename = (key || "default") + ".xml";
var sql_io = this;
sql_io.listresponse("Saving...", 200);
var xml = this.owner.toXML();
this.dropboxClient.writeFile(filename, xml, function(error, stat) {
if (error) {
sql_io.listresponse("", 200);
return this.showDropboxError(error);
}
sql_io.listresponse(filename+" "+_("was saved to Dropbox"), 200);
});
}
SQL.IO.prototype.dropboxload = function() {
if (!this.showDropboxAuthenticate()) return;
var key = this.promptName("serverloadprompt", ".xml");
if (!key) { return; }
var filename = (key || "default") + ".xml";
var sql_io = this;
sql_io.listresponse("Loading...", 200);
this.dropboxClient.readFile(filename, function(error, data) {
sql_io.listresponse("", 200);
if (error) {
return this.showDropboxError(error);
}
sql_io.fromXMLText(data);
});
}
SQL.IO.prototype.dropboxlist = function() {
if (!this.showDropboxAuthenticate()) return;
var sql_io = this;
sql_io.listresponse("Loading...", 200);
this.dropboxClient.readdir("/", function(error, entries) {
if (error) {
sql_io.listresponse("", 200);
return this.showDropboxError(error);
}
var data = entries.join("\n")+"\n";
sql_io.listresponse(data, 200);
});
}
/* ------------------------- Dropbox end ------------------------ */
SQL.IO.prototype.clientsql = function() {
SQL.IO.prototype._clientsql = function() {
var bp = this.owner.getOption("staticpath");
var path = bp + "db/"+window.DATATYPES.getAttribute("db")+"/output.xsl";
this.owner.window.showThrobber();
OZ.Request(path, this.finish.bind(this), {xml:true});
OZ.Request(path, this._transform.bind(this), {xml:true});
}
SQL.IO.prototype.finish = function(xslDoc) {
SQL.IO.prototype._transform = function(xslDoc) {
this.owner.window.hideThrobber();
var xml = this.owner.toXML();
var sql = "";
@@ -392,98 +122,40 @@ SQL.IO.prototype.finish = function(xslDoc) {
this.dom.ta.value = sql.trim();
}
SQL.IO.prototype.serversave = function(e, keyword) {
var name = keyword || prompt(_("serversaveprompt"), this._name);
if (!name) { return; }
this._name = name;
var xml = this.owner.toXML();
var bp = this.owner.getOption("xhrpath");
var url = bp + "backend/"+this.dom.backend.value+"/?action=save&keyword="+encodeURIComponent(name);
var h = {"Content-type":"application/xml"};
this.owner.window.showThrobber();
this.owner.setTitle(name);
OZ.Request(url, this.saveresponse, {xml:true, method:"post", data:xml, headers:h});
SQL.IO.prototype._quicksave = function(e) {
this._currentStorage.quicksave(e);
}
SQL.IO.prototype.quicksave = function(e) {
this.serversave(e, this._name);
}
SQL.IO.prototype.serverload = function(e, keyword) {
var name = keyword || prompt(_("serverloadprompt"), this._name);
if (!name) { return; }
this._name = name;
var bp = this.owner.getOption("xhrpath");
var url = bp + "backend/"+this.dom.backend.value+"/?action=load&keyword="+encodeURIComponent(name);
this.owner.window.showThrobber();
this.name = name;
OZ.Request(url, this.loadresponse, {xml:true});
}
SQL.IO.prototype.serverlist = function(e) {
var bp = this.owner.getOption("xhrpath");
var url = bp + "backend/"+this.dom.backend.value+"/?action=list";
this.owner.window.showThrobber();
OZ.Request(url, this.listresponse);
}
SQL.IO.prototype.serverimport = function(e) {
var name = prompt(_("serverimportprompt"), "");
if (!name) { return; }
var bp = this.owner.getOption("xhrpath");
var url = bp + "backend/"+this.dom.backend.value+"/?action=import&database="+name;
this.owner.window.showThrobber();
OZ.Request(url, this.importresponse, {xml:true});
}
SQL.IO.prototype.check = function(code) {
switch (code) {
case 201:
case 404:
case 500:
case 501:
case 503:
var lang = "http"+code;
this.dom.ta.value = _("httpresponse")+": "+_(lang);
return false;
break;
default: return true;
}
}
SQL.IO.prototype.saveresponse = function(data, code) {
this.owner.window.hideThrobber();
this.check(code);
}
SQL.IO.prototype.loadresponse = function(data, code) {
this.owner.window.hideThrobber();
if (!this.check(code)) { return; }
this.fromXML(data);
this.owner.setTitle(this.name);
}
SQL.IO.prototype.listresponse = function(data, code) {
this.owner.window.hideThrobber();
if (!this.check(code)) { return; }
this.dom.ta.value = data;
}
SQL.IO.prototype.importresponse = function(data, code) {
this.owner.window.hideThrobber();
if (!this.check(code)) { return; }
if (this.fromXML(data)) {
this.owner.alignTables();
}
}
SQL.IO.prototype.press = function(e) {
SQL.IO.prototype._keydown = function(e) {
switch (e.keyCode) {
case 113:
if (OZ.opera) {
e.preventDefault();
}
this.quicksave(e);
this._currentStorage.quicksave(e);
break;
}
}
SQL.IO.prototype._addStorage = function(ctor, parent) {
var storage = new ctor(this);
if (!storage.isSupported()) { return; }
var option = storage.getOption();
option.value = this._storages.length;
parent.appendChild(option);
this._storages.push(storage);
}
SQL.IO.prototype._storageChange = function(e) {
var index = Number(e.target.selectedIndex);
this._setStorage(index);
}
SQL.IO.prototype._setStorage = function(index) {
this._currentStorage && this._currentStorage.deactivate();
this.dom.content.innerHTML = "";
this._currentStorage = this._storages[index];
this._currentStorage.activate(this.dom.content);
}
+2 -2
View File
@@ -13,8 +13,8 @@ SQL.Relation = function(owner, row1, row2) {
if (all.length) { /* inherit */
this.color = all[0].getColor();
} else if (CONFIG.RELATION_COLORS) { /* pick next */
this.constructor._counter++;
var colorIndex = this.constructor._counter - 1;
SQL.Relation._counter++;
var colorIndex = SQL.Relation._counter - 1;
this.color = CONFIG.RELATION_COLORS[colorIndex % CONFIG.RELATION_COLORS.length];
}
+1 -1
View File
@@ -23,7 +23,7 @@ SQL.RowManager = function(owner) {
OZ.Event.add(this.dom.foreigncreate, "click", this.foreigncreate.bind(this));
OZ.Event.add(this.dom.foreignconnect, "click", this.foreignconnect.bind(this));
OZ.Event.add(this.dom.foreigndisconnect, "click", this.foreigndisconnect.bind(this));
OZ.Event.add(document, "keydown", this.press.bind(this));
OZ.Event.add(window, "keydown", this.press.bind(this));
SQL.subscribe("tableclick", this.tableClick.bind(this));
SQL.subscribe("rowclick", this.rowClick.bind(this));
+98
View File
@@ -0,0 +1,98 @@
SQL.Storage.Browser = function(owner) {
SQL.Storage.call(this, owner);
this._dom.option.innerHTML = _("storage.browser");
this._prefix = "wwwsqldesigner_databases_";
this._buildButton("clientlocalsave", "_clickSave");
this._buildButton("clientlocalload", "_clickLoad");
this._dom.list = document.createElement("select");
}
SQL.Storage.Browser.prototype = Object.create(SQL.Storage.prototype);
SQL.Storage.Browser.prototype.activate = function(parent) {
parent.appendChild(this._dom.list);
SQL.Storage.prototype.activate.call(this, parent);
this._list();
}
SQL.Storage.Browser.prototype._save = function(keyword) {
var xml = this.owner.owner.toXML();
if (xml.length >= (5*1024*1024)/2) { /* this is a very big db structure... */
alert("Warning: your database structure is above 5 megabytes in size, this is above the localStorage single key limit allowed by some browsers, example Mozilla Firefox 10");
return;
}
var key = this._prefix + keyword;
try {
localStorage.setItem(key, xml);
if (localStorage.getItem(key) != xml) { throw new Error("Content verification failed"); }
this._keyword = keyword;
this._list();
} catch (e) {
alert("Error saving database structure to localStorage! ("+e.message+")");
}
}
SQL.Storage.Browser.prototype._load = function(keyword) {
try {
var xml = localStorage.getItem(this._prefix + keyword);
if (!xml) { throw new Error("No data available"); }
} catch (e) {
alert("Error loading database structure from localStorage! ("+e.message+")");
return;
}
this.owner.fromXMLText(xml);
this._keyword = keyword;
}
SQL.Storage.Browser.prototype._clickSave = function(e) {
var keyword = this._dom.list.value;
if (!keyword) {
keyword = this.owner.promptName("serversaveprompt");
if (!keyword) { return; }
}
this._save(keyword);
}
SQL.Storage.Browser.prototype._clickLoad = function(e) {
var keyword = this._dom.list.value;
if (!keyword) {
alert("Error loading saved data");
return;
}
this._load(keyword);
}
SQL.Storage.Browser.prototype._list = function() {
var re = new RegExp("^" + this._prefix);
var localLen = localStorage.length;
var results = [];
for (var i = 0; i<localStorage.length; i++) {
var key = localStorage.key(i);
if (!key.match(re)) { continue; }
results.push(key.substring(this._prefix.length));
}
this._dom.list.innerHTML = "";
if (results.length) {
results.forEach(function(result) {
var option = document.createElement("option");
option.innerHTML = result;
this._dom.list.appendChild(option);
}.bind(this));
} else {
var empty = document.createElement("option");
empty.innerHTML = "[no saved designs]";
empty.value = "";
this._dom.list.appendChild(empty);
}
this._dom.list.value = this._keyword;
}
+22
View File
@@ -0,0 +1,22 @@
SQL.Storage.Clipboard = function(owner) {
SQL.Storage.call(this, owner);
this._dom.option.innerHTML = _("storage.clipboard");
this._buildButton("clientsave", "_save");
this._buildButton("clientload", "_load");
}
SQL.Storage.Clipboard.prototype = Object.create(SQL.Storage.prototype);
SQL.Storage.Clipboard.prototype._save = function() {
this.owner.getArea().value = this.owner.owner.toXML();
}
SQL.Storage.Clipboard.prototype._load = function() {
var xml = this.owner.getArea().value;
if (!xml) {
alert(_("empty"));
return;
}
this.owner.fromXMLText(xml);
}
+146
View File
@@ -0,0 +1,146 @@
/**
* The following code uses this lib: https://github.com/dropbox/dropbox-js
*/
SQL.Storage.Dropbox = function(owner) {
SQL.Storage.call(this, owner);
this._dom.option.innerHTML = _("storage.dropbox");
if (CONFIG.DROPBOX_KEY) { this.dropboxClient = new Dropbox.Client({ key: CONFIG.DROPBOX_KEY }); }
this._buildButton("dropboxsave", "_clickSave");
this._buildButton("dropboxload", "_clickLoad");
this._buildButton("dropboxlist", "_clickList");
}
SQL.Storage.Dropbox.prototype = Object.create(SQL.Storage.prototype);
SQL.Storage.Dropbox.prototype.isSupported = function() {
return !!CONFIG.DROPBOX_KEY;
}
SQL.Storage.Dropbox.prototype.showDropboxError = function(error) {
var prefix = _("Dropbox error")+": ";
var msg = error.status;
switch (error.status) {
case Dropbox.ApiError.INVALID_TOKEN:
// If you're using dropbox.js, the only cause behind this error is that
// the user token expired.
// Get the user through the authentication flow again.
msg = _("Invalid Token (expired)");
break;
case Dropbox.ApiError.NOT_FOUND:
// The file or folder you tried to access is not in the user's Dropbox.
// Handling this error is specific to your application.
msg = _("File not found");
break;
case Dropbox.ApiError.OVER_QUOTA:
// The user is over their Dropbox quota.
// Tell them their Dropbox is full. Refreshing the page won't help.
msg = _("Dropbox is full");
break;
case Dropbox.ApiError.RATE_LIMITED:
// Too many API requests. Tell the user to try again later.
// Long-term, optimize your code to use fewer API calls.
break;
case Dropbox.ApiError.NETWORK_ERROR:
// An error occurred at the XMLHttpRequest layer.
// Most likely, the user's network connection is down.
// API calls will not succeed until the user gets back online.
msg = _("Network error");
break;
case Dropbox.ApiError.INVALID_PARAM:
case Dropbox.ApiError.OAUTH_ERROR:
case Dropbox.ApiError.INVALID_METHOD:
default:
// Caused by a bug in dropbox.js, in your application, or in Dropbox.
// Tell the user an error occurred, ask them to refresh the page.
}
alert(prefix+msg);
};
SQL.Storage.Dropbox.prototype.showDropboxAuthenticate = function() {
if (!this.dropboxClient) return false;
// We want to use a popup window for authentication as the default redirection won't work for us as it'll make us lose our schema data
this.dropboxClient.authDriver(new Dropbox.AuthDriver.Popup({ receiverUrl: "dropbox-oauth-receiver.html" }));
// Now let's authenticate us
var success = false;
this.dropboxClient.authenticate( function(error, client) {
if (error) {
this.showDropboxError(error);
return;
}
success = true;
return;
});
return success;
}
SQL.Storage.Dropbox.prototype._save = function(keyword) {
if (!this.showDropboxAuthenticate()) return;
var xml = this.owner.owner.toXML();
var filename = keyword + ".xml";
this.owner.owner.window.showThrobber();
this.dropboxClient.writeFile(filename, xml, function(error, stat) {
this.owner.owner.window.hideThrobber();
if (error) {
this.showDropboxError(error);
} else {
this._keyword = keyword;
this.owner.getArea().value = filename+" "+_("was saved to Dropbox");
}
}.bind(this));
}
SQL.Storage.Dropbox.prototype._load = function(keyword) {
if (!this.showDropboxAuthenticate()) return;
var filename = keyword + ".xml";
this.owner.owner.window.showThrobber();
this.dropboxClient.readFile(filename, function(error, data) {
this.owner.owner.window.hideThrobber();
if (error) {
this.showDropboxError(error);
} else {
this.owner.fromXMLText(data);
this._keyword = keyword;
}
}.bind(this));
}
SQL.Storage.Dropbox.prototype._clickSave = function(e) {
var keyword = prompt(_("serversaveprompt"), this._keyword);
if (!keyword) { return; }
this._save(keyword);
}
SQL.Storage.Dropbox.prototype._clickLoad = function(e) {
var keyword = prompt(_("serverloadprompt"), this._keyword);
if (!keyword) { return; }
this._load(keyword);
}
SQL.Storage.Dropbox.prototype._clickList = function(e) {
if (!this.showDropboxAuthenticate()) return;
this.owner.owner.window.showThrobber();
this.dropboxClient.readdir("/", function(error, entries) {
this.owner.owner.window.hideThrobber();
if (error) {
this.showDropboxError(error);
} else {
this.owner.getArea().value = entries.join("\n")+"\n"
}
}.bind(this));
}
+45
View File
@@ -0,0 +1,45 @@
SQL.Storage = function(owner) {
this.owner = owner;
this._keyword = "";
this._dom = {
option: document.createElement("option"),
buttons: {}
}
}
SQL.Storage.prototype.getOption = function() {
return this._dom.option;
}
SQL.Storage.prototype.isSupported = function() {
return true;
}
SQL.Storage.prototype.activate = function(parent) {
for (var p in this._dom.buttons) {
parent.appendChild(this._dom.buttons[p]);
}
}
SQL.Storage.prototype.deactivate = function() {
}
SQL.Storage.prototype.quicksave = function() {
if (!this._keyword) { return; }
this._save(this._keyword);
}
SQL.Storage.prototype._save = function(keyword) {
this._keyword = keyword;
}
SQL.Storage.prototype._load = function(keyword) {
this._keyword = keyword;
}
SQL.Storage.prototype._buildButton = function(labelKey, method) {
var button = document.createElement("button");
button.innerHTML = _(labelKey);
this._dom.buttons[labelKey] = button;
OZ.Event.add(button, "click", this[method].bind(this));
}
+129
View File
@@ -0,0 +1,129 @@
SQL.Storage.REST = function(owner) {
SQL.Storage.call(this, owner);
this._dom.option.innerHTML = _("storage.rest");
this._dom.label = document.createElement("label");
this._dom.label.innerHTML = _("backendlabel");
this._dom.backend = document.createElement("select");
this._dom.label.appendChild(this._dom.backend);
this._buildButton("serversave", "_clickSave");
this._buildButton("serverload", "_clickLoad");
this._buildButton("serverlist", "_clickList");
this._buildButton("serverimport", "_clickImport");
var bs = CONFIG.AVAILABLE_BACKENDS;
var be = CONFIG.DEFAULT_BACKEND;
var r = window.location.search.substring(1).match(/backend=([^&]*)/);
if (r) {
req = r[1];
if (bs.indexOf(req) != -1) {
be = req;
}
}
for (var i=0;i<bs.length;i++) {
var o = document.createElement("option");
o.value = bs[i];
o.innerHTML = bs[i];
this._dom.backend.appendChild(o);
if (bs[i] == be) { this._dom.backend.selectedIndex = i; }
}
var url = window.location.href;
var r = url.match(/keyword=([^&]+)/);
if (r) { this._load(r[1]); }
}
SQL.Storage.REST.prototype = Object.create(SQL.Storage.prototype);
SQL.Storage.REST.prototype.activate = function(parent) {
parent.appendChild(this._dom.label);
SQL.Storage.prototype.activate.call(this, parent);
}
SQL.Storage.REST.prototype._save = function(keyword) {
var xml = this.owner.owner.toXML();
var bp = this.owner.owner.getOption("xhrpath");
var url = bp + "backend/"+this._dom.backend.value+"/?action=save&keyword="+encodeURIComponent(keyword);
var h = {"Content-type":"application/xml"};
this.owner.owner.window.showThrobber();
this.owner.owner.setTitle(keyword);
this._keyword = keyword;
OZ.Request(url, this._responseSave.bind(this), {xml:true, method:"post", data:xml, headers:h});
}
SQL.Storage.REST.prototype._load = function(keyword) {
var bp = this.owner.owner.getOption("xhrpath");
var url = bp + "backend/"+this._dom.backend.value+"/?action=load&keyword="+encodeURIComponent(keyword);
this.owner.owner.window.showThrobber();
this._keyword = keyword;
OZ.Request(url, this._responseLoad.bind(this), {xml:true});
}
SQL.Storage.REST.prototype._clickSave = function(e) {
var keyword = prompt(_("serversaveprompt"), this._keyword);
if (!keyword) { return; }
this._save(keyword);
}
SQL.Storage.REST.prototype._clickLoad = function(e) {
var keyword = prompt(_("serverloadprompt"), this._keyword);
if (!keyword) { return; }
this._load(keyword);
}
SQL.Storage.REST.prototype._clickList = function(e) {
var bp = this.owner.owner.getOption("xhrpath");
var url = bp + "backend/"+this._dom.backend.value+"/?action=list";
this.owner.owner.window.showThrobber();
OZ.Request(url, this._responseList.bind(this));
}
SQL.Storage.REST.prototype._clickImport = function(e) {
var name = prompt(_("serverimportprompt"), "");
if (!name) { return; }
var bp = this.owner.owner.getOption("xhrpath");
var url = bp + "backend/"+this._dom.backend.value+"/?action=import&database="+name;
this.owner.owner.window.showThrobber();
OZ.Request(url, this._responseImport.bind(this), {xml:true});
}
SQL.Storage.REST.prototype._check = function(code) {
switch (code) {
case 201:
case 404:
case 500:
case 501:
case 503:
var lang = "http"+code;
this.owner.getArea().value = _("httpresponse")+": "+_(lang);
return false;
break;
default: return true;
}
}
SQL.Storage.REST.prototype._responseSave = function(data, code) {
this.owner.owner.window.hideThrobber();
this._check(code);
}
SQL.Storage.REST.prototype._responseLoad = function(data, code) {
this.owner.owner.window.hideThrobber();
if (!this._check(code)) { return; }
this.owner.fromXML(data);
this.owner.owner.setTitle(this._keyword);
}
SQL.Storage.REST.prototype._responseList = function(data, code) {
this.owner.owner.window.hideThrobber();
if (!this._check(code)) { return; }
this.owner.getArea().value = data;
}
SQL.Storage.REST.prototype._responseImport = function(data, code) {
this.owner.owner.window.hideThrobber();
if (!this._check(code)) { return; }
if (this.owner.fromXML(data)) {
this.owner.owner.alignTables();
}
}
+1 -1
View File
@@ -38,7 +38,7 @@ SQL.TableManager = function(owner) {
OZ.Event.add(this.dom.aligntables, "click", this.owner.alignTables.bind(this.owner));
OZ.Event.add(this.dom.edittable, "click", this.edit.bind(this));
OZ.Event.add(this.dom.tablekeys, "click", this.keys.bind(this));
OZ.Event.add(document, "keydown", this.press.bind(this));
OZ.Event.add(window, "keydown", this.press.bind(this));
this.dom.container.parentNode.removeChild(this.dom.container);
}
+1 -1
View File
@@ -16,7 +16,7 @@ SQL.Window = function(owner) {
this.dom.throbber.alt = this.dom.throbber.title = _("throbber");
OZ.Event.add(this.dom.ok, "click", this.ok.bind(this));
OZ.Event.add(this.dom.cancel, "click", this.close.bind(this));
OZ.Event.add(document, "keydown", this.key.bind(this));
OZ.Event.add(window, "keydown", this.key.bind(this));
this.sync = this.sync.bind(this);
+1 -7
View File
@@ -93,20 +93,14 @@ SQL.Designer.prototype.init2 = function() { /* secondary init, after locale & da
this.tableManager = new SQL.TableManager(this);
this.rowManager = new SQL.RowManager(this);
this.keyManager = new SQL.KeyManager(this);
this.io = new SQL.IO(this);
this.options = new SQL.Options(this);
this.window = new SQL.Window(this);
this.io = new SQL.IO(this);
this.sync();
OZ.$("docs").value = _("docs");
var url = window.location.href;
var r = url.match(/keyword=([^&]+)/);
if (r) {
var keyword = r[1];
this.io.serverload(false, keyword);
}
document.body.style.visibility = "visible";
}
-3
View File
@@ -68,9 +68,6 @@
<!-- io -->
<string name="saveload">حفظ / تحميل</string>
<string name="empty">قم بوضع بيانات نموذج XML في المربع أدناه، ثم حاول مرّة أخرى.</string>
<string name="client">العميل</string>
<string name="server">الخادم</string>
<string name="output">المدخلات / المخرجات</string>
<string name="clientsave">حفظ كنموذح XML</string>
<string name="clientload">إستيراد نموذج XML</string>
<string name="clientsql">حفظ كنموذج SQL</string>
+5 -3
View File
@@ -70,9 +70,11 @@
<!-- io -->
<string name="saveload">Uložit / Načíst</string>
<string name="empty">Prosím vložte XML data do textového pole níže.</string>
<string name="client">Klient</string>
<string name="server">Server</string>
<string name="output">Vstup / Výstup</string>
<string name="storage">Úložiště</string>
<string name="storage.browser">V prohlížeči</string>
<string name="storage.clipboard">Schránka</string>
<string name="storage.rest">Vzdálený REST server</string>
<string name="storage.dropbox">Dropbox</string>
<string name="clientsave">Uložit XML</string>
<string name="clientload">Načíst XML</string>
<string name="clientlocalsave">Uložit v prohlížeči</string>
-3
View File
@@ -69,9 +69,6 @@
<!-- io -->
<string name="saveload">Speichern / Laden</string>
<string name="empty">Bitte fügen Sie die XML-Daten in das untere Textfeld ein und versuchen es erneut.</string>
<string name="client">Client</string>
<string name="server">Server</string>
<string name="output">Eingabe / Ausgabe</string>
<string name="clientsave">XML speichern</string>
<string name="clientload">XML laden</string>
<string name="clientsql">SQL erzeugen</string>
-3
View File
@@ -69,9 +69,6 @@
<!-- io -->
<string name="saveload">Αποθήκ./Άνοιγμα</string>
<string name="empty">Κάντε επικόλληση των δεδομένων XML στο πεδίο κειμένου παρακάτω και δοκιμάστε ξανά.</string>
<string name="client">Πελάτης</string>
<string name="server">Διακομιστής</string>
<string name="output">Εισαγωγή/Εξαγωγή</string>
<string name="clientsave">Αποθήκευση XML</string>
<string name="clientload">Άνοιγμα XML</string>
<string name="clientsql">Δημιουργία SQL</string>
+5 -3
View File
@@ -70,9 +70,11 @@
<!-- io -->
<string name="saveload">Save / Load</string>
<string name="empty">Please paste XML data into the text area below and try again.</string>
<string name="client">Client</string>
<string name="server">Server</string>
<string name="output">Input / Output</string>
<string name="storage">Storage</string>
<string name="storage.browser">Browser storage</string>
<string name="storage.clipboard">System clipboard</string>
<string name="storage.rest">Remote REST server</string>
<string name="storage.dropbox">Dropbox</string>
<string name="clientsave">Save XML</string>
<string name="clientload">Load XML</string>
<string name="clientlocalsave">Save in Browser</string>
-3
View File
@@ -70,9 +70,6 @@
<!-- io -->
<string name="saveload">Konservi / Ŝargi</string>
<string name="empty">Bonvolu alglui XML datumon en la tekst-zono sube kaj provi de nove.</string>
<string name="client">Kliento</string>
<string name="server">Servilo</string>
<string name="output">Enigo / Eligo</string>
<string name="clientsave">Konservi XML</string>
<string name="clientload">Ŝargi XML</string>
<string name="clientsql">Krei SQL</string>
-3
View File
@@ -70,9 +70,6 @@ habilitadas para opciones de trabajo.</string>
<!-- io -->
<string name="saveload">Guardar / Cargar</string>
<string name="empty">Favor de pegar el XML dentro del &#225;rea de texto siguiente e intentar nuevamente.</string>
<string name="client">Cliente</string>
<string name="server">Servidor</string>
<string name="output">Entrada / Salida</string>
<string name="clientsave">Guardar XML</string>
<string name="clientload">Cargar XML</string>
<string name="clientsql">Generar SQL</string>
-3
View File
@@ -70,9 +70,6 @@
<!-- io -->
<string name="saveload">Enregistrer / Charger</string>
<string name="empty">Merci de coller les données XML dans le champs prévu avant de ré-essayer.</string>
<string name="client">Client</string>
<string name="server">Serveur</string>
<string name="output">Entrée / Sortie</string>
<string name="clientsave">Enregistrer XML</string>
<string name="clientload">Charger XML</string>
<string name="clientlocalsave">Enregistrer dans le navigateur</string>
-3
View File
@@ -69,9 +69,6 @@
<!-- io -->
<string name="saveload">Mentés / Beolvasás</string>
<string name="empty">Kérem illessze be az XML-tartalmat az alábbi szöveges mezőbe, és próbálja újra.</string>
<string name="client">Kliens</string>
<string name="server">Szerver</string>
<string name="output">Bemenet / Kimenet</string>
<string name="clientsave">XML mentése</string>
<string name="clientload">XML beolvasása</string>
<string name="clientsql">SQL generálása</string>
-3
View File
@@ -70,9 +70,6 @@
<!-- io -->
<string name="saveload">Salva / Carica</string>
<string name="empty">Reincolla i dati XML nell'area sottostante e prova di nuovo.</string>
<string name="client">Intestatario</string>
<string name="server">Server</string>
<string name="output">Ingresso / Uscita</string>
<string name="clientsave">Salva XML</string>
<string name="clientload">Carica XML</string>
<string name="clientsql">Genera SQL</string>
-3
View File
@@ -68,9 +68,6 @@
<!-- io -->
<string name="saveload">保存/読み込み</string>
<string name="empty">下の入出力欄にXMLデータを貼りつけてから実行してください。</string>
<string name="client">クライアント</string>
<string name="server">サーバ</string>
<string name="output">入力出欄</string>
<string name="clientsave">XMLを出力</string>
<string name="clientload">XMLを読込</string>
<string name="clientsql">SQLを生成</string>
-3
View File
@@ -70,9 +70,6 @@
<!-- io -->
<string name="saveload">Opslaan / laden</string>
<string name="empty">Please paste XML data into the text area below and try again.</string>
<string name="client">Lokaal</string>
<string name="server">Server</string>
<string name="output">Input / Output</string>
<string name="clientsave">XML Opslaan</string>
<string name="clientload">XML Laden</string>
<string name="clientlocalsave">Opslaan in Browser</string>
-3
View File
@@ -70,9 +70,6 @@
<!-- io -->
<string name="saveload">Zapisz / Otwórz</string>
<string name="empty">Proszę wklej kod XML w poniższe pole tekstowe i spróbuj ponownie.</string>
<string name="client">Klient</string>
<string name="server">Serwer</string>
<string name="output">Wejście / Wyjście</string>
<string name="clientsave">Zapisz XML</string>
<string name="clientload">Załaduj XML</string>
<string name="clientsql">Generuj SQL</string>
-3
View File
@@ -69,9 +69,6 @@
<!-- io -->
<string name="saveload">Salvar / Carregar</string>
<string name="empty">Por favor cole os dados XML na área de texto abaixo e tente novamente.</string>
<string name="client">Cliente</string>
<string name="server">Servidor</string>
<string name="output">Entrada / Saída</string>
<string name="clientsave">Salvar XML</string>
<string name="clientload">Carregar XML</string>
<string name="clientsql">Gerar SQL</string>
-3
View File
@@ -69,9 +69,6 @@
<!-- io -->
<string name="saveload">Salveaza / Incarca</string>
<string name="empty">Introduceti codul XML si re-incercati.</string>
<string name="client">Client</string>
<string name="server">Server</string>
<string name="output">Input / Output</string>
<string name="clientsave">Genereaza XML</string>
<string name="clientload">Incarca din XML</string>
<string name="clientsql">Genereaza SQL</string>
-3
View File
@@ -69,9 +69,6 @@
<!-- io -->
<string name="saveload">Сохранить / Загрузить</string>
<string name="empty">Пожалуйста, вставьте XML данные в поле ниже и попробуйте ещё раз.</string>
<string name="client">Клиент</string>
<string name="server">Сервер</string>
<string name="output">Ввод / Вывод</string>
<string name="clientsave">Сохранить XML</string>
<string name="clientload">Загрузить XML</string>
<string name="clientsql">Генерировать SQL</string>
-3
View File
@@ -69,9 +69,6 @@
<!-- io -->
<string name="saveload">Spara / Ladda</string>
<string name="empty">Vänligen klistra in XML i textrutan nedan och försök igen.</string>
<string name="client">Klient</string>
<string name="server">Server</string>
<string name="output">Input / Output</string>
<string name="clientsave">Spara XML</string>
<string name="clientload">Ladda XML</string>
<string name="clientsql">Generera SQL</string>
-3
View File
@@ -72,9 +72,6 @@
<string name="logout">注销</string>
<string name="saveload">保存 / 载入</string>
<string name="empty">请先粘帖一个XML文件内容到文本框中,然后再导入。</string>
<string name="client">客户端</string>
<string name="server">服务端</string>
<string name="output">输入 / 输出</string>
<string name="clientsave">保存为XML</string>
<string name="clientload">载入XML</string>
<string name="clientsql">传化为数据库脚本</string>
-62
View File
@@ -1,62 +0,0 @@
v\:* {
behavior:url(#default#VML);
}
#bar {
position: absolute;
right: auto;
left: expression(eval(document.documentElement.scrollLeft)+document.documentElement.clientWidth-eval(this.offsetWidth));
top: expression(eval(document.documentElement.scrollTop));
}
#bar .shadow-corner {
background-image: none;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/bar_corner.png',sizingMethod='crop');
overflow: hidden;
}
#bar .shadow-left {
background-image: none;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/bar_left.png',sizingMethod='crop');
height: expression(eval(this.parentNode.offsetHeight));
overflow: hidden;
}
#bar .shadow-bottom {
background-image: none;
filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='../images/bar_bottom.png',sizingMethod='crop');
width: expression(eval(this.parentNode.offsetWidth));
overflow: hidden;
}
.table .shadow-corner {
background-image: none;
}
.table .shadow-right {
background-image: none;
}
.table .shadow-bottom {
background-image: none;
}
#minimap {
filter: alpha(opacity=90);
position: absolute;
right: auto;
left: expression(eval(document.documentElement.scrollLeft)+document.documentElement.clientWidth-eval(this.offsetWidth));
top: expression(eval(document.documentElement.scrollTop)+document.documentElement.clientHeight-eval(this.offsetHeight));
}
#background {
filter: alpha(opacity=50);
}
#keys, #opts {
width: expression(eval(document.documentElement.clientWidth)/2);
}
#rubberband {
filter: alpha(opacity=50);
}
-19
View File
@@ -1,19 +0,0 @@
v\:* {
behavior:url(#default#VML);
}
#minimap {
filter: alpha(opacity=90);
}
#background {
filter: alpha(opacity=50);
}
#keys, #opts {
width: expression(eval(document.documentElement.clientWidth)/2);
}
#rubberband {
filter: alpha(opacity=50);
}
+2 -2
View File
@@ -40,7 +40,7 @@ body {
-ms-filter: "progid:DXImageTransform.Microsoft.Shadow(Strength=5, Direction=215, Color='#888888')"; /* IE 8 */
}
#bar input {
#bar input, #bar button {
display: block;
width: 90%;
margin: auto;
@@ -228,7 +228,7 @@ legend {
font-weight: bold;
}
label, input, select {
label, input, button, select {
vertical-align: middle;
}