Spaces:
Sleeping
Sleeping
File size: 7,358 Bytes
2ed4a17 9ae2835 2ed4a17 |
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 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Upload Image</title>
<!-- Include Bootstrap CSS -->
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<header>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container">
<a class="navbar-brand" href="{% url 'index' %}">Catalogue</a>
</div>
</nav>
</header>
<body>
<div class="container mt-5">
<h1 class="text-center">Upload Image</h1>
<form id="upload-form" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="form-group">
<label for="images">Choose Images:</label>
<input type="file" class="form-control-file" id="images" name="images" multiple>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
</form>
<!-- Display product details for editing -->
<div id="edit-product" style="display: none;">
<h2 class="mt-4">Edit Product</h2>
<form id="edit-product-form">
{% csrf_token %}
<div class="form-group">
<label for="barcode">Barcode:</label>
<input type="text" class="form-control" id="barcode" name="barcode">
</div>
<div class="form-group">
<label for="brand">Brand:</label>
<input type="text" class="form-control" id="brand" name="brand">
</div>
<div class="form-group">
<label for="sub_brand">Sub Brand:</label>
<input type="text" class="form-control" id="sub_brand" name="sub_brand">
</div>
<div class="form-group">
<label for="manufacturer">Manufacturer:</label>
<input type="text" class="form-control" id="manufacturer" name="manufactured_by">
</div>
<div class="form-group">
<label for="product_name">Product Name:</label>
<input type="text" class="form-control" id="product_name" name="product_name">
</div>
<div class="form-group">
<label for="weight">Weight:</label>
<input type="text" class="form-control" id="weight" name="weight">
</div>
<div class="form-group">
<label for="variant">Variant:</label>
<input type="text" class="form-control" id="variant" name="variant">
</div>
<div class="form-group">
<label for="net_content">Net Content:</label>
<input type="text" class="form-control" id="net_content" name="net_content">
</div>
<div class="form-group">
<label for="price">Price:</label>
<input type="text" class="form-control" id="price" name="price">
</div>
<div class="form-group">
<label for="parent_category">Parent Category:</label>
<input type="text" class="form-control" id="parent_category" name="parent_category">
</div>
<div class="form-group">
<label for="child_category">Child Category:</label>
<input type="text" class="form-control" id="child_category" name="child_category">
</div>
<div class="form-group">
<label for="sub_child_category">Sub Child Category:</label>
<input type="text" class="form-control" id="sub_child_category" name="sub_child_category">
</div>
<div class="form-group">
<label for="description">Description:</label>
<textarea class="form-control" id="description" name="description"></textarea>
</div>
<div class="form-group">
<label for="quantity">Quantity:</label>
<input type="text" class="form-control" id="quantity" name="quantity">
</div>
<div class="form-group">
<label for="mrp">MRP:</label>
<input type="text" class="form-control" id="mrp" name="mrp">
</div>
<!-- Add image input if needed -->
<button type="submit" class="btn btn-primary">Save</button>
</form>
</div>
<!-- Display product details here -->
<div class="mt-4" id="product-details">
<h2>Product Details</h2>
<ul id="product-details-list">
<!-- Product details will be added dynamically here -->
</ul>
</div>
</div>
<!-- Include jQuery for AJAX -->
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function() {
// Submit form via AJAX when image is uploaded
$('#upload-form').submit(function(event) {
event.preventDefault();
var formData = new FormData($(this)[0]);
$.ajax({
url: $(this).attr('action'),
type: $(this).attr('method'),
data: formData,
processData: false,
contentType: false,
success: function(response) {
// Display product details
displayProductDetails(response);
// Show edit product form
$('#edit-product').show();
},
error: function(xhr, status, error) {
console.log(xhr.responseText);
}
});
});
// Submit edit product form via AJAX
$('#edit-product-form').submit(function(event) {
event.preventDefault();
var formData = $(this).serialize();
$.ajax({
url: 'http://34.122.223.224:9002/api/products/',
type: 'POST',
data: formData,
success: function(response) {
// Optionally, handle success response
console.log(response);
},
error: function(xhr, status, error) {
console.log(xhr.responseText);
}
});
});
function displayProductDetails(details) {
$('#product-details-list').empty();
$.each(details, function(key, value) {
$('#product-details-list').append('<li><strong>' + key + ':</strong> ' + value + '</li>');
// Populate edit product form fields
$('#edit-product-form').find('[name="' + key + '"]').val(value);
});
}
});
</script>
</body>
</html>
|