Skip to content
This repository has been archived by the owner on May 31, 2024. It is now read-only.

Fixed bug 143 & 144 #155

Merged
merged 3 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
Integer idP = Integer.valueOf(pId);
String productName = request.getParameter("productName");
String productDescription = request.getParameter("productDescription");
double price = Double.parseDouble(request.getParameter("price"));
String productPrice = request.getParameter("price");

Part part = request.getPart("imageUpload");
String imgURL = null;
if (part.getSize() > 0) {
Expand All @@ -88,16 +88,23 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
part.write(realPath + "/" + fileName);
}


Product product = Singleton.productDAO.getByID(idP).get();
product.setPrice(price);
product.setName(productName);
product.setImageURL(imgURL);
product.setDescription(productDescription);
if (!productName.isEmpty()) {
product.setName(productName);
}
if (!productPrice.isEmpty()) {
product.setPrice(Double.parseDouble(productPrice));
}
if (imgURL != null) {
product.setImageURL(imgURL);
}
if (!productDescription.isEmpty()) {
product.setDescription(productDescription);
}

Singleton.productDAO.save(product);

response.sendRedirect("./product");
response.sendRedirect("./product-detail?id=" + idP);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ $(document).ready(function () {
title: 'Thành công!',
text: 'Thêm sản phẩm thành công',
icon: 'success',
timer: 3000
timer: 1500
}).then((result) => {
if (result.dismiss === Swal.DismissReason.timer) {
console.log('I was closed by the timer')
Expand All @@ -25,7 +25,7 @@ $(document).ready(function () {

setTimeout(function () {
window.location.href = 'product';
}, 3000);
}, 1500);
},
error: function (response) {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
$(document).ready(function () {
$('#update-product').on('submit', function (e) {
e.preventDefault();

var formData = new FormData(this);

var productId = formData.get('id');

$.ajax({
type: 'POST',
url: $(this).attr('action'),
data: formData,
processData: false,
contentType: false,
success: function (response) {
Swal.fire({
title: 'Thành công!',
text: 'Cập nhật sản phẩm thành công',
icon: 'success',
timer: 1500
}).then((result) => {
if (result.dismiss === Swal.DismissReason.timer) {
console.log('I was closed by the timer')
}
window.location.href = 'product-detail?id=' + productId;
});

setTimeout(function () {
window.location.href = 'product-detail?id=' + productId;
}, 1500);
},
error: function (response) {

}
});
});
});
10 changes: 5 additions & 5 deletions src/main/webapp/view/jsp/management/customer/customer-detail.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,11 @@
<div class="mb-3"><label class="form-label" for="country"><strong>Email</strong></label>
<input class="form-control" type="text" id="country" placeholder="${requestScope.cus.email}" name="country" readonly="">
</div>

<button class="btn btn-primary btn-sm" type="button">
<a class="back" href="<%=request.getContextPath()%>/customer" style="color: white; text-decoration: none;">Quay lại</a>
</button>

<a class="back" href="<%=request.getContextPath()%>/customer" style="color: white; text-decoration: none;">
<button class="btn btn-primary btn-sm" type="button">
Quay lại
</button>
</a>
</div>
</form>
</div>
Expand Down
20 changes: 10 additions & 10 deletions src/main/webapp/view/jsp/management/product/update-product.jsp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@page import="io.hardingadonis.saledock.utils.Singleton" %>

<!DOCTYPE html>
Expand Down Expand Up @@ -39,7 +40,7 @@
<p class="text-primary m-0 fw-bold">Cập nhập sản phẩm</p>
</div>
<div class="card-body">
<form action="update-product" enctype="multipart/form-data" method="post">
<form id="update-product" action="update-product" enctype="multipart/form-data" method="post">
<input name="id" hidden value="${param.id}" />
<div class="row">
<div class="col">
Expand Down Expand Up @@ -72,14 +73,10 @@
<div class="mb-3">
<label class="form-label" for="email">
<strong>Giá tiền</strong>
</label>
<input class="form-control" type="number" id="price" placeholder="${requestScope.pro.price}" name="price" required min="0" oninvalid="this.setCustomValidity('Vui lòng nhập Giá sản phẩm.')" oninput="this.setCustomValidity('')">
<script>
let inputElement = document.getElementById("price");
let valueText = inputElement.value;
let formattedNum = new Intl.NumberFormat('vi-VN', {style: 'currency', currency: 'VND'}).format(valueText);
inputElement.value = formattedNum;
</script>
</label>
<fmt:formatNumber value="${requestScope.pro.price}" type="currency" currencySymbol="₫" pattern="#,##0 ¤" var="proPrice" />
<input class="form-control" type="number" id="price" placeholder="${proPrice}" name="price" min="0">

</div>
</div>
</div>
Expand Down Expand Up @@ -121,7 +118,7 @@
Quay lại
</a>
<button class="btn btn-primary btn-sm" type="submit">
Lưu
Cập nhật sản phẩm
</button>
</div>
</div>
Expand All @@ -141,9 +138,12 @@
<%@include file="../../../common/_goback.jsp" %>
</div>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/sweetalert2@11"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/bootstrap.min.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/bs-init.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/theme.js"></script>
<script src="<%=request.getContextPath()%>/view/assets/js/management/product/update-product.js"></script>
</body>

</html>
Loading