From fefde638719a742c944098e4d233c07f3a008fa9 Mon Sep 17 00:00:00 2001 From: Gregor Wuest Date: Tue, 26 May 2020 18:23:49 +0200 Subject: [PATCH] Added dynamic creation of the note form divs --- css/notes_app.css | 16 +++------ html/index.html | 12 +++---- scripts/notes_app.js | 82 +++++++++++++++++++++++++++++++++++++++----- 3 files changed, 83 insertions(+), 27 deletions(-) diff --git a/css/notes_app.css b/css/notes_app.css index 8d877bb..0870f95 100644 --- a/css/notes_app.css +++ b/css/notes_app.css @@ -15,23 +15,17 @@ body{ padding:2.5px; } -#noteFormDiv{ - display: none; -} - -#noteForm{ +.noteDiv{ padding:5px; margin-top:2px; display: inline-block; border:1px black solid; } -#noteText{ - width: 300px; - height: 150px; - box-sizing: border-box; +#saveProgressDiv{ + display: none; } -#inputTitle{ - margin-bottom:5px; +#saveProgress{ + width: 312px; } diff --git a/html/index.html b/html/index.html index 52f5dc3..94c100d 100644 --- a/html/index.html +++ b/html/index.html @@ -20,14 +20,10 @@
-
-
- -
- -
- -
+
+
+
+
\ No newline at end of file diff --git a/scripts/notes_app.js b/scripts/notes_app.js index 36e7a10..a9764ad 100644 --- a/scripts/notes_app.js +++ b/scripts/notes_app.js @@ -1,25 +1,91 @@ $(document).ready(function(){ + $("#addNoteDiv").on('click', function() { - $("#noteFormDiv").toggle() + createForm(); + }) + + $('#allNotesDiv').on('click', 'button', function() { + console.log("1") + console.log(this) + //$("#saveProgressDiv").toggle(); + //saveNoteObject(this); }) - $("#saveNoteButton").click(getNoteObject); }) -const noteFolder = "C:\\Users\\wuest\\Desktop\\Studium\\Master\\MDT5\\Hofmann\\Praktikum\\WebApp\\notes\\"; +function randomId(){ + return '_' + Math.random().toString(36).substr(2,9); + }; + +function createForm(){ + let id = randomId() + + let wrapper = document.createElement("div") + let inputsWrapper = document.createElement("div") + //let form = document.createElement("form"); + inputsWrapper.setAttribute('class', "noteDiv"); + + let input = document.createElement("input"); + input.setAttribute('type', "text"); + input.setAttribute('name',"noteTitle"); + input.setAttribute('id', "inputTitle"+id); + input.setAttribute('placeholder', "Enter title..."); + input.style.marginBottom='5px'; + + let div1 = document.createElement("div"); + let textarea = document.createElement("textarea"); + textarea.setAttribute('name',"noteText"); + textarea.setAttribute('id', "noteText"+id); + textarea.setAttribute('placeholder', "Enter notes..."); + textarea.style.width='300px'; + textarea.style.height='150px'; + textarea.style.boxSizing='border-box'; + div1.appendChild(textarea); + + let div2 = document.createElement("div") + div2.setAttribute('id', 'buttonDiv'+id) + let btn = document.createElement("button"); + btn.setAttribute('type',"button"); + btn.setAttribute('id',"saveNoteButton"+id); + btn.innerHTML = 'Save'; + + inputsWrapper.appendChild(input); + inputsWrapper.appendChild(div1); + inputsWrapper.appendChild(btn); + wrapper.appendChild(inputsWrapper); + + document.getElementById('allNotesDiv').appendChild(wrapper); +} + +let ctr; + +function saveNoteObject(a){ + console.log(a) + //ctr = setInterval(progressBar, 1000); //simulate delay for saving note -function saveNoteObject(){ let noteTitle = document.getElementById('inputTitle').value; - let noteText = document.getElementById('noteText').value; - + let noteText = document.getElementById('noteText').value; let noteObj = { title: noteTitle, text: noteText }; - - let noteObj_serialized = JSON.stringify(noteObj); + let noteObj_serialized = JSON.stringify(noteObj); //stringify noteObj so it is displayed properly when set to local Storage localStorage.setItem("noteObj", noteObj_serialized); + + console.log(noteObj_serialized) } +function progressBar(){ + document.getElementById('saveProgress').value = + document.getElementById('saveProgress').value + 5; + if (document.getElementById('saveProgress').value == 100){ + clearInterval(ctr); + } +} + + + + + function getNoteObject(){ }