Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
npbreland committed Nov 26, 2023
1 parent dd36a69 commit a57d79d
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions apps/habitbuilder/interface.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
<link rel="stylesheet" href="../../css/spectre.min.css">
</head>
<body>
<h2>Data</h2>
<div id="data"></div>
<button class="btn btn-default" id="btnSave">Save</button>
<button class="btn btn-default" id="btnDelete">Delete</button>
<h2>Settings</h2>
<div id="settings"></div>
<button class="btn btn-primary" id="btnSaveSettings">Save settings</button>

<script src="../../core/lib/interface.js"></script>
<script src="settings-form.js"></script>
<script>
var dataElement = document.getElementById("data");
var csvData = "";
Expand Down Expand Up @@ -43,6 +48,34 @@
});
}

function getSettings() {
// show loading window
Util.showModal("Loading...");
Util.readStorage('habitbuilder.settings.json', data=>{
const settings = JSON.parse(data || "[]");

// remove window
Util.hideModal();

// build settings form
settingsHtml = buildSettingsForm(settings.questions, settings.reminderTime);
settingsElement.innerHTML = settingsHtml;

document.getElementById("btnSaveSettings").addEventListener("click", function() {
// Get questions
const settings = getSettingsFromForm();
if (!settings) {
return;
}
disableFormInput();
Util.writeStorage('habitbuilder.settings.json', JSON.stringify(settings), () => {
location.reload(); // reload so we see current data
});
});
});
}


// You can call a utility function to save the data
document.getElementById("btnSave").addEventListener("click", function() {
Util.saveCSV("habitbuilder", csvData);
Expand All @@ -58,6 +91,7 @@
// Called when app starts
function onInit() {
getData();
getSettings();
}

</script>
Expand Down

0 comments on commit a57d79d

Please sign in to comment.