shopping-list/bin/settings.js

105 lines
3.5 KiB
JavaScript
Raw Normal View History

2018-10-29 22:14:56 +01:00
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();
}
2018-10-29 19:57:40 +01:00
$(document).ready(function(){
$("#username-input").focus(function(){$(this).css("color", "black");});
$("#mail-input").focus(function(){$(this).css("color", "black");});
// change password
$("#old-password-input").focus(function(){$(this).css("color", "black");});
$("#new-password-input").focus(function(){$(this).css("color", "black");});
$("#check-password-input").focus(function(){$(this).css("color", "black");});
$(".password-input").on("input", function(){
if(
(($("#old-password-input").val()).length>0) &&
(($("#new-password-input").val()).length>0) &&
(($("#check-password-input").val()).length>0) &&
($("#new-password-input").val()==$("#check-password-input").val())
){
$("#passwordSaveButton").prop("disabled", false);
$("#passwordSaveButton").removeClass("button-disabled");
}
else{
$("#passwordSaveButton").prop("disabled", true);
$("#passwordSaveButton").addClass("button-disabled");
}
});
$("#passwordSaveButton").click(function(){
2018-11-20 13:53:17 +01:00
$.post("/api/user/change-pw",
{
current: $("#old-password-input").val(),
new: $("#new-password-input").val()
},
function(data){
if(data==0){
$("#old-password-input").val("");
$("#new-password-input").val("");
$("#check-password-input").val("");
2018-11-14 16:25:50 +01:00
infoPopUp("Passwort erfolgreich geändert!", 100);
}
else {
2018-11-14 16:25:50 +01:00
infoPopUp("Altes Passwort Falsch!", 100);
}
}
);
});
2018-10-29 22:14:56 +01:00
$("#export-recipe-button").click(function(){
2018-11-20 09:59:59 +01:00
$.post("/api/recipes/export", {}, function(data){
2018-10-29 22:23:51 +01:00
downloadObjectAsJson(JSON.parse(data), "recipes");
});
});
2018-11-14 16:08:36 +01:00
2018-10-29 22:23:51 +01:00
$("#export-list-button").click(function(){
2018-11-20 09:59:59 +01:00
$.post("/api/list/export", {}, function(data){
2018-10-29 22:23:51 +01:00
downloadObjectAsJson(JSON.parse(data), "list");
2018-10-29 22:14:56 +01:00
});
2018-10-29 19:57:40 +01:00
});
2018-11-14 16:08:36 +01:00
$("#import-button").click(function(){
$('<input type="file" accept=".json">').on('change', function () {
var file = this.files[0];
var reader = new FileReader();
reader.onload = function(){
var content = JSON.parse(reader.result);
if(content.sites!=null){
2018-11-20 09:59:59 +01:00
$.post("/api/recipes/import",
2018-11-14 16:08:36 +01:00
{
content: reader.result
},
function(data){
if(data==0){
2018-11-14 16:25:50 +01:00
infoPopUp("Alle Rezepte erfolgreich Importiert!", 200);
2018-11-14 16:08:36 +01:00
}
else{
2018-11-14 16:25:50 +01:00
infoPopUp("Nicht alle Rezepte konnten Importiert werden!", 1000);
downloadObjectAsJson(JSON.parse(data), "failed_recipe_import");
2018-11-14 16:08:36 +01:00
}
}
);
}
else if(content.list!=null){
2018-11-20 09:59:59 +01:00
$.post("/api/list/import",
2018-11-14 16:08:36 +01:00
{
content: reader.result
},
function(data){
console.log(data);
2018-11-14 16:25:50 +01:00
if(data==0){
infoPopUp("Alle Listeneinträge erfolgreich Importiert!", 200);
}
2018-11-14 16:08:36 +01:00
}
);
}
};
reader.readAsText(file);
}).click();
});
2018-10-29 19:57:40 +01:00
});