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