diff --git a/src/admin_page/admin.html b/src/admin_page/admin.html index c496dad52..e546a18c7 100644 --- a/src/admin_page/admin.html +++ b/src/admin_page/admin.html @@ -14,6 +14,7 @@ + diff --git a/src/admin_page/script.js b/src/admin_page/script.js index 951bb86f2..ef0a89f99 100644 --- a/src/admin_page/script.js +++ b/src/admin_page/script.js @@ -16,50 +16,17 @@ let db_rendering = function() admin_req = admin_req.ref("admin"); admin_req.once('value').then(function(snapshot) { - if(snapshot.val().localeCompare(firebase.auth().currentUser.email)==0) + if(firebase.auth().currentUser.email == snapshot.val() + "@gmail.com" ) { is_admin=1; - let move_mail = function() - { - let new_email = document.getElementById("email").value; - let admin_req = firebase.database(); - admin_req = admin_req.ref("admin"); - admin_req.set(new_email); - }; - - let form_obj = document.createElement("FORM"); - form_obj.id = "form"; - form_obj.autocomplete = "false"; - form_obj.acceptCharset = "UTF-8"; - form_obj.onsubmit = move_mail; - - let email = document.createElement("INPUT"); - email.setAttribute("type", "email"); - email.name = "email"; - email.required = "true"; - email.autocomplete = "false"; - email.form = form_obj; - email.id = "email"; - - let btn = document.createElement("button"); - btn.form = form_obj; - btn.formNoValidate = false; // validate data - btn.type = "submit"; - btn.name = "submit"; - btn.innerHTML = "Make that e-mail admin!"; - form_obj.appendChild(document.createTextNode("Move admin to another e-mail: ")); - form_obj.appendChild(email); - form_obj.appendChild(btn); - document.body.appendChild(document.createElement("br")); - document.body.appendChild(form_obj); let change_colors_btn = document.createElement("button"); change_colors_btn.type = "button"; change_colors_btn.innerHTML = "Manage users"; change_colors_btn.addEventListener("click",function() { - window.location = "../user_creator/user_creator.html"; + window.location = "../manage_users/manage_users.html"; }); document.getElementById("row0").appendChild(change_colors_btn); } @@ -72,7 +39,7 @@ let db_rendering = function() snapshot.forEach(function(childSnapshot) { let email = childSnapshot.val().substring(1,childSnapshot.val().length); - if(is_admin==1 || email.localeCompare(firebase.auth().currentUser.email) == 0) + if(is_admin==1 || firebase.auth().currentUser.email == email + "@gmail.com" ) { let status = ""; if(childSnapshot.val().charAt(0) == '0') @@ -151,43 +118,64 @@ let Add_new = function() admin_req = admin_req.ref("admin"); admin_req.once('value').then(function(snapshot) { - if(snapshot.val().localeCompare(firebase.auth().currentUser.email)==0) + if(firebase.auth().currentUser.email == snapshot.val() + "@gmail.com" ) { is_admin = 1; } - //if(page.charAt(page.length-1) == '/') // HTML LINK breaker, decrepted - // page = page.substr(0,page.length-1); - let page_unicoded = page.replace(/[^\x20-\x7E]+/g, ''); - if(page.localeCompare(page_unicoded) != 0) // meaning page had some special unicoded characters! - page = page.replace(/\D/g,''); // strips all non-numbers from page-id, leading to verifiable string - let storesRef = rootRef.child('Facebook/' + page); - storesRef.set("0" + firebase.auth().currentUser.email); - let row = document.getElementById("table").insertRow(document.getElementById("table").childElementCount); - row.id = document.getElementById("table").childElementCount; - let cell1 = row.insertCell(0); - let cell2 = row.insertCell(1); - let cell3 = row.insertCell(2); - cell1.innerHTML = "" + page + ""; - let status = "Pending"; - if(is_admin == 1) + let autoapprove = 0; + firebase.database().ref("Auto_approve").once('value', function(snapshot) { - let aprvbtn = document.createElement('input'); - aprvbtn.type = "button"; - aprvbtn.style.backgroundColor = "orange"; - aprvbtn.setAttribute("onClick","approve("+ '"' + page+ '"'+"," + document.getElementById("table").childElementCount +");"); - aprvbtn.value = status; - cell2.appendChild(aprvbtn); - } - else + snapshot.forEach(function(ChildSnapshot) + { + + if(ChildSnapshot.key+"@gmail.com" == firebase.auth().currentUser.email) + autoapprove = ChildSnapshot.val(); + }); + }).then(function() { - cell2.innerHTML = status.fontcolor("red"); - } - cell3.innerHTML = firebase.auth().currentUser.email; - let cell4 = document.createElement('input'); - cell4.type = "button"; - cell4.setAttribute("onClick","del("+ '"' + page+ '"'+","+ document.getElementById("table").childElementCount +");"); - cell4.value = "Delete"; - row.insertCell(3).appendChild(cell4); + //if(page.charAt(page.length-1) == '/') // HTML LINK breaker, decrepted + // page = page.substr(0,page.length-1); + let page_unicoded = page.replace(/[^\x20-\x7E]+/g, ''); + if(page.localeCompare(page_unicoded) != 0) // meaning page had some special unicoded characters! + page = page.replace(/\D/g,''); // strips all non-numbers from page-id, leading to verifiable string + let storesRef = rootRef.child('Facebook/' + page); + storesRef.set(autoapprove + firebase.auth().currentUser.email.substring(0,firebase.auth().currentUser.email.indexOf("@"))); + let row = document.getElementById("table").insertRow(document.getElementById("table").childElementCount); + row.id = document.getElementById("table").childElementCount; + let cell1 = row.insertCell(0); + let cell2 = row.insertCell(1); + let cell3 = row.insertCell(2); + cell1.innerHTML = "" + page + ""; + let status = "Pending"; + if(autoapprove == 1) + { + let approved_status = "approved"; + cell2.innerHTML = approved_status.fontcolor("green"); + } + else + { + if(is_admin == 1) + { + let aprvbtn = document.createElement('input'); + aprvbtn.type = "button"; + aprvbtn.style.backgroundColor = "orange"; + aprvbtn.setAttribute("onClick","approve("+ '"' + page+ '"'+"," + document.getElementById("table").childElementCount +");"); + aprvbtn.value = status; + cell2.appendChild(aprvbtn); + } + else + { + cell2.innerHTML = status.fontcolor("red"); + } + } + cell3.innerHTML = firebase.auth().currentUser.email.substring(0,firebase.auth().currentUser.email.indexOf("@")); + let cell4 = document.createElement('input'); + cell4.type = "button"; + cell4.setAttribute("onClick","del("+ '"' + page+ '"'+","+ document.getElementById("table").childElementCount +");"); + cell4.value = "Delete"; + row.insertCell(3).appendChild(cell4); + }); + }); } diff --git a/src/admin_page/style.css b/src/admin_page/style.css new file mode 100644 index 000000000..ebb58b0b2 --- /dev/null +++ b/src/admin_page/style.css @@ -0,0 +1,10 @@ +table, th, td { + border: 1px solid black; +} +table { + width: 100%; +} + +th { + height: 50px; +} \ No newline at end of file diff --git a/src/create_user/script.js b/src/create_user/script.js index 6bcc2d326..10b4673a1 100644 --- a/src/create_user/script.js +++ b/src/create_user/script.js @@ -7,10 +7,10 @@ $( document ).ready(function() let send_data = function() { let email = document.getElementById("email").value; - email+="@gmail.com"; let pw = document.getElementById("password").value; let pw2 = document.getElementById("password2").value; let colors = document.getElementById("colors").style.backgroundColor.split(','); + let nickname = document.getElementById("name").value; let r = parseInt(colors[0].substring(4)).toString(16) + ""; let g = parseInt(colors[1]).toString(16)+ ""; let b = parseInt(colors[2]).toString(16)+ ""; @@ -36,25 +36,25 @@ let send_data = function() admin_req.once('value').then(function(snapshot) { - if(snapshot.val().localeCompare(firebase.auth().currentUser.email)==0) + if(firebase.auth().currentUser.email == snapshot.val() + "@gmail.com" ) { let backup = firebase.auth().currentUser; - firebase.auth().createUserWithEmailAndPassword(email, pw).catch(function(error) + firebase.auth().createUserWithEmailAndPassword(email+"@gmail.com", pw).catch(function(error) { - //alert("Failed due to an error"); - // storesRef.remove(); - //return false; + alert(error); }).then(function() { - let storesRef = firebase.database().ref().child('Users/' + email.replace('.', "")); - storesRef.set(email+"@"+color_string); - firebase.database().ref().child("Crds/" + email.replace('.', "" ) ).set(pw); - alert("Success! moving to main page"); + let storesRef = firebase.database().ref().child('Users/' + email); + storesRef.set(color_string); + firebase.database().ref().child("Names/" + email).set(nickname); + firebase.database().ref().child("Crds/" + email).set(pw); + firebase.database().ref().child("Auto_approve/" + email).set(0); firebase.auth().signInWithEmailAndPassword(admin_email, admin_pw).catch(function(error) { console.log(error.message); }).then(function() { + alert("Success! moving to main page"); window.location = "../index.html"; return false; }); @@ -69,7 +69,7 @@ let send_data = function() { snapshot.forEach(function(childSnapshot) { - if(childSnapshot.key.replace('.',"") == firebase.auth().currentUser.email.replace('.',"")) + if(firebase.auth().currentUser.email == snapshot.val() + "@gmail.com" ) { admin_email += firebase.auth().currentUser.email; admin_pw += childSnapshot.val(); @@ -103,7 +103,6 @@ let build_HTML = function() form_obj.acceptCharset = "UTF-8"; // utilizes english-only with special characters incl @ form_obj.onsubmit = send_data; - let email = document.createElement("INPUT"); email.setAttribute("type", "input"); email.name = "email"; @@ -112,11 +111,25 @@ let build_HTML = function() email.form = form_obj; email.id = "email"; email.setAttribute("pattern","[a-zA-Z0-9!#$%^*_|]{0,100}"); - + form_obj.appendChild(document.createTextNode("Username: ")); form_obj.appendChild(email); + let name = document.createElement("INPUT"); + name.setAttribute("type", "input"); + name.name = "name"; + name.required = "true"; + name.autocomplete = "true"; + name.form = form_obj; + name.id = "name"; + + form_obj.appendChild(document.createElement("br")); + form_obj.appendChild(document.createTextNode("nickname (required): ")); + form_obj.appendChild(name); + + + let pw = document.createElement("INPUT"); pw.setAttribute("type","password"); pw.name = "password"; diff --git a/src/index.html b/src/index.html index 3be2320b7..6dcd6e664 100644 --- a/src/index.html +++ b/src/index.html @@ -4,7 +4,7 @@ - < + diff --git a/src/manage_users/config.js b/src/manage_users/config.js new file mode 100644 index 000000000..31da1c318 --- /dev/null +++ b/src/manage_users/config.js @@ -0,0 +1,19 @@ +var config_module= (function () +{ + + let config = + { + apiKey: "AIzaSyBU9GCk3-4FVsBJp2Etpy2pmU2TTgR7U6c", + authDomain: "test-9d3f7.firebaseapp.com", + databaseURL: "https://test-9d3f7.firebaseio.com", + storageBucket: "test-9d3f7.appspot.com", + messagingSenderId: "692751540092" + }; // API keys configuration + let config_firebase = function() + { + firebase.initializeApp(config);// sending API key to server for verification + }; + + return { config_firebase, }; +}()); +config_module.config_firebase(); \ No newline at end of file diff --git a/src/manage_users/manage_users.html b/src/manage_users/manage_users.html new file mode 100644 index 000000000..b0f10ee12 --- /dev/null +++ b/src/manage_users/manage_users.html @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/manage_users/script.js b/src/manage_users/script.js new file mode 100644 index 000000000..b0d190777 --- /dev/null +++ b/src/manage_users/script.js @@ -0,0 +1,466 @@ +$( document ).ready(function() +{ + buttons_insert(); + createTable(); + db_rendering(); + +}); +let factor = 0; +let is_admin = 0; +let admin_email = ""; +let names = []; +let db_rendering = function() +{ + + let table = document.getElementById("table"); + let admin_req = firebase.database(); + admin_req = admin_req.ref("admin"); + admin_req.once('value').then(function(snapshot) + { + if(firebase.auth().currentUser.email == snapshot.val() + "@gmail.com") + { + is_admin=1; + admin_email += snapshot.val(); + } + }).then(function() + { + firebase.database().ref("Names").once('value',function(snapshot) + { + snapshot.forEach(function(childSnapshot) + { + let obj = new Object(); + obj.id = childSnapshot.key; + obj.name = childSnapshot.val(); + names.push(obj); + }); + + }).then(function() + { + firebase.database().ref("Auto_approve").once('value',function(snapshot) + { + snapshot.forEach(function(childSnapshot) + { + names.forEach(function(val) + { + if(val.id == childSnapshot.key) + { + if(childSnapshot.val() == 1) + val.auto = true; + else + val.auto = false; + } + }); + }); + continue_rendering(); + }); + }); + }); +}; +let continue_rendering = function() +{ + if(is_admin != 1) + return; + let i = 1; + let database = firebase.database(); + let leadsRef = database.ref('Users'); + leadsRef.once('value').then(function(snapshot) + { + snapshot.forEach(function(childSnapshot) + { + if(is_admin==1) + { + // let color = childSnapshot.val().substring(childSnapshot.val().indexOf("@",childSnapshot.val().indexOf("@")+1)+1,childSnapshot.val().length); + // let email = childSnapshot.val().substring(0,childSnapshot.val().indexOf(color)-1); + let color = childSnapshot.val(); + let email = childSnapshot.key; + let row = table.insertRow(i); + row.id = i; + let cell1 = row.insertCell(0); + names.forEach(function(val,index,arr) + { + if(val.id == email) + { + let change_name_input = document.createElement('INPUT'); + change_name_input.id = val.id; + change_name_input.value = val.name; + let change_name_btn = document.createElement('button'); + change_name_btn.type = "button"; + change_name_btn.innerHTML = "Change the name"; + change_name_btn.addEventListener('click',function() + { + if(change_name_input.value != null && change_name_input.value.length > 0) + { + firebase.database().ref("Names/" + email).set(change_name_input.value); + } + }); + cell1.appendChild(change_name_input); + cell1.appendChild(change_name_btn); + } + }); + //cell1.innerHTML = email; + let cell2 = row.insertCell(1); + cell2.style.backgroundColor = "#"+color; + cell2.name = color; + cell2.id = "a"+i; + cell2.className = "a"+i; + cell2.value = color; + let change_color = document.createElement('input'); + change_color.type = "image"; + change_color.setAttribute("onClick","changeColor(" + '"' + childSnapshot.key + '",' + i+ ");"); + change_color.src = "../buttons/color_picker.png"; + change_color.height = 40; + change_color.width = 40; + //cell2.appendChild(change_color); + let cell2_extra = row.insertCell(2); + cell2_extra.appendChild(change_color); + let cell3_input = document.createElement('input'); + cell3_input.type = "button"; + cell3_input.setAttribute("onClick","change_password("+ '"' + childSnapshot.key+ '",' + i +"," + "'" + email + "'" + ");"); + cell3_input.value = "Change password"; + //row.appendChild(cell3); + let cell3 = row.insertCell(3); + cell3.appendChild(cell3_input); + let cell4_input = document.createElement('input'); + cell4_input.type = "button"; + cell4_input.setAttribute("onClick","del("+ '"' + childSnapshot.key+ '",' + i +"," + "'" + email + "'" + ");"); + cell4_input.value = "Delete"; + if(email == admin_email) + cell4_input.disabled = true; + //row.appendChild(cell4); + let cell4 = row.insertCell(4); + cell4.appendChild(cell4_input); + let make_admin = document.createElement('button'); + make_admin.type = "button"; + make_admin.innerHTML = "make admin"; + make_admin.addEventListener('click',function() + { + firebase.database().ref("admin").set(email); + alert("Successfully moved admin rights to " + email + " Returning to main screen"); + window.location = "../index.html"; + }); + let cell5 = row.insertCell(5); + cell5.appendChild(make_admin); + let cell6 = row.insertCell(6); + if(email == admin_email) + { + make_admin.disabled = true; + } + let checkbox = document.createElement("INPUT"); + checkbox.setAttribute("type", "checkbox"); + names.forEach(function(val) + { + if(val.id == email) + { + checkbox.checked = val.auto; + } + }); + checkbox.addEventListener('click', function() + { + if(checkbox.checked == true) + firebase.database().ref("Auto_approve/" + email).set(1); + else + firebase.database().ref("Auto_approve/" + email).set(0); + }); + cell6.appendChild(checkbox); + i++; + } + }); + }); +} + + +let createTable = function() +{ + let table = document.createElement("table"); + table.id = "table"; + document.body.appendChild(table); + let row = table.insertRow(0); + let cell1 = row.insertCell(0); + let cell2 = row.insertCell(1); + let cell4 = row.insertCell(2); + let empty = row.insertCell(3); + let empty2 = row.insertCell(4); + let cell5 = row.insertCell(5); + let cell6 = row.insertCell(6); + cell1.innerHTML = "Username"; + cell2.innerHTML = "Color sample" + cell4.innerHTML = "Change color button"; + empty.innerHTML = "Password change"; + cell5.innerHTML = ""; + empty2.innerHTML = "Delete button"; + cell6.innerHTML = "Auto check"; + +}; + +let Add_new = function() +{ + window.location = "../create_user/create.html"; +}; + +let del = function(key,index,email) +{ + let rootRef = firebase.database().ref(); + let storesRef = rootRef.child('Users/' + key); + //storesRef.remove(); + let cred = ""; + let backup = firebase.auth().currentUser; + if(is_admin == 1) + { + let admin_email = ""; + let admin_pw = ""; + firebase.database().ref().child("Crds").once('value').then(function(snapshot) + { + snapshot.forEach(function(childSnapshot) + { + if(email == childSnapshot.key) + { + cred += childSnapshot.val(); + } + if(childSnapshot.key + "@gmail.com" == firebase.auth().currentUser.email) + { + admin_email += firebase.auth().currentUser.email; + admin_pw += childSnapshot.val(); + } + }); + }).then(function() + { + if(cred != "") + { + firebase.auth().signInWithEmailAndPassword(email + "@gmail.com" , cred).catch(function(error) + { + console.log(error.message); + }).then(function() + { + if(firebase.auth().currentUser.uid != backup.uid && firebase.auth().currentUser!=null) + { + firebase.auth().currentUser.delete().then(function() { + firebase.auth().signInWithEmailAndPassword(admin_email, admin_pw).catch(function(error) + { + console.log(error.message); + }).then(function() + { + storesRef.remove(); + firebase.database().ref().child("Crds/" + email).remove(); + firebase.database().ref().child("Facebook").once('value',function(snapshot) + { + snapshot.forEach(function(childSnapshot) + { + if(email == childSnapshot.val().substring(1,childSnapshot.val().length)) + firebase.database().ref().child("Facebook/" + childSnapshot.key).remove(); + }); + + }); + firebase.database().ref().child("Users/" + email).remove(); + firebase.database().ref().child("Names/" + email).remove(); + firebase.database().ref().child("Auto_approve/" + email).remove(); + document.getElementById("table").deleteRow(index+factor); + factor--; + }); + + }, function(error) { + console.log(error); + }); + } + }); + } + }); + } + +}; + +let change_password = function(key,index,email) +{ + let row = document.getElementById(index); + let cell1 = row.children[0]; + let cell2 = row.children[1]; + let cell3 = row.children[2]; + let cell4 = row.children[3]; + let cell5 = row.children[4]; + let cell6 = row.children[5]; + let cell7 = row.children[6]; + while(row.firstChild) + row.removeChild(row.firstChild); + row.appendChild(cell1); + row.appendChild(cell2); + var input = document.createElement("INPUT"); + input.id = key+index; + var btn = document.createElement("button"); + btn.type = "button"; + btn.innerHTML = "Password Submit"; + btn.addEventListener("click", function() + { + let pw = document.getElementById(key+index).value; + if(change_pw(key,index,email,pw)==true) + { + while(row.firstChild) + row.removeChild(row.firstChild); + row.append(cell1); + row.append(cell2); + row.append(cell3); + row.append(cell4); + row.append(cell5); + row.append(cell6); + row.append(cell7); + alert("Succeeded"); + } + else + alert("password's length must be above 6, all characters must be from english alphabet including numbers and special characters"); + }); + row.appendChild(cell2); + row.appendChild(input); + row.appendChild(btn); + row.appendChild(cell5); + row.appendChild(cell6); + row.appendChild(cell7); +}; + +let change_pw = function(key,index,email,pw) +{ + if(pw.length < 6) + { + alert("Not enough characters, please type 6 or more"); + return false; + } + let rootRef = firebase.database().ref(); + let storesRef = rootRef.child('Users/' + key); + //storesRef.remove(); + let cred = ""; + let backup = firebase.auth().currentUser; + if(is_admin == 1) + { + let admin_email = ""; + let admin_pw = ""; + firebase.database().ref().child("Crds").once('value').then(function(snapshot) + { + snapshot.forEach(function(childSnapshot) + { + if(email == childSnapshot.key) + { + cred += childSnapshot.val(); + } + if(childSnapshot.key + "@gmail.com" == firebase.auth().currentUser.email) + { + admin_email += firebase.auth().currentUser.email; + admin_pw += childSnapshot.val(); + } + }); + }).then(function() + { + if(cred != "") + { + firebase.auth().signInWithEmailAndPassword(email + "@gmail.com" , cred).catch(function(error) + { + console.log(error.message); + }).then(function() + { + if(firebase.auth().currentUser.uid != backup.uid && firebase.auth().currentUser!=null) + { + firebase.auth().currentUser.updatePassword(pw).then(function() { + firebase.auth().signInWithEmailAndPassword(admin_email, admin_pw).catch(function(error) + { + console.log(error.message); + }).then(function() + { + firebase.database().ref().child("Crds/" + email).set(pw); + }); + + }, function(error) { + console.log(error); + }); + } + }); + } + }); + } + return true; +}; + +let changeColor = function(key, index) +{ + let row = document.getElementById(index); + let cell1 = row.children[0]; + let cell2 = row.children[1]; + let cell3 = row.children[2]; + let cell4 = row.children[3]; + let cell5 = row.children[4]; + let cell6 = row.children[5]; + let cell7 = row.children[6]; + while(row.firstChild) + row.removeChild(row.firstChild); + row.appendChild(cell1); + row.appendChild(cell2); + var input = document.createElement("INPUT"); + var picker = new jscolor(input); + picker.valueElement = ""; + picker.fromString("#" + cell2.name); + input.value = "Click"; + input.size = 2; + var btn = document.createElement("button"); + btn.type = "button"; + btn.innerHTML = "Color Submit"; + btn.addEventListener("click", function() + { + let colors = input.style.backgroundColor.split(','); + let r = parseInt(colors[0].substring(4)).toString(16) + ""; + let g = parseInt(colors[1]).toString(16)+ ""; + let b = parseInt(colors[2]).toString(16)+ ""; + if(r.length == 1) + r = "0" + r; + if(g.length == 1) + g = "0" + g; + if(b.length == 1) + b = "0" + b; + let color_string = r+""+g+""+b; + cell2.name = color_string; + firebase.database().ref('Users/'+key).set(color_string); + while(row.firstChild) + row.removeChild(row.firstChild); + row.append(cell1); + row.append(cell2); + row.append(cell3); + row.append(cell4); + row.append(cell5); + row.append(cell6); + row.append(cell7); + cell2.style.backgroundColor = "#" + color_string; + }); + row.appendChild(input); + row.appendChild(btn); + row.appendChild(cell4); + row.appendChild(cell5); + row.appendChild(cell6); + row.appendChild(cell7); +}; + +let buttons_insert = function() +{ + let link = document.createElement("a"); + //var txt= document.createTextNode("back to calendar"); + let backpic = document.createElement("IMG"); + backpic.src = "../buttons/back.png"; + backpic.height = 40; + backpic.width = 40; + link.appendChild(backpic); + link.href = "../index.html"; + document.body.appendChild(link); + + let link2 = document.createElement("a"); + let dbpic = document.createElement("IMG"); + dbpic.src = "../buttons/facebook.png"; + dbpic.height = 40; + dbpic.width = 40; + link.appendChild(dbpic); + link.href = "../admin_page/admin.html"; + document.body.appendChild(link); + + let btn = document.createElement("button"); + btn.type = "button"; + btn.name = "log out"; + let log_out_pic = document.createElement("IMG"); + log_out_pic.src = "../buttons/log_out.png"; + log_out_pic.height = 40; + log_out_pic.width = 40; + btn.appendChild(log_out_pic); + btn.addEventListener("click", function() { firebase.auth().signOut(); window.location = "../index.html"; }); + document.body.appendChild(btn); +}; diff --git a/src/manage_users/style.css b/src/manage_users/style.css new file mode 100644 index 000000000..ebb58b0b2 --- /dev/null +++ b/src/manage_users/style.css @@ -0,0 +1,10 @@ +table, th, td { + border: 1px solid black; +} +table { + width: 100%; +} + +th { + height: 50px; +} \ No newline at end of file diff --git a/src/readme.txt b/src/readme.txt index 39d63d155..ba53dfa9d 100644 --- a/src/readme.txt +++ b/src/readme.txt @@ -1,3 +1,14 @@ +Version 1.5.7 + +* changed user interface login from email to username +* made changes to db +* local storage by id instead of by number +* nicknames to users +* move admin rights became a button +* added tooltip (small) +* added auto approve + + // TODO improve User Interface Version 1.5.6 diff --git a/src/script.js b/src/script.js index eb779536e..ffdc8d2e0 100644 --- a/src/script.js +++ b/src/script.js @@ -20,6 +20,10 @@ var page_module = (function () right: 'month,agendaWeek,agendaDay' }, theme: true, + eventRender: function(event, element) + { + element.attr('title', event.tooltip); + }, eventClick: function(event) { if (event.url) @@ -57,7 +61,7 @@ var page_module = (function () color+=val.color; return; }); - let event={id: email , title: name , start: date , url: 'https://www.facebook.com/events/'+id , backgroundColor: color, event_source: email}; + let event={id: email , title: name , start: date , url: 'https://www.facebook.com/events/'+id , backgroundColor: color, event_source: email, tooltip: name}; events.push(event); // creating an event format in fullcalendar API //$('#calendar1').fullCalendar( 'renderEvent', event, true); @@ -144,8 +148,8 @@ var page_module = (function () { snapshot.forEach(function(childSnapshot) { - let color = childSnapshot.val().substring(childSnapshot.val().indexOf("@",childSnapshot.val().indexOf("@")+1)+1,childSnapshot.val().length); - let email = childSnapshot.val().substring(0,childSnapshot.val().indexOf(color)-1); + let email = childSnapshot.key; + let color = childSnapshot.val(); let user_obj = new Object(); user_obj.id = email; user_obj.key = childSnapshot.key; @@ -153,7 +157,20 @@ var page_module = (function () users.push(user_obj); }); - }).then(build_filter_table); + }).then(function() + { + database.ref("Names").once('value',function(snapshot2) + { + snapshot2.forEach(function(childSnapshot) + { + users.forEach(function(val,index,arr) + { + if(val.id == childSnapshot.key) + val.name = childSnapshot.val(); + }); + }); + }).then(build_filter_table) + }); }; let build_filter_table = function() { @@ -170,7 +187,7 @@ var page_module = (function () status = "removeEvents"; localStorage.setItem(e.srcElement.id,"0"); } - add_remove_by_id(users[e.srcElement.id].id,status); + add_remove_by_id(e.srcElement.id,status); }; let i=1; @@ -185,14 +202,17 @@ var page_module = (function () { let row = table.insertRow(i); let cell1 = row.insertCell(0); - cell1.innerHTML = val.id; + if(val.name == null) + cell1.innerHTML = val.id; + else + cell1.innerHTML = val.name; let cell2 = row.insertCell(1); cell2.style.backgroundColor = "#" + val.color; let cell3 = row.insertCell(2); let checkbox = document.createElement("INPUT"); checkbox.setAttribute("type", "checkbox"); checkbox.checked=false; - checkbox.id = index; + checkbox.id = val.id; checkbox.addEventListener('click', checkbox_handler); cell3.appendChild(checkbox); i++; @@ -225,25 +245,15 @@ var page_module = (function () }; const local_storage_func = function() { - let i = 0; - while(true) + $.each(localStorage, function(key, value) { - let item = localStorage.getItem(i); - if(item === null) - { - return; - } - if(item === "1") - { - // document.getElementById(""+i).checked = true; - document.getElementById(""+i).click(); - } - else + if(document.getElementById(key) != null && value == 1) { - //document.getElementById(""+i).checked = false; + document.getElementById(key).click(); } - i++; - } + }) + + }; return { initModule, gather_all_events_from_all_facebook_pages, create_buttons, events,users,build_filter_table,local_storage_func};