Skip to content

Commit 098289f

Browse files
committed
added function to create form for adding/editing notes
fixed bug with imports (extensions of js files were missing)
1 parent 419e54f commit 098289f

File tree

8 files changed

+133
-27
lines changed

8 files changed

+133
-27
lines changed

index.html

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,25 @@ <h1>Hometask #1 | JavaScript</h1>
1616
<table>
1717
<thead>
1818
<tr>
19-
<th class="col category-icon">&nbsp;</th>
20-
<th class="col name">Name</th>
21-
<th class="col created">Created</th>
22-
<th class="col category1">Category</th>
23-
<th class="col content">Content</th>
24-
<th class="col dates">Dates</th>
25-
<th class="col header-icon">&nbsp;</th>
26-
<th class="col header-icon archive" onclick="switchTables()"></th>
27-
<th class="col header-icon delete"></th>
19+
<th class="category-icon">&nbsp;</th>
20+
<th class="name">Name</th>
21+
<th class="created">Created</th>
22+
<th class="category1">Category</th>
23+
<th class="content">Content</th>
24+
<th class="dates">Dates</th>
25+
<th class="header-icon">&nbsp;</th>
26+
<th class="header-icon archive" onclick="switchTables()"></th>
27+
<th class="header-icon delete"></th>
2828
</tr>
2929
</thead>
3030
<tbody id="active-archive-table"></tbody>
3131
</table>
3232

33+
<script type="module" src="mainThread.js" defer></script>
3334
<div id="create-note">
34-
<button>Create Note</button>
35+
<button onclick="buildForm()">Build form</button>
36+
<button onclick="loadLocalData()">Load local data</button>
37+
<button id="create-note-button">Create Note</button>
3538
</div>
3639

3740
<table>
@@ -47,11 +50,5 @@ <h1>Hometask #1 | JavaScript</h1>
4750
</table>
4851
</main>
4952

50-
<script type="module" src="mainThread.js"></script>
51-
<!-- <script type="module" src="scripts/svgs.js"></script>-->
52-
<!-- <script src="scripts/data.js"></script>-->
53-
<!-- <script src="scripts/HTMLBuilder.js"></script>-->
54-
<!-- <script type="module" src="scripts/functions.js"></script>-->
55-
<!-- <script src="scripts/form.js"></script>-->
5653
</body>
5754
</html>

mainThread.js

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
1-
// import { archiveIcon, unarchiveIcon, editIcon, deleteIcon, ideaIcon, quoteIcon, taskIcon, thoughtIcon } from './svgs';
2-
import * as icons from './scripts/svgs.js';
3-
import { loadDataIntoTables, loadIconsIntoHeader } from './scripts/functions.js';
1+
import { archiveIcon, unarchiveIcon, editIcon, deleteIcon, ideaIcon, quoteIcon, taskIcon, thoughtIcon } from './scripts/svgs.js';
2+
// import * from './scripts/svgs.js';
3+
import { loadDataIntoTables,
4+
loadIconsIntoHeader,
5+
switchTables,
6+
refreshTables,
7+
openForm,
8+
loadLocalData} from './scripts/functions.js';
9+
import { buildForm } from './scripts/HTMLBuilder.js';
410

5-
6-
loadIconsIntoHeader( icons.archiveIcon, icons.deleteIcon );
11+
loadIconsIntoHeader( archiveIcon, deleteIcon );
712

813
loadDataIntoTables();

scripts/HTMLBuilder.js

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,27 @@
1-
function buildForm(){
1+
import { categories } from "./data.js";
22

3+
document.getElementById("create-note-button").addEventListener("click", buildForm);
4+
5+
function buildForm(name, created, category, content){
6+
let form = document.createElement('form');
7+
8+
form.innerHTML = `
9+
<input type="text" name="name" value="${typeof name === "string"? name : ""}" placeholder="Name">
10+
<input type="date" name="date" value="${created}">
11+
<select name="categories">
12+
` + categories.map(c => `<option value="${c}">${c}</option>`) + `
13+
</select>
14+
<input type="text" name="content" value="${content? content : ""}" placeholder="Content">
15+
<button type="submit">Submit</button>
16+
`;
17+
18+
document.body.append(form);
319
}
20+
421
function buildTable(){
522

623
}
724
function refreshTable(){
825

926
}
27+
export { buildForm, buildTable }

scripts/data.js

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,70 @@
1-
let notes = [
1+
export let categories = ["Task", "Random Thought", "Idea", "Quote"]
2+
3+
export let notes = [
4+
{
5+
name: "",
6+
created: "",
7+
category: "",
8+
content: "",
9+
dates: "",
10+
archived: false
11+
},
12+
{
13+
name: "",
14+
created: "",
15+
category: "",
16+
content: "",
17+
dates: "",
18+
archived: false
19+
},
20+
{
21+
name: "",
22+
created: "",
23+
category: "",
24+
content: "",
25+
dates: "",
26+
archived: false
27+
},
28+
{
29+
name: "",
30+
created: "",
31+
category: "",
32+
content: "",
33+
dates: "",
34+
archived: false
35+
},
36+
{
37+
name: "",
38+
created: "",
39+
category: "",
40+
content: "",
41+
dates: "",
42+
archived: true
43+
},
44+
{
45+
name: "",
46+
created: "",
47+
category: "",
48+
content: "",
49+
dates: "",
50+
archived: true
51+
},
52+
{
53+
name: "",
54+
created: "",
55+
category: "",
56+
content: "",
57+
dates: "",
58+
archived: true
59+
},
60+
{
61+
name: "",
62+
created: "",
63+
category: "",
64+
content: "",
65+
dates: "",
66+
archived: false
67+
},
268
{
369
name: "",
470
created: "",

scripts/form.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
buildForm();
1+

scripts/functions.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,18 @@
11
function loadDataIntoTables(){
22

33
}
4+
function switchTables(){
45

6+
}
7+
function loadLocalData(){
8+
9+
}
10+
function openForm(){
11+
12+
}
13+
function refreshTables(){
14+
15+
}
516
function loadIconsIntoHeader(archiveIcon, deleteIcon){
617
Array.from(document.getElementsByClassName('header-icon')).forEach(col => {
718
if (col.classList.contains('archive'))
@@ -14,5 +25,9 @@ function loadIconsIntoHeader(archiveIcon, deleteIcon){
1425

1526
export {
1627
loadDataIntoTables,
17-
loadIconsIntoHeader
28+
loadIconsIntoHeader,
29+
switchTables,
30+
refreshTables,
31+
openForm,
32+
loadLocalData
1833
}

styles/form-styles.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
display: flex;
44
justify-content: end;
55
}
6+
#create-note *{
7+
margin-left: 2em;
8+
}
69
#create-note button{
710
padding: 1em;
811
border-radius: 0.5em;

styles/table-styles.css

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ tr td:last-child, tr th:last-child{
3131
}
3232
.category-icon{
3333
width: 5%;
34-
min-width: 1em;
35-
max-width: 2em;
34+
/*min-width: 1.5em;*/
35+
min-width: 2em;
3636
}
3737
.name{
3838
width: 20%;
@@ -45,6 +45,8 @@ tr td:last-child, tr th:last-child{
4545
.header-icon{
4646
width: 4%;
4747
fill: ghostwhite;
48+
min-width: 1.5em;
49+
min-height: 1.5em;
4850
}
4951
.header-icon svg {
5052
width: 1.5em;

0 commit comments

Comments
 (0)