diff --git a/index.html b/index.html index f51116e..5982357 100644 --- a/index.html +++ b/index.html @@ -182,6 +182,11 @@ +
+ + + +
@@ -192,6 +197,10 @@
+
+ + +

@@ -309,4 +318,4 @@ - \ No newline at end of file + diff --git a/js/io.js b/js/io.js index 1eda861..a5c6271 100644 --- a/js/io.js +++ b/js/io.js @@ -22,6 +22,11 @@ SQL.IO = function (owner) { "serversave", "serverload", "serverlist", + "clientcopy", + "clientpaste", + "clientdownloadxml", + "clientdownloadtxt", + "clientloadfromfile", "serverimport", ]; for (var i = 0; i < ids.length; i++) { @@ -81,6 +86,11 @@ SQL.IO = function (owner) { 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(this.dom.clientcopy, "click", this.clientcopy.bind(this)); + OZ.Event.add(this.dom.clientpaste, "click", this.clientpaste.bind(this)); + OZ.Event.add(this.dom.clientdownloadxml, "click", this.clientdownloadxml.bind(this)); + OZ.Event.add(this.dom.clientdownloadtxt, "click", this.clientdownloadtxt.bind(this)); + OZ.Event.add(this.dom.clientloadfromfile, "click", this.clientloadfromfile.bind(this)); OZ.Event.add(document, "keydown", this.press.bind(this)); this.build(); }; @@ -160,6 +170,48 @@ SQL.IO.prototype.clientload = function () { this.fromXMLText(xml); }; +SQL.IO.prototype.clientcopy = function () { + var xml = this.owner.toXML(); + navigator.clipboard.writeText(xml).then(function() { + alert(_("clientsave") + " - Copied to clipboard!"); + }).catch(function(err) { + alert("Failed to copy: " + err); + }); +}; + +SQL.IO.prototype.clientpaste = function () { + var self = this; + navigator.clipboard.readText().then(function(xml) { + if (!xml) { + alert(_("empty")); + return; + } + self.fromXMLText(xml); + }).catch(function(err) { + alert("Failed to paste: " + err); + }); +}; + +SQL.IO.prototype.clientdownloadxml = function () { + var xml = this.owner.toXML(); + this.downloadFile(xml, "new-database.xml", "application/xml"); +}; + +SQL.IO.prototype.clientdownloadtxt = function () { + var xml = this.owner.toXML(); + this.downloadFile(xml, "new-database.txt", "text/plain"); +}; +SQL.IO.prototype.downloadFile = function (content, filename, mimeType) { + var blob = new Blob([content], { type: mimeType }); + var url = URL.createObjectURL(blob); + var a = document.createElement("a"); + a.href = url; + a.download = filename; + document.body.appendChild(a); + a.click(); + document.body.removeChild(a); + URL.revokeObjectURL(url); +}; SQL.IO.prototype.promptName = function (title, suffix) { var lastUsedName = this.owner.getOption("lastUsedName") || this.lastUsedName; @@ -176,6 +228,41 @@ SQL.IO.prototype.promptName = function (title, suffix) { return name; }; +SQL.IO.prototype.clientloadfromfile = function () { + var self = this; + var input = document.createElement("input"); + input.type = "file"; + input.accept = ".xml,.txt"; + input.onchange = function(e) { + var file = e.target.files[0]; + if (!file) { + return; + } + + // Check file extension + var fileName = file.name.toLowerCase(); + if (!fileName.endsWith(".xml") && !fileName.endsWith(".txt")) { + alert(_("clientloadfromfile") + ": Please select an XML or TXT file."); + return; + } + + var reader = new FileReader(); + reader.onload = function(e) { + var xml = e.target.result; + if (!xml || xml.trim() === "") { + alert(_("empty")); + return; + } + self.fromXMLText(xml); + }; + reader.onerror = function(e) { + alert(_("xmlerror") + ": Failed to read file."); + }; + reader.readAsText(file); + }; + input.click(); +}; + SQL.IO.prototype.clientlocalsave = function () { if (!window.localStorage) { alert("Sorry, your browser does not seem to support localStorage."); diff --git a/locale/de.xml b/locale/de.xml index 1cb4b3e..9413d44 100644 --- a/locale/de.xml +++ b/locale/de.xml @@ -7,7 +7,7 @@ Tabellen entfernen Tabellen ausrichten Tabellen löschen - Wirklich alle Tabellen löschen + Wollen sie wirklich alle Tabellen löschen? Neue Tabelle Tabelle platzieren Name @@ -23,10 +23,10 @@ Fremdschlüssel erstellen Ziel-Tabelle wählen Fremdschlüssel Verknüpfung - Ziel-Zeile auswählen - Ziel-Zeile entfernen - Tabelle wirklich löschen - Feld wirklich löschen + Ziel-Key-Zeile auswählen + Ziel-Key-Zeile entfernen + Tabelle wirklich löschen? + Feld wirklich löschen? Name @@ -51,15 +51,15 @@ in Pixel, 0 = einrasten deaktivieren Format für die Namen der Fremdschlüssel %T = Primärtabelle, %R = Primärschlüssel, %t = Fremdtabelle - Verstecke Verbindungslinien beim Bewegen von Tabellen? - Zeichne gekrümmte Verbindungslinien (Browser-abhängig)? - Zeige Feldgröße im Tabellendesign? + Verbindungslinien beim bewegen von Tabellen verstecken? + Zeichne runde Verbindungslinien (Browser-abhängig)? + Feldgröße im Tabellendesign anzeigen? Zeige Felddatentyp im Tabellendesign? Stil Schlüssel - Schlüssel in Tabelle "%s" + Schlüssel in der Tabelle "%s" Typ: Name: Felder im Schlüssel @@ -71,18 +71,23 @@ Speichern / Laden Bitte fügen Sie die XML-Daten in das untere Textfeld ein und versuchen Sie es erneut. - Client + Klient Server Eingabe / Ausgabe XML speichern XML laden + Ausgabe Speichern + Kopierten Code einfügen + als XML speichern + als TXT speichern + Datenbank von Datei laden In Browser speichern Von Browser laden Von Browser auflisten In Dropbox speichern Von Dropbox laden Von Dropbox auflisten - SQL erzeugen + SQL generieren Server Basis: Speichern Schnellspeichern diff --git a/locale/en.xml b/locale/en.xml index 50676dc..9160d94 100755 --- a/locale/en.xml +++ b/locale/en.xml @@ -83,6 +83,11 @@ Load from Dropbox List from Dropbox Generate SQL + Copy Output + Paste from Clipboard + Download as XML + Download as TXT + Load Database from file Server backend: Save Quicksave