Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit ae8c4c0

Browse files
crud operations working fine
1 parent c6b92c5 commit ae8c4c0

File tree

3 files changed

+102
-54
lines changed

3 files changed

+102
-54
lines changed

‎css/style.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
body
2+
{
3+
padding-right: 0px !important;
4+
}
15
.main-container
26
{
37
max-width: 60%;

‎index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<link rel="stylesheet" href="css/style.css">
1313
<title>NoteFizz</title>
1414
</head>
15-
<bodystyle="padding-right: 0px !important;">
15+
<body>
1616

1717
<nav class="navbar navbar-expand-lg navbar-dark bg-dark">
1818
<a class="navbar-brand" href="/">NoteFizz</a>

‎js/script.js

Lines changed: 97 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
/////////////////// getting the note container/////////////////
22
main_container = document.querySelector(".note_container");
3+
4+
////////////////making storenote as a default and unchangeble option/////////////////
35
document.getElementById("storenote").checked=true;
46
document.getElementById("storenote").disabled=true;
57
///////////////////////fetching the value on startup////////////////
68
fetchnote_value = localStorage.getItem("fetchnote");
79

810
if (fetchnote_value == "true") {
911
document.getElementById("fetchnote").checked = true;
12+
1013
saved_notes_display();
1114
} else {
1215
document.getElementById("fetchnote").checked = false;
@@ -36,26 +39,59 @@ function save_to_local(checker, title, data) {
3639
}
3740
}
3841
}
39-
function error_message_shower(title =0, data =0) {
42+
function error_message_shower(title ="", data ="") {
4043
////////////error message shower
41-
if (title) {
42-
terror = document.getElementById("title_error");
44+
terror = document.getElementById("title_error");
45+
derror = document.getElementById("data_error");
46+
if (title!="" && data!="") {
47+
4348
terror.innerHTML = title;
4449
terror.setAttribute("style", "color: red; font-size: 12px;");
4550
t_el = document
4651
.getElementById("note_title")
4752
.setAttribute("style", "border: 1px solid red;");
53+
derror.innerHTML = data;
54+
derror.setAttribute("style", "color: red; font-size: 12px;");
55+
d_el = document
56+
.getElementById("note_data")
57+
.setAttribute("style", "border: 1px solid red;");
4858
}
49-
50-
if (data) {
51-
derror = document.getElementById("data_error");
52-
59+
else if(title!="" && data=="")
60+
{
61+
derror.innerHTML = data;
62+
d_el = document
63+
.getElementById("note_data")
64+
.setAttribute("style", "border: 1px solid green;");
65+
terror.innerHTML = title;
66+
terror.setAttribute("style", "color: red; font-size: 12px;");
67+
t_el = document
68+
.getElementById("note_title")
69+
.setAttribute("style", "border: 1px solid red;");
70+
}
71+
else if (title=="" && data!="") {
72+
73+
terror.innerHTML = ""
74+
t_el = document
75+
.getElementById("note_title")
76+
.setAttribute("style", "border: 1px solid green;");
5377
derror.innerHTML = data;
5478
derror.setAttribute("style", "color: red; font-size: 12px;");
5579
d_el = document
5680
.getElementById("note_data")
5781
.setAttribute("style", "border: 1px solid red;");
5882
}
83+
else if (title=="" && data=="") {
84+
85+
terror.innerHTML = ""
86+
t_el = document
87+
.getElementById("note_title")
88+
.setAttribute("style", "border: 1px solid green;");
89+
90+
derror.innerHTML = ""
91+
d_el = document
92+
.getElementById("note_data")
93+
.setAttribute("style", "border: 1px solid green;");
94+
}
5995
}
6096
//main function which check for the value and wil raise error if founc empty
6197
function data_validator() {
@@ -64,21 +100,30 @@ function data_validator() {
64100
storenote = document.getElementById("storenote").checked;
65101
document.getElementById("note_title");
66102

67-
if (title_el == "") {
68-
error_message_shower("Note Title Can't Empty", false);
103+
if (title_el == "" && data_el == "") {
104+
105+
error_message_shower("Note Title Can't Empty", "Note Data Can't be Empty");
69106
}
70-
if (data_el == "") {
71-
error_message_shower(false, "Note Data Can't be Empty");
72-
} else {
107+
else if (title_el == "" && data_el != "") {
108+
error_message_shower("Note Title Can't Empty","");
109+
}
110+
else if (title_el != "" && data_el == "") {
111+
112+
error_message_shower("", "Note Data Can't be Empty");
113+
}
114+
else {
73115
if(unique_notes_verifier())
74-
{add_note(title_el, data_el);
75-
save_to_local(storenote, title_el, data_el);}
116+
{
117+
add_note(title_el, data_el);
118+
save_to_local(storenote, title_el, data_el);
119+
alert_shower("success", "Note Added Succesfully");
120+
}
76121
}
77122
}
78123
//////////////add note fuction ////////////////////////
79124
function add_note(title_el, data_el) {
80125
notes_count = document.querySelectorAll(".note").length; // returns total created notes
81-
126+
82127
note_card = document.createElement("div");
83128
note_card.className = "note";
84129
note_card.id = `${notes_count + 1}`; //for giving unique id to every note
@@ -104,12 +149,14 @@ function add_note(title_el, data_el) {
104149
</div>`;
105150

106151
document.getElementById(`${notes_count + 1}`).innerHTML = html; //adding the html for the proper view
107-
alert_shower("success","Note Added Succesfully");
152+
108153
}
154+
155+
109156
//////////////////////the delete function. This will remove note from dom and also from localstorage if the note is previously saved in local storage ////////////////////
110-
function notedelete(id, title) {
157+
function notedelete(id, title,msg="") {
111158
el = document.getElementById(id);
112-
// note_title = el.children[0].children[1].children[0].innerHTML;
159+
113160
el.remove();
114161
let notes_array = JSON.parse(localStorage.getItem("notes"));
115162
temp = notes_array;
@@ -123,8 +170,15 @@ function notedelete(id, title) {
123170
return false;
124171
});
125172
localStorage.setItem("notes", JSON.stringify(notes_array));
173+
if(msg!="")
174+
{
175+
alert_shower("success",msg);
176+
}
177+
else
126178
alert_shower("success", "No deleted Succesfully");
127179
}
180+
181+
128182
///////////////////////saved notes display//////////////////////////
129183
function saved_notes_display() {
130184
let noteselm = JSON.parse(localStorage.getItem("notes"));
@@ -135,32 +189,37 @@ function saved_notes_display() {
135189
all_note_in_dom.forEach(function (note, ind) {
136190
all_dom_notes_title.push(note.innerHTML);
137191
});
138-
192+
193+
if(all_notes_in_dom.length > 0)
194+
{
195+
alert_shower("success", "Notes Already Added");
196+
return;
197+
198+
}
139199
if (!noteselm.length) {
200+
140201
alert_shower("danger", "No Notes Found");
141202
} else {
142203
notesObj = noteselm;
143204

144205
notesObj.forEach(function note_data_extractor(note, ind) {
145206
for (var title in note) {
146-
letchk=0;
207+
147208
if (!all_dom_notes_title.length) {
148209
data = note[title];
149210
add_note(title, data);
150211
}
151212
}
152213
});
153214
}
154-
if(all_dom_notes_title.length)
155-
{
156-
alert_shower("success", "Notes Already Added");
157-
}
215+
alert_shower("success", "Note Added Succesfully");
158216
}
217+
/////////////////////verify if it is in local storage///////////////////
159218
function unique_notes_verifier() {
160219

161220
input = document.getElementById("note_title").value;
162221

163-
/////////////////////verify if it is in dom///////////////////
222+
164223
let noteselm = JSON.parse(localStorage.getItem("notes"));
165224
try
166225
{
@@ -199,10 +258,12 @@ function unique_notes_verifier() {
199258

200259
}
201260
//////////////////this will clear your local storage////////////////////
261+
202262
function localStorage_clear() {
203263
localStorage.clear();
204264
alert_shower("danger", "Local Storage Cleared");
205265
}
266+
206267
///////////////////bootstrap alert shower/////////////////////////////
207268
function alert_shower(type, msg) {
208269
el = document.getElementById("alert");
@@ -218,13 +279,19 @@ function alert_shower(type, msg) {
218279
seconds = 1;
219280

220281
let interval_id = setInterval(function () {
221-
if (seconds == 5) {
282+
283+
if (seconds == 8)
284+
{
222285
el.style.display = "none";
223286
clearInterval(interval_id);
224-
} else {
287+
}
288+
else
289+
{
290+
225291
seconds += 1;
292+
226293
}
227-
},1000);
294+
},1000);
228295
}
229296
////////////////////////////////search function///////////////////////////////
230297

@@ -235,7 +302,6 @@ function note_search(e) {
235302
for (i = 0; i < cards.length; i++) {
236303
if (cards[i].innerHTML.toLowerCase().indexOf(input) > -1) {
237304
cards[i].parentNode.parentNode.style.display = "";
238-
console.log(cards[i].parentNode.parentNode);
239305
} else {
240306
cards[i].parentNode.parentNode.style.display = "none";
241307
}
@@ -252,33 +318,11 @@ function edit_note(id)
252318

253319
title.value=note.children[0].innerText;
254320
data.value = note.children[1].innerText;
255-
256-
addbtn = document.getElementById("addbtn");
257-
258-
savebtn = document.createElement('button');
259-
savebtn.innerHTML="Save Note"
260-
savebtn.setAttribute('id',"savebtn")
261-
savebtn.setAttribute('class',"btn btn-dark")
262-
savebtn.setAttribute('onclick',"edit_save()")
263-
addbtn.replaceWith(savebtn);
264-
265-
266-
267-
321+
msg="Note is in edit mode now. Don't left without saving this note otherwise it will be lost."
322+
notedelete(id,note.children[0].innerText,msg);
268323

269324
}
270-
function edit_save()
271-
{
272-
oldnote = document.getElementById(id).children[0];
273-
title = document.getElementById("note_title").value;
274-
275-
data = document.getElementById("note_data").value;
276-
let noteselm = JSON.parse(localStorage.getItem("notes"));
277-
console.log(noteselm)
278-
savebtn.replaceWith(addbtn)
279325

280-
281-
}
282326
//////////////////////////////////////text transition using anime.js/////////////////////////////////////////
283327

284328
var textWrapper = document.querySelector(".ml3");

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /