-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patholdJS.js
310 lines (220 loc) · 9.43 KB
/
oldJS.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
const generalCommands = {
// I need to be able to have the warning message pop up and return if yes was clicked or no
warningPrompt: function(messageText){
// apply the show to the warning box
document.querySelector('.warningBox').classList.add('warningBox_show');
// debugger;
var checked = null;
// create a pop-up box that is a yes or no answer
// take a input for the text of the warning "X" is the text
// return if YES or NO is clicked
var buttonYES = document.querySelector('button.YES');
var buttonNO = document.querySelector('button.NO');
buttonYES.addEventListener('click',function(){
checked = true;
return checked;
});
buttonNO.addEventListener('click',function(){
checked = false;
return checked;
})
},
// delete notes from screen && from local note if not saved
clearNotes: function(){
var checked = generalCommands.compareNotes();
// use a promise instead -
// if there are no notes or notes length is 0 - return as nothing needs to be saved
if(dataStorage.notes === null || dataStorage.notes.length === 0 || checked === 1){
return;
}
// else > show warning to user that un-saved notes
else {
if(confirm('Any not saved data will be deleted')){
document.querySelector('section').innerHTML="";
dataStorage.notes=[];
} else {
return
}
}
},
compareNotes: function(){
var notesSavedOnline = JSON.parse(window.localStorage.getItem('notes'));
var localUnsavedNotes = dataStorage.notes;
// String the two to comapre them
notesSavedOnline = JSON.stringify(notesSavedOnline);
localUnsavedNotes = JSON.stringify(localUnsavedNotes);
// Check to see if they are they same ----
// return 1 if true 0 if false
// Maybe could use a turnery operator below instead of the if or else statment??????
if(notesSavedOnline === localUnsavedNotes) {
return 1;
} else {
return 0
}
}
}
// 1) ----- get the inputs from the form when the user clicks submit
// dont get the inptus if they have left out a field
const uiControlls = {
// get the values
getNote: function(){
// debugger
var noteTitle = document.querySelector('input[name="noteTitle"]');
var noteDescription = document.querySelector('input[name="noteDescription"]');
dataStorage.notes.push({
title: noteTitle.value,
description: noteDescription.value
})
noteTitle.value="";
noteDescription.value="";
// call population automatically once you hit submit -
population.createNotes();
}
}
// 2) ----- store the information in the local cahce of the browser
const dataStorage = {
notes: [],
completedNotes: []
}
const pushData = {
pushLocal: function(){
// debugger;
// If there is **not** a notes list already in local storage then take the notes in
// dataStorage.notes and upload it to local storage
var isNotes = window.localStorage.getItem('notes');
if(isNotes === null){
window.localStorage.setItem('notes',JSON.stringify(dataStorage.notes));
}
},
pullLocal: function(){
// clear current notes if any
generalCommands.clearNotes();
// create a check to see if you have unsaved notes
// pull notes from local storage
// dataStorage.notes.push(JSON.parse(window.localStorage.getItem('notes'))); ******************<<<<<<<<<<<< prior value
// create the notes in the window for the user to see
// *********** bug **************
// if there is only one note in the local storage then the aplcation will not pull the data
// BETTER WAY BELOW -
// get the notes
var localStoedNotes = JSON.parse(window.localStorage.getItem('notes'));
// for each of the notes push the note (object) to the dataStorage
localStoedNotes.forEach(e=>dataStorage.notes.push(e));
population.createNotes();
},
combineData: function(){
debugger;
// get the local notes
var created_notes = dataStorage.notes;
// get the local-storage notes
var local_stored_notes = JSON.parse(window.localStorage.getItem('notes'));
// check to see if there is any local-stored notes
if( local_stored_notes === null){
window.localStorage.setItem('notes',JSON.stringify(local_stored_notes));
// remove the notes from the data-stored notes
dataStorage.notes=[];
return
} else {
var combinedNotes = created_notes.concat(local_stored_notes);
console.log(combinedNotes);
// remove the current array -
window.localStorage.removeItem('notes');
// set a new updated array of notes
window.localStorage.setItem('notes',JSON.stringify(combinedNotes));
// reset the current notes -
dataStorage.notes=[]
}
// combine them into a new array
// return the new array
},
saveNotes: function(){
// push the notes to the local storage
window.localStorage.setItem('notes',JSON.stringify(dataStorage.notes));
}
}
// 3) ----- create the elements for the div
const population = {
createNotes: function(){
document.querySelector('section').innerHTML="";
for(i=0;i<dataStorage.notes.length;i++){
var title = dataStorage.notes[i].title;
var description = dataStorage.notes[i].description;
this.createNoteElements(title, description, i);
}
},
createLocalStorangeNotes: function(){
// debugger;
document.querySelector('section').innerHTML="";
for(i=0;i<dataStorage.notes[0].length;i++){
var title = dataStorage.notes[0][i].title;
var description = dataStorage.notes[0][i].description;
this.createNoteElements(title, description, i);
}
},
createNoteElements: function(title,description, i){
// create dives
// perant >>>>
let noteNumber = i;
let note = document.createElement('div');
note.className="note fade-in";
// siblings >>>>
let details = document.createElement('div')
details.className="details";
let options = document.createElement('div')
options.className="options";
// **************** details
// TITLE >>>>>
let h2 = document.createElement('h2');
h2.innerHTML=title;
h2.className="title";
// DESCRIPTION >>>>>
let p = document.createElement('p');
p.innerHTML=description;
p.className="description";
details.appendChild(h2);
details.appendChild(p);
// **************** options
let edit = document.createElement('button');
edit.innerHTML="edit".className="edit";
var complete = document.createElement('button');
complete.innerHTML="complete".className="complete";
// ************************
// CLICK EVENT FOR COMPLETED BUTTON BELOW
// 1) create Confirm div + assign it styles
// 2) if confirm clicked - store the note in A) completed notes A-2) Remove note from current notes > and B) reload the notes
// ************************
// 1)
var completeDuplicated;
complete.addEventListener('click', function(){
if (completeDuplicated === undefined){
completeDuplicated = 1
var div = document.createElement('div');
div.innerText="Confirm?";
div.className="confirm fade-in";
note.appendChild(div);
// 2)
}
else{return}
div.addEventListener('click',function(){
div.className="confirm fade-away";
// >>>> Assign the note completed animation
document.querySelectorAll('.note')[noteNumber].className="note noteCompleted";
// A)
dataStorage.completedNotes.push(dataStorage.notes[noteNumber]);
// A-2)
dataStorage.notes.splice(noteNumber,1);
// B) - timeout function here is so that the animations line up -
setTimeout(function(){
population.createNotes();
},1000)
})
})
options.appendChild(edit);
options.appendChild(complete);
// Append
note.appendChild(details);
note.appendChild(options);
const section = document.querySelector('section');
section.appendChild(note);
}
}