-
Notifications
You must be signed in to change notification settings - Fork 0
/
addPart.js
50 lines (46 loc) · 1.39 KB
/
addPart.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
window.onload = function() {
console.log("loaded");
firebase.auth().onAuthStateChanged(function(user) {
if (user.email == "admin@annex272.com") {
} else {
console.log("notsignedin")
document.location.href = "index.html";
}
});
}
function addPart(){
var db = firebase.firestore()
name = document.getElementById('name').value
description = document.getElementById('description').value
resources = document.getElementById('resources').value
image = document.getElementById('image').value
quantity = document.getElementById('quantity').value
loc = document.getElementById('location').value
if (name == "" || description == "" || resources == "" || image == "" || quantity == "" || loc == ""){
alert("We need the name of the part")
} else {
db.collection("components").doc(name).set({
name: name,
description: description,
quantity: Number(quantity),
resources: resources,
image: image,
location: loc
})
.then(function(docRef) {
alert("Part added")
console.log("Document written");
document.location.href = "admin.html";
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
}
}
function signOutAccount() {
firebase.auth().signOut().then(function() {
console.log("signing out")
}).catch(function(error) {
// An error happened.
});
};