-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
217 additions
and
189 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,59 @@ | ||
// Handles product to edit selection | ||
function loadProductInfo() { | ||
// Get selected product | ||
const productId = document.getElementById('product_id').value | ||
const productId = document.getElementById("product_id").value; | ||
|
||
// Image should change no matter what | ||
const newImg = new Image() | ||
const newImg = new Image(); | ||
newImg.onload = function () { | ||
document.getElementById('product_img').src = this.src | ||
} | ||
document.getElementById("product_img").src = this.src; | ||
}; | ||
|
||
// Reset form if product deselected | ||
if (productId === '') { | ||
document.getElementById('supplier_edit_product').reset() | ||
newImg.src = '/static_images/preview.png' | ||
return | ||
if (productId === "") { | ||
document.getElementById("supplier_edit_product").reset(); | ||
newImg.src = "/static_images/preview.png"; | ||
return; | ||
} | ||
|
||
// Load image | ||
newImg.src = json_data[productId].product_image | ||
newImg.src = json_data[productId].product_image; | ||
|
||
// Display Name | ||
document.getElementById('product_name').value = | ||
json_data[productId].product_name | ||
document.getElementById("product_name").value = | ||
json_data[productId].product_name; | ||
|
||
// Description | ||
document.getElementById('product_description').value = | ||
json_data[productId].product_description | ||
document.getElementById("product_description").value = | ||
json_data[productId].product_description; | ||
|
||
// Description - optional parameter | ||
document.getElementById("product_code").value = | ||
json_data[productId].product_code || ""; | ||
|
||
// Category - optional parameter | ||
if (json_data[productId].product_category === '') { | ||
document.getElementById('product_category').value = '' | ||
} else { | ||
document.getElementById('product_category').value = | ||
json_data[productId].product_category | ||
} | ||
document.getElementById("product_category").value = | ||
json_data[productId].product_category || ""; | ||
} | ||
|
||
// Handles new image to upload selection | ||
function readURL(input) { | ||
if (input.files && input.files[0]) { | ||
var reader = new FileReader() | ||
var reader = new FileReader(); | ||
|
||
reader.onload = function (e) { | ||
document | ||
.getElementById('product_img') | ||
.setAttribute('src', e.target.result) | ||
} | ||
.getElementById("product_img") | ||
.setAttribute("src", e.target.result); | ||
}; | ||
|
||
reader.readAsDataURL(input.files[0]) | ||
reader.readAsDataURL(input.files[0]); | ||
} | ||
} | ||
|
||
document.addEventListener('DOMContentLoaded', function () { | ||
document.addEventListener("DOMContentLoaded", function () { | ||
// Load image when browser navigates back to this page | ||
if (document.getElementById('product_id').value) { | ||
loadProductInfo() | ||
if (document.getElementById("product_id").value) { | ||
loadProductInfo(); | ||
} | ||
}) | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.