mirror of
https://github.com/tim-krehan/shopping-list.git
synced 2024-11-23 22:30:41 +01:00
implemented export function
This commit is contained in:
parent
e7e5773762
commit
406c5d9e0a
4 changed files with 23 additions and 4 deletions
|
@ -1,7 +1,18 @@
|
|||
function downloadObjectAsJson(exportObj, exportName){
|
||||
var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
|
||||
var downloadAnchorNode = document.createElement('a');
|
||||
downloadAnchorNode.setAttribute("href", dataStr);
|
||||
downloadAnchorNode.setAttribute("download", exportName + ".json");
|
||||
document.body.appendChild(downloadAnchorNode); // required for firefox
|
||||
downloadAnchorNode.click();
|
||||
downloadAnchorNode.remove();
|
||||
}
|
||||
$(document).ready(function(){
|
||||
$("#username-input").focus(function(){$(this).css("color", "black");});
|
||||
$("#mail-input").focus(function(){$(this).css("color", "black");});
|
||||
$("#userSaveButton").click(function(){
|
||||
|
||||
$("#export-recipe-button").click(function(){
|
||||
$.post("/php/edit-recipes.php", {function:"export"}, function(data){
|
||||
downloadObjectAsJson(data, "recipes");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -29,8 +29,9 @@
|
|||
<div class="import-export-pane">
|
||||
<h2>Import / Export</h2>
|
||||
<p>Hiermit werden alle Rezepte und sich zurzeit auf der Shoppingliste befindlichen Einträge als Download zur Verfügung gestellt. Diese Datei kann dann an anderer Stelle wieder Importiert werden, oder als Backup abgespeichert werden.</p>
|
||||
<button type="button" name="export-button" class="button">Export</button>
|
||||
<button type="button" id="export-recipe-button" class="button">Export Rezepte</button>
|
||||
<button type="button" id="export-list-button" class="button">Export Shoppingliste</button>
|
||||
<p>Der Import kann benutzt werden, um alle Daten von einer exportierten Datei in diese Datenbank einzupflegen. Hierbei werden nur die Einträge in der Shoppingliste, sowie die Rezepte beachtet. Die Benutzer bleiben unberührt!</p>
|
||||
<button type="button" name="import-button" class="button">Import ...</button>
|
||||
<button type="button" id="import-button" class="button">Import ...</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -27,6 +27,12 @@
|
|||
header(("Location: /recipe/".$_POST["id"]));
|
||||
break;
|
||||
|
||||
case 'export':
|
||||
$book->fillCookbook();
|
||||
header("Content-type: text/json");
|
||||
echo json_encode($book);
|
||||
break;
|
||||
|
||||
default:
|
||||
// code...
|
||||
break;
|
||||
|
|
|
@ -62,6 +62,7 @@ h3 {
|
|||
font-weight: 800;
|
||||
background-color: #4CAF50;
|
||||
color: white;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.hover:hover {
|
||||
|
|
Loading…
Reference in a new issue