Added Programs with Firebase (v.2)
This commit is contained in:
+92
-9
@@ -1,3 +1,86 @@
|
||||
// Display List of Programs in form
|
||||
function programList() {
|
||||
database = firebase.database().ref("programs");
|
||||
database.once('value', function(snapshot) {
|
||||
snapshot.forEach(function(child) {
|
||||
var a = document.createElement("option")
|
||||
a.setAttribute("value",child["key"].replace(/,/g,"."))
|
||||
a.innerHTML = child["key"].replace(/,/g,".")
|
||||
document.getElementById("program-list").appendChild(a)
|
||||
})
|
||||
});
|
||||
programOnChange();
|
||||
}
|
||||
|
||||
// Add New Program
|
||||
function submitProgram() {
|
||||
var data = {
|
||||
title: document.getElementById("new-program-title").value.replace(".",","),
|
||||
link: document.getElementById("new-program-link").value,
|
||||
imglink: document.getElementById("new-program-imglink").value,
|
||||
author: document.getElementById("new-program-author").value,
|
||||
description: document.getElementById("new-program-description").value,
|
||||
programtype: document.getElementById("new-program-type").value
|
||||
}
|
||||
firebase.database().ref("programs/"+document.getElementById("new-program-title").value.replace(".",",")).set(data)
|
||||
document.getElementById("new-program-title").value = '';
|
||||
document.getElementById("new-program-link").value = '';
|
||||
document.getElementById("new-program-imglink").value = '';
|
||||
document.getElementById("new-program-description").value = '';
|
||||
document.getElementById("new-program-author").value = "";
|
||||
document.getElementById("new-program-type").value = "";
|
||||
}
|
||||
|
||||
|
||||
// onChange Page Update
|
||||
function programOnChange() {
|
||||
var title = document.getElementById("program-list").value
|
||||
var database = firebase.database().ref("programs/"+title.replace(/,/g,"."));
|
||||
database.on('value', function(data) {
|
||||
var data1 = data.val()
|
||||
document.getElementById("edit-program-link").value = data1["link"]
|
||||
document.getElementById("edit-program-imglink").value = data1["imglink"]
|
||||
document.getElementById("edit-program-description").value = data1["description"]
|
||||
document.getElementById("edit-program-author").value = data1["author"]
|
||||
document.getElementById("edit-program-type").value = data1["programtype"]
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
// Display all programs
|
||||
function displayPrograms() {
|
||||
database = firebase.database().ref("programs");
|
||||
database.once('value', function(snapshot) {
|
||||
snapshot.forEach(function(child) {
|
||||
firebase.database().ref("programs/"+child["key"]).on('value', function (data) {
|
||||
var data1 = data.val();
|
||||
var a = document.createElement("tr")
|
||||
a.innerHTML = "<td style='border-right-style: solid;' width='5%'><img src='"+data1["imglink"]+"' width='200'></td><td><a href='"+data1["link"]+" style='text-decoration: underline;'>"+data1["title"]+"</a><br> By "+data1["author"]+"<br>"+data1["programtype"]+"<br>"+data1["description"]+"</td>"
|
||||
document.getElementById("programs").appendChild(a)
|
||||
}
|
||||
)})
|
||||
});
|
||||
}
|
||||
|
||||
// Edit Program Entry
|
||||
function editProgram() {
|
||||
var data = {
|
||||
title: document.getElementById("program-list").value.replace(".",","),
|
||||
link: document.getElementById("edit-program-link").value,
|
||||
imglink: document.getElementById("edit-program-imglink").value,
|
||||
author: document.getElementById("edit-program-author").value,
|
||||
description: document.getElementById("edit-program-description").value,
|
||||
programtype: document.getElementById("edit-program-type").value
|
||||
}
|
||||
firebase.database().ref("programs/"+document.getElementById("program-list").value.replace(".",",")).set(data)
|
||||
document.getElementById("program-list").value = '';
|
||||
document.getElementById("edit-program-link").value = '';
|
||||
document.getElementById("edit-program-author").value = '';
|
||||
document.getElementById("edit-program-description").value = '';
|
||||
document.getElementById("edit-program-type").value = "";
|
||||
document.getElementById("edit-program-imglink").value = "";
|
||||
}
|
||||
|
||||
// Display all projects
|
||||
function displayProjects() {
|
||||
database = firebase.database().ref("projects");
|
||||
@@ -7,9 +90,9 @@ function displayProjects() {
|
||||
var data1 = data.val();
|
||||
var a = document.createElement("table")
|
||||
if (data1["link"] == "") {
|
||||
a.innerHTML = "<tr><td><div id='titles'>"+data1["title"]+"</h4><div class='"+data1["status"]+"'>"+data1["status"]+"</div></td></tr><tr class='spacing'><td>"+data1["description"]+"</td></tr><tr class='separator'></tr>"
|
||||
a.innerHTML = "<tr><td><div id='titles'>"+data1["title"].replace(/,/g,".")+"</h4><div class='"+data1["status"]+"'>"+data1["status"]+"</div></td></tr><tr class='spacing'><td>"+data1["description"]+"</td></tr><tr class='separator'></tr>"
|
||||
} else {
|
||||
a.innerHTML = "<tr><td><div id='titles'><a href='"+data1["link"]+"'>"+data1["title"]+"</a></h4><div class='"+data1["status"]+"'>"+data1["status"]+"</div></td></tr><tr class='spacing'><td>"+data1["description"]+"</td></tr><tr class='separator'></tr>"
|
||||
a.innerHTML = "<tr><td><div id='titles'><a href='"+data1["link"]+"'>"+data1["title"].replace(/,/g,".")+"</a></h4><div class='"+data1["status"]+"'>"+data1["status"]+"</div></td></tr><tr class='spacing'><td>"+data1["description"]+"</td></tr><tr class='separator'></tr>"
|
||||
}
|
||||
document.getElementById("projects").appendChild(a)
|
||||
}
|
||||
@@ -20,12 +103,12 @@ function displayProjects() {
|
||||
// Edit Selected Project
|
||||
function editProject() {
|
||||
var data = {
|
||||
title: document.getElementById("project-list").value,
|
||||
title: document.getElementById("project-list").value.replace(".",","),
|
||||
link: document.getElementById("edit-project-link").value,
|
||||
status: document.getElementById("edit-project-status").value,
|
||||
description: document.getElementById("edit-project-description").value
|
||||
}
|
||||
firebase.database().ref("projects/"+document.getElementById("project-list").value).set(data)
|
||||
firebase.database().ref("projects/"+document.getElementById("project-list").value.replace(".",",")).set(data)
|
||||
document.getElementById("project-list").value = '';
|
||||
document.getElementById("edit-project-link").value = '';
|
||||
document.getElementById("edit-project-status").value = 'active';
|
||||
@@ -35,7 +118,7 @@ function editProject() {
|
||||
// onChange page update
|
||||
function projectOnChange() {
|
||||
var title = document.getElementById("project-list").value
|
||||
var database = firebase.database().ref("projects/"+title);
|
||||
var database = firebase.database().ref("projects/"+title.replace(/,/g,"."));
|
||||
database.on('value', function(data) {
|
||||
var data1 = data.val()
|
||||
document.getElementById("edit-project-link").value = data1["link"]
|
||||
@@ -47,12 +130,12 @@ function projectOnChange() {
|
||||
// Project Submit
|
||||
function submitProject() {
|
||||
var data = {
|
||||
title: document.getElementById("new-project-title").value,
|
||||
title: document.getElementById("new-project-title").value.replace(".",","),
|
||||
link: document.getElementById("new-project-link").value,
|
||||
status: document.getElementById("new-project-status").value,
|
||||
description: document.getElementById("new-project-description").value
|
||||
}
|
||||
firebase.database().ref("projects/"+document.getElementById("new-project-title").value).set(data)
|
||||
firebase.database().ref("projects/"+document.getElementById("new-project-title").value.replace(".",",")).set(data)
|
||||
document.getElementById("new-project-title").value = '';
|
||||
document.getElementById("new-project-link").value = '';
|
||||
document.getElementById("new-project-status").value = 'active';
|
||||
@@ -65,8 +148,8 @@ function projectList() {
|
||||
database.once('value', function(snapshot) {
|
||||
snapshot.forEach(function(child) {
|
||||
var a = document.createElement("option")
|
||||
a.setAttribute("value",child["key"])
|
||||
a.innerHTML = child["key"]
|
||||
a.setAttribute("value",child["key"].replace(/,/g,"."))
|
||||
a.innerHTML = child["key"].replace(/,/g,".")
|
||||
document.getElementById("project-list").appendChild(a)
|
||||
})
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user