Update
This commit is contained in:
parent
160d1b9275
commit
45bfa84f8d
@ -55,19 +55,19 @@
|
||||
<div class="new-product-field" id="npf" style="display: none;">
|
||||
<p>Add product</p>
|
||||
<div class="npf-short">
|
||||
<input type="text" id="pName" placeholder="Product Name">
|
||||
<input required autofocus type="text" id="pName" placeholder="Product Name">
|
||||
</div>
|
||||
<div class="npf-long">
|
||||
<input type="text" id="pDesc" placeholder="Description">
|
||||
<input required type="text" id="pDesc" placeholder="Description">
|
||||
</div>
|
||||
<input type="file" id="pImg" value="upload">
|
||||
<input type="text" id="pLoc" placeholder="Location (eg. London)">
|
||||
<input type="text" id="pStock" placeholder="Quantity in stock (default: 1)">
|
||||
<input required type="file" id="pImg" value="upload">
|
||||
<input required type="text" id="pLoc" placeholder="Location (eg. London)">
|
||||
<input required type="text" id="pStock" placeholder="Quantity in stock (default: 1)">
|
||||
<div class="npf-long">
|
||||
<input type="text" id="pPublic" placeholder="Display: leave empty for public, type for private, CHECKBOXES ARE FUCKING HARD">
|
||||
</div>
|
||||
<div class="npf-short">
|
||||
<input type="text" id="pPrice" placeholder="Price £">
|
||||
<input required type="text" id="pPrice" placeholder="Price £">
|
||||
</div>
|
||||
<button id="pSend" onclick={productSubmutEventHandler()}>Submit</button>
|
||||
</div>
|
||||
|
||||
@ -20,16 +20,13 @@ function productSubmutEventHandler(){
|
||||
const priceField = document.getElementById('pPrice')
|
||||
|
||||
const imgBtn = document.getElementById('pImg')
|
||||
var image = imgBtn.files[0]
|
||||
var storageRef = firebase.storage().ref('/product-img/' + image.name)
|
||||
storageRef.put(image)
|
||||
|
||||
var sessUid = firebase.auth().currentUser.uid
|
||||
|
||||
data.id = 999
|
||||
data.name = nameField.value
|
||||
data.desc = descField.value
|
||||
data.img = image.name
|
||||
data.img = "default.png"
|
||||
data.location = locField.value
|
||||
data.stock = stockField.value
|
||||
data.public = publicField.value
|
||||
@ -37,20 +34,33 @@ function productSubmutEventHandler(){
|
||||
data.owner = sessUid
|
||||
data.holder = sessUid
|
||||
|
||||
addItem(data)
|
||||
var productKey = addItem(data)
|
||||
console.log(productKey)
|
||||
|
||||
var image = imgBtn.files[0]
|
||||
var imgPath = productKey + '/' + image.name
|
||||
var storageRef = firebase.storage().ref('/product-img/' + imgPath)
|
||||
updateDBImg(productKey, imgPath)
|
||||
|
||||
storageRef.put(image).then(function(){
|
||||
window.location.replace('home?itemAdded=true')
|
||||
})
|
||||
}
|
||||
|
||||
function addItem(item){
|
||||
var database = firebase.database()
|
||||
var itemRef = database.ref('/products')
|
||||
var key = itemRef.push(item)
|
||||
return key.key
|
||||
}
|
||||
|
||||
itemRef.push(item)
|
||||
.then(function(){
|
||||
window.location.replace('home?itemAdded=true')
|
||||
})
|
||||
.catch(function(error){
|
||||
console.log(error)
|
||||
})
|
||||
function updateDBImg(key, value){
|
||||
console.log("Updating db, key=" + key + " value="+value+" total=" + '/products/' + key)
|
||||
var database = firebase.database()
|
||||
var itemRef = database.ref('/products/' + key)
|
||||
console.log("itemRef")
|
||||
console.log(itemRef)
|
||||
itemRef.update({img: value});
|
||||
}
|
||||
|
||||
function updateImgs() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user