-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
174 lines (167 loc) · 5.83 KB
/
app.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
/*All element Selector */
var sname=document.getElementById('name');
fname=document.getElementById('fname'),
ssubmit=document.getElementById('submit'),
className=document.getElementById('class'),
roll=document.getElementById('roll'),
religion=document.getElementById('religion'),
tbody=document.getElementById('tbody'),
birth=document.getElementById('birth'),
search=document.getElementById('search'),
popup=document.getElementById('popup'),
popup1=document.getElementById('popup1'),
search_select=document.getElementById('search_select'),
studentValue=new Array();
/*Form Submited Action Doing Here*/
ssubmit.addEventListener('submit',(e)=>{
e.preventDefault();
/*Required Element Value Goting Action*/
let snameval=sname.value,
classval=className.value,
rollval=roll.value,
subjectval=fname.value,
religionval=religion.value,
birthval=birth.value;
/*Form Validation Work Action Here (if Validation is success then value gonna local storage*/
if(snameval=='' || classval=='' || rollval=='' || religionval=='' || birthval==''){
popup.classList.add('popupshow');
}else{
getData()
studentValue.push({
name:snameval,
subject:subjectval,
class:classval,
roll:rollval,
religion:religionval,
birth:birthval
})
localStorage.setItem('allvalue',JSON.stringify(studentValue));
showData();
sname.value='';
roll.value='';
className.value='Class';
religion.value='Religion';
birth.value='';
}
})
/*Global Array Innar new new value passing action here*/
function getData() {
let allcoverval=localStorage.getItem('allvalue');
if(allcoverval != null){
studentValue=JSON.parse(allcoverval);
}
}
/*Collect All the JSONdata in LocalStorage and Show Browser*/
showData()
function showData() {
getData()
let child=tbody.children.length;
for(i=child;i<studentValue.length;i++){
var snameval=studentValue[i].name,
classval=studentValue[i].class,
rollval=studentValue[i].roll,
subjectval=studentValue[i].subject,
religionval=studentValue[i].religion,
birthval=studentValue[i].birth;
let editsave='<button class="btn btn-outline-warning mr-2" onclick="edit(this)"><i class="fa fa-pencil-square-o "></i></button><button class="btn btn-outline-success" onclick="save(this)"> <i class="fa fa-floppy-o"></i></button><button class="btn btn-danger ml-2" onclick="trash(this)"><i class="fa fa-trash-o"></i></button>';
let allval=[snameval,classval,rollval,subjectval,religionval,birthval,editsave];
let tr=document.createElement('tr');
for(item of allval){
let td=document.createElement('td');
td.innerHTML=item;
tr.appendChild(td);
tbody.appendChild(tr)
}
/*Hover to Show Button Effect Code*/
let settrCover=tbody.children;
for(let i=0;i<settrCover.length;i++){
settrCover[i].setAttribute("class", "cover")
settrCover[i].children[6].setAttribute("class", "edit_card")
}
}
}
/*Change Search Value*/
let changevalue =0;
search_select.addEventListener('change',()=>{
changevalue = search_select.value;
if(changevalue==0){
search.setAttribute('placeholder','Name Search...');
search.type='search';
}else if(changevalue==1){
search.setAttribute('placeholder','Class Search...');
search.type='search';
}else if(changevalue==2){
search.setAttribute('placeholder','Roll Search...');
search.type='number';
}
})
/*Search Section*/
search.addEventListener('input',()=>{
var myinput=search.value.toUpperCase().trim();
let tr=tbody.children;
for(var i=0; i < tr.length;i++){
let td= tr[i].children[changevalue].innerText.toUpperCase();
if(td.indexOf(myinput)>-1){
tr[i].style.display=""
}else{
tr[i].style.display="none";
}
}
})
/****** 3Button(edit,save,delete) Code Section **********/
/*Edit Button*/
function edit(elmnt) {
let a=elmnt.parentElement.parentElement.children;
for(let i=0;i<6;i++){
a[i].setAttribute('contenteditable','true');
a[i].style.border="2px solid #86fa66"
a[i].style.background="white";
}
}
/*After Edit Save Button*/
function save(elmnt) {
let a=elmnt.parentElement.parentElement.children;
for(let i=0;i<6;i++){
a[i].setAttribute('contenteditable','false');
a[i].style.border="";
a[i].style.background="";
}
for (var i = 0, len = tbody.children.length; i < len; i++){
(function(index){
tbody.children[i].onclick = function(){
let getval=tbody.children[index].children;
studentValue[index].name=getval[0].innerText;
studentValue[index].subject=getval[3].innerText;
studentValue[index].class=getval[1].innerText;
studentValue[index].roll=getval[2].innerText;
studentValue[index].religion=getval[4].innerText;
studentValue[index].birth=getval[5].innerText;
localStorage.setItem('allvalue',JSON.stringify(studentValue));
}
})(i);
}
}
/*Table Element Delete Button */
function trash(e){
for (var i = 0, len = tbody.children.length; i < len; i++){
(function(index){
tbody.children[i].onclick = function(){
studentValue.splice(index,1);
localStorage.setItem('allvalue',JSON.stringify(studentValue));
}
})(i);
}
e.parentElement.parentElement.remove();
}
/*Popup Close Button*/
function exit(){
popup.classList.remove('popupshow')
popup1.classList.remove('popupshow')
}
function cleardata(){
popup1.classList.add('popupshow');
}
function deleltedata(){
localStorage.clear();
location.reload();
}