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

Commit

Permalink
fixed bug 143 & 144
Browse files Browse the repository at this point in the history
  • Loading branch information
bakaqc committed Mar 6, 2024
1 parent 5483afb commit 2847994
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 19 deletions.
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,12 +88,19 @@ 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);

Expand Down
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,35 @@
$(document).ready(function () {
$('#update-product').on('submit', function (e) {
e.preventDefault();

var formData = new FormData(this);

$.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';
});

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

}
});
});
});
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>

0 comments on commit 2847994

Please sign in to comment.