From 84f346a8df8b6692fe6f484a2b148fb3971e3cb9 Mon Sep 17 00:00:00 2001 From: Ondrej Zara Date: Mon, 25 Jun 2012 16:21:44 +0200 Subject: [PATCH] issue #160 - localStorage; thanks to divinity76 --- index.html | 2 ++ js/wwwsqldesigner.js | 68 +++++++++++++++++++++++++++++++++++++++++++- locale/cs.xml | 2 ++ locale/en.xml | 2 ++ styles/style.css | 2 +- 5 files changed, 74 insertions(+), 2 deletions(-) diff --git a/index.html b/index.html index c8092c3..3e4a730 100644 --- a/index.html +++ b/index.html @@ -151,6 +151,8 @@ + +
diff --git a/js/wwwsqldesigner.js b/js/wwwsqldesigner.js index 113ce84..7df7811 100644 --- a/js/wwwsqldesigner.js +++ b/js/wwwsqldesigner.js @@ -1245,7 +1245,7 @@ SQL.IO.prototype.init = function(owner) { container:OZ.$("io") }; - var ids = ["saveload", "clientsave", "clientload", "clientsql", + var ids = ["saveload","clientlocalsave", "clientsave", "clientlocalload","clientload", "clientsql", "quicksave", "serversave", "serverload", "serverlist", "serverimport"]; for (var i=0;i= (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 = prompt(_("serversaveprompt"), this._name) || "default"; + key = "wwwsqldesigner_databases_"+key; + + 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 = prompt(_("serverloadprompt"), this._name) || "default"; + key = "wwwsqldesigner_databases_"+key; + + 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; + } + + try { + if (window.DOMParser) { + var parser = new DOMParser(); + var xmlDoc = parser.parseFromString(xml, "text/xml"); + } else if (window.ActiveXObject) { + var xmlDoc = new ActiveXObject("Microsoft.XMLDOM"); + xmlDoc.loadXML(xml); + } else { + throw new Error("No XML parser available."); + } + } catch(e) { + alert(_("xmlerror")+': '+e.message); + return; + } + + this.fromXML(xmlDoc); +} + + SQL.IO.prototype.clientsql = function() { var bp = this.owner.getOption("staticpath"); var path = bp + "db/"+window.DATATYPES.getAttribute("db")+"/output.xsl"; @@ -1924,6 +1987,7 @@ SQL.KeyManager.prototype.build = function() { } var types = ["PRIMARY","INDEX","UNIQUE","FULLTEXT"]; + OZ.DOM.clear(this.dom.type); for (var i=0;iVstup / Výstup Uložit XML Načíst XML + Uložit v prohlížeči + Načíst z prohlížeče Generovat SQL Server backend: Uložit diff --git a/locale/en.xml b/locale/en.xml index d65ca04..2df92a1 100644 --- a/locale/en.xml +++ b/locale/en.xml @@ -75,6 +75,8 @@ Input / Output Save XML Load XML + Save in Browser + Load from Browser Generate SQL Server backend: Save diff --git a/styles/style.css b/styles/style.css index 875f7e3..f99b6a1 100644 --- a/styles/style.css +++ b/styles/style.css @@ -205,7 +205,7 @@ body { } #textarea { - width: 500px; + width: 600px; height: 100px; }